26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loanschedule.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/loan.lib.php';
33 $langs->loadLangs(array(
"bills",
"loan"));
36 $action =
GETPOST(
'action',
'aZ09');
37 $cancel =
GETPOST(
'cancel',
'alpha');
43 $socid = $user->socid;
47 $loan = new
Loan($db);
53 $res = $ls->fetchAll($chid);
56 foreach ($ls->lines as $l)
60 if (empty($l->fk_bank))
66 elseif ($line_id == $l->id)
77 $res = $line->fetch($line_id);
79 $amount_capital =
price($line->amount_capital);
80 $amount_insurance =
price($line->amount_insurance);
81 $amount_interest =
price($line->amount_interest);
82 if (empty($datepaid)) $ts_temppaid = $line->datep;
91 if ($action ==
'add_payment')
97 $loc = DOL_URL_ROOT.
'/loan/card.php?id='.$chid;
98 header(
"Location: ".$loc);
102 if (!
GETPOST(
'paymenttype',
'int') > 0)
104 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode")), null,
'errors');
109 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Date")), null,
'errors');
112 if (!empty($conf->banque->enabled) && !
GETPOST(
'accountid',
'int') > 0)
114 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AccountToCredit")), null,
'errors');
125 if (!empty($line)) $pay_amount_interest = $line->amount_interest;
128 $amount = $pay_amount_capital + $pay_amount_insurance + $pay_amount_interest;
131 if (!empty($line) && !empty($line->fk_bank))
137 if (empty($remaindertopay))
155 $payment->chid = $chid;
156 $payment->datep = $datepaid;
157 $payment->label = $loan->label;
158 $payment->amount_capital = $pay_amount_capital;
159 $payment->amount_insurance = $pay_amount_insurance;
160 $payment->amount_interest = $pay_amount_interest;
161 $payment->fk_bank =
GETPOST(
'accountid',
'int');
162 $payment->paymenttype =
GETPOST(
'paymenttype',
'int');
163 $payment->num_payment =
GETPOST(
'num_payment');
164 $payment->note_private =
GETPOST(
'note_private',
'restricthtml');
165 $payment->note_public =
GETPOST(
'note_public',
'restricthtml');
169 $paymentid = $payment->create($user);
179 $result = $payment->addPaymentToBank($user, $chid,
'payment_loan',
'(LoanPayment)', $payment->fk_bank,
'',
'');
188 if (!$error && !empty($line))
191 if (($line->amount_capital <> $pay_amount_capital) || ($line->amount_insurance <> $pay_amount_insurance) || ($line->amount_interest <> $pay_amount_interest))
193 $arr_term =
loanCalcMonthlyPayment(($pay_amount_capital + $pay_amount_interest), $remaindertopay, ($loan->rate / 100), $echance, $loan->nbterm);
194 foreach ($arr_term as $k=>$v)
199 $ls->lines[$k - 1]->fk_bank = $payment->fk_bank;
200 $ls->lines[$k - 1]->fk_payment_loan = $payment->id;
202 $ls->lines[$k - 1]->amount_capital = $v[
'mens'] - $v[
'interet'];
203 $ls->lines[$k - 1]->amount_interest = $v[
'interet'];
204 $ls->lines[$k - 1]->tms =
dol_now();
205 $ls->lines[$k - 1]->fk_user_modif = $user->id;
206 $result = $ls->lines[$k - 1]->update($user, 0);
217 $line->fk_bank = $payment->fk_bank;
218 $line->fk_payment_loan = $payment->id;
219 $result = $line->update($user, 0);
231 $loc = DOL_URL_ROOT.
'/loan/card.php?id='.$chid;
232 header(
'Location: '.$loc);
250 $form =
new Form($db);
254 if ($action ==
'create')
256 $total = $loan->capital;
260 $sql =
"SELECT SUM(amount_capital) as total";
261 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan";
262 $sql .=
" WHERE fk_loan = ".$chid;
263 $resql = $db->query($sql);
266 $obj = $db->fetch_object(
$resql);
267 $sumpaid = $obj->total;
271 print '<form name="add_payment" action="'.$_SERVER[
'PHP_SELF'].
'" method="post">';
272 print '<input type="hidden" name="token" value="'.newToken().
'">';
273 print '<input type="hidden" name="id" value="'.$chid.
'">';
274 print '<input type="hidden" name="chid" value="'.$chid.
'">';
275 print '<input type="hidden" name="line_id" value="'.$line_id.
'">';
276 print '<input type="hidden" name="remaindertopay" value="'.($total - $sumpaid).
'">';
277 print '<input type="hidden" name="action" value="add_payment">';
300 print
'<table class="border centpercent">';
302 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"Date").
'</td><td colspan="2">';
303 if (empty($datepaid))
304 if (empty($ts_temppaid)) $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 :
dol_now();
305 else $datepayment = $ts_temppaid;
306 else $datepayment = $datepaid;
307 print $form->selectDate($datepayment,
'',
'',
'',
'',
"add_payment", 1, 1);
311 print
'<tr><td class="fieldrequired">'.$langs->trans(
"PaymentMode").
'</td><td colspan="2">';
312 $form->select_types_paiements(
GETPOSTISSET(
"paymenttype") ?
GETPOST(
"paymenttype",
'alphanohtml') : $loan->fk_typepayment,
"paymenttype");
317 print
'<td class="fieldrequired">'.$langs->trans(
'AccountToDebit').
'</td>';
318 print
'<td colspan="2">';
319 $form->select_comptes(
GETPOSTISSET(
"accountid") ?
GETPOST(
"accountid",
'int') : $loan->accountid,
"accountid", 0,
'courant = '.Account::TYPE_CURRENT, 1);
323 print
'<tr><td>'.$langs->trans(
'Numero');
324 print
' <em>('.$langs->trans(
"ChequeOrTransferNumber").
')</em>';
326 print
'<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST(
'num_payment',
'alphanohtml').
'"></td>'.
"\n";
330 print
'<td class="tdtop">'.$langs->trans(
"NotePrivate").
'</td>';
331 print
'<td valign="top" colspan="2"><textarea name="note_private" wrap="soft" cols="60" rows="'.ROWS_3.
'"></textarea></td>';
335 print
'<td class="tdtop">'.$langs->trans(
"NotePublic").
'</td>';
336 print
'<td valign="top" colspan="2"><textarea name="note_public" wrap="soft" cols="60" rows="'.ROWS_3.
'"></textarea></td>';
344 print
'<table class="noborder centpercent">';
345 print
'<tr class="liste_titre">';
346 print
'<td class="left">'.$langs->trans(
"DateDue").
'</td>';
347 print
'<td class="right">'.$langs->trans(
"LoanCapital").
'</td>';
348 print
'<td class="right">'.$langs->trans(
"AlreadyPaid").
'</td>';
349 print
'<td class="right">'.$langs->trans(
"RemainderToPay").
'</td>';
350 print
'<td class="right">'.$langs->trans(
"Amount").
'</td>';
353 print
'<tr class="oddeven">';
355 if ($loan->datestart > 0)
357 print
'<td class="left" valign="center">'.dol_print_date($loan->datestart,
'day').
'</td>';
359 print
'<td class="center" valign="center"><b>!!!</b></td>';
362 print
'<td class="right" valign="center">'.price($loan->capital).
"</td>";
364 print
'<td class="right" valign="center">'.price($sumpaid).
"</td>";
366 print
'<td class="right" valign="center">'.price($loan->capital - $sumpaid).
"</td>";
368 print
'<td class="right">';
369 if ($sumpaid < $loan->capital)
371 print $langs->trans(
"LoanCapital").
': <input type="text" size="8" name="amount_capital" value="'.(
GETPOSTISSET(
'amount_capital') ?
GETPOST(
'amount_capital') : $amount_capital).
'">';
377 if ($sumpaid < $loan->capital)
379 print $langs->trans(
"Insurance").
': <input type="text" size="8" name="amount_insurance" value="'.(
GETPOSTISSET(
'amount_insurance') ?
GETPOST(
'amount_insurance') : $amount_insurance).
'">';
385 if ($sumpaid < $loan->capital)
387 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').
'"' :
'').
'>';
398 print
'<br><div class="center">';
399 print
'<input type="submit" class="button button-save" name="save" value="'.$langs->trans(
"Save").
'">';
400 print
' ';
401 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
loanCalcMonthlyPayment($mens, $capital, $rate, $echance, $nbterm)
Calculate remaining loan mensuality and interests.
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...
dol_now($mode= 'auto')
Return date for now.
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...
Class to manage Schedule of loans.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
Class to manage payments of loans.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.