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;
73if ($action ==
'createecheancier' && empty($pay_without_schedule)) {
76 while ($i < $object->nbterm + 1) {
84 $new_echeance->fk_loan =
$object->id;
85 $new_echeance->datec =
dol_now();
87 $new_echeance->datep = $date;
88 $new_echeance->amount_capital = $mens - (float) $int;
89 $new_echeance->amount_insurance = $insurance;
90 $new_echeance->amount_interest = $int;
91 $new_echeance->fk_typepayment = 3;
92 $new_echeance->fk_bank = 0;
93 $new_echeance->fk_user_creat = $user->id;
94 $new_echeance->fk_user_modif = $user->id;
95 $result = $new_echeance->create($user);
99 unset($echeances->lines);
102 $echeances->lines[] = $new_echeance;
110if ($action ==
'updateecheancier' && empty($pay_without_schedule)) {
113 while ($i < $object->nbterm + 1) {
120 $new_echeance->fetch($id);
121 $new_echeance->tms =
dol_now();
122 $new_echeance->amount_capital = $mens - (float) $int;
123 $new_echeance->amount_insurance = $insurance;
124 $new_echeance->amount_interest = $int;
125 $new_echeance->fk_user_modif = $user->id;
126 $result = $new_echeance->update($user, 0);
130 $echeances->fetchAll(
$object->id);
134 $echeances->lines[$i - 1] = $new_echeance;
145$form =
new Form($db);
148$title = $langs->trans(
"Loan").
' - '.$langs->trans(
"Card");
149$help_url =
'EN:Module_Loan|FR:Module_Emprunt';
151llxHeader(
"", $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-loan page-card_schedule');
154print
dol_get_fiche_head($head,
'FinancialCommitment', $langs->trans(
"Loan"), -1,
'money-bill-alt');
156$linkback =
'<a href="'.DOL_URL_ROOT.
'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
158$morehtmlref =
'<div class="refidno">';
160$morehtmlref .= $form->editfieldkey(
"Label",
'label',
$object->label, $object, 0,
'string',
'', 0, 1);
161$morehtmlref .= $form->editfieldval(
"Label",
'label',
$object->label, $object, 0,
'string',
'',
null,
null,
'', 1);
163if (isModEnabled(
'project')) {
164 $langs->loadLangs(array(
"projects"));
165 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' : ';
166 if ($user->hasRight(
'loan',
'write')) {
167 if ($action !=
'classify') {
169 if ($action ==
'classify') {
171 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'">';
172 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
173 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
174 $morehtmlref .= $formproject->select_projects(-1,
$object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
175 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
176 $morehtmlref .=
'</form>';
178 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id, -1,
$object->fk_project,
'none', 0, 0, 0, 1,
'',
'maxwidth300');
182 if (!empty(
$object->fk_project)) {
184 $proj->fetch(
$object->fk_project);
185 $morehtmlref .=
' : '.$proj->getNomUrl(1);
187 $morehtmlref .=
' - '.$proj->title;
194$morehtmlref .=
'</div>';
198dol_banner_tab($object,
'loanid', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlstatus);
201<script
type=
"text/javascript">
202$(document).ready(
function() {
203 $(
'[name^="mens"]').focusout(
function() {
204 var echeance=$(
this).attr(
'ech');
206 var idcap=echeance-1;
207 idcap =
'#hi_capital'+idcap;
209 console.log(
"Change monthly amount echeance="+echeance+
" idcap="+idcap+
" capital="+capital);
214 data: { echeance: echeance, mens: mens, capital:capital, rate:<?php echo
$object->rate / 100; ?>, nbterm: <?php echo
$object->nbterm; ?>, token:
'<?php echo currentToken(); ?>' },
215 success:
function(data) {
216 $.each(data,
function(index, element) {
217 var idcap_res=
'#hi_capital'+index;
218 var idcap_res_srt=
'#capital'+index;
219 var interet_res=
'#hi_interets'+index;
220 var interet_res_str=
'#interets'+index;
221 var men_res=
'#mens'+index;
222 $(idcap_res).val(element.cap_rest);
223 $(idcap_res_srt).text(element.cap_rest_str);
224 $(interet_res).val(element.interet);
225 $(interet_res_str).text(element.interet_str);
226 $(men_res).val(element.mens);
235if ($pay_without_schedule == 1) {
236 print
'<div class="warning">'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'</div>'.
"\n";
239print
'<form name="createecheancier" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
240print
'<input type="hidden" name="token" value="'.newToken().
'">';
241print
'<input type="hidden" name="loanid" value="'.$loanid.
'">';
242if (count($echeances->lines) > 0) {
243 print
'<input type="hidden" name="action" value="updateecheancier">';
245 print
'<input type="hidden" name="action" value="createecheancier">';
251print
'<div class="div-table-responsive-no-min">';
252print
'<table class="border centpercent">';
255if (count($echeances->lines) > 0) {
259print
'<tr class="liste_titre">';
260print
'<th class="center">'.$langs->trans(
"Term").
'</th>';
261print
'<th class="center">'.$langs->trans(
"Date").
'</th>';
262print
'<th class="center">'.$langs->trans(
"Insurance");
263print
'<th class="center">'.$langs->trans(
"InterestAmount").
'</th>';
264print
'<th class="center">'.$langs->trans(
"Amount").
'</th>';
265print
'<th class="center">'.$langs->trans(
"CapitalRemain");
266print
'<br>('.price(
$object->capital, 0,
'', 1, -1, -1, $conf->currency).
')';
267print
'<input type="hidden" name="hi_capital0" id ="hi_capital0" value="'.$object->capital.
'">';
269if (count($echeances->lines) > 0) {
270 print
'<th class="center">'.$langs->trans(
'DoPayment').
'</th>';
274if (
$object->nbterm > 0 && count($echeances->lines) == 0) {
278 $insurance =
price2num($insurance,
'MT');
280 while ($i < $object->nbterm + 1) {
281 $mens =
price2num($echeances->calcMonthlyPayments($capital,
$object->rate / 100,
$object->nbterm - $i + 1),
'MT');
282 $int = ($capital * (
$object->rate / 12)) / 100;
284 $insu = ((float) $insurance + (($i == 1) ? (float) $regulInsurance : 0));
285 $cap_rest =
price2num((
float) $capital - ((
float) $mens - (
float) $int),
'MT');
287 print
'<td class="center" id="n'.$i.
'">'.$i.
'</td>';
289 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.
'">';
290 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.
'">';
291 print
'<td class="center"><input class="width75 right" name="mens'.$i.
'" id="mens'.$i.
'" value="'.$mens.
'" ech="'.$i.
'"></td>';
292 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.
'">';
295 $capital = $cap_rest;
297} elseif (count($echeances->lines) > 0) {
301 $insurance =
price2num($insurance,
'MT');
304 foreach ($echeances->lines as $line) {
305 $mens = $line->amount_capital + $line->amount_interest;
306 $int = $line->amount_interest;
307 $insu = ((float) $insurance + (($i == 1) ? (float) $regulInsurance : 0));
308 $cap_rest =
price2num($capital - ($mens - $int),
'MT');
311 print
'<td class="center" id="n'.$i.
'"><input type="hidden" name="hi_rowid'.$i.
'" id ="hi_rowid'.$i.
'" value="'.$line->id.
'">'.$i.
'</td>';
312 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>';
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 if (empty($line->fk_bank)) {
316 print
'<td class="center"><input class="right width75" name="mens'.$i.
'" id="mens'.$i.
'" value="'.$mens.
'" ech="'.$i.
'"></td>';
318 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.
'">';
321 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.
'">';
322 print
'<td class="center">';
323 if (!empty($line->fk_bank)) {
324 print $langs->trans(
'Paid');
325 if (!empty($line->fk_payment_loan)) {
326 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>';
328 } elseif (!$printed) {
329 print
'<a class="butAction smallpaddingimp" href="'.DOL_URL_ROOT.
'/loan/payment/payment.php?id='.
$object->id.
'&action=create">'.$langs->trans(
'DoPayment').
'</a>';
335 $capital = $cap_rest;
344if (count($echeances->lines) == 0) {
345 $label = $langs->trans(
"Create");
347 $label = $langs->trans(
"Save");
349print
'<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)
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.
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.