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