*
* 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/createecheancier.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';
global $user;
$loanid = GETPOST('loanid', 'int');
$action = GETPOST('action','aZ09');
$object = new Loan($db);
$object->fetch($loanid);
$langs->load('loan');
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);
$echeance = new LoanSchedule($db);
$echeance->fk_loan = $object->id;
$echeance->datec = dol_now();
$echeance->tms = dol_now();
$echeance->datepaid = $date;
$echeance->amount_capital = $mens-$int;
$echeance->amount_insurance = 0;
$echeance->amount_interest = $int;
$echeance->fk_typepayment = 3;
$echeance->fk_bank = 1;
$echeance->fk_user_creat = $user->id;
$echeance->fk_user_modif = $user->id;
$result=$echeance->create($user);
if ($result<0) {
setEventMessages(null, $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);
$echeance = new LoanSchedule($db);
$echeance->fetch($id);
$echeance->tms = dol_now();
$echeance->amount_capital = $mens-$int;
$echeance->amount_insurance = 0;
$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);
top_htmlhead('', '');
$var = ! $var;
?>
';
print '';
print '';
if(count($echeance->lines)>0){
print '';
}else{
print '';
}
print '