27require
'../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/loan.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/loan/class/loanschedule.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
34$loanid =
GETPOST(
'loanid',
'int');
35$action =
GETPOST(
'action',
'aZ09');
39if (GETPOSTISSET(
'socid')) {
40 $socid =
GETPOST(
'socid',
'int');
43 $socid = $user->socid;
45if (!$user->hasRight(
'loan',
'calc')) {
50$langs->loadLangs(array(
"compta",
"bills",
"loan"));
52$object =
new Loan($db);
53$object->fetch($loanid);
56$echeances->fetchAll($object->id);
58if ($object->paid > 0 && count($echeances->lines) == 0) {
59 $pay_without_schedule = 1;
61 $pay_without_schedule = 0;
68if ($action ==
'createecheancier' && empty($pay_without_schedule)) {
71 while ($i < $object->nbterm + 1) {
72 $date =
GETPOST(
'hi_date'.$i,
'int');
79 $new_echeance->fk_loan = $object->id;
80 $new_echeance->datec =
dol_now();
82 $new_echeance->datep = $date;
83 $new_echeance->amount_capital = $mens - $int;
84 $new_echeance->amount_insurance = $insurance;
85 $new_echeance->amount_interest = $int;
86 $new_echeance->fk_typepayment = 3;
87 $new_echeance->fk_bank = 0;
88 $new_echeance->fk_user_creat = $user->id;
89 $new_echeance->fk_user_modif = $user->id;
90 $result = $new_echeance->create($user);
94 $echeances->lines = [];
97 $echeances->lines[] = $new_echeance;
105if ($action ==
'updateecheancier' && empty($pay_without_schedule)) {
108 while ($i < $object->nbterm + 1) {
115 $new_echeance->fetch($id);
116 $new_echeance->tms =
dol_now();
117 $new_echeance->amount_capital = $mens - $int;
118 $new_echeance->amount_insurance = $insurance;
119 $new_echeance->amount_interest = $int;
120 $new_echeance->fk_user_modif = $user->id;
121 $result = $new_echeance->update($user, 0);
125 $echeances->fetchAll($object->id);
129 $echeances->lines[$i - 1] = $new_echeance;
141$title = $langs->trans(
"Loan").
' - '.$langs->trans(
"Card");
142$help_url =
'EN:Module_Loan|FR:Module_Emprunt';
146print
dol_get_fiche_head($head,
'FinancialCommitment', $langs->trans(
"Loan"), -1,
'money-bill-alt');
148$linkback =
'<a href="'.DOL_URL_ROOT.
'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
150$morehtmlref =
'<div class="refidno">';
152$morehtmlref .= $form->editfieldkey(
"Label",
'label', $object->label, $object, 0,
'string',
'', 0, 1);
153$morehtmlref .= $form->editfieldval(
"Label",
'label', $object->label, $object, 0,
'string',
'',
null,
null,
'', 1);
155if (isModEnabled(
'project')) {
156 $langs->loadLangs(array(
"projects"));
157 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' : ';
158 if ($user->hasRight(
'loan',
'write')) {
159 if ($action !=
'classify') {
161 if ($action ==
'classify') {
163 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
164 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
165 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
166 $morehtmlref .= $formproject->select_projects(-1, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
167 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
168 $morehtmlref .=
'</form>';
170 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, -1, $object->fk_project,
'none', 0, 0, 0, 1,
'',
'maxwidth300');
174 if (!empty($object->fk_project)) {
176 $proj->fetch($object->fk_project);
177 $morehtmlref .=
' : '.$proj->getNomUrl(1);
179 $morehtmlref .=
' - '.$proj->title;
186$morehtmlref .=
'</div>';
190dol_banner_tab($object,
'loanid', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlright);
193<script
type=
"text/javascript">
194$(document).ready(
function() {
195 $(
'[name^="mens"]').focusout(
function() {
196 var echeance=$(
this).attr(
'ech');
198 var idcap=echeance-1;
199 idcap =
'#hi_capital'+idcap;
201 console.log(
"Change montly amount echeance="+echeance+
" idcap="+idcap+
" capital="+capital);
206 data: { echeance: echeance, mens: mens, capital:capital, rate:<?php echo $object->rate / 100; ?>, nbterm: <?php echo $object->nbterm; ?>, token:
'<?php echo currentToken(); ?>' },
207 success:
function(data) {
208 $.each(data,
function(index, element) {
209 var idcap_res=
'#hi_capital'+index;
210 var idcap_res_srt=
'#capital'+index;
211 var interet_res=
'#hi_interets'+index;
212 var interet_res_str=
'#interets'+index;
213 var men_res=
'#mens'+index;
214 $(idcap_res).val(element.cap_rest);
215 $(idcap_res_srt).text(element.cap_rest_str);
216 $(interet_res).val(element.interet);
217 $(interet_res_str).text(element.interet_str);
218 $(men_res).val(element.mens);
227if ($pay_without_schedule == 1) {
228 print
'<div class="warning">'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'</div>'.
"\n";
231print
'<form name="createecheancier" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
232print
'<input type="hidden" name="token" value="'.newToken().
'">';
233print
'<input type="hidden" name="loanid" value="'.$loanid.
'">';
234if (count($echeances->lines) > 0) {
235 print
'<input type="hidden" name="action" value="updateecheancier">';
237 print
'<input type="hidden" name="action" value="createecheancier">';
243print
'<div class="div-table-responsive-no-min">';
244print
'<table class="border centpercent">';
247if (count($echeances->lines) > 0) {
251print
'<tr class="liste_titre">';
252print
'<th class="center">'.$langs->trans(
"Term").
'</th>';
253print
'<th class="center">'.$langs->trans(
"Date").
'</th>';
254print
'<th class="center">'.$langs->trans(
"Insurance");
255print
'<th class="center">'.$langs->trans(
"InterestAmount").
'</th>';
256print
'<th class="center">'.$langs->trans(
"Amount").
'</th>';
257print
'<th class="center">'.$langs->trans(
"CapitalRemain");
258print
'<br>('.price($object->capital, 0,
'', 1, -1, -1, $conf->currency).
')';
259print
'<input type="hidden" name="hi_capital0" id ="hi_capital0" value="'.$object->capital.
'">';
261if (count($echeances->lines) > 0) {
262 print
'<th class="center">'.$langs->trans(
'DoPayment').
'</th>';
266if ($object->nbterm > 0 && count($echeances->lines) == 0) {
268 $capital = $object->capital;
269 $insurance = $object->insurance_amount / $object->nbterm;
270 $insurance =
price2num($insurance,
'MT');
271 $regulInsurance =
price2num($object->insurance_amount - ($insurance * $object->nbterm));
272 while ($i < $object->nbterm + 1) {
273 $mens =
price2num($echeances->calcMonthlyPayments($capital, $object->rate / 100, $object->nbterm - $i + 1),
'MT');
274 $int = ($capital * ($object->rate / 12)) / 100;
276 $insu = ($insurance + (($i == 1) ? $regulInsurance : 0));
277 $cap_rest =
price2num($capital - ($mens - $int),
'MT');
279 print
'<td class="center" id="n'.$i.
'">'.$i.
'</td>';
280 print
'<td class="center" id ="date'.$i.
'"><input type="hidden" name="hi_date'.$i.
'" id ="hi_date'.$i.
'" value="'.
dol_time_plus_duree($object->datestart, $i - 1,
'm').
'">'.
dol_print_date(
dol_time_plus_duree($object->datestart, $i - 1,
'm'),
'day').
'</td>';
281 print
'<td class="center amount" id="insurance'.$i.
'">'.
price($insurance + (($i == 1) ? $regulInsurance : 0), 0,
'', 1, -1, -1, $conf->currency).
'</td><input type="hidden" name="hi_insurance'.$i.
'" id ="hi_insurance'.$i.
'" value="'.($insurance + (($i == 1) ? $regulInsurance : 0)).
'">';
282 print
'<td class="center amount" id="interets'.$i.
'">'.
price($int, 0,
'', 1, -1, -1, $conf->currency).
'</td><input type="hidden" name="hi_interets'.$i.
'" id ="hi_interets'.$i.
'" value="'.$int.
'">';
283 print
'<td class="center"><input class="width75 right" name="mens'.$i.
'" id="mens'.$i.
'" value="'.$mens.
'" ech="'.$i.
'"></td>';
284 print
'<td class="center amount" id="capital'.$i.
'">'.
price($cap_rest).
'</td><input type="hidden" name="hi_capital'.$i.
'" id ="hi_capital'.$i.
'" value="'.$cap_rest.
'">';
287 $capital = $cap_rest;
289} elseif (count($echeances->lines) > 0) {
291 $capital = $object->capital;
292 $insurance = $object->insurance_amount / $object->nbterm;
293 $insurance =
price2num($insurance,
'MT');
294 $regulInsurance =
price2num($object->insurance_amount - ($insurance * $object->nbterm));
296 foreach ($echeances->lines as $line) {
297 $mens = $line->amount_capital + $line->amount_interest;
298 $int = $line->amount_interest;
299 $insu = ($insurance + (($i == 1) ? $regulInsurance : 0));
300 $cap_rest =
price2num($capital - ($mens - $int),
'MT');
303 print
'<td class="center" id="n'.$i.
'"><input type="hidden" name="hi_rowid'.$i.
'" id ="hi_rowid'.$i.
'" value="'.$line->id.
'">'.$i.
'</td>';
304 print
'<td class="center" id ="date'.$i.
'"><input type="hidden" name="hi_date'.$i.
'" id ="hi_date'.$i.
'" value="'.$line->datep.
'">'.
dol_print_date($line->datep,
'day').
'</td>';
305 print
'<td class="center amount" id="insurance'.$i.
'">'.
price($insu, 0,
'', 1, -1, -1, $conf->currency).
'</td><input type="hidden" name="hi_insurance'.$i.
'" id ="hi_insurance'.$i.
'" value="'.$insu.
'">';
306 print
'<td class="center amount" id="interets'.$i.
'">'.
price($int, 0,
'', 1, -1, -1, $conf->currency).
'</td><input type="hidden" name="hi_interets'.$i.
'" id ="hi_interets'.$i.
'" value="'.$int.
'">';
307 if (empty($line->fk_bank)) {
308 print
'<td class="center"><input class="right width75" name="mens'.$i.
'" id="mens'.$i.
'" value="'.$mens.
'" ech="'.$i.
'"></td>';
310 print
'<td class="center amount">'.price($mens, 0,
'', 1, -1, -1, $conf->currency).
'</td><input type="hidden" name="mens'.$i.
'" id ="mens'.$i.
'" value="'.$mens.
'">';
313 print
'<td class="center amount" id="capital'.$i.
'">'.
price($cap_rest, 0,
'', 1, -1, -1, $conf->currency).
'</td><input type="hidden" name="hi_capital'.$i.
'" id ="hi_capital'.$i.
'" value="'.$cap_rest.
'">';
314 print
'<td class="center">';
315 if (!empty($line->fk_bank)) {
316 print $langs->trans(
'Paid');
317 if (!empty($line->fk_payment_loan)) {
318 print
' <a href="'.DOL_URL_ROOT.
'/loan/payment/card.php?id='.$line->fk_payment_loan.
'">('.
img_object($langs->trans(
"Payment"),
"payment").
' '.$line->fk_payment_loan.
')</a>';
320 } elseif (!$printed) {
321 print
'<a class="butAction smallpaddingimp" href="'.DOL_URL_ROOT.
'/loan/payment/payment.php?id='.$object->id.
'&action=create">'.$langs->trans(
'DoPayment').
'</a>';
327 $capital = $cap_rest;
336if (count($echeances->lines) == 0) {
337 $label = $langs->trans(
"Create");
339 $label = $langs->trans(
"Save");
341print
'<div class="center"><input type="submit" class="button button-add" value="'.$label.
'" '.(($pay_without_schedule == 1) ?
'disabled title="'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'"' :
'').
'title=""></div>';
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage Schedule of loans.
Class to manage projects.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
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 '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
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.
price2numjs(amount)
Function similar to PHP price2num()
loan_prepare_head($object)
Prepare array with list of tabs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.