dolibarr 22.0.5
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-2023 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-2024 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.'/product/stock/class/productlot.class.php';
44
45if (isModEnabled('project')) {
46 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
47}
48
57// Load translation files required by the page
58$langs->loadLangs(array("bills", "orders", "sendings", "companies", "deliveries", "products", "stocks", "receptions"));
59
60if (isModEnabled('productbatch')) {
61 $langs->load('productbatch');
62}
63
64// Security check
65$id = GETPOSTINT("id");
66$ref = GETPOST('ref');
67$lineid = GETPOSTINT('lineid');
68$action = GETPOST('action', 'aZ09');
69$fk_default_warehouse = GETPOSTINT('fk_default_warehouse');
70$cancel = GETPOST('cancel', 'alpha');
71$confirm = GETPOST('confirm', 'alpha');
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
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}
97
98if (empty($conf->reception->enabled)) {
99 $permissiontoreceive = $user->hasRight("fournisseur", "commande", "receptionner");
100 $permissiontocontrol = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "commande", "receptionner")) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "commande_advance", "check")));
101} else {
102 $permissiontoreceive = $user->hasRight("reception", "creer");
103 $permissiontocontrol = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("reception", "creer")) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("reception", "reception_advance", "validate")));
104}
105
106// $id is id of a purchase order.
107$result = restrictedArea($user, 'fournisseur', $object, 'commande_fournisseur', 'commande');
108
109if (!isModEnabled('stock')) {
111}
112
113// A dispatched line linked to a reception can be updated or deleted only while the reception is a draft
114if (($action == 'confirm_deleteline' || ($action == 'updateline' && empty($cancel))) && $lineid > 0) {
115 $tmpdispatchline = new CommandeFournisseurDispatch($db);
116 if ($tmpdispatchline->fetch($lineid) > 0 && $tmpdispatchline->fk_reception > 0) {
117 require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
118 $tmpreception = new Reception($db);
119 if ($tmpreception->fetch($tmpdispatchline->fk_reception) > 0 && $tmpreception->status != Reception::STATUS_DRAFT) {
120 setEventMessages($langs->trans('StatusOfRefMustBe', $langs->transnoentitiesnoconv('Reception'), $langs->transnoentitiesnoconv('StatusReceptionDraftShort')), null, 'errors');
121 $action = '';
122 }
123 }
124}
125
126$usercancreate = ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"));
127$permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php
128
129
130/*
131 * Actions
132 */
133
134$error = 0;
135$errors = [];
136$parameters = array();
137$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
138if ($reshook < 0) {
139 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
140}
141
142if ($action == 'checkdispatchline' && $permissiontocontrol) {
143 $supplierorderdispatch = new CommandeFournisseurDispatch($db);
144
145 $db->begin();
146
147 $result = $supplierorderdispatch->fetch($lineid);
148 if (!$result) {
149 $error++;
150 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
151 $action = '';
152 }
153
154 if (!$error) {
155 $result = $supplierorderdispatch->setStatut(1);
156 if ($result < 0) {
157 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
158 $error++;
159 $action = '';
160 }
161 }
162
163 if (!$error) {
164 $result = $object->calcAndSetStatusDispatch($user);
165 if ($result < 0) {
166 setEventMessages($object->error, $object->errors, 'errors');
167 $error++;
168 $action = '';
169 }
170 }
171 if (!$error) {
172 $db->commit();
173 } else {
174 $db->rollback();
175 }
176}
177
178if ($action == 'uncheckdispatchline' && $permissiontocontrol) {
179 $supplierorderdispatch = new CommandeFournisseurDispatch($db);
180
181 $db->begin();
182
183 $result = $supplierorderdispatch->fetch($lineid);
184 if (!$result) {
185 $error++;
186 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
187 $action = '';
188 }
189
190 if (!$error) {
191 $result = $supplierorderdispatch->setStatut(0);
192 if ($result < 0) {
193 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
194 $error++;
195 $action = '';
196 }
197 }
198 if (!$error) {
199 $result = $object->calcAndSetStatusDispatch($user);
200 if ($result < 0) {
201 setEventMessages($object->error, $object->errors, 'errors');
202 $error++;
203 $action = '';
204 }
205 }
206 if (!$error) {
207 $db->commit();
208 } else {
209 $db->rollback();
210 }
211}
212
213if ($action == 'denydispatchline' && $permissiontocontrol) {
214 $supplierorderdispatch = new CommandeFournisseurDispatch($db);
215
216 $db->begin();
217
218 $result = $supplierorderdispatch->fetch($lineid);
219 if (!$result) {
220 $error++;
221 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
222 $action = '';
223 }
224
225 if (!$error) {
226 $result = $supplierorderdispatch->setStatut(2);
227 if ($result < 0) {
228 setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
229 $error++;
230 $action = '';
231 }
232 }
233 if (!$error) {
234 $result = $object->calcAndSetStatusDispatch($user);
235 if ($result < 0) {
236 setEventMessages($object->error, $object->errors, 'errors');
237 $error++;
238 $action = '';
239 }
240 }
241 if (!$error) {
242 $db->commit();
243 } else {
244 $db->rollback();
245 }
246}
247
248$saveprice = "savepriceIsNotSet";
249if ($action == 'dispatch' && $permissiontoreceive) {
250 $notrigger = 0;
251
252 $db->begin();
253
254 $pos = 0;
255 foreach ($_POST as $key => $value) {
256 // without batch module enabled
257 $reg = array();
258 if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
259 $pos++;
260
261 // $numline=$reg[2] + 1; // line of product
262 $numline = $pos;
263 $prod = "product_".$reg[1].'_'.$reg[2];
264 $qty = "qty_".$reg[1].'_'.$reg[2];
265 $ent = "entrepot_".$reg[1].'_'.$reg[2];
266 if (empty(GETPOST($ent))) {
267 $ent = $fk_default_warehouse;
268 }
269 $pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount
270 $fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2];
271
272 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
273 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
274 $dto = GETPOSTINT("dto_".$reg[1].'_'.$reg[2]);
275 if (!empty($dto)) {
276 $unit_price = price2num((float) GETPOST("pu_".$reg[1]) * (100 - $dto) / 100, 'MU');
277 }
278 $saveprice = "saveprice_".$reg[1].'_'.$reg[2];
279 }
280 }
281
282 // We ask to move a qty
283 $qtytomove = GETPOSTFLOAT($qty);
284 $puformove = GETPOSTFLOAT($pu);
285 if ($qtytomove != 0) {
286 if (!(GETPOSTINT($ent) > 0)) {
287 dol_syslog('No dispatch for line '.$key.' as no warehouse was chosen.');
288 $text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' '.($numline);
289 setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
290 $error++;
291 }
292
293 if (!$error) {
294 $result = $object->dispatchProduct($user, GETPOSTINT($prod), $qtytomove, GETPOSTINT($ent), $puformove, GETPOST('comment'), '', '', '', GETPOSTINT($fk_commandefourndet), $notrigger);
295 if ($result < 0) {
296 setEventMessages($object->error, $object->errors, 'errors');
297 $error++;
298 }
299
300 if (!$error && getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
301 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
302 $dto = price2num(GETPOST("dto_".$reg[1].'_'.$reg[2]), '');
303 if (empty($dto)) {
304 $dto = 0;
305 }
306
307 //update supplier price
308 if (GETPOSTISSET($saveprice)) {
309 // TODO Use class
310 $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
311 $sql .= " SET unitprice='".price2num(GETPOST($pu), 'MU')."'";
312 $sql .= ", price=".price2num(GETPOST($pu), 'MU')."*quantity";
313 $sql .= ", remise_percent = ".((float) $dto);
314 $sql .= " WHERE fk_soc=".((int) $object->socid);
315 $sql .= " AND fk_product=".(GETPOSTINT($prod));
316
317 $resql = $db->query($sql);
318 }
319 }
320 }
321 }
322 }
323 }
324 // with batch module enabled
325 if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
326 $pos++;
327
328 // eat-by date dispatch
329 // $numline=$reg[2] + 1; // line of product
330 $numline = $pos;
331 $prod = 'product_batch_'.$reg[1].'_'.$reg[2];
332 $qty = 'qty_'.$reg[1].'_'.$reg[2];
333 $ent = 'entrepot_'.$reg[1].'_'.$reg[2];
334 $pu = 'pu_'.$reg[1].'_'.$reg[2];
335 $fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2];
336 $lot = 'lot_number_'.$reg[1].'_'.$reg[2];
337 $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'));
338 $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'));
339
340 $fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2];
341
342 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
343 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
344 $dto = GETPOSTFLOAT("dto_".$reg[1].'_'.$reg[2]);
345 if (!empty($dto)) {
346 $unit_price = price2num((float) GETPOST("pu_".$reg[1]) * (100 - $dto) / 100, 'MU');
347 }
348 $saveprice = "saveprice_".$reg[1].'_'.$reg[2];
349 }
350 }
351
352 // We ask to move a qty
353 $qtytomove = GETPOSTFLOAT($qty);
354 $puformove = GETPOSTFLOAT($pu);
355 if ($qtytomove > 0) {
356 $productId = GETPOSTINT($prod);
357
358 if (!(GETPOSTINT($ent) > 0)) {
359 dol_syslog('No dispatch for line '.$key.' as no warehouse was chosen.');
360 $text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' '.($numline).'-'.((int) $reg[1] + 1);
361 setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
362 $error++;
363 }
364
365 // check sell-by / eat-by date is mandatory
366 /* Not required. Mandatory is checked when we insert the lot. Once lot has been recorded and is known, user can just enter the lot/serial
367 $errorMsgArr = Productlot::checkSellOrEatByMandatoryFromProductIdAndDates($productId, $dDLC, $dDLUO);
368 if (!(GETPOST($lot, 'alpha')) || !empty($errorMsgArr)) {
369 dol_syslog('No dispatch for line '.$key.' as serial/eat-by/sellby date are not set');
370 $text = $langs->transnoentities('atleast1batchfield').', '.$langs->transnoentities('Line').' '.($numline).'-'.($reg[1] + 1);
371 setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
372 $error++;
373 }*/
374 if (!GETPOST($lot, 'alpha') && !$dDLUO && !$dDLC) {
375 dol_syslog('No dispatch for line '.$key.' as serial/eat-by/sellby date are not set');
376 $text = $langs->transnoentities('atleast1batchfield').', '.$langs->transnoentities('Line').' '.($numline).'-'.((int) $reg[1] + 1);
377 setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
378 $error++;
379 }
380
381 if (!$error) {
382 $result = $object->dispatchProduct($user, $productId, $qtytomove, GETPOSTINT($ent), $puformove, GETPOST('comment'), $dDLUO, $dDLC, GETPOST($lot, 'alpha'), GETPOSTINT($fk_commandefourndet), $notrigger);
383 if ($result < 0) {
384 setEventMessages($object->error, $object->errors, 'errors');
385 $error++;
386 }
387
388 if (!$error && getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
389 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
390 $dto = GETPOSTFLOAT("dto_".$reg[1].'_'.$reg[2]);
391 //update supplier price
392 if (GETPOSTISSET($saveprice)) {
393 // TODO Use class
394 $sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
395 $sql .= " SET unitprice = ".price2num(GETPOST($pu), 'MU', 2);
396 $sql .= ", price = ".price2num(GETPOST($pu), 'MU', 2)." * quantity";
397 $sql .= ", remise_percent = ".price2num((empty($dto) ? 0 : $dto), 3, 2)."'";
398 $sql .= " WHERE fk_soc = ".((int) $object->socid);
399 $sql .= " AND fk_product=".((int) $productId);
400
401 $resql = $db->query($sql);
402 }
403 }
404 }
405 }
406 }
407 }
408 }
409
410 if (!$error) {
411 $result = $object->calcAndSetStatusDispatch($user, GETPOST('closeopenorder') ? 1 : 0, GETPOST('comment'));
412 if ($result < 0) {
413 setEventMessages($object->error, $object->errors, 'errors');
414 $error++;
415 }
416 }
417
418 if ($result >= 0 && !$error) {
419 $db->commit();
420
421 setEventMessages($langs->trans("ReceptionsRecorded"), null, 'mesgs');
422
423 header("Location: dispatch.php?id=".$id);
424 exit();
425 } else {
426 $db->rollback();
427 }
428}
429
430$batch = '';
431$eatby = null;
432$sellby = 0;
433$qty = 0;
434$price = '0';
435$entrepot = 0;
436
437// Remove a dispatched line
438if ($action == 'confirm_deleteline' && $confirm == 'yes' && $permissiontoreceive) {
439 $db->begin();
440
441 $supplierorderdispatch = new CommandeFournisseurDispatch($db);
442 $result = $supplierorderdispatch->fetch($lineid);
443 if ($result > 0) {
444 $qty = $supplierorderdispatch->qty;
445 $entrepot = $supplierorderdispatch->fk_entrepot;
446 $product = $supplierorderdispatch->fk_product;
447 $price = price2num(GETPOST('price', 'alpha'), 'MU');
448 $comment = $supplierorderdispatch->comment;
449 $eatby = $supplierorderdispatch->eatby;
450 $sellby = $supplierorderdispatch->sellby;
451 $batch = $supplierorderdispatch->batch;
452
453 $result = $supplierorderdispatch->delete($user);
454 }
455 if ($result < 0) {
456 $errors = $object->errors;
457 $error++;
458 } else {
459 // If module stock is enabled and the stock increase is done on purchase order dispatching
460 if ($entrepot > 0 && isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') && empty($supplierorderdispatch->fk_reception)) {
461 $mouv = new MouvementStock($db);
462 if ($product > 0) {
463 $mouv->origin = &$object;
464 $mouv->setOrigin($object->element, $object->id);
465 $result = $mouv->livraison($user, $product, $entrepot, $qty, (float) $price, $comment, '', (int) $eatby, (int) $sellby, $batch);
466 if ($result < 0) {
467 $errors = $mouv->errors;
468 $error++;
469 }
470 }
471 }
472 }
473 if ($error > 0) {
474 $db->rollback();
475 setEventMessages(null, $errors, 'errors');
476 } else {
477 $db->commit();
478 }
479}
480
481// Update a dispatched line
482if ($action == 'updateline' && $permissiontoreceive && empty($cancel)) {
483 $db->begin();
484
485 $supplierorderdispatch = new CommandeFournisseurDispatch($db);
486 $result = $supplierorderdispatch->fetch($lineid);
487 if ($result > 0) {
488 $qty = $supplierorderdispatch->qty;
489 $entrepot = $supplierorderdispatch->fk_entrepot;
490 $product = $supplierorderdispatch->fk_product;
491 $price = GETPOSTFLOAT('price');
492 $comment = $supplierorderdispatch->comment;
493 // Dates are not given to the stock movements: those of the lot are used (the copy on the line may be outdated)
494 $eatby = '';
495 $sellby = '';
496 $batch = $supplierorderdispatch->batch;
497
498 $supplierorderdispatch->qty = GETPOSTFLOAT('qty', 'MS');
499 $supplierorderdispatch->fk_entrepot = GETPOSTINT('fk_entrepot');
500 $result = $supplierorderdispatch->update($user);
501 }
502 if ($result < 0) {
503 $error++;
504 $errors = $supplierorderdispatch->errors;
505 } else {
506 // If module stock is enabled and the stock increase is done on purchase order dispatching
507 if ($entrepot > 0 && isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
508 $mouv = new MouvementStock($db);
509 if ($product > 0) {
510 $mouv->origin = &$object;
511 $mouv->setOrigin($object->element, $object->id);
512 $result = $mouv->livraison($user, $product, $entrepot, $qty, $price, $comment, '', (int) $eatby, (int) $sellby, $batch);
513 if ($result < 0) {
514 $errors = $mouv->errors;
515 $error++;
516 } else {
517 $mouv->origin = &$object;
518 $result = $mouv->reception($user, $product, $supplierorderdispatch->fk_entrepot, $supplierorderdispatch->qty, $price, $comment, (int) $eatby, (int) $sellby, $batch);
519 if ($result < 0) {
520 $errors = $mouv->errors;
521 $error++;
522 }
523 }
524 }
525 }
526 }
527 if ($error > 0) {
528 $db->rollback();
529 setEventMessages($langs->trans("Error"), $errors, 'errors');
530 } else {
531 $db->commit();
532 }
533}
534
535
536/*
537 * View
538 */
539
540$now = dol_now();
541
542$form = new Form($db);
543$formproduct = new FormProduct($db);
544$warehouse_static = new Entrepot($db);
545$supplierorderdispatch = new CommandeFournisseurDispatch($db);
546
547$title = $object->ref." - ".$langs->trans('OrderDispatch');
548$help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
549$morejs = array('/fourn/js/lib_dispatch.js.php');
550
551llxHeader('', $title, $help_url, '', 0, 0, $morejs, '', '', 'mod-supplier-order page-card_dispatch');
552
553if ($id > 0 || !empty($ref)) {
554 $soc = new Societe($db);
555 $soc->fetch($object->socid);
556
557 $author = new User($db);
558 $author->fetch($object->user_author_id);
559
560 $head = ordersupplier_prepare_head($object);
561
562 $title = $langs->trans("SupplierOrder");
563 print dol_get_fiche_head($head, 'dispatch', $title, -1, 'order');
564
565 $formconfirm = '';
566
567 // Confirmation to delete line
568 if ($action == 'ask_deleteline') {
569 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
570 }
571
572 // Call Hook formConfirm
573 $parameters = array('lineid' => $lineid);
574 // Note that $action and $object may be modified by hook
575 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action);
576 if (empty($reshook)) {
577 $formconfirm .= $hookmanager->resPrint;
578 } elseif ($reshook > 0) {
579 $formconfirm = $hookmanager->resPrint;
580 }
581
582 // Print form confirm
583 print $formconfirm;
584
585 // Supplier order card
586
587 $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
588
589 $morehtmlref = '<div class="refidno">';
590 // Ref supplier
591 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
592 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
593 // Thirdparty
594 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
595 // Project
596 if (isModEnabled('project')) {
597 $langs->load("projects");
598 $morehtmlref .= '<br>';
599 if (0) {
600 $caneditproject = false; // For static analysis
601 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
602 if ($action != 'classify' && $caneditproject) {
603 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
604 }
605 $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');
606 } else {
607 if (!empty($object->fk_project)) {
608 $proj = new Project($db);
609 $proj->fetch($object->fk_project);
610 $morehtmlref .= $proj->getNomUrl(1);
611 if ($proj->title) {
612 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
613 }
614 }
615 }
616 }
617 $morehtmlref .= '</div>';
618
619
620 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
621
622
623 print '<div class="fichecenter">';
624 print '<div class="underbanner clearboth"></div>';
625
626 print '<table class="border tableforfield" width="100%">';
627
628 // Date
629 if ($object->methode_commande_id > 0) {
630 print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>';
631 if ($object->date_commande) {
632 print dol_print_date($object->date_commande, "dayhour")."\n";
633 }
634 print "</td></tr>";
635
636 if ($object->methode_commande) {
637 print '<tr><td>'.$langs->trans("Method").'</td><td>'.$object->getInputMethod().'</td></tr>';
638 }
639 }
640
641 // Author
642 print '<tr><td class="titlefield">'.$langs->trans("AuthorRequest").'</td>';
643 print '<td>'.$author->getNomUrl(-1, '', 0, 0, 0).'</td>';
644 print '</tr>';
645
646 $parameters = array();
647 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
648
649 print "</table>";
650
651 print '</div>';
652
653 // if ($mesg) print $mesg;
654 print '<br>';
655
656 $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.
657
658 // Line of orders
660 print '<br><span class="opacitymedium">'.$langs->trans("OrderStatusNotReadyToDispatch").'</span>';
661 }
662
663
664 print '<br>';
665
666 $listwarehouses = array();
667
671 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
672 $formproduct = new FormProduct($db);
673 $formproduct->loadWarehouses();
674 $entrepot = new Entrepot($db);
675 $listwarehouses = $entrepot->list_array(1);
676
677
678 if (empty($conf->reception->enabled)) {
679 print '<form method="POST" action="dispatch.php?id='.$object->id.'">';
680 } else {
681 print '<form method="post" action="'.dol_buildpath('/reception/card.php', 1).'?originid='.$object->id.'&origin=supplierorder">';
682 }
683
684 print '<input type="hidden" name="token" value="'.newToken().'">';
685 if (empty($conf->reception->enabled)) {
686 print '<input type="hidden" name="action" value="dispatch">';
687 } else {
688 print '<input type="hidden" name="action" value="create">';
689 }
690
691 print '<div class="div-table-responsive-no-min">';
692 print '<table class="noborder centpercent">';
693
694 // Set $products_dispatched with qty dispatched for each product id
695 $products_dispatched = array();
696 $sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty";
697 $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as cfd";
698 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_elementdet";
699 $sql .= " WHERE cfd.fk_element = ".((int) $object->id);
700 $sql .= " GROUP BY l.rowid, cfd.fk_product";
701
702 $resql = $db->query($sql);
703 if ($resql) {
704 $num = $db->num_rows($resql);
705 $i = 0;
706
707 if ($num) {
708 while ($i < $num) {
709 $objd = $db->fetch_object($resql);
710 $products_dispatched[$objd->rowid] = price2num($objd->qty, 'MS');
711 $i++;
712 }
713 }
714 $db->free($resql);
715 }
716
717 //$sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, SUM(l.qty) as qty,";
718 $sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, l.qty as qty,";
719 $sql .= " p.ref, p.label, p.tobatch, p.fk_default_warehouse";
720
721 // Enable hooks to alter the SQL query (SELECT)
722 $parameters = array();
723 $reshook = $hookmanager->executeHooks(
724 'printFieldListSelect',
725 $parameters,
726 $object,
727 $action
728 );
729 if ($reshook < 0) {
730 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
731 }
732 $sql .= $hookmanager->resPrint;
733
734 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
735 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid";
736 $sql .= " WHERE l.fk_commande = ".((int) $object->id);
737 if (!getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
738 $sql .= " AND l.product_type = 0";
739 }
740
741 // Enable hooks to alter the SQL query (WHERE)
742 $parameters = array();
743 $reshook = $hookmanager->executeHooks(
744 'printFieldListWhere',
745 $parameters,
746 $object,
747 $action
748 );
749 if ($reshook < 0) {
750 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
751 }
752 $sql .= $hookmanager->resPrint;
753
754 //$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
755 $sql .= " ORDER BY l.rang, p.ref, p.label";
756
757 // Nb of predefined product lines to dispatch (already done or not) if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is off (default)
758 // or nb of line that remain to dispatch if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is on.
759 $nbproduct = 0;
760
761 $resql = $db->query($sql);
762 if ($resql) {
763 $num = $db->num_rows($resql);
764 $i = 0;
765
766 if ($num) {
767 print '<tr class="liste_titre">';
768
769 print '<td>'.$langs->trans("Description").'</td>';
770 if (isModEnabled('productbatch')) {
771 print '<td class="dispatch_batch_number_title">'.$langs->trans("batch_number").'</td>';
772 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
773 print '<td class="dispatch_dlc_title">'.$langs->trans("SellByDate").'</td>';
774 }
775 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
776 print '<td class="dispatch_dluo_title">'.$langs->trans("EatByDate").'</td>';
777 }
778 } else {
779 print '<td></td>';
780 print '<td></td>';
781 print '<td></td>';
782 }
783 print '<td class="right">'.$langs->trans("SupplierRef").'</td>';
784 print '<td class="right">'.$langs->trans("QtyOrdered").'</td>';
785 print '<td class="right">'.$langs->trans("QtyDispatchedShort").'</td>';
786 print ' <td class="right">'.$langs->trans("QtyToDispatchShort");
787 print '<br><a href="#" id="autoreset">'.img_picto($langs->trans("Reset"), 'eraser', 'class="pictofixedwidth opacitymedium"').$langs->trans("Reset").'</a></td>';
788 print '<td width="32"></td>';
789
790 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
791 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
792 print '<td class="right">'.$langs->trans("Price").'</td>';
793 print '<td class="right">'.$langs->trans("ReductionShort").' (%)</td>';
794 print '<td class="right">'.$langs->trans("UpdatePrice").'</td>';
795 }
796 }
797
798 print '<td align="right">'.$langs->trans("Warehouse");
799
800 // Select warehouse to force it everywhere
801 if (count($listwarehouses) > 1) {
802 print '<br>'.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, $langs->trans("ForceTo"), 0, 0, '', 0, 0, $disabled, '', 'minwidth100 maxwidth300', 1);
803 } elseif (count($listwarehouses) == 1) {
804 print '<br>'.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0, '', 0, 0, $disabled, '', 'minwidth100 maxwidth300', 1);
805 }
806
807 print '</td>';
808
809 // Enable hooks to append additional columns
810 $parameters = array();
811 $reshook = $hookmanager->executeHooks(
812 'printFieldListTitle',
813 $parameters,
814 $object,
815 $action
816 );
817 if ($reshook < 0) {
818 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
819 }
820 print $hookmanager->resPrint;
821
822 print "</tr>\n";
823 }
824
825 $nbfreeproduct = 0; // Nb of lines of free products/services
826
827 $conf->cache['product'] = array();
828
829 // Loop on each source order line (may be more or less than current number of lines in llx_commande_fournisseurdet)
830 while ($i < $num) {
831 $objp = $db->fetch_object($resql);
832
833 // On n'affiche pas les produits libres
834 if (!$objp->fk_product > 0) {
835 $nbfreeproduct++;
836 } else {
837 $alreadydispatched = isset($products_dispatched[$objp->rowid]) ? $products_dispatched[$objp->rowid] : 0;
838 $remaintodispatch = price2num($objp->qty - ((float) $alreadydispatched), 5); // Calculation of dispatched
839 if ($remaintodispatch < 0 && !getDolGlobalString('SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN')) {
840 $remaintodispatch = 0;
841 }
842
843 if ($remaintodispatch || !getDolGlobalString('SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED')) {
844 $nbproduct++;
845
846 // To show detail cref and description value, we must make calculation by cref
847 // print ($objp->cref?' ('.$objp->cref.')':'');
848 // if ($objp->description) print '<br>'.nl2br($objp->description);
849 $suffix = '_0_'.$i;
850
851 print "\n";
852 print '<!-- Line to dispatch '.$suffix.' -->'."\n";
853 // hidden fields for js function
854 print '<input id="qty_ordered'.$suffix.'" type="hidden" value="'.$objp->qty.'">';
855 print '<input id="qty_dispatched'.$suffix.'" type="hidden" value="'.(float) $alreadydispatched.'">';
856 print '<tr class="oddeven">';
857
858 if (empty($conf->cache['product'][$objp->fk_product])) {
859 $tmpproduct = new Product($db);
860 $tmpproduct->fetch($objp->fk_product);
861 $conf->cache['product'][$objp->fk_product] = $tmpproduct;
862 } else {
863 $tmpproduct = $conf->cache['product'][$objp->fk_product];
864 }
865
866 $linktoprod = $tmpproduct->getNomUrl(1);
867 $linktoprod .= ' - '.$objp->label."\n";
868
869 if (isModEnabled('productbatch')) {
870 if ($objp->tobatch) {
871 // Product
872 print '<td>';
873 print $linktoprod;
874 print "</td>";
875 print '<td class="dispatch_batch_number"></td>';
876 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
877 print '<td class="dispatch_dlc"></td>';
878 }
879 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
880 print '<td class="dispatch_dluo"></td>';
881 }
882 } else {
883 // Product
884 print '<td>';
885 print $linktoprod;
886 print "</td>";
887 print '<td class="dispatch_batch_number">';
888 print '<span class="opacitymedium small">'.$langs->trans("ProductDoesNotUseBatchSerial").'</small>';
889 print '</td>';
890 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
891 print '<td class="dispatch_dlc"></td>';
892 }
893 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
894 print '<td class="dispatch_dluo"></td>';
895 }
896 }
897 } else {
898 print '<td colspan="4">';
899 print $linktoprod;
900 print "</td>";
901 }
902
903 // Define unit price for PMP calculation
904 $up_ht_disc = $objp->subprice;
905 if (!empty($objp->remise_percent) && !getDolGlobalString('STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
906 $up_ht_disc = price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU');
907 }
908
909 // Supplier ref
910 print '<td class="right">'.$objp->sref.'</td>';
911
912 // Qty ordered
913 print '<td class="right">'.$objp->qty.'</td>';
914
915 // Already dispatched
916 print '<td class="right">'.$alreadydispatched.'</td>';
917
918 if (isModEnabled('productbatch') && $objp->tobatch > 0) {
919 $type = 'batch';
920 print '<td class="right">';
921 print '</td>'; // Qty to dispatch
922 print '<td>';
923 //print img_picto($langs->trans('AddDispatchBatchLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"');
924 print '</td>'; // Dispatch column
925 print '<td></td>'; // Warehouse column
926
927 // Enable hooks to append additional columns
928 $parameters = array(
929 // allows hook to distinguish between the rows with information and the rows with dispatch form input
930 'is_information_row' => true,
931 'i' => $i,
932 'suffix' => $suffix,
933 'objp' => $objp,
934 );
935 $reshook = $hookmanager->executeHooks(
936 'printFieldListValue',
937 $parameters,
938 $object,
939 $action
940 );
941 if ($reshook < 0) {
942 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
943 }
944 print $hookmanager->resPrint;
945
946 print '</tr>';
947
948 print '<tr class="oddeven" name="'.$type.$suffix.'">';
949 print '<td>';
950 print '<input name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
951 print '<input name="product_batch'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
952
953 print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
954 if (getDolGlobalString('SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT')) { // Not tested !
955 print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" type="text" value="'.price($up_ht_disc).'">';
956 } else {
957 print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price($up_ht_disc).'">';
958 }
959
960 print '</td>';
961
962 print '<td>';
963 print '<input type="text" class="inputlotnumber quatrevingtquinzepercent" id="lot_number'.$suffix.'" name="lot_number'.$suffix.'" value="'.GETPOST('lot_number'.$suffix).'">';
964 print '</td>';
965 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
966 print '<td class="nowraponall">';
967 $dlcdatesuffix = dol_mktime(0, 0, 0, GETPOSTINT('dlc'.$suffix.'month'), GETPOSTINT('dlc'.$suffix.'day'), GETPOSTINT('dlc'.$suffix.'year'));
968 print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, 0, 0, 1, '');
969 print '</td>';
970 }
971 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
972 print '<td class="nowraponall">';
973 $dluodatesuffix = dol_mktime(0, 0, 0, GETPOSTINT('dluo'.$suffix.'month'), GETPOSTINT('dluo'.$suffix.'day'), GETPOSTINT('dluo'.$suffix.'year'));
974 print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, 0, 0, 1, '');
975 print '</td>';
976 }
977 print '<td colspan="3">&nbsp;</td>'; // Supplier ref + Qty ordered + qty already dispatched
978 } else {
979 $type = 'dispatch';
980 $colspan = 7;
981 $colspan = (getDolGlobalString('PRODUCT_DISABLE_SELLBY')) ? --$colspan : $colspan;
982 $colspan = (getDolGlobalString('PRODUCT_DISABLE_EATBY')) ? --$colspan : $colspan;
983 print '<td class="right">';
984 print '</td>'; // Qty to dispatch
985 print '<td>';
986 //print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"');
987 print '</td>'; // Dispatch column
988 print '<td></td>'; // Warehouse column
989
990 // Enable hooks to append additional columns
991 $parameters = array(
992 // allows hook to distinguish between the rows with information and the rows with dispatch form input
993 'is_information_row' => true,
994 'i' => $i,
995 'suffix' => $suffix,
996 'objp' => $objp,
997 );
998 $reshook = $hookmanager->executeHooks(
999 'printFieldListValue',
1000 $parameters,
1001 $object,
1002 $action
1003 );
1004 if ($reshook < 0) {
1005 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1006 }
1007 print $hookmanager->resPrint;
1008
1009 print '</tr>';
1010
1011 print '<tr class="oddeven" name="'.$type.$suffix.'">';
1012 print '<td colspan="'.$colspan.'">';
1013 print '<input name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
1014 print '<input name="product'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
1015
1016 print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
1017 if (getDolGlobalString('SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT')) { // Not tested !
1018 print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" type="text" value="'.price2num($up_ht_disc, 'MU').'">';
1019 } else {
1020 print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
1021 }
1022
1023 print '</td>';
1024 }
1025
1026 // Qty to dispatch
1027 print '<td class="right nowrap">';
1028 if ($remaintodispatch > 0) {
1029 $btnLabel = $langs->trans("Fill").' : '.$remaintodispatch;
1030 print '<button class="auto-fill-qty btn-low-emphasis --btn-icon" data-rowname="qty'.$suffix.'" data-value="'.$remaintodispatch.'" title="'.dol_escape_htmltag($btnLabel).'" aria-label="'.dol_escape_htmltag($btnLabel).'" >'.img_picto($btnLabel, 'fa-arrow-right', 'aria-hidden="true"', 0, 0, 1).'</button>';
1031 }
1032 print '<input id="qty'.$suffix.'" name="qty'.$suffix.'" type="number" step="any" class="width50 right qtydispatchinput" value="'.(GETPOSTISSET('qty'.$suffix) ? GETPOSTINT('qty'.$suffix) : (!getDolGlobalString('SUPPLIER_ORDER_DISPATCH_FORCE_QTY_INPUT_TO_ZERO') ? $remaintodispatch : 0)).'">';
1033 print '<button class="resetline btn-low-emphasis --btn-icon" id="reset'.$suffix.'" title="'.dol_escape_htmltag($langs->trans("Reset")).'" >'.img_picto($langs->trans("Reset"), 'eraser', 'aria-hidden="true"', 0, 0, 1).'</button>';
1034 print '</td>';
1035
1036 print '<td>';
1037 if (isModEnabled('productbatch') && $objp->tobatch > 0) {
1038 $type = 'batch';
1039 print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"');
1040 } else {
1041 $type = 'dispatch';
1042 print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"');
1043 }
1044 print '</td>';
1045
1046 if (getDolGlobalString('SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT')) {
1047 if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
1048 // Price
1049 print '<td class="right">';
1050 print '<input id="pu'.$suffix.'" name="pu'.$suffix.'" type="text" size="8" value="'.price((GETPOST('pu'.$suffix) != '' ? price2num(GETPOST('pu'.$suffix)) : $up_ht_disc)).'">';
1051 print '</td>';
1052
1053 // Discount
1054 print '<td class="right">';
1055 print '<input id="dto'.$suffix.'" name="dto'.$suffix.'" type="text" size="8" value="'.(GETPOST('dto'.$suffix) != '' ? GETPOST('dto'.$suffix) : '').'">';
1056 print '</td>';
1057
1058 // Save price
1059 print '<td class="center">';
1060 print '<input class="flat checkformerge" type="checkbox" name="saveprice'.$suffix.'" value="'.(GETPOST('saveprice'.$suffix) != '' ? GETPOST('saveprice'.$suffix) : '').'">';
1061 print '</td>';
1062 }
1063 }
1064
1065 // Warehouse
1066 print '<td class="right">';
1067 if (count($listwarehouses) > 1) {
1068 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);
1069 } elseif (count($listwarehouses) == 1) {
1070 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);
1071 } else {
1072 $langs->load("errors");
1073 print $langs->trans("ErrorNoWarehouseDefined");
1074 }
1075 print "</td>\n";
1076
1077 // Enable hooks to append additional columns
1078 $parameters = array(
1079 'is_information_row' => false, // this is a dispatch form row
1080 'i' => $i,
1081 'suffix' => $suffix,
1082 'objp' => $objp,
1083 );
1084 $reshook = $hookmanager->executeHooks(
1085 'printFieldListValue',
1086 $parameters,
1087 $object,
1088 $action
1089 );
1090 if ($reshook < 0) {
1091 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1092 }
1093 print $hookmanager->resPrint;
1094
1095 print "</tr>\n";
1096 }
1097 }
1098 $i++;
1099 }
1100 $db->free($resql);
1101 } else {
1102 dol_print_error($db);
1103 }
1104
1105 print "</table>\n";
1106 print '</div>';
1107
1108 if ($nbproduct) {
1109 $checkboxlabel = $langs->trans("CloseReceivedSupplierOrdersAutomatically", $langs->transnoentitiesnoconv('StatusOrderReceivedAll'));
1110
1111 print '<div class="center">';
1112 $parameters = array();
1113 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
1114 // modified by hook
1115 if (empty($reshook)) {
1116 if (empty($conf->reception->enabled)) {
1117 print $langs->trans("Comment").' : ';
1118 print '<input type="text" class="minwidth400" maxlength="128" name="comment" value="';
1119 print GETPOSTISSET("comment") ? GETPOST("comment") : $langs->trans("DispatchSupplierOrder", $object->ref);
1120 // print ' / '.$object->ref_supplier; // Not yet available
1121 print '" class="flat"><br>';
1122
1123 print '<input type="checkbox" checked="checked" name="closeopenorder"> '.$checkboxlabel;
1124 }
1125
1126 $dispatchBt = empty($conf->reception->enabled) ? $langs->trans("Receive") : $langs->trans("CreateReception");
1127
1128 print '<br>';
1129 print '<input type="hidden" name="backtopageforcancel" value="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
1130 print '<input type="submit" class="button" name="dispatch" value="'.dol_escape_htmltag($dispatchBt).'"';
1131 $disabled = 0;
1132 if (!$permissiontoreceive) {
1133 $disabled = 1;
1134 }
1135 if (count($listwarehouses) <= 0) {
1136 $disabled = 1;
1137 }
1138 if ($disabled) {
1139 print ' disabled';
1140 }
1141
1142 print '>';
1143 }
1144 print '</div>';
1145 }
1146
1147 // Message if nothing to dispatch
1148 if (!$nbproduct) {
1149 print "<br>\n";
1150 if (!getDolGlobalString('SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED')) {
1151 print '<div class="opacitymedium">'.$langs->trans("NoPredefinedProductToDispatch").'</div>'; // No predefined line at all
1152 } else {
1153 print '<div class="opacitymedium">'.$langs->trans("NoMorePredefinedProductToDispatch").'</div>'; // No predefined line that remain to be dispatched.
1154 }
1155 }
1156
1157 print '</form>';
1158 }
1159
1160 print dol_get_fiche_end();
1161
1162 // traitement entrepot par défaut
1163 print '<script type="text/javascript">
1164 $(document).ready(function () {
1165 $("select[name=fk_default_warehouse]").change(function() {
1166 var fk_default_warehouse = $("option:selected", this).val();
1167 $("select[name^=entrepot_]").val(fk_default_warehouse).change();
1168 });
1169
1170 $(".auto-fill-qty").on("click touchstart", function(e){
1171 e.preventDefault();
1172 $("input[name="+$(this).data("rowname")+"]").val($(this).data("value")).trigger("change");
1173 });
1174
1175 $("#autoreset").click(function() {
1176 $(".qtydispatchinput").each(function(){
1177 id = $(this).attr("id");
1178 idtab = id.split("_");
1179 if(idtab[1] == 0){
1180 console.log(idtab);
1181 $(this).val("");
1182 $("#qty_dispatched_0_"+idtab[2]).val("0");
1183 } else {
1184 obj = $(this).parent().parent();
1185 nameobj = obj.attr("name");
1186 nametab = nameobj.split("_");
1187 obj.remove();
1188 $("tr[name^=\'"+nametab[0]+"_\'][name$=\'_"+nametab[2]+"\']:last .splitbutton").show();
1189 }
1190 });
1191 });
1192
1193 $(".resetline").click(function(e){
1194 e.preventDefault();
1195 id = $(this).attr("id");
1196 id = id.split("reset_");
1197 console.log("Reset trigger for id = qty_"+id[1]);
1198 $("#qty_"+id[1]).val("");
1199 });
1200 });
1201 </script>';
1202
1203 // List of lines already dispatched
1204 $sql = "SELECT p.rowid as pid, p.ref, p.label,";
1205 $sql .= " e.rowid as warehouse_id, e.ref as entrepot,";
1206 $sql .= " cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.datec";
1207 $sql .= " ,cd.rowid, cd.subprice";
1208 if (isModEnabled('reception')) {
1209 $sql .= ", cfd.fk_reception, r.date_delivery";
1210 }
1211 $sql .= " FROM ".MAIN_DB_PREFIX."product as p,";
1212 $sql .= " ".MAIN_DB_PREFIX."receptiondet_batch as cfd";
1213 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as cd ON cd.rowid = cfd.fk_elementdet";
1214 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid";
1215 if (isModEnabled('reception')) {
1216 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception as r ON cfd.fk_reception = r.rowid";
1217 }
1218 $sql .= " WHERE cfd.fk_element = ".((int) $object->id);
1219 $sql .= " AND cfd.fk_product = p.rowid";
1220 $sql .= " ORDER BY cfd.rowid ASC";
1221
1222 $resql = $db->query($sql);
1223 if ($resql) {
1224 $num = $db->num_rows($resql);
1225 $i = 0;
1226
1227 if ($num > 0) {
1228 print "<br>\n";
1229
1230 print load_fiche_titre($langs->trans("ReceivingForSameOrder"));
1231
1232 print '<div class="div-table-responsive">';
1233 print '<table id="dispatch_received_products" class="noborder centpercent">';
1234
1235 print '<tr class="liste_titre">';
1236 // Reception ref
1237 if (isModEnabled("reception")) {
1238 print '<td>'.$langs->trans("Reception").'</td>';
1239 }
1240 // Product
1241 print '<td>'.$langs->trans("Product").'</td>';
1242 print '<td class="center">'.$langs->trans("DateCreation").'</td>';
1243 print '<td class="center">'.$langs->trans("DateDeliveryPlanned").'</td>';
1244 if (isModEnabled('productbatch')) {
1245 print '<td class="dispatch_batch_number_title">'.$langs->trans("batch_number").'</td>';
1246 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1247 print '<td class="dispatch_dlc_title">'.$langs->trans("SellByDate").'</td>';
1248 }
1249 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1250 print '<td class="dispatch_dluo_title">'.$langs->trans("EatByDate").'</td>';
1251 }
1252 }
1253 print '<td class="right">'.$langs->trans("QtyDispatched").'</td>';
1254 print '<td>'.$langs->trans("Warehouse").'</td>';
1255 print '<td>'.$langs->trans("Comment").'</td>';
1256
1257 // Status
1258 if (getDolGlobalString('SUPPLIER_ORDER_USE_DISPATCH_STATUS') && !isModEnabled("reception")) {
1259 print '<td class="center" colspan="2">'.$langs->trans("Status").'</td>';
1260 } elseif (isModEnabled("reception")) {
1261 print '<td class="center"></td>';
1262 }
1263
1264 print '<td class="center" colspan="2"></td>';
1265
1266 print "</tr>\n";
1267
1268
1269 while ($i < $num) {
1270 $objp = $db->fetch_object($resql);
1271
1272 if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
1273 print '<form name="editdispatchedlines" id="editdispatchedlines" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'#line_'.GETPOSTINT('lineid').'" method="POST">
1274 <input type="hidden" name="token" value="'.newToken().'">
1275 <input type="hidden" name="action" value="updateline">
1276 <input type="hidden" name="mode" value="">
1277 <input type="hidden" name="lineid" value="'.$objp->dispatchlineid.'">';
1278 }
1279
1280 print '<tr class="oddeven" id="line_'.$objp->dispatchlineid.'" >';
1281
1282 // Reception ref
1283 $reception = null;
1284 if (isModEnabled("reception")) {
1285 print '<td class="nowraponall">';
1286 if (!empty($objp->fk_reception)) {
1287 $reception = new Reception($db);
1288 $reception->fetch($objp->fk_reception);
1289 print $reception->getNomUrl(1);
1290 }
1291
1292 print "</td>";
1293 }
1294
1295 // Product
1296 print '<td class="tdoverflowmax150">';
1297 if (empty($conf->cache['product'][$objp->fk_product])) {
1298 $tmpproduct = new Product($db);
1299 $tmpproduct->fetch($objp->fk_product);
1300 $conf->cache['product'][$objp->fk_product] = $tmpproduct;
1301 } else {
1302 $tmpproduct = $conf->cache['product'][$objp->fk_product];
1303 }
1304 print $tmpproduct->getNomUrl(1);
1305 print ' - '.$objp->label;
1306 print "</td>\n";
1307
1308 // Date creation
1309 print '<td class="center">'.dol_print_date($db->jdate($objp->datec), 'day').'</td>';
1310
1311 // Date delivery of reception
1312 if (isModEnabled('reception')) {
1313 print '<td class="center">';
1314 if (!empty($objp->date_delivery)) {
1315 print dol_print_date($db->jdate($objp->date_delivery), 'day');
1316 }
1317 print '</td>';
1318 } else {
1319 print '<td class="center"></td>';
1320 }
1321
1322 // Batch / Eat by / Sell by
1323 if (isModEnabled('productbatch')) {
1324 if ($objp->batch) {
1325 include_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
1326 $lot = new Productlot($db);
1327 $lot->fetch(0, $objp->pid, $objp->batch);
1328 print '<td class="dispatch_batch_number">'.$lot->getNomUrl(1).'</td>';
1329 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1330 print '<td class="dispatch_dlc">'.dol_print_date($lot->sellby, 'day').'</td>';
1331 }
1332 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1333 print '<td class="dispatch_dluo">'.dol_print_date($lot->eatby, 'day').'</td>';
1334 }
1335 } else {
1336 print '<td class="dispatch_batch_number"></td>';
1337 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1338 print '<td class="dispatch_dlc"></td>';
1339 }
1340 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1341 print '<td class="dispatch_dluo"></td>';
1342 }
1343 }
1344 }
1345
1346 // Qty
1347 print '<td class="right">';
1348 if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
1349 print '<input style="width: 50px;" type="text" min="1" name="qty" value="'.$objp->qty.'" />';
1350 } else {
1351 print $objp->qty;
1352 }
1353 print '<input type="hidden" name="price" value="'.$objp->subprice.'" />';
1354 print '</td>';
1355 // Warehouse
1356 print '<td class="tdoverflowmax150">';
1357 if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
1358 $warehouse_id = GETPOSTINT("fk_entrepot") ? GETPOSTINT("fk_entrepot") : ($objp->warehouse_id ? $objp->warehouse_id : '');
1359 if (count($listwarehouses) > 1) {
1360 print $formproduct->selectWarehouses($warehouse_id, "fk_entrepot", '', 1, 0, $objp->fk_product, '', 1, 1, array(), 'csswarehouse');
1361 } elseif (count($listwarehouses) == 1) {
1362 print $formproduct->selectWarehouses($warehouse_id, "fk_entrepot", '', 0, 0, $objp->fk_product, '', 1, 1, array(), 'csswarehouse');
1363 } else {
1364 $langs->load("errors");
1365 print $langs->trans("ErrorNoWarehouseDefined");
1366 }
1367 } else {
1368 $warehouse_static->id = $objp->warehouse_id;
1369 $warehouse_static->label = $objp->entrepot;
1370 print $warehouse_static->getNomUrl(1);
1371 }
1372 print '</td>';
1373
1374 // Comment
1375 print '<td class="tdoverflowmax300" style="white-space: pre;">'.$objp->comment.'</td>';
1376
1377 // Status
1378 if (getDolGlobalString('SUPPLIER_ORDER_USE_DISPATCH_STATUS') && !isModEnabled("reception")) {
1379 print '<td class="right">';
1380 $supplierorderdispatch->status = (empty($objp->status) ? 0 : $objp->status);
1381 // print $supplierorderdispatch->status;
1382 print $supplierorderdispatch->getLibStatut(5);
1383 print '</td>';
1384
1385 // Add button to check/uncheck disaptching
1386 print '<td class="center">';
1387 if (!$permissiontocontrol) {
1388 if (empty($objp->status)) {
1389 print '<a class="button buttonRefused" href="#">'.$langs->trans("Approve").'</a>';
1390 print '<a class="button buttonRefused" href="#">'.$langs->trans("Deny").'</a>';
1391 } else {
1392 print '<a class="button buttonRefused" href="#">'.$langs->trans("Disapprove").'</a>';
1393 print '<a class="button buttonRefused" href="#">'.$langs->trans("Deny").'</a>';
1394 }
1395 } else {
1396 $disabled = '';
1397 if ($object->status == $object::STATUS_RECEIVED_COMPLETELY) {
1398 $disabled = 1;
1399 }
1400 if (empty($objp->status)) {
1401 print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=checkdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Approve").'</a>';
1402 print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=denydispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Deny").'</a>';
1403 }
1404 if ($objp->status == 1) {
1405 print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=uncheckdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Reinit").'</a>';
1406 print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=denydispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Deny").'</a>';
1407 }
1408 if ($objp->status == 2) {
1409 print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=uncheckdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Reinit").'</a>';
1410 print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=checkdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Approve").'</a>';
1411 }
1412 }
1413 print '</td>';
1414 } elseif (isModEnabled("reception")) {
1415 print '<td class="right">';
1416 if ($reception !== null && !empty($reception->id)) {
1417 print $reception->getLibStatut(5);
1418 }
1419 print '</td>';
1420 }
1421
1422 // Action
1423 if ($action != 'editline' || $lineid != $objp->dispatchlineid) {
1424 if (($reception === null) || empty($reception->id) || ($reception->statut == Reception::STATUS_DRAFT)) { // only allow edit on draft reception
1425 print '<td class="linecoledit center">';
1426 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&lineid='.$objp->dispatchlineid.'#line_'.$objp->dispatchlineid.'">';
1427 print img_edit();
1428 print '</a>';
1429 print '</td>';
1430
1431 print '<td class="linecoldelete center">';
1432 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=ask_deleteline&token='.newToken().'&lineid='.$objp->dispatchlineid.'#dispatch_received_products">';
1433 print img_delete();
1434 print '</a>';
1435 print '</td>';
1436 } else {
1437 print '<td></td><td></td>';
1438 }
1439 } else {
1440 print '<td class="center valignmiddle">';
1441 print '<input type="submit" class="button button-save" id="savelinebutton" name="save" value="'.$langs->trans("Save").'" />';
1442 print '</td>';
1443 print '<td class="center valignmiddle">';
1444 print '<input type="submit" class="button button-cancel" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'" />';
1445 print '</td>';
1446 }
1447
1448
1449 print "</tr>\n";
1450 if ($action == 'editline' && $lineid == $objp->dispatchlineid) {
1451 print '</form>';
1452 }
1453
1454 $i++;
1455 }
1456 $db->free($resql);
1457
1458 print "</table>\n";
1459 print '</div>';
1460 }
1461 } else {
1462 dol_print_error($db);
1463 }
1464}
1465
1466// End of page
1467llxFooter();
1468$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
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.
const STATUS_RECEIVED_PARTIALLY
Received partially.
const STATUS_CANCELED
Order canceled.
const STATUS_RECEIVED_COMPLETELY
Received completely.
const STATUS_ORDERSENT
Order sent, shipment on process.
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 stock movements.
Class to manage products or services.
Class with list of lots and properties.
Class to manage projects.
Class to manage receptions.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='')
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
treeview li table
No Email.
ui state ui widget content ui state ui widget header ui state a ui button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:161
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.