dolibarr 25.0.0-alpha
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-2026 MDW <mdeweerd@users.noreply.github.com>
16 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
17 * Copyright (C) 2025 Nick Fragoulis
18 * Copyright (C) 2026 Jose MARTINEZ <jose.martinez@pichinov.com>
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program. If not, see <https://www.gnu.org/licenses/>.
32 */
33
40// Load Dolibarr environment
41require '../main.inc.php';
50require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
51require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
52require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
53require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
54require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
55require_once DOL_DOCUMENT_ROOT.'/core/lib/reception.lib.php';
56require_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
57require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
58require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
59require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
60require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
61if (isModEnabled("product") || isModEnabled("service")) {
62 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
63}
64if (isModEnabled("propal")) {
65 require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
66}
67require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
68require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.orderline.class.php';
69require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
70if (isModEnabled('productbatch')) {
71 require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
72}
73if (isModEnabled('project')) {
74 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
75 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
76}
77
78$langs->loadLangs(array("receptions", "companies", "bills", 'orders', 'stocks', 'other', 'propal', 'sendings'));
79
80if (isModEnabled('incoterm')) {
81 $langs->load('incoterm');
82}
83if (isModEnabled('productbatch')) {
84 $langs->load('productbatch');
85}
86
87$origin = GETPOST('origin', 'alpha'); // Example: commande, propal
88$origin_id = GETPOSTINT('origin_id') ? GETPOSTINT('id') : '';
89$id = GETPOSTINT('id');
90if (empty($origin_id) && !empty($origin)) {
91 $origin_id = GETPOSTINT('origin_id'); // Id of order or propal
92}
93if (empty($origin_id) && !empty($origin)) {
94 $origin_id = GETPOSTINT('object_id'); // Id of order or propal
95}
96if (empty($origin_id) && !empty($origin)) {
97 $origin_id = GETPOSTINT('originid'); // Id of order or propal
98}
99$ref = GETPOST('ref', 'alpha');
100$line_id = GETPOSTINT('lineid') ? GETPOSTINT('lineid') : 0;
101$facid = GETPOSTINT('facid');
102$socid = GETPOSTINT('socid');
103$action = GETPOST('action', 'alpha');
104//Select mail models is same action as presend
105if (GETPOST('modelselected')) {
106 $action = 'presend';
107}
108$confirm = GETPOST('confirm', 'alpha');
109$cancel = GETPOST('cancel', 'alpha');
110$backtopage = GETPOST('backtopage', 'alpha');
111$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
112
113$contactid = GETPOSTINT('contactid');
114$projectid = GETPOSTINT('projectid');
115
116
117$cancel = GETPOST('cancel', 'alpha');
118$rank = (GETPOSTINT('rank') > 0) ? GETPOSTINT('rank') : -1;
119$lineid = GETPOSTINT('lineid');
120$backtopage = GETPOST('backtopage', 'alpha');
121//PDF
122$hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
123$hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
124$hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
125
126$object = new Reception($db);
127$objectorder = new CommandeFournisseur($db);
128$extrafields = new ExtraFields($db);
129
130// fetch optionals attributes and labels
131$extrafields->fetch_name_optionals_label($object->table_element);
132$extrafields->fetch_name_optionals_label($object->table_element_line);
133$extrafields->fetch_name_optionals_label($objectorder->table_element_line);
134
135// Load object. Make an object->fetch
136include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
137
138// Restore $origin and $origin_id from the loaded object when the request only carried the
139// reception id (e.g. the line edit form on an existing reception posts action=updateline
140// and id=N but no origin field). Without this, the action handler below sees $origin
141// empty and silently skips both its standalone and its origin branches, so updates to
142// quantity, comment, batch and extrafields on an existing line are not persisted
143// (see issue #38386, regression from PR #36134).
144// The restore is gated on $object->origin_id > 0 so standalone receptions, which have
145// no upstream origin, are not affected: $origin stays empty and the standalone branch
146// of the updateline handler is still selected.
147if ($object->origin_id > 0) {
148 if (empty($origin)) {
149 if (!empty($object->origin_type)) {
150 $origin = $object->origin_type;
151 } elseif (is_string($object->origin) && $object->origin !== '') {
152 $origin = (string) $object->origin;
153 }
154 }
155 if (empty($origin_id)) {
156 $origin_id = $object->origin_id;
157 }
158}
159
160// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
161$hookmanager->initHooks(array('receptioncard', 'globalcard'));
162
163$date_delivery = dol_mktime(GETPOSTINT('date_deliveryhour'), GETPOSTINT('date_deliverymin'), 0, GETPOSTINT('date_deliverymonth'), GETPOSTINT('date_deliveryday'), GETPOSTINT('date_deliveryyear'));
164$date_reception = dol_mktime(GETPOSTINT('date_receptionhour'), GETPOSTINT('date_receptionmin'), 0, GETPOSTINT('date_receptionmonth'), GETPOSTINT('date_receptionday'), GETPOSTINT('date_receptionyear'));
165
166// Security check
167if ($user->socid) {
168 $socid = $user->socid;
169}
170$result = restrictedArea($user, 'reception', $object->id, '');
171// TODO Test on reception module on only
172if (isModEnabled("reception") || $origin == 'reception' || empty($origin)) {
173 $result = restrictedArea($user, 'reception', $object->id);
174} else {
175 // We do not use the reception module, so we test permission on the supplier orders
176 if ($origin == 'supplierorder' || $origin == 'order_supplier') {
177 $result = restrictedArea($user, 'fournisseur', $origin_id, 'commande_fournisseur', 'commande');
178 } elseif (!$user->hasRight($origin, 'lire') && !$user->hasRight($origin, 'read')) {
180 }
181}
182
183if (isModEnabled("reception")) {
184 $permissiontoread = $user->hasRight('reception', 'lire');
185 $permissiontoadd = $user->hasRight('reception', 'creer');
186 $permissiontoedit = $user->hasRight('reception', 'creer'); // Used by the include of actions_lineupdown.inc.php
187 $permissiondellink = $user->hasRight('reception', 'creer'); // Used by the include of actions_dellink.inc.php
188 $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate')));
189 $permissiontodelete = $user->hasRight('reception', 'supprimer');
190} else {
191 $permissiontoread = $user->hasRight('fournisseur', 'commande', 'receptionner');
192 $permissiontoadd = $user->hasRight('fournisseur', 'commande', 'receptionner');
193 $permissiontoedit = $user->hasRight('fournisseur', 'commande', 'receptionner'); // Used by the include of actions_lineupdown.inc.php
194 $permissiondellink = $user->hasRight('fournisseur', 'commande', 'receptionner'); // Used by the include of actions_dellink.inc.php
195 $permissiontovalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('fournisseur', 'commande', 'receptionner')) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('fournisseur', 'commande_advance', 'check')));
196 $permissiontodelete = $user->hasRight('fournisseur', 'commande', 'receptionner');
197}
198$permissiontoeditextra = $permissiontoadd;
199if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
200 // For action 'update_extras' there is a specific permission set for the attribute to update
201 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
202}
203
204$editColspan = 0;
205$objectsrc = null;
206$typeobject = null;
207$ref_customer = null;
208$shipping_method_id = null;
209$warehouse_id = null;
210$note_public = null;
211$note_private = null;
212
213
214/*
215 * Actions
216 */
217
218$error = 0;
219$parameters = array();
220$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
221if ($reshook < 0) {
222 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
223}
224
225if (empty($reshook)) {
226 $backurlforlist = DOL_URL_ROOT.'/reception/list.php';
227
228 if (empty($backtopage) || ($cancel && empty($id))) {
229 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
230 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
231 $backtopage = $backurlforlist;
232 } else {
233 $backtopage = DOL_URL_ROOT.'/reception/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
234 }
235 }
236 }
237
238 if ($cancel) {
239 if (!empty($backtopageforcancel)) {
240 header("Location: ".$backtopageforcancel);
241 exit;
242 } elseif (!empty($backtopage)) {
243 header("Location: ".$backtopage);
244 exit;
245 }
246
247 $action = '';
248 }
249
250 if ($cancel) {
251 if (!$origin) {
252 $action = '';
253 $object->fetch($object->id); // show reception also after canceling modification
254 }
255 }
256
257 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
258
259 include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
260
261 // Reopen
262 if ($action == 'reopen' && $permissiontoadd) { // Test on permissions not required here
263 $result = $object->reOpen();
264 if ($result < 0) {
265 setEventMessages($object->error, $object->errors, 'errors');
266 }
267 }
268
269 // Confirm back to draft status
270 if ($action == 'modif' && $permissiontoadd) {
271 $result = $object->setDraft($user);
272 if ($result >= 0) {
273 // Define output language
274 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
275 $outputlangs = $langs;
276 $newlang = '';
277 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
278 $newlang = GETPOST('lang_id', 'aZ09');
279 }
280 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
281 $newlang = $object->thirdparty->default_lang;
282 }
283 if (!empty($newlang)) {
284 $outputlangs = new Translate("", $conf);
285 $outputlangs->setDefaultLang($newlang);
286 }
287 $model = $object->model_pdf;
288 $ret = $object->fetch($id); // Reload to get new records
289 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
290 }
291 } else {
292 setEventMessages($object->error, $object->errors, 'errors');
293 }
294 }
295
296 // Set incoterm
297 if ($action == 'set_incoterms' && isModEnabled('incoterm') && $permissiontoadd) {
298 $result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
299 }
300
301 if ($action == 'setref_supplier' && $permissiontoadd) {
302 if ($result < 0) {
303 setEventMessages($object->error, $object->errors, 'errors');
304 }
305
306 $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'), '', null, 'text', '', $user, 'RECEPTION_MODIFY');
307 if ($result < 0) {
308 setEventMessages($object->error, $object->errors, 'errors');
309 $action = 'editref_supplier';
310 } else {
311 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
312 exit;
313 }
314 }
315
316 if ($action == 'update_extras' && $permissiontoeditextra) {
317 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
318
319 $attribute_name = GETPOST('attribute', 'aZ09');
320
321 // Fill array 'array_options' with data from update form
322 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
323 if ($ret < 0) {
324 $error++;
325 }
326
327 if (!$error) {
328 $result = $object->updateExtraField($attribute_name, 'RECEPTION_MODIFY');
329 if ($result < 0) {
330 setEventMessages($object->error, $object->errors, 'errors');
331 $error++;
332 }
333 }
334
335 if ($error) {
336 $action = 'edit_extras';
337 }
338 }
339
340 // Create reception
341 if ($action == 'add' && $permissiontoadd) {
342 $db->begin();
343
344 if (!$error && !$origin && getDolGlobalString('RECEPTION_STANDALONE')) {
345 if (GETPOSTINT('socid') < 1) {
346 $error++;
347 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty")), null, 'errors');
348 $action = 'create';
349 }
350
351 $object->socid = GETPOSTINT('socid');
352 $object->fetch_thirdparty();
353 $object->note = GETPOST('note', 'alpha');
354 $object->note_private = GETPOST('note', 'alpha');
355 $object->origin = $origin; // deprecated
356 $object->origin_type = $origin;
357 $object->origin_id = $origin_id;
358 $object->fk_project = GETPOSTINT('projectid');
359 $object->weight = GETPOSTINT('weight') == '' ? null : GETPOSTINT('weight');
360 $object->trueHeight = GETPOSTINT('trueHeight') == '' ? null : GETPOSTINT('trueHeight');
361 $object->trueWidth = GETPOSTINT('trueWidth') == '' ? null : GETPOSTINT('trueWidth');
362 $object->trueDepth = GETPOSTINT('trueDepth') == '' ? null : GETPOSTINT('trueDepth');
363 $object->size_units = GETPOSTINT('size_units');
364 $object->weight_units = GETPOSTINT('weight_units');
365 $object->ref_supplier = GETPOST('ref_supplier', 'alpha');
366 $object->fk_warehouse = GETPOSTINT('fk_warehouse'); // Default warehouse for the lines
367 $object->model_pdf = GETPOST('model');
368 $object->date_delivery = $date_delivery; // Date delivery planned
369 $object->date_reception = $date_reception;
370 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
371 $object->tracking_number = GETPOST('tracking_number', 'alpha');
372 $object->note_private = GETPOST('note_private', 'restricthtml');
373 $object->note_public = GETPOST('note_public', 'restricthtml');
374 $object->fk_incoterms = GETPOSTINT('incoterm_id');
375 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
376
377 $product = new Product($db);
378
379 // Fill array 'array_options' with data from add form
380 $ret = $extrafields->setOptionalsFromPost(null, $object);
381 if ($ret < 0) {
382 $error++;
383 }
384
385 if (!$error) {
386 $ret = $object->create($user);
387 if ($ret <= 0) {
388 setEventMessages($object->error, $object->errors, 'errors');
389 $error++;
390 }
391 }
392 }
393 if ($origin && $origin_id > 0) {
394 $object->note = GETPOST('note', 'alpha');
395 $object->note_private = GETPOST('note', 'alpha');
396 $object->origin = $origin;
397 $object->origin_type = $origin;
398 $object->origin_id = $origin_id;
399 $object->fk_project = GETPOSTINT('projectid');
400 $object->weight = GETPOST('weight') == '' ? null : GETPOSTINT('weight');
401 $object->trueHeight = GETPOST('trueHeight') == '' ? null : GETPOSTINT('trueHeight');
402 $object->trueWidth = GETPOST('trueWidth') == '' ? null : GETPOSTINT('trueWidth');
403 $object->trueDepth = GETPOST('trueDepth') == '' ? null : GETPOSTINT('trueDepth');
404 $object->size_units = GETPOSTINT('size_units');
405 $object->weight_units = GETPOSTINT('weight_units');
406
407 $object->ref_supplier = GETPOST('ref_supplier', 'alpha');
408 $object->fk_warehouse = GETPOSTINT('fk_warehouse'); // Default warehouse for the lines
409 $object->model_pdf = GETPOST('model');
410 $object->date_delivery = $date_delivery; // Date delivery planned
411 $object->date_reception = $date_reception;
412 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
413 $object->tracking_number = GETPOST('tracking_number', 'alpha');
414 $object->note_private = GETPOST('note_private', 'restricthtml');
415 $object->note_public = GETPOST('note_public', 'restricthtml');
416 $object->fk_incoterms = GETPOSTINT('incoterm_id');
417 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
418
419 if ($object->origin == "supplierorder") {
420 $object->origin = 'order_supplier';
421 $object->origin_type = 'order_supplier';
422 $classname = 'CommandeFournisseur';
423 } else {
424 $classname = ucfirst($object->origin_type);
425 }
426 $objectsrc = new $classname($db);
427 $objectsrc->fetch($object->origin_id);
428
429 $object->socid = $objectsrc->socid;
430
431 $product = new Product($db);
432 $batch_line = array();
433 $stockLine = array();
434 $array_options = array();
435
436 $totalqty = 0;
437
438 $num = 0;
439 foreach ($_POST as $key => $value) {
440 // without batch module enabled
441
442 if (strpos($key, 'qtyasked') !== false) {
443 $num++;
444 }
445 }
446
447 // Loop lines to calculate $totalqty
448 for ($i = 1; $i <= $num; $i++) {
449 $idl = "idl".$i; // id line source
450
451 //$sub_qty = array();
452 //$subtotalqty = 0;
453
454 //$j = 0;
455 //$batch = "batchl".$i."_0";
456 //$stockLocation = "ent1".$i."_0";
457 $qty = "qtyl".$i; // qty
458
459 //reception line for product with no batch management and no multiple stock location
460 if (GETPOST($qty, 'alpha') > 0) {
461 $totalqty += price2num(GETPOST($qty, 'alpha'), 'MS');
462 }
463
464 // Extrafields
465 $array_options[$i] = $extrafields->getOptionalsFromPost($object->table_element_line, (string) $i);
466 }
467
468
469 if ($totalqty > 0) { // There is at least one thing to ship
470 for ($i = 1; $i <= $num; $i++) {
471 $idl = "idl".$i; // id line source
472 $lineToTest = '';
473 $lineId = GETPOSTINT($idl);
474 foreach ($objectsrc->lines as $linesrc) {
475 if ($linesrc->id == $lineId) {
476 $lineToTest = $linesrc;
477 break;
478 }
479 }
480 if (empty($lineToTest)) {
481 continue;
482 }
483 $qty = "qtyl".$i;
484 $comment = "comment".$i;
485 // EATBY <-> DLUO and SELLBY <-> DLC, see productbatch.class.php
486 $eatby = "dluo".$i;
487 $sellby = "dlc".$i;
488 $batch = "batch".$i;
489 $cost_price = "cost_price".$i;
490
491 //var_dump(GETPOST("productl".$i, 'int').' '.GETPOST('entl'.$i, 'int').' '.GETPOST($idl, 'int').' '.GETPOST($qty, 'int').' '.GETPOST($batch, 'alpha'));
492
493 //if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS')) || (GETPOST($qty, 'int') < 0 && getDolGlobalString('RECEPTION_ALLOW_NEGATIVE_QTY'))) {
494 if (GETPOSTFLOAT($qty) > 0 || (GETPOSTFLOAT($qty) == 0 && getDolGlobalString('RECEPTION_GETS_ALL_ORDER_PRODUCTS'))) {
495 $ent = "entl".$i;
496 $idl = "idl".$i;
497
498 $entrepot_id = is_numeric(GETPOST($ent)) ? GETPOSTINT($ent) : GETPOSTINT('entrepot_id');
499
500 /*
501 if (!empty($lineToTest)) {
502 $fk_product = $lineToTest->fk_product;
503 } else {
504 $fk_product = $linesrc->fk_product;
505 }*/
506 $fk_product = GETPOSTINT("productl".$i);
507
508 if ($entrepot_id < 0) {
509 $entrepot_id = '';
510 }
511 if (!($fk_product > 0) && !getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
512 $entrepot_id = 0;
513 }
514
515 $eatbydate = dol_mktime(12, 0, 0, GETPOSTINT($eatby.'month'), GETPOSTINT($eatby.'day'), GETPOSTINT($eatby.'year'));
516 $sellbydate = dol_mktime(12, 0, 0, GETPOSTINT($sellby.'month'), GETPOSTINT($sellby.'day'), GETPOSTINT($sellby.'year'));
517
518 if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
519 $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'));
520 } else {
521 $ret = $object->addline($entrepot_id, GETPOSTINT($idl), (float) price2num(GETPOST($qty), 'MS'), $array_options[$i], GETPOST($comment), $eatbydate, $sellbydate, GETPOST($batch));
522 }
523 if ($ret < 0) {
524 setEventMessages($object->error, $object->errors, 'errors');
525 $error++;
526 }
527 }
528 }
529
530 // Fill array 'array_options' with data from add form
531 $ret = $extrafields->setOptionalsFromPost(null, $object);
532 if ($ret < 0) {
533 $error++;
534 }
535 if (!$error) {
536 $ret = $object->create($user); // This create reception (like Odoo picking) and line of receptions. Stock movement will when validating reception.
537
538 if ($ret <= 0) {
539 setEventMessages($object->error, $object->errors, 'errors');
540 $error++;
541 } else {
542 // Define output language
543 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
544 $object->fetch_thirdparty();
545 $outputlangs = $langs;
546 $newlang = '';
547 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
548 $newlang = GETPOST('lang_id', 'aZ09');
549 }
550 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
551 $newlang = $object->thirdparty->default_lang;
552 }
553 if (!empty($newlang)) {
554 $outputlangs = new Translate("", $conf);
555 $outputlangs->setDefaultLang($newlang);
556 }
557 $model = $object->model_pdf;
558 $ret = $object->fetch($object->id); // Reload to get new records
559
560 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
561 if ($result < 0) {
562 dol_print_error($db, $object->error, $object->errors);
563 }
564 }
565 }
566 }
567 } else {
568 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("QtyToReceive").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
569 $error++;
570 }
571 }
572 if (!$error) {
573 $db->commit();
574 header("Location: card.php?id=" . $object->id);
575 exit;
576 } else {
577 $db->rollback();
578 //$_GET["commande_id"] = GETPOSTINT('commande_id');
579 $action = 'create';
580 }
581 } elseif ($action == 'confirm_valid' && $confirm == 'yes' && $permissiontovalidate) {
582 $object->fetch_thirdparty();
583
584 $result = $object->valid($user);
585
586 if ($result < 0) {
587 $langs->load("errors");
588 setEventMessages($langs->trans($object->error), null, 'errors');
589 } else {
590 // Define output language
591 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
592 $outputlangs = $langs;
593 $newlang = '';
594 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
595 $newlang = GETPOST('lang_id', 'aZ09');
596 }
597 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
598 $newlang = $object->thirdparty->default_lang;
599 }
600 if (!empty($newlang)) {
601 $outputlangs = new Translate("", $conf);
602 $outputlangs->setDefaultLang($newlang);
603 }
604 $model = $object->model_pdf;
605 $ret = $object->fetch($id); // Reload to get new records
606
607 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
608 if ($result < 0) {
609 dol_print_error($db, $object->error, $object->errors);
610 }
611 }
612 }
613 } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) {
614 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
615 $result = $object->delete($user);
616 if ($result > 0) {
617 header("Location: ".DOL_URL_ROOT.'/reception/index.php');
618 exit;
619 } else {
620 setEventMessages($object->error, $object->errors, 'errors');
621 }
622
623 // TODO add alternative status
624 /*} elseif ($action == 'reopen' && ($user->hasRights('reception', 'creer') || $user->hasRights('reception', 'reception_advance', 'validate'))) {
625 $result = $object->setStatut(Reception::STATUS_DRAFT);
626 if ($result < 0) {
627 setEventMessages($object->error, $object->errors, 'errors');
628 }*/
629 } elseif ($action == 'setdate_livraison' && $permissiontoadd) {
630 $datedelivery = dol_mktime(GETPOSTINT('liv_hour'), GETPOSTINT('liv_min'), 0, GETPOSTINT('liv_month'), GETPOSTINT('liv_day'), GETPOSTINT('liv_year'));
631
632 $object->fetch($id);
633 $result = $object->setDeliveryDate($user, $datedelivery);
634 if ($result < 0) {
635 setEventMessages($object->error, $object->errors, 'errors');
636 }
637 } elseif ($action == 'setdate_reception' && $user->hasRight('reception', 'creer')) {
638 $datereception = dol_mktime(GETPOSTINT('recep_hour'), GETPOSTINT('recep_min'), 0, GETPOSTINT('recep_month'), GETPOSTINT('recep_day'), GETPOSTINT('recep_year'));
639
640 $object->fetch($id);
641 $result = $object->setReceptionDate($user, $datereception);
642 if ($result < 0) {
643 setEventMessages($object->error, $object->errors, 'errors');
644 }
645 } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $permissiontoadd) {
646 // Remove a product line
647 $result = $object->deleteLine($user, $lineid);
648 if ($result > 0) {
649 // reorder lines
650 $object->line_order(true);
651 // Define output language
652 $outputlangs = $langs;
653 $newlang = '';
654 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
655 $newlang = GETPOST('lang_id', 'aZ09');
656 }
657 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
658 $newlang = $object->thirdparty->default_lang;
659 }
660 if (!empty($newlang)) {
661 $outputlangs = new Translate("", $conf);
662 $outputlangs->setDefaultLang($newlang);
663 }
664 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
665 $ret = $object->fetch($object->id); // Reload to get new records
666 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
667 }
668
669 header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id);
670 exit;
671 } else {
672 setEventMessages($object->error, $object->errors, 'errors');
673 }
674 } elseif (in_array($action, array('setwarehouse', 'settracking_number', 'settracking_url', 'settrueWeight', 'settrueWidth', 'settrueHeight', 'settrueDepth', 'setshipping_method_id')) && $permissiontoadd) {
675 // Action update
676 $error = 0;
677
678 if ($action == 'setwarehouse') { // Test on permission already done. Default warehouse for the lines
679 // Note: setValueFrom() casts the value to int, so it can not store an empty warehouse.
680 // We use update() to keep a NULL, because a line without warehouse must not move stock.
681 $object->fk_warehouse = (GETPOSTINT('warehouse_id') > 0 ? GETPOSTINT('warehouse_id') : null);
682 if ($object->update($user) < 0) {
683 $error++;
684 setEventMessages($object->error, $object->errors, 'errors');
685 }
686 }
687
688 if ($action == 'settracking_number') { // Test on permission already done
689 $object->tracking_number = trim(GETPOST('tracking_number', 'alpha'));
690 }
691 if ($action == 'settracking_url') { // Test on permission already done
692 $object->tracking_url = trim(GETPOST('tracking_url', 'restricthtml'));
693 }
694 if ($action == 'settrueWeight') { // Test on permission already done
695 $object->trueWeight = GETPOST('trueWeight');
696 $object->weight_units = GETPOSTINT('weight_units');
697 }
698 if ($action == 'settrueWidth') { // Test on permission already done
699 $object->trueWidth = GETPOST('trueWidth');
700 }
701 if ($action == 'settrueHeight') { // Test on permission already done
702 $object->trueHeight = GETPOST('trueHeight');
703 $object->size_units = GETPOSTINT('size_units');
704 }
705 if ($action == 'settrueDepth') { // Test on permission already done
706 $object->trueDepth = GETPOST('trueDepth');
707 }
708 if ($action == 'setshipping_method_id') { // Test on permission already done
709 $object->shipping_method_id = GETPOSTINT('shipping_method_id');
710 }
711
712 if ($object->update($user) >= 0) {
713 header("Location: card.php?id=" . $object->id);
714 exit;
715 }
716 setEventMessages($object->error, $object->errors, 'errors');
717
718 $action = "";
719 } elseif ($action == 'builddoc' && $permissiontoread) {
720 // Build document
721 // En get ou en post
722 // Save last template used to generate document
723 if (GETPOST('model')) {
724 $object->setDocModel($user, GETPOST('model', 'alpha'));
725 }
726
727 // Define output language
728 $outputlangs = $langs;
729 $newlang = '';
730 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
731 $newlang = GETPOST('lang_id', 'aZ09');
732 }
733 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
734 $newlang = $object->thirdparty->default_lang;
735 }
736 if (!empty($newlang)) {
737 $outputlangs = new Translate("", $conf);
738 $outputlangs->setDefaultLang($newlang);
739 }
740 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
741 if ($result <= 0) {
742 setEventMessages($object->error, $object->errors, 'errors');
743 $action = '';
744 }
745 } elseif ($action == 'remove_file' && $permissiontoadd) {
746 // Delete file in doc form
747 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
748
749 $upload_dir = $conf->reception->dir_output;
750 $file = $upload_dir.'/'.GETPOST('file');
751 $ret = dol_delete_file($file, 1, 0, 0, $object);
752 if ($ret) {
753 setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
754 } else {
755 setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), null, 'errors');
756 }
757 } elseif ($action == 'classifybilled' && $permissiontoadd) {
758 $result = $object->setBilled();
759 if ($result >= 0) {
760 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
761 exit();
762 } else {
763 setEventMessages($object->error, $object->errors, 'errors');
764 $action = '';
765 }
766 } elseif ($action == 'classifyclosed' && $permissiontoadd) {
767 $result = $object->setClosed();
768 if ($result >= 0) {
769 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
770 exit();
771 } else {
772 setEventMessages($object->error, $object->errors, 'errors');
773 $action = '';
774 }
775 } elseif ($action == 'deleteline' && !empty($line_id) && $permissiontoread) {
776 // delete a line
777 $lines = $object->lines;
778 $line = new CommandeFournisseurDispatch($db);
779
780 $num_prod = count($lines);
781 for ($i = 0; $i < $num_prod; $i++) {
782 if ($lines[$i]->id == $line_id) {
783 // delete single warehouse line
784 $line->id = $line_id;
785 if (!$error && $line->delete($user) < 0) {
786 $error++;
787 }
788 }
789 unset($_POST["lineid"]);
790 }
791
792 if (!$error) {
793 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
794 exit();
795 } else {
796 setEventMessages($line->error, $line->errors, 'errors');
797 }
798 } elseif ($action == 'updateline' && GETPOST('save') && $permissiontoadd) {
799 if (!$origin && getDolGlobalString('RECEPTION_STANDALONE')) {
800 // Update a line
801 // Clean parameters
802
803 if (!$object->fetch($id) > 0) {
804 dol_print_error($db);
805 }
806 $object->fetch_thirdparty();
807
808 $qty = GETPOST('qty', 'alpha');
809 $description = '';
810 $element_type = 'reception';
811 $fk_unit = '';
812 $fk_product = 0;
813 $rang = 0;
814
815 // Extrafields
816 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
817 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
818 // Unset extrafield
819 if (is_array($extralabelsline)) {
820 // Get extra fields
821 foreach ($extralabelsline as $key => $value) {
822 unset($_POST["options_" . $key]);
823 }
824 }
825
826 $receptionline = new ReceptionLineBatch($db);
827 $receptionline->fetch(GETPOSTINT('lineid'));
828
829
830 if (!$error) {
831 // Warehouse: the empty choice of the select posts -1, which means "clear the warehouse" (0),
832 // while an absent field means "do not change" (-1)
833 $wh_line = GETPOSTISSET('entrepot_id') ? max(0, GETPOSTINT('entrepot_id')) : -1;
834 $result = $object->updatelinefree(GETPOSTINT('lineid'), (float) $qty, $element_type, $fk_product, GETPOSTINT('units'), $rang, $description, 0, $array_options, GETPOSTISSET('cost_price') ? price2num(GETPOST('cost_price', 'alpha')) : null, GETPOSTISSET('fourn_ref') ? GETPOST('fourn_ref', 'alphanohtml') : null, $wh_line, GETPOSTISSET('batch') ? GETPOST('batch', 'alphanohtml') : null);
835
836 if ($result >= 0) {
837 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
838 // Define output language
839 $outputlangs = $langs;
840 $newlang = '';
841 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
842 $newlang = GETPOST('lang_id', 'aZ09');
843 }
844 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
845 $newlang = $object->thirdparty->default_lang;
846 }
847 if (!empty($newlang)) {
848 $outputlangs = new Translate("", $conf);
849 $outputlangs->setDefaultLang($newlang);
850 $outputlangs->load('products');
851 }
852
853 $ret = $object->fetch($object->id); // Reload to get new records
854 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
855 }
856 unset($_POST['qty']);
857 unset($_POST['units']);
858 } else {
859 setEventMessages($object->error, $object->errors, 'errors');
860 }
861 }
862 } elseif ($origin && $origin_id > 0) {
863 // Update a line
864 // Clean parameters
865 $qty = 0;
866 $entrepot_id = 0;
867 $batch_id = 0;
868
869 $lines = $object->lines;
870 $num_prod = count($lines);
871 for ($i = 0; $i < $num_prod; $i++) {
872 if ($lines[$i]->id == $line_id) { // we have found line to update
873 $line = new CommandeFournisseurDispatch($db);
874 $line->fetch($line_id);
875 // Extrafields Lines
876 $extrafields->fetch_name_optionals_label($object->table_element_line);
877 $line->array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
878
879 $line->fk_product = $lines[$i]->fk_product;
880
881 if ($lines[$i]->fk_product > 0) {
882 // single warehouse reception line
883 $stockLocation = "entl".$line_id;
884 $qty = "qtyl".$line_id;
885 $comment = "comment".$line_id;
886
887 $line->id = $line_id;
888 $line->fk_entrepot = GETPOSTINT($stockLocation);
889 $line->qty = GETPOSTFLOAT($qty, 'MS');
890 $line->comment = GETPOST($comment, 'alpha');
891
892 if (isModEnabled('productbatch')) {
893 $batch = "batch".$line_id;
894 $dlc = "dlc".$line_id;
895 $dluo = "dluo".$line_id;
896 $line->batch = GETPOST($batch, 'alpha');
897 // EATBY <-> DLUO
898 $line->eatby = dol_mktime(12, 0, 0, GETPOSTINT($dluo.'month'), GETPOSTINT($dluo.'day'), GETPOSTINT($dluo.'year'));
899 // SELLBY <-> DLC
900 $line->sellby = dol_mktime(12, 0, 0, GETPOSTINT($dlc.'month'), GETPOSTINT($dlc.'day'), GETPOSTINT($dlc.'year'));
901 }
902
903 if ($line->update($user) < 0) {
904 setEventMessages($line->error, $line->errors, 'errors');
905 $error++;
906 }
907 } else { // Product no predefined
908 $qty = "qtyl".$line_id;
909 $line->id = $line_id;
910 $line->qty = GETPOSTFLOAT($qty, 'MS');
911 $line->fk_entrepot = 0;
912 if ($line->update($user) < 0) {
913 setEventMessages($line->error, $line->errors, 'errors');
914 $error++;
915 }
916 unset($_POST[$qty]);
917 }
918 }
919 }
920
921 unset($_POST["lineid"]);
922
923 if (!$error) {
924 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
925 // Define output language
926 $outputlangs = $langs;
927 $newlang = '';
928 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
929 $newlang = GETPOST('lang_id', 'aZ09');
930 }
931 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
932 $newlang = $object->thirdparty->default_lang;
933 }
934 if (!empty($newlang)) {
935 $outputlangs = new Translate("", $conf);
936 $outputlangs->setDefaultLang($newlang);
937 }
938
939 $ret = $object->fetch($object->id); // Reload to get new records
940 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
941 }
942
943 // Redirect after the successful save so the page leaves edit mode and the
944 // updated values are read back from DB, matching the cancel path below
945 // and the header-data save handlers (see issue #38386).
946 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
947 exit();
948 } else {
949 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To reshow the record we edit
950 exit();
951 }
952 }
953 } elseif ($action == 'updateline' && $permissiontoadd && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {
954 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To reshow the record we edit
955 exit();
956 } elseif ($action == 'addline' && !$origin && getDolGlobalString('RECEPTION_STANDALONE') && $permissiontoadd) { // Add a new line
957 $langs->load('errors');
958 $error = 0;
959 $line_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
960 $predef = '';
961 $description = '';
962 $fk_elementdet = '';
963 $element_type = 'reception';
964 $fk_unit = GETPOSTINT('units');
965 $idprod = 0;
966 $fk_product = 0;
967 $fk_entrepot = '';
968 $rang = '';
969 $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09');
970 $cost_price_from_pfp = 0;
971 $reffourn_from_pfp = '';
972 if ($prod_entry_mode == 'free') {
973 $idprod = 0;
974 } else {
975 $idprod = GETPOSTINT('idprod');
976 if (empty($idprod) && GETPOSTISSET('idprodfournprice')) {
977 // The supplier product combo posts idprodfournprice (id of supplier price, or 'idprod_x' if product has no supplier price)
978 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
979 $ipfp = GETPOST('idprodfournprice', 'alpha');
980 $reg = array();
981 if (preg_match('/^idprod_([0-9]+)$/', $ipfp, $reg)) {
982 $idprod = (int) $reg[1];
983 } elseif ((int) $ipfp > 0) {
984 $productsupplier = new ProductFournisseur($db);
985 $idprod = $productsupplier->get_buyprice((int) $ipfp, (float) price2num(GETPOST('qty', 'alpha'), 'MS'));
986 if ($idprod > 0) {
987 $cost_price_from_pfp = price2num($productsupplier->fourn_unitprice);
988 $reffourn_from_pfp = $productsupplier->ref_supplier;
989 }
990 }
991 }
992 if ($prod_entry_mode != 'free' && $idprod <= 0) {
993 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors');
994 $error++;
995 }
996 if (getDolGlobalString('MAIN_DISABLE_FREE_LINES') && $idprod <= 0) {
997 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors');
998 $error++;
999 }
1000 }
1001
1002 $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
1003
1004 // Extrafields
1005 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1006 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1007 // Unset extrafield
1008 if (is_array($extralabelsline)) {
1009 // Get extra fields
1010 foreach ($extralabelsline as $key => $value) {
1011 unset($_POST["options_".$key]);
1012 }
1013 }
1014
1015 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
1016 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
1017 $error++;
1018 }
1019
1020 if ($qty == '') {
1021 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
1022 $error++;
1023 }
1024 if ($qty < 0) {
1025 setEventMessages($langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
1026 $error++;
1027 }
1028 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
1029 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
1030 $error++;
1031 }
1032
1033 if (!$error && isModEnabled('variants') && $prod_entry_mode != 'free') {
1034 if ($combinations = GETPOST('combinations', 'array')) {
1035 // Check if there is a product with the given combination
1036 $prodcomb = new ProductCombination($db);
1037
1038 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1039 $idprod = $res->fk_product_child;
1040 $fk_product = $idprod; // Update $fk_product with the fetched child product
1041 } else {
1042 setEventMessages($langs->trans('ErrorProductCombinationNotFound'), null, 'errors');
1043 $error++;
1044 }
1045 }
1046 }
1047
1048 if (!$error && ($qty >= 0) && (!empty($line_desc) || (!empty($idprod) && $idprod > 0))) {
1049 // Clean parameters
1050 if (!empty($idprod) && $idprod > 0) {
1051 $prod = new Product($db);
1052 $prod->fetch($idprod);
1053 $desc = $prod->label;
1054 $description = $desc;
1055 // Define output language
1056 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
1057 $outputlangs = $langs;
1058 $newlang = '';
1059 if (GETPOST('lang_id', 'aZ09')) {
1060 $newlang = GETPOST('lang_id', 'aZ09');
1061 }
1062 if (empty($newlang)) {
1063 $newlang = $object->thirdparty->default_lang;
1064 }
1065 if (!empty($newlang)) {
1066 $outputlangs = new Translate("", $conf);
1067 $outputlangs->setDefaultLang($newlang);
1068 }
1069
1070 $description = (!empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
1071 } else {
1072 $description = $prod->description;
1073 }
1074 if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 0) {
1075 $description = dol_concatdesc($desc, $line_desc, false, getDolGlobalString('MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION') ? true : false);
1076 } else {
1077 $description = $line_desc;
1078 }
1079
1080 // Add custom code and origin country into description
1081 if (!getDolGlobalString('MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
1082 $tmptxt = '(';
1083 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
1084 $outputlangs = $langs;
1085 $newlang = '';
1086 if (GETPOST('lang_id', 'alpha')) {
1087 $newlang = GETPOST('lang_id', 'alpha');
1088 }
1089 if (empty($newlang)) {
1090 $newlang = $object->thirdparty->default_lang;
1091 }
1092 if (!empty($newlang)) {
1093 $outputlangs = new Translate("", $conf);
1094 $outputlangs->setDefaultLang($newlang);
1095 $outputlangs->load('products');
1096 }
1097 if (!empty($prod->customcode)) {
1098 $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomsCode").': '.$prod->customcode;
1099 }
1100 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1101 $tmptxt .= ' - ';
1102 }
1103 if (!empty($prod->country_code)) {
1104 $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, '', $db, $outputlangs, 0);
1105 }
1106 } else {
1107 if (!empty($prod->customcode)) {
1108 $tmptxt .= $langs->transnoentitiesnoconv("CustomsCode").': '.$prod->customcode;
1109 }
1110 if (!empty($prod->customcode) && !empty($prod->country_code)) {
1111 $tmptxt .= ' - ';
1112 }
1113 if (!empty($prod->country_code)) {
1114 $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, '', $db, $langs, 0);
1115 }
1116 }
1117 $tmptxt .= ')';
1118 $description = dol_concatdesc($desc, $tmptxt);
1119 }
1120 $type = $prod->type;
1121 $fk_unit = $prod->fk_unit;
1122 } else {
1123 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1124 $desc = $line_desc;
1125 $type = GETPOST('type');
1126 $fk_unit = GETPOST('units', 'alpha');
1127 $description = $desc;
1128 $fk_elementdet = '';
1129 }
1130 $desc = dol_htmlcleanlastbr($desc);
1131
1132 if (!$error) {
1133 // Insert line
1134 // Buying price: typed value first (field of the supplier add-line block), then known supplier price
1135 $typedcost = price2num(GETPOST('cost_price', 'alpha'));
1136 if (!(float) $typedcost) {
1137 $typedcost = price2num(GETPOST('price_ht', 'alpha'));
1138 }
1139 $finalcost = ((float) $typedcost > 0) ? (float) $typedcost : (float) $cost_price_from_pfp;
1140 $reffourn_line = GETPOST('fourn_ref', 'alphanohtml');
1141 if ($reffourn_line === '' && !empty($reffourn_from_pfp)) {
1142 $reffourn_line = $reffourn_from_pfp;
1143 }
1144 $wh_line = max(0, GETPOSTINT('entrepot_id')); // Empty choice of the select posts -1: store 0 (a line without warehouse deliberately generates no stock movement)
1145 $result = $object->addlinefree((float) $qty, $element_type, $idprod, $fk_unit, min($rank, count($object->lines) + 1), $description, $array_options, (float) $finalcost, $reffourn_line, $wh_line, GETPOST('batch', 'alphanohtml'));
1146
1147 if ($result > 0) {
1148 $ret = $object->fetch($object->id); // Reload to get new records
1149 $object->fetch_thirdparty();
1150 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1151 // Define output language
1152 $outputlangs = $langs;
1153 $newlang = GETPOST('lang_id', 'alpha');
1154 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1155 $newlang = $object->thirdparty->default_lang;
1156 }
1157 if (!empty($newlang)) {
1158 $outputlangs = new Translate("", $conf);
1159 $outputlangs->setDefaultLang($newlang);
1160 }
1161 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1162 }
1163 } else {
1164 header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id); // To redisplay the form being edited
1165 exit();
1166 }
1167 }
1168 }
1169 }
1170
1171 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
1172
1173 // Actions to send emails
1174 if (empty($id)) {
1175 $id = $facid;
1176 }
1177 $triggersendname = 'RECEPTION_SENTBYMAIL';
1178 $paramname = 'id';
1179 $mode = 'emailfromreception';
1180 $autocopy = 'MAIN_MAIL_AUTOCOPY_RECEPTION_TO';
1181 $trackid = 'rec'.$object->id;
1182 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
1183}
1184
1185
1186/*
1187 * View
1188 */
1189
1190$title = $object->ref.' - '.$langs->trans('Reception');
1191if ($action == 'create') {
1192 $title = $langs->trans("NewReception");
1193}
1194llxHeader('', $title, 'Reception', '', 0, 0, '', '', '', 'mod-reception page-card');
1195
1196$form = new Form($db);
1197$formfile = new FormFile($db);
1198$formproduct = new FormProduct($db);
1199$formproject = null;
1200if (isModEnabled('project')) {
1201 $formproject = new FormProjets($db);
1202} else {
1203 $formproject = null;
1204}
1205
1206$product_static = new Product($db);
1207$reception_static = new Reception($db);
1208$warehousestatic = new Entrepot($db);
1209
1210if ($action == 'create' && $origin != 'supplierorder' && !getDolGlobalString('RECEPTION_STANDALONE')) {
1211 print load_fiche_titre($langs->trans("CreateReception"), '', 'dollyrevert');
1212
1213 print '<br>'.$langs->trans("ReceptionCreationIsDoneFromOrder");
1214 $action = '';
1215 $id = '';
1216 $ref = '';
1217}
1218
1219// Mode creation.
1220if ($action == 'create' && $permissiontoadd) {
1221 $recept = new Reception($db);
1222
1223 print load_fiche_titre($langs->trans("NewReception"), '', 'dollyrevert');
1224 if (empty($origin) && getDolGlobalString('RECEPTION_STANDALONE')) {
1225 $soc = new Societe($db);
1226 if ($socid > 0) {
1227 $res = $soc->fetch($socid);
1228 }
1229
1230 $note_private = $object->getDefaultCreateValueFor('note_private');
1231 $note_public = $object->getDefaultCreateValueFor('note_public');
1232
1233 print '<form name="crea_reception" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
1234 print '<input type="hidden" name="token" value="' . newToken() . '">';
1235 print '<input type="hidden" name="action" value="add">';
1236 print '<input type="hidden" name="changecompany" value="0">'; // will be set to 1 by javascript so we know post is done after a company change
1237 print '<input type="hidden" name="originid" value="' . $id . '">';
1238 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
1239
1240 print dol_get_fiche_head([]);
1241
1242 print '<table class="border centpercent">';
1243
1244
1245 // Thirdparty
1246 print '<tr>';
1247 print '<td class="fieldrequired">' . $langs->trans('ThirdParty') . '</td>';
1248 if ($socid > 0) {
1249 print '<td>';
1250 print $soc->getNomUrl(1);
1251 print '<input type="hidden" name="socid" value="' . $soc->id . '">';
1252 print '</td>';
1253 } else {
1254 print '<td class="valuefieldcreate">';
1255 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, array(), 0, 'minwidth175 maxwidth500 widthcentpercentminusxx');
1256 // reload page to retrieve customer information
1257 if (!getDolGlobalString('RELOAD_PAGE_ON_CUSTOMER_CHANGE_DISABLED')) {
1258 print '<script>
1259 $(document).ready(function() {
1260 $("#socid").change(function() {
1261 console.log("We have changed the company - Reload page");
1262 var socid = $(this).val();
1263 // reload page
1264 $("input[name=action]").val("create");
1265 $("input[name=changecompany]").val("1");
1266 $("form[name=crea_reception]").submit();
1267 });
1268 });
1269 </script>';
1270 }
1271 print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=3&fournisseur=0&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
1272 print '</td>';
1273 }
1274 print '</tr>'."\n";
1275
1276 // Default warehouse for the lines
1277 if (isModEnabled('stock')) {
1278 $langs->load('stocks');
1279 print '<tr><td>'.$langs->trans('Warehouse').'</td>';
1280 print '<td>';
1281 print img_picto('', 'stock', 'class="pictofixedwidth"');
1282 print $formproduct->selectWarehouses(GETPOSTINT('fk_warehouse') > 0 ? GETPOSTINT('fk_warehouse') : 'ifone', 'fk_warehouse', '', 1, 0, 0, '', 1, 0, array(), 'minwidth200');
1283 print '</td></tr>'."\n";
1284 }
1285
1286 // Project
1287 if (isModEnabled('project') && is_object($formproject)) {
1288 $projectid = GETPOSTINT('projectid');
1289 if (empty($projectid) && !empty($object->fk_project)) {
1290 $projectid = (int) $object->fk_project;
1291 }
1292 $langs->load("projects");
1293 print '<tr>';
1294 print '<td>' . $langs->trans("Project") . '</td><td colspan="2">';
1295 print img_picto('', 'project', 'class="pictofixedwidth"');
1296 print $formproject->select_projects($soc->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 1, 0, 'widthcentpercentminusxx');
1297 print ' <a class="paddingleft" 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"></span></a>';
1298 print '</td>';
1299 print '</tr>';
1300 }
1301
1302 // Reception Date
1303 print '<tr><td>'.$langs->trans("DateReception").'</td>';
1304 print '<td colspan="3">';
1305 print img_picto('', 'action', 'class="pictofixedwidth"');
1306 $date_reception = ($date_reception ? $date_reception : $object->date_reception); // $date_reception comes from GETPOST
1307 print $form->selectDate($date_reception ? $date_reception : -1, 'date_reception', 1, 1, 1);
1308 print "</td>\n";
1309 print '</tr>';
1310
1311 // Date delivery planned
1312 print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
1313 print '<td colspan="3">';
1314 print img_picto('', 'action', 'class="pictofixedwidth"');
1315 $date_delivery = ($date_delivery ? $date_delivery : $object->date_delivery); // $date_delivery comes from GETPOST
1316 print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);
1317 print "</td>\n";
1318 print '</tr>';
1319
1320 // Weight
1321 print '<tr><td>';
1322 print $langs->trans("Weight");
1323 print '</td><td colspan="3">';
1324 print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"');
1325 print '<input name="weight" size="4" value="'.GETPOST('weight').'"> ';
1326 $text = $formproduct->selectMeasuringUnits("weight_units", "weight", (string) GETPOSTINT('weight_units'), 0, 2);
1327 $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
1328 print $form->textwithpicto($text, $htmltext);
1329 print '</td></tr>';
1330
1331 // Dim
1332 print '<tr><td>';
1333 print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth");
1334 print ' </td><td colspan="3">';
1335 print img_picto('', 'fa-ruler', 'class="pictofixedwidth"');
1336 print '<input name="sizeW" size="4" value="'.GETPOST('sizeW').'">';
1337 print ' x <input name="sizeH" size="4" value="'.GETPOST('sizeH').'">';
1338 print ' x <input name="sizeS" size="4" value="'.GETPOST('sizeS').'">';
1339 print ' ';
1340 $text = $formproduct->selectMeasuringUnits("size_units", "size", (string) GETPOSTINT('size_units'), 0, 2);
1341 $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
1342 print $form->textwithpicto($text, $htmltext);
1343 print '</td></tr>';
1344
1345 // Delivery method
1346 print "<tr><td>".$langs->trans("ReceptionMethod")."</td>";
1347 print '<td colspan="3">';
1348 $recept->fetch_delivery_methods();
1349 print $form->selectarray("shipping_method_id", $recept->meths, GETPOSTINT('shipping_method_id'), 1, 0, 0, "", 1);
1350 if ($user->admin) {
1351 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1352 }
1353 print "</td></tr>\n";
1354
1355 // Tracking number
1356 print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
1357 print '<td colspan="3">';
1358 print img_picto('', 'barcode', 'class="pictofixedwidth"');
1359 print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number', 'alpha').'">';
1360 print "</td></tr>\n";
1361
1362 // Here $object can be of an object Reception
1363 $extrafields->fetch_name_optionals_label($object->table_element);
1364 if (empty($reshook) && !empty($extrafields->attributes[$object->table_element]['label'])) {
1365 if ($object->fetch_optionals() > 0) {
1366 $recept->array_options = array_merge($recept->array_options, $object->array_options);
1367 }
1368 print $recept->showOptionals($extrafields, 'create', $parameters);
1369 }
1370
1371 // Incoterms
1372 if (isModEnabled('incoterm')) {
1373 print '<tr>';
1374 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $object->label_incoterms, 1).'</label></td>';
1375 print '<td colspan="3" class="maxwidthonsmartphone">';
1376 print img_picto('', 'incoterm', 'class="pictofixedwidth"');
1377 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));
1378 print '</td></tr>';
1379 }
1380
1381 // Template to use by default
1383 if (is_countable($list) && count($list) > 0) {
1384 print '<tr><td>'.$langs->trans('Model').'</td>';
1385 print '<td colspan="2">';
1386 print img_picto('', 'pdf', 'class="pictofixedwidth"');
1387 include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
1388 print $form->selectarray('model', $list, getDolGlobalString('RECEPTION_ADDON_PDF'), 0, 0, 0, '', 0, 0, 0, '', 'maxwidth200 widthcentpercentminusx', 1);
1389 print "</td></tr>";
1390 }
1391
1392 // Note Public
1393 $htmltext = '';
1394 print '<tr>';
1395 print '<td class="tdtop">';
1396 print $form->textwithpicto($langs->trans('NotePublic'), $htmltext);
1397 print '</td>';
1398 print '<td valign="top" colspan="2">';
1399 $doleditor = new DolEditor('note_public', (string) $note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1400 print $doleditor->Create(1);
1401
1402 // Note Private
1403 if (!$user->socid) {
1404 print '<tr>';
1405 print '<td class="tdtop">';
1406 print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext);
1407 print '</td>';
1408 print '<td valign="top" colspan="2">';
1409 $doleditor = new DolEditor('note_private', (string) $note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1410 print $doleditor->Create(1);
1411 print "</td></tr>";
1412 }
1413
1414 print "</table>\n";
1415
1416 print dol_get_fiche_end();
1417
1418 print $form->buttonsSaveCancel("CreateDraft");
1419
1420 print "</form>\n";
1421 } elseif ($origin) {
1422 if ($origin == 'supplierorder') {
1423 $classname = 'CommandeFournisseur';
1424 } else {
1425 $classname = ucfirst($origin);
1426 }
1427
1428 $objectsrc = new $classname($db);
1429 if ($objectsrc->fetch($origin_id)) { // This include the fetch_lines
1430 $soc = new Societe($db);
1431 $soc->fetch($objectsrc->socid);
1432
1433 $author = new User($db);
1434 $author->fetch($objectsrc->user_author_id);
1435
1436 if (isModEnabled('stock')) {
1437 $entrepot = new Entrepot($db);
1438 }
1439
1440 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
1441 print '<input type="hidden" name="token" value="'.newToken().'">';
1442 print '<input type="hidden" name="action" value="add">';
1443 print '<input type="hidden" name="origin" value="'.$origin.'">';
1444 print '<input type="hidden" name="origin_id" value="'.$objectsrc->id.'">';
1445 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
1446 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1447 if (GETPOSTINT('entrepot_id')) {
1448 print '<input type="hidden" name="entrepot_id" value="'.GETPOSTINT('entrepot_id').'">';
1449 }
1450
1451 print dol_get_fiche_head();
1452
1453 print '<table class="border centpercent">';
1454
1455 // Ref
1456 print '<tr><td class="titlefieldcreate fieldrequired">';
1457 if ($origin == 'supplierorder' && isModEnabled("supplier_order")) {
1458 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;
1459 }
1460 if ($origin == 'propal' && isModEnabled("propal")) {
1461 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;
1462 }
1463 print '</a></td>';
1464 print "</tr>\n";
1465
1466 // Ref client
1467 print '<tr><td>';
1468 if ($origin == 'supplier_order') {
1469 print $langs->trans('SupplierOrder');
1470 } else {
1471 print $langs->trans('RefSupplier');
1472 }
1473 print '</td><td colspan="3">';
1474 print '<input type="text" name="ref_supplier" value="'.$objectsrc->ref_supplier.'" />';
1475 print '</td>';
1476 print '</tr>';
1477
1478 // Thirdparty provider
1479 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Company').'</td>';
1480 print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
1481 print '</tr>';
1482
1483 // Project
1484 if (isModEnabled('project') && $formproject !== null) {
1485 $projectid = GETPOSTINT('projectid') ? GETPOSTINT('projectid') : 0;
1486 if (empty($projectid) && !empty($objectsrc->fk_project)) {
1487 $projectid = $objectsrc->fk_project;
1488 }
1489 if ($origin == 'project') {
1490 $projectid = ($origin_id ? $origin_id : 0);
1491 }
1492
1493 $langs->load("projects");
1494 print '<tr>';
1495 print '<td>'.$langs->trans("Project").'</td><td colspan="2">';
1496 print img_picto('', 'project', 'class="paddingright"');
1497 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');
1498 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>';
1499 print '</td>';
1500 print '</tr>';
1501 }
1502
1503 // Reception Date
1504 print '<tr><td>'.$langs->trans("DateReception").'</td>';
1505 print '<td colspan="3">';
1506 print img_picto('', 'action', 'class="pictofixedwidth"');
1507 $date_reception = ($date_reception ? $date_reception : $object->date_reception); // $date_reception comes from GETPOST
1508 print $form->selectDate($date_reception ? $date_reception : -1, 'date_reception', 1, 1, 1);
1509 print "</td>\n";
1510 print '</tr>';
1511
1512 // Date delivery planned
1513 print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';
1514 print '<td colspan="3">';
1515 print img_picto('', 'action', 'class="pictofixedwidth"');
1516 $date_delivery = ($date_delivery ? $date_delivery : $objectsrc->delivery_date); // $date_delivery comes from GETPOST
1517 print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);
1518 print "</td>\n";
1519 print '</tr>';
1520
1521 // Note Public
1522 print '<tr><td>'.$langs->trans("NotePublic").'</td>';
1523 print '<td colspan="3">';
1524 $doleditor = new DolEditor('note_public', $objectsrc->note_public, '', 60, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1525 print $doleditor->Create(1);
1526 print "</td></tr>";
1527
1528 // Note Private
1529 if ($objectsrc->note_private && !$user->socid) {
1530 print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
1531 print '<td colspan="3">';
1532 $doleditor = new DolEditor('note_private', $objectsrc->note_private, '', 60, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1533 print $doleditor->Create(1);
1534 print "</td></tr>";
1535 }
1536
1537 // Weight
1538 print '<tr><td>';
1539 print $langs->trans("Weight");
1540 print '</td><td colspan="3"><input name="weight" size="4" value="'.GETPOST('weight').'"> ';
1541 $text = $formproduct->selectMeasuringUnits("weight_units", "weight", (string) GETPOSTINT('weight_units'), 0, 2);
1542 $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
1543 print $form->textwithpicto($text, $htmltext);
1544 print '</td></tr>';
1545 // Dim
1546 print '<tr><td>';
1547 print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth");
1548 print ' </td><td colspan="3"><input name="trueWidth" size="4" value="'.GETPOST('trueWidth').'">';
1549 print ' x <input name="trueHeight" size="4" value="'.GETPOST('trueHeight').'">';
1550 print ' x <input name="trueDepth" size="4" value="'.GETPOST('trueDepth').'">';
1551 print ' ';
1552 $text = $formproduct->selectMeasuringUnits("size_units", "size", (string) GETPOSTINT('size_units'), 0, 2);
1553 $htmltext = $langs->trans("KeepEmptyForAutoCalculation");
1554 print $form->textwithpicto($text, $htmltext);
1555 print '</td></tr>';
1556
1557 // Delivery method
1558 print "<tr><td>".$langs->trans("ReceptionMethod")."</td>";
1559 print '<td colspan="3">';
1560 $recept->fetch_delivery_methods();
1561 print $form->selectarray("shipping_method_id", $recept->meths, GETPOSTINT('shipping_method_id'), 1, 0, 0, "", 1);
1562 if ($user->admin) {
1563 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1564 }
1565 print "</td></tr>\n";
1566
1567 // Tracking number
1568 print "<tr><td>".$langs->trans("TrackingNumber")."</td>";
1569 print '<td colspan="3">';
1570 print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number', 'alpha').'">';
1571 print "</td></tr>\n";
1572
1573 // Other attributes
1574 $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'cols' => '3', 'socid' => $socid);
1575 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $recept, $action); // Note that $action and $objectsrc may have been modified by hook
1576 print $hookmanager->resPrint;
1577
1578 // Here $object can be of an object Reception
1579 $extrafields->fetch_name_optionals_label($object->table_element);
1580 if (empty($reshook) && !empty($extrafields->attributes[$object->table_element]['label'])) {
1581 // copy from order
1582 if ($objectsrc->fetch_optionals() > 0) {
1583 $recept->array_options = array_merge($recept->array_options, $objectsrc->array_options);
1584 }
1585 print $recept->showOptionals($extrafields, 'create', $parameters);
1586 }
1587
1588 // Incoterms
1589 if (isModEnabled('incoterm')) {
1590 print '<tr>';
1591 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), $objectsrc->label_incoterms, 1).'</label></td>';
1592 print '<td colspan="3" class="maxwidthonsmartphone">';
1593 print $form->select_incoterms((!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : ''), (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : ''));
1594 print '</td></tr>';
1595 }
1596
1597 // Document model
1598 include_once DOL_DOCUMENT_ROOT.'/core/modules/reception/modules_reception.php';
1600
1601 if (is_array($list) && count($list) > 1) {
1602 print "<tr><td>".$langs->trans("DefaultModel")."</td>";
1603 print '<td colspan="3">';
1604 print $form->selectarray('model', $list, getDolGlobalString('RECEPTION_ADDON_PDF'));
1605 print "</td></tr>\n";
1606 }
1607
1608 print "</table>";
1609
1610 print dol_get_fiche_end();
1611
1612 // Number of lines show on the reception card
1613 $numAsked = 0;
1614
1619 $suffix2numAsked = array();
1620 $dispatchLines = array();
1621
1622 foreach ($_POST as $key => $value) {
1623 // If create form is coming from the button "Create Reception" of previous page
1624
1625 // without batch module enabled or product with no lot/serial
1626 $reg = array();
1627 if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
1628 $numAsked++;
1629 $paramSuffix = $reg[1] . '_' . $reg[2];
1630 $suffix2numAsked[$paramSuffix] = $numAsked;
1631
1632 // $numline=$reg[2] + 1; // line of product
1633 $numline = $numAsked;
1634
1635 $prod = "product_" . $paramSuffix;
1636 $qty = "qty_" . $paramSuffix;
1637 $ent = "entrepot_" . $paramSuffix;
1638 $pu = "pu_" . $paramSuffix; // This is unit price including discount
1639 $fk_commandefourndet = "fk_commandefourndet_" . $paramSuffix;
1640 $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));
1641 }
1642
1643 // with batch module enabled and product with lot/serial
1644 if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
1645 $numAsked++;
1646 $paramSuffix = $reg[1] . '_' . $reg[2];
1647 $suffix2numAsked[$paramSuffix] = $numAsked;
1648
1649 // eat-by date dispatch
1650 // $numline=$reg[2] + 1; // line of product
1651 $numline = $numAsked;
1652
1653 $prod = 'product_batch_' . $paramSuffix;
1654 $qty = 'qty_' . $paramSuffix;
1655 $ent = 'entrepot_' . $paramSuffix;
1656 $pu = 'pu_' . $paramSuffix;
1657 $lot = 'lot_number_' . $paramSuffix;
1658 $dDLUO = dol_mktime(12, 0, 0, GETPOSTINT('dluo_'.$paramSuffix.'month'), GETPOSTINT('dluo_'.$paramSuffix.'day'), GETPOSTINT('dluo_'.$paramSuffix.'year'));
1659 $dDLC = dol_mktime(12, 0, 0, GETPOSTINT('dlc_'.$paramSuffix.'month'), GETPOSTINT('dlc_'.$paramSuffix.'day'), GETPOSTINT('dlc_'.$paramSuffix.'year'));
1660 $fk_commandefourndet = 'fk_commandefourndet_'.$paramSuffix;
1661 $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));
1662 }
1663
1664 // If create form is coming from same page, it means that post was sent but an error occurred
1665 if (preg_match('/^productl([0-9]+)$/i', $key, $reg)) {
1666 $numAsked++;
1667 $paramSuffix = $reg[1];
1668 $suffix2numAsked[$paramSuffix] = $numAsked;
1669
1670 // eat-by date dispatch
1671 // $numline=$reg[2] + 1; // line of product
1672 $numline = $numAsked;
1673
1674 $prod = 'productid'.$paramSuffix;
1675 $comment = 'comment'.$paramSuffix;
1676 $qty = 'qtyl'.$paramSuffix;
1677 $ent = 'entl'.$paramSuffix;
1678 $pu = 'pul'.$paramSuffix;
1679 $lot = 'batch'.$paramSuffix;
1680 $dDLUO = dol_mktime(12, 0, 0, GETPOSTINT('dluo'.$paramSuffix.'month'), GETPOSTINT('dluo'.$paramSuffix.'day'), GETPOSTINT('dluo'.$paramSuffix.'year'));
1681 $dDLC = dol_mktime(12, 0, 0, GETPOSTINT('dlc'.$paramSuffix.'month'), GETPOSTINT('dlc'.$paramSuffix.'day'), GETPOSTINT('dlc'.$paramSuffix.'year'));
1682 $fk_commandefourndet = 'fk_commandefournisseurdet'.$paramSuffix;
1683 $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));
1684 }
1685 }
1686
1687 // If extrafield values are passed in the HTTP query, assign them to the correct dispatch line
1688 // Note that if an extrafield with the same name exists in the origin supplier order line, the value
1689 // from the HTTP query will be ignored
1690 foreach ($suffix2numAsked as $suffix => $n) {
1691 $dispatchLines[$n]['array_options'] = $extrafields->getOptionalsFromPost('receptiondet_batch', '_' . $suffix, '');
1692 }
1693
1694 $reshook = $hookmanager->executeHooks('dataProcessing', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1695 if ($reshook < 0) {
1696 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1697 } elseif (empty($reshook)) {
1698 // Only merge if resArray is a valid, non-empty array
1699 if (is_array($hookmanager->resArray) && !empty($hookmanager->resArray)) {
1700 // Check if the merge would overwrite valid data with NULL
1701 $tempMerged = array_merge($dispatchLines, $hookmanager->resArray);
1702
1703 // Sanity check: ensure our existing keys are still valid arrays
1704 $corrupted = false;
1705 foreach ($dispatchLines as $idx => $val) {
1706 if (!is_array($tempMerged[$idx]) || !isset($tempMerged[$idx]['fk_commandefourndet'])) {
1707 $corrupted = true;
1708 break;
1709 }
1710 }
1711
1712 if (!$corrupted) {
1713 $dispatchLines = $tempMerged;
1714 } else {
1715 // If merge corrupted data, ignore the hook result and keep original
1716 error_log("WARNING: Hook dataProcessing returned invalid data, ignoring merge.");
1717 }
1718 }
1719 } elseif ($reshook > 0) {
1720 // $resArray starts from [0], we need $dispatchLines to start from [1], so we shift it
1721 $dispatchLines = $hookmanager->resArray;
1722 array_unshift($dispatchLines, null);
1723 unset($dispatchLines[0]);
1724 $numAsked = count($dispatchLines);
1725 }
1726
1727 print '<script type="text/javascript">
1728 jQuery(document).ready(function() {
1729 jQuery("#autofill").click(function(event) {
1730 event.preventDefault();';
1731 $i = 1;
1732 while ($i <= $numAsked) {
1733 print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";
1734 $i++;
1735 }
1736 print '});
1737 jQuery("#autoreset").click(function(event) {
1738 event.preventDefault();';
1739 $i = 1;
1740 while ($i <= $numAsked) {
1741 print 'jQuery("#qtyl'.$i.'").val(0);'."\n";
1742 $i++;
1743 }
1744 print '});
1745 });
1746 </script>';
1747
1748 print '<br>';
1749
1750 print '<table class="noborder centpercent">';
1751
1752 // Load receptions already done for same order
1753 $objectsrc->loadReceptions();
1754
1755 if ($numAsked) {
1756 print '<tr class="liste_titre">';
1757 print '<td>'.$langs->trans("Description").'</td>';
1758 print '<td>'.$langs->trans("Comment").'</td>';
1759 print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
1760 print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
1761 print '<td class="center">'.$langs->trans("QtyToReceive");
1762 if (getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1763 print '<td>'.$langs->trans("BuyingPrice").'</td>';
1764 }
1765 if (!isModEnabled('productbatch')) {
1766 print ' <br><center><a href="#" id="autofill"><span class="fas fa-fill pictofixedwidth" style=""></span> '.$langs->trans("Fill").'</a>';
1767 print ' &nbsp; &nbsp; <a href="#" id="autoreset"><span class="fas fa-eraser pictofixedwidth" style=""></span>'.$langs->trans("Reset").'</a></center><br>';
1768 }
1769 print '</td>';
1770 if (isModEnabled('stock')) {
1771 print '<td class="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';
1772 }
1773 if (isModEnabled('productbatch')) {
1774 print '<td class="left">'.$langs->trans("batch_number").'</td>';
1775 if (!getDolGlobalInt('PRODUCT_DISABLE_SELLBY')) {
1776 print '<td class="left">'.$langs->trans("SellByDate").'</td>';
1777 }
1778 if (!getDolGlobalInt('PRODUCT_DISABLE_EATBY')) {
1779 print '<td class="left">'.$langs->trans("EatByDate").'</td>';
1780 }
1781 }
1782
1783 $parameters = array();
1784 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1785 if ($reshook < 0) {
1786 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1787 } else {
1788 print $hookmanager->resPrint;
1789 }
1790 print "</tr>\n";
1791 }
1792
1793 // $objectsrc->lines contains the line of the purchase order
1794 // $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.
1795
1796 $arrayofpurchaselinealreadyoutput = array();
1797
1798 // $_POST contains fk_commandefourndet_X_Y where Y is num of product line and X is number of split lines
1799 $indiceAsked = 1;
1800 while ($indiceAsked <= $numAsked) { // Loop on $dispatchLines. Warning: $dispatchLines must be sorted by fk_commandefourndet (it is a regroupment key on output)
1801 $product = new Product($db);
1802 $line = new CommandeFournisseurLigne($db); // By default
1803
1804 // We search the purchase order line that is linked to the dispatchLines
1805 foreach ($objectsrc->lines as $supplierLine) {
1806 if ($dispatchLines[$indiceAsked]['fk_commandefourndet'] == $supplierLine->id) {
1807 $line = $supplierLine;
1808 break;
1809 }
1810 }
1811
1812 // Now $line can be CommandeFournisseurLigne but could be other type of line.
1813
1814 // Show product and description
1815 $type = $line->product_type ? $line->product_type : $line->fk_product_type;
1816 // Try to enhance type detection using date_start and date_end for free lines where type was not saved.
1817 if (!empty($line->date_start)) {
1818 $type = 1;
1819 }
1820 if (!empty($line->date_end)) {
1821 $type = 1;
1822 }
1823
1824 print '<!-- line fk_commandefourndet='.$line->id.' for product='.$line->fk_product.' -->'."\n";
1825 print '<tr class="oddeven">'."\n";
1826
1827 // Product label
1828 if ($line->fk_product > 0) { // If predefined product
1829 $product->fetch($line->fk_product);
1830 $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch
1831 //var_dump($product->stock_warehouse[1]);
1832 //var_dump($dispatchLines[$indiceAsked]);
1833
1834 print '<td>';
1835 print '<a name="'.$line->id.'"></a>'; // Anchor to return to the line
1836
1837 print '<input type="hidden" name="productl'.$indiceAsked.'" value="'.$line->fk_product.'">';
1838
1839 if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
1840 print '<input type="hidden" name="productid'.$indiceAsked.'" value="'.$line->fk_product.'">';
1841
1842 // Show product and description
1843 $product_static = $product;
1844
1845 $text = $product_static->getNomUrl(1);
1846 $text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label);
1847 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($line->desc));
1848 print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i);
1849
1850 // Show range
1851 print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
1852
1853 // Add description in form
1854 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
1855 print ($line->desc && $line->desc != $line->product_label) ? '<br>'.dol_htmlentitiesbr($line->desc) : '';
1856 }
1857 }
1858 print '</td>';
1859 } else {
1860 print "<td>";
1861 if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
1862 if ($type == 1) {
1863 $text = img_object($langs->trans('Service'), 'service');
1864 } else {
1865 $text = img_object($langs->trans('Product'), 'product');
1866 }
1867
1868 if (!empty($line->label)) {
1869 $text .= ' <strong>'.$line->label.'</strong>';
1870 print $form->textwithtooltip($text, $line->desc, 3, 0, '', (string) $i);
1871 } else {
1872 print $text.' '.nl2br($line->desc);
1873 }
1874
1875 // Show range
1876 print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));
1877 }
1878 print "</td>\n";
1879 }
1880
1881 // Comment
1882 //$defaultcomment = 'Line create from order line id '.$line->id;
1883 $defaultcomment = $dispatchLines[$indiceAsked]['comment'];
1884 print '<td>';
1885 print '<input type="text" class="maxwidth100" name="comment'.$indiceAsked.'" value="'.$defaultcomment.'">';
1886 print '</td>';
1887
1888 // Qty in source purchase order line
1889 print '<td class="center">';
1890 if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
1891 print $line->qty;
1892 }
1893 print '<input type="hidden" name="fk_commandefournisseurdet'.$indiceAsked.'" value="'.$line->id.'">';
1894 print '<input type="hidden" name="pul'.$indiceAsked.'" value="'.$line->subprice.'">';
1895 print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';
1896 print '</td>';
1897 $qtyProdCom = $line->qty;
1898
1899 // Qty already received
1900 print '<td class="center">';
1901 $quantityDelivered = isset($objectsrc->receptions[$line->id]) ? $objectsrc->receptions[$line->id] : 0;
1902 if (! array_key_exists($line->id, $arrayofpurchaselinealreadyoutput)) { // Add test to avoid to show qty twice
1903 print $quantityDelivered;
1904 }
1905 print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';
1906 print '</td>';
1907
1908
1909 if ($line->product_type == 1 && !getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1910 $quantityToBeDelivered = 0;
1911 } else {
1912 $quantityToBeDelivered = $dispatchLines[$indiceAsked]['qty'];
1913 }
1914 $warehouse_id = $dispatchLines[$indiceAsked]['ent'];
1915
1916
1917 $warehouseObject = null;
1918 if (isModEnabled('stock')) {
1919 // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection
1920 print '<!-- Case warehouse already known or product not a predefined product -->';
1921 if (array_key_exists($dispatchLines[$indiceAsked]['ent'], $product->stock_warehouse)) {
1922 $stock = +$product->stock_warehouse[$dispatchLines[$indiceAsked]['ent']]->real; // Convert to number
1923 }
1924 $deliverableQty = $dispatchLines[$indiceAsked]['qty'];
1925 $cost_price = $dispatchLines[$indiceAsked]['pu'];
1926
1927 // Quantity to send
1928 print '<td class="center">';
1929 if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
1930 if (GETPOSTINT('qtyl'.$indiceAsked)) {
1931 $defaultqty = GETPOSTINT('qtyl'.$indiceAsked);
1932 }
1933 print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';
1934 print '<input class="right" name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';
1935 } else {
1936 print $langs->trans("NA");
1937 }
1938 print '</td>';
1939
1940 if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
1941 print '<td>';
1942 print '<input class="width75 right" name="cost_price'.$indiceAsked.'" id="cost_price'.$indiceAsked.'" value="'.price($cost_price).'">';
1943 print '</td>';
1944 }
1945
1946 // Stock
1947 if (isModEnabled('stock')) {
1948 print '<td class="left">';
1949 if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) { // Type of product need stock change ?
1950 // Show warehouse combo list
1951 $ent = "entl".$indiceAsked;
1952 $idl = "idl".$indiceAsked;
1953 $tmpentrepot_id = is_numeric(GETPOST($ent)) ? GETPOSTINT($ent) : $warehouse_id;
1954 if ($line->fk_product > 0) {
1955 print '<!-- Show warehouse selection -->';
1956 print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 0, 0, $line->fk_product, '', 1);
1957 }
1958 } else {
1959 print $langs->trans("Service");
1960 }
1961 print '</td>';
1962 }
1963
1964 if (isModEnabled('productbatch')) {
1965 if (!empty($product->status_batch)) {
1966 print '<td><input name="batch'.$indiceAsked.'" value="'.dol_escape_htmltag($dispatchLines[$indiceAsked]['lot']).'"></td>';
1967 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
1968 print '<td class="nowraponall">';
1969 print $form->selectDate($dispatchLines[$indiceAsked]['DLC'], 'dlc'.$indiceAsked, 0, 0, 1, "");
1970 print '</td>';
1971 }
1972 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
1973 print '<td class="nowraponall">';
1974 print $form->selectDate($dispatchLines[$indiceAsked]['DLUO'], 'dluo'.$indiceAsked, 0, 0, 1, "");
1975 print '</td>';
1976 }
1977 } else {
1978 print '<td colspan="3"></td>';
1979 }
1980 }
1981
1982 $parameters = array();
1983 $parameters['dispatchLine'] = $dispatchLines[$indiceAsked];
1984 $parameters['indiceAsked'] = $indiceAsked;
1985 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
1986 if ($reshook < 0) {
1987 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1988 } else {
1989 print $hookmanager->resPrint;
1990 }
1991 }
1992
1993 $arrayofpurchaselinealreadyoutput[$line->id] = $line->id;
1994
1995 print "</tr>\n";
1996
1997 // Display lines for extrafields of the Reception line
1998 // $line is a 'CommandeFournisseurLigne', $dispatchLines contains values of Reception lines so properties of CommandeFournisseurDispatch
1999 if (!empty($extrafields)) {
2000 $colspan = 5;
2001 if (isModEnabled('productbatch')) {
2002 $colspan += 2;
2003 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
2004 $colspan += 1;
2005 }
2006 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
2007 $colspan += 1;
2008 }
2009 }
2010 $recLine = new CommandeFournisseurDispatch($db);
2011
2012 $srcLine = new CommandeFournisseurLigne($db);
2013 $srcLine->id = $line->id;
2014 $srcLine->fetch_optionals(); // fetch extrafields also available in orderline
2015
2016 if (empty($recLine->array_options) && !empty($dispatchLines[$indiceAsked]['array_options'])) {
2017 $recLine->array_options = $dispatchLines[$indiceAsked]['array_options'];
2018 }
2019 $recLine->array_options = array_merge($recLine->array_options, $srcLine->array_options);
2020
2021 print $recLine->showOptionals($extrafields, 'edit', array('style' => 'class="oddeven"', 'colspan' => $colspan), (string) $indiceAsked, '', '1');
2022 }
2023
2024 $indiceAsked++;
2025 }
2026
2027 print "</table>";
2028
2029 print '<br>';
2030
2031 print $form->buttonsSaveCancel("Create");
2032
2033 print '</form>';
2034
2035 print '<br>';
2036 } else {
2037 dol_print_error($db);
2038 }
2039 }
2040} elseif ($object->id > 0) {
2041 /* *************************************************************************** */
2042 /* */
2043 /* Edit and view mode */
2044 /* */
2045 /* *************************************************************************** */
2046 $lines = $object->lines;
2047
2048 $num_prod = count($lines);
2049 $indiceAsked = 0;
2050
2051 if ($object->id <= 0) {
2052 print $langs->trans("NoRecordFound");
2053 llxFooter();
2054 exit;
2055 }
2056
2057 $typeobject = '';
2058 if (!empty($object->origin) && $object->origin_id > 0) {
2059 $typeobject = $object->origin;
2060 $origin = $object->origin;
2061 $origin_id = $object->origin_id;
2062 $object->fetch_origin(); // Load property $object->origin_object, $object->commande, $object->propal, ...
2063 }
2064
2065 $soc = new Societe($db);
2066 $soc->fetch($object->socid);
2067
2068 $res = $object->fetch_optionals();
2069
2070 $head = reception_prepare_head($object);
2071 print dol_get_fiche_head($head, 'reception', $langs->trans("Reception"), -1, 'dollyrevert', 0, '', '', 0, '', 1);
2072
2073 $formconfirm = '';
2074
2075 // Confirm deletion
2076 if ($action == 'delete') {
2077 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteReception'), $langs->trans("ConfirmDeleteReception", $object->ref), 'confirm_delete', '', 0, 1);
2078 }
2079
2080 // Confirmation validation
2081 if ($action == 'valid') {
2082 $objectref = substr($object->ref, 1, 4);
2083 if ($objectref == 'PROV') {
2084 $numref = $object->getNextNumRef($soc);
2085 } else {
2086 $numref = (string) $object->ref;
2087 }
2088
2089 $text = $langs->trans("ConfirmValidateReception", $numref);
2090 if (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION')) {
2091 $text .= '<br>'.img_picto('', 'movement', 'class="pictofixedwidth"').$langs->trans("StockMovementWillBeRecorded").'.';
2092 } elseif (getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) {
2093 $text .= '<br>'.img_picto('', 'movement', 'class="pictofixedwidth"').$langs->trans("StockMovementNotYetRecorded").'.';
2094 }
2095
2096 if (isModEnabled('notification')) {
2097 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
2098 $notify = new Notify($db);
2099 $text .= '<br>';
2100 $text .= $notify->confirmMessage('RECEPTION_VALIDATE', $object->socid, $object);
2101 }
2102
2103 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateReception'), $text, 'confirm_valid', '', 0, 1, 250);
2104 }
2105
2106 // Confirm cancellation
2107 if ($action == 'annuler') {
2108 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelReception'), $langs->trans("ConfirmCancelReception", $object->ref), 'confirm_cancel', '', 0, 1);
2109 }
2110
2111 if (!$formconfirm) {
2112 $parameters = array('formConfirm' => $formconfirm);
2113 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2114 if (empty($reshook)) {
2115 $formconfirm .= $hookmanager->resPrint;
2116 } elseif ($reshook > 0) {
2117 $formconfirm = $hookmanager->resPrint;
2118 }
2119 }
2120
2121 // Print form confirm
2122 print $formconfirm;
2123
2124
2125 // Calculate totalWeight and totalVolume for all products
2126 // by adding weight and volume of each product line.
2127 $tmparray = $object->getTotalWeightVolume();
2128 $totalWeight = $tmparray['weight'];
2129 $totalVolume = $tmparray['volume'];
2130
2131
2132 if ($typeobject == 'commande' && $object->origin_object->id && isModEnabled('order')) {
2133 $objectsrc = new Commande($db);
2134 $objectsrc->fetch($object->origin_object->id);
2135 }
2136 if ($typeobject == 'propal' && $object->origin_object->id && isModEnabled("propal")) {
2137 $objectsrc = new Propal($db);
2138 $objectsrc->fetch($object->origin_object->id);
2139 }
2140 if (($typeobject == 'order_supplier' || $typeobject == 'supplier_order' || $typeobject == 'CommandeFournisseur') && $object->origin_object->id && isModEnabled("supplier_order")) {
2141 $objectsrc = new CommandeFournisseur($db);
2142 $objectsrc->fetch($object->origin_object->id);
2143 }
2144 // Reception card
2145 $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
2146 $morehtmlref = '<div class="refidno">';
2147 // Ref customer reception
2148
2149 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', 0, 1);
2150 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->hasRight('reception', 'creer'), 'string', '', null, null, '', 1);
2151
2152 // Thirdparty
2153 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
2154 // Project
2155 if ($origin && $origin_id > 0) {
2156 if (isModEnabled('project')) {
2157 $langs->load("projects");
2158 $morehtmlref .= '<br>';
2159 if (0) { // @phpstan-ignore-line Do not change on shipment
2160 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
2161 if ($action != 'classify') {
2162 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
2163 }
2164 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, (string) $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
2165 } else {
2166 if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
2167 $proj = new Project($db);
2168 $proj->fetch((int) $objectsrc->fk_project);
2169 $morehtmlref .= $proj->getNomUrl(1);
2170 if ($proj->title) {
2171 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
2172 }
2173 }
2174 }
2175 }
2176 } elseif (!$origin && getDolGlobalString('RECEPTION_STANDALONE')) {
2177 // Project
2178 if (isModEnabled('project')) {
2179 $langs->load("projects");
2180 $morehtmlref .= '<br>';
2181 if ($permissiontoadd) {
2182 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
2183 if ($action != 'classify') {
2184 $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> ';
2185 }
2186 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
2187 } else {
2188 if (!empty($object->fk_project)) {
2189 $proj = new Project($db);
2190 $proj->fetch($object->fk_project);
2191 $morehtmlref .= $proj->getNomUrl(1);
2192 if ($proj->title) {
2193 $morehtmlref .= '<span class="opacitymedium"> - ' . dol_escape_htmltag($proj->title) . '</span>';
2194 }
2195 }
2196 }
2197 }
2198 }
2199 $morehtmlref .= '</div>';
2200
2201 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
2202
2203
2204 print '<div class="fichecenter">';
2205 print '<div class="fichehalfleft">';
2206 print '<div class="underbanner clearboth"></div>';
2207
2208 print '<table class="border centpercent tableforfield">';
2209
2210 // Linked documents
2211 if ($typeobject == 'commande' && $object->origin_object->id && isModEnabled('order')) {
2212 print '<tr><td>';
2213 print $langs->trans("RefOrder").'</td>';
2214 print '<td colspan="3">';
2215 print $objectsrc->getNomUrl(1, 'commande');
2216 print "</td>\n";
2217 print '</tr>';
2218 }
2219 if ($typeobject == 'propal' && $object->origin_object->id && isModEnabled("propal")) {
2220 print '<tr><td>';
2221 print $langs->trans("RefProposal").'</td>';
2222 print '<td colspan="3">';
2223 print $objectsrc->getNomUrl(1, 'reception');
2224 print "</td>\n";
2225 print '</tr>';
2226 }
2227 if (($typeobject == 'order_supplier' || $typeobject == 'supplier_order' || $typeobject == 'CommandeFournisseur') && $object->origin_object->id && isModEnabled("supplier_order")) {
2228 print '<tr><td>';
2229 print $langs->trans("SupplierOrder").'</td>';
2230 print '<td colspan="3">';
2231 print $objectsrc->getNomUrl(1, 'reception');
2232 print "</td>\n";
2233 print '</tr>';
2234 }
2235
2236 // Date creation
2237 print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
2238 print '<td colspan="3">'.dol_print_date($object->date_creation, "dayhour", "tzuserrel")."</td>\n";
2239 print '</tr>';
2240
2241 // Reception Date
2242 print '<tr><td height="10">';
2243 print '<table class="nobordernopadding centpercent"><tr><td>';
2244 print $langs->trans('DateReception');
2245 print '</td>';
2246 if ($action != 'editdate_reception') {
2247 print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editdate_reception&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->trans('SetReceptionDate'), 1) . '</a></td>';
2248 }
2249 print '</tr></table>';
2250 print '</td><td>';
2251 if ($action == 'editdate_reception') {
2252 print '<form name="setdate_reception" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="post">';
2253 print '<input type="hidden" name="token" value="' . newToken() . '">';
2254 print '<input type="hidden" name="action" value="setdate_reception">';
2255 print $form->selectDate($object->date_reception ? $object->date_reception : -1, 'recep_', 1, 1, 0, "setdate_reception", 1, 0);
2256 print '<input type="submit" class="button button-edit smallpaddingimp" value="' . $langs->trans('Modify') . '">';
2257 print '</form>';
2258 } else {
2259 print $object->date_reception ? dol_print_date($object->date_reception, 'dayhour') : '&nbsp;';
2260 }
2261 print '</td>';
2262 print '</tr>';
2263
2264 // Delivery date planned
2265 print '<tr><td height="10">';
2266 print '<table class="nobordernopadding" width="100%"><tr><td>';
2267 print $langs->trans('DateDeliveryPlanned');
2268 print '</td>';
2269
2270 if ($action != 'editdate_livraison' && $permissiontoadd) {
2271 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>';
2272 }
2273 print '</tr></table>';
2274 print '</td><td colspan="2">';
2275 if ($action == 'editdate_livraison') {
2276 print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2277 print '<input type="hidden" name="token" value="'.newToken().'">';
2278 print '<input type="hidden" name="action" value="setdate_livraison">';
2279 print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, 0, "setdate_livraison", 1, 0);
2280 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
2281 print '</form>';
2282 } else {
2283 print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
2284 }
2285 print '</td>';
2286 print '</tr>';
2287
2288 // Weight
2289 print '<tr><td>';
2290 print $form->editfieldkey("Weight", 'trueWeight', (string) $object->trueWeight, $object, $user->hasRight('reception', 'creer'));
2291 print '</td><td colspan="3">';
2292
2293 if ($action == 'edittrueWeight') {
2294 print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
2295 print '<input name="action" value="settrueWeight" type="hidden">';
2296 print '<input name="id" value="'.$object->id.'" type="hidden">';
2297 print '<input type="hidden" name="token" value="'.newToken().'">';
2298 print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text">';
2299 print $formproduct->selectMeasuringUnits("weight_units", "weight", (string) $object->weight_units, 0, 2);
2300 print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
2301 print ' <input class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
2302 print '</form>';
2303 } else {
2304 print $object->trueWeight;
2305 print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : '';
2306 }
2307
2308 // Calculated
2309 if ($totalWeight > 0) {
2310 if (!empty($object->trueWeight)) {
2311 print ' ('.$langs->trans("SumOfProductWeights").': ';
2312 }
2313 print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, getDolGlobalInt('MAIN_WEIGHT_DEFAULT_ROUND', -1), getDolGlobalString('MAIN_WEIGHT_DEFAULT_UNIT', 'no'));
2314 if (!empty($object->trueWeight)) {
2315 print ')';
2316 }
2317 }
2318 print '</td></tr>';
2319
2320 // Width
2321 print '<tr><td>'.$form->editfieldkey("Width", 'trueWidth', (string) $object->trueWidth, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
2322 print $form->editfieldval("Width", 'trueWidth', $object->trueWidth, $object, $user->hasRight('reception', 'creer'));
2323 print ($object->trueWidth && $object->width_units != '') ? ' '.measuringUnitString(0, "size", $object->width_units) : '';
2324 print '</td></tr>';
2325
2326 // Height
2327 print '<tr><td>'.$form->editfieldkey("Height", 'trueHeight', (string) $object->trueHeight, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
2328 if ($action == 'edittrueHeight') {
2329 print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';
2330 print '<input name="action" value="settrueHeight" type="hidden">';
2331 print '<input name="id" value="'.$object->id.'" type="hidden">';
2332 print '<input type="hidden" name="token" value="'.newToken().'">';
2333 print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text">';
2334 print $formproduct->selectMeasuringUnits("size_units", "size", $object->size_units, 0, 2);
2335 print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';
2336 print ' <input class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';
2337 print '</form>';
2338 } else {
2339 print $object->trueHeight;
2340 print ($object->trueHeight && $object->height_units != '') ? ' '.measuringUnitString(0, "size", $object->height_units) : '';
2341 }
2342
2343 print '</td></tr>';
2344
2345 // Depth
2346 print '<tr><td>'.$form->editfieldkey("Depth", 'trueDepth', (string) $object->trueDepth, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
2347 print $form->editfieldval("Depth", 'trueDepth', $object->trueDepth, $object, $user->hasRight('reception', 'creer'));
2348 print ($object->trueDepth && $object->depth_units != '') ? ' '.measuringUnitString(0, "size", $object->depth_units) : '';
2349 print '</td></tr>';
2350
2351 // Default warehouse for the lines
2352 if (isModEnabled('stock')) {
2353 $langs->load('stocks');
2354 print '<tr><td><table class="nobordernopadding centpercent"><tr><td>';
2355 print $langs->trans('Warehouse');
2356 print '</td>';
2357 if ($action != 'editwarehouse' && $object->statut == Reception::STATUS_DRAFT && $user->hasRight('reception', 'creer')) {
2358 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editwarehouse&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetWarehouse'), 1).'</a></td>';
2359 }
2360 print '</tr></table></td><td colspan="3">';
2361 if ($action == 'editwarehouse' && $permissiontoadd) {
2362 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'warehouse_id', 1);
2363 } else {
2364 $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'none');
2365 }
2366 print '</td></tr>';
2367 }
2368
2369 // Volume
2370 print '<tr><td>';
2371 print $langs->trans("Volume");
2372 print '</td>';
2373 print '<td colspan="3">';
2374 $calculatedVolume = 0;
2375 $volumeUnit = 0;
2376 if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {
2377 $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);
2378 $volumeUnit = $object->size_units * 3;
2379 }
2380 // If reception volume not defined we use sum of products
2381 if ($calculatedVolume > 0) {
2382 if ($volumeUnit < 50) {
2383 print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, getDolGlobalInt('MAIN_VOLUME_DEFAULT_ROUND', -1), getDolGlobalString("MAIN_VOLUME_DEFAULT_UNIT", 'no'));
2384 } else {
2385 print $calculatedVolume.' '.measuringUnitString(0, "volume", $volumeUnit);
2386 }
2387 }
2388 if ($totalVolume > 0) {
2389 if ($calculatedVolume) {
2390 print ' ('.$langs->trans("SumOfProductVolumes").': ';
2391 }
2392 print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, getDolGlobalInt('MAIN_VOLUME_DEFAULT_ROUND', -1), getDolGlobalString('MAIN_VOLUME_DEFAULT_UNIT', 'no'));
2393 //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';
2394 if ($calculatedVolume) {
2395 print ')';
2396 }
2397 }
2398 print "</td>\n";
2399 print '</tr>';
2400
2401 // Other attributes
2402 $cols = 2;
2403
2404 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2405
2406 print '</table>';
2407
2408 print '</div>';
2409 print '<div class="fichehalfright">';
2410 print '<div class="underbanner clearboth"></div>';
2411
2412 print '<table class="border centpercent tableforfield">';
2413
2414 // Reception method
2415 print '<tr><td height="10">';
2416 print '<table class="nobordernopadding centpercent"><tr><td>';
2417 print $langs->trans('ReceptionMethod');
2418 print '</td>';
2419
2420 if ($action != 'editshipping_method_id' && $permissiontoadd) {
2421 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>';
2422 }
2423 print '</tr></table>';
2424 print '</td><td colspan="2">';
2425 if ($action == 'editshipping_method_id') {
2426 print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
2427 print '<input type="hidden" name="token" value="'.newToken().'">';
2428 print '<input type="hidden" name="action" value="setshipping_method_id">';
2429 $object->fetch_delivery_methods();
2430 print $form->selectarray("shipping_method_id", $object->meths, $object->shipping_method_id, 1, 0, 0, "", 1);
2431 if ($user->admin) {
2432 print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2433 }
2434 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
2435 print '</form>';
2436 } else {
2437 if ($object->shipping_method_id > 0) {
2438 // Get code using getLabelFromKey
2439 $code = $langs->getLabelFromKey($db, (string) $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');
2440 print $langs->trans("SendingMethod".strtoupper($code));
2441 }
2442 }
2443 print '</td>';
2444 print '</tr>';
2445
2446 // Tracking Number
2447 print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber", 'tracking_number', $object->tracking_number, $object, $user->hasRight('reception', 'creer')).'</td><td colspan="3">';
2448 print $form->editfieldval("TrackingNumber", 'tracking_number', $object->tracking_url, $object, $user->hasRight('reception', 'creer'), 'safehtmlstring', $object->tracking_number);
2449 print '</td></tr>';
2450
2451 // Incoterms
2452 if (isModEnabled('incoterm')) {
2453 print '<tr><td>';
2454 print '<table width="100%" class="nobordernopadding"><tr><td>';
2455 print $langs->trans('IncotermLabel');
2456 print '<td><td class="right">';
2457 if ($user->hasRight('reception', 'creer')) {
2458 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/reception/card.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
2459 } else {
2460 print '&nbsp;';
2461 }
2462 print '</td></tr></table>';
2463 print '</td>';
2464 print '<td colspan="3">';
2465 if ($action != 'editincoterm') {
2466 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
2467 } else {
2468 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
2469 }
2470 print '</td></tr>';
2471 }
2472
2473 print "</table>";
2474
2475 print '</div>';
2476 print '</div>';
2477
2478 print '<div class="clearboth"></div>';
2479
2480 /*
2481 * Lines of simple reception
2482 */
2483 if (!$origin_id && getDolGlobalString('RECEPTION_STANDALONE')) {
2484 if (!empty($object->table_element_line)) {
2485 // Show object lines
2486 $result = $object->getLinesArray();
2487
2488 print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOSTINT('lineid')).'" method="POST">
2489 <input type="hidden" name="token" value="' . newToken().'">
2490 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
2491 <input type="hidden" name="mode" value="">
2492 <input type="hidden" name="page_y" value="">
2493 <input type="hidden" name="id" value="' . $object->id.'">
2494 ';
2495
2496 if (!empty($conf->use_javascript_ajax) && $object->status == $object::STATUS_DRAFT) {
2497 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
2498 }
2499
2500 print '<div class="div-table-responsive-no-min">';
2501 if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
2502 print '<table id="tablelines" class="noborder noshadow" width="100%">';
2503 }
2504
2505 if (!empty($object->lines)) {
2506 $object->printObjectLines($action, $mysoc, null, GETPOSTINT('lineid'), 0, '/reception/tpl');
2507 }
2508
2509 // Form to add new line
2510 if ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines') {
2511 if ($action != 'editline') {
2512 // Add products/services form
2513
2514 $parameters = array();
2515 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2516 if ($reshook < 0) {
2517 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2518 }
2519 if (empty($reshook)) {
2520 $senderissupplier = 2; // Use the same add-line block as supplier orders; 2 = also list products without supplier price for this supplier
2521 $object->formAddObjectLine(0, $mysoc, $soc);
2522 }
2523 }
2524 }
2525
2526 if (!empty($object->lines) || ($object->status == Reception::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
2527 print '</table>';
2528 }
2529 print '</div>';
2530
2531 print "</form>\n";
2532 }
2533 } elseif (!empty($object->origin) && $object->origin_id > 0) {
2534 // Lines of products of origin
2535 if ($action == 'editline') {
2536 print '<form name="updateline" id="updateline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;lineid='.$line_id.'" method="POST">
2537 <input type="hidden" name="token" value="' . newToken().'">
2538 <input type="hidden" name="action" value="updateline">
2539 <input type="hidden" name="mode" value="">
2540 <input type="hidden" name="id" value="' . $object->id.'">';
2541 }
2542 print '<br><br>';
2543
2544 print '<div class="div-table-responsive-no-min">';
2545 print '<table id="tablelines" class="noborder centpercent">';
2546 print '<thead>';
2547 print '<tr class="liste_titre">';
2548 // #
2549 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
2550 print '<td width="5" class="center">&nbsp;</td>';
2551 }
2552 // Product/Service
2553 print '<td>'.$langs->trans("Products").'</td>';
2554 // Comment
2555 print '<td>'.$langs->trans("Comment").'</td>';
2556 // Qty
2557 print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';
2558 if ($origin && $origin_id > 0) {
2559 print '<td class="center">'.$langs->trans("QtyInOtherReceptions").'</td>';
2560 }
2561
2562 $editColspan = 3;
2563 if ($action == 'editline') {
2564 if (!isModEnabled('stock')) {
2565 $editColspan--;
2566 }
2567 if (empty($conf->productbatch->enabled)) {
2568 $editColspan--;
2569 }
2570 print '<td class="center" colspan="'.$editColspan.'">';
2571 if ($object->statut <= 1) {
2572 print $langs->trans("QtyToReceive").' - ';
2573 } else {
2574 print $langs->trans("QtyReceived").' - ';
2575 }
2576 if (isModEnabled('stock')) {
2577 print $langs->trans("WarehouseTarget").' - ';
2578 }
2579 if (isModEnabled('productbatch')) {
2580 print $langs->trans("Batch");
2581 }
2582 print '</td>';
2583
2584 $parameters = array();
2585 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2586 if ($reshook < 0) {
2587 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2588 } else {
2589 print $hookmanager->resPrint;
2590 }
2591 } else {
2592 $statusreceived = $object::STATUS_CLOSED;
2593 if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION")) {
2594 $statusreceived = $object::STATUS_VALIDATED;
2595 }
2596 if (getDolGlobalInt("STOCK_CALCULATE_ON_RECEPTION_CLOSE")) {
2597 $statusreceived = $object::STATUS_CLOSED;
2598 }
2599 if ($object->statut < $statusreceived) {
2600 print '<td class="center">'.$langs->trans("QtyToReceive").'</td>';
2601 } else {
2602 print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
2603 }
2604 if (isModEnabled('stock')) {
2605 print '<td class="left">'.$langs->trans("WarehouseTarget").'</td>';
2606 }
2607
2608 if (isModEnabled('productbatch')) {
2609 print '<td class="left">'.$langs->trans("Batch").'</td>';
2610 }
2611
2612 $parameters = array();
2613 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2614 if ($reshook < 0) {
2615 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2616 } else {
2617 print $hookmanager->resPrint;
2618 }
2619 }
2620 print '<td class="center">'.$langs->trans("CalculatedWeight").'</td>';
2621 print '<td class="center">'.$langs->trans("CalculatedVolume").'</td>';
2622 //print '<td class="center">'.$langs->trans("Size").'</td>';
2623 if ($object->statut == 0) {
2624 print '<td class="linecoledit"></td>';
2625 print '<td class="linecoldelete" width="10"></td>';
2626 }
2627 print "</tr>\n";
2628 print '</thead>';
2629
2630 $var = false;
2631
2632 $outputlangs = $langs;
2633 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
2634 $object->fetch_thirdparty();
2635 $newlang = '';
2636 if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) {
2637 $newlang = GETPOST('lang_id', 'aZ09');
2638 }
2639 if (empty($newlang)) {
2640 $newlang = $object->thirdparty->default_lang;
2641 }
2642 if (!empty($newlang)) {
2643 $outputlangs = new Translate("", $conf);
2644 $outputlangs->setDefaultLang($newlang);
2645 }
2646 }
2647
2648 // Get list of products already sent for same source object into $alreadysent
2649 $alreadysent = array();
2650
2651 $origin = (string) $origin;
2652
2653 // The origin may arrive as 'order_supplier' from some callers, while the table name below is
2654 // built from 'supplier_order'. Normalise it or the query targets a table that does not exist.
2655 if (empty($origin) || $origin == 'order_supplier') {
2656 $origin = 'supplier_order';
2657 }
2658
2659 // List of allowed value of $origin
2660 if (!in_array($origin, array('supplier_proposal', 'supplier_order', 'commande_fournisseur', 'facture_fourn', 'propal', 'commande', 'facture'))) {
2661 dol_print_error($db, 'Bad value for parameter origin in reception/card.php');
2662 exit;
2663 }
2664
2665 if ($origin_id > 0) {
2666 $tablenametouse = (($origin == 'supplier_order') ? 'commande_fournisseur' : (($origin == 'facture_fourn') ? 'facture_fourn_' : $origin));
2667
2668 $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";
2669 $sql .= ", ed.rowid as receptionline_id, ed.qty, ed.fk_reception as reception_id, ed.fk_entrepot";
2670 $sql .= ", e.rowid as reception_id, e.ref as reception_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_reception";
2671 $sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch';
2672 $sql .= ', p.description as product_desc';
2673 $sql .= " FROM ".MAIN_DB_PREFIX."receptiondet_batch as ed";
2674 $sql .= ", ".MAIN_DB_PREFIX."reception as e";
2675 $sql .= ", ".MAIN_DB_PREFIX.$db->sanitize($tablenametouse)."det as obj";
2676 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";
2677 $sql .= " WHERE e.entity IN (".getEntity('reception').")";
2678 $sql .= " AND obj.fk_commande = ".((int) $origin_id);
2679 $sql .= " AND obj.rowid = ed.fk_elementdet";
2680 $sql .= " AND ed.fk_reception = e.rowid";
2681 $sql .= " AND ed.fk_reception !=".((int) $object->id);
2682 $sql .= " ORDER BY obj.fk_product";
2683
2684 dol_syslog("get list of reception lines", LOG_DEBUG);
2685 $resql = $db->query($sql);
2686 if ($resql) {
2687 $num = $db->num_rows($resql);
2688 $i = 0;
2689
2690 while ($i < $num) {
2691 $obj = $db->fetch_object($resql);
2692 if ($obj) {
2693 // $obj->rowid is rowid in $origin."det" table
2694 $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);
2695 }
2696 $i++;
2697 }
2698 }
2699 //var_dump($alreadysent);
2700 }
2701
2702 $arrayofpurchaselinealreadyoutput = array();
2703
2704 // Loop on each product to send/sent. Warning: $lines must be sorted by ->fk_commandefourndet (it is a regroupment key on output)
2705 print '<tbody>';
2706 for ($i = 0; $i < $num_prod; $i++) {
2707 print '<!-- origin line id = '.(!empty($lines[$i]->origin_line_id) ? $lines[$i]->origin_line_id : 0).' -->'; // id of order line
2708 print '<tr class="oddeven" id="row-'.$lines[$i]->id.'" data-id="'.$lines[$i]->id.'" data-element="'.$lines[$i]->element.'">';
2709
2710 // #
2711 if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
2712 print '<td class="center">'.($i + 1).'</td>';
2713 }
2714
2715 // Predefined product or service
2716 if ($lines[$i]->fk_product > 0) {
2717 // Define output language
2718 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
2719 $prod = new Product($db);
2720 $prod->fetch($lines[$i]->fk_product);
2721 $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product->label;
2722 } else {
2723 $label = (!empty($lines[$i]->product->label) ? $lines[$i]->product->label : '');
2724 }
2725
2726 print '<td class="linecoldescription">';
2727 if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
2728 $text = $lines[$i]->product->getNomUrl(1);
2729 $text .= ' - '.$label;
2730 $description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($lines[$i]->description));
2731 print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i);
2732 print_date_range(!empty($lines[$i]->date_start) ? $lines[$i]->date_start : 0, !empty($lines[$i]->date_end) ? $lines[$i]->date_end : 0);
2733 if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
2734 print (!empty($lines[$i]->description) && $lines[$i]->description != $label) ? '<br>'.dol_htmlentitiesbr($lines[$i]->description) : '';
2735 }
2736 }
2737 print "</td>\n";
2738 } else {
2739 print '<td class="linecoldescription">';
2740 if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
2741 if ($lines[$i]->product_type == Product::TYPE_SERVICE) {
2742 $text = img_object($langs->trans('Service'), 'service');
2743 } else {
2744 $text = img_object($langs->trans('Product'), 'product');
2745 }
2746
2747 if (!empty($lines[$i]->label)) {
2748 $text .= ' <strong>'.$lines[$i]->label.'</strong>';
2749 print $form->textwithtooltip($text, $lines[$i]->description, 3, 0, '', (string) $i);
2750 } else {
2751 print $text.' '.nl2br($lines[$i]->description);
2752 }
2753
2754 print_date_range($lines[$i]->date_start, $lines[$i]->date_end);
2755 }
2756 print "</td>\n";
2757 }
2758
2759 if ($action == 'editline' && $lines[$i]->id == $line_id) {
2760 print '<td><input name="comment'.$line_id.'" id="comment'.$line_id.'" value="'.dol_escape_htmltag($lines[$i]->comment).'"></td>';
2761 } else {
2762 print '<td style="white-space: pre-wrap; max-width: 200px;">'.dol_escape_htmltag($lines[$i]->comment).'</td>';
2763 }
2764
2765
2766 // Qty ordered
2767 print '<td class="center linecolqty">';
2768 if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
2769 print $lines[$i]->qty_asked;
2770 }
2771 print '</td>';
2772
2773 // Qty in other receptions (with reception and warehouse used)
2774 // Note: here $origin is always a non-empty string (normalized above), so only $origin_id needs to be tested
2775 if ($origin_id > 0) {
2776 print '<td class="center nowrap linecolqtyinotherreceptions">';
2777 $htmltooltip = '';
2778 $qtyalreadyreceived = 0;
2779 if (!array_key_exists($lines[$i]->fk_commandefourndet, $arrayofpurchaselinealreadyoutput)) {
2780 foreach ($alreadysent as $key => $val) {
2781 if ($lines[$i]->fk_commandefourndet == $key) {
2782 $j = 0;
2783 foreach ($val as $receptionline_id => $receptionline_var) {
2784 if ($receptionline_var['reception_id'] == $lines[$i]->fk_reception) {
2785 continue; // We want to show only "other receptions"
2786 }
2787
2788 $j++;
2789 if ($j > 1) {
2790 $htmltooltip .= '<br>';
2791 }
2792 if (empty($conf->cache['reception'][$receptionline_var['reception_id']])) {
2793 $reception_static = new Reception($db);
2794 $reception_static->fetch($receptionline_var['reception_id']);
2795 $conf->cache['reception'][$receptionline_var['reception_id']] = $reception_static;
2796 } else {
2797 $reception_static = $conf->cache['reception'][$receptionline_var['reception_id']];
2798 }
2799 $htmltooltip .= $reception_static->getNomUrl(1, 'nolink', 0, 0, 1);
2800 $htmltooltip .= ' - '.$receptionline_var['qty'];
2801
2802 $htmltext = $langs->trans("DateValidation").' : '.(empty($receptionline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($receptionline_var['date_valid'], 'dayhour'));
2803 if (isModEnabled('stock') && $receptionline_var['warehouse'] > 0) {
2804 if (empty($conf->cache['warehouse'][$receptionline_var['warehouse']])) {
2805 $warehousestatic = new Entrepot($db);
2806 $warehousestatic->fetch($receptionline_var['warehouse']);
2807 $conf->cache['warehouse'][$receptionline_var['warehouse']] = $warehousestatic;
2808 } else {
2809 $warehousestatic = $conf->cache['warehouse'][$receptionline_var['warehouse']];
2810 }
2811 $htmltext .= '<br>'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1, '', 0, 1);
2812 }
2813 $htmltooltip .= ' '.$form->textwithpicto('', $htmltext, 1);
2814
2815 $qtyalreadyreceived += $receptionline_var['qty'];
2816 }
2817 if ($j) {
2818 $htmltooltip = $langs->trans("QtyInOtherReceptions").'...<br><br>'.$htmltooltip.'<br><input type="submit" name="dummyhiddenbuttontogetfocus" style="display:none" autofocus>';
2819 }
2820 }
2821 }
2822 }
2823 print $form->textwithpicto((string) $qtyalreadyreceived, $htmltooltip, 1, 'info', '', 0, 3, 'tooltip'.$lines[$i]->id);
2824 print '</td>';
2825 }
2826
2827 if ($action == 'editline' && $lines[$i]->id == $line_id) {
2828 // edit mode
2829 print '<td colspan="'.$editColspan.'" class="center"><table class="nobordernopadding">';
2830 if (isModEnabled('stock')) {
2831 if ($lines[$i]->fk_product > 0) {
2832 print '<!-- case edit 1 -->';
2833 print '<tr>';
2834 // Qty to receive or received
2835 print '<td><input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'"></td>';
2836 // Warehouse source
2837 print '<td>'.$formproduct->selectWarehouses($lines[$i]->fk_entrepot, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'</td>';
2838 // Batch number management
2839 if ($conf->productbatch->enabled && !empty($lines[$i]->product->status_batch)) {
2840 print '<td class="nowraponall left"><input name="batch'.$line_id.'" id="batch'.$line_id.'" type="text" value="'.$lines[$i]->batch.'"><br>';
2841 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
2842 print $langs->trans('SellByDate').' : ';
2843 print $form->selectDate($lines[$i]->sellby, 'dlc'.$line_id, 0, 0, 1, "").'<br>';
2844 }
2845 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
2846 print $langs->trans('EatByDate').' : ';
2847 print $form->selectDate($lines[$i]->eatby, 'dluo'.$line_id, 0, 0, 1, "");
2848 }
2849 print '</td>';
2850 }
2851 print '</tr>';
2852 } else {
2853 print '<!-- case edit 2 -->';
2854 print '<tr>';
2855 // Qty to receive or received
2856 print '<td><input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty.'"></td>';
2857 // Warehouse source
2858 print '<td></td>';
2859 // Batch number management
2860 print '<td></td>';
2861 print '</tr>';
2862 }
2863 }
2864 print '</table></td>';
2865
2866 $parameters = array();
2867 $parameters['line'] = $lines[$i];
2868 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2869 if ($reshook < 0) {
2870 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2871 } else {
2872 print $hookmanager->resPrint;
2873 }
2874 } else {
2875 // Qty to receive or received
2876 print '<td class="center linecolqtytoreceive">'.$lines[$i]->qty.'</td>';
2877
2878 // Warehouse source
2879 if (isModEnabled('stock')) {
2880 if ($lines[$i]->fk_entrepot > 0) {
2881 $entrepot = new Entrepot($db);
2882 $entrepot->fetch($lines[$i]->fk_entrepot);
2883
2884 print '<td class="left tdoverflowmax150" title="'.dol_escape_htmltag($entrepot->label).'">';
2885 print $entrepot->getNomUrl(1);
2886 print '</td>';
2887 } else {
2888 print '<td></td>';
2889 }
2890 }
2891
2892 // Batch number management
2893 if (isModEnabled('productbatch')) {
2894 if (isset($lines[$i]->batch)) {
2895 print '<!-- Detail of lot -->';
2896 print '<td class="linecolbatch nowrap">';
2897 $detail = $langs->trans("NA");
2898 if ($lines[$i]->product->status_batch > 0 && $lines[$i]->fk_product > 0) {
2899 require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
2900 $productlot = new Productlot($db);
2901 $reslot = $productlot->fetch(0, $lines[$i]->fk_product, $lines[$i]->batch);
2902 if ($reslot > 0) {
2903 $detail = $productlot->getNomUrl(1);
2904 } else {
2905 // lot is not created and info is only in reception lines
2906 $batchinfo = $langs->trans("Batch").': '.$lines[$i]->batch;
2907 if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
2908 $batchinfo .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($lines[$i]->sellby, "day");
2909 }
2910 if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
2911 $batchinfo .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($lines[$i]->eatby, "day");
2912 }
2913 $detail = $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $batchinfo);
2914 }
2915 }
2916 print $detail . '</td>';
2917 } else {
2918 print '<td></td>';
2919 }
2920 }
2921
2922 $parameters = array();
2923 $parameters['line'] = $lines[$i];
2924 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2925 if ($reshook < 0) {
2926 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2927 } else {
2928 print $hookmanager->resPrint;
2929 }
2930 }
2931
2932 // Weight
2933 print '<td class="center linecolweight">';
2934 if (!empty($lines[$i]->fk_product_type) && $lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
2935 print $lines[$i]->product->weight * $lines[$i]->qty.' '.measuringUnitString(0, "weight", $lines[$i]->product->weight_units);
2936 } else {
2937 print '&nbsp;';
2938 }
2939 print '</td>';
2940
2941 // Volume
2942 print '<td class="center linecolvolume">';
2943 if (!empty($lines[$i]->fk_product_type) && $lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {
2944 print $lines[$i]->product->volume * $lines[$i]->qty.' '.measuringUnitString(0, "volume", $lines[$i]->product->volume_units);
2945 } else {
2946 print '&nbsp;';
2947 }
2948 print '</td>';
2949
2950
2951 if ($action == 'editline' && $lines[$i]->id == $line_id) {
2952 print '<td class="center valignmiddle" colspan="2">';
2953 print '<input type="submit" class="button small button-save" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';
2954 print '<input type="submit" class="button small button-cancel" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"><br>';
2955 print '</td>';
2956 } elseif ($object->statut == Reception::STATUS_DRAFT) {
2957 // edit-delete buttons
2958 print '<td class="linecoledit center">';
2959 print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&lineid='.$lines[$i]->id.'">'.img_edit().'</a>';
2960 print '</td>';
2961 print '<td class="linecoldelete" width="10">';
2962 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteline&token='.newToken().'&lineid='.$lines[$i]->id.'">'.img_delete().'</a>';
2963 print '</td>';
2964
2965 // Display lines extrafields
2966 if (isset($rowExtrafieldsStart, $rowExtrafieldsView, $rowEnd)) { // @phan-suppress-current-line PhanPluginUndeclaredVariableIsset
2967 print $rowExtrafieldsStart;
2968 print $rowExtrafieldsView;
2969 print $rowEnd;
2970 }
2971 }
2972 print "</tr>";
2973
2974 $arrayofpurchaselinealreadyoutput[$lines[$i]->fk_commandefourndet] = $lines[$i]->fk_commandefourndet;
2975
2976 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2977 if ($reshook < 0) {
2978 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2979 } else {
2980 print $hookmanager->resPrint;
2981 }
2982
2983 // Display lines extrafields
2984 $extralabelslines = $extrafields->attributes[$lines[$i]->table_element];
2985 if (!empty($extralabelslines) && is_array($extralabelslines) && count($extralabelslines) > 0) {
2986 $colspan = 8;
2987 if (isModEnabled('stock')) {
2988 $colspan++;
2989 }
2990 if (isModEnabled('productbatch')) {
2991 $colspan++;
2992 }
2993
2994 $line = new CommandeFournisseurDispatch($db);
2995 $line->id = $lines[$i]->id;
2996 $line->fetch_optionals();
2997
2998 if ($action == 'editline' && $lines[$i]->id == $line_id) {
2999 print $line->showOptionals($extrafields, 'edit', array('colspan' => $colspan), '');
3000 } else {
3001 print $line->showOptionals($extrafields, 'view', array('colspan' => $colspan), '');
3002 }
3003 }
3004 }
3005 print '</tbody>';
3006
3007 // TODO Show also lines ordered but not delivered
3008
3009 print "</table>\n";
3010 print '</div>';
3011
3012
3013 print dol_get_fiche_end();
3014
3015
3016 $object->fetchObjectLinked($object->id, $object->element);
3017 }
3018
3019 /*
3020 * Button actions
3021 */
3022
3023 if (($user->socid == 0) && ($action != 'presend') && ($action != 'editline')) {
3024 print '<div class="tabsAction">';
3025
3026 $parameters = array();
3027 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3028 if (empty($reshook)) {
3029 if ($object->statut == Reception::STATUS_DRAFT && $num_prod > 0) {
3030 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'creer'))
3031 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('reception', 'reception_advance', 'validate'))) {
3032 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken().'">'.$langs->trans("Validate").'</a>';
3033 } else {
3034 print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';
3035 }
3036 }
3037 // Back to draft
3038 if ($object->statut == Reception::STATUS_VALIDATED && $user->hasRight('reception', 'creer')) {
3039 print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modif&token='.newToken().'">'.$langs->trans('SetToDraft').'</a></div>';
3040 }
3041
3042 // TODO add alternative status
3043 // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)
3044 if ($object->statut == Reception::STATUS_CLOSED && $user->hasRight('reception', 'creer')) {
3045 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a>';
3046 }
3047
3048 // Send mail
3049 if (empty($user->socid)) {
3050 if ($object->statut > 0) {
3051 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('reception', 'reception_advance', 'send')) {
3052 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendByMail').'</a>';
3053 } else {
3054 print '<a class="butActionRefused" href="#">'.$langs->trans('SendByMail').'</a>';
3055 }
3056 }
3057 }
3058
3059 // Create bill
3060 if (isModEnabled("supplier_invoice") && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED) && !getDolGlobalString('RECEPTION_STANDALONE')) {
3061 if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight('supplier_invoice', 'creer')) {
3062 if (getDolGlobalString('WORKFLOW_BILL_ON_RECEPTION') !== '0') {
3063 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>';
3064 }
3065 }
3066 }
3067
3068
3069 // Set Billed and Closed
3070 if ($object->statut == Reception::STATUS_VALIDATED) {
3071 if ($user->hasRight('reception', 'creer') && $object->statut > 0) {
3072 if (!$object->billed && getDolGlobalString('WORKFLOW_BILL_ON_RECEPTION') !== '0') {
3073 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifybilled&token='.newToken().'">'.$langs->trans('ClassifyBilled').'</a>';
3074 }
3075 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifyclosed&token='.newToken().'">'.$langs->trans("Close").'</a>';
3076 }
3077 }
3078
3079 if ($user->hasRight('reception', 'supprimer')) {
3080 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', true, array('attr' => array('class' => 'reposition')))."\n";
3081 }
3082 }
3083
3084 print '</div>';
3085 }
3086
3087
3088 /*
3089 * Documents generated
3090 */
3091
3092 if ($action != 'presend' && $action != 'editline') {
3093 print '<div class="fichecenter"><div class="fichehalfleft">';
3094
3095 $objectref = dol_sanitizeFileName((string) $object->ref);
3096 $filedir = $conf->reception->dir_output."/".$objectref;
3097
3098 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
3099
3100 $genallowed = $user->hasRight('reception', 'lire');
3101 $delallowed = $user->hasRight('reception', 'creer');
3102
3103 print $formfile->showdocuments('reception', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
3104
3105 // Show links to link elements
3106 //$tmparray = $form->showLinkToObjectBlock($object, null, array('order'), 1);
3107 $somethingshown = $form->showLinkedObjectBlock($object, '');
3108
3109 print '</div><div class="fichehalfright">';
3110
3111 print '</div></div>';
3112 }
3113
3114 // Presend form
3115 $modelmail = 'reception_send';
3116 $defaulttopic = 'SendReceptionRef';
3117 $diroutput = $conf->reception->dir_output;
3118 $trackid = 'rec'.$object->id;
3119
3120 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
3121}
3122
3123llxFooter();
3124
3125$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage table ReceptionLineBatch.
Class to manage predefined suppliers products.
Class to manage 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 ProductCombination Used to represent the relation between a product and one of its variants.
Class to manage predefined suppliers products.
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 table commandefournisseurdispatch.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
global $mysoc
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...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
print_date_range($date_start, $date_end, $format='', $outputlangs=null)
Format output for start and end date.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no', $use_short_label=0)
Output a dimension with best unit.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
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, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.