dolibarr 21.0.0-beta
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
30require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
31require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
32
41$langs->loadLangs(array("suppliers", "orders", "companies"));
42
43// Security check
44$socid = GETPOSTINT("socid");
45if ($user->socid) {
46 $socid = $user->socid;
47}
48$result = restrictedArea($user, 'societe', $socid, '');
49
50
51/*
52 * View
53 */
54
55$commandestatic = new CommandeFournisseur($db);
56$facturestatic = new FactureFournisseur($db);
57$companystatic = new Societe($db);
58
59llxHeader("", $langs->trans("SuppliersArea"), '', '', 0, 0, '', '', '', 'mod-fourn-facture page-index');
60
61print load_fiche_titre($langs->trans("SuppliersArea"));
62
63
64//print '<table border="0" width="100%" class="notopnoleftnoright">';
65//print '<tr><td valign="top" width="30%" class="notopnoleft">';
66print '<div class="fichecenter"><div class="fichethirdleft">';
67
68
69// Orders
70$sql = "SELECT count(cf.rowid), cf.fk_statut";
71$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf,";
72$sql .= " ".MAIN_DB_PREFIX."societe as s";
73if (!$user->hasRight("societe", "client", "voir") && !$socid) {
74 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
75}
76$sql .= " WHERE cf.fk_soc = s.rowid ";
77if (!$user->hasRight("societe", "client", "voir") && !$socid) {
78 $sql .= " AND sc.fk_user = ".((int) $user->id);
79}
80$sql .= " AND cf.entity = ".$conf->entity;
81$sql .= " GROUP BY cf.fk_statut";
82
83$resql = $db->query($sql);
84if ($resql) {
85 $num = $db->num_rows($resql);
86 $i = 0;
87
88 print '<table class="noborder centpercent">';
89 print '<tr class="liste_titre"><td>'.$langs->trans("Orders").'</td><td class="center">'.$langs->trans("Nb").'</td><td>&nbsp;</td>';
90 print "</tr>\n";
91
92 while ($i < $num) {
93 $row = $db->fetch_row($resql);
94
95 print '<tr class="oddeven">';
96 print '<td>'.$commandestatic->LibStatut($row[1]).'</td>';
97 print '<td class="center">'.$row[0].'</td>';
98 print '<td class="center"><a href="'.DOL_URL_ROOT.'/fourn/commande/list.php?statut='.$row[1].'">'.$commandestatic->LibStatut($row[1], 3).'</a></td>';
99
100 print "</tr>\n";
101 $i++;
102 }
103 print "</table>";
104 print "<br>\n";
105 $db->free($resql);
106} else {
107 dol_print_error($db);
108}
109
110
111// Draft orders
112if (isModEnabled("supplier_order")) {
113 $langs->load("orders");
114
115 $sql = "SELECT cf.rowid, cf.ref, cf.total_ttc,";
116 $sql .= " s.nom as name, s.rowid as socid";
117 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
118 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
119 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
120 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
121 }
122 $sql .= " WHERE cf.fk_soc = s.rowid";
123 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
124 $sql .= " AND sc.fk_user = ".((int) $user->id);
125 }
126 $sql .= " AND cf.entity = ".$conf->entity;
127 $sql .= " AND cf.fk_statut = 0";
128 if ($socid) {
129 $sql .= " AND cf.fk_soc = ".((int) $socid);
130 }
131
132 $resql = $db->query($sql);
133 if ($resql) {
134 $total = 0;
135 $num = $db->num_rows($resql);
136 if ($num) {
137 print '<table class="noborder centpercent">';
138 print '<tr class="liste_titre">';
139 print '<td colspan="3">'.$langs->trans("DraftOrders").'<span class="badge marginleftonlyshort">'.$num.'</span></td></tr>';
140
141 $i = 0;
142 while ($i < $num) {
143 $obj = $db->fetch_object($resql);
144
145 print '<tr class="oddeven"><td class="nowrap">';
146 $commandestatic->id = $obj->rowid;
147 $commandestatic->ref = $obj->ref;
148 print $commandestatic->getNomUrl(1, '', 16);
149 print '</td>';
150 print '<td class="nowrap">';
151 $companystatic->id = $obj->socid;
152 $companystatic->name = $obj->name;
153 $companystatic->client = 0;
154 print $companystatic->getNomUrl(1, '', 16);
155 print '</td>';
156 print '<td class="right nowrap">'.price($obj->total_ttc).'</td></tr>';
157 $i++;
158 $total += $obj->total_ttc;
159 }
160 if ($total > 0) {
161 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" class="right">'.price($total)."</td></tr>";
162 }
163 print "</table>";
164 print "<br>\n";
165 }
166 }
167}
168
169// Draft invoices
170if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
171 $sql = "SELECT ff.ref_supplier, ff.rowid, ff.total_ttc, ff.type";
172 $sql .= ", s.nom as name, s.rowid as socid";
173 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
174 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
175 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
176 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
177 }
178 $sql .= " WHERE s.rowid = ff.fk_soc";
179 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
180 $sql .= " AND sc.fk_user = ".((int) $user->id);
181 }
182 $sql .= " AND ff.entity = ".$conf->entity;
183 $sql .= " AND ff.fk_statut = 0";
184 if ($socid) {
185 $sql .= " AND f.fk_soc = ".((int) $socid);
186 }
187
188 $resql = $db->query($sql);
189
190 if ($resql) {
191 $num = $db->num_rows($resql);
192 if ($num) {
193 print '<table class="noborder centpercent">';
194 print '<tr class="liste_titre">';
195 print '<td colspan="3">'.$langs->trans("DraftBills").'<span class="badge marginleftonlyshort">'.$num.'</span></td></tr>';
196 $i = 0;
197 $tot_ttc = 0;
198
199 while ($i < $num && $i < 20) {
200 $obj = $db->fetch_object($resql);
201
202 print '<tr class="oddeven"><td class="nowrap">';
203 $facturestatic->ref = $obj->ref;
204 $facturestatic->id = $obj->rowid;
205 $facturestatic->type = $obj->type;
206 print $facturestatic->getNomUrl(1, '');
207 print '</td>';
208 print '<td class="nowrap">';
209 $companystatic->id = $obj->socid;
210 $companystatic->name = $obj->name;
211 $companystatic->client = 0;
212 print $companystatic->getNomUrl(1, '', 16);
213 print '</td>';
214 print '<td class="right">'.price($obj->total_ttc).'</td>';
215 print '</tr>';
216 $tot_ttc += $obj->total_ttc;
217 $i++;
218 }
219
220 print '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
221 print '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
222 print '</tr>';
223
224 print "</table>";
225 print "<br>\n";
226 }
227 $db->free($resql);
228 } else {
229 dol_print_error($db);
230 }
231}
232
233
234print '</div><div class="fichetwothirdright">';
235
236
237/*
238 * List last modified supliers
239 */
240$max = 10;
241$sql = "SELECT s.rowid as socid, s.nom as name, s.town, s.datec, s.tms, s.prefix_comm, s.code_fournisseur";
242if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
243 $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
244} else {
245 $sql .= ", s.code_compta_fournisseur";
246}
247$sql .= ", st.libelle as stcomm";
248$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
249if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
250 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
251}
252$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st";
253if (!$user->hasRight("societe", "client", "voir") && !$socid) {
254 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
255}
256$sql .= " WHERE s.fk_stcomm = st.id";
257$sql .= " AND s.fournisseur = 1";
258$sql .= " AND s.entity IN (".getEntity('societe').")";
259if (!$user->hasRight("societe", "client", "voir") && !$socid) {
260 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
261}
262if ($socid) {
263 $sql .= " AND s.rowid = ".((int) $socid);
264}
265$sql .= " ORDER BY s.tms DESC";
266$sql .= $db->plimit($max, 0);
267
268$resql = $db->query($sql);
269if ($resql) {
270 $langs->load("boxes");
271 $num = $db->num_rows($resql);
272 $i = 0;
273
274 print '<table class="noborder centpercent">';
275 print '<tr class="liste_titre">';
276 print '<td colspan="2">'.$langs->trans("BoxTitleLastSuppliers", min($max, $num))."</td>\n";
277 print '<td class="right">'.$langs->trans("DateModification")."</td>\n";
278 print "</tr>\n";
279
280 while ($obj = $db->fetch_object($resql)) {
281 print '<tr class="oddeven">';
282 print '<td><a href="card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowSupplier"), "company").'</a>';
283 print "&nbsp;<a href=\"card.php?socid=".$obj->socid."\">".$obj->name."</a></td>\n";
284 print '<td class="left">'.$obj->code_fournisseur.'&nbsp;</td>';
285 print '<td class="right">'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
286 print "</tr>\n";
287 }
288 print "</table>\n";
289
290 $db->free($resql);
291} else {
292 dol_print_error($db);
293}
294
295
296/*
297 * List of suppliers categories
298 */
299$companystatic->LoadSupplierCateg();
300$categstatic = new Categorie($db);
301
302if (count($companystatic->SupplierCategories)) {
303 print '<br>';
304
305 print '<table class="liste centpercent">';
306 print '<tr class="liste_titre"><td colspan="2">';
307 print $langs->trans("Category");
308 print "</td></tr>\n";
309
310 foreach ($companystatic->SupplierCategories as $rowid => $label) {
311 print '<tr class="oddeven">'."\n";
312 print '<td>';
313 $categstatic->id = $rowid;
314 $categstatic->ref = $label;
315 $categstatic->label = $label;
316 print $categstatic->getNomUrl(1);
317 print '</td>'."\n";
318 // TODO this page not exist
319 /*
320 print '<td class="right">';
321 print '<a href="stats.php?cat='.$rowid.'">('.$langs->trans("Stats").')</a>';
322 print "</tr>\n";
323 */
324 }
325 print "</table>\n";
326 print "<br>\n";
327}
328
329
330print '</div></div>';
331
332// End of page
333llxFooter();
334$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 manage categories.
Class to manage predefined suppliers products.
Class to manage suppliers invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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_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.