dolibarr 21.0.0-beta
box_goodcustomers.php
Go to the documentation of this file.
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) 2016 Charlie Benke <charlie@patas-monkey.com>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
30
31
36{
37 public $boxcode = "goodcustomers";
38 public $boximg = "object_company";
39 public $boxlabel = "BoxGoodCustomers";
40 public $depends = array("societe");
41
42 public $enabled = 1;
43
50 public function __construct($db, $param = '')
51 {
52 global $user;
53
54 $this->db = $db;
55
56 // disable box for such cases
57 if (getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
58 $this->enabled = 0; // disabled by this option
59 }
60 if (!getDolGlobalString('MAIN_BOX_ENABLE_BEST_CUSTOMERS')) {
61 $this->enabled = 0; // not enabled by default. Very slow on large database
62 }
63
64 $this->hidden = !$user->hasRight('societe', 'lire');
65 }
66
73 public function loadBox($max = 5)
74 {
75 global $user, $langs, $conf;
76 $langs->load("boxes");
77
78 $this->max = $max;
79
80 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
81 $thirdpartystatic = new Societe($this->db);
82
83 $this->info_box_head = array('text' => $langs->trans("BoxTitleGoodCustomers", $max));
84
85 if ($user->hasRight('societe', 'lire')) {
86 $sql = "SELECT s.rowid, s.nom as name, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms as datem, s.status as status,";
87 $sql .= " count(*) as nbfact, sum(".$this->db->ifsql('f.paye=1', '1', '0').") as nbfactpaye";
88 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f";
89 $sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
90 $sql .= ' AND s.rowid = f.fk_soc';
91 $sql .= " GROUP BY s.rowid, s.nom, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms, s.status";
92 $sql .= $this->db->order("nbfact", "DESC");
93 $sql .= $this->db->plimit($max, 0);
94
95 dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
96 $result = $this->db->query($sql);
97 if ($result) {
98 $num = $this->db->num_rows($result);
99
100 $line = 0;
101 while ($line < $num) {
102 $objp = $this->db->fetch_object($result);
103 $datem = $this->db->jdate($objp->tms);
104 $thirdpartystatic->id = $objp->rowid;
105 $thirdpartystatic->name = $objp->name;
106 $thirdpartystatic->code_client = $objp->code_client;
107 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
108 $thirdpartystatic->client = $objp->client;
109 $thirdpartystatic->fournisseur = $objp->fournisseur;
110 $thirdpartystatic->logo = $objp->logo;
111 $nbfact = $objp->nbfact;
112 $nbimpaye = $objp->nbfact - $objp->nbfactpaye;
113
114 $this->info_box_contents[$line][] = array(
115 'td' => 'class="tdoverflowmax150"',
116 'text' => $thirdpartystatic->getNomUrl(1),
117 'asis' => 1,
118 );
119
120 $this->info_box_contents[$line][] = array(
121 'td' => 'class="center nowraponall"',
122 'text' => dol_print_date($datem, "day", 'tzuserrel')
123 );
124
125 $this->info_box_contents[$line][] = array(
126 'td' => 'class="right"',
127 'text' => $nbfact.($nbimpaye != 0 ? ' ('.$nbimpaye.')' : '')
128 );
129
130 $this->info_box_contents[$line][] = array(
131 'td' => 'class="right" width="18"',
132 'text' => $thirdpartystatic->LibStatut($objp->status, 3)
133 );
134
135 $line++;
136 }
137
138 if ($num == 0) {
139 $this->info_box_contents[$line][0] = array(
140 'td' => 'class="center"',
141 'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedCustomers").'</span>'
142 );
143 }
144
145 $this->db->free($result);
146 } else {
147 $this->info_box_contents[0][0] = array(
148 'td' => '',
149 'maxlength' => 500,
150 'text' => ($this->db->error().' sql='.$sql),
151 );
152 }
153 } else {
154 $this->info_box_contents[0][0] = array(
155 'td' => 'class="nohover left"',
156 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
157 );
158 }
159 }
160
161
162
171 public function showBox($head = null, $contents = null, $nooutput = 0)
172 {
173 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
174 }
175}
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show top-selling customers.
loadBox($max=5)
Load data for box to show them later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param='')
Constructor.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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