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