dolibarr 25.0.0-alpha
box_invoices_dispute.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012 Charles-François BENKE <charles.fr@benke.fr>
3 * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2014-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28
33{
34 public $boxcode = "box_invoices_dispute";
35 public $boximg = "object_invoice";
36 public $boxlabel = 'BoxInvoicesDispute';
37 public $depends = array("invoice");
38
45 public function __construct($db, $param) // @phpstan-ignore constructor.unusedParameter
46 {
47 global $user;
48
49 $this->db = $db;
50
51 $this->hidden = !(isModEnabled('invoice') && $user->hasRight('facture', 'read'));
52 }
53
60 public function loadBox($max = 5)
61 {
62 global $conf, $user, $langs;
63
64 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
65 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
66
67 $totalnb = 0;
68 $line = 0;
69 $now = dol_now();
70 $nbofperiod = 3;
71
72 $langs->load("bills");
73
74 // Force use of cache for this box as it has very bad performances
75 $savMAIN_ACTIVATE_FILECACHE = getDolGlobalInt('MAIN_ACTIVATE_FILECACHE');
76 $conf->global->MAIN_ACTIVATE_FILECACHE = 1;
77
78
79 $textHead = $langs->trans("InvoicesDispute");
80 $this->info_box_head = array(
81 'text' => $textHead,
82 'limit' => dol_strlen($textHead),
83 );
84
85 // compute the date limit for lost and won disputes
86 $tmpdate = dol_time_plus_duree(dol_now(), -1 * $nbofperiod, "m");
87 $tmparray = dol_getdate($tmpdate);
88
89 // list the summary of the bills
90 if (isModEnabled('invoice') && $user->hasRight("facture", "lire")) {
91 // Init the 3 lines always visible: open (any date), lost and won (last months)
92 $data = array(
93 1 => array('nb' => 0, 'mnttot' => 0, 'label' => $langs->trans("DisputesOpenInProgress"), 'datefilter' => false),
94 8 => array('nb' => 0, 'mnttot' => 0, 'label' => $langs->trans("DisputesLostLastXMonths", $nbofperiod), 'datefilter' => true),
95 9 => array('nb' => 0, 'mnttot' => 0, 'label' => $langs->trans("DisputesWonLastXMonths", $nbofperiod), 'datefilter' => true),
96 );
97
98 $sql = "SELECT f.dispute_status, SUM(f.total_ttc) as mnttot, COUNT(*) as nb";
99 $sql .= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
100 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
101 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
102 }
103 $sql .= ")";
104 $sql .= " WHERE f.entity IN (".getEntity('invoice').')';
105 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
106 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
107 }
108 if ($user->socid) {
109 $sql .= " AND s.rowid = ".((int) $user->socid);
110 }
111 $sql .= " AND f.fk_soc = s.rowid";
112 $sql .= " AND (f.dispute_status = 1 OR (f.dispute_status IN (8, 9) AND f.datef >= '".$this->db->idate($tmpdate)."'))";
113 $sql .= " GROUP BY f.dispute_status";
114
115 $result = $this->db->query($sql);
116 if ($result) {
117 while ($obj = $this->db->fetch_object($result)) {
118 if (isset($data[$obj->dispute_status])) {
119 $data[$obj->dispute_status]['nb'] = (int) $obj->nb;
120 $data[$obj->dispute_status]['mnttot'] = $obj->mnttot;
121 }
122 }
123
124 $this->db->free($result);
125 } else {
126 dol_print_error($this->db);
127 }
128
129 foreach ($data as $disputestatus => $val) {
130 $billurl = DOL_URL_ROOT."/compta/facture/list.php?search_dispute_status=".((int) $disputestatus);
131 if ($val['datefilter']) {
132 $billurl .= "&search_date_startday=".((int) $tmparray['mday'])."&search_date_startmonth=".((int) $tmparray['mon'])."&search_date_startyear=".((int) $tmparray['year']);
133 }
134 $billurl .= "&mainmenu=accountancy&leftmenu=customers_bills";
135
136 if ($disputestatus == 1) {
137 $badgeclass = ($val['nb'] > 0 ? 'badge badge-danger' : 'badge badge-status4');
138 } else {
139 //$badgeclass = ($val['nb'] > 0 ? 'badge badge-info' : 'badge badge-info');
140 $badgeclass = 'badge badge-info';
141 }
142
143 // Column picto
144 $this->info_box_contents[$line][0] = array(
145 'td' => 'class="left" width="16"',
146 'tooltip' => $val['label'],
147 'url' => $billurl,
148 'logo' => 'bill',
149 );
150
151 // Column label
152 $this->info_box_contents[$line][1] = array(
153 'td' => '',
154 'text' => $val['label'],
155 );
156
157 // Column value
158 $this->info_box_contents[$line][2] = array(
159 'td' => 'class="right"',
160 'tooltip' => $val['label'],
161 'textnoformat' => '<a href="'.$billurl.'" class="nounderlineimp"><span class="center '.$badgeclass.'">'.$val['nb'].'</span></a>',
162 );
163
164 // Column amount
165 $this->info_box_contents[$line][3] = array(
166 'td' => 'class="nowraponall right amount"',
167 'text' => price($val['mnttot'], 1, $langs, 0, 0, -1, $conf->currency)
168 );
169
170 $line++;
171 }
172 }
173
174 $conf->global->MAIN_ACTIVATE_FILECACHE = $savMAIN_ACTIVATE_FILECACHE;
175 }
176
177
178
179
188 public function showBox($head = null, $contents = null, $nooutput = 0)
189 {
190 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
191 }
192}
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class ModeleBoxes.
Class to manage the box of disputed invoices.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
loadBox($max=5)
Charge les donnees en memoire pour affichage ulterieur.
__construct($db, $param)
Constructor.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
Definition date.lib.php:127
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.