Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into
develop Conflicts: htdocs/install/mysql/tables/llx_loan.sql
This commit is contained in:
commit
3765db422a
@ -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
|
||||
|
||||
@ -147,6 +147,7 @@ CREATE TABLE llx_takepos_floor_tables(
|
||||
|
||||
UPDATE llx_c_payment_term SET decalage = nbjour, nbjour = 0 where decalage IS NULL AND type_cdr = 2;
|
||||
|
||||
|
||||
UPDATE llx_holiday SET ref = rowid WHERE ref IS NULL;
|
||||
|
||||
|
||||
|
||||
@ -28,6 +28,8 @@ create table llx_loan
|
||||
fk_bank integer,
|
||||
|
||||
capital double(24,8) DEFAULT 0 NOT NULL,
|
||||
insurance_amount double(24,8) DEFAULT 0,
|
||||
|
||||
datestart date,
|
||||
dateend date,
|
||||
nbterm real,
|
||||
@ -38,7 +40,6 @@ create table llx_loan
|
||||
|
||||
capital_position double(24,8) DEFAULT 0, -- If not a new loan, just have the position of capital
|
||||
date_position date,
|
||||
insurance_amount double(24,8) DEFAULT 0,
|
||||
|
||||
paid smallint default 0 NOT NULL,
|
||||
|
||||
|
||||
@ -135,6 +135,7 @@ if (empty($reshook))
|
||||
$object->note_private = GETPOST('note_private','none');
|
||||
$object->note_public = GETPOST('note_public','none');
|
||||
$object->fk_project = GETPOST('projectid','int');
|
||||
$object->insurance_amount = GETPOST('insurance_amount', 'int');
|
||||
|
||||
$accountancy_account_capital = GETPOST('accountancy_account_capital');
|
||||
$accountancy_account_insurance = GETPOST('accountancy_account_insurance');
|
||||
@ -148,7 +149,7 @@ if (empty($reshook))
|
||||
if ($id <= 0)
|
||||
{
|
||||
$error++;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
setEventMessages($object->db->lastqueryerror, $object->errors, 'errors');
|
||||
$action = 'create';
|
||||
}
|
||||
}
|
||||
@ -301,6 +302,9 @@ if ($action == 'create')
|
||||
// Rate
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Rate").'</td><td><input name="rate" size="5" value="' . dol_escape_htmltag(GETPOST("rate")) . '"> %</td></tr>';
|
||||
|
||||
// insurance amount
|
||||
print '<tr><td>'.$langs->trans("Insurance").'</td><td><input name="insurance_amount" size="10" value="' . dol_escape_htmltag(GETPOST("insurance_amount")) . '" placeholder="'.$langs->trans('Amount').'"></td></tr>';
|
||||
|
||||
// Project
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
@ -495,6 +499,18 @@ if ($id > 0)
|
||||
{
|
||||
print '<tr><td class="titlefield">'.$langs->trans("LoanCapital").'</td><td>'.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
|
||||
}
|
||||
|
||||
// Insurance
|
||||
if ($action == 'edit')
|
||||
{
|
||||
print '<tr><td class="titlefield">'.$langs->trans("Insurance").'</td><td>';
|
||||
print '<input name="insurance_amount" size="10" value="' . $object->insurance_amount . '"></td></tr>';
|
||||
print '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<tr><td class="titlefield">'.$langs->trans("Insurance").'</td><td>'.price($object->insurance_amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
|
||||
}
|
||||
|
||||
// Date start
|
||||
print '<tr><td>'.$langs->trans("DateStart")."</td>";
|
||||
@ -771,7 +787,7 @@ if ($id > 0)
|
||||
// Edit
|
||||
if ($object->paid == 0 && $user->rights->loan->write)
|
||||
{
|
||||
print '<a href="javascript:popEcheancier()" class="butAction">'.$langs->trans('CreateCalcSchedule').'</a>';
|
||||
// print '<a href="javascript:popEcheancier()" class="butAction">'.$langs->trans('CreateCalcSchedule').'</a>';
|
||||
|
||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/card.php?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>';
|
||||
}
|
||||
@ -779,7 +795,7 @@ if ($id > 0)
|
||||
// Emit payment
|
||||
if ($object->paid == 0 && ((price2num($object->capital) > 0 && round($staytopay) < 0) || (price2num($object->capital) > 0 && round($staytopay) > 0)) && $user->rights->loan->write)
|
||||
{
|
||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&action=create">'.$langs->trans("DoPayment").'</a>';
|
||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&action=create&last=true">'.$langs->trans("DoPayment").'</a>';
|
||||
}
|
||||
|
||||
// Classify 'paid'
|
||||
|
||||
@ -66,6 +66,8 @@ class Loan extends CommonObject
|
||||
public $date_creation;
|
||||
public $date_modification;
|
||||
public $date_validation;
|
||||
|
||||
public $insurance_amount;
|
||||
|
||||
/**
|
||||
* @var int Bank ID
|
||||
@ -106,7 +108,7 @@ class Loan extends CommonObject
|
||||
*/
|
||||
function fetch($id)
|
||||
{
|
||||
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public,";
|
||||
$sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend, l.nbterm, l.rate, l.note_private, l.note_public, l.insurance_amount,";
|
||||
$sql.= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."loan as l";
|
||||
$sql.= " WHERE l.rowid = ".$id;
|
||||
@ -129,6 +131,7 @@ class Loan extends CommonObject
|
||||
$this->rate = $obj->rate;
|
||||
$this->note_private = $obj->note_private;
|
||||
$this->note_public = $obj->note_public;
|
||||
$this->insurance_amount = $obj->insurance_amount;
|
||||
$this->paid = $obj->paid;
|
||||
|
||||
$this->account_capital = $obj->accountancy_account_capital;
|
||||
@ -169,6 +172,8 @@ class Loan extends CommonObject
|
||||
|
||||
// clean parameters
|
||||
$newcapital=price2num($this->capital,'MT');
|
||||
if (empty($this->insurance_amount)) $this->insurance_amount = 0;
|
||||
$newinsuranceamount=price2num($this->insurance_amount, 'MT');
|
||||
if (isset($this->note_private)) $this->note_private = trim($this->note_private);
|
||||
if (isset($this->note_public)) $this->note_public = trim($this->note_public);
|
||||
if (isset($this->account_capital)) $this->account_capital = trim($this->account_capital);
|
||||
@ -205,7 +210,7 @@ class Loan extends CommonObject
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."loan (label, fk_bank, capital, datestart, dateend, nbterm, rate, note_private, note_public,";
|
||||
$sql.= " accountancy_account_capital, accountancy_account_insurance, accountancy_account_interest, entity,";
|
||||
$sql.= " datec, fk_projet, fk_user_author)";
|
||||
$sql.= " datec, fk_projet, fk_user_author, insurance_amount)";
|
||||
$sql.= " VALUES ('".$this->db->escape($this->label)."',";
|
||||
$sql.= " '".$this->db->escape($this->fk_bank)."',";
|
||||
$sql.= " '".price2num($newcapital)."',";
|
||||
@ -221,7 +226,8 @@ class Loan extends CommonObject
|
||||
$sql.= " ".$conf->entity.",";
|
||||
$sql.= " '".$this->db->idate($now)."',";
|
||||
$sql.= " ".(empty($this->fk_project)?'NULL':$this->fk_project).",";
|
||||
$sql.= " ".$user->id;
|
||||
$sql.= " ".$user->id.",";
|
||||
$sql.= " '".price2num($newinsuranceamount)."'";
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::create", LOG_DEBUG);
|
||||
@ -339,7 +345,8 @@ class Loan extends CommonObject
|
||||
$sql.= " accountancy_account_insurance = '".$this->db->escape($this->account_insurance)."',";
|
||||
$sql.= " accountancy_account_interest = '".$this->db->escape($this->account_interest)."',";
|
||||
$sql.= " fk_projet=".(empty($this->fk_project)?'NULL':$this->fk_project).",";
|
||||
$sql.= " fk_user_modif = ".$user->id;
|
||||
$sql.= " fk_user_modif = ".$user->id.",";
|
||||
$sql.= " insurance_amount = '".price2num($this->db->escape($this->insurance_amount))."'";
|
||||
$sql.= " WHERE rowid=".$this->id;
|
||||
|
||||
dol_syslog(get_class($this)."::update", LOG_DEBUG);
|
||||
@ -549,7 +556,6 @@ class Loan extends CommonObject
|
||||
{
|
||||
$sql = 'SELECT l.rowid, l.datec, l.fk_user_author, l.fk_user_modif,';
|
||||
$sql.= ' l.tms';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'loan as l';
|
||||
$sql.= ' WHERE l.rowid = '.$id;
|
||||
|
||||
dol_syslog(get_class($this).'::info', LOG_DEBUG);
|
||||
|
||||
@ -529,6 +529,7 @@ class PaymentLoan extends CommonObject
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$this->fk_bank = $id_bank;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
||||
@ -35,7 +35,7 @@ $object = new Loan($db);
|
||||
$object->fetch($loanid);
|
||||
|
||||
// Load translation files required by the page
|
||||
$langs->loadLangs(array("loan"));
|
||||
$langs->loadLangs(array("compta","bills","loan"));
|
||||
|
||||
if ($action == 'createecheancier') {
|
||||
|
||||
@ -45,6 +45,7 @@ if ($action == 'createecheancier') {
|
||||
$date = GETPOST('hi_date'.$i,'int');
|
||||
$mens = GETPOST('mens'.$i);
|
||||
$int = GETPOST('hi_interets'.$i);
|
||||
$insurance = GETPOST('hi_insurance'.$i);
|
||||
|
||||
$echeance = new LoanSchedule($db);
|
||||
|
||||
@ -53,10 +54,10 @@ if ($action == 'createecheancier') {
|
||||
$echeance->tms = dol_now();
|
||||
$echeance->datep = $date;
|
||||
$echeance->amount_capital = $mens-$int;
|
||||
$echeance->amount_insurance = 0;
|
||||
$echeance->amount_insurance = $insurance;
|
||||
$echeance->amount_interest = $int;
|
||||
$echeance->fk_typepayment = 3;
|
||||
$echeance->fk_bank = 1;
|
||||
$echeance->fk_bank = 0;
|
||||
$echeance->fk_user_creat = $user->id;
|
||||
$echeance->fk_user_modif = $user->id;
|
||||
$result=$echeance->create($user);
|
||||
@ -75,11 +76,13 @@ if ($action == 'updateecheancier') {
|
||||
$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 = 0;
|
||||
$echeance->amount_insurance = $insurance;
|
||||
$echeance->amount_interest = $int;
|
||||
$echeance->fk_user_modif = $user->id;
|
||||
$result= $echeance->update($user,0);
|
||||
@ -143,26 +146,33 @@ if(count($echeance->lines)>0)
|
||||
}
|
||||
print '<table class="border" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<th align="center" colspan="5">';
|
||||
$colspan = 6;
|
||||
if (count($echeance->lines)>0) $colspan++;
|
||||
print '<th align="center" colspan="'.$colspan.'">';
|
||||
print $langs->trans("FinancialCommitment");
|
||||
print '</th>';
|
||||
print '</tr>';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
Print '<th width="10%" align="center">'.$langs->trans("Term").'</th>';
|
||||
Print '<th width="10%" align="center">'.$langs->trans("Date").'</th>';
|
||||
Print '<th width="5%" align="center">'.$langs->trans("Term").'</th>';
|
||||
Print '<th width="5%" align="center">'.$langs->trans("Date").'</th>';
|
||||
print '<th width="15%" align="center">'.$langs->trans("Insurance");
|
||||
Print '<th width="15%" align="center">'.$langs->trans("InterestAmount").'</th>';
|
||||
Print '<th width="10%" align="center">'.$langs->trans("Amount").'</th>';
|
||||
Print '<th width="20%" align="center">'.$langs->trans("InterestAmount").'</th>';
|
||||
Print '<th width="40%" align="center">'.$langs->trans("CapitalRemain");
|
||||
print ' ('.price2num($object->capital).')';
|
||||
print '<input type="hidden" name="hi_capital0" id ="hi_capital0" value="'.$object->capital.'">';
|
||||
print '</th>';
|
||||
if (count($echeance->lines)>0) print '<th>'.$langs->trans('DoPayment').'</th>';
|
||||
print '</tr>'."\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');
|
||||
@ -172,8 +182,9 @@ if ($object->nbterm > 0 && count($echeance->lines)==0)
|
||||
print '<tr>';
|
||||
print '<td align="center" id="n'.$i.'">' . $i .'</td>';
|
||||
print '<td align="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>';
|
||||
print '<td align="center"><input name="mens'.$i.'" id="mens'.$i.'" size="5" value="'.$mens.'" ech="'.$i.'"> €</td>';
|
||||
print '<td align="center" id="insurance'.$i.'">'.price($insurance+(($i == 1) ? $regulInsurance : 0),0,'',1).' €</td><input type="hidden" name="hi_insurance' .$i .'" id ="hi_insurance' .$i .'" value="' . ($insurance+(($i == 1) ? $regulInsurance : 0)) . '">';
|
||||
print '<td align="center" id="interets'.$i.'">'.price($int,0,'',1).' €</td><input type="hidden" name="hi_interets' .$i .'" id ="hi_interets' .$i .'" value="' . $int . '">';
|
||||
print '<td align="center"><input name="mens'.$i.'" id="mens'.$i.'" size="5" value="'.$mens.'" ech="'.$i.'"> €</td>';
|
||||
print '<td align="center" id="capital'.$i.'">'.price($cap_rest).' €</td><input type="hidden" name="hi_capital' .$i .'" id ="hi_capital' .$i .'" value="' . $cap_rest . '">';
|
||||
print '</tr>'."\n";
|
||||
$i++;
|
||||
@ -184,6 +195,9 @@ 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;
|
||||
@ -191,13 +205,16 @@ elseif(count($echeance->lines)>0)
|
||||
print '<tr>';
|
||||
print '<td align="center" id="n'.$i.'"><input type="hidden" name="hi_rowid' .$i .'" id ="hi_rowid' .$i .'" value="' . $line->id . '">' . $i .'</td>';
|
||||
print '<td align="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>';
|
||||
print '<td align="center" id="insurance'.$i.'">'.price($insurance+(($i == 1) ? $regulInsurance : 0),0,'',1).' €</td><input type="hidden" name="hi_insurance' .$i .'" id ="hi_insurance' .$i .'" value="' . ($insurance+(($i == 1) ? $regulInsurance : 0)) . '">';
|
||||
print '<td align="center" id="interets'.$i.'">'.price($int,0,'',1).' €</td><input type="hidden" name="hi_interets' .$i .'" id ="hi_interets' .$i .'" value="' . $int . '">';
|
||||
if($line->datep > dol_now()){
|
||||
print '<td align="center"><input name="mens'.$i.'" id="mens'.$i.'" size="5" value="'.$mens.'" ech="'.$i.'"> €</td>';
|
||||
}else{
|
||||
print '<td align="center">' . price($mens) . ' €</td><input type="hidden" name="mens' .$i .'" id ="mens' .$i .'" value="' . $mens . '">';
|
||||
}
|
||||
print '<td align="center" id="interets'.$i.'">'.price($int,0,'',1).' €</td><input type="hidden" name="hi_interets' .$i .'" id ="hi_interets' .$i .'" value="' . $int . '">';
|
||||
|
||||
print '<td align="center" id="capital'.$i.'">'.price($cap_rest).' €</td><input type="hidden" name="hi_capital' .$i .'" id ="hi_capital' .$i .'" value="' . $cap_rest . '">';
|
||||
print '<td align="center"><a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&action=create">'.$langs->trans('DoPayment').'</a></td>';
|
||||
print '</tr>'."\n";
|
||||
$i++;
|
||||
$capital = $cap_rest;
|
||||
|
||||
@ -54,6 +54,9 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->del
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".$payment->fk_bank;
|
||||
$db->query($sql);
|
||||
|
||||
$result = $payment->delete($user);
|
||||
if ($result > 0)
|
||||
{
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
|
||||
@ -32,6 +33,8 @@ $langs->loadLangs(array("bills","loan"));
|
||||
$chid=GETPOST('id','int');
|
||||
$action=GETPOST('action','aZ09');
|
||||
$cancel=GETPOST('cancel','alpha');
|
||||
$line_id = GETPOST('line_id', 'int');
|
||||
$last=GETPOST('last');
|
||||
|
||||
// Security check
|
||||
$socid=0;
|
||||
@ -43,6 +46,37 @@ if ($user->societe_id > 0)
|
||||
$loan = new Loan($db);
|
||||
$loan->fetch($chid);
|
||||
|
||||
if($last)
|
||||
{
|
||||
$ls = new LoanSchedule($db);
|
||||
// grab all loanschedule
|
||||
$res = $ls->fetchAll($chid);
|
||||
if ($res > 0)
|
||||
{
|
||||
foreach ($ls->lines as $l)
|
||||
{
|
||||
// get the last unpaid loanschedule
|
||||
if (empty($l->fk_bank))
|
||||
{
|
||||
$line_id = $l->id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!empty($line_id))
|
||||
{
|
||||
$line = new LoanSchedule($db);
|
||||
$res = $line->fetch($line_id);
|
||||
if ($res > 0){
|
||||
$amount_capital = price($line->amount_capital);
|
||||
$amount_insurance = price($line->amount_insurance);
|
||||
$amount_interest = price($line->amount_interest);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
@ -121,6 +155,12 @@ if ($action == 'add_payment')
|
||||
setEventMessages($payment->error, $payment->errors, 'errors');
|
||||
$error++;
|
||||
}
|
||||
elseif(isset($line))
|
||||
{
|
||||
$line->fk_bank = $payment->fk_bank;
|
||||
$line->update($user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
@ -161,6 +201,7 @@ if ($action == 'create')
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="id" value="'.$chid.'">';
|
||||
print '<input type="hidden" name="chid" value="'.$chid.'">';
|
||||
print '<input type="hidden" name="line_id" value="'.$line_id.'">';
|
||||
print '<input type="hidden" name="action" value="add_payment">';
|
||||
|
||||
dol_fiche_head();
|
||||
@ -264,7 +305,7 @@ if ($action == 'create')
|
||||
print '<td align="right">';
|
||||
if ($sumpaid < $loan->capital)
|
||||
{
|
||||
print $langs->trans("LoanCapital") .': <input type="text" size="8" name="amount_capital">';
|
||||
print $langs->trans("LoanCapital") .': <input type="text" size="8" name="amount_capital" value="'.$amount_capital.'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -273,7 +314,7 @@ if ($action == 'create')
|
||||
print '<br>';
|
||||
if ($sumpaid < $loan->capital)
|
||||
{
|
||||
print $langs->trans("Insurance") .': <input type="text" size="8" name="amount_insurance">';
|
||||
print $langs->trans("Insurance") .': <input type="text" size="8" name="amount_insurance" value="'.$amount_insurance.'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -282,7 +323,7 @@ if ($action == 'create')
|
||||
print '<br>';
|
||||
if ($sumpaid < $loan->capital)
|
||||
{
|
||||
print $langs->trans("Interest") .': <input type="text" size="8" name="amount_interest">';
|
||||
print $langs->trans("Interest") .': <input type="text" size="8" name="amount_interest" value="'.$amount_interest.'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
251
htdocs/loan/schedule.php
Normal file
251
htdocs/loan/schedule.php
Normal file
@ -0,0 +1,251 @@
|
||||
<?php
|
||||
/* Copyright (C) 2017 Franck Moreau <franck.moreau@theobald.com>
|
||||
* Copyright (C) 2018 Alexandre Spangaro <aspangaro@zendsi.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \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;
|
||||
|
||||
|
||||
?>
|
||||
<script type="text/javascript" language="javascript">
|
||||
$(document).ready(function() {
|
||||
$('[name^="mens"]').focusout(function() {
|
||||
var echeance=$(this).attr('ech');
|
||||
var mens=$(this).val();
|
||||
var idcap=echeance-1;
|
||||
idcap = '#hi_capital'+idcap;
|
||||
var capital=$(idcap).val();
|
||||
console.log("Change montly amount echeance="+echeance+" idcap="+idcap+" capital="+capital);
|
||||
$.ajax({
|
||||
dataType: 'json',
|
||||
url: 'calcmens.php',
|
||||
data: { echeance: echeance, mens: mens, capital:capital, rate:<?php echo $object->rate/100;?> , nbterm : <?php echo $object->nbterm;?>},
|
||||
success: function(data) {
|
||||
$.each(data, function(index, element) {
|
||||
var idcap_res='#hi_capital'+index;
|
||||
var idcap_res_srt='#capital'+index;
|
||||
var interet_res='#hi_interets'+index;
|
||||
var interet_res_str='#interets'+index;
|
||||
var men_res='#mens'+index;
|
||||
$(idcap_res).val(element.cap_rest);
|
||||
$(idcap_res_srt).text(element.cap_rest_str+' €');
|
||||
$(interet_res).val(element.interet);
|
||||
$(interet_res_str).text(element.interet_str+' €');
|
||||
$(men_res).val(element.mens);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
||||
|
||||
print '<form name="createecheancier" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
|
||||
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
|
||||
print '<input type="hidden" name="loanid" value="' . $loanid . '">';
|
||||
if(count($echeance->lines)>0)
|
||||
{
|
||||
print '<input type="hidden" name="action" value="updateecheancier">';
|
||||
}else{
|
||||
print '<input type="hidden" name="action" value="createecheancier">';
|
||||
}
|
||||
print '<table class="border" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
$colspan = 6;
|
||||
if (count($echeance->lines)>0) $colspan++;
|
||||
print '<th align="center" colspan="'.$colspan.'">';
|
||||
print $langs->trans("FinancialCommitment");
|
||||
print '</th>';
|
||||
print '</tr>';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
Print '<th width="5%" align="center">'.$langs->trans("Term").'</th>';
|
||||
Print '<th width="5%" align="center">'.$langs->trans("Date").'</th>';
|
||||
print '<th width="15%" align="center">'.$langs->trans("Insurance");
|
||||
Print '<th width="15%" align="center">'.$langs->trans("InterestAmount").'</th>';
|
||||
Print '<th width="10%" align="center">'.$langs->trans("Amount").'</th>';
|
||||
Print '<th width="40%" align="center">'.$langs->trans("CapitalRemain");
|
||||
print ' ('.price2num($object->capital).')';
|
||||
print '<input type="hidden" name="hi_capital0" id ="hi_capital0" value="'.$object->capital.'">';
|
||||
print '</th>';
|
||||
if (count($echeance->lines)>0) print '<th>'.$langs->trans('DoPayment').'</th>';
|
||||
print '</tr>'."\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');
|
||||
$insu = ($insurance+(($i == 1) ? $regulInsurance : 0));
|
||||
$cap_rest = price2num($capital - ($mens-$int), 'MT');
|
||||
print '<tr>';
|
||||
print '<td align="center" id="n'.$i.'">' . $i .'</td>';
|
||||
print '<td align="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>';
|
||||
print '<td align="center" id="insurance'.$i.'">'.price($insurance+(($i == 1) ? $regulInsurance : 0),0,'',1).' €</td><input type="hidden" name="hi_insurance' .$i .'" id ="hi_insurance' .$i .'" value="' . ($insurance+(($i == 1) ? $regulInsurance : 0)) . '">';
|
||||
print '<td align="center" id="interets'.$i.'">'.price($int,0,'',1).' €</td><input type="hidden" name="hi_interets' .$i .'" id ="hi_interets' .$i .'" value="' . $int . '">';
|
||||
print '<td align="center"><input name="mens'.$i.'" id="mens'.$i.'" size="5" value="'.$mens.'" ech="'.$i.'"> €</td>';
|
||||
print '<td align="center" id="capital'.$i.'">'.price($cap_rest).' €</td><input type="hidden" name="hi_capital' .$i .'" id ="hi_capital' .$i .'" value="' . $cap_rest . '">';
|
||||
print '</tr>'."\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));
|
||||
$printed = false;
|
||||
foreach ($echeance->lines as $line){
|
||||
$mens = $line->amount_capital+$line->amount_interest;
|
||||
$int = $line->amount_interest;
|
||||
$insu = ($insurance+(($i == 1) ? $regulInsurance : 0));
|
||||
$cap_rest = price2num($capital - ($mens-$int), 'MT');
|
||||
|
||||
print '<tr>';
|
||||
print '<td align="center" id="n'.$i.'"><input type="hidden" name="hi_rowid' .$i .'" id ="hi_rowid' .$i .'" value="' . $line->id . '">' . $i .'</td>';
|
||||
print '<td align="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>';
|
||||
print '<td align="center" id="insurance'.$i.'">'.price($insu,0,'',1).' €</td><input type="hidden" name="hi_insurance' .$i .'" id ="hi_insurance' .$i .'" value="' . $insu . '">';
|
||||
print '<td align="center" id="interets'.$i.'">'.price($int,0,'',1).' €</td><input type="hidden" name="hi_interets' .$i .'" id ="hi_interets' .$i .'" value="' . $int . '">';
|
||||
if($line->datep > dol_now() && empty($line->fk_bank)){
|
||||
print '<td align="center"><input name="mens'.$i.'" id="mens'.$i.'" size="5" value="'.$mens.'" ech="'.$i.'"> €</td>';
|
||||
}else{
|
||||
print '<td align="center">' . price($mens) . ' €</td><input type="hidden" name="mens' .$i .'" id ="mens' .$i .'" value="' . $mens . '">';
|
||||
}
|
||||
|
||||
print '<td align="center" id="capital'.$i.'">'.price($cap_rest).' €</td><input type="hidden" name="hi_capital' .$i .'" id ="hi_capital' .$i .'" value="' . $cap_rest . '">';
|
||||
print '<td align="center">';
|
||||
if (!empty($line->fk_bank)) print $langs->trans('Paid');
|
||||
elseif (!$printed)
|
||||
{
|
||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&action=create&line_id='.$line->id.'">'.$langs->trans('DoPayment').'</a>';
|
||||
$printed = true;
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>'."\n";
|
||||
$i++;
|
||||
$capital = $cap_rest;
|
||||
}
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
print '</br>';
|
||||
print '</br>';
|
||||
if (count($echeance->lines)==0) $label = $langs->trans("Create");
|
||||
else $label = $langs->trans("Save");
|
||||
print '<div align="center"><input class="button" type="submit" value="'.$label.'"></div>';
|
||||
print '</form>';
|
||||
|
||||
// End of page
|
||||
llxFooter();
|
||||
$db->close();
|
||||
Loading…
Reference in New Issue
Block a user