34 protected $lastfetchdate = array();
35 public $cachefilesuffix =
'';
97 global $conf, $user, $langs;
99 if ($startyear > $endyear) {
107 if (!empty($cachedelay)) {
108 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
111 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
117 if ($cachedelay > 0) {
119 if ($filedate >= ($nowgmt - $cachedelay)) {
122 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
124 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.");
128 if ($foundintocache) {
129 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
130 $data = json_decode(file_get_contents($newpathofdestfile),
true);
131 '@phan-var-force array<int<0,11>,array{0:int<1,12>,1:int}> $data';
134 $sm = $startmonth - 1;
138 while ($year <= $endyear) {
143 for ($i = 0; $i < 12; $i++) {
144 $data[$i][] = $datay[$endyear][($i + $sm) % 12][0];
146 while ($year <= $endyear) {
148 $data[$i][] = $datay[$year - (1 - (int) floor(($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1];
156 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
157 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
161 $fp = @fopen($newpathofdestfile,
'w');
163 fwrite($fp, json_encode($data));
166 dol_syslog(
"Failed to save cache file ".$newpathofdestfile, LOG_ERR);
170 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
198 global $conf, $user, $langs;
200 if ($startyear > $endyear) {
208 if (!empty($cachedelay)) {
209 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
212 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
218 if ($cachedelay > 0) {
220 if ($filedate >= ($nowgmt - $cachedelay)) {
223 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
225 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.");
230 if ($foundintocache) {
231 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
232 $data = json_decode(file_get_contents($newpathofdestfile),
true);
235 $sm = $startmonth - 1;
239 while ($year <= $endyear) {
245 for ($i = 0; $i < 12; $i++) {
246 $data[$i][] = isset($datay[$endyear][($i + $sm) % 12][
'label']) ? $datay[$endyear][($i + $sm) % 12][
'label'] : $datay[$endyear][($i + $sm) % 12][0];
248 while ($year <= $endyear) {
250 $data[$i][] = $datay[$year - (1 - floor(($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1];
257 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
258 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
262 $fp = @fopen($newpathofdestfile,
'w');
264 fwrite($fp, json_encode($data));
267 dol_syslog(
"Failed to save cache file ".$newpathofdestfile, LOG_ERR);
271 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
292 if ($startyear > $endyear) {
300 while ($year <= $endyear) {
305 for ($i = 0; $i < 12; $i++) {
306 $data[$i][] = $datay[$endyear][$i][0];
308 while ($year <= $endyear) {
309 $data[$i][] = $datay[$year][$i][1];
327 global $conf, $user, $langs;
332 if (!empty($cachedelay)) {
333 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
336 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
342 if ($cachedelay > 0) {
344 if ($filedate >= ($nowgmt - $cachedelay)) {
347 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
349 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.");
354 if ($foundintocache) {
355 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
356 $data = json_decode(file_get_contents($newpathofdestfile),
true);
357 '@phan-var-force array<int<0,11>,array{0:int<1,12>,1:int|float}> $data';
361 $data = $this->getAllByProduct($year, $limit);
365 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
366 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
370 $fp = @fopen($newpathofdestfile,
'w');
372 fwrite($fp, json_encode($data));
375 dol_syslog(
"Failed to save cache file ".$newpathofdestfile, LOG_ERR);
379 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
401 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
402 $resql = $this->db->query($sql);
404 $num = $this->db->num_rows($resql);
407 $row = $this->db->fetch_row($resql);
411 $this->db->free($resql);
430 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
431 $resql = $this->db->query($sql);
433 $num = $this->db->num_rows($resql);
436 $row = $this->db->fetch_object($resql);
437 $result[$i][
'year'] = $row->year;
438 $result[$i][
'nb'] = $row->nb;
439 if ($i > 0 && $row->nb > 0) {
440 $result[$i - 1][
'nb_diff'] = ($result[$i - 1][
'nb'] - $row->nb) / $row->nb * 100;
443 if (property_exists($row,
'total')) {
444 $result[$i][
'total'] = $row->total;
445 if ($i > 0 && $row->total > 0) {
446 $result[$i - 1][
'total_diff'] = ($result[$i - 1][
'total'] - $row->total) / $row->total * 100;
450 if (property_exists($row,
'total')) {
451 $result[$i][
'avg'] = $row->avg;
452 if ($i > 0 && $row->avg > 0) {
453 $result[$i - 1][
'avg_diff'] = ($result[$i - 1][
'avg'] - $row->avg) / $row->avg * 100;
457 if (property_exists($row,
'weighted')) {
458 $result[$i][
'weighted'] = $row->weighted;
459 if ($i > 0 && $row->weighted > 0) {
460 $result[$i - 1][
'avg_weighted'] = ($result[$i - 1][
'weighted'] - $row->weighted) / $row->weighted * 100;
465 $this->db->free($resql);
490 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
491 $resql = $this->db->query($sql);
493 $num = $this->db->num_rows($resql);
497 $row = $this->db->fetch_row($resql);
499 $result[$j] = $row[1];
502 $this->db->free($resql);
507 for ($i = 1; $i < 13; $i++) {
508 $res[$i] = (isset($result[$i]) ? $result[$i] : 0);
513 for ($i = 1; $i < 13; $i++) {
516 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
517 } elseif ($format == 1) {
519 } elseif ($format == 2) {
520 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
524 $data[$i - 1] = array($month, $res[$i]);
547 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
549 $resql = $this->db->query($sql);
551 $num = $this->db->num_rows($resql);
554 $row = $this->db->fetch_row($resql);
556 $result[$j] = $row[1];
559 $this->db->free($resql);
564 for ($i = 1; $i < 13; $i++) {
565 $res[$i] = (int) round((isset($result[$i]) ? $result[$i] : 0));
570 for ($i = 1; $i < 13; $i++) {
573 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
574 } elseif ($format == 1) {
576 } elseif ($format == 2) {
577 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
581 $data[$i - 1] = array($month, $res[$i]);
604 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
605 $resql = $this->db->query($sql);
607 $num = $this->db->num_rows($resql);
611 $row = $this->db->fetch_row($resql);
613 $result[$j] = $row[1];
616 $this->db->free($resql);
621 for ($i = 1; $i < 13; $i++) {
622 $res[$i] = (isset($result[$i]) ? $result[$i] : 0);
627 for ($i = 1; $i < 13; $i++) {
630 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
631 } elseif ($format == 1) {
633 } elseif ($format == 2) {
634 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
638 $data[$i - 1] = array($month, $res[$i]);
660 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
661 $resql = $this->db->query($sql);
663 $num = $this->db->num_rows($resql);
667 $row = $this->db->fetch_row($resql);
668 if ($i < $limit || $num == $limit) {
669 $result[$i] = array($row[0], $row[1]);
676 $result[$i] = array($langs->transnoentitiesnoconv(
"Other"), $other);
678 $this->db->free($resql);
695 $resql = $this->db->query($sql);
697 $num = $this->db->num_rows($resql);
700 $row = $this->db->fetch_row($resql);
707 $this->db->free($resql);
Parent class of statistics class.
getNbByMonth($year, $format=0)
getAmountByMonth($year, $format=0)
_getAmountByYear($sql)
Returns the summed amounts per year for a given number of past years ending now.
_getAverageByMonth($year, $sql, $format=0)
Return the amount average par month for a given year.
_getAmountByMonth($year, $sql, $format=0)
Return the amount per month for a given year.
_getNbByYear($sql)
Return nb of elements by year.
_getAllByYear($sql)
Return nb of elements, total amount and avg amount each year.
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.
getAllByProductEntry($year, $cachedelay=0, $limit=10)
Return count, and sum of products.
getAverageByMonthWithPrevYear($endyear, $startyear)
Return average of entity by month for several years.
_getAllByProduct($sql, $limit=10)
Return number or total of product refs.
_getNbByMonth($year, $sql, $format=0)
Renvoie le nombre de documents par mois pour une annee donnee Return number of documents per month fo...
dol_filemtime($pathoffile)
Return time of a file.
dol_is_dir($folder)
Test if filename is a directory.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)