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,33 +508,91 @@ if ($id > 0)
print '</div><div class="fichehalfright"><div class="ficheaddleft">';
$boxstat = '';
// Nbre max d'elements des petites listes
$MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
// Lien recap
$outstandingBills = $object->get_OutstandingBill();
$warn = '';
if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingBills)
$boxstat.='<div class="box">';
$boxstat.='<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="noborder boxtable" width="100%">';
$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>';
}
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 '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
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>';
print '</tr>';
if ($conf->facture->enabled)
{
$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
$tmp = $object->getOutstandingBills();
$outstandingOpened=$tmp['opened'];
$outstandingTotal=$tmp['total_ht'];
$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>';
}
// Outstanding bill
print '<tr class="impair">';
print '<td>'.$langs->trans("CurrentOutstandingBill").'</td>';
print '<td>'.price($outstandingBills).$warn.'</td>';
print '</tr>';
$boxstat.='</td></tr>';
$boxstat.='</table>';
$boxstat.='</div>';
print '</table>';
print '<br>';
print $boxstat;
$now=dol_now();
/*

View File

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

View File

@ -3338,49 +3338,166 @@ class Societe extends CommonObject
return $this->update($this->id, $user);
}
/**
* Return amount of bill not paid
*
* @return int Amount in debt for thirdparty
*/
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
/**
* Return amount of order not paid and total
*
* @return array array('opened'=>Amount, 'total'=>Total amount)
*/
function getOutstandingProposals()
{
$sql = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX."propal as f";
$sql .= " WHERE fk_soc = ". $this->id;
dol_syslog("get_OutstandingBill", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$outstandingBill = 0;
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$facturestatic=new Facture($this->db);
while($obj=$this->db->fetch_object($resql)) {
$facturestatic->id=$obj->rowid;
$paiement = $facturestatic->getSommePaiement();
$creditnotes = $facturestatic->getSumCreditNotesUsed();
$deposits = $facturestatic->getSumDepositsUsed();
$outstandingBill+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
}
return $outstandingBill;
}
else
return 0;
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();
}
/**
* Return amount of order not paid and total
*
* @return array array('opened'=>Amount, 'total'=>Total amount)
*/
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;
}
/**
* Return label of status customer is prospect/customer
*