dolibarr 24.0.2
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-2026 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024-2026 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';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
44require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
45require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
46require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
47require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
48require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
49require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
50require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
51if (isModEnabled('contract')) {
52 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
53}
54if (isModEnabled('intervention')) {
55 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
56}
57
58
59// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
60$hookmanager->initHooks(array('commercialindex'));
61
62// Load translation files required by the page
63$langs->loadLangs(array("boxes", "commercial", "contracts", "orders", "propal", "supplier_proposal"));
64
65$action = GETPOST('action', 'aZ09');
66$bid = GETPOSTINT('bid');
67
68// Securite access client
69$socid = GETPOSTINT('socid');
70if (!empty($user->socid) && $user->socid > 0) {
71 $action = '';
72 $socid = $user->socid;
73}
74
75$total = 0;
76
77$max = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
78
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, $max);
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 {
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, $max);
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 {
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, $max);
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 {
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, $max);
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 {
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, $max);
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);
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.name_alias, 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->name_alias = $obj->name_alias;
807 $companystatic->client = $obj->client;
808 $companystatic->canvas = $obj->canvas;
809 $companystatic->email = $obj->email;
810 $companystatic->code_compta = $obj->code_compta_client;
811 $companystatic->code_compta_client = $obj->code_compta_client;
812
813 $filename = dol_sanitizeFileName($obj->ref);
814 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
815 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
816
817 print '<tr class="oddeven">';
818
819 print '<td class="nowrap">';
820 print '<table class="nobordernopadding">';
821 print '<tr class="nocellnopadd">';
822 print '<td width="96" class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
823 print '<td width="16" class="nobordernopadding nowrap"></td>';
824 print '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
825 print '</tr>';
826 print '</table>';
827 print '</td>';
828
829 print '<td class="tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
830
831 $datem = $db->jdate($obj->datem);
832 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
833 print dol_print_date($datem, 'day', 'tzuserrel');
834 print '</td>';
835
836 print '<td class="right">'.$propalstatic->LibStatut($obj->status, 3).'</td>';
837
838 print '</tr>';
839
840 $i++;
841 }
842 }
843
844 addSummaryTableLine(4, $num);
845 finishSimpleTable(true);
846 $db->free($resql);
847 } else {
849 }
850}
851
852
853/*
854 * Latest modified orders
855 */
856
857if (isModEnabled('order')) {
858 $commandestatic = new Commande($db);
859
860 $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, c.facture, c.date_cloture as datec, c.tms as datem,";
861 $sql .= " s.nom as name, s.name_alias, s.rowid as socid";
862 $sql .= ", s.client";
863 $sql .= ", s.code_client";
864 $sql .= ", s.canvas";
865 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
866 $sql .= " ".MAIN_DB_PREFIX."societe as s";
867 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
868 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
869 }
870 $sql .= " WHERE c.fk_soc = s.rowid";
871 $sql .= " AND c.entity IN (".getEntity('commande').")";
872 //$sql.= " AND c.fk_statut > 2";
873 if ($socid) {
874 $sql .= " AND c.fk_soc = ".((int) $socid);
875 }
876 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
877 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
878 }
879 // Add where from hooks
880 $parameters = array('socid' => $user->socid);
881 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $orderstatic); // Note that $action and $object may have been modified by hook
882 $sql .= $hookmanager->resPrint;
883 $sql .= " ORDER BY c.tms DESC";
884 $sql .= $db->plimit($max, 0);
885
886 $resql = $db->query($sql);
887 if ($resql) {
888 $num = $db->num_rows($resql);
889
890 startSimpleTable($langs->trans("LastModifiedOrders", $max), "commande/list.php", "sortfield=c.tms&sortorder=DESC", 2, -1, 'order');
891
892 if ($num) {
893 $i = 0;
894 while ($i < $num) {
895 $obj = $db->fetch_object($resql);
896
897 print '<tr class="oddeven">';
898 print '<td width="20%" class="nowrap">';
899
900 $commandestatic->id = $obj->rowid;
901 $commandestatic->ref = $obj->ref;
902
903 $companystatic->id = $obj->socid;
904 $companystatic->name = $obj->name;
905 $companystatic->name_alias = $obj->name_alias;
906 $companystatic->client = $obj->client;
907 $companystatic->code_client = $obj->code_client;
908 $companystatic->canvas = $obj->canvas;
909
910 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
911 print '<td width="96" class="nobordernopadding nowrap">';
912 print $commandestatic->getNomUrl(1);
913 print '</td>';
914
915 print '<td width="16" class="nobordernopadding nowrap">';
916 print '&nbsp;';
917 print '</td>';
918
919 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
920 $filename = dol_sanitizeFileName($obj->ref);
921 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
922 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
923 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
924 print '</td></tr></table>';
925
926 print '</td>';
927
928 print '<td class="nowrap">';
929 print $companystatic->getNomUrl(1, 'company', 16);
930 print '</td>';
931
932 $datem = $db->jdate($obj->datem);
933 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
934 print dol_print_date($datem, 'day', 'tzuserrel');
935 print '</td>';
936
937 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
938 print '</tr>';
939 $i++;
940 }
941 }
942 finishSimpleTable(true);
943 } else {
945 }
946}
947
948
949/*
950 * Last suppliers
951 */
952/* Hidden, should be into the Thirdparty menu
953if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $user->hasRight('societe', 'lire')) {
954 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
955 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
956 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
957 $sql .= ", s.logo, s.email, s.entity";
958 $sql .= ", s.canvas";
959 $sql .= ", s.datec as dc, s.tms as dm";
960 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
961 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
962 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
963 }
964 $sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
965 $sql .= " AND s.fournisseur = ".Societe::SUPPLIER;
966 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
967 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
968 }
969 // Add where from hooks
970 $parameters = array('socid' => $socid);
971 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $companystatic); // Note that $action and $object may have been modified by hook
972 if (empty($reshook)) {
973 if ($socid > 0) {
974 $sql .= " AND s.rowid = ".((int) $socid);
975 }
976 }
977 $sql .= $hookmanager->resPrint;
978 $sql .= " ORDER BY s.datec DESC";
979 $sql .= $db->plimit($max, 0);
980
981 $resql = $db->query($sql);
982 if ($resql) {
983 $num = $db->num_rows($resql);
984 startSimpleTable($langs->trans("BoxTitleLastModifiedSuppliers", min($max, $num)), "societe/list.php", "type=f", 1, -1, 'company');
985
986 if ($num) {
987 $i = 0;
988 while ($i < $num && $i < $max) {
989 $objp = $db->fetch_object($resql);
990
991 $companystatic->id = $objp->socid;
992 $companystatic->name = $objp->name;
993 $companystatic->name_alias = $objp->name_alias;
994 $companystatic->code_client = $objp->code_client;
995 $companystatic->code_compta = $objp->code_compta_client;
996 $companystatic->code_compta_client = $objp->code_compta_client;
997 $companystatic->client = $objp->client;
998 $companystatic->code_fournisseur = $objp->code_fournisseur;
999 $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
1000 $companystatic->fournisseur = $objp->fournisseur;
1001 $companystatic->logo = $objp->logo;
1002 $companystatic->email = $objp->email;
1003 $companystatic->entity = $objp->entity;
1004 $companystatic->canvas = $objp->canvas;
1005
1006 print '<tr class="oddeven">';
1007 print '<td class="nowraponall tdoverflowmax100">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
1008 print '<td>';
1009
1010 $obj = $companystatic;
1011 $s = '';
1012 if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $obj->fournisseur) {
1013 $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>';
1014 }
1015 print $s;
1016
1017 print '</td>';
1018
1019 $datem = $db->jdate($objp->dm);
1020 print '<td class="right tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
1021 print dol_print_date($datem, 'day', 'tzuserrel');
1022 print '</td>';
1023 print '</tr>';
1024
1025 $i++;
1026 }
1027 }
1028
1029 addSummaryTableLine(3, $num);
1030 finishSimpleTable(true);
1031
1032 $db->free($resql);
1033 } else {
1034 dol_print_error($db);
1035 }
1036}
1037*/
1038
1039
1040/*
1041 * Latest contracts
1042 */
1043if (isModEnabled('contract') && $user->hasRight("contrat", "lire") && 0) { // TODO To redo/reimplement for new contract
1044 $staticcontrat = new Contrat($db);
1045
1046 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
1047 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
1048 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
1049 $sql .= ", s.logo, s.email, s.entity";
1050 $sql .= ", s.canvas";
1051 $sql .= ", c.statut, c.rowid as contratid, p.ref, c.fin_validite as datefin, c.date_cloture as dateclo";
1052 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
1053 $sql .= ", ".MAIN_DB_PREFIX."contrat as c";
1054 $sql .= ", ".MAIN_DB_PREFIX."product as p";
1055 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1056 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1057 }
1058 $sql .= " WHERE c.entity IN (".getEntity($staticcontrat->element).")";
1059 $sql .= " AND c.fk_soc = s.rowid";
1060 $sql .= " AND c.fk_product = p.rowid";
1061 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1062 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1063 }
1064 if ($socid) {
1065 $sql .= " AND s.rowid = ".((int) $socid);
1066 }
1067 // Add where from hooks
1068 $parameters = array('socid' => $user->socid);
1069 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $staticcontrat); // Note that $action and $object may have been modified by hook
1070 $sql .= $hookmanager->resPrint;
1071 $sql .= " ORDER BY c.tms DESC";
1072 $sql .= $db->plimit($max + 1, 0);
1073
1074 $resql = $db->query($sql);
1075 if ($resql) {
1076 $num = $db->num_rows($resql);
1077 startSimpleTable($langs->trans("LastContracts", $max), "", "", 2);
1078
1079 if ($num > 0) {
1080 $i = 0;
1081
1082 while ($i < $num) {
1083 $obj = $db->fetch_object($resql);
1084
1085 $companystatic->id = $obj->socid;
1086 $companystatic->name = $obj->name;
1087 $companystatic->name_alias = $obj->name_alias;
1088 $companystatic->code_client = $obj->code_client;
1089 $companystatic->code_compta = $obj->code_compta_client;
1090 $companystatic->code_compta_client = $obj->code_compta_client;
1091 $companystatic->client = $obj->client;
1092 $companystatic->code_fournisseur = $obj->code_fournisseur;
1093 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1094 $companystatic->fournisseur = $obj->fournisseur;
1095 $companystatic->logo = $obj->logo;
1096 $companystatic->email = $obj->email;
1097 $companystatic->entity = $obj->entity;
1098 $companystatic->canvas = $obj->canvas;
1099
1100 $staticcontrat->id = $obj->contratid;
1101 $staticcontrat->ref = $obj->ref;
1102
1103 print '<tr class="oddeven">';
1104 print '<td class="nowraponall">'.$staticcontrat->getNomUrl(1).'</td>';
1105 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
1106 print '<td class="right">'.$staticcontrat->LibStatut($obj->statut, 3).'</td>';
1107 print '</tr>';
1108
1109 $i++;
1110 }
1111 }
1112
1113 addSummaryTableLine(2, $num);
1114 finishSimpleTable(true);
1115
1116 $db->free($resql);
1117 } else {
1119 }
1120}
1121
1122
1123/*
1124 * Opened (validated) proposals
1125 */
1126if (isModEnabled("propal") && $user->hasRight("propal", "lire")) {
1127 $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";
1128 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
1129 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
1130 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
1131 $sql .= ", s.logo, s.email, s.entity";
1132 $sql .= ", s.canvas";
1133 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
1134 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
1135 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1136 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1137 }
1138 $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
1139 $sql .= " AND p.fk_soc = s.rowid";
1140 $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
1141 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1142 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1143 }
1144 if ($socid) {
1145 $sql .= " AND s.rowid = ".((int) $socid);
1146 }
1147 // Add where from hooks
1148 $parameters = array('socid' => $user->socid);
1149 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $propalstatic); // Note that $action and $object may have been modified by hook
1150 $sql .= $hookmanager->resPrint;
1151 $sql .= " ORDER BY p.rowid DESC";
1152
1153 $resql = $db->query($sql);
1154 if ($resql) {
1155 $total = $total_ttc = 0;
1156 $num = $db->num_rows($resql);
1157 $nbofloop = min($num, getDolGlobalInt('MAIN_MAXLIST_OVERLOAD', 500));
1158 startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=1", 4, $num);
1159
1160 if ($num > 0) {
1161 $i = 0;
1162 $othernb = 0;
1163
1164 while ($i < $nbofloop) {
1165 $obj = $db->fetch_object($resql);
1166
1167 if ($i >= $max) {
1168 $othernb += 1;
1169 $i++;
1170 $total += $obj->total_ht;
1171 $total_ttc += $obj->total_ttc;
1172 continue;
1173 }
1174
1175 $propalstatic->id = $obj->propalid;
1176 $propalstatic->ref = $obj->ref;
1177 $propalstatic->ref_client = $obj->ref_client; // deprecated
1178 $propalstatic->ref_customer = $obj->ref_client;
1179 $propalstatic->total_ht = $obj->total_ht;
1180 $propalstatic->total_tva = $obj->total_tva;
1181 $propalstatic->total_ttc = $obj->total_ttc;
1182
1183 $companystatic->id = $obj->socid;
1184 $companystatic->name = $obj->name;
1185 $companystatic->name_alias = $obj->name_alias;
1186 $companystatic->code_client = $obj->code_client;
1187 $companystatic->code_compta = $obj->code_compta_client;
1188 $companystatic->code_compta_client = $obj->code_compta_client;
1189 $companystatic->client = $obj->client;
1190 $companystatic->code_fournisseur = $obj->code_fournisseur;
1191 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1192 $companystatic->fournisseur = $obj->fournisseur;
1193 $companystatic->logo = $obj->logo;
1194 $companystatic->email = $obj->email;
1195 $companystatic->entity = $obj->entity;
1196 $companystatic->canvas = $obj->canvas;
1197
1198 $filename = dol_sanitizeFileName($obj->ref);
1199 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
1200 //$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
1201 $warning = ($db->jdate($obj->dfv) < ($now - getWarningDelay('propal', 'cloture'))) ? img_warning($langs->trans("Late")) : '';
1202
1203 print '<tr class="oddeven">';
1204
1205 print '<td class="nowrap" width="140">';
1206 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1207 print '<td class="nobordernopadding nowraponall">'.$propalstatic->getNomUrl(1).'</td>';
1208 print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
1209 print '<td width="16" class="nobordernopadding center">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
1210 print '</tr>';
1211 print '</table>';
1212 print '</td>';
1213
1214 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
1215 $datem = $db->jdate($obj->dp);
1216 print '<td class="center tddate" title="'.dol_escape_htmltag($langs->trans("Date").': '.dol_print_date($datem, 'day', 'tzserver')).'">';
1217 print dol_print_date($datem, 'day', 'tzserver');
1218 print '</td>';
1219 print '<td class="right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
1220 print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
1221
1222 print '</tr>';
1223
1224 $i++;
1225 $total += $obj->total_ht;
1226 $total_ttc += $obj->total_ttc;
1227 }
1228
1229 if ($othernb) {
1230 print '<tr class="oddeven">';
1231 print '<td class="nowrap" colspan="5">';
1232 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1233 print '</td>';
1234 print "</tr>\n";
1235 }
1236 }
1237
1238 addSummaryTableLine(5, $num, $nbofloop, !getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $total_ttc : $total, "NoProposal", true);
1239 finishSimpleTable(true);
1240
1241 $db->free($resql);
1242 } else {
1244 }
1245}
1246
1247
1248/*
1249 * Opened (validated) order
1250 */
1251if (isModEnabled('order') && $user->hasRight('commande', 'lire') && is_object($orderstatic)) {
1252 $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";
1253 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
1254 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
1255 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
1256 $sql .= ", s.logo, s.email, s.entity";
1257 $sql .= ", s.canvas";
1258 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
1259 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
1260 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1261 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1262 }
1263 $sql .= " WHERE c.entity IN (".getEntity($orderstatic->element).")";
1264 $sql .= " AND c.fk_soc = s.rowid";
1265 $sql .= " AND c.fk_statut IN (".Commande::STATUS_VALIDATED.", ".Commande::STATUS_SHIPMENTONPROCESS.")";
1266 if (empty($user->socid) && !$user->hasRight('societe', 'client', 'voir')) {
1267 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1268 }
1269 if ($socid) {
1270 $sql .= " AND s.rowid = ".((int) $socid);
1271 }
1272 // Add where from hooks
1273 $parameters = array('socid' => $user->socid);
1274 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $orderstatic); // Note that $action and $object may have been modified by hook
1275 $sql .= $hookmanager->resPrint;
1276 $sql .= " ORDER BY c.rowid DESC";
1277
1278 $resql = $db->query($sql);
1279 if ($resql) {
1280 $total = $total_ttc = 0;
1281 $num = $db->num_rows($resql);
1282 $nbofloop = min($num, getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500));
1283 startSimpleTable("OrdersOpened", "commande/list.php", "search_status=".Commande::STATUS_VALIDATED, 4, $num);
1284
1285 if ($num > 0) {
1286 $i = 0;
1287 $othernb = 0;
1288
1289 while ($i < $nbofloop) {
1290 $obj = $db->fetch_object($resql);
1291
1292 if ($i >= $max) {
1293 $othernb += 1;
1294 $i++;
1295 $total += $obj->total_ht;
1296 $total_ttc += $obj->total_ttc;
1297 continue;
1298 }
1299
1300 $orderstatic->id = $obj->commandeid;
1301 $orderstatic->ref = $obj->ref;
1302 $orderstatic->ref_client = $obj->ref_client;
1303 $orderstatic->statut = $obj->fk_statut; // deprecated
1304 $orderstatic->status = $obj->fk_statut;
1305 $orderstatic->total_ht = $obj->total_ht;
1306 $orderstatic->total_tva = $obj->total_tva;
1307 $orderstatic->total_ttc = $obj->total_ttc;
1308
1309 $companystatic->id = $obj->socid;
1310 $companystatic->name = $obj->name;
1311 $companystatic->name_alias = $obj->name_alias;
1312 $companystatic->code_client = $obj->code_client;
1313 $companystatic->code_compta = $obj->code_compta_client;
1314 $companystatic->code_compta_client = $obj->code_compta_client;
1315 $companystatic->client = $obj->client;
1316 $companystatic->code_fournisseur = $obj->code_fournisseur;
1317 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1318 $companystatic->fournisseur = $obj->fournisseur;
1319 $companystatic->logo = $obj->logo;
1320 $companystatic->email = $obj->email;
1321 $companystatic->entity = $obj->entity;
1322 $companystatic->canvas = $obj->canvas;
1323
1324 $filename = dol_sanitizeFileName($obj->ref);
1325 $filedir = $conf->order->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1326 //$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
1327 //$warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
1328
1329 print '<tr class="oddeven">';
1330
1331 print '<td class="nowrap" width="140">';
1332 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1333 print '<td class="nobordernopadding nowraponall">'.$orderstatic->getNomUrl(1).'</td>';
1334 print '<td width="18" class="nobordernopadding nowrap"></td>';
1335 print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($orderstatic->element, $filename, $filedir).'</td>';
1336 print '</tr>';
1337 print '</table>';
1338 print '</td>';
1339
1340 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
1341 $datem = $db->jdate($obj->dv);
1342 print '<td class="center tddate" title="'.dol_escape_htmltag($langs->trans("DateValue").': '.dol_print_date($datem, 'day', 'tzserver')).'">';
1343 print dol_print_date($datem, 'day', 'tzserver');
1344 print '</td>';
1345
1346 print '<td class="right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
1347 print '<td align="center" width="14">'.$orderstatic->LibStatut($obj->fk_statut, $obj->billed, 3).'</td>';
1348
1349 print '</tr>';
1350
1351 $i++;
1352 $total += $obj->total_ht;
1353 $total_ttc += $obj->total_ttc;
1354 }
1355
1356 if ($othernb) {
1357 print '<tr class="oddeven">';
1358 print '<td class="nowrap" colspan="5">';
1359 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1360 print '</td>';
1361 print "</tr>\n";
1362 }
1363 }
1364
1365 addSummaryTableLine(5, $num, $nbofloop, !getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $total_ttc : $total, "None", true);
1366 finishSimpleTable(true);
1367
1368 $db->free($resql);
1369 } else {
1371 }
1372}
1373
1374print '</div>';
1375print '</div>';
1376print '</div>';
1377
1378$parameters = array('user' => $user);
1379$reshook = $hookmanager->executeHooks('dashboardCommercials', $parameters, $object); // Note that $action and $object may have been modified by hook
1380
1381// End of page
1382llxFooter();
1383$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 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:263
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.