dolibarr 21.0.0-beta
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 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
118 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
119
120 print '<div class="div-table-responsive-no-min">';
121 print '<table class="noborder centpercent">';
122 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("CommRequests").'</th></tr>'."\n";
123 $listofstatus = array(0, 1, 2, 3, 4);
124 foreach ($listofstatus as $status) {
125 $dataseries[] = array($supplier_proposalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
126 if ($status == SupplierProposal::STATUS_DRAFT) {
127 $colorseries[$status] = '-'.$badgeStatus0;
128 }
129 if ($status == SupplierProposal::STATUS_VALIDATED) {
130 $colorseries[$status] = $badgeStatus1;
131 }
132 if ($status == SupplierProposal::STATUS_SIGNED) {
133 $colorseries[$status] = $badgeStatus4;
134 }
135 if ($status == SupplierProposal::STATUS_NOTSIGNED) {
136 $colorseries[$status] = $badgeStatus9;
137 }
138 if ($status == SupplierProposal::STATUS_CLOSE) {
139 $colorseries[$status] = $badgeStatus6;
140 }
141
142 if (empty($conf->use_javascript_ajax)) {
143 print '<tr class="oddeven">';
144 print '<td>'.$supplier_proposalstatic->LibStatut($status, 0).'</td>';
145 print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
146 print "</tr>\n";
147 }
148 }
149 if ($conf->use_javascript_ajax) {
150 print '<tr><td class="center" colspan="2">';
151
152 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
153 $dolgraph = new DolGraph();
154 $dolgraph->SetData($dataseries);
155 $dolgraph->SetDataColor(array_values($colorseries));
156 $dolgraph->setShowLegend(2);
157 $dolgraph->setShowPercent(1);
158 $dolgraph->SetType(array('pie'));
159 $dolgraph->setHeight('200');
160 $dolgraph->draw('idgraphstatus');
161 print $dolgraph->show($total ? 0 : 1);
162
163 print '</td></tr>';
164 }
165
166 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
167 print "</table></div><br>";
168} else {
169 dol_print_error($db);
170}
171
172
173/*
174 * Draft askprice
175 */
176if (isModEnabled('supplier_proposal')) {
177 $sql = "SELECT c.rowid, c.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client";
178 $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
179 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
180 if (!$user->hasRight('societe', 'client', 'voir')) {
181 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
182 }
183 $sql .= " WHERE c.fk_soc = s.rowid";
184 $sql .= " AND c.entity = ".$conf->entity;
185 $sql .= " AND c.fk_statut = 0";
186 if ($socid) {
187 $sql .= " AND c.fk_soc = ".((int) $socid);
188 }
189 if (!$user->hasRight('societe', 'client', 'voir')) {
190 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
191 }
192
193 $resql = $db->query($sql);
194 if ($resql) {
195 print '<div class="div-table-responsive-no-min">';
196 print '<table class="noborder centpercent">';
197 print '<tr class="liste_titre">';
198 print '<th colspan="2">'.$langs->trans("DraftRequests").'</th></tr>';
199 $langs->load("supplier_proposal");
200 $num = $db->num_rows($resql);
201 if ($num) {
202 $i = 0;
203 while ($i < $num) {
204 $obj = $db->fetch_object($resql);
205
206 print '<tr class="oddeven">';
207 $supplier_proposalstatic->id = $obj->rowid;
208 $supplier_proposalstatic->ref = $obj->ref;
209 print '<td class="nowrap">'.$supplier_proposalstatic->getNomUrl(1).'</td>';
210
211 $companystatic->id = $obj->socid;
212 $companystatic->name = $obj->socname;
213 $companystatic->client = $obj->client;
214 $companystatic->canvas = $obj->canvas;
215 print '<td>'.$companystatic->getNomUrl(1, 'customer', 24).'</td>';
216
217 print '</tr>';
218 $i++;
219 }
220 }
221 print "</table></div><br>";
222 }
223}
224
225print '</div><div class="fichetwothirdright">';
226
227
228$max = 5;
229
230/*
231 * Last modified askprice
232 */
233
234$sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as socname, s.rowid as socid, s.canvas, s.client,";
235$sql .= " date_cloture as datec";
236$sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
237$sql .= ", ".MAIN_DB_PREFIX."societe as s";
238if (!$user->hasRight('societe', 'client', 'voir')) {
239 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
240}
241$sql .= " WHERE c.fk_soc = s.rowid";
242$sql .= " AND c.entity = ".$conf->entity;
243//$sql.= " AND c.fk_statut > 2";
244if ($socid) {
245 $sql .= " AND c.fk_soc = ".((int) $socid);
246}
247if (!$user->hasRight('societe', 'client', 'voir')) {
248 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
249}
250$sql .= " ORDER BY c.tms DESC";
251$sql .= $db->plimit($max, 0);
252
253$resql = $db->query($sql);
254if ($resql) {
255 print '<div class="div-table-responsive-no-min">';
256 print '<table class="noborder centpercent">';
257 print '<tr class="liste_titre">';
258 print '<th colspan="4">'.$langs->trans("LastModifiedRequests", $max).'</th></tr>';
259
260 $num = $db->num_rows($resql);
261 if ($num) {
262 $i = 0;
263 while ($i < $num) {
264 $obj = $db->fetch_object($resql);
265
266 print '<tr class="oddeven">';
267 print '<td width="20%" class="nowrap">';
268
269 $supplier_proposalstatic->id = $obj->rowid;
270 $supplier_proposalstatic->ref = $obj->ref;
271
272 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
273 print '<td width="96" class="nobordernopadding nowrap">';
274 print $supplier_proposalstatic->getNomUrl(1);
275 print '</td>';
276
277 print '<td width="16" class="nobordernopadding nowrap">';
278 print '&nbsp;';
279 print '</td>';
280
281 print '<td width="16" class="right nobordernopadding">';
282 $filename = dol_sanitizeFileName($obj->ref);
283 $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
284 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
285 print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
286 print '</td></tr></table>';
287
288 print '</td>';
289
290 $companystatic->id = $obj->socid;
291 $companystatic->name = $obj->socname;
292 $companystatic->client = $obj->client;
293 $companystatic->canvas = $obj->canvas;
294 print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
295
296 print '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
297 print '<td class="right">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>';
298 print '</tr>';
299 $i++;
300 }
301 }
302 print "</table></div><br>";
303} else {
304 dol_print_error($db);
305}
306
307
308/*
309 * Opened askprice
310 */
311if (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')) {
312 $langs->load("supplier_proposal");
313
314 $now = dol_now();
315
316 $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";
317 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
318 $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
319 if (!$user->hasRight('societe', 'client', 'voir')) {
320 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
321 }
322 $sql .= " WHERE p.fk_soc = s.rowid";
323 $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
324 $sql .= " AND p.fk_statut = 1";
325 if (!$user->hasRight('societe', 'client', 'voir')) {
326 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
327 }
328 if ($socid) {
329 $sql .= " AND s.rowid = ".((int) $socid);
330 }
331 $sql .= " ORDER BY p.rowid DESC";
332
333 $result = $db->query($sql);
334 if ($result) {
335 $total = 0;
336 $num = $db->num_rows($result);
337 $i = 0;
338 if ($num > 0) {
339 print '<div class="div-table-responsive-no-min">';
340 print '<table class="noborder centpercent">';
341 print '<tr class="liste_titre"><th colspan="5">'.$langs->trans("RequestsOpened");
342 print ' <a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?search_status=1" alt="'.$langs->trans("GoOnList").'"><span class="badge">'.$num.'</span></a>';
343 print '</th></tr>';
344
345 $nbofloop = min($num, (!getDolGlobalString('MAIN_MAXLIST_OVERLOAD') ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
346 while ($i < $nbofloop) {
347 $obj = $db->fetch_object($result);
348
349 print '<tr class="oddeven">';
350
351 // Ref
352 print '<td class="nowrap" width="140">';
353
354 $supplier_proposalstatic->id = $obj->supplier_proposalid;
355 $supplier_proposalstatic->ref = $obj->ref;
356
357 print '<table class="nobordernopadding"><tr class="nocellnopadd">';
358 print '<td class="nobordernopadding nowrap">';
359 print $supplier_proposalstatic->getNomUrl(1);
360 print '</td>';
361 print '<td width="18" class="nobordernopadding nowrap">';
362 if ($db->jdate($obj->dfv) < ($now - $conf->supplier_proposal->cloture->warning_delay)) {
363 print img_warning($langs->trans("Late"));
364 }
365 print '</td>';
366 print '<td width="16" class="center nobordernopadding">';
367 $filename = dol_sanitizeFileName($obj->ref);
368 $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
369 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->supplier_proposalid;
370 print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
371 print '</td></tr></table>';
372
373 print "</td>";
374
375 $companystatic->id = $obj->socid;
376 $companystatic->name = $obj->socname;
377 $companystatic->client = $obj->client;
378 $companystatic->canvas = $obj->canvas;
379 print '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>'."\n";
380
381 print '<td class="right">';
382 print dol_print_date($db->jdate($obj->dp), 'day').'</td>'."\n";
383 print '<td class="right">'.price($obj->total_ttc).'</td>';
384 print '<td class="center" width="14">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>'."\n";
385 print '</tr>'."\n";
386 $i++;
387 $total += $obj->total_ttc;
388 }
389 if ($num > $nbofloop) {
390 print '<tr class="liste_total"><td colspan="5">'.$langs->trans("XMoreLines", ($num - $nbofloop))."</td></tr>";
391 } elseif ($total > 0) {
392 print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total").'</td><td class="right">'.price($total)."</td><td>&nbsp;</td></tr>";
393 }
394 print "</table></div><br>";
395 }
396 } else {
397 dol_print_error($db);
398 }
399}
400
401print '</div></div>';
402
403$parameters = array('user' => $user);
404$reshook = $hookmanager->executeHooks('dashboardSupplierProposal', $parameters, $object); // Note that $action and $object may have been modified by hook
405
406// End of page
407llxFooter();
408$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:71
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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.