';
-print getCustomerInvoicePieChart($socid);
+//print getCustomerInvoicePieChart($socid);
+getNumberInvoicesPieChart('customers');
print '
';
-print getPurchaseInvoicePieChart($socid);
+getNumberInvoicesPieChart('fourn');
+//print getPurchaseInvoicePieChart($socid);
print '
';
print getCustomerInvoiceDraftTable($max, $socid);
print '
';
diff --git a/htdocs/core/lib/invoice.lib.php b/htdocs/core/lib/invoice.lib.php
index ece491d2c69..f294cbd7916 100644
--- a/htdocs/core/lib/invoice.lib.php
+++ b/htdocs/core/lib/invoice.lib.php
@@ -456,6 +456,121 @@ function getPurchaseInvoicePieChart($socid = 0)
return $result;
}
+/**
+ * Return an HTML table that contains a pie chart of the number of customers or supplier invoices
+ * @param string $mode Can be customer or fourn
+ * @return string A HTML table that contains a pie chart of customers or supplier invoices
+ */
+function getNumberInvoicesPieChart($mode)
+{
+ global $conf, $db, $langs, $user;
+ if (!empty($conf->facture->enabled) && !empty($user->rights->facture->lire)) {
+ include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
+ $langs->load("boxes");
+ $tmpinvoice = new Facture($db);
+ $sql = "SELECT f.rowid, f.ref, f.fk_statut as status, f.type, f.total_ht, f.total_tva, f.total_ttc, f.paye, f.datef";
+ if ($mode == 'customers') {
+ $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
+ } elseif ($mode == 'fourn') {
+ $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
+ } else {
+ return '';
+ }
+ $sql .= " WHERE f.type <> 2";
+ $sql .= " AND f.fk_statut = 1";
+ $resql = $db->query($sql);
+ if ($resql) {
+ $num = $db->num_rows($resql);
+ $i = 0;
+ $now = date_create(date('Y-m-d', dol_now()));
+ $datenowsub30 = date_create(date('Y-m-d', dol_now()));
+ $datenowsub15 = date_create(date('Y-m-d', dol_now()));
+ $datenowadd30 = date_create(date('Y-m-d', dol_now()));
+ $datenowadd15 = date_create(date('Y-m-d', dol_now()));
+ $interval30days = date_interval_create_from_date_string('30 days');
+ $interval15days = date_interval_create_from_date_string('15 days');
+ date_sub($datenowsub30, $interval30days);
+ date_sub($datenowsub15, $interval15days);
+ date_add($datenowadd30, $interval30days);
+ date_add($datenowadd15, $interval15days);
+ $numberinvoices = array('late30'=>0,'late15'=>0,'late'=>0,'notlate'=>0,'notlate15'=>0,'notlate30'=>0);
+ $labelnumberinvoices = array('late30'=>'InvoiceLate30Days',
+ 'late15'=>'InvoiceLate15Days',
+ 'late'=>'InvoiceLateMinus15Days',
+ 'notlate'=>'InvoiceNotLate',
+ 'notlate15'=>'InvoiceNotLate15Days',
+ 'notlate30'=>'InvoiceNotLate30Days');
+ $total = 0;
+ while ($i < $num) {
+ $obj = $db->fetch_object($resql);
+ $datef = date_create($obj->datef);
+ if ($datef < $datenowsub30) {
+ $numberinvoices['late30']++;
+ } elseif ($datef < $datenowsub15) {
+ $numberinvoices['late15']++;
+ } elseif ($datef < $now) {
+ $numberinvoices['late']++;
+ } elseif ($datef > $datenowadd30) {
+ $numberinvoices['notlate30']++;
+ } elseif ($datef > $datenowadd15) {
+ $numberinvoices['notlate15']++;
+ } else {
+ $numberinvoices['notlate']++;
+ }
+ $total++;
+ $i++;
+ }
+ $dataseries = array();
+ $colorseries = array();
+ foreach ($numberinvoices as $key => $nbinvoice) {
+ $dataseries[] = array($langs->trans($labelnumberinvoices[$key]),$nbinvoice);
+ }
+ $colorseries[] = $badgeStatus8;
+ $colorseries[] = $badgeStatus1;
+ $colorseries[] = $badgeStatus3;
+ $colorseries[] = $badgeStatus2;
+ $colorseries[] = $badgeStatus4;
+ $colorseries[] = $badgeStatus0;
+ if ($conf->use_javascript_ajax) {
+ $result = '
';
+ $result .= '
';
+ $result .= '';
+ $result .= '| '.$langs->trans("Statistics").' - ';
+ if ($mode == 'customers') {
+ $result .= $langs->trans("CustomerInvoice").' | ';
+ } elseif ($mode == 'fourn') {
+ $result .= $langs->trans("SupplierInvoice").'';
+ } else {
+ return '';
+ }
+ $result .= '
';
+
+ $dolgraph = new DolGraph();
+ $dolgraph->SetData($dataseries);
+ $dolgraph->SetDataColor(array_values($colorseries));
+ $dolgraph->setShowLegend(2);
+ $dolgraph->setShowPercent(1);
+ $dolgraph->SetType(['pie']);
+ $dolgraph->setHeight('150');
+ $dolgraph->setWidth('300');
+ if ($mode == 'customers') {
+ $dolgraph->draw('idgraphcustomerinvoices');
+ } elseif ($mode == 'fourn') {
+ $dolgraph->draw('idgraphfourninvoices');
+ } else {
+ return '';
+ }
+
+ $result .= '';
+ $result .= '| '.$dolgraph->show($total ? 0 : 1).' | ';
+ $result .= '
';
+ $result .= '
';
+ $result .= '
';
+ }
+ print $result;
+ }
+ }
+}
/**
* Return a HTML table that contains a list with customer invoice drafts
*
diff --git a/htdocs/langs/en_US/compta.lang b/htdocs/langs/en_US/compta.lang
index 926cda53c9f..b326eeced00 100644
--- a/htdocs/langs/en_US/compta.lang
+++ b/htdocs/langs/en_US/compta.lang
@@ -286,3 +286,9 @@ ReportPurchaseTurnover=Purchase turnover invoiced
ReportPurchaseTurnoverCollected=Purchase turnover collected
IncludeVarpaysInResults = Include various payments in reports
IncludeLoansInResults = Include loans in reports
+InvoiceLate30Days = Invoices late 30 days
+InvoiceLate15Days = Invoices late 15 days
+InvoiceLateMinus15Days = Invoices late
+InvoiceNotLate = To pay < 15 days
+InvoiceNotLate15Days = To pay > 15 days
+InvoiceNotLate30Days = To pay in > 30 days