From f0849aaf81e42b2725dc1403008d108191ee0216 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 18 Oct 2018 17:16:38 +0200 Subject: [PATCH] schedule as a tab --- htdocs/core/lib/loan.lib.php | 5 + htdocs/loan/card.php | 2 +- htdocs/loan/schedule.php | 242 +++++++++++++++++++++++++++++++++++ 3 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 htdocs/loan/schedule.php diff --git a/htdocs/core/lib/loan.lib.php b/htdocs/core/lib/loan.lib.php index b61c57b4bc3..0b617bb0d5c 100644 --- a/htdocs/core/lib/loan.lib.php +++ b/htdocs/core/lib/loan.lib.php @@ -40,6 +40,11 @@ function loan_prepare_head($object) $head[$tab][1] = $langs->trans('Card'); $head[$tab][2] = 'card'; $tab++; + + $head[$tab][0] = DOL_URL_ROOT.'/loan/schedule.php?loanid='.$object->id; + $head[$tab][1] = $langs->trans('FinancialCommitment'); + $head[$tab][2] = 'FinancialCommitment'; + $tab++; // Show more tabs from modules // Entries must be declared in modules descriptor with line diff --git a/htdocs/loan/card.php b/htdocs/loan/card.php index 2a6708655a8..8fef98075b1 100644 --- a/htdocs/loan/card.php +++ b/htdocs/loan/card.php @@ -787,7 +787,7 @@ if ($id > 0) // Edit if ($object->paid == 0 && $user->rights->loan->write) { - print ''.$langs->trans('CreateCalcSchedule').''; + // print ''.$langs->trans('CreateCalcSchedule').''; print ''.$langs->trans("Modify").''; } diff --git a/htdocs/loan/schedule.php b/htdocs/loan/schedule.php new file mode 100644 index 00000000000..58130c2c26a --- /dev/null +++ b/htdocs/loan/schedule.php @@ -0,0 +1,242 @@ + + * Copyright (C) 2018 Alexandre Spangaro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/loan/createschedule.php + * \ingroup loan + * \brief Schedule card + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php'; + +$loanid = GETPOST('loanid', 'int'); +$action = GETPOST('action','aZ09'); + +$object = new Loan($db); +$object->fetch($loanid); + +// Load translation files required by the page +$langs->loadLangs(array("compta","bills","loan")); + +$title = $langs->trans("Loan") . ' - ' . $langs->trans("Card"); +$help_url = 'EN:Module_Loan|FR:Module_Emprunt'; +llxHeader("",$title,$help_url); + +$head=loan_prepare_head($object); +dol_fiche_head($head, 'FinancialCommitment', $langs->trans("Loan"), -1, 'bill'); + +if ($action == 'createecheancier') { + + $i=1; + while($i <$object->nbterm+1){ + + $date = GETPOST('hi_date'.$i,'int'); + $mens = GETPOST('mens'.$i); + $int = GETPOST('hi_interets'.$i); + $insurance = GETPOST('hi_insurance'.$i); + + $echeance = new LoanSchedule($db); + + $echeance->fk_loan = $object->id; + $echeance->datec = dol_now(); + $echeance->tms = dol_now(); + $echeance->datep = $date; + $echeance->amount_capital = $mens-$int; + $echeance->amount_insurance = $insurance; + $echeance->amount_interest = $int; + $echeance->fk_typepayment = 3; + $echeance->fk_bank = 0; + $echeance->fk_user_creat = $user->id; + $echeance->fk_user_modif = $user->id; + $result=$echeance->create($user); + if ($result<0) { + setEventMessages($echeance->error, $echeance->errors,'errors'); + } + $i++; + } +} + +if ($action == 'updateecheancier') { + + $i=1; + while($i <$object->nbterm+1){ + + $mens = GETPOST('mens'.$i); + $int = GETPOST('hi_interets'.$i); + $id = GETPOST('hi_rowid'.$i); + $insurance = GETPOST('hi_insurance'.$i); + + $echeance = new LoanSchedule($db); + $echeance->fetch($id); + $echeance->tms = dol_now(); + $echeance->amount_capital = $mens-$int; + $echeance->amount_insurance = $insurance; + $echeance->amount_interest = $int; + $echeance->fk_user_modif = $user->id; + $result= $echeance->update($user,0); + if ($result<0) { + setEventMessages(null, $echeance->errors,'errors'); + } + $i++; + } +} + +$echeance = new LoanSchedule($db); +$echeance->fetchAll($object->id); + +$var = ! $var; + + +?> + +'; +print ''; +print ''; +if(count($echeance->lines)>0) +{ + print ''; +}else{ + print ''; +} +print ''; +print ''; +$colspan = 6; +if (count($echeance->lines)>0) $colspan++; +print ''; +print ''; + +print ''; +Print ''; +Print ''; +print ''; +Print ''; +Print ''; +if (count($echeance->lines)>0) print ''; +print ''."\n"; + +if ($object->nbterm > 0 && count($echeance->lines)==0) +{ + $i=1; + $capital = $object->capital; + $insurance = $object->insurance_amount/$object->nbterm; + $insurance = price2num($insurance, 'MT'); + $regulInsurance = price2num($object->insurance_amount - ($insurance * $object->nbterm)); + while($i <$object->nbterm+1) + { + $mens = price2num($echeance->calcMonthlyPayments($capital, $object->rate/100, $object->nbterm-$i+1), 'MT'); + $int = ($capital*($object->rate/12))/100; + $int = price2num($int, 'MT'); + $cap_rest = price2num($capital - ($mens-$int), 'MT'); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''."\n"; + $i++; + $capital = $cap_rest; + } +} +elseif(count($echeance->lines)>0) +{ + $i=1; + $capital = $object->capital; + $insurance = $object->insurance_amount/$object->nbterm; + $insurance = price2num($insurance, 'MT'); + $regulInsurance = price2num($object->insurance_amount - ($insurance * $object->nbterm)); + foreach ($echeance->lines as $line){ + $mens = $line->amount_capital+$line->amount_insurance+$line->amount_interest; + $int = $line->amount_interest; + $cap_rest = price2num($capital - ($mens-$int), 'MT'); + print ''; + print ''; + print ''; + print ''; + print ''; + if($line->datep > dol_now()){ + print ''; + }else{ + print ''; + } + + print ''; + print ''; + print ''."\n"; + $i++; + $capital = $cap_rest; + } +} + +print '
'; +print $langs->trans("FinancialCommitment"); +print '
'.$langs->trans("Term").''.$langs->trans("Date").''.$langs->trans("Insurance"); +Print ''.$langs->trans("InterestAmount").''.$langs->trans("Amount").''.$langs->trans("CapitalRemain"); +print ' ('.price2num($object->capital).')'; +print ''; +print ''.$langs->trans('DoPayment').'
' . $i .'' . dol_print_date(dol_time_plus_duree($object->datestart, $i-1, 'm'),'day') . ''.price($insurance+(($i == 1) ? $regulInsurance : 0),0,'',1).' €'.price($int,0,'',1).' €'.price($cap_rest).' €
' . $i .'' . dol_print_date($line->datep,'day') . ''.price($insurance+(($i == 1) ? $regulInsurance : 0),0,'',1).' €'.price($int,0,'',1).' €' . price($mens) . ' €'.price($cap_rest).' €'; + print ''.$langs->trans('DoPayment').''; + print '
'; +print '
'; +print '
'; +if (count($echeance->lines)==0) $label = $langs->trans("Create"); +else $label = $langs->trans("Save"); +print '
'; +print ''; + +// End of page +llxFooter(); +$db->close();