dolibarr 24.0.0-beta
lifetimeamount.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Laurent Destailleur <eldy@destailleur.fr>
3 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
38'@phan-var-force array<string,array<string,float>> $totalamountlifetime';
39'@phan-var-force array<string,array<string,float>> $totalhtamountlifetime';
40'@phan-var-force int $error';
41global $foundoldformat, $firstrecorddate, $error;
42
43// Protection to avoid direct call of template
44if (empty($conf) || !is_object($conf)) {
45 print "Error, template page ".basename(__FILE__)." can't be called with no conf defined.";
46 exit;
47}
48
49$firstrecorddatearray = array();
50if (!empty($search_end) && $search_end > 0) {
51 $dateend = $search_end;
52} else {
53 $dateend = dol_get_last_day(GETPOSTINT('yeartoexport'), GETPOSTINT('monthtoexport') > 0 ? GETPOSTINT('monthtoexport') : 12);
54}
55
56
57// Calculate lifetime totals (with date of first record)
58$sql = "SELECT action, module_source, object_format, MIN(date_creation) as datemin, SUM(amounts_taxexcl) as sumamounts_taxexcl, SUM(amounts) as sumamounts";
59$sql .= " FROM ".MAIN_DB_PREFIX."blockedlog";
60$sql .= " WHERE entity = ".((int) $conf->entity);
61//$sql .= " AND action IN ('BILL_VALIDATE', 'BILL_SENTBYMAIL', 'PAYMENT_CUSTOMER_CREATE', 'CASHCONTROL_CLOSE', 'PAYMENT_CUSTOMER_DELETE', 'DOC_DOWNLOAD', 'DOC_PREVIEW')";
62$sql .= " AND action IN ('BILL_VALIDATE', 'PAYMENT_CUSTOMER_CREATE', 'PAYMENT_CUSTOMER_DELETE')"; // Only event into lifetime total
63if ($dateend > 0) {
64 $sql .= " AND date_creation < '".$db->idate($dateend)."'";
65}
66if (empty($includebeforev2)) {
67 $sql .= " AND object_format >= 'V2'"; // We take all record from the new format (V2)
68}
69$sql .= " GROUP BY action, module_source, object_format";
70
71$resql = $db->query($sql);
72if ($resql) {
73 while ($obj = $db->fetch_object($resql)) {
74 // First record date per action code and module
75 if (!empty($firstrecorddatearray[$obj->action][$obj->module_source])) {
76 $firstrecorddatearray[$obj->action] = min($firstrecorddatearray[$obj->action][$obj->module_source], $db->jdate($obj->datemin, 'gmt'));
77 } else {
78 $firstrecorddatearray[$obj->action] = $db->jdate($obj->datemin, 'gmt');
79 }
80 // First record for all actions code
81 if (!empty($firstrecorddate)) {
82 $firstrecorddate = min($firstrecorddate, $db->jdate($obj->datemin, 'gmt'));
83 } else {
84 $firstrecorddate = $db->jdate($obj->datemin, 'gmt');
85 }
86
87 if (!isset($totalamountlifetime[$obj->action][$obj->module_source])) {
88 $totalamountlifetime[$obj->action][$obj->module_source] = 0;
89 }
90 if (!isset($totalhtamountlifetime[$obj->action][$obj->module_source])) {
91 $totalhtamountlifetime[$obj->action][$obj->module_source] = 0;
92 }
93
94 // Total per action code and module
95 $totalamountlifetime[$obj->action][$obj->module_source] += $obj->sumamounts;
96
97 // If format of line is old, the sumamounts_taxexcl was not recorded. So we flag this case.
98 if (empty($obj->object_format) || $obj->object_format === 'V1') {
99 $foundoldformat = 1;
100 } else {
101 $totalhtamountlifetime[$obj->action][$obj->module_source] += $obj->sumamounts_taxexcl;
102 }
103 }
104} else {
105 $error++;
106 setEventMessages($db->lasterror, null, 'errors');
107}
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:623
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.