33 protected $lastfetchdate = array();
34 public $cachefilesuffix =
'';
41 protected abstract function getNbByMonth($year, $format = 0);
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) {
106 $data[$i][] = $datay[$year - (1 - ((int) ($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1];
113 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
114 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
118 $fp = fopen($newpathofdestfile,
'w');
119 fwrite($fp, json_encode($data));
121 if (!empty($conf->global->MAIN_UMASK)) {
122 $newmask = $conf->global->MAIN_UMASK;
124 @chmod($newpathofdestfile, octdec($newmask));
126 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
155 global $conf, $user, $langs;
157 if ($startyear > $endyear) {
164 if (!empty($cachedelay)) {
165 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
166 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
169 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
175 if ($cachedelay > 0) {
177 if ($filedate >= ($nowgmt - $cachedelay)) {
180 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
182 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.");
187 if ($foundintocache) {
188 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
189 $data = json_decode(file_get_contents($newpathofdestfile),
true);
192 $sm = $startmonth - 1;
196 while ($year <= $endyear) {
203 for ($i = 0; $i < 12; $i++) {
204 $data[$i][] = isset($datay[$endyear][($i + $sm) % 12][
'label']) ? $datay[$endyear][($i + $sm) % 12][
'label'] : $datay[$endyear][($i + $sm) % 12][0];
206 while ($year <= $endyear) {
207 $data[$i][] = $datay[$year - (1 - ((int) ($i + $sm) / 12)) + ($sm == 0 ? 1 : 0)][($i + $sm) % 12][1];
214 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
215 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
219 $fp = fopen($newpathofdestfile,
'w');
221 fwrite($fp, json_encode($data));
223 if (!empty($conf->global->MAIN_UMASK)) {
224 $newmask = $conf->global->MAIN_UMASK;
226 @chmod($newpathofdestfile, octdec($newmask));
228 dol_syslog(
"Failed to write cache file", LOG_ERR);
230 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
251 if ($startyear > $endyear) {
258 while ($year <= $endyear) {
265 for ($i = 0; $i < 12; $i++) {
266 $data[$i][] = $datay[$endyear][$i][0];
268 while ($year <= $endyear) {
269 $data[$i][] = $datay[$year][$i][1];
287 global $conf, $user, $langs;
292 if (!empty($cachedelay)) {
293 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
294 include_once DOL_DOCUMENT_ROOT.
'/core/lib/json.lib.php';
297 $newpathofdestfile = $conf->user->dir_temp.
'/'.get_class($this).
'_'.__FUNCTION__.
'_'.(empty($this->cachefilesuffix) ?
'' : $this->cachefilesuffix.
'_').$langs->defaultlang.
'_entity.'.$conf->entity.
'_user'.$user->id.
'.cache';
303 if ($cachedelay > 0) {
305 if ($filedate >= ($nowgmt - $cachedelay)) {
308 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $filedate;
310 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.");
315 if ($foundintocache) {
316 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" read data from cache file ".$newpathofdestfile.
" ".$filedate.
".");
317 $data = json_decode(file_get_contents($newpathofdestfile),
true);
319 $data = $this->getAllByProduct($year, $limit);
324 if (empty($foundintocache) && ($cachedelay > 0 || $cachedelay == -1)) {
325 dol_syslog(get_class($this).
'::'.__FUNCTION__.
" save cache file ".$newpathofdestfile.
" onto disk.");
329 $fp = fopen($newpathofdestfile,
'w');
331 fwrite($fp, json_encode($data));
333 if (!empty($conf->global->MAIN_UMASK)) {
334 $newmask = $conf->global->MAIN_UMASK;
336 @chmod($newpathofdestfile, octdec($newmask));
338 $this->lastfetchdate[get_class($this).
'_'.__FUNCTION__] = $nowgmt;
360 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
366 $row = $this->
db->fetch_row(
$resql);
389 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
395 $row = $this->
db->fetch_object(
$resql);
396 $result[$i][
'year'] = $row->year;
397 $result[$i][
'nb'] = $row->nb;
398 if ($i > 0 && $row->nb > 0) {
399 $result[$i - 1][
'nb_diff'] = ($result[$i - 1][
'nb'] - $row->nb) / $row->nb * 100;
401 $result[$i][
'total'] = $row->total;
402 if ($i > 0 && $row->total > 0) {
403 $result[$i - 1][
'total_diff'] = ($result[$i - 1][
'total'] - $row->total) / $row->total * 100;
405 $result[$i][
'avg'] = $row->avg;
406 if ($i > 0 && $row->avg > 0) {
407 $result[$i - 1][
'avg_diff'] = ($result[$i - 1][
'avg'] - $row->avg) / $row->avg * 100;
410 if (isset($row->weighted)) {
411 $result[$i][
'weighted'] = $row->weighted;
412 if ($i > 0 && $row->weighted > 0) {
413 $result[$i - 1][
'avg_weighted'] = ($result[$i - 1][
'weighted'] - $row->weighted) / $row->weighted * 100;
443 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
450 $row = $this->
db->fetch_row(
$resql);
452 $result[$j] = $row[1];
460 for ($i = 1; $i < 13; $i++) {
461 $res[$i] = (isset($result[$i]) ? $result[$i] : 0);
466 for ($i = 1; $i < 13; $i++) {
469 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
470 } elseif ($format == 1) {
472 } elseif ($format == 2) {
473 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
477 $data[$i - 1] = array($month, $res[$i]);
500 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
507 $row = $this->
db->fetch_row(
$resql);
509 $result[$j] = $row[1];
517 for ($i = 1; $i < 13; $i++) {
518 $res[$i] = (int) round((isset($result[$i]) ? $result[$i] : 0));
523 for ($i = 1; $i < 13; $i++) {
526 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
527 } elseif ($format == 1) {
529 } elseif ($format == 2) {
530 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
534 $data[$i - 1] = array($month, $res[$i]);
558 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
565 $row = $this->
db->fetch_row(
$resql);
567 $result[$j] = $row[1];
575 for ($i = 1; $i < 13; $i++) {
576 $res[$i] = (isset($result[$i]) ? $result[$i] : 0);
581 for ($i = 1; $i < 13; $i++) {
584 $month = $langs->transnoentitiesnoconv(
'MonthShort'.sprintf(
"%02d", $i));
585 } elseif ($format == 1) {
587 } elseif ($format == 2) {
588 $month = $langs->transnoentitiesnoconv(
'MonthVeryShort'.sprintf(
"%02d", $i));
592 $data[$i - 1] = array($month, $res[$i]);
614 dol_syslog(get_class($this).
'::'.__FUNCTION__.
"", LOG_DEBUG);
621 $row = $this->
db->fetch_row(
$resql);
622 if ($i < $limit || $num == $limit) {
623 $result[$i] = array($row[0], $row[1]);
630 $result[$i] = array($langs->transnoentitiesnoconv(
"Other"), $other);
654 $row = $this->
db->fetch_row(
$resql);
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.
dol_mkdir($dir, $dataroot= '', $newmask= '')
Creation of a directory (this can create recursive subdir)
getNbByMonthWithPrevYear($endyear, $startyear, $cachedelay=0, $format=0, $startmonth=1)
Return nb of elements by month for several years.
$conf db
API class for accounts.
getNbByMonth($year, $format=0)
dol_now($mode= 'auto')
Return date for now.
_getAmountByYear($sql)
Returns the summed amounts per year for a given number of past years ending 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...
_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.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->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_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...
getAmountByMonth($year, $format=0)