From d7fbddb8e1387b382a64bf3f83c4a11ccf6fa183 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 28 Jun 2021 16:45:29 +0200 Subject: [PATCH] Add rowid/ref in response --- htdocs/societe/class/societe.class.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index fdfd32cb5d8..a213cca5577 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4383,21 +4383,24 @@ class Societe extends CommonObject $table = 'supplier_proposal'; } - $sql = "SELECT rowid, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f"; - $sql .= " WHERE fk_soc = ".$this->id; + $sql = "SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f"; + $sql .= " WHERE fk_soc = ".((int) $this->id); if ($mode == 'supplier') { $sql .= " AND entity IN (".getEntity('supplier_proposal').")"; } else { $sql .= " AND entity IN (".getEntity('propal').")"; } - dol_syslog("getOutstandingProposals", LOG_DEBUG); + dol_syslog("getOutstandingProposals for fk_soc = ".((int) $this->id), LOG_DEBUG); + $resql = $this->db->query($sql); if ($resql) { $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; + $arrayofref = array(); while ($obj = $this->db->fetch_object($resql)) { + $arrayofref[$obj->rowid] = $obj->ref; $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; if ($obj->status != 0) { @@ -4405,7 +4408,7 @@ class Societe extends CommonObject $outstandingOpened += $obj->total_ttc; } } - return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' + return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax, 'refs'=>$arrayofref); // 'opened' is 'incl taxes' } else { return array(); } @@ -4424,8 +4427,8 @@ class Societe extends CommonObject $table = 'commande_fournisseur'; } - $sql = "SELECT rowid, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f"; - $sql .= " WHERE fk_soc = ".$this->id; + $sql = "SELECT rowid, ref, total_ht, total_ttc, fk_statut as status FROM ".MAIN_DB_PREFIX.$table." as f"; + $sql .= " WHERE fk_soc = ".((int) $this->id); if ($mode == 'supplier') { $sql .= " AND entity IN (".getEntity('supplier_order').")"; } else { @@ -4438,7 +4441,9 @@ class Societe extends CommonObject $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; + $arrayofref = array(); while ($obj = $this->db->fetch_object($resql)) { + $arrayofref[$obj->rowid] = $obj->ref; $outstandingTotal += $obj->total_ht; $outstandingTotalIncTax += $obj->total_ttc; if ($obj->status != 0) { @@ -4446,7 +4451,7 @@ class Societe extends CommonObject $outstandingOpened += $obj->total_ttc; } } - return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' + return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax, 'refs'=>$arrayofref); // 'opened' is 'incl taxes' } else { return array(); } @@ -4473,7 +4478,7 @@ class Societe extends CommonObject $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); */ - $sql = "SELECT rowid, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + $sql = "SELECT rowid, ref, total_ht, total_ttc, paye, type, fk_statut as status, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; $sql .= " WHERE fk_soc = ".((int) $this->id); if (!empty($late)) { $sql .= " AND date_lim_reglement < '".$this->db->idate(dol_now())."'"; @@ -4490,6 +4495,7 @@ class Societe extends CommonObject $outstandingOpened = 0; $outstandingTotal = 0; $outstandingTotalIncTax = 0; + $arrayofref = array(); if ($mode == 'supplier') { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; $tmpobject = new FactureFournisseur($this->db); @@ -4498,6 +4504,7 @@ class Societe extends CommonObject $tmpobject = new Facture($this->db); } while ($obj = $this->db->fetch_object($resql)) { + $arrayofref[$obj->rowid] = $obj->ref; $tmpobject->id = $obj->rowid; if ($obj->status != $tmpobject::STATUS_DRAFT // Not a draft @@ -4524,7 +4531,7 @@ class Societe extends CommonObject $outstandingOpened -= $tmpobject->getSumFromThisCreditNotesNotUsed(); } } - return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes' + return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax, 'refs'=>$arrayofref); // 'opened' is 'incl taxes' } else { dol_syslog("Sql error ".$this->db->lasterror, LOG_ERR); return array();