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