dolibarr 21.0.0-beta
box_customers_outstanding_bill_reached.php
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29
30
35{
36 public $boxcode = "customersoutstandingbillreached";
37 public $boximg = "object_company";
38 public $boxlabel = "BoxCustomersOutstandingBillReached";
39 public $depends = array("facture", "societe");
40
41 public $enabled = 1;
42
49 public function __construct($db, $param = '')
50 {
51 global $user;
52
53 $this->db = $db;
54
55 // disable box for such cases
56 if (getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
57 $this->enabled = 0; // disabled by this option
58 }
59
60 $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
61 }
62
69 public function loadBox($max = 5)
70 {
71 global $user, $langs, $conf;
72 $langs->load("boxes");
73
74 $this->max = $max;
75
76 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
77 $thirdpartystatic = new Societe($this->db);
78
79 $this->info_box_head = array('text' => $langs->trans("BoxTitleLastOutstandingBillReached", $max));
80
81 if ($user->hasRight('societe', 'lire')) {
82 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
83 $sql .= ", s.code_client, s.code_compta, s.client";
84 $sql .= ", s.logo, s.email, s.entity";
85 $sql .= ", s.outstanding_limit";
86 $sql .= ", s.datec, s.tms, s.status";
87 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
88 if (!$user->hasRight('societe', 'client', 'voir')) {
89 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
90 }
91 $sql .= " WHERE s.client IN (1, 3)";
92 $sql .= " AND s.entity IN (".getEntity('societe').")";
93 if (!$user->hasRight('societe', 'client', 'voir')) {
94 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
95 }
96 if ($user->socid) {
97 $sql .= " AND s.rowid = $user->socid";
98 }
99 $sql .= " AND s.outstanding_limit > 0";
100 $sql .= " AND s.rowid IN (SELECT fk_soc from ".MAIN_DB_PREFIX."facture as f WHERE f.fk_statut = 1 and f.fk_soc = s.rowid)";
101 $sql .= " ORDER BY s.tms DESC";
102 //$sql .= $this->db->plimit($max, 0);
103
104 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
105 $result = $this->db->query($sql);
106 if ($result) {
107 $num = $this->db->num_rows($result);
108
109 $nboutstandingbillreachedcustomers = 0;
110
111 $line = 0;
112 while ($line < $num) {
113 $objp = $this->db->fetch_object($result);
114 $datec = $this->db->jdate($objp->datec);
115 $datem = $this->db->jdate($objp->tms);
116
117 $thirdpartystatic->id = $objp->socid;
118 $thirdpartystatic->name = $objp->name;
119 //$thirdpartystatic->name_alias = $objp->name_alias;
120 $thirdpartystatic->code_client = $objp->code_client;
121 $thirdpartystatic->code_compta = $objp->code_compta;
122 $thirdpartystatic->code_compta_client = $objp->code_compta;
123 $thirdpartystatic->client = $objp->client;
124 $thirdpartystatic->logo = $objp->logo;
125 $thirdpartystatic->email = $objp->email;
126 $thirdpartystatic->entity = $objp->entity;
127 $thirdpartystatic->outstanding_limit = $objp->outstanding_limit;
128
129 $tmp = $thirdpartystatic->getOutstandingBills();
130 $outstandingtotal = $tmp['opened'];
131 $outstandinglimit = $thirdpartystatic->outstanding_limit;
132
133 if ($outstandingtotal >= $outstandinglimit) {
134 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
135 'td' => '',
136 'text' => $thirdpartystatic->getNomUrl(1, 'customer'),
137 'asis' => 1,
138 );
139
140 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
141 'td' => 'class="right" width="18"',
142 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
143 );
144 $nboutstandingbillreachedcustomers++;
145 }
146
147 $line++;
148 }
149
150 if ($num == 0 || $nboutstandingbillreachedcustomers == 0) {
151 $this->info_box_contents[0][] = array(
152 'td' => 'class="center"',
153 'text' => '<span class="opacitymedium">'.$langs->trans("None").'</span>'
154 );
155 }
156
157 $this->db->free($result);
158 } else {
159 $this->info_box_contents[0][0] = array(
160 'td' => '',
161 'maxlength' => 500,
162 'text' => ($this->db->error().' sql='.$sql)
163 );
164 }
165 } else {
166 $this->info_box_contents[0][0] = array(
167 'td' => 'class="nohover left"',
168 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
169 );
170 }
171 }
172
173
174
183 public function showBox($head = null, $contents = null, $nooutput = 0)
184 {
185 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
186 }
187}
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last thirdparties.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79