dolibarr 22.0.5
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2008 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Simon TOSSER <simon@kornog-computing.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
6 * Copyright (C) 2011-2017 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
8 * Copyright (C) 2013 Marcos García <marcosgdf@gmail.com>
9 * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
10 * Copyright (C) 2014-2017 Francis Appels <francis.appels@yahoo.com>
11 * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
12 * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2016 Yasser Carreón <yacasia@gmail.com>
14 * Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
15 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
16 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 */
31
38// Load Dolibarr environment
39require '../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
41require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
42require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
48require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
49require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
50if (isModEnabled("product") || isModEnabled("service")) {
51 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
52}
53if (isModEnabled("propal")) {
54 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
55}
56require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
57require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.orderline.class.php';
58require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
59if (isModEnabled('productbatch')) {
60 require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
61}
62if (isModEnabled('project')) {
63 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
64 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
65}
74$langs->loadLangs(array("receptions", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal', 'sendings'));
75
76if (isModEnabled('incoterm')) {
77 $langs->load('incoterm');
78}
79if (isModEnabled('productbatch')) {
80 $langs->load('productbatch');
81}
82
83$origin = GETPOST('origin', 'alpha') ? GETPOST('origin', 'alpha') : 'reception'; // Example: commande, propal
84$origin_id = GETPOSTINT('id') ? GETPOSTINT('id') : '';
85$id = $origin_id;
86if (empty($origin_id)) {
87 $origin_id = GETPOSTINT('origin_id'); // Id of order or propal
88}
89if (empty($origin_id)) {
90 $origin_id = GETPOSTINT('object_id'); // Id of order or propal
91}
92if (empty($origin_id)) {
93 $origin_id = GETPOSTINT('originid'); // Id of order or propal
94}
95$ref = GETPOST('ref', 'alpha');
96$line_id = GETPOSTINT('lineid') ? GETPOSTINT('lineid') : 0;
97$facid = GETPOSTINT('facid');
98
99$action = GETPOST('action', 'alpha');
100//Select mail models is same action as presend
101if (GETPOST('modelselected')) {
102 $action = 'presend';
103}
104$confirm = GETPOST('confirm', 'alpha');
105$cancel = GETPOST('cancel', 'alpha');
106$backtopage = GETPOST('backtopage', 'alpha');
107$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
108
109//PDF
110$hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
111$hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
112$hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
113
114$object = new Reception($db);
115$objectorder = new CommandeFournisseur($db);
116$extrafields = new ExtraFields($db);
117
118// fetch optionals attributes and labels
119$extrafields->fetch_name_optionals_label($object->table_element);
120$extrafields->fetch_name_optionals_label($object->table_element_line);
121$extrafields->fetch_name_optionals_label($objectorder->table_element_line);
122
123// Load object. Make an object->fetch
124include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
125
126// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
127$hookmanager->initHooks(array('receptioncard', 'globalcard'));
128
129$date_delivery = dol_mktime(GETPOSTINT('date_deliveryhour'), GETPOSTINT('date_deliverymin'), 0, GETPOSTINT('date_deliverymonth'), GETPOSTINT('date_deliveryday'), GETPOSTINT('date_deliveryyear'));
130
131if ($id > 0 || !empty($ref)) {
132 $object->fetch($id, $ref);
133 $object->fetch_thirdparty();
134
135 $typeobject = '';
136 if (!empty($object->origin)) {
137 $origin = $object->origin;
138 $typeobject = $object->origin;
139
140 $object->fetch_origin();
141 }
142
143 // Set $origin_id and $objectsrc
144 if (($origin == 'order_supplier' || $origin == 'supplier_order') && is_object($object->origin_object) && isModEnabled("supplier_order")) {
145 $origin_id = $object->origin_object->id;
146 $objectsrc = $object->origin_object;
147 }
148}
149
150// Security check
151$socid = '';
152if ($user->socid) {
153 $socid = $user->socid;
154}
155
156// TODO Test on reception module on only
157if (isModEnabled("reception") || $origin == 'reception' || empty($origin)) {
158 $result = restrictedArea($user, 'reception', $object->id);
159} else {
160 // We do not use the reception module, so we test permission on the supplier orders
161 if ($origin == 'supplierorder' || $origin == 'order_supplier') {
162 $result = restrictedArea($user, 'fournisseur', $origin_id, 'commande_fournisseur', 'commande');
163 } elseif (!$user->hasRight($origin, 'lire') && !$user->hasRight($origin, 'read')) {
165 }
166}
167
168if (isModEnabled("reception")) {
169 $permissiontoread = $user->hasRight('reception', 'lire');
170 $permissiontoadd = $user->hasRight('reception', 'creer');
171 $permissiondellink = $user->hasRight('reception', 'creer'); // Used by the include of actions_dellink.inc.php
172 $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate')));
173 $permissiontodelete = $user->hasRight('reception', 'supprimer');
174} else {
175 $permissiontoread = $user->hasRight('fournisseur', 'commande', 'receptionner');
176 $permissiontoadd = $user->hasRight('fournisseur', 'commande', 'receptionner');
177 $permissiondellink = $user->hasRight('fournisseur', 'commande', 'receptionner'); // Used by the include of actions_dellink.inc.php
178 $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('fournisseur', 'commande', 'receptionner')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('fournisseur', 'commande_advance', 'check')));
179 $permissiontodelete = $user->hasRight('fournisseur', 'commande', 'receptionner');
180}
181$permissiontoeditextra = $permissiontoadd;
182if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
183 // For action 'update_extras', is there a specific permission set for the attribute to update
184 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
185}
186
187$error = 0;
188
189
190/*
191 * Actions
192 */
193
194$parameters = array();
195$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
196if ($reshook < 0) {
197 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
198}
199
200if (empty($reshook)) {
201 /*
202 $backurlforlist = DOL_URL_ROOT.'/reception/list.php';
203
204 if (empty($backtopage) || ($cancel && empty($id))) {
205 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
206 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
207 $backtopage = $backurlforlist;
208 } else {
209 $backtopage = dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
210 }
211 }
212 }
213 */
214
215 if ($cancel) {
216 if (!empty($backtopageforcancel)) {
217 header("Location: ".$backtopageforcancel);
218 exit;
219 } elseif (!empty($backtopage)) {
220 header("Location: ".$backtopage);
221 exit;
222 }
223
224 $action = '';
225 }
226
227 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
228
229 // Reopen
230 if ($action == 'reopen' && $permissiontoadd) { // Test on permissions not required here
231 $result = $object->reOpen();
232 if ($result < 0) {
233 setEventMessages($object->error, $object->errors, 'errors');
234 }
235 }
236
237 // Confirm back to draft status
238 if ($action == 'modif' && $permissiontoadd) {
239 $result = $object->setDraft($user);
240 if ($result >= 0) {
241 // Define output language
242 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
243 $outputlangs = $langs;
244 $newlang = '';
245 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
246 $newlang = GETPOST('lang_id', 'aZ09');
247 }
248 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
249 $newlang = $object->thirdparty->default_lang;
250 }
251 if (!empty($newlang)) {
252 $outputlangs = new Translate("", $conf);
253 $outputlangs->setDefaultLang($newlang);
254 }
255 $model = $object->model_pdf;
256 $ret = $object->fetch($id); // Reload to get new records
257 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
258 }
259 } else {
260 setEventMessages($object->error, $object->errors, 'errors');
261 }
262 }
263
264 // Set incoterm
265 if ($action == 'set_incoterms' && isModEnabled('incoterm') && $permissiontoadd) {
266 $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
267 }
268
269 if ($action == 'setref_supplier' && $permissiontoadd) {
270 if ($result < 0) {
271 setEventMessages($object->error, $object->errors, 'errors');
272 }
273
274 $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'), '', null, 'text', '', $user, 'RECEPTION_MODIFY');
275 if ($result < 0) {
276 setEventMessages($object->error, $object->errors, 'errors');
277 $action = 'editref_supplier';
278 } else {
279 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
280 exit;
281 }
282 }
283
284 if ($action == 'update_extras' && $permissiontoeditextra) {
285 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
286
287 $attribute_name = GETPOST('attribute', 'aZ09');
288
289 // Fill array 'array_options' with data from update form
290 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
291 if ($ret < 0) {
292 $error++;
293 }
294
295 if (!$error) {
296 $result = $object->updateExtraField($attribute_name, 'RECEPTION_MODIFY');
297 if ($result < 0) {
298 setEventMessages($object->error, $object->errors, 'errors');
299 $error++;
300 }
301 }
302
303 if ($error) {
304 $action = 'edit_extras';
305 }
306 }
307
308 // Create reception
309 if ($action == 'add' && $permissiontoadd) {
310 $error = 0;
311
312 $db->begin();
313
314 $object->note = GETPOST('note', 'alpha');
315 $object->note_private = GETPOST('note', 'alpha');
316 $object->origin = $origin;
317 $object->origin_id = $origin_id;
318 $object->fk_project = GETPOSTINT('projectid');
319 $object->weight = GETPOST('weight') == '' ? null : GETPOSTINT('weight');
320 $object->trueHeight = GETPOST('trueHeight') == '' ? null : GETPOSTINT('trueHeight');
321 $object->trueWidth = GETPOST('trueWidth') == '' ? null : GETPOSTINT('trueWidth');
322 $object->trueDepth = GETPOST('trueDepth') == '' ? null : GETPOSTINT('trueDepth');
323 $object->size_units = GETPOSTINT('size_units');
324 $object->weight_units = GETPOSTINT('weight_units');
325
326 // On va boucler sur chaque ligne du document d'origine pour completer object reception
327 // avec info diverses + qte a livrer
328
329 if ($object->origin == "supplierorder") {
330 $object->origin = 'order_supplier';
331 $classname = 'CommandeFournisseur';
332 } else {
333 $classname = ucfirst($object->origin);
334 }
335 $objectsrc = new $classname($db);
336 $objectsrc->fetch($object->origin_id);
337
338 $object->socid = $objectsrc->socid;
339 $object->ref_supplier = GETPOST('ref_supplier', 'alpha');
340 $object->model_pdf = GETPOST('model');
341 $object->date_delivery = $date_delivery; // Date delivery planned
342 $object->fk_delivery_address = $objectsrc->fk_delivery_address;
343 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
344 $object->tracking_number = GETPOST('tracking_number', 'alpha');
345 $object->note_private = GETPOST('note_private', 'restricthtml');
346 $object->note_public = GETPOST('note_public', 'restricthtml');
347 $object->fk_incoterms = GETPOSTINT('incoterm_id');
348 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
349
350 $batch_line = array();
351 $stockLine = array();
352 $array_options = array();
353
354 $totalqty = 0;
355
356 $num = 0;
357 foreach ($_POST as $key => $value) {
358 // without batch module enabled
359
360 if (strpos($key, 'qtyasked') !== false) {
361 $num++;
362 }
363 }
364
365 // Loop lines to calculate $totalqty
366 for ($i = 1; $i <= $num; $i++) {
367 $idl = "idl".$i; // id line source
368
369 //$sub_qty = array();
370 //$subtotalqty = 0;
371
372 //$j = 0;
373 //$batch = "batchl".$i."_0";
374 //$stockLocation = "ent1".$i."_0";
375 $qty = "qtyl".$i; // qty
376
377 //reception line for product with no batch management and no multiple stock location
378 if (GETPOST($qty, 'alpha') > 0) {
379 $totalqty += price2num(GETPOST($qty, 'alpha'), 'MS');
380 }
381
382 // Extrafields
383 $array_options[$i] = $extrafields->getOptionalsFromPost($object->table_element_line, (string) $i);
384 }
385
386
387 if ($totalqty > 0) { // There is at least one thing to ship
388 for ($i = 1; $i <= $num; $i++) {
389 $idl = "idl".$i; // id line source
390 $lineToTest = '';
391 $lineId = GETPOSTINT($idl);
392 foreach ($objectsrc->lines as $linesrc) {
393 if ($linesrc->id == $lineId) {
394 $lineToTest = $linesrc;
395 break;
396 }
397 }
398 if (empty($lineToTest)) {
399 continue;
400 }
401 $qty = "qtyl".$i;
402 $comment = "comment".$i;
403 // EATBY <-> DLUO and SELLBY <-> DLC, see productbatch.class.php
404 $eatby = "dluo".$i;
405 $sellby = "dlc".$i;
406 $batch = "batch".$i;
407 $cost_price = "cost_price".$i;
408
409 //var_dump(GETPOST("productl".$i, 'int').' '.GETPOST('entl'.$i, 'int').' '.GETPOST($idl, 'int').' '.GETPOST($qty, 'int').' '.GETPOST($batch, 'alpha'));
410
411 //if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS')) || (GETPOST($qty, 'int') < 0 && getDolGlobalString('RECEPTION_ALLOW_NEGATIVE_QTY'))) {
412 if (GETPOSTFLOAT($qty) > 0 || (GETPOSTFLOAT($qty) == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS'))) {
413 $ent = "entl".$i;
414 $idl = "idl".$i;
415
416 $entrepot_id = is_numeric(GETPOST($ent)) ? GETPOSTINT($ent) : GETPOSTINT('entrepot_id');
417
418 /*
419 if (!empty($lineToTest)) {
420 $fk_product = $lineToTest->fk_product;
421 } else {
422 $fk_product = $linesrc->fk_product;
423 }*/
424 $fk_product = GETPOSTINT("productl".$i);
425
426 if ($entrepot_id < 0) {
427 $entrepot_id = '';
428 }
429 if (!($fk_product > 0) && !getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
430 $entrepot_id = 0;
431 }
432
433 $eatbydate = dol_mktime(12, 0, 0, GETPOSTINT($eatby.'month'), GETPOSTINT($eatby.'day'), GETPOSTINT($eatby.'year'));
434 $sellbydate = dol_mktime(12, 0, 0, GETPOSTINT($sellby.'month'), GETPOSTINT($sellby.'day'), GETPOSTINT($sellby.'year'));
435
436 if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
437 $ret = $object->addline($entrepot_id, GETPOSTINT($idl), (float) price2num(GETPOST($qty), 'MS'), $array_options[$i], GETPOST($comment), $eatbydate, $sellbydate, GETPOST($batch), GETPOSTFLOAT($cost_price, 'MU'));
438 } else {
439 $ret = $object->addline($entrepot_id, GETPOSTINT($idl), (float) price2num(GETPOST($qty), 'MS'), $array_options[$i], GETPOST($comment), $eatbydate, $sellbydate, GETPOST($batch));
440 }
441 if ($ret < 0) {
442 setEventMessages($object->error, $object->errors, 'errors');
443 $error++;
444 }
445 }
446 }
447
448 // Fill array 'array_options' with data from add form
449 $ret = $extrafields->setOptionalsFromPost(null, $object);
450 if ($ret < 0) {
451 $error++;
452 }
453 if (!$error) {
454 $ret = $object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
455
456 if ($ret <= 0) {
457 setEventMessages($object->error, $object->errors, 'errors');
458 $error++;
459 } else {
460 // Define output language
461 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
462 $object->fetch_thirdparty();
463 $outputlangs = $langs;
464 $newlang = '';
465 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
466 $newlang = GETPOST('lang_id', 'aZ09');
467 }
468 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
469 $newlang = $object->thirdparty->default_lang;
470 }
471 if (!empty($newlang)) {
472 $outputlangs = new Translate("", $conf);
473 $outputlangs->setDefaultLang($newlang);
474 }
475 $model = $object->model_pdf;
476 $ret = $object->fetch($object->id); // Reload to get new records
477
478 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
479 if ($result < 0) {
480 dol_print_error($db, $object->error, $object->errors);
481 }
482 }
483 }
484 }
485 } else {
486 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
487 $error++;
488 }
489
490 if (!$error) {
491 $db->commit();
492 header("Location: card.php?id=".$object->id);
493 exit;
494 } else {
495 $db->rollback();
496 //$_GET["commande_id"] = GETPOSTINT('commande_id');
497 $action = 'create';
498 }
499 } elseif ($action == 'confirm_valid' && $confirm == 'yes' && $permissiontovalidate) {
500 $object->fetch_thirdparty();
501
502 $result = $object->valid($user);
503
504 if ($result < 0) {
505 $langs->load("errors");
506 setEventMessages($langs->trans($object->error), null, 'errors');
507 } else {
508 // Define output language
509 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
510 $outputlangs = $langs;
511 $newlang = '';
512 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
513 $newlang = GETPOST('lang_id', 'aZ09');
514 }
515 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
516 $newlang = $object->thirdparty->default_lang;
517 }
518 if (!empty($newlang)) {
519 $outputlangs = new Translate("", $conf);
520 $outputlangs->setDefaultLang($newlang);
521 }
522 $model = $object->model_pdf;
523 $ret = $object->fetch($id); // Reload to get new records
524
525 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
526 if ($result < 0) {
527 dol_print_error($db, $object->error, $object->errors);
528 }
529 }
530 }
531 } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
532 $result = $object->delete($user);
533 if ($result > 0) {
534 header("Location: ".DOL_URL_ROOT.'/reception/index.php');
535 exit;
536 } else {
537 setEventMessages($object->error, $object->errors, 'errors');
538 }
539
540 // TODO add alternative status
541 /*} elseif ($action == 'reopen' && ($user->hasRights('reception', 'creer') || $user->hasRights('reception', 'reception_advance', 'validate'))) {
542 $result = $object->setStatut(0);
543 if ($result < 0) {
544 setEventMessages($object->error, $object->errors, 'errors');
545 }*/
546 } elseif ($action == 'setdate_livraison' && $permissiontoadd) {
547 $datedelivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
548
549 $object->fetch($id);
550 $result = $object->setDeliveryDate($user, $datedelivery);
551 if ($result < 0) {
552 setEventMessages($object->error, $object->errors, 'errors');
553 }
554 } elseif (in_array($action, array('settracking_number', 'settracking_url', 'settrueWeight', 'settrueWidth', 'settrueHeight', 'settrueDepth', 'setshipping_method_id')) && $permissiontoadd) {
555 // Action update
556 $error = 0;
557
558 if ($action == 'settracking_number') { // Test on permission already done
559 $object->tracking_number = trim(GETPOST('tracking_number', 'alpha'));
560 }
561 if ($action == 'settracking_url') { // Test on permission already done
562 $object->tracking_url = trim(GETPOST('tracking_url', 'restricthtml'));
563 }
564 if ($action == 'settrueWeight') { // Test on permission already done
565 $object->trueWeight = GETPOST('trueWeight');
566 $object->weight_units = GETPOSTINT('weight_units');
567 }
568 if ($action == 'settrueWidth') { // Test on permission already done
569 $object->trueWidth = GETPOST('trueWidth');
570 }
571 if ($action == 'settrueHeight') { // Test on permission already done
572 $object->trueHeight = GETPOST('trueHeight');
573 $object->size_units = GETPOSTINT('size_units');
574 }
575 if ($action == 'settrueDepth') { // Test on permission already done
576 $object->trueDepth = GETPOST('trueDepth');
577 }
578 if ($action == 'setshipping_method_id') { // Test on permission already done
579 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
580 }
581
582 if (!$error) {
583 if ($object->update($user) >= 0) {
584 header("Location: card.php?id=".$object->id);
585 exit;
586 }
587 setEventMessages($object->error, $object->errors, 'errors');
588 }
589
590 $action = "";
591 } elseif ($action == 'builddoc' && $permissiontoread) {
592 // Build document
593 // En get ou en post
594 // Save last template used to generate document
595 if (GETPOST('model')) {
596 $object->setDocModel($user, GETPOST('model', 'alpha'));
597 }
598
599 // Define output language
600 $outputlangs = $langs;
601 $newlang = '';
602 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
603 $newlang = GETPOST('lang_id', 'aZ09');
604 }
605 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
606 $newlang = $reception->thirdparty->default_lang;
607 }
608 if (!empty($newlang)) {
609 $outputlangs = new Translate("", $conf);
610 $outputlangs->setDefaultLang($newlang);
611 }
612 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
613 if ($result <= 0) {
614 setEventMessages($object->error, $object->errors, 'errors');
615 $action = '';
616 }
617 } elseif ($action == 'remove_file' && $permissiontoadd) {
618 // Delete file in doc form
619 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
620
621 $upload_dir = $conf->reception->dir_output;
622 $file = $upload_dir.'/'.GETPOST('file');
623 $ret = dol_delete_file($file, 0, 0, 0, $object);
624 if ($ret) {
625 setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
626 } else {
627 setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
628 }
629 } elseif ($action == 'classifybilled' && $permissiontoadd) {
630 $result = $object->setBilled();
631 if ($result >= 0) {
632 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
633 exit();
634 } else {
635 setEventMessages($object->error, $object->errors, 'errors');
636 $action = '';
637 }
638 } elseif ($action == 'classifyclosed' && $permissiontoadd) {
639 $result = $object->setClosed();
640 if ($result >= 0) {
641 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
642 exit();
643 } else {
644 setEventMessages($object->error, $object->errors, 'errors');
645 $action = '';
646 }
647 } elseif ($action == 'deleteline' && !empty($line_id) && $permissiontoread) {
648 // delete a line
649 $lines = $object->lines;
650 $line = new CommandeFournisseurDispatch($db);
651
652 $num_prod = count($lines);
653 for ($i = 0; $i < $num_prod; $i++) {
654 if ($lines[$i]->id == $line_id) {
655 // delete single warehouse line
656 $line->id = $line_id;
657 if (!$error && $line->delete($user) < 0) {
658 $error++;
659 }
660 }
661 unset($_POST["lineid"]);
662 }
663
664 if (!$error) {
665 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
666 exit();
667 } else {
668 setEventMessages($line->error, $line->errors, 'errors');
669 }
670 } elseif ($action == 'updateline' && GETPOST('save') && $permissiontoadd) {
671 // Update a line
672 // Clean parameters
673 $qty = 0;
674 $entrepot_id = 0;
675 $batch_id = 0;
676
677 $lines = $object->lines;
678 $num_prod = count($lines);
679 for ($i = 0; $i < $num_prod; $i++) {
680 if ($lines[$i]->id == $line_id) { // we have found line to update
681 $line = new CommandeFournisseurDispatch($db);
682 $line->fetch($line_id);
683 // Extrafields Lines
684 $extrafields->fetch_name_optionals_label($object->table_element_line);
685 $line->array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
686
687
688 $line->fk_product = $lines[$i]->fk_product;
689
690
691 if ($lines[$i]->fk_product > 0) {
692 // single warehouse reception line
693 $stockLocation = "entl".$line_id;
694 $qty = "qtyl".$line_id;
695 $comment = "comment".$line_id;
696
697
698 $line->id = $line_id;
699 $line->fk_entrepot = GETPOSTINT($stockLocation);
700 $line->qty = GETPOSTFLOAT($qty, 'MS');
701 $line->comment = GETPOST($comment, 'alpha');
702
703 if (isModEnabled('productbatch')) {
704 $batch = "batch".$line_id;
705 $dlc = "dlc".$line_id;
706 $dluo = "dluo".$line_id;
707 $line->batch = GETPOST($batch, 'alpha');
708 // EATBY <-> DLUO
709 $line->eatby = dol_mktime(12, 0, 0, GETPOSTINT($dluo.'month'), GETPOSTINT($dluo.'day'), GETPOSTINT($dluo.'year'));
710 // SELLBY <-> DLC
711 $line->sellby = dol_mktime(12, 0, 0, GETPOSTINT($dlc.'month'), GETPOSTINT($dlc.'day'), GETPOSTINT($dlc.'year'));
712 }
713
714 if ($line->update($user) < 0) {
715 setEventMessages($line->error, $line->errors, 'errors');
716 $error++;
717 }
718 } else { // Product no predefined
719 $qty = "qtyl".$line_id;
720 $line->id = $line_id;
721 $line->qty = GETPOSTFLOAT($qty, 'MS');
722 $line->fk_entrepot = 0;
723 if ($line->update($user) < 0) {
724 setEventMessages($line->error, $line->errors, 'errors');
725 $error++;
726 }
727 unset($_POST[$qty]);
728 }
729 }
730 }
731
732 unset($_POST["lineid"]);
733
734 if (!$error) {
735 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
736 // Define output language
737 $outputlangs = $langs;
738 $newlang = '';
739 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
740 $newlang = GETPOST('lang_id', 'aZ09');
741 }
742 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
743 $newlang = $object->thirdparty->default_lang;
744 }
745 if (!empty($newlang)) {
746 $outputlangs = new Translate("", $conf);
747 $outputlangs->setDefaultLang($newlang);
748 }
749
750 $ret = $object->fetch($object->id); // Reload to get new records
751 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
752 }
753 } else {
754 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To reshow the record we edit
755 exit();
756 }
757 } elseif ($action == 'updateline' && $permissiontoadd && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
758 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To reshow the record we edit
759 exit();
760 }
761
762 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
763
764 // Actions to send emails
765 if (empty($id)) {
766 $id = $facid;
767 }
768 $triggersendname = 'RECEPTION_SENTBYMAIL';
769 $paramname = 'id';
770 $mode = 'emailfromreception';
771 $autocopy = 'MAIN_MAIL_AUTOCOPY_RECEPTION_TO';
772 $trackid = 'rec'.$object->id;
773 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
774}
775
776
777/*
778 * View
779 */
780
781$title = $object->ref.' - '.$langs->trans('Reception');
782
783llxHeader('', $title, 'Reception', '', 0, 0, '', '', '', 'mod-reception page-card');
784
785$form = new Form($db);
786$formfile = new FormFile($db);
787$formproduct = new FormProduct($db);
788$formproject = null;
789if (isModEnabled('project')) {
790 $formproject = new FormProjets($db);
791}
792
793$product_static = new Product($db);
794$reception_static = new Reception($db);
795$warehousestatic = new Entrepot($db);
796
797if ($action == 'create2') {
798 print load_fiche_titre($langs->trans("CreateReception"), '', 'dollyrevert');
799
800 print '<br>'.$langs->trans("ReceptionCreationIsDoneFromOrder");
801 $action = '';
802 $id = '';
803 $ref = '';
804}
805
806// Mode creation.
807if ($action == 'create') {
808 $recept = new Reception($db);
809
810 print load_fiche_titre($langs->trans("CreateReception"));
811 if (!$origin) {
812 setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors');
813 }
814
815 if ($origin) {
816 if ($origin == 'supplierorder') {
817 $classname = 'CommandeFournisseur';
818 } else {
819 $classname = ucfirst($origin);
820 }
821
822 $objectsrc = new $classname($db);
823 if ($objectsrc->fetch($origin_id)) { // This include the fetch_lines
824 $soc = new Societe($db);
825 $soc->fetch($objectsrc->socid);
826
827 $author = new User($db);
828 $author->fetch($objectsrc->user_author_id);
829
830 if (isModEnabled('stock')) {
831 $entrepot = new Entrepot($db);
832 }
833
834 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
835 print '<input type="hidden" name="token" value="'.newToken().'">';
836 print '<input type="hidden" name="action" value="add">';
837 print '<input type="hidden" name="origin" value="'.$origin.'">';
838 print '<input type="hidden" name="origin_id" value="'.$objectsrc->id.'">';
839 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
840 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
841 if (GETPOSTINT('entrepot_id')) {
842 print '<input type="hidden" name="entrepot_id" value="'.GETPOSTINT('entrepot_id').'">';
843 }
844
845 print dol_get_fiche_head();
846
847 print '<table class="border centpercent">';
848
849 // Ref
850 print '<tr><td class="titlefieldcreate fieldrequired">';
851 if ($origin == 'supplierorder' && isModEnabled("supplier_order")) {
852 print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/fourn/commande/card.php?id='.$objectsrc->id.'">'.img_object($langs->trans("ShowOrder"), 'order').' '.$objectsrc->ref;
853 }
854 if ($origin == 'propal' && isModEnabled("propal")) {
855 print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/card.php?id='.$objectsrc->id.'">'.img_object($langs->trans("ShowProposal"), 'propal').' '.$objectsrc->ref;
856 }
857 print '</a></td>';
858 print "</tr>\n";
859
860 // Ref client
861 print '<tr><td>';
862 if ($origin == 'supplier_order') {
863 print $langs->trans('SupplierOrder');
864 } else {
865 print $langs->trans('RefSupplier');
866 }
867 print '</td><td colspan="3">';
868 print '<input type="text" name="ref_supplier" value="'.$objectsrc->ref_supplier.'" />';
869 print '</td>';
870 print '</tr>';
871
872 // Tiers
873 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Company').'</td>';
874 print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
875 print '</tr>';
876
877 // Project
878 if (isModEnabled('project') && $formproject !== null) {
879 $projectid = GETPOSTINT('projectid') ? GETPOSTINT('projectid') : 0;
880 if (empty($projectid) && !empty($objectsrc->fk_project)) {
881 $projectid = $objectsrc->fk_project;
882 }
883 if ($origin == 'project') {
884 $projectid = ($originid ? $originid : 0);
885 }
886
887 $langs->load("projects");
888 print '<tr>';
889 print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
890 print img_picto('', 'project', 'class="paddingright"');
891 print $formproject->select_projects((!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $soc->id : -1), (string) $projectid, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1, 0, 'maxwidth500');
892 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>';
893 print '</td>';
894 print '</tr>';
895 }
896
897 // Date delivery planned
898 print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
899 print '<td colspan="3">';
900 $date_delivery = ($date_delivery ? $date_delivery : $objectsrc->delivery_date); // $date_delivery comes from GETPOST
901 print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);
902 print "</td>\n";
903 print '</tr>';
904
905 // Note Public
906 print '<tr><td>'.$langs->trans("NotePublic").'</td>';
907 print '<td colspan="3">';
908 $doleditor = new DolEditor('note_public', $objectsrc->note_public, '', 60, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
909 print $doleditor->Create(1);
910 print "</td></tr>";
911
912 // Note Private
913 if ($objectsrc->note_private && !$user->socid) {
914 print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
915 print '<td colspan="3">';
916 $doleditor = new DolEditor('note_private', $objectsrc->note_private, '', 60, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
917 print $doleditor->Create(1);
918 print "</td></tr>";
919 }
920
921 // Weight
922 print '<tr><td>';
923 print $langs->trans("Weight");
924 print '</td><td colspan="3"><input name="weight" size="4" value="'.GETPOST('weight').'"> ';
925 $text = $formproduct->selectMeasuringUnits("weight_units", "weight", (string) GETPOSTINT('weight_units'), 0, 2);
926 $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
927 print $form->textwithpicto($text, $htmltext);
928 print '</td></tr>';
929 // Dim
930 print '<tr><td>';
931 print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth");
932 print ' </td><td colspan="3"><input name="trueWidth" size="4" value="'.GETPOST('trueWidth').'">';
933 print ' x <input name="trueHeight" size="4" value="'.GETPOST('trueHeight').'">';
934 print ' x <input name="trueDepth" size="4" value="'.GETPOST('trueDepth').'">';
935 print ' ';
936 $text = $formproduct->selectMeasuringUnits("size_units", "size", (string) GETPOSTINT('size_units'), 0, 2);
937 $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
938 print $form->textwithpicto($text, $htmltext);
939 print '</td></tr>';
940
941 // Delivery method
942 print "<tr><td>".$langs->trans("ReceptionMethod")."</td>";
943 print '<td colspan="3">';
944 $recept->fetch_delivery_methods();
945 print $form->selectarray("shipping_method_id", $recept->meths, GETPOSTINT('shipping_method_id'), 1, 0, 0, "", 1);
946 if ($user->admin) {
947 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
948 }
949 print "</td></tr>\n";
950
951 // Tracking number
952 print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
953 print '<td colspan="3">';
954 print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number', 'alpha').'">';
955 print "</td></tr>\n";
956
957 // Other attributes
958 $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'cols' => '3', 'socid' => $socid);
959 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $recept, $action); // Note that $action and $objectsrc may have been modified by hook
960 print $hookmanager->resPrint;
961
962 // Here $object can be of an object Reception
963 $extrafields->fetch_name_optionals_label($object->table_element);
964 if (empty($reshook) && !empty($extrafields->attributes[$object->table_element]['label'])) {
965 // copy from order
966 if ($objectsrc->fetch_optionals() > 0) {
967 $recept->array_options = array_merge($recept->array_options, $objectsrc->array_options);
968 }
969 print $recept->showOptionals($extrafields, 'create', $parameters);
970 }
971
972 // Incoterms
973 if (isModEnabled('incoterm')) {
974 print '<tr>';
975 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $objectsrc->label_incoterms, 1).'</label></td>';
976 print '<td colspan="3" class="maxwidthonsmartphone">';
977 print $form->select_incoterms((!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : ''), (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : ''));
978 print '</td></tr>';
979 }
980
981 // Document model
982 include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
984
985 if (is_array($list) && count($list) > 1) {
986 print "<tr><td>".$langs->trans("DefaultModel")."</td>";
987 print '<td colspan="3">';
988 print $form->selectarray('model', $list, getDolGlobalString('RECEPTION_ADDON_PDF'));
989 print "</td></tr>\n";
990 }
991
992 print "</table>";
993
994 print dol_get_fiche_end();
995
996 // Number of lines show on the reception card
997 $numAsked = 0;
998
1003 $suffix2numAsked = array();
1004 $dispatchLines = array();
1005
1006 foreach ($_POST as $key => $value) {
1007 // If create form is coming from the button "Create Reception" of previous page
1008
1009 // without batch module enabled or product with no lot/serial
1010 $reg = array();
1011 if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
1012 $numAsked++;
1013 $paramSuffix = $reg[1] . '_' . $reg[2];
1014 $suffix2numAsked[$paramSuffix] = $numAsked;
1015
1016 // $numline=$reg[2] + 1; // line of product
1017 $numline = $numAsked;
1018
1019 $prod = "product_" . $paramSuffix;
1020 $qty = "qty_" . $paramSuffix;
1021 $ent = "entrepot_" . $paramSuffix;
1022 $pu = "pu_" . $paramSuffix; // This is unit price including discount
1023 $fk_commandefourndet = "fk_commandefourndet_" . $paramSuffix;
1024 $dispatchLines[$numAsked] = array('paramSuffix' => $paramSuffix, 'prod' => GETPOSTINT($prod), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' => GETPOSTINT($ent), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' => GETPOST('comment'), 'fk_commandefourndet' => GETPOSTINT($fk_commandefourndet));
1025 }
1026
1027 // with batch module enabled and product with lot/serial
1028 if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
1029 $numAsked++;
1030 $paramSuffix = $reg[1] . '_' . $reg[2];
1031 $suffix2numAsked[$paramSuffix] = $numAsked;
1032
1033 // eat-by date dispatch
1034 // $numline=$reg[2] + 1; // line of product
1035 $numline = $numAsked;
1036
1037 $prod = 'product_batch_' . $paramSuffix;
1038 $qty = 'qty_' . $paramSuffix;
1039 $ent = 'entrepot_' . $paramSuffix;
1040 $pu = 'pu_' . $paramSuffix;
1041 $lot = 'lot_number_' . $paramSuffix;
1042 $dDLUO = dol_mktime(12, 0, 0, GETPOSTINT('dluo_'.$paramSuffix.'month'), GETPOSTINT('dluo_'.$paramSuffix.'day'), GETPOSTINT('dluo_'.$paramSuffix.'year'));
1043 $dDLC = dol_mktime(12, 0, 0, GETPOSTINT('dlc_'.$paramSuffix.'month'), GETPOSTINT('dlc_'.$paramSuffix.'day'), GETPOSTINT('dlc_'.$paramSuffix.'year'));
1044 $fk_commandefourndet = 'fk_commandefourndet_'.$paramSuffix;
1045 $dispatchLines[$numAsked] = array('paramSuffix' => $paramSuffix, 'prod' => GETPOSTINT($prod), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' => GETPOSTINT($ent), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' => GETPOST('comment'), 'fk_commandefourndet' => GETPOSTINT($fk_commandefourndet), 'DLC' => $dDLC, 'DLUO' => $dDLUO, 'lot' => GETPOST($lot));
1046 }
1047
1048 // If create form is coming from same page, it means that post was sent but an error occurred
1049 if (preg_match('/^productl([0-9]+)$/i', $key, $reg)) {
1050 $numAsked++;
1051 $paramSuffix = $reg[1];
1052 $suffix2numAsked[$paramSuffix] = $numAsked;
1053
1054 // eat-by date dispatch
1055 // $numline=$reg[2] + 1; // line of product
1056 $numline = $numAsked;
1057
1058 $prod = 'productid'.$paramSuffix;
1059 $comment = 'comment'.$paramSuffix;
1060 $qty = 'qtyl'.$paramSuffix;
1061 $ent = 'entl'.$paramSuffix;
1062 $pu = 'pul'.$paramSuffix;
1063 $lot = 'batch'.$paramSuffix;
1064 $dDLUO = dol_mktime(12, 0, 0, GETPOSTINT('dluo'.$paramSuffix.'month'), GETPOSTINT('dluo'.$paramSuffix.'day'), GETPOSTINT('dluo'.$paramSuffix.'year'));
1065 $dDLC = dol_mktime(12, 0, 0, GETPOSTINT('dlc'.$paramSuffix.'month'), GETPOSTINT('dlc'.$paramSuffix.'day'), GETPOSTINT('dlc'.$paramSuffix.'year'));
1066 $fk_commandefourndet = 'fk_commandefournisseurdet'.$paramSuffix;
1067 $dispatchLines[$numAsked] = array('prod' => GETPOSTINT($prod), 'qty' => price2num(GETPOST($qty), 'MS'), 'ent' => GETPOSTINT($ent), 'pu' => price2num(GETPOST($pu), 'MU'), 'comment' => GETPOST($comment), 'fk_commandefourndet' => GETPOSTINT($fk_commandefourndet), 'DLC' => $dDLC, 'DLUO' => $dDLUO, 'lot' => GETPOST($lot));
1068 }
1069 }
1070
1071 // If extrafield values are passed in the HTTP query, assign them to the correct dispatch line
1072 // Note that if an extrafield with the same name exists in the origin supplier order line, the value
1073 // from the HTTP query will be ignored
1074 foreach ($suffix2numAsked as $suffix => $n) {
1075 $dispatchLines[$n]['array_options'] = $extrafields->getOptionalsFromPost('receptiondet_batch', '_' . $suffix, '');
1076 }
1077
1078 print '<script type="text/javascript">
1079 jQuery(document).ready(function() {
1080 jQuery("#autofill").click(function(event) {
1081 event.preventDefault();';
1082 $i = 1;
1083 while ($i <= $numAsked) {
1084 print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
1085 $i++;
1086 }
1087 print '});
1088 jQuery("#autoreset").click(function(event) {
1089 event.preventDefault();';
1090 $i = 1;
1091 while ($i <= $numAsked) {
1092 print 'jQuery("#qtyl'.$i.'").val(0);'."\n";
1093 $i++;
1094 }
1095 print '});
1096 });
1097 </script>';
1098
1099 print '<br>';
1100
1101 print '<table class="noborder centpercent">';
1102
1103 // Load receptions already done for same order
1104 $objectsrc->loadReceptions();
1105
1106 if ($numAsked) {
1107 print '<tr class="liste_titre">';
1108 print '<td>'.$langs->trans("Description").'</td>';
1109 print '<td>'.$langs->trans("Comment").'</td>';
1110 print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
1111 print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
1112 print '<td class="center">'.$langs->trans("QtyToReceive");
1113 if (getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1114 print '<td>'.$langs->trans("BuyingPrice").'</td>';
1115 }
1116 if (!isModEnabled('productbatch')) {
1117 print ' <br><center><a href="#" id="autofill"><span class="fas fa-fill pictofixedwidth" style=""></span> '.$langs->trans("Fill").'</a>';
1118 print ' &nbsp; &nbsp; <a href="#" id="autoreset"><span class="fas fa-eraser pictofixedwidth" style=""></span>'.$langs->trans("Reset").'</a></center><br>';
1119 }
1120 print '</td>';
1121 if (isModEnabled('stock')) {
1122 print '<td class="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
1123 }
1124 if (isModEnabled('productbatch')) {
1125 print '<td class="left">'.$langs->trans("batch_number").'</td>';
1126 if (!getDolGlobalInt('PRODUCT_DISABLE_SELLBY')) {
1127 print '<td class="left">'.$langs->trans("SellByDate").'</td>';
1128 }
1129 if (!getDolGlobalInt('PRODUCT_DISABLE_EATBY')) {
1130 print '<td class="left">'.$langs->trans("EatByDate").'</td>';
1131 }
1132 }
1133 print "</tr>\n";
1134 }
1135
1136 // $objectsrc->lines contains the line of the purchase order
1137 // $dispatchLines is an array with dispatching detail (with product, qty, warehouse and fk_commandefourndet). One purchase order line may have n of this dispatch lines.
1138
1139 $arrayofpurchaselinealreadyoutput = array();
1140
1141 // $_POST contains fk_commandefourndet_X_Y where Y is num of product line and X is number of split lines
1142 $indiceAsked = 1;
1143 while ($indiceAsked <= $numAsked) { // Loop on $dispatchLines. Warning: $dispatchLines must be sorted by fk_commandefourndet (it is a regroupment key on output)
1144 $product = new Product($db);
1145 $line = new CommandeFournisseurLigne($db); // By default
1146
1147 // We search the purchase order line that is linked to the dispatchLines
1148 foreach ($objectsrc->lines as $supplierLine) {
1149 if ($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id) {
1150 $line = $supplierLine;
1151 break;
1152 }
1153 }
1154
1155 // Now $line can be CommandeFournisseurLigne but could be other type of line.
1156
1157 // Show product and description
1158 $type = $line->product_type ? $line->product_type : $line->fk_product_type;
1159 // Try to enhance type detection using date_start and date_end for free lines where type was not saved.
1160 if (!empty($line->date_start)) {
1161 $type = 1;
1162 }
1163 if (!empty($line->date_end)) {
1164 $type = 1;
1165 }
1166
1167 print '<!-- line fk_commandefourndet='.$line->id.' for product='.$line->fk_product.' -->'."\n";
1168 print '<tr class="oddeven">'."\n";
1169
1170 // Product label
1171 if ($line->fk_product > 0) { // If predefined product
1172 $product->fetch($line->fk_product);
1173 $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
1174 //var_dump($product->stock_warehouse[1]);
1175 //var_dump($dispatchLines[$indiceAsked]);
1176
1177 print '<td>';
1178 print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne
1179
1180 print '<input type="hidden" name="productl'.$indiceAsked.'" value="'.$line->fk_product.'">';
1181
1182 if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
1183 print '<input type="hidden" name="productid'.$indiceAsked.'" value="'.$line->fk_product.'">';
1184
1185 // Show product and description
1186 $product_static = $product;
1187
1188 $text = $product_static->getNomUrl(1);
1189 $text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label);
1190 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($line->desc));
1191 print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i);
1192
1193 // Show range
1194 print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
1195
1196 // Add description in form
1197 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
1198 print ($line->desc && $line->desc != $line->product_label) ? '<br>'.dol_htmlentitiesbr($line->desc) : '';
1199 }
1200 }
1201 print '</td>';
1202 } else {
1203 print "<td>";
1204 if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
1205 if ($type == 1) {
1206 $text = img_object($langs->trans('Service'), 'service');
1207 } else {
1208 $text = img_object($langs->trans('Product'), 'product');
1209 }
1210
1211 if (!empty($line->label)) {
1212 $text .= ' <strong>'.$line->label.'</strong>';
1213 print $form->textwithtooltip($text, $line->desc, 3, 0, '', (string) $i);
1214 } else {
1215 print $text.' '.nl2br($line->desc);
1216 }
1217
1218 // Show range
1219 print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
1220 }
1221 print "</td>\n";
1222 }
1223
1224 // Comment
1225 //$defaultcomment = 'Line create from order line id '.$line->id;
1226 $defaultcomment = $dispatchLines[$indiceAsked]['comment'];
1227 print '<td>';
1228 print '<input type="text" class="maxwidth100" name="comment'.$indiceAsked.'" value="'.$defaultcomment.'">';
1229 print '</td>';
1230
1231 // Qty in source purchase order line
1232 print '<td class="center">';
1233 if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
1234 print $line->qty;
1235 }
1236 print '<input type="hidden" name="fk_commandefournisseurdet'.$indiceAsked.'" value="'.$line->id.'">';
1237 print '<input type="hidden" name="pul'.$indiceAsked.'" value="'.$line->pu_ht.'">';
1238 print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
1239 print '</td>';
1240 $qtyProdCom = $line->qty;
1241
1242 // Qty already received
1243 print '<td class="center">';
1244 $quantityDelivered = isset($objectsrc->receptions[$line->id]) ? $objectsrc->receptions[$line->id] : 0;
1245 if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
1246 print $quantityDelivered;
1247 }
1248 print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';
1249 print '</td>';
1250
1251
1252 if ($line->product_type == 1 && !getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1253 $quantityToBeDelivered = 0;
1254 } else {
1255 $quantityToBeDelivered = $dispatchLines[$indiceAsked]['qty'];
1256 }
1257 $warehouse_id = $dispatchLines[$indiceAsked]['ent'];
1258
1259
1260 $warehouseObject = null;
1261 if (isModEnabled('stock')) {
1262 // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
1263 print '<!-- Case warehouse already known or product not a predefined product -->';
1264 if (array_key_exists($dispatchLines[$indiceAsked]['ent'], $product->stock_warehouse)) {
1265 $stock = +$product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
1266 }
1267 $deliverableQty = $dispatchLines[$indiceAsked]['qty'];
1268 $cost_price = $dispatchLines[$indiceAsked]['pu'];
1269
1270 // Quantity to send
1271 print '<td class="center">';
1272 if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1273 if (GETPOSTINT('qtyl'.$indiceAsked)) {
1274 $defaultqty = GETPOSTINT('qtyl'.$indiceAsked);
1275 }
1276 print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
1277 print '<input class="right" name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
1278 } else {
1279 print $langs->trans("NA");
1280 }
1281 print '</td>';
1282
1283 if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1284 print '<td>';
1285 print '<input class="width75 right" name="cost_price'.$indiceAsked.'" id="cost_price'.$indiceAsked.'" value="'.price($cost_price).'">';
1286 print '</td>';
1287 }
1288
1289 // Stock
1290 if (isModEnabled('stock')) {
1291 print '<td class="left">';
1292 if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { // Type of product need stock change ?
1293 // Show warehouse combo list
1294 $ent = "entl".$indiceAsked;
1295 $idl = "idl".$indiceAsked;
1296 $tmpentrepot_id = is_numeric(GETPOST($ent)) ? GETPOSTINT($ent) : $warehouse_id;
1297 if ($line->fk_product > 0) {
1298 print '<!-- Show warehouse selection -->';
1299 print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 0, 0, $line->fk_product, '', 1);
1300 }
1301 } else {
1302 print $langs->trans("Service");
1303 }
1304 print '</td>';
1305 }
1306
1307 if (isModEnabled('productbatch')) {
1308 if (!empty($product->status_batch)) {
1309 print '<td><input name="batch'.$indiceAsked.'" value="'.dol_escape_htmltag($dispatchLines[$indiceAsked]['lot']).'"></td>';
1310 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1311 print '<td class="nowraponall">';
1312 print $form->selectDate($dispatchLines[$indiceAsked]['DLC'], 'dlc'.$indiceAsked, 0, 0, 1, "");
1313 print '</td>';
1314 }
1315 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1316 print '<td class="nowraponall">';
1317 print $form->selectDate($dispatchLines[$indiceAsked]['DLUO'], 'dluo'.$indiceAsked, 0, 0, 1, "");
1318 print '</td>';
1319 }
1320 } else {
1321 print '<td colspan="3"></td>';
1322 }
1323 }
1324 }
1325
1326 $arrayofpurchaselinealreadyoutput[$line->id] = $line->id;
1327
1328 print "</tr>\n";
1329
1330 // Display lines for extrafields of the Reception line
1331 // $line is a 'CommandeFournisseurLigne', $dispatchLines contains values of Reception lines so properties of CommandeFournisseurDispatch
1332 if (!empty($extrafields)) {
1333 $colspan = 5;
1334 if (isModEnabled('productbatch')) {
1335 $colspan += 2;
1336 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1337 $colspan += 1;
1338 }
1339 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1340 $colspan += 1;
1341 }
1342 }
1343 $recLine = new CommandeFournisseurDispatch($db);
1344
1345 $srcLine = new CommandeFournisseurLigne($db);
1346 $srcLine->id = $line->id;
1347 $srcLine->fetch_optionals(); // fetch extrafields also available in orderline
1348
1349 if (empty($recLine->array_options) && !empty($dispatchLines[$indiceAsked]['array_options'])) {
1350 $recLine->array_options = $dispatchLines[$indiceAsked]['array_options'];
1351 }
1352 $recLine->array_options = array_merge($recLine->array_options, $srcLine->array_options);
1353
1354 print $recLine->showOptionals($extrafields, 'edit', array('style' => 'class="oddeven"', 'colspan' => $colspan), (string) $indiceAsked, '', '1');
1355 }
1356
1357 $indiceAsked++;
1358 }
1359
1360 print "</table>";
1361
1362 print '<br>';
1363
1364 print $form->buttonsSaveCancel("Create");
1365
1366 print '</form>';
1367
1368 print '<br>';
1369 } else {
1370 dol_print_error($db);
1371 }
1372 }
1373} elseif ($id || $ref) {
1374 /* *************************************************************************** */
1375 /* */
1376 /* Edit and view mode */
1377 /* */
1378 /* *************************************************************************** */
1379 $lines = $object->lines;
1380
1381 $num_prod = count($lines);
1382 $indiceAsked = 0;
1383
1384 if ($object->id <= 0) {
1385 print $langs->trans("NoRecordFound");
1386 llxFooter();
1387 exit;
1388 }
1389
1390 $typeobject = '';
1391 if (!empty($object->origin) && $object->origin_id > 0) {
1392 $object->origin = 'CommandeFournisseur';
1393 $typeobject = $object->origin;
1394 $origin = $object->origin;
1395 $origin_id = $object->origin_id;
1396 $object->fetch_origin(); // Load property $object->origin_object, $object->commande, $object->propal, ...
1397 }
1398
1399 $soc = new Societe($db);
1400 $soc->fetch($object->socid);
1401
1402 $res = $object->fetch_optionals();
1403
1405 print dol_get_fiche_head($head, 'reception', $langs->trans("Reception"), -1, 'dollyrevert');
1406
1407 $formconfirm = '';
1408
1409 // Confirm deletion
1410 if ($action == 'delete') {
1411 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteReception'), $langs->trans("ConfirmDeleteReception", $object->ref), 'confirm_delete', '', 0, 1);
1412 }
1413
1414 // Confirmation validation
1415 if ($action == 'valid') {
1416 $objectref = substr($object->ref, 1, 4);
1417 if ($objectref == 'PROV') {
1418 $numref = $object->getNextNumRef($soc);
1419 } else {
1420 $numref = $object->ref;
1421 }
1422
1423 $text = $langs->trans("ConfirmValidateReception", $numref);
1424 if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION')) {
1425 $text .= '<br>'.img_picto('', 'movement', 'class="pictofixedwidth"').$langs->trans("StockMovementWillBeRecorded").'.';
1426 } elseif (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1427 $text .= '<br>'.img_picto('', 'movement', 'class="pictofixedwidth"').$langs->trans("StockMovementNotYetRecorded").'.';
1428 }
1429
1430 if (isModEnabled('notification')) {
1431 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
1432 $notify = new Notify($db);
1433 $text .= '<br>';
1434 $text .= $notify->confirmMessage('RECEPTION_VALIDATE', $object->socid, $object);
1435 }
1436
1437 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateReception'), $text, 'confirm_valid', '', 0, 1, 250);
1438 }
1439
1440 // Confirm cancellation
1441 if ($action == 'annuler') {
1442 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelReception'), $langs->trans("ConfirmCancelReception", $object->ref), 'confirm_cancel', '', 0, 1);
1443 }
1444
1445 if (!$formconfirm) {
1446 $parameters = array('formConfirm' => $formconfirm);
1447 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1448 if (empty($reshook)) {
1449 $formconfirm .= $hookmanager->resPrint;
1450 } elseif ($reshook > 0) {
1451 $formconfirm = $hookmanager->resPrint;
1452 }
1453 }
1454
1455 // Print form confirm
1456 print $formconfirm;
1457
1458
1459 // Calculate totalWeight and totalVolume for all products
1460 // by adding weight and volume of each product line.
1461 $tmparray = $object->getTotalWeightVolume();
1462 $totalWeight = $tmparray['weight'];
1463 $totalVolume = $tmparray['volume'];
1464
1465
1466 if ($typeobject == 'commande' && $object->origin_object->id && isModEnabled('order')) {
1467 $objectsrc = new Commande($db);
1468 $objectsrc->fetch($object->origin_object->id);
1469 }
1470 if ($typeobject == 'propal' && $object->origin_object->id && isModEnabled("propal")) {
1471 $objectsrc = new Propal($db);
1472 $objectsrc->fetch($object->origin_object->id);
1473 }
1474 if ($typeobject == 'CommandeFournisseur' && $object->origin_object->id && isModEnabled("supplier_order")) {
1475 $objectsrc = new CommandeFournisseur($db);
1476 $objectsrc->fetch($object->origin_object->id);
1477 }
1478 // Reception card
1479 $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1480 $morehtmlref = '<div class="refidno">';
1481 // Ref customer reception
1482
1483 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', 0, 1);
1484 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', null, null, '', 1);
1485
1486 // Thirdparty
1487 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
1488 // Project
1489 if (isModEnabled('project')) {
1490 $langs->load("projects");
1491 $morehtmlref .= '<br>';
1492 if (0) { // Do not change on reception
1493 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
1494 if ($action != 'classify' && $permissiontoadd) {
1495 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
1496 }
1497 $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');
1498 } else {
1499 if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
1500 $proj = new Project($db);
1501 $proj->fetch($objectsrc->fk_project);
1502 $morehtmlref .= $proj->getNomUrl(1);
1503 if ($proj->title) {
1504 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
1505 }
1506 }
1507 }
1508 }
1509 $morehtmlref .= '</div>';
1510
1511 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1512
1513
1514 print '<div class="fichecenter">';
1515 print '<div class="fichehalfleft">';
1516 print '<div class="underbanner clearboth"></div>';
1517
1518 print '<table class="border centpercent tableforfield">';
1519
1520 // Linked documents
1521 if ($typeobject == 'commande' && $object->origin_object->id && isModEnabled('order')) {
1522 print '<tr><td>';
1523 print $langs->trans("RefOrder").'</td>';
1524 print '<td colspan="3">';
1525 print $objectsrc->getNomUrl(1, 'commande');
1526 print "</td>\n";
1527 print '</tr>';
1528 }
1529 if ($typeobject == 'propal' && $object->origin_object->id && isModEnabled("propal")) {
1530 print '<tr><td>';
1531 print $langs->trans("RefProposal").'</td>';
1532 print '<td colspan="3">';
1533 print $objectsrc->getNomUrl(1, 'reception');
1534 print "</td>\n";
1535 print '</tr>';
1536 }
1537 if ($typeobject == 'CommandeFournisseur' && $object->origin_object->id && isModEnabled("propal")) {
1538 print '<tr><td>';
1539 print $langs->trans("SupplierOrder").'</td>';
1540 print '<td colspan="3">';
1541 print $objectsrc->getNomUrl(1, 'reception');
1542 print "</td>\n";
1543 print '</tr>';
1544 }
1545
1546 // Date creation
1547 print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
1548 print '<td colspan="3">'.dol_print_date($object->date_creation, "dayhour", "tzuserrel")."</td>\n";
1549 print '</tr>';
1550
1551 // Delivery date planned
1552 print '<tr><td height="10">';
1553 print '<table class="nobordernopadding" width="100%"><tr><td>';
1554 print $langs->trans('DateDeliveryPlanned');
1555 print '</td>';
1556
1557 if ($action != 'editdate_livraison' && $permissiontoadd) {
1558 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
1559 }
1560 print '</tr></table>';
1561 print '</td><td colspan="2">';
1562 if ($action == 'editdate_livraison') {
1563 print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1564 print '<input type="hidden" name="token" value="'.newToken().'">';
1565 print '<input type="hidden" name="action" value="setdate_livraison">';
1566 print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, 0, "setdate_livraison", 1, 0);
1567 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
1568 print '</form>';
1569 } else {
1570 print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
1571 }
1572 print '</td>';
1573 print '</tr>';
1574
1575 // Weight
1576 print '<tr><td>';
1577 print $form->editfieldkey("Weight", 'trueWeight', (string) $object->trueWeight, $object, $user->hasRight('reception', 'creer'));
1578 print '</td><td colspan="3">';
1579
1580 if ($action == 'edittrueWeight') {
1581 print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1582 print '<input name="action" value="settrueWeight" type="hidden">';
1583 print '<input name="id" value="'.$object->id.'" type="hidden">';
1584 print '<input type="hidden" name="token" value="'.newToken().'">';
1585 print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text">';
1586 print $formproduct->selectMeasuringUnits("weight_units", "weight", (string) $object->weight_units, 0, 2);
1587 print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
1588 print ' <input class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1589 print '</form>';
1590 } else {
1591 print $object->trueWeight;
1592 print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : '';
1593 }
1594
1595 // Calculated
1596 if ($totalWeight > 0) {
1597 if (!empty($object->trueWeight)) {
1598 print ' ('.$langs->trans("SumOfProductWeights").': ';
1599 }
1600 print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, getDolGlobalInt('MAIN_WEIGHT_DEFAULT_ROUND', -1), getDolGlobalString('MAIN_WEIGHT_DEFAULT_UNIT', 'no'));
1601 if (!empty($object->trueWeight)) {
1602 print ')';
1603 }
1604 }
1605 print '</td></tr>';
1606
1607 // Width
1608 print '<tr><td>'.$form->editfieldkey("Width", 'trueWidth', (string) $object->trueWidth, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
1609 print $form->editfieldval("Width", 'trueWidth', $object->trueWidth, $object, $user->hasRight('reception', 'creer'));
1610 print ($object->trueWidth && $object->width_units != '') ? ' '.measuringUnitString(0, "size", $object->width_units) : '';
1611 print '</td></tr>';
1612
1613 // Height
1614 print '<tr><td>'.$form->editfieldkey("Height", 'trueHeight', (string) $object->trueHeight, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
1615 if ($action == 'edittrueHeight') {
1616 print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1617 print '<input name="action" value="settrueHeight" type="hidden">';
1618 print '<input name="id" value="'.$object->id.'" type="hidden">';
1619 print '<input type="hidden" name="token" value="'.newToken().'">';
1620 print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text">';
1621 print $formproduct->selectMeasuringUnits("size_units", "size", $object->size_units, 0, 2);
1622 print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
1623 print ' <input class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
1624 print '</form>';
1625 } else {
1626 print $object->trueHeight;
1627 print ($object->trueHeight && $object->height_units != '') ? ' '.measuringUnitString(0, "size", $object->height_units) : '';
1628 }
1629
1630 print '</td></tr>';
1631
1632 // Depth
1633 print '<tr><td>'.$form->editfieldkey("Depth", 'trueDepth', (string) $object->trueDepth, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
1634 print $form->editfieldval("Depth", 'trueDepth', $object->trueDepth, $object, $user->hasRight('reception', 'creer'));
1635 print ($object->trueDepth && $object->depth_units != '') ? ' '.measuringUnitString(0, "size", $object->depth_units) : '';
1636 print '</td></tr>';
1637
1638 // Volume
1639 print '<tr><td>';
1640 print $langs->trans("Volume");
1641 print '</td>';
1642 print '<td colspan="3">';
1643 $calculatedVolume = 0;
1644 $volumeUnit = 0;
1645 if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
1646 $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
1647 $volumeUnit = $object->size_units * 3;
1648 }
1649 // If reception volume not defined we use sum of products
1650 if ($calculatedVolume > 0) {
1651 if ($volumeUnit < 50) {
1652 print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, getDolGlobalInt('MAIN_VOLUME_DEFAULT_ROUND', -1), getDolGlobalString("MAIN_VOLUME_DEFAULT_UNIT", 'no'));
1653 } else {
1654 print $calculatedVolume.' '.measuringUnitString(0, "volume", $volumeUnit);
1655 }
1656 }
1657 if ($totalVolume > 0) {
1658 if ($calculatedVolume) {
1659 print ' ('.$langs->trans("SumOfProductVolumes").': ';
1660 }
1661 print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, getDolGlobalInt('MAIN_VOLUME_DEFAULT_ROUND', -1), getDolGlobalString('MAIN_VOLUME_DEFAULT_UNIT', 'no'));
1662 //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
1663 if ($calculatedVolume) {
1664 print ')';
1665 }
1666 }
1667 print "</td>\n";
1668 print '</tr>';
1669
1670 // Other attributes
1671 $cols = 2;
1672
1673 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1674
1675 print '</table>';
1676
1677 print '</div>';
1678 print '<div class="fichehalfright">';
1679 print '<div class="underbanner clearboth"></div>';
1680
1681 print '<table class="border centpercent tableforfield">';
1682
1683 // Reception method
1684 print '<tr><td height="10">';
1685 print '<table class="nobordernopadding centpercent"><tr><td>';
1686 print $langs->trans('ReceptionMethod');
1687 print '</td>';
1688
1689 if ($action != 'editshipping_method_id' && $permissiontoadd) {
1690 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetReceptionMethod'), 1).'</a></td>';
1691 }
1692 print '</tr></table>';
1693 print '</td><td colspan="2">';
1694 if ($action == 'editshipping_method_id') {
1695 print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1696 print '<input type="hidden" name="token" value="'.newToken().'">';
1697 print '<input type="hidden" name="action" value="setshipping_method_id">';
1698 $object->fetch_delivery_methods();
1699 print $form->selectarray("shipping_method_id", $object->meths, $object->shipping_method_id, 1, 0, 0, "", 1);
1700 if ($user->admin) {
1701 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1702 }
1703 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
1704 print '</form>';
1705 } else {
1706 if ($object->shipping_method_id > 0) {
1707 // Get code using getLabelFromKey
1708 $code = $langs->getLabelFromKey($db, (string) $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
1709 print $langs->trans("SendingMethod".strtoupper($code));
1710 }
1711 }
1712 print '</td>';
1713 print '</tr>';
1714
1715 // Tracking Number
1716 print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber", 'tracking_number', $object->tracking_number, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
1717 print $form->editfieldval("TrackingNumber", 'tracking_number', $object->tracking_url, $object, $user->hasRight('reception', 'creer'), 'safehtmlstring', $object->tracking_number);
1718 print '</td></tr>';
1719
1720 // Incoterms
1721 if (isModEnabled('incoterm')) {
1722 print '<tr><td>';
1723 print '<table width="100%" class="nobordernopadding"><tr><td>';
1724 print $langs->trans('IncotermLabel');
1725 print '<td><td class="right">';
1726 if ($user->hasRight('reception', 'creer')) {
1727 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/reception/card.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
1728 } else {
1729 print '&nbsp;';
1730 }
1731 print '</td></tr></table>';
1732 print '</td>';
1733 print '<td colspan="3">';
1734 if ($action != 'editincoterm') {
1735 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
1736 } else {
1737 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
1738 }
1739 print '</td></tr>';
1740 }
1741
1742 print "</table>";
1743
1744 print '</div>';
1745 print '</div>';
1746
1747 print '<div class="clearboth"></div>';
1748
1749
1750 // Lines of products
1751 if ($action == 'editline') {
1752 print '<form name="updateline" id="updateline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;lineid='.$line_id.'" method="POST">
1753 <input type="hidden" name="token" value="' . newToken().'">
1754 <input type="hidden" name="action" value="updateline">
1755 <input type="hidden" name="mode" value="">
1756 <input type="hidden" name="id" value="' . $object->id.'">';
1757 }
1758 print '<br><br>';
1759
1760 print '<div class="div-table-responsive-no-min">';
1761 print '<table id="tablelines" class="noborder centpercent">';
1762 print '<thead>';
1763 print '<tr class="liste_titre">';
1764 // #
1765 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1766 print '<td width="5" class="center">&nbsp;</td>';
1767 }
1768 // Product/Service
1769 print '<td>'.$langs->trans("Products").'</td>';
1770 // Comment
1771 print '<td>'.$langs->trans("Comment").'</td>';
1772 // Qty
1773 print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
1774 if ($origin && $origin_id > 0) {
1775 print '<td class="center">'.$langs->trans("QtyInOtherReceptions").'</td>';
1776 }
1777
1778 $editColspan = 3;
1779 if ($action == 'editline') {
1780 if (!isModEnabled('stock')) {
1781 $editColspan--;
1782 }
1783 if (empty($conf->productbatch->enabled)) {
1784 $editColspan--;
1785 }
1786 print '<td class="center" colspan="'.$editColspan.'">';
1787 if ($object->statut <= 1) {
1788 print $langs->trans("QtyToReceive").' - ';
1789 } else {
1790 print $langs->trans("QtyReceived").' - ';
1791 }
1792 if (isModEnabled('stock')) {
1793 print $langs->trans("WarehouseTarget").' - ';
1794 }
1795 if (isModEnabled('productbatch')) {
1796 print $langs->trans("Batch");
1797 }
1798 print '</td>';
1799 } else {
1800 $statusreceived = $object::STATUS_CLOSED;
1801 if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION")) {
1802 $statusreceived = $object::STATUS_VALIDATED;
1803 }
1804 if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION_CLOSE")) {
1805 $statusreceived = $object::STATUS_CLOSED;
1806 }
1807 if ($object->statut < $statusreceived) {
1808 print '<td class="center">'.$langs->trans("QtyToReceive").'</td>';
1809 } else {
1810 print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
1811 }
1812 if (isModEnabled('stock')) {
1813 print '<td class="left">'.$langs->trans("WarehouseTarget").'</td>';
1814 }
1815
1816 if (isModEnabled('productbatch')) {
1817 print '<td class="left">'.$langs->trans("Batch").'</td>';
1818 }
1819 }
1820 print '<td class="center">'.$langs->trans("CalculatedWeight").'</td>';
1821 print '<td class="center">'.$langs->trans("CalculatedVolume").'</td>';
1822 //print '<td class="center">'.$langs->trans("Size").'</td>';
1823 if ($object->statut == 0) {
1824 print '<td class="linecoledit"></td>';
1825 print '<td class="linecoldelete" width="10"></td>';
1826 }
1827 print "</tr>\n";
1828 print '</thead>';
1829
1830 $var = false;
1831
1832 $outputlangs = $langs;
1833 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
1834 $object->fetch_thirdparty();
1835 $newlang = '';
1836 if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) {
1837 $newlang = GETPOST('lang_id', 'aZ09');
1838 }
1839 if (empty($newlang)) {
1840 $newlang = $object->thirdparty->default_lang;
1841 }
1842 if (!empty($newlang)) {
1843 $outputlangs = new Translate("", $conf);
1844 $outputlangs->setDefaultLang($newlang);
1845 }
1846 }
1847
1848 // Get list of products already sent for same source object into $alreadysent
1849 $alreadysent = array();
1850
1851 $origin = 'commande_fournisseur';
1852
1853 if ($origin && $origin_id > 0) {
1854 $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end";
1855 $sql .= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id, ed.fk_entrepot";
1856 $sql .= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception";
1857 //if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";
1858 $sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch';
1859 $sql .= ', p.description as product_desc';
1860 $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as ed";
1861 $sql .= ", ".MAIN_DB_PREFIX."reception as e";
1862 $sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj";
1863 //if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.fk_reception = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."deliverydet as ld ON ld.fk_delivery = l.rowid AND obj.rowid = ld.fk_origin_line";
1864 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
1865 $sql .= " WHERE e.entity IN (".getEntity('reception').")";
1866 $sql .= " AND obj.fk_commande = ".((int) $origin_id);
1867 $sql .= " AND obj.rowid = ed.fk_elementdet";
1868 $sql .= " AND ed.fk_reception = e.rowid";
1869 $sql .= " AND ed.fk_reception !=".((int) $object->id);
1870 //if ($filter) $sql.= $filter;
1871 $sql .= " ORDER BY obj.fk_product";
1872
1873 dol_syslog("get list of reception lines", LOG_DEBUG);
1874 $resql = $db->query($sql);
1875 if ($resql) {
1876 $num = $db->num_rows($resql);
1877 $i = 0;
1878
1879 while ($i < $num) {
1880 $obj = $db->fetch_object($resql);
1881 if ($obj) {
1882 // $obj->rowid is rowid in $origin."det" table
1883 $alreadysent[$obj->rowid][$obj->receptionline_id] = array('reception_ref' => $obj->reception_ref, 'reception_id' => $obj->reception_id, 'warehouse' => $obj->fk_entrepot, 'qty' => $obj->qty, 'date_valid' => $obj->date_valid, 'date_delivery' => $obj->date_delivery);
1884 }
1885 $i++;
1886 }
1887 }
1888 //var_dump($alreadysent);
1889 }
1890
1891 $arrayofpurchaselinealreadyoutput = array();
1892
1893 // Loop on each product to send/sent. Warning: $lines must be sorted by ->fk_commandefourndet (it is a regroupment key on output)
1894 print '<tbody>';
1895 for ($i = 0; $i < $num_prod; $i++) {
1896 print '<!-- origin line id = '.(!empty($lines[$i]->origin_line_id) ? $lines[$i]->origin_line_id : 0).' -->'; // id of order line
1897 print '<tr class="oddeven" id="row-'.$lines[$i]->id.'" data-id="'.$lines[$i]->id.'" data-element="'.$lines[$i]->element.'">';
1898
1899 // #
1900 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
1901 print '<td class="center">'.($i + 1).'</td>';
1902 }
1903
1904 // Predefined product or service
1905 if ($lines[$i]->fk_product > 0) {
1906 // Define output language
1907 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
1908 $prod = new Product($db);
1909 $prod->fetch($lines[$i]->fk_product);
1910 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label;
1911 } else {
1912 $label = (!empty($lines[$i]->product->label) ? $lines[$i]->product->label : $lines[$i]->product->product_label);
1913 }
1914
1915 print '<td class="linecoldescription">';
1916 if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
1917 $text = $lines[$i]->product->getNomUrl(1);
1918 $text .= ' - '.$label;
1919 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($lines[$i]->product->description));
1920 print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i);
1921 print_date_range(!empty($lines[$i]->date_start) ? $lines[$i]->date_start : 0, !empty($lines[$i]->date_end) ? $lines[$i]->date_end : 0);
1922 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
1923 print (!empty($lines[$i]->product->description) && $lines[$i]->description != $lines[$i]->product->description) ? '<br>'.dol_htmlentitiesbr($lines[$i]->description) : '';
1924 }
1925 }
1926 print "</td>\n";
1927 } else {
1928 print '<td class="linecoldescription">';
1929 if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
1930 if ($lines[$i]->product_type == Product::TYPE_SERVICE) {
1931 $text = img_object($langs->trans('Service'), 'service');
1932 } else {
1933 $text = img_object($langs->trans('Product'), 'product');
1934 }
1935
1936 if (!empty($lines[$i]->label)) {
1937 $text .= ' <strong>'.$lines[$i]->label.'</strong>';
1938 print $form->textwithtooltip($text, $lines[$i]->description, 3, 0, '', (string) $i);
1939 } else {
1940 print $text.' '.nl2br($lines[$i]->description);
1941 }
1942
1943 print_date_range($lines[$i]->date_start, $lines[$i]->date_end);
1944 }
1945 print "</td>\n";
1946 }
1947
1948 if ($action == 'editline' && $lines[$i]->id == $line_id) {
1949 print '<td><input name="comment'.$line_id.'" id="comment'.$line_id.'" value="'.dol_escape_htmltag($lines[$i]->comment).'"></td>';
1950 } else {
1951 print '<td style="white-space: pre-wrap; max-width: 200px;">'.dol_escape_htmltag($lines[$i]->comment).'</td>';
1952 }
1953
1954
1955 // Qty ordered
1956 print '<td class="center linecolqty">';
1957 if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
1958 print $lines[$i]->qty_asked;
1959 }
1960 print '</td>';
1961
1962 // Qty in other receptions (with reception and warehouse used)
1963 if ($origin && $origin_id > 0) {
1964 print '<td class="center nowrap linecolqtyinotherreceptions">';
1965 $htmltooltip = '';
1966 $qtyalreadyreceived = 0;
1967 if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
1968 foreach ($alreadysent as $key => $val) {
1969 if ($lines[$i]->fk_commandefourndet == $key) {
1970 $j = 0;
1971 foreach ($val as $receptionline_id => $receptionline_var) {
1972 if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) {
1973 continue; // We want to show only "other receptions"
1974 }
1975
1976 $j++;
1977 if ($j > 1) {
1978 $htmltooltip .= '<br>';
1979 }
1980 $reception_static->fetch($receptionline_var['reception_id']);
1981 $htmltooltip .= $reception_static->getNomUrl(1, 0, 0, 0, 1);
1982 $htmltooltip .= ' - '.$receptionline_var['qty'];
1983
1984 $htmltext = $langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($receptionline_var['date_valid'], 'dayhour'));
1985 if (isModEnabled('stock') && $receptionline_var['warehouse'] > 0) {
1986 $warehousestatic->fetch($receptionline_var['warehouse']);
1987 $htmltext .= '<br>'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1, '', 0, 1);
1988 }
1989 $htmltooltip .= ' '.$form->textwithpicto('', $htmltext, 1);
1990
1991 $qtyalreadyreceived += $receptionline_var['qty'];
1992 }
1993 if ($j) {
1994 $htmltooltip = $langs->trans("QtyInOtherReceptions").'...<br><br>'.$htmltooltip.'<br><input type="submit" name="dummyhiddenbuttontogetfocus" style="display:none" autofocus>';
1995 }
1996 }
1997 }
1998 }
1999 print $form->textwithpicto((string) $qtyalreadyreceived, $htmltooltip, 1, 'info', '', 0, 3, 'tooltip'.$lines[$i]->id);
2000 print '</td>';
2001 }
2002
2003 if ($action == 'editline' && $lines[$i]->id == $line_id) {
2004 // edit mode
2005 print '<td colspan="'.$editColspan.'" class="center"><table class="nobordernopadding">';
2006 if (isModEnabled('stock')) {
2007 if ($lines[$i]->fk_product > 0) {
2008 print '<!-- case edit 1 -->';
2009 print '<tr>';
2010 // Qty to receive or received
2011 print '<td><input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'"></td>';
2012 // Warehouse source
2013 print '<td>'.$formproduct->selectWarehouses($lines[$i]->fk_entrepot, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'</td>';
2014 // Batch number management
2015 if ($conf->productbatch->enabled && !empty($lines[$i]->product->status_batch)) {
2016 print '<td class="nowraponall left"><input name="batch'.$line_id.'" id="batch'.$line_id.'" type="text" value="'.$lines[$i]->batch.'"><br>';
2017 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
2018 print $langs->trans('SellByDate').' : ';
2019 print $form->selectDate($lines[$i]->sellby, 'dlc'.$line_id, 0, 0, 1, "").'</br>';
2020 }
2021 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
2022 print $langs->trans('EatByDate').' : ';
2023 print $form->selectDate($lines[$i]->eatby, 'dluo'.$line_id, 0, 0, 1, "");
2024 }
2025 print '</td>';
2026 }
2027 print '</tr>';
2028 } else {
2029 print '<!-- case edit 2 -->';
2030 print '<tr>';
2031 // Qty to receive or received
2032 print '<td><input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'"></td>';
2033 // Warehouse source
2034 print '<td></td>';
2035 // Batch number management
2036 print '<td></td>';
2037 print '</tr>';
2038 }
2039 }
2040 print '</table></td>';
2041 } else {
2042 // Qty to receive or received
2043 print '<td class="center linecolqtytoreceive">'.$lines[$i]->qty.'</td>';
2044
2045 // Warehouse source
2046 if (isModEnabled('stock')) {
2047 if ($lines[$i]->fk_entrepot > 0) {
2048 $entrepot = new Entrepot($db);
2049 $entrepot->fetch($lines[$i]->fk_entrepot);
2050
2051 print '<td class="left tdoverflowmax150" title="'.dol_escape_htmltag($entrepot->label).'">';
2052 print $entrepot->getNomUrl(1);
2053 print '</td>';
2054 } else {
2055 print '<td></td>';
2056 }
2057 }
2058
2059 // Batch number management
2060 if (isModEnabled('productbatch')) {
2061 if (isset($lines[$i]->batch)) {
2062 print '<!-- Detail of lot -->';
2063 print '<td class="linecolbatch nowrap">';
2064 $detail = $langs->trans("NA");
2065 if ($lines[$i]->product->status_batch > 0 && $lines[$i]->fk_product > 0) {
2066 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
2067 $productlot = new Productlot($db);
2068 $reslot = $productlot->fetch(0, $lines[$i]->fk_product, $lines[$i]->batch);
2069 if ($reslot > 0) {
2070 $detail = $productlot->getNomUrl(1);
2071 } else {
2072 // lot is not created and info is only in reception lines
2073 $batchinfo = $langs->trans("Batch").': '.$lines[$i]->batch;
2074 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
2075 $batchinfo .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby, "day");
2076 }
2077 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
2078 $batchinfo .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby, "day");
2079 }
2080 $detail = $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $batchinfo);
2081 }
2082 }
2083 print $detail . '</td>';
2084 } else {
2085 print '<td></td>';
2086 }
2087 }
2088 }
2089
2090 // Weight
2091 print '<td class="center linecolweight">';
2092 if (!empty($lines[$i]->fk_product_type) && $lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
2093 print $lines[$i]->product->weight * $lines[$i]->qty.' '.measuringUnitString(0, "weight", $lines[$i]->product->weight_units);
2094 } else {
2095 print '&nbsp;';
2096 }
2097 print '</td>';
2098
2099 // Volume
2100 print '<td class="center linecolvolume">';
2101 if (!empty($lines[$i]->fk_product_type) && $lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
2102 print $lines[$i]->product->volume * $lines[$i]->qty.' '.measuringUnitString(0, "volume", $lines[$i]->product->volume_units);
2103 } else {
2104 print '&nbsp;';
2105 }
2106 print '</td>';
2107
2108
2109 if ($action == 'editline' && $lines[$i]->id == $line_id) {
2110 print '<td class="center valignmiddle" colspan="2">';
2111 print '<input type="submit" class="button small button-save" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';
2112 print '<input type="submit" class="button small button-cancel" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"><br>';
2113 print '</td>';
2114 } elseif ($object->statut == Reception::STATUS_DRAFT) {
2115 // edit-delete buttons
2116 print '<td class="linecoledit center">';
2117 print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&lineid='.$lines[$i]->id.'">'.img_edit().'</a>';
2118 print '</td>';
2119 print '<td class="linecoldelete" width="10">';
2120 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteline&token='.newToken().'&lineid='.$lines[$i]->id.'">'.img_delete().'</a>';
2121 print '</td>';
2122
2123 // Display lines extrafields
2124 if (isset($rowExtrafieldsStart, $rowExtrafieldsView, $rowEnd)) { // @phan-suppress-current-line PhanPluginUndeclaredVariableIsset
2125 print $rowExtrafieldsStart;
2126 print $rowExtrafieldsView;
2127 print $rowEnd;
2128 }
2129 }
2130 print "</tr>";
2131
2132 $arrayofpurchaselinealreadyoutput[$lines[$i]->fk_commandefourndet] = $lines[$i]->fk_commandefourndet;
2133
2134 // Display lines extrafields
2135 $extralabelslines = $extrafields->attributes[$lines[$i]->table_element];
2136 if (!empty($extralabelslines) && is_array($extralabelslines) && count($extralabelslines) > 0) {
2137 $colspan = 8;
2138 if (isModEnabled('stock')) {
2139 $colspan++;
2140 }
2141 if (isModEnabled('productbatch')) {
2142 $colspan++;
2143 }
2144
2145 $line = new CommandeFournisseurDispatch($db);
2146 $line->id = $lines[$i]->id;
2147 $line->fetch_optionals();
2148
2149 if ($action == 'editline' && $lines[$i]->id == $line_id) {
2150 print $line->showOptionals($extrafields, 'edit', array('colspan' => $colspan), '');
2151 } else {
2152 print $line->showOptionals($extrafields, 'view', array('colspan' => $colspan), '');
2153 }
2154 }
2155 }
2156 print '</tbody>';
2157
2158 // TODO Show also lines ordered but not delivered
2159
2160 print "</table>\n";
2161 print '</div>';
2162
2163
2164 print dol_get_fiche_end();
2165
2166
2167 $object->fetchObjectLinked($object->id, $object->element);
2168
2169
2170 /*
2171 * Boutons actions
2172 */
2173
2174 if (($user->socid == 0) && ($action != 'presend')) {
2175 print '<div class="tabsAction">';
2176
2177 $parameters = array();
2178 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2179 if (empty($reshook)) {
2180 if ($object->statut == Reception::STATUS_DRAFT && $num_prod > 0) {
2181 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer'))
2182 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate'))) {
2183 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken().'">'.$langs->trans("Validate").'</a>';
2184 } else {
2185 print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
2186 }
2187 }
2188 // Back to draft
2189 if ($object->statut == Reception::STATUS_VALIDATED && $user->hasRight('reception', 'creer')) {
2190 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modif&token='.newToken().'">'.$langs->trans('SetToDraft').'</a></div>';
2191 }
2192
2193 // TODO add alternative status
2194 // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
2195 if ($object->statut == Reception::STATUS_CLOSED && $user->hasRight('reception', 'creer')) {
2196 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a>';
2197 }
2198
2199 // Send
2200 if (empty($user->socid)) {
2201 if ($object->statut > 0) {
2202 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('reception', 'reception_advance', 'send')) {
2203 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendByMail').'</a>';
2204 } else {
2205 print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
2206 }
2207 }
2208 }
2209
2210 // Create bill
2211 if (isModEnabled("supplier_invoice") && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED)) {
2212 if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer')) {
2213 if (getDolGlobalString('WORKFLOW_BILL_ON_RECEPTION') !== '0') {
2214 print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';
2215 }
2216 }
2217 }
2218
2219
2220 // Set Billed and Closed
2221 if ($object->statut == Reception::STATUS_VALIDATED) {
2222 if ($user->hasRight('reception', 'creer') && $object->statut > 0) {
2223 if (!$object->billed && getDolGlobalString('WORKFLOW_BILL_ON_RECEPTION') !== '0') {
2224 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifybilled&token='.newToken().'">'.$langs->trans('ClassifyBilled').'</a>';
2225 }
2226 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifyclosed&token='.newToken().'">'.$langs->trans("Close").'</a>';
2227 }
2228 }
2229
2230 if ($user->hasRight('reception', 'supprimer')) {
2231 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
2232 }
2233 }
2234
2235 print '</div>';
2236 }
2237
2238
2239 /*
2240 * Documents generated
2241 */
2242
2243 if ($action != 'presend' && $action != 'editline') {
2244 print '<div class="fichecenter"><div class="fichehalfleft">';
2245
2246 $objectref = dol_sanitizeFileName($object->ref);
2247 $filedir = $conf->reception->dir_output."/".$objectref;
2248
2249 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2250
2251 $genallowed = $user->hasRight('reception', 'lire');
2252 $delallowed = $user->hasRight('reception', 'creer');
2253
2254 print $formfile->showdocuments('reception', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
2255
2256 // Show links to link elements
2257 //$tmparray = $form->showLinkToObjectBlock($object, null, array('order'), 1);
2258 $somethingshown = $form->showLinkedObjectBlock($object, '');
2259
2260 print '</div><div class="fichehalfright">';
2261
2262 print '</div></div>';
2263 }
2264
2265 // Presend form
2266 $modelmail = 'reception_send';
2267 $defaulttopic = 'SendReceptionRef';
2268 $diroutput = $conf->reception->dir_output;
2269 $trackid = 'rec'.$object->id;
2270
2271 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2272}
2273
2274
2275llxFooter();
2276
2277$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.
Class to manage line orders.
Class to manage customers orders.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage standard extra fields.
Class to offer components to list and upload files.
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 building of HTML components.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage the table of subscription to notifications.
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class with list of lots and properties.
Class to manage projects.
Class to manage proposals.
Class to manage receptions.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
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 '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_date_range($date_start, $date_end, $format='', $outputlangs=null)
Format output for start and end date.
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_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
measuringUnitString($unitid, $measuring_style='', $unitscale=null, $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
reception_prepare_head(Reception $object)
Prepare array with list of tabs.
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.