Fix : withdrawal rejection were taking the total amount of the invoice instead of the amount of the withdrawal
This commit is contained in:
parent
bd4d108217
commit
20bdfdb286
@ -87,7 +87,7 @@ class RejetPrelevement
|
|||||||
|
|
||||||
dol_syslog("RejetPrelevement::Create id $id");
|
dol_syslog("RejetPrelevement::Create id $id");
|
||||||
$bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
|
$bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
|
||||||
$facs = $this->getListInvoices();
|
$facs = $this->getListInvoices(1);
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ class RejetPrelevement
|
|||||||
for ($i = 0; $i < $num; $i++)
|
for ($i = 0; $i < $num; $i++)
|
||||||
{
|
{
|
||||||
$fac = new Facture($this->db);
|
$fac = new Facture($this->db);
|
||||||
$fac->fetch($facs[$i]);
|
$fac->fetch($facs[$i][0]);
|
||||||
|
|
||||||
// Make a negative payment
|
// Make a negative payment
|
||||||
$pai = new Paiement($this->db);
|
$pai = new Paiement($this->db);
|
||||||
@ -144,7 +144,7 @@ class RejetPrelevement
|
|||||||
* PHP installs sends only the part integer negative
|
* PHP installs sends only the part integer negative
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$pai->amounts[$facs[$i]] = price2num($fac->total_ttc * -1);
|
$pai->amounts[$facs[$i][0]] = price2num($facs[$i][1] * -1);
|
||||||
$pai->datepaye = $date_rejet;
|
$pai->datepaye = $date_rejet;
|
||||||
$pai->paiementid = 3; // type of payment: withdrawal
|
$pai->paiementid = 3; // type of payment: withdrawal
|
||||||
$pai->num_paiement = $fac->ref;
|
$pai->num_paiement = $fac->ref;
|
||||||
@ -152,7 +152,7 @@ class RejetPrelevement
|
|||||||
if ($pai->create($this->user) < 0) // we call with no_commit
|
if ($pai->create($this->user) < 0) // we call with no_commit
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
dol_syslog("RejetPrelevement::Create Error creation payment invoice ".$facs[$i]);
|
dol_syslog("RejetPrelevement::Create Error creation payment invoice ".$facs[$i][0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -269,22 +269,24 @@ class RejetPrelevement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the list of invoices
|
* Retrieve the list of invoices
|
||||||
|
* @param int $amounts If you want to get the amount of the order for each invoice
|
||||||
*
|
*
|
||||||
* @return void
|
* @return Array List of invoices related to the withdrawal line
|
||||||
|
* @TODO A withdrawal line is today linked to one and only one invoice. So the function should return only one object ?
|
||||||
*/
|
*/
|
||||||
private function getListInvoices()
|
private function getListInvoices($amounts=0)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$arr = array();
|
$arr = array();
|
||||||
|
|
||||||
//Returns all invoices of a withdrawal
|
//Returns all invoices of a withdrawal
|
||||||
$sql = "SELECT f.rowid as facid";
|
$sql = "SELECT f.rowid as facid, pl.amount";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_facture as pf";
|
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_facture as pf";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."facture as f";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON (pf.fk_facture = f.rowid)";
|
||||||
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."prelevement_lignes as pl ON (pf.fk_prelevement_lignes = pl.rowid)";
|
||||||
$sql.= " WHERE pf.fk_prelevement_lignes = ".$this->id;
|
$sql.= " WHERE pf.fk_prelevement_lignes = ".$this->id;
|
||||||
$sql.= " AND pf.fk_facture = f.rowid";
|
|
||||||
$sql.= " AND f.entity = ".$conf->entity;
|
$sql.= " AND f.entity = ".$conf->entity;
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
@ -298,7 +300,14 @@ class RejetPrelevement
|
|||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$row = $this->db->fetch_row($resql);
|
$row = $this->db->fetch_row($resql);
|
||||||
$arr[$i] = $row[0];
|
if (!$amounts) $arr[$i] = $row[0];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$arr[$i] = array(
|
||||||
|
$row[0],
|
||||||
|
$row[1]
|
||||||
|
);
|
||||||
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user