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