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