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