From 94309525616d60647ba137f449ada6527777bca5 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 12 Jul 2017 11:00:18 +0200 Subject: [PATCH] Fix: missing entity filter (multicompany) --- htdocs/comm/card.php | 123 +++++++------- htdocs/societe/class/societe.class.php | 223 +++++++++++++------------ 2 files changed, 180 insertions(+), 166 deletions(-) diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index a51ef902eb62b..dfdc91838860b 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2017 Regis Houssin * Copyright (C) 2008 Raphael Bertrand (Resultic) * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2013 Alexandre Spangaro @@ -534,74 +534,73 @@ $boxstat.=''; $boxstat.=''; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 1605e7281b8d1..2bd764c92ede1 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4,7 +4,7 @@ * Copyright (C) 2004 Eric Seigne * Copyright (C) 2003 Brian Fraval * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2005-2016 Regis Houssin + * Copyright (C) 2005-2017 Regis Houssin * Copyright (C) 2008 Patrick Raguin * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2013 Florian Henry @@ -3346,31 +3346,36 @@ function set_OutstandingBill(User $user) */ function getOutstandingProposals($mode='customer') { - $table='propal'; - if ($mode == 'supplier') $table = 'supplier_proposal'; + $table='propal'; + if ($mode == 'supplier') $table = 'supplier_proposal'; - $sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f"; - $sql .= " WHERE fk_soc = ". $this->id; + $sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f"; + $sql .= " WHERE fk_soc = ". $this->id; + if ($mode == 'supplier') { + $sql .= " AND entity IN (".getEntity('supplier_proposal').")"; + } else { + $sql .= " AND entity IN (".getEntity('propal').")"; + } - dol_syslog("getOutstandingProposals", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $outstandingOpened = 0; - $outstandingTotal = 0; - $outstandingTotalIncTax = 0; - while($obj=$this->db->fetch_object($resql)) { - $outstandingTotal+= $obj->total_ht; - $outstandingTotalIncTax+= $obj->total_ttc; - if ($obj->fk_statut != 0) // Not a draft - { - $outstandingOpened+=$obj->total_ttc; - } - } - return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); - } - else - return array(); + dol_syslog("getOutstandingProposals", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $outstandingOpened = 0; + $outstandingTotal = 0; + $outstandingTotalIncTax = 0; + while($obj=$this->db->fetch_object($resql)) { + $outstandingTotal+= $obj->total_ht; + $outstandingTotalIncTax+= $obj->total_ttc; + if ($obj->fk_statut != 0) // Not a draft + { + $outstandingOpened+=$obj->total_ttc; + } + } + return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); + } + else + return array(); } /** @@ -3381,31 +3386,36 @@ function getOutstandingProposals($mode='customer') */ function getOutstandingOrders($mode='customer') { - $table='commande'; - if ($mode == 'supplier') $table = 'commande_fournisseur'; + $table='commande'; + if ($mode == 'supplier') $table = 'commande_fournisseur'; - $sql = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f"; - $sql .= " WHERE fk_soc = ". $this->id; + $sql = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f"; + $sql .= " WHERE fk_soc = ". $this->id; + if ($mode == 'supplier') { + $sql .= " AND entity IN (".getEntity('supplier_order').")"; + } else { + $sql .= " AND entity IN (".getEntity('commande').")"; + } - dol_syslog("getOutstandingOrders", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $outstandingOpened = 0; - $outstandingTotal = 0; - $outstandingTotalIncTax = 0; - while($obj=$this->db->fetch_object($resql)) { - $outstandingTotal+= $obj->total_ht; - $outstandingTotalIncTax+= $obj->total_ttc; - if ($obj->fk_statut != 0) // Not a draft - { - $outstandingOpened+=$obj->total_ttc; - } - } - return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); - } - else - return array(); + dol_syslog("getOutstandingOrders", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $outstandingOpened = 0; + $outstandingTotal = 0; + $outstandingTotalIncTax = 0; + while($obj=$this->db->fetch_object($resql)) { + $outstandingTotal+= $obj->total_ht; + $outstandingTotalIncTax+= $obj->total_ttc; + if ($obj->fk_statut != 0) // Not a draft + { + $outstandingOpened+=$obj->total_ttc; + } + } + return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); + } + else + return array(); } /** @@ -3416,64 +3426,69 @@ function getOutstandingOrders($mode='customer') */ function getOutstandingBills($mode='customer') { - $table='facture'; - if ($mode == 'supplier') $table = 'facture_fourn'; - - /* Accurate value of remain to pay is to sum remaintopay for each invoice - $paiement = $invoice->getSommePaiement(); - $creditnotes=$invoice->getSumCreditNotesUsed(); - $deposits=$invoice->getSumDepositsUsed(); - $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); - $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); - */ - if ($mode == 'supplier') $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; - else $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; - $sql .= " WHERE fk_soc = ". $this->id; + $table='facture'; + if ($mode == 'supplier') $table = 'facture_fourn'; + + /* Accurate value of remain to pay is to sum remaintopay for each invoice + $paiement = $invoice->getSommePaiement(); + $creditnotes=$invoice->getSumCreditNotesUsed(); + $deposits=$invoice->getSumDepositsUsed(); + $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); + $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT'); + */ + if ($mode == 'supplier') $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + else $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f"; + $sql .= " WHERE fk_soc = ". $this->id; + if ($mode == 'supplier') { + $sql .= " AND entity IN (".getEntity('facture_fourn').")"; + } else { + $sql .= " AND entity IN (".getEntity('facture').")"; + } - dol_syslog("getOutstandingBills", LOG_DEBUG); - $resql=$this->db->query($sql); - if ($resql) - { - $outstandingOpened = 0; - $outstandingTotal = 0; - $outstandingTotalIncTax = 0; - if ($mode == 'supplier') - { - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; - $tmpobject=new FactureFournisseur($this->db); - } - else - { - require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; - $tmpobject=new Facture($this->db); - } - while($obj=$this->db->fetch_object($resql)) { - $tmpobject->id=$obj->rowid; - if ($obj->fk_statut != 0 // Not a draft - && ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced') // Not a replaced invoice - ) - { - $outstandingTotal+= $obj->total_ht; - $outstandingTotalIncTax+= $obj->total_ttc; - } - if ($obj->paye == 0 - && $obj->fk_statut != 0 // Not a draft - && $obj->fk_statut != 3 // Not abandonned - && $obj->fk_statut != 2) // Not classified as paid - //$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason - { - $paiement = $tmpobject->getSommePaiement(); - $creditnotes = $tmpobject->getSumCreditNotesUsed(); - $deposits = $tmpobject->getSumDepositsUsed(); - $outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits; - } - } - return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); - } - else - { - return array(); - } + dol_syslog("getOutstandingBills", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $outstandingOpened = 0; + $outstandingTotal = 0; + $outstandingTotalIncTax = 0; + if ($mode == 'supplier') + { + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; + $tmpobject=new FactureFournisseur($this->db); + } + else + { + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + $tmpobject=new Facture($this->db); + } + while($obj=$this->db->fetch_object($resql)) { + $tmpobject->id=$obj->rowid; + if ($obj->fk_statut != 0 // Not a draft + && ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced') // Not a replaced invoice + ) + { + $outstandingTotal+= $obj->total_ht; + $outstandingTotalIncTax+= $obj->total_ttc; + } + if ($obj->paye == 0 + && $obj->fk_statut != 0 // Not a draft + && $obj->fk_statut != 3 // Not abandonned + && $obj->fk_statut != 2) // Not classified as paid + //$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason + { + $paiement = $tmpobject->getSommePaiement(); + $creditnotes = $tmpobject->getSumCreditNotesUsed(); + $deposits = $tmpobject->getSumDepositsUsed(); + $outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits; + } + } + return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); + } + else + { + return array(); + } } /**
'; - if ($conf->propal->enabled) + if (! empty($conf->propal->enabled)) { - // Box proposals - $tmp = $object->getOutstandingProposals(); - $outstandingOpened=$tmp['opened']; - $outstandingTotal=$tmp['total_ht']; - $outstandingTotalIncTax=$tmp['total_ttc']; - $text=$langs->trans("OverAllProposals"); - $link=''; - $icon='bill'; - if ($link) $boxstat.=''; - $boxstat.='
'; - $boxstat.=''.img_object("",$icon).' '.$text.'
'; - $boxstat.=''.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).''; - $boxstat.='
'; - if ($link) $boxstat.='
'; + // Box proposals + $tmp = $object->getOutstandingProposals(); + $outstandingOpened=$tmp['opened']; + $outstandingTotal=$tmp['total_ht']; + $outstandingTotalIncTax=$tmp['total_ttc']; + $text=$langs->trans("OverAllProposals"); + $link=''; + $icon='bill'; + if ($link) $boxstat.=''; + $boxstat.='
'; + $boxstat.=''.img_object("",$icon).' '.$text.'
'; + $boxstat.=''.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).''; + $boxstat.='
'; + if ($link) $boxstat.='
'; } - if ($conf->commande->enabled) + if (! empty($conf->commande->enabled)) { - // Box proposals - $tmp = $object->getOutstandingOrders(); - $outstandingOpened=$tmp['opened']; - $outstandingTotal=$tmp['total_ht']; - $outstandingTotalIncTax=$tmp['total_ttc']; - $text=$langs->trans("OverAllOrders"); - $link=''; - $icon='bill'; - if ($link) $boxstat.=''; - $boxstat.='
'; - $boxstat.=''.img_object("",$icon).' '.$text.'
'; - $boxstat.=''.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).''; - $boxstat.='
'; - if ($link) $boxstat.='
'; + // Box proposals + $tmp = $object->getOutstandingOrders(); + $outstandingOpened=$tmp['opened']; + $outstandingTotal=$tmp['total_ht']; + $outstandingTotalIncTax=$tmp['total_ttc']; + $text=$langs->trans("OverAllOrders"); + $link=''; + $icon='bill'; + if ($link) $boxstat.=''; + $boxstat.='
'; + $boxstat.=''.img_object("",$icon).' '.$text.'
'; + $boxstat.=''.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).''; + $boxstat.='
'; + if ($link) $boxstat.='
'; } - if ($conf->facture->enabled) + if (! empty($conf->facture->enabled)) { - $tmp = $object->getOutstandingBills(); - $outstandingOpened=$tmp['opened']; - $outstandingTotal=$tmp['total_ht']; - $outstandingTotalIncTax=$tmp['total_ttc']; - - $text=$langs->trans("OverAllInvoices"); - $link=''; - $icon='bill'; - if ($link) $boxstat.=''; - $boxstat.='
'; - $boxstat.=''.img_object("",$icon).' '.$text.'
'; - $boxstat.=''.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).''; - $boxstat.='
'; - if ($link) $boxstat.='
'; - - // Box outstanding bill - $warn = ''; - if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened) - { - $warn = ' '.img_warning($langs->trans("OutstandingBillReached")); - } - $text=$langs->trans("CurrentOutstandingBill"); - $link=DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id; - $icon='bill'; - if ($link) $boxstat.=''; - $boxstat.='
'; - $boxstat.=''.img_object("",$icon).' '.$text.'
'; - $boxstat.=''.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.''; - $boxstat.='
'; - if ($link) $boxstat.='
'; + $tmp = $object->getOutstandingBills(); + $outstandingOpened=$tmp['opened']; + $outstandingTotal=$tmp['total_ht']; + $outstandingTotalIncTax=$tmp['total_ttc']; + $text=$langs->trans("OverAllInvoices"); + $link=''; + $icon='bill'; + if ($link) $boxstat.=''; + $boxstat.='
'; + $boxstat.=''.img_object("",$icon).' '.$text.'
'; + $boxstat.=''.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).''; + $boxstat.='
'; + if ($link) $boxstat.='
'; + + // Box outstanding bill + $warn = ''; + if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened) + { + $warn = ' '.img_warning($langs->trans("OutstandingBillReached")); + } + $text=$langs->trans("CurrentOutstandingBill"); + $link=DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id; + $icon='bill'; + if ($link) $boxstat.=''; + $boxstat.='
'; + $boxstat.=''.img_object("",$icon).' '.$text.'
'; + $boxstat.=''.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.''; + $boxstat.='
'; + if ($link) $boxstat.='
'; } $boxstat.='