dolibarr 24.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-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.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';
37require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
38require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
39require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
40
41
42$langs->loadLangs(array("suppliers", "orders", "companies"));
43
44// Security check
45$socid = GETPOSTINT("socid");
46if ($user->isExternalUser()) {
47 $socid = $user->isExternalUser();
48}
49$result = restrictedArea($user, 'societe', $socid, '');
50
51
52/*
53 * View
54 */
55
56$commandestatic = new CommandeFournisseur($db);
57$facturestatic = new FactureFournisseur($db);
58$companystatic = new Societe($db);
59
60llxHeader("", $langs->trans("SuppliersArea"), '', '', 0, 0, '', '', '', 'mod-fourn-facture page-index');
61
62print load_fiche_titre($langs->trans("SuppliersArea"));
63
64
65//print '<table border="0" width="100%" class="notopnoleftnoright">';
66//print '<tr><td valign="top" width="30%" class="notopnoleft">';
67print '<div class="fichecenter"><div class="fichethirdleft">';
68
69
70// Orders
71$sql = "SELECT count(cf.rowid), cf.fk_statut";
72$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf,";
73$sql .= " ".MAIN_DB_PREFIX."societe as s";
74if (!$user->hasRight("societe", "client", "voir") && !$socid) {
75 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
76}
77$sql .= " WHERE cf.fk_soc = s.rowid ";
78if (!$user->hasRight("societe", "client", "voir") && !$socid) {
79 $sql .= " AND sc.fk_user = ".((int) $user->id);
80}
81$sql .= " AND cf.entity = ".$conf->entity;
82$sql .= " GROUP BY cf.fk_statut";
83
84$resql = $db->query($sql);
85if ($resql) {
86 $num = $db->num_rows($resql);
87 $i = 0;
88
89 print '<table class="noborder centpercent">';
90 print '<tr class="liste_titre"><td>'.$langs->trans("Orders").'</td><td class="center">'.$langs->trans("Nb").'</td><td>&nbsp;</td>';
91 print "</tr>\n";
92
93 while ($i < $num) {
94 $row = $db->fetch_row($resql);
95
96 print '<tr class="oddeven">';
97 print '<td>'.$commandestatic->LibStatut($row[1]).'</td>';
98 print '<td class="center">'.$row[0].'</td>';
99 print '<td class="center"><a href="'.DOL_URL_ROOT.'/fourn/commande/list.php?statut='.$row[1].'">'.$commandestatic->LibStatut($row[1], 3).'</a></td>';
100
101 print "</tr>\n";
102 $i++;
103 }
104 print "</table>";
105 print "<br>\n";
106 $db->free($resql);
107} else {
109}
110
111
112// Draft orders
113if (isModEnabled("supplier_order")) {
114 $langs->load("orders");
115
116 $sql = "SELECT cf.rowid, cf.ref, cf.total_ttc,";
117 $sql .= " s.nom as name, s.rowid as socid";
118 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
119 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
120 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
121 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
122 }
123 $sql .= " WHERE cf.fk_soc = s.rowid";
124 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
125 $sql .= " AND sc.fk_user = ".((int) $user->id);
126 }
127 $sql .= " AND cf.entity = ".$conf->entity;
128 $sql .= " AND cf.fk_statut = 0";
129 if ($socid) {
130 $sql .= " AND cf.fk_soc = ".((int) $socid);
131 }
132
133 $resql = $db->query($sql);
134 if ($resql) {
135 $total = 0;
136 $num = $db->num_rows($resql);
137 if ($num) {
138 print '<table class="noborder centpercent">';
139 print '<tr class="liste_titre">';
140 print '<td colspan="3">'.$langs->trans("DraftOrders").'<span class="badge marginleftonlyshort">'.$num.'</span></td></tr>';
141
142 $i = 0;
143 while ($i < $num) {
144 $obj = $db->fetch_object($resql);
145
146 print '<tr class="oddeven"><td class="nowrap">';
147 $commandestatic->id = $obj->rowid;
148 $commandestatic->ref = $obj->ref;
149 print $commandestatic->getNomUrl(1, '', 16);
150 print '</td>';
151 print '<td class="nowrap">';
152 $companystatic->id = $obj->socid;
153 $companystatic->name = $obj->name;
154 $companystatic->client = 0;
155 print $companystatic->getNomUrl(1, '', 16);
156 print '</td>';
157 print '<td class="right nowrap">'.price($obj->total_ttc).'</td></tr>';
158 $i++;
159 $total += $obj->total_ttc;
160 }
161 if ($total > 0) {
162 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" class="right">'.price($total)."</td></tr>";
163 }
164 print "</table>";
165 print "<br>\n";
166 }
167 }
168}
169
170// Draft invoices
171if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
172 $sql = "SELECT ff.ref_supplier, ff.rowid, ff.total_ttc, ff.type";
173 $sql .= ", s.nom as name, s.rowid as socid";
174 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as ff";
175 $sql .= ", ".MAIN_DB_PREFIX."societe as s";
176 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
177 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
178 }
179 $sql .= " WHERE s.rowid = ff.fk_soc";
180 if (!$user->hasRight("societe", "client", "voir") && !$socid) {
181 $sql .= " AND sc.fk_user = ".((int) $user->id);
182 }
183 $sql .= " AND ff.entity = ".$conf->entity;
184 $sql .= " AND ff.fk_statut = 0";
185 if ($socid) {
186 $sql .= " AND f.fk_soc = ".((int) $socid);
187 }
188
189 $resql = $db->query($sql);
190
191 if ($resql) {
192 $num = $db->num_rows($resql);
193 if ($num) {
194 print '<table class="noborder centpercent">';
195 print '<tr class="liste_titre">';
196 print '<td colspan="3">'.$langs->trans("DraftBills").'<span class="badge marginleftonlyshort">'.$num.'</span></td></tr>';
197 $i = 0;
198 $tot_ttc = 0;
199
200 while ($i < $num && $i < 20) {
201 $obj = $db->fetch_object($resql);
202
203 print '<tr class="oddeven"><td class="nowrap">';
204 $facturestatic->ref = $obj->ref;
205 $facturestatic->id = $obj->rowid;
206 $facturestatic->type = $obj->type;
207 print $facturestatic->getNomUrl(1, '');
208 print '</td>';
209 print '<td class="nowrap">';
210 $companystatic->id = $obj->socid;
211 $companystatic->name = $obj->name;
212 $companystatic->client = 0;
213 print $companystatic->getNomUrl(1, '', 16);
214 print '</td>';
215 print '<td class="right">'.price($obj->total_ttc).'</td>';
216 print '</tr>';
217 $tot_ttc += $obj->total_ttc;
218 $i++;
219 }
220
221 print '<tr class="liste_total"><td class="left">'.$langs->trans("Total").'</td>';
222 print '<td colspan="2" class="right">'.price($tot_ttc).'</td>';
223 print '</tr>';
224
225 print "</table>";
226 print "<br>\n";
227 }
228 $db->free($resql);
229 } else {
231 }
232}
233
234
235print '</div><div class="fichetwothirdright">';
236
237
238/*
239 * List last modified supliers
240 */
241$max = 10;
242$sql = "SELECT s.rowid as socid, s.nom as name, s.town, s.datec, s.tms, s.prefix_comm, s.code_fournisseur";
243if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
244 $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
245} else {
246 $sql .= ", s.code_compta_fournisseur";
247}
248$sql .= ", st.libelle as stcomm";
249$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
250if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
251 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
252}
253$sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st";
254if (!$user->hasRight("societe", "client", "voir") && !$socid) {
255 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
256}
257$sql .= " WHERE s.fk_stcomm = st.id";
258$sql .= " AND s.fournisseur = 1";
259$sql .= " AND s.entity IN (".getEntity('societe').")";
260if (!$user->hasRight("societe", "client", "voir") && !$socid) {
261 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
262}
263if ($socid) {
264 $sql .= " AND s.rowid = ".((int) $socid);
265}
266$sql .= " ORDER BY s.tms DESC";
267$sql .= $db->plimit($max, 0);
268
269$resql = $db->query($sql);
270if ($resql) {
271 $langs->load("boxes");
272 $num = $db->num_rows($resql);
273 $i = 0;
274
275 print '<table class="noborder centpercent">';
276 print '<tr class="liste_titre">';
277 print '<td colspan="2">'.$langs->trans("BoxTitleLastSuppliers", min($max, $num))."</td>\n";
278 print '<td class="right">'.$langs->trans("DateModification")."</td>\n";
279 print "</tr>\n";
280
281 while ($obj = $db->fetch_object($resql)) {
282 print '<tr class="oddeven">';
283 print '<td><a href="card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowSupplier"), "company").'</a>';
284 print "&nbsp;<a href=\"card.php?socid=".$obj->socid."\">".$obj->name."</a></td>\n";
285 print '<td class="left">'.$obj->code_fournisseur.'&nbsp;</td>';
286 print '<td class="right">'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
287 print "</tr>\n";
288 }
289 print "</table>\n";
290
291 $db->free($resql);
292} else {
294}
295
296
297/*
298 * List of suppliers categories
299 */
300$companystatic->LoadSupplierCateg();
301$categstatic = new Categorie($db);
302
303if (count($companystatic->SupplierCategories)) {
304 print '<br>';
305
306 print '<table class="liste centpercent">';
307 print '<tr class="liste_titre"><td colspan="2">';
308 print $langs->trans("Category");
309 print "</td></tr>\n";
310
311 foreach ($companystatic->SupplierCategories as $rowid => $label) {
312 print '<tr class="oddeven">'."\n";
313 print '<td>';
314 $categstatic->id = (int) $rowid;
315 $categstatic->ref = $label;
316 $categstatic->label = $label;
317 print $categstatic->getNomUrl(1);
318 print '</td>'."\n";
319 // TODO this page not exist
320 /*
321 print '<td class="right">';
322 print '<a href="stats.php?cat='.$rowid.'">('.$langs->trans("Stats").')</a>';
323 print "</tr>\n";
324 */
325 }
326 print "</table>\n";
327 print "<br>\n";
328}
329
330
331print '</div></div>';
332
333// End of page
334llxFooter();
335$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 manage categories.
Class to manage predefined suppliers products.
Class to manage suppliers invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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...
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.