From 582608cc572a982deb02a3969d8765898793dbe5 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Fri, 19 Oct 2018 15:36:13 +0200 Subject: [PATCH] manage fk_bank on loanschedule --- htdocs/loan/class/paymentloan.class.php | 1 + htdocs/loan/payment/card.php | 3 +++ htdocs/loan/payment/payment.php | 26 ++++++++++++++++++++++--- htdocs/loan/schedule.php | 14 ++++++++++--- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/htdocs/loan/class/paymentloan.class.php b/htdocs/loan/class/paymentloan.class.php index c4c29c99dce..7bed069cec2 100644 --- a/htdocs/loan/class/paymentloan.class.php +++ b/htdocs/loan/class/paymentloan.class.php @@ -530,6 +530,7 @@ class PaymentLoan extends CommonObject $result = $this->db->query($sql); if ($result) { + $this->fk_bank = $id_bank; return 1; } else diff --git a/htdocs/loan/payment/card.php b/htdocs/loan/payment/card.php index 919139bd6e3..110ad8d891c 100644 --- a/htdocs/loan/payment/card.php +++ b/htdocs/loan/payment/card.php @@ -54,6 +54,9 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->del { $db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".$payment->fk_bank; + $db->query($sql); + $result = $payment->delete($user); if ($result > 0) { diff --git a/htdocs/loan/payment/payment.php b/htdocs/loan/payment/payment.php index ba6650c9c03..2d81f95d034 100644 --- a/htdocs/loan/payment/payment.php +++ b/htdocs/loan/payment/payment.php @@ -24,6 +24,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; @@ -32,6 +33,7 @@ $langs->loadLangs(array("bills","loan")); $chid=GETPOST('id','int'); $action=GETPOST('action','aZ09'); $cancel=GETPOST('cancel','alpha'); +$line_id = GETPOST('line_id', 'int'); // Security check $socid=0; @@ -43,6 +45,17 @@ if ($user->societe_id > 0) $loan = new Loan($db); $loan->fetch($chid); +if (!empty($line_id)) +{ + $line = new LoanSchedule($db); + $res = $line->fetch($line_id); + if ($res > 0){ + $amount_capital = price($line->amount_capital); + $amount_insurance = price($line->amount_insurance); + $amount_interest = price($line->amount_interest); + } +} + /* * Actions */ @@ -121,6 +134,12 @@ if ($action == 'add_payment') setEventMessages($payment->error, $payment->errors, 'errors'); $error++; } + elseif(isset($line)) + { + $line->fk_bank = $payment->fk_bank; + $line->update($user); + } + } if (! $error) @@ -161,6 +180,7 @@ if ($action == 'create') print ''; print ''; print ''; + print ''; print ''; dol_fiche_head(); @@ -264,7 +284,7 @@ if ($action == 'create') print ''; if ($sumpaid < $loan->capital) { - print $langs->trans("LoanCapital") .': '; + print $langs->trans("LoanCapital") .': '; } else { @@ -273,7 +293,7 @@ if ($action == 'create') print '
'; if ($sumpaid < $loan->capital) { - print $langs->trans("Insurance") .': '; + print $langs->trans("Insurance") .': '; } else { @@ -282,7 +302,7 @@ if ($action == 'create') print '
'; if ($sumpaid < $loan->capital) { - print $langs->trans("Interest") .': '; + print $langs->trans("Interest") .': '; } else { diff --git a/htdocs/loan/schedule.php b/htdocs/loan/schedule.php index d775ebaca84..9fb5a4397ee 100644 --- a/htdocs/loan/schedule.php +++ b/htdocs/loan/schedule.php @@ -184,6 +184,7 @@ if ($object->nbterm > 0 && count($echeance->lines)==0) $mens = price2num($echeance->calcMonthlyPayments($capital, $object->rate/100, $object->nbterm-$i+1), 'MT'); $int = ($capital*($object->rate/12))/100; $int = price2num($int, 'MT'); + $insu = ($insurance+(($i == 1) ? $regulInsurance : 0)); $cap_rest = price2num($capital - ($mens-$int), 'MT'); print ''; print '' . $i .''; @@ -204,17 +205,19 @@ elseif(count($echeance->lines)>0) $insurance = $object->insurance_amount/$object->nbterm; $insurance = price2num($insurance, 'MT'); $regulInsurance = price2num($object->insurance_amount - ($insurance * $object->nbterm)); + $printed = false; foreach ($echeance->lines as $line){ $mens = $line->amount_capital+$line->amount_insurance+$line->amount_interest; $int = $line->amount_interest; - $cap_rest = price2num($capital - ($mens-$int), 'MT'); $insu = ($insurance+(($i == 1) ? $regulInsurance : 0)); + $cap_rest = price2num($capital - ($mens-$int-$insu), 'MT'); + print ''; print '' . $i .''; print '' . dol_print_date($line->datep,'day') . ''; print ''.price($insu,0,'',1).' €'; print ''.price($int,0,'',1).' €'; - if($line->datep > dol_now()){ + if($line->datep > dol_now() && empty($line->fk_bank)){ print ' €'; }else{ print '' . price($mens) . ' €'; @@ -222,7 +225,12 @@ elseif(count($echeance->lines)>0) print ''.price($cap_rest).' €'; print ''; - print ''.$langs->trans('DoPayment').''; + if (!empty($line->fk_bank)) print $langs->trans('Paid'); + elseif (!$printed) + { + print ''.$langs->trans('DoPayment').''; + $printed = true; + } print ''; print ''."\n"; $i++;