29require
'../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/loan.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/loan/class/loanschedule.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
49$action =
GETPOST(
'action',
'aZ09');
53if (GETPOSTISSET(
'socid')) {
57 $socid = $user->socid;
59if (!$user->hasRight(
'loan',
'calc')) {
64$langs->loadLangs(array(
"compta",
"bills",
"loan"));
70$echeances->fetchAll(
$object->id);
72if (
$object->paid > 0 && count($echeances->lines) == 0) {
73 $pay_without_schedule = 1;
75 $pay_without_schedule = 0;
78$permissiontoadd = $user->hasRight(
'loan',
'write');
85if ($action ==
'createecheancier' && empty($pay_without_schedule) && $permissiontoadd) {
88 while ($i < $object->nbterm + 1) {
96 $new_echeance->fk_loan =
$object->id;
97 $new_echeance->datec =
dol_now();
99 $new_echeance->datep = $date;
100 $new_echeance->amount_capital = (float) $mens - (
float) $int;
101 $new_echeance->amount_insurance = $insurance;
102 $new_echeance->amount_interest = $int;
103 $new_echeance->fk_typepayment = 3;
104 $new_echeance->fk_bank = 0;
105 $new_echeance->fk_user_creat = $user->id;
106 $new_echeance->fk_user_modif = $user->id;
107 $result = $new_echeance->create($user);
111 $echeances->lines = [];
114 $echeances->lines[] = $new_echeance;
122if ($action ==
'updateecheancier' && empty($pay_without_schedule) && $permissiontoadd) {
125 while ($i < $object->nbterm + 1) {
132 $new_echeance->fetch(
$id);
133 $new_echeance->tms =
dol_now();
134 $new_echeance->amount_capital = (float) $mens - (
float) $int;
135 $new_echeance->amount_insurance = $insurance;
136 $new_echeance->amount_interest = $int;
137 $new_echeance->fk_user_modif = $user->id;
138 $result = $new_echeance->update($user, 0);
142 $echeances->fetchAll(
$object->id);
146 $echeances->lines[$i - 1] = $new_echeance;
159$form =
new Form($db);
162$title = $langs->trans(
"Loan").
' - '.$langs->trans(
"FinancialCommitment");
163$help_url =
'EN:Module_Loan|FR:Module_Emprunt';
165llxHeader(
"", $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-loan page-card_schedule');
168print
dol_get_fiche_head($head,
'FinancialCommitment', $langs->trans(
"Loan"), -1,
'money-bill-alt');
170$linkback =
'<a href="'.DOL_URL_ROOT.
'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
172$morehtmlref =
'<div class="refidno">';
174$morehtmlref .= $form->editfieldkey(
"Label",
'label',
$object->label, $object, 0,
'string',
'', 0, 1);
175$morehtmlref .= $form->editfieldval(
"Label",
'label',
$object->label, $object, 0,
'string',
'',
null,
null,
'', 1);
178 $langs->loadLangs(array(
"projects"));
179 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' : ';
180 if ($user->hasRight(
'loan',
'write')) {
181 if ($action !=
'classify') {
183 if ($action ==
'classify') {
185 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
186 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
187 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
188 $morehtmlref .= $formproject->select_projects(-1, (
string)
$object->fk_project,
'projectid', 16, 0, 1, 0, 1, 0, 0,
'', 1);
189 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
190 $morehtmlref .=
'</form>';
192 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, -1, (
string)
$object->fk_project,
'none', 0, 0, 0, 1,
'',
'maxwidth300');
196 if (!empty(
$object->fk_project)) {
198 $proj->fetch(
$object->fk_project);
199 $morehtmlref .=
' : '.$proj->getNomUrl(1);
201 $morehtmlref .=
' - '.$proj->title;
208$morehtmlref .=
'</div>';
212dol_banner_tab($object,
'loanid', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlstatus);
215<script
type=
"text/javascript">
216$(document).ready(
function() {
219 $(
'[name^="mens"]').keyup(
function() {
220 clearTimeout(timeout);
221 timeout = setTimeout(() => {
222 var echeance = $(
this).attr(
'ech');
223 var mens = $(
this).val();
224 calculateMens(echeance, mens);
227 function calculateMens(echeance, mens) {
228 var
table = $(
'[name^="mens"]');
229 var idcap = echeance-1;
230 idcap =
'#hi_capital'+idcap;
232 console.log(
"Change monthly amount echeance="+echeance+
" idcap="+idcap+
" capital="+capital);
241 rate: <?php echo
$object->rate / 100; ?>,
242 nbterm: <?php echo
$object->nbterm; ?>,
243 token:
'<?php echo currentToken(); ?>'
245 success:
function(data) {
246 $.each(data,
function(index, element) {
247 $(
'#hi_capital'+index).val(element.cap_rest);
248 $(
'#capital'+index).text(element.cap_rest_str);
249 $(
'#hi_interets'+index).val(element.interet);
250 $(
'#interets'+index).text(element.interet_str);
251 $(
'#mens'+index).val(element.mens);
260if ($pay_without_schedule == 1) {
261 print
'<div class="warning">'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'</div>'.
"\n";
264print
'<form name="createecheancier" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
265print
'<input type="hidden" name="token" value="'.newToken().
'">';
266print
'<input type="hidden" name="loanid" value="'.$loanid.
'">';
267if (count($echeances->lines) > 0) {
268 print
'<input type="hidden" name="action" value="updateecheancier">';
270 print
'<input type="hidden" name="action" value="createecheancier">';
275print
'<div class="div-table-responsive-no-min">';
276print
'<table class="border centpercent">';
279if (count($echeances->lines) > 0) {
283print
'<tr class="liste_titre">';
284print
'<th class="center">'.$langs->trans(
"Term").
'</th>';
285print
'<th class="center">'.$langs->trans(
"Date").
'</th>';
286print
'<th class="center">'.$langs->trans(
"Insurance");
287print
'<th class="center">'.$langs->trans(
"InterestAmount").
'</th>';
288print
'<th class="center">'.$langs->trans(
"Amount").
'</th>';
289print
'<th class="center">'.$langs->trans(
"CapitalRemain");
290print
'<br>('.price(
$object->capital, 0,
'', 1, -1, -1, $conf->currency).
')';
291print
'<input type="hidden" name="hi_capital0" id ="hi_capital0" value="'.$object->capital.
'">';
293if (count($echeances->lines) > 0) {
294 print
'<th class="center">'.$langs->trans(
'DoPayment').
'</th>';
298if (
$object->nbterm > 0 && count($echeances->lines) == 0) {
302 $insurance =
price2num($insurance,
'MT');
304 while ($i < $object->nbterm + 1) {
305 $mens =
price2num($echeances->calcMonthlyPayments($capital,
$object->rate / 100,
$object->nbterm - $i + 1),
'MT');
306 $int = ($capital * (
$object->rate / 12)) / 100;
308 $insu = ((float) $insurance + (($i == 1) ? (float) $regulInsurance : 0));
309 $cap_rest =
price2num((
float) $capital - ((
float) $mens - (
float) $int),
'MT');
311 print
'<td class="center" id="n'.$i.
'">'.$i.
'</td>';
313 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.
'">';
314 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.
'">';
315 print
'<td class="center"><input class="width75 right" name="mens'.$i.
'" id="mens'.$i.
'" value="'.
price($mens).
'" ech="'.$i.
'"></td>';
316 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.
'">';
319 $capital = $cap_rest;
321} elseif (count($echeances->lines) > 0) {
325 $insurance =
price2num($insurance,
'MT');
328 foreach ($echeances->lines as $line) {
329 $mens = $line->amount_capital + $line->amount_interest;
330 $int = $line->amount_interest;
331 $insu = ((float) $insurance + (($i == 1) ? (float) $regulInsurance : 0));
332 $cap_rest =
price2num($capital - ($mens - $int),
'MT');
335 print
'<td class="center" id="n'.$i.
'"><input type="hidden" name="hi_rowid'.$i.
'" id ="hi_rowid'.$i.
'" value="'.$line->id.
'">'.$i.
'</td>';
336 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>';
337 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.
'">';
338 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.
'">';
339 if (empty($line->fk_bank)) {
340 print
'<td class="center"><input class="right width75" name="mens'.$i.
'" id="mens'.$i.
'" value="'.
price($mens).
'" ech="'.$i.
'"></td>';
342 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.
'">';
345 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.
'">';
346 print
'<td class="center">';
347 if (!empty($line->fk_bank)) {
348 print $langs->trans(
'Paid');
349 if (!empty($line->fk_payment_loan)) {
350 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>';
352 } elseif (!$printed) {
353 print
'<a class="butAction smallpaddingimp" href="'.DOL_URL_ROOT.
'/loan/payment/payment.php?id='.
$object->id.
'&action=create">'.$langs->trans(
'DoPayment').
'</a>';
359 $capital = $cap_rest;
368if (count($echeances->lines) == 0) {
369 $label = $langs->trans(
"Create");
371 $label = $langs->trans(
"Save");
373print
'<div class="center"><input type="submit" class="button button-add" value="'.$label.
'" '.(($pay_without_schedule == 1) ?
'disabled title="'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'"' :
'').
'title=""></div>';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
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 Schedule of loans.
Class to manage projects.
price2numjs(amount)
Function similar to PHP price2num()
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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 '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
isModEnabled($module)
Is Dolibarr module enabled.
treeview li table
No Email.
loan_prepare_head($object)
Prepare array with list of tabs.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.