33 protected $lastfetchdate = array();
34 public $cachefilesuffix =
'';
48 global $conf, $user, $langs;
50 if ($startyear > $endyear)
return -1;
55 if (!empty($cachedelay))
57 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
58 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
61 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
70 if ($filedate >= ($nowgmt - $cachedelay))
74 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
76 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.");
82 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
83 $data = json_decode(file_get_contents($newpathofdestfile),
true);
86 $sm = $startmonth - 1;
87 if ($sm != 0) $year = $year - 1;
88 while ($year <= $endyear)
90 $datay[$year] = $this->getNbByMonth($year, $format);
96 for ($i = 0; $i < 12; $i++)
98 $data[$i][] = $datay[$endyear][($i + $sm) % 12][0];
100 while ($year <= $endyear)
102 $data[$i][] = $datay[$year - (1 - ((int) ($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1];
109 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1))
111 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
113 $fp = fopen($newpathofdestfile,
'w');
114 fwrite($fp, json_encode($data));
116 if (!empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
117 @chmod($newpathofdestfile, octdec($newmask));
119 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
141 global $conf, $user, $langs;
143 if ($startyear > $endyear)
return -1;
148 if (!empty($cachedelay))
150 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
151 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
154 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
163 if ($filedate >= ($nowgmt - $cachedelay))
167 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
169 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.");
176 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
177 $data = json_decode(file_get_contents($newpathofdestfile),
true);
180 $sm = $startmonth - 1;
181 if ($sm != 0) $year = $year - 1;
182 while ($year <= $endyear)
184 $datay[$year] = $this->getAmountByMonth($year, $format);
190 for ($i = 0; $i < 12; $i++)
192 $data[$i][] = isset($datay[$endyear][($i + $sm) % 12][
'label']) ? $datay[$endyear][($i + $sm) % 12][
'label'] : $datay[$endyear][($i + $sm) % 12][0];
194 while ($year <= $endyear)
196 $data[$i][] = $datay[$year - (1 - ((int) ($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1];
203 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1))
205 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
207 $fp = fopen($newpathofdestfile,
'w');
210 fwrite($fp, json_encode($data));
212 if (!empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
213 @chmod($newpathofdestfile, octdec($newmask));
214 }
else dol_syslog(
"Failed to write cache file", LOG_ERR);
215 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
230 if ($startyear > $endyear)
return -1;
235 while ($year <= $endyear)
237 $datay[$year] = $this->getAverageByMonth($year);
243 for ($i = 0; $i < 12; $i++)
245 $data[$i][] = $datay[$endyear][$i][0];
247 while ($year <= $endyear)
249 $data[$i][] = $datay[$year][$i][1];
267 global $conf, $user, $langs;
272 if (!empty($cachedelay))
274 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
275 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
278 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
287 if ($filedate >= ($nowgmt - $cachedelay))
291 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
293 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.");
300 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
301 $data = json_decode(file_get_contents($newpathofdestfile),
true);
303 $data = $this->getAllByProduct($year, $limit);
308 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1))
310 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
312 $fp = fopen($newpathofdestfile,
'w');
315 fwrite($fp, json_encode($data));
317 if (!empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
318 @chmod($newpathofdestfile, octdec($newmask));
320 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
342 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
350 $row = $this->
db->fetch_row(
$resql);
373 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
381 $row = $this->
db->fetch_object(
$resql);
382 $result[$i][
'year'] = $row->year;
383 $result[$i][
'nb'] = $row->nb;
384 if ($i > 0 && $row->nb > 0) $result[$i - 1][
'nb_diff'] = ($result[$i - 1][
'nb'] - $row->nb) / $row->nb * 100;
385 $result[$i][
'total'] = $row->total;
386 if ($i > 0 && $row->total > 0) $result[$i - 1][
'total_diff'] = ($result[$i - 1][
'total'] - $row->total) / $row->total * 100;
387 $result[$i][
'avg'] = $row->avg;
388 if ($i > 0 && $row->avg > 0) $result[$i - 1][
'avg_diff'] = ($result[$i - 1][
'avg'] - $row->avg) / $row->avg * 100;
390 if (isset($row->weighted))
392 $result[$i][
'weighted'] = $row->weighted;
393 if ($i > 0 && $row->weighted > 0) $result[$i - 1][
'avg_weighted'] = ($result[$i - 1][
'weighted'] - $row->weighted) / $row->weighted * 100;
422 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
430 $row = $this->
db->fetch_row(
$resql);
432 $result[$j] = $row[1];
440 for ($i = 1; $i < 13; $i++)
442 $res[$i] = (isset($result[$i]) ? $result[$i] : 0);
447 for ($i = 1; $i < 13; $i++)
450 if ($format == 0) $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
451 elseif ($format == 1) $month = $i;
452 elseif ($format == 2) $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
455 $data[$i - 1] = array($month, $res[$i]);
479 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
488 $row = $this->
db->fetch_row(
$resql);
490 $result[$j] = $row[1];
496 for ($i = 1; $i < 13; $i++)
498 $res[$i] = (int) round((isset($result[$i]) ? $result[$i] : 0));
503 for ($i = 1; $i < 13; $i++)
506 if ($format == 0) $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
507 elseif ($format == 1) $month = $i;
508 elseif ($format == 2) $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
511 $data[$i - 1] = array($month, $res[$i]);
535 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
543 $row = $this->
db->fetch_row(
$resql);
545 $result[$j] = $row[1];
551 for ($i = 1; $i < 13; $i++)
553 $res[$i] = (isset($result[$i]) ? $result[$i] : 0);
558 for ($i = 1; $i < 13; $i++)
561 if ($format == 0) $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
562 elseif ($format == 1) $month = $i;
563 elseif ($format == 2) $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
566 $data[$i - 1] = array($month, $res[$i]);
588 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
596 $row = $this->
db->fetch_row(
$resql);
597 if ($i < $limit || $num == $limit) $result[$i] = array($row[0], $row[1]);
598 else $other += $row[1];
601 if ($num > $limit) $result[$i] = array($langs->transnoentitiesnoconv(
"Other"), $other);
getAllByProductEntry($year, $cachedelay=0, $limit=10)
Return count, and sum of products.
Parent class of statistics class.
getAmountByMonthWithPrevYear($endyear, $startyear, $cachedelay=0, $format=0, $startmonth=1)
Return amount of elements by month for several years.
getNbByMonthWithPrevYear($endyear, $startyear, $cachedelay=0, $format=0, $startmonth=1)
Return nb of elements by month for several years.
dol_now($mode= 'auto')
Return date for now.
dol_is_dir($folder)
Test if filename is a directory.
_getNbByMonth($year, $sql, $format=0)
Renvoie le nombre de documents par mois pour une annee donnee Return number of documents per month fo...
$conf db
API class for accounts.
_getAllByProduct($sql, $limit=10)
Return number or total of product refs.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
_getAllByYear($sql)
Return nb of elements, total amount and avg amount each year.
dol_filemtime($pathoffile)
Return time of a file.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
_getAmountByMonth($year, $sql, $format=0)
Return the amount per month for a given year.
getAverageByMonthWithPrevYear($endyear, $startyear)
Return average of entity by month for several years.
_getNbByYear($sql)
Return nb of elements by year.
_getAverageByMonth($year, $sql, $format=0)
Renvoie le montant moyen par mois pour une annee donnee Return the amount average par month for a giv...
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)