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