Skip to content

Commit

Permalink
Debug payment loan
Browse files Browse the repository at this point in the history
  • Loading branch information
frederic34 committed Mar 29, 2015
1 parent be1595a commit bf3e78a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 122 deletions.
2 changes: 1 addition & 1 deletion htdocs/loan/class/loan.class.php
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
/* Copyright (C) 2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
Expand Down
30 changes: 13 additions & 17 deletions htdocs/loan/class/paymentloan.class.php
Expand Up @@ -86,24 +86,18 @@ function create($user)

// 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
Expand All @@ -118,7 +112,9 @@ function create($user)
$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)";

Expand All @@ -145,7 +141,7 @@ function create($user)
}
else
{
$this->error=$this->db->error();
$this->error=$this->db->lasterror();
$this->db->rollback();
return -1;
}
Expand Down Expand Up @@ -190,8 +186,8 @@ function fetch($id)
{
$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);
Expand Down Expand Up @@ -509,7 +505,7 @@ function update_fk_bank($id_bank)
* @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;

Expand Down
3 changes: 2 additions & 1 deletion htdocs/loan/note.php
Expand Up @@ -40,7 +40,7 @@
$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


/*
Expand Down Expand Up @@ -88,6 +88,7 @@
print '<br>';

$colwidth='25';
$permission = $user->rights->loan->write; // Used by the include of notes.tpl.php
include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';


Expand Down
163 changes: 60 additions & 103 deletions htdocs/loan/payment/payment.php
Expand Up @@ -32,7 +32,6 @@

$chid=GETPOST('id','int');
$action=GETPOST('action');
$amounts = array();
$cancel=GETPOST('cancel','alpha');

// Security check
Expand All @@ -58,7 +57,7 @@

$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++;
Expand All @@ -68,7 +67,7 @@
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++;
Expand All @@ -78,17 +77,8 @@
{
$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++;
Expand All @@ -102,7 +92,6 @@
$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');
Expand All @@ -123,7 +112,7 @@

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');
Expand Down Expand Up @@ -185,33 +174,33 @@
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>';

$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)
{
$obj=$db->fetch_object($resql);
$sumpaid = $obj->total;
$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 valign="top">'.$langs->trans("RemainderToPay").'</td><td colspan="2">'.price($total-$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>';

print '</table>';

print '<br>';

print '<table cellspacing="0" class="border" width="100%" cellpadding="2">';
print '<tr class="liste_titre">';
print '<td colspan="3">'.$langs->trans("Payment").'</td>';
print '</tr>';

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;
$form->select_date($datepayment,'','','','',"add_payment",1,1);
$form->select_date($datepayment, '', '', '', '', "add_payment", 1, 1);
print "</td>";
print '</tr>';

Expand All @@ -227,7 +216,7 @@
print '</td></tr>';

// Number
print '<tr><td>'.$langs->trans('Number');
print '<tr><td>'.$langs->trans('Numero');
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
print '</td>';
print '<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST('num_payment').'"></td></tr>'."\n";
Expand All @@ -245,12 +234,6 @@

print '<br>';

/*
* Other loan unpaid
*/
$num = 1;
$i = 0;

print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td align="left">'.$langs->trans("DateDue").'</td>';
Expand All @@ -261,83 +244,57 @@
print "</tr>\n";

$var=True;
$total=0;
$totalrecu=0;

while ($i < $num)

print "<tr ".$bc[$var].">";

if ($loan->datestart > 0)
{
print '<td align="left" valign="center">'.dol_print_date($loan->datestart,'day').'</td>';
}
else
{
print '<td align="center" valign="center"><b>!!!</b></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($loan->capital - $sumpaid)."</td>";

print '<td align="right">';
if ($sumpaid < $loan->capital)
{
$objp = $loan;

$var=!$var;

print "<tr ".$bc[$var].">";

if ($objp->datestart > 0)
{
print '<td align="left" valign="center">'.dol_print_date($objp->datestart,'day').'</td>';
}
else
{
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($sumpaid)."</td>";

print '<td align="right" valign="center">'.price($objp->capital - $sumpaid)."</td>";

print '<td align="right">';
if ($sumpaid < $objp->capital)
{
$namec = "amount_capital_".$objp->id;
print $langs->trans("Capital") .': <input type="text" size="8" name="'.$namec.'">';
}
else
{
print '-';
}
print '<br>';
if ($sumpaid < $objp->capital)
{
$namea = "amount_insurance_".$objp->id;
print $langs->trans("Insurance") .': <input type="text" size="8" name="'.$namea.'">';
}
else
{
print '-';
}
print '<br>';
if ($sumpaid < $objp->capital)
{
$namei = "amount_interest_".$objp->id;
print $langs->trans("Interest") .': <input type="text" size="8" name="'.$namei.'">';
}
else
{
print '-';
}
print "</td>";

print "</tr>\n";
$total+=$objp->total;
$total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am;
$i++;
print $langs->trans("Capital") .': <input type="text" size="8" name="amount_capital">';
}
if ($i > 1)
else
{
// 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 '-';
}
print '<br>';
if ($sumpaid < $loan->capital)
{
print $langs->trans("Insurance") .': <input type="text" size="8" name="amount_insurance">';
}
else
{
print '-';
}
print '<br>';
if ($sumpaid < $loan->capital)
{
print $langs->trans("Interest") .': <input type="text" size="8" name="amount_interest">';
}
else
{
print '-';
}
print "</td>";

print "</table>";
print "</tr>\n";

print '</table>';

print '<br><center>';

Expand Down

0 comments on commit bf3e78a

Please sign in to comment.