Solved

Inter-Dependant Variables in procedural application model

Posted on 2006-06-18
2
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

729 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