dolibarr 24.0.3
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// Recuperation de l'id de projet
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($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 } else {
839 $type = 'dispatch';
840 print img_picto($langs->trans('AddStockLocationLine'), 'split', 'class="splitbutton" '.($numd != $j + 1 ? 'style="display:none"' : '').' onClick="addDispatchLine('.$i.', \''.$type.'\')"');
841 }
842
843 print '</td>';
844
845 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
846 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
847 // Price
848 print '<td class="right">';
849 print '<input id="pu'.$suffix.'" name="pu'.$suffix.'" type="text" size="8" value="'.price((GETPOST('pu'.$suffix) != '' ? price2num(GETPOST('pu'.$suffix)) : $up_ht_disc)).'">';
850 print '</td>';
851
852 // Discount
853 print '<td class="right">';
854 print '<input id="dto'.$suffix.'" name="dto'.$suffix.'" type="text" size="8" value="'.(GETPOST('dto'.$suffix) != '' ? GETPOST('dto'.$suffix) : '').'">';
855 print '</td>';
856
857 // Save price
858 print '<td class="center">';
859 print '<input class="flat checkformerge" type="checkbox" name="saveprice'.$suffix.'" value="'.(GETPOST('saveprice'.$suffix) != '' ? GETPOST('saveprice'.$suffix) : '').'">';
860 print '</td>';
861 }
862 }
863
864 // Warehouse
865 print '<td class="right">';
866 if (count($listwarehouses) > 1) {
867 print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ? GETPOST("entrepot".$suffix) : $objd->fk_entrepot, "entrepot".$suffix, '', 1, 0, $objp->fk_product, '', 1, 0, array(), 'csswarehouse'.$suffix);
868 } elseif (count($listwarehouses) == 1) {
869 print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ? GETPOST("entrepot".$suffix) : $objd->fk_entrepot, "entrepot".$suffix, '', 0, 0, $objp->fk_product, '', 1, 0, array(), 'csswarehouse'.$suffix);
870 } else {
871 $langs->load("errors");
872 print $langs->trans("ErrorNoWarehouseDefined");
873 }
874 print "</td>\n";
875
876 // Enable hooks to append additional columns
877 $parameters = array(
878 'is_information_row' => false, // this is a dispatch form row
879 'i' => $i,
880 'suffix' => $suffix,
881 'objp' => $objp,
882 );
883 $reshook = $hookmanager->executeHooks(
884 'printFieldListValue',
885 $parameters,
886 $object,
887 $action
888 );
889 if ($reshook < 0) {
890 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
891 }
892 print $hookmanager->resPrint;
893
894 print "</tr>\n";
895 $j++;
896
897 $numline++;
898 }
899 $suffix = "_".$j."_".$i;
900 }
901
902 if ($j == 0) {
903 if (isModEnabled('productbatch') && !empty($objp->tobatch)) {
904 $type = 'batch';
905
906 // Enable hooks to append additional columns
907 $parameters = array(
908 // allows hook to distinguish between the rows with information and the rows with dispatch form input
909 'is_information_row' => true,
910 'j' => $j,
911 'suffix' => $suffix,
912 'objp' => $objp,
913 );
914 $reshook = $hookmanager->executeHooks(
915 'printFieldListValue',
916 $parameters,
917 $object,
918 $action
919 );
920 if ($reshook < 0) {
921 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
922 }
923 print $hookmanager->resPrint;
924
925 print '</tr>';
926
927 print '<!-- line for batch '.$numline.' (not dispatched line yet for this order line) -->';
928 print '<tr class="oddeven autoresettr" name="'.$type.$suffix.'">';
929 print '<td>';
930 print '<input id="fk_commandefourndet'.$suffix.'" name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
931 print '<input id="idline'.$suffix.'" name="idline'.$suffix.'" type="hidden" value="-1">';
932 print '<input name="product_batch'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
933
934 print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
935 if (getDolGlobalString('SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT')) { // Not tested !
936 print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" type="text" value="'.price2num($up_ht_disc, 'MU').'">';
937 } else {
938 print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
939 }
940
941 print '</td>';
942
943 print '<td>';
944 print '<input type="text" class="inputlotnumber quatrevingtquinzepercent" id="lot_number'.$suffix.'" name="lot_number'.$suffix.'" value="'.GETPOST('lot_number'.$suffix).'">';
945 print '</td>';
946 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
947 print '<td class="nowraponall">';
948 $dlcdatesuffix = dol_mktime(0, 0, 0, GETPOSTINT('dlc'.$suffix.'month'), GETPOSTINT('dlc'.$suffix.'day'), GETPOSTINT('dlc'.$suffix.'year'));
949 print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, 0, 0, 1, '');
950 print '</td>';
951 }
952 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
953 print '<td class="nowraponall">';
954 $dluodatesuffix = dol_mktime(0, 0, 0, GETPOSTINT('dluo'.$suffix.'month'), GETPOSTINT('dluo'.$suffix.'day'), GETPOSTINT('dluo'.$suffix.'year'));
955 print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, 0, 0, 1, '');
956 print '</td>';
957 }
958 print '<td colspan="3">&nbsp;</td>'; // Supplier ref + Qty ordered + qty already dispatched
959 } else {
960 $type = 'dispatch';
961 $colspan = 7;
962 $colspan = (getDolGlobalString('PRODUCT_DISABLE_SELLBY')) ? --$colspan : $colspan;
963 $colspan = (getDolGlobalString('PRODUCT_DISABLE_EATBY')) ? --$colspan : $colspan;
964
965 // Enable hooks to append additional columns
966 $parameters = array(
967 // allows hook to distinguish between the rows with information and the rows with dispatch form input
968 'is_information_row' => true,
969 'j' => $j,
970 'suffix' => $suffix,
971 'objp' => $objp,
972 );
973 $reshook = $hookmanager->executeHooks(
974 'printFieldListValue',
975 $parameters,
976 $object,
977 $action
978 );
979 if ($reshook < 0) {
980 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
981 }
982 print $hookmanager->resPrint;
983
984 print '</tr>';
985
986 print '<!-- line no batch '.$numline.' (not dispatched line yet for this order line) -->';
987 print '<tr class="oddeven autoresettr" name="'.$type.$suffix.'" data-remove="clear">';
988 print '<td colspan="'.$colspan.'">';
989 print '<input id="fk_commandefourndet'.$suffix.'" name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
990 print '<input id="idline'.$suffix.'" name="idline'.$suffix.'" type="hidden" value="-1">';
991 print '<input name="product'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
992
993 print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
994 if (getDolGlobalString('SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT')) { // Not tested !
995 print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" data-type="text" value="'.price2num($up_ht_disc, 'MU').'">';
996 } else {
997 print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
998 }
999
1000 print '</td>';
1001 }
1002 // Qty to dispatch
1003 print '<td class="right">';
1004 print '<a href="#" id="reset'.$suffix.'" class="resetline">'.img_picto($langs->trans("Reset"), 'eraser', 'class="pictofixedwidth opacitymedium"').'</a>';
1005 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.'">';
1006 print '</td>';
1007 print '<td>';
1008 if (isModEnabled('productbatch') && $objp->tobatch > 0) {
1009 $type = 'batch';
1010 print img_picto($langs->trans('AddStockLocationLine'), 'split', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"');
1011 } else {
1012 $type = 'dispatch';
1013 print img_picto($langs->trans('AddStockLocationLine'), 'split', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"');
1014 }
1015
1016 print '</td>';
1017
1018 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
1019 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
1020 // Price
1021 print '<td class="right">';
1022 print '<input id="pu'.$suffix.'" name="pu'.$suffix.'" type="text" size="8" value="'.price((GETPOST('pu'.$suffix) != '' ? price2num(GETPOST('pu'.$suffix)) : $up_ht_disc)).'">';
1023 print '</td>';
1024
1025 // Discount
1026 print '<td class="right">';
1027 print '<input id="dto'.$suffix.'" name="dto'.$suffix.'" type="text" size="8" value="'.(GETPOST('dto'.$suffix) != '' ? GETPOST('dto'.$suffix) : '').'">';
1028 print '</td>';
1029
1030 // Save price
1031 print '<td class="center">';
1032 print '<input class="flat checkformerge" type="checkbox" name="saveprice'.$suffix.'" value="'.(GETPOST('saveprice'.$suffix) != '' ? GETPOST('saveprice'.$suffix) : '').'">';
1033 print '</td>';
1034 }
1035 }
1036
1037 // Warehouse
1038 print '<td class="right">';
1039 if (count($listwarehouses) > 1) {
1040 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);
1041 } elseif (count($listwarehouses) == 1) {
1042 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);
1043 } else {
1044 $langs->load("errors");
1045 print $langs->trans("ErrorNoWarehouseDefined");
1046 }
1047 print "</td>\n";
1048
1049 // Enable hooks to append additional columns
1050 $parameters = array(
1051 'is_information_row' => false, // this is a dispatch form row
1052 'i' => $i,
1053 'suffix' => $suffix,
1054 'objp' => $objp,
1055 );
1056 $reshook = $hookmanager->executeHooks(
1057 'printFieldListValue',
1058 $parameters,
1059 $object,
1060 $action
1061 );
1062 if ($reshook < 0) {
1063 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1064 }
1065 print $hookmanager->resPrint;
1066 print "</tr>\n";
1067 }
1068 }
1069 }
1070 $i++;
1071 }
1072 $db->free($resql);
1073 } else {
1074 dol_print_error($db);
1075 }
1076
1077 print "</table>\n";
1078 print '</div>';
1079
1080 if ($nbproduct) {
1081 print '<div class="center">';
1082 $parameters = array();
1083 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1084 // modified by hook
1085 if (empty($reshook)) {
1086 /*$checkboxlabel = $langs->trans("CloseReceivedSupplierOrdersAutomatically", $langs->transnoentitiesnoconv('StatusOrderReceivedAll'));
1087
1088 if (empty($conf->reception->enabled)) {
1089 print $langs->trans("Comment").' : ';
1090 print '<input type="text" class="minwidth400" maxlength="128" name="comment" value="';
1091 print GETPOSTISSET("comment") ? GETPOST("comment") : $langs->trans("DispatchSupplierOrder", $object->ref);
1092 // print ' / '.$object->ref_supplier; // Not yet available
1093 print '" class="flat"><br>';
1094
1095 print '<input type="checkbox" checked="checked" name="closeopenorder"> '.$checkboxlabel;
1096 }
1097
1098 $dispatchBt = empty($conf->reception->enabled) ? $langs->trans("Receive") : $langs->trans("CreateReception");
1099
1100 print '<br>';
1101 */
1102
1103 print '<input type="submit" id="submitform" class="button" name="dispatch" value="'.$langs->trans("Save").'"';
1104 $disabled = 0;
1105 if (!$permissiontoreceive) {
1106 $disabled = 1;
1107 }
1108 if (count($listwarehouses) <= 0) {
1109 $disabled = 1;
1110 }
1111 if ($disabled) {
1112 print ' disabled';
1113 }
1114
1115 print '>';
1116 }
1117 print '</div>';
1118 }
1119
1120 // Message if nothing to dispatch
1121 if (!$nbproduct) {
1122 print "<br>\n";
1123 if (!getDolGlobalString('SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED')) {
1124 print '<div class="opacitymedium">'.$langs->trans("NoPredefinedProductToDispatch").'</div>'; // No predefined line at all
1125 } else {
1126 print '<div class="opacitymedium">'.$langs->trans("NoMorePredefinedProductToDispatch").'</div>'; // No predefined line that remain to be dispatched.
1127 }
1128 }
1129
1130 print '</form>';
1131 }
1132
1133 print dol_get_fiche_end();
1134
1135 // Handling of the default warehouse
1136 print '<script type="text/javascript">
1137 $(document).ready(function () {
1138 $("select[name=fk_default_warehouse]").change(function() {
1139 var fk_default_warehouse = $("option:selected", this).val();
1140 $("select[name^=entrepot_]").val(fk_default_warehouse).change();
1141 });
1142
1143 $("#autoreset").click(function() {
1144 $(".autoresettr").each(function(){
1145 id = $(this).attr("name");
1146 idtab = id.split("_");
1147 if ($(this).data("remove") == "clear"){
1148 console.log("We clear the object to expected value")
1149 $("#qty_"+idtab[1]+"_"+idtab[2]).val("");
1150 /*
1151 qtyexpected = $("#qty_"+idtab[1]+"_"+idtab[2]).data("expected")
1152 console.log(qtyexpected);
1153 $("#qty_"+idtab[1]+"_"+idtab[2]).val(qtyexpected);
1154 qtydispatched = $("#qty_dispatched_0_"+idtab[2]).data("dispatched")
1155 $("#qty_dispatched_0_"+idtab[2]).val(qtydispatched);
1156 */
1157 } else {
1158 console.log("We remove the object")
1159 $(this).remove();
1160 $("tr[name^=\'"+idtab[0]+"_\'][name$=\'_"+idtab[2]+"\']:last .splitbutton").show();
1161 }
1162 });
1163 return false;
1164 });
1165
1166 $("#resetalltoexpected").click(function(){
1167 $(".qtydispatchinput").each(function(){
1168 console.log("We reset to expected "+$(this).attr("id")+" qty to dispatch");
1169 $(this).val($(this).data("expected"));
1170 });
1171 return false;
1172 });
1173
1174 $(".resetline").click(function(e){
1175 e.preventDefault();
1176 id = $(this).attr("id");
1177 id = id.split("reset_");
1178 console.log("Reset trigger for id = qty_"+id[1]);
1179 $("#qty_"+id[1]).val("");
1180 return false;
1181 });
1182 });
1183 </script>';
1184}
1185
1186// End of page
1187llxFooter();
1188$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:451
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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)
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.
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.
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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:140
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.