Skip to content

Commit

Permalink
Fix: missing entity filter (multicompany)
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Jul 12, 2017
1 parent ceeb9d7 commit 9430952
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 166 deletions.
123 changes: 61 additions & 62 deletions htdocs/comm/card.php
Expand Up @@ -3,7 +3,7 @@
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* 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) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
Expand Down Expand Up @@ -534,74 +534,73 @@
$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">';

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.='<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>';
// 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.='<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>';
}

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.='<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>';
// 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.='<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>';
}

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.='<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>';

// 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.='<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>';
$tmp = $object->getOutstandingBills();
$outstandingOpened=$tmp['opened'];
$outstandingTotal=$tmp['total_ht'];
$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>';

// 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.='<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>';
Expand Down
223 changes: 119 additions & 104 deletions htdocs/societe/class/societe.class.php
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2003 Brian Fraval <brian@fraval.org>
* 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) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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();
}

/**
Expand All @@ -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();
}
}

/**
Expand Down

0 comments on commit 9430952

Please sign in to comment.