From 6a3661586ffdf9d6b3aa7b7d1ff471ea0d3b0644 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Fri, 19 Oct 2018 16:12:21 +0200 Subject: [PATCH] create payment for the last loanschedule --- htdocs/loan/card.php | 2 +- htdocs/loan/payment/payment.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 8fef98075b1..c8da0262f38 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -795,7 +795,7 @@ if ($id > 0) // Emit payment if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write) { - print ''.$langs->trans("DoPayment").''; + print ''.$langs->trans("DoPayment").''; } // Classify 'paid' diff --git a/htdocs/loan/payment/payment.php b/htdocs/loan/payment/payment.php index 2d81f95d034..b38a058126f 100644 --- a/htdocs/loan/payment/payment.php +++ b/htdocs/loan/payment/payment.php @@ -34,6 +34,7 @@ $chid=GETPOST('id','int'); $action=GETPOST('action','aZ09'); $cancel=GETPOST('cancel','alpha'); $line_id = GETPOST('line_id', 'int'); +$last=GETPOST('last'); // Security check $socid=0; @@ -45,6 +46,26 @@ if ($user->societe_id > 0) $loan = new Loan($db); $loan->fetch($chid); +if($last) +{ + $ls = new LoanSchedule($db); + // grab all loanschedule + $res = $ls->fetchAll($chid); + if ($res > 0) + { + foreach ($ls->lines as $l) + { + // get the last unpaid loanschedule + if (empty($l->fk_bank)) + { + $line_id = $l->id; + break; + } + } + } + +} + if (!empty($line_id)) { $line = new LoanSchedule($db);