27 require
'../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/loan.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loanschedule.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/loan/class/paymentloan.class.php';
34 $loanid =
GETPOST(
'loanid',
'int');
35 $action =
GETPOST(
'action',
'aZ09');
40 $socid =
GETPOST(
'socid',
'int');
43 $socid = $user->socid;
45 if (empty($user->rights->loan->calc)) {
50 $langs->loadLangs(array(
"compta",
"bills",
"loan"));
52 $object =
new Loan($db);
53 $object->fetch($loanid);
56 $echeances->fetchAll($object->id);
58 if ($object->paid > 0 && count($echeances->lines) == 0) {
59 $pay_without_schedule = 1;
66 if ($action ==
'createecheancier' && empty($pay_without_schedule)) {
69 while ($i < $object->nbterm + 1) {
70 $date =
GETPOST(
'hi_date'.$i,
'int');
77 $new_echeance->fk_loan = $object->id;
78 $new_echeance->datec =
dol_now();
80 $new_echeance->datep = $date;
81 $new_echeance->amount_capital = $mens - $int;
82 $new_echeance->amount_insurance = $insurance;
83 $new_echeance->amount_interest = $int;
84 $new_echeance->fk_typepayment = 3;
85 $new_echeance->fk_bank = 0;
86 $new_echeance->fk_user_creat = $user->id;
87 $new_echeance->fk_user_modif = $user->id;
88 $result = $new_echeance->create($user);
92 unset($echeances->lines);
95 $echeances->lines[] = $new_echeance;
103 if ($action ==
'updateecheancier' && empty($pay_without_schedule)) {
106 while ($i < $object->nbterm + 1) {
113 $new_echeance->fetch($id);
114 $new_echeance->tms =
dol_now();
115 $new_echeance->amount_capital = $mens - $int;
116 $new_echeance->amount_insurance = $insurance;
117 $new_echeance->amount_interest = $int;
118 $new_echeance->fk_user_modif = $user->id;
119 $result = $new_echeance->update($user, 0);
123 $echeances->fetchAll($object->id);
127 $echeances->lines[$i - 1] = $new_echeance;
139 $title = $langs->trans(
"Loan").
' - '.$langs->trans(
"Card");
140 $help_url =
'EN:Module_Loan|FR:Module_Emprunt';
144 print
dol_get_fiche_head($head,
'FinancialCommitment', $langs->trans(
"Loan"), -1,
'bill');
146 $linkback =
'<a href="'.DOL_URL_ROOT.
'/loan/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
148 $morehtmlref =
'<div class="refidno">';
150 $morehtmlref .=
$form->editfieldkey(
"Label",
'label', $object->label, $object, 0,
'string',
'', 0, 1);
151 $morehtmlref .=
$form->editfieldval(
"Label",
'label', $object->label, $object, 0,
'string',
'',
null,
null,
'', 1);
153 if (!empty($conf->project->enabled)) {
154 $langs->loadLangs(array(
"projects"));
155 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' : ';
156 if ($user->rights->loan->write) {
157 if ($action !=
'classify') {
159 if ($action ==
'classify') {
161 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
162 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
163 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
164 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
165 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
166 $morehtmlref .=
'</form>';
168 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project,
'none', 0, 0, 0, 1);
172 if (!empty($object->fk_project)) {
174 $proj->fetch($object->fk_project);
175 $morehtmlref .=
' : '.$proj->getNomUrl(1);
177 $morehtmlref .=
' - '.$proj->title;
184 $morehtmlref .=
'</div>';
188 dol_banner_tab($object,
'loanid', $linkback, 1,
'rowid',
'ref', $morehtmlref,
'', 0,
'', $morehtmlright);
191 <script
type=
"text/javascript">
192 $(document).ready(
function() {
193 $(
'[name^="mens"]').focusout(
function() {
194 var echeance=$(
this).attr(
'ech');
196 var idcap=echeance-1;
197 idcap =
'#hi_capital'+idcap;
199 console.log(
"Change montly amount echeance="+echeance+
" idcap="+idcap+
" capital="+capital);
204 data: { echeance: echeance, mens: mens, capital:capital, rate:<?php echo $object->rate / 100; ?>, nbterm: <?php echo $object->nbterm; ?>, token:
'<?php echo currentToken(); ?>' },
205 success:
function(data) {
206 $.each(data,
function(index, element) {
207 var idcap_res=
'#hi_capital'+index;
208 var idcap_res_srt=
'#capital'+index;
209 var interet_res=
'#hi_interets'+index;
210 var interet_res_str=
'#interets'+index;
211 var men_res=
'#mens'+index;
212 $(idcap_res).val(element.cap_rest);
213 $(idcap_res_srt).text(element.cap_rest_str);
214 $(interet_res).val(element.interet);
215 $(interet_res_str).text(element.interet_str);
216 $(men_res).val(element.mens);
225 if ($pay_without_schedule == 1) {
226 print
'<div class="warning">'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'</div>'.
"\n";
229 print
'<form name="createecheancier" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
230 print
'<input type="hidden" name="token" value="'.newToken().
'">';
231 print
'<input type="hidden" name="loanid" value="'.$loanid.
'">';
232 if (count($echeances->lines) > 0) {
233 print
'<input type="hidden" name="action" value="updateecheancier">';
235 print
'<input type="hidden" name="action" value="createecheancier">';
241 print
'<div class="div-table-responsive-no-min">';
242 print
'<table class="border centpercent">';
245 if (count($echeances->lines) > 0) {
249 print
'<tr class="liste_titre">';
250 print
'<th class="center">'.$langs->trans(
"Term").
'</th>';
251 print
'<th class="center">'.$langs->trans(
"Date").
'</th>';
252 print
'<th class="center">'.$langs->trans(
"Insurance");
253 print
'<th class="center">'.$langs->trans(
"InterestAmount").
'</th>';
254 print
'<th class="center">'.$langs->trans(
"Amount").
'</th>';
255 print
'<th class="center">'.$langs->trans(
"CapitalRemain");
256 print
'<br>('.price($object->capital, 0,
'', 1, -1, -1, $conf->currency).
')';
257 print
'<input type="hidden" name="hi_capital0" id ="hi_capital0" value="'.$object->capital.
'">';
259 if (count($echeances->lines) > 0) {
260 print
'<th class="center">'.$langs->trans(
'DoPayment').
'</th>';
264 if ($object->nbterm > 0 && count($echeances->lines) == 0) {
266 $capital = $object->capital;
267 $insurance = $object->insurance_amount / $object->nbterm;
268 $insurance =
price2num($insurance,
'MT');
269 $regulInsurance =
price2num($object->insurance_amount - ($insurance * $object->nbterm));
270 while ($i < $object->nbterm + 1) {
271 $mens =
price2num($echeances->calcMonthlyPayments($capital, $object->rate / 100, $object->nbterm - $i + 1),
'MT');
272 $int = ($capital * ($object->rate / 12)) / 100;
274 $insu = ($insurance + (($i == 1) ? $regulInsurance : 0));
275 $cap_rest =
price2num($capital - ($mens - $int),
'MT');
277 print
'<td class="center" id="n'.$i.
'">'.$i.
'</td>';
278 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>';
279 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)).
'">';
280 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.
'">';
281 print
'<td class="center"><input class="width75 right" name="mens'.$i.
'" id="mens'.$i.
'" value="'.$mens.
'" ech="'.$i.
'"></td>';
282 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.
'">';
285 $capital = $cap_rest;
287 } elseif (count($echeances->lines) > 0) {
289 $capital = $object->capital;
290 $insurance = $object->insurance_amount / $object->nbterm;
291 $insurance =
price2num($insurance,
'MT');
292 $regulInsurance =
price2num($object->insurance_amount - ($insurance * $object->nbterm));
294 foreach ($echeances->lines as $line) {
295 $mens = $line->amount_capital + $line->amount_interest;
296 $int = $line->amount_interest;
297 $insu = ($insurance + (($i == 1) ? $regulInsurance : 0));
298 $cap_rest =
price2num($capital - ($mens - $int),
'MT');
301 print
'<td class="center" id="n'.$i.
'"><input type="hidden" name="hi_rowid'.$i.
'" id ="hi_rowid'.$i.
'" value="'.$line->id.
'">'.$i.
'</td>';
302 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>';
303 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.
'">';
304 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.
'">';
305 if (empty($line->fk_bank)) {
306 print
'<td class="center"><input class="right width75" name="mens'.$i.
'" id="mens'.$i.
'" value="'.$mens.
'" ech="'.$i.
'"></td>';
308 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.
'">';
311 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.
'">';
312 print
'<td class="center">';
313 if (!empty($line->fk_bank)) {
314 print $langs->trans(
'Paid');
315 if (!empty($line->fk_payment_loan)) {
316 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>';
318 } elseif (!$printed) {
319 print
'<a class="butAction smallpaddingimp" href="'.DOL_URL_ROOT.
'/loan/payment/payment.php?id='.$object->id.
'&action=create">'.$langs->trans(
'DoPayment').
'</a>';
325 $capital = $cap_rest;
334 if (count($echeances->lines) == 0) {
335 $label = $langs->trans(
"Create");
337 $label = $langs->trans(
"Save");
339 print
'<div class="center"><input type="submit" class="button button-add" value="'.$label.
'" '.(($pay_without_schedule == 1) ?
'disabled title="'.$langs->trans(
'CantUseScheduleWithLoanStartedToPaid').
'"' :
'').
'title=""></div>';
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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='')
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)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.