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