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