create payment for the last loanschedule

This commit is contained in:
atm-greg 2018-10-19 16:12:21 +02:00
parent 582608cc57
commit 6a3661586f
2 changed files with 22 additions and 1 deletions

View File

@ -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 '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&amp;action=create">'.$langs->trans("DoPayment").'</a>';
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&amp;action=create&last=true">'.$langs->trans("DoPayment").'</a>';
}
// Classify 'paid'

View File

@ -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);