dolibarr 21.0.0-beta
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 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37
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 = GETPOSTINT('search_month');
86$search_year = GETPOSTINT('search_year');
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 $titre = $langs->trans("CardProduct".$object->type);
133 $picto = 'lot';
134 $morehtmlref = '';
135 print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
136
137 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
138 print $hookmanager->resPrint;
139 if ($reshook < 0) {
140 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
141 }
142
143 $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
144
145 $shownav = 1;
146 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
147 $shownav = 0;
148 }
149
150 dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
151
152 print '<div class="fichecenter">';
153
154 print '<div class="underbanner clearboth"></div>';
155 print '<table class="border centpercent tableforfield" width="100%">';
156
157
158 // Product
159 print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
160 $producttmp = new Product($db);
161 $producttmp->fetch($object->fk_product);
162 print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
163 print '</td></tr>';
164 print "</table>";
165
166 echo '<br>';
167
168 // // Sell by
169 // if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
170 // print '<tr><td>';
171 // print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
172 // print '</td><td>';
173 // print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
174 // print '</td>';
175 // print '</tr>';
176 // }
177 //
178 // // Eat by
179 // if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
180 // print '<tr><td>';
181 // print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
182 // print '</td><td>';
183 // print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
184 // print '</td>';
185 // print '</tr>';
186 // }
187 //
188 // if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABILITY)) {
189 // print '<tr><td>'.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).'</td>';
190 // print '<td>'.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
191 // print '</tr>';
192 // // print '<tr><td>'.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).'</td>';
193 // // print '<td>'.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
194 // // print '</tr>';
195 // print '<tr><td>'.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).'</td>';
196 // print '<td>'.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
197 // print '</tr>';
198 // }
199 //
200 // // Quality control
201 // if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
202 // print '<tr><td>'.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).'</td>';
203 // print '<td>'.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
204 // print '</tr>';
205 // print '<tr><td>'.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).'</td>';
206 // print '<td>'.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').'</td>';
207 // print '</tr>';
208 // }
209 //
210 // // Other attributes
211 // include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
212
213 print '<table class="border centpercent tableforfield" width="100%">';
214
215 $nboflines = show_stats_for_batch($object, $socid);
216
217 print "</table>";
218
219 print '</div>';
220 print '<div class="clearboth"></div>';
221
222 print dol_get_fiche_end();
223
224 if ($showmessage && $nboflines > 1) {
225 print '<span class="opacitymedium">'.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).'</span>';
226 } elseif ($user->hasRight('reception', 'lire')) {
227 $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_fournisseur,";
228 $sql .= " recep.ref, recep.date_creation, recep.fk_statut as statut, recep.rowid as facid,";
229 $sql .= " d.qty";
230 // $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
231 if (!$user->hasRight('societe', 'client', 'voir')) {
232 $sql .= ", sc.fk_soc, sc.fk_user ";
233 }
234 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
235 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."reception as recep ON (recep.fk_soc = s.rowid)";
236 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."receptiondet_batch as d ON (d.fk_reception = recep.rowid)";
237 if (!$user->hasRight('societe', 'client', 'voir')) {
238 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
239 }
240 $sql .= " WHERE recep.entity IN (".getEntity('product').")";
241 $sql .= " AND d.batch = '".($db->escape($object->batch))."'";
242 if (!empty($search_month)) {
243 $sql .= ' AND MONTH(recep.date_creation) IN ('.$db->sanitize($search_month).')';
244 }
245 if (!empty($search_year)) {
246 $sql .= ' AND YEAR(recep.date_creation) IN ('.$db->sanitize($search_year).')';
247 }
248 if (!$user->hasRight('societe', 'client', 'voir')) {
249 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
250 }
251 if ($socid) {
252 $sql .= " AND recep.fk_soc = ".((int) $socid);
253 }
254 $sql .= $db->order($sortfield, $sortorder);
255
256 // Calcul total qty and amount for global if full scan list
257 $total_ht = 0;
258 $total_qty = 0;
259
260 // Count total nb of records
261 $totalofrecords = '';
262 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
263 $result = $db->query($sql);
264 $totalofrecords = $db->num_rows($result);
265 }
266
267 $sql .= $db->plimit($limit + 1, $offset);
268
269 $result = $db->query($sql);
270 if ($result) {
271 $num = $db->num_rows($result);
272
273 $option = '&id='.$object->id;
274
275 if ($limit > 0 && $limit != $conf->liste_limit) {
276 $option .= '&limit='.((int) $limit);
277 }
278 if (!empty($search_month)) {
279 $option .= '&search_month='.urlencode((string) ($search_month));
280 }
281 if (!empty($search_year)) {
282 $option .= '&search_year='.urlencode((string) ($search_year));
283 }
284
285 print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
286 print '<input type="hidden" name="token" value="'.newToken().'">';
287 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
288 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
289
290 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
291 print_barre_liste($langs->trans("Receptions"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
292
293 if (!empty($page)) {
294 $option .= '&page='.urlencode((string) ($page));
295 }
296
297 print '<div class="liste_titre liste_titre_bydiv centpercent">';
298 print '<div class="divsearchfield">';
299 print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
300 print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
301 print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
302 print '<div style="vertical-align: middle; display: inline-block">';
303 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")).'">';
304 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")).'">';
305 print '</div>';
306 print '</div>';
307 print '</div>';
308
309 $i = 0;
310 print '<div class="div-table-responsive">';
311 print '<table class="tagtable liste listwithfilterbefore" width="100%">';
312 print '<tr class="liste_titre">';
313 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
314 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
315 print_liste_field_titre("SupplierCode", $_SERVER["PHP_SELF"], "s.code_fournisseur", "", $option, '', $sortfield, $sortorder);
316 print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "recep.date_creation", "", $option, 'align="center"', $sortfield, $sortorder);
317 print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
318 // print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "d.total_ht", "", $option, 'align="right"', $sortfield, $sortorder);
319 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "recep.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
320 print "</tr>\n";
321
322 if ($num > 0) {
323 while ($i < min($num, $limit)) {
324 $objp = $db->fetch_object($result);
325
326 $total_ht += $objp->total_ht;
327 $total_qty += $objp->qty;
328
329 $receptionstatic->id = $objp->facid;
330 $receptionstatic->ref = $objp->ref;
331 $societestatic->fetch($objp->socid);
332 // $paiement = $receptionstatic->getSommePaiement();
333
334 print '<tr class="oddeven">';
335 print '<td>';
336 print $receptionstatic->getNomUrl(1);
337 print "</td>\n";
338 print '<td>'.$societestatic->getNomUrl(1).'</td>';
339 print "<td>".$objp->code_fournisseur."</td>\n";
340 print '<td class="center">';
341 print dol_print_date($db->jdate($objp->date_creation), 'dayhour')."</td>";
342 print '<td class="center">'.$objp->qty."</td>\n";
343 // print '<td align="right">'.price($objp->total_ht)."</td>\n";
344 print '<td align="right">'.$receptionstatic->LibStatut($objp->statut, 5).'</td>';
345 print "</tr>\n";
346 $i++;
347 }
348 }
349 print '<tr class="liste_total">';
350 if ($num < $limit) {
351 print '<td class="left">'.$langs->trans("Total").'</td>';
352 } else {
353 print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
354 }
355 print '<td colspan="2"></td>';
356 print '<td></td>';
357 print '<td class="center">'.$total_qty.'</td>';
358 print '<td></td>';
359 print "</table>";
360 print '</div>';
361 print '</form>';
362 } else {
363 dol_print_error($db);
364 }
365 $db->free($result);
366 }
367 }
368} else {
370}
371
372// End of page
373llxFooter();
374$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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 generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre 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...)
llxFooter()
Footer empty.
Definition document.php:107
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.