* 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 * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/loan/payment/payment.php * \ingroup Loan * \brief Page to add payment of a loan */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load("bills"); $langs->load("loan"); $chid=GETPOST('id','int'); $action=GETPOST('action'); $cancel=GETPOST('cancel','alpha'); // Security check $socid=0; if ($user->societe_id > 0) { $socid = $user->societe_id; } $loan = new Loan($db); $loan->fetch($chid); /* * Actions */ if ($action == 'add_payment') { $error=0; if ($cancel) { $loc = DOL_URL_ROOT.'/loan/card.php?id='.$chid; header("Location: ".$loc); exit; } $datepaid = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); if (! GETPOST('paymenttype', 'int') > 0) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")), 'errors'); $error++; } if ($datepaid == '') { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Date")), 'errors'); $error++; } if (! empty($conf->banque->enabled) && ! GETPOST('accountid', 'int') > 0) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit")), 'errors'); $error++; } if (! $error) { $paymentid = 0; $amount = GETPOST('amount_capital') + GETPOST('amount_insurance') + GETPOST('amount_interest'); if ($amount == 0) { setEventMessage($langs->trans('ErrorNoPaymentDefined'), 'errors'); $error++; } if (! $error) { $db->begin(); // Create a line of payments $payment = new PaymentLoan($db); $payment->chid = $chid; $payment->datepaid = $datepaid; $payment->label = $loan->label; $payment->amount_capital = GETPOST('amount_capital'); $payment->amount_insurance = GETPOST('amount_insurance'); $payment->amount_interest = GETPOST('amount_interest'); $payment->paymenttype = GETPOST('paymenttype'); $payment->num_payment = GETPOST('num_payment'); $payment->note_private = GETPOST('note_private'); $payment->note_public = GETPOST('note_public'); if (! $error) { $paymentid = $payment->create($user); if ($paymentid < 0) { setEventMessage($payment->error, 'errors'); $error++; } } if (! $error) { $result = $payment->addPaymentToBank($user, 'payment_loan', '(LoanPayment)', GETPOST('accountid', 'int'), '', ''); if (! $result > 0) { setEventMessage($payment->error, 'errors'); $error++; } } if (! $error) { $db->commit(); $loc = DOL_URL_ROOT.'/loan/card.php?id='.$chid; header('Location: '.$loc); exit; } else { $db->rollback(); } } } $_GET["action"]='create'; } /* * View */ llxHeader(); $form=new Form($db); // Form to create loan's payment if ($_GET["action"] == 'create') { $total = $loan->capital; print_fiche_titre($langs->trans("DoPayment")); print "
\n"; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '\n"; print '\n"; print ''; $sql = "SELECT SUM(amount_capital + amount_insurance + amount_interest) as total"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan"; $sql.= " WHERE fk_loan = ".$chid; $resql = $db->query($sql); if ($resql) { $obj=$db->fetch_object($resql); $sumpaid = $obj->total; $db->free(); } print ''; print ''; print ''; print '
'.$langs->trans("Loan").'
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("DateStart").''.dol_print_date($loan->datestart,'day')."
'.$langs->trans("Label").''.$loan->label."
'.$langs->trans("Amount").''.price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("AlreadyPaid").''.price($sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans("RemainderToPay").''.price($total-$sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'; print '
'; print ''; print ''; print ''; print ''; print '"; print ''; print '\n"; print ''; print ''; print ''; print ''; // Number print ''; print ''."\n"; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("Payment").'
'.$langs->trans("Date").''; $datepaid = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0; $form->select_date($datepayment, '', '', '', '', "add_payment", 1, 1); print "
'.$langs->trans("PaymentMode").''; $form->select_types_paiements(isset($_POST["paymenttype"])?$_POST["paymenttype"]:$loan->paymenttype, "paymenttype"); print "
'.$langs->trans('AccountToDebit').''; $form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$loan->accountid, "accountid", 0, '',1); // Show opend bank account list print '
'.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print '
'.$langs->trans("NotePrivate").'
'.$langs->trans("NotePublic").'
'; print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $var=True; print ""; if ($loan->datestart > 0) { print ''; } else { print ''; } print '"; print '"; print '"; print '"; print "\n"; print '
'.$langs->trans("DateDue").''.$langs->trans("Capital").''.$langs->trans("AlreadyPaid").''.$langs->trans("RemainderToPay").''.$langs->trans("Amount").'
'.dol_print_date($loan->datestart,'day').'!!!'.price($loan->capital)."'.price($sumpaid)."'.price($loan->capital - $sumpaid)."'; if ($sumpaid < $loan->capital) { print $langs->trans("Capital") .': '; } else { print '-'; } print '
'; if ($sumpaid < $loan->capital) { print $langs->trans("Insurance") .': '; } else { print '-'; } print '
'; if ($sumpaid < $loan->capital) { print $langs->trans("Interest") .': '; } else { print '-'; } print "
'; print '
'; print ''; print '   '; print ''; print '
'; print "
\n"; } $db->close(); llxFooter();