dolibarr 23.0.3
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
6 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
7 * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
8 * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
9 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
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
32// Load Dolibarr environment
33require '../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
37require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
38require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
39require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
40require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
41require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
44if (isModEnabled('contract')) {
45 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
46}
47if (isModEnabled('intervention')) {
48 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
49}
50
59// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
60$hookmanager = new HookManager($db);
61$hookmanager->initHooks(array('commercialindex'));
62
63// Load translation files required by the page
64$langs->loadLangs(array("boxes", "commercial", "contracts", "orders", "propal", "supplier_proposal"));
65
66$action = GETPOST('action', 'aZ09');
67$bid = GETPOSTINT('bid');
68
69// Securite access client
70$socid = GETPOSTINT('socid');
71if (!empty($user->socid) && $user->socid > 0) {
72 $action = '';
73 $socid = $user->socid;
74}
75
76$total = 0;
77
78$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
79$maxofloop = getDolGlobalInt('MAIN_MAXLIST_OVERLOAD', 500);
80$now = dol_now();
81
82//restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0);
83if (!$user->hasRight('propal', 'read') && !$user->hasRight('supplier_proposal', 'read') && !$user->hasRight('commande', 'read') && !$user->hasRight('fournisseur', 'commande', 'read')
84 && !$user->hasRight('supplier_order', 'read') && !$user->hasRight('fichinter', 'read') && !$user->hasRight('contrat', 'read')) {
86}
87
88
89
90/*
91 * Actions
92 */
93
94// None
95
96
97/*
98 * View
99 */
100
101$form = new Form($db);
102$formfile = new FormFile($db);
103$companystatic = new Societe($db);
104$propalstatic = null;
105$supplierproposalstatic = null;
106$orderstatic = null;
107$supplierorderstatic = null;
108$fichinterstatic = null;
109if (isModEnabled("propal")) {
110 $propalstatic = new Propal($db);
111}
112if (isModEnabled('supplier_proposal')) {
113 $supplierproposalstatic = new SupplierProposal($db);
114}
115if (isModEnabled('order')) {
116 $orderstatic = new Commande($db);
117}
118if (isModEnabled("supplier_order")) {
119 $supplierorderstatic = new CommandeFournisseur($db);
120}
121
122if (isModEnabled('intervention')) {
123 $fichinterstatic = new Fichinter($db);
124}
125
126llxHeader("", $langs->trans("CommercialArea"));
127
128print load_fiche_titre($langs->trans("CommercialArea"), '', 'commercial');
129
130print '<div class="fichecenter">';
131
132print '<div class="twocolumns">';
133
134print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
135
136
137$tmp = getCustomerProposalPieChart($socid);
138if ($tmp) {
139 print $tmp;
140}
141$tmp = getCustomerOrderPieChart($socid);
142if ($tmp) {
143 print $tmp;
144}
145
146/*
147 * Draft customer proposals
148 */
149
150if (isModEnabled("propal") && $user->hasRight("propal", "lire") && is_object($propalstatic)) {
151 $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.total_tva, p.total_ttc, p.fk_statut as status";
152 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
153 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
154 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
155 $sql .= ", s.logo, s.email, s.entity";
156 $sql .= ", s.canvas";
157 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p,";
158 $sql .= " ".MAIN_DB_PREFIX."societe as s";
159 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
160 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
161 }
162 $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
163 $sql .= " AND p.fk_soc = s.rowid";
164 $sql .= " AND p.fk_statut = ".Propal::STATUS_DRAFT;
165 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
166 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
167 }
168 if ($socid) {
169 $sql .= " AND s.rowid = ".((int) $socid);
170 }
171 // Add where from hooks
172 $parameters = array('socid' => $user->socid);
173 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
174 $sql .= $hookmanager->resPrint;
175
176 $resql = $db->query($sql);
177 if ($resql) {
178 $total = 0;
179 $num = $db->num_rows($resql);
180 $nbofloop = min($num, $maxofloop);
181 startSimpleTable("ProposalsDraft", "comm/propal/list.php", "search_status=".Propal::STATUS_DRAFT, 2, $num);
182
183 if ($num > 0) {
184 $i = 0;
185 $othernb = 0;
186
187 while ($i < $nbofloop) {
188 $obj = $db->fetch_object($resql);
189
190 if ($i >= $max) {
191 $othernb++;
192 $i++;
193 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
194 continue;
195 }
196
197 $propalstatic->id = $obj->rowid;
198 $propalstatic->ref = $obj->ref;
199 $propalstatic->ref_client = $obj->ref_client;
200 $propalstatic->ref_customer = $obj->ref_client;
201 $propalstatic->total_ht = $obj->total_ht;
202 $propalstatic->total_tva = $obj->total_tva;
203 $propalstatic->total_ttc = $obj->total_ttc;
204 $propalstatic->statut = $obj->status; // deprecated
205 $propalstatic->status = $obj->status;
206
207 $companystatic->id = $obj->socid;
208 $companystatic->name = $obj->name;
209 $companystatic->name_alias = $obj->name_alias;
210 $companystatic->code_client = $obj->code_client;
211 $companystatic->code_compta = $obj->code_compta_client;
212 $companystatic->code_compta_client = $obj->code_compta_client;
213 $companystatic->client = $obj->client;
214 $companystatic->code_fournisseur = $obj->code_fournisseur;
215 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
216 $companystatic->fournisseur = $obj->fournisseur;
217 $companystatic->logo = $obj->logo;
218 $companystatic->email = $obj->email;
219 $companystatic->entity = $obj->entity;
220 $companystatic->canvas = $obj->canvas;
221
222 print '<tr class="oddeven">';
223 print '<td class="nowraponall tdoverflowmax125 minwidth75">'.$propalstatic->getNomUrl(1).'</td>';
224 print '<td class="nowrap tdoverflowmax250">'.$companystatic->getNomUrl(1, 'customer').'</td>';
225 print '<td class="nowrap right tdamount amount">'.price((getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc)).'</td>';
226 print '</tr>';
227
228 $i++;
229 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
230 }
231
232 if ($othernb) {
233 print '<tr class="oddeven">';
234 print '<td class="nowrap" colspan="5">';
235 print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
236 print '</td>';
237 print "</tr>\n";
238 }
239 }
240
241 addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
242 finishSimpleTable(true);
243
244 $db->free($resql);
245 } else {
246 dol_print_error($db);
247 }
248}
249
250
251/*
252 * Draft supplier proposals
253 */
254
255if (isModEnabled('supplier_proposal') && $user->hasRight("supplier_proposal", "lire") && is_object($supplierproposalstatic)) {
256 $sql = "SELECT p.rowid, p.ref, p.total_ht, p.total_tva, p.total_ttc, p.fk_statut as status";
257 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
258 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
259 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
260 $sql .= ", s.logo, s.email, s.entity";
261 $sql .= ", s.canvas";
262 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p,";
263 $sql .= " ".MAIN_DB_PREFIX."societe as s";
264 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
265 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
266 }
267 $sql .= " WHERE p.entity IN (".getEntity($supplierproposalstatic->element).")";
268 $sql .= " AND p.fk_statut = ".SupplierProposal::STATUS_DRAFT;
269 $sql .= " AND p.fk_soc = s.rowid";
270 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
271 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
272 }
273 if ($socid) {
274 $sql .= " AND s.rowid = ".((int) $socid);
275 }
276 // Add where from hooks
277 $parameters = array('socid' => $user->socid);
278 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $supplierproposalstatic); // Note that $action and $object may have been modified by hook
279 $sql .= $hookmanager->resPrint;
280 $resql = $db->query($sql);
281 if ($resql) {
282 $total = 0;
283 $num = $db->num_rows($resql);
284 $nbofloop = min($num, $maxofloop);
285 startSimpleTable("SupplierProposalsDraft", "supplier_proposal/list.php", "search_status=".SupplierProposal::STATUS_DRAFT, 2, $num);
286
287 if ($num > 0) {
288 $i = 0;
289 $othernb = 0;
290
291 while ($i < $nbofloop) {
292 $obj = $db->fetch_object($resql);
293
294 if ($i >= $max) {
295 $othernb += 1;
296 $i++;
297 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
298 continue;
299 }
300
301 $supplierproposalstatic->id = $obj->rowid;
302 $supplierproposalstatic->ref = $obj->ref;
303 $supplierproposalstatic->total_ht = $obj->total_ht;
304 $supplierproposalstatic->total_tva = $obj->total_tva;
305 $supplierproposalstatic->total_ttc = $obj->total_ttc;
306 $supplierproposalstatic->statut = $obj->status;
307 $supplierproposalstatic->status = $obj->status;
308
309 $companystatic->id = $obj->socid;
310 $companystatic->name = $obj->name;
311 $companystatic->name_alias = $obj->name_alias;
312 $companystatic->code_client = $obj->code_client;
313 $companystatic->code_compta_client = $obj->code_compta_client;
314 $companystatic->client = $obj->client;
315 $companystatic->code_fournisseur = $obj->code_fournisseur;
316 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
317 $companystatic->fournisseur = $obj->fournisseur;
318 $companystatic->logo = $obj->logo;
319 $companystatic->email = $obj->email;
320 $companystatic->entity = $obj->entity;
321 $companystatic->canvas = $obj->canvas;
322
323 print '<tr class="oddeven">';
324 print '<td class="nowraponall tdoverflowmax125 minwidth75">'.$supplierproposalstatic->getNomUrl(1).'</td>';
325 print '<td class="nowrap tdoverflowmax250">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
326 print '<td class="nowrap right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
327 print '</tr>';
328
329 $i++;
330 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
331 }
332
333 if ($othernb) {
334 print '<tr class="oddeven">';
335 print '<td class="nowrap" colspan="5">';
336 print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
337 print '</td>';
338 print "</tr>\n";
339 }
340 }
341
342 addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
343 finishSimpleTable(true);
344
345 $db->free($resql);
346 } else {
347 dol_print_error($db);
348 }
349}
350
351
352/*
353 * Draft sales orders
354 */
355
356if (isModEnabled('order') && $user->hasRight('commande', 'lire') && is_object($orderstatic)) {
357 $sql = "SELECT c.rowid, c.ref, c.ref_client, c.total_ht, c.total_tva, c.total_ttc, c.fk_statut as status";
358 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
359 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
360 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
361 $sql .= ", s.logo, s.email, s.entity";
362 $sql .= ", s.canvas";
363 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
364 $sql .= " ".MAIN_DB_PREFIX."societe as s";
365 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
366 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
367 }
368 $sql .= " WHERE c.entity IN (".getEntity($orderstatic->element).")";
369 $sql .= " AND c.fk_statut = ".Commande::STATUS_DRAFT;
370 $sql .= " AND c.fk_soc = s.rowid";
371 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
372 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
373 }
374 if ($socid) {
375 $sql .= " AND c.fk_soc = ".((int) $socid);
376 }
377 // Add where from hooks
378 $parameters = array('socid' => $user->socid);
379 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $orderstatic); // Note that $action and $object may have been modified by hook
380 $sql .= $hookmanager->resPrint;
381 $resql = $db->query($sql);
382 if ($resql) {
383 $total = 0;
384 $num = $db->num_rows($resql);
385 $nbofloop = min($num, $maxofloop);
386 startSimpleTable("DraftOrders", "commande/list.php", "search_status=".Commande::STATUS_DRAFT, 2, $num);
387
388 if ($num > 0) {
389 $i = 0;
390 $othernb = 0;
391
392 while ($i < $nbofloop) {
393 $obj = $db->fetch_object($resql);
394
395 if ($i >= $max) {
396 $othernb += 1;
397 $i++;
398 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
399 continue;
400 }
401
402 $orderstatic->id = $obj->rowid;
403 $orderstatic->ref = $obj->ref;
404 $orderstatic->ref_client = $obj->ref_client;
405 $orderstatic->total_ht = $obj->total_ht;
406 $orderstatic->total_tva = $obj->total_tva;
407 $orderstatic->total_ttc = $obj->total_ttc;
408 $orderstatic->statut = $obj->status; // deprecated
409 $orderstatic->status = $obj->status;
410
411 $companystatic->id = $obj->socid;
412 $companystatic->name = $obj->name;
413 $companystatic->name_alias = $obj->name_alias;
414 $companystatic->code_client = $obj->code_client;
415 $companystatic->code_compta = $obj->code_compta_client;
416 $companystatic->code_compta_client = $obj->code_compta_client;
417 $companystatic->client = $obj->client;
418 $companystatic->code_fournisseur = $obj->code_fournisseur;
419 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
420 $companystatic->fournisseur = $obj->fournisseur;
421 $companystatic->logo = $obj->logo;
422 $companystatic->email = $obj->email;
423 $companystatic->entity = $obj->entity;
424 $companystatic->canvas = $obj->canvas;
425
426 print '<tr class="oddeven">';
427 print '<td class="nowraponall tdoverflowmax125 minwidth75">'.$orderstatic->getNomUrl(1).'</td>';
428 print '<td class="nowrap tdoverflowmax250">'.$companystatic->getNomUrl(1, 'customer').'</td>';
429 print '<td class="nowrap right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
430 print '</tr>';
431
432 $i++;
433 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
434 }
435
436 if ($othernb) {
437 print '<tr class="oddeven">';
438 print '<td class="nowrap" colspan="5">';
439 print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
440 print '</td>';
441 print "</tr>\n";
442 }
443 }
444
445 addSummaryTableLine(3, $num, $nbofloop, $total, "NoOrder");
446 finishSimpleTable(true);
447
448 $db->free($resql);
449 } else {
450 dol_print_error($db);
451 }
452}
453
454
455/*
456 * Draft purchase orders
457 */
458
459if ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "commande", "lire")) || (isModEnabled("supplier_order") && $user->hasRight("supplier_order", "lire"))) {
460 $supplierorderstatic = new CommandeFournisseur($db);
461
462 $sql = "SELECT cf.rowid, cf.ref, cf.ref_supplier, cf.total_ht, cf.total_tva, cf.total_ttc, cf.fk_statut as status";
463 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
464 $sql .= ", s.code_client, s.code_compta, s.client";
465 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
466 $sql .= ", s.logo, s.email, s.entity";
467 $sql .= ", s.canvas";
468 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf,";
469 $sql .= " ".MAIN_DB_PREFIX."societe as s";
470 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
471 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
472 }
473 $sql .= " WHERE cf.entity IN (".getEntity($supplierorderstatic->element).")";
474 $sql .= " AND cf.fk_statut = ".CommandeFournisseur::STATUS_DRAFT;
475 $sql .= " AND cf.fk_soc = s.rowid";
476 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
477 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
478 }
479 if ($socid) {
480 $sql .= " AND cf.fk_soc = ".((int) $socid);
481 }
482 // Add where from hooks
483 $parameters = array('socid' => $user->socid);
484 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $supplierorderstatic); // Note that $action and $object may have been modified by hook
485 $sql .= $hookmanager->resPrint;
486 $resql = $db->query($sql);
487 if ($resql) {
488 $total = 0;
489 $num = $db->num_rows($resql);
490 $nbofloop = min($num, $maxofloop);
491 startSimpleTable("DraftSuppliersOrders", "fourn/commande/list.php", "search_status=".CommandeFournisseur::STATUS_DRAFT, 2, $num);
492
493 if ($num > 0) {
494 $i = 0;
495 $othernb = 0;
496
497 while ($i < $nbofloop) {
498 $obj = $db->fetch_object($resql);
499
500 if ($i >= $max) {
501 $othernb += 1;
502 $i++;
503 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
504 continue;
505 }
506
507 $supplierorderstatic->id = $obj->rowid;
508 $supplierorderstatic->ref = $obj->ref;
509 $supplierorderstatic->ref_supplier = $obj->ref_supplier;
510 $supplierorderstatic->total_ht = $obj->total_ht;
511 $supplierorderstatic->total_tva = $obj->total_tva;
512 $supplierorderstatic->total_ttc = $obj->total_ttc;
513 $supplierorderstatic->statut = $obj->status; // deprecated
514 $supplierorderstatic->status = $obj->status;
515
516 $companystatic->id = $obj->socid;
517 $companystatic->name = $obj->name;
518 $companystatic->name_alias = $obj->name_alias;
519 $companystatic->code_client = $obj->code_client;
520 $companystatic->code_compta = $obj->code_compta;
521 $companystatic->code_compta_client = $obj->code_compta;
522 $companystatic->client = $obj->client;
523 $companystatic->code_fournisseur = $obj->code_fournisseur;
524 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
525 $companystatic->fournisseur = $obj->fournisseur;
526 $companystatic->logo = $obj->logo;
527 $companystatic->email = $obj->email;
528 $companystatic->entity = $obj->entity;
529 $companystatic->canvas = $obj->canvas;
530
531 print '<tr class="oddeven">';
532 print '<td class="nowraponall tdoverflowmax125 minwidth75">'.$supplierorderstatic->getNomUrl(1).'</td>';
533 print '<td class="nowrap tdoverflowmax250">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
534 print '<td class="nowrap right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
535 print '</tr>';
536
537 $i++;
538 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
539 }
540
541 if ($othernb) {
542 print '<tr class="oddeven">';
543 print '<td class="nowrap" colspan="5">';
544 print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
545 print '</td>';
546 print "</tr>\n";
547 }
548 }
549
550 addSummaryTableLine(3, $num, $nbofloop, $total, "NoOrder");
551 finishSimpleTable(true);
552
553 $db->free($resql);
554 } else {
555 dol_print_error($db);
556 }
557}
558
559
560/*
561 * Draft interventions
562 */
563if (isModEnabled('intervention') && is_object($fichinterstatic)) {
564 $sql = "SELECT f.rowid, f.ref, s.nom as name, f.fk_statut, f.duree as duration";
565 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
566 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
567 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
568 $sql .= ", s.logo, s.email, s.entity";
569 $sql .= ", s.canvas";
570 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
571 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
572 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
573 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
574 }
575 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
576 $sql .= " AND f.fk_soc = s.rowid";
577 $sql .= " AND f.fk_statut = 0";
578 if ($socid) {
579 $sql .= " AND f.fk_soc = ".((int) $socid);
580 }
581 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
582 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
583 }
584
585 // Add where from hooks
586 $parameters = array('socid' => $user->socid);
587 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $fichinterstatic); // Note that $action and $object may have been modified by hook
588 $sql .= $hookmanager->resPrint;
589 $resql = $db->query($sql);
590 if ($resql) {
591 $num = $db->num_rows($resql);
592 $nbofloop = min($num, $maxofloop);
593 startSimpleTable("DraftFichinter", "fichinter/list.php", "search_status=".Fichinter::STATUS_DRAFT, 2, $num);
594
595 //print '<tr class="liste_titre">';
596 //print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
597
598 if ($num > 0) {
599 $i = 0;
600 while ($i < $nbofloop) {
601 $obj = $db->fetch_object($resql);
602
603 $fichinterstatic->id = $obj->rowid;
604 $fichinterstatic->ref = $obj->ref;
605 $fichinterstatic->statut = $obj->fk_statut; // deprecated
606 $fichinterstatic->status = $obj->fk_statut;
607
608 $companystatic->id = $obj->socid;
609 $companystatic->name = $obj->name;
610 $companystatic->name_alias = $obj->name_alias;
611 $companystatic->code_client = $obj->code_client;
612 $companystatic->code_compta = $obj->code_compta_client;
613 $companystatic->code_compta_client = $obj->code_compta_client;
614 $companystatic->client = $obj->client;
615 $companystatic->code_fournisseur = $obj->code_fournisseur;
616 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
617 $companystatic->fournisseur = $obj->fournisseur;
618 $companystatic->logo = $obj->logo;
619 $companystatic->email = $obj->email;
620 $companystatic->entity = $obj->entity;
621 $companystatic->canvas = $obj->canvas;
622
623 print '<tr class="oddeven">';
624 print '<td class="tdoverflowmax125 minwidth75">';
625 print $fichinterstatic->getNomUrl(1);
626 print "</td>";
627 print '<td class="tdoverflowmax250 minwidth100">';
628 print $companystatic->getNomUrl(1, 'customer');
629 print '</td>';
630 print '<td class="nowraponall tdoverflowmax100 right">';
631 print convertSecondToTime($obj->duration);
632 print '</td>';
633 print '</tr>';
634 $i++;
635 }
636 }
637
638 addSummaryTableLine(3, $num, $nbofloop, $total, "NoIntervention");
639 finishSimpleTable(true);
640
641 $db->free($resql);
642 }
643}
644
645
646print '</div><div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
647
648
649/*
650 * Last modified customers or prospects
651 */
652/* Hidden, already into the menu thirdparty, and it is more relevant in this menu.
653if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) {
654 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
655 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
656 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
657 $sql .= ", s.logo, s.email, s.entity";
658 $sql .= ", s.canvas";
659 $sql .= ", s.datec, s.tms";
660 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
661 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
662 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
663 }
664 $sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
665 $sql .= " AND s.client IN (".Societe::CUSTOMER.", ".Societe::PROSPECT.", ".Societe::CUSTOMER_AND_PROSPECT.")";
666 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
667 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
668 }
669 // Add where from hooks
670 $parameters = array('socid' => $socid);
671 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $companystatic); // Note that $action and $object may have been modified by hook
672 if (empty($reshook)) {
673 if ($socid > 0) {
674 $sql .= " AND s.rowid = ".((int) $socid);
675 }
676 }
677 $sql .= $hookmanager->resPrint;
678 $sql .= " ORDER BY s.tms DESC";
679 $sql .= $db->plimit($max, 0);
680
681 $resql = $db->query($sql);
682 if ($resql) {
683 if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
684 $header = "BoxTitleLastCustomersOrProspects";
685 } elseif (getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
686 $header = "BoxTitleLastModifiedProspects";
687 } else {
688 $header = "BoxTitleLastModifiedCustomers";
689 }
690
691 $num = $db->num_rows($resql);
692 startSimpleTable($langs->trans($header, min($max, $num)), "societe/list.php", "type=p,c&sortfield=s.tms&sortorder=DESC", 1, -1, 'company');
693
694 if ($num) {
695 $i = 0;
696
697 while ($i < $num && $i < $max) {
698 $objp = $db->fetch_object($resql);
699
700 $companystatic->id = $objp->socid;
701 $companystatic->name = $objp->name;
702 $companystatic->name_alias = $objp->name_alias;
703 $companystatic->code_client = $objp->code_client;
704 $companystatic->code_compta = $objp->code_compta_client;
705 $companystatic->code_compta_client = $objp->code_compta_client;
706 $companystatic->client = $objp->client;
707 $companystatic->code_fournisseur = $objp->code_fournisseur;
708 $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
709 $companystatic->fournisseur = $objp->fournisseur;
710 $companystatic->logo = $objp->logo;
711 $companystatic->email = $objp->email;
712 $companystatic->entity = $objp->entity;
713 $companystatic->canvas = $objp->canvas;
714
715 print '<tr class="oddeven">';
716 print '<td class="nowraponall tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
717 print '<td class="nowrap">';
718 //print $companystatic->getLibCustProspStatut();
719
720 $obj = $companystatic;
721 $s = '';
722 if (($obj->client == 2 || $obj->client == 3) && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS')) {
723 $s .= '<a class="customer-back opacitymedium" title="'.$langs->trans("Prospect").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Prospect"), 0, 1).'</a>';
724 }
725 if (($obj->client == 1 || $obj->client == 3) && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
726 $s .= '<a class="customer-back" title="'.$langs->trans("Customer").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Customer"), 0, 1).'</a>';
727 }
728 print $s;
729
730 print '</td>';
731
732 $datem = $db->jdate($objp->tms);
733 print '<td class="right nowrap tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
734 print dol_print_date($datem, 'day', 'tzuserrel');
735 print '</td>';
736 print '</tr>';
737
738 $i++;
739 }
740 }
741
742 addSummaryTableLine(3, $num);
743 finishSimpleTable(true);
744
745 $db->free($resql);
746 } else {
747 dol_print_error($db);
748 }
749}
750*/
751
752
753/*
754 * Last modified proposals
755 */
756
757if (isModEnabled('propal') && is_object($propalstatic)) {
758 $sql = "SELECT p.rowid, p.entity, p.ref, p.fk_statut as status, p.tms as datem,";
759 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta as code_compta_client";
760 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p,";
761 $sql .= " ".MAIN_DB_PREFIX."societe as s";
762 $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
763 $sql .= " AND p.fk_soc = s.rowid";
764 // If the internal user must only see his customers, force searching by him
765 $search_sale = 0;
766 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
767 $search_sale = $user->id;
768 }
769 // Search on sale representative
770 if ($search_sale && $search_sale != '-1') {
771 if ($search_sale == -2) {
772 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
773 } elseif ($search_sale > 0) {
774 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
775 }
776 }
777 // Search on socid
778 if ($socid) {
779 $sql .= " AND p.fk_soc = ".((int) $socid);
780 }
781 // Add where from hooks
782 $parameters = array('socid' => $user->socid);
783 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
784 $sql .= $hookmanager->resPrint;
785 $sql .= " ORDER BY p.tms DESC";
786
787 $sql .= $db->plimit($max, 0);
788
789 $resql = $db->query($sql);
790 if ($resql) {
791 $num = $db->num_rows($resql);
792
793 startSimpleTable($langs->trans("LastModifiedProposals", $max), "comm/propal/list.php", "sortfield=p.tms&sortorder=DESC", 2, -1, 'propal');
794
795 if ($num) {
796 $i = 0;
797 while ($i < $num) {
798 $obj = $db->fetch_object($resql);
799
800 $propalstatic->id = $obj->rowid;
801 $propalstatic->ref = $obj->ref;
802 $propalstatic->status = $obj->status;
803
804 $companystatic->id = $obj->socid;
805 $companystatic->name = $obj->socname;
806 $companystatic->client = $obj->client;
807 $companystatic->canvas = $obj->canvas;
808 $companystatic->email = $obj->email;
809 $companystatic->code_compta = $obj->code_compta_client;
810 $companystatic->code_compta_client = $obj->code_compta_client;
811
812 $filename = dol_sanitizeFileName($obj->ref);
813 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
814 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
815
816 print '<tr class="oddeven">';
817
818 print '<td class="nowrap">';
819 print '<table class="nobordernopadding">';
820 print '<tr class="nocellnopadd">';
821 print '<td width="96" class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
822 print '<td width="16" class="nobordernopadding nowrap"></td>';
823 print '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
824 print '</tr>';
825 print '</table>';
826 print '</td>';
827
828 print '<td class="tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
829
830 $datem = $db->jdate($obj->datem);
831 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
832 print dol_print_date($datem, 'day', 'tzuserrel');
833 print '</td>';
834
835 print '<td class="right">'.$propalstatic->LibStatut($obj->status, 3).'</td>';
836
837 print '</tr>';
838
839 $i++;
840 }
841 }
842
843 finishSimpleTable(true);
844 $db->free($resql);
845 } else {
846 dol_print_error($db);
847 }
848}
849
850
851/*
852 * Latest modified orders
853 */
854
855if (isModEnabled('order')) {
856 $commandestatic = new Commande($db);
857
858 $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, c.facture, c.date_cloture as datec, c.tms as datem,";
859 $sql .= " s.nom as name, s.rowid as socid";
860 $sql .= ", s.client";
861 $sql .= ", s.code_client";
862 $sql .= ", s.canvas";
863 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
864 $sql .= " ".MAIN_DB_PREFIX."societe as s";
865 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
866 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
867 }
868 $sql .= " WHERE c.fk_soc = s.rowid";
869 $sql .= " AND c.entity IN (".getEntity('commande').")";
870 //$sql.= " AND c.fk_statut > 2";
871 if ($socid) {
872 $sql .= " AND c.fk_soc = ".((int) $socid);
873 }
874 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
875 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
876 }
877 // Add where from hooks
878 $parameters = array('socid' => $user->socid);
879 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $orderstatic); // Note that $action and $object may have been modified by hook
880 $sql .= $hookmanager->resPrint;
881 $sql .= " ORDER BY c.tms DESC";
882 $sql .= $db->plimit($max, 0);
883
884 $resql = $db->query($sql);
885 if ($resql) {
886 $num = $db->num_rows($resql);
887
888 startSimpleTable($langs->trans("LastModifiedOrders", $max), "commande/list.php", "sortfield=c.tms&sortorder=DESC", 2, -1, 'order');
889
890 if ($num) {
891 $i = 0;
892 while ($i < $num) {
893 $obj = $db->fetch_object($resql);
894
895 print '<tr class="oddeven">';
896 print '<td width="20%" class="nowrap">';
897
898 $commandestatic->id = $obj->rowid;
899 $commandestatic->ref = $obj->ref;
900
901 $companystatic->id = $obj->socid;
902 $companystatic->name = $obj->name;
903 $companystatic->client = $obj->client;
904 $companystatic->code_client = $obj->code_client;
905 $companystatic->canvas = $obj->canvas;
906
907 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
908 print '<td width="96" class="nobordernopadding nowrap">';
909 print $commandestatic->getNomUrl(1);
910 print '</td>';
911
912 print '<td width="16" class="nobordernopadding nowrap">';
913 print '&nbsp;';
914 print '</td>';
915
916 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
917 $filename = dol_sanitizeFileName($obj->ref);
918 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
919 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
920 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
921 print '</td></tr></table>';
922
923 print '</td>';
924
925 print '<td class="nowrap">';
926 print $companystatic->getNomUrl(1, 'company', 16);
927 print '</td>';
928
929 $datem = $db->jdate($obj->datem);
930 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
931 print dol_print_date($datem, 'day', 'tzuserrel');
932 print '</td>';
933
934 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
935 print '</tr>';
936 $i++;
937 }
938 }
939 finishSimpleTable(true);
940 } else {
941 dol_print_error($db);
942 }
943}
944
945
946/*
947 * Last suppliers
948 */
949/* Hidden, should be into the Thirdparty menu
950if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $user->hasRight('societe', 'lire')) {
951 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
952 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
953 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
954 $sql .= ", s.logo, s.email, s.entity";
955 $sql .= ", s.canvas";
956 $sql .= ", s.datec as dc, s.tms as dm";
957 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
958 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
959 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
960 }
961 $sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
962 $sql .= " AND s.fournisseur = ".Societe::SUPPLIER;
963 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
964 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
965 }
966 // Add where from hooks
967 $parameters = array('socid' => $socid);
968 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $companystatic); // Note that $action and $object may have been modified by hook
969 if (empty($reshook)) {
970 if ($socid > 0) {
971 $sql .= " AND s.rowid = ".((int) $socid);
972 }
973 }
974 $sql .= $hookmanager->resPrint;
975 $sql .= " ORDER BY s.datec DESC";
976 $sql .= $db->plimit($max, 0);
977
978 $resql = $db->query($sql);
979 if ($resql) {
980 $num = $db->num_rows($resql);
981 startSimpleTable($langs->trans("BoxTitleLastModifiedSuppliers", min($max, $num)), "societe/list.php", "type=f", 1, -1, 'company');
982
983 if ($num) {
984 $i = 0;
985 while ($i < $num && $i < $max) {
986 $objp = $db->fetch_object($resql);
987
988 $companystatic->id = $objp->socid;
989 $companystatic->name = $objp->name;
990 $companystatic->name_alias = $objp->name_alias;
991 $companystatic->code_client = $objp->code_client;
992 $companystatic->code_compta = $objp->code_compta_client;
993 $companystatic->code_compta_client = $objp->code_compta_client;
994 $companystatic->client = $objp->client;
995 $companystatic->code_fournisseur = $objp->code_fournisseur;
996 $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
997 $companystatic->fournisseur = $objp->fournisseur;
998 $companystatic->logo = $objp->logo;
999 $companystatic->email = $objp->email;
1000 $companystatic->entity = $objp->entity;
1001 $companystatic->canvas = $objp->canvas;
1002
1003 print '<tr class="oddeven">';
1004 print '<td class="nowraponall tdoverflowmax100">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
1005 print '<td>';
1006
1007 $obj = $companystatic;
1008 $s = '';
1009 if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $obj->fournisseur) {
1010 $s .= '<a class="vendor-back" title="'.$langs->trans("Supplier").'" href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$companystatic->id.'">'.dol_substr($langs->trans("Supplier"), 0, 1).'</a>';
1011 }
1012 print $s;
1013
1014 print '</td>';
1015
1016 $datem = $db->jdate($objp->dm);
1017 print '<td class="right tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
1018 print dol_print_date($datem, 'day', 'tzuserrel');
1019 print '</td>';
1020 print '</tr>';
1021
1022 $i++;
1023 }
1024 }
1025
1026 addSummaryTableLine(3, $num);
1027 finishSimpleTable(true);
1028
1029 $db->free($resql);
1030 } else {
1031 dol_print_error($db);
1032 }
1033}
1034*/
1035
1036
1037/*
1038 * Latest contracts
1039 */
1040if (isModEnabled('contract') && $user->hasRight("contrat", "lire") && 0) { // TODO A REFAIRE DEPUIS NOUVEAU CONTRAT
1041 $staticcontrat = new Contrat($db);
1042
1043 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
1044 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
1045 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
1046 $sql .= ", s.logo, s.email, s.entity";
1047 $sql .= ", s.canvas";
1048 $sql .= ", c.statut, c.rowid as contratid, p.ref, c.fin_validite as datefin, c.date_cloture as dateclo";
1049 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
1050 $sql .= ", ".MAIN_DB_PREFIX."contrat as c";
1051 $sql .= ", ".MAIN_DB_PREFIX."product as p";
1052 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1053 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1054 }
1055 $sql .= " WHERE c.entity IN (".getEntity($staticcontrat->element).")";
1056 $sql .= " AND c.fk_soc = s.rowid";
1057 $sql .= " AND c.fk_product = p.rowid";
1058 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1059 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1060 }
1061 if ($socid) {
1062 $sql .= " AND s.rowid = ".((int) $socid);
1063 }
1064 // Add where from hooks
1065 $parameters = array('socid' => $user->socid);
1066 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $staticcontrat); // Note that $action and $object may have been modified by hook
1067 $sql .= $hookmanager->resPrint;
1068 $sql .= " ORDER BY c.tms DESC";
1069 $sql .= $db->plimit($max + 1, 0);
1070
1071 $resql = $db->query($sql);
1072 if ($resql) {
1073 $num = $db->num_rows($resql);
1074 startSimpleTable($langs->trans("LastContracts", $max), "", "", 2);
1075
1076 if ($num > 0) {
1077 $i = 0;
1078
1079 while ($i < $num) {
1080 $obj = $db->fetch_object($resql);
1081
1082 $companystatic->id = $obj->socid;
1083 $companystatic->name = $obj->name;
1084 $companystatic->name_alias = $obj->name_alias;
1085 $companystatic->code_client = $obj->code_client;
1086 $companystatic->code_compta = $obj->code_compta_client;
1087 $companystatic->code_compta_client = $obj->code_compta_client;
1088 $companystatic->client = $obj->client;
1089 $companystatic->code_fournisseur = $obj->code_fournisseur;
1090 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1091 $companystatic->fournisseur = $obj->fournisseur;
1092 $companystatic->logo = $obj->logo;
1093 $companystatic->email = $obj->email;
1094 $companystatic->entity = $obj->entity;
1095 $companystatic->canvas = $obj->canvas;
1096
1097 $staticcontrat->id = $obj->contratid;
1098 $staticcontrat->ref = $obj->ref;
1099
1100 print '<tr class="oddeven">';
1101 print '<td class="nowraponall">'.$staticcontrat->getNomUrl(1).'</td>';
1102 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
1103 print '<td class="right">'.$staticcontrat->LibStatut($obj->statut, 3).'</td>';
1104 print '</tr>';
1105
1106 $i++;
1107 }
1108 }
1109
1110 addSummaryTableLine(2, $num);
1111 finishSimpleTable(true);
1112
1113 $db->free($resql);
1114 } else {
1115 dol_print_error($db);
1116 }
1117}
1118
1119
1120/*
1121 * Opened (validated) proposals
1122 */
1123if (isModEnabled("propal") && $user->hasRight("propal", "lire")) {
1124 $sql = "SELECT p.rowid as propalid, p.entity, p.total_ttc, p.total_ht, p.total_tva, p.ref, p.ref_client, p.fk_statut, p.datep as dp, p.fin_validite as dfv";
1125 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
1126 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
1127 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
1128 $sql .= ", s.logo, s.email, s.entity";
1129 $sql .= ", s.canvas";
1130 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
1131 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
1132 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1133 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1134 }
1135 $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
1136 $sql .= " AND p.fk_soc = s.rowid";
1137 $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
1138 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1139 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1140 }
1141 if ($socid) {
1142 $sql .= " AND s.rowid = ".((int) $socid);
1143 }
1144 // Add where from hooks
1145 $parameters = array('socid' => $user->socid);
1146 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
1147 $sql .= $hookmanager->resPrint;
1148 $sql .= " ORDER BY p.rowid DESC";
1149
1150 $resql = $db->query($sql);
1151 if ($resql) {
1152 $total = $total_ttc = 0;
1153 $num = $db->num_rows($resql);
1154 $nbofloop = min($num, getDolGlobalInt('MAIN_MAXLIST_OVERLOAD', 500));
1155 startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=1", 4, $num);
1156
1157 if ($num > 0) {
1158 $i = 0;
1159 $othernb = 0;
1160
1161 while ($i < $nbofloop) {
1162 $obj = $db->fetch_object($resql);
1163
1164 if ($i >= $max) {
1165 $othernb += 1;
1166 $i++;
1167 $total += $obj->total_ht;
1168 $total_ttc += $obj->total_ttc;
1169 continue;
1170 }
1171
1172 $propalstatic->id = $obj->propalid;
1173 $propalstatic->ref = $obj->ref;
1174 $propalstatic->ref_client = $obj->ref_client; // deprecated
1175 $propalstatic->ref_customer = $obj->ref_client;
1176 $propalstatic->total_ht = $obj->total_ht;
1177 $propalstatic->total_tva = $obj->total_tva;
1178 $propalstatic->total_ttc = $obj->total_ttc;
1179
1180 $companystatic->id = $obj->socid;
1181 $companystatic->name = $obj->name;
1182 $companystatic->name_alias = $obj->name_alias;
1183 $companystatic->code_client = $obj->code_client;
1184 $companystatic->code_compta = $obj->code_compta_client;
1185 $companystatic->code_compta_client = $obj->code_compta_client;
1186 $companystatic->client = $obj->client;
1187 $companystatic->code_fournisseur = $obj->code_fournisseur;
1188 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1189 $companystatic->fournisseur = $obj->fournisseur;
1190 $companystatic->logo = $obj->logo;
1191 $companystatic->email = $obj->email;
1192 $companystatic->entity = $obj->entity;
1193 $companystatic->canvas = $obj->canvas;
1194
1195 $filename = dol_sanitizeFileName($obj->ref);
1196 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
1197 //$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
1198 $warning = ($db->jdate($obj->dfv) < ($now - getWarningDelay('propal', 'cloture'))) ? img_warning($langs->trans("Late")) : '';
1199
1200 print '<tr class="oddeven">';
1201
1202 print '<td class="nowrap" width="140">';
1203 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1204 print '<td class="nobordernopadding nowraponall">'.$propalstatic->getNomUrl(1).'</td>';
1205 print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
1206 print '<td width="16" class="nobordernopadding center">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
1207 print '</tr>';
1208 print '</table>';
1209 print '</td>';
1210
1211 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
1212 $datem = $db->jdate($obj->dp);
1213 print '<td class="center tddate" title="'.dol_escape_htmltag($langs->trans("Date").': '.dol_print_date($datem, 'day', 'tzserver')).'">';
1214 print dol_print_date($datem, 'day', 'tzserver');
1215 print '</td>';
1216 print '<td class="right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
1217 print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
1218
1219 print '</tr>';
1220
1221 $i++;
1222 $total += $obj->total_ht;
1223 $total_ttc += $obj->total_ttc;
1224 }
1225
1226 if ($othernb) {
1227 print '<tr class="oddeven">';
1228 print '<td class="nowrap" colspan="5">';
1229 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1230 print '</td>';
1231 print "</tr>\n";
1232 }
1233 }
1234
1235 addSummaryTableLine(5, $num, $nbofloop, !getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $total_ttc : $total, "NoProposal", true);
1236 finishSimpleTable(true);
1237
1238 $db->free($resql);
1239 } else {
1240 dol_print_error($db);
1241 }
1242}
1243
1244
1245/*
1246 * Opened (validated) order
1247 */
1248if (isModEnabled('order') && $user->hasRight('commande', 'lire') && is_object($orderstatic)) {
1249 $sql = "SELECT c.rowid as commandeid, c.total_ttc, c.total_ht, c.total_tva, c.ref, c.ref_client, c.fk_statut, c.date_valid as dv, c.facture as billed";
1250 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
1251 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
1252 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
1253 $sql .= ", s.logo, s.email, s.entity";
1254 $sql .= ", s.canvas";
1255 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
1256 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
1257 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1258 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1259 }
1260 $sql .= " WHERE c.entity IN (".getEntity($orderstatic->element).")";
1261 $sql .= " AND c.fk_soc = s.rowid";
1262 $sql .= " AND c.fk_statut IN (".Commande::STATUS_VALIDATED.", ".Commande::STATUS_SHIPMENTONPROCESS.")";
1263 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1264 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1265 }
1266 if ($socid) {
1267 $sql .= " AND s.rowid = ".((int) $socid);
1268 }
1269 // Add where from hooks
1270 $parameters = array('socid' => $user->socid);
1271 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $orderstatic); // Note that $action and $object may have been modified by hook
1272 $sql .= $hookmanager->resPrint;
1273 $sql .= " ORDER BY c.rowid DESC";
1274
1275 $resql = $db->query($sql);
1276 if ($resql) {
1277 $total = $total_ttc = 0;
1278 $num = $db->num_rows($resql);
1279 $nbofloop = min($num, getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500));
1280 startSimpleTable("OrdersOpened", "commande/list.php", "search_status=".Commande::STATUS_VALIDATED, 4, $num);
1281
1282 if ($num > 0) {
1283 $i = 0;
1284 $othernb = 0;
1285
1286 while ($i < $nbofloop) {
1287 $obj = $db->fetch_object($resql);
1288
1289 if ($i >= $max) {
1290 $othernb += 1;
1291 $i++;
1292 $total += $obj->total_ht;
1293 $total_ttc += $obj->total_ttc;
1294 continue;
1295 }
1296
1297 $orderstatic->id = $obj->commandeid;
1298 $orderstatic->ref = $obj->ref;
1299 $orderstatic->ref_client = $obj->ref_client;
1300 $orderstatic->statut = $obj->fk_statut; // deprecated
1301 $orderstatic->status = $obj->fk_statut;
1302 $orderstatic->total_ht = $obj->total_ht;
1303 $orderstatic->total_tva = $obj->total_tva;
1304 $orderstatic->total_ttc = $obj->total_ttc;
1305
1306 $companystatic->id = $obj->socid;
1307 $companystatic->name = $obj->name;
1308 $companystatic->name_alias = $obj->name_alias;
1309 $companystatic->code_client = $obj->code_client;
1310 $companystatic->code_compta = $obj->code_compta_client;
1311 $companystatic->code_compta_client = $obj->code_compta_client;
1312 $companystatic->client = $obj->client;
1313 $companystatic->code_fournisseur = $obj->code_fournisseur;
1314 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1315 $companystatic->fournisseur = $obj->fournisseur;
1316 $companystatic->logo = $obj->logo;
1317 $companystatic->email = $obj->email;
1318 $companystatic->entity = $obj->entity;
1319 $companystatic->canvas = $obj->canvas;
1320
1321 $filename = dol_sanitizeFileName($obj->ref);
1322 $filedir = $conf->order->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1323 //$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
1324 //$warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
1325
1326 print '<tr class="oddeven">';
1327
1328 print '<td class="nowrap" width="140">';
1329 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1330 print '<td class="nobordernopadding nowraponall">'.$orderstatic->getNomUrl(1).'</td>';
1331 print '<td width="18" class="nobordernopadding nowrap"></td>';
1332 print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($orderstatic->element, $filename, $filedir).'</td>';
1333 print '</tr>';
1334 print '</table>';
1335 print '</td>';
1336
1337 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
1338 $datem = $db->jdate($obj->dv);
1339 print '<td class="center tddate" title="'.dol_escape_htmltag($langs->trans("DateValue").': '.dol_print_date($datem, 'day', 'tzserver')).'">';
1340 print dol_print_date($datem, 'day', 'tzserver');
1341 print '</td>';
1342
1343 print '<td class="right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
1344 print '<td align="center" width="14">'.$orderstatic->LibStatut($obj->fk_statut, $obj->billed, 3).'</td>';
1345
1346 print '</tr>';
1347
1348 $i++;
1349 $total += $obj->total_ht;
1350 $total_ttc += $obj->total_ttc;
1351 }
1352
1353 if ($othernb) {
1354 print '<tr class="oddeven">';
1355 print '<td class="nowrap" colspan="5">';
1356 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1357 print '</td>';
1358 print "</tr>\n";
1359 }
1360 }
1361
1362 addSummaryTableLine(5, $num, $nbofloop, !getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $total_ttc : $total, "None", true);
1363 finishSimpleTable(true);
1364
1365 $db->free($resql);
1366 } else {
1367 dol_print_error($db);
1368 }
1369}
1370
1371print '</div>';
1372print '</div>';
1373print '</div>';
1374
1375$parameters = array('user' => $user);
1376$reshook = $hookmanager->executeHooks('dashboardCommercials', $parameters, $object); // Note that $action and $object may have been modified by hook
1377
1378// End of page
1379llxFooter();
1380$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage predefined suppliers products.
Class to manage customers orders.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage hooks.
Class to manage proposals.
const STATUS_DRAFT
Draft status.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage price ask supplier.
const STATUS_DRAFT
Draft status.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
Definition date.lib.php:247
dol_now($mode='gmt')
Return date for now.
finishSimpleTable($addLineBreak=false)
Add the correct HTML close tags for "startSimpleTable(...)" (use after the last table line)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
addSummaryTableLine($tableColumnCount, $num, $nbofloop=0, $total=0, $noneWord="None", $extraRightColumn=false)
Add a summary line to the current open table ("None", "XMoreLines" or "Total xxx")
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getWarningDelay($module, $parmlevel1, $parmlevel2='')
Return a warning delay You can use it like this: if (getWarningDelay('module', 'paramlevel1')) It rep...
startSimpleTable($header, $link="", $arguments="", $emptyColumns=0, $number=-1, $pictofulllist='')
Start a table with headers and a optional clickable number (don't forget to use "finishSimpleTable()"...
getCustomerOrderPieChart($socid=0)
Return a HTML table that contains a pie chart of sales orders.
getCustomerProposalPieChart($socid=0)
Return a HTML table that contains a pie chart of customer proposals.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.