From bf3e78a63df84025b1bfda7ce16b254ebfc31312 Mon Sep 17 00:00:00 2001 From: frederic34 Date: Sun, 29 Mar 2015 11:39:55 +0200 Subject: [PATCH] Debug payment loan --- htdocs/loan/class/loan.class.php | 2 +- htdocs/loan/class/paymentloan.class.php | 30 ++--- htdocs/loan/note.php | 3 +- htdocs/loan/payment/payment.php | 163 +++++++++--------------- 4 files changed, 76 insertions(+), 122 deletions(-) diff --git a/htdocs/loan/class/loan.class.php b/htdocs/loan/class/loan.class.php index cf58bb1d2c4..c2c0bba6381 100644 --- a/htdocs/loan/class/loan.class.php +++ b/htdocs/loan/class/loan.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2014 Alexandre Spangaro * Copyright (C) 2015 Frederic France * * This program is free software; you can redistribute it and/or modify diff --git a/htdocs/loan/class/paymentloan.class.php b/htdocs/loan/class/paymentloan.class.php index 41b64bcd865..a4e5aa4ad61 100644 --- a/htdocs/loan/class/paymentloan.class.php +++ b/htdocs/loan/class/paymentloan.class.php @@ -86,24 +86,18 @@ class PaymentLoan extends CommonObject // Clean parameters if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan); - 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->amount_capital)) $this->amount_capital = trim($this->amount_capital?$this->amount_capital:0); + if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance?$this->amount_insurance:0); + if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest?$this->amount_interest:0); 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_private)) $this->note = trim($this->note_private); - if (isset($this->note_public)) $this->note = trim($this->note_public); + 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->fk_bank)) $this->fk_bank = trim($this->fk_bank); if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat); if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif); - $totalamount = 0; - foreach ($this->amounts as $key => $value) // How payment is dispatch - { - $newvalue = price2num($value,'MT'); - $this->amounts[$key] = $newvalue; - $totalamount += $newvalue; - } + $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest; $totalamount = price2num($totalamount); // Check parameters @@ -118,7 +112,9 @@ class PaymentLoan extends CommonObject $sql.= " fk_typepayment, num_payment, note_private, note_public, fk_user_creat, fk_bank)"; $sql.= " VALUES (".$this->chid.", '".$this->db->idate($now)."',"; $sql.= " '".$this->db->idate($this->datepaid)."',"; - $sql.= " ".$totalamount.","; + $sql.= " ".$this->amount_capital.","; + $sql.= " ".$this->amount_insurance.","; + $sql.= " ".$this->amount_interest.","; $sql.= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', '".$this->db->escape($this->note_public)."', ".$user->id.","; $sql.= " 0)"; @@ -145,7 +141,7 @@ class PaymentLoan extends CommonObject } else { - $this->error=$this->db->error(); + $this->error=$this->db->lasterror(); $this->db->rollback(); return -1; } @@ -190,8 +186,8 @@ class PaymentLoan extends CommonObject { $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - $this->ref = $obj->rowid; + $this->id = $obj->rowid; + $this->ref = $obj->rowid; $this->fk_loan = $obj->fk_loan; $this->datec = $this->db->jdate($obj->datec); @@ -509,7 +505,7 @@ class PaymentLoan extends CommonObject * @param int $maxlen Max length label * @return string Chaine with URL */ - function getNameUrl($withpicto=0,$maxlen=0) + function getNomUrl($withpicto=0,$maxlen=0) { global $langs; diff --git a/htdocs/loan/note.php b/htdocs/loan/note.php index a87cd3870d8..28f2a0f4918 100644 --- a/htdocs/loan/note.php +++ b/htdocs/loan/note.php @@ -40,7 +40,7 @@ $result = restrictedArea($user, 'loan', $id, '&loan'); $object = new Loan($db); if ($id > 0) $object->fetch($id); -$permissionnote=$user->rights->loan->read; // Used by the include of actions_setnotes.inc.php +$permissionnote=$user->rights->loan->write; // Used by the include of actions_setnotes.inc.php /* @@ -88,6 +88,7 @@ if ($id > 0) print '
'; $colwidth='25'; + $permission = $user->rights->loan->write; // Used by the include of notes.tpl.php include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; diff --git a/htdocs/loan/payment/payment.php b/htdocs/loan/payment/payment.php index 52921bc6b18..ece4a5e0271 100644 --- a/htdocs/loan/payment/payment.php +++ b/htdocs/loan/payment/payment.php @@ -32,7 +32,6 @@ $langs->load("loan"); $chid=GETPOST('id','int'); $action=GETPOST('action'); -$amounts = array(); $cancel=GETPOST('cancel','alpha'); // Security check @@ -58,7 +57,7 @@ if ($action == 'add_payment') $datepaid = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); - if (! $_POST["paymenttype"] > 0) + if (! GETPOST('paymenttype', 'int') > 0) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")), 'errors'); $error++; @@ -68,7 +67,7 @@ if ($action == 'add_payment') setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Date")), 'errors'); $error++; } - if (! empty($conf->banque->enabled) && ! $_POST["accountid"] > 0) + if (! empty($conf->banque->enabled) && ! GETPOST('accountid', 'int') > 0) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit")), 'errors'); $error++; @@ -78,17 +77,8 @@ if ($action == 'add_payment') { $paymentid = 0; - // Read possible payments - foreach ($_POST as $key => $value) - { - if (substr($key,0,7) == 'amount_') - { - $other_chid = substr($key,7); - $amounts[$other_chid] = price2num($_POST[$key]); - } - } - - if (count($amounts) <= 0) + $amount = GETPOST('amount_capital') + GETPOST('amount_insurance') + GETPOST('amount_interest'); + if ($amount == 0) { setEventMessage($langs->trans('ErrorNoPaymentDefined'), 'errors'); $error++; @@ -102,7 +92,6 @@ if ($action == 'add_payment') $payment = new PaymentLoan($db); $payment->chid = $chid; $payment->datepaid = $datepaid; - $payment->amounts = $amounts; // Tableau de montant $payment->amount_capital = GETPOST('amount_capital'); $payment->amount_insurance = GETPOST('amount_insurance'); $payment->amount_interest = GETPOST('amount_interest'); @@ -123,7 +112,7 @@ if ($action == 'add_payment') if (! $error) { - $result=$payment->addPaymentToBank($user, 'payment_loan', '(LoanPayment)', GETPOST('accountid', 'int'), '', ''); + $result = $payment->addPaymentToBank($user, 'payment_loan', '(LoanPayment)', GETPOST('accountid', 'int'), '', ''); if (! $result > 0) { setEventMessage($payment->error, 'errors'); @@ -185,9 +174,9 @@ if ($_GET["action"] == 'create') print ''.$langs->trans("Label").''.$loan->label."\n"; print ''.$langs->trans("Amount").''.price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).''; - $sql = "SELECT sum(p.amount) as total"; - $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; - $sql.= " WHERE p.fk_loan = ".$chid; + $sql = "SELECT SUM(amount_capital + amount_insurance + amount_interest) as total"; + $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan"; + $sql.= " WHERE fk_loan = ".$chid; $resql = $db->query($sql); if ($resql) { @@ -195,23 +184,23 @@ if ($_GET["action"] == 'create') $sumpaid = $obj->total; $db->free(); } - print ''.$langs->trans("AlreadyPaid").''.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).''; - print ''.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).''; + print ''.$langs->trans("AlreadyPaid").''.price($sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).''; + print ''.$langs->trans("RemainderToPay").''.price($total-$sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).''; print ''; print ''; - + print '
'; - + print ''; print ''; print ''; print ''; print '"; print ''; @@ -227,7 +216,7 @@ if ($_GET["action"] == 'create') print ''; // Number - print ''; print ''."\n"; @@ -245,12 +234,6 @@ if ($_GET["action"] == 'create') print '
'; - /* - * Other loan unpaid - */ - $num = 1; - $i = 0; - print '
'.$langs->trans("Payment").'
'.$langs->trans("Date").''; - $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $datepaid = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0; - $form->select_date($datepayment,'','','','',"add_payment",1,1); + $form->select_date($datepayment, '', '', '', '', "add_payment", 1, 1); print "
'.$langs->trans('Number'); + print '
'.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print '
'; print ''; print ''; @@ -261,83 +244,57 @@ if ($_GET["action"] == 'create') print "\n"; $var=True; - $total=0; - $totalrecu=0; - while ($i < $num) + + print ""; + + if ($loan->datestart > 0) { - $objp = $loan; - - $var=!$var; - - print ""; - - if ($objp->datestart > 0) - { - print ''; - } - else - { - print ''; - } - - print '"; - - print '"; - - print '"; - - print '"; - - print "\n"; - $total+=$objp->total; - $total_ttc+=$objp->total_ttc; - $totalrecu+=$objp->am; - $i++; + print ''; } - if ($i > 1) + else { - // Print total - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; + print ''; } - print "
'.$langs->trans("DateDue").'
'.dol_print_date($objp->datestart,'day').'!!!'.price($objp->capital)."'.price($sumpaid)."'.price($objp->capital - $sumpaid)."'; - if ($sumpaid < $objp->capital) - { - $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 - { - print '-'; - } - print "
'.dol_print_date($loan->datestart,'day').'
'.$langs->trans("Total").':"'.price($total_ttc).'""'.price($totalrecu).'""'.price($total_ttc - $totalrecu).'" 
!!!
"; + print ''.price($loan->capital).""; + + print ''.price($sumpaid).""; + + print ''.price($loan->capital - $sumpaid).""; + + print ''; + if ($sumpaid < $loan->capital) + { + print $langs->trans("Capital") .': '; + } + else + { + print '-'; + } + print '
'; + if ($sumpaid < $loan->capital) + { + print $langs->trans("Insurance") .': '; + } + else + { + print '-'; + } + print '
'; + if ($sumpaid < $loan->capital) + { + print $langs->trans("Interest") .': '; + } + else + { + print '-'; + } + print ""; + + print "\n"; + + print ''; print '
';