dolibarr 25.0.0-alpha
dispatch.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
5 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2010-2021 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2014 Cedric Gross <c.gross@kreiz-it.fr>
8 * Copyright (C) 2016 Florian Henry <florian.henry@atm-consulting.fr>
9 * Copyright (C) 2017-2022 Ferran Marcet <fmarcet@2byte.es>
10 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2019-2020 Christophe Battarel <christophe@altairis.fr>
12 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
34// Load Dolibarr environment
35require '../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
37require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
40require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
41require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
42require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
45
54// Load translation files required by the page
55$langs->loadLangs(array("bills", "orders", "sendings", "companies", "products", "stocks", "receptions"));
56
57if (isModEnabled('productbatch')) {
58 $langs->load('productbatch');
59}
60
61// Security check
62$id = GETPOSTINT("id");
63$ref = GETPOST('ref');
64$lineid = GETPOSTINT('lineid');
65$action = GETPOST('action', 'aZ09');
66$fk_default_warehouse = GETPOSTINT('fk_default_warehouse');
67$cancel = GETPOST('cancel', 'alpha');
68$confirm = GETPOST('confirm', 'alpha');
69
70$error = 0;
71$errors = array();
72
73if ($user->socid) {
74 $socid = $user->socid;
75}
76
77$hookmanager->initHooks(array('ordersupplierdispatch'));
78
79// Retrieve the project id
80$projectid = 0;
81if (GETPOSTISSET("projectid")) {
82 $projectid = GETPOSTINT("projectid");
83}
84
85$object = new Reception($db);
86$objectsrc = null;
87
88if ($id > 0 || !empty($ref)) {
89 $result = $object->fetch($id, $ref);
90 if ($result < 0) {
91 setEventMessages($object->error, $object->errors, 'errors');
92 }
93 $result = $object->fetch_thirdparty();
94 if ($result < 0) {
95 setEventMessages($object->error, $object->errors, 'errors');
96 }
97 $origin = null;
98 if (!empty($object->origin)) {
99 $origin = $object->origin;
100 $typeobject = $object->origin;
101
102 $object->fetch_origin();
103 }
104 if ($origin == 'order_supplier' && $object->origin_object->id && (isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') || isModEnabled("supplier_order"))) {
105 $origin_id = $object->origin_object->id;
106 $objectsrc = new CommandeFournisseur($db);
107 $objectsrc->fetch($origin_id);
108 }
109}
110
111if (empty($conf->reception->enabled)) {
112 $permissiontoreceive = $user->hasRight('fournisseur', 'commande', 'receptionner');
113 $permissiontocontrol = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('fournisseur', 'commande', 'receptionner')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('fournisseur', 'commande_advance', 'check')));
114} else {
115 $permissiontoreceive = $user->hasRight('reception', 'creer');
116 $permissiontocontrol = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate')));
117}
118
119// $id is id of a reception
120$result = restrictedArea($user, 'reception', $object->id);
121
122if (!isModEnabled('stock')) {
123 accessforbidden('Module stock disabled');
124}
125
126$usercancreate = $user->hasRight('reception', 'creer');
127$permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php
128
129
130/*
131 * Actions
132 */
133
134$parameters = array();
135$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
136if ($reshook < 0) {
137 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
138}
139
140// Lines can be updated only while the stock of the reception is not moved (same rule as the display of the form)
141if ($action == 'updatelines' && $permissiontoreceive && !($object->status == Reception::STATUS_DRAFT || ($object->status == Reception::STATUS_VALIDATED && !getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION')))) {
142 setEventMessages($langs->trans('StatusOfRefMustBe', $object->ref, $langs->transnoentitiesnoconv('StatusReceptionDraftShort')), null, 'errors');
143 $action = '';
144}
145
146// Update a dispatched line
147if ($action == 'updatelines' && $permissiontoreceive) {
148 $db->begin();
149 $error = 0;
150
151 $supplierorderdispatch = new CommandeFournisseurDispatch($db);
152 $pos = 0;
153
154 foreach ($_POST as $key => $value) {
155 // without batch module enabled
156 $reg = array();
157 if (preg_match('/^product_.*([0-9]+)_([0-9]+)$/i', $key, $reg)) {
158 $pos++;
159 $modebatch = '';
160 if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
161 $modebatch = "barcode";
162 } elseif (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) { // With batchmode enabled
163 $modebatch = "batch";
164 }
165
166 $numline = $pos;
167 if ($modebatch == "barcode") {
168 $prod = "product_".$reg[1].'_'.$reg[2];
169 } else {
170 $prod = 'product_batch_'.$reg[1].'_'.$reg[2];
171 }
172 $qty = "qty_".$reg[1].'_'.$reg[2];
173 $ent = "entrepot_".$reg[1].'_'.$reg[2];
174 $pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount
175 $fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2];
176 $idline = GETPOSTINT("idline_".$reg[1].'_'.$reg[2]);
177 $lot = '';
178 $dDLUO = '';
179 $dDLC = '';
180 if ($modebatch == "batch") {
181 $lot = GETPOST('lot_number_'.$reg[1].'_'.$reg[2]);
182 $dDLUO = dol_mktime(12, 0, 0, GETPOSTINT('dluo_'.$reg[1].'_'.$reg[2].'month'), GETPOSTINT('dluo_'.$reg[1].'_'.$reg[2].'day'), GETPOSTINT('dluo_'.$reg[1].'_'.$reg[2].'year'));
183 $dDLC = dol_mktime(12, 0, 0, GETPOSTINT('dlc_'.$reg[1].'_'.$reg[2].'month'), GETPOSTINT('dlc_'.$reg[1].'_'.$reg[2].'day'), GETPOSTINT('dlc_'.$reg[1].'_'.$reg[2].'year'));
184 }
185
186 $saveprice = '__invalidsavepricekey__';
187 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
188 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
189 $dto = GETPOSTINT("dto_".$reg[1].'_'.$reg[2]);
190 if (!empty($dto)) {
191 $unit_price = (float) price2num(GETPOSTFLOAT("pu_".$reg[1]) * (100 - $dto) / 100, 'MU');
192 }
193 $saveprice = "saveprice_".$reg[1].'_'.$reg[2];
194 }
195 }
196
197 // We ask to move a qty
198 if (($modebatch == "batch" && GETPOST($qty) > 0) || ($modebatch == "barcode" && GETPOST($qty) != 0)) {
199 if (!(GETPOSTINT($ent) > 0)) {
200 dol_syslog('No dispatch for line '.$key.' as no warehouse was chosen.');
201 $text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' '.($numline);
202 setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
203 $error++;
204 }
205
206 if (!$error) {
207 if ($idline > 0) {
208 $result = $supplierorderdispatch->fetch($idline);
209 if ($result > 0 && (int) $supplierorderdispatch->fk_reception !== (int) $object->id) {
210 // The line must be a line of the reception of the page
211 $supplierorderdispatch->error = $langs->trans('ErrorRecordNotFound');
212 $result = -1;
213 }
214 if ($result < 0) {
215 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
216 $error++;
217 } else {
218 $qtystart = $supplierorderdispatch->qty;
219 $supplierorderdispatch->qty = (float) price2num(GETPOST($qty));
220 $supplierorderdispatch->fk_entrepot = GETPOSTINT($ent);
221 if ($modebatch == "batch") {
222 $supplierorderdispatch->eatby = $dDLUO;
223 $supplierorderdispatch->sellby = $dDLC;
224 }
225
226 $result = $supplierorderdispatch->update($user);
227 if ($result < 0) {
228 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
229 $error++;
230 }
231
232 // If module stock is enabled and the stock decrease is done on edition of this page
233 /*
234 if (!$error && GETPOST($ent, 'int') > 0 && isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
235 $mouv = new MouvementStock($db);
236 $product = GETPOST($prod, 'int');
237 $entrepot = GETPOST($ent, 'int');
238 $qtymouv = GETPOST($qty) - $qtystart;
239 $price = GETPOST($pu);
240 $comment = GETPOST('comment');
241 $inventorycode = dol_print_date(dol_now(), 'dayhourlog');
242 $now = dol_now();
243 $eatby = '';
244 $sellby = '';
245 $batch = '';
246 if ($modebatch == "batch") {
247 $eatby = $dDLUO;
248 $sellby = $dDLC;
249 $batch = $supplierorderdispatch->batch;
250 }
251 if ($product > 0) {
252 // $price should take into account discount (except if option STOCK_EXCLUDE_DISCOUNT_FOR_PMP is on)
253 $mouv->origin = $objectsrc;
254 $mouv->setOrigin($objectsrc->element, $objectsrc->id);
255
256 // Method change if qty < 0
257 if (getDolGlobalString('SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qtymouv < 0) {
258 $result = $mouv->livraison($user, $product, $entrepot, $qtymouv*(-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
259 } else {
260 $result = $mouv->reception($user, $product, $entrepot, $qtymouv, $price, $comment, $eatby, $sellby, $batch, '', 0, $inventorycode);
261 }
262
263 if ($result < 0) {
264 setEventMessages($mouv->error, $mouv->errors, 'errors');
265 $error++;
266 }
267 }
268 }
269 */
270 }
271 } else {
272 $result = $objectsrc->dispatchProduct($user, GETPOSTINT($prod), GETPOSTFLOAT($qty), GETPOSTINT($ent), GETPOSTFLOAT($pu), GETPOST('comment'), $dDLUO, $dDLC, $lot, GETPOSTINT($fk_commandefourndet), 0, $object->id);
273 if ($result < 0) {
274 setEventMessages($objectsrc->error, $objectsrc->errors, 'errors');
275 $error++;
276 }
277 }
278
279 if (!$error && getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
280 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
281 $dto = price2num(GETPOST("dto_".$reg[1].'_'.$reg[2]), '');
282 if (empty($dto)) {
283 $dto = 0;
284 }
285
286 //update supplier price
287 if (GETPOSTISSET($saveprice)) {
288 // TODO Use class
289 $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
290 $sql .= " SET unitprice='".price2num(GETPOST($pu), 'MU')."'";
291 $sql .= ", price=".price2num(GETPOST($pu), 'MU')."*quantity";
292 $sql .= ", remise_percent = ".((float) $dto);
293 $sql .= " WHERE fk_soc=".((int) $object->socid);
294 $sql .= " AND fk_product=".(GETPOSTINT($prod));
295
296 $resql = $db->query($sql);
297 }
298 }
299 }
300 }
301 }
302 }
303 }
304 if ($error > 0) {
305 $db->rollback();
306 setEventMessages($langs->trans("Error"), $errors, 'errors');
307 } else {
308 $db->commit();
309 setEventMessages($langs->trans("ReceptionUpdated"), null);
310
311 header("Location: ".DOL_URL_ROOT.'/reception/dispatch.php?id='.$object->id);
312 exit;
313 }
314}
315
316
317/*
318 * View
319 */
320
321$now = dol_now();
322
323$form = new Form($db);
324$formproduct = new FormProduct($db);
325$warehouse_static = new Entrepot($db);
326$supplierorderdispatch = new CommandeFournisseurDispatch($db);
327
328$title = $object->ref." - ".$langs->trans('ReceptionDistribution');
329$help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
330$morejs = array('/fourn/js/lib_dispatch.js.php');
331$numline = 0;
332
333llxHeader('', $title, $help_url, '', 0, 0, $morejs, '', '', 'mod-reception page-card_dispatch');
334
335if ($id > 0 || !empty($ref)) {
336 $typeobject = '';
337 if (!empty($object->origin) && $object->origin_id > 0) {
338 $typeobject = $object->origin;
339 $origin = $object->origin;
340 $origin_id = $object->origin_id;
341 $object->fetch_origin(); // Load property $object->origin_object, $object->commande, $object->propal, ...
342 }
343 $soc = new Societe($db);
344 $soc->fetch($object->socid);
345
346 $author = new User($db);
347 $author->fetch($object->user_author_id);
348
349 $head = reception_prepare_head($object);
350
351 $title = $langs->trans("SupplierOrder");
352 print dol_get_fiche_head($head, 'dispatch', $langs->trans("Reception"), -1, 'dollyrevert');
353
354
355 $formconfirm = '';
356
357 // Confirmation to delete line
358 if ($action == 'ask_deleteline') {
359 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
360 }
361
362 // Call Hook formConfirm
363 $parameters = array('lineid' => $lineid);
364 // Note that $action and $object may be modified by hook
365 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action);
366 if (empty($reshook)) {
367 $formconfirm .= $hookmanager->resPrint;
368 } elseif ($reshook > 0) {
369 $formconfirm = $hookmanager->resPrint;
370 }
371
372 // Print form confirm
373 print $formconfirm;
374
375 // Reception card
376 $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
377 $morehtmlref = '<div class="refidno">';
378 // Ref customer reception
379
380 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', 0, 1);
381 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', null, null, '', 1);
382
383 // Thirdparty
384 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
385 // Project
386 if (isModEnabled('project')) {
387 $langs->load("projects");
388 $morehtmlref .= '<br>';
389 if (0) { // @phpstan-ignore-line Do not change on reception
390 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
391 if ($action != 'classify' && $permissiontoadd) {
392 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
393 }
394 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
395 } else {
396 if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
397 $proj = new Project($db);
398 $proj->fetch((int) $objectsrc->fk_project);
399 $morehtmlref .= $proj->getNomUrl(1);
400 if ($proj->title) {
401 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
402 }
403 }
404 }
405 }
406 $morehtmlref .= '</div>';
407
408 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
409
410
411 print '<div class="fichecenter">';
412 print '<div class="underbanner clearboth"></div>';
413
414 print '<table class="border tableforfield" width="100%">';
415
416 // Linked documents
417 if ($typeobject == 'commande' && $object->origin_object->id && isModEnabled('order')) {
418 print '<tr><td>';
419 print $langs->trans("RefOrder").'</td>';
420 print '<td colspan="3">';
421 print $objectsrc->getNomUrl(1, 'commande');
422 print "</td>\n";
423 print '</tr>';
424 }
425 if ($typeobject == 'propal' && $object->origin_object->id && isModEnabled("propal")) {
426 print '<tr><td>';
427 print $langs->trans("RefProposal").'</td>';
428 print '<td colspan="3">';
429 print $objectsrc->getNomUrl(1, 'reception');
430 print "</td>\n";
431 print '</tr>';
432 }
433 if (($typeobject == 'supplier_order' || $typeobject == 'order_supplier') && $object->origin_object->id && isModEnabled("propal")) {
434 print '<tr><td>';
435 print $langs->trans("SupplierOrder").'</td>';
436 print '<td colspan="3">';
437 print $objectsrc->getNomUrl(1, 'reception');
438 print "</td>\n";
439 print '</tr>';
440 }
441
442 // Date creation
443 print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
444 print '<td colspan="3">'.dol_print_date($object->date_creation, "dayhour", "tzuserrel")."</td>\n";
445 print '</tr>';
446
447 // Delivery date planned
448 print '<tr><td height="10">';
449 print '<table class="nobordernopadding" width="100%"><tr><td>';
450 print $langs->trans('DateDeliveryPlanned');
451 print '</td>';
452 print '</tr></table>';
453 print '</td><td colspan="2">';
454 print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
455 print '</td>';
456 print '</tr>';
457 print '</table>';
458
459 print '<br><br><center>';
460 print '<a href="#" id="resetalltoexpected" class="marginrightonly paddingright marginleftonly paddingleft">'.img_picto("", 'autofill', 'class="pictofixedwidth"').$langs->trans("RestoreWithCurrentQtySaved").'</a></td>';
461 // Link to clear qty
462 print '<a href="#" id="autoreset" class="marginrightonly paddingright marginleftonly paddingleft">'.img_picto("", 'eraser', 'class="pictofixedwidth"').$langs->trans("ClearQtys").'</a></td>';
463 print '<center>';
464
465 print '<br>';
466 $disabled = 0; // This is used to disable or not the bulk selection of target warehouse. No reason to have it disabled so forced to 0.
467
468 $nbproduct = 0; // Nb of predefined product lines to dispatch (already done or not) if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is off (default)
469
470 if ($object->statut == Reception::STATUS_DRAFT || ($object->statut == Reception::STATUS_VALIDATED && !getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION'))) {
471 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
472 $formproduct = new FormProduct($db);
473 $formproduct->loadWarehouses();
474 $entrepot = new Entrepot($db);
475 $listwarehouses = $entrepot->list_array(1);
476
477 print '<form method="post" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
478
479 print '<input type="hidden" name="token" value="'.newToken().'">';
480 print '<input type="hidden" name="action" value="updatelines">';
481 print '<input type="hidden" name="id" value="'.$object->id.'">';
482
483 print '<div class="div-table-responsive-no-min">';
484 print '<table class="noborder centpercent">';
485
486 // Get list of lines from the original Order into $products_dispatched with qty dispatched for each product id
487 $products_dispatched = array();
488 $sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty";
489 $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd";
490 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."receptiondet_batch as l on l.rowid = cfd.fk_elementdet";
491 $sql .= " WHERE cfd.fk_reception = ".((int) $object->id);
492 $sql .= " GROUP BY l.rowid, cfd.fk_product";
493
494 $resql = $db->query($sql);
495 if ($resql) {
496 $num = $db->num_rows($resql);
497 $i = 0;
498
499 if ($num) {
500 while ($i < $num) {
501 $objd = $db->fetch_object($resql);
502 $products_dispatched[$objd->rowid] = price2num($objd->qty, 'MS');
503 $i++;
504 }
505 }
506 $db->free($resql);
507 }
508
509
510 //$sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, SUM(l.qty) as qty,";
511 $sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, l.qty as qty,";
512 $sql .= " p.ref, p.label, p.tobatch, p.fk_default_warehouse";
513 // Enable hooks to alter the SQL query (SELECT)
514 $parameters = array();
515 $reshook = $hookmanager->executeHooks(
516 'printFieldListSelect',
517 $parameters,
518 $object,
519 $action
520 );
521 if ($reshook < 0) {
522 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
523 }
524 $sql .= $hookmanager->resPrint;
525 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
526 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid";
527 $sql .= " WHERE l.fk_commande = ".((int) $objectsrc->id);
528 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
529 $sql .= " AND l.product_type = 0";
530 }
531 // Enable hooks to alter the SQL query (WHERE)
532 $parameters = array();
533 $reshook = $hookmanager->executeHooks(
534 'printFieldListWhere',
535 $parameters,
536 $object,
537 $action
538 );
539 if ($reshook < 0) {
540 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
541 }
542 $sql .= $hookmanager->resPrint;
543
544 //$sql .= " GROUP BY p.ref, p.label, p.tobatch, p.fk_default_warehouse, l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product
545 $sql .= " ORDER BY l.rang, p.ref, p.label";
546
547 $resql = $db->query($sql);
548 if ($resql) {
549 $num = $db->num_rows($resql);
550 $i = 0;
551
552 if ($num) {
553 print '<tr class="liste_titre">';
554
555 print '<td>'.$langs->trans("Description").'</td>';
556 if (isModEnabled('productbatch')) {
557 print '<td class="dispatch_batch_number_title">'.$langs->trans("batch_number").'</td>';
558 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
559 print '<td class="dispatch_dlc_title">'.$langs->trans("SellByDate").'</td>';
560 }
561 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
562 print '<td class="dispatch_dluo_title">'.$langs->trans("EatByDate").'</td>';
563 }
564 } else {
565 print '<td></td>';
566 print '<td></td>';
567 print '<td></td>';
568 }
569 print '<td class="right">'.$langs->trans("SupplierRef").'</td>';
570 print '<td class="right">'.$langs->trans("QtyOrdered").'</td>';
571 if ($object->status == Reception::STATUS_DRAFT) {
572 print '<td class="right">'.$langs->trans("QtyToReceive"); // Qty to dispatch (sum for all lines of batch detail if there is)
573 } else {
574 print '<td class="right">'.$langs->trans("QtyDispatchedShort").'</td>';
575 }
576 print '<td class="right">'.$langs->trans("Details");
577 print '<td width="32"></td>';
578
579 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
580 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
581 print '<td class="right">'.$langs->trans("Price").'</td>';
582 print '<td class="right">'.$langs->trans("ReductionShort").' (%)</td>';
583 print '<td class="right">'.$langs->trans("UpdatePrice").'</td>';
584 }
585 }
586
587 print '<td align="right">'.$langs->trans("Warehouse");
588
589 // Select warehouse to force it everywhere
590 if (count($listwarehouses) > 1) {
591 print '<br><span class="opacitymedium">'.$langs->trans("ForceTo").'</span> '.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 1, 0, 0, '', 0, 0, $disabled, '', 'minwidth100 maxwidth300', 1);
592 } elseif (count($listwarehouses) == 1) {
593 print '<br><span class="opacitymedium">'.$langs->trans("ForceTo").'</span> '.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0, '', 0, 0, $disabled, '', 'minwidth100 maxwidth300', 1);
594 }
595
596 print '</td>';
597
598 // Enable hooks to append additional columns
599 $parameters = array();
600 $reshook = $hookmanager->executeHooks(
601 'printFieldListTitle',
602 $parameters,
603 $object,
604 $action
605 );
606 if ($reshook < 0) {
607 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
608 }
609 print $hookmanager->resPrint;
610
611 print "</tr>\n";
612 }
613
614 $nbfreeproduct = 0; // Nb of lines of free products/services
615 // or nb of line that remain to dispatch if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is on.
616
617 $conf->cache['product'] = array();
618
619 // Loop on each source order line (may be more or less than current number of lines in llx_commande_fournisseurdet)
620 while ($i < $num) {
621 $objp = $db->fetch_object($resql);
622
623 // Hide the free products
624 if (!$objp->fk_product > 0) {
625 $nbfreeproduct++;
626 } else {
627 $alreadydispatched = isset($products_dispatched[$objp->rowid]) ? $products_dispatched[$objp->rowid] : 0;
628 $remaintodispatch = price2num($objp->qty, 5); // Calculation of dispatched
629 if ($remaintodispatch < 0 && !getDolGlobalString('SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN')) {
630 $remaintodispatch = 0;
631 }
632
633 if ($remaintodispatch || !getDolGlobalString('SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED')) {
634 $nbproduct++;
635
636 // To show detail cref and description value, we must make calculation by cref
637 // print ($objp->cref?' ('.$objp->cref.')':'');
638 // if ($objp->description) print '<br>'.nl2br($objp->description);
639 $suffix = '_0_'.$i;
640
641 print "\n";
642 print '<!-- Line to dispatch '.$suffix.' -->'."\n";
643 // hidden fields for js function
644 print '<input id="qty_ordered'.$suffix.'" type="hidden" value="'.$objp->qty.'">';
645 print '<input id="qty_dispatched'.$suffix.'" type="hidden" data-dispatched="'.((float) $alreadydispatched).'" value="'.(float) $alreadydispatched.'">';
646 print '<tr class="oddeven">';
647
648 if (empty($conf->cache['product'][$objp->fk_product])) {
649 $tmpproduct = new Product($db);
650 $tmpproduct->fetch($objp->fk_product);
651 $conf->cache['product'][$objp->fk_product] = $tmpproduct;
652 } else {
653 $tmpproduct = $conf->cache['product'][$objp->fk_product];
654 }
655
656 $linktoprod = $tmpproduct->getNomUrl(1);
657 $linktoprod .= ' - '.$objp->label."\n";
658
659 if (isModEnabled('productbatch')) {
660 if ($objp->tobatch) {
661 // Product
662 print '<td class="tdoverflowmax200">';
663 print $linktoprod;
664 print "</td>";
665 print '<td class="dispatch_batch_number"></td>';
666 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
667 print '<td class="dispatch_dlc"></td>';
668 }
669 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
670 print '<td class="dispatch_dluo"></td>';
671 }
672 } else {
673 // Product
674 print '<td class="tdoverflowmax200">';
675 print $linktoprod;
676 print "</td>";
677 print '<td class="dispatch_batch_number">';
678 print '<span class="opacitymedium small">'.$form->textwithpicto($langs->transnoentitiesnoconv("NA"), $langs->transnoentitiesnoconv("ProductDoesNotUseBatchSerial")).'</small>';
679 print '</td>';
680 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
681 print '<td class="dispatch_dlc"></td>';
682 }
683 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
684 print '<td class="dispatch_dluo"></td>';
685 }
686 }
687 } else {
688 print '<td colspan="4">';
689 print $linktoprod;
690 print "</td>";
691 }
692
693 // Define unit price for PMP calculation
694 $up_ht_disc = $objp->subprice;
695 if (!empty($objp->remise_percent) && !getDolGlobalString('STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
696 $up_ht_disc = price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU');
697 }
698
699 // Supplier ref
700 print '<td class="right">'.$objp->sref.'</td>';
701
702 // Qty ordered
703 print '<td class="right">'.$objp->qty.'</td>';
704
705 // Already dispatched
706 print '<td class="right">'.$alreadydispatched.'</td>';
707
708 print '<td class="right">';
709 print '</td>'; // Qty to dispatch
710 print '<td>';
711 print '</td>'; // Dispatch column
712 print '<td></td>'; // Warehouse column
713
714 $sql = "SELECT cfd.rowid, cfd.qty, cfd.fk_entrepot, cfd.batch, cfd.eatby, cfd.sellby, cfd.fk_product";
715 $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd";
716 $sql .= " WHERE cfd.fk_reception = ".((int) $object->id);
717 $sql .= " AND cfd.fk_element = ".((int) $objectsrc->id);
718 $sql .= " AND cfd.fk_elementdet = ".(int) $objp->rowid;
719
720 //print $sql;
721 $resultsql = $db->query($sql);
722 $j = 0;
723 if ($resultsql) {
724 $numd = $db->num_rows($resultsql);
725
726 while ($j < $numd) {
727 $suffix = "_".$j."_".$i;
728 $objd = $db->fetch_object($resultsql);
729
730 if (isModEnabled('productbatch') && (!empty($objd->batch) || (is_null($objd->batch) && $tmpproduct->status_batch > 0))) {
731 $type = 'batch';
732
733 // Enable hooks to append additional columns
734 $parameters = array(
735 // allows hook to distinguish between the rows with information and the rows with dispatch form input
736 'is_information_row' => true,
737 'j' => $j,
738 'suffix' => $suffix,
739 'objd' => $objd,
740 );
741 $reshook = $hookmanager->executeHooks(
742 'printFieldListValue',
743 $parameters,
744 $object,
745 $action
746 );
747 if ($reshook < 0) {
748 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
749 }
750 print $hookmanager->resPrint;
751
752 print '</tr>';
753
754 print '<!-- line for batch '.$numline.' -->';
755 print '<tr class="oddeven autoresettr" name="'.$type.$suffix.'" data-remove="clear">';
756 print '<td>';
757 print '<input id="fk_commandefourndet'.$suffix.'" name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
758 print '<input id="idline'.$suffix.'" name="idline'.$suffix.'" type="hidden" value="'.$objd->rowid.'">';
759 print '<input name="product_batch'.$suffix.'" type="hidden" value="'.$objd->fk_product.'">';
760
761 print '<!-- This is a U.P. (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
762 if (getDolGlobalString('SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT')) { // Not tested !
763 print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" type="text" value="'.price2num($up_ht_disc, 'MU').'">';
764 } else {
765 print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
766 }
767
768 print '</td>';
769
770 print '<td>';
771 print '<input disabled="" type="text" class="inputlotnumber quatrevingtquinzepercent" id="lot_number'.$suffix.'" name="lot_number'.$suffix.'" value="'.(GETPOSTISSET('lot_number'.$suffix) ? GETPOST('lot_number'.$suffix) : $objd->batch).'">';
772 print '</td>';
773 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
774 print '<td class="nowraponall">';
775 $dlcdatesuffix = !empty($objd->sellby) ? dol_stringtotime($objd->sellby) : dol_mktime(0, 0, 0, GETPOSTINT('dlc'.$suffix.'month'), GETPOSTINT('dlc'.$suffix.'day'), GETPOSTINT('dlc'.$suffix.'year'));
776 print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, 0, 0, 1, '');
777 print '</td>';
778 }
779 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
780 print '<td class="nowraponall">';
781 $dluodatesuffix = !empty($objd->eatby) ? dol_stringtotime($objd->eatby) : dol_mktime(0, 0, 0, GETPOSTINT('dluo'.$suffix.'month'), GETPOSTINT('dluo'.$suffix.'day'), GETPOSTINT('dluo'.$suffix.'year'));
782 print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, 0, 0, 1, '');
783 print '</td>';
784 }
785 print '<td colspan="3">&nbsp;</td>'; // Supplier ref + Qty ordered + qty already dispatched
786 } else {
787 $type = 'dispatch';
788 $colspan = 7;
789 $colspan = (getDolGlobalString('PRODUCT_DISABLE_SELLBY')) ? --$colspan : $colspan;
790 $colspan = (getDolGlobalString('PRODUCT_DISABLE_EATBY')) ? --$colspan : $colspan;
791
792 // Enable hooks to append additional columns
793 $parameters = array(
794 // allows hook to distinguish between the rows with information and the rows with dispatch form input
795 'is_information_row' => true,
796 'j' => $j,
797 'suffix' => $suffix,
798 'objd' => $objd,
799 );
800 $reshook = $hookmanager->executeHooks(
801 'printFieldListValue',
802 $parameters,
803 $object,
804 $action
805 );
806 if ($reshook < 0) {
807 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
808 }
809 print $hookmanager->resPrint;
810
811 print '</tr>';
812
813 print '<!-- line no batch '.$numline.' -->';
814 print '<tr class="oddeven autoresettr" name="'.$type.$suffix.'" data-remove="clear">';
815 print '<td colspan="'.$colspan.'">';
816 print '<input id="fk_commandefourndet'.$suffix.'" name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
817 print '<input id="idline'.$suffix.'" name="idline'.$suffix.'" type="hidden" value="'.$objd->rowid.'">';
818 print '<input name="product'.$suffix.'" type="hidden" value="'.$objd->fk_product.'">';
819
820 print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
821 if (getDolGlobalString('SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT')) { // Not tested !
822 print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" type="text" value="'.price2num($up_ht_disc, 'MU').'">';
823 } else {
824 print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
825 }
826
827 print '</td>';
828 }
829 // Qty to dispatch
830 print '<td class="right nowraponall">';
831 print '<a href="#" id="reset'.$suffix.'" class="resetline">'.img_picto($langs->trans("Reset"), 'eraser', 'class="pictofixedwidth opacitymedium"').'</a>';
832 print '<input id="qty'.$suffix.'" onchange="onChangeDispatchLineQty($(this))" name="qty'.$suffix.'" data-type="'.$type.'" data-index="'.$i.'" class="width50 right qtydispatchinput" value="'.(GETPOSTISSET('qty'.$suffix) ? GETPOSTINT('qty'.$suffix) : $objd->qty).'" data-expected="'.$objd->qty.'">';
833 print '</td>';
834 print '<td>';
835 if (isModEnabled('productbatch') && $objp->tobatch > 0) {
836 $type = 'batch';
837 print img_picto($langs->trans('AddStockLocationLine'), 'split', 'class="splitbutton" '.($numd != $j + 1 ? 'style="display:none"' : '').' onClick="addDispatchLine('.$i.', \''.$type.'\')"');
838 if ($objp->tobatch == 2) {
839 // Product managed with unique serial numbers: allow to enter several serial numbers at once (one line per serial)
840 print img_picto($langs->trans('EnterMultipleSerialNumbers'), 'barcode', 'class="splitbutton marginleftonly" '.($numd != $j + 1 ? 'style="display:none"' : '').' onClick="addDispatchLinesFromSerialList('.$i.', \''.$type.'\')"');
841 }
842 } else {
843 $type = 'dispatch';
844 print img_picto($langs->trans('AddStockLocationLine'), 'split', 'class="splitbutton" '.($numd != $j + 1 ? 'style="display:none"' : '').' onClick="addDispatchLine('.$i.', \''.$type.'\')"');
845 }
846
847 print '</td>';
848
849 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
850 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
851 // Price
852 print '<td class="right">';
853 print '<input id="pu'.$suffix.'" name="pu'.$suffix.'" type="text" size="8" value="'.price((GETPOST('pu'.$suffix) != '' ? price2num(GETPOST('pu'.$suffix)) : $up_ht_disc)).'">';
854 print '</td>';
855
856 // Discount
857 print '<td class="right">';
858 print '<input id="dto'.$suffix.'" name="dto'.$suffix.'" type="text" size="8" value="'.(GETPOST('dto'.$suffix) != '' ? GETPOST('dto'.$suffix) : '').'">';
859 print '</td>';
860
861 // Save price
862 print '<td class="center">';
863 print '<input class="flat checkformerge" type="checkbox" name="saveprice'.$suffix.'" value="'.(GETPOST('saveprice'.$suffix) != '' ? GETPOST('saveprice'.$suffix) : '').'">';
864 print '</td>';
865 }
866 }
867
868 // Warehouse
869 print '<td class="right">';
870 if (count($listwarehouses) > 1) {
871 print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ? GETPOST("entrepot".$suffix) : $objd->fk_entrepot, "entrepot".$suffix, '', 1, 0, $objp->fk_product, '', 1, 0, array(), 'csswarehouse'.$suffix);
872 } elseif (count($listwarehouses) == 1) {
873 print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ? GETPOST("entrepot".$suffix) : $objd->fk_entrepot, "entrepot".$suffix, '', 0, 0, $objp->fk_product, '', 1, 0, array(), 'csswarehouse'.$suffix);
874 } else {
875 $langs->load("errors");
876 print $langs->trans("ErrorNoWarehouseDefined");
877 }
878 print "</td>\n";
879
880 // Enable hooks to append additional columns
881 $parameters = array(
882 'is_information_row' => false, // this is a dispatch form row
883 'i' => $i,
884 'suffix' => $suffix,
885 'objp' => $objp,
886 );
887 $reshook = $hookmanager->executeHooks(
888 'printFieldListValue',
889 $parameters,
890 $object,
891 $action
892 );
893 if ($reshook < 0) {
894 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
895 }
896 print $hookmanager->resPrint;
897
898 print "</tr>\n";
899 $j++;
900
901 $numline++;
902 }
903 $suffix = "_".$j."_".$i;
904 }
905
906 if ($j == 0) {
907 if (isModEnabled('productbatch') && !empty($objp->tobatch)) {
908 $type = 'batch';
909
910 // Enable hooks to append additional columns
911 $parameters = array(
912 // allows hook to distinguish between the rows with information and the rows with dispatch form input
913 'is_information_row' => true,
914 'j' => $j,
915 'suffix' => $suffix,
916 'objp' => $objp,
917 );
918 $reshook = $hookmanager->executeHooks(
919 'printFieldListValue',
920 $parameters,
921 $object,
922 $action
923 );
924 if ($reshook < 0) {
925 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
926 }
927 print $hookmanager->resPrint;
928
929 print '</tr>';
930
931 print '<!-- line for batch '.$numline.' (not dispatched line yet for this order line) -->';
932 print '<tr class="oddeven autoresettr" name="'.$type.$suffix.'">';
933 print '<td>';
934 print '<input id="fk_commandefourndet'.$suffix.'" name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
935 print '<input id="idline'.$suffix.'" name="idline'.$suffix.'" type="hidden" value="-1">';
936 print '<input name="product_batch'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
937
938 print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
939 if (getDolGlobalString('SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT')) { // Not tested !
940 print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" type="text" value="'.price2num($up_ht_disc, 'MU').'">';
941 } else {
942 print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
943 }
944
945 print '</td>';
946
947 print '<td>';
948 print '<input type="text" class="inputlotnumber quatrevingtquinzepercent" id="lot_number'.$suffix.'" name="lot_number'.$suffix.'" value="'.GETPOST('lot_number'.$suffix).'">';
949 print '</td>';
950 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
951 print '<td class="nowraponall">';
952 $dlcdatesuffix = dol_mktime(0, 0, 0, GETPOSTINT('dlc'.$suffix.'month'), GETPOSTINT('dlc'.$suffix.'day'), GETPOSTINT('dlc'.$suffix.'year'));
953 print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, 0, 0, 1, '');
954 print '</td>';
955 }
956 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
957 print '<td class="nowraponall">';
958 $dluodatesuffix = dol_mktime(0, 0, 0, GETPOSTINT('dluo'.$suffix.'month'), GETPOSTINT('dluo'.$suffix.'day'), GETPOSTINT('dluo'.$suffix.'year'));
959 print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, 0, 0, 1, '');
960 print '</td>';
961 }
962 print '<td colspan="3">&nbsp;</td>'; // Supplier ref + Qty ordered + qty already dispatched
963 } else {
964 $type = 'dispatch';
965 $colspan = 7;
966 $colspan = (getDolGlobalString('PRODUCT_DISABLE_SELLBY')) ? --$colspan : $colspan;
967 $colspan = (getDolGlobalString('PRODUCT_DISABLE_EATBY')) ? --$colspan : $colspan;
968
969 // Enable hooks to append additional columns
970 $parameters = array(
971 // allows hook to distinguish between the rows with information and the rows with dispatch form input
972 'is_information_row' => true,
973 'j' => $j,
974 'suffix' => $suffix,
975 'objp' => $objp,
976 );
977 $reshook = $hookmanager->executeHooks(
978 'printFieldListValue',
979 $parameters,
980 $object,
981 $action
982 );
983 if ($reshook < 0) {
984 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
985 }
986 print $hookmanager->resPrint;
987
988 print '</tr>';
989
990 print '<!-- line no batch '.$numline.' (not dispatched line yet for this order line) -->';
991 print '<tr class="oddeven autoresettr" name="'.$type.$suffix.'" data-remove="clear">';
992 print '<td colspan="'.$colspan.'">';
993 print '<input id="fk_commandefourndet'.$suffix.'" name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
994 print '<input id="idline'.$suffix.'" name="idline'.$suffix.'" type="hidden" value="-1">';
995 print '<input name="product'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
996
997 print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
998 if (getDolGlobalString('SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT')) { // Not tested !
999 print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" data-type="text" value="'.price2num($up_ht_disc, 'MU').'">';
1000 } else {
1001 print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
1002 }
1003
1004 print '</td>';
1005 }
1006 // Qty to dispatch
1007 print '<td class="right">';
1008 print '<a href="#" id="reset'.$suffix.'" class="resetline">'.img_picto($langs->trans("Reset"), 'eraser', 'class="pictofixedwidth opacitymedium"').'</a>';
1009 print '<input id="qty'.$suffix.'" onchange="onChangeDispatchLineQty($(this))" name="qty'.$suffix.'" data-index="'.$i.'" data-type="text" class="width50 right qtydispatchinput" value="'.(GETPOSTISSET('qty'.$suffix) ? GETPOSTINT('qty'.$suffix) : (!getDolGlobalString('SUPPLIER_ORDER_DISPATCH_FORCE_QTY_INPUT_TO_ZERO') ? $remaintodispatch : 0)).'" data-expected="'.$remaintodispatch.'">';
1010 print '</td>';
1011 print '<td>';
1012 if (isModEnabled('productbatch') && $objp->tobatch > 0) {
1013 $type = 'batch';
1014 print img_picto($langs->trans('AddStockLocationLine'), 'split', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"');
1015 if ($objp->tobatch == 2) {
1016 // Product managed with unique serial numbers: allow to enter several serial numbers at once (one line per serial)
1017 print img_picto($langs->trans('EnterMultipleSerialNumbers'), 'barcode', 'class="splitbutton marginleftonly" onClick="addDispatchLinesFromSerialList('.$i.', \''.$type.'\')"');
1018 }
1019 } else {
1020 $type = 'dispatch';
1021 print img_picto($langs->trans('AddStockLocationLine'), 'split', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"');
1022 }
1023
1024 print '</td>';
1025
1026 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
1027 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
1028 // Price
1029 print '<td class="right">';
1030 print '<input id="pu'.$suffix.'" name="pu'.$suffix.'" type="text" size="8" value="'.price((GETPOST('pu'.$suffix) != '' ? price2num(GETPOST('pu'.$suffix)) : $up_ht_disc)).'">';
1031 print '</td>';
1032
1033 // Discount
1034 print '<td class="right">';
1035 print '<input id="dto'.$suffix.'" name="dto'.$suffix.'" type="text" size="8" value="'.(GETPOST('dto'.$suffix) != '' ? GETPOST('dto'.$suffix) : '').'">';
1036 print '</td>';
1037
1038 // Save price
1039 print '<td class="center">';
1040 print '<input class="flat checkformerge" type="checkbox" name="saveprice'.$suffix.'" value="'.(GETPOST('saveprice'.$suffix) != '' ? GETPOST('saveprice'.$suffix) : '').'">';
1041 print '</td>';
1042 }
1043 }
1044
1045 // Warehouse
1046 print '<td class="right">';
1047 if (count($listwarehouses) > 1) {
1048 print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ? GETPOST("entrepot".$suffix) : ($objp->fk_default_warehouse ? $objp->fk_default_warehouse : ''), "entrepot".$suffix, '', 1, 0, $objp->fk_product, '', 1, 0, array(), 'csswarehouse'.$suffix);
1049 } elseif (count($listwarehouses) == 1) {
1050 print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ? GETPOST("entrepot".$suffix) : ($objp->fk_default_warehouse ? $objp->fk_default_warehouse : ''), "entrepot".$suffix, '', 0, 0, $objp->fk_product, '', 1, 0, array(), 'csswarehouse'.$suffix);
1051 } else {
1052 $langs->load("errors");
1053 print $langs->trans("ErrorNoWarehouseDefined");
1054 }
1055 print "</td>\n";
1056
1057 // Enable hooks to append additional columns
1058 $parameters = array(
1059 'is_information_row' => false, // this is a dispatch form row
1060 'i' => $i,
1061 'suffix' => $suffix,
1062 'objp' => $objp,
1063 );
1064 $reshook = $hookmanager->executeHooks(
1065 'printFieldListValue',
1066 $parameters,
1067 $object,
1068 $action
1069 );
1070 if ($reshook < 0) {
1071 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1072 }
1073 print $hookmanager->resPrint;
1074 print "</tr>\n";
1075 }
1076 }
1077 }
1078 $i++;
1079 }
1080 $db->free($resql);
1081 } else {
1082 dol_print_error($db);
1083 }
1084
1085 print "</table>\n";
1086 print '</div>';
1087
1088 if ($nbproduct) {
1089 print '<div class="center">';
1090 $parameters = array();
1091 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1092 // modified by hook
1093 if (empty($reshook)) {
1094 /*$checkboxlabel = $langs->trans("CloseReceivedSupplierOrdersAutomatically", $langs->transnoentitiesnoconv('StatusOrderReceivedAll'));
1095
1096 if (empty($conf->reception->enabled)) {
1097 print $langs->trans("Comment").' : ';
1098 print '<input type="text" class="minwidth400" maxlength="128" name="comment" value="';
1099 print GETPOSTISSET("comment") ? GETPOST("comment") : $langs->trans("DispatchSupplierOrder", $object->ref);
1100 // print ' / '.$object->ref_supplier; // Not yet available
1101 print '" class="flat"><br>';
1102
1103 print '<input type="checkbox" checked="checked" name="closeopenorder"> '.$checkboxlabel;
1104 }
1105
1106 $dispatchBt = empty($conf->reception->enabled) ? $langs->trans("Receive") : $langs->trans("CreateReception");
1107
1108 print '<br>';
1109 */
1110
1111 print '<input type="submit" id="submitform" class="button" name="dispatch" value="'.$langs->trans("Save").'"';
1112 $disabled = 0;
1113 if (!$permissiontoreceive) {
1114 $disabled = 1;
1115 }
1116 if (count($listwarehouses) <= 0) {
1117 $disabled = 1;
1118 }
1119 if ($disabled) {
1120 print ' disabled';
1121 }
1122
1123 print '>';
1124 }
1125 print '</div>';
1126 }
1127
1128 // Message if nothing to dispatch
1129 if (!$nbproduct) {
1130 print "<br>\n";
1131 if (!getDolGlobalString('SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED')) {
1132 print '<div class="opacitymedium">'.$langs->trans("NoPredefinedProductToDispatch").'</div>'; // No predefined line at all
1133 } else {
1134 print '<div class="opacitymedium">'.$langs->trans("NoMorePredefinedProductToDispatch").'</div>'; // No predefined line that remain to be dispatched.
1135 }
1136 }
1137
1138 print '</form>';
1139 }
1140
1141 print dol_get_fiche_end();
1142
1143 // Handling of the default warehouse
1144 print '<script type="text/javascript">
1145 $(document).ready(function () {
1146 $("select[name=fk_default_warehouse]").change(function() {
1147 var fk_default_warehouse = $("option:selected", this).val();
1148 $("select[name^=entrepot_]").val(fk_default_warehouse).change();
1149 });
1150
1151 $("#autoreset").click(function() {
1152 $(".autoresettr").each(function(){
1153 id = $(this).attr("name");
1154 idtab = id.split("_");
1155 if ($(this).data("remove") == "clear"){
1156 console.log("We clear the object to expected value")
1157 $("#qty_"+idtab[1]+"_"+idtab[2]).val("");
1158 /*
1159 qtyexpected = $("#qty_"+idtab[1]+"_"+idtab[2]).data("expected")
1160 console.log(qtyexpected);
1161 $("#qty_"+idtab[1]+"_"+idtab[2]).val(qtyexpected);
1162 qtydispatched = $("#qty_dispatched_0_"+idtab[2]).data("dispatched")
1163 $("#qty_dispatched_0_"+idtab[2]).val(qtydispatched);
1164 */
1165 } else {
1166 console.log("We remove the object")
1167 $(this).remove();
1168 $("tr[name^=\'"+idtab[0]+"_\'][name$=\'_"+idtab[2]+"\']:last .splitbutton").show();
1169 }
1170 });
1171 return false;
1172 });
1173
1174 $("#resetalltoexpected").click(function(){
1175 $(".qtydispatchinput").each(function(){
1176 console.log("We reset to expected "+$(this).attr("id")+" qty to dispatch");
1177 $(this).val($(this).data("expected"));
1178 });
1179 return false;
1180 });
1181
1182 $(".resetline").click(function(e){
1183 e.preventDefault();
1184 id = $(this).attr("id");
1185 id = id.split("reset_");
1186 console.log("Reset trigger for id = qty_"+id[1]);
1187 $("#qty_"+id[1]).val("");
1188 return false;
1189 });
1190 });
1191 </script>';
1192}
1193
1194// End of page
1195llxFooter();
1196$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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage table ReceptionLineBatch.
Class to manage predefined suppliers products.
Class to manage comment.
Class to manage warehouses.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage products or services.
Class to manage projects.
Class to manage receptions.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
dol_stringtotime($string, $gm=1, $processnotimeasnoon=0)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:452
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
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).
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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:542
reception_prepare_head(Reception $object)
Prepare array with list of tabs.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
treeview li table
No Email.