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