dolibarr  21.0.0-alpha
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
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
33 
34 // Initialize a 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 = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
43 
44 // Security check
45 $socid = GETPOSTINT('socid');
46 if (isset($user->socid) && $user->socid > 0) {
47  $action = '';
48  $socid = $user->socid;
49 }
50 
51 restrictedArea($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 
64 llxHeader("", $langs->trans("ProspectionArea"), $help_url);
65 
66 print load_fiche_titre($langs->trans("ProspectionArea"), '', 'propal');
67 
68 print '<div class="fichecenter">';
69 print '<div class="fichethirdleft">';
70 
71 $tmp = getCustomerProposalPieChart($socid);
72 if ($tmp) {
73  print $tmp;
74  print '<br>';
75 }
76 
77 /*
78  * Draft proposals
79  */
80 if (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  $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
86  $sql .= " AND p.fk_soc = s.rowid";
87  $sql .= " AND p.fk_statut =".Propal::STATUS_DRAFT;
88  // If the internal user must only see his customers, force searching by him
89  $search_sale = 0;
90  if (!$user->hasRight('societe', 'client', 'voir')) {
91  $search_sale = $user->id;
92  }
93  // Search on sale representative
94  if ($search_sale && $search_sale != '-1') {
95  if ($search_sale == -2) {
96  $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
97  } elseif ($search_sale > 0) {
98  $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
99  }
100  }
101  // Search on socid
102  if ($socid) {
103  $sql .= " AND p.fk_soc = ".((int) $socid);
104  }
105 
106  $resql = $db->query($sql);
107  if ($resql) {
108  $num = $db->num_rows($resql);
109  $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
110  startSimpleTable("DraftPropals", "comm/propal/list.php", "search_status=".Propal::STATUS_DRAFT, 2, $num);
111 
112  $total = 0;
113  if ($num) {
114  $i = 0;
115 
116  while ($i < $nbofloop) {
117  $obj = $db->fetch_object($resql);
118 
119  $propalstatic->id = $obj->rowid;
120  $propalstatic->ref = $obj->ref;
121  $propalstatic->ref_client = $obj->ref_client;
122  $propalstatic->total_ht = $obj->total_ht;
123  $propalstatic->total_tva = $obj->total_tva;
124  $propalstatic->total_ttc = $obj->total_ttc;
125 
126  $companystatic->id = $obj->socid;
127  $companystatic->name = $obj->name;
128  $companystatic->client = $obj->client;
129  $companystatic->code_client = $obj->code_client;
130  $companystatic->code_fournisseur = $obj->code_fournisseur;
131  $companystatic->canvas = $obj->canvas;
132  $companystatic->entity = $obj->entity;
133  $companystatic->email = $obj->email;
134  $companystatic->code_compta = $obj->code_compta;
135 
136  print '<tr class="oddeven">';
137  print '<td class="nowrap">'.$propalstatic->getNomUrl(1).'</td>';
138  print '<td class="nowrap">'.$companystatic->getNomUrl(1, 'customer', 16).'</td>';
139  print '<td class="nowrap right">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
140  print '</tr>';
141 
142  $i++;
143  $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
144  }
145  }
146 
147  addSummaryTableLine(3, $num, $nbofloop, $total, "NoProposal");
148  finishSimpleTable(true);
149  $db->free($resql);
150  } else {
151  dol_print_error($db);
152  }
153 }
154 
155 print '</div>';
156 
157 print '<div class="fichetwothirdright">';
158 
159 /*
160  * Last modified proposals
161  */
162 
163 $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut as status, date_cloture as datec, c.tms as datem,";
164 $sql .= " s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta";
165 $sql .= " FROM ".MAIN_DB_PREFIX."propal as c,";
166 $sql .= " ".MAIN_DB_PREFIX."societe as s";
167 $sql .= " WHERE c.entity IN (".getEntity($propalstatic->element).")";
168 $sql .= " AND c.fk_soc = s.rowid";
169 // If the internal user must only see his customers, force searching by him
170 $search_sale = 0;
171 if (!$user->hasRight('societe', 'client', 'voir')) {
172  $search_sale = $user->id;
173 }
174 // Search on sale representative
175 if ($search_sale && $search_sale != '-1') {
176  if ($search_sale == -2) {
177  $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
178  } elseif ($search_sale > 0) {
179  $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).")";
180  }
181 }
182 // Search on socid
183 if ($socid) {
184  $sql .= " AND c.fk_soc = ".((int) $socid);
185 }
186 $sql .= " ORDER BY c.tms DESC";
187 
188 $sql .= $db->plimit($max, 0);
189 
190 $resql = $db->query($sql);
191 if ($resql) {
192  $num = $db->num_rows($resql);
193 
194  startSimpleTable($langs->trans("LastModifiedProposals", $max), "comm/propal/list.php", "sortfield=p.tms&sortorder=DESC", 2, -1, 'propal');
195 
196  if ($num) {
197  $i = 0;
198  while ($i < $num) {
199  $obj = $db->fetch_object($resql);
200 
201  $propalstatic->id = $obj->rowid;
202  $propalstatic->ref = $obj->ref;
203 
204  $companystatic->id = $obj->socid;
205  $companystatic->name = $obj->socname;
206  $companystatic->client = $obj->client;
207  $companystatic->canvas = $obj->canvas;
208  $companystatic->email = $obj->email;
209  $companystatic->code_compta = $obj->code_compta;
210 
211  $filename = dol_sanitizeFileName($obj->ref);
212  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
213  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
214 
215  print '<tr class="oddeven">';
216 
217  print '<td class="nowrap">';
218  print '<table class="nobordernopadding">';
219  print '<tr class="nocellnopadd">';
220  print '<td width="96" class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
221  print '<td width="16" class="nobordernopadding nowrap"></td>';
222  print '<td width="16" class="nobordernopadding right">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
223  print '</tr>';
224  print '</table>';
225  print '</td>';
226 
227  print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
228 
229  $datem = $db->jdate($obj->datem);
230  print '<td class="center" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'">';
231  print dol_print_date($datem, 'day', 'tzuserrel');
232  print '</td>';
233 
234  print '<td class="right">'.$propalstatic->LibStatut($obj->status, 3).'</td>';
235 
236  print '</tr>';
237 
238  $i++;
239  }
240  }
241 
242  finishSimpleTable(true);
243  $db->free($resql);
244 } else {
245  dol_print_error($db);
246 }
247 
248 
249 /*
250  * Open (validated) proposals
251  */
252 if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
253  $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, s.email, s.code_compta";
254  $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";
255  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
256  $sql .= ", ".MAIN_DB_PREFIX."propal as p";
257  $sql .= " WHERE p.fk_soc = s.rowid";
258  $sql .= " AND p.entity IN (".getEntity($propalstatic->element).")";
259  $sql .= " AND p.fk_statut = ".Propal::STATUS_VALIDATED;
260  // If the internal user must only see his customers, force searching by him
261  $search_sale = 0;
262  if (!$user->hasRight('societe', 'client', 'voir')) {
263  $search_sale = $user->id;
264  }
265  // Search on sale representative
266  if ($search_sale && $search_sale != '-1') {
267  if ($search_sale == -2) {
268  $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
269  } elseif ($search_sale > 0) {
270  $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
271  }
272  }
273  // Search on socid
274  if ($socid) {
275  $sql .= " AND p.fk_soc = ".((int) $socid);
276  }
277  $sql .= " ORDER BY p.rowid DESC";
278 
279  $resql = $db->query($sql);
280  if ($resql) {
281  $total = 0;
282  $num = $db->num_rows($resql);
283  $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
284  startSimpleTable("ProposalsOpened", "comm/propal/list.php", "search_status=".Propal::STATUS_VALIDATED, 4, $num);
285 
286  if ($num > 0) {
287  $i = 0;
288  while ($i < $nbofloop) {
289  $obj = $db->fetch_object($resql);
290 
291  $propalstatic->id = $obj->propalid;
292  $propalstatic->ref = $obj->ref;
293 
294  $companystatic->id = $obj->socid;
295  $companystatic->name = $obj->socname;
296  $companystatic->client = $obj->client;
297  $companystatic->canvas = $obj->canvas;
298  $companystatic->email = $obj->email;
299  $companystatic->code_compta = $obj->code_compta;
300 
301  $filename = dol_sanitizeFileName($obj->ref);
302  $filedir = $conf->propal->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
303  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->propalid;
304 
305  $warning = ($db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) ? img_warning($langs->trans("Late")) : '';
306 
307  print '<tr class="oddeven">';
308 
309  // Ref
310  print '<td class="nowrap" width="140">';
311  print '<table class="nobordernopadding">';
312  print '<tr class="nocellnopadd">';
313  print '<td class="nobordernopadding nowrap">'.$propalstatic->getNomUrl(1).'</td>';
314  print '<td width="18" class="nobordernopadding nowrap">'.$warning.'</td>';
315  print '<td width="16" align="center" class="nobordernopadding">'.$formfile->getDocumentsLink($propalstatic->element, $filename, $filedir).'</td>';
316  print '</tr>';
317  print '</table>';
318  print '</td>';
319 
320  print '<td class="tdoverflowmax150">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>';
321  print '<td class="right">'.dol_print_date($db->jdate($obj->dp), 'day').'</td>';
322  print '<td class="right">'.price(getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc).'</td>';
323  print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut, 3).'</td>';
324 
325  print '</tr>';
326 
327  $i++;
328  $total += (getDolGlobalString('MAIN_DASHBOARD_USE_TOTAL_HT') ? $obj->total_ht : $obj->total_ttc);
329  }
330  }
331 
332  addSummaryTableLine(5, $num, $nbofloop, $total, "None", true);
333  finishSimpleTable(true);
334  $db->free($resql);
335  } else {
336  dol_print_error($db);
337  }
338 }
339 
340 print '</div>';
341 print '</div>';
342 
343 $parameters = array('user' => $user);
344 $reshook = $hookmanager->executeHooks('dashboardPropals', $parameters, $object); // Note that $action and $object may have been modified by hook
345 
346 // End of page
347 llxFooter();
348 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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...)
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:751
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_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 dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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()"...
getCustomerProposalPieChart($socid=0)
Return a HTML table that contains a pie chart of customer proposals.
Definition: propal.lib.php:211
llxFooter()
Footer empty.
Definition: index.php:72
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:64
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.