Merge pull request #7143 from hregis/6.0_bug

Fix: missing entity filter (multicompany)
This commit is contained in:
Laurent Destailleur 2017-07-13 14:33:45 +02:00 committed by GitHub
commit 4ee70e496e
2 changed files with 178 additions and 164 deletions

View File

@ -3,7 +3,7 @@
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr> * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
@ -534,74 +534,73 @@ if ($id > 0)
$boxstat.='<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="noborder boxtable boxtablenobottom" width="100%">'; $boxstat.='<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="noborder boxtable boxtablenobottom" width="100%">';
$boxstat.='<tr class="impair"><td colspan="2" class="tdboxstats nohover">'; $boxstat.='<tr class="impair"><td colspan="2" class="tdboxstats nohover">';
if ($conf->propal->enabled) if (! empty($conf->propal->enabled))
{ {
// Box proposals // Box proposals
$tmp = $object->getOutstandingProposals(); $tmp = $object->getOutstandingProposals();
$outstandingOpened=$tmp['opened']; $outstandingOpened=$tmp['opened'];
$outstandingTotal=$tmp['total_ht']; $outstandingTotal=$tmp['total_ht'];
$outstandingTotalIncTax=$tmp['total_ttc']; $outstandingTotalIncTax=$tmp['total_ttc'];
$text=$langs->trans("OverAllProposals"); $text=$langs->trans("OverAllProposals");
$link=''; $link='';
$icon='bill'; $icon='bill';
if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">'; if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
$boxstat.='<div class="boxstats">'; $boxstat.='<div class="boxstats">';
$boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>'; $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
$boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>'; $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
$boxstat.='</div>'; $boxstat.='</div>';
if ($link) $boxstat.='</a>'; if ($link) $boxstat.='</a>';
} }
if ($conf->commande->enabled) if (! empty($conf->commande->enabled))
{ {
// Box proposals // Box proposals
$tmp = $object->getOutstandingOrders(); $tmp = $object->getOutstandingOrders();
$outstandingOpened=$tmp['opened']; $outstandingOpened=$tmp['opened'];
$outstandingTotal=$tmp['total_ht']; $outstandingTotal=$tmp['total_ht'];
$outstandingTotalIncTax=$tmp['total_ttc']; $outstandingTotalIncTax=$tmp['total_ttc'];
$text=$langs->trans("OverAllOrders"); $text=$langs->trans("OverAllOrders");
$link=''; $link='';
$icon='bill'; $icon='bill';
if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">'; if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
$boxstat.='<div class="boxstats">'; $boxstat.='<div class="boxstats">';
$boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>'; $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
$boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>'; $boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
$boxstat.='</div>'; $boxstat.='</div>';
if ($link) $boxstat.='</a>'; if ($link) $boxstat.='</a>';
} }
if ($conf->facture->enabled) if (! empty($conf->facture->enabled))
{ {
$tmp = $object->getOutstandingBills(); $tmp = $object->getOutstandingBills();
$outstandingOpened=$tmp['opened']; $outstandingOpened=$tmp['opened'];
$outstandingTotal=$tmp['total_ht']; $outstandingTotal=$tmp['total_ht'];
$outstandingTotalIncTax=$tmp['total_ttc']; $outstandingTotalIncTax=$tmp['total_ttc'];
$text=$langs->trans("OverAllInvoices");
$link='';
$icon='bill';
if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
$boxstat.='<div class="boxstats">';
$boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
$boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
$boxstat.='</div>';
if ($link) $boxstat.='</a>';
$text=$langs->trans("OverAllInvoices"); // Box outstanding bill
$link=''; $warn = '';
$icon='bill'; if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened)
if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">'; {
$boxstat.='<div class="boxstats">'; $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
$boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>'; }
$boxstat.='<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>'; $text=$langs->trans("CurrentOutstandingBill");
$boxstat.='</div>'; $link=DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
if ($link) $boxstat.='</a>'; $icon='bill';
if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
// Box outstanding bill $boxstat.='<div class="boxstats">';
$warn = ''; $boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened) $boxstat.='<span class="boxstatsindicator'.($outstandingOpened>0?' amountremaintopay':'').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
{ $boxstat.='</div>';
$warn = ' '.img_warning($langs->trans("OutstandingBillReached")); if ($link) $boxstat.='</a>';
}
$text=$langs->trans("CurrentOutstandingBill");
$link=DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
$icon='bill';
if ($link) $boxstat.='<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
$boxstat.='<div class="boxstats">';
$boxstat.='<span class="boxstatstext">'.img_object("",$icon).' '.$text.'</span><br>';
$boxstat.='<span class="boxstatsindicator'.($outstandingOpened>0?' amountremaintopay':'').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
$boxstat.='</div>';
if ($link) $boxstat.='</a>';
} }
$boxstat.='</td></tr>'; $boxstat.='</td></tr>';

View File

@ -4,7 +4,7 @@
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2003 Brian Fraval <brian@fraval.org> * Copyright (C) 2003 Brian Fraval <brian@fraval.org>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2005-2016 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net> * Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
@ -3346,31 +3346,36 @@ class Societe extends CommonObject
*/ */
function getOutstandingProposals($mode='customer') function getOutstandingProposals($mode='customer')
{ {
$table='propal'; $table='propal';
if ($mode == 'supplier') $table = 'supplier_proposal'; 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 = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
$sql .= " WHERE fk_soc = ". $this->id; $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); dol_syslog("getOutstandingProposals", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$outstandingOpened = 0; $outstandingOpened = 0;
$outstandingTotal = 0; $outstandingTotal = 0;
$outstandingTotalIncTax = 0; $outstandingTotalIncTax = 0;
while($obj=$this->db->fetch_object($resql)) { while($obj=$this->db->fetch_object($resql)) {
$outstandingTotal+= $obj->total_ht; $outstandingTotal+= $obj->total_ht;
$outstandingTotalIncTax+= $obj->total_ttc; $outstandingTotalIncTax+= $obj->total_ttc;
if ($obj->fk_statut != 0) // Not a draft if ($obj->fk_statut != 0) // Not a draft
{ {
$outstandingOpened+=$obj->total_ttc; $outstandingOpened+=$obj->total_ttc;
} }
} }
return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);
} }
else else
return array(); return array();
} }
/** /**
@ -3381,31 +3386,36 @@ class Societe extends CommonObject
*/ */
function getOutstandingOrders($mode='customer') function getOutstandingOrders($mode='customer')
{ {
$table='commande'; $table='commande';
if ($mode == 'supplier') $table = 'commande_fournisseur'; if ($mode == 'supplier') $table = 'commande_fournisseur';
$sql = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f"; $sql = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
$sql .= " WHERE fk_soc = ". $this->id; $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); dol_syslog("getOutstandingOrders", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$outstandingOpened = 0; $outstandingOpened = 0;
$outstandingTotal = 0; $outstandingTotal = 0;
$outstandingTotalIncTax = 0; $outstandingTotalIncTax = 0;
while($obj=$this->db->fetch_object($resql)) { while($obj=$this->db->fetch_object($resql)) {
$outstandingTotal+= $obj->total_ht; $outstandingTotal+= $obj->total_ht;
$outstandingTotalIncTax+= $obj->total_ttc; $outstandingTotalIncTax+= $obj->total_ttc;
if ($obj->fk_statut != 0) // Not a draft if ($obj->fk_statut != 0) // Not a draft
{ {
$outstandingOpened+=$obj->total_ttc; $outstandingOpened+=$obj->total_ttc;
} }
} }
return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);
} }
else else
return array(); return array();
} }
/** /**
@ -3416,64 +3426,69 @@ class Societe extends CommonObject
*/ */
function getOutstandingBills($mode='customer') function getOutstandingBills($mode='customer')
{ {
$table='facture'; $table='facture';
if ($mode == 'supplier') $table = 'facture_fourn'; if ($mode == 'supplier') $table = 'facture_fourn';
/* Accurate value of remain to pay is to sum remaintopay for each invoice /* Accurate value of remain to pay is to sum remaintopay for each invoice
$paiement = $invoice->getSommePaiement(); $paiement = $invoice->getSommePaiement();
$creditnotes=$invoice->getSumCreditNotesUsed(); $creditnotes=$invoice->getSumCreditNotesUsed();
$deposits=$invoice->getSumDepositsUsed(); $deposits=$invoice->getSumDepositsUsed();
$alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT'); $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
$remaintopay=price2num($invoice->total_ttc - $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"; 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"; 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; $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); dol_syslog("getOutstandingBills", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$outstandingOpened = 0; $outstandingOpened = 0;
$outstandingTotal = 0; $outstandingTotal = 0;
$outstandingTotalIncTax = 0; $outstandingTotalIncTax = 0;
if ($mode == 'supplier') if ($mode == 'supplier')
{ {
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
$tmpobject=new FactureFournisseur($this->db); $tmpobject=new FactureFournisseur($this->db);
} }
else else
{ {
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$tmpobject=new Facture($this->db); $tmpobject=new Facture($this->db);
} }
while($obj=$this->db->fetch_object($resql)) { while($obj=$this->db->fetch_object($resql)) {
$tmpobject->id=$obj->rowid; $tmpobject->id=$obj->rowid;
if ($obj->fk_statut != 0 // Not a draft if ($obj->fk_statut != 0 // Not a draft
&& ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced') // Not a replaced invoice && ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced') // Not a replaced invoice
) )
{ {
$outstandingTotal+= $obj->total_ht; $outstandingTotal+= $obj->total_ht;
$outstandingTotalIncTax+= $obj->total_ttc; $outstandingTotalIncTax+= $obj->total_ttc;
} }
if ($obj->paye == 0 if ($obj->paye == 0
&& $obj->fk_statut != 0 // Not a draft && $obj->fk_statut != 0 // Not a draft
&& $obj->fk_statut != 3 // Not abandonned && $obj->fk_statut != 3 // Not abandonned
&& $obj->fk_statut != 2) // Not classified as paid && $obj->fk_statut != 2) // Not classified as paid
//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason //$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason
{ {
$paiement = $tmpobject->getSommePaiement(); $paiement = $tmpobject->getSommePaiement();
$creditnotes = $tmpobject->getSumCreditNotesUsed(); $creditnotes = $tmpobject->getSumCreditNotesUsed();
$deposits = $tmpobject->getSumDepositsUsed(); $deposits = $tmpobject->getSumDepositsUsed();
$outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits; $outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
} }
} }
return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);
} }
else else
{ {
return array(); return array();
} }
} }
/** /**