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