28require
'../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/loan.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/loan/class/loanschedule.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
35if (isModEnabled(
'project')) {
36 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
40$action =
GETPOST(
'action',
'aZ09');
44if (GETPOSTISSET(
'socid')) {
48 $socid = $user->socid;
50if (!$user->hasRight(
'loan',
'calc')) {
55$langs->loadLangs(array(
"compta",
"bills",
"loan"));
61$echeances->fetchAll(
$object->id);
63if (
$object->paid > 0 && count($echeances->lines) == 0) {
64 $pay_without_schedule = 1;
66 $pay_without_schedule = 0;
69$permissiontoadd = $user->hasRight(
'loan',
'write');
76if ($action ==
'createecheancier' && empty($pay_without_schedule) && $permissiontoadd) {
79 while ($i < $object->nbterm + 1) {
87 $new_echeance->fk_loan =
$object->id;
88 $new_echeance->datec =
dol_now();
90 $new_echeance->datep = $date;
91 $new_echeance->amount_capital = (float) $mens - (
float) $int;
92 $new_echeance->amount_insurance = $insurance;
93 $new_echeance->amount_interest = $int;
94 $new_echeance->fk_typepayment = 3;
95 $new_echeance->fk_bank = 0;
96 $new_echeance->fk_user_creat = $user->id;
97 $new_echeance->fk_user_modif = $user->id;
98 $result = $new_echeance->create($user);
102 $echeances->lines = [];
105 $echeances->lines[] = $new_echeance;
113if ($action ==
'updateecheancier' && empty($pay_without_schedule) && $permissiontoadd) {
116 while ($i < $object->nbterm + 1) {
123 $new_echeance->fetch(
$id);
124 $new_echeance->tms =
dol_now();
125 $new_echeance->amount_capital = (float) $mens - (
float) $int;
126 $new_echeance->amount_insurance = $insurance;
127 $new_echeance->amount_interest = $int;
128 $new_echeance->fk_user_modif = $user->id;
129 $result = $new_echeance->update($user, 0);
133 $echeances->fetchAll(
$object->id);
137 $echeances->lines[$i - 1] = $new_echeance;
150$form =
new Form($db);
153$title = $langs->trans(
"Loan").
' - '.$langs->trans(
"Card");
154$help_url =
'EN:Module_Loan|FR:Module_Emprunt';
156llxHeader(
"", $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-loan page-card_schedule');
159print
dol_get_fiche_head($head,
'FinancialCommitment', $langs->trans(
"Loan"), -1,
'money-bill-alt');
161$linkback =
'<a href="'.DOL_URL_ROOT.
'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
163$morehtmlref =
'<div class="refidno">';
165$morehtmlref .= $form->editfieldkey(
"Label",
'label',
$object->label, $object, 0,
'string',
'', 0, 1);
166$morehtmlref .= $form->editfieldval(
"Label",
'label',
$object->label, $object, 0,
'string',
'',
null,
null,
'', 1);
168if (isModEnabled(
'project')) {
169 $langs->loadLangs(array(
"projects"));
170 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' : ';
171 if ($user->hasRight(
'loan',
'write')) {
172 if ($action !=
'classify') {
174 if ($action ==
'classify') {
176 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
177 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
178 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
179 $morehtmlref .= $formproject->select_projects(-1,
$object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
180 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
181 $morehtmlref .=
'</form>';
183 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, -1,
$object->fk_project,
'none', 0, 0, 0, 1,
'',
'maxwidth300');
187 if (!empty(
$object->fk_project)) {
189 $proj->fetch(
$object->fk_project);
190 $morehtmlref .=
' : '.$proj->getNomUrl(1);
192 $morehtmlref .=
' - '.$proj->title;
199$morehtmlref .=
'</div>';
203dol_banner_tab($object,
'loanid', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlstatus);
206<script
type=
"text/javascript">
207$(document).ready(
function() {
208 $(
'[name^="mens"]').focusout(
function() {
209 var echeance=$(
this).attr(
'ech');
211 var idcap=echeance-1;
212 idcap =
'#hi_capital'+idcap;
214 console.log(
"Change monthly amount echeance="+echeance+
" idcap="+idcap+
" capital="+capital);
219 data: { echeance: echeance, mens: mens, capital:capital, rate:<?php echo
$object->rate / 100; ?>, nbterm: <?php echo
$object->nbterm; ?>, token:
'<?php echo currentToken(); ?>' },
220 success:
function(data) {
221 $.each(data,
function(index, element) {
222 var idcap_res=
'#hi_capital'+index;
223 var idcap_res_srt=
'#capital'+index;
224 var interet_res=
'#hi_interets'+index;
225 var interet_res_str=
'#interets'+index;
226 var men_res=
'#mens'+index;
227 $(idcap_res).val(element.cap_rest);
228 $(idcap_res_srt).text(element.cap_rest_str);
229 $(interet_res).val(element.interet);
230 $(interet_res_str).text(element.interet_str);
231 $(men_res).val(element.mens);
240if ($pay_without_schedule == 1) {
241 print
'<div class="warning">'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'</div>'.
"\n";
244print
'<form name="createecheancier" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
245print
'<input type="hidden" name="token" value="'.newToken().
'">';
246print
'<input type="hidden" name="loanid" value="'.$loanid.
'">';
247if (count($echeances->lines) > 0) {
248 print
'<input type="hidden" name="action" value="updateecheancier">';
250 print
'<input type="hidden" name="action" value="createecheancier">';
256print
'<div class="div-table-responsive-no-min">';
257print
'<table class="border centpercent">';
260if (count($echeances->lines) > 0) {
264print
'<tr class="liste_titre">';
265print
'<th class="center">'.$langs->trans(
"Term").
'</th>';
266print
'<th class="center">'.$langs->trans(
"Date").
'</th>';
267print
'<th class="center">'.$langs->trans(
"Insurance");
268print
'<th class="center">'.$langs->trans(
"InterestAmount").
'</th>';
269print
'<th class="center">'.$langs->trans(
"Amount").
'</th>';
270print
'<th class="center">'.$langs->trans(
"CapitalRemain");
271print
'<br>('.price(
$object->capital, 0,
'', 1, -1, -1, $conf->currency).
')';
272print
'<input type="hidden" name="hi_capital0" id ="hi_capital0" value="'.$object->capital.
'">';
274if (count($echeances->lines) > 0) {
275 print
'<th class="center">'.$langs->trans(
'DoPayment').
'</th>';
279if (
$object->nbterm > 0 && count($echeances->lines) == 0) {
283 $insurance =
price2num($insurance,
'MT');
285 while ($i < $object->nbterm + 1) {
286 $mens =
price2num($echeances->calcMonthlyPayments($capital,
$object->rate / 100,
$object->nbterm - $i + 1),
'MT');
287 $int = ($capital * (
$object->rate / 12)) / 100;
289 $insu = ((float) $insurance + (($i == 1) ? (float) $regulInsurance : 0));
290 $cap_rest =
price2num((
float) $capital - ((
float) $mens - (
float) $int),
'MT');
292 print
'<td class="center" id="n'.$i.
'">'.$i.
'</td>';
294 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.
'">';
295 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.
'">';
296 print
'<td class="center"><input class="width75 right" name="mens'.$i.
'" id="mens'.$i.
'" value="'.$mens.
'" ech="'.$i.
'"></td>';
297 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.
'">';
300 $capital = $cap_rest;
302} elseif (count($echeances->lines) > 0) {
306 $insurance =
price2num($insurance,
'MT');
309 foreach ($echeances->lines as $line) {
310 $mens = $line->amount_capital + $line->amount_interest;
311 $int = $line->amount_interest;
312 $insu = ((float) $insurance + (($i == 1) ? (float) $regulInsurance : 0));
313 $cap_rest =
price2num($capital - ($mens - $int),
'MT');
316 print
'<td class="center" id="n'.$i.
'"><input type="hidden" name="hi_rowid'.$i.
'" id ="hi_rowid'.$i.
'" value="'.$line->id.
'">'.$i.
'</td>';
317 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>';
318 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.
'">';
319 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.
'">';
320 if (empty($line->fk_bank)) {
321 print
'<td class="center"><input class="right width75" name="mens'.$i.
'" id="mens'.$i.
'" value="'.$mens.
'" ech="'.$i.
'"></td>';
323 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.
'">';
326 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.
'">';
327 print
'<td class="center">';
328 if (!empty($line->fk_bank)) {
329 print $langs->trans(
'Paid');
330 if (!empty($line->fk_payment_loan)) {
331 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>';
333 } elseif (!$printed) {
334 print
'<a class="butAction smallpaddingimp" href="'.DOL_URL_ROOT.
'/loan/payment/payment.php?id='.
$object->id.
'&action=create">'.$langs->trans(
'DoPayment').
'</a>';
340 $capital = $cap_rest;
349if (count($echeances->lines) == 0) {
350 $label = $langs->trans(
"Create");
352 $label = $langs->trans(
"Save");
354print
'<div class="center"><input type="submit" class="button button-add" value="'.$label.
'" '.(($pay_without_schedule == 1) ?
'disabled title="'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'"' :
'').
'title=""></div>';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.