dolibarr  13.0.2
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-2011 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  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
30 
31 $hookmanager = new HookManager($db);
32 
33 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
34 $hookmanager->initHooks(array('suppliersproposalsindex'));
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('supplier_proposal', 'companies'));
38 
39 // Security check
40 $socid = GETPOST('socid', 'int');
41 if (isset($user->socid) && $user->socid > 0)
42 {
43  $action = '';
44  $socid = $user->socid;
45 }
46 $result = restrictedArea($user, 'supplier_proposal');
47 
48 
49 /*
50  * View
51  */
52 $now = dol_now();
53 $supplier_proposalstatic = new SupplierProposal($db);
54 $companystatic = new Societe($db);
55 $form = new Form($db);
56 $formfile = new FormFile($db);
57 $help_url = "EN:Module_Ask_Price_Supplier|FR:Module_Demande_de_prix_fournisseur";
58 
59 llxHeader("", $langs->trans("SupplierProposalArea"), $help_url);
60 
61 print load_fiche_titre($langs->trans("SupplierProposalArea"), '', 'supplier_proposal');
62 
63 print '<div class="fichecenter"><div class="fichethirdleft">';
64 
65 
66 // Search form
67 
68 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
69 {
70  print '<form method="post" action="'.DOL_URL_ROOT.'/supplier_proposal/list.php">';
71  print '<input type="hidden" name="token" value="'.newToken().'">';
72  print '<div class="div-table-responsive-no-min">';
73  print '<table class="noborder nohover centpercent">';
74  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
75  print '<tr class="oddeven"><td>';
76  print $langs->trans("SupplierProposal").':</td><td><input type="text" class="flat" name="sall" size="18"></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
77  print '</tr>';
78  print "</table></div></form><br>\n";
79 }
80 
81 
82 // Statistics
83 
84 $sql = "SELECT count(p.rowid), p.fk_statut";
85 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
86 $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
87 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
88 $sql .= " WHERE p.fk_soc = s.rowid";
89 $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
90 if ($user->socid) $sql .= ' AND p.fk_soc = '.$user->socid;
91 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
92 $sql .= " AND p.fk_statut IN (0,1,2,3,4)";
93 $sql .= " GROUP BY p.fk_statut";
94 $resql = $db->query($sql);
95 if ($resql)
96 {
97  $num = $db->num_rows($resql);
98  $i = 0;
99 
100  $total = 0;
101  $totalinprocess = 0;
102  $dataseries = array();
103  $colorseries = array();
104  $vals = array();
105  // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not)
106  while ($i < $num)
107  {
108  $row = $db->fetch_row($resql);
109  if ($row)
110  {
111  //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
112  {
113  $vals[$row[1]] = $row[0];
114  $totalinprocess += $row[0];
115  }
116  $total += $row[0];
117  }
118  $i++;
119  }
120  $db->free($resql);
121 
122  include_once DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
123 
124  print '<div class="div-table-responsive-no-min">';
125  print '<table class="noborder centpercent">';
126  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("CommRequests").'</th></tr>'."\n";
127  $listofstatus = array(0, 1, 2, 3, 4);
128  foreach ($listofstatus as $status)
129  {
130  $dataseries[] = array($supplier_proposalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
131  if ($status == SupplierProposal::STATUS_DRAFT) $colorseries[$status] = '-'.$badgeStatus0;
132  if ($status == SupplierProposal::STATUS_VALIDATED) $colorseries[$status] = $badgeStatus1;
133  if ($status == SupplierProposal::STATUS_SIGNED) $colorseries[$status] = $badgeStatus4;
134  if ($status == SupplierProposal::STATUS_NOTSIGNED) $colorseries[$status] = $badgeStatus9;
135  if ($status == SupplierProposal::STATUS_CLOSE) $colorseries[$status] = $badgeStatus6;
136 
137  if (empty($conf->use_javascript_ajax))
138  {
139  print '<tr class="oddeven">';
140  print '<td>'.$supplier_proposalstatic->LibStatut($status, 0).'</td>';
141  print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
142  print "</tr>\n";
143  }
144  }
145  if ($conf->use_javascript_ajax)
146  {
147  print '<tr><td class="center" colspan="2">';
148 
149  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
150  $dolgraph = new DolGraph();
151  $dolgraph->SetData($dataseries);
152  $dolgraph->SetDataColor(array_values($colorseries));
153  $dolgraph->setShowLegend(2);
154  $dolgraph->setShowPercent(1);
155  $dolgraph->SetType(array('pie'));
156  $dolgraph->setHeight('200');
157  $dolgraph->draw('idgraphstatus');
158  print $dolgraph->show($total ? 0 : 1);
159 
160  print '</td></tr>';
161  }
162 
163  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
164  print "</table></div><br>";
165 } else {
166  dol_print_error($db);
167 }
168 
169 
170 /*
171  * Draft askprice
172  */
173 if (!empty($conf->supplier_proposal->enabled))
174 {
175  $sql = "SELECT c.rowid, c.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client";
176  $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
177  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
178  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
179  $sql .= " WHERE c.fk_soc = s.rowid";
180  $sql .= " AND c.entity = ".$conf->entity;
181  $sql .= " AND c.fk_statut = 0";
182  if ($socid) $sql .= " AND c.fk_soc = ".$socid;
183  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
184 
185  $resql = $db->query($sql);
186  if ($resql)
187  {
188  print '<div class="div-table-responsive-no-min">';
189  print '<table class="noborder centpercent">';
190  print '<tr class="liste_titre">';
191  print '<th colspan="2">'.$langs->trans("DraftRequests").'</th></tr>';
192  $langs->load("supplier_proposal");
193  $num = $db->num_rows($resql);
194  if ($num)
195  {
196  $i = 0;
197  while ($i < $num)
198  {
199  $obj = $db->fetch_object($resql);
200 
201  print '<tr class="oddeven">';
202  $supplier_proposalstatic->id = $obj->rowid;
203  $supplier_proposalstatic->ref = $obj->ref;
204  print '<td class="nowrap">'.$supplier_proposalstatic->getNomUrl(1).'</td>';
205 
206  $companystatic->id = $obj->socid;
207  $companystatic->name = $obj->socname;
208  $companystatic->client = $obj->client;
209  $companystatic->canvas = $obj->canvas;
210  print '<td>'.$companystatic->getNomUrl(1, 'customer', 24).'</td>';
211 
212  print '</tr>';
213  $i++;
214  }
215  }
216  print "</table></div><br>";
217  }
218 }
219 
220 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
221 
222 
223 $max = 5;
224 
225 /*
226  * Last modified askprice
227  */
228 
229 $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as socname, s.rowid as socid, s.canvas, s.client,";
230 $sql .= " date_cloture as datec";
231 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
232 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
233 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
234 $sql .= " WHERE c.fk_soc = s.rowid";
235 $sql .= " AND c.entity = ".$conf->entity;
236 //$sql.= " AND c.fk_statut > 2";
237 if ($socid) $sql .= " AND c.fk_soc = ".$socid;
238 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
239 $sql .= " ORDER BY c.tms DESC";
240 $sql .= $db->plimit($max, 0);
241 
242 $resql = $db->query($sql);
243 if ($resql)
244 {
245  print '<div class="div-table-responsive-no-min">';
246  print '<table class="noborder centpercent">';
247  print '<tr class="liste_titre">';
248  print '<th colspan="4">'.$langs->trans("LastModifiedRequests", $max).'</th></tr>';
249 
250  $num = $db->num_rows($resql);
251  if ($num)
252  {
253  $i = 0;
254  while ($i < $num)
255  {
256  $obj = $db->fetch_object($resql);
257 
258  print '<tr class="oddeven">';
259  print '<td width="20%" class="nowrap">';
260 
261  $supplier_proposalstatic->id = $obj->rowid;
262  $supplier_proposalstatic->ref = $obj->ref;
263 
264  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
265  print '<td width="96" class="nobordernopadding nowrap">';
266  print $supplier_proposalstatic->getNomUrl(1);
267  print '</td>';
268 
269  print '<td width="16" class="nobordernopadding nowrap">';
270  print '&nbsp;';
271  print '</td>';
272 
273  print '<td width="16" class="right nobordernopadding">';
274  $filename = dol_sanitizeFileName($obj->ref);
275  $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
276  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
277  print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
278  print '</td></tr></table>';
279 
280  print '</td>';
281 
282  $companystatic->id = $obj->socid;
283  $companystatic->name = $obj->socname;
284  $companystatic->client = $obj->client;
285  $companystatic->canvas = $obj->canvas;
286  print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
287 
288  print '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
289  print '<td class="right">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>';
290  print '</tr>';
291  $i++;
292  }
293  }
294  print "</table></div><br>";
295 } else dol_print_error($db);
296 
297 
298 /*
299  * Opened askprice
300  */
301 if (!empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire)
302 {
303  $langs->load("supplier_proposal");
304 
305  $now = dol_now();
306 
307  $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, p.rowid as supplier_proposalid, p.total as total_ttc, p.total_ht, p.ref, p.fk_statut, p.datec as dp";
308  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
309  $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
310  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
311  $sql .= " WHERE p.fk_soc = s.rowid";
312  $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
313  $sql .= " AND p.fk_statut = 1";
314  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
315  if ($socid) $sql .= " AND s.rowid = ".$socid;
316  $sql .= " ORDER BY p.rowid DESC";
317 
318  $result = $db->query($sql);
319  if ($result)
320  {
321  $total = 0;
322  $num = $db->num_rows($result);
323  $i = 0;
324  if ($num > 0)
325  {
326  print '<div class="div-table-responsive-no-min">';
327  print '<table class="noborder centpercent">';
328  print '<tr class="liste_titre"><th colspan="5">'.$langs->trans("RequestsOpened").' <a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?search_status=1"><span class="badge">'.$num.'</span></a></th></tr>';
329 
330  $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
331  while ($i < $nbofloop)
332  {
333  $obj = $db->fetch_object($result);
334 
335  print '<tr class="oddeven">';
336 
337  // Ref
338  print '<td class="nowrap" width="140">';
339 
340  $supplier_proposalstatic->id = $obj->supplier_proposalid;
341  $supplier_proposalstatic->ref = $obj->ref;
342 
343  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
344  print '<td class="nobordernopadding nowrap">';
345  print $supplier_proposalstatic->getNomUrl(1);
346  print '</td>';
347  print '<td width="18" class="nobordernopadding nowrap">';
348  if ($db->jdate($obj->dfv) < ($now - $conf->supplier_proposal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
349  print '</td>';
350  print '<td width="16" class="center nobordernopadding">';
351  $filename = dol_sanitizeFileName($obj->ref);
352  $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
353  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->supplier_proposalid;
354  print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
355  print '</td></tr></table>';
356 
357  print "</td>";
358 
359  $companystatic->id = $obj->socid;
360  $companystatic->name = $obj->socname;
361  $companystatic->client = $obj->client;
362  $companystatic->canvas = $obj->canvas;
363  print '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>'."\n";
364 
365  print '<td class="right">';
366  print dol_print_date($db->jdate($obj->dp), 'day').'</td>'."\n";
367  print '<td class="right">'.price($obj->total_ttc).'</td>';
368  print '<td class="center" width="14">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>'."\n";
369  print '</tr>'."\n";
370  $i++;
371  $total += $obj->total_ttc;
372  }
373  if ($num > $nbofloop)
374  {
375  print '<tr class="liste_total"><td colspan="5">'.$langs->trans("XMoreLines", ($num - $nbofloop))."</td></tr>";
376  } elseif ($total > 0)
377  {
378  print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total").'</td><td class="right">'.price($total)."</td><td>&nbsp;</td></tr>";
379  }
380  print "</table></div><br>";
381  }
382  } else {
383  dol_print_error($db);
384  }
385 }
386 
387 print '</div></div></div>';
388 
389 $parameters = array('user' => $user);
390 $reshook = $hookmanager->executeHooks('dashboardSupplierProposal', $parameters, $object); // Note that $action and $object may have been modified by hook
391 
392 // End of page
393 llxFooter();
394 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
const STATUS_NOTSIGNED
Not signed quote, canceled.
dol_now($mode= 'auto')
Return date for now.
const STATUS_CLOSE
Billed or closed/processed quote.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage hooks.
const STATUS_SIGNED
Signed quote.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
const STATUS_VALIDATED
Validated status.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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.
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const STATUS_DRAFT
Draft status.
Class to build graphs.
Class to manage price ask supplier.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59