Debug payment loan

This commit is contained in:
frederic34 2015-03-29 11:39:55 +02:00
parent be1595a187
commit bf3e78a63d
4 changed files with 76 additions and 122 deletions

View File

@ -86,24 +86,18 @@ class PaymentLoan extends CommonObject
// Clean parameters // Clean parameters
if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan); 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_capital)) $this->amount_capital = trim($this->amount_capital?$this->amount_capital:0);
if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance); 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); 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->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment);
if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); 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_private)) $this->note_private = trim($this->note_private);
if (isset($this->note_public)) $this->note = trim($this->note_public); 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_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_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); if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif);
$totalamount = 0; $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest;
foreach ($this->amounts as $key => $value) // How payment is dispatch
{
$newvalue = price2num($value,'MT');
$this->amounts[$key] = $newvalue;
$totalamount += $newvalue;
}
$totalamount = price2num($totalamount); $totalamount = price2num($totalamount);
// Check parameters // 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.= " fk_typepayment, num_payment, note_private, note_public, fk_user_creat, fk_bank)";
$sql.= " VALUES (".$this->chid.", '".$this->db->idate($now)."',"; $sql.= " VALUES (".$this->chid.", '".$this->db->idate($now)."',";
$sql.= " '".$this->db->idate($this->datepaid)."',"; $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.= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', '".$this->db->escape($this->note_public)."', ".$user->id.",";
$sql.= " 0)"; $sql.= " 0)";
@ -145,7 +141,7 @@ class PaymentLoan extends CommonObject
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->lasterror();
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
@ -509,7 +505,7 @@ class PaymentLoan extends CommonObject
* @param int $maxlen Max length label * @param int $maxlen Max length label
* @return string Chaine with URL * @return string Chaine with URL
*/ */
function getNameUrl($withpicto=0,$maxlen=0) function getNomUrl($withpicto=0,$maxlen=0)
{ {
global $langs; global $langs;

View File

@ -40,7 +40,7 @@ $result = restrictedArea($user, 'loan', $id, '&loan');
$object = new Loan($db); $object = new Loan($db);
if ($id > 0) $object->fetch($id); 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 '<br>'; print '<br>';
$colwidth='25'; $colwidth='25';
$permission = $user->rights->loan->write; // Used by the include of notes.tpl.php
include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';

View File

@ -32,7 +32,6 @@ $langs->load("loan");
$chid=GETPOST('id','int'); $chid=GETPOST('id','int');
$action=GETPOST('action'); $action=GETPOST('action');
$amounts = array();
$cancel=GETPOST('cancel','alpha'); $cancel=GETPOST('cancel','alpha');
// Security check // 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')); $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'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode")), 'errors');
$error++; $error++;
@ -68,7 +67,7 @@ if ($action == 'add_payment')
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Date")), 'errors'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Date")), 'errors');
$error++; $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'); setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit")), 'errors');
$error++; $error++;
@ -78,17 +77,8 @@ if ($action == 'add_payment')
{ {
$paymentid = 0; $paymentid = 0;
// Read possible payments $amount = GETPOST('amount_capital') + GETPOST('amount_insurance') + GETPOST('amount_interest');
foreach ($_POST as $key => $value) if ($amount == 0)
{
if (substr($key,0,7) == 'amount_')
{
$other_chid = substr($key,7);
$amounts[$other_chid] = price2num($_POST[$key]);
}
}
if (count($amounts) <= 0)
{ {
setEventMessage($langs->trans('ErrorNoPaymentDefined'), 'errors'); setEventMessage($langs->trans('ErrorNoPaymentDefined'), 'errors');
$error++; $error++;
@ -102,7 +92,6 @@ if ($action == 'add_payment')
$payment = new PaymentLoan($db); $payment = new PaymentLoan($db);
$payment->chid = $chid; $payment->chid = $chid;
$payment->datepaid = $datepaid; $payment->datepaid = $datepaid;
$payment->amounts = $amounts; // Tableau de montant
$payment->amount_capital = GETPOST('amount_capital'); $payment->amount_capital = GETPOST('amount_capital');
$payment->amount_insurance = GETPOST('amount_insurance'); $payment->amount_insurance = GETPOST('amount_insurance');
$payment->amount_interest = GETPOST('amount_interest'); $payment->amount_interest = GETPOST('amount_interest');
@ -123,7 +112,7 @@ if ($action == 'add_payment')
if (! $error) 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) if (! $result > 0)
{ {
setEventMessage($payment->error, 'errors'); setEventMessage($payment->error, 'errors');
@ -185,9 +174,9 @@ if ($_GET["action"] == 'create')
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$loan->label."</td></tr>\n"; print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$loan->label."</td></tr>\n";
print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">'.price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>'; print '<tr><td>'.$langs->trans("Amount").'</td><td colspan="2">'.price($loan->capital,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
$sql = "SELECT sum(p.amount) as total"; $sql = "SELECT SUM(amount_capital + amount_insurance + amount_interest) as total";
$sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan";
$sql.= " WHERE p.fk_loan = ".$chid; $sql.= " WHERE fk_loan = ".$chid;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
@ -195,8 +184,8 @@ if ($_GET["action"] == 'create')
$sumpaid = $obj->total; $sumpaid = $obj->total;
$db->free(); $db->free();
} }
print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td colspan="2">'.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>'; print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td colspan="2">'.price($sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
print '<tr><td valign="top">'.$langs->trans("RemainderToPay").'</td><td colspan="2">'.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>'; print '<tr><td valign="top">'.$langs->trans("RemainderToPay").'</td><td colspan="2">'.price($total-$sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
print '</tr>'; print '</tr>';
print '</table>'; print '</table>';
@ -209,9 +198,9 @@ if ($_GET["action"] == 'create')
print '</tr>'; print '</tr>';
print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("Date").'</td><td colspan="2">'; print '<tr><td width="25%" class="fieldrequired">'.$langs->trans("Date").'</td><td colspan="2">';
$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; $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 "</td>"; print "</td>";
print '</tr>'; print '</tr>';
@ -227,7 +216,7 @@ if ($_GET["action"] == 'create')
print '</td></tr>'; print '</td></tr>';
// Number // Number
print '<tr><td>'.$langs->trans('Number'); print '<tr><td>'.$langs->trans('Numero');
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>'; print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
print '</td>'; print '</td>';
print '<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST('num_payment').'"></td></tr>'."\n"; print '<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST('num_payment').'"></td></tr>'."\n";
@ -245,12 +234,6 @@ if ($_GET["action"] == 'create')
print '<br>'; print '<br>';
/*
* Other loan unpaid
*/
$num = 1;
$i = 0;
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td align="left">'.$langs->trans("DateDue").'</td>'; print '<td align="left">'.$langs->trans("DateDue").'</td>';
@ -261,57 +244,47 @@ if ($_GET["action"] == 'create')
print "</tr>\n"; print "</tr>\n";
$var=True; $var=True;
$total=0;
$totalrecu=0;
while ($i < $num)
{
$objp = $loan;
$var=!$var;
print "<tr ".$bc[$var].">"; print "<tr ".$bc[$var].">";
if ($objp->datestart > 0) if ($loan->datestart > 0)
{ {
print '<td align="left" valign="center">'.dol_print_date($objp->datestart,'day').'</td>'; print '<td align="left" valign="center">'.dol_print_date($loan->datestart,'day').'</td>';
} }
else else
{ {
print '<td align="center" valign="center"><b>!!!</b></td>'; print '<td align="center" valign="center"><b>!!!</b></td>';
} }
print '<td align="right" valign="center">'.price($objp->capital)."</td>"; print '<td align="right" valign="center">'.price($loan->capital)."</td>";
print '<td align="right" valign="center">'.price($sumpaid)."</td>"; print '<td align="right" valign="center">'.price($sumpaid)."</td>";
print '<td align="right" valign="center">'.price($objp->capital - $sumpaid)."</td>"; print '<td align="right" valign="center">'.price($loan->capital - $sumpaid)."</td>";
print '<td align="right">'; print '<td align="right">';
if ($sumpaid < $objp->capital) if ($sumpaid < $loan->capital)
{ {
$namec = "amount_capital_".$objp->id; print $langs->trans("Capital") .': <input type="text" size="8" name="amount_capital">';
print $langs->trans("Capital") .': <input type="text" size="8" name="'.$namec.'">';
} }
else else
{ {
print '-'; print '-';
} }
print '<br>'; print '<br>';
if ($sumpaid < $objp->capital) if ($sumpaid < $loan->capital)
{ {
$namea = "amount_insurance_".$objp->id; print $langs->trans("Insurance") .': <input type="text" size="8" name="amount_insurance">';
print $langs->trans("Insurance") .': <input type="text" size="8" name="'.$namea.'">';
} }
else else
{ {
print '-'; print '-';
} }
print '<br>'; print '<br>';
if ($sumpaid < $objp->capital) if ($sumpaid < $loan->capital)
{ {
$namei = "amount_interest_".$objp->id; print $langs->trans("Interest") .': <input type="text" size="8" name="amount_interest">';
print $langs->trans("Interest") .': <input type="text" size="8" name="'.$namei.'">';
} }
else else
{ {
@ -320,24 +293,8 @@ if ($_GET["action"] == 'create')
print "</td>"; print "</td>";
print "</tr>\n"; print "</tr>\n";
$total+=$objp->total;
$total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am;
$i++;
}
if ($i > 1)
{
// Print total
print "<tr ".$bc[!$var].">";
print '<td colspan="2" align="left">'.$langs->trans("Total").':</td>';
print '<td align="right"><b>"'.price($total_ttc).'"</b></td>';
print '<td align="right"><b>"'.price($totalrecu).'"</b></td>';
print '<td align="right"><b>"'.price($total_ttc - $totalrecu).'"</b></td>';
print '<td align="center">&nbsp;</td>';
print "</tr>\n";
}
print "</table>"; print '</table>';
print '<br><center>'; print '<br><center>';