From d8883dba7f6f3e5646374d1c154b321eea498b66 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 Jun 2013 19:19:18 +0200 Subject: [PATCH] New: Add new graphical boxes (customer invoices per month). --- ChangeLog | 20 +-- .../facture/class/facturestats.class.php | 9 +- .../boxes/box_graph_invoices_permonth.php | 101 ++++++++------ htdocs/core/boxes/modules_boxes.php | 29 +++-- htdocs/core/class/dolgraph.class.php | 2 +- htdocs/core/class/stats.class.php | 123 +++++++++++++----- 6 files changed, 182 insertions(+), 102 deletions(-) diff --git a/ChangeLog b/ChangeLog index 19e8c4058d9..def026d92ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,8 +6,8 @@ English Dolibarr ChangeLog For users: - New: [ task #877 ] Reorganize menus. - New: [ task #858 ] Holiday module: note on manual holiday assignation. -- New: [ task #892 ] Add option in thirdparty customer/supplier admin to hide non active - companies in select_company method. +- New: [ task #892 ] Add hidden option in thirdparty customer/supplier module to + hide non active companies in select_company method. - New: [ task #531 ] Add a workload field on tasks. - New: Add graph of bank account input/output into input-output report page. - New: Add script export-bank-receipts.php @@ -16,28 +16,30 @@ For users: - New: [ task #901 ] Add Extrafeild on Fiche Inter. - New: Show process id in all command line scripts. - New: Module mailman can subscribe/unsubscribe to ML according to categories or type of member. -- New: Add object_hour as substitution tag for opendocument generation. -- New: Add option to send email when paypal or paybox payment is done. -- New: Implement same rule for return value of all command line scripts (0 when success, <>0 if error). +- New: Add object_hour and object_date_rfc as substitution tag for opendocument generation. +- New: Add options to send an email when paypal or paybox payment is done. - New: Clone product/service composition. - New: [ task #926 ] Add extrafield feature on order lines. - New: [ task #927 ] Add extrafield feature on Proposal lines. - New: [ task #928 ] Add extrafield feature on invoice lines. - New: Add option ADHERENT_LOGIN_NOT_REQUIRED. -- New: Add a cron module. +- New: Add a cron module to define scheduled jobs. +- New: Add new graphical boxes (customer invoices per month). +- Qual: Implement same rule for return value of all command line scripts (0 when success, <>0 if error). For translators: - Normalized sort order of all languages files with english reference files. For developers: - New: DolGraph can build graph with three lines. -- New: Can enable tuning info from option MAIN_SHOW_TUNING_INFO. +- New: DolGraph accept a parameter to cache data of graph getNbByMonthWithPrevYear. +- New: Can enable tuning info with option MAIN_SHOW_TUNING_INFO. - New: Show version of client lib used by mysql drivers. - New: Add function to get content of an url (using all dolibarr setup like timeout, proxies...) - New: Upgrade lib of TCPDF to 6.0 -- New: Add property hidden into module descriptor to allow to hide a module according to +- New: Add property "hidden" into module descriptors to allow to hide a module according to some dynamic conditions. - + ***** ChangeLog for 3.4 compared to 3.3.2 ***** For users: diff --git a/htdocs/compta/facture/class/facturestats.class.php b/htdocs/compta/facture/class/facturestats.class.php index 0fe45fc6c66..148ceb57617 100644 --- a/htdocs/compta/facture/class/facturestats.class.php +++ b/htdocs/compta/facture/class/facturestats.class.php @@ -28,8 +28,7 @@ include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; /** - * \class FactureStats - * \brief Classe permettant la gestion des stats des factures + * Class to manage stats for invoices (customer and supplier) */ class FactureStats extends Stats { @@ -47,7 +46,7 @@ class FactureStats extends Stats * * @param DoliDB $db Database handler * @param int $socid Id third party - * @param string $mode Option + * @param string $mode Option ('customer', 'supplier') * @param int $userid Id user for filter (creation user) * @return FactureStats */ @@ -87,8 +86,8 @@ class FactureStats extends Stats /** * Renvoie le nombre de facture par mois pour une annee donnee * - * @param int $year Year to scan - * @return array Array of values + * @param int $year Year to scan + * @return array Array of values */ function getNbByMonth($year) { diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php index 968413be6c3..1899d96c57d 100644 --- a/htdocs/core/boxes/box_graph_invoices_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_permonth.php @@ -64,7 +64,9 @@ class box_graph_invoices_permonth extends ModeleBoxes global $conf, $user, $langs, $db; $this->max=$max; - + + $refreshaction='refresh_'.$this->boxcode; + include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; $facturestatic=new Facture($db); @@ -72,58 +74,73 @@ class box_graph_invoices_permonth extends ModeleBoxes $this->info_box_head = array( 'text' => $text, 'limit'=> dol_strlen($text), - 'graph'=> 1 + 'graph'=> 1, + 'sublink'=>$_SERVER["PHP_SELF"].'?action='.$refreshaction, + 'subtext'=>$langs->trans("Refresh"), + 'subpicto'=>'refresh.png', + 'target'=>'none' ); if ($user->rights->facture->lire) { - $sql = "SELECT f.rowid as facid, f.facnumber, f.type, f.amount, f.datef as df"; - $sql.= ", f.paye, f.fk_statut, f.datec, f.tms"; - $sql.= ", s.nom, s.rowid as socid"; - $sql.= ", f.date_lim_reglement as datelimite"; - $sql.= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= ")"; - $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND f.entity = ".$conf->entity; - if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; - $sql.= " ORDER BY f.tms DESC"; - $sql.= $db->plimit($max, 0); - - $result = $db->query($sql); - if ($result) + require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; + include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facturestats.class.php'; + + $nowarray=dol_getdate(dol_now(),true); + $endyear=$nowarray['year']; + $startyear=$endyear-1; + $mode='customer'; + $userid=0; + $WIDTH='256'; + $HEIGHT='192'; + + $stats = new FactureStats($this->db, 0, $mode, ($userid>0?$userid:0)); + + // Build graphic number of object + // $data = array(array('Lib',val1,val2,val3),...) + $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear,(GETPOST('action')==$refreshaction?-1:(3600*24))); + //var_dump($data); + + $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) { - $num = $db->num_rows($result); - $now=dol_now(); + $px1->SetData($data); + $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->mode='depth'; + //$px1->SetTitle($langs->trans("NumberOfBillsByMonth")); + + $px1->draw($filenamenb,$fileurlnb); + } - $i = 0; - $l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateEcheance')).': %s)'; - - while ($i < $num) - { - $objp = $db->fetch_object($result); - $datelimite=$db->jdate($objp->datelimite); - $datec=$db->jdate($objp->datec); - - $picto='bill'; - if ($objp->type == 1) $picto.='r'; - if ($objp->type == 2) $picto.='a'; - $late = ''; - if ($objp->paye == 0 && ($objp->fk_statut != 2 && $objp->fk_statut != 3) && $datelimite < ($now - $conf->facture->client->warning_delay)) { $late = img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day')));} - - $i++; - } - - $this->info_box_contents[0][0] = array('td' => 'align="center"','text2'=>'xxxxxxx'); - - $db->free($result); + + if (! $mesg) + { + $this->info_box_contents[0][0] = array('td' => 'align="center"','textnoformat'=>$px1->show()); } else { $this->info_box_contents[0][0] = array( 'td' => 'align="left"', 'maxlength'=>500, - 'text' => ($db->error().' sql='.$sql)); + 'text' => $mesg); } } diff --git a/htdocs/core/boxes/modules_boxes.php b/htdocs/core/boxes/modules_boxes.php index 140b5c757f9..10ea413740a 100644 --- a/htdocs/core/boxes/modules_boxes.php +++ b/htdocs/core/boxes/modules_boxes.php @@ -160,7 +160,7 @@ class ModeleBoxes // Can't be abtract as it is instanciated to build "empty" } if (! empty($head['sublink'])) { - print ' '.img_picto($head['subtext'],$head['subpicto']).''; + print ' '.img_picto($head['subtext'],$head['subpicto']).''; } if ($conf->use_javascript_ajax) { @@ -203,19 +203,20 @@ class ModeleBoxes // Can't be abtract as it is instanciated to build "empty" if (isset($contents[$i][$j]['td'])) $tdparam.=' '.$contents[$i][$j]['td']; if (empty($contents[$i][$j]['text'])) $contents[$i][$j]['text']=""; - $texte=isset($contents[$i][$j]['text'])?$contents[$i][$j]['text']:''; - $textewithnotags=preg_replace('/<([^>]+)>/i','',$texte); - $texte2=isset($contents[$i][$j]['text2'])?$contents[$i][$j]['text2']:''; - $texte2withnotags=preg_replace('/<([^>]+)>/i','',$texte2); - //print "xxx $textewithnotags y"; + $text=isset($contents[$i][$j]['text'])?$contents[$i][$j]['text']:''; + $textwithnotags=preg_replace('/<([^>]+)>/i','',$text); + $text2=isset($contents[$i][$j]['text2'])?$contents[$i][$j]['text2']:''; + $text2withnotags=preg_replace('/<([^>]+)>/i','',$text2); + $textnoformat=isset($contents[$i][$j]['textnoformat'])?$contents[$i][$j]['textnoformat']:''; + //print "xxx $textwithnotags y"; print ''; // Url if (! empty($contents[$i][$j]['url'])) { - print '" + print '" print isset($contents[$i][$j]['target'])?' target="'.$contents[$i][$j]['target'].'"':''; print '>'; } @@ -230,16 +231,18 @@ class ModeleBoxes // Can't be abtract as it is instanciated to build "empty" $maxlength=$MAXLENGTHBOX; if (! empty($contents[$i][$j]['maxlength'])) $maxlength=$contents[$i][$j]['maxlength']; - if ($maxlength) $textewithnotags=dol_trunc($textewithnotags,$maxlength); - if (preg_match('/^'; - if (preg_match('/^"; } diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index c5057a4b63a..63d3fdd1e66 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -785,7 +785,7 @@ class DolGraph $tag=dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file),'_',array('-','.')))); $this->_stringtoshow =''."\n"; - $this->_stringtoshow.='
'.$this->title.'

'; + if (! empty($this->title)) $this->_stringtoshow.='
'.$this->title.'

'; $this->_stringtoshow.='
'."\n"; $this->_stringtoshow.='