dolibarr 18.0.6
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 *
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
29
34{
35 public $boxcode = "customersoutstandingbillreached";
36 public $boximg = "object_company";
37 public $boxlabel = "BoxCustomersOutstandingBillReached";
38 public $depends = array("facture", "societe");
39
43 public $db;
44
45 public $enabled = 1;
46
47 public $info_box_head = array();
48 public $info_box_contents = array();
49
50
57 public function __construct($db, $param = '')
58 {
59 global $conf, $user;
60
61 $this->db = $db;
62
63 // disable box for such cases
64 if (!empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
65 $this->enabled = 0; // disabled by this option
66 }
67
68 $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
69 }
70
77 public function loadBox($max = 5)
78 {
79 global $user, $langs, $conf;
80 $langs->load("boxes");
81
82 $this->max = $max;
83
84 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
85 $thirdpartystatic = new Societe($this->db);
86
87 $this->info_box_head = array('text' => $langs->trans("BoxTitleLastOutstandingBillReached", $max));
88
89 if ($user->hasRight('societe', 'lire')) {
90 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
91 $sql .= ", s.code_client, s.code_compta, s.client";
92 $sql .= ", s.logo, s.email, s.entity";
93 $sql .= ", s.outstanding_limit";
94 $sql .= ", s.datec, s.tms, s.status";
95 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
96 if (empty($user->rights->societe->client->voir) && !$user->socid) {
97 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
98 }
99 $sql .= " WHERE s.client IN (1, 3)";
100 $sql .= " AND s.entity IN (".getEntity('societe').")";
101 if (empty($user->rights->societe->client->voir) && !$user->socid) {
102 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
103 }
104 if ($user->socid) {
105 $sql .= " AND s.rowid = $user->socid";
106 }
107 $sql .= " AND s.outstanding_limit > 0";
108 $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)";
109 $sql .= " ORDER BY s.tms DESC";
110 //$sql .= $this->db->plimit($max, 0);
111
112 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
113 $result = $this->db->query($sql);
114 if ($result) {
115 $num = $this->db->num_rows($result);
116
117 $nboutstandingbillreachedcustomers = 0;
118
119 $line = 0;
120 while ($line < $num) {
121 $objp = $this->db->fetch_object($result);
122 $datec = $this->db->jdate($objp->datec);
123 $datem = $this->db->jdate($objp->tms);
124
125 $thirdpartystatic->id = $objp->socid;
126 $thirdpartystatic->name = $objp->name;
127 //$thirdpartystatic->name_alias = $objp->name_alias;
128 $thirdpartystatic->code_client = $objp->code_client;
129 $thirdpartystatic->code_compta = $objp->code_compta;
130 $thirdpartystatic->client = $objp->client;
131 $thirdpartystatic->logo = $objp->logo;
132 $thirdpartystatic->email = $objp->email;
133 $thirdpartystatic->entity = $objp->entity;
134 $thirdpartystatic->outstanding_limit = $objp->outstanding_limit;
135
136 $tmp = $thirdpartystatic->getOutstandingBills();
137 $outstandingtotal = $tmp['opened'];
138 $outstandinglimit = $thirdpartystatic->outstanding_limit;
139
140 if ($outstandingtotal >= $outstandinglimit) {
141 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
142 'td' => '',
143 'text' => $thirdpartystatic->getNomUrl(1, 'customer'),
144 'asis' => 1,
145 );
146
147 $this->info_box_contents[$nboutstandingbillreachedcustomers][] = array(
148 'td' => 'class="right" width="18"',
149 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
150 );
151 $nboutstandingbillreachedcustomers++;
152 }
153
154 $line++;
155 }
156
157 if ($num == 0 || $nboutstandingbillreachedcustomers == 0) {
158 $this->info_box_contents[0][] = array(
159 'td' => 'class="center"',
160 'text'=> '<span class="opacitymedium">'.$langs->trans("None").'</span>'
161 );
162 }
163
164 $this->db->free($result);
165 } else {
166 $this->info_box_contents[0][0] = array(
167 'td' => '',
168 'maxlength'=>500,
169 'text' => ($this->db->error().' sql='.$sql)
170 );
171 }
172 } else {
173 $this->info_box_contents[0][0] = array(
174 'td' => 'class="nohover left"',
175 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
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}
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.