2
0
forked from Wavyzz/dolibarr

Uniformize code

This commit is contained in:
Laurent Destailleur
2015-07-04 04:34:14 +02:00
parent 3520c94641
commit 9321272838
3 changed files with 32 additions and 35 deletions

View File

@@ -229,7 +229,7 @@ if ($action == 'confirm_reject_check' && $confirm == 'yes' && $user->rights->ban
{
$reject_date = dol_mktime(0, 0, 0, GETPOST('rejectdate_month'), GETPOST('rejectdate_day'), GETPOST('rejectdate_year'));
$rejected_check = GETPOST('bankid');
$object->fetch($id);
$paiement_id = $object->reject_check($rejected_check, $reject_date);
if ($paiement_id > 0)
@@ -353,7 +353,7 @@ else
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("ValidateCheckReceipt"), $langs->trans("ConfirmValidateCheckReceipt"), 'confirm_valide','','',1);
}
/*
* Confirm check rejection
*/
@@ -381,7 +381,7 @@ if ($action == 'new')
print '<input type="hidden" name="action" value="new">';
dol_fiche_head();
print '<table class="border" width="100%">';
//print '<tr><td width="30%">'.$langs->trans('Date').'</td><td width="70%">'.dol_print_date($now,'day').'</td></tr>';
// Filter
@@ -392,9 +392,9 @@ if ($action == 'new')
$form->select_comptes($filteraccountid,'accountid',0,'courant <> 2',1);
print '</td></tr>';
print '</table>';
dol_fiche_end();
print '<div class="center">';
print '<input type="submit" class="button" name="filter" value="'.dol_escape_htmltag($langs->trans("ToFilter")).'">';
if ($filterdate || $filteraccountid > 0)
@@ -655,8 +655,7 @@ else
print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"b.amount", "",$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("LineRecord"),$_SERVER["PHP_SELF"],"b.rowid", "",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Payment"),$_SERVER["PHP_SELF"],"p.rowid", "",$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre('');
print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
print "</tr>\n";
$i=1;
$var=false;
@@ -699,17 +698,11 @@ else
print '</td>';
if ($object->statut == 0)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=remove&amp;lineid='.$objp->rowid.'">'.img_delete().'</a></td>';
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=remove&amp;lineid='.$objp->rowid.'">'.img_delete().'</a>';
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reject_check&amp;lineid='.$objp->rowid.'">'.img_picto($langs->trans("RejectCheck"),'disable').'</a></td>';
}
else
{
if($objp->statut == 0)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reject_check&amp;lineid='.$objp->rowid.'">'.img_picto($langs->trans("RejectCheck"),'disable').'</a></td>';
}
else if($objp->statut == 2) {
print '<td align="right">'.img_picto($langs->trans('CheckRejected'),'statut8').'</a></td>';
}
else if($objp->statut == 2) {
print '<td align="right">'.img_picto($langs->trans('CheckRejected'),'statut8').'</a></td>';
}
print '</tr>';
$var=!$var;

View File

@@ -659,7 +659,7 @@ class RemiseCheque extends CommonObject
}
return 0;
}
/**
* Check rejection management
* Reopen linked invoices and saves a new negative payment
@@ -671,34 +671,35 @@ class RemiseCheque extends CommonObject
function reject_check($bank_id, $rejection_date)
{
global $db, $user;
$payment = new Paiement($db);
$payment->fetch(0,$bank_id);
$payment->fetch(0,0,$bank_id);
$bankaccount = $payment->fk_account;
// Get invoice list to reopen them
$sql = 'SELECT pf.fk_facture, pf.amount';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
$sql.= ' WHERE pf.fk_paiement = '.$payment->id;
$resql=$db->query($sql);
if ($resql)
{
$rejectedPayment = new Paiement($db);
$rejectedPayment->amounts = array();
$rejectedPayment->datepaye = $rejection_date;
$rejectedPayment->paiementid = 7; // type of payment: check
$rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement');
$rejectedPayment->num_paiement = $payment->numero;
while($obj = $db->fetch_object($resql)) {
while($obj = $db->fetch_object($resql))
{
$invoice = new Facture($db);
$invoice->fetch($obj->fk_facture);
$invoice->set_unpaid($user);
$rejectedPayment->amounts[$obj->fk_facture] = price2num($obj->amount) * -1;
}
if ($rejectedPayment->create($user) > 0)
{
$result=$rejectedPayment->addPaymentToBank($user,'payment','(CheckRejected)',$bankaccount,'','');
@@ -723,7 +724,7 @@ class RemiseCheque extends CommonObject
return -1;
}
}
/**
* Charge les proprietes ref_previous et ref_next
*
@@ -813,7 +814,7 @@ class RemiseCheque extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
$sql.= " SET number = '".$number."'" ;
$sql.= " WHERE rowid = ".$this->id;
dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)

View File

@@ -79,10 +79,11 @@ class Paiement extends CommonObject
* Load payment from database
*
* @param int $id Id of payment to get
* @param string $ref Ref of payment to get (currently ref = id but this may change in future)
* @param int $fk_bank Id of bank line associated to payment
* @return int <0 if KO, 0 if not found, >0 if OK
*/
function fetch($id, $fk_bank='')
function fetch($id, $ref='', $fk_bank='')
{
$sql = 'SELECT p.rowid, p.datep as dp, p.amount, p.statut, p.fk_bank,';
$sql.= ' c.code as type_code, c.libelle as type_libelle,';
@@ -91,10 +92,12 @@ class Paiement extends CommonObject
$sql.= ' FROM '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement as p';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid ';
$sql.= ' WHERE p.fk_paiement = c.id';
if ($fk_bank)
$sql.= ' AND p.fk_bank = '.$fk_bank;
else
if ($id > 0)
$sql.= ' AND p.rowid = '.$id;
else if ($ref)
$sql.= ' AND p.rowid = '.$ref;
else if ($fk_bank)
$sql.= ' AND p.fk_bank = '.$fk_bank;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result = $this->db->query($sql);
@@ -670,7 +673,7 @@ class Paiement extends CommonObject
return -1;
}
}
/**
* Reject payment
*