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