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