41 protected $lastfetchdate = array();
46 public $cachefilesuffix =
'';
108 global
$conf, $user, $langs;
110 if ($startyear > $endyear) {
118 if (!empty($cachedelay)) {
119 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
122 $newpathofdestfile =
$conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.
$conf->entity.
'_user'.$user->id.
'.cache';
129 if ($cachedelay > 0) {
131 if ($filedate >= ($nowgmt - $cachedelay)) {
134 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
136 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.");
140 if ($foundintocache) {
141 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
142 $data = json_decode(file_get_contents($newpathofdestfile),
true);
143 '@phan-var-force array<int<0,11>,array{0:int<1,12>,1:int}> $data';
146 $sm = $startmonth - 1;
150 while ($year <= $endyear) {
155 for ($i = 0; $i < 12; $i++) {
156 $data[$i][] = $datay[$endyear][($i + $sm) % 12][0];
158 while ($year <= $endyear) {
160 $data[$i][] = $datay[$year - (1 - (int) floor(($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1];
168 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
169 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
173 $fp = @fopen($newpathofdestfile,
'w');
175 fwrite($fp, json_encode($data));
178 dol_syslog(
"Failed to save cache file ".$newpathofdestfile, LOG_ERR);
182 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
210 global
$conf, $user, $langs;
212 if ($startyear > $endyear) {
220 if (!empty($cachedelay)) {
221 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
224 $newpathofdestfile =
$conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.
$conf->entity.
'_user'.$user->id.
'.cache';
231 if ($cachedelay > 0) {
233 if ($filedate >= ($nowgmt - $cachedelay)) {
236 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
238 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.");
243 if ($foundintocache) {
244 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
245 $data = json_decode(file_get_contents($newpathofdestfile),
true);
248 $sm = $startmonth - 1;
252 while ($year <= $endyear) {
258 for ($i = 0; $i < 12; $i++) {
259 $data[$i][] = isset($datay[$endyear][($i + $sm) % 12][
'label']) ? $datay[$endyear][($i + $sm) % 12][
'label'] : $datay[$endyear][($i + $sm) % 12][0];
261 while ($year <= $endyear) {
263 $data[$i][] = $datay[$year - (1 - (int) floor(($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1];
270 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
271 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
275 $fp = @fopen($newpathofdestfile,
'w');
277 fwrite($fp, json_encode($data));
280 dol_syslog(
"Failed to save cache file ".$newpathofdestfile, LOG_ERR);
284 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
305 if ($startyear > $endyear) {
313 while ($year <= $endyear) {
318 for ($i = 0; $i < 12; $i++) {
319 $data[$i][] = $datay[$endyear][$i][0];
321 while ($year <= $endyear) {
322 $data[$i][] = $datay[$year][$i][1];
340 global
$conf, $user, $langs;
345 if (!empty($cachedelay)) {
346 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
349 $newpathofdestfile =
$conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.
$conf->entity.
'_user'.$user->id.
'.cache';
356 if ($cachedelay > 0) {
358 if ($filedate >= ($nowgmt - $cachedelay)) {
361 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
363 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.");
368 if ($foundintocache) {
369 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
370 $data = json_decode(file_get_contents($newpathofdestfile),
true);
371 '@phan-var-force array<int<0,11>,array{0:int<1,12>,1:int|float}> $data';
377 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
378 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
382 $fp = @fopen($newpathofdestfile,
'w');
384 fwrite($fp, json_encode($data));
387 dol_syslog(
"Failed to save cache file ".$newpathofdestfile, LOG_ERR);
391 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
413 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
414 $resql = $this->db->query($sql);
416 $num = $this->db->num_rows($resql);
419 $row = $this->db->fetch_row($resql);
423 $this->db->free($resql);
442 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
443 $resql = $this->db->query($sql);
445 $num = $this->db->num_rows($resql);
448 $row = $this->db->fetch_object($resql);
449 $result[$i][
'year'] = $row->year;
450 $result[$i][
'nb'] = $row->nb;
451 if ($i > 0 && $row->nb > 0) {
452 $result[$i - 1][
'nb_diff'] = ($result[$i - 1][
'nb'] - $row->nb) / $row->nb * 100;
455 if (property_exists($row,
'total')) {
456 $result[$i][
'total'] = $row->total;
457 if ($i > 0 && $row->total > 0) {
458 $result[$i - 1][
'total_diff'] = ($result[$i - 1][
'total'] - $row->total) / $row->total * 100;
462 if (property_exists($row,
'total')) {
463 $result[$i][
'avg'] = $row->avg;
464 if ($i > 0 && $row->avg > 0) {
465 $result[$i - 1][
'avg_diff'] = ($result[$i - 1][
'avg'] - $row->avg) / $row->avg * 100;
469 if (property_exists($row,
'weighted')) {
470 $result[$i][
'weighted'] = $row->weighted;
471 if ($i > 0 && $row->weighted > 0) {
472 $result[$i - 1][
'avg_weighted'] = ($result[$i - 1][
'weighted'] - $row->weighted) / $row->weighted * 100;
477 $this->db->free($resql);
502 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
503 $resql = $this->db->query($sql);
505 $num = $this->db->num_rows($resql);
509 $row = $this->db->fetch_row($resql);
511 $result[$j] = $row[1];
514 $this->db->free($resql);
519 for ($i = 1; $i < 13; $i++) {
520 $res[$i] = (isset($result[$i]) ? $result[$i] : 0);
525 for ($i = 1; $i < 13; $i++) {
528 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
529 } elseif ($format == 1) {
531 } elseif ($format == 2) {
532 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
536 $data[$i - 1] = array($month, $res[$i]);
559 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
561 $resql = $this->db->query($sql);
563 $num = $this->db->num_rows($resql);
566 $row = $this->db->fetch_row($resql);
568 $result[$j] = $row[1];
571 $this->db->free($resql);
576 for ($i = 1; $i < 13; $i++) {
577 $res[$i] = (int) round((isset($result[$i]) ? $result[$i] : 0));
582 for ($i = 1; $i < 13; $i++) {
585 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
586 } elseif ($format == 1) {
588 } elseif ($format == 2) {
589 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
593 $data[$i - 1] = array($month, $res[$i]);
616 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
617 $resql = $this->db->query($sql);
619 $num = $this->db->num_rows($resql);
623 $row = $this->db->fetch_row($resql);
625 $result[$j] = $row[1];
628 $this->db->free($resql);
633 for ($i = 1; $i < 13; $i++) {
634 $res[$i] = (isset($result[$i]) ? $result[$i] : 0);
639 for ($i = 1; $i < 13; $i++) {
642 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
643 } elseif ($format == 1) {
645 } elseif ($format == 2) {
646 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
650 $data[$i - 1] = array($month, $res[$i]);
672 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
673 $resql = $this->db->query($sql);
675 $num = $this->db->num_rows($resql);
679 $row = $this->db->fetch_row($resql);
680 if ($i < $limit || $num == $limit) {
681 $result[$i] = array($row[0], $row[1]);
688 $result[$i] = array($langs->transnoentitiesnoconv(
"Other"), $other);
690 $this->db->free($resql);
707 $resql = $this->db->query($sql);
709 $num = $this->db->num_rows($resql);
712 $row = $this->db->fetch_row($resql);
719 $this->db->free($resql);
735 $msg = get_class($this).
"::".__FUNCTION__.
" not implemented";
738 return array($l,$l,$l,$l,$l,$l,$l,$l,$l,$l,$l,$l);
Parent class of statistics class.
getNbByMonth($year, $format=0)
getAllByProduct($year, $limit=0)
Return nb, amount of predefined product for year.
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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...