28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/loan/class/loanschedule.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/loan.lib.php';
43$langs->loadLangs(array(
"bills",
"loan"));
45$action =
GETPOST(
'action',
'aZ09');
46$confirm =
GETPOST(
'confirm',
'alpha');
47$cancel =
GETPOST(
'cancel',
'alpha');
54if ($user->socid > 0) {
55 $socid = $user->socid;
56} elseif (GETPOSTISSET(
'socid')) {
59if (!$user->hasRight(
'loan',
'write')) {
74$res = $ls->fetchAll($chid);
76 foreach ($ls->lines as $l) {
79 if (empty($l->fk_bank)) {
82 } elseif ($line_id == $l->id) {
90if (!empty($line_id)) {
92 $res = $line->fetch($line_id);
94 $amount_capital =
price($line->amount_capital);
95 $amount_insurance =
price($line->amount_insurance);
96 $amount_interest =
price($line->amount_interest);
97 if (empty($datepaid)) {
98 $ts_temppaid = $line->datep;
103$permissiontoadd = $user->hasRight(
'loan',
'write');
110if ($action ==
'add_payment' && $permissiontoadd) {
114 $loc = DOL_URL_ROOT.
'/loan/card.php?id='.$chid;
115 header(
"Location: ".$loc);
120 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode")),
null,
'errors');
123 if ($datepaid ==
'') {
124 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date")),
null,
'errors');
128 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AccountToCredit")),
null,
'errors');
139 $pay_amount_interest = $line->amount_interest;
144 $amount = (float)
price2num($pay_amount_capital + $pay_amount_insurance + $pay_amount_interest,
'MT');
147 if (!empty($line) && !empty($line->fk_bank)) {
152 if (empty($remaindertopay)) {
167 $payment->chid = $chid;
168 $payment->datep = $datepaid;
169 $payment->label = $loan->label;
170 $payment->amount_capital = $pay_amount_capital;
171 $payment->amount_insurance = $pay_amount_insurance;
172 $payment->amount_interest = $pay_amount_interest;
174 $payment->paymenttype =
GETPOSTINT(
'paymenttype');
175 $payment->num_payment =
GETPOST(
'num_payment',
'alphanohtml');
176 $payment->note_private =
GETPOST(
'note_private',
'restricthtml');
177 $payment->note_public =
GETPOST(
'note_public',
'restricthtml');
180 $paymentid = $payment->create($user);
181 if ($paymentid < 0) {
189 $result = $payment->addPaymentToBank($user, $chid,
'payment_loan',
'(LoanPayment)', $payment->fk_bank,
'',
'');
190 if (!($result > 0)) {
197 if (!$error && !empty($line)) {
199 if (($line->amount_capital != $pay_amount_capital) || ($line->amount_insurance != $pay_amount_insurance) || ($line->amount_interest != $pay_amount_interest)) {
200 $arr_term =
loanCalcMonthlyPayment(($pay_amount_capital + $pay_amount_interest), $remaindertopay, ($loan->rate / 100), $echance, (
int) $loan->nbterm);
201 foreach ($arr_term as $k => $v) {
203 if ($k == $echance) {
204 $ls->lines[$k - 1]->fk_bank = $payment->fk_bank;
205 $ls->lines[$k - 1]->fk_payment_loan = $payment->id;
207 $ls->lines[$k - 1]->amount_capital = ((float)
price2num($v[
'mens'])) - $v[
'interet'];
208 $ls->lines[$k - 1]->amount_interest = $v[
'interet'];
209 $ls->lines[$k - 1]->tms =
dol_now();
210 $ls->lines[$k - 1]->fk_user_modif = $user->id;
211 $result = $ls->lines[$k - 1]->update($user, 0);
219 $line->fk_bank = $payment->fk_bank;
220 $line->fk_payment_loan = $payment->id;
221 $result = $line->update($user, 0);
231 $loc = DOL_URL_ROOT.
'/loan/card.php?id='.$chid;
232 header(
'Location: '.$loc);
247$form =
new Form($db);
249$title = $langs->trans(
'Loans');
250$help_url =
"EN:Module_Loan|FR:Module_Emprunt";
252llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'bodyforlist mod-loan page-payment-list');
256if ($action ==
'create') {
257 $total = $loan->capital;
262 $sql =
"SELECT SUM(amount_capital) as total";
263 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan";
264 $sql .=
" WHERE fk_loan = ".((int) $chid);
265 $resql = $db->query($sql);
267 $obj = $db->fetch_object($resql);
268 $sumpaid = $obj->total;
272 print
'<form name="add_payment" action="'.$_SERVER[
'PHP_SELF'].
'" method="post">';
273 print
'<input type="hidden" name="token" value="'.newToken().
'">';
274 print
'<input type="hidden" name="id" value="'.$chid.
'">';
275 print
'<input type="hidden" name="chid" value="'.$chid.
'">';
276 print
'<input type="hidden" name="line_id" value="'.$line_id.
'">';
277 print
'<input type="hidden" name="remaindertopay" value="'.($total - $sumpaid).
'">';
278 print
'<input type="hidden" name="action" value="add_payment">';
301 print
'<table class="border centpercent">';
303 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"Date").
'</td><td colspan="2">';
304 if (empty($datepaid)) {
305 if (empty($ts_temppaid)) {
308 $datepayment = $ts_temppaid;
311 $datepayment = $datepaid;
313 print $form->selectDate($datepayment,
'', 0, 0, 0,
"add_payment", 1, 1);
317 print
'<tr><td class="fieldrequired">'.$langs->trans(
"PaymentMode").
'</td><td colspan="2">';
318 print
img_picto(
'',
'money-bill-alt',
'class="pictofixedwidth"');
319 $form->select_types_paiements(GETPOSTISSET(
"paymenttype") ?
GETPOST(
"paymenttype",
'alphanohtml') : $loan->fk_typepayment,
"paymenttype");
324 print
'<td class="fieldrequired">'.$langs->trans(
'AccountToDebit').
'</td>';
325 print
'<td colspan="2">';
326 print
img_picto(
'',
'bank_account',
'class="pictofixedwidth"');
327 $form->select_comptes(GETPOSTISSET(
"accountid") ?
GETPOSTINT(
"accountid") : $loan->accountid,
"accountid", 0,
'courant = '.
Account::TYPE_CURRENT, 1);
331 print
'<tr><td>'.$langs->trans(
'Numero');
332 print
' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
334 print
'<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST(
'num_payment',
'alphanohtml').
'"></td>'.
"\n";
338 print
'<td class="tdtop">'.$langs->trans(
"NotePrivate").
'</td>';
339 print
'<td valign="top" colspan="2"><textarea name="note_private" wrap="soft" cols="60" rows="'.ROWS_3.
'"></textarea></td>';
343 print
'<td class="tdtop">'.$langs->trans(
"NotePublic").
'</td>';
344 print
'<td valign="top" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.
'"></textarea></td>';
352 print
'<table class="noborder centpercent">';
353 print
'<tr class="liste_titre">';
354 print
'<td class="left">'.$langs->trans(
"DateDue").
'</td>';
355 print
'<td class="right">'.$langs->trans(
"LoanCapital").
'</td>';
356 print
'<td class="right">'.$langs->trans(
"AlreadyPaid").
'</td>';
357 print
'<td class="right">'.$langs->trans(
"RemainderToPay").
'</td>';
358 print
'<td class="right">'.$langs->trans(
"Amount").
'</td>';
361 print
'<tr class="oddeven">';
363 if ($loan->datestart > 0) {
364 print
'<td class="left" valign="center">'.dol_print_date($loan->datestart,
'day').
'</td>';
366 print
'<td class="center" valign="center"><b>!!!</b></td>';
369 print
'<td class="right" valign="center">'.price($loan->capital).
"</td>";
371 print
'<td class="right" valign="center">'.price($sumpaid).
"</td>";
373 print
'<td class="right" valign="center">'.price($loan->capital - $sumpaid).
"</td>";
375 print
'<td class="right">';
376 if ($sumpaid < $loan->capital) {
377 print $langs->trans(
"LoanCapital").
': <input type="text" size="8" name="amount_capital" value="'.(GETPOSTISSET(
'amount_capital') ?
GETPOST(
'amount_capital') : $amount_capital).
'">';
382 if ($sumpaid < $loan->capital) {
383 print $langs->trans(
"Insurance").
': <input type="text" size="8" name="amount_insurance" value="'.(GETPOSTISSET(
'amount_insurance') ?
GETPOST(
'amount_insurance') : $amount_insurance).
'">';
388 if ($sumpaid < $loan->capital) {
389 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').
'"' :
'').
'>';
399 print $form->buttonsSaveCancel();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage bank accounts.
Class to manage Schedule of loans.
Class to manage payments of loans.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.