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
39 public $enabled = 1;
40
47 public function __construct($db, $param) // @phpstan-ignore constructor.unusedParameter
48 {
49 global $conf, $user;
50
51 $this->db = $db;
52
53 $this->enabled = getDolGlobalInt('MAIN_FEATURES_LEVEL'); // Not enabled by default due to bugs (see previous comments)
54
55 $this->hidden = !(isModEnabled('invoice') && $user->hasRight('facture', 'read'));
56 }
57
64 public function loadBox($max = 5)
65 {
66 global $conf, $user, $langs;
67
68 include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
69 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
70
71 $totalnb = 0;
72 $line = 0;
73 $now = dol_now();
74 $nbofperiod = 3;
75
76 // Force use of cache for this box as it has very bad performances
77 $savMAIN_ACTIVATE_FILECACHE = getDolGlobalInt('MAIN_ACTIVATE_FILECACHE');
78 $conf->global->MAIN_ACTIVATE_FILECACHE = 1;
79
80
81 $textHead = $langs->trans("InvoicesDispute").' - '.$langs->trans("LastXMonthRolling", $nbofperiod);
82 $this->info_box_head = array(
83 'text' => $textHead,
84 'limit' => dol_strlen($textHead),
85 );
86
87 // compute the year limit to show
88 $tmpdate = dol_time_plus_duree(dol_now(), -1 * $nbofperiod, "m");
89
90 // list the summary of the bills
91 if (isModEnabled('invoice') && $user->hasRight("facture", "lire")) {
92 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
93 $facturestatic = new Facture($this->db);
94
95 $data = array();
96 $sql = "SELECT f.dispute_status, f.fk_statut, SUM(f.total_ttc) as mnttot, COUNT(*) as nb";
97 $sql .= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
98 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
99 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
100 }
101 $sql .= ")";
102 $sql .= " WHERE f.entity IN (".getEntity('invoice').')';
103 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
104 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
105 }
106 if ($user->socid) {
107 $sql .= " AND s.rowid = ".((int) $user->socid);
108 }
109 $sql .= " AND f.fk_soc = s.rowid";
110 $sql .= " AND f.dispute_status > 0";
111 $sql .= " AND f.datef >= '".$this->db->idate($tmpdate)."' AND f.paye=1";
112 $sql .= " GROUP BY f.dispute_status, f.fk_statut";
113 $sql .= " ORDER BY f.dispute_status ASC";
114
115 $result = $this->db->query($sql);
116 if ($result) {
117 $num = $this->db->num_rows($result);
118 $j = 0;
119 while ($j < $num) {
120 $data[$j] = $this->db->fetch_object($result);
121 $j++;
122 }
123
124 $this->db->free($result);
125 } else {
126 dol_print_error($this->db);
127 }
128
129 if (!empty($data)) {
130 $j = 0;
131 while ($j < count($data)) {
132 $billurl = "search_status=2&paye=1&search_dispute_status=".$data[$j]->dispute_status;
133 $this->info_box_contents[$line][0] = array(
134 'td' => 'class="left" width="16"',
135 'tooltip' => $langs->trans('Bills').'&nbsp;'.$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0, -1, -1, array("dispute_status" => $data[$j]->dispute_status)),
136 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&mainmenu=accountancy&leftmenu=customers_bills",
137 'logo' => 'bill',
138 );
139
140 $this->info_box_contents[$line][1] = array(
141 'td' => '',
142 'text' => $langs->trans("Bills")."&nbsp;".$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0, -1, -1, array("dispute_status" => $data[$j]->dispute_status)),
143 );
144
145 $this->info_box_contents[$line][2] = array(
146 'td' => 'class="right"',
147 'tooltip' => $langs->trans('Bills').'&nbsp;'.$facturestatic->LibStatut(1, $data[$j]->fk_statut, 0, -1, -1, array("dispute_status" => $data[$j]->dispute_status)),
148 'text' => $data[$j]->nb,
149 'url' => DOL_URL_ROOT."/compta/facture/list.php?".$billurl."&mainmenu=accountancy&leftmenu=customers_bills",
150 );
151
152 $this->info_box_contents[$line][3] = array(
153 'td' => 'class="nowraponall right amount"',
154 'text' => price($data[$j]->mnttot, 1, $langs, 0, 0, -1, $conf->currency)
155 );
156
157 // We add only for the current year
158 $totalnb += $data[$j]->nb;
159
160 $this->info_box_contents[$line][4] = array(
161 'td' => 'class="right" width="18"',
162 'text' => $facturestatic->LibStatut(1, $data[$j]->fk_statut, 3, -1, -1, array("dispute_status" => $data[$j]->dispute_status)),
163 );
164 $line++;
165 $j++;
166 }
167 if (count($data) == 0) {
168 $this->info_box_contents[$line][0] = array(
169 'td' => 'class="center"',
170 'text' => $langs->trans("NoRecordedInvoices"),
171 );
172 $line++;
173 }
174 }
175 }
176 // Add the sum in the bottom of the boxes
177 $this->info_box_contents[$line][0] = array('tr' => 'class="liste_total_wrap"');
178 $this->info_box_contents[$line][1] = array('td' => 'class="liste_total left" ', 'text' => $langs->trans("Total")."&nbsp;".$textHead);
179 $this->info_box_contents[$line][2] = array('td' => 'class="liste_total right" ', 'text' => (string) $totalnb);
180 $this->info_box_contents[$line][3] = array('td' => 'class="liste_total right" ', 'text' => '');
181 $this->info_box_contents[$line][4] = array('td' => 'class="liste_total right" ', 'text' => "");
182
183 $conf->global->MAIN_ACTIVATE_FILECACHE = $savMAIN_ACTIVATE_FILECACHE;
184 }
185
186
187
188
197 public function showBox($head = null, $contents = null, $nooutput = 0)
198 {
199 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
200 }
201}
Class to manage invoices.
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)
Add a delay to a date.
Definition date.lib.php:126
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
dol_strlen($string, $stringencoding='UTF-8')
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...