dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
32require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
33
42// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
43$hookmanager->initHooks(array('receptionindex'));
44
45$langs->loadLangs(array("orders", "receptions"));
46
47$reception = new Reception($db);
48
49// Security check
50$socid = '';
51if ($user->socid) {
52 $socid = $user->socid;
53}
54$result = restrictedArea($user, 'reception', 0, '');
55
56
57/*
58 * View
59 */
60
61$orderstatic = new CommandeFournisseur($db);
62$companystatic = new Societe($db);
63
64$helpurl = 'EN:Module_Receptions|FR:Module_Receptions|ES:M&oacute;dulo_Receptiones';
65llxHeader('', $langs->trans("Reception"), $helpurl, '', 0, 0, '', '', '', 'mod-reception page-dashboard');
66
67print load_fiche_titre($langs->trans("ReceptionsArea"), '', 'dollyrevert');
68
69
70print '<div class="fichecenter"><div class="fichethirdleft">';
71
72
73if (getDolGlobalString('MAIN_SEARCH_FORM_ON_HOME_AREAS')) { // This may be useless due to the global search combo
74 print '<form method="post" action="list.php">';
75 print '<input type="hidden" name="token" value="'.newToken().'">';
76 print '<div class="div-table-responsive-no-min">';
77 print '<table class="noborder nohover centpercent">';
78 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
79 print '<tr class="oddeven"><td>';
80 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>';
81 print "</table></div></form><br>\n";
82}
83
84
85/*
86 * Draft receptions
87 */
88
89$sql = "SELECT e.rowid, e.ref, e.ref_supplier,";
90$sql .= " s.nom as name, s.rowid as socid,";
91$sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
92$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
93$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'reception'";
94$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseur as c ON el.fk_source = c.rowid";
95$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
96if (!$user->hasRight('societe', 'client', 'voir')) {
97 $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).")";
98}
99$sql .= " WHERE e.fk_statut = 0";
100$sql .= " AND e.entity IN (".getEntity('reception').")";
101if ($socid) {
102 $sql .= " AND c.fk_soc = ".((int) $socid);
103}
104
105$resql = $db->query($sql);
106if ($resql) {
107 print '<div class="div-table-responsive-no-min">';
108 print '<table class="noborder centpercent">';
109 print '<tr class="liste_titre">';
110 print '<th colspan="3">'.$langs->trans("ReceptionsToValidate").'</th></tr>';
111
112 $num = $db->num_rows($resql);
113 if ($num) {
114 $i = 0;
115 while ($i < $num) {
116 $obj = $db->fetch_object($resql);
117
118 $reception->id = $obj->rowid;
119 $reception->ref = $obj->ref;
120 $reception->ref_supplier = $obj->ref_supplier;
121
122 print '<tr class="oddeven"><td class="nowrap">';
123 print $reception->getNomUrl(1);
124 print "</td>";
125 print '<td>';
126 print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
127 print '</td>';
128 print '<td>';
129 if ($obj->commande_fournisseur_id) {
130 print '<a href="'.DOL_URL_ROOT.'/commande_fournisseur/card.php?id='.$obj->commande_fournisseur_id.'">'.$obj->commande_fournisseur_ref.'</a>';
131 }
132 print '</td></tr>';
133 $i++;
134 }
135 } else {
136 print '<tr><td><span class="opacitymedium">'.$langs->trans("None").'</span></td><td></td><td></td></tr>';
137 }
138
139 print "</table></div><br>";
140}
141
142
143print '</div><div class="fichetwothirdright">';
144
145$max = 5;
146
147/*
148 * Latest receptions
149 */
150
151$sql = "SELECT e.rowid, e.ref, e.ref_supplier,";
152$sql .= " s.nom as name, s.rowid as socid,";
153$sql .= " c.ref as commande_fournisseur_ref, c.rowid as commande_fournisseur_id";
154$sql .= " FROM ".MAIN_DB_PREFIX."reception as e";
155$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')";
156$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'";
157$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
158if (!$user->hasRight('societe', 'client', 'voir')) {
159 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
160}
161$sql .= " WHERE e.entity IN (".getEntity('reception').")";
162if (!$user->hasRight('societe', 'client', 'voir')) {
163 $sql .= " AND sc.fk_user = ".((int) $user->id);
164}
165$sql .= " AND e.fk_statut = 1";
166if ($socid) {
167 $sql .= " AND c.fk_soc = ".((int) $socid);
168}
169$sql .= " ORDER BY e.date_delivery DESC";
170$sql .= $db->plimit($max, 0);
171
172$resql = $db->query($sql);
173if ($resql) {
174 $num = $db->num_rows($resql);
175 if ($num) {
176 $i = 0;
177 print '<div class="div-table-responsive-no-min">';
178 print '<table class="noborder centpercent">';
179 print '<tr class="liste_titre">';
180 print '<th colspan="3">'.$langs->trans("LastReceptions", $num).'</th></tr>';
181 while ($i < $num) {
182 $obj = $db->fetch_object($resql);
183
184 $reception->id = $obj->rowid;
185 $reception->ref = $obj->ref;
186 $reception->ref_supplier = $obj->ref_supplier;
187
188 print '<tr class="oddeven"><td>';
189 print $reception->getNomUrl(1);
190 print '</td>';
191 print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
192 print '<td>';
193 if ($obj->commande_fournisseur_id > 0) {
194 $orderstatic->id = $obj->commande_fournisseur_id;
195 $orderstatic->ref = $obj->commande_fournisseur_ref;
196 print $orderstatic->getNomUrl(1);
197 } else {
198 print '&nbsp;';
199 }
200 print '</td></tr>';
201 $i++;
202 }
203 print "</table></div><br>";
204 }
205 $db->free($resql);
206} else {
207 dol_print_error($db);
208}
209
210
211
212/*
213 * Open pruchase orders to process
214 */
215
216$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";
217$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c,";
218$sql .= " ".MAIN_DB_PREFIX."societe as s";
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 (!$user->hasRight('societe', 'client', 'voir')) {
226 $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).")";
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");
240 print ' <a href="'.DOL_URL_ROOT.'/reception/list.php?search_status=1" alt="'.$langs->trans("GoOnList").'"><span class="badge">'.$num.'</span></a>';
241 while ($i < $num) {
242 $obj = $db->fetch_object($resql);
243
244 $orderstatic->id = $obj->rowid;
245 $orderstatic->ref = $obj->ref;
246 $orderstatic->ref_supplier = $obj->ref_supplier;
247 $orderstatic->statut = $obj->status;
248 $orderstatic->facturee = $obj->billed;
249
250 $companystatic->name = $obj->name;
251 $companystatic->id = $obj->socid;
252
253 print '<tr class="oddeven">';
254 print '<td class="nowrap">';
255 print $orderstatic->getNomUrl(1);
256 print '</td>';
257 print '<td>';
258 print $companystatic->getNomUrl(1, 'customer', 32);
259 print '</td>';
260 print '<td class="right">';
261 print $orderstatic->getLibStatut(3);
262 print '</td>';
263 print '</tr>';
264 $i++;
265 }
266 print "</table></div><br>";
267 }
268}
269
270print '</div></div>';
271
272$parameters = array('user' => $user);
273$reshook = $hookmanager->executeHooks('dashboardWarehouseReceptions', $parameters, $object); // Note that $action and $object may have been modified by hook
274
275llxFooter();
276$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:71
Class to manage predefined suppliers products.
const STATUS_RECEIVED_PARTIALLY
Received partially.
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.