Work on boxes with graph
This commit is contained in:
parent
d8883dba7f
commit
4b00da5fa8
@ -64,13 +64,13 @@ 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);
|
||||
|
||||
$text = $langs->trans("BoxInvoicesPerMonth",$max);
|
||||
$text = $langs->trans("BoxCustomersInvoicesPerMonth",$max);
|
||||
$this->info_box_head = array(
|
||||
'text' => $text,
|
||||
'limit'=> dol_strlen($text),
|
||||
@ -85,7 +85,7 @@ class box_graph_invoices_permonth extends ModeleBoxes
|
||||
{
|
||||
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;
|
||||
@ -93,23 +93,22 @@ class box_graph_invoices_permonth extends ModeleBoxes
|
||||
$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);
|
||||
|
||||
|
||||
// Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...)
|
||||
$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';
|
||||
|
||||
|
||||
$px1 = new DolGraph();
|
||||
$mesg = $px1->isGraphKo();
|
||||
if (! $mesg)
|
||||
{
|
||||
$px1->SetData($data);
|
||||
$px1->SetData($data1);
|
||||
unset($data1);
|
||||
$px1->SetPrecisionY(0);
|
||||
$i=$startyear;$legend=array();
|
||||
while ($i <= $endyear)
|
||||
@ -124,17 +123,61 @@ class box_graph_invoices_permonth extends ModeleBoxes
|
||||
$px1->SetYLabel($langs->trans("NumberOfBills"));
|
||||
$px1->SetShading(3);
|
||||
$px1->SetHorizTickIncrement(1);
|
||||
$px1->SetPrecisionY(0);
|
||||
$px1->SetPrecisionY(0);
|
||||
$px1->SetCssPrefix("cssboxes");
|
||||
$px1->mode='depth';
|
||||
//$px1->SetTitle($langs->trans("NumberOfBillsByMonth"));
|
||||
|
||||
$px1->SetTitle($langs->trans("NumberOfBillsByMonth"));
|
||||
|
||||
$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)));
|
||||
|
||||
$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';
|
||||
|
||||
$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("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);
|
||||
}
|
||||
|
||||
|
||||
if (! $mesg)
|
||||
{
|
||||
$this->info_box_contents[0][0] = array('td' => 'align="center"','textnoformat'=>$px1->show());
|
||||
$stringtoshow ='<div class="fichecenter">';
|
||||
//$stringtoshow.='<div class="fichehalfleft">';
|
||||
//$stringtoshow.=$px1->show();
|
||||
//$stringtoshow.='</div>';
|
||||
//$stringtoshow.='<div class="fichehalfright">';
|
||||
$stringtoshow.=$px2->show();
|
||||
//$stringtoshow.='</div>';
|
||||
$stringtoshow.='</div>';
|
||||
$this->info_box_contents[0][0] = array('td' => 'align="center"','textnoformat'=>$stringtoshow);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -48,8 +48,9 @@ class DolGraph
|
||||
private $_library='jflot'; // Graphic library to use (jflot, artichow)
|
||||
|
||||
//! Array of data
|
||||
var $data; // array(array('abs1',valA1,valB1), array('abs2',valA2,valB2), ...)
|
||||
var $title;
|
||||
var $data; // Data of graph: array(array('abs1',valA1,valB1), array('abs2',valA2,valB2), ...)
|
||||
var $title; // Title of graph
|
||||
var $cssprefix=''; // To add into css styles
|
||||
var $width=380;
|
||||
var $height=200;
|
||||
var $MaxValue=0;
|
||||
@ -337,6 +338,17 @@ class DolGraph
|
||||
$this->SetShading = $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set shading
|
||||
*
|
||||
* @param string $s Shading
|
||||
* @return void
|
||||
*/
|
||||
function SetCssPrefix($s)
|
||||
{
|
||||
$this->cssprefix = $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset bg color
|
||||
*
|
||||
@ -785,8 +797,8 @@ class DolGraph
|
||||
$tag=dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file),'_',array('-','.'))));
|
||||
|
||||
$this->_stringtoshow ='<!-- Build using '.$this->_library.' -->'."\n";
|
||||
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";
|
||||
if (! empty($this->title)) $this->_stringtoshow.='<div align="center" class="dolgraphtitle'.(empty($this->cssprefix)?'':' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>';
|
||||
$this->_stringtoshow.='<div id="placeholder_'.$tag.'" style="width:'.$this->width.'px;height:'.$this->height.'px;" class="dolgraph'.(empty($this->cssprefix)?'':' dolgraph'.$this->cssprefix).'"></div>'."\n";
|
||||
$this->_stringtoshow.='<script id="'.$tag.'">'."\n";
|
||||
$this->_stringtoshow.='$(function () {'."\n";
|
||||
$i=$firstlot;
|
||||
|
||||
@ -30,8 +30,8 @@
|
||||
abstract class Stats
|
||||
{
|
||||
protected $db;
|
||||
var $_lastfetchdategetNbByMonthWithPrevYear; // Date of cache file read by getNbByMonthWithPrevYear
|
||||
|
||||
var $_lastfetchdate=array(); // Dates of cache file read by methods
|
||||
|
||||
|
||||
/**
|
||||
* Return nb of elements by month for several years
|
||||
@ -44,23 +44,23 @@ abstract class Stats
|
||||
function getNbByMonthWithPrevYear($endyear,$startyear,$cachedelay=0)
|
||||
{
|
||||
global $conf,$user,$langs;
|
||||
|
||||
|
||||
if ($startyear > $endyear) return -1;
|
||||
|
||||
if (! empty($cachedelay))
|
||||
$datay=array();
|
||||
|
||||
// Search into cache
|
||||
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();
|
||||
|
||||
$newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.$langs->defaultlang.'_user'.$user->id.'.cache';
|
||||
$newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.__FUNCTION__.'_'.$langs->defaultlang.'_user'.$user->id.'.cache';
|
||||
$newmask='0644';
|
||||
|
||||
$nowgmt = dol_now();
|
||||
|
||||
// Search into cache
|
||||
$foundintocache=0;
|
||||
if ($cachedelay > 0)
|
||||
{
|
||||
@ -68,19 +68,19 @@ abstract class Stats
|
||||
if ($filedate >= ($nowgmt - $cachedelay))
|
||||
{
|
||||
$foundintocache=1;
|
||||
|
||||
$this->_lastfetchdategetNbByMonthWithPrevYear=$filedate;
|
||||
|
||||
$this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$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.");
|
||||
dol_syslog(get_class($this).'_'.__FUNCTION__." 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.".");
|
||||
dol_syslog(get_class($this).'_'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate.".");
|
||||
$data = dol_json_decode(file_get_contents($newpathofdestfile), true);
|
||||
}
|
||||
else
|
||||
@ -91,9 +91,9 @@ abstract class Stats
|
||||
$datay[$year] = $this->getNbByMonth($year);
|
||||
$year++;
|
||||
}
|
||||
|
||||
|
||||
$data = array();
|
||||
|
||||
|
||||
for ($i = 0 ; $i < 12 ; $i++)
|
||||
{
|
||||
$data[$i][]=$datay[$endyear][$i][0];
|
||||
@ -104,23 +104,22 @@ abstract class Stats
|
||||
$year++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Save cache file
|
||||
if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1))
|
||||
{
|
||||
dol_syslog(get_class($this)."::getNbByMonthWithPrevYear save cache file ".$newpathofdestfile." onto disk.");
|
||||
dol_syslog(get_class($this).'_'.__FUNCTION__." 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;
|
||||
|
||||
$this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt;
|
||||
}
|
||||
|
||||
|
||||
// return array(array('Month',val1,val2,val3),...)
|
||||
return $data;
|
||||
}
|
||||
@ -130,32 +129,86 @@ abstract class Stats
|
||||
*
|
||||
* @param int $endyear Start 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
|
||||
*/
|
||||
function getAmountByMonthWithPrevYear($endyear,$startyear)
|
||||
function getAmountByMonthWithPrevYear($endyear,$startyear,$cachedelay=0)
|
||||
{
|
||||
global $conf,$user,$langs;
|
||||
|
||||
if ($startyear > $endyear) return -1;
|
||||
|
||||
$datay=array();
|
||||
|
||||
$year=$startyear;
|
||||
while($year <= $endyear)
|
||||
// Search into cache
|
||||
if (! empty($cachedelay))
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
|
||||
}
|
||||
|
||||
$newpathofdestfile=$conf->user->dir_temp.'/'.get_class($this).'_'.__FUNCTION__.'_'.$langs->defaultlang.'_user'.$user->id.'.cache';
|
||||
$newmask='0644';
|
||||
|
||||
$nowgmt = dol_now();
|
||||
|
||||
$foundintocache=0;
|
||||
if ($cachedelay > 0)
|
||||
{
|
||||
$filedate=dol_filemtime($newpathofdestfile);
|
||||
if ($filedate >= ($nowgmt - $cachedelay))
|
||||
{
|
||||
$foundintocache=1;
|
||||
|
||||
$this->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$filedate;
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_syslog(get_class($this).'_'.__FUNCTION__." 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).'_'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate.".");
|
||||
$data = dol_json_decode(file_get_contents($newpathofdestfile), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$datay[$year] = $this->getAmountByMonth($year);
|
||||
$year++;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
for ($i = 0 ; $i < 12 ; $i++)
|
||||
{
|
||||
$data[$i][]=$datay[$endyear][$i][0];
|
||||
$year=$startyear;
|
||||
while($year <= $endyear)
|
||||
{
|
||||
$data[$i][]=$datay[$year][$i][1];
|
||||
$datay[$year] = $this->getAmountByMonth($year);
|
||||
$year++;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
for ($i = 0 ; $i < 12 ; $i++)
|
||||
{
|
||||
$data[$i][]=$datay[$endyear][$i][0];
|
||||
$year=$startyear;
|
||||
while($year <= $endyear)
|
||||
{
|
||||
$data[$i][]=$datay[$year][$i][1];
|
||||
$year++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save cache file
|
||||
if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1))
|
||||
{
|
||||
dol_syslog(get_class($this).'_'.__FUNCTION__." 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->_lastfetchdate[get_class($this).'_'.__FUNCTION__]=$nowgmt;
|
||||
}
|
||||
|
||||
return $data;
|
||||
@ -266,7 +319,7 @@ abstract class Stats
|
||||
*
|
||||
* @param int $year Year
|
||||
* @param string $sql SQL
|
||||
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is a number
|
||||
* @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
|
||||
*/
|
||||
function _getNbByMonth($year, $sql, $format=0)
|
||||
@ -317,7 +370,7 @@ abstract class Stats
|
||||
*
|
||||
* @param int $year Year
|
||||
* @param string $sql SQL
|
||||
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is a number
|
||||
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is a number
|
||||
* @return array
|
||||
*/
|
||||
function _getAmountByMonth($year, $sql, $format=0)
|
||||
@ -365,7 +418,7 @@ abstract class Stats
|
||||
*
|
||||
* @param int $year Year
|
||||
* @param string $sql SQL
|
||||
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is a number
|
||||
* @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is a number
|
||||
* @return array
|
||||
*/
|
||||
function _getAverageByMonth($year, $sql)
|
||||
|
||||
@ -78,7 +78,9 @@ NoRecordedContracts=No recorded contracts
|
||||
BoxLatestSupplierOrders=Latest supplier orders
|
||||
BoxTitleLatestSupplierOrders=%s latest supplier orders
|
||||
NoSupplierOrder=No recorded supplier order
|
||||
BoxInvoicesPerMonth=Invoices per month
|
||||
BoxOrdersPerMonth=Orders per month
|
||||
BoxCustomersInvoicesPerMonth=Customer invoices per month
|
||||
BoxSuppliersInvoicesPerMonth=Supplier invoices per month
|
||||
BoxCustomersOrdersPerMonth=Customer orders per month
|
||||
BoxSuppliersOrdersPerMonth=Supplier orders per month
|
||||
BoxProposalsPerMonth=Proposals per month
|
||||
NoTooLowStockProducts=No product under the low stock limit
|
||||
@ -78,7 +78,9 @@ NoRecordedContracts=Pas de contrat enregistré
|
||||
BoxLatestSupplierOrders=Dernières commandes fournisseur
|
||||
BoxTitleLatestSupplierOrders=Les %s dernières commandes fournisseur enregistrées
|
||||
NoSupplierOrder=Pas de commande fournisseur enregistrée
|
||||
BoxInvoicesPerMonth=Factures par mois
|
||||
BoxOrdersPerMonth=Commandes par mois
|
||||
BoxCustomersInvoicesPerMonth=Factures clients par mois
|
||||
BoxSuppliersInvoicesPerMonth=Factures fournisseurs par mois
|
||||
BoxCustomersOrdersPerMonth=Commandes clients par mois
|
||||
BoxSuppliersOrdersPerMonth=Commandes fournisseurs par mois
|
||||
BoxProposalsPerMonth=Proposition par mois
|
||||
NoTooLowStockProducts=Pas de produits sous le seuil de stock minimal
|
||||
|
||||
@ -1389,6 +1389,9 @@ div.error {
|
||||
color:#333333;
|
||||
}
|
||||
|
||||
.dolgraphtitle { margin-top: 6px; margin-bottom: 4px; }
|
||||
.dolgraphtitlecssboxes { margin: 0px; }
|
||||
|
||||
#pictotitle {
|
||||
padding-left:5px;
|
||||
padding-right:1px;
|
||||
|
||||
@ -1552,6 +1552,9 @@ a.impayee:hover { font-weight: bold; color: #550000; }
|
||||
|
||||
.fieldrequired { font-weight: bold; color: #000055; }
|
||||
|
||||
.dolgraphtitle { margin-top: 6px; margin-bottom: 4px; }
|
||||
.dolgraphtitlecssboxes { margin: 0px; }
|
||||
|
||||
.photo {
|
||||
border: 0px;
|
||||
/* filter:alpha(opacity=55); */
|
||||
|
||||
@ -1684,6 +1684,9 @@ a.impayee:hover { font-weight: bold; color: #550000; }
|
||||
|
||||
.fieldrequired { font-weight: bold; color: #000055; }
|
||||
|
||||
.dolgraphtitle { margin-top: 6px; margin-bottom: 4px; }
|
||||
.dolgraphtitlecssboxes { margin: 0px; }
|
||||
|
||||
.photo {
|
||||
border: 0px;
|
||||
/* filter:alpha(opacity=55); */
|
||||
|
||||
@ -1672,6 +1672,9 @@ a.impayee:hover { font-weight: bold; color: #550000; }
|
||||
|
||||
.fieldrequired { font-weight: bold; color: #000055; }
|
||||
|
||||
.dolgraphtitle { margin-top: 6px; margin-bottom: 4px; }
|
||||
.dolgraphtitlecssboxes { margin: 0px; }
|
||||
|
||||
.photo {
|
||||
border: 0px;
|
||||
/* filter:alpha(opacity=55); */
|
||||
|
||||
@ -1962,6 +1962,9 @@ a.impayee:hover { font-weight: bold; color: #550000; }
|
||||
|
||||
.fieldrequired { font-weight: bold; color: #000055; }
|
||||
|
||||
.dolgraphtitle { margin-top: 6px; margin-bottom: 4px; }
|
||||
.dolgraphtitlecssboxes { margin: 0px; }
|
||||
|
||||
.photo {
|
||||
border: 0px;
|
||||
/* filter:alpha(opacity=55); */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user