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