From 387c213aea22116f65298b4f3061bb4484287559 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 30 Jun 2013 23:01:28 +0200 Subject: [PATCH] New: Add box for graph of customer orders --- .../boxes/box_graph_invoices_permonth.php | 159 +++++++------ .../core/boxes/box_graph_orders_permonth.php | 225 ++++++++++++++++++ htdocs/core/class/infobox.class.php | 13 +- htdocs/core/lib/functions.lib.php | 4 +- htdocs/core/modules/modCommande.class.php | 4 +- htdocs/core/modules/modFacture.class.php | 4 +- htdocs/langs/en_US/orders.lang | 2 +- 7 files changed, 325 insertions(+), 86 deletions(-) create mode 100644 htdocs/core/boxes/box_graph_orders_permonth.php diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php index a9906304ccf..63b1b4531e6 100644 --- a/htdocs/core/boxes/box_graph_invoices_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_permonth.php @@ -30,7 +30,7 @@ class box_graph_invoices_permonth extends ModeleBoxes { var $boxcode="invoicespermonth"; var $boximg="object_bill"; - var $boxlabel="BoxInvoicesPerMonth"; + var $boxlabel="BoxCustomersInvoicesPerMonth"; var $depends = array("facture"); var $db; @@ -50,7 +50,6 @@ class box_graph_invoices_permonth extends ModeleBoxes global $conf; $this->db=$db; - $this->enabled=$conf->global->MAIN_FEATURES_LEVEL; } /** @@ -83,9 +82,11 @@ class box_graph_invoices_permonth extends ModeleBoxes if ($user->rights->facture->lire) { - require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; - include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facturestats.class.php'; + include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; + include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facturestats.class.php'; + $shownb=(! empty($conf->global->FACTURE_BOX_GRAPH_SHOW_NB)); + $showtot=(! isset($conf->global->FACTURE_BOX_GRAPH_SHOW_TOT) || ! empty($conf->global->FACTURE_BOX_GRAPH_SHOW_TOT)); $nowarray=dol_getdate(dol_now(),true); $endyear=$nowarray['year']; $startyear=$endyear-1; @@ -96,87 +97,101 @@ class box_graph_invoices_permonth extends ModeleBoxes $stats = new FactureStats($this->db, 0, $mode, ($userid>0?$userid:0)); - // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...) - $data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24))); + // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...) + if ($shownb) + { + $data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24))); - $filenamenb = $dir."/invoicesnbinyear-".$year.".png"; - if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png'; - if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.'.png'; + $filenamenb = $dir."/invoicesnbinyear-".$year.".png"; + if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesnbinyear-'.$year.'.png'; + if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesnbinyear-'.$year.'.png'; - $px1 = new DolGraph(); - $mesg = $px1->isGraphKo(); - if (! $mesg) - { - $px1->SetData($data1); - unset($data1); - $px1->SetPrecisionY(0); - $i=$startyear;$legend=array(); - while ($i <= $endyear) - { - $legend[]=$i; - $i++; - } - $px1->SetLegend($legend); - $px1->SetMaxValue($px1->GetCeilMaxValue()); - $px1->SetWidth($WIDTH); - $px1->SetHeight($HEIGHT); - $px1->SetYLabel($langs->trans("NumberOfBills")); - $px1->SetShading(3); - $px1->SetHorizTickIncrement(1); - $px1->SetPrecisionY(0); - $px1->SetCssPrefix("cssboxes"); - $px1->mode='depth'; - $px1->SetTitle($langs->trans("NumberOfBillsByMonth")); + $px1 = new DolGraph(); + $mesg = $px1->isGraphKo(); + if (! $mesg) + { + $px1->SetData($data1); + unset($data1); + $px1->SetPrecisionY(0); + $i=$startyear;$legend=array(); + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px1->SetLegend($legend); + $px1->SetMaxValue($px1->GetCeilMaxValue()); + $px1->SetWidth($WIDTH); + $px1->SetHeight($HEIGHT); + $px1->SetYLabel($langs->trans("NumberOfBills")); + $px1->SetShading(3); + $px1->SetHorizTickIncrement(1); + $px1->SetPrecisionY(0); + $px1->SetCssPrefix("cssboxes"); + $px1->mode='depth'; + $px1->SetTitle($langs->trans("NumberOfBillsByMonth")); - $px1->draw($filenamenb,$fileurlnb); + $px1->draw($filenamenb,$fileurlnb); + } } // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...) - $data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24))); + if ($showtot) + { + $data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24))); - $filenamenb = $dir."/invoicesnbinyear-".$year.".png"; - if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.'.png'; - if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.'.png'; + $filenamenb = $dir."/invoicesamountinyear-".$year.".png"; + if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstats&file=invoicesamountinyear-'.$year.'.png'; + if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&file=invoicesamountinyear-'.$year.'.png'; - $px2 = new DolGraph(); - $mesg = $px2->isGraphKo(); - if (! $mesg) - { - $px2->SetData($data2); - unset($data2); - $px2->SetPrecisionY(0); - $i=$startyear;$legend=array(); - while ($i <= $endyear) + $px2 = new DolGraph(); + $mesg = $px2->isGraphKo(); + if (! $mesg) { - $legend[]=$i; - $i++; - } - $px2->SetLegend($legend); - $px2->SetMaxValue($px2->GetCeilMaxValue()); - $px2->SetWidth($WIDTH); - $px2->SetHeight($HEIGHT); - $px2->SetYLabel($langs->trans("AmountOfBillsHT")); - $px2->SetShading(3); - $px2->SetHorizTickIncrement(1); - $px2->SetPrecisionY(0); - $px2->SetCssPrefix("cssboxes"); - $px2->mode='depth'; - $px2->SetTitle($langs->trans("AmountOfBillsByMonthHT")); + $px2->SetData($data2); + unset($data2); + $px2->SetPrecisionY(0); + $i=$startyear;$legend=array(); + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px2->SetLegend($legend); + $px2->SetMaxValue($px2->GetCeilMaxValue()); + $px2->SetWidth($WIDTH); + $px2->SetHeight($HEIGHT); + $px2->SetYLabel($langs->trans("AmountOfBillsHT")); + $px2->SetShading(3); + $px2->SetHorizTickIncrement(1); + $px2->SetPrecisionY(0); + $px2->SetCssPrefix("cssboxes"); + $px2->mode='depth'; + $px2->SetTitle($langs->trans("AmountOfBillsByMonthHT")); - $px2->draw($filenamenb,$fileurlnb); - } - + $px2->draw($filenamenb,$fileurlnb); + } + } if (! $mesg) { - $stringtoshow ='
'; - //$stringtoshow.='
'; - //$stringtoshow.=$px1->show(); - //$stringtoshow.='
'; - //$stringtoshow.='
'; - $stringtoshow.=$px2->show(); - //$stringtoshow.='
'; - $stringtoshow.='
'; + if ($shownb && $showtot) + { + $stringtoshow ='
'; + $stringtoshow.='
'; + } + if ($shownb) $stringtoshow.=$px1->show(); + if ($shownb && $showtot) + { + $stringtoshow.='
'; + $stringtoshow.='
'; + } + if ($showtot) $stringtoshow.=$px2->show(); + if ($shownb && $showtot) + { + $stringtoshow.='
'; + $stringtoshow.='
'; + } $this->info_box_contents[0][0] = array('td' => 'align="center"','textnoformat'=>$stringtoshow); } else diff --git a/htdocs/core/boxes/box_graph_orders_permonth.php b/htdocs/core/boxes/box_graph_orders_permonth.php new file mode 100644 index 00000000000..51c9eb4fba0 --- /dev/null +++ b/htdocs/core/boxes/box_graph_orders_permonth.php @@ -0,0 +1,225 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/boxes/box_order_permonth.php + * \ingroup commandes + * \brief Box to show graph of orders per month + */ +include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php'; + + +/** + * Class to manage the box to show last orders + */ +class box_graph_orders_permonth extends ModeleBoxes +{ + var $boxcode="orderspermonth"; + var $boximg="object_bill"; + var $boxlabel="BoxCustomersOrdersPerMonth"; + var $depends = array("commande"); + + var $db; + + var $info_box_head = array(); + var $info_box_contents = array(); + + + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $conf; + + $this->db=$db; + } + + /** + * Load data into info_box_contents array to show array later. + * + * @param int $max Maximum number of records to load + * @return void + */ + function loadBox($max=5) + { + global $conf, $user, $langs, $db; + + $this->max=$max; + + $refreshaction='refresh_'.$this->boxcode; + + include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; + $commandestatic=new Commande($db); + + $text = $langs->trans("BoxCustomersOrdersPerMonth",$max); + $this->info_box_head = array( + 'text' => $text, + 'limit'=> dol_strlen($text), + 'graph'=> 1, + 'sublink'=>$_SERVER["PHP_SELF"].'?action='.$refreshaction, + 'subtext'=>$langs->trans("Refresh"), + 'subpicto'=>'refresh.png', + 'target'=>'none' + ); + + if ($user->rights->commande->lire) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; + include_once DOL_DOCUMENT_ROOT.'/commande/class/commandestats.class.php'; + + $shownb=(! empty($conf->global->COMMANDE_BOX_GRAPH_SHOW_NB)); + $showtot=(! isset($conf->global->COMMANDE_BOX_GRAPH_SHOW_TOT) || ! empty($conf->global->COMMANDE_BOX_GRAPH_SHOW_TOT)); + $nowarray=dol_getdate(dol_now(),true); + $endyear=$nowarray['year']; + $startyear=$endyear-1; + $mode='customer'; + $userid=0; + $WIDTH='256'; + $HEIGHT='192'; + + $stats = new CommandeStats($this->db, 0, $mode, ($userid>0?$userid:0)); + + // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...) + if ($shownb) + { + $data1 = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24))); + + $filenamenb = $dir."/ordersnbinyear-".$year.".png"; + if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersnbinyear-'.$year.'.png'; + if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersnbinyear-'.$year.'.png'; + + $px1 = new DolGraph(); + $mesg = $px1->isGraphKo(); + if (! $mesg) + { + $px1->SetData($data1); + unset($data1); + $px1->SetPrecisionY(0); + $i=$startyear;$legend=array(); + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px1->SetLegend($legend); + $px1->SetMaxValue($px1->GetCeilMaxValue()); + $px1->SetWidth($WIDTH); + $px1->SetHeight($HEIGHT); + $px1->SetYLabel($langs->trans("NumberOfOrders")); + $px1->SetShading(3); + $px1->SetHorizTickIncrement(1); + $px1->SetPrecisionY(0); + $px1->SetCssPrefix("cssboxes"); + $px1->mode='depth'; + $px1->SetTitle($langs->trans("NumberOfOrdersByMonth")); + + $px1->draw($filenamenb,$fileurlnb); + } + } + + // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...) + if ($showtot) + { + $data2 = $stats->getAmountByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24))); + + $filenamenb = $dir."/ordersamountinyear-".$year.".png"; + if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstats&file=ordersamountinyear-'.$year.'.png'; + if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=orderstatssupplier&file=ordersamountinyear-'.$year.'.png'; + + $px2 = new DolGraph(); + $mesg = $px2->isGraphKo(); + if (! $mesg) + { + $px2->SetData($data2); + unset($data2); + $px2->SetPrecisionY(0); + $i=$startyear;$legend=array(); + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px2->SetLegend($legend); + $px2->SetMaxValue($px2->GetCeilMaxValue()); + $px2->SetWidth($WIDTH); + $px2->SetHeight($HEIGHT); + $px2->SetYLabel($langs->trans("AmountOfOrdersHT")); + $px2->SetShading(3); + $px2->SetHorizTickIncrement(1); + $px2->SetPrecisionY(0); + $px2->SetCssPrefix("cssboxes"); + $px2->mode='depth'; + $px2->SetTitle($langs->trans("AmountOfOrdersByMonthHT")); + + $px2->draw($filenamenb,$fileurlnb); + } + } + + if (! $mesg) + { + if ($shownb && $showtot) + { + $stringtoshow ='
'; + $stringtoshow.='
'; + } + if ($shownb) $stringtoshow.=$px1->show(); + if ($shownb && $showtot) + { + $stringtoshow.='
'; + $stringtoshow.='
'; + } + if ($showtot) $stringtoshow.=$px2->show(); + if ($shownb && $showtot) + { + $stringtoshow.='
'; + $stringtoshow.='
'; + } + $this->info_box_contents[0][0] = array('td' => 'align="center"','textnoformat'=>$stringtoshow); + } + else + { + $this->info_box_contents[0][0] = array( 'td' => 'align="left"', + 'maxlength'=>500, + 'text' => $mesg); + } + + } + else { + $this->info_box_contents[0][0] = array('td' => 'align="left"', + 'text' => $langs->trans("ReadPermissionNotAllowed")); + } + } + + /** + * Method to show box + * + * @param array $head Array with properties of box title + * @param array $contents Array with properties of box lines + * @return void + */ + function showBox($head = null, $contents = null) + { + parent::showBox($this->info_box_head, $this->info_box_contents); + } + +} + +?> diff --git a/htdocs/core/class/infobox.class.php b/htdocs/core/class/infobox.class.php index 131ece58aee..5b3881e06e4 100644 --- a/htdocs/core/class/infobox.class.php +++ b/htdocs/core/class/infobox.class.php @@ -100,13 +100,12 @@ class InfoBox // TODO PERF Do not make "dol_include_once" here, nor "new" later. This means, we must store a 'depends' field to store modules list, then // the "enabled" condition for modules forbidden for external users and the depends condition can be done. // Goal is to avoid making a new instance for each boxes returned by select. - dol_include_once($relsourcefile); if (class_exists($boxname)) { - $box=new $boxname($db,$obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params. + $box=new $boxname($db,$obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params. //$box=new stdClass(); - + // box properties $box->rowid = (empty($obj->rowid) ? '' : $obj->rowid); $box->id = (empty($obj->box_id) ? '' : $obj->box_id); @@ -115,7 +114,8 @@ class InfoBox $box->fk_user = (empty($obj->fk_user) ? 0 : $obj->fk_user); $box->sourcefile= $relsourcefile; $box->class = $boxname; - if ($mode == 'activated' && ! is_object($user)) // List of activated box was not yet personalized into database + + if ($mode == 'activated' && ! is_object($user)) // List of activated box was not yet personalized into database { if (is_numeric($box->box_order)) { @@ -126,9 +126,8 @@ class InfoBox // box_def properties $box->box_id = (empty($obj->box_id) ? '' : $obj->box_id); $box->note = (empty($obj->note) ? '' : $obj->note); - - // Filter on box->enabled (fused for example by box_comptes) and box->depends - //$enabled=1; + + // Filter on box->enabled (used for example by box_comptes) and box->depends $enabled=$box->enabled; if (isset($box->depends) && count($box->depends) > 0) { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 20565a1162b..84c9a6cb58f 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2811,9 +2811,9 @@ function get_localtax($tva, $local, $thirdparty_buyer="", $thirdparty_seller="") } } - if ($local == 2) + if ($local == 2) { - + if ($thirdparty_seller->id==$mysoc->id) { if (! $thirdparty_buyer->localtax2_assuj) return 0; diff --git a/htdocs/core/modules/modCommande.class.php b/htdocs/core/modules/modCommande.class.php index 2a74e9d7a44..b0a07e0a046 100644 --- a/htdocs/core/modules/modCommande.class.php +++ b/htdocs/core/modules/modCommande.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2004-2013 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Eric Seigne @@ -99,7 +99,7 @@ class modCommande extends DolibarrModules // Boites $this->boxes = array(); - $this->boxes[0][1] = "box_commandes.php"; + $this->boxes = array(0=>array('file'=>'box_commandes.php','enabledbydefaulton'=>'Home'),2=>array('file'=>'box_graph_orders_permonth.php','enabledbydefaulton'=>'Home')); // Permissions $this->rights = array(); diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index 6b243b4d22e..384d1c63c45 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2004-2013 Laurent Destailleur * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2012 Regis Houssin @@ -30,7 +30,7 @@ include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; /** - * Classe de description et activation du module Facture + * Class to describe module customer invoices */ class modFacture extends DolibarrModules { diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index b982f693776..db5be3df9c9 100644 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -82,7 +82,7 @@ NbOfOrders=Number of orders OrdersStatistics=Order's statistics OrdersStatisticsSuppliers=Supplier order's statistics NumberOfOrdersByMonth=Number of orders by month -AmountOfOrdersByMonthHT=amount of orders by month (net of tax) +AmountOfOrdersByMonthHT=Amount of orders by month (net of tax) ListOfOrders=List of orders CloseOrder=Close order ConfirmCloseOrder=Are you sure you want to set this order to deliverd ? Once an order is delivered, it can be set to billed.