forked from Wavyzz/dolibarr
Merge pull request #3131 from atm-maxime/check_rejection
New : Check rejection management
This commit is contained in:
@@ -221,7 +221,26 @@ if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->banque->c
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessage($paiement->error, 'errors');
|
||||
setEventMessage($object->error, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'confirm_reject_check' && $confirm == 'yes' && $user->rights->banque->cheque)
|
||||
{
|
||||
$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)
|
||||
{
|
||||
setEventMessage($langs->trans("CheckRejectedAndInvoicesReopened"));
|
||||
header("Location: ".DOL_URL_ROOT.'/compta/paiement/card.php?id='.$paiement_id);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
setEventMessage($object->error, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,6 +353,18 @@ else
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("ValidateCheckReceipt"), $langs->trans("ConfirmValidateCheckReceipt"), 'confirm_valide','','',1);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Confirm check rejection
|
||||
*/
|
||||
if ($action == 'reject_check')
|
||||
{
|
||||
$formquestion = array(
|
||||
array('type' => 'hidden','name' => 'bankid','value' => GETPOST('lineid')),
|
||||
array('type' => 'date','name' => 'rejectdate_','label' => $langs->trans("RejectCheckDate"),'value' => dol_now())
|
||||
);
|
||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans("RejectCheck"), $langs->trans("ConfirmRejectCheck"), 'confirm_reject_check',$formquestion,'',1);
|
||||
}
|
||||
}
|
||||
|
||||
$accounts = array();
|
||||
@@ -377,10 +408,9 @@ if ($action == 'new')
|
||||
|
||||
$sql = "SELECT ba.rowid as bid, b.datec as datec, b.dateo as date, b.rowid as chqid, ";
|
||||
$sql.= " b.amount, ba.label, b.emetteur, b.num_chq, b.banque";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."bank as b,";
|
||||
$sql.= " ".MAIN_DB_PREFIX."bank_account as ba";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (b.fk_account = ba.rowid)";
|
||||
$sql.= " WHERE b.fk_type = 'CHQ'";
|
||||
$sql.= " AND b.fk_account = ba.rowid";
|
||||
$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")";
|
||||
$sql.= " AND b.fk_bordereau = 0";
|
||||
$sql.= " AND b.amount > 0";
|
||||
@@ -599,12 +629,11 @@ else
|
||||
// Liste des cheques
|
||||
$sql = "SELECT b.rowid, b.amount, b.num_chq, b.emetteur,";
|
||||
$sql.= " b.dateo as date, b.datec as datec, b.banque,";
|
||||
$sql.= " p.rowid as pid, ba.rowid as bid";
|
||||
$sql.= " p.rowid as pid, ba.rowid as bid, p.statut";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."bank as b";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON (b.fk_account = ba.rowid)";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid";
|
||||
$sql.= " WHERE ba.rowid = b.fk_account";
|
||||
$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")";
|
||||
$sql.= " WHERE ba.entity IN (".getEntity('bank_account', 1).")";
|
||||
$sql.= " AND b.fk_type= 'CHQ'";
|
||||
$sql.= " AND b.fk_bordereau = ".$object->id;
|
||||
$sql.= " ORDER BY $sortfield $sortorder";
|
||||
@@ -625,7 +654,9 @@ else
|
||||
print_liste_field_titre($langs->trans("Bank"),$_SERVER["PHP_SELF"],"b.banque", "",$param,"",$sortfield,$sortorder);
|
||||
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 "</tr>\n";
|
||||
$i=1;
|
||||
$var=false;
|
||||
@@ -654,13 +685,31 @@ else
|
||||
print ' ';
|
||||
}
|
||||
print '</td>';
|
||||
print '<td align="center">';
|
||||
$paymentstatic->id=$objp->pid;
|
||||
$paymentstatic->ref=$objp->pid;
|
||||
if ($paymentstatic->id)
|
||||
{
|
||||
print $paymentstatic->getNomUrl(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
print ' ';
|
||||
}
|
||||
print '</td>';
|
||||
if ($object->statut == 0)
|
||||
{
|
||||
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=remove&lineid='.$objp->rowid.'">'.img_delete().'</a></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td> </td>';
|
||||
if($objp->statut == 0)
|
||||
{
|
||||
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reject_check&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>';
|
||||
}
|
||||
}
|
||||
print '</tr>';
|
||||
$var=!$var;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
* \brief File with class to manage cheque delivery receipts
|
||||
*/
|
||||
require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
|
||||
|
||||
|
||||
/**
|
||||
@@ -647,17 +648,82 @@ class RemiseCheque extends CommonObject
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$this->updateAmount();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errno = -1032;
|
||||
dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
|
||||
}
|
||||
{
|
||||
$this->updateAmount();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errno = -1032;
|
||||
dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check rejection management
|
||||
* Reopen linked invoices and saves a new negative payment
|
||||
*
|
||||
* @param int $bank_id Id of bank line concerned
|
||||
* @param date $rejection_date Date to use on the negative payment
|
||||
* @return int
|
||||
*/
|
||||
function reject_check($bank_id, $rejection_date)
|
||||
{
|
||||
global $db, $user;
|
||||
|
||||
$payment = new Paiement($db);
|
||||
$payment->fetch(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->num_paiement = $payment->numero;
|
||||
|
||||
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,'','');
|
||||
if ($result > 0)
|
||||
{
|
||||
$payment->reject();
|
||||
return $rejectedPayment->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge les proprietes ref_previous et ref_next
|
||||
*
|
||||
|
||||
@@ -78,11 +78,11 @@ class Paiement extends CommonObject
|
||||
/**
|
||||
* Load payment from database
|
||||
*
|
||||
* @param int $id Id of payment to get
|
||||
* @param int $ref Ref of payment to get (same as $id)
|
||||
* @return int <0 if KO, 0 if not found, >0 if OK
|
||||
* @param int $id Id of payment to get
|
||||
* @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, $ref='')
|
||||
function fetch($id, $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,8 +91,8 @@ 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 ($ref)
|
||||
$sql.= ' AND p.rowid = '.$ref;
|
||||
if ($fk_bank)
|
||||
$sql.= ' AND p.fk_bank = '.$fk_bank;
|
||||
else
|
||||
$sql.= ' AND p.rowid = '.$id;
|
||||
|
||||
@@ -116,7 +116,8 @@ class Paiement extends CommonObject
|
||||
$this->type_code = $obj->type_code;
|
||||
$this->statut = $obj->statut;
|
||||
|
||||
$this->bank_account = $obj->fk_account;
|
||||
$this->bank_account = $obj->fk_account; // deprecated
|
||||
$this->fk_account = $obj->fk_account;
|
||||
$this->bank_line = $obj->fk_bank;
|
||||
|
||||
$this->db->free($result);
|
||||
@@ -669,6 +670,29 @@ class Paiement extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject payment
|
||||
*
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function reject()
|
||||
{
|
||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 2 WHERE rowid = '.$this->id;
|
||||
|
||||
dol_syslog(get_class($this).'::reject', LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog(get_class($this).'::reject '.$this->error);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* \brief Information sur l'objet
|
||||
|
||||
@@ -3167,6 +3167,18 @@ class Form
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else if ($input['type'] == 'date')
|
||||
{
|
||||
$more.='<tr><td>'.$input['label'].'</td>';
|
||||
$more.='<td colspan="2" align="left">';
|
||||
$more.=$this->select_date($input['value'],$input['name'],0,0,0,'',1,0,1);
|
||||
$more.='</td></tr>'."\n";
|
||||
$formquestion[] = array('name'=>$input['name'].'day');
|
||||
$formquestion[] = array('name'=>$input['name'].'month');
|
||||
$formquestion[] = array('name'=>$input['name'].'year');
|
||||
$formquestion[] = array('name'=>$input['name'].'hour');
|
||||
$formquestion[] = array('name'=>$input['name'].'min');
|
||||
}
|
||||
else if ($input['type'] == 'other')
|
||||
{
|
||||
$more.='<tr><td>';
|
||||
|
||||
@@ -57,7 +57,8 @@ function showDP(base,dateFieldID,format,codelang)
|
||||
|
||||
showDP.box=document.createElement("div");
|
||||
showDP.box.className="bodyline";
|
||||
showDP.box.style.siplay="block";
|
||||
showDP.box.style.display="block";
|
||||
showDP.box.style.zIndex="1000";
|
||||
showDP.box.style.position="absolute";
|
||||
showDP.box.style.top=thetop + "px";
|
||||
showDP.box.style.left=theleft + "px";
|
||||
|
||||
@@ -165,3 +165,8 @@ DeleteARib=Delete BAN record
|
||||
ConfirmDeleteRib=Are you sure you want to delete this BAN record ?
|
||||
StartDate=Start date
|
||||
EndDate=End date
|
||||
RejectCheck=Check rejection
|
||||
ConfirmRejectCheck=Are you sure you want to mark this check as rejected ?
|
||||
RejectCheckDate=Check rejection date
|
||||
CheckRejected=Check rejected
|
||||
CheckRejectedAndInvoicesReopened=Check rejected and invoices reopened
|
||||
|
||||
Reference in New Issue
Block a user