From 8c6a50554ee02e41fee21b81109fa8aa74f6faa1 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Thu, 5 Mar 2015 20:37:36 +0100 Subject: [PATCH] Debug of Frederic34. Thanks ! --- htdocs/compta/loan/calc.php | 43 ++++++++++++++++++++---------------- htdocs/langs/en_US/loan.lang | 1 + 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/htdocs/compta/loan/calc.php b/htdocs/compta/loan/calc.php index 5cc2c830094..009c61095c9 100644 --- a/htdocs/compta/loan/calc.php +++ b/htdocs/compta/loan/calc.php @@ -1,6 +1,7 @@ * Copyright (C) 2014 Alexandre Spangaro + * Copyright (C) 2015 Frederic France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,7 +20,7 @@ require '../../main.inc.php'; $langs->load("loan"); - + /* --------------------------------------------------- * * Set Form DEFAULT values * --------------------------------------------------- */ @@ -82,12 +83,17 @@ if ($form_complete) { $annual_interest_percent = preg_replace( "[^0-9.]", "", $annual_interest_percent); $year_term = preg_replace( "[^0-9.]", "", $year_term); $down_percent = preg_replace( "[^0-9.]", "", $down_percent); - - if (((float) $year_term <= 0) || ((float) $sale_price <= 0) || ((float) $annual_interest_percent <= 0)) { - $error = "You must enter a Sale Price of Home, Length of Motgage and Annual Interest Rate"; - } - if (!$error) { + if ((float) $year_term <= 0) { + $errors[] = "You must enter a Sale Price of Home"; + } + if ((float) $sale_price <= 0) { + $errors[] = "You must enter a Length of Mortgage"; + } + if ((float) $annual_interest_percent <= 0) { + $errors[] = "You must enter an Annual Interest Rate"; + } + if (!$errors) { $month_term = $year_term * 12; $down_payment = $sale_price * ($down_percent / 100); $annual_interest_rate = $annual_interest_percent / 100; @@ -104,8 +110,8 @@ if ($form_complete) { if (!$show_progress) { $show_progress = $default_show_progress; } } -if ($error) { - print("" . $error . "

\n"); +if (! empty($errors)) { + setEventMessages('', $errors, 'errors'); $form_complete = false; } @@ -123,17 +129,16 @@ echo "This mortgage calculator can be use print '
'; print ''; print ''; -print ''; -print ''; -print ''; -print ''; +//print ''; +//print ''; +//print ''; +//print ''; print ''; print ''; print ''; print ''; print ''; -print ''; -print ''; +print '';print ''; print ''; print ''; print ''; @@ -289,7 +294,7 @@ if ($form_complete && $show_progress) { print '
Purchase & Financing Information
Sale Price of Home: '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("Currency".$conf->currency).'
Percentage Down:%'; print 'The montly payment is figured out using the following formula:
'; print 'Monthly Payment = ' . number_format($financing_price, "2", "", "") . ' * '; - print number_format($monthly_interest_rate, "4", "", "") . ' / '; + print $langs->trans('MonthlyPayment').' = ' . number_format($financing_price, "2", "", "") . ' * '; print '(1 - ((1 + ' . number_format($monthly_interest_rate, "4", "", "") . ')'; print '-(' . $month_term . '))))'; print '

'; @@ -311,7 +316,7 @@ if ($form_complete && $show_progress) { $denom = pow((1 + $monthly_interest_rate), $power); $monthly_payment = $principal * ($monthly_interest_rate / (1 - $denom)); - print("

Amortization For Monthly Payment: \$" . number_format($monthly_payment, "2", ".", ",") . " over " . $year_term . " years
\n"); + print "

Amortization For Monthly Payment: " . number_format($monthly_payment, "2", ".", ",") . " over " . $year_term . " years
\n"); print ''; @@ -323,8 +328,8 @@ if ($form_complete && $show_progress) { $legend.= ''; $legend.= ''; - echo $legend; - + print $legend; + // Loop through and get the current month's payments for // the length of the loan while ($current_month <= $month_term) @@ -377,7 +382,7 @@ if ($form_complete && $show_progress) { $principal = $remaining_balance; $current_month++; } - print("
' . $langs->trans("Position") . '
\n"); + print "
\n"; } llxFooter(); diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang index e59fc7898b8..a035c8cf68c 100644 --- a/htdocs/langs/en_US/loan.lang +++ b/htdocs/langs/en_US/loan.lang @@ -19,6 +19,7 @@ ErrorLoanLength=Loan length has to be numeric and greater ErrorLoanInterest=Annual interest has to be numeric and greater than zero. # Calc Totalsforyear=Totals for year +MonthlyPayment=Monthly Payment # Admin ConfigLoan=Configuration of the module loan LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Accountancy code capital by default