Solved

Inter-Dependant Variables in procedural application model

Posted on 2006-06-18
2
218 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now