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-2026 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';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/dashboard.lib.php';
35
44// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
45$hookmanager->initHooks(array('suppliersproposalsindex'));
46
47// Load translation files required by the page
48$langs->loadLangs(array('supplier_proposal', 'companies'));
49
50// Security check
51$socid = GETPOSTINT('socid');
52if (!empty($user->socid) && $user->socid > 0) {
53 $action = '';
54 $socid = $user->socid;
55}
56$result = restrictedArea($user, 'supplier_proposal');
57
58
59/*
60 * View
61 */
62$now = dol_now();
63$supplier_proposalstatic = new SupplierProposal($db);
64$companystatic = new Societe($db);
65$form = new Form($db);
66$formfile = new FormFile($db);
67
68$title = $langs->trans("SupplierProposalArea");
69$help_url = "EN:Module_Ask_Price_Supplier|FR:Module_Demande_de_prix_fournisseur";
70
71llxHeader("", $title, $help_url, '', 0, 0, '', '', '', 'mod-supplierproposal page-index');
72
73print load_fiche_titre($langs->trans("SupplierProposalArea"), '', 'supplier_proposal');
74
75print '<div class="fichecenter"><div class="fichethirdleft">';
76
77// Statistics
78
79$sql = "SELECT count(p.rowid), p.fk_statut";
80$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
81$sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
82if (!$user->hasRight('societe', 'client', 'voir')) {
83 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
84}
85$sql .= " WHERE p.fk_soc = s.rowid";
86$sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
87if ($user->socid) {
88 $sql .= ' AND p.fk_soc = '.((int) $user->socid);
89}
90if (!$user->hasRight('societe', 'client', 'voir')) {
91 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
92}
93$sql .= " AND p.fk_statut IN (0,1,2,3,4)";
94$sql .= " GROUP BY p.fk_statut";
95$resql = $db->query($sql);
96if ($resql) {
97 $vals = array();
98 while ($row = $db->fetch_row($resql)) {
99 $vals[$row[1]] = $row[0];
100 }
101 $db->free($resql);
102
103 $colors = getThemeBadgeStatusColors();
104 $colorofstatus = array(
105 SupplierProposal::STATUS_DRAFT => '-'.$colors[0],
109 SupplierProposal::STATUS_CLOSE => $colors[6],
110 );
111 $series = array();
112 foreach (array(0, 1, 2, 3, 4) as $status) {
113 $series[] = array(
114 'label' => $supplier_proposalstatic->LibStatut($status, 1),
115 'labelnojs' => $supplier_proposalstatic->LibStatut($status, 0),
116 'nb' => (isset($vals[$status]) ? (int) $vals[$status] : 0),
117 'color' => $colorofstatus[$status],
118 'url' => 'list.php?search_status='.$status,
119 );
120 }
121 print getStatusPieChart($langs->trans("Statistics").' - '.$langs->trans("CommRequests"), $series);
122} else {
123 dol_print_error($db);
124}
125
126
127/*
128 * Draft askprice
129 */
130if (isModEnabled('supplier_proposal')) {
131 $sql = "SELECT c.rowid, c.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client";
132 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
133 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
134 if (!$user->hasRight('societe', 'client', 'voir')) {
135 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
136 }
137 $sql .= " WHERE c.fk_soc = s.rowid";
138 $sql .= " AND c.entity = ".((int) $conf->entity);
139 $sql .= " AND c.fk_statut = 0";
140 if ($socid) {
141 $sql .= " AND c.fk_soc = ".((int) $socid);
142 }
143 if (!$user->hasRight('societe', 'client', 'voir')) {
144 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
145 }
146
147 $resql = $db->query($sql);
148 if ($resql) {
149 print '<div class="div-table-responsive-no-min">';
150 print '<table class="noborder centpercent">';
151 print '<tr class="liste_titre">';
152 print '<th colspan="2">'.$langs->trans("DraftRequests").'</th></tr>';
153 $langs->load("supplier_proposal");
154 $num = $db->num_rows($resql);
155 if ($num) {
156 $i = 0;
157 while ($i < $num) {
158 $obj = $db->fetch_object($resql);
159
160 print '<tr class="oddeven">';
161 $supplier_proposalstatic->id = $obj->rowid;
162 $supplier_proposalstatic->ref = $obj->ref;
163 print '<td class="nowrap">'.$supplier_proposalstatic->getNomUrl(1).'</td>';
164
165 $companystatic->id = $obj->socid;
166 $companystatic->name = $obj->socname;
167 $companystatic->client = $obj->client;
168 $companystatic->canvas = $obj->canvas;
169 print '<td>'.$companystatic->getNomUrl(1, 'customer', 24).'</td>';
170
171 print '</tr>';
172 $i++;
173 }
174 }
175 print "</table></div><br>";
176 }
177}
178
179print '</div><div class="fichetwothirdright">';
180
181
182$max = 5;
183
184/*
185 * Last modified askprice
186 */
187
188$sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as socname, s.rowid as socid, s.canvas, s.client,";
189$sql .= " date_cloture as datec";
190$sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
191$sql .= ", ".MAIN_DB_PREFIX."societe as s";
192if (!$user->hasRight('societe', 'client', 'voir')) {
193 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
194}
195$sql .= " WHERE c.fk_soc = s.rowid";
196$sql .= " AND c.entity = ".((int) $conf->entity);
197//$sql.= " AND c.fk_statut > 2";
198if ($socid) {
199 $sql .= " AND c.fk_soc = ".((int) $socid);
200}
201if (!$user->hasRight('societe', 'client', 'voir')) {
202 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
203}
204$sql .= " ORDER BY c.tms DESC";
205$sql .= $db->plimit($max, 0);
206
207$resql = $db->query($sql);
208if ($resql) {
209 print '<div class="div-table-responsive-no-min">';
210 print '<table class="noborder centpercent">';
211 print '<tr class="liste_titre">';
212 print '<th colspan="4">'.$langs->trans("LastModifiedRequests", $max).'</th></tr>';
213
214 $num = $db->num_rows($resql);
215 if ($num) {
216 $i = 0;
217 while ($i < $num) {
218 $obj = $db->fetch_object($resql);
219
220 print '<tr class="oddeven">';
221 print '<td width="20%" class="nowrap">';
222
223 $supplier_proposalstatic->id = $obj->rowid;
224 $supplier_proposalstatic->ref = $obj->ref;
225
226 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
227 print '<td width="96" class="nobordernopadding nowrap">';
228 print $supplier_proposalstatic->getNomUrl(1);
229 print '</td>';
230
231 print '<td width="16" class="nobordernopadding nowrap">';
232 print '&nbsp;';
233 print '</td>';
234
235 print '<td width="16" class="right nobordernopadding">';
236 $filename = dol_sanitizeFileName($obj->ref);
237 $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
238 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
239 print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
240 print '</td></tr></table>';
241
242 print '</td>';
243
244 $companystatic->id = $obj->socid;
245 $companystatic->name = $obj->socname;
246 $companystatic->client = $obj->client;
247 $companystatic->canvas = $obj->canvas;
248 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
249
250 print '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
251 print '<td class="right">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>';
252 print '</tr>';
253 $i++;
254 }
255 }
256 print "</table></div><br>";
257} else {
258 dol_print_error($db);
259}
260
261
262/*
263 * Opened askprice
264 */
265if (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')) {
266 $langs->load("supplier_proposal");
267
268 $now = dol_now();
269
270 $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";
271 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
272 $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
273 if (!$user->hasRight('societe', 'client', 'voir')) {
274 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
275 }
276 $sql .= " WHERE p.fk_soc = s.rowid";
277 $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
278 $sql .= " AND p.fk_statut = 1";
279 if (!$user->hasRight('societe', 'client', 'voir')) {
280 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
281 }
282 if ($socid) {
283 $sql .= " AND s.rowid = ".((int) $socid);
284 }
285 $sql .= " ORDER BY p.rowid DESC";
286
287 $result = $db->query($sql);
288 if ($result) {
289 $total = 0;
290 $num = $db->num_rows($result);
291 $i = 0;
292 if ($num > 0) {
293 print '<div class="div-table-responsive-no-min">';
294 print '<table class="noborder centpercent">';
295 print '<tr class="liste_titre"><th colspan="5">'.$langs->trans("RequestsOpened");
296 print ' <a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?search_status=1" alt="'.$langs->trans("GoOnList").'"><span class="badge">'.$num.'</span></a>';
297 print '</th></tr>';
298
299 $nbofloop = min($num, getDolGlobalString('MAIN_MAXLIST_OVERLOAD', 500));
300 while ($i < $nbofloop) {
301 $obj = $db->fetch_object($result);
302
303 print '<tr class="oddeven">';
304
305 // Ref
306 print '<td class="nowrap" width="140">';
307
308 $supplier_proposalstatic->id = $obj->supplier_proposalid;
309 $supplier_proposalstatic->ref = $obj->ref;
310
311 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
312 print '<td class="nobordernopadding nowrap">';
313 print $supplier_proposalstatic->getNomUrl(1);
314 print '</td>';
315 print '<td width="18" class="nobordernopadding nowrap">';
316 if (isset($obj->dfv) && $db->jdate($obj->dfv) < ($now - $conf->supplier_proposal->cloture->warning_delay)) {
317 print img_warning($langs->trans("Late"));
318 }
319 print '</td>';
320 print '<td width="16" class="center nobordernopadding">';
321 $filename = dol_sanitizeFileName($obj->ref);
322 $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
323 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->supplier_proposalid;
324 print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
325 print '</td></tr></table>';
326
327 print "</td>";
328
329 $companystatic->id = $obj->socid;
330 $companystatic->name = $obj->socname;
331 $companystatic->client = $obj->client;
332 $companystatic->canvas = $obj->canvas;
333 print '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>'."\n";
334
335 print '<td class="right">';
336 print dol_print_date($db->jdate($obj->dp), 'day').'</td>'."\n";
337 print '<td class="right">'.price($obj->total_ttc).'</td>';
338 print '<td class="center" width="14">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>'."\n";
339 print '</tr>'."\n";
340 $i++;
341 $total += $obj->total_ttc;
342 }
343 if ($num > $nbofloop) {
344 print '<tr class="liste_total"><td colspan="5">'.$langs->trans("XMoreLines", ($num - $nbofloop))."</td></tr>";
345 } elseif ($total > 0) {
346 print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total").'</td><td class="right">'.price($total)."</td><td>&nbsp;</td></tr>";
347 }
348 print "</table></div><br>";
349 }
350 } else {
351 dol_print_error($db);
352 }
353}
354
355print '</div></div>';
356
357$parameters = array('user' => $user);
358$reshook = $hookmanager->executeHooks('dashboardSupplierProposal', $parameters, $object); // Note that $action and $object may have been modified by hook
359
360// End of page
361llxFooter();
362$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 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.
getThemeBadgeStatusColors()
Return the colors of status badges defined by the current theme (theme_vars.inc.php)
getStatusPieChart($title, $series, $options=array())
Return the HTML table with a pie chart of values by status, as shown on the home page of a module.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
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).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.