New: Add new graphical boxes (customer invoices per month).

This commit is contained in:
Laurent Destailleur 2013-06-28 19:19:18 +02:00
parent 1afef513b1
commit d8883dba7f
6 changed files with 182 additions and 102 deletions

View File

@ -6,8 +6,8 @@ English Dolibarr ChangeLog
For users: For users:
- New: [ task #877 ] Reorganize menus. - New: [ task #877 ] Reorganize menus.
- New: [ task #858 ] Holiday module: note on manual holiday assignation. - New: [ task #858 ] Holiday module: note on manual holiday assignation.
- New: [ task #892 ] Add option in thirdparty customer/supplier admin to hide non active - New: [ task #892 ] Add hidden option in thirdparty customer/supplier module to
companies in select_company method. hide non active companies in select_company method.
- New: [ task #531 ] Add a workload field on tasks. - New: [ task #531 ] Add a workload field on tasks.
- New: Add graph of bank account input/output into input-output report page. - New: Add graph of bank account input/output into input-output report page.
- New: Add script export-bank-receipts.php - New: Add script export-bank-receipts.php
@ -16,26 +16,28 @@ For users:
- New: [ task #901 ] Add Extrafeild on Fiche Inter. - New: [ task #901 ] Add Extrafeild on Fiche Inter.
- New: Show process id in all command line scripts. - 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: 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 object_hour and object_date_rfc as substitution tag for opendocument generation.
- New: Add option to send email when paypal or paybox payment is done. - New: Add options to send an 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: Clone product/service composition. - New: Clone product/service composition.
- New: [ task #926 ] Add extrafield feature on order lines. - New: [ task #926 ] Add extrafield feature on order lines.
- New: [ task #927 ] Add extrafield feature on Proposal lines. - New: [ task #927 ] Add extrafield feature on Proposal lines.
- New: [ task #928 ] Add extrafield feature on invoice lines. - New: [ task #928 ] Add extrafield feature on invoice lines.
- New: Add option ADHERENT_LOGIN_NOT_REQUIRED. - 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: For translators:
- Normalized sort order of all languages files with english reference files. - Normalized sort order of all languages files with english reference files.
For developers: For developers:
- New: DolGraph can build graph with three lines. - 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: 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: Add function to get content of an url (using all dolibarr setup like timeout, proxies...)
- New: Upgrade lib of TCPDF to 6.0 - 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. some dynamic conditions.

View File

@ -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'; include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
/** /**
* \class FactureStats * Class to manage stats for invoices (customer and supplier)
* \brief Classe permettant la gestion des stats des factures
*/ */
class FactureStats extends Stats class FactureStats extends Stats
{ {
@ -47,7 +46,7 @@ class FactureStats extends Stats
* *
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
* @param int $socid Id third party * @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) * @param int $userid Id user for filter (creation user)
* @return FactureStats * @return FactureStats
*/ */

View File

@ -65,6 +65,8 @@ class box_graph_invoices_permonth extends ModeleBoxes
$this->max=$max; $this->max=$max;
$refreshaction='refresh_'.$this->boxcode;
include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$facturestatic=new Facture($db); $facturestatic=new Facture($db);
@ -72,58 +74,73 @@ class box_graph_invoices_permonth extends ModeleBoxes
$this->info_box_head = array( $this->info_box_head = array(
'text' => $text, 'text' => $text,
'limit'=> dol_strlen($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) if ($user->rights->facture->lire)
{ {
$sql = "SELECT f.rowid as facid, f.facnumber, f.type, f.amount, f.datef as df"; require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
$sql.= ", f.paye, f.fk_statut, f.datec, f.tms"; include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facturestats.class.php';
$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); $nowarray=dol_getdate(dol_now(),true);
if ($result) $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&amp;file=invoicesnbinyear-'.$year.'.png';
if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=billstatssupplier&amp;file=invoicesnbinyear-'.$year.'.png';
$px1 = new DolGraph();
$mesg = $px1->isGraphKo();
if (! $mesg)
{ {
$num = $db->num_rows($result); $px1->SetData($data);
$now=dol_now(); $px1->SetPrecisionY(0);
$i=$startyear;$legend=array();
$i = 0; while ($i <= $endyear)
$l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateEcheance')).': %s)';
while ($i < $num)
{ {
$objp = $db->fetch_object($result); $legend[]=$i;
$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++; $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"));
$this->info_box_contents[0][0] = array('td' => 'align="center"','text2'=>'xxxxxxx'); $px1->draw($filenamenb,$fileurlnb);
}
$db->free($result);
if (! $mesg)
{
$this->info_box_contents[0][0] = array('td' => 'align="center"','textnoformat'=>$px1->show());
} }
else else
{ {
$this->info_box_contents[0][0] = array( 'td' => 'align="left"', $this->info_box_contents[0][0] = array( 'td' => 'align="left"',
'maxlength'=>500, 'maxlength'=>500,
'text' => ($db->error().' sql='.$sql)); 'text' => $mesg);
} }
} }

View File

@ -160,7 +160,7 @@ class ModeleBoxes // Can't be abtract as it is instanciated to build "empty"
} }
if (! empty($head['sublink'])) if (! empty($head['sublink']))
{ {
print ' <a href="'.$head['sublink'].'" target="_blank">'.img_picto($head['subtext'],$head['subpicto']).'</a>'; print ' <a href="'.$head['sublink'].'"'.(empty($head['target'])?' target="_blank"':'').'>'.img_picto($head['subtext'],$head['subpicto']).'</a>';
} }
if ($conf->use_javascript_ajax) 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 (isset($contents[$i][$j]['td'])) $tdparam.=' '.$contents[$i][$j]['td'];
if (empty($contents[$i][$j]['text'])) $contents[$i][$j]['text']=""; if (empty($contents[$i][$j]['text'])) $contents[$i][$j]['text']="";
$texte=isset($contents[$i][$j]['text'])?$contents[$i][$j]['text']:''; $text=isset($contents[$i][$j]['text'])?$contents[$i][$j]['text']:'';
$textewithnotags=preg_replace('/<([^>]+)>/i','',$texte); $textwithnotags=preg_replace('/<([^>]+)>/i','',$text);
$texte2=isset($contents[$i][$j]['text2'])?$contents[$i][$j]['text2']:''; $text2=isset($contents[$i][$j]['text2'])?$contents[$i][$j]['text2']:'';
$texte2withnotags=preg_replace('/<([^>]+)>/i','',$texte2); $text2withnotags=preg_replace('/<([^>]+)>/i','',$text2);
//print "xxx $textewithnotags y"; $textnoformat=isset($contents[$i][$j]['textnoformat'])?$contents[$i][$j]['textnoformat']:'';
//print "xxx $textwithnotags y";
print '<td'.$tdparam.'>'; print '<td'.$tdparam.'>';
// Url // Url
if (! empty($contents[$i][$j]['url'])) if (! empty($contents[$i][$j]['url']))
{ {
print '<a href="'.$contents[$i][$j]['url'].'" title="'.$textewithnotags.'"'; print '<a href="'.$contents[$i][$j]['url'].'" title="'.$textwithnotags.'"';
//print ' alt="'.$textewithnotags.'"'; // Pas de alt sur un "<a href>" //print ' alt="'.$textwithnotags.'"'; // Pas de alt sur un "<a href>"
print isset($contents[$i][$j]['target'])?' target="'.$contents[$i][$j]['target'].'"':''; print isset($contents[$i][$j]['target'])?' target="'.$contents[$i][$j]['target'].'"':'';
print '>'; print '>';
} }
@ -230,15 +231,17 @@ class ModeleBoxes // Can't be abtract as it is instanciated to build "empty"
$maxlength=$MAXLENGTHBOX; $maxlength=$MAXLENGTHBOX;
if (! empty($contents[$i][$j]['maxlength'])) $maxlength=$contents[$i][$j]['maxlength']; if (! empty($contents[$i][$j]['maxlength'])) $maxlength=$contents[$i][$j]['maxlength'];
if ($maxlength) $textewithnotags=dol_trunc($textewithnotags,$maxlength); if ($maxlength) $textwithnotags=dol_trunc($textwithnotags,$maxlength);
if (preg_match('/^<img/i',$texte) || ! empty($contents[$i][$j]['asis'])) print $texte; // show text with no html cleaning if (preg_match('/^<img/i',$text) || ! empty($contents[$i][$j]['asis'])) print $text; // show text with no html cleaning
else print $textewithnotags; // show text with html cleaning else print $textwithnotags; // show text with html cleaning
// End Url // End Url
if (! empty($contents[$i][$j]['url'])) print '</a>'; if (! empty($contents[$i][$j]['url'])) print '</a>';
if (preg_match('/^<img/i',$texte2) || ! empty($contents[$i][$j]['asis2'])) print $texte2; // show text with no html cleaning if (preg_match('/^<img/i',$text2) || ! empty($contents[$i][$j]['asis2'])) print $text2; // show text with no html cleaning
else print $texte2withnotags; // show text with html cleaning else print $text2withnotags; // show text with html cleaning
if (! empty($textnoformat)) print "\n".$textnoformat."\n";
print "</td>"; print "</td>";
} }

View File

@ -785,7 +785,7 @@ class DolGraph
$tag=dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file),'_',array('-','.')))); $tag=dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file),'_',array('-','.'))));
$this->_stringtoshow ='<!-- Build using '.$this->_library.' -->'."\n"; $this->_stringtoshow ='<!-- Build using '.$this->_library.' -->'."\n";
$this->_stringtoshow.='<br><div align="center">'.$this->title.'</div><br>'; if (! empty($this->title)) $this->_stringtoshow.='<br><div align="center">'.$this->title.'</div><br>';
$this->_stringtoshow.='<div id="placeholder_'.$tag.'" style="width:'.$this->width.'px;height:'.$this->height.'px;" class="dolgraph"></div>'."\n"; $this->_stringtoshow.='<div id="placeholder_'.$tag.'" style="width:'.$this->width.'px;height:'.$this->height.'px;" class="dolgraph"></div>'."\n";
$this->_stringtoshow.='<script id="'.$tag.'">'."\n"; $this->_stringtoshow.='<script id="'.$tag.'">'."\n";
$this->_stringtoshow.='$(function () {'."\n"; $this->_stringtoshow.='$(function () {'."\n";

View File

@ -30,21 +30,61 @@
abstract class Stats abstract class Stats
{ {
protected $db; protected $db;
var $_lastfetchdategetNbByMonthWithPrevYear; // Date of cache file read by getNbByMonthWithPrevYear
/** /**
* Return nb of entity by month for several years * Return nb of elements by month for several years
* *
* @param int $endyear Start year * @param int $endyear Start year
* @param int $startyear End year * @param int $startyear End year
* @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save)
* @return array Array of values * @return array Array of values
*/ */
function getNbByMonthWithPrevYear($endyear,$startyear) function getNbByMonthWithPrevYear($endyear,$startyear,$cachedelay=0)
{ {
global $conf,$user,$langs;
if ($startyear > $endyear) return -1; if ($startyear > $endyear) return -1;
if (! empty($cachedelay))
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
}
$datay=array(); $datay=array();
$newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.$langs->defaultlang.'_user'.$user->id.'.cache';
$newmask='0644';
$nowgmt = dol_now();
// Search into cache
$foundintocache=0;
if ($cachedelay > 0)
{
$filedate=dol_filemtime($newpathofdestfile);
if ($filedate >= ($nowgmt - $cachedelay))
{
$foundintocache=1;
$this->_lastfetchdategetNbByMonthWithPrevYear=$filedate;
}
else
{
dol_syslog(get_class($this)."::getNbByMonthWithPrevYear cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
}
}
// Load file into $data
if ($foundintocache) // Cache file found and is not too old
{
dol_syslog(get_class($this)."::getNbByMonthWithPrevYear read data from cache file ".$newpathofdestfile." ".$filedate.".");
$data = dol_json_decode(file_get_contents($newpathofdestfile), true);
}
else
{
$year=$startyear; $year=$startyear;
while ($year <= $endyear) while ($year <= $endyear)
{ {
@ -65,12 +105,28 @@ abstract class Stats
} }
} }
}
// Save cache file
if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1))
{
dol_syslog(get_class($this)."::getNbByMonthWithPrevYear save cache file ".$newpathofdestfile." onto disk.");
if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp);
$fp = fopen($newpathofdestfile, 'w');
fwrite($fp, dol_json_encode($data));
fclose($fp);
if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
@chmod($newpathofdestfile, octdec($newmask));
$this->_lastfetchdategetNbByMonthWithPrevYear=$nowgmt;
}
// return array(array('Month',val1,val2,val3),...) // return array(array('Month',val1,val2,val3),...)
return $data; return $data;
} }
/** /**
* Return amount of entity by month for several years * Return amount of elements by month for several years
* *
* @param int $endyear Start year * @param int $endyear Start year
* @param int $startyear End year * @param int $startyear End year
@ -210,9 +266,10 @@ abstract class Stats
* *
* @param int $year Year * @param int $year Year
* @param string $sql SQL * @param string $sql SQL
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is a number
* @return array Array of nb each month * @return array Array of nb each month
*/ */
function _getNbByMonth($year, $sql) function _getNbByMonth($year, $sql, $format=0)
{ {
$result=array(); $result=array();
$res=array(); $res=array();
@ -246,9 +303,9 @@ abstract class Stats
for ($i = 1 ; $i < 13 ; $i++) for ($i = 1 ; $i < 13 ; $i++)
{ {
$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),"%b"); $month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b"));
$month=dol_substr($month,0,3); $month=dol_substr($month,0,3);
$data[$i-1] = array(ucfirst($month), $res[$i]); $data[$i-1] = array($month, $res[$i]);
} }
return $data; return $data;
@ -260,9 +317,10 @@ abstract class Stats
* *
* @param int $year Year * @param int $year Year
* @param string $sql SQL * @param string $sql SQL
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is a number
* @return array * @return array
*/ */
function _getAmountByMonth($year, $sql) function _getAmountByMonth($year, $sql, $format=0)
{ {
$result=array(); $result=array();
$res=array(); $res=array();
@ -294,9 +352,9 @@ abstract class Stats
for ($i = 1 ; $i < 13 ; $i++) for ($i = 1 ; $i < 13 ; $i++)
{ {
$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),"%b"); $month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b"));
$month=dol_substr($month,0,3); $month=dol_substr($month,0,3);
$data[$i-1] = array(ucfirst($month), $res[$i]); $data[$i-1] = array($month, $res[$i]);
} }
return $data; return $data;
@ -307,6 +365,7 @@ abstract class Stats
* *
* @param int $year Year * @param int $year Year
* @param string $sql SQL * @param string $sql SQL
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is a number
* @return array * @return array
*/ */
function _getAverageByMonth($year, $sql) function _getAverageByMonth($year, $sql)
@ -340,9 +399,9 @@ abstract class Stats
for ($i = 1 ; $i < 13 ; $i++) for ($i = 1 ; $i < 13 ; $i++)
{ {
$month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),"%b"); $month=dol_print_date(dol_mktime(12,0,0,$i,1,$year),($format?"%m":"%b"));
$month=dol_substr($month,0,3); $month=dol_substr($month,0,3);
$data[$i-1] = array(ucfirst($month), $res[$i]); $data[$i-1] = array($month, $res[$i]);
} }
return $data; return $data;