1 | <?php |
||
2 | |||
3 | /* Copyright (C) 2001-2006 Rodolphe Quiedeville <[email protected]> |
||
4 | * Copyright (C) 2004-2018 Laurent Destailleur <[email protected]> |
||
5 | * Copyright (C) 2005-2012 Regis Houssin <[email protected]> |
||
6 | * Copyright (C) 2014-2021 Charlene Benke <[email protected]> |
||
7 | * Copyright (C) 2015 Jean-François Ferry <[email protected]> |
||
8 | * Copyright (C) 2016 Ferran Marcet <[email protected]> |
||
9 | * Copyright (C) 2019 Nicolas ZABOURI <[email protected]> |
||
10 | * Copyright (C) 2024 Rafael San José <[email protected]> |
||
11 | * |
||
12 | * This program is free software; you can redistribute it and/or modify |
||
13 | * it under the terms of the GNU General Public License as published by |
||
14 | * the Free Software Foundation; either version 3 of the License, or |
||
15 | * (at your option) any later version. |
||
16 | * |
||
17 | * This program is distributed in the hope that it will be useful, |
||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
20 | * GNU General Public License for more details. |
||
21 | * |
||
22 | * You should have received a copy of the GNU General Public License |
||
23 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
24 | */ |
||
25 | |||
26 | use Dolibarr\Code\Contact\Classes\Contact; |
||
27 | use Dolibarr\Code\Core\Classes\DolGraph; |
||
28 | use Dolibarr\Code\Core\Classes\Form; |
||
29 | use Dolibarr\Code\Core\Classes\FormOther; |
||
30 | use Dolibarr\Code\Core\Classes\HookManager; |
||
31 | use Dolibarr\Code\Core\Classes\InfoBox; |
||
32 | use Dolibarr\Code\Societe\Classes\Societe; |
||
33 | use Dolibarr\Lib\ViewMain; |
||
34 | |||
35 | /** |
||
36 | * \file htdocs/societe/index.php |
||
37 | * \ingroup societe |
||
38 | * \brief Home page for third parties area |
||
39 | */ |
||
40 | |||
41 | // Load Dolibarr environment |
||
42 | require constant('DOL_DOCUMENT_ROOT') . '/main.inc.php'; |
||
43 | |||
44 | // Load translation files required by the page |
||
45 | $langs->load("companies"); |
||
46 | |||
47 | // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array |
||
48 | $hookmanager = new HookManager($db); |
||
49 | $hookmanager->initHooks(array('thirdpartiesindex')); |
||
50 | |||
51 | $socid = GETPOSTINT('socid'); |
||
52 | if ($user->socid) { |
||
53 | $socid = $user->socid; |
||
54 | } |
||
55 | |||
56 | // Security check |
||
57 | $result = restrictedArea($user, 'societe|contact', 0, '', '', '', ''); |
||
58 | |||
59 | $thirdparty_static = new Societe($db); |
||
60 | $contact_static = new Contact($db); |
||
61 | |||
62 | if (!isset($form) || !is_object($form)) { |
||
63 | $form = new Form($db); |
||
64 | } |
||
65 | |||
66 | // Load $resultboxes |
||
67 | $resultboxes = FormOther::getBoxesArea($user, "3"); |
||
68 | |||
69 | if (GETPOST('addbox')) { |
||
70 | // Add box (when submit is done from a form when ajax disabled) |
||
71 | $zone = GETPOSTINT('areacode'); |
||
72 | $userid = GETPOSTINT('userid'); |
||
73 | $boxorder = GETPOST('boxorder', 'aZ09'); |
||
74 | $boxorder .= GETPOST('boxcombo', 'aZ09'); |
||
75 | $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid); |
||
76 | if ($result > 0) { |
||
77 | setEventMessages($langs->trans("BoxAdded"), null); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | $max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5); |
||
82 | |||
83 | /* |
||
84 | * View |
||
85 | */ |
||
86 | |||
87 | $transAreaType = $langs->trans("ThirdPartiesArea"); |
||
88 | $helpurl = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Módulo_Terceros'; |
||
89 | |||
90 | ViewMain::llxHeader("", $langs->trans("ThirdParties"), $helpurl); |
||
91 | |||
92 | print load_fiche_titre($transAreaType, $resultboxes['selectboxlist'], 'companies'); |
||
93 | |||
94 | |||
95 | // Statistics area |
||
96 | |||
97 | $third = array( |
||
98 | 'customer' => 0, |
||
99 | 'prospect' => 0, |
||
100 | 'supplier' => 0, |
||
101 | 'other' => 0 |
||
102 | ); |
||
103 | $total = 0; |
||
104 | |||
105 | $sql = "SELECT s.rowid, s.client, s.fournisseur"; |
||
106 | $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; |
||
107 | if (!$user->hasRight('societe', 'client', 'voir')) { |
||
108 | $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
||
109 | } |
||
110 | $sql .= ' WHERE s.entity IN (' . getEntity('societe') . ')'; |
||
111 | if (!$user->hasRight('societe', 'client', 'voir')) { |
||
112 | $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int)$user->id); |
||
113 | } |
||
114 | if (!$user->hasRight('fournisseur', 'lire')) { |
||
115 | $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible |
||
116 | } |
||
117 | // Add where from hooks |
||
118 | $parameters = array('socid' => $socid); |
||
119 | $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook |
||
120 | if (empty($reshook)) { |
||
121 | if ($socid > 0) { |
||
122 | $sql .= " AND s.rowid = " . ((int)$socid); |
||
123 | } |
||
124 | } |
||
125 | $sql .= $hookmanager->resPrint; |
||
126 | //print $sql; |
||
127 | $result = $db->query($sql); |
||
128 | if ($result) { |
||
129 | while ($objp = $db->fetch_object($result)) { |
||
130 | $found = 0; |
||
131 | if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS') && ($objp->client == 2 || $objp->client == 3)) { |
||
132 | $found = 1; |
||
133 | $third['prospect']++; |
||
134 | } |
||
135 | if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS') && ($objp->client == 1 || $objp->client == 3)) { |
||
136 | $found = 1; |
||
137 | $third['customer']++; |
||
138 | } |
||
139 | if (((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire'))) && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_STATS') && $objp->fournisseur) { |
||
140 | $found = 1; |
||
141 | $third['supplier']++; |
||
142 | } |
||
143 | if (isModEnabled('societe') && $objp->client == 0 && $objp->fournisseur == 0) { |
||
144 | $found = 1; |
||
145 | $third['other']++; |
||
146 | } |
||
147 | if ($found) { |
||
148 | $total++; |
||
149 | } |
||
150 | } |
||
151 | } else { |
||
152 | dol_print_error($db); |
||
153 | } |
||
154 | |||
155 | $thirdpartygraph = '<div class="div-table-responsive-no-min">'; |
||
156 | $thirdpartygraph .= '<table class="noborder nohover centpercent">' . "\n"; |
||
157 | $thirdpartygraph .= '<tr class="liste_titre"><th colspan="2">' . $langs->trans("Statistics") . '</th></tr>'; |
||
158 | if (!empty($conf->use_javascript_ajax) && ((round($third['prospect']) ? 1 : 0) + (round($third['customer']) ? 1 : 0) + (round($third['supplier']) ? 1 : 0) + (round($third['other']) ? 1 : 0) >= 2)) { |
||
159 | $thirdpartygraph .= '<tr><td class="center" colspan="2">'; |
||
160 | $dataseries = array(); |
||
161 | if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS')) { |
||
162 | $dataseries[] = array($langs->transnoentitiesnoconv("Prospects"), round($third['prospect'])); |
||
163 | } |
||
164 | if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS')) { |
||
165 | $dataseries[] = array($langs->transnoentitiesnoconv("Customers"), round($third['customer'])); |
||
166 | } |
||
167 | if (((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire'))) && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_STATS')) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
168 | $dataseries[] = array($langs->transnoentitiesnoconv("Suppliers"), round($third['supplier'])); |
||
169 | } |
||
170 | if (isModEnabled('societe')) { |
||
171 | $dataseries[] = array($langs->transnoentitiesnoconv("Others"), round($third['other'])); |
||
172 | } |
||
173 | $dolgraph = new DolGraph(); |
||
174 | $dolgraph->SetData($dataseries); |
||
175 | $dolgraph->setShowLegend(2); |
||
176 | $dolgraph->setShowPercent(1); |
||
177 | $dolgraph->SetType(array('pie')); |
||
178 | $dolgraph->setHeight('200'); |
||
179 | $dolgraph->draw('idgraphthirdparties'); |
||
180 | $thirdpartygraph .= $dolgraph->show(); |
||
181 | $thirdpartygraph .= '</td></tr>' . "\n"; |
||
182 | } else { |
||
183 | $statstring = ''; |
||
184 | if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS')) { |
||
185 | $statstring .= "<tr>"; |
||
186 | $statstring .= '<td><a href="' . constant('BASE_URL') . '/societe/list.php?type=p">' . $langs->trans("Prospects") . '</a></td><td class="right">' . round($third['prospect']) . '</td>'; |
||
187 | $statstring .= "</tr>"; |
||
188 | } |
||
189 | if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS')) { |
||
190 | $statstring .= "<tr>"; |
||
191 | $statstring .= '<td><a href="' . constant('BASE_URL') . '/societe/list.php?type=c">' . $langs->trans("Customers") . '</a></td><td class="right">' . round($third['customer']) . '</td>'; |
||
192 | $statstring .= "</tr>"; |
||
193 | } |
||
194 | $statstring2 = ''; |
||
195 | if (((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire'))) && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_STATS')) { |
||
0 ignored issues
–
show
|
|||
196 | $statstring2 .= "<tr>"; |
||
197 | $statstring2 .= '<td><a href="' . constant('BASE_URL') . '/societe/list.php?type=f">' . $langs->trans("Suppliers") . '</a></td><td class="right">' . round($third['supplier']) . '</td>'; |
||
198 | $statstring2 .= "</tr>"; |
||
199 | } |
||
200 | $thirdpartygraph .= $statstring; |
||
201 | $thirdpartygraph .= $statstring2; |
||
202 | } |
||
203 | $thirdpartygraph .= '<tr class="liste_total"><td>' . $langs->trans("UniqueThirdParties") . '</td><td class="right">'; |
||
204 | $thirdpartygraph .= $total; |
||
205 | $thirdpartygraph .= '</td></tr>'; |
||
206 | $thirdpartygraph .= '</table>'; |
||
207 | $thirdpartygraph .= '</div>'; |
||
208 | |||
209 | $thirdpartycateggraph = ''; |
||
210 | if (isModEnabled('category') && getDolGlobalString('CATEGORY_GRAPHSTATS_ON_THIRDPARTIES')) { |
||
211 | $elementtype = 'societe'; |
||
212 | |||
213 | $thirdpartycateggraph = '<div class="div-table-responsive-no-min">'; |
||
214 | $thirdpartycateggraph .= '<table class="noborder nohover centpercent">'; |
||
215 | $thirdpartycateggraph .= '<tr class="liste_titre"><th colspan="2">' . $langs->trans("Categories") . '</th></tr>'; |
||
216 | $thirdpartycateggraph .= '<tr><td class="center" colspan="2">'; |
||
217 | $sql = "SELECT c.label, count(*) as nb"; |
||
218 | $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_societe as cs"; |
||
219 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "categorie as c ON cs.fk_categorie = c.rowid"; |
||
220 | $sql .= " WHERE c.type = 2"; |
||
221 | if (!is_numeric(getDolGlobalString('CATEGORY_GRAPHSTATS_ON_THIRDPARTIES'))) { |
||
222 | $sql .= " AND c.label like '" . $db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES) . "'"; |
||
223 | } |
||
224 | $sql .= " AND c.entity IN (" . getEntity('category') . ")"; |
||
225 | $sql .= " GROUP BY c.label"; |
||
226 | $total = 0; |
||
227 | $result = $db->query($sql); |
||
228 | if ($result) { |
||
229 | $num = $db->num_rows($result); |
||
230 | $i = 0; |
||
231 | if (!empty($conf->use_javascript_ajax)) { |
||
232 | $dataseries = array(); |
||
233 | $rest = 0; |
||
234 | $nbmax = 10; |
||
235 | |||
236 | while ($i < $num) { |
||
237 | $obj = $db->fetch_object($result); |
||
238 | if ($i < $nbmax) { |
||
239 | $dataseries[] = array($obj->label, round($obj->nb)); |
||
240 | } else { |
||
241 | $rest += $obj->nb; |
||
242 | } |
||
243 | $total += $obj->nb; |
||
244 | $i++; |
||
245 | } |
||
246 | if ($i > $nbmax) { |
||
247 | $dataseries[] = array($langs->trans("Other"), round($rest)); |
||
248 | } |
||
249 | $dolgraph = new DolGraph(); |
||
250 | $dolgraph->SetData($dataseries); |
||
251 | $dolgraph->setShowLegend(2); |
||
252 | $dolgraph->setShowPercent(1); |
||
253 | $dolgraph->SetType(array('pie')); |
||
254 | $dolgraph->setHeight('200'); |
||
255 | $dolgraph->draw('idgraphcateg'); |
||
256 | $thirdpartycateggraph .= $dolgraph->show(); |
||
257 | } else { |
||
258 | while ($i < $num) { |
||
259 | $obj = $db->fetch_object($result); |
||
260 | |||
261 | $thirdpartycateggraph .= '<tr class="oddeven"><td>' . $obj->label . '</td><td>' . $obj->nb . '</td></tr>'; |
||
262 | $total += $obj->nb; |
||
263 | $i++; |
||
264 | } |
||
265 | } |
||
266 | } |
||
267 | $thirdpartycateggraph .= '</td></tr>'; |
||
268 | $thirdpartycateggraph .= '<tr class="liste_total"><td>' . $langs->trans("Total") . '</td><td class="right">'; |
||
269 | $thirdpartycateggraph .= $total; |
||
270 | $thirdpartycateggraph .= '</td></tr>'; |
||
271 | $thirdpartycateggraph .= '</table>'; |
||
272 | $thirdpartycateggraph .= '</div>'; |
||
273 | } else { |
||
274 | $thirdpartycateggraph = ''; |
||
275 | } |
||
276 | |||
277 | |||
278 | /* |
||
279 | * Latest modified third parties |
||
280 | */ |
||
281 | $sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur"; |
||
282 | $sql .= ", s.code_client"; |
||
283 | $sql .= ", s.code_fournisseur"; |
||
284 | if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { |
||
285 | $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur"; |
||
286 | $sql .= ", spe.accountancy_code_customer as code_compta"; |
||
287 | } else { |
||
288 | $sql .= ", s.code_compta_fournisseur"; |
||
289 | $sql .= ", s.code_compta"; |
||
290 | } |
||
291 | $sql .= ", s.logo"; |
||
292 | $sql .= ", s.entity"; |
||
293 | $sql .= ", s.canvas, s.tms as date_modification, s.status as status"; |
||
294 | $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; |
||
295 | if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { |
||
296 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)$conf->entity); |
||
297 | } |
||
298 | // TODO Replace this |
||
299 | if (!$user->hasRight('societe', 'client', 'voir')) { |
||
300 | $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
||
301 | } |
||
302 | $sql .= ' WHERE s.entity IN (' . getEntity('societe') . ')'; |
||
303 | if (!$user->hasRight('societe', 'client', 'voir')) { |
||
304 | $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int)$user->id); |
||
305 | } |
||
306 | if (!$user->hasRight('fournisseur', 'lire')) { |
||
307 | $sql .= " AND (s.fournisseur != 1 OR s.client != 0)"; |
||
308 | } |
||
309 | // Add where from hooks |
||
310 | $parameters = array('socid' => $socid); |
||
311 | $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook |
||
312 | if (empty($reshook)) { |
||
313 | if ($socid > 0) { |
||
314 | $sql .= " AND s.rowid = " . ((int)$socid); |
||
315 | } |
||
316 | } |
||
317 | $sql .= $hookmanager->resPrint; |
||
318 | $sql .= $db->order("s.tms", "DESC"); |
||
319 | $sql .= $db->plimit($max, 0); |
||
320 | |||
321 | //print $sql; |
||
322 | $lastmodified = ""; |
||
323 | $result = $db->query($sql); |
||
324 | if ($result) { |
||
325 | $num = $db->num_rows($result); |
||
326 | |||
327 | $i = 0; |
||
328 | |||
329 | if ($num > 0) { |
||
330 | $transRecordedType = $langs->trans("LastModifiedThirdParties", $max); |
||
331 | |||
332 | $lastmodified = "\n<!-- last thirdparties modified -->\n"; |
||
333 | $lastmodified .= '<div class="div-table-responsive-no-min">'; |
||
334 | $lastmodified .= '<table class="noborder centpercent">'; |
||
335 | |||
336 | $lastmodified .= '<tr class="liste_titre"><th colspan="2">'; |
||
337 | //$lastmodified .= img_picto('', 'company', 'class="pictofixedwidth"'); |
||
338 | $lastmodified .= '<span class="valignmiddle">' . $transRecordedType . '</span>'; |
||
339 | $lastmodified .= '<a class="marginleftonlyshort" href="' . constant('BASE_URL') . '/societe/list.php?sortfield=s.tms&sortorder=DESC" title="' . $langs->trans("FullList") . '">'; |
||
340 | $lastmodified .= '<span class="badge marginleftonlyshort">...</span>'; |
||
341 | $lastmodified .= '</a>'; |
||
342 | $lastmodified .= '</th>'; |
||
343 | $lastmodified .= '<th> </th>'; |
||
344 | $lastmodified .= '<th class="right">'; |
||
345 | $lastmodified .= '</th>'; |
||
346 | $lastmodified .= '</tr>' . "\n"; |
||
347 | |||
348 | while ($i < $num) { |
||
349 | $objp = $db->fetch_object($result); |
||
350 | |||
351 | $thirdparty_static->id = $objp->rowid; |
||
352 | $thirdparty_static->name = $objp->name; |
||
353 | $thirdparty_static->client = $objp->client; |
||
354 | $thirdparty_static->fournisseur = $objp->fournisseur; |
||
355 | $thirdparty_static->logo = $objp->logo; |
||
356 | $thirdparty_static->date_modification = $db->jdate($objp->date_modification); |
||
357 | $thirdparty_static->status = $objp->status; |
||
358 | $thirdparty_static->code_client = $objp->code_client; |
||
359 | $thirdparty_static->code_fournisseur = $objp->code_fournisseur; |
||
360 | $thirdparty_static->canvas = $objp->canvas; |
||
361 | $thirdparty_static->email = $objp->email; |
||
362 | $thirdparty_static->entity = $objp->entity; |
||
363 | $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur; |
||
364 | $thirdparty_static->code_compta_client = $objp->code_compta; |
||
365 | |||
366 | $lastmodified .= '<tr class="oddeven">'; |
||
367 | // Name |
||
368 | $lastmodified .= '<td class="nowrap tdoverflowmax200">'; |
||
369 | $lastmodified .= $thirdparty_static->getNomUrl(1); |
||
370 | $lastmodified .= "</td>\n"; |
||
371 | // Type |
||
372 | $lastmodified .= '<td class="center">'; |
||
373 | $lastmodified .= $thirdparty_static->getTypeUrl(); |
||
374 | $lastmodified .= '</td>'; |
||
375 | // Last modified date |
||
376 | $lastmodified .= '<td class="right tddate" title="' . dol_escape_htmltag($langs->trans("DateModification") . ' ' . dol_print_date($thirdparty_static->date_modification, 'dayhour', 'tzuserrel')) . '">'; |
||
377 | $lastmodified .= dol_print_date($thirdparty_static->date_modification, 'day', 'tzuserrel'); |
||
378 | $lastmodified .= "</td>"; |
||
379 | $lastmodified .= '<td class="right nowrap">'; |
||
380 | $lastmodified .= $thirdparty_static->getLibStatut(3); |
||
381 | $lastmodified .= "</td>"; |
||
382 | $lastmodified .= "</tr>\n"; |
||
383 | $i++; |
||
384 | } |
||
385 | |||
386 | $db->free($result); |
||
387 | |||
388 | $lastmodified .= "</table>\n"; |
||
389 | $lastmodified .= '</div>'; |
||
390 | $lastmodified .= "<!-- End last thirdparties modified -->\n"; |
||
391 | } |
||
392 | } else { |
||
393 | dol_print_error($db); |
||
394 | } |
||
395 | |||
396 | |||
397 | /* |
||
398 | * Latest modified contacts |
||
399 | */ |
||
400 | $sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur"; |
||
401 | $sql .= ", s.code_client"; |
||
402 | $sql .= ", s.code_fournisseur"; |
||
403 | if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { |
||
404 | $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur"; |
||
405 | $sql .= ", spe.accountancy_code_customer as code_compta"; |
||
406 | } else { |
||
407 | $sql .= ", s.code_compta_fournisseur"; |
||
408 | $sql .= ", s.code_compta"; |
||
409 | } |
||
410 | $sql .= ", s.logo"; |
||
411 | $sql .= ", s.entity"; |
||
412 | $sql .= ", s.canvas"; |
||
413 | $sql .= ", s.tms as date_modification, s.status as status"; |
||
414 | $sql .= ", sp.rowid as cid, sp.canvas as ccanvas, sp.email as cemail, sp.firstname, sp.lastname"; |
||
415 | $sql .= ", sp.address as caddress, sp.phone as cphone"; |
||
416 | $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "socpeople as sp"; |
||
417 | if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) { |
||
418 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)$conf->entity); |
||
419 | } |
||
420 | // TODO Replace this |
||
421 | if (!$user->hasRight('societe', 'client', 'voir')) { |
||
422 | $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
||
423 | } |
||
424 | $sql .= ' WHERE s.entity IN (' . getEntity('societe') . ') AND sp.fk_soc = s.rowid'; |
||
425 | if (!$user->hasRight('societe', 'client', 'voir')) { |
||
426 | $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . ((int)$user->id); |
||
427 | } |
||
428 | if (!$user->hasRight('fournisseur', 'lire')) { |
||
429 | $sql .= " AND (s.fournisseur != 1 OR s.client != 0)"; |
||
430 | } |
||
431 | // Add where from hooks |
||
432 | $parameters = array('socid' => $socid); |
||
433 | $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook |
||
434 | if (empty($reshook)) { |
||
435 | if ($socid > 0) { |
||
436 | $sql .= " AND s.rowid = " . ((int)$socid); |
||
437 | } |
||
438 | } |
||
439 | $sql .= $hookmanager->resPrint; |
||
440 | $sql .= $db->order("s.tms", "DESC"); |
||
441 | $sql .= $db->plimit($max, 0); |
||
442 | |||
443 | //print $sql; |
||
444 | $lastmodifiedcontact = ''; |
||
445 | $result = $db->query($sql); |
||
446 | if ($result) { |
||
447 | $num = $db->num_rows($result); |
||
448 | |||
449 | $i = 0; |
||
450 | |||
451 | if ($num > 0) { |
||
452 | $transRecordedType = $langs->trans("LastModifiedContacts", $max); |
||
453 | |||
454 | $lastmodifiedcontact = "\n<!-- last contacts modified -->\n"; |
||
455 | $lastmodifiedcontact .= '<div class="div-table-responsive-no-min">'; |
||
456 | $lastmodifiedcontact .= '<table class="noborder centpercent">'; |
||
457 | |||
458 | $lastmodifiedcontact .= '<tr class="liste_titre"><th colspan="2">'; |
||
459 | //$lastmodifiedcontact .= img_picto('', 'contact', 'class="pictofixedwidth"'); |
||
460 | $lastmodifiedcontact .= '<span class="valignmiddle">' . $transRecordedType . '</div>'; |
||
461 | $lastmodifiedcontact .= '<a class="marginleftonlyshort" href="' . constant('BASE_URL') . '/contact/list.php?sortfield=p.tms&sortorder=DESC" title="' . $langs->trans("FullList") . '">'; |
||
462 | //$lastmodifiedcontact .= img_picto($langs->trans("FullList"), 'contact'); |
||
463 | $lastmodifiedcontact .= '<span class="badge marginleftonlyshort">...</span>'; |
||
464 | $lastmodifiedcontact .= '</th>'; |
||
465 | $lastmodifiedcontact .= '<th> </th>'; |
||
466 | $lastmodifiedcontact .= '<th class="right">'; |
||
467 | //$lastmodifiedcontact .= '<a href="'.DOL_URL_ROOT.'/contact/list.php?sortfield=s.tms&sortorder=DESC">'.img_picto($langs->trans("FullList"), 'contact'); |
||
468 | $lastmodifiedcontact .= '</th>'; |
||
469 | $lastmodifiedcontact .= '</tr>' . "\n"; |
||
470 | |||
471 | while ($i < $num) { |
||
472 | $objp = $db->fetch_object($result); |
||
473 | |||
474 | $thirdparty_static->id = $objp->rowid; |
||
475 | $thirdparty_static->name = $objp->name; |
||
476 | $thirdparty_static->client = $objp->client; |
||
477 | $thirdparty_static->fournisseur = $objp->fournisseur; |
||
478 | $thirdparty_static->logo = $objp->logo; |
||
479 | $thirdparty_static->date_modification = $db->jdate($objp->date_modification); |
||
480 | $thirdparty_static->status = $objp->status; |
||
481 | $thirdparty_static->code_client = $objp->code_client; |
||
482 | $thirdparty_static->code_fournisseur = $objp->code_fournisseur; |
||
483 | $thirdparty_static->canvas = $objp->canvas; |
||
484 | $thirdparty_static->email = $objp->email; |
||
485 | $thirdparty_static->entity = $objp->entity; |
||
486 | $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur; |
||
487 | $thirdparty_static->code_compta_client = $objp->code_compta; |
||
488 | |||
489 | $contact_static->id = $objp->cid; |
||
490 | $contact_static->firstname = $objp->firstname; |
||
491 | $contact_static->lastname = $objp->lastname; |
||
492 | $contact_static->email = $objp->cemail; |
||
493 | $contact_static->socid = $objp->rowid; |
||
494 | $contact_static->canvas = $objp->ccanvas; |
||
495 | $contact_static->phone_pro = $objp->cphone; |
||
496 | $contact_static->address = $objp->caddress; |
||
497 | |||
498 | $lastmodifiedcontact .= '<tr class="oddeven">'; |
||
499 | // Contact |
||
500 | $lastmodifiedcontact .= '<td>'; |
||
501 | $lastmodifiedcontact .= $contact_static->getNomUrl(1); |
||
502 | $lastmodifiedcontact .= '</td>'; |
||
503 | // Third party |
||
504 | $lastmodifiedcontact .= '<td class="nowrap tdoverflowmax200">'; |
||
505 | $lastmodifiedcontact .= $thirdparty_static->getNomUrl(1); |
||
506 | $lastmodifiedcontact .= "</td>\n"; |
||
507 | // Last modified date |
||
508 | $lastmodifiedcontact .= '<td class="right tddate" title="' . dol_escape_htmltag($langs->trans("DateModification") . ' ' . dol_print_date($thirdparty_static->date_modification, 'dayhour', 'tzuserrel')) . '">'; |
||
509 | $lastmodifiedcontact .= dol_print_date($thirdparty_static->date_modification, 'day', 'tzuserrel'); |
||
510 | $lastmodifiedcontact .= "</td>"; |
||
511 | $lastmodifiedcontact .= '<td class="right nowrap">'; |
||
512 | $lastmodifiedcontact .= $thirdparty_static->getLibStatut(3); |
||
513 | $lastmodifiedcontact .= "</td>"; |
||
514 | $lastmodifiedcontact .= "</tr>\n"; |
||
515 | $i++; |
||
516 | } |
||
517 | |||
518 | $db->free($result); |
||
519 | |||
520 | $lastmodifiedcontact .= "</table>\n"; |
||
521 | $lastmodifiedcontact .= '</div>'; |
||
522 | $lastmodifiedcontact .= "<!-- End last contacts modified -->\n"; |
||
523 | } |
||
524 | } else { |
||
525 | dol_print_error($db); |
||
526 | } |
||
527 | |||
528 | |||
529 | // boxes |
||
530 | print '<div class="clearboth"></div>'; |
||
531 | print '<div class="fichecenter fichecenterbis">'; |
||
532 | |||
533 | $boxlist = '<div class="twocolumns">'; |
||
534 | |||
535 | $boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">'; |
||
536 | $boxlist .= $thirdpartygraph; |
||
537 | $boxlist .= '<br>'; |
||
538 | $boxlist .= $thirdpartycateggraph; |
||
539 | $boxlist .= '<br>'; |
||
540 | $boxlist .= $resultboxes['boxlista']; |
||
541 | $boxlist .= '</div>' . "\n"; |
||
542 | |||
543 | $boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">'; |
||
544 | $boxlist .= $lastmodified; |
||
545 | $boxlist .= '<br>'; |
||
546 | $boxlist .= $lastmodifiedcontact; |
||
547 | $boxlist .= '<br>'; |
||
548 | $boxlist .= $resultboxes['boxlistb']; |
||
549 | $boxlist .= '</div>' . "\n"; |
||
550 | |||
551 | $boxlist .= '</div>'; |
||
552 | |||
553 | print $boxlist; |
||
554 | |||
555 | print '</div>'; |
||
556 | |||
557 | $parameters = array('user' => $user); |
||
558 | $reshook = $hookmanager->executeHooks('dashboardThirdparties', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook |
||
559 | |||
560 | // End of page |
||
561 | ViewMain::llxFooter(); |
||
562 | $db->close(); |
||
563 |