Skip to content
Snippets Groups Projects
Commit d7e9bcca authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Merge pull request #3199 from atm-maxime/fix_rejet_prel

Fix : withdrawal rejection were taking the total amount of the invoic…
parents bd4d1082 20bdfdb2
No related branches found
No related tags found
No related merge requests found
...@@ -87,7 +87,7 @@ class RejetPrelevement ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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
{ {
...@@ -270,21 +270,23 @@ class RejetPrelevement ...@@ -270,21 +270,23 @@ 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 ...@@ -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++;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment