27require
'../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/loan/class/loanschedule.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/loan.lib.php';
34$langs->loadLangs(array(
"bills",
"loan"));
37$action =
GETPOST(
'action',
'aZ09');
38$cancel =
GETPOST(
'cancel',
'alpha');
43if ($user->socid > 0) {
44 $socid = $user->socid;
45} elseif (GETPOSTISSET(
'socid')) {
46 $socid =
GETPOST(
'socid',
'int');
48if (empty($user->rights->loan->write)) {
58$res = $ls->fetchAll($chid);
60 foreach ($ls->lines as $l) {
63 if (empty($l->fk_bank)) {
66 } elseif ($line_id == $l->id) {
74if (!empty($line_id)) {
76 $res = $line->fetch($line_id);
78 $amount_capital =
price($line->amount_capital);
79 $amount_insurance =
price($line->amount_insurance);
80 $amount_interest =
price($line->amount_interest);
81 if (empty($datepaid)) {
82 $ts_temppaid = $line->datep;
92if ($action ==
'add_payment') {
96 $loc = DOL_URL_ROOT.
'/loan/card.php?id='.$chid;
97 header(
"Location: ".$loc);
101 if (!
GETPOST(
'paymenttype',
'int') > 0) {
102 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode")),
null,
'errors');
105 if ($datepaid ==
'') {
106 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date")),
null,
'errors');
109 if (isModEnabled(
"banque") && !
GETPOST(
'accountid',
'int') > 0) {
110 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AccountToCredit")),
null,
'errors');
121 $pay_amount_interest = $line->amount_interest;
126 $amount = (float)
price2num($pay_amount_capital + $pay_amount_insurance + $pay_amount_interest,
'MT');
129 if (!empty($line) && !empty($line->fk_bank)) {
134 if (empty($remaindertopay)) {
149 $payment->chid = $chid;
150 $payment->datep = $datepaid;
151 $payment->label = $loan->label;
152 $payment->amount_capital = $pay_amount_capital;
153 $payment->amount_insurance = $pay_amount_insurance;
154 $payment->amount_interest = $pay_amount_interest;
155 $payment->fk_bank =
GETPOST(
'accountid',
'int');
156 $payment->paymenttype =
GETPOST(
'paymenttype',
'int');
157 $payment->num_payment =
GETPOST(
'num_payment');
158 $payment->note_private =
GETPOST(
'note_private',
'restricthtml');
159 $payment->note_public =
GETPOST(
'note_public',
'restricthtml');
162 $paymentid = $payment->create($user);
163 if ($paymentid < 0) {
170 $result = $payment->addPaymentToBank($user, $chid,
'payment_loan',
'(LoanPayment)', $payment->fk_bank,
'',
'');
171 if (!($result > 0)) {
178 if (!$error && !empty($line)) {
180 if (($line->amount_capital <> $pay_amount_capital) || ($line->amount_insurance <> $pay_amount_insurance) || ($line->amount_interest <> $pay_amount_interest)) {
181 $arr_term =
loanCalcMonthlyPayment(($pay_amount_capital + $pay_amount_interest), $remaindertopay, ($loan->rate / 100), $echance, $loan->nbterm);
182 foreach ($arr_term as $k => $v) {
184 if ($k == $echance) {
185 $ls->lines[$k - 1]->fk_bank = $payment->fk_bank;
186 $ls->lines[$k - 1]->fk_payment_loan = $payment->id;
188 $ls->lines[$k - 1]->amount_capital = $v[
'mens'] - $v[
'interet'];
189 $ls->lines[$k - 1]->amount_interest = $v[
'interet'];
190 $ls->lines[$k - 1]->tms =
dol_now();
191 $ls->lines[$k - 1]->fk_user_modif = $user->id;
192 $result = $ls->lines[$k - 1]->update($user, 0);
201 $line->fk_bank = $payment->fk_bank;
202 $line->fk_payment_loan = $payment->id;
203 $result = $line->update($user, 0);
213 $loc = DOL_URL_ROOT.
'/loan/card.php?id='.$chid;
214 header(
'Location: '.$loc);
232$form =
new Form($db);
236if ($action ==
'create') {
237 $total = $loan->capital;
241 $sql =
"SELECT SUM(amount_capital) as total";
242 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan";
243 $sql .=
" WHERE fk_loan = ".((int) $chid);
244 $resql = $db->query($sql);
246 $obj = $db->fetch_object($resql);
247 $sumpaid = $obj->total;
251 print
'<form name="add_payment" action="'.$_SERVER[
'PHP_SELF'].
'" method="post">';
252 print
'<input type="hidden" name="token" value="'.newToken().
'">';
253 print
'<input type="hidden" name="id" value="'.$chid.
'">';
254 print
'<input type="hidden" name="chid" value="'.$chid.
'">';
255 print
'<input type="hidden" name="line_id" value="'.$line_id.
'">';
256 print
'<input type="hidden" name="remaindertopay" value="'.($total - $sumpaid).
'">';
257 print
'<input type="hidden" name="action" value="add_payment">';
280 print
'<table class="border centpercent">';
282 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"Date").
'</td><td colspan="2">';
283 if (empty($datepaid)) {
284 if (empty($ts_temppaid)) {
285 $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
dol_now();
287 $datepayment = $ts_temppaid;
290 $datepayment = $datepaid;
292 print $form->selectDate($datepayment,
'',
'',
'',
'',
"add_payment", 1, 1);
296 print
'<tr><td class="fieldrequired">'.$langs->trans(
"PaymentMode").
'</td><td colspan="2">';
297 print
img_picto(
'',
'money-bill-alt',
'class="pictofixedwidth"');
298 $form->select_types_paiements(GETPOSTISSET(
"paymenttype") ?
GETPOST(
"paymenttype",
'alphanohtml') : $loan->fk_typepayment,
"paymenttype");
303 print
'<td class="fieldrequired">'.$langs->trans(
'AccountToDebit').
'</td>';
304 print
'<td colspan="2">';
305 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
306 $form->select_comptes(GETPOSTISSET(
"accountid") ?
GETPOST(
"accountid",
'int') : $loan->accountid,
"accountid", 0,
'courant = '.
Account::TYPE_CURRENT, 1);
310 print
'<tr><td>'.$langs->trans(
'Numero');
311 print
' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
313 print
'<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST(
'num_payment',
'alphanohtml').
'"></td>'.
"\n";
317 print
'<td class="tdtop">'.$langs->trans(
"NotePrivate").
'</td>';
318 print
'<td valign="top" colspan="2"><textarea name="note_private" wrap="soft" cols="60" rows="'.ROWS_3.
'"></textarea></td>';
322 print
'<td class="tdtop">'.$langs->trans(
"NotePublic").
'</td>';
323 print
'<td valign="top" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.
'"></textarea></td>';
331 print
'<table class="noborder centpercent">';
332 print
'<tr class="liste_titre">';
333 print
'<td class="left">'.$langs->trans(
"DateDue").
'</td>';
334 print
'<td class="right">'.$langs->trans(
"LoanCapital").
'</td>';
335 print
'<td class="right">'.$langs->trans(
"AlreadyPaid").
'</td>';
336 print
'<td class="right">'.$langs->trans(
"RemainderToPay").
'</td>';
337 print
'<td class="right">'.$langs->trans(
"Amount").
'</td>';
340 print
'<tr class="oddeven">';
342 if ($loan->datestart > 0) {
343 print
'<td class="left" valign="center">'.dol_print_date($loan->datestart,
'day').
'</td>';
345 print
'<td class="center" valign="center"><b>!!!</b></td>';
348 print
'<td class="right" valign="center">'.price($loan->capital).
"</td>";
350 print
'<td class="right" valign="center">'.price($sumpaid).
"</td>";
352 print
'<td class="right" valign="center">'.price($loan->capital - $sumpaid).
"</td>";
354 print
'<td class="right">';
355 if ($sumpaid < $loan->capital) {
356 print $langs->trans(
"LoanCapital").
': <input type="text" size="8" name="amount_capital" value="'.(GETPOSTISSET(
'amount_capital') ?
GETPOST(
'amount_capital') : $amount_capital).
'">';
361 if ($sumpaid < $loan->capital) {
362 print $langs->trans(
"Insurance").
': <input type="text" size="8" name="amount_insurance" value="'.(GETPOSTISSET(
'amount_insurance') ?
GETPOST(
'amount_insurance') : $amount_insurance).
'">';
367 if ($sumpaid < $loan->capital) {
368 print $langs->trans(
"Interest").
': <input type="text" size="8" name="amount_interest" value="'.(GETPOSTISSET(
'amount_interest') ?
GETPOST(
'amount_interest') : $amount_interest).
'" '.(!empty($line) ?
'disabled title="'.$langs->trans(
'CantModifyInterestIfScheduleIsUsed').
'"' :
'').
'>';
378 print $form->buttonsSaveCancel();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage bank accounts.
Class to manage Schedule of loans.
Class to manage payments of loans.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
loanCalcMonthlyPayment($mens, $capital, $rate, $numactualloadterm, $nbterm)
Calculate remaining loan mensuality and interests.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.