dolibarr 21.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 *
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 a 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 as code_compta_client, 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_client;
191 $companystatic->code_compta_client = $obj->code_compta_client;
192 $companystatic->client = $obj->client;
193 $companystatic->code_fournisseur = $obj->code_fournisseur;
194 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
195 $companystatic->fournisseur = $obj->fournisseur;
196 $companystatic->logo = $obj->logo;
197 $companystatic->email = $obj->email;
198 $companystatic->entity = $obj->entity;
199 $companystatic->canvas = $obj->canvas;
200
201 print '<tr class="oddeven">';
202 print '<td class="nowraponall tdoverflowmax125">'.$propalstatic->getNomUrl(1).'</td>';
203 print '<td class="nowrap tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
204 print '<td class="nowrap right tdamount amount">'.price((getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc)).'</td>';
205 print '</tr>';
206
207 $i++;
208 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
209 }
210
211 if ($othernb) {
212 print '<tr class="oddeven">';
213 print '<td class="nowrap" colspan="5">';
214 print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
215 print '</td>';
216 print "</tr>\n";
217 }
218 }
219
220 addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
221 finishSimpleTable(true);
222
223 $db->free($resql);
224 } else {
225 dol_print_error($db);
226 }
227}
228
229
230/*
231 * Draft supplier proposals
232 */
233
234if (isModEnabled('supplier_proposal') && $user->hasRight("supplier_proposal", "lire")) {
235 $sql = "SELECT p.rowid, p.ref, p.total_ht, p.total_tva, p.total_ttc, p.fk_statut as status";
236 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
237 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
238 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
239 $sql .= ", s.logo, s.email, s.entity";
240 $sql .= ", s.canvas";
241 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as p,";
242 $sql .= " ".MAIN_DB_PREFIX."societe as s";
243 if (!$user->hasRight('societe', 'client', 'voir')) {
244 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
245 }
246 $sql .= " WHERE p.entity IN (".getEntity($supplierproposalstatic->element).")";
247 $sql .= " AND p.fk_statut = ".SupplierProposal::STATUS_DRAFT;
248 $sql .= " AND p.fk_soc = s.rowid";
249 if (!$user->hasRight('societe', 'client', 'voir')) {
250 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
251 }
252 if ($socid) {
253 $sql .= " AND s.rowid = ".((int) $socid);
254 }
255
256 $resql = $db->query($sql);
257 if ($resql) {
258 $total = 0;
259 $num = $db->num_rows($resql);
260 $nbofloop = min($num, $maxofloop);
261 startSimpleTable("SupplierProposalsDraft", "supplier_proposal/list.php", "search_status=".SupplierProposal::STATUS_DRAFT, 2, $num);
262
263 if ($num > 0) {
264 $i = 0;
265 $othernb = 0;
266
267 while ($i < $nbofloop) {
268 $obj = $db->fetch_object($resql);
269
270 if ($i >= $max) {
271 $othernb += 1;
272 $i++;
273 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
274 continue;
275 }
276
277 $supplierproposalstatic->id = $obj->rowid;
278 $supplierproposalstatic->ref = $obj->ref;
279 $supplierproposalstatic->total_ht = $obj->total_ht;
280 $supplierproposalstatic->total_tva = $obj->total_tva;
281 $supplierproposalstatic->total_ttc = $obj->total_ttc;
282 $supplierproposalstatic->statut = $obj->status;
283
284 $companystatic->id = $obj->socid;
285 $companystatic->name = $obj->name;
286 $companystatic->name_alias = $obj->name_alias;
287 $companystatic->code_client = $obj->code_client;
288 $companystatic->code_compta = $obj->code_compta;
289 $companystatic->code_compta_client = $obj->code_compta_client;
290 $companystatic->client = $obj->client;
291 $companystatic->code_fournisseur = $obj->code_fournisseur;
292 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
293 $companystatic->fournisseur = $obj->fournisseur;
294 $companystatic->logo = $obj->logo;
295 $companystatic->email = $obj->email;
296 $companystatic->entity = $obj->entity;
297 $companystatic->canvas = $obj->canvas;
298
299 print '<tr class="oddeven">';
300 print '<td class="nowraponall tdoverflowmax125">'.$supplierproposalstatic->getNomUrl(1).'</td>';
301 print '<td class="nowrap tdoverflowmax100">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
302 print '<td class="nowrap right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
303 print '</tr>';
304
305 $i++;
306 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
307 }
308
309 if ($othernb) {
310 print '<tr class="oddeven">';
311 print '<td class="nowrap" colspan="5">';
312 print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
313 print '</td>';
314 print "</tr>\n";
315 }
316 }
317
318 addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
319 finishSimpleTable(true);
320
321 $db->free($resql);
322 } else {
323 dol_print_error($db);
324 }
325}
326
327
328/*
329 * Draft sales orders
330 */
331
332if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
333 $sql = "SELECT c.rowid, c.ref, c.ref_client, c.total_ht, c.total_tva, c.total_ttc, c.fk_statut as status";
334 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
335 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
336 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
337 $sql .= ", s.logo, s.email, s.entity";
338 $sql .= ", s.canvas";
339 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
340 $sql .= " ".MAIN_DB_PREFIX."societe as s";
341 if (!$user->hasRight('societe', 'client', 'voir')) {
342 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
343 }
344 $sql .= " WHERE c.entity IN (".getEntity($orderstatic->element).")";
345 $sql .= " AND c.fk_statut = ".Commande::STATUS_DRAFT;
346 $sql .= " AND c.fk_soc = s.rowid";
347 if (!$user->hasRight('societe', 'client', 'voir')) {
348 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
349 }
350 if ($socid) {
351 $sql .= " AND c.fk_soc = ".((int) $socid);
352 }
353
354 $resql = $db->query($sql);
355 if ($resql) {
356 $total = 0;
357 $num = $db->num_rows($resql);
358 $nbofloop = min($num, $maxofloop);
359 startSimpleTable("DraftOrders", "commande/list.php", "search_status=".Commande::STATUS_DRAFT, 2, $num);
360
361 if ($num > 0) {
362 $i = 0;
363 $othernb = 0;
364
365 while ($i < $nbofloop) {
366 $obj = $db->fetch_object($resql);
367
368 if ($i >= $max) {
369 $othernb += 1;
370 $i++;
371 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
372 continue;
373 }
374
375 $orderstatic->id = $obj->rowid;
376 $orderstatic->ref = $obj->ref;
377 $orderstatic->ref_client = $obj->ref_client;
378 $orderstatic->total_ht = $obj->total_ht;
379 $orderstatic->total_tva = $obj->total_tva;
380 $orderstatic->total_ttc = $obj->total_ttc;
381 $orderstatic->statut = $obj->status;
382
383 $companystatic->id = $obj->socid;
384 $companystatic->name = $obj->name;
385 $companystatic->name_alias = $obj->name_alias;
386 $companystatic->code_client = $obj->code_client;
387 $companystatic->code_compta = $obj->code_compta_client;
388 $companystatic->code_compta_client = $obj->code_compta_client;
389 $companystatic->client = $obj->client;
390 $companystatic->code_fournisseur = $obj->code_fournisseur;
391 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
392 $companystatic->fournisseur = $obj->fournisseur;
393 $companystatic->logo = $obj->logo;
394 $companystatic->email = $obj->email;
395 $companystatic->entity = $obj->entity;
396 $companystatic->canvas = $obj->canvas;
397
398 print '<tr class="oddeven">';
399 print '<td class="nowraponall tdoverflowmax125">'.$orderstatic->getNomUrl(1).'</td>';
400 print '<td class="nowrap tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
401 print '<td class="nowrap right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
402 print '</tr>';
403
404 $i++;
405 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
406 }
407
408 if ($othernb) {
409 print '<tr class="oddeven">';
410 print '<td class="nowrap" colspan="5">';
411 print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
412 print '</td>';
413 print "</tr>\n";
414 }
415 }
416
417 addSummaryTableLine(3, $num, $nbofloop, $total, "NoOrder");
418 finishSimpleTable(true);
419
420 $db->free($resql);
421 } else {
422 dol_print_error($db);
423 }
424}
425
426
427/*
428 * Draft purchase orders
429 */
430
431if ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "commande", "lire")) || (isModEnabled("supplier_order") && $user->hasRight("supplier_order", "lire"))) {
432 $supplierorderstatic = new CommandeFournisseur($db);
433
434 $sql = "SELECT cf.rowid, cf.ref, cf.ref_supplier, cf.total_ht, cf.total_tva, cf.total_ttc, cf.fk_statut as status";
435 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
436 $sql .= ", s.code_client, s.code_compta, s.client";
437 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
438 $sql .= ", s.logo, s.email, s.entity";
439 $sql .= ", s.canvas";
440 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf,";
441 $sql .= " ".MAIN_DB_PREFIX."societe as s";
442 if (!$user->hasRight('societe', 'client', 'voir')) {
443 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
444 }
445 $sql .= " WHERE cf.entity IN (".getEntity($supplierorderstatic->element).")";
446 $sql .= " AND cf.fk_statut = ".CommandeFournisseur::STATUS_DRAFT;
447 $sql .= " AND cf.fk_soc = s.rowid";
448 if (!$user->hasRight('societe', 'client', 'voir')) {
449 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
450 }
451 if ($socid) {
452 $sql .= " AND cf.fk_soc = ".((int) $socid);
453 }
454
455 $resql = $db->query($sql);
456 if ($resql) {
457 $total = 0;
458 $num = $db->num_rows($resql);
459 $nbofloop = min($num, $maxofloop);
460 startSimpleTable("DraftSuppliersOrders", "fourn/commande/list.php", "search_status=".CommandeFournisseur::STATUS_DRAFT, 2, $num);
461
462 if ($num > 0) {
463 $i = 0;
464 $othernb = 0;
465
466 while ($i < $nbofloop) {
467 $obj = $db->fetch_object($resql);
468
469 if ($i >= $max) {
470 $othernb += 1;
471 $i++;
472 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
473 continue;
474 }
475
476 $supplierorderstatic->id = $obj->rowid;
477 $supplierorderstatic->ref = $obj->ref;
478 $supplierorderstatic->ref_supplier = $obj->ref_supplier;
479 $supplierorderstatic->total_ht = $obj->total_ht;
480 $supplierorderstatic->total_tva = $obj->total_tva;
481 $supplierorderstatic->total_ttc = $obj->total_ttc;
482 $supplierorderstatic->statut = $obj->status;
483
484 $companystatic->id = $obj->socid;
485 $companystatic->name = $obj->name;
486 $companystatic->name_alias = $obj->name_alias;
487 $companystatic->code_client = $obj->code_client;
488 $companystatic->code_compta = $obj->code_compta;
489 $companystatic->code_compta_client = $obj->code_compta;
490 $companystatic->client = $obj->client;
491 $companystatic->code_fournisseur = $obj->code_fournisseur;
492 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
493 $companystatic->fournisseur = $obj->fournisseur;
494 $companystatic->logo = $obj->logo;
495 $companystatic->email = $obj->email;
496 $companystatic->entity = $obj->entity;
497 $companystatic->canvas = $obj->canvas;
498
499 print '<tr class="oddeven">';
500 print '<td class="nowraponall tdoverflowmax125">'.$supplierorderstatic->getNomUrl(1).'</td>';
501 print '<td class="nowrap tdoverflowmax100">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
502 print '<td class="nowrap right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
503 print '</tr>';
504
505 $i++;
506 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
507 }
508
509 if ($othernb) {
510 print '<tr class="oddeven">';
511 print '<td class="nowrap" colspan="5">';
512 print '<span class="opacitymedium">'.$langs->trans("More").'...'.($othernb < $maxofloop ? ' ('.$othernb.')' : '').'</span>';
513 print '</td>';
514 print "</tr>\n";
515 }
516 }
517
518 addSummaryTableLine(3, $num, $nbofloop, $total, "NoOrder");
519 finishSimpleTable(true);
520
521 $db->free($resql);
522 } else {
523 dol_print_error($db);
524 }
525}
526
527
528/*
529 * Draft interventions
530 */
531if (isModEnabled('intervention')) {
532 $sql = "SELECT f.rowid, f.ref, s.nom as name, f.fk_statut, f.duree as duration";
533 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
534 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
535 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
536 $sql .= ", s.logo, s.email, s.entity";
537 $sql .= ", s.canvas";
538 $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
539 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
540 if (!$user->hasRight('societe', 'client', 'voir')) {
541 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
542 }
543 $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
544 $sql .= " AND f.fk_soc = s.rowid";
545 $sql .= " AND f.fk_statut = 0";
546 if ($socid) {
547 $sql .= " AND f.fk_soc = ".((int) $socid);
548 }
549 if (!$user->hasRight('societe', 'client', 'voir')) {
550 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
551 }
552
553
554 $resql = $db->query($sql);
555 if ($resql) {
556 $num = $db->num_rows($resql);
557 $nbofloop = min($num, $maxofloop);
558 startSimpleTable("DraftFichinter", "fichinter/list.php", "search_status=".Fichinter::STATUS_DRAFT, 2, $num);
559
560 //print '<tr class="liste_titre">';
561 //print '<th colspan="2">'.$langs->trans("DraftFichinter").'</th></tr>';
562
563 if ($num > 0) {
564 $i = 0;
565 while ($i < $nbofloop) {
566 $obj = $db->fetch_object($resql);
567
568 $fichinterstatic->id=$obj->rowid;
569 $fichinterstatic->ref=$obj->ref;
570 $fichinterstatic->statut=$obj->fk_statut;
571
572 $companystatic->id = $obj->socid;
573 $companystatic->name = $obj->name;
574 $companystatic->name_alias = $obj->name_alias;
575 $companystatic->code_client = $obj->code_client;
576 $companystatic->code_compta = $obj->code_compta_client;
577 $companystatic->code_compta_client = $obj->code_compta_client;
578 $companystatic->client = $obj->client;
579 $companystatic->code_fournisseur = $obj->code_fournisseur;
580 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
581 $companystatic->fournisseur = $obj->fournisseur;
582 $companystatic->logo = $obj->logo;
583 $companystatic->email = $obj->email;
584 $companystatic->entity = $obj->entity;
585 $companystatic->canvas = $obj->canvas;
586
587 print '<tr class="oddeven">';
588 print '<td class="tdoverflowmax125">';
589 print $fichinterstatic->getNomUrl(1);
590 print "</td>";
591 print '<td class="tdoverflowmax100">';
592 print $companystatic->getNomUrl(1, 'customer');
593 print '</td>';
594 print '<td class="nowraponall tdoverflowmax100 right">';
595 print convertSecondToTime($obj->duration);
596 print '</td>';
597 print '</tr>';
598 $i++;
599 }
600 }
601
602 addSummaryTableLine(3, $num, $nbofloop, $total, "NoIntervention");
603 finishSimpleTable(true);
604
605 $db->free($resql);
606 }
607}
608
609
610print '</div><div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
611
612
613/*
614 * Last modified customers or prospects
615 */
616if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) {
617 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
618 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
619 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
620 $sql .= ", s.logo, s.email, s.entity";
621 $sql .= ", s.canvas";
622 $sql .= ", s.datec, s.tms";
623 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
624 if (!$user->hasRight('societe', 'client', 'voir')) {
625 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
626 }
627 $sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
628 $sql .= " AND s.client IN (".Societe::CUSTOMER.", ".Societe::PROSPECT.", ".Societe::CUSTOMER_AND_PROSPECT.")";
629 if (!$user->hasRight('societe', 'client', 'voir')) {
630 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
631 }
632 // Add where from hooks
633 $parameters = array('socid' => $socid);
634 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $companystatic); // Note that $action and $object may have been modified by hook
635 if (empty($reshook)) {
636 if ($socid > 0) {
637 $sql .= " AND s.rowid = ".((int) $socid);
638 }
639 }
640 $sql .= $hookmanager->resPrint;
641 $sql .= " ORDER BY s.tms DESC";
642 $sql .= $db->plimit($max, 0);
643
644 $resql = $db->query($sql);
645 if ($resql) {
646 if (!getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
647 $header = "BoxTitleLastCustomersOrProspects";
648 } elseif (getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
649 $header = "BoxTitleLastModifiedProspects";
650 } else {
651 $header = "BoxTitleLastModifiedCustomers";
652 }
653
654 $num = $db->num_rows($resql);
655 startSimpleTable($langs->trans($header, min($max, $num)), "societe/list.php", "type=p,c&sortfield=s.tms&sortorder=DESC", 1, -1, 'company');
656
657 if ($num) {
658 $i = 0;
659
660 while ($i < $num && $i < $max) {
661 $objp = $db->fetch_object($resql);
662
663 $companystatic->id = $objp->socid;
664 $companystatic->name = $objp->name;
665 $companystatic->name_alias = $objp->name_alias;
666 $companystatic->code_client = $objp->code_client;
667 $companystatic->code_compta = $objp->code_compta_client;
668 $companystatic->code_compta_client = $objp->code_compta_client;
669 $companystatic->client = $objp->client;
670 $companystatic->code_fournisseur = $objp->code_fournisseur;
671 $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
672 $companystatic->fournisseur = $objp->fournisseur;
673 $companystatic->logo = $objp->logo;
674 $companystatic->email = $objp->email;
675 $companystatic->entity = $objp->entity;
676 $companystatic->canvas = $objp->canvas;
677
678 print '<tr class="oddeven">';
679 print '<td class="nowraponall tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
680 print '<td class="nowrap">';
681 //print $companystatic->getLibCustProspStatut();
682
683 $obj = $companystatic;
684 $s = '';
685 if (($obj->client == 2 || $obj->client == 3) && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS')) {
686 $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>';
687 }
688 if (($obj->client == 1 || $obj->client == 3) && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS')) {
689 $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>';
690 }
691 /*
692 if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $obj->fournisseur)
693 {
694 $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>';
695 }*/
696 print $s;
697
698 print '</td>';
699
700 $datem = $db->jdate($objp->tms);
701 print '<td class="right nowrap tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
702 print dol_print_date($datem, 'day', 'tzuserrel');
703 print '</td>';
704 print '</tr>';
705
706 $i++;
707 }
708 }
709
710 addSummaryTableLine(3, $num);
711 finishSimpleTable(true);
712
713 $db->free($resql);
714 } else {
715 dol_print_error($db);
716 }
717}
718
719
720/*
721 * Last modified proposals
722 */
723
724if (isModEnabled('propal')) {
725 $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, c.tms as datem,";
726 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta as code_compta_client";
727 $sql .= " FROM ".MAIN_DB_PREFIX."propal as c,";
728 $sql .= " ".MAIN_DB_PREFIX."societe as s";
729 $sql .= " WHERE c.entity IN (".getEntity($propalstatic->element).")";
730 $sql .= " AND c.fk_soc = s.rowid";
731 // If the internal user must only see his customers, force searching by him
732 $search_sale = 0;
733 if (!$user->hasRight('societe', 'client', 'voir')) {
734 $search_sale = $user->id;
735 }
736 // Search on sale representative
737 if ($search_sale && $search_sale != '-1') {
738 if ($search_sale == -2) {
739 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
740 } elseif ($search_sale > 0) {
741 $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).")";
742 }
743 }
744 // Search on socid
745 if ($socid) {
746 $sql .= " AND c.fk_soc = ".((int) $socid);
747 }
748 $sql .= " ORDER BY c.tms DESC";
749
750 $sql .= $db->plimit($max, 0);
751
752 $resql = $db->query($sql);
753 if ($resql) {
754 $num = $db->num_rows($resql);
755
756 startSimpleTable($langs->trans("LastModifiedProposals", $max), "comm/propal/list.php", "sortfield=p.tms&sortorder=DESC", 2, -1, 'propal');
757
758 if ($num) {
759 $i = 0;
760 while ($i < $num) {
761 $obj = $db->fetch_object($resql);
762
763 $propalstatic->id = $obj->rowid;
764 $propalstatic->ref = $obj->ref;
765 $propalstatic->status = $obj->status;
766
767 $companystatic->id = $obj->socid;
768 $companystatic->name = $obj->socname;
769 $companystatic->client = $obj->client;
770 $companystatic->canvas = $obj->canvas;
771 $companystatic->email = $obj->email;
772 $companystatic->code_compta = $obj->code_compta_client;
773 $companystatic->code_compta_client = $obj->code_compta_client;
774
775 $filename = dol_sanitizeFileName($obj->ref);
776 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
777 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
778
779 print '<tr class="oddeven">';
780
781 print '<td class="nowrap">';
782 print '<table class="nobordernopadding">';
783 print '<tr class="nocellnopadd">';
784 print '<td width="96" class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
785 print '<td width="16" class="nobordernopadding nowrap"></td>';
786 print '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
787 print '</tr>';
788 print '</table>';
789 print '</td>';
790
791 print '<td class="tdoverflowmax100">'.$companystatic->getNomUrl(1, 'customer').'</td>';
792
793 $datem = $db->jdate($obj->datem);
794 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
795 print dol_print_date($datem, 'day', 'tzuserrel');
796 print '</td>';
797
798 print '<td class="right">'.$propalstatic->LibStatut($obj->status, 3).'</td>';
799
800 print '</tr>';
801
802 $i++;
803 }
804 }
805
806 finishSimpleTable(true);
807 $db->free($resql);
808 } else {
809 dol_print_error($db);
810 }
811}
812
813
814/*
815 * Latest modified orders
816 */
817
818if (isModEnabled('order')) {
819 $commandestatic = new Commande($db);
820
821 $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, c.facture, c.date_cloture as datec, c.tms as datem,";
822 $sql .= " s.nom as name, s.rowid as socid";
823 $sql .= ", s.client";
824 $sql .= ", s.code_client";
825 $sql .= ", s.canvas";
826 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
827 $sql .= " ".MAIN_DB_PREFIX."societe as s";
828 if (!$user->hasRight('societe', 'client', 'voir')) {
829 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
830 }
831 $sql .= " WHERE c.fk_soc = s.rowid";
832 $sql .= " AND c.entity IN (".getEntity('commande').")";
833 //$sql.= " AND c.fk_statut > 2";
834 if ($socid) {
835 $sql .= " AND c.fk_soc = ".((int) $socid);
836 }
837 if (!$user->hasRight('societe', 'client', 'voir')) {
838 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
839 }
840 $sql .= " ORDER BY c.tms DESC";
841 $sql .= $db->plimit($max, 0);
842
843 $resql = $db->query($sql);
844 if ($resql) {
845 $num = $db->num_rows($resql);
846
847 startSimpleTable($langs->trans("LastModifiedOrders", $max), "commande/list.php", "sortfield=c.tms&sortorder=DESC", 2, -1, 'order');
848
849 if ($num) {
850 $i = 0;
851 while ($i < $num) {
852 $obj = $db->fetch_object($resql);
853
854 print '<tr class="oddeven">';
855 print '<td width="20%" class="nowrap">';
856
857 $commandestatic->id = $obj->rowid;
858 $commandestatic->ref = $obj->ref;
859
860 $companystatic->id = $obj->socid;
861 $companystatic->name = $obj->name;
862 $companystatic->client = $obj->client;
863 $companystatic->code_client = $obj->code_client;
864 $companystatic->canvas = $obj->canvas;
865
866 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
867 print '<td width="96" class="nobordernopadding nowrap">';
868 print $commandestatic->getNomUrl(1);
869 print '</td>';
870
871 print '<td width="16" class="nobordernopadding nowrap">';
872 print '&nbsp;';
873 print '</td>';
874
875 print '<td width="16" class="nobordernopadding hideonsmartphone right">';
876 $filename = dol_sanitizeFileName($obj->ref);
877 $filedir = $conf->commande->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
878 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
879 print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
880 print '</td></tr></table>';
881
882 print '</td>';
883
884 print '<td class="nowrap">';
885 print $companystatic->getNomUrl(1, 'company', 16);
886 print '</td>';
887
888 $datem = $db->jdate($obj->datem);
889 print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
890 print dol_print_date($datem, 'day', 'tzuserrel');
891 print '</td>';
892
893 print '<td class="right">'.$commandestatic->LibStatut($obj->status, $obj->facture, 3).'</td>';
894 print '</tr>';
895 $i++;
896 }
897 }
898 finishSimpleTable(true);
899 } else {
900 dol_print_error($db);
901 }
902}
903
904
905/*
906 * Last suppliers
907 */
908if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $user->hasRight('societe', 'lire')) {
909 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
910 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
911 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
912 $sql .= ", s.logo, s.email, s.entity";
913 $sql .= ", s.canvas";
914 $sql .= ", s.datec as dc, s.tms as dm";
915 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
916 if (!$user->hasRight('societe', 'client', 'voir')) {
917 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
918 }
919 $sql .= " WHERE s.entity IN (".getEntity($companystatic->element).")";
920 $sql .= " AND s.fournisseur = ".Societe::SUPPLIER;
921 if (!$user->hasRight('societe', 'client', 'voir')) {
922 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
923 }
924 // Add where from hooks
925 $parameters = array('socid' => $socid);
926 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $companystatic); // Note that $action and $object may have been modified by hook
927 if (empty($reshook)) {
928 if ($socid > 0) {
929 $sql .= " AND s.rowid = ".((int) $socid);
930 }
931 }
932 $sql .= $hookmanager->resPrint;
933 $sql .= " ORDER BY s.datec DESC";
934 $sql .= $db->plimit($max, 0);
935
936 $resql = $db->query($sql);
937 if ($resql) {
938 $num = $db->num_rows($resql);
939 startSimpleTable($langs->trans("BoxTitleLastModifiedSuppliers", min($max, $num)), "societe/list.php", "type=f", 1, -1, 'company');
940
941 if ($num) {
942 $i = 0;
943 while ($i < $num && $i < $max) {
944 $objp = $db->fetch_object($resql);
945
946 $companystatic->id = $objp->socid;
947 $companystatic->name = $objp->name;
948 $companystatic->name_alias = $objp->name_alias;
949 $companystatic->code_client = $objp->code_client;
950 $companystatic->code_compta = $objp->code_compta_client;
951 $companystatic->code_compta_client = $objp->code_compta_client;
952 $companystatic->client = $objp->client;
953 $companystatic->code_fournisseur = $objp->code_fournisseur;
954 $companystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
955 $companystatic->fournisseur = $objp->fournisseur;
956 $companystatic->logo = $objp->logo;
957 $companystatic->email = $objp->email;
958 $companystatic->entity = $objp->entity;
959 $companystatic->canvas = $objp->canvas;
960
961 print '<tr class="oddeven">';
962 print '<td class="nowraponall tdoverflowmax100">'.$companystatic->getNomUrl(1, 'supplier').'</td>';
963 print '<td>';
964
965 $obj = $companystatic;
966 $s = '';
967 /*if (($obj->client == 2 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
968 $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>';
969 }
970 if (($obj->client == 1 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
971 {
972 $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>';
973 }*/
974 if ((isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) && $obj->fournisseur) {
975 $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>';
976 }
977 print $s;
978
979 print '</td>';
980
981 $datem = $db->jdate($objp->dm);
982 print '<td class="right tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
983 print dol_print_date($datem, 'day', 'tzuserrel');
984 print '</td>';
985 print '</tr>';
986
987 $i++;
988 }
989 }
990
991 addSummaryTableLine(3, $num);
992 finishSimpleTable(true);
993
994 $db->free($resql);
995 } else {
996 dol_print_error($db);
997 }
998}
999
1000
1001/*
1002 * Last actions
1003 */
1004/*if ($user->hasRight('agenda', 'myactions', 'read')) {
1005 show_array_last_actions_done($max);
1006}*/
1007
1008
1009/*
1010 * Actions to do
1011 */
1012/*if ($user->hasRight('agenda', 'myactions', 'read')) {
1013 show_array_actions_to_do($max);
1014}*/
1015
1016
1017/*
1018 * Latest contracts
1019 */
1020if (isModEnabled('contract') && $user->hasRight("contrat", "lire") && 0) { // TODO A REFAIRE DEPUIS NOUVEAU CONTRAT
1021 $staticcontrat = new Contrat($db);
1022
1023 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
1024 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
1025 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
1026 $sql .= ", s.logo, s.email, s.entity";
1027 $sql .= ", s.canvas";
1028 $sql .= ", c.statut, c.rowid as contratid, p.ref, c.fin_validite as datefin, c.date_cloture as dateclo";
1029 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
1030 $sql .= ", ".MAIN_DB_PREFIX."contrat as c";
1031 $sql .= ", ".MAIN_DB_PREFIX."product as p";
1032 if (!$user->hasRight('societe', 'client', 'voir')) {
1033 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1034 }
1035 $sql .= " WHERE c.entity IN (".getEntity($staticcontrat->element).")";
1036 $sql .= " AND c.fk_soc = s.rowid";
1037 $sql .= " AND c.fk_product = p.rowid";
1038 if (!$user->hasRight('societe', 'client', 'voir')) {
1039 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1040 }
1041 if ($socid) {
1042 $sql .= " AND s.rowid = ".((int) $socid);
1043 }
1044 $sql .= " ORDER BY c.tms DESC";
1045 $sql .= $db->plimit($max + 1, 0);
1046
1047 $resql = $db->query($sql);
1048 if ($resql) {
1049 $num = $db->num_rows($resql);
1050 startSimpleTable($langs->trans("LastContracts", $max), "", "", 2);
1051
1052 if ($num > 0) {
1053 $i = 0;
1054
1055 while ($i < $num) {
1056 $obj = $db->fetch_object($resql);
1057
1058 $companystatic->id = $obj->socid;
1059 $companystatic->name = $obj->name;
1060 $companystatic->name_alias = $obj->name_alias;
1061 $companystatic->code_client = $obj->code_client;
1062 $companystatic->code_compta = $obj->code_compta_client;
1063 $companystatic->code_compta_client = $obj->code_compta_client;
1064 $companystatic->client = $obj->client;
1065 $companystatic->code_fournisseur = $obj->code_fournisseur;
1066 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1067 $companystatic->fournisseur = $obj->fournisseur;
1068 $companystatic->logo = $obj->logo;
1069 $companystatic->email = $obj->email;
1070 $companystatic->entity = $obj->entity;
1071 $companystatic->canvas = $obj->canvas;
1072
1073 $staticcontrat->id = $obj->contratid;
1074 $staticcontrat->ref = $obj->ref;
1075
1076 print '<tr class="oddeven">';
1077 print '<td class="nowraponall">'.$staticcontrat->getNomUrl(1).'</td>';
1078 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
1079 print '<td class="right">'.$staticcontrat->LibStatut($obj->statut, 3).'</td>';
1080 print '</tr>';
1081
1082 $i++;
1083 }
1084 }
1085
1086 addSummaryTableLine(2, $num);
1087 finishSimpleTable(true);
1088
1089 $db->free($resql);
1090 } else {
1091 dol_print_error($db);
1092 }
1093}
1094
1095
1096/*
1097 * Opened (validated) proposals
1098 */
1099if (isModEnabled("propal") && $user->hasRight("propal", "lire")) {
1100 $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";
1101 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
1102 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
1103 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
1104 $sql .= ", s.logo, s.email, s.entity";
1105 $sql .= ", s.canvas";
1106 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
1107 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
1108 if (!$user->hasRight('societe', 'client', 'voir')) {
1109 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1110 }
1111 $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
1112 $sql .= " AND p.fk_soc = s.rowid";
1113 $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
1114 if (!$user->hasRight('societe', 'client', 'voir')) {
1115 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1116 }
1117 if ($socid) {
1118 $sql .= " AND s.rowid = ".((int) $socid);
1119 }
1120 $sql .= " ORDER BY p.rowid DESC";
1121
1122 $resql = $db->query($sql);
1123 if ($resql) {
1124 $total = $total_ttc = 0;
1125 $num = $db->num_rows($resql);
1126 $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
1127 startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=1", 4, $num);
1128
1129 if ($num > 0) {
1130 $i = 0;
1131 $othernb = 0;
1132
1133 while ($i < $nbofloop) {
1134 $obj = $db->fetch_object($resql);
1135
1136 if ($i >= $max) {
1137 $othernb += 1;
1138 $i++;
1139 $total += $obj->total_ht;
1140 $total_ttc += $obj->total_ttc;
1141 continue;
1142 }
1143
1144 $propalstatic->id = $obj->propalid;
1145 $propalstatic->ref = $obj->ref;
1146 $propalstatic->ref_client = $obj->ref_client;
1147 $propalstatic->total_ht = $obj->total_ht;
1148 $propalstatic->total_tva = $obj->total_tva;
1149 $propalstatic->total_ttc = $obj->total_ttc;
1150
1151 $companystatic->id = $obj->socid;
1152 $companystatic->name = $obj->name;
1153 $companystatic->name_alias = $obj->name_alias;
1154 $companystatic->code_client = $obj->code_client;
1155 $companystatic->code_compta = $obj->code_compta_client;
1156 $companystatic->code_compta_client = $obj->code_compta_client;
1157 $companystatic->client = $obj->client;
1158 $companystatic->code_fournisseur = $obj->code_fournisseur;
1159 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1160 $companystatic->fournisseur = $obj->fournisseur;
1161 $companystatic->logo = $obj->logo;
1162 $companystatic->email = $obj->email;
1163 $companystatic->entity = $obj->entity;
1164 $companystatic->canvas = $obj->canvas;
1165
1166 $filename = dol_sanitizeFileName($obj->ref);
1167 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
1168 //$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
1169 $warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
1170
1171 print '<tr class="oddeven">';
1172
1173 print '<td class="nowrap" width="140">';
1174 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1175 print '<td class="nobordernopadding nowraponall">'.$propalstatic->getNomUrl(1).'</td>';
1176 print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
1177 print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
1178 print '</tr>';
1179 print '</table>';
1180 print '</td>';
1181
1182 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
1183 $datem = $db->jdate($obj->dp);
1184 print '<td class="center tddate" title="'.dol_escape_htmltag($langs->trans("Date").': '.dol_print_date($datem, 'day', 'tzserver')).'">';
1185 print dol_print_date($datem, 'day', 'tzserver');
1186 print '</td>';
1187 print '<td class="right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
1188 print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
1189
1190 print '</tr>';
1191
1192 $i++;
1193 $total += $obj->total_ht;
1194 $total_ttc += $obj->total_ttc;
1195 }
1196
1197 if ($othernb) {
1198 print '<tr class="oddeven">';
1199 print '<td class="nowrap" colspan="5">';
1200 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1201 print '</td>';
1202 print "</tr>\n";
1203 }
1204 }
1205
1206 addSummaryTableLine(5, $num, $nbofloop, !getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $total_ttc : $total, "NoProposal", true);
1207 finishSimpleTable(true);
1208
1209 $db->free($resql);
1210 } else {
1211 dol_print_error($db);
1212 }
1213}
1214
1215
1216/*
1217 * Opened (validated) order
1218 */
1219if (isModEnabled('order') && $user->hasRight('commande', 'lire')) {
1220 $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";
1221 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
1222 $sql .= ", s.code_client, s.code_compta as code_compta_client, s.client";
1223 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
1224 $sql .= ", s.logo, s.email, s.entity";
1225 $sql .= ", s.canvas";
1226 $sql .= " FROM ".MAIN_DB_PREFIX."commande as c";
1227 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
1228 if (!$user->hasRight('societe', 'client', 'voir')) {
1229 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
1230 }
1231 $sql .= " WHERE c.entity IN (".getEntity($orderstatic->element).")";
1232 $sql .= " AND c.fk_soc = s.rowid";
1233 $sql .= " AND c.fk_statut IN (".Commande::STATUS_VALIDATED.", ".Commande::STATUS_SHIPMENTONPROCESS.")";
1234 if (!$user->hasRight('societe', 'client', 'voir')) {
1235 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
1236 }
1237 if ($socid) {
1238 $sql .= " AND s.rowid = ".((int) $socid);
1239 }
1240 $sql .= " ORDER BY c.rowid DESC";
1241
1242 $resql = $db->query($sql);
1243 if ($resql) {
1244 $total = $total_ttc = 0;
1245 $num = $db->num_rows($resql);
1246 $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
1247 startSimpleTable("OrdersOpened", "commande/list.php", "search_status=".Commande::STATUS_VALIDATED, 4, $num);
1248
1249 if ($num > 0) {
1250 $i = 0;
1251 $othernb = 0;
1252
1253 while ($i < $nbofloop) {
1254 $obj = $db->fetch_object($resql);
1255
1256 if ($i >= $max) {
1257 $othernb += 1;
1258 $i++;
1259 $total += $obj->total_ht;
1260 $total_ttc += $obj->total_ttc;
1261 continue;
1262 }
1263
1264 $orderstatic->id = $obj->commandeid;
1265 $orderstatic->ref = $obj->ref;
1266 $orderstatic->ref_client = $obj->ref_client;
1267 $orderstatic->statut = $obj->fk_statut;
1268 $orderstatic->total_ht = $obj->total_ht;
1269 $orderstatic->total_tva = $obj->total_tva;
1270 $orderstatic->total_ttc = $obj->total_ttc;
1271
1272 $companystatic->id = $obj->socid;
1273 $companystatic->name = $obj->name;
1274 $companystatic->name_alias = $obj->name_alias;
1275 $companystatic->code_client = $obj->code_client;
1276 $companystatic->code_compta = $obj->code_compta_client;
1277 $companystatic->code_compta_client = $obj->code_compta_client;
1278 $companystatic->client = $obj->client;
1279 $companystatic->code_fournisseur = $obj->code_fournisseur;
1280 $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1281 $companystatic->fournisseur = $obj->fournisseur;
1282 $companystatic->logo = $obj->logo;
1283 $companystatic->email = $obj->email;
1284 $companystatic->entity = $obj->entity;
1285 $companystatic->canvas = $obj->canvas;
1286
1287 $filename = dol_sanitizeFileName($obj->ref);
1288 $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1289 //$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
1290 //$warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
1291
1292 print '<tr class="oddeven">';
1293
1294 print '<td class="nowrap" width="140">';
1295 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1296 print '<td class="nobordernopadding nowraponall">'.$orderstatic->getNomUrl(1).'</td>';
1297 print '<td width="18" class="nobordernopadding nowrap"></td>';
1298 print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($orderstatic->element, $filename, $filedir).'</td>';
1299 print '</tr>';
1300 print '</table>';
1301 print '</td>';
1302
1303 print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer').'</td>';
1304 $datem = $db->jdate($obj->dv);
1305 print '<td class="center tddate" title="'.dol_escape_htmltag($langs->trans("DateValue").': '.dol_print_date($datem, 'day', 'tzserver')).'">';
1306 print dol_print_date($datem, 'day', 'tzserver');
1307 print '</td>';
1308
1309 print '<td class="right tdamount amount">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
1310 print '<td align="center" width="14">'.$orderstatic->LibStatut($obj->fk_statut, $obj->billed, 3).'</td>';
1311
1312 print '</tr>';
1313
1314 $i++;
1315 $total += $obj->total_ht;
1316 $total_ttc += $obj->total_ttc;
1317 }
1318
1319 if ($othernb) {
1320 print '<tr class="oddeven">';
1321 print '<td class="nowrap" colspan="5">';
1322 print '<span class="opacitymedium">'.$langs->trans("More").'... ('.$othernb.')</span>';
1323 print '</td>';
1324 print "</tr>\n";
1325 }
1326 }
1327
1328 addSummaryTableLine(5, $num, $nbofloop, !getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $total_ttc : $total, "None", true);
1329 finishSimpleTable(true);
1330
1331 $db->free($resql);
1332 } else {
1333 dol_print_error($db);
1334 }
1335}
1336
1337print '</div>';
1338print '</div>';
1339print '</div>';
1340
1341$parameters = array('user' => $user);
1342$reshook = $hookmanager->executeHooks('dashboardCommercials', $parameters, $object); // Note that $action and $object may have been modified by hook
1343
1344// End of page
1345llxFooter();
1346$db->close();
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:70
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:241
llxFooter()
Footer empty.
Definition document.php:107
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 a 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.