NEW Add statistics on tabs

This commit is contained in:
Laurent Destailleur 2017-01-20 14:02:51 +01:00
parent 412be59f78
commit 94249b7926
3 changed files with 236 additions and 58 deletions

View File

@ -508,32 +508,90 @@ if ($id > 0)
print '</div><div class="fichehalfright"><div class="ficheaddleft">'; print '</div><div class="fichehalfright"><div class="ficheaddleft">';
$boxstat = '';
// Nbre max d'elements des petites listes // Nbre max d'elements des petites listes
$MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT; $MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
// Lien recap // Lien recap
$outstandingBills = $object->get_OutstandingBill(); $boxstat.='<div class="box">';
$warn = ''; $boxstat.='<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="noborder boxtable" width="100%">';
if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingBills) $boxstat.='<tr class="impair"><td colspan="2" class="tdboxstats nohover">';
if ($conf->propal->enabled)
{ {
$warn = img_warning($langs->trans("OutstandingBillReached")); // 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>';
} }
print '<table class="noborder" width="100%">'; if ($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>';
}
print '<tr class="liste_titre">'; if ($conf->facture->enabled)
print '<td>'.$langs->trans("Summary").'</td>'; {
print '<td align="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id.'">'.$langs->trans("ShowCustomerPreview").'</a></td>'; $text=$langs->trans("OverAllInvoices");
print '</tr>'; $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>';
// Outstanding bill // Box outstanding bill
print '<tr class="impair">'; $tmp = $object->getOutstandingBills();
print '<td>'.$langs->trans("CurrentOutstandingBill").'</td>'; $outstandingOpened=$tmp['opened'];
print '<td>'.price($outstandingBills).$warn.'</td>'; $outstandingTotal=$tmp['total_ht'];
print '</tr>'; $outstandingTotalIncTax=$tmp['total_ttc'];
$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).$warn.'</span>';
$boxstat.='</div>';
if ($link) $boxstat.='</a>';
}
print '</table>'; $boxstat.='</td></tr>';
print '<br>'; $boxstat.='</table>';
$boxstat.='</div>';
print $boxstat;
$now=dol_now(); $now=dol_now();

View File

@ -78,6 +78,9 @@ VATIsNotUsed=VAT is not used
CopyAddressFromSoc=Fill address with third party address CopyAddressFromSoc=Fill address with third party address
ThirdpartyNotCustomerNotSupplierSoNoRef=Thirdparty neither customer nor supplier, no available refering objects ThirdpartyNotCustomerNotSupplierSoNoRef=Thirdparty neither customer nor supplier, no available refering objects
PaymentBankAccount=Payment bank account PaymentBankAccount=Payment bank account
OverAllProposals=Total proposals
OverAllOrders=Total orders
OverAllInvoices=Total invoices
##### Local Taxes ##### ##### Local Taxes #####
LocalTax1IsUsed=Use second tax LocalTax1IsUsed=Use second tax
LocalTax1IsUsedES= RE is used LocalTax1IsUsedES= RE is used

View File

@ -3338,47 +3338,164 @@ class Societe extends CommonObject
return $this->update($this->id, $user); return $this->update($this->id, $user);
} }
/** /**
* Return amount of bill not paid * Return amount of order not paid and total
* *
* @return int Amount in debt for thirdparty * @return array array('opened'=>Amount, 'total'=>Total amount)
*/ */
function get_OutstandingBill() function getOutstandingProposals()
{ {
/* Accurate value of remain to pay is to sum remaintopay for each invoice $sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX."propal as f";
$paiement = $invoice->getSommePaiement(); $sql .= " WHERE fk_soc = ". $this->id;
$creditnotes=$invoice->getSumCreditNotesUsed();
$deposits=$invoice->getSumDepositsUsed();
$alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
$remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
*/
$sql = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE fk_soc = ". $this->id;
$sql .= " AND paye = 0";
$sql .= " AND fk_statut <> 0"; // Not a draft
//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason
$sql .= " AND fk_statut <> 3"; // Not abandonned
$sql .= " AND fk_statut <> 2"; // Not clasified as paid
dol_syslog("get_OutstandingBill", LOG_DEBUG); dol_syslog("getOutstandingProposals", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$outstandingBill = 0; $outstandingOpened = 0;
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; $outstandingTotal = 0;
$facturestatic=new Facture($this->db); $outstandingTotalIncTax = 0;
while($obj=$this->db->fetch_object($resql)) { while($obj=$this->db->fetch_object($resql)) {
$facturestatic->id=$obj->rowid; $outstandingTotal+= $obj->total_ht;
$paiement = $facturestatic->getSommePaiement(); $outstandingTotalIncTax+= $obj->total_ttc;
$creditnotes = $facturestatic->getSumCreditNotesUsed(); if ($obj->fk_statut != 0) // Not a draft
$deposits = $facturestatic->getSumDepositsUsed(); {
$outstandingOpened+=$obj->total_ttc;
}
}
return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);
}
else
return array();
}
$outstandingBill+= $obj->total_ttc - $paiement - $creditnotes - $deposits; /**
} * Return amount of order not paid and total
return $outstandingBill; *
} * @return array array('opened'=>Amount, 'total'=>Total amount)
else */
return 0; function getOutstandingOrders()
{
$sql = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX."commande as f";
$sql .= " WHERE fk_soc = ". $this->id;
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();
}
/**
* Return amount of bill not paid and total
*
* @return array array('opened'=>Amount, 'total'=>Total amount)
*/
function getOutstandingBills()
{
/* 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');
*/
$sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE fk_soc = ". $this->id;
dol_syslog("getOutstandingBills", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$outstandingOpened = 0;
$outstandingTotal = 0;
$outstandingTotalIncTax = 0;
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();
}
}
/**
* Return amount of bill not paid
*
* @return int Amount in debt for thirdparty
* @deprecated
*/
function get_OutstandingBill()
{
/* 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');
*/
$sql = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " WHERE fk_soc = ". $this->id;
$sql .= " AND paye = 0";
$sql .= " AND fk_statut <> 0"; // Not a draft
//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')"; // Not abandonned for undefined reason
$sql .= " AND fk_statut <> 3"; // Not abandonned
$sql .= " AND fk_statut <> 2"; // Not clasified as paid
dol_syslog("get_OutstandingBill", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$outstandingAmount = 0;
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;
$paiement = $tmpobject->getSommePaiement();
$creditnotes = $tmpobject->getSumCreditNotesUsed();
$deposits = $tmpobject->getSumDepositsUsed();
$outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
}
return $outstandingAmount;
}
else
return 0;
} }
/** /**