dolibarr 25.0.0-alpha
reception.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Load Dolibarr environment
32require '../../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
42require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
43require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
45
46// Load translation files required by the page
47$langs->loadLangs(array('companies', 'bills', 'products', 'supplier_proposal', 'productbatch'));
48
49$id = GETPOSTINT('id');
50$ref = GETPOST('ref', 'alpha');
51$batch = GETPOST('batch', 'alpha');
52$objectid = GETPOSTINT('productid');
53
54// Security check
55$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
56$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
57$socid = 0;
58if (!empty($user->socid)) {
59 $socid = $user->socid;
60}
61
62// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
63$hookmanager->initHooks(array('batchproductstatsreception'));
64
65$showmessage = GETPOST('showmessage');
66
67// Load variable for pagination
68$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
69$sortfield = GETPOST('sortfield', 'aZ09comma');
70$sortorder = GETPOST('sortorder', 'aZ09comma');
71$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
72if (empty($page) || $page == -1) {
73 $page = 0;
74} // If $page is not defined, or '' or -1
75$offset = $limit * $page;
76$pageprev = $page - 1;
77$pagenext = $page + 1;
78if (empty($sortorder)) {
79 $sortorder = "DESC";
80}
81if (empty($sortfield)) {
82 $sortfield = "recep.date_creation";
83}
84
85$search_month = GETPOST('search_month'); // Can be ''
86$search_year = GETPOST('search_year'); // Can be '''
87
88if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
89 $search_month = '';
90 $search_year = '';
91}
92
93if (!$user->hasRight('produit', 'lire')) {
95}
96
97
98/*
99 * View
100 */
101
102$receptionstatic = new Reception($db);
103$societestatic = new Societe($db);
104
105$form = new Form($db);
106$formother = new FormOther($db);
107
108if ($id > 0 || !empty($ref)) {
109 $object = new Productlot($db);
110 if ($ref) {
111 $tmp = explode('_', $ref);
112 $objectid = $tmp[0];
113 $batch = $tmp[1];
114 }
115 $result = $object->fetch($id, $objectid, $batch);
116
117 $parameters = array('id' => $id);
118 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
119 if ($reshook < 0) {
120 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
121 }
122
123 $title = $langs->trans('ProductServiceCard');
124 $helpurl = '';
125 $shortlabel = dol_trunc($object->batch, 16);
126 $title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
127
128 llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-product page-stock-stats_reception');
129
130 if ($result > 0) {
132 $picto = 'lot';
133 $morehtmlref = '';
134 print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
135
136 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
137 print $hookmanager->resPrint;
138 if ($reshook < 0) {
139 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
140 }
141
142 $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
143
144 $shownav = 1;
145 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
146 $shownav = 0;
147 }
148
149 dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
150
151 print '<div class="fichecenter">';
152
153 print '<div class="underbanner clearboth"></div>';
154 print '<table class="border centpercent tableforfield" width="100%">';
155
156
157 // Product
158 print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
159 $producttmp = new Product($db);
160 $producttmp->fetch($object->fk_product);
161 print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
162 print '</td></tr>';
163 print "</table>";
164
165 echo '<br>';
166
167 // // Sell by
168 // if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
169 // print '<tr><td>';
170 // print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
171 // print '</td><td>';
172 // print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
173 // print '</td>';
174 // print '</tr>';
175 // }
176 //
177 // // Eat by
178 // if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
179 // print '<tr><td>';
180 // print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
181 // print '</td><td>';
182 // print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
183 // print '</td>';
184 // print '</tr>';
185 // }
186 //
187 // if (getDolGlobalString('PRODUCT_LOT_ENABLE_TRACEABILITY')) {
188 // print '<tr><td>'.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).'</td>';
189 // print '<td>'.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
190 // print '</tr>';
191 // // print '<tr><td>'.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).'</td>';
192 // // print '<td>'.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
193 // // print '</tr>';
194 // print '<tr><td>'.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).'</td>';
195 // print '<td>'.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
196 // print '</tr>';
197 // }
198 //
199 // // Quality control
200 // if (getDolGlobalString('PRODUCT_LOT_ENABLE_QUALITY_CONTROL')) {
201 // print '<tr><td>'.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).'</td>';
202 // print '<td>'.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
203 // print '</tr>';
204 // print '<tr><td>'.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).'</td>';
205 // print '<td>'.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').'</td>';
206 // print '</tr>';
207 // }
208 //
209 // // Other attributes
210 // include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
211
212 print '<br>';
213
214
215 print '<table class="noborder centpercent tableforfield">';
216
217 $nboflines = show_stats_for_batch($object, $socid);
218
219 print "</table>";
220
221 print '</div>';
222
223
224 print '<div class="clearboth"></div>';
225
226 print dol_get_fiche_end();
227
228 if ($showmessage && $nboflines > 1) {
229 print '<span class="opacitymedium">'.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).'</span>';
230 } elseif ($user->hasRight('reception', 'lire')) {
231 $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_fournisseur,";
232 $sql .= " recep.ref, recep.date_creation, recep.fk_statut as statut, recep.rowid as facid,";
233 $sql .= " d.qty";
234 // $sql.= ", d.total_ht as total_ht"; // We must keep the d.rowid here to not loose record because of the distinct used to ignore duplicate line when link on societe_commerciaux is used
235 if (!$user->hasRight('societe', 'client', 'voir')) {
236 $sql .= ", sc.fk_soc, sc.fk_user ";
237 }
238 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
239 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."reception as recep ON (recep.fk_soc = s.rowid)";
240 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."receptiondet_batch as d ON (d.fk_reception = recep.rowid)";
241 if (!$user->hasRight('societe', 'client', 'voir')) {
242 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
243 }
244 $sql .= " WHERE recep.entity IN (".getEntity('product').")";
245 $sql .= " AND d.batch = '".($db->escape($object->batch))."'";
246 if (!empty($search_month)) {
247 $sql .= ' AND MONTH(recep.date_creation) IN ('.$db->sanitize((string) $search_month).')';
248 }
249 if (!empty($search_year)) {
250 $sql .= ' AND YEAR(recep.date_creation) IN ('.$db->sanitize((string) $search_year).')';
251 }
252 if (!$user->hasRight('societe', 'client', 'voir')) {
253 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
254 }
255 if ($socid) {
256 $sql .= " AND recep.fk_soc = ".((int) $socid);
257 }
258 $sql .= $db->order($sortfield, $sortorder);
259
260 // Calcul total qty and amount for global if full scan list
261 $total_ht = 0;
262 $total_qty = 0;
263
264 // Count total nb of records
265 $totalofrecords = '';
266 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
267 $result = $db->query($sql);
268 $totalofrecords = $db->num_rows($result);
269 }
270
271 $sql .= $db->plimit($limit + 1, $offset);
272
273 $result = $db->query($sql);
274 if ($result) {
275 $num = $db->num_rows($result);
276
277 $option = '&id='.$object->id;
278
279 if ($limit > 0 && $limit != $conf->liste_limit) {
280 $option .= '&limit='.((int) $limit);
281 }
282 if (!empty($search_month)) {
283 $option .= '&search_month='.urlencode((string) ($search_month));
284 }
285 if (!empty($search_year)) {
286 $option .= '&search_year='.urlencode((string) ($search_year));
287 }
288
289 print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
290 print '<input type="hidden" name="token" value="'.newToken().'">';
291 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
292 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
293
294 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
295 print_barre_liste($langs->trans("Receptions"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
296
297 if (!empty($page)) {
298 $option .= '&page='.urlencode((string) ($page));
299 }
300
301 print '<div class="liste_titre liste_titre_bydiv centpercent">';
302 print '<div class="divsearchfield">';
303 print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
304 print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
305 print $langs->trans('Year').':'.$formother->selectyear($search_year ? (string) $search_year : '-1', 'search_year', 1, 20, 5);
306 print '<div style="vertical-align: middle; display: inline-block">';
307 print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', 0, 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
308 print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"), 'searchclear.png', '', 0, 1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
309 print '</div>';
310 print '</div>';
311 print '</div>';
312
313 $i = 0;
314 print '<div class="div-table-responsive">';
315 print '<table class="tagtable liste listwithfilterbefore" width="100%">';
316 print '<tr class="liste_titre">';
317 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
318 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
319 print_liste_field_titre("SupplierCode", $_SERVER["PHP_SELF"], "s.code_fournisseur", "", $option, '', $sortfield, $sortorder);
320 print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "recep.date_creation", "", $option, 'align="center"', $sortfield, $sortorder);
321 print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
322 // print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "d.total_ht", "", $option, 'align="right"', $sortfield, $sortorder);
323 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "recep.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
324 print "</tr>\n";
325
326 if ($num > 0) {
327 while ($i < min($num, $limit)) {
328 $objp = $db->fetch_object($result);
329
330 $total_ht += $objp->total_ht;
331 $total_qty += $objp->qty;
332
333 $receptionstatic->id = $objp->facid;
334 $receptionstatic->ref = $objp->ref;
335 $societestatic->fetch($objp->socid);
336 // $paiement = $receptionstatic->getSommePaiement();
337
338 print '<tr class="oddeven">';
339 print '<td>';
340 print $receptionstatic->getNomUrl(1);
341 print "</td>\n";
342 print '<td>'.$societestatic->getNomUrl(1).'</td>';
343 print "<td>".$objp->code_fournisseur."</td>\n";
344 print '<td class="center">';
345 print dol_print_date($db->jdate($objp->date_creation), 'dayhour')."</td>";
346 print '<td class="center">'.$objp->qty."</td>\n";
347 // print '<td align="right">'.price($objp->total_ht)."</td>\n";
348 print '<td align="right">'.$receptionstatic->LibStatut($objp->statut, 5).'</td>';
349 print "</tr>\n";
350 $i++;
351 }
352 }
353 print '<tr class="liste_total">';
354 if ($num < $limit) {
355 print '<td class="left">'.$langs->trans("Total").'</td>';
356 } else {
357 print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
358 }
359 print '<td colspan="2"></td>';
360 print '<td></td>';
361 print '<td class="center">'.$total_qty.'</td>';
362 print '<td></td>';
363 print "</table>";
364 print '</div>';
365 print '</form>';
366 } else {
367 dol_print_error($db);
368 }
369 $db->free($result);
370 }
371 }
372} else {
373 dol_print_error();
374}
375
376// End of page
377llxFooter();
378$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
Class to manage products or services.
Class with list of lots and properties.
Class to manage receptions.
Class to manage third parties objects (customers, suppliers, prospects...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:181
show_stats_for_batch($batch, $socid)
Show stats for product batch.
productlot_prepare_head($object)
Prepare array with list of tabs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.