From 3042bf4dc2a4fbaab5d759fcf94a2b809b1de2a8 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 10 Nov 2014 06:08:50 +0100 Subject: [PATCH] Correct lot of bugs --- htdocs/compta/loan/card.php | 176 +++++++++--------- htdocs/compta/loan/class/loan.class.php | 82 ++++---- .../compta/loan/class/paymentloan.class.php | 29 ++- htdocs/compta/loan/index.php | 42 ++--- htdocs/compta/loan/payment/card.php | 19 +- htdocs/compta/loan/payment/payment.php | 74 +++++--- .../install/mysql/migration/3.6.0-3.7.0.sql | 42 ----- .../install/mysql/migration/3.7.0-3.8.0.sql | 63 +++++++ .../install/mysql/tables/llx_payment_loan.sql | 4 +- htdocs/langs/en_US/loan.lang | 3 + htdocs/langs/fr_FR/loan.lang | 3 + 11 files changed, 306 insertions(+), 231 deletions(-) create mode 100644 htdocs/install/mysql/migration/3.7.0-3.8.0.sql diff --git a/htdocs/compta/loan/card.php b/htdocs/compta/loan/card.php index 49e3884562c..88a4429e7c5 100644 --- a/htdocs/compta/loan/card.php +++ b/htdocs/compta/loan/card.php @@ -33,13 +33,15 @@ $langs->load("loan"); $id=GETPOST('id','int'); $action=GETPOST('action'); $confirm=GETPOST('confirm'); -$cancel=GETPOST('cancel'); +$cancel=GETPOST('cancel','alpha'); // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'loan', $id, '',''); +$object = new Loan($db); + /* * Actions */ @@ -47,7 +49,6 @@ $result = restrictedArea($user, 'loan', $id, '',''); // Classify paid if ($action == 'confirm_paid' && $confirm == 'yes') { - $object = new Loan($db); $object->fetch($id); $result = $object->set_paid($user); } @@ -55,7 +56,6 @@ if ($action == 'confirm_paid' && $confirm == 'yes') // Delete loan if ($action == 'confirm_delete' && $confirm == 'yes') { - $object = new Loan($db); $object->fetch($id); $result=$object->delete($user); if ($result > 0) @@ -72,86 +72,88 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // Add loan if ($action == 'add' && $user->rights->loan->write) { - $datestart=@dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); - $dateend=@dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); - - if (! $datestart) + if (! $cancel) { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); - $action = 'create'; - } - elseif (! $dateend) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors'); - $action = 'create'; - } - elseif (! $_POST["capital"]) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Capital")), 'errors'); - $action = 'create'; - } - else - { - $object = new Loan($db); - - $object->label = $_POST["label"]; - $object->fk_bank = $_POST["accountid"]; - $object->capital = $_POST["capital"]; - $object->datestart = $datestart; - $object->dateend = $dateend; - $object->nbterm = $_POST["nbterm"]; - $object->rate = $_POST["rate"]; + $datestart=@dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); + $dateend=@dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); - $object->account_capital = $_POST["accountancy_account_capital"]; - $object->account_insurance = $_POST["accountancy_account_insurance"]; - $object->account_interest = $_POST["accountancy_account_interest"]; - - $id=$object->create($user); - if ($id <= 0) + if (! $datestart) { - setEventMessage($object->error, 'errors'); + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); + $action = 'create'; } - } -} - - -if ($action == 'update' && ! $cancel && $user->rights->loan->write) -{ - $datestart=dol_mktime(12,0,0, $GETPOST("startmonth"), $GETPOST("startday"), $GETPOST("startyear")); - $dateend=dol_mktime(12,0,0, $GETPOST("endmonth"), $GETPOST("endday"), $GETPOST("endyear")); - if (! $datestart) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); - $action = 'edit'; - } - elseif (! $dateend) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors'); - $action = 'edit'; - } - else - { - $object = new Loan($db); - if ($object->fetch($id)) + elseif (! $dateend) { - $object->label = $GETPOST("label"); - $object->datestart = $datestart; - $object->dateend = $dateend; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors'); + $action = 'create'; } - - if ($object->update($id, $user) > 0) + elseif (! $_POST["capital"]) { - $action = ''; + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Capital")), 'errors'); + $action = 'create'; } else { - $action = 'edit'; - setEventMessage($object->error, 'errors'); + $object->label = $_POST["label"]; + $object->fk_bank = $_POST["accountid"]; + $object->capital = $_POST["capital"]; + $object->datestart = $datestart; + $object->dateend = $dateend; + $object->nbterm = $_POST["nbterm"]; + $object->rate = $_POST["rate"]; + + $object->account_capital = $_POST["accountancy_account_capital"]; + $object->account_insurance = $_POST["accountancy_account_insurance"]; + $object->account_interest = $_POST["accountancy_account_interest"]; + + $id=$object->create($user); + if ($id <= 0) + { + setEventMessage($object->error, 'errors'); + } } } + else + { + header("Location: index.php"); + exit(); + } } +// Update record +else if ($action == 'update' && $user->rights->loan->write) +{ + if (! $cancel) + { + $result = $object->fetch($id); + + if ($object->fetch($id)) + { + $object->label = GETPOST("label"); + $object->datestart = dol_mktime(12, 0, 0, GETPOST('startmonth','int'), GETPOST('startday','int'), GETPOST('startyear','int')); + $object->dateend = dol_mktime(12, 0, 0, GETPOST('endmonth','int'), GETPOST('endday','int'), GETPOST('endyear','int')); + $object->nbterm = GETPOST("nbterm"); + $object->rate = GETPOST("rate"); + } + + $result = $object->update($user); + if ($result > 0) + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } + else + { + setEventMessage($object->error, 'errors'); + } + } + else + { + header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id); + exit; + } +} /* * View @@ -212,10 +214,10 @@ if ($action == 'create') print ''; // Number of terms - print ''.$langs->trans("Nbterms").''; + print ''.$langs->trans("Nbterms").''; // Rate - print ''.$langs->trans("Rate").''; + print ''.$langs->trans("Rate").' %'; // Note print ''; @@ -273,7 +275,6 @@ if ($action == 'create') // View if ($id > 0) { - $object = new Loan($db); $result = $object->fetch($id); if ($result > 0) @@ -297,8 +298,10 @@ if ($id > 0) if ($action == 'edit') { - print '
id&action=update" method="POST">'; - print ''; + print '' . "\n"; + print ''; + print ''; + print ''; } print ''; @@ -353,7 +356,7 @@ if ($id > 0) print ''; // Rate - print ''; + print ''; // Status print ''; @@ -378,8 +381,9 @@ if ($id > 0) /* * Payments */ - $sql = "SELECT p.rowid, p.num_payment, datep as dp, p.amount,"; - $sql.= "c.libelle as paiement_type"; + $sql = "SELECT p.rowid, p.num_payment, datep as dp,"; + $sql.= " p.amount_capital, p.amount_insurance, p.amount_interest,"; + $sql.= " c.libelle as paiement_type"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; $sql.= ", ".MAIN_DB_PREFIX."loan as l"; @@ -400,7 +404,9 @@ if ($id > 0) print ''; print ''; print ''; - print ''; + print ''; + print ''; + print ''; print ''; print ''; @@ -413,21 +419,23 @@ if ($id > 0) print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''; print '\n"; print "\n"; - print '\n"; + print '\n"; + print '\n"; + print '\n"; print ""; - $totalpaid += $objp->amount; + $totalpaid += $objp->amount_capital; $i++; } if ($object->paid == 0) { - print "\n"; - print "\n"; + print ''; + print ''; $staytopay = $object->capital - $totalpaid; - print ""; - print "\n"; + print ''; + print ''; } print "
'.$langs->trans("Nbterms").''.$object->nbterm.'
'.$langs->trans("Rate").''.$object->rate.'
'.$langs->trans("Rate").''.$object->rate.' %
'.$langs->trans("Status").''.$object->getLibStatut(4, $totalpaye).'
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").''.$langs->trans("Insurance").''.$langs->trans("Interest").''.$langs->trans("Capital").' 
'.dol_print_date($db->jdate($objp->dp),'day')."".$objp->paiement_type.' '.$objp->num_payment."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."'.price($objp->amount_insurance)." ".$langs->trans("Currency".$conf->currency)."'.price($objp->amount_interest)." ".$langs->trans("Currency".$conf->currency)."'.price($objp->amount_capital)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaid)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->capital)." ".$langs->trans("Currency".$conf->currency)."
'.$langs->trans("AlreadyPaid").' :'.price($totalpaid).' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("AmountExpected").' :'.price($object->capital).' '.$langs->trans("Currency".$conf->currency).'
".$langs->trans("RemainderToPay")." :".price($staytopay)." ".$langs->trans("Currency".$conf->currency)."
'.$langs->trans("RemainderToPay").' :'.price($staytopay).' '.$langs->trans("Currency".$conf->currency).'
"; $db->free($resql); @@ -444,7 +452,7 @@ if ($id > 0) */ if ($action != 'edit') { - print "
\n"; + print '
'; // Edit if ($user->rights->loan->write) diff --git a/htdocs/compta/loan/class/loan.class.php b/htdocs/compta/loan/class/loan.class.php index 07b842b708e..b8fcf04728f 100644 --- a/htdocs/compta/loan/class/loan.class.php +++ b/htdocs/compta/loan/class/loan.class.php @@ -263,8 +263,8 @@ class Loan extends CommonObject /** * Update loan * - * @param User $user Utilisateur qui modifie - * @return int <0 si erreur, >0 si ok + * @param User $user User who modified + * @return int <0 if error, >0 if ok */ function update($user) { @@ -273,7 +273,8 @@ class Loan extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."loan"; $sql.= " SET label='".$this->db->escape($this->label)."',"; $sql.= " datestart='".$this->db->idate($this->datestart)."',"; - $sql.= " dateend='".$this->db->idate($this->dateend)."'"; + $sql.= " dateend='".$this->db->idate($this->dateend)."',"; + $sql.= " fk_user_modif = ".$user->id; $sql.= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::update", LOG_DEBUG); @@ -379,7 +380,7 @@ class Loan extends CommonObject * @param int $maxlen Label max length * @return string Chaine with URL */ - function getNameUrl($withpicto=0,$maxlen=0) + function getLinkUrl($withpicto=0,$maxlen=0) { global $langs; @@ -432,40 +433,43 @@ class Loan extends CommonObject * @param int $id Id of record * @return void */ - function info($id) - { - $sql = "SELECT l.rowid, l.tms as datem, l.fk_user_author as user_author, l.datec as datec"; - $sql.= " FROM ".MAIN_DB_PREFIX."loan as l"; - $sql.= " WHERE l.rowid = ".$id; + function info($id) + { + $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); - $result=$this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); - - $this->id = $obj->rowid; - - if ($obj->user_author) { - $cuser = new User($this->db); - $cuser->fetch($obj->user_author); - $this->user_creation = $cuser; - } - - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_modification = $this->db->jdate($obj->datem); - - } - - $this->db->free($result); - - } - else - { - dol_print_error($this->db); - } - } -} + dol_syslog(get_class($this).'::info', LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $this->id = $obj->rowid; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + if ($obj->fk_user_modif) + { + $muser = new User($this->db); + $muser->fetch($obj->fk_user_modif); + $this->user_modification = $muser; + } + $this->date_creation = $this->db->jdate($obj->datec); + if (empty($obj->fk_user_modif)) $obj->tms = ""; + $this->date_modification = $this->db->jdate($obj->tms); + } + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + } +} \ No newline at end of file diff --git a/htdocs/compta/loan/class/paymentloan.class.php b/htdocs/compta/loan/class/paymentloan.class.php index 0a558fc9bf4..944cfe4ce2f 100644 --- a/htdocs/compta/loan/class/paymentloan.class.php +++ b/htdocs/compta/loan/class/paymentloan.class.php @@ -39,8 +39,10 @@ class PaymentLoan extends CommonObject var $datec=''; var $tms=''; var $datep=''; - var $amount; // Total amount of payment var $amounts=array(); // Array of amounts + var $amount_capital; // Total amount of payment + var $amount_insurance; + var $amount_interest; var $fk_typepayment; var $num_payment; var $note; @@ -82,7 +84,9 @@ class PaymentLoan extends CommonObject // Clean parameters if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan); - if (isset($this->amount)) $this->amount = trim($this->amount); + if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital); + if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance); + if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest); if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); if (isset($this->note)) $this->note = trim($this->note); @@ -107,7 +111,7 @@ class PaymentLoan extends CommonObject if ($totalamount != 0) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan (fk_loan, datec, datep, amount,"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_loan (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,"; $sql.= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)"; $sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',"; $sql.= " '".$this->db->idate($this->datepaid)."',"; @@ -130,7 +134,7 @@ class PaymentLoan extends CommonObject if ($totalamount != 0 && ! $error) { - $this->amount=$totalamount; + $this->amount_capital=$totalamount; $this->total=$totalamount; // deprecated $this->db->commit(); return $this->id; @@ -158,7 +162,9 @@ class PaymentLoan extends CommonObject $sql.= " t.datec,"; $sql.= " t.tms,"; $sql.= " t.datep,"; - $sql.= " t.amount,"; + $sql.= " t.amount_capital,"; + $sql.= " t.amount_insurance,"; + $sql.= " t.amount_interest,"; $sql.= " t.fk_typepayment,"; $sql.= " t.num_payment,"; $sql.= " t.note,"; @@ -186,7 +192,9 @@ class PaymentLoan extends CommonObject $this->datec = $this->db->jdate($obj->datec); $this->tms = $this->db->jdate($obj->tms); $this->datep = $this->db->jdate($obj->datep); - $this->amount = $obj->amount; + $this->amount_capital = $obj->amount_capital; + $this->amount_insurance = $obj->amount_insurance; + $this->amount_interest = $obj->amount_interest; $this->fk_typepayment = $obj->fk_typepayment; $this->num_payment = $obj->num_payment; $this->note = $obj->note; @@ -225,9 +233,10 @@ class PaymentLoan extends CommonObject $error=0; // Clean parameters - if (isset($this->fk_loan)) $this->fk_loan=trim($this->fk_loan); - if (isset($this->amount)) $this->amount=trim($this->amount); + if (isset($this->amount_capital)) $this->amount_capital=trim($this->amount_capital); + if (isset($this->amount_insurance)) $this->amount_insurance=trim($this->amount_insurance); + if (isset($this->amount_interest)) $this->amount_interest=trim($this->amount_interest); if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment); if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment); if (isset($this->note)) $this->note=trim($this->note); @@ -245,7 +254,9 @@ class PaymentLoan extends CommonObject $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; - $sql.= " amount=".(isset($this->amount)?$this->amount:"null").","; + $sql.= " amount_capital=".(isset($this->amount_capital)?$this->amount_capital:"null").","; + $sql.= " amount_insurance=".(isset($this->amount_insurance)?$this->amount_insurance:"null").","; + $sql.= " amount_interest=".(isset($this->amount_interest)?$this->amount_interest:"null").","; $sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").","; $sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").","; $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").","; diff --git a/htdocs/compta/loan/index.php b/htdocs/compta/loan/index.php index 2834ce2069f..720b52de0a1 100644 --- a/htdocs/compta/loan/index.php +++ b/htdocs/compta/loan/index.php @@ -47,6 +47,7 @@ $limit = $conf->liste_limit; $search_ref=GETPOST('search_ref','int'); $search_label=GETPOST('search_label','alpha'); +$search_amount=GETPOST('search_amount','alpha'); $filtre=GETPOST("filtre"); if (GETPOST("button_removefilter")) @@ -60,36 +61,37 @@ if (GETPOST("button_removefilter")) * View */ -$loan = new Loan($db); +$loan_static = new Loan($db); llxHeader(); $sql = "SELECT l.rowid, l.label, l.capital, l.datestart, l.dateend,"; -$sql.= " SUM(pl.amount) as alreadypayed"; -$sql.= " FROM ".MAIN_DB_PREFIX."loan as l,"; -$sql.= " ".MAIN_DB_PREFIX."payment_loan as pl"; -$sql.= " WHERE pl.fk_loan = l.rowid"; -$sql.= " AND l.entity = ".$conf->entity; -if (GETPOST("search_ref")) $sql.=" AND (l.rowid = ".$db->escape($search_ref).")"; -if (GETPOST("search_label")) $sql.=" AND l.label LIKE '%".$db->escape($search_label)."%'"; - +$sql.= " SUM(pl.amount_capital) as alreadypayed"; +$sql.= " FROM ".MAIN_DB_PREFIX."loan as l LEFT JOIN ".MAIN_DB_PREFIX."payment_loan AS pl"; +$sql.= " ON l.rowid = pl.fk_loan"; +$sql.= " WHERE l.entity = ".$conf->entity; +if ($search_amount) $sql.=" AND l.capital='".$db->escape(price2num(trim($search_amount)))."'"; +if ($search_ref) $sql.=" AND l.rowid = ".$db->escape($search_ref); +if ($search_label) $sql.=" AND l.label LIKE '%".$db->escape($search_label)."%'"; if ($filtre) { $filtre=str_replace(":","=",$filtre); $sql .= " AND ".$filtre; } +$sql.= " GROUP BY l.rowid, l.label, l.capital, l.datestart, l.dateend"; $sql.= $db->order($sortfield,$sortorder); -$sql.= $db->plimit($limit + 1, $offset); +$sql.= $db->plimit($limit+1, $offset); //print $sql; $resql=$db->query($sql); if ($resql) { $num = $db->num_rows($resql); + $i = 0; + $var=true; print_fiche_titre($langs->trans("Loans")); - $i = 0; - print ''."\n"; + print ''."\n"; print ''; print ''; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"l.rowid","",$param,"",$sortfield,$sortorder); @@ -101,9 +103,9 @@ if ($resql) // Filters lines print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; print ''; print ''; print ''; - $var=true; while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); - + $var = !$var; print ""; // Ref - print ''; + print ''; // Label print ''; @@ -134,7 +132,7 @@ if ($resql) // Date start print ''; - print ''; + print ''; print "\n"; diff --git a/htdocs/compta/loan/payment/card.php b/htdocs/compta/loan/payment/card.php index d08c5f8ce0f..4dc1407e8ad 100644 --- a/htdocs/compta/loan/payment/card.php +++ b/htdocs/compta/loan/payment/card.php @@ -118,7 +118,6 @@ if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->loan->wri llxHeader(); $loan = new Loan($db); - $form = new Form($db); $h=0; @@ -168,7 +167,9 @@ print ''; // Amount -print ''; +print ''; +print ''; +print ''; // Note print ''; @@ -198,7 +199,7 @@ print '
   '; print ''; @@ -111,19 +113,15 @@ if ($resql) print '
'; - $loan->id = $obj->id; - print $loan->getNameUrl(1,'20'); - print ''.img_object($langs->trans("ShowLoan"),"label").' '.$obj->rowid.''.dol_trunc($obj->label,42).''.dol_print_date($db->jdate($obj->datestart), 'day').''.$loan->LibStatut($obj->paid,5,$obj->alreadypayed).''.$loan_static->LibStatut($obj->paid,5,$obj->alreadypayed).'
'.$langs->trans('Mode').''.$lan print '
'.$langs->trans('Number').''.$payment->num_payment.'
'.$langs->trans('Amount').''.price($payment->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Capital').''.price($payment->amount_capital, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Insurance').''.price($payment->amount_insurance, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Interest').''.price($payment->amount_interest, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans('Note').''.nl2br($payment->note).'
'; */ $disable_delete = 0; -$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount'; +$sql = 'SELECT l.rowid as id, l.label, l.paid, l.capital as capital, pl.amount_capital, pl.amount_insurance, pl.amount_interest'; $sql.= ' FROM '.MAIN_DB_PREFIX.'payment_loan as pl,'.MAIN_DB_PREFIX.'loan as l'; $sql.= ' WHERE pl.fk_loan = l.rowid'; $sql.= ' AND l.entity = '.$conf->entity; @@ -234,22 +235,22 @@ if ($resql) // Ref print ''; $loan->fetch($objp->id); - print $loan->getNameUrl(1); + print $loan->getLinkUrl(1); print "\n"; // Label print ''.$objp->label.''; // Expected to pay print ''.price($objp->capital).''; // Status - print ''.$loan->getLibStatut(4,$objp->amount).''; + print ''.$loan->getLibStatut(4,$objp->amount_capital).''; // Amount payed - print ''.price($objp->amount).''; + print ''.price($objp->amount_capital).''; print "\n"; - if ($objp->paye == 1) // If at least one invoice is paid, disable delete + if ($objp->paid == 1) // If at least one invoice is paid, disable delete { $disable_delete = 1; } - $total = $total + $objp->amount; + $total = $total + $objp->amount_capital; $i++; } } @@ -267,7 +268,7 @@ print '
'; /* - * Boutons Actions + * Actions buttons */ print '
'; diff --git a/htdocs/compta/loan/payment/payment.php b/htdocs/compta/loan/payment/payment.php index ed249d8f246..678ca1b8429 100644 --- a/htdocs/compta/loan/payment/payment.php +++ b/htdocs/compta/loan/payment/payment.php @@ -29,9 +29,10 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->load("bills"); $langs->load("loan"); -$chid=GETPOST("id"); +$chid=GETPOST('id','int'); $action=GETPOST('action'); $amounts = array(); +$cancel=GETPOST('cancel','alpha'); // Security check $socid=0; @@ -47,7 +48,7 @@ if ($action == 'add_payment') { $error=0; - if ($_POST["cancel"]) + if ($cancel) { $loc = DOL_URL_ROOT.'/compta/loan/card.php?id='.$chid; header("Location: ".$loc); @@ -98,12 +99,15 @@ if ($action == 'add_payment') // Create a line of payments $payment = new PaymentLoan($db); - $payment->chid = $chid; - $payment->datepaid = $datepaid; - $payment->amounts = $amounts; // Tableau de montant - $payment->paymenttype = $_POST["paymenttype"]; - $payment->num_payment = $_POST["num_payment"]; - $payment->note = $_POST["note"]; + $payment->chid = $chid; + $payment->datepaid = $datepaid; + $payment->amounts = $amounts; // Tableau de montant + $payment->amount_capital = $_POST["amount_capital"]; + $payment->amount_insurance = $_POST["amount_insurance"]; + $payment->amount_interest = $_POST["amount_interest"]; + $payment->paymenttype = $_POST["paymenttype"]; + $payment->num_payment = $_POST["num_payment"]; + $payment->note = $_POST["note"]; if (! $error) { @@ -177,12 +181,12 @@ if ($_GET["action"] == 'create') print ''; - print ""; + print ''; print ''; - print '\n"; + print '\n"; print '\n"; - print ''; + print ''; $sql = "SELECT sum(p.amount) as total"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; @@ -204,7 +208,7 @@ if ($_GET["action"] == 'create') print '
".$langs->trans("Loan")."
'.$langs->trans("Loan").'
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("DateStart")."".dol_print_date($loan->datestart,'day')."
'.$langs->trans("DateStart").''.dol_print_date($loan->datestart,'day')."
'.$langs->trans("Label").''.$loan->label."
'.$langs->trans("Amount")."".price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Amount").''.price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).'
'; print ''; - print "'; + print ''; print ''; print '
".$langs->trans("Payment").''.$langs->trans("Payment").'
'.$langs->trans("Date").''; @@ -249,10 +253,10 @@ if ($_GET["action"] == 'create') print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print "\n"; $var=True; @@ -269,24 +273,44 @@ if ($_GET["action"] == 'create') if ($objp->datestart > 0) { - print "\n"; + print ''; } else { - print "\n"; + print ''; } - print '"; + print '"; - print '"; + print '"; - print '"; + print '"; - print '"; print ''; - print ""; - print ""; - print ""; + print ''; + print ''; + print ''; print ''; print "\n"; } diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index 95158c60a4f..0cbede46864 100755 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -1099,48 +1099,6 @@ CREATE TABLE llx_usergroup_extrafields ( ALTER TABLE llx_usergroup_extrafields ADD INDEX idx_usergroup_extrafields (fk_object); --- Loan -create table llx_loan -( - rowid integer AUTO_INCREMENT PRIMARY KEY, - entity integer DEFAULT 1 NOT NULL, - datec datetime, - tms timestamp, - label varchar(80) NOT NULL, - fk_bank integer, - capital real default 0 NOT NULL, - datestart date, - dateend date, - nbterm real, - rate double NOT NULL, - note text, - capital_position real default 0, - date_position date, - paid smallint default 0 NOT NULL, - accountancy_account_capital varchar(32), - accountancy_account_insurance varchar(32), - accountancy_account_interest varchar(32), - fk_user_author integer DEFAULT NULL, - fk_user_modif integer DEFAULT NULL, - active tinyint DEFAULT 1 NOT NULL -)ENGINE=innodb; - -create table llx_payment_loan -( - rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_loan integer, - datec datetime, - tms timestamp, - datep datetime, - amount real DEFAULT 0, - fk_typepayment integer NOT NULL, - num_payment varchar(50), - note text, - fk_bank integer NOT NULL, - fk_user_creat integer, - fk_user_modif integer -)ENGINE=innodb; - ALTER TABLE llx_contrat ADD COLUMN model_pdf varchar(255) DEFAULT NULL AFTER note_public; ALTER TABLE llx_c_country ADD COLUMN favorite tinyint DEFAULT 0 AFTER active; diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql new file mode 100644 index 00000000000..93f2197de12 --- /dev/null +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -0,0 +1,63 @@ +-- +-- Be carefull to requests order. +-- This file must be loaded by calling /install/index.php page +-- when current version is 3.8.0 or higher. +-- +-- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new; +-- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; +-- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); +-- To drop a column: ALTER TABLE llx_table DROP COLUMN oldname; +-- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60); +-- To drop a foreign key: ALTER TABLE llx_table DROP FOREIGN KEY fk_name; +-- To restrict request to Mysql version x.y use -- VMYSQLx.y +-- To restrict request to Pgsql version x.y use -- VPGSQLx.y +-- To make pk to be auto increment (mysql): VMYSQL4.3 ALTER TABLE llx_c_shipment_mode CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; +-- To make pk to be auto increment (postgres): VPGSQL8.2 NOT POSSIBLE. MUST DELETE/CREATE TABLE +-- To set a field as NULL: VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL; +-- To set a field as default NULL: VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET DEFAULT NULL; +-- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user); +-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); + +-- Loan +create table llx_loan +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, + datec datetime, + tms timestamp, + label varchar(80) NOT NULL, + fk_bank integer, + capital real default 0 NOT NULL, + datestart date, + dateend date, + nbterm real, + rate double NOT NULL, + note text, + capital_position real default 0, + date_position date, + paid smallint default 0 NOT NULL, + accountancy_account_capital varchar(32), + accountancy_account_insurance varchar(32), + accountancy_account_interest varchar(32), + fk_user_author integer DEFAULT NULL, + fk_user_modif integer DEFAULT NULL, + active tinyint DEFAULT 1 NOT NULL +)ENGINE=innodb; + +create table llx_payment_loan +( + rowid integer AUTO_INCREMENT PRIMARY KEY, + fk_loan integer, + datec datetime, + tms timestamp, + datep datetime, + amount_capital real DEFAULT 0, + amount_insurance real DEFAULT 0, + amount_interest real DEFAULT 0, + fk_typepayment integer NOT NULL, + num_payment varchar(50), + note text, + fk_bank integer NOT NULL, + fk_user_creat integer, + fk_user_modif integer +)ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_payment_loan.sql b/htdocs/install/mysql/tables/llx_payment_loan.sql index 83bb3ac2548..0fb6b566ca5 100644 --- a/htdocs/install/mysql/tables/llx_payment_loan.sql +++ b/htdocs/install/mysql/tables/llx_payment_loan.sql @@ -23,7 +23,9 @@ create table llx_payment_loan datec datetime, -- creation date tms timestamp, datep datetime, -- payment date - amount real DEFAULT 0, + amount_capital real DEFAULT 0, + amount_insurance real DEFAULT 0, + amount_interest real DEFAULT 0, fk_typepayment integer NOT NULL, num_payment varchar(50), note text, diff --git a/htdocs/langs/en_US/loan.lang b/htdocs/langs/en_US/loan.lang index 10fb0249f6d..9ccff4eecf4 100644 --- a/htdocs/langs/en_US/loan.lang +++ b/htdocs/langs/en_US/loan.lang @@ -5,10 +5,13 @@ NewLoan=New Loan ShowLoan=Show Loan PaymentLoan=Loan payment Capital=Capital +Insurance=Insurance +Interest=Interest Nbterms=Number of terms LoanAccountancyCapitalCode=Accountancy code capital LoanAccountancyInsuranceCode=Accountancy code insurance LoanAccountancyInterestCode=Accountancy code interest +LoanPayment=Loan payment ConfirmDeleteLoan=Confirm deleting this loan ConfirmPayLoan=Confirm classify paid this loan ErrorLoanCapital=Loan amount has to be numeric and greater than zero. diff --git a/htdocs/langs/fr_FR/loan.lang b/htdocs/langs/fr_FR/loan.lang index 1e54f90e2be..0a5c6320d5b 100644 --- a/htdocs/langs/fr_FR/loan.lang +++ b/htdocs/langs/fr_FR/loan.lang @@ -5,10 +5,13 @@ NewLoan=Nouvel emprunt ShowLoan=Voir emprunt PaymentLoan=Règlement d'emprunt Capital=Capital +Insurance=Assurance +Interest=Intérêt Nbterms=Nombre d'échéances LoanAccountancyCapitalCode=Compte comptable capital LoanAccountancyInsuranceCode=Compte comptable assurance LoanAccountancyInterestCode=Compte comptable intérêts +LoanPayment=Règlement emprunt ConfirmDeleteLoan=Confirmation de supression de cet emprunt ConfirmPayLoan=Confirmation que cet emprunt est classé comme payé ErrorLoanCapital=Le capital de l'emprunt doit être au format numérique et supérieur à zéro.
'.$langs->trans("DateDue").''.$langs->trans("Amount").''.$langs->trans("Capital").''.$langs->trans("AlreadyPaid").''.$langs->trans("RemainderToPay").''.$langs->trans("Amount").''.$langs->trans("Amount").'
".dol_print_date($objp->datestart,'day')."'.dol_print_date($objp->datestart,'day').'!!!!!!'.price($objp->capital)."'.price($objp->capital)."'.price($sumpaid)."'.price($sumpaid)."'.price($objp->capital - $sumpaid)."'.price($objp->capital - $sumpaid)."'; + print ''; if ($sumpaid < $objp->capital) { - $namef = "amount_".$objp->id; - print ''; + $namec = "amount_capital_".$objp->id; + print $langs->trans("Capital") .': '; + } + else + { + print '-'; + } + print '
'; + if ($sumpaid < $objp->capital) + { + $namea = "amount_insurance_".$objp->id; + print $langs->trans("Insurance") .': '; + } + else + { + print '-'; + } + print '
'; + if ($sumpaid < $objp->capital) + { + $namei = "amount_interest_".$objp->id; + print $langs->trans("Interest") .': '; } else { @@ -305,9 +329,9 @@ if ($_GET["action"] == 'create') // Print total print "
'.$langs->trans("Total").':".price($total_ttc)."".price($totalrecu)."".price($total_ttc - $totalrecu).""'.price($total_ttc).'""'.price($totalrecu).'""'.price($total_ttc - $totalrecu).'"