dolibarr 21.0.0-alpha
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 a 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, '', 0, 0, '', '', '', 'mod-reception page-dashboard');
59
60print load_fiche_titre($langs->trans("ReceptionsArea"), '', 'dollyrevert');
61
62
63print '<div class="fichecenter"><div class="fichethirdleft">';
64
65
66if (getDolGlobalString('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$sql = "SELECT e.rowid, e.ref, e.ref_supplier,";
83$sql .= " s.nom as name, s.rowid as socid,";
84$sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
85$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
86$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception'";
87$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid";
88$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
89if (!$user->hasRight('societe', 'client', 'voir')) {
90 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = e.fk_soc AND sc.fk_user = ".((int) $user->id).")";
91}
92$sql .= " WHERE e.fk_statut = 0";
93$sql .= " AND e.entity IN (".getEntity('reception').")";
94if ($socid) {
95 $sql .= " AND c.fk_soc = ".((int) $socid);
96}
97
98$resql = $db->query($sql);
99if ($resql) {
100 print '<div class="div-table-responsive-no-min">';
101 print '<table class="noborder centpercent">';
102 print '<tr class="liste_titre">';
103 print '<th colspan="3">'.$langs->trans("ReceptionsToValidate").'</th></tr>';
104
105 $num = $db->num_rows($resql);
106 if ($num) {
107 $i = 0;
108 while ($i < $num) {
109 $obj = $db->fetch_object($resql);
110
111 $reception->id = $obj->rowid;
112 $reception->ref = $obj->ref;
113 $reception->ref_supplier = $obj->ref_supplier;
114
115 print '<tr class="oddeven"><td class="nowrap">';
116 print $reception->getNomUrl(1);
117 print "</td>";
118 print '<td>';
119 print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
120 print '</td>';
121 print '<td>';
122 if ($obj->commande_fournisseur_id) {
123 print '<a href="'.DOL_URL_ROOT.'/commande_fournisseur/card.php?id='.$obj->commande_fournisseur_id.'">'.$obj->commande_fournisseur_ref.'</a>';
124 }
125 print '</td></tr>';
126 $i++;
127 }
128 } else {
129 print '<tr><td><span class="opacitymedium">'.$langs->trans("None").'</span></td><td></td><td></td></tr>';
130 }
131
132 print "</table></div><br>";
133}
134
135
136print '</div><div class="fichetwothirdright">';
137
138$max = 5;
139
140/*
141 * Latest receptions
142 */
143
144$sql = "SELECT e.rowid, e.ref, e.ref_supplier,";
145$sql .= " s.nom as name, s.rowid as socid,";
146$sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
147$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
148$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')";
149$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'";
150$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
151if (!$user->hasRight('societe', 'client', 'voir')) {
152 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
153}
154$sql .= " WHERE e.entity IN (".getEntity('reception').")";
155if (!$user->hasRight('societe', 'client', 'voir')) {
156 $sql .= " AND sc.fk_user = ".((int) $user->id);
157}
158$sql .= " AND e.fk_statut = 1";
159if ($socid) {
160 $sql .= " AND c.fk_soc = ".((int) $socid);
161}
162$sql .= " ORDER BY e.date_delivery DESC";
163$sql .= $db->plimit($max, 0);
164
165$resql = $db->query($sql);
166if ($resql) {
167 $num = $db->num_rows($resql);
168 if ($num) {
169 $i = 0;
170 print '<div class="div-table-responsive-no-min">';
171 print '<table class="noborder centpercent">';
172 print '<tr class="liste_titre">';
173 print '<th colspan="3">'.$langs->trans("LastReceptions", $num).'</th></tr>';
174 while ($i < $num) {
175 $obj = $db->fetch_object($resql);
176
177 $reception->id = $obj->rowid;
178 $reception->ref = $obj->ref;
179 $reception->ref_supplier = $obj->ref_supplier;
180
181 print '<tr class="oddeven"><td>';
182 print $reception->getNomUrl(1);
183 print '</td>';
184 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
185 print '<td>';
186 if ($obj->commande_fournisseur_id > 0) {
187 $orderstatic->id = $obj->commande_fournisseur_id;
188 $orderstatic->ref = $obj->commande_fournisseur_ref;
189 print $orderstatic->getNomUrl(1);
190 } else {
191 print '&nbsp;';
192 }
193 print '</td></tr>';
194 $i++;
195 }
196 print "</table></div><br>";
197 }
198 $db->free($resql);
199} else {
200 dol_print_error($db);
201}
202
203
204
205/*
206 * Open pruchase orders to process
207 */
208
209$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";
210$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c,";
211$sql .= " ".MAIN_DB_PREFIX."societe as s";
212$sql .= " WHERE c.fk_soc = s.rowid";
213$sql .= " AND c.entity IN (".getEntity('supplier_order').")";
214$sql .= " AND c.fk_statut IN (".CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.")";
215if ($socid > 0) {
216 $sql .= " AND c.fk_soc = ".((int) $socid);
217}
218if (!$user->hasRight('societe', 'client', 'voir')) {
219 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id).")";
220}
221$sql .= " ORDER BY c.rowid ASC";
222$resql = $db->query($sql);
223if ($resql) {
224 $num = $db->num_rows($resql);
225 if ($num) {
226 $langs->load("orders");
227
228 $i = 0;
229 print '<div class="div-table-responsive-no-min">';
230 print '<table class="noborder centpercent">';
231 print '<tr class="liste_titre">';
232 print '<th colspan="3">'.$langs->trans("SuppliersOrdersToProcess");
233 print ' <a href="'.DOL_URL_ROOT.'/reception/list.php?search_status=1" alt="'.$langs->trans("GoOnList").'"><span class="badge">'.$num.'</span></a>';
234 while ($i < $num) {
235 $obj = $db->fetch_object($resql);
236
237 $orderstatic->id = $obj->rowid;
238 $orderstatic->ref = $obj->ref;
239 $orderstatic->ref_supplier = $obj->ref_supplier;
240 $orderstatic->statut = $obj->status;
241 $orderstatic->facturee = $obj->billed;
242
243 $companystatic->name = $obj->name;
244 $companystatic->id = $obj->socid;
245
246 print '<tr class="oddeven">';
247 print '<td class="nowrap">';
248 print $orderstatic->getNomUrl(1);
249 print '</td>';
250 print '<td>';
251 print $companystatic->getNomUrl(1, 'customer', 32);
252 print '</td>';
253 print '<td class="right">';
254 print $orderstatic->getLibStatut(3);
255 print '</td>';
256 print '</tr>';
257 $i++;
258 }
259 print "</table></div><br>";
260 }
261}
262
263print '</div></div>';
264
265$parameters = array('user' => $user);
266$reshook = $hookmanager->executeHooks('dashboardWarehouseReceptions', $parameters, $object); // Note that $action and $object may have been modified by hook
267
268llxFooter();
269$db->close();
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: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...)
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.