dolibarr 23.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 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
7 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
32require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
33
42// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
43$hookmanager->initHooks(array('suppliersproposalsindex'));
44
45// Load translation files required by the page
46$langs->loadLangs(array('supplier_proposal', 'companies'));
47
48// Security check
49$socid = GETPOSTINT('socid');
50if (!empty($user->socid) && $user->socid > 0) {
51 $action = '';
52 $socid = $user->socid;
53}
54$result = restrictedArea($user, 'supplier_proposal');
55
56
57/*
58 * View
59 */
60$now = dol_now();
61$supplier_proposalstatic = new SupplierProposal($db);
62$companystatic = new Societe($db);
63$form = new Form($db);
64$formfile = new FormFile($db);
65
66$title = $langs->trans("SupplierProposalArea");
67$help_url = "EN:Module_Ask_Price_Supplier|FR:Module_Demande_de_prix_fournisseur";
68
69llxHeader("", $title, $help_url, '', 0, 0, '', '', '', 'mod-supplierproposal page-index');
70
71print load_fiche_titre($langs->trans("SupplierProposalArea"), '', 'supplier_proposal');
72
73print '<div class="fichecenter"><div class="fichethirdleft">';
74
75// Statistics
76
77$sql = "SELECT count(p.rowid), p.fk_statut";
78$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
79$sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
80if (!$user->hasRight('societe', 'client', 'voir')) {
81 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
82}
83$sql .= " WHERE p.fk_soc = s.rowid";
84$sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
85if ($user->socid) {
86 $sql .= ' AND p.fk_soc = '.((int) $user->socid);
87}
88if (!$user->hasRight('societe', 'client', 'voir')) {
89 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
90}
91$sql .= " AND p.fk_statut IN (0,1,2,3,4)";
92$sql .= " GROUP BY p.fk_statut";
93$resql = $db->query($sql);
94if ($resql) {
95 $num = $db->num_rows($resql);
96 $i = 0;
97
98 $total = 0;
99 $totalinprocess = 0;
100 $dataseries = array();
101 $colorseries = array();
102 $vals = array();
103 // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for sales orders), 3=Closed (Sent/Received, billed or not)
104 while ($i < $num) {
105 $row = $db->fetch_row($resql);
106 if ($row) {
107 //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
108 {
109 $vals[$row[1]] = $row[0];
110 $totalinprocess += $row[0];
111 }
112 $total += $row[0];
113 }
114 $i++;
115 }
116 $db->free($resql);
117
127 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
128
129 print '<div class="div-table-responsive-no-min">';
130 print '<table class="noborder centpercent">';
131 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("CommRequests").'</th></tr>'."\n";
132 $listofstatus = array(0, 1, 2, 3, 4);
133 foreach ($listofstatus as $status) {
134 $dataseries[] = array($supplier_proposalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
135 if ($status == SupplierProposal::STATUS_DRAFT) {
136 $colorseries[$status] = '-'.$badgeStatus0;
137 }
138 if ($status == SupplierProposal::STATUS_VALIDATED) {
139 $colorseries[$status] = $badgeStatus1;
140 }
141 if ($status == SupplierProposal::STATUS_SIGNED) {
142 $colorseries[$status] = $badgeStatus4;
143 }
144 if ($status == SupplierProposal::STATUS_NOTSIGNED) {
145 $colorseries[$status] = $badgeStatus9;
146 }
147 if ($status == SupplierProposal::STATUS_CLOSE) {
148 $colorseries[$status] = $badgeStatus6;
149 }
150
151 if (empty($conf->use_javascript_ajax)) {
152 print '<tr class="oddeven">';
153 print '<td>'.$supplier_proposalstatic->LibStatut($status, 0).'</td>';
154 print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
155 print "</tr>\n";
156 }
157 }
158 if ($conf->use_javascript_ajax) {
159 print '<tr><td class="center" colspan="2">';
160
161 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
162 $dolgraph = new DolGraph();
163 $dolgraph->SetData($dataseries);
164 $dolgraph->SetDataColor(array_values($colorseries));
165 $dolgraph->setShowLegend(2);
166 $dolgraph->setShowPercent(1);
167 $dolgraph->SetType(array('pie'));
168 $dolgraph->setHeight('200');
169 $dolgraph->draw('idgraphstatus');
170 print $dolgraph->show($total ? 0 : 1);
171
172 print '</td></tr>';
173 }
174
175 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
176 print "</table></div><br>";
177} else {
178 dol_print_error($db);
179}
180
181
182/*
183 * Draft askprice
184 */
185if (isModEnabled('supplier_proposal')) {
186 $sql = "SELECT c.rowid, c.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client";
187 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
188 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
189 if (!$user->hasRight('societe', 'client', 'voir')) {
190 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
191 }
192 $sql .= " WHERE c.fk_soc = s.rowid";
193 $sql .= " AND c.entity = ".$conf->entity;
194 $sql .= " AND c.fk_statut = 0";
195 if ($socid) {
196 $sql .= " AND c.fk_soc = ".((int) $socid);
197 }
198 if (!$user->hasRight('societe', 'client', 'voir')) {
199 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
200 }
201
202 $resql = $db->query($sql);
203 if ($resql) {
204 print '<div class="div-table-responsive-no-min">';
205 print '<table class="noborder centpercent">';
206 print '<tr class="liste_titre">';
207 print '<th colspan="2">'.$langs->trans("DraftRequests").'</th></tr>';
208 $langs->load("supplier_proposal");
209 $num = $db->num_rows($resql);
210 if ($num) {
211 $i = 0;
212 while ($i < $num) {
213 $obj = $db->fetch_object($resql);
214
215 print '<tr class="oddeven">';
216 $supplier_proposalstatic->id = $obj->rowid;
217 $supplier_proposalstatic->ref = $obj->ref;
218 print '<td class="nowrap">'.$supplier_proposalstatic->getNomUrl(1).'</td>';
219
220 $companystatic->id = $obj->socid;
221 $companystatic->name = $obj->socname;
222 $companystatic->client = $obj->client;
223 $companystatic->canvas = $obj->canvas;
224 print '<td>'.$companystatic->getNomUrl(1, 'customer', 24).'</td>';
225
226 print '</tr>';
227 $i++;
228 }
229 }
230 print "</table></div><br>";
231 }
232}
233
234print '</div><div class="fichetwothirdright">';
235
236
237$max = 5;
238
239/*
240 * Last modified askprice
241 */
242
243$sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as socname, s.rowid as socid, s.canvas, s.client,";
244$sql .= " date_cloture as datec";
245$sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
246$sql .= ", ".MAIN_DB_PREFIX."societe as s";
247if (!$user->hasRight('societe', 'client', 'voir')) {
248 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
249}
250$sql .= " WHERE c.fk_soc = s.rowid";
251$sql .= " AND c.entity = ".$conf->entity;
252//$sql.= " AND c.fk_statut > 2";
253if ($socid) {
254 $sql .= " AND c.fk_soc = ".((int) $socid);
255}
256if (!$user->hasRight('societe', 'client', 'voir')) {
257 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
258}
259$sql .= " ORDER BY c.tms DESC";
260$sql .= $db->plimit($max, 0);
261
262$resql = $db->query($sql);
263if ($resql) {
264 print '<div class="div-table-responsive-no-min">';
265 print '<table class="noborder centpercent">';
266 print '<tr class="liste_titre">';
267 print '<th colspan="4">'.$langs->trans("LastModifiedRequests", $max).'</th></tr>';
268
269 $num = $db->num_rows($resql);
270 if ($num) {
271 $i = 0;
272 while ($i < $num) {
273 $obj = $db->fetch_object($resql);
274
275 print '<tr class="oddeven">';
276 print '<td width="20%" class="nowrap">';
277
278 $supplier_proposalstatic->id = $obj->rowid;
279 $supplier_proposalstatic->ref = $obj->ref;
280
281 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
282 print '<td width="96" class="nobordernopadding nowrap">';
283 print $supplier_proposalstatic->getNomUrl(1);
284 print '</td>';
285
286 print '<td width="16" class="nobordernopadding nowrap">';
287 print '&nbsp;';
288 print '</td>';
289
290 print '<td width="16" class="right nobordernopadding">';
291 $filename = dol_sanitizeFileName($obj->ref);
292 $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
293 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
294 print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
295 print '</td></tr></table>';
296
297 print '</td>';
298
299 $companystatic->id = $obj->socid;
300 $companystatic->name = $obj->socname;
301 $companystatic->client = $obj->client;
302 $companystatic->canvas = $obj->canvas;
303 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
304
305 print '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
306 print '<td class="right">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>';
307 print '</tr>';
308 $i++;
309 }
310 }
311 print "</table></div><br>";
312} else {
313 dol_print_error($db);
314}
315
316
317/*
318 * Opened askprice
319 */
320if (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')) {
321 $langs->load("supplier_proposal");
322
323 $now = dol_now();
324
325 $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";
326 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
327 $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
328 if (!$user->hasRight('societe', 'client', 'voir')) {
329 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
330 }
331 $sql .= " WHERE p.fk_soc = s.rowid";
332 $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
333 $sql .= " AND p.fk_statut = 1";
334 if (!$user->hasRight('societe', 'client', 'voir')) {
335 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
336 }
337 if ($socid) {
338 $sql .= " AND s.rowid = ".((int) $socid);
339 }
340 $sql .= " ORDER BY p.rowid DESC";
341
342 $result = $db->query($sql);
343 if ($result) {
344 $total = 0;
345 $num = $db->num_rows($result);
346 $i = 0;
347 if ($num > 0) {
348 print '<div class="div-table-responsive-no-min">';
349 print '<table class="noborder centpercent">';
350 print '<tr class="liste_titre"><th colspan="5">'.$langs->trans("RequestsOpened");
351 print ' <a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?search_status=1" alt="'.$langs->trans("GoOnList").'"><span class="badge">'.$num.'</span></a>';
352 print '</th></tr>';
353
354 $nbofloop = min($num, getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500));
355 while ($i < $nbofloop) {
356 $obj = $db->fetch_object($result);
357
358 print '<tr class="oddeven">';
359
360 // Ref
361 print '<td class="nowrap" width="140">';
362
363 $supplier_proposalstatic->id = $obj->supplier_proposalid;
364 $supplier_proposalstatic->ref = $obj->ref;
365
366 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
367 print '<td class="nobordernopadding nowrap">';
368 print $supplier_proposalstatic->getNomUrl(1);
369 print '</td>';
370 print '<td width="18" class="nobordernopadding nowrap">';
371 if ($db->jdate($obj->dfv) < ($now - $conf->supplier_proposal->cloture->warning_delay)) {
372 print img_warning($langs->trans("Late"));
373 }
374 print '</td>';
375 print '<td width="16" class="center nobordernopadding">';
376 $filename = dol_sanitizeFileName($obj->ref);
377 $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
378 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->supplier_proposalid;
379 print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
380 print '</td></tr></table>';
381
382 print "</td>";
383
384 $companystatic->id = $obj->socid;
385 $companystatic->name = $obj->socname;
386 $companystatic->client = $obj->client;
387 $companystatic->canvas = $obj->canvas;
388 print '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>'."\n";
389
390 print '<td class="right">';
391 print dol_print_date($db->jdate($obj->dp), 'day').'</td>'."\n";
392 print '<td class="right">'.price($obj->total_ttc).'</td>';
393 print '<td class="center" width="14">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>'."\n";
394 print '</tr>'."\n";
395 $i++;
396 $total += $obj->total_ttc;
397 }
398 if ($num > $nbofloop) {
399 print '<tr class="liste_total"><td colspan="5">'.$langs->trans("XMoreLines", ($num - $nbofloop))."</td></tr>";
400 } elseif ($total > 0) {
401 print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total").'</td><td class="right">'.price($total)."</td><td>&nbsp;</td></tr>";
402 }
403 print "</table></div><br>";
404 }
405 } else {
406 dol_print_error($db);
407 }
408}
409
410print '</div></div>';
411
412$parameters = array('user' => $user);
413$reshook = $hookmanager->executeHooks('dashboardSupplierProposal', $parameters, $object); // Note that $action and $object may have been modified by hook
414
415// End of page
416llxFooter();
417$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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 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.
dol_now($mode='gmt')
Return date for now.
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_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.