Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Inter-Dependant Variables in procedural application model

Posted on 2006-06-18
2
Medium Priority
?
252 Views
Last Modified: 2006-11-18
So I’m building a php loan application for my client. I’ve pretty much finished the entire app down to a problem with these 7 lines included below. I’m new at doing things that have so many interdependent variables and I am in a bit over my head at this point.

Basically what this thing does is takes a bunch of user input, sanitizes and validates it all then hands it off to this calculator. My approach was to take all of the formulas required to do the loan calculations and make a bunch of little functions that do little calculations and return values, arrays or sometimes print html out to the browser. Below all of the functions I instantiate all of the variables needed to do the loan calculations by making calls to the functions and interweave all of that with html and some logic to get everything done.  

The problem is that I have a value, $ltv (below) that requires $estLoanCost to determine it’s value. $estLoanCost is not instantiated until further down the line. I have been moving things around (up or down) to make sure things happen in the right order. But this has boiled down to a kind of circular dependency between a handful of variables. I can’t move things around anymore without breaking more variables, I’ve basically boiled it all down to this. I can’t move $estLoanCost up because it requires everything above it to determine itself.

Right now this works because the ltv_func() is producing a value that allows the calculations to complete, but it does not use all of the right criteria in it’s decision making.

$ltv = ltv_func($nmdBal,$currentMortPayoffEst,$estLoanCost,$_SESSION['userHomeValue'],$ltvDeterminer);
$amtNewMort = amt_new_mort_func($ltv,$_SESSION['userHomeValue']);
$originationFee = origination_fee_func($amtNewMortA,$originationFeeDeterminer);
$titleCost = title_cost_func($amtNewMortA,$titleCostTable);
$escrowWaiverCost = round(escrow_waiver_cost($amtNewMort,$escrowWaiverDeterminer));
$interimInterest = round(interim_interest_func($amtNewMort,$interimRate));
$estLoanCost = est_loan_cost_func($originationFee,$hardCost,$titleCost,$escrowWaiverCost,$interimInterest);

So I think my problem is that I need a new paradigm for my approach of stitching all of this together. Is there a way I can have these run simultaneously? Doesn’t seem likely to me, but I’m definitely stumped as to how to get around this.

Any help would be greatly appreciated. My eyeballs hurt.
0
Comment
Question by:bmarshallbri
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 16931918
well, either you redefine the procedures to work differently, or merge all of this into 1 procedure, or run the code 2 times (once with $estLoanCost parameter value of 0 (or some other arbitrary value), and then with the value returned...

$ltv = ltv_func($nmdBal,$currentMortPayoffEst,0,$_SESSION['userHomeValue'],$ltvDeterminer);
$amtNewMort = amt_new_mort_func($ltv,$_SESSION['userHomeValue']);
$originationFee = origination_fee_func($amtNewMortA,$originationFeeDeterminer);
$titleCost = title_cost_func($amtNewMortA,$titleCostTable);
$escrowWaiverCost = round(escrow_waiver_cost($amtNewMort,$escrowWaiverDeterminer));
$interimInterest = round(interim_interest_func($amtNewMort,$interimRate));
$estLoanCost = est_loan_cost_func($originationFee,$hardCost,$titleCost,$escrowWaiverCost,$interimInterest);

$ltv = ltv_func($nmdBal,$currentMortPayoffEst,$estLoanCost,$_SESSION['userHomeValue'],$ltvDeterminer);
$amtNewMort = amt_new_mort_func($ltv,$_SESSION['userHomeValue']);
$originationFee = origination_fee_func($amtNewMortA,$originationFeeDeterminer);
$titleCost = title_cost_func($amtNewMortA,$titleCostTable);
$escrowWaiverCost = round(escrow_waiver_cost($amtNewMort,$escrowWaiverDeterminer));
$interimInterest = round(interim_interest_func($amtNewMort,$interimRate));
$estLoanCost = est_loan_cost_func($originationFee,$hardCost,$titleCost,$escrowWaiverCost,$interimInterest);

Possibly run it several loops to approach the value...

I am not sure how the formulas are working and what they are exactly calculating in order to be depending in the circular way.
My best suggestion would be to get rid of the $estLoadCost in the ltv_func if possible
0
 

Author Comment

by:bmarshallbri
ID: 16931951
Thanks for the prompt response!

That was so simple. Running it twice did it! The first time it runs the $estLoanCost is taken as a zero. It's a nominal dollar ammount, so simply running those lines a second time produces the right adjustment.

Thanks so much. I really appreciate it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question