dolibarr 19.0.3
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
6 * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
33
34// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
35$hookmanager = new HookManager($db);
36$hookmanager->initHooks(array('proposalindex'));
37
38// Load translation files required by the page
39$langs->loadLangs(array('propal', 'companies'));
40
41$now = dol_now();
42$max = 5;
43
44// Security check
45$socid = GETPOST('socid', 'int');
46if (isset($user->socid) && $user->socid > 0) {
47 $action = '';
48 $socid = $user->socid;
49}
50
51restrictedArea($user, 'propal');
52
53
54/*
55 * View
56 */
57
58$propalstatic = new Propal($db);
59$companystatic = new Societe($db);
60$form = new Form($db);
61$formfile = new FormFile($db);
62$help_url = "EN:Module_Commercial_Proposals|FR:Module_Propositions_commerciales|ES:Módulo_Presupuestos";
63
64llxHeader("", $langs->trans("ProspectionArea"), $help_url);
65
66print load_fiche_titre($langs->trans("ProspectionArea"), '', 'propal');
67
68print '<div class="fichecenter">';
69print '<div class="fichethirdleft">';
70
71$tmp = getCustomerProposalPieChart($socid);
72if ($tmp) {
73 print $tmp;
74 print '<br>';
75}
76
77/*
78 * Draft proposals
79 */
80if (isModEnabled("propal")) {
81 $sql = "SELECT p.rowid, p.ref, p.ref_client, p.total_ht, p.total_tva, p.total_ttc";
82 $sql .= ", s.rowid as socid, s.nom as name, s.client, s.canvas, s.code_client, s.code_fournisseur, s.email, s.entity, s.code_compta";
83 $sql .= " FROM ".MAIN_DB_PREFIX."propal as p";
84 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
85 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
86 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
87 }
88 $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
89 $sql .= " AND p.fk_soc = s.rowid";
90 $sql .= " AND p.fk_statut =".Propal::STATUS_DRAFT;
91 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
92 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
93 }
94 if ($socid) {
95 $sql .= " AND p.fk_soc = ".((int) $socid);
96 }
97
98 $resql = $db->query($sql);
99 if ($resql) {
100 $num = $db->num_rows($resql);
101 $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
102 startSimpleTable("DraftPropals", "comm/propal/list.php", "search_status=".Propal::STATUS_DRAFT, 2, $num);
103
104 $total = 0;
105 if ($num) {
106 $i = 0;
107
108 while ($i < $nbofloop) {
109 $obj = $db->fetch_object($resql);
110
111 $propalstatic->id = $obj->rowid;
112 $propalstatic->ref = $obj->ref;
113 $propalstatic->ref_client = $obj->ref_client;
114 $propalstatic->total_ht = $obj->total_ht;
115 $propalstatic->total_tva = $obj->total_tva;
116 $propalstatic->total_ttc = $obj->total_ttc;
117
118 $companystatic->id = $obj->socid;
119 $companystatic->name = $obj->name;
120 $companystatic->client = $obj->client;
121 $companystatic->code_client = $obj->code_client;
122 $companystatic->code_fournisseur = $obj->code_fournisseur;
123 $companystatic->canvas = $obj->canvas;
124 $companystatic->entity = $obj->entity;
125 $companystatic->email = $obj->email;
126 $companystatic->code_compta = $obj->code_compta;
127
128 print '<tr class="oddeven">';
129 print '<td class="nowrap">'.$propalstatic->getNomUrl(1).'</td>';
130 print '<td class="nowrap">'.$companystatic->getNomUrl(1, 'customer', 16).'</td>';
131 print '<td class="nowrap right">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
132 print '</tr>';
133
134 $i++;
135 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
136 }
137 }
138
139 addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
140 finishSimpleTable(true);
141 $db->free($resql);
142 } else {
143 dol_print_error($db);
144 }
145}
146
147print '</div>';
148
149print '<div class="fichetwothirdright">';
150
151/*
152 * Last modified proposals
153 */
154
155$sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, date_cloture as datec";
156$sql .= ", s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta";
157$sql .= " FROM ".MAIN_DB_PREFIX."propal as c";
158$sql .= ", ".MAIN_DB_PREFIX."societe as s";
159if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
160 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
161}
162$sql .= " WHERE c.entity IN (".getEntity($propalstatic->element).")";
163$sql .= " AND c.fk_soc = s.rowid";
164//$sql.= " AND c.fk_statut > 2";
165if ($socid) {
166 $sql .= " AND c.fk_soc = ".((int) $socid);
167}
168if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
169 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
170}
171$sql .= " ORDER BY c.tms DESC";
172$sql .= $db->plimit($max, 0);
173
174$resql = $db->query($sql);
175if ($resql) {
176 $num = $db->num_rows($resql);
177 startSimpleTable($langs->trans("LastModifiedProposals", $max), "", "", 3);
178
179 if ($num) {
180 $i = 0;
181 while ($i < $num) {
182 $obj = $db->fetch_object($resql);
183
184 $propalstatic->id = $obj->rowid;
185 $propalstatic->ref = $obj->ref;
186
187 $companystatic->id = $obj->socid;
188 $companystatic->name = $obj->socname;
189 $companystatic->client = $obj->client;
190 $companystatic->canvas = $obj->canvas;
191 $companystatic->email = $obj->email;
192 $companystatic->code_compta = $obj->code_compta;
193
194 $filename = dol_sanitizeFileName($obj->ref);
195 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
196 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
197
198 print '<tr class="oddeven">';
199
200 print '<td width="20%" class="nowrap">';
201 print '<table class="nobordernopadding">';
202 print '<tr class="nocellnopadd">';
203 print '<td width="96" class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
204 print '<td width="16" class="nobordernopadding nowrap"></td>';
205 print '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
206 print '</tr>';
207 print '</table>';
208 print '</td>';
209
210 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
211 print '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
212 print '<td class="right">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
213
214 print '</tr>';
215
216 $i++;
217 }
218 }
219
220 finishSimpleTable(true);
221 $db->free($resql);
222} else {
223 dol_print_error($db);
224}
225
226
227/*
228 * Open (validated) proposals
229 */
230if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
231 $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta";
232 $sql .= ", p.rowid as propalid, p.entity, p.total_ttc, p.total_ht, p.ref, p.fk_statut, p.datep as dp, p.fin_validite as dfv";
233 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
234 $sql .= ", ".MAIN_DB_PREFIX."propal as p";
235 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
236 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
237 }
238 $sql .= " WHERE p.fk_soc = s.rowid";
239 $sql .= " AND p.entity IN (".getEntity($propalstatic->element).")";
240 $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
241 if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
242 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
243 }
244 if ($socid) {
245 $sql .= " AND s.rowid = ".((int) $socid);
246 }
247 $sql .= " ORDER BY p.rowid DESC";
248
249 $resql = $db->query($sql);
250 if ($resql) {
251 $total = 0;
252 $num = $db->num_rows($resql);
253 $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
254 startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=".Propal::STATUS_VALIDATED, 4, $num);
255
256 if ($num > 0) {
257 $i = 0;
258 while ($i < $nbofloop) {
259 $obj = $db->fetch_object($resql);
260
261 $propalstatic->id = $obj->propalid;
262 $propalstatic->ref = $obj->ref;
263
264 $companystatic->id = $obj->socid;
265 $companystatic->name = $obj->socname;
266 $companystatic->client = $obj->client;
267 $companystatic->canvas = $obj->canvas;
268 $companystatic->email = $obj->email;
269 $companystatic->code_compta = $obj->code_compta;
270
271 $filename = dol_sanitizeFileName($obj->ref);
272 $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
273 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
274
275 $warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
276
277 print '<tr class="oddeven">';
278
279 // Ref
280 print '<td class="nowrap" width="140">';
281 print '<table class="nobordernopadding">';
282 print '<tr class="nocellnopadd">';
283 print '<td class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
284 print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
285 print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
286 print '</tr>';
287 print '</table>';
288 print '</td>';
289
290 print '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>';
291 print '<td class="right">'.dol_print_date($db->jdate($obj->dp), 'day').'</td>';
292 print '<td class="right">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
293 print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
294
295 print '</tr>';
296
297 $i++;
298 $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
299 }
300 }
301
302 addSummaryTableLine(5, $num, $nbofloop, $total, "None", true);
303 finishSimpleTable(true);
304 $db->free($resql);
305 } else {
306 dol_print_error($db);
307 }
308}
309
310/*
311 * Proposals to process
312 */
313
314/*
315if (isModEnabled('propal'))
316{
317 $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as name, s.rowid as socid";
318 $sql.=" FROM ".MAIN_DB_PREFIX."propal as c";
319 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
320 if (empty($user->rights->societe->client->voir) && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
321 $sql.= " WHERE c.fk_soc = s.rowid";
322 $sql.= " AND c.entity = ".$conf->entity;
323 $sql.= " AND c.fk_statut = 1";
324 if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
325 if (empty($user->rights->societe->client->voir) && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
326 $sql.= " ORDER BY c.rowid DESC";
327
328 $resql=$db->query($sql);
329 if ($resql)
330 {
331 $num = $db->num_rows($resql);
332
333 print '<div class="div-table-responsive-no-min">';
334 print '<table class="noborder centpercent">';
335 print '<tr class="liste_titre">';
336 print '<td colspan="3">'.$langs->trans("ProposalsToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status=1"><span class="badge">'.$num.'</span></a></td></tr>';
337
338 if ($num)
339 {
340 $i = 0;
341 while ($i < $num)
342 {
343
344 $obj = $db->fetch_object($resql);
345 print '<tr class="oddeven">';
346 print '<td class="nowrap">';
347
348 $propalstatic->id=$obj->rowid;
349 $propalstatic->ref=$obj->ref;
350
351 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
352 print '<td width="96" class="nobordernopadding nowrap">';
353 print $propalstatic->getNomUrl(1);
354 print '</td>';
355
356 print '<td width="16" class="nobordernopadding nowrap">';
357 print '&nbsp;';
358 print '</td>';
359
360 print '<td width="16" class="nobordernopadding right">';
361 $filename=dol_sanitizeFileName($obj->ref);
362 $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
363 $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
364 print $formfile->getDocumentsLink($propalstatic->element, $filename, $filedir);
365 print '</td></tr></table>';
366
367 print '</td>';
368
369 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->name,24).'</a></td>';
370
371 print '<td class="right">'.$propalstatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
372
373 print '</tr>';
374 $i++;
375 }
376 }
377
378 print "</table>";
379 print "</div><br>";
380 }
381 else dol_print_error($db);
382}
383*/
384
385/*
386 * Proposal that are in a shipping process
387 */
388
389/*
390if (isModEnabled('propal'))
391{
392 $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom as name, s.rowid as socid";
393 $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
394 $sql.= ", ".MAIN_DB_PREFIX."societe as s";
395 if (empty($user->rights->societe->client->voir) && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
396 $sql.= " WHERE c.fk_soc = s.rowid";
397 $sql.= " AND c.entity = ".$conf->entity;
398 $sql.= " AND c.fk_statut = 2 ";
399 if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
400 if (empty($user->rights->societe->client->voir) && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
401 $sql.= " ORDER BY c.rowid DESC";
402
403 $resql=$db->query($sql);
404 if ($resql)
405 {
406 $num = $db->num_rows($resql);
407
408 print '<div class="div-table-responsive-no-min">';
409 print '<table class="noborder centpercent">';
410 print '<tr class="liste_titre">';
411 print '<td colspan="3">'.$langs->trans("OnProcessOrders").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status=2"><span class="badge">'.$num.'</span></a></td></tr>';
412
413 if ($num)
414 {
415 $i = 0;
416 while ($i < $num)
417 {
418
419 $obj = $db->fetch_object($resql);
420 print '<tr class="oddeven">';
421 print '<td width="20%" class="nowrap">';
422
423 $propalstatic->id=$obj->rowid;
424 $propalstatic->ref=$obj->ref;
425
426 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
427 print '<td width="96" class="nobordernopadding nowrap">';
428 print $propalstatic->getNomUrl(1);
429 print '</td>';
430
431 print '<td width="16" class="nobordernopadding nowrap">';
432 print '&nbsp;';
433 print '</td>';
434
435 print '<td width="16" class="nobordernopadding right">';
436 $filename=dol_sanitizeFileName($obj->ref);
437 $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
438 $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
439 print $formfile->getDocumentsLink($propalstatic->element, $filename, $filedir);
440 print '</td></tr></table>';
441
442 print '</td>';
443
444 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
445
446 print '<td class="right">'.$propalstatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
447
448 print '</tr>';
449 $i++;
450 }
451 }
452 print "</table>";
453 print "</div><br>";
454 }
455 else dol_print_error($db);
456}
457*/
458
459print '</div>';
460print '</div>';
461
462$parameters = array('user' => $user);
463$reshook = $hookmanager->executeHooks('dashboardPropals', $parameters, $object); // Note that $action and $object may have been modified by hook
464
465// End of page
466llxFooter();
467$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to 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.
const STATUS_VALIDATED
Validated status.
Class to manage third parties objects (customers, suppliers, prospects...)
finishSimpleTable($addLineBreak=false)
Add the correct HTML close tags for "startSimpleTable(...)" (use after the last table line)
startSimpleTable($header, $link="", $arguments="", $emptyRows=0, $number=-1)
Start a table with headers and a optinal clickable number (don't forget to use "finishSimpleTable()" ...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_now($mode='auto')
Return date for now.
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.
addSummaryTableLine($tableColumnCount, $num, $nbofloop=0, $total=0, $noneWord="None", $extraRightColumn=false)
Add a summary line to the current open table ("None", "XMoreLines" or "Total xxx")
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getCustomerProposalPieChart($socid=0)
Return a HTML table that contains a pie chart of customer proposals.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.