26 require
'../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/loan.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loanschedule.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
33 $loanid =
GETPOST(
'loanid',
'int');
34 $action =
GETPOST(
'action',
'aZ09');
39 if ($user->socid) $socid = $user->socid;
43 $langs->loadLangs(array(
"compta",
"bills",
"loan"));
45 $object =
new Loan($db);
46 $object->fetch($loanid);
49 $echeances->fetchAll($object->id);
51 if ($object->paid > 0 && count($echeances->lines) == 0) {
52 $pay_without_schedule = 1;
59 if ($action ==
'createecheancier' && empty($pay_without_schedule)) {
62 while ($i < $object->nbterm + 1) {
63 $date =
GETPOST(
'hi_date'.$i,
'int');
70 $new_echeance->fk_loan = $object->id;
71 $new_echeance->datec =
dol_now();
73 $new_echeance->datep = $date;
74 $new_echeance->amount_capital = $mens - $int;
75 $new_echeance->amount_insurance = $insurance;
76 $new_echeance->amount_interest = $int;
77 $new_echeance->fk_typepayment = 3;
78 $new_echeance->fk_bank = 0;
79 $new_echeance->fk_user_creat = $user->id;
80 $new_echeance->fk_user_modif = $user->id;
81 $result = $new_echeance->create($user);
85 unset($echeances->lines);
88 $echeances->lines[] = $new_echeance;
96 if ($action ==
'updateecheancier' && empty($pay_without_schedule)) {
99 while ($i < $object->nbterm + 1) {
106 $new_echeance->fetch($id);
107 $new_echeance->tms =
dol_now();
108 $new_echeance->amount_capital = $mens - $int;
109 $new_echeance->amount_insurance = $insurance;
110 $new_echeance->amount_interest = $int;
111 $new_echeance->fk_user_modif = $user->id;
112 $result = $new_echeance->update($user, 0);
116 $echeances->fetchAll($object->id);
120 $echeances->lines[$i - 1] = $new_echeance;
123 if ($result > 0) $db->commit();
130 $title = $langs->trans(
"Loan").
' - '.$langs->trans(
"Card");
131 $help_url =
'EN:Module_Loan|FR:Module_Emprunt';
137 $linkback =
'<a href="'.DOL_URL_ROOT.
'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
139 $morehtmlref =
'<div class="refidno">';
141 $morehtmlref .= $form->editfieldkey(
"Label",
'label', $object->label, $object, 0,
'string',
'', 0, 1);
142 $morehtmlref .= $form->editfieldval(
"Label",
'label', $object->label, $object, 0,
'string',
'', null, null,
'', 1);
144 if (!empty($conf->projet->enabled))
146 $langs->loadLangs(array(
"projects"));
147 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' : ';
148 if ($user->rights->loan->write)
150 if ($action !=
'classify')
152 if ($action ==
'classify') {
154 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
155 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
156 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
157 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
158 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
159 $morehtmlref .=
'</form>';
161 $morehtmlref .= $form->form_project(
$_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
164 if (!empty($object->fk_project)) {
166 $proj->fetch($object->fk_project);
167 $morehtmlref .=
'<a href="'.DOL_URL_ROOT.
'/projet/card.php?id='.$object->fk_project.
'" title="'.$langs->trans(
'ShowProject').
'">';
168 $morehtmlref .= $proj->ref;
169 $morehtmlref .=
'</a>';
175 $morehtmlref .=
'</div>';
179 dol_banner_tab($object,
'loanid', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlright);
182 <script
type=
"text/javascript" language=
"javascript">
183 $(document).ready(
function() {
184 $(
'[name^="mens"]').focusout(
function() {
185 var echeance=$(
this).attr(
'ech');
187 var idcap=echeance-1;
188 idcap =
'#hi_capital'+idcap;
190 console.log(
"Change montly amount echeance="+echeance+
" idcap="+idcap+
" capital="+capital);
194 data: { echeance: echeance, mens: mens, capital:capital, rate:<?php echo $object->rate / 100; ?> , nbterm : <?php echo $object->nbterm; ?>},
195 success:
function(data) {
196 $.each(data,
function(index, element) {
197 var idcap_res=
'#hi_capital'+index;
198 var idcap_res_srt=
'#capital'+index;
199 var interet_res=
'#hi_interets'+index;
200 var interet_res_str=
'#interets'+index;
201 var men_res=
'#mens'+index;
202 $(idcap_res).val(element.cap_rest);
203 $(idcap_res_srt).text(element.cap_rest_str);
204 $(interet_res).val(element.interet);
205 $(interet_res_str).text(element.interet_str);
206 $(men_res).val(element.mens);
215 if ($pay_without_schedule == 1)
216 print '<div class="warning">'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'</div>'.
"\n";
218 print '<form name="createecheancier" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
219 print '<input type="hidden" name="token" value="'.newToken().
'">';
220 print '<input type="hidden" name="loanid" value="'.$loanid.
'">';
221 if (count($echeances->lines) > 0)
223 print '<input type="hidden" name="action" value="updateecheancier">';
225 print '<input type="hidden" name="action" value="createecheancier">';
228 print '<div class="div-table-responsive-no-min">';
229 print '<table class="border centpercent">';
230 print '<tr class="liste_titre">';
232 if (count($echeances->lines) > 0) $colspan++;
233 print '<th class="center" colspan="'.$colspan.
'">';
234 print $langs->trans(
"FinancialCommitment");
238 print '<tr class="liste_titre">';
239 print '<th class="center">'.$langs->trans(
"Term").
'</th>';
240 print '<th class="center">'.$langs->trans(
"Date").
'</th>';
241 print '<th class="center">'.$langs->trans(
"Insurance");
242 print '<th class="center">'.$langs->trans(
"InterestAmount").
'</th>';
243 print '<th class="center">'.$langs->trans(
"Amount").
'</th>';
244 print '<th class="center">'.$langs->trans(
"CapitalRemain");
245 print '<br>('.price($object->capital, 0,
'', 1, -1, -1, $conf->currency).
')';
246 print '<input type="hidden" name="hi_capital0" id ="hi_capital0" value="'.$object->capital.
'">';
248 if (count($echeances->lines) > 0)
print '<th class="center">'.$langs->trans(
'DoPayment').
'</th>';
251 if ($object->nbterm > 0 && count($echeances->lines) == 0)
254 $capital = $object->capital;
255 $insurance = $object->insurance_amount / $object->nbterm;
256 $insurance =
price2num($insurance,
'MT');
257 $regulInsurance =
price2num($object->insurance_amount - ($insurance * $object->nbterm));
258 while ($i < $object->nbterm + 1)
260 $mens =
price2num($echeances->calcMonthlyPayments($capital, $object->rate / 100, $object->nbterm - $i + 1),
'MT');
261 $int = ($capital * ($object->rate / 12)) / 100;
263 $insu = ($insurance + (($i == 1) ? $regulInsurance : 0));
264 $cap_rest =
price2num($capital - ($mens - $int),
'MT');
266 print '<td class="center" id="n'.$i.
'">'.$i.
'</td>';
268 print '<td class="center" 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)).
'">';
269 print '<td class="center" 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.
'">';
270 print '<td class="center"><input name="mens'.$i.
'" id="mens'.$i.
'" size="5" value="'.$mens.
'" ech="'.$i.
'"></td>';
271 print '<td class="center" id="capital'.$i.
'">'.
price($cap_rest).
'</td><input type="hidden" name="hi_capital'.$i.
'" id ="hi_capital'.$i.
'" value="'.$cap_rest.
'">';
274 $capital = $cap_rest;
276 } elseif (count($echeances->lines) > 0)
279 $capital = $object->capital;
280 $insurance = $object->insurance_amount / $object->nbterm;
281 $insurance =
price2num($insurance,
'MT');
282 $regulInsurance =
price2num($object->insurance_amount - ($insurance * $object->nbterm));
284 foreach ($echeances->lines as $line) {
285 $mens = $line->amount_capital + $line->amount_interest;
286 $int = $line->amount_interest;
287 $insu = ($insurance + (($i == 1) ? $regulInsurance : 0));
288 $cap_rest =
price2num($capital - ($mens - $int),
'MT');
291 print '<td class="center" id="n'.$i.
'"><input type="hidden" name="hi_rowid'.$i.
'" id ="hi_rowid'.$i.
'" value="'.$line->id.
'">'.$i.
'</td>';
292 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>';
293 print '<td class="center" 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.
'">';
294 print '<td class="center" 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.
'">';
295 if (empty($line->fk_bank)) {
296 print '<td class="center"><input name="mens'.$i.
'" id="mens'.$i.
'" size="5" value="'.$mens.
'" ech="'.$i.
'"></td>';
298 print '<td class="center">'.price($mens, 0,
'', 1, -1, -1, $conf->currency).
'</td><input type="hidden" name="mens'.$i.
'" id ="mens'.$i.
'" value="'.$mens.
'">';
301 print '<td class="center" 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.
'">';
302 print '<td class="center">';
303 if (!empty($line->fk_bank))
305 print $langs->trans(
'Paid');
306 if (!empty($line->fk_payment_loan))
307 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>';
311 print '<a class="butAction" href="'.DOL_URL_ROOT.
'/loan/payment/payment.php?id='.$object->id.
'&action=create">'.$langs->trans(
'DoPayment').
'</a>';
317 $capital = $cap_rest;
326 if (count($echeances->lines) == 0) $label = $langs->trans(
"Create");
327 else $label = $langs->trans(
"Save");
328 print '<div class="center"><input class="button" type="submit" value="'.$label.
'" '.(($pay_without_schedule == 1) ?
'disabled title="'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'"' :
'').
'title=""></div>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
loan_prepare_head($object)
Prepare array with list of tabs.
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.
price2numjs(amount)
Function similar to PHP price2num()
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage projects.
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)
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
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.
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_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_time_plus_duree($time, $duration_value, $duration_unit)
Add a delay to a date.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type