dolibarr 21.0.0-alpha
expedition.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.'/expedition/class/expedition.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
38// Load translation files required by the page
39$langs->loadLangs(array('companies', 'bills', 'products', 'supplier_proposal', 'productbatch'));
40
41$id = GETPOSTINT('id');
42$ref = GETPOST('ref', 'alpha');
43$batch = GETPOST('batch', 'alpha');
44$objectid = GETPOSTINT('productid');
45
46// Security check
47$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
48$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
49$socid = '';
50if (!empty($user->socid)) {
51 $socid = $user->socid;
52}
53
54// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
55$hookmanager->initHooks(array('batchproductstatsexpedition'));
56
57$showmessage = GETPOST('showmessage');
58
59// Load variable for pagination
60$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
61$sortfield = GETPOST('sortfield', 'aZ09comma');
62$sortorder = GETPOST('sortorder', 'aZ09comma');
63$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
64if (empty($page) || $page == -1) {
65 $page = 0;
66} // If $page is not defined, or '' or -1
67$offset = $limit * $page;
68$pageprev = $page - 1;
69$pagenext = $page + 1;
70if (!$sortorder) {
71 $sortorder = "DESC";
72}
73if (!$sortfield) {
74 $sortfield = "exp.date_creation";
75}
76
77$search_month = GETPOSTINT('search_month');
78$search_year = GETPOSTINT('search_year');
79
80if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
81 $search_month = '';
82 $search_year = '';
83}
84
85if (!$user->hasRight('produit', 'lire')) {
87}
88
89
90/*
91 * View
92 */
93
94$expeditionstatic = new Expedition($db);
95$societestatic = new Societe($db);
96
97$form = new Form($db);
98$formother = new FormOther($db);
99
100if ($id > 0 || !empty($ref)) {
101 $object = new Productlot($db);
102 if ($ref) {
103 $tmp = explode('_', $ref);
104 $objectid = $tmp[0];
105 $batch = $tmp[1];
106 }
107 $result = $object->fetch($id, $objectid, $batch);
108
109 $parameters = array('id' => $id);
110 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
111 if ($reshook < 0) {
112 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
113 }
114
115 $helpurl = '';
116 $shortlabel = dol_trunc($object->batch, 16);
117 $title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
118 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
119
120 llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-product page-stock-stats_expedition');
121
122 if ($result > 0) {
124 $titre = $langs->trans("CardProduct".$object->type);
125 $picto = 'lot';
126 print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
127
128 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
129 print $hookmanager->resPrint;
130 if ($reshook < 0) {
131 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
132 }
133
134 $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
135
136 $shownav = 1;
137 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
138 $shownav = 0;
139 }
140
141 dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
142
143 print '<div class="fichecenter">';
144
145 print '<div class="underbanner clearboth"></div>';
146 print '<table class="border centpercent tableforfield" width="100%">';
147
148
149 // Product
150 print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
151 $producttmp = new Product($db);
152 $producttmp->fetch($object->fk_product);
153 print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
154 print '</td></tr>';
155 print "</table>";
156
157 echo '<br>';
158
159 // // Sell by
160 // if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
161 // print '<tr><td>';
162 // print $form->editfieldkey($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
163 // print '</td><td>';
164 // print $form->editfieldval($langs->trans('SellByDate'), 'sellby', $object->sellby, $object, $user->rights->stock->creer, 'datepicker');
165 // print '</td>';
166 // print '</tr>';
167 // }
168 //
169 // // Eat by
170 // if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
171 // print '<tr><td>';
172 // print $form->editfieldkey($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
173 // print '</td><td>';
174 // print $form->editfieldval($langs->trans('EatByDate'), 'eatby', $object->eatby, $object, $user->rights->stock->creer, 'datepicker');
175 // print '</td>';
176 // print '</tr>';
177 // }
178 //
179 // if (!empty($conf->global->PRODUCT_LOT_ENABLE_TRACEABILITY)) {
180 // print '<tr><td>'.$form->editfieldkey($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer).'</td>';
181 // print '<td>'.$form->editfieldval($langs->trans('ManufacturingDate'), 'manufacturing_date', $object->manufacturing_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
182 // print '</tr>';
183 // // print '<tr><td>'.$form->editfieldkey($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer).'</td>';
184 // // print '<td>'.$form->editfieldval($langs->trans('FirstUseDate'), 'commissionning_date', $object->commissionning_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
185 // // print '</tr>';
186 // print '<tr><td>'.$form->editfieldkey($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer).'</td>';
187 // print '<td>'.$form->editfieldval($langs->trans('DestructionDate'), 'scrapping_date', $object->scrapping_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
188 // print '</tr>';
189 // }
190 //
191 // // Quality control
192 // if (!empty($conf->global->PRODUCT_LOT_ENABLE_QUALITY_CONTROL)) {
193 // print '<tr><td>'.$form->editfieldkey($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer).'</td>';
194 // print '<td>'.$form->editfieldval($langs->trans('EndOfLife'), 'eol_date', $object->eol_date, $object, $user->rights->stock->creer, 'datepicker').'</td>';
195 // print '</tr>';
196 // print '<tr><td>'.$form->editfieldkey($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer).'</td>';
197 // print '<td>'.$form->editfieldval($langs->trans('QCFrequency'), 'qc_frequency', $object->qc_frequency, $object, $user->rights->stock->creer, 'numeric').'</td>';
198 // print '</tr>';
199 // }
200 //
201 // // Other attributes
202 // include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
203
204 print '<table class="border centpercent tableforfield" width="100%">';
205
206 $nboflines = show_stats_for_batch($object, $socid);
207
208 print "</table>";
209
210 print '</div>';
211 print '<div class="clearboth"></div>';
212
213 print dol_get_fiche_end();
214
215 if ($showmessage && $nboflines > 1) {
216 print '<span class="opacitymedium">'.$langs->trans("ClinkOnALinkOfColumn", $langs->transnoentitiesnoconv("Referers")).'</span>';
217 } elseif ($user->hasRight('expedition', 'lire')) {
218 $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client,";
219 $sql .= " exp.ref, exp.date_creation, exp.fk_statut as statut, exp.rowid as facid,";
220 $sql .= " d.rowid, db.qty";
221 // $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
222 if (!$user->hasRight('societe', 'client', 'voir')) {
223 $sql .= ", sc.fk_soc, sc.fk_user ";
224 }
225 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
226 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expedition as exp ON (exp.fk_soc = s.rowid)";
227 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expeditiondet as d ON (d.fk_expedition = exp.rowid)";
228 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as db ON (db.fk_expeditiondet = d.rowid)";
229 if (!$user->hasRight('societe', 'client', 'voir')) {
230 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
231 }
232 $sql .= " WHERE exp.entity IN (".getEntity('product').")";
233 $sql .= " AND db.batch = '".($db->escape($object->batch))."'";
234 if (!empty($search_month)) {
235 $sql .= ' AND MONTH(exp.date_creation) IN ('.$db->sanitize($search_month).')';
236 }
237 if (!empty($search_year)) {
238 $sql .= ' AND YEAR(exp.date_creation) IN ('.$db->sanitize($search_year).')';
239 }
240 if (!$user->hasRight('societe', 'client', 'voir')) {
241 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
242 }
243 if ($socid) {
244 $sql .= " AND exp.fk_soc = ".((int) $socid);
245 }
246 $sql .= $db->order($sortfield, $sortorder);
247
248 // Calcul total qty and amount for global if full scan list
249 $total_ht = 0;
250 $total_qty = 0;
251
252 // Count total nb of records
253 $totalofrecords = '';
254 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
255 $result = $db->query($sql);
256 $totalofrecords = $db->num_rows($result);
257 }
258
259 $sql .= $db->plimit($limit + 1, $offset);
260
261 $result = $db->query($sql);
262 if ($result) {
263 $num = $db->num_rows($result);
264
265 $option .= '&id='.$object->id;
266
267 if ($limit > 0 && $limit != $conf->liste_limit) {
268 $option .= '&limit='.((int) $limit);
269 }
270 if (!empty($search_month)) {
271 $option .= '&search_month='.urlencode((string) ($search_month));
272 }
273 if (!empty($search_year)) {
274 $option .= '&search_year='.urlencode((string) ($search_year));
275 }
276
277 print '<form method="post" action="'.$_SERVER ['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
278 print '<input type="hidden" name="token" value="'.newToken().'">';
279 if (!empty($sortfield)) {
280 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
281 }
282 if (!empty($sortorder)) {
283 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
284 }
285
286 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
287 print_barre_liste($langs->trans("Shipments"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
288
289 if (!empty($page)) {
290 $option .= '&page='.urlencode((string) ($page));
291 }
292
293 print '<div class="liste_titre liste_titre_bydiv centpercent">';
294 print '<div class="divsearchfield">';
295 print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
296 print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
297 print $langs->trans('Year').':'.$formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5);
298 print '<div style="vertical-align: middle; display: inline-block">';
299 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")).'">';
300 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")).'">';
301 print '</div>';
302 print '</div>';
303 print '</div>';
304
305 $i = 0;
306 print '<div class="div-table-responsive">';
307 print '<table class="tagtable liste listwithfilterbefore" width="100%">';
308 print '<tr class="liste_titre">';
309 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder);
310 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder);
311 print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", $option, '', $sortfield, $sortorder);
312 print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "exp.date_creation", "", $option, 'align="center"', $sortfield, $sortorder);
313 print_liste_field_titre("Qty", $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder);
314 // print_liste_field_titre("AmountHT", $_SERVER["PHP_SELF"], "d.total_ht", "", $option, 'align="right"', $sortfield, $sortorder);
315 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "exp.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder);
316 print "</tr>\n";
317
318 if ($num > 0) {
319 while ($i < min($num, $limit)) {
320 $objp = $db->fetch_object($result);
321
322 $total_ht += $objp->total_ht;
323 $total_qty += $objp->qty;
324
325 $expeditionstatic->id = $objp->facid;
326 $expeditionstatic->ref = $objp->ref;
327 $societestatic->fetch($objp->socid);
328 // $paiement = $expeditionstatic->getSommePaiement();
329
330 print '<tr class="oddeven">';
331 print '<td>';
332 print $expeditionstatic->getNomUrl(1);
333 print "</td>\n";
334 print '<td>'.$societestatic->getNomUrl(1).'</td>';
335 print "<td>".$objp->code_client."</td>\n";
336 print '<td class="center">';
337 print dol_print_date($db->jdate($objp->date_creation), 'dayhour')."</td>";
338 print '<td class="center">'.$objp->qty."</td>\n";
339 // print '<td align="right">'.price($objp->total_ht)."</td>\n";
340 print '<td align="right">'.$expeditionstatic->LibStatut($objp->statut, 5).'</td>';
341 print "</tr>\n";
342 $i++;
343 }
344 }
345 print '<tr class="liste_total">';
346 if ($num < $limit) {
347 print '<td class="left">'.$langs->trans("Total").'</td>';
348 } else {
349 print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
350 }
351 print '<td colspan="2"></td>';
352 print '<td></td>';
353 print '<td class="center">'.$total_qty.'</td>';
354 print '<td></td>';
355 print "</table>";
356 print '</div>';
357 print '</form>';
358 } else {
359 dol_print_error($db);
360 }
361 $db->free($result);
362 }
363 }
364} else {
366}
367
368// End of page
369llxFooter();
370$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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 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 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...
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.