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