dolibarr  16.0.5
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  $action = '';
43  $socid = $user->socid;
44 }
45 $result = restrictedArea($user, 'supplier_proposal');
46 
47 
48 /*
49  * View
50  */
51 $now = dol_now();
52 $supplier_proposalstatic = new SupplierProposal($db);
53 $companystatic = new Societe($db);
54 $form = new Form($db);
55 $formfile = new FormFile($db);
56 $help_url = "EN:Module_Ask_Price_Supplier|FR:Module_Demande_de_prix_fournisseur";
57 
58 llxHeader("", $langs->trans("SupplierProposalArea"), $help_url);
59 
60 print load_fiche_titre($langs->trans("SupplierProposalArea"), '', 'supplier_proposal');
61 
62 print '<div class="fichecenter"><div class="fichethirdleft">';
63 
64 // Statistics
65 
66 $sql = "SELECT count(p.rowid), p.fk_statut";
67 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
68 $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
69 if (empty($user->rights->societe->client->voir) && !$socid) {
70  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
71 }
72 $sql .= " WHERE p.fk_soc = s.rowid";
73 $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
74 if ($user->socid) {
75  $sql .= ' AND p.fk_soc = '.((int) $user->socid);
76 }
77 if (empty($user->rights->societe->client->voir) && !$socid) {
78  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
79 }
80 $sql .= " AND p.fk_statut IN (0,1,2,3,4)";
81 $sql .= " GROUP BY p.fk_statut";
82 $resql = $db->query($sql);
83 if ($resql) {
84  $num = $db->num_rows($resql);
85  $i = 0;
86 
87  $total = 0;
88  $totalinprocess = 0;
89  $dataseries = array();
90  $colorseries = array();
91  $vals = array();
92  // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not)
93  while ($i < $num) {
94  $row = $db->fetch_row($resql);
95  if ($row) {
96  //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
97  {
98  $vals[$row[1]] = $row[0];
99  $totalinprocess += $row[0];
100  }
101  $total += $row[0];
102  }
103  $i++;
104  }
105  $db->free($resql);
106 
107  include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
108 
109  print '<div class="div-table-responsive-no-min">';
110  print '<table class="noborder centpercent">';
111  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("CommRequests").'</th></tr>'."\n";
112  $listofstatus = array(0, 1, 2, 3, 4);
113  foreach ($listofstatus as $status) {
114  $dataseries[] = array($supplier_proposalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
115  if ($status == SupplierProposal::STATUS_DRAFT) {
116  $colorseries[$status] = '-'.$badgeStatus0;
117  }
118  if ($status == SupplierProposal::STATUS_VALIDATED) {
119  $colorseries[$status] = $badgeStatus1;
120  }
121  if ($status == SupplierProposal::STATUS_SIGNED) {
122  $colorseries[$status] = $badgeStatus4;
123  }
124  if ($status == SupplierProposal::STATUS_NOTSIGNED) {
125  $colorseries[$status] = $badgeStatus9;
126  }
127  if ($status == SupplierProposal::STATUS_CLOSE) {
128  $colorseries[$status] = $badgeStatus6;
129  }
130 
131  if (empty($conf->use_javascript_ajax)) {
132  print '<tr class="oddeven">';
133  print '<td>'.$supplier_proposalstatic->LibStatut($status, 0).'</td>';
134  print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
135  print "</tr>\n";
136  }
137  }
138  if ($conf->use_javascript_ajax) {
139  print '<tr><td class="center" colspan="2">';
140 
141  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
142  $dolgraph = new DolGraph();
143  $dolgraph->SetData($dataseries);
144  $dolgraph->SetDataColor(array_values($colorseries));
145  $dolgraph->setShowLegend(2);
146  $dolgraph->setShowPercent(1);
147  $dolgraph->SetType(array('pie'));
148  $dolgraph->setHeight('200');
149  $dolgraph->draw('idgraphstatus');
150  print $dolgraph->show($total ? 0 : 1);
151 
152  print '</td></tr>';
153  }
154 
155  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
156  print "</table></div><br>";
157 } else {
158  dol_print_error($db);
159 }
160 
161 
162 /*
163  * Draft askprice
164  */
165 if (!empty($conf->supplier_proposal->enabled)) {
166  $sql = "SELECT c.rowid, c.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client";
167  $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
168  $sql .= ", ".MAIN_DB_PREFIX."societe as s";
169  if (empty($user->rights->societe->client->voir) && !$socid) {
170  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
171  }
172  $sql .= " WHERE c.fk_soc = s.rowid";
173  $sql .= " AND c.entity = ".$conf->entity;
174  $sql .= " AND c.fk_statut = 0";
175  if ($socid) {
176  $sql .= " AND c.fk_soc = ".((int) $socid);
177  }
178  if (empty($user->rights->societe->client->voir) && !$socid) {
179  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
180  }
181 
182  $resql = $db->query($sql);
183  if ($resql) {
184  print '<div class="div-table-responsive-no-min">';
185  print '<table class="noborder centpercent">';
186  print '<tr class="liste_titre">';
187  print '<th colspan="2">'.$langs->trans("DraftRequests").'</th></tr>';
188  $langs->load("supplier_proposal");
189  $num = $db->num_rows($resql);
190  if ($num) {
191  $i = 0;
192  while ($i < $num) {
193  $obj = $db->fetch_object($resql);
194 
195  print '<tr class="oddeven">';
196  $supplier_proposalstatic->id = $obj->rowid;
197  $supplier_proposalstatic->ref = $obj->ref;
198  print '<td class="nowrap">'.$supplier_proposalstatic->getNomUrl(1).'</td>';
199 
200  $companystatic->id = $obj->socid;
201  $companystatic->name = $obj->socname;
202  $companystatic->client = $obj->client;
203  $companystatic->canvas = $obj->canvas;
204  print '<td>'.$companystatic->getNomUrl(1, 'customer', 24).'</td>';
205 
206  print '</tr>';
207  $i++;
208  }
209  }
210  print "</table></div><br>";
211  }
212 }
213 
214 print '</div><div class="fichetwothirdright">';
215 
216 
217 $max = 5;
218 
219 /*
220  * Last modified askprice
221  */
222 
223 $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as socname, s.rowid as socid, s.canvas, s.client,";
224 $sql .= " date_cloture as datec";
225 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
226 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
227 if (empty($user->rights->societe->client->voir) && !$socid) {
228  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
229 }
230 $sql .= " WHERE c.fk_soc = s.rowid";
231 $sql .= " AND c.entity = ".$conf->entity;
232 //$sql.= " AND c.fk_statut > 2";
233 if ($socid) {
234  $sql .= " AND c.fk_soc = ".((int) $socid);
235 }
236 if (empty($user->rights->societe->client->voir) && !$socid) {
237  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
238 }
239 $sql .= " ORDER BY c.tms DESC";
240 $sql .= $db->plimit($max, 0);
241 
242 $resql = $db->query($sql);
243 if ($resql) {
244  print '<div class="div-table-responsive-no-min">';
245  print '<table class="noborder centpercent">';
246  print '<tr class="liste_titre">';
247  print '<th colspan="4">'.$langs->trans("LastModifiedRequests", $max).'</th></tr>';
248 
249  $num = $db->num_rows($resql);
250  if ($num) {
251  $i = 0;
252  while ($i < $num) {
253  $obj = $db->fetch_object($resql);
254 
255  print '<tr class="oddeven">';
256  print '<td width="20%" class="nowrap">';
257 
258  $supplier_proposalstatic->id = $obj->rowid;
259  $supplier_proposalstatic->ref = $obj->ref;
260 
261  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
262  print '<td width="96" class="nobordernopadding nowrap">';
263  print $supplier_proposalstatic->getNomUrl(1);
264  print '</td>';
265 
266  print '<td width="16" class="nobordernopadding nowrap">';
267  print '&nbsp;';
268  print '</td>';
269 
270  print '<td width="16" class="right nobordernopadding">';
271  $filename = dol_sanitizeFileName($obj->ref);
272  $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
273  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
274  print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
275  print '</td></tr></table>';
276 
277  print '</td>';
278 
279  $companystatic->id = $obj->socid;
280  $companystatic->name = $obj->socname;
281  $companystatic->client = $obj->client;
282  $companystatic->canvas = $obj->canvas;
283  print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
284 
285  print '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
286  print '<td class="right">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>';
287  print '</tr>';
288  $i++;
289  }
290  }
291  print "</table></div><br>";
292 } else {
293  dol_print_error($db);
294 }
295 
296 
297 /*
298  * Opened askprice
299  */
300 if (!empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire) {
301  $langs->load("supplier_proposal");
302 
303  $now = dol_now();
304 
305  $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, p.rowid as supplier_proposalid, p.total_ttc, p.total_tva, p.total_ht, p.ref, p.fk_statut, p.datec as dp";
306  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
307  $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
308  if (empty($user->rights->societe->client->voir) && !$socid) {
309  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
310  }
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 (empty($user->rights->societe->client->voir) && !$socid) {
315  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
316  }
317  if ($socid) {
318  $sql .= " AND s.rowid = ".((int) $socid);
319  }
320  $sql .= " ORDER BY p.rowid DESC";
321 
322  $result = $db->query($sql);
323  if ($result) {
324  $total = 0;
325  $num = $db->num_rows($result);
326  $i = 0;
327  if ($num > 0) {
328  print '<div class="div-table-responsive-no-min">';
329  print '<table class="noborder centpercent">';
330  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>';
331 
332  $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
333  while ($i < $nbofloop) {
334  $obj = $db->fetch_object($result);
335 
336  print '<tr class="oddeven">';
337 
338  // Ref
339  print '<td class="nowrap" width="140">';
340 
341  $supplier_proposalstatic->id = $obj->supplier_proposalid;
342  $supplier_proposalstatic->ref = $obj->ref;
343 
344  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
345  print '<td class="nobordernopadding nowrap">';
346  print $supplier_proposalstatic->getNomUrl(1);
347  print '</td>';
348  print '<td width="18" class="nobordernopadding nowrap">';
349  if ($db->jdate($obj->dfv) < ($now - $conf->supplier_proposal->cloture->warning_delay)) {
350  print img_warning($langs->trans("Late"));
351  }
352  print '</td>';
353  print '<td width="16" class="center nobordernopadding">';
354  $filename = dol_sanitizeFileName($obj->ref);
355  $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
356  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->supplier_proposalid;
357  print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
358  print '</td></tr></table>';
359 
360  print "</td>";
361 
362  $companystatic->id = $obj->socid;
363  $companystatic->name = $obj->socname;
364  $companystatic->client = $obj->client;
365  $companystatic->canvas = $obj->canvas;
366  print '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>'."\n";
367 
368  print '<td class="right">';
369  print dol_print_date($db->jdate($obj->dp), 'day').'</td>'."\n";
370  print '<td class="right">'.price($obj->total_ttc).'</td>';
371  print '<td class="center" width="14">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>'."\n";
372  print '</tr>'."\n";
373  $i++;
374  $total += $obj->total_ttc;
375  }
376  if ($num > $nbofloop) {
377  print '<tr class="liste_total"><td colspan="5">'.$langs->trans("XMoreLines", ($num - $nbofloop))."</td></tr>";
378  } elseif ($total > 0) {
379  print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total").'</td><td class="right">'.price($total)."</td><td>&nbsp;</td></tr>";
380  }
381  print "</table></div><br>";
382  }
383  } else {
384  dol_print_error($db);
385  }
386 }
387 
388 print '</div></div>';
389 
390 $parameters = array('user' => $user);
391 $reshook = $hookmanager->executeHooks('dashboardSupplierProposal', $parameters, $object); // Note that $action and $object may have been modified by hook
392 
393 // End of page
394 llxFooter();
395 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
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.
Definition: security.lib.php:234
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
SupplierProposal\STATUS_NOTSIGNED
const STATUS_NOTSIGNED
Not signed quote, canceled.
Definition: supplier_proposal.class.php:215
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
$help_url
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
SupplierProposal\STATUS_VALIDATED
const STATUS_VALIDATED
Validated status.
Definition: supplier_proposal.class.php:205
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
llxHeader
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:63
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
SupplierProposal\STATUS_CLOSE
const STATUS_CLOSE
Billed or closed/processed quote.
Definition: supplier_proposal.class.php:220
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
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
price
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.
Definition: functions.lib.php:5541
SupplierProposal
Class to manage price ask supplier.
Definition: supplier_proposal.class.php:50
SupplierProposal\STATUS_DRAFT
const STATUS_DRAFT
Draft status.
Definition: supplier_proposal.class.php:200
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
SupplierProposal\STATUS_SIGNED
const STATUS_SIGNED
Signed quote.
Definition: supplier_proposal.class.php:210