dolibarr  16.0.5
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2005 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@capnetworks.com>
5  * Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
6  * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.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 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
31 
32 $hookmanager = new HookManager($db);
33 
34 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
35 $hookmanager->initHooks(array('receptionindex'));
36 
37 $langs->loadLangs(array("orders", "receptions"));
38 
39 $reception = new Reception($db);
40 
41 // Security check
42 $socid = '';
43 if ($user->socid) {
44  $socid = $user->socid;
45 }
46 $result = restrictedArea($user, 'reception', 0, '');
47 
48 
49 /*
50  * View
51  */
52 
53 $orderstatic = new CommandeFournisseur($db);
54 $companystatic = new Societe($db);
55 
56 $helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
57 llxHeader('', $langs->trans("Reception"), $helpurl);
58 
59 print load_fiche_titre($langs->trans("ReceptionsArea"), '', 'dollyrevert');
60 
61 
62 print '<div class="fichecenter"><div class="fichethirdleft">';
63 
64 
65 if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This may be useless due to the global search combo
66  print '<form method="post" action="list.php">';
67  print '<input type="hidden" name="token" value="'.newToken().'">';
68  print '<div class="div-table-responsive-no-min">';
69  print '<table class="noborder nohover centpercent">';
70  print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
71  print '<tr class="oddeven"><td>';
72  print $langs->trans("Reception").':</td><td><input type="text" class="flat" name="sall" size="18"></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
73  print "</table></div></form><br>\n";
74 }
75 
76 
77 /*
78  * Draft receptions
79  */
80 
81 $clause = " WHERE ";
82 
83 $sql = "SELECT e.rowid, e.ref, e.ref_supplier,";
84 $sql .= " s.nom as name, s.rowid as socid,";
85 $sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
86 $sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
87 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception'";
88 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid";
89 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
90 if (empty($user->rights->societe->client->voir) && !$socid) {
91  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
92  $sql .= $clause." sc.fk_user = ".((int) $user->id);
93  $clause = " AND ";
94 }
95 $sql .= $clause." e.fk_statut = 0";
96 $sql .= " AND e.entity IN (".getEntity('reception').")";
97 if ($socid) {
98  $sql .= " AND c.fk_soc = ".((int) $socid);
99 }
100 
101 $resql = $db->query($sql);
102 if ($resql) {
103  print '<div class="div-table-responsive-no-min">';
104  print '<table class="noborder centpercent">';
105  print '<tr class="liste_titre">';
106  print '<th colspan="3">'.$langs->trans("ReceptionsToValidate").'</th></tr>';
107 
108  $num = $db->num_rows($resql);
109  if ($num) {
110  $i = 0;
111  while ($i < $num) {
112  $obj = $db->fetch_object($resql);
113 
114  $reception->id = $obj->rowid;
115  $reception->ref = $obj->ref;
116  $reception->ref_supplier = $obj->ref_supplier;
117 
118  print '<tr class="oddeven"><td class="nowrap">';
119  print $reception->getNomUrl(1);
120  print "</td>";
121  print '<td>';
122  print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
123  print '</td>';
124  print '<td>';
125  if ($obj->commande_fournisseur_id) {
126  print '<a href="'.DOL_URL_ROOT.'/commande_fournisseur/card.php?id='.$obj->commande_fournisseur_id.'">'.$obj->commande_fournisseur_ref.'</a>';
127  }
128  print '</td></tr>';
129  $i++;
130  }
131  } else {
132  print '<tr><td><span class="opacitymedium">'.$langs->trans("None").'</span></td><td></td><td></td></tr>';
133  }
134 
135  print "</table></div><br>";
136 }
137 
138 
139 print '</div><div class="fichetwothirdright">';
140 
141 $max = 5;
142 
143 /*
144  * Latest receptions
145  */
146 
147 $sql = "SELECT e.rowid, e.ref, e.ref_supplier,";
148 $sql .= " s.nom as name, s.rowid as socid,";
149 $sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
150 $sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
151 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception' AND el.sourcetype IN ('order_supplier')";
152 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid AND el.sourcetype IN ('order_supplier') AND el.targettype = 'reception'";
153 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
154 if (empty($user->rights->societe->client->voir) && !$socid) {
155  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
156 }
157 $sql .= " WHERE e.entity IN (".getEntity('reception').")";
158 if (empty($user->rights->societe->client->voir) && !$socid) {
159  $sql .= " AND sc.fk_user = ".((int) $user->id);
160 }
161 $sql .= " AND e.fk_statut = 1";
162 if ($socid) {
163  $sql .= " AND c.fk_soc = ".((int) $socid);
164 }
165 $sql .= " ORDER BY e.date_delivery DESC";
166 $sql .= $db->plimit($max, 0);
167 
168 $resql = $db->query($sql);
169 if ($resql) {
170  $num = $db->num_rows($resql);
171  if ($num) {
172  $i = 0;
173  print '<div class="div-table-responsive-no-min">';
174  print '<table class="noborder centpercent">';
175  print '<tr class="liste_titre">';
176  print '<th colspan="3">'.$langs->trans("LastReceptions", $num).'</th></tr>';
177  while ($i < $num) {
178  $obj = $db->fetch_object($resql);
179 
180  $reception->id = $obj->rowid;
181  $reception->ref = $obj->ref;
182  $reception->ref_supplier = $obj->ref_supplier;
183 
184  print '<tr class="oddeven"><td>';
185  print $reception->getNomUrl(1);
186  print '</td>';
187  print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
188  print '<td>';
189  if ($obj->commande_fournisseur_id > 0) {
190  $orderstatic->id = $obj->commande_fournisseur_id;
191  $orderstatic->ref = $obj->commande_fournisseur_ref;
192  print $orderstatic->getNomUrl(1);
193  } else {
194  print '&nbsp;';
195  }
196  print '</td></tr>';
197  $i++;
198  }
199  print "</table></div><br>";
200  }
201  $db->free($resql);
202 } else {
203  dol_print_error($db);
204 }
205 
206 
207 
208 /*
209  * Open pruchase orders to process
210  */
211 
212 $sql = "SELECT c.rowid, c.ref, c.ref_supplier as ref_supplier, c.fk_statut as status, c.billed as billed, s.nom as name, s.rowid as socid";
213 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c,";
214 $sql .= " ".MAIN_DB_PREFIX."societe as s";
215 if (empty($user->rights->societe->client->voir) && !$socid) {
216  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
217 }
218 $sql .= " WHERE c.fk_soc = s.rowid";
219 $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
220 $sql .= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.")";
221 if ($socid > 0) {
222  $sql .= " AND c.fk_soc = ".((int) $socid);
223 }
224 if (empty($user->rights->societe->client->voir) && !$socid) {
225  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
226 }
227 $sql .= " ORDER BY c.rowid ASC";
228 $resql = $db->query($sql);
229 if ($resql) {
230  $num = $db->num_rows($resql);
231  if ($num) {
232  $langs->load("orders");
233 
234  $i = 0;
235  print '<div class="div-table-responsive-no-min">';
236  print '<table class="noborder centpercent">';
237  print '<tr class="liste_titre">';
238  print '<th colspan="3">'.$langs->trans("SuppliersOrdersToProcess").' <span class="badge">'.$num.'</span></th></tr>';
239  while ($i < $num) {
240  $obj = $db->fetch_object($resql);
241 
242  $orderstatic->id = $obj->rowid;
243  $orderstatic->ref = $obj->ref;
244  $orderstatic->ref_supplier = $obj->ref_supplier;
245  $orderstatic->statut = $obj->status;
246  $orderstatic->facturee = $obj->billed;
247 
248  $companystatic->name = $obj->name;
249  $companystatic->id = $obj->socid;
250 
251  print '<tr class="oddeven">';
252  print '<td class="nowrap">';
253  print $orderstatic->getNomUrl(1);
254  print '</td>';
255  print '<td>';
256  print $companystatic->getNomUrl(1, 'customer', 32);
257  print '</td>';
258  print '<td class="right">';
259  print $orderstatic->getLibStatut(3);
260  print '</td>';
261  print '</tr>';
262  $i++;
263  }
264  print "</table></div><br>";
265  }
266 }
267 
268 print '</div></div>';
269 
270 $parameters = array('user' => $user);
271 $reshook = $hookmanager->executeHooks('dashboardWarehouseReceptions', $parameters, $object); // Note that $action and $object may have been modified by hook
272 
273 llxFooter();
274 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
Reception
Class to manage receptions.
Definition: reception.class.php:49
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
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
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
CommandeFournisseur\STATUS_RECEIVED_PARTIALLY
const STATUS_RECEIVED_PARTIALLY
Received partially.
Definition: fournisseur.commande.class.php:288
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30