From c4d852ffd73e3fa6af264aaf6a254ab3a80f1cfb Mon Sep 17 00:00:00 2001 From: aspangaro Date: Sun, 22 Mar 2015 20:57:41 +0100 Subject: [PATCH] Correct from frederic34 --- htdocs/langs/en_US/loan.lang | 1 + htdocs/loan/calc.php | 33 +++++++++++++++----------------- htdocs/loan/class/loan.class.php | 26 ++++++++++++++++++------- htdocs/loan/index.php | 13 +++++++------ htdocs/loan/info.php | 25 ++++++++++++++---------- htdocs/loan/payment/card.php | 21 ++++++++------------ 6 files changed, 65 insertions(+), 54 deletions(-) diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang index a035c8cf68c..4922c0fc0a1 100644 --- a/htdocs/langs/en_US/loan.lang +++ b/htdocs/langs/en_US/loan.lang @@ -20,6 +20,7 @@ ErrorLoanInterest=Annual interest has to be numeric and g # Calc Totalsforyear=Totals for year MonthlyPayment=Monthly Payment +LoanCalcDesc=This mortgage calculator can be used to figure out monthly payments of a home mortgage loan, based on the home's sale price, the term of the loan desired, buyer's down payment percentage, and the loan's interest rate.
This calculator factors in PMI (Private Mortgage Insurance) for loans where less than 20% is put as a down payment. Also taken into consideration are the town property taxes, and their effect on the total monthly mortgage payment.
# Admin ConfigLoan=Configuration of the module loan LOAN_ACCOUNTING_ACCOUNT_CAPITAL=Accountancy code capital by default diff --git a/htdocs/loan/calc.php b/htdocs/loan/calc.php index 0b40ef38f70..0a5ee21923a 100644 --- a/htdocs/loan/calc.php +++ b/htdocs/loan/calc.php @@ -121,10 +121,7 @@ if (! empty($errors)) { llxHeader(); -echo "This mortgage calculator can be used to figure out monthly payments of a home mortgage loan, - based on the home's sale price, the term of the loan desired, buyer's down payment percentage, and the loan's interest rate. - This calculator factors in PMI (Private Mortgage Insurance) for loans where less than 20% is put as a down payment. Also taken - into consideration are the town property taxes, and their effect on the total monthly mortgage payment.
"; +print $langs->trans('LoanCalcDesc'); print '
'; print ''; @@ -190,7 +187,7 @@ if ($form_complete && $monthly_payment) print 'Monthly Payment:'; print '' . number_format($monthly_payment, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '
(Principal & Interest ONLY)'; print ''; - + if ($down_percent < 20) { $pmi_per_month = 55 * ($financing_price / 100000); @@ -216,11 +213,11 @@ if ($form_complete && $monthly_payment) print ' '; print ''; print '
'; - + $assessed_price = ($sale_price * .85); $residential_yearly_tax = ($assessed_price / 1000) * 14; $residential_monthly_tax = $residential_yearly_tax / 12; - + if ($pmi_per_month) { $pmi_text = "PMI and "; @@ -304,8 +301,8 @@ if ($form_complete && $show_progress) { print ''; print ''; print '
'; - - + + // Set some base variables $principal = $financing_price; $current_month = 1; @@ -315,11 +312,11 @@ if ($form_complete && $show_progress) { $power = -($month_term); $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 ''; - + // This LEGEND will get reprinted every 12 months $legend = ''; $legend.= ''; @@ -327,7 +324,7 @@ if ($form_complete && $show_progress) { $legend.= ''; $legend.= ''; $legend.= ''; - + print $legend; // Loop through and get the current month's payments for @@ -348,14 +345,14 @@ if ($form_complete && $show_progress) { print ''; print ''; print ''; - + ($current_month % 12) ? $show_legend = FALSE : $show_legend = TRUE; if ($show_legend) { print ''; print ''; print ''; - + $total_spent_this_year = $this_year_interest_paid + $this_year_principal_paid; print ''; print ''; @@ -369,11 +366,11 @@ if ($form_complete && $show_progress) { print ''; print ''; print ''; - + $current_year++; $this_year_interest_paid = 0; $this_year_principal_paid = 0; - + if (($current_month + 6) < $month_term) { echo $legend; diff --git a/htdocs/loan/class/loan.class.php b/htdocs/loan/class/loan.class.php index d1b770f744c..9ab8a690494 100644 --- a/htdocs/loan/class/loan.class.php +++ b/htdocs/loan/class/loan.class.php @@ -69,7 +69,7 @@ class Loan extends CommonObject * Load object in memory from database * * @param int $id id object - * @return void + * @return int <0 error , >=0 no error */ function fetch($id) { @@ -146,8 +146,8 @@ class Loan extends CommonObject if (($conf->accounting->enabled) && empty($this->account_capital) && empty($this->account_insurance) && empty($this->account_interest)) { $this->error="ErrorAccountingParameter"; - return -2; - } + return -2; + } $this->db->begin(); @@ -304,8 +304,12 @@ class Loan extends CommonObject $sql.= " paid = 1"; $sql.= " WHERE rowid = ".$this->id; $return = $this->db->query($sql); - if ($return) return 1; - else return -1; + if ($return) { + return 1; + } else { + $this->error=$this->db->lasterror(); + return -1; + } } /** @@ -423,7 +427,8 @@ class Loan extends CommonObject } else { - return -1; + $this->error=$this->db->lasterror(); + return -1; } } @@ -464,12 +469,19 @@ class Loan extends CommonObject $this->date_creation = $this->db->jdate($obj->datec); if (empty($obj->fk_user_modif)) $obj->tms = ""; $this->date_modification = $this->db->jdate($obj->tms); + + return 1; + } + else + { + return 0; } $this->db->free($result); } else { - dol_print_error($this->db); + $this->error=$this->db->lasterror(); + return -1; } } } \ No newline at end of file diff --git a/htdocs/loan/index.php b/htdocs/loan/index.php index db6e9544cee..082e5d0d0c2 100644 --- a/htdocs/loan/index.php +++ b/htdocs/loan/index.php @@ -50,7 +50,8 @@ $search_label=GETPOST('search_label','alpha'); $search_amount=GETPOST('search_amount','alpha'); $filtre=GETPOST("filtre"); -if (GETPOST("button_removefilter")) +// Purge search criteria +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers { $search_ref=""; $search_label=""; @@ -112,11 +113,11 @@ if ($resql) print ''; print ''; print ''; - + while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); - + $var = !$var; print ""; @@ -135,7 +136,7 @@ if ($resql) print ''; print "\n"; - + $i++; } @@ -147,6 +148,6 @@ else { dol_print_error($db); } -$db->close(); - llxFooter(); + +$db->close(); \ No newline at end of file diff --git a/htdocs/loan/info.php b/htdocs/loan/info.php index 5e90474642a..16c349b92e9 100644 --- a/htdocs/loan/info.php +++ b/htdocs/loan/info.php @@ -46,20 +46,25 @@ $result = restrictedArea($user, 'loan', $id, '',''); $help_url='EN:Module_Loan|FR:Module_Emprunt'; llxHeader("",$langs->trans("Loan"),$help_url); -$loan = new Loan($db); -$loan->fetch($id); -$loan->info($id); +if ($id > 0) { + $loan = new Loan($db); + $loan->fetch($id); + $loan->info($id); -$head = loan_prepare_head($loan); + $head = loan_prepare_head($loan); -dol_fiche_head($head, 'info', $langs->trans("Loan"), 0, 'bill'); + dol_fiche_head($head, 'info', $langs->trans("Loan"), 0, 'bill'); + print '
' . $langs->trans("Month") . '' . $langs->trans("Capital") . '' . $langs->trans("Position") . '
' . number_format($principal_paid, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '' . number_format($remaining_balance, "2", ".", ",") . ' ' . $langs->trans("Currency".$conf->currency) . '
' . $langs->trans("Totalsforyear") . ' ' . $current_year . '
 
 
'.$loan_static->LibStatut($obj->paid,5,$obj->alreadypayed).'
'; + dol_print_object_info($loan); + print '
'; -print '
'; -dol_print_object_info($loan); -print '
'; - -print ''; + print ''; +} +else +{ + // $id ? +} llxFooter(); diff --git a/htdocs/loan/payment/card.php b/htdocs/loan/payment/card.php index 901daffaa2d..f75a2244154 100644 --- a/htdocs/loan/payment/card.php +++ b/htdocs/loan/payment/card.php @@ -133,7 +133,6 @@ dol_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), 0, 'payment'); if ($action == 'delete') { print $form->formconfirm('card.php?id='.$payment->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2); - } /* @@ -142,8 +141,7 @@ if ($action == 'delete') if ($action == 'valide') { $facid = $_GET['facid']; - print $form->formconfirm('card.php?id='.$payment->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); - + print $form->formconfirm('card.php?id='.$payment->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2); } @@ -283,18 +281,15 @@ if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) } */ -if ($_GET['action'] == '') +if (empty($action) && ! empty($user->rights->loan->delete)) { - if ($user->rights->loan->delete) + if (! $disable_delete) { - if (! $disable_delete) - { - print ''.$langs->trans('Delete').''; - } - else - { - print ''.$langs->trans('Delete').''; - } + print ''.$langs->trans('Delete').''; + } + else + { + print ''.$langs->trans('Delete').''; } }