33 protected $lastfetchdate = array();
34 public $cachefilesuffix =
'';
55 global $conf, $user, $langs;
57 if ($startyear > $endyear) {
64 if (!empty($cachedelay)) {
65 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
66 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
69 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
75 if ($cachedelay > 0) {
77 if ($filedate >= ($nowgmt - $cachedelay)) {
80 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
82 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.");
86 if ($foundintocache) {
87 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
88 $data = json_decode(file_get_contents($newpathofdestfile),
true);
91 $sm = $startmonth - 1;
95 while ($year <= $endyear) {
102 for ($i = 0; $i < 12; $i++) {
103 $data[$i][] = $datay[$endyear][($i + $sm) % 12][0];
105 while ($year <= $endyear) {
107 $data[$i][] = $datay[$year - (1 - floor(($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1];
114 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
115 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
119 $fp = fopen($newpathofdestfile,
'w');
120 fwrite($fp, json_encode($data));
122 if (!empty($conf->global->MAIN_UMASK)) {
123 $newmask = $conf->global->MAIN_UMASK;
125 @chmod($newpathofdestfile, octdec($newmask));
127 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
156 global $conf, $user, $langs;
158 if ($startyear > $endyear) {
165 if (!empty($cachedelay)) {
166 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
167 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
170 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
176 if ($cachedelay > 0) {
178 if ($filedate >= ($nowgmt - $cachedelay)) {
181 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
183 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.");
188 if ($foundintocache) {
189 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
190 $data = json_decode(file_get_contents($newpathofdestfile),
true);
193 $sm = $startmonth - 1;
197 while ($year <= $endyear) {
204 for ($i = 0; $i < 12; $i++) {
205 $data[$i][] = isset($datay[$endyear][($i + $sm) % 12][
'label']) ? $datay[$endyear][($i + $sm) % 12][
'label'] : $datay[$endyear][($i + $sm) % 12][0];
207 while ($year <= $endyear) {
209 $data[$i][] = $datay[$year - (1 - floor(($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1];
216 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
217 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
221 $fp = fopen($newpathofdestfile,
'w');
223 fwrite($fp, json_encode($data));
225 if (!empty($conf->global->MAIN_UMASK)) {
226 $newmask = $conf->global->MAIN_UMASK;
228 @chmod($newpathofdestfile, octdec($newmask));
230 dol_syslog(
"Failed to write cache file", LOG_ERR);
232 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
253 if ($startyear > $endyear) {
260 while ($year <= $endyear) {
267 for ($i = 0; $i < 12; $i++) {
268 $data[$i][] = $datay[$endyear][$i][0];
270 while ($year <= $endyear) {
271 $data[$i][] = $datay[$year][$i][1];
289 global $conf, $user, $langs;
294 if (!empty($cachedelay)) {
295 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
296 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
299 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
305 if ($cachedelay > 0) {
307 if ($filedate >= ($nowgmt - $cachedelay)) {
310 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
312 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.");
317 if ($foundintocache) {
318 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
319 $data = json_decode(file_get_contents($newpathofdestfile),
true);
321 $data = $this->getAllByProduct($year, $limit);
326 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
327 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
331 $fp = fopen($newpathofdestfile,
'w');
333 fwrite($fp, json_encode($data));
335 if (!empty($conf->global->MAIN_UMASK)) {
336 $newmask = $conf->global->MAIN_UMASK;
338 @chmod($newpathofdestfile, octdec($newmask));
340 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
362 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
368 $row = $this->
db->fetch_row(
$resql);
391 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
397 $row = $this->
db->fetch_object(
$resql);
398 $result[$i][
'year'] = $row->year;
399 $result[$i][
'nb'] = $row->nb;
400 if ($i > 0 && $row->nb > 0) {
401 $result[$i - 1][
'nb_diff'] = ($result[$i - 1][
'nb'] - $row->nb) / $row->nb * 100;
403 $result[$i][
'total'] = $row->total;
404 if ($i > 0 && $row->total > 0) {
405 $result[$i - 1][
'total_diff'] = ($result[$i - 1][
'total'] - $row->total) / $row->total * 100;
407 $result[$i][
'avg'] = $row->avg;
408 if ($i > 0 && $row->avg > 0) {
409 $result[$i - 1][
'avg_diff'] = ($result[$i - 1][
'avg'] - $row->avg) / $row->avg * 100;
412 if (isset($row->weighted)) {
413 $result[$i][
'weighted'] = $row->weighted;
414 if ($i > 0 && $row->weighted > 0) {
415 $result[$i - 1][
'avg_weighted'] = ($result[$i - 1][
'weighted'] - $row->weighted) / $row->weighted * 100;
445 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
452 $row = $this->
db->fetch_row(
$resql);
454 $result[$j] = $row[1];
462 for ($i = 1; $i < 13; $i++) {
463 $res[$i] = (isset($result[$i]) ? $result[$i] : 0);
468 for ($i = 1; $i < 13; $i++) {
471 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
472 } elseif ($format == 1) {
474 } elseif ($format == 2) {
475 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
479 $data[$i - 1] = array($month, $res[$i]);
502 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
509 $row = $this->
db->fetch_row(
$resql);
511 $result[$j] = $row[1];
519 for ($i = 1; $i < 13; $i++) {
520 $res[$i] = (int) round((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]);
560 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
567 $row = $this->
db->fetch_row(
$resql);
569 $result[$j] = $row[1];
577 for ($i = 1; $i < 13; $i++) {
578 $res[$i] = (isset($result[$i]) ? $result[$i] : 0);
583 for ($i = 1; $i < 13; $i++) {
586 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
587 } elseif ($format == 1) {
589 } elseif ($format == 2) {
590 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
594 $data[$i - 1] = array($month, $res[$i]);
616 dol_syslog(get_class($this).
'::'.__FUNCTION__, LOG_DEBUG);
623 $row = $this->
db->fetch_row(
$resql);
624 if ($i < $limit || $num == $limit) {
625 $result[$i] = array($row[0], $row[1]);
632 $result[$i] = array($langs->transnoentitiesnoconv(
"Other"), $other);
656 $row = $this->
db->fetch_row(
$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)
Renvoie le montant moyen par mois pour une annee donnee Return the amount average par month for a giv...
_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...
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_filemtime($pathoffile)
Return time of a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_now($mode='auto')
Return date for now.
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)
$conf db
API class for accounts.