• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 264
  • Last Modified:

Inter-Dependant Variables in procedural application model

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
bmarshallbri
Asked:
bmarshallbri
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
bmarshallbriAuthor Commented:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now