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