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