--- /tmp/dsg/dolibarr/htdocs/expedition/github_19.0.3_card.php
+++ /tmp/dsg/dolibarr/htdocs/expedition/client_card.php
@@ -14 +14 @@
- * Copyright (C) 2018-2022  Frédéric France         <frederic.france@netlogic.fr>

+ * Copyright (C) 2018       Frédéric France         <frederic.france@netlogic.fr>

@@ -16 +15,0 @@
- * Copyright (C) 2022       Josep Lluís Amador      <joseplluis@lliuretic.cat>

@@ -38 +36,0 @@
-// Load Dolibarr environment

@@ -51,2 +49,6 @@
-if (isModEnabled("product") || isModEnabled("service")) {

-	require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';

+if (!empty($conf->product->enabled) || !empty($conf->service->enabled))  require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';

+if (!empty($conf->propal->enabled))   require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';

+if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';

+if (!empty($conf->projet->enabled)) {

+    require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';

+    require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';

@@ -54,2 +56,23 @@
-if (isModEnabled("propal")) {

-	require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';

+

+// Load translation files required by the page

+$langs->loadLangs(array("sendings", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal'));

+

+if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');

+if (!empty($conf->productbatch->enabled)) $langs->load('productbatch');

+

+$origin = GETPOST('origin', 'alpha') ?GETPOST('origin', 'alpha') : 'expedition'; // Example: commande, propal

+$origin_id = GETPOST('id', 'int') ?GETPOST('id', 'int') : '';

+$id = $origin_id;

+if (empty($origin_id)) $origin_id  = GETPOST('origin_id', 'int'); // Id of order or propal

+if (empty($origin_id)) $origin_id  = GETPOST('object_id', 'int'); // Id of order or propal

+$ref = GETPOST('ref', 'alpha');

+$line_id = GETPOST('lineid', 'int') ?GETPOST('lineid', 'int') : '';

+

+// Security check

+$socid = '';

+if ($user->socid) $socid = $user->socid;

+

+if ($origin == 'expedition') $result = restrictedArea($user, $origin, $id);

+else {

+	$result = restrictedArea($user, 'expedition');

+	if (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) accessforbidden();

@@ -57,30 +79,0 @@
-if (isModEnabled('productbatch')) {

-	require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';

-}

-if (isModEnabled('project')) {

-	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';

-	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';

-}

-

-// Load translation files required by the page

-$langs->loadLangs(array("sendings", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal', 'productbatch'));

-

-if (isModEnabled('incoterm')) {

-	$langs->load('incoterm');

-}

-if (isModEnabled('productbatch')) {

-	$langs->load('productbatch');

-}

-

-$origin = GETPOST('origin', 'alpha') ? GETPOST('origin', 'alpha') : 'expedition'; // Example: commande, propal

-$origin_id = GETPOST('id', 'int') ? GETPOST('id', 'int') : '';

-$id = $origin_id;

-if (empty($origin_id)) {

-	$origin_id  = GETPOST('origin_id', 'int'); // Id of order or propal

-}

-if (empty($origin_id)) {

-	$origin_id  = GETPOST('object_id', 'int'); // Id of order or propal

-}

-$ref = GETPOST('ref', 'alpha');

-$line_id = GETPOST('lineid', 'int') ? GETPOST('lineid', 'int') : '';

-$facid = GETPOST('facid', 'int');

@@ -93,3 +86,3 @@
-$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));

-$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));

-$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));

+$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));

+$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));

+$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));

@@ -112,17 +105,2 @@
-$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'));

-

-if ($id > 0 || !empty($ref)) {

-	$object->fetch($id, $ref);

-	$object->fetch_thirdparty();

-}

-

-// Security check

-$socid = '';

-if ($user->socid) {

-	$socid = $user->socid;

-}

-

-$result = restrictedArea($user, 'expedition', $object->id, '');

-

-$permissiondellink = $user->rights->expedition->delivery->creer; // Used by the include of actions_dellink.inc.php

-$permissiontoadd = $user->rights->expedition->creer;

+$permissiondellink = $user->rights->expedition->livraison->creer; // Used by the include of actions_dellink.inc.php

+//var_dump($object->lines[0]->detail_batch);

@@ -137,16 +115,9 @@
-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

-

-if (empty($reshook)) {

-	if ($cancel) {

-		if ($origin && $origin_id > 0) {

-			if ($origin == 'commande') {

-				header("Location: ".DOL_URL_ROOT.'/expedition/shipment.php?id='.((int) $origin_id));

-				exit;

-			}

-		} else {

-			$action = '';

-			$object->fetch($id); // show shipment also after canceling modification

-		}

-	}

+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

+

+if (empty($reshook))

+{

+    if ($cancel)

+	{

+		$action = '';

+		$object->fetch($id); // show shipment also after canceling modification

+    }

@@ -157,0 +129 @@
+	$permissiontoadd = $user->rights->expedition->creer;

@@ -160,7 +132,5 @@
-	// Back to draft

-	if ($action == 'setdraft' && $user->hasRight('expedition', 'creer')) {

-		$object->fetch($id);

-		$result = $object->setDraft($user, 0);

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

+	// Reopen

+	if ($action == 'reopen' && $user->rights->expedition->creer)

+	{

+	    $object->fetch($id);

+	    $result = $object->reOpen();

@@ -168,7 +138,5 @@
-	// Reopen

-	if ($action == 'reopen' && $user->hasRight('expedition', 'creer')) {

-		$object->fetch($id);

-		$result = $object->reOpen();

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

+

+	// Set incoterm

+	if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))

+	{

+	    $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));

@@ -177,3 +145,15 @@
-	// Set incoterm

-	if ($action == 'set_incoterms' && isModEnabled('incoterm')) {

-		$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));

+	if ($action == 'setref_customer')

+	{

+        $result = $object->fetch($id);

+        if ($result < 0) {

+            setEventMessages($object->error, $object->errors, 'errors');

+        }

+

+        $result = $object->setValueFrom('ref_customer', GETPOST('ref_customer', 'alpha'), '', null, 'text', '', $user, 'SHIPMENT_MODIFY');

+        if ($result < 0) {

+            setEventMessages($object->error, $object->errors, 'errors');

+            $action = 'editref_customer';

+        } else {

+            header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

+            exit;

+        }

@@ -182,18 +162,3 @@
-	if ($action == 'setref_customer') {

-		$result = $object->fetch($id);

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-

-		$result = $object->setValueFrom('ref_customer', GETPOST('ref_customer', 'alpha'), '', null, 'text', '', $user, 'SHIPMENT_MODIFY');

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-			$action = 'editref_customer';

-		} else {

-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

-			exit;

-		}

-	}

-

-	if ($action == 'update_extras') {

-		$object->oldcopy = dol_clone($object, 2);

+	if ($action == 'update_extras')

+	{

+		$object->oldcopy = dol_clone($object);

@@ -202,9 +167,9 @@
-		$ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));

-		if ($ret < 0) {

-			$error++;

-		}

-

-		if (!$error) {

-			// Actions on extra fields

-			$result = $object->insertExtraFields('SHIPMENT_MODIFY');

-			if ($result < 0) {

+	    $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none'));

+	    if ($ret < 0) $error++;

+

+	    if (!$error)

+	    {

+	        // Actions on extra fields

+            $result = $object->insertExtraFields('SHIPMENT_MODIFY');

+			if ($result < 0)

+			{

@@ -214,5 +179,4 @@
-		}

-

-		if ($error) {

-			$action = 'edit_extras';

-		}

+	    }

+

+	    if ($error)

+	        $action = 'edit_extras';

@@ -222,33 +186,35 @@
-	if ($action == 'add' && $user->hasRight('expedition', 'creer')) {

-		$error = 0;

-

-		$db->begin();

-

-		$object->note = GETPOST('note', 'restricthtml');

-		$object->note_private = GETPOST('note', 'restricthtml');

-		$object->origin = $origin;

-		$object->origin_id = $origin_id;

-		$object->fk_project = GETPOST('projectid', 'int');

-		$object->weight = GETPOST('weight', 'int') == '' ? "NULL" : GETPOST('weight', 'int');

-		$object->sizeH = GETPOST('sizeH', 'int') == '' ? "NULL" : GETPOST('sizeH', 'int');

-		$object->sizeW = GETPOST('sizeW', 'int') == '' ? "NULL" : GETPOST('sizeW', 'int');

-		$object->sizeS = GETPOST('sizeS', 'int') == '' ? "NULL" : GETPOST('sizeS', 'int');

-		$object->size_units = GETPOST('size_units', 'int');

-		$object->weight_units = GETPOST('weight_units', 'int');

-

-		$product = new Product($db);

-

-		// We will loop on each line of the original document to complete the shipping object with various info and quantity to deliver

-		$classname = ucfirst($object->origin);

-		$objectsrc = new $classname($db);

-		$objectsrc->fetch($object->origin_id);

-

-		$object->socid = $objectsrc->socid;

-		$object->ref_customer = GETPOST('ref_customer', 'alpha');

-		$object->model_pdf = GETPOST('model');

-		$object->date_delivery = $date_delivery; // Date delivery planed

-		$object->fk_delivery_address = $objectsrc->fk_delivery_address;

-		$object->shipping_method_id = GETPOST('shipping_method_id', 'int');

-		$object->tracking_number = GETPOST('tracking_number', 'alpha');

-		$object->note_private = GETPOST('note_private', 'restricthtml');

-		$object->note_public = GETPOST('note_public', 'restricthtml');

+	if ($action == 'add' && $user->rights->expedition->creer)

+	{

+	    $error = 0;

+	    $predef = '';

+

+	    $db->begin();

+

+	    $object->note = GETPOST('note', 'alpha');

+	    $object->origin				= $origin;

+        $object->origin_id = $origin_id;

+        $object->fk_project = GETPOST('projectid', 'int');

+	    $object->weight				= GETPOST('weight', 'int') == '' ? "NULL" : GETPOST('weight', 'int');

+	    $object->sizeH				= GETPOST('sizeH', 'int') == '' ? "NULL" : GETPOST('sizeH', 'int');

+	    $object->sizeW				= GETPOST('sizeW', 'int') == '' ? "NULL" : GETPOST('sizeW', 'int');

+	    $object->sizeS				= GETPOST('sizeS', 'int') == '' ? "NULL" : GETPOST('sizeS', 'int');

+	    $object->size_units = GETPOST('size_units', 'int');

+	    $object->weight_units = GETPOST('weight_units', 'int');

+

+	    $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'));

+

+	    // We will loop on each line of the original document to complete the shipping object with various info and quantity to deliver

+	    $classname = ucfirst($object->origin);

+	    $objectsrc = new $classname($db);

+	    $objectsrc->fetch($object->origin_id);

+

+	    $object->socid = $objectsrc->socid;

+	    $object->ref_customer = GETPOST('ref_customer', 'alpha');

+	    $object->model_pdf = GETPOST('model');

+	    $object->date_delivery = $date_delivery; // Date delivery planed

+	    $object->fk_delivery_address	= $objectsrc->fk_delivery_address;

+	    $object->shipping_method_id		= GETPOST('shipping_method_id', 'int');

+	    $object->tracking_number = GETPOST('tracking_number', 'alpha');

+	    $object->ref_int = GETPOST('ref_int', 'alpha');

+	    $object->note_private = GETPOST('note_private', 'none');

+	    $object->note_public = GETPOST('note_public', 'none');

@@ -258 +224 @@
-		$batch_line = array();

+	    $batch_line = array();

@@ -262,4 +228,5 @@
-		$num = count($objectsrc->lines);

-		$totalqty = 0;

-

-		for ($i = 0; $i < $num; $i++) {

+	    $num = count($objectsrc->lines);

+	    $totalqty = 0;

+

+	    for ($i = 0; $i < $num; $i++)

+	    {

@@ -274,70 +241,61 @@
-			$qty = "qtyl".$i;

-

-			$is_batch_or_serial=0;

-			if (!empty($objectsrc->lines[$i]->fk_product)) {

-				$resultFetch = $product->fetch($objectsrc->lines[$i]->fk_product, '', '', '', 1, 1, 1);

-				if ($resultFetch < 0) {

-					setEventMessages($product->error, $product->errors, 'errors');

-				}

-				$is_batch_or_serial = $product->status_batch;

-			}

-

-			// If product need a batch or serial number

-			if (isModEnabled('productbatch') && $objectsrc->lines[$i]->product_tobatch) {

-				if (GETPOSTISSET($batch)) {

-					//shipment line with batch-enable product

-					$qty .= '_'.$j;

-					while (GETPOSTISSET($batch)) {

-						// save line of detail into sub_qty

-						$sub_qty[$j]['q'] = price2num(GETPOST($qty, 'alpha'), 'MS'); // the qty we want to move for this stock record

-						$sub_qty[$j]['id_batch'] = GETPOST($batch, 'int'); // the id into llx_product_batch of stock record to move

-						$subtotalqty += $sub_qty[$j]['q'];

-

-						//var_dump($qty);

-						//var_dump($batch);

-						//var_dump($sub_qty[$j]['q']);

-						//var_dump($sub_qty[$j]['id_batch']);

-

-						//var_dump($qty);var_dump($batch);var_dump($sub_qty[$j]['q']);var_dump($sub_qty[$j]['id_batch']);

-						if ($is_batch_or_serial==2 && $sub_qty[$j]['q']>1) {

-							setEventMessages($langs->trans("TooManyQtyForSerialNumber", $product->ref, ''), null, 'errors');

-							$totalqty=0;

-							break 2;

-						}

-						$j++;

-						$batch = "batchl".$i."_".$j;

-						$qty = "qtyl".$i.'_'.$j;

-					}

-

-					$batch_line[$i]['detail'] = $sub_qty; // array of details

-					$batch_line[$i]['qty'] = $subtotalqty;

-					$batch_line[$i]['ix_l'] = GETPOST($idl, 'int');

-

-					$totalqty += $subtotalqty;

-				} else {

-					// No detail were provided for lots, so if a qty was provided, we can throw an error.

-					if (GETPOST($qty)) {

-						// We try to set an amount

-						// Case we dont use the list of available qty for each warehouse/lot

-						// GUI does not allow this yet

-						setEventMessages($langs->trans("StockIsRequiredToChooseWhichLotToUse").' ('.$langs->trans("Line").' '.GETPOST($idl, 'int').')', null, 'errors');

-						$error++;

-					}

-				}

-			} elseif (GETPOSTISSET($stockLocation)) {

-				//shipment line from multiple stock locations

-				$qty .= '_'.$j;

-				while (GETPOSTISSET($stockLocation)) {

-					// save sub line of warehouse

-					$stockLine[$i][$j]['qty'] = price2num(GETPOST($qty, 'alpha'), 'MS');

-					$stockLine[$i][$j]['warehouse_id'] = GETPOST($stockLocation, 'int');

-					$stockLine[$i][$j]['ix_l'] = GETPOST($idl, 'int');

-

-					$totalqty += price2num(GETPOST($qty, 'alpha'), 'MS');

-					$subtotalqty += price2num(GETPOST($qty, 'alpha'), 'MS');

-

-					$j++;

-					$stockLocation = "ent1".$i."_".$j;

-					$qty = "qtyl".$i.'_'.$j;

-				}

-			} else {

+	    	$qty = "qtyl".$i;

+

+			if ($objectsrc->lines[$i]->product_tobatch)      // If product need a batch number

+			{

+			    if (GETPOSTISSET($batch))

+			    {

+    				//shipment line with batch-enable product

+    				$qty .= '_'.$j;

+    				while (GETPOSTISSET($batch))

+    				{

+    					// save line of detail into sub_qty

+    				    $sub_qty[$j]['q'] = GETPOST($qty, 'int'); // the qty we want to move for this stock record

+    				    $sub_qty[$j]['id_batch'] = GETPOST($batch, 'int'); // the id into llx_product_batch of stock record to move

+    					$subtotalqty += $sub_qty[$j]['q'];

+

+    					//var_dump($qty);var_dump($batch);var_dump($sub_qty[$j]['q']);var_dump($sub_qty[$j]['id_batch']);

+

+    					$j++;

+    					$batch = "batchl".$i."_".$j;

+    					$qty = "qtyl".$i.'_'.$j;

+    				}

+

+    				$batch_line[$i]['detail'] = $sub_qty; // array of details

+    				$batch_line[$i]['qty'] = $subtotalqty;

+    				$batch_line[$i]['ix_l'] = GETPOST($idl, 'int');

+

+    				$totalqty += $subtotalqty;

+			    }

+			    else

+			    {

+			        // No detail were provided for lots

+			        if (!empty($_POST[$qty]))

+			        {

+			            // We try to set an amount

+    			        // Case we dont use the list of available qty for each warehouse/lot

+    			        // GUI does not allow this yet

+    			        setEventMessages($langs->trans("StockIsRequiredToChooseWhichLotToUse"), null, 'errors');

+			        }

+			    }

+			}

+			elseif (GETPOSTISSET($stockLocation))

+			{

+			    //shipment line from multiple stock locations

+			    $qty .= '_'.$j;

+			    while (GETPOSTISSET($stockLocation))

+			    {

+			        // save sub line of warehouse

+			        $stockLine[$i][$j]['qty'] = GETPOST($qty, 'int');

+			        $stockLine[$i][$j]['warehouse_id'] = GETPOST($stockLocation, 'int');

+			        $stockLine[$i][$j]['ix_l'] = GETPOST($idl, 'int');

+

+			        $totalqty += GETPOST($qty, 'int');

+

+			        $j++;

+			        $stockLocation = "ent1".$i."_".$j;

+			        $qty = "qtyl".$i.'_'.$j;

+			    }

+			}

+			else

+			{

+			    //var_dump(GETPOST($qty,'int')); var_dump($_POST); var_dump($batch);exit;

@@ -345,11 +303 @@
-				if (GETPOST($qty, 'int') > 0) {

-					$totalqty += price2num(GETPOST($qty, 'alpha'), 'MS');

-					$subtotalqty = price2num(GETPOST($qty, 'alpha'), 'MS');

-				}

-			}

-

-			// check qty shipped not greater than ordered

-			if (getDolGlobalInt("MAIN_DONT_SHIP_MORE_THAN_ORDERED") && $subtotalqty > $objectsrc->lines[$i]->qty) {

-				setEventMessages($langs->trans("ErrorTooMuchShipped", $i+1), null, 'errors');

-				$error++;

-				continue;

+				if (GETPOST($qty, 'int') > 0) $totalqty += GETPOST($qty, 'int');

@@ -361 +309 @@
-			if (isset($extrafields->attributes[$object->table_element_line]['label']) && is_array($extrafields->attributes[$object->table_element_line]['label'])) {

+			if (is_array($extrafields->attributes[$object->table_element_line]['label'])) {

@@ -367,8 +315,12 @@
-		}

-

-		//var_dump($batch_line[2]);

-		if (($totalqty > 0 || getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) && !$error) {		// There is at least one thing to ship and no error

-			for ($i = 0; $i < $num; $i++) {

-				$qty = "qtyl".$i;

-

-				if (!isset($batch_line[$i])) {

+	    }

+

+	    //var_dump($batch_line[2]);

+

+	    if ($totalqty > 0)		// There is at least one thing to ship

+	    {

+	        //var_dump($_POST);exit;

+	        for ($i = 0; $i < $num; $i++)

+	        {

+	            $qty = "qtyl".$i;

+				if (!isset($batch_line[$i]))

+				{

@@ -376,14 +328,21 @@
-					if (isset($stockLine[$i])) {

-						//shipment from multiple stock locations

-						$nbstockline = count($stockLine[$i]);

-						for ($j = 0; $j < $nbstockline; $j++) {

-							if ($stockLine[$i][$j]['qty'] > 0 || ($stockLine[$i][$j]['qty'] == 0 && getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {

-								$ret = $object->addline($stockLine[$i][$j]['warehouse_id'], $stockLine[$i][$j]['ix_l'], $stockLine[$i][$j]['qty'], $array_options[$i]);

-								if ($ret < 0) {

-									setEventMessages($object->error, $object->errors, 'errors');

-									$error++;

-								}

-							}

-						}

-					} else {

-						if (GETPOST($qty, 'int') > 0 || getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {

+					if (isset($stockLine[$i]))

+					{

+    					//shipment from multiple stock locations

+					    $nbstockline = count($stockLine[$i]);

+    					for ($j = 0; $j < $nbstockline; $j++)

+    					{

+    					    if ($stockLine[$i][$j]['qty'] > 0)

+    					    {

+    					        $ret = $object->addline($stockLine[$i][$j]['warehouse_id'], $stockLine[$i][$j]['ix_l'], $stockLine[$i][$j]['qty'], $array_options[$i]);

+    					        if ($ret < 0)

+    					        {

+    					            setEventMessages($object->error, $object->errors, 'errors');

+    					            $error++;

+    					        }

+    					    }

+    					}

+					}

+					else

+					{

+						if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS))

+						{

@@ -392,10 +351,7 @@
-							$entrepot_id = is_numeric(GETPOST($ent, 'int')) ? GETPOST($ent, 'int') : GETPOST('entrepot_id', 'int');

-							if ($entrepot_id < 0) {

-								$entrepot_id = '';

-							}

-							if (!($objectsrc->lines[$i]->fk_product > 0)) {

-								$entrepot_id = 0;

-							}

-

-							$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), price2num(GETPOST($qty, 'alpha'), 'MS'), $array_options[$i]);

-							if ($ret < 0) {

+							$entrepot_id = is_numeric(GETPOST($ent, 'int')) ?GETPOST($ent, 'int') : GETPOST('entrepot_id', 'int');

+							if ($entrepot_id < 0) $entrepot_id = '';

+							if (!($objectsrc->lines[$i]->fk_product > 0)) $entrepot_id = 0;

+

+							$ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i]);

+							if ($ret < 0)

+							{

@@ -407 +363,3 @@
-				} else {

+				}

+				else

+				{

@@ -409 +367,2 @@
-					if ($batch_line[$i]['qty'] > 0 || ($batch_line[$i]['qty'] == 0 && getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) {

+					if ($batch_line[$i]['qty'] > 0)

+					{

@@ -411 +370,2 @@
-						if ($ret < 0) {

+						if ($ret < 0)

+						{

@@ -417,45 +377,98 @@
-			}

-			// Fill array 'array_options' with data from add form

-			$ret = $extrafields->setOptionalsFromPost(null, $object);

-			if ($ret < 0) {

-				$error++;

-			}

-

-			if (!$error) {

-				$ret = $object->create($user); // This create shipment (like Odoo picking) and lines of shipments. Stock movement will be done when validating or closing shipment.

-				if ($ret <= 0) {

-					setEventMessages($object->error, $object->errors, 'errors');

-					$error++;

-				}

-			}

-		} elseif (!$error) {

-			$labelfieldmissing = $langs->transnoentitiesnoconv("QtyToShip");

-			if (isModEnabled('stock')) {

-				$labelfieldmissing .= '/'.$langs->transnoentitiesnoconv("Warehouse");

-			}

-			setEventMessages($langs->trans("ErrorFieldRequired", $labelfieldmissing), null, 'errors');

-			$error++;

-		}

-

-		if (!$error) {

-			$db->commit();

-			header("Location: card.php?id=".$object->id);

-			exit;

-		} else {

-			$db->rollback();

-			$_GET["commande_id"] = GETPOST('commande_id', 'int');

-			$action = 'create';

-		}

-	} elseif ($action == 'create_delivery' && getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') && $user->hasRight('expedition', 'delivery', 'creer')) {

-		// Build a receiving receipt

-		$db->begin();

-

-		$result = $object->create_delivery($user);

-		if ($result > 0) {

-			$db->commit();

-

-			header("Location: ".DOL_URL_ROOT.'/delivery/card.php?action=create_delivery&id='.$result);

-			exit;

-		} else {

-			$db->rollback();

-

+	        }

+	        // Fill array 'array_options' with data from add form

+	        $ret = $extrafields->setOptionalsFromPost(null, $object);

+	        if ($ret < 0) $error++;

+

+	        if (!$error)

+	        {

+	            $ret = $object->create($user); // This create shipment (like Odoo picking) and lines of shipments. Stock movement will be done when validating shipment.

+	            if ($ret <= 0)

+	            {

+	                setEventMessages($object->error, $object->errors, 'errors');

+	                $error++;

+	            }

+	        }

+	    }

+	    else

+	    {

+	        setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("QtyToShip").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors');

+	        $error++;

+	    }

+

+	    if (!$error)

+	    {

+	        $db->commit();

+	        header("Location: card.php?id=".$object->id);

+	        exit;

+	    }

+	    else

+	    {

+	        $db->rollback();

+	        $_GET["commande_id"] = GETPOST('commande_id', 'int');

+	        $action = 'create';

+	    }

+	}

+

+	/*

+	 * Build a receiving receipt

+	 */

+	elseif ($action == 'create_delivery' && $conf->livraison_bon->enabled && $user->rights->expedition->livraison->creer)

+	{

+	    $result = $object->create_delivery($user);

+	    if ($result > 0)

+	    {

+	        header("Location: ".DOL_URL_ROOT.'/livraison/card.php?action=create_delivery&id='.$result);

+	        exit;

+	    }

+	    else

+	    {

+	        setEventMessages($object->error, $object->errors, 'errors');

+	    }

+	}

+

+	elseif ($action == 'confirm_valid' && $confirm == 'yes' &&

+        ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer))

+       	|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate)))

+	)

+	{

+	    $object->fetch_thirdparty();

+

+	    $result = $object->valid($user);

+

+	    if ($result < 0)

+	    {

+			$langs->load("errors");

+			setEventMessages($langs->trans($object->error), $object->errors, 'errors');

+	    }

+	    else

+	    {

+	    	// Define output language

+	    	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))

+	    	{

+	    		$outputlangs = $langs;

+	    		$newlang = '';

+	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');

+	    		if ($conf->global->MAIN_MULTILANGS && empty($newlang))	$newlang = $object->thirdparty->default_lang;

+	    		if (!empty($newlang)) {

+	    			$outputlangs = new Translate("", $conf);

+	    			$outputlangs->setDefaultLang($newlang);

+	    		}

+	    		$model = $object->modelpdf;

+	    		$ret = $object->fetch($id); // Reload to get new records

+

+	    		$result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);

+	    		if ($result < 0) dol_print_error($db, $result);

+	    	}

+	    }

+	}

+

+	elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->expedition->supprimer)

+	{

+		$also_update_stock = (GETPOST('alsoUpdateStock', 'alpha') ? 1 : 0);

+	    $result = $object->cancel(0, $also_update_stock);

+	    if ($result > 0)

+	    {

+	        $result = $object->setStatut(-1);

+	    }

+	    else

+		{

@@ -463,10 +476,14 @@
-		}

-	} elseif ($action == 'confirm_valid' && $confirm == 'yes' &&

-		((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'creer'))

-		|| (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'shipping_advance', 'validate')))

-	) {

-		$object->fetch_thirdparty();

-

-		$result = $object->valid($user);

-

-		if ($result < 0) {

+	    }

+	}

+

+	elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer)

+	{

+	    $also_update_stock = (GETPOST('alsoUpdateStock', 'alpha') ? 1 : 0);

+	    $result = $object->delete(0, $also_update_stock);

+	    if ($result > 0)

+	    {

+	        header("Location: ".DOL_URL_ROOT.'/expedition/index.php');

+	        exit;

+	    }

+	    else

+		{

@@ -474,59 +491,28 @@
-		} else {

-			// Define output language

-			if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {

-				$outputlangs = $langs;

-				$newlang = '';

-				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {

-					$newlang = GETPOST('lang_id', 'aZ09');

-				}

-				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {

-					$newlang = $object->thirdparty->default_lang;

-				}

-				if (!empty($newlang)) {

-					$outputlangs = new Translate("", $conf);

-					$outputlangs->setDefaultLang($newlang);

-				}

-				$model = $object->model_pdf;

-				$ret = $object->fetch($id); // Reload to get new records

-

-				$result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);

-				if ($result < 0) {

-					dol_print_error($db, $result);

-				}

-			}

-		}

-	} elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $user->hasRight('expedition', 'supprimer')) {

-		$also_update_stock = (GETPOST('alsoUpdateStock', 'alpha') ? 1 : 0);

-		$result = $object->cancel(0, $also_update_stock);

-		if ($result > 0) {

-			$result = $object->setStatut(-1);

-		} else {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	} elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('expedition', 'supprimer')) {

-		$also_update_stock = (GETPOST('alsoUpdateStock', 'alpha') ? 1 : 0);

-		$result = $object->delete(0, $also_update_stock);

-		if ($result > 0) {

-			header("Location: ".DOL_URL_ROOT.'/expedition/index.php');

-			exit;

-		} else {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-		// TODO add alternative status

-		//} elseif ($action == 'reopen' && (!empty($user->rights->expedition->creer) || !empty($user->rights->expedition->shipping_advance->validate)))

-		//{

-		//	$result = $object->setStatut(0);

-		//	if ($result < 0)

-		//	{

-		//		setEventMessages($object->error, $object->errors, 'errors');

-		//	}

-		//}

-	} elseif ($action == 'setdate_livraison' && $user->hasRight('expedition', 'creer')) {

-		$datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));

-

-		$object->fetch($id);

-		$result = $object->setDeliveryDate($user, $datedelivery);

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	} elseif (($action == 'settracking_number'

+	    }

+	}

+	// TODO add alternative status

+	/*elseif ($action == 'reopen' && (! empty($user->rights->expedition->creer) || ! empty($user->rights->expedition->shipping_advance->validate)))

+	{

+	    $result = $object->setStatut(0);

+	    if ($result < 0)

+	    {

+	        setEventMessages($object->error, $object->errors, 'errors');

+	    }

+	}*/

+

+	elseif ($action == 'setdate_livraison' && $user->rights->expedition->creer)

+	{

+	    //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];

+	    $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));

+

+	    $object->fetch($id);

+	    $result = $object->set_date_livraison($user, $datedelivery);

+	    if ($result < 0)

+	    {

+	        setEventMessages($object->error, $object->errors, 'errors');

+	    }

+	}

+

+	// Action update

+	elseif (

+		($action == 'settracking_number'

@@ -539,13 +525,9 @@
-		&& $user->hasRight('expedition', 'creer')

-		) {

-		// Action update

-		$error = 0;

-

-		if ($action == 'settracking_number') {

-			$object->tracking_number = trim(GETPOST('tracking_number', 'alpha'));

-		}

-		if ($action == 'settracking_url') {

-			$object->tracking_url = trim(GETPOST('tracking_url', 'int'));

-		}

-		if ($action == 'settrueWeight') {

-			$object->trueWeight = trim(GETPOST('trueWeight', 'int'));

+		&& $user->rights->expedition->creer

+		)

+	{

+	    $error = 0;

+

+	    if ($action == 'settracking_number')		$object->tracking_number = trim(GETPOST('tracking_number', 'alpha'));

+	    if ($action == 'settracking_url')		$object->tracking_url = trim(GETPOST('tracking_url', 'int'));

+	    if ($action == 'settrueWeight') {

+	    	$object->trueWeight = trim(GETPOST('trueWeight', 'int'));

@@ -553,31 +535,30 @@
-		}

-		if ($action == 'settrueWidth') {

-			$object->trueWidth = trim(GETPOST('trueWidth', 'int'));

-		}

-		if ($action == 'settrueHeight') {

-			$object->trueHeight = trim(GETPOST('trueHeight', 'int'));

-			$object->size_units = GETPOST('size_units', 'int');

-		}

-		if ($action == 'settrueDepth') {

-			$object->trueDepth = trim(GETPOST('trueDepth', 'int'));

-		}

-		if ($action == 'setshipping_method_id') {

-			$object->shipping_method_id = trim(GETPOST('shipping_method_id', 'int'));

-		}

-

-		if (!$error) {

-			if ($object->update($user) >= 0) {

-				header("Location: card.php?id=".$object->id);

-				exit;

-			}

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-

-		$action = "";

-	} elseif ($action == 'classifybilled') {

-		$object->fetch($id);

-		$result = $object->setBilled();

-		if ($result >= 0) {

-			header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);

-			exit();

-		}

+	    }

+	    if ($action == 'settrueWidth')			$object->trueWidth = trim(GETPOST('trueWidth', 'int'));

+	    if ($action == 'settrueHeight') {

+	    				$object->trueHeight = trim(GETPOST('trueHeight', 'int'));

+						$object->size_units = GETPOST('size_units', 'int');

+		}

+	    if ($action == 'settrueDepth')			$object->trueDepth = trim(GETPOST('trueDepth', 'int'));

+	    if ($action == 'setshipping_method_id')	$object->shipping_method_id = trim(GETPOST('shipping_method_id', 'int'));

+

+	    if (!$error)

+	    {

+	        if ($object->update($user) >= 0)

+	        {

+	            header("Location: card.php?id=".$object->id);

+	            exit;

+	        }

+	        setEventMessages($object->error, $object->errors, 'errors');

+	    }

+

+	    $action = "";

+	}

+

+	elseif ($action == 'classifybilled')

+	{

+	    $object->fetch($id);

+	    $result = $object->set_billed();

+	    if ($result >= 0) {

+	    	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);

+	    	exit();

+	    }

@@ -585,7 +566,10 @@
-	} elseif ($action == 'classifyclosed') {

-		$object->fetch($id);

-		$result = $object->setClosed();

-		if ($result >= 0) {

-			header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);

-			exit();

-		}

+	}

+

+	elseif ($action == 'classifyclosed')

+	{

+	    $object->fetch($id);

+	    $result = $object->setClosed();

+	    if ($result >= 0) {

+	    	header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);

+	    	exit();

+	    }

@@ -593,2 +577,7 @@
-	} elseif ($action == 'deleteline' && !empty($line_id)) {

-		// delete a line

+	}

+

+	/*

+	 *  delete a line

+	 */

+	elseif ($action == 'deleteline' && !empty($line_id))

+	{

@@ -598 +586,0 @@
-		$line->fk_expedition = $object->id;

@@ -601,3 +589,6 @@
-		for ($i = 0; $i < $num_prod; $i++) {

-			if ($lines[$i]->id == $line_id) {

-				if (count($lines[$i]->details_entrepot) > 1) {

+		for ($i = 0; $i < $num_prod; $i++)

+		{

+			if ($lines[$i]->id == $line_id)

+			{

+				if (count($lines[$i]->details_entrepot) > 1)

+				{

@@ -607 +598,2 @@
-						if (!$error && $line->delete($user) < 0) {

+						if (!$error && $line->delete($user) < 0)

+						{

@@ -611 +603,3 @@
-				} else {

+				}

+				else

+				{

@@ -614 +608,2 @@
-					if (!$error && $line->delete($user) < 0) {

+					if (!$error && $line->delete($user) < 0)

+					{

@@ -625 +620,3 @@
-		} else {

+		}

+		else

+		{

@@ -628,2 +625,7 @@
-	} elseif ($action == 'updateline' && $user->hasRight('expedition', 'creer') && GETPOST('save')) {

-		// Update a line

+	}

+

+	/*

+	 *  Update a line

+	 */

+	elseif ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('save'))

+	{

@@ -637,3 +639,4 @@
-		for ($i = 0; $i < $num_prod; $i++) {

-			if ($lines[$i]->id == $line_id) {		// we have found line to update

-				$update_done = false;

+		for ($i = 0; $i < $num_prod; $i++)

+		{

+			if ($lines[$i]->id == $line_id)		// we have found line to update

+			{

@@ -641 +643,0 @@
-				$line->fk_expedition = $object->id;

@@ -652 +654,2 @@
-				if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) {

+				if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0)

+				{

@@ -654 +657,2 @@
-					foreach ($lines[$i]->detail_batch as $detail_batch) {

+					foreach ($lines[$i]->detail_batch as $detail_batch)

+					{

@@ -660,3 +664,6 @@
-						if (!empty($batch_id)) {

-							if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0) {	// $line is ExpeditionLine

-								if ($lines[$i]->entrepot_id != 0) {

+						if (!empty($batch_id) && ($batch_id != $detail_batch->fk_origin_stock || $batch_qty != $detail_batch->qty))

+						{

+							if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0)	// $line is ExpeditionLine

+							{

+								if ($lines[$i]->entrepot_id != 0)

+								{

@@ -668,3 +675 @@
-								if (empty($line->detail_batch)) {

-									$line->detail_batch = new stdClass();

-								}

+								if (empty($line->detail_batch)) $line->detail_batch = new stdClass();

@@ -680,2 +684,0 @@
-								} else {

-									$update_done=true;

@@ -683 +686,3 @@
-							} else {

+							}

+							else

+							{

@@ -698,2 +703,4 @@
-					if ($batch_qty > 0 && !empty($batch_id)) {

-						if ($lotStock->fetch($batch_id) > 0) {

+					if ($batch_qty > 0 && !empty($batch_id))

+					{

+						if ($lotStock->fetch($batch_id) > 0)

+						{

@@ -701 +708,2 @@
-							if ($lines[$i]->entrepot_id > 0) {

+							if ($lines[$i]->entrepot_id > 0)

+							{

@@ -703 +711,2 @@
-								if ($lines[$i]->entrepot_id == $lotStock->warehouseid) {

+								if ($lines[$i]->entrepot_id == $lotStock->warehouseid)

+								{

@@ -706 +715,3 @@
-							} elseif (count($lines[$i]->details_entrepot) > 1) {

+							}

+							elseif (count($lines[$i]->details_entrepot) > 1)

+							{

@@ -708,2 +719,4 @@
-								foreach ($lines[$i]->details_entrepot as $detail_entrepot) {

-									if ($detail_entrepot->entrepot_id == $lotStock->warehouseid) {

+								foreach ($lines[$i]->details_entrepot as $detail_entrepot)

+								{

+									if ($detail_entrepot->entrepot_id == $lotStock->warehouseid)

+									{

@@ -714 +727,2 @@
-							if ($lineIdToAddLot) {

+							if ($lineIdToAddLot)

+							{

@@ -716 +730,2 @@
-								if ($line->fetch($lineIdToAddLot) > 0) {

+								if ($line->fetch($lineIdToAddLot) > 0)

+								{

@@ -724,2 +738,0 @@
-									} else {

-										$update_done=true;

@@ -727 +740,3 @@
-								} else {

+								}

+								else

+								{

@@ -731 +746,3 @@
-							} else {

+							}

+							else

+							{

@@ -740 +757,2 @@
-								if ($object->create_line_batch($line, $line->array_options) < 0) {

+								if ($object->create_line_batch($line, $line->array_options) < 0)

+								{

@@ -743,2 +760,0 @@
-								} else {

-									$update_done=true;

@@ -747 +763,3 @@
-						} else {

+						}

+						else

+						{

@@ -752,2 +770,5 @@
-				} else {

-					if ($lines[$i]->fk_product > 0) {

+				}

+				else

+				{

+					if ($lines[$i]->fk_product > 0)

+					{

@@ -755,14 +776,2 @@
-						if ($lines[$i]->entrepot_id == 0) {

-							// single warehouse shipment line

-							$stockLocation = 0;

-							$qty = "qtyl".$line_id;

-							$line->id = $line_id;

-							$line->entrepot_id = GETPOST($stockLocation, 'int');

-							$line->qty = GETPOST($qty, 'int');

-							if ($line->update($user) < 0) {

-								setEventMessages($line->error, $line->errors, 'errors');

-								$error++;

-							}

-							unset($_POST[$stockLocation]);

-							unset($_POST[$qty]);

-						} elseif ($lines[$i]->entrepot_id > 0) {

+						if ($lines[$i]->entrepot_id > 0)

+						{

@@ -781 +790,3 @@
-						} elseif (count($lines[$i]->details_entrepot) > 1) {

+						}

+						elseif (count($lines[$i]->details_entrepot) > 1)

+						{

@@ -783 +794,2 @@
-							foreach ($lines[$i]->details_entrepot as $detail_entrepot) {

+							foreach ($lines[$i]->details_entrepot as $detail_entrepot)

+							{

@@ -788 +800,2 @@
-									if (!empty($warehouse)) {

+									if (!empty($warehouse))

+									{

@@ -795,2 +807,0 @@
-										} else {

-											$update_done=true;

@@ -803,12 +813,0 @@
-						} elseif (!isModEnabled('stock') && empty($conf->productbatch->enabled)) { // both product batch and stock are not activated.

-							$qty = "qtyl".$line_id;

-							$line->id = $line_id;

-							$line->qty = GETPOST($qty, 'int');

-							$line->entrepot_id = 0;

-							if ($line->update($user) < 0) {

-								setEventMessages($line->error, $line->errors, 'errors');

-								$error++;

-							} else {

-								$update_done=true;

-							}

-							unset($_POST[$qty]);

@@ -816,2 +815,4 @@
-					} else {

-						// Product no predefined

+					}

+					else

+					{

+                        // Product no predefined

@@ -825,2 +825,0 @@
-						} else {

-							$update_done=true;

@@ -831,5 +829,0 @@
-

-				if (empty($update_done)) {

-					$line->id = $lines[$i]->id;

-					$line->insertExtraFields();

-				}

@@ -842 +836 @@
-			if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {

+			if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {

@@ -846 +840 @@
-				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {

+				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09'))

@@ -848,2 +842 @@
-				}

-				if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {

+				if ($conf->global->MAIN_MULTILANGS && empty($newlang))

@@ -851 +843,0 @@
-				}

@@ -858,3 +850,5 @@
-				$object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);

-			}

-		} else {

+				$object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);

+			}

+		}

+		else

+		{

@@ -864 +858 @@
-	} elseif ($action == 'updateline' && $user->hasRight('expedition', 'creer') && GETPOST('cancel', 'alpha') == $langs->trans("Cancel")) {

+	} elseif ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('cancel', 'alpha') == $langs->trans('Cancel')) {

@@ -872,3 +866 @@
-	if (empty($id)) {

-		$id = $facid;

-	}

+	if (empty($id)) $id = $facid;

@@ -877 +868,0 @@
-	$autocopy = 'MAIN_MAIL_AUTOCOPY_SHIPMENT_TO';

@@ -888,11 +879 @@
-$title = $object->ref.' - '.$langs->trans("Shipment");

-if ($action == 'create2') {

-	$title = $langs->trans("CreateShipment");

-}

-$help_url = 'EN:Module_Shipments|FR:Module_Expéditions|ES:M&oacute;dulo_Expediciones|DE:Modul_Lieferungen';

-

-llxHeader('', $title, $help_url);

-

-if (empty($action)) {

-	$action = 'view';

-}

+llxHeader('', $langs->trans('Shipment'), 'Expedition');

@@ -903,3 +884 @@
-if (isModEnabled('project')) {

-	$formproject = new FormProjets($db);

-}

+if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }

@@ -911,7 +890,6 @@
-if ($action == 'create2') {

-	print load_fiche_titre($langs->trans("CreateShipment"), '', 'dolly');

-

-	print '<br>'.$langs->trans("ShipmentCreationIsDoneFromOrder");

-	$action = '';

-	$id = '';

-	$ref = '';

+if ($action == 'create2')

+{

+    print load_fiche_titre($langs->trans("CreateShipment"), '', 'dolly');

+

+    print '<br>'.$langs->trans("ShipmentCreationIsDoneFromOrder");

+    $action = ''; $id = ''; $ref = '';

@@ -921,160 +899,150 @@
-if ($action == 'create') {

-	$expe = new Expedition($db);

-

-	print load_fiche_titre($langs->trans("CreateShipment"), '', 'dolly');

-

-	if (!$origin) {

-		setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors');

-	}

-

-	if ($origin) {

-		$classname = ucfirst($origin);

-

-		$object = new $classname($db);

-		if ($object->fetch($origin_id)) {	// This include the fetch_lines

-			$soc = new Societe($db);

-			$soc->fetch($object->socid);

-

-			$author = new User($db);

-			$author->fetch($object->user_author_id);

-

-			if (isModEnabled('stock')) {

-				$entrepot = new Entrepot($db);

-			}

-

-			print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';

-			print '<input type="hidden" name="token" value="'.newToken().'">';

-			print '<input type="hidden" name="action" value="add">';

-			print '<input type="hidden" name="origin" value="'.$origin.'">';

-			print '<input type="hidden" name="origin_id" value="'.$object->id.'">';

-			if (GETPOST('entrepot_id', 'int')) {

-				print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id', 'int').'">';

-			}

-

-			print dol_get_fiche_head('');

-

-			print '<table class="border centpercent">';

-

-			// Ref

-			print '<tr><td class="titlefieldcreate fieldrequired">';

-			if ($origin == 'commande' && isModEnabled('commande')) {

-				print $langs->trans("RefOrder");

-			}

-			if ($origin == 'propal' && isModEnabled("propal")) {

-				print $langs->trans("RefProposal");

-			}

-			print '</td><td colspan="3">';

-			print $object->getNomUrl(1);

-			print '</td>';

-			print "</tr>\n";

-

-			// Ref client

-			print '<tr><td>';

-			if ($origin == 'commande') {

-				print $langs->trans('RefCustomerOrder');

-			} elseif ($origin == 'propal') {

-				print $langs->trans('RefCustomerOrder');

-			} else {

-				print $langs->trans('RefCustomer');

-			}

-			print '</td><td colspan="3">';

-			print '<input type="text" name="ref_customer" value="'.$object->ref_client.'" />';

-			print '</td>';

-			print '</tr>';

-

-			// Tiers

-			print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Company').'</td>';

-			print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';

-			print '</tr>';

-

-			// Project

-			if (isModEnabled('project')) {

-				$projectid = GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : 0;

-				if (empty($projectid) && !empty($object->fk_project)) {

-					$projectid = $object->fk_project;

-				}

-				if ($origin == 'project') {

-					$projectid = ($originid ? $originid : 0);

-				}

-

-				$langs->load("projects");

-				print '<tr>';

-				print '<td>'.$langs->trans("Project").'</td><td colspan="2">';

-				print img_picto('', 'project', 'class="pictofixedwidth"');

-				$numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0);

-				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>';

-				print '</td>';

-				print '</tr>';

-			}

-

-			// Date delivery planned

-			print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';

-			print '<td colspan="3">';

-			print img_picto('', 'action', 'class="pictofixedwidth"');

-			$date_delivery = ($date_delivery ? $date_delivery : $object->delivery_date); // $date_delivery comes from GETPOST

-			print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);

-			print "</td>\n";

-			print '</tr>';

-

-			// Note Public

-			print '<tr><td>'.$langs->trans("NotePublic").'</td>';

-			print '<td colspan="3">';

-			$doleditor = new DolEditor('note_public', $object->note_public, '', 60, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');

-			print $doleditor->Create(1);

-			print "</td></tr>";

-

-			// Note Private

-			if ($object->note_private && !$user->socid) {

-				print '<tr><td>'.$langs->trans("NotePrivate").'</td>';

-				print '<td colspan="3">';

-				$doleditor = new DolEditor('note_private', $object->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');

-				print $doleditor->Create(1);

-				print "</td></tr>";

-			}

-

-			// Weight

-			print '<tr><td>';

-			print $langs->trans("Weight");

-			print '</td><td colspan="3">';

-			print img_picto('', 'fa-balance-scale', 'class="pictofixedwidth"');

-			print '<input name="weight" size="4" value="'.GETPOST('weight', 'int').'"> ';

-			$text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units', 'int'), 0, 2);

-			$htmltext = $langs->trans("KeepEmptyForAutoCalculation");

-			print $form->textwithpicto($text, $htmltext);

-			print '</td></tr>';

-			// Dim

-			print '<tr><td>';

-			print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth");

-			print ' </td><td colspan="3">';

-			print img_picto('', 'fa-ruler', 'class="pictofixedwidth"');

-			print '<input name="sizeW" size="4" value="'.GETPOST('sizeW', 'int').'">';

-			print ' x <input name="sizeH" size="4" value="'.GETPOST('sizeH', 'int').'">';

-			print ' x <input name="sizeS" size="4" value="'.GETPOST('sizeS', 'int').'">';

-			print ' ';

-			$text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units', 'int'), 0, 2);

-			$htmltext = $langs->trans("KeepEmptyForAutoCalculation");

-			print $form->textwithpicto($text, $htmltext);

-			print '</td></tr>';

-

-			// Delivery method

-			print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";

-			print '<td colspan="3">';

-			$expe->fetch_delivery_methods();

-			print img_picto('', 'dolly', 'class="pictofixedwidth"');

-			print $form->selectarray("shipping_method_id", $expe->meths, GETPOST('shipping_method_id', 'int'), 1, 0, 0, "", 1);

-			if ($user->admin) {

-				print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);

-			}

-			print "</td></tr>\n";

-

-			// Tracking number

-			print "<tr><td>".$langs->trans("TrackingNumber")."</td>";

-			print '<td colspan="3">';

-			print img_picto('', 'barcode', 'class="pictofixedwidth"');

-			print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number', 'alpha').'">';

-			print "</td></tr>\n";

-

-			// Other attributes

-			$parameters = array('objectsrc' => isset($objectsrc) ? $objectsrc : '', 'colspan' => ' colspan="3"', 'cols' => '3', 'socid' => $socid);

-			$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $expe, $action); // Note that $action and $object may have been modified by hook

-			print $hookmanager->resPrint;

+if ($action == 'create')

+{

+    $expe = new Expedition($db);

+

+    print load_fiche_titre($langs->trans("CreateShipment"), '', 'dolly');

+

+    if (!$origin)

+    {

+        setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors');

+    }

+

+    if ($origin)

+    {

+        $classname = ucfirst($origin);

+

+        $object = new $classname($db);

+        if ($object->fetch($origin_id))	// This include the fetch_lines

+        {

+            $soc = new Societe($db);

+            $soc->fetch($object->socid);

+

+            $author = new User($db);

+            $author->fetch($object->user_author_id);

+

+            if (!empty($conf->stock->enabled)) $entrepot = new Entrepot($db);

+

+            print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';

+            print '<input type="hidden" name="token" value="'.newToken().'">';

+            print '<input type="hidden" name="action" value="add">';

+            print '<input type="hidden" name="origin" value="'.$origin.'">';

+            print '<input type="hidden" name="origin_id" value="'.$object->id.'">';

+            print '<input type="hidden" name="ref_int" value="'.$object->ref_int.'">';

+            if (GETPOST('entrepot_id', 'int'))

+            {

+                print '<input type="hidden" name="entrepot_id" value="'.GETPOST('entrepot_id', 'int').'">';

+            }

+

+            dol_fiche_head('');

+

+            print '<table class="border centpercent">';

+

+            // Ref

+            print '<tr><td class="titlefieldcreate fieldrequired">';

+            if ($origin == 'commande' && !empty($conf->commande->enabled))

+            {

+                print $langs->trans("RefOrder").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowOrder"), 'order').' '.$object->ref;

+            }

+            if ($origin == 'propal' && !empty($conf->propal->enabled))

+            {

+                print $langs->trans("RefProposal").'</td><td colspan="3"><a href="'.DOL_URL_ROOT.'/comm/card.php?id='.$object->id.'">'.img_object($langs->trans("ShowProposal"), 'propal').' '.$object->ref;

+            }

+            print '</a></td>';

+            print "</tr>\n";

+

+            // Ref client

+            print '<tr><td>';

+            if ($origin == 'commande') print $langs->trans('RefCustomerOrder');

+            elseif ($origin == 'propal') print $langs->trans('RefCustomerOrder');

+            else print $langs->trans('RefCustomer');

+            print '</td><td colspan="3">';

+            print '<input type="text" name="ref_customer" value="'.$object->ref_client.'" />';

+            print '</td>';

+            print '</tr>';

+

+            // Tiers

+            print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Company').'</td>';

+            print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';

+            print '</tr>';

+

+            // Project

+            if (!empty($conf->projet->enabled))

+            {

+                $projectid = GETPOST('projectid', 'int') ?GETPOST('projectid', 'int') : 0;

+                if (empty($projectid) && !empty($object->fk_project)) $projectid = $object->fk_project;

+                if ($origin == 'project') $projectid = ($originid ? $originid : 0);

+

+                $langs->load("projects");

+                print '<tr>';

+                print '<td>'.$langs->trans("Project").'</td><td colspan="2">';

+                print img_picto('', 'project');

+                $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0);

+                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>';

+                print '</td>';

+                print '</tr>';

+            }

+

+            // Date delivery planned

+            print '<tr><td>'.$langs->trans("DateDeliveryPlanned").'</td>';

+            print '<td colspan="3">';

+            //print dol_print_date($object->date_livraison, "day");	// date_livraison come from order and will be stored into date_delivery planed.

+            $date_delivery = ($date_delivery ? $date_delivery : $object->date_livraison); // $date_delivery comes from GETPOST

+            print $form->selectDate($date_delivery ? $date_delivery : -1, 'date_delivery', 1, 1, 1);

+            print "</td>\n";

+            print '</tr>';

+

+            // Note Public

+            print '<tr><td>'.$langs->trans("NotePublic").'</td>';

+            print '<td colspan="3">';

+            $doleditor = new DolEditor('note_public', $object->note_public, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');

+            print $doleditor->Create(1);

+            print "</td></tr>";

+

+            // Note Private

+            if ($object->note_private && !$user->socid)

+            {

+                print '<tr><td>'.$langs->trans("NotePrivate").'</td>';

+                print '<td colspan="3">';

+                $doleditor = new DolEditor('note_private', $object->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%');

+        		print $doleditor->Create(1);

+                print "</td></tr>";

+            }

+

+            // Weight

+            print '<tr><td>';

+            print $langs->trans("Weight");

+            print '</td><td colspan="3"><input name="weight" size="4" value="'.GETPOST('weight', 'int').'"> ';

+            $text = $formproduct->selectMeasuringUnits("weight_units", "weight", GETPOST('weight_units', 'int'), 0, 2);

+            $htmltext = $langs->trans("KeepEmptyForAutoCalculation");

+            print $form->textwithpicto($text, $htmltext);

+            print '</td></tr>';

+            // Dim

+            print '<tr><td>';

+            print $langs->trans("Width").' x '.$langs->trans("Height").' x '.$langs->trans("Depth");

+            print ' </td><td colspan="3"><input name="sizeW" size="4" value="'.GETPOST('sizeW', 'int').'">';

+            print ' x <input name="sizeH" size="4" value="'.GETPOST('sizeH', 'int').'">';

+            print ' x <input name="sizeS" size="4" value="'.GETPOST('sizeS', 'int').'">';

+            print ' ';

+            $text = $formproduct->selectMeasuringUnits("size_units", "size", GETPOST('size_units', 'int'), 0, 2);

+            $htmltext = $langs->trans("KeepEmptyForAutoCalculation");

+            print $form->textwithpicto($text, $htmltext);

+            print '</td></tr>';

+

+            // Delivery method

+            print "<tr><td>".$langs->trans("DeliveryMethod")."</td>";

+            print '<td colspan="3">';

+            $expe->fetch_delivery_methods();

+            print $form->selectarray("shipping_method_id", $expe->meths, GETPOST('shipping_method_id', 'int'), 1, 0, 0, "", 1);

+            if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);

+            print "</td></tr>\n";

+

+            // Tracking number

+            print "<tr><td>".$langs->trans("TrackingNumber")."</td>";

+            print '<td colspan="3">';

+            print '<input name="tracking_number" size="20" value="'.GETPOST('tracking_number', 'alpha').'">';

+            print "</td></tr>\n";

+

+            // Other attributes

+            $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'cols' => '3', 'socid' => $socid);

+            $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $expe, $action); // Note that $action and $object may have been modified by hook

+            print $hookmanager->resPrint;

@@ -1091,2 +1059,3 @@
-			// Incoterms

-			if (isModEnabled('incoterm')) {

+            // Incoterms

+			if (!empty($conf->incoterm->enabled))

+			{

@@ -1095,3 +1064,2 @@
-				print '<td colspan="3" class="maxwidthonsmartphone">';

-				print img_picto('', 'incoterm', 'class="pictofixedwidth"');

-				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));

+		        print '<td colspan="3" class="maxwidthonsmartphone">';

+		        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''));

@@ -1101 +1069 @@
-			// Document model

+            // Document model

@@ -1103,26 +1071,57 @@
-			$list = ModelePdfExpedition::liste_modeles($db);

-			if (count($list) > 1) {

-				print "<tr><td>".$langs->trans("DefaultModel")."</td>";

-				print '<td colspan="3">';

-				print img_picto('', 'pdf', 'class="pictofixedwidth"');

-				print $form->selectarray('model', $list, $conf->global->EXPEDITION_ADDON_PDF);

-				print "</td></tr>\n";

-			}

-

-			print "</table>";

-

-			print dol_get_fiche_end();

-

-

-			// Shipment lines

-

-			$numAsked = count($object->lines);

-

-			print '<script type="text/javascript">'."\n";

-			print 'jQuery(document).ready(function() {'."\n";

-			print 'jQuery("#autofill").click(function() {';

-			$i = 0;

-			while ($i < $numAsked) {

-				print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";

-				if (isModEnabled('productbatch')) {

-					print 'jQuery("#qtyl'.$i.'_'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";

+			$liste = ModelePdfExpedition::liste_modeles($db);

+			if (count($liste) > 1)

+			{

+    			print "<tr><td>".$langs->trans("DefaultModel")."</td>";

+                print '<td colspan="3">';

+    			print $form->selectarray('model', $liste, $conf->global->EXPEDITION_ADDON_PDF);

+                print "</td></tr>\n";

+			}

+

+            print "</table>";

+

+            dol_fiche_end();

+

+

+            // Shipment lines

+

+            $numAsked = count($object->lines);

+

+            print '<script type="text/javascript" language="javascript">

+            jQuery(document).ready(function() {

+	            jQuery("#autofill").click(function() {';

+    	    $i = 0;

+    	    while ($i < $numAsked)

+    	    {

+    	    	print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n";

+    	    	$i++;

+    	    }

+        	print '});

+	            jQuery("#autoreset").click(function() {';

+    	    $i = 0;

+    	    while ($i < $numAsked)

+    	    {

+    	    	print 'jQuery("#qtyl'.$i.'").val(0);'."\n";

+    	    	$i++;

+    	    }

+        	print '});

+        	});

+            </script>';

+

+            print '<br>';

+

+            print '<table class="noborder centpercent">';

+

+            // Load shipments already done for same order

+            $object->loadExpeditions();

+

+            if ($numAsked)

+            {

+                print '<tr class="liste_titre">';

+                print '<td>'.$langs->trans("Description").'</td>';

+                print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';

+                print '<td class="center">'.$langs->trans("QtyShipped").'</td>';

+                print '<td class="center">'.$langs->trans("QtyToShip");

+				if (empty($conf->productbatch->enabled))

+				{

+	                print ' <br>(<a href="#" id="autofill">'.$langs->trans("Fill").'</a>';

+	                print ' / <a href="#" id="autoreset">'.$langs->trans("Reset").'</a>)';

@@ -1130,36 +1129,9 @@
-				$i++;

-			}

-			print 'return false; });'."\n";

-			print 'jQuery("#autoreset").click(function() { console.log("Reset values to 0"); jQuery(".qtyl").val(0);'."\n";

-			print 'return false; });'."\n";

-			print '});'."\n";

-			print '</script>'."\n";

-

-			print '<br>';

-

-			print '<table class="noborder centpercent">';

-

-			// Load shipments already done for same order

-			$object->loadExpeditions();

-

-

-			$alreadyQtyBatchSetted = $alreadyQtySetted = array();

-

-			if ($numAsked) {

-				print '<tr class="liste_titre">';

-				print '<td>'.$langs->trans("Description").'</td>';

-				print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';

-				print '<td class="center">'.$langs->trans("QtyShipped").'</td>';

-				print '<td class="center">'.$langs->trans("QtyToShip");

-				if (empty($conf->productbatch->enabled)) {

-					print '<br><a href="#" id="autofill" class="opacitymedium link cursor cursorpointer">'.img_picto($langs->trans("Autofill"), 'autofill', 'class="paddingrightonly"').'</a>';

-					print ' / ';

-				} else {

-					print '<br>';

-				}

-				print '<span id="autoreset" class="opacitymedium link cursor cursorpointer">'.img_picto($langs->trans("Reset"), 'eraser').'</span>';

-				print '</td>';

-				if (isModEnabled('stock')) {

-					if (empty($conf->productbatch->enabled)) {

-						print '<td class="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';

-					} else {

+                print '</td>';

+                if (!empty($conf->stock->enabled))

+                {

+					if (empty($conf->productbatch->enabled))

+					{

+                    	print '<td class="left">'.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')</td>';

+					}

+					else

+					{

@@ -1168,122 +1140,93 @@
-				}

-				if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-					print '<td class="left">'.$langs->trans('StockEntryDate').'</td>';

-				}

-				print "</tr>\n";

-			}

-

-			$warehouse_id = GETPOST('entrepot_id', 'int');

-			$warehousePicking = array();

-			// get all warehouse children for picking

-			if ($warehouse_id > 0) {

-				$warehousePicking[] = $warehouse_id;

-				$warehouseObj = new Entrepot($db);

-				$warehouseObj->get_children_warehouses($warehouse_id, $warehousePicking);

-			}

-

-			$indiceAsked = 0;

-			while ($indiceAsked < $numAsked) {

-				$product = new Product($db);

-

-				$line = $object->lines[$indiceAsked];

-

-				$parameters = array('i' => $indiceAsked, 'line' => $line, 'num' => $numAsked);

-				$reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);

-				if ($reshook < 0) {

-					setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-				}

-

-				if (empty($reshook)) {

-					// Show product and description

-					$type = $line->product_type ? $line->product_type : $line->fk_product_type;

-					// Try to enhance type detection using date_start and date_end for free lines where type

-					// was not saved.

-					if (!empty($line->date_start)) {

-						$type = 1;

-					}

-					if (!empty($line->date_end)) {

-						$type = 1;

-					}

-

-					print '<!-- line for order line '.$line->id.' -->'."\n";

-					print '<tr class="oddeven" id="row-'.$line->id.'">'."\n";

-

-					// Product label

-					if ($line->fk_product > 0) {  // If predefined product

-						$res = $product->fetch($line->fk_product);

-						if ($res < 0) {

-							dol_print_error($db, $product->error, $product->errors);

-						}

-						$product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch

-						//var_dump($product->stock_warehouse[1]);

-

-						print '<td>';

-						print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne

-

-						// Show product and description

-						$product_static->type = $line->fk_product_type;

-						$product_static->id = $line->fk_product;

-						$product_static->ref = $line->ref;

-						$product_static->status = $line->product_tosell;

-						$product_static->status_buy = $line->product_tobuy;

-						$product_static->status_batch = $line->product_tobatch;

-

-						$showdescinproductdesc = getDolGlobalString('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE');

-

-						$text = $product_static->getNomUrl(1);

-						$text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label);

-						$description = ($showdescinproductdesc ? '' : dol_htmlentitiesbr($line->desc));

-

-						print $form->textwithtooltip($text, $description, 3, '', '', $i);

-

-						// Show range

-						print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));

-

-						// Add description in form

-						if ($showdescinproductdesc) {

-							print ($line->desc && $line->desc != $line->product_label) ? '<br>'.dol_htmlentitiesbr($line->desc) : '';

-						}

-

-						print '</td>';

-					} else {

-						print "<td>";

-						if ($type == 1) {

-							$text = img_object($langs->trans('Service'), 'service');

-						} else {

-							$text = img_object($langs->trans('Product'), 'product');

-						}

-

-						if (!empty($line->label)) {

-							$text .= ' <strong>'.$line->label.'</strong>';

-							print $form->textwithtooltip($text, $line->desc, 3, '', '', $i);

-						} else {

-							print $text.' '.nl2br($line->desc);

-						}

-

-						// Show range

-						print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));

-						print "</td>\n";

-					}

-

-					// unit of order

-					$unit_order = '';

-					if (getDolGlobalString('PRODUCT_USE_UNITS')) {

-						$unit_order = measuringUnitString($line->fk_unit);

-					}

-

-					// Qty

-					print '<td class="center">'.$line->qty;

-					print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';

-					print ''.$unit_order.'</td>';

-					$qtyProdCom = $line->qty;

-

-					// Qty already shipped

-					print '<td class="center">';

-					$quantityDelivered = isset($object->expeditions[$line->id]) ? $object->expeditions[$line->id] : '';

-					print $quantityDelivered;

-					print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';

-					print ''.$unit_order.'</td>';

-

-					// Qty to ship

-					$quantityAsked = $line->qty;

-					if ($line->product_type == 1 && !getDolGlobalString('STOCK_SUPPORTS_SERVICES') && !getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {

+                }

+                print "</tr>\n";

+            }

+

+            $indiceAsked = 0;

+            while ($indiceAsked < $numAsked)

+            {

+                $product = new Product($db);

+

+                $line = $object->lines[$indiceAsked];

+

+                $parameters = array('i' => $indiceAsked, 'line' => $line, 'num' => $numAsked);

+                $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);

+                if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

+

+                if (empty($reshook))

+                {

+	                // Show product and description

+	                $type = $line->product_type ? $line->product_type : $line->fk_product_type;

+	                // Try to enhance type detection using date_start and date_end for free lines where type

+	                // was not saved.

+	                if (!empty($line->date_start)) $type = 1;

+	                if (!empty($line->date_end)) $type = 1;

+

+	                print '<!-- line '.$line->rowid.' for product -->'."\n";

+	                print '<tr class="oddeven">'."\n";

+

+	                // Product label

+	                if ($line->fk_product > 0)  // If predefined product

+	                {

+	                    $product->fetch($line->fk_product);

+	                    $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch

+	                    //var_dump($product->stock_warehouse[1]);

+

+	                    print '<td>';

+	                    print '<a name="'.$line->rowid.'"></a>'; // ancre pour retourner sur la ligne

+

+	                    // Show product and description

+	                    $product_static->type = $line->fk_product_type;

+	                    $product_static->id = $line->fk_product;

+	                    $product_static->ref = $line->ref;

+	                    $product_static->status_batch = $line->product_tobatch;

+	                    $text = $product_static->getNomUrl(1);

+	                    $text .= ' - '.(!empty($line->label) ? $line->label : $line->product_label);

+	                    $description = ($conf->global->PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr($line->desc));

+	                    print $form->textwithtooltip($text, $description, 3, '', '', $i);

+

+	                    // Show range

+	                    print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));

+

+	                    // Add description in form

+	                    if (!empty($conf->global->PRODUIT_DESC_IN_FORM))

+	                    {

+	                        print ($line->desc && $line->desc != $line->product_label) ? '<br>'.dol_htmlentitiesbr($line->desc) : '';

+	                    }

+

+	                    print '</td>';

+	                }

+	                else

+					{

+					    print "<td>";

+	                    if ($type == 1) $text = img_object($langs->trans('Service'), 'service');

+	                    else $text = img_object($langs->trans('Product'), 'product');

+

+	                    if (!empty($line->label)) {

+	                    	$text .= ' <strong>'.$line->label.'</strong>';

+	                    	print $form->textwithtooltip($text, $line->desc, 3, '', '', $i);

+	                    } else {

+	                    	print $text.' '.nl2br($line->desc);

+	                    }

+

+	                    // Show range

+	                    print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end));

+	                    print "</td>\n";

+	                }

+

+	                // Qty

+	                print '<td class="center">'.$line->qty;

+	                print '<input name="qtyasked'.$indiceAsked.'" id="qtyasked'.$indiceAsked.'" type="hidden" value="'.$line->qty.'">';

+	                print '</td>';

+	                $qtyProdCom = $line->qty;

+

+	                // Qty already shipped

+	                print '<td class="center">';

+	                $quantityDelivered = $object->expeditions[$line->id];

+	                print $quantityDelivered;

+	                print '<input name="qtydelivered'.$indiceAsked.'" id="qtydelivered'.$indiceAsked.'" type="hidden" value="'.$quantityDelivered.'">';

+	                print '</td>';

+

+	                // Qty to ship

+	                $quantityAsked = $line->qty;

+					if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES))

+					{

@@ -1291,7 +1234,6 @@
-					} else {

-						if (is_numeric($quantityDelivered)) {

-							$quantityToBeDelivered = $quantityAsked - $quantityDelivered;

-						} else {

-							$quantityToBeDelivered = $quantityAsked;

-						}

-					}

+					}

+					else

+					{

+						$quantityToBeDelivered = $quantityAsked - $quantityDelivered;

+					}

+	                $warehouse_id = GETPOST('entrepot_id', 'int');

@@ -1300,2 +1242,3 @@
-					if (count($warehousePicking) == 1 || !($line->fk_product > 0) || !isModEnabled('stock')) {     // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection

-						print '<!-- Case warehouse already known or product not a predefined product -->';

+					if ($warehouse_id > 0 || !($line->fk_product > 0) || 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

+					{

+					    print '<!-- Case warehouse already known or product not a predefined product -->';

@@ -1303,10 +1246,5 @@
-						$stock = + (isset($product->stock_warehouse[$warehouse_id]->real) ? $product->stock_warehouse[$warehouse_id]->real : 0); // Convert to number

-						if (getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {

-							$deliverableQty = $quantityToBeDelivered;

-						} else {

-							$deliverableQty = min($quantityToBeDelivered, $stock);

-						}

-						if ($deliverableQty < 0) {

-							$deliverableQty = 0;

-						}

-						if (empty($conf->productbatch->enabled) || !$product->hasbatch()) {

+						$stock = + $product->stock_warehouse[$warehouse_id]->real; // Convert to number

+						$deliverableQty = min($quantityToBeDelivered, $stock);

+						if ($deliverableQty < 0) $deliverableQty = 0;

+						if (empty($conf->productbatch->enabled) || !$product->hasbatch())

+						{

@@ -1315,14 +1253,7 @@
-							if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {

-								if (GETPOST('qtyl'.$indiceAsked, 'int')) {

-									$deliverableQty = GETPOST('qtyl'.$indiceAsked, 'int');

-								}

-								print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';

-								print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" class="qtyl right" type="text" size="4" value="'.$deliverableQty.'">';

-							} else {

-								if (getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {

-									print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';

-									print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="hidden" value="0">';

-								}

-

-								print $langs->trans("NA");

-							}

+							if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))

+							{

+	                            if (GETPOST('qtyl'.$indiceAsked, 'int')) $deliverableQty = GETPOST('qtyl'.$indiceAsked, 'int');

+	                            print '<input name="idl'.$indiceAsked.'" type="hidden" value="'.$line->id.'">';

+								print '<input name="qtyl'.$indiceAsked.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';

+							}

+							else print $langs->trans("NA");

@@ -1332 +1263,2 @@
-							if (isModEnabled('stock')) {

+							if (!empty($conf->stock->enabled))

+							{

@@ -1334 +1266,2 @@
-								if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {   // Type of product need stock change ?

+								if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))   // Type of product need stock change ?

+								{

@@ -1338,11 +1271,13 @@
-									$tmpentrepot_id = is_numeric(GETPOST($ent, 'int')) ? GETPOST($ent, 'int') : $warehouse_id;

-									if ($line->fk_product > 0) {

-										print '<!-- Show warehouse selection -->';

-

-										$stockMin = false;

-										if (!getDolGlobalInt('STOCK_ALLOW_NEGATIVE_TRANSFER')) {

-											$stockMin = 0;

-										}

-										print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 1, 0, $line->fk_product, '', 1, 0, array(), 'minwidth200', '', 1, $stockMin, 'stock DESC, e.ref');

-

-										if ($tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id) {

+									$tmpentrepot_id = is_numeric(GETPOST($ent, 'int')) ?GETPOST($ent, 'int') : $warehouse_id;

+									if ($line->fk_product > 0)

+									{

+									    print '<!-- Show warehouse selection -->';

+

+                                        $stockMin = false;

+									    if (empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) {

+									        $stockMin = 0;

+									    }

+                                        print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 1, 0, $line->fk_product, '', 1, 0, array(), 'minwidth200', '', 1, $stockMin, 'stock DESC, e.ref');

+

+										if ($tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id)

+										{

@@ -1350 +1285,2 @@
-											if ($stock < $quantityToBeDelivered) {

+											if ($stock < $quantityToBeDelivered)

+											{

@@ -1355,2 +1291,4 @@
-								} else {

-									print '<span class="opacitymedium">('.$langs->trans("Service").')</span><input name="entl'.$indiceAsked.'" id="entl'.$indiceAsked.'" type="hidden" value="0">';

+								}

+								else

+								{

+									print $langs->trans("Service");

@@ -1360,3 +1298 @@
-							if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-								print '<td></td>';

-							} //StockEntrydate

+

@@ -1366 +1302,2 @@
-							if (getDolGlobalString('PRODUIT_SOUSPRODUITS') && $line->fk_product > 0) {

+							if (!empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0)

+							{

@@ -1369,2 +1306,4 @@
-								if (count($prods_arbo) > 0) {

-									foreach ($prods_arbo as $key => $value) {

+								if (count($prods_arbo) > 0)

+								{

+									foreach ($prods_arbo as $key => $value)

+									{

@@ -1373 +1312,2 @@
-										if ($value['stock'] < $value['stock_alert']) {

+										if ($value['stock'] < $value['stock_alert'])

+										{

@@ -1378,6 +1318,2 @@
-											</a> (".$value['nb'].")</td><td class=\"center\"> ".$value['nb_total']."</td><td>&nbsp;</td><td>&nbsp;</td>

-											<td class=\"center\">".$value['stock']." ".$img."</td>";

-										if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-											print '<td></td>';

-										} //StockEntrydate

-										print "</tr>";

+											</a> (".$value['nb'].")</td><td class=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>

+											<td class=\"center\">".$value['stock']." ".$img."</td></tr>";

@@ -1387,7 +1323,5 @@
-						} else {

-							// Product need lot

-							print '<td></td><td></td>';

-							if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-								print '<td></td>';

-							} //StockEntrydate

-							print '</tr>'; // end line and start a new one for lot/serial

+						}

+						else

+						{

+						    // Product need lot

+							print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial

@@ -1397,3 +1331 @@
-							if ($warehouse_id > 0) {

-								$staticwarehouse->fetch($warehouse_id);

-							}

+							if ($warehouse_id > 0) $staticwarehouse->fetch($warehouse_id);

@@ -1404,5 +1336,7 @@
-							if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch)) {

-								foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) {

-									$nbofsuggested++;

-								}

-							}

+							if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch))

+							{

+							    foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch)

+							    {

+							        $nbofsuggested++;

+							    }

+						    }

@@ -1410,2 +1344,4 @@
-							if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch)) {

-								foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) {	// $dbatch is instance of Productbatch

+							if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch))

+							{

+								foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch)	// $dbatch is instance of Productbatch

+								{

@@ -1415,33 +1351 @@
-

-									// Now we will check if we have to reduce the deliverableQty by taking into account the qty already suggested in previous line

-									if (isset($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)])) {

-										$deliverableQty = min($quantityToBeDelivered, $batchStock - $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)]);

-									} else {

-										if (!isset($alreadyQtyBatchSetted[$line->fk_product])) {

-											$alreadyQtyBatchSetted[$line->fk_product] = array();

-										}

-

-										if (!isset($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch])) {

-											$alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch] = array();

-										}

-

-										$deliverableQty = min($quantityToBeDelivered, $batchStock);

-									}

-

-									if ($deliverableQty < 0) $deliverableQty = 0;

-

-									$inputName = 'qtyl'.$indiceAsked.'_'.$subj;

-									if (GETPOSTISSET($inputName)) {

-										$deliverableQty = GETPOST($inputName, 'int');

-									}

-

-									$tooltipClass = $tooltipTitle = '';

-									if (!empty($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)])) {

-										$tooltipClass = ' classfortooltip';

-										$tooltipTitle = $langs->trans('StockQuantitiesAlreadyAllocatedOnPreviousLines').' : '.$alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)];

-									} else {

-										$alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)] = 0 ;

-									}

-									$alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)] = $deliverableQty + $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)];

-

-									print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested) ? 'oddeven' : '').'>';

+									print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested) ? $bc[$var] : '').'>';

@@ -1449 +1353 @@
-									print '<input class="qtyl '.$tooltipClass.' right" title="'.$tooltipTitle.'" name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$deliverableQty.'">';

+									print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$deliverableQty.'">';

@@ -1461,6 +1365,2 @@
-									if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && !empty($dbatch->sellby)) {

-										$detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day");

-									}

-									if (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && !empty($dbatch->eatby)) {

-										$detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby, "day");

-									}

+									$detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day");

+									$detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby, "day");

@@ -1472 +1372,2 @@
-									if ($quantityToBeDelivered < 0) {

+									if ($quantityToBeDelivered < 0)

+									{

@@ -1476,5 +1377 @@
-									print '</td>';

-									if (getDolGlobalInt('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-										print '<td>'.dol_print_date($dbatch->context['stock_entry_date'], 'day').'</td>'; //StockEntrydate

-									}

-									print '</tr>';

+									print '</td></tr>';

@@ -1482,13 +1379,11 @@
-							} else {

-								print '<!-- Case there is no details of lot at all -->';

-								print '<tr class="oddeven"><td colspan="3"></td><td class="center">';

-								print '<input class="qtyl right" name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0" disabled="disabled"> ';

-								print '</td>';

-

-								print '<td class="left">';

-								print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $staticwarehouse->label);

-								print '</td>';

-								if (getDolGlobalInt('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-									print '<td></td>';

-								} //StockEntrydate

-								print '</tr>';

+							}

+							else

+							{

+							    print '<!-- Case there is no details of lot at all -->';

+							    print '<tr class="oddeven"><td colspan="3"></td><td class="center">';

+							    print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0" disabled="disabled"> ';

+							    print '</td>';

+

+							    print '<td class="left">';

+							    print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $staticwarehouse->label);

+							    print '</td></tr>';

@@ -1497 +1392,3 @@
-					} else {

+					}

+					else

+					{

@@ -1499,7 +1396,4 @@
-						if (empty($conf->productbatch->enabled) || !$product->hasbatch()) {

-							print '<!-- Case warehouse not already known and product does not need lot -->';

-							print '<td></td><td></td>';

-							if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-								print '<td></td>';

-							}//StockEntrydate

-							print '</tr>'."\n"; // end line and start a new one for each warehouse

+						if (empty($conf->productbatch->enabled) || !$product->hasbatch())

+						{

+						    print '<!-- Case warehouse not already known and product does not need lot -->';

+						    print '<td></td><td></td></tr>'."\n"; // end line and start a new one for each warehouse

@@ -1509 +1403 @@
-							// Define nb of lines suggested for this order line

+	    					// Define nb of lines suggested for this order line

@@ -1511,5 +1405,6 @@
-

-							foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) {

-								if ($stock_warehouse->real > 0 || !empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) {

-									$nbofsuggested++;

-								}

+							foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)

+							{

+								if ($stock_warehouse->real > 0)

+								{

+	                                $nbofsuggested++;

+							    }

@@ -1518,7 +1413,2 @@
-							foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) {    // $stock_warehouse is product_stock

-								$var = $subj % 2;

-								if (!empty($warehousePicking) && !in_array($warehouse_id, $warehousePicking)) {

-									// if a warehouse was selected by user, picking is limited to this warehouse and his children

-									continue;

-								}

-

+							foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)    // $stock_warehouse is product_stock

+							{

@@ -1526 +1416,2 @@
-								if ($stock_warehouse->real > 0 || !empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) {

+								if ($stock_warehouse->real > 0)

+								{

@@ -1531 +1422 @@
-									print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested) ? 'oddeven' : '').'>';

+									print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested) ? $bc[$var] : '').'>';

@@ -1533,31 +1424,3 @@
-									if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {

-										if (isset($alreadyQtySetted[$line->fk_product][intval($warehouse_id)])) {

-											$deliverableQty = min($quantityToBeDelivered, $stock - $alreadyQtySetted[$line->fk_product][intval($warehouse_id)]);

-										} else {

-											if (!isset($alreadyQtySetted[$line->fk_product])) {

-												$alreadyQtySetted[$line->fk_product] = array();

-											}

-

-											$deliverableQty = min($quantityToBeDelivered, $stock);

-										}

-

-										if ($deliverableQty < 0) {

-											$deliverableQty = 0;

-										}

-

-										$tooltipClass = $tooltipTitle = '';

-										if (!empty($alreadyQtySetted[$line->fk_product][intval($warehouse_id)])) {

-											$tooltipClass = ' classfortooltip';

-											$tooltipTitle = $langs->trans('StockQuantitiesAlreadyAllocatedOnPreviousLines').' : '.$alreadyQtySetted[$line->fk_product][intval($warehouse_id)];

-										} else {

-											$alreadyQtySetted[$line->fk_product][intval($warehouse_id)] = 0;

-										}

-

-										$alreadyQtySetted[$line->fk_product][intval($warehouse_id)] = $deliverableQty + $alreadyQtySetted[$line->fk_product][intval($warehouse_id)];

-

-										$inputName = 'qtyl'.$indiceAsked.'_'.$subj;

-										if (GETPOSTISSET($inputName)) {

-											$deliverableQty = GETPOST($inputName, 'int');

-										}

-

-										print '<input class="qtyl'.$tooltipClass.' right" title="'.$tooltipTitle.'" name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';

+									if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))

+									{

+										print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'" type="text" size="4" value="'.$deliverableQty.'">';

@@ -1565,6 +1427,0 @@
-									} else {

-										if (getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) {

-											print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'" type="hidden" value="0">';

-										}

-

-										print $langs->trans("NA");

@@ -1571,0 +1429 @@
+									else print $langs->trans("NA");

@@ -1575 +1433,2 @@
-									if (isModEnabled('stock')) {

+									if (!empty($conf->stock->enabled))

+									{

@@ -1577 +1436,2 @@
-										if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {

+										if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))

+										{

@@ -1582,2 +1442,4 @@
-										} else {

-											print '<span class="opacitymedium">('.$langs->trans("Service").')</span>';

+										}

+										else

+										{

+											print $langs->trans("Service");

@@ -1588 +1450,2 @@
-									if ($quantityToBeDelivered < 0) {

+									if ($quantityToBeDelivered < 0)

+									{

@@ -1592,3 +1454,0 @@
-									if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-										print '<td></td>';

-									}//StockEntrydate

@@ -1599 +1459,2 @@
-							if (getDolGlobalString('PRODUIT_SOUSPRODUITS') && $line->fk_product > 0) {

+							if (!empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0)

+							{

@@ -1602,2 +1463,4 @@
-								if (count($prods_arbo) > 0) {

-									foreach ($prods_arbo as $key => $value) {

+								if (count($prods_arbo) > 0)

+								{

+									foreach ($prods_arbo as $key => $value)

+									{

@@ -1606 +1469,2 @@
-										if ($value['stock'] < $value['stock_alert']) {

+										if ($value['stock'] < $value['stock_alert'])

+										{

@@ -1612 +1476 @@
-										</a> (".$value['nb'].")</td><td class=\"center\"> ".$value['nb_total']."</td><td>&nbsp;</td><td>&nbsp;</td>

+										</a> (".$value['nb'].")</td><td class=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>

@@ -1614,3 +1477,0 @@
-										if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-											print '<td></td>';

-										}//StockEntrydate

@@ -1621,7 +1482,5 @@
-						} else {

-							print '<!-- Case warehouse not already known and product need lot -->';

-							print '<td></td><td></td>';

-							if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-								print '<td></td>';

-							}//StockEntrydate

-							print '</tr>'; // end line and start a new one for lot/serial

+						}

+						else

+						{

+						    print '<!-- Case warehouse not already known and product need lot -->';

+						    print '<td></td><td></td></tr>'; // end line and start a new one for lot/serial

@@ -1634 +1492,0 @@
-

@@ -1637,13 +1495,11 @@
-							foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) {

-								if (($stock_warehouse->real > 0 || !empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) && (count($stock_warehouse->detail_batch))) {

-									$nbofsuggested+=count($stock_warehouse->detail_batch);

-								}

-							}

-

-							foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) {

-								$var = $subj % 2;

-								if (!empty($warehousePicking) && !in_array($warehouse_id, $warehousePicking)) {

-									// if a warehouse was selected by user, picking is limited to this warehouse and his children

-									continue;

-								}

-

+							foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)

+							{

+							    if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) {

+							        foreach ($stock_warehouse->detail_batch as $dbatch)

+									{

+	                                    $nbofsuggested++;

+									}

+							    }

+							}

+							foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse)

+							{

@@ -1651,2 +1507,4 @@
-								if (($stock_warehouse->real > 0 || !empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) && (count($stock_warehouse->detail_batch))) {

-									foreach ($stock_warehouse->detail_batch as $dbatch) {

+								if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) {

+							        foreach ($stock_warehouse->detail_batch as $dbatch)

+									{

+										//var_dump($dbatch);

@@ -1654,34 +1512,4 @@
-										if (isset($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)])) {

-											$deliverableQty = min($quantityToBeDelivered, $batchStock - $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)]);

-										} else {

-											if (!isset($alreadyQtyBatchSetted[$line->fk_product])) {

-												$alreadyQtyBatchSetted[$line->fk_product] = array();

-											}

-

-											if (!isset($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch])) {

-												$alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch] = array();

-											}

-

-											$deliverableQty = min($quantityToBeDelivered, $batchStock);

-										}

-

-										if ($deliverableQty < 0) {

-											$deliverableQty = 0;

-										}

-

-										$inputName = 'qtyl'.$indiceAsked.'_'.$subj;

-										if (GETPOSTISSET($inputName)) {

-											$deliverableQty = GETPOST($inputName, 'int');

-										}

-

-										$tooltipClass = $tooltipTitle = '';

-										if (!empty($alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)])) {

-											$tooltipClass = ' classfortooltip';

-											$tooltipTitle = $langs->trans('StockQuantitiesAlreadyAllocatedOnPreviousLines').' : '.$alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)];

-										} else {

-											$alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)] = 0 ;

-										}

-										$alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)] = $deliverableQty + $alreadyQtyBatchSetted[$line->fk_product][$dbatch->batch][intval($warehouse_id)];

-

-										print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested) ? 'oddeven' : '').'><td colspan="3"></td><td class="center">';

-										print '<input class="qtyl right '.$tooltipClass.'" title="'.$tooltipTitle.'" name="'.$inputName.'" id="'.$inputName.'" type="text" size="4" value="'.$deliverableQty.'">';

+										$deliverableQty = min($quantityToBeDelivered, $batchStock);

+										if ($deliverableQty < 0) $deliverableQty = 0;

+										print '<!-- subj='.$subj.'/'.$nbofsuggested.' --><tr '.((($subj + 1) == $nbofsuggested) ? $bc[$var] : '').'><td colspan="3"></td><td class="center">';

+										print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="'.$deliverableQty.'">';

@@ -1700,11 +1528,2 @@
-										if ($result > 0) {

-											print $productlotObject->getNomUrl(1);

-										} else {

-											print $langs->trans("TableLotIncompleteRunRepairWithParamStandardEqualConfirmed");

-										}

-										if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY') && !empty($dbatch->sellby)) {

-											print ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day");

-										}

-										if (!getDolGlobalString('PRODUCT_DISABLE_EATBY') && !empty($dbatch->eatby)) {

-											print ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby, "day");

-										}

+										if ($result > 0) print $productlotObject->getNomUrl(1);

+										else print 'TableLotIncompleteRunRepairWithParamStandardEqualConfirmed';

@@ -1713 +1532,2 @@
-										if ($quantityToBeDelivered < 0) {

+										if ($quantityToBeDelivered < 0)

+										{

@@ -1718,5 +1538 @@
-										print '</td>';

-										if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-											print '<td class="left">'.dol_print_date($dbatch->context['stock_entry_date'], 'day').'</td>';

-										}

-										print '</tr>';

+										print '</td></tr>';

@@ -1727,20 +1543,16 @@
-						if ($subj == 0) { // Line not shown yet, we show it

-							$warehouse_selected_id = GETPOST('entrepot_id', 'int');

-

-							print '<!-- line not shown yet, we show it -->';

-							print '<tr class="oddeven"><td colspan="3"></td><td class="center">';

-

-							if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {

-								$disabled = '';

-								if (isModEnabled('productbatch') && $product->hasbatch()) {

-									$disabled = 'disabled="disabled"';

-								}

-								if ($warehouse_selected_id <= 0) {		// We did not force a given warehouse, so we won't have no warehouse to change qty.

-									$disabled = 'disabled="disabled"';

-								}

-								print '<input class="qtyl right" name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0"'.($disabled ? ' '.$disabled : '').'> ';

-								if (empty($disabled) && getDolGlobalString('STOCK_ALLOW_NEGATIVE_TRANSFER')) {

-									print '<input name="ent1' . $indiceAsked . '_' . $subj . '" type="hidden" value="' . $warehouse_selected_id . '">';

-								}

-							} else {

-								print $langs->trans("NA");

+						if ($subj == 0) // Line not shown yet, we show it

+						{

+						    print '<!-- line not shown yet, we show it -->';

+							print '<tr class="oddeven"><td colspan="3" ></td><td class="center">';

+							if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))

+							{

+							    $disabled = '';

+						        if (!empty($conf->productbatch->enabled) && $product->hasbatch())

+						        {

+	                                $disabled = 'disabled="disabled"';

+							    }

+	    						print '<input name="qtyl'.$indiceAsked.'_'.$subj.'" id="qtyl'.$indiceAsked.'_'.$subj.'" type="text" size="4" value="0"'.($disabled ? ' '.$disabled : '').'> ';

+							}

+							else

+							{

+							    print $langs->trans("NA");

@@ -1751,14 +1563,18 @@
-							if ($line->product_type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {

-								if ($warehouse_selected_id > 0) {

-									$warehouseObject = new Entrepot($db);

-									$warehouseObject->fetch($warehouse_selected_id);

-									print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $warehouseObject->label);

-								} else {

-									if ($line->fk_product) {

-										print img_warning().' '.$langs->trans("StockTooLow");

-									} else {

-										print '';

-									}

-								}

-							} else {

-								print '<span class="opacitymedium">('.$langs->trans("Service").')</span>';

+							if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES))

+							{

+								$warehouse_selected_id = GETPOST('entrepot_id', 'int');

+	    						if ($warehouse_selected_id > 0)

+	    						{

+	    							$warehouseObject = new Entrepot($db);

+	    							$warehouseObject->fetch($warehouse_selected_id);

+	    							print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $warehouseObject->label);

+	    						}

+	    						else

+	    						{

+	    						    if ($line->fk_product) print img_warning().' '.$langs->trans("StockTooLow");

+	    						    else print '';

+	    						}

+							}

+							else

+							{

+							    print $langs->trans("Service");

@@ -1767,3 +1582,0 @@
-							if (getDolGlobalString('SHIPPING_DISPLAY_STOCK_ENTRY_DATE')) {

-								print '<td></td>';

-							}//StockEntrydate

@@ -1774,3 +1587,3 @@
-					// Display lines for extrafields of the Shipment line

-					// $line is a 'Order line'

-					if (!empty($extrafields)) {

+					// Line extrafield

+					if (!empty($extrafields))

+					{

@@ -1784,2 +1597 @@
-

-						$expLine->array_options = array_merge($expLine->array_options, $srcLine->array_options);

+						$line->array_options = array_merge($line->array_options, $srcLine->array_options);

@@ -1789,11 +1601,234 @@
-				}

-

-				$indiceAsked++;

-			}

-

-			print "</table>";

-

-			print '<br>';

-

-			print $form->buttonsSaveCancel("Create");

-

+                }

+

+	            $indiceAsked++;

+            }

+

+            print "</table>";

+

+            print '<br>';

+

+            print '<div class="center">';

+            print '<input type="submit" class="button" name="add" value="'.dol_escape_htmltag($langs->trans("Create")).'">';

+            print '&nbsp; ';

+            print '<input type="'.($backtopage ? "submit" : "button").'" class="button" 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

+            print '</div>';

+

+            print '</form>';

+

+            print '<br>';

+        }

+        else

+		{

+            dol_print_error($db);

+        }

+    }

+}

+elseif ($id || $ref)

+/* *************************************************************************** */

+/*                                                                             */

+/* Edit and view mode                                                          */

+/*                                                                             */

+/* *************************************************************************** */

+{

+	$lines = $object->lines;

+

+	$num_prod = count($lines);

+

+	if ($object->id > 0)

+	{

+		if (!empty($object->origin) && $object->origin_id > 0)

+		{

+			$typeobject = $object->origin;

+			$origin = $object->origin;

+			$origin_id = $object->origin_id;

+			$object->fetch_origin(); // Load property $object->commande, $object->propal, ...

+		}

+

+		$soc = new Societe($db);

+		$soc->fetch($object->socid);

+

+		$res = $object->fetch_optionals();

+

+		$head = shipping_prepare_head($object);

+		dol_fiche_head($head, 'shipping', $langs->trans("Shipment"), -1, 'sending');

+

+		$formconfirm = '';

+

+		// Confirm deleteion

+		if ($action == 'delete')

+		{

+		    $formquestion = array();

+		    if ($object->statut == Expedition::STATUS_CLOSED && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) {

+		        $formquestion = array(

+                        array(

+                            'label' => $langs->trans('ShipmentIncrementStockOnDelete'),

+                            'name' => 'alsoUpdateStock',

+                            'type' => 'checkbox',

+                            'value' => 0

+                        ),

+                    );

+            }

+		    $formconfirm = $form->formconfirm(

+			    $_SERVER['PHP_SELF'].'?id='.$object->id,

+                $langs->trans('DeleteSending'),

+                $langs->trans("ConfirmDeleteSending", $object->ref),

+                'confirm_delete',

+                $formquestion,

+                0,

+                1

+            );

+		}

+

+		// Confirmation validation

+		if ($action == 'valid')

+		{

+			$objectref = substr($object->ref, 1, 4);

+			if ($objectref == 'PROV')

+			{

+				$numref = $object->getNextNumRef($soc);

+			}

+			else

+			{

+				$numref = $object->ref;

+			}

+

+			$text = $langs->trans("ConfirmValidateSending", $numref);

+

+			if (!empty($conf->notification->enabled))

+			{

+				require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';

+				$notify = new Notify($db);

+				$text .= '<br>';

+				$text .= $notify->confirmMessage('SHIPPING_VALIDATE', $object->socid, $object);

+			}

+

+			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateSending'), $text, 'confirm_valid', '', 0, 1);

+		}

+		// Confirm cancelation

+		if ($action == 'cancel')

+		{

+			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelSending'), $langs->trans("ConfirmCancelSending", $object->ref), 'confirm_cancel', '', 0, 1);

+		}

+

+		// Call Hook formConfirm

+		$parameters = array('formConfirm' => $formconfirm);

+		$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+		if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;

+		elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;

+

+		// Print form confirm

+		print $formconfirm;

+

+		// Calculate totalWeight and totalVolume for all products

+		// by adding weight and volume of each product line.

+		$tmparray = $object->getTotalWeightVolume();

+		$totalWeight = $tmparray['weight'];

+		$totalVolume = $tmparray['volume'];

+

+

+		if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))

+		{

+		    $objectsrc = new Commande($db);

+		    $objectsrc->fetch($object->$typeobject->id);

+		}

+		if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))

+		{

+		    $objectsrc = new Propal($db);

+		    $objectsrc->fetch($object->$typeobject->id);

+		}

+

+		// Shipment card

+		$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';

+		$morehtmlref = '<div class="refidno">';

+		// Ref customer shipment

+		$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);

+		$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);

+		// Thirdparty

+        $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);

+        // Project

+        if (!empty($conf->projet->enabled)) {

+            $langs->load("projects");

+            $morehtmlref .= '<br>'.$langs->trans('Project').' ';

+            if (0) {    // Do not change on shipment

+                if ($action != 'classify') {

+                    $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';

+                }

+                if ($action == 'classify') {

+                    // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);

+                    $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

+                    $morehtmlref .= '<input type="hidden" name="action" value="classin">';

+                    $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';

+                    $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);

+                    $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';

+                    $morehtmlref .= '</form>';

+                } else {

+                    $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);

+                }

+            } else {

+                // We don't have project on shipment, so we will use the project or source object instead

+                // TODO Add project on shipment

+                $morehtmlref .= ' : ';

+                if (!empty($objectsrc->fk_project)) {

+                    $proj = new Project($db);

+                    $proj->fetch($objectsrc->fk_project);

+                    $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';

+                    $morehtmlref .= $proj->ref;

+                    $morehtmlref .= '</a>';

+                } else {

+                    $morehtmlref .= '';

+                }

+            }

+        }

+		$morehtmlref .= '</div>';

+

+

+    	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);

+

+

+    	print '<div class="fichecenter">';

+    	print '<div class="fichehalfleft">';

+    	print '<div class="underbanner clearboth"></div>';

+

+        print '<table class="border tableforfield" width="100%">';

+

+		// Linked documents

+		if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))

+		{

+			print '<tr><td>';

+			print $langs->trans("RefOrder").'</td>';

+			print '<td colspan="3">';

+			print $objectsrc->getNomUrl(1, 'commande');

+			print "</td>\n";

+			print '</tr>';

+		}

+		if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))

+		{

+			print '<tr><td>';

+			print $langs->trans("RefProposal").'</td>';

+			print '<td colspan="3">';

+			print $objectsrc->getNomUrl(1, 'expedition');

+			print "</td>\n";

+			print '</tr>';

+		}

+

+		// Date creation

+		print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';

+		print '<td colspan="3">'.dol_print_date($object->date_creation, "dayhour")."</td>\n";

+		print '</tr>';

+

+		// Delivery date planned

+		print '<tr><td height="10">';

+		print '<table class="nobordernopadding" width="100%"><tr><td>';

+		print $langs->trans('DateDeliveryPlanned');

+		print '</td>';

+

+		if ($action != 'editdate_livraison') 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>';

+		print '</tr></table>';

+		print '</td><td colspan="2">';

+		if ($action == 'editdate_livraison')

+		{

+			print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';

+			print '<input type="hidden" name="token" value="'.newToken().'">';

+			print '<input type="hidden" name="action" value="setdate_livraison">';

+			print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0);

+			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';

@@ -1801,158 +1836,9 @@
-

-			print '<br>';

-		} else {

-			dol_print_error($db);

-		}

-	}

-} elseif ($object->id > 0) {

-	/* *************************************************************************** */

-	/*                                                                             */

-	/* Edit and view mode                                                          */

-	/*                                                                             */

-	/* *************************************************************************** */

-	$lines = $object->lines;

-

-	$num_prod = count($lines);

-

-	if (!empty($object->origin) && $object->origin_id > 0) {

-		$typeobject = $object->origin;

-		$origin = $object->origin;

-		$origin_id = $object->origin_id;

-

-		$object->fetch_origin(); // Load property $object->origin_object (old $object->commande, $object->propal, ...)

-	}

-

-	$soc = new Societe($db);

-	$soc->fetch($object->socid);

-

-	$res = $object->fetch_optionals();

-

-	$head = shipping_prepare_head($object);

-	print dol_get_fiche_head($head, 'shipping', $langs->trans("Shipment"), -1, $object->picto);

-

-	$formconfirm = '';

-

-	// Confirm deletion

-	if ($action == 'delete') {

-		$formquestion = array();

-		if ($object->statut == Expedition::STATUS_CLOSED && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {

-			$formquestion = array(

-					array(

-						'label' => $langs->trans('ShipmentIncrementStockOnDelete'),

-						'name' => 'alsoUpdateStock',

-						'type' => 'checkbox',

-						'value' => 0

-					),

-				);

-		}

-		$formconfirm = $form->formconfirm(

-			$_SERVER['PHP_SELF'].'?id='.$object->id,

-			$langs->trans('DeleteSending'),

-			$langs->trans("ConfirmDeleteSending", $object->ref),

-			'confirm_delete',

-			$formquestion,

-			0,

-			1

-		);

-	}

-

-	// Confirmation validation

-	if ($action == 'valid') {

-		$objectref = substr($object->ref, 1, 4);

-		if ($objectref == 'PROV') {

-			$numref = $object->getNextNumRef($soc);

-		} else {

-			$numref = $object->ref;

-		}

-

-		$text = $langs->trans("ConfirmValidateSending", $numref);

-		if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) {

-			$text .= '<br>'.img_picto('', 'movement', 'class="pictofixedwidth"').$langs->trans("StockMovementWillBeRecorded").'.';

-		} elseif (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) {

-			$text .= '<br>'.img_picto('', 'movement', 'class="pictofixedwidth"').$langs->trans("StockMovementNotYetRecorded").'.';

-		}

-

-		if (isModEnabled('notification')) {

-			require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';

-			$notify = new Notify($db);

-			$text .= '<br>';

-			$text .= $notify->confirmMessage('SHIPPING_VALIDATE', $object->socid, $object);

-		}

-

-		$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateSending'), $text, 'confirm_valid', '', 0, 1, 250);

-	}

-	// Confirm cancelation

-	if ($action == 'cancel') {

-		$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelSending'), $langs->trans("ConfirmCancelSending", $object->ref), 'confirm_cancel', '', 0, 1);

-	}

-

-	// Call Hook formConfirm

-	$parameters = array('formConfirm' => $formconfirm);

-	$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-	if (empty($reshook)) {

-		$formconfirm .= $hookmanager->resPrint;

-	} elseif ($reshook > 0) {

-		$formconfirm = $hookmanager->resPrint;

-	}

-

-	// Print form confirm

-	print $formconfirm;

-

-	// Calculate totalWeight and totalVolume for all products

-	// by adding weight and volume of each product line.

-	$tmparray = $object->getTotalWeightVolume();

-	$totalWeight = $tmparray['weight'];

-	$totalVolume = $tmparray['volume'];

-

-	if (!empty($typeobject) && $typeobject === 'commande' && is_object($object->$typeobject) && $object->$typeobject->id && isModEnabled('commande')) {

-		$objectsrc = new Commande($db);

-		$objectsrc->fetch($object->$typeobject->id);

-	}

-	if (!empty($typeobject) && $typeobject === 'propal' && is_object($object->$typeobject) && $object->$typeobject->id && isModEnabled("propal")) {

-		$objectsrc = new Propal($db);

-		$objectsrc->fetch($object->$typeobject->id);

-	}

-

-	// Shipment card

-	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';

-	$morehtmlref = '<div class="refidno">';

-	// Ref customer shipment

-	$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string', '', 0, 1);

-	$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':' . getDolGlobalString('THIRDPARTY_REF_INPUT_SIZE') : ''), '', null, null, '', 1);

-	// Thirdparty

-	$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);

-	// Project

-	if (isModEnabled('project')) {

-		$langs->load("projects");

-		$morehtmlref .= '<br>';

-		if (0) {	// Do not change on shipment

-			$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');

-			if ($action != 'classify') {

-				$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';

-			}

-			$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');

-		} else {

-			if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {

-				$proj = new Project($db);

-				$proj->fetch($objectsrc->fk_project);

-				$morehtmlref .= $proj->getNomUrl(1);

-				if ($proj->title) {

-					$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';

-				}

-			}

-		}

-	}

-	$morehtmlref .= '</div>';

-

-

-	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);

-

-

-	print '<div class="fichecenter">';

-	print '<div class="fichehalfleft">';

-	print '<div class="underbanner clearboth"></div>';

-

-	print '<table class="border tableforfield centpercent">';

-

-	// Linked documents

-	if (!empty($typeobject) && $typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {

+		}

+		else

+		{

+			print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';

+		}

+		print '</td>';

+		print '</tr>';

+

+		// Weight

@@ -1960 +1846,68 @@
-		print $langs->trans("RefOrder").'</td>';

+		print $form->editfieldkey("Weight", 'trueWeight', $object->trueWeight, $object, $user->rights->expedition->creer);

+		print '</td><td colspan="3">';

+

+		if ($action == 'edittrueWeight')

+		{

+			print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';

+			print '<input name="action" value="settrueWeight" type="hidden">';

+			print '<input name="id" value="'.$object->id.'" type="hidden">';

+			print '<input type="hidden" name="token" value="'.newToken().'">';

+			print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text" class="width50">';

+			print $formproduct->selectMeasuringUnits("weight_units", "weight", $object->weight_units, 0, 2);

+			print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';

+			print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';

+			print '</form>';

+		}

+		else

+		{

+			print $object->trueWeight;

+			print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : '';

+		}

+

+        // Calculated

+		if ($totalWeight > 0)

+		{

+			if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': ';

+			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');

+			if (!empty($object->trueWeight)) print ')';

+		}

+		print '</td></tr>';

+

+		// Width

+		print '<tr><td>'.$form->editfieldkey("Width", 'trueWidth', $object->trueWidth, $object, $user->rights->expedition->creer).'</td><td colspan="3">';

+		print $form->editfieldval("Width", 'trueWidth', $object->trueWidth, $object, $user->rights->expedition->creer);

+		print ($object->trueWidth && $object->width_units != '') ? ' '.measuringUnitString(0, "size", $object->width_units) : '';

+		print '</td></tr>';

+

+		// Height

+		print '<tr><td>'.$form->editfieldkey("Height", 'trueHeight', $object->trueHeight, $object, $user->rights->expedition->creer).'</td><td colspan="3">';

+		if ($action == 'edittrueHeight')

+		{

+			print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';

+			print '<input name="action" value="settrueHeight" type="hidden">';

+			print '<input name="id" value="'.$object->id.'" type="hidden">';

+			print '<input type="hidden" name="token" value="'.newToken().'">';

+			print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text" class="width50">';

+			print $formproduct->selectMeasuringUnits("size_units", "size", $object->size_units, 0, 2);

+			print ' <input class="button" name="modify" value="'.$langs->trans("Modify").'" type="submit">';

+			print ' <input class="button" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';

+			print '</form>';

+		}

+		else

+		{

+			print $object->trueHeight;

+			print ($object->trueHeight && $object->height_units != '') ? ' '.measuringUnitString(0, "size", $object->height_units) : '';

+		}

+

+		print '</td></tr>';

+

+		// Depth

+		print '<tr><td>'.$form->editfieldkey("Depth", 'trueDepth', $object->trueDepth, $object, $user->rights->expedition->creer).'</td><td colspan="3">';

+		print $form->editfieldval("Depth", 'trueDepth', $object->trueDepth, $object, $user->rights->expedition->creer);

+		print ($object->trueDepth && $object->depth_units != '') ? ' '.measuringUnitString(0, "size", $object->depth_units) : '';

+		print '</td></tr>';

+

+		// Volume

+		print '<tr><td>';

+		print $langs->trans("Volume");

+		print '</td>';

@@ -1962 +1915,23 @@
-		print $objectsrc->getNomUrl(1, 'commande');

+		$calculatedVolume = 0;

+		$volumeUnit = 0;

+		if ($object->trueWidth && $object->trueHeight && $object->trueDepth)

+		{

+		    $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);

+		    $volumeUnit = $object->size_units * 3;

+		}

+		// If sending volume not defined we use sum of products

+		if ($calculatedVolume > 0)

+		{

+			if ($volumeUnit < 50)

+			{

+			    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');

+			}

+			else print $calculatedVolume.' '.measuringUnitString(0, "volume", $volumeUnit);

+		}

+		if ($totalVolume > 0)

+		{

+			if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': ';

+			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');

+			//if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';

+			if ($calculatedVolume) print ')';

+		}

@@ -1965,7 +1940,44 @@
-	}

-	if (!empty($typeobject) && $typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {

-		print '<tr><td>';

-		print $langs->trans("RefProposal").'</td>';

-		print '<td colspan="3">';

-		print $objectsrc->getNomUrl(1, 'expedition');

-		print "</td>\n";

+

+		// Other attributes

+		$cols = 2;

+		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';

+

+		print '</table>';

+

+		print '</div>';

+		print '<div class="fichehalfright">';

+		print '<div class="ficheaddleft">';

+		print '<div class="underbanner clearboth"></div>';

+

+		print '<table class="border centpercent">';

+

+		// Sending method

+		print '<tr><td height="10">';

+		print '<table class="nobordernopadding" width="100%"><tr><td>';

+		print $langs->trans('SendingMethod');

+		print '</td>';

+

+		if ($action != 'editshipping_method_id') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&amp;id='.$object->id.'">'.img_edit($langs->trans('SetSendingMethod'), 1).'</a></td>';

+		print '</tr></table>';

+		print '</td><td colspan="2">';

+		if ($action == 'editshipping_method_id')

+		{

+			print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';

+			print '<input type="hidden" name="token" value="'.newToken().'">';

+			print '<input type="hidden" name="action" value="setshipping_method_id">';

+			$object->fetch_delivery_methods();

+			print $form->selectarray("shipping_method_id", $object->meths, $object->shipping_method_id, 1, 0, 0, "", 1);

+			if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);

+			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';

+			print '</form>';

+		}

+		else

+		{

+			if ($object->shipping_method_id > 0)

+			{

+				// Get code using getLabelFromKey

+				$code = $langs->getLabelFromKey($db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');

+				print $langs->trans("SendingMethod".strtoupper($code));

+			}

+		}

+		print '</td>';

@@ -1973,194 +1985,4 @@
-	}

-

-	// Date creation

-	print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';

-	print '<td colspan="3">'.dol_print_date($object->date_creation, "dayhour")."</td>\n";

-	print '</tr>';

-

-	// Delivery date planned

-	print '<tr><td height="10">';

-	print '<table class="nobordernopadding centpercent"><tr><td>';

-	print $langs->trans('DateDeliveryPlanned');

-	print '</td>';

-

-	if ($action != 'editdate_livraison') {

-		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>';

-	}

-	print '</tr></table>';

-	print '</td><td colspan="2">';

-	if ($action == 'editdate_livraison') {

-		print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';

-		print '<input type="hidden" name="token" value="'.newToken().'">';

-		print '<input type="hidden" name="action" value="setdate_livraison">';

-		print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0);

-		print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';

-		print '</form>';

-	} else {

-		print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';

-	}

-	print '</td>';

-	print '</tr>';

-

-	// Weight

-	print '<tr><td>';

-	print $form->editfieldkey("Weight", 'trueWeight', $object->trueWeight, $object, $user->hasRight('expedition', 'creer'));

-	print '</td><td colspan="3">';

-

-	if ($action == 'edittrueWeight') {

-		print '<form name="settrueweight" action="'.$_SERVER["PHP_SELF"].'" method="post">';

-		print '<input name="action" value="settrueWeight" type="hidden">';

-		print '<input name="id" value="'.$object->id.'" type="hidden">';

-		print '<input type="hidden" name="token" value="'.newToken().'">';

-		print '<input id="trueWeight" name="trueWeight" value="'.$object->trueWeight.'" type="text" class="width50 valignmiddle">';

-		print $formproduct->selectMeasuringUnits("weight_units", "weight", $object->weight_units, 0, 2, 'maxwidth125 valignmiddle');

-		print ' <input class="button smallpaddingimp valignmiddle" name="modify" value="'.$langs->trans("Modify").'" type="submit">';

-		print ' <input class="button button-cancel smallpaddingimp valignmiddle" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';

-		print '</form>';

-	} else {

-		print $object->trueWeight;

-		print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : '';

-	}

-

-	// Calculated

-	if ($totalWeight > 0) {

-		if (!empty($object->trueWeight)) {

-			print ' ('.$langs->trans("SumOfProductWeights").': ';

-		}

-		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');

-		if (!empty($object->trueWeight)) {

-			print ')';

-		}

-	}

-	print '</td></tr>';

-

-	// Width

-	print '<tr><td>'.$form->editfieldkey("Width", 'trueWidth', $object->trueWidth, $object, $user->hasRight('expedition', 'creer')).'</td><td colspan="3">';

-	print $form->editfieldval("Width", 'trueWidth', $object->trueWidth, $object, $user->hasRight('expedition', 'creer'));

-	print ($object->trueWidth && $object->width_units != '') ? ' '.measuringUnitString(0, "size", $object->width_units) : '';

-	print '</td></tr>';

-

-	// Height

-	print '<tr><td>'.$form->editfieldkey("Height", 'trueHeight', $object->trueHeight, $object, $user->hasRight('expedition', 'creer')).'</td><td colspan="3">';

-	if ($action == 'edittrueHeight') {

-		print '<form name="settrueHeight" action="'.$_SERVER["PHP_SELF"].'" method="post">';

-		print '<input name="action" value="settrueHeight" type="hidden">';

-		print '<input name="id" value="'.$object->id.'" type="hidden">';

-		print '<input type="hidden" name="token" value="'.newToken().'">';

-		print '<input id="trueHeight" name="trueHeight" value="'.$object->trueHeight.'" type="text" class="width50">';

-		print $formproduct->selectMeasuringUnits("size_units", "size", $object->size_units, 0, 2);

-		print ' <input class="button smallpaddingimp" name="modify" value="'.$langs->trans("Modify").'" type="submit">';

-		print ' <input class="button button-cancel smallpaddingimp" name="cancel" value="'.$langs->trans("Cancel").'" type="submit">';

-		print '</form>';

-	} else {

-		print $object->trueHeight;

-		print ($object->trueHeight && $object->height_units != '') ? ' '.measuringUnitString(0, "size", $object->height_units) : '';

-	}

-

-	print '</td></tr>';

-

-	// Depth

-	print '<tr><td>'.$form->editfieldkey("Depth", 'trueDepth', $object->trueDepth, $object, $user->hasRight('expedition', 'creer')).'</td><td colspan="3">';

-	print $form->editfieldval("Depth", 'trueDepth', $object->trueDepth, $object, $user->hasRight('expedition', 'creer'));

-	print ($object->trueDepth && $object->depth_units != '') ? ' '.measuringUnitString(0, "size", $object->depth_units) : '';

-	print '</td></tr>';

-

-	// Volume

-	print '<tr><td>';

-	print $langs->trans("Volume");

-	print '</td>';

-	print '<td colspan="3">';

-	$calculatedVolume = 0;

-	$volumeUnit = 0;

-	if ($object->trueWidth && $object->trueHeight && $object->trueDepth) {

-		$calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth);

-		$volumeUnit = $object->size_units * 3;

-	}

-	// If sending volume not defined we use sum of products

-	if ($calculatedVolume > 0) {

-		if ($volumeUnit < 50) {

-			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');

-		} else {

-			print $calculatedVolume.' '.measuringUnitString(0, "volume", $volumeUnit);

-		}

-	}

-	if ($totalVolume > 0) {

-		if ($calculatedVolume) {

-			print ' ('.$langs->trans("SumOfProductVolumes").': ';

-		}

-		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');

-		//if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')';

-		if ($calculatedVolume) {

-			print ')';

-		}

-	}

-	print "</td>\n";

-	print '</tr>';

-

-	// Other attributes

-	$cols = 2;

-	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';

-

-	print '</table>';

-

-	print '</div>';

-	print '<div class="fichehalfright">';

-	print '<div class="underbanner clearboth"></div>';

-

-	print '<table class="border centpercent tableforfield">';

-

-	// Sending method

-	print '<tr><td height="10">';

-	print '<table class="nobordernopadding centpercent"><tr><td>';

-	print $langs->trans('SendingMethod');

-	print '</td>';

-

-	if ($action != 'editshipping_method_id') {

-		print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshipping_method_id&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetSendingMethod'), 1).'</a></td>';

-	}

-	print '</tr></table>';

-	print '</td><td colspan="2">';

-	if ($action == 'editshipping_method_id') {

-		print '<form name="setshipping_method_id" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';

-		print '<input type="hidden" name="token" value="'.newToken().'">';

-		print '<input type="hidden" name="action" value="setshipping_method_id">';

-		$object->fetch_delivery_methods();

-		print $form->selectarray("shipping_method_id", $object->meths, $object->shipping_method_id, 1, 0, 0, "", 1);

-		if ($user->admin) {

-			print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);

-		}

-		print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';

-		print '</form>';

-	} else {

-		if ($object->shipping_method_id > 0) {

-			// Get code using getLabelFromKey

-			$code = $langs->getLabelFromKey($db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');

-			print $langs->trans("SendingMethod".strtoupper($code));

-		}

-	}

-	print '</td>';

-	print '</tr>';

-

-	// Tracking Number

-	print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber", 'tracking_number', $object->tracking_number, $object, $user->hasRight('expedition', 'creer')).'</td><td colspan="3">';

-	print $form->editfieldval("TrackingNumber", 'tracking_number', $object->tracking_url, $object, $user->hasRight('expedition', 'creer'), 'safehtmlstring', $object->tracking_number);

-	print '</td></tr>';

-

-	// Incoterms

-	if (isModEnabled('incoterm')) {

-		print '<tr><td>';

-		print '<table width="100%" class="nobordernopadding"><tr><td>';

-		print $langs->trans('IncotermLabel');

-		print '<td><td class="right">';

-		if ($user->hasRight('expedition', 'creer')) {

-			print '<a class="editfielda" href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';

-		} else {

-			print '&nbsp;';

-		}

-		print '</td></tr></table>';

-		print '</td>';

-		print '<td colspan="3">';

-		if ($action != 'editincoterm') {

-			print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);

-		} else {

-			print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);

-		}

+

+		// Tracking Number

+		print '<tr><td class="titlefield">'.$form->editfieldkey("TrackingNumber", 'tracking_number', $object->tracking_number, $object, $user->rights->expedition->creer).'</td><td colspan="3">';

+		print $form->editfieldval("TrackingNumber", 'tracking_number', $object->tracking_url, $object, $user->rights->expedition->creer, 'safehtmlstring', $object->tracking_number);

@@ -2168,139 +1990,197 @@
-	}

-

-	// Other attributes

-	$parameters = array('colspan' => ' colspan="3"', 'cols' => '3');

-	$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-	print $hookmanager->resPrint;

-

-	print "</table>";

-

-	print '</div>';

-	print '</div>';

-

-	print '<div class="clearboth"></div>';

-

-

-	// Lines of products

-

-	if ($action == 'editline') {

-		print '	<form name="updateline" id="updateline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;lineid='.$line_id.'" method="POST">

-		<input type="hidden" name="token" value="' . newToken().'">

-		<input type="hidden" name="action" value="updateline">

-		<input type="hidden" name="mode" value="">

-		<input type="hidden" name="id" value="' . $object->id.'">

-		';

-	}

-	print '<br>';

-

-	print '<div class="div-table-responsive-no-min">';

-	print '<table class="noborder" width="100%" id="tablelines" >';

-	print '<thead>';

-	print '<tr class="liste_titre">';

-	// Adds a line numbering column

-	if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {

-		print '<td width="5" class="center linecolnum">&nbsp;</td>';

-	}

-	// Product/Service

-	print '<td  class="linecoldescription" >'.$langs->trans("Products").'</td>';

-	// Qty

-	print '<td class="center linecolqty">'.$langs->trans("QtyOrdered").'</td>';

-	if ($origin && $origin_id > 0) {

-		print '<td class="center linecolqtyinothershipments">'.$langs->trans("QtyInOtherShipments").'</td>';

-	}

-	if ($action == 'editline') {

-		$editColspan = 3;

-		if (!isModEnabled('stock')) {

-			$editColspan--;

-		}

-		if (empty($conf->productbatch->enabled)) {

-			$editColspan--;

-		}

-		print '<td class="center linecoleditlineotherinfo" colspan="'.$editColspan.'">';

-		if ($object->statut <= 1) {

-			print $langs->trans("QtyToShip").' - ';

-		} else {

-			print $langs->trans("QtyShipped").' - ';

-		}

-		if (isModEnabled('stock')) {

-			print $langs->trans("WarehouseSource").' - ';

-		}

-		if (isModEnabled('productbatch')) {

-			print $langs->trans("Batch");

-		}

-		print '</td>';

-	} else {

-		if ($object->statut <= 1) {

-			print '<td class="center linecolqtytoship">'.$langs->trans("QtyToShip").'</td>';

-		} else {

-			print '<td class="center linecolqtyshipped">'.$langs->trans("QtyShipped").'</td>';

-		}

-		if (isModEnabled('stock')) {

-			print '<td class="left linecolwarehousesource">'.$langs->trans("WarehouseSource").'</td>';

-		}

-

-		if (isModEnabled('productbatch')) {

-			print '<td class="left linecolbatch">'.$langs->trans("Batch").'</td>';

-		}

-	}

-	print '<td class="center linecolweight">'.$langs->trans("CalculatedWeight").'</td>';

-	print '<td class="center linecolvolume">'.$langs->trans("CalculatedVolume").'</td>';

-	//print '<td class="center">'.$langs->trans("Size").'</td>';

-	if ($object->statut == 0) {

-		print '<td class="linecoledit"></td>';

-		print '<td class="linecoldelete" width="10"></td>';

-	}

-	print "</tr>\n";

-	print '</thead>';

-

-	$outputlangs = $langs;

-

-	if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {

-		$object->fetch_thirdparty();

-		$newlang = '';

-		if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {

-			$newlang = GETPOST('lang_id', 'aZ09');

-		}

-		if (empty($newlang)) {

-			$newlang = $object->thirdparty->default_lang;

-		}

-		if (!empty($newlang)) {

-			$outputlangs = new Translate("", $conf);

-			$outputlangs->setDefaultLang($newlang);

-		}

-	}

-

-	// Get list of products already sent for same source object into $alreadysent

-	$alreadysent = array();

-	if ($origin && $origin_id > 0) {

-		$sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.fk_unit, obj.date_start, obj.date_end";

-		$sql .= ", ed.rowid as shipmentline_id, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line, ed.fk_entrepot";

-		$sql .= ", e.rowid as shipment_id, e.ref as shipment_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_expedition";

-		//if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";

-		$sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tosell as product_tosell, p.tobuy as product_tobuy, p.tobatch as product_tobatch';

-		$sql .= ', p.description as product_desc';

-		$sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";

-		$sql .= ", ".MAIN_DB_PREFIX."expedition as e";

-		$sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj";

-		//if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."deliverydet as ld ON ld.fk_delivery = l.rowid  AND obj.rowid = ld.fk_origin_line";

-		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";

-		$sql .= " WHERE e.entity IN (".getEntity('expedition').")";

-		$sql .= " AND obj.fk_".$origin." = ".((int) $origin_id);

-		$sql .= " AND obj.rowid = ed.fk_origin_line";

-		$sql .= " AND ed.fk_expedition = e.rowid";

-		//if ($filter) $sql.= $filter;

-		$sql .= " ORDER BY obj.fk_product";

-

-		dol_syslog("expedition/card.php get list of shipment lines", LOG_DEBUG);

-		$resql = $db->query($sql);

-		if ($resql) {

-			$num = $db->num_rows($resql);

-			$i = 0;

-

-			while ($i < $num) {

-				$obj = $db->fetch_object($resql);

-				if ($obj) {

-					// $obj->rowid is rowid in $origin."det" table

-					$alreadysent[$obj->rowid][$obj->shipmentline_id] = array(

-						'shipment_ref'=>$obj->shipment_ref, 'shipment_id'=>$obj->shipment_id, 'warehouse'=>$obj->fk_entrepot, 'qty_shipped'=>$obj->qty_shipped,

-						'product_tosell'=>$obj->product_tosell, 'product_tobuy'=>$obj->product_tobuy, 'product_tobatch'=>$obj->product_tobatch,

-						'date_valid'=>$db->jdate($obj->date_valid), 'date_delivery'=>$db->jdate($obj->date_delivery));

+

+		// Incoterms

+		if (!empty($conf->incoterm->enabled))

+		{

+			print '<tr><td>';

+	        print '<table width="100%" class="nobordernopadding"><tr><td>';

+	        print $langs->trans('IncotermLabel');

+	        print '<td><td class="right">';

+	        if ($user->rights->expedition->creer) print '<a class="editfielda" href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';

+	        else print '&nbsp;';

+	        print '</td></tr></table>';

+	        print '</td>';

+	        print '<td colspan="3">';

+			if ($action != 'editincoterm')

+			{

+				print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);

+			}

+			else

+			{

+				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);

+			}

+	        print '</td></tr>';

+		}

+

+		// Other attributes

+		$parameters = array('colspan' => ' colspan="3"', 'cols' => '3');

+		$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+		print $hookmanager->resPrint;

+

+		print "</table>";

+

+		print '</div>';

+		print '</div>';

+		print '</div>';

+

+		print '<div class="clearboth"></div>';

+

+

+		// Lines of products

+

+		if ($action == 'editline')

+		{

+			print '	<form name="updateline" id="updateline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;lineid='.$line_id.'" method="POST">

+			<input type="hidden" name="token" value="' . newToken().'">

+			<input type="hidden" name="action" value="updateline">

+			<input type="hidden" name="mode" value="">

+			<input type="hidden" name="id" value="' . $object->id.'">

+			';

+		}

+		print '<br>';

+

+        print '<div class="div-table-responsive-no-min">';

+		print '<table class="noborder" width="100%" id="tablelines" >';

+		print '<thead>';

+		print '<tr class="liste_titre">';

+		// Adds a line numbering column

+		if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER))

+		{

+			print '<td width="5" class="center linecolnum">&nbsp;</td>';

+		}

+		// Product/Service

+		print '<td  class="linecoldescription" >'.$langs->trans("Products").'</td>';

+		// Qty

+		print '<td class="center linecolqty">'.$langs->trans("QtyOrdered").'</td>';

+		if ($origin && $origin_id > 0)

+		{

+			print '<td class="center linecolqtyinothershipments">'.$langs->trans("QtyInOtherShipments").'</td>';

+		}

+		if ($action == 'editline')

+		{

+			$editColspan = 3;

+			if (empty($conf->stock->enabled)) $editColspan--;

+			if (empty($conf->productbatch->enabled)) $editColspan--;

+			print '<td class="center linecoleditlineotherinfo" colspan="'.$editColspan.'">';

+			if ($object->statut <= 1)

+			{

+				print $langs->trans("QtyToShip").' - ';

+			}

+			else

+			{

+				print $langs->trans("QtyShipped").' - ';

+			}

+			if (!empty($conf->stock->enabled))

+			{

+				print $langs->trans("WarehouseSource").' - ';

+			}

+			if (!empty($conf->productbatch->enabled))

+			{

+				print $langs->trans("Batch");

+			}

+			print '</td>';

+		}

+		else

+		{

+			if ($object->statut <= 1)

+			{

+				print '<td class="center linecolqtytoship">'.$langs->trans("QtyToShip").'</td>';

+			}

+			else

+			{

+				print '<td class="center linecolqtyshipped">'.$langs->trans("QtyShipped").'</td>';

+			}

+			if (!empty($conf->stock->enabled))

+			{

+				print '<td class="left linecolwarehousesource">'.$langs->trans("WarehouseSource").'</td>';

+			}

+

+			if (!empty($conf->productbatch->enabled))

+			{

+				print '<td class="left linecolbatch">'.$langs->trans("Batch").'</td>';

+			}

+		}

+		print '<td class="center linecolweight">'.$langs->trans("CalculatedWeight").'</td>';

+		print '<td class="center linecolvolume">'.$langs->trans("CalculatedVolume").'</td>';

+		//print '<td class="center">'.$langs->trans("Size").'</td>';

+		if ($object->statut == 0)

+		{

+			print '<td class="linecoledit"></td>';

+			print '<td class="linecoldelete" width="10"></td>';

+		}

+		print "</tr>\n";

+		print '</thead>';

+

+		if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))

+		{

+			$object->fetch_thirdparty();

+			$outputlangs = $langs;

+			$newlang = '';

+			if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');

+			if (empty($newlang)) $newlang = $object->thirdparty->default_lang;

+			if (!empty($newlang))

+			{

+				$outputlangs = new Translate("", $conf);

+				$outputlangs->setDefaultLang($newlang);

+			}

+		}

+

+		// Get list of products already sent for same source object into $alreadysent

+		$alreadysent = array();

+		if ($origin && $origin_id > 0)

+		{

+    		$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";

+    		$sql .= ", ed.rowid as shipmentline_id, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line, ed.fk_entrepot";

+    		$sql .= ", e.rowid as shipment_id, e.ref as shipment_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_expedition";

+    		//if ($conf->livraison_bon->enabled) $sql .= ", l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received";

+    		$sql .= ', p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch';

+    		$sql .= ', p.description as product_desc';

+    		$sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";

+    		$sql .= ", ".MAIN_DB_PREFIX."expedition as e";

+    		$sql .= ", ".MAIN_DB_PREFIX.$origin."det as obj";

+    		//if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid  AND obj.rowid = ld.fk_origin_line";

+    		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid";

+    		$sql .= " WHERE e.entity IN (".getEntity('expedition').")";

+    		$sql .= " AND obj.fk_".$origin." = ".$origin_id;

+    		$sql .= " AND obj.rowid = ed.fk_origin_line";

+    		$sql .= " AND ed.fk_expedition = e.rowid";

+    		//if ($filter) $sql.= $filter;

+    		$sql .= " ORDER BY obj.fk_product";

+

+    		dol_syslog("get list of shipment lines", LOG_DEBUG);

+    		$resql = $db->query($sql);

+    		if ($resql)

+    		{

+    		    $num = $db->num_rows($resql);

+    		    $i = 0;

+

+    		    while ($i < $num)

+    		    {

+        		    $obj = $db->fetch_object($resql);

+        		    if ($obj)

+        		    {

+        		        // $obj->rowid is rowid in $origin."det" table

+        		        $alreadysent[$obj->rowid][$obj->shipmentline_id] = array('shipment_ref'=>$obj->shipment_ref, 'shipment_id'=>$obj->shipment_id, 'warehouse'=>$obj->fk_entrepot, 'qty_shipped'=>$obj->qty_shipped, 'date_valid'=>$db->jdate($obj->date_valid), 'date_delivery'=>$db->jdate($obj->date_delivery));

+        		    }

+        		    $i++;

+    		    }

+    		}

+    		//var_dump($alreadysent);

+		}

+

+		print '<tbody>';

+		// Loop on each product to send/sent

+		for ($i = 0; $i < $num_prod; $i++)

+		{

+			$parameters = array('i' => $i, 'line' => $lines[$i], 'line_id' => $line_id, 'num' => $num_prod, 'alreadysent' => $alreadysent, 'editColspan' => $editColspan, 'outputlangs' => $outputlangs);

+			$reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);

+			if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

+

+			if (empty($reshook))

+			{

+			    print '<!-- origin line id = '.$lines[$i]->origin_line_id.' -->'; // id of order line

+				print '<tr class="oddeven" id="row-'.$lines[$i]->id.'" data-id="'.$lines[$i]->id.'" data-element="'.$lines[$i]->element.'" >';

+

+				// #

+				if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER))

+				{

+					print '<td class="center linecolnum">'.($i + 1).'</td>';

@@ -2308,34 +2188,45 @@
-				$i++;

-			}

-		}

-		//var_dump($alreadysent);

-	}

-

-	print '<tbody>';

-

-	// Loop on each product to send/sent

-	for ($i = 0; $i < $num_prod; $i++) {

-		$parameters = array('i' => $i, 'line' => $lines[$i], 'line_id' => $line_id, 'num' => $num_prod, 'alreadysent' => $alreadysent, 'editColspan' => !empty($editColspan) ? $editColspan : 0, 'outputlangs' => $outputlangs);

-		$reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action);

-		if ($reshook < 0) {

-			setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-		}

-

-		if (empty($reshook)) {

-			print '<!-- origin line id = '.$lines[$i]->origin_line_id.' -->'; // id of order line

-			print '<tr class="oddeven" id="row-'.$lines[$i]->id.'" data-id="'.$lines[$i]->id.'" data-element="'.$lines[$i]->element.'" >';

-

-			// #

-			if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {

-				print '<td class="center linecolnum">'.($i + 1).'</td>';

-			}

-

-			// Predefined product or service

-			if ($lines[$i]->fk_product > 0) {

-				// Define output language

-				if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {

-					$prod = new Product($db);

-					$prod->fetch($lines[$i]->fk_product);

-					$label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;

-				} else {

-					$label = (!empty($lines[$i]->label) ? $lines[$i]->label : $lines[$i]->product_label);

+

+				// Predefined product or service

+				if ($lines[$i]->fk_product > 0)

+				{

+					// Define output language

+					if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))

+					{

+						$prod = new Product($db);

+						$prod->fetch($lines[$i]->fk_product);

+						$label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label;

+					}

+					else

+						$label = (!empty($lines[$i]->label) ? $lines[$i]->label : $lines[$i]->product_label);

+

+					print '<td class="linecoldescription">';

+

+					// Show product and description

+					$product_static->type = $lines[$i]->fk_product_type;

+					$product_static->id = $lines[$i]->fk_product;

+					$product_static->ref = $lines[$i]->ref;

+					$product_static->status_batch = $lines[$i]->product_tobatch;

+

+					$product_static->weight = $lines[$i]->weight;

+					$product_static->weight_units = $lines[$i]->weight_units;

+					$product_static->length = $lines[$i]->length;

+					$product_static->length_units = $lines[$i]->length_units;

+					$product_static->width = $lines[$i]->width;

+					$product_static->width_units = $lines[$i]->width_units;

+					$product_static->height = $lines[$i]->height;

+					$product_static->height_units = $lines[$i]->height_units;

+					$product_static->surface = $lines[$i]->surface;

+					$product_static->surface_units = $lines[$i]->surface_units;

+					$product_static->volume = $lines[$i]->volume;

+					$product_static->volume_units = $lines[$i]->volume_units;

+

+					$text = $product_static->getNomUrl(1);

+					$text .= ' - '.$label;

+					$description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($lines[$i]->description));

+					print $form->textwithtooltip($text, $description, 3, '', '', $i);

+					print_date_range($lines[$i]->date_start, $lines[$i]->date_end);

+					if (!empty($conf->global->PRODUIT_DESC_IN_FORM))

+					{

+						print (!empty($lines[$i]->description) && $lines[$i]->description != $lines[$i]->product) ? '<br>'.dol_htmlentitiesbr($lines[$i]->description) : '';

+					}

+					print "</td>\n";

@@ -2343,31 +2234,15 @@
-

-				print '<td class="linecoldescription">';

-

-				// Show product and description

-				$product_static->type = $lines[$i]->fk_product_type;

-				$product_static->id = $lines[$i]->fk_product;

-				$product_static->ref = $lines[$i]->ref;

-				$product_static->status = $lines[$i]->product_tosell;

-				$product_static->status_buy = $lines[$i]->product_tobuy;

-				$product_static->status_batch = $lines[$i]->product_tobatch;

-

-				$product_static->weight = $lines[$i]->weight;

-				$product_static->weight_units = $lines[$i]->weight_units;

-				$product_static->length = $lines[$i]->length;

-				$product_static->length_units = $lines[$i]->length_units;

-				$product_static->width = !empty($lines[$i]->width) ? $lines[$i]->width : 0;

-				$product_static->width_units = !empty($lines[$i]->width_units) ? $lines[$i]->width_units : 0;

-				$product_static->height = !empty($lines[$i]->height) ? $lines[$i]->height : 0;

-				$product_static->height_units = !empty($lines[$i]->height_units) ? $lines[$i]->height_units : 0;

-				$product_static->surface = $lines[$i]->surface;

-				$product_static->surface_units = $lines[$i]->surface_units;

-				$product_static->volume = $lines[$i]->volume;

-				$product_static->volume_units = $lines[$i]->volume_units;

-

-				$text = $product_static->getNomUrl(1);

-				$text .= ' - '.$label;

-				$description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($lines[$i]->description));

-				print $form->textwithtooltip($text, $description, 3, '', '', $i);

-				print_date_range(!empty($lines[$i]->date_start) ? $lines[$i]->date_start : '', !empty($lines[$i]->date_end) ? $lines[$i]->date_end : '');

-				if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {

-					print (!empty($lines[$i]->description) && $lines[$i]->description != $lines[$i]->product) ? '<br>'.dol_htmlentitiesbr($lines[$i]->description) : '';

+				else

+				{

+					print '<td class="linecoldescription" >';

+					if ($lines[$i]->product_type == Product::TYPE_SERVICE) $text = img_object($langs->trans('Service'), 'service');

+					else $text = img_object($langs->trans('Product'), 'product');

+

+					if (!empty($lines[$i]->label)) {

+						$text .= ' <strong>'.$lines[$i]->label.'</strong>';

+						print $form->textwithtooltip($text, $lines[$i]->description, 3, '', '', $i);

+					} else {

+						print $text.' '.nl2br($lines[$i]->description);

+					}

+

+					print_date_range($lines[$i]->date_start, $lines[$i]->date_end);

+					print "</td>\n";

@@ -2375,56 +2250,56 @@
-				print "</td>\n";

-			} else {

-				print '<td class="linecoldescription" >';

-				if ($lines[$i]->product_type == Product::TYPE_SERVICE) {

-					$text = img_object($langs->trans('Service'), 'service');

-				} else {

-					$text = img_object($langs->trans('Product'), 'product');

-				}

-

-				if (!empty($lines[$i]->label)) {

-					$text .= ' <strong>'.$lines[$i]->label.'</strong>';

-					print $form->textwithtooltip($text, $lines[$i]->description, 3, '', '', $i);

-				} else {

-					print $text.' '.nl2br($lines[$i]->description);

-				}

-

-				print_date_range($lines[$i]->date_start, $lines[$i]->date_end);

-				print "</td>\n";

-			}

-

-			$unit_order = '';

-			if (getDolGlobalString('PRODUCT_USE_UNITS')) {

-				$unit_order = measuringUnitString($lines[$i]->fk_unit);

-			}

-

-			// Qty ordered

-			print '<td class="center linecolqty">'.$lines[$i]->qty_asked.' '.$unit_order.'</td>';

-

-			// Qty in other shipments (with shipment and warehouse used)

-			if ($origin && $origin_id > 0) {

-				print '<td class="linecolqtyinothershipments center nowrap">';

-				$htmltooltip = '';

-				$qtyalreadysent = 0;

-				foreach ($alreadysent as $key => $val) {

-					if ($lines[$i]->fk_origin_line == $key) {

-						$j = 0;

-						foreach ($val as $shipmentline_id => $shipmentline_var) {

-							if ($shipmentline_var['shipment_id'] == $lines[$i]->fk_expedition) {

-								continue; // We want to show only "other shipments"

-							}

-

-							$j++;

-							if ($j > 1) {

-								$htmltooltip .= '<br>';

-							}

-							$shipment_static->fetch($shipmentline_var['shipment_id']);

-							$htmltooltip .= $shipment_static->getNomUrl(1, '', 0, 0, 1);

-							$htmltooltip .= ' - '.$shipmentline_var['qty_shipped'];

-							$htmltooltip .= ' - '.$langs->trans("DateValidation").' : '.(empty($shipmentline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($shipmentline_var['date_valid'], 'dayhour'));

-							/*if (isModEnabled('stock') && $shipmentline_var['warehouse'] > 0) {

-								$warehousestatic->fetch($shipmentline_var['warehouse']);

-								$htmltext .= '<br>'.$langs->trans("FromLocation").' : '.$warehousestatic->getNomUrl(1, '', 0, 1);

-							}*/

-							//print ' '.$form->textwithpicto('', $htmltext, 1);

-

-							$qtyalreadysent += $shipmentline_var['qty_shipped'];

+

+				// Qty ordered

+				print '<td class="center linecolqty">'.$lines[$i]->qty_asked.'</td>';

+

+				// Qty in other shipments (with shipment and warehouse used)

+	    		if ($origin && $origin_id > 0)

+	    		{

+	    			print '<td class="linecolqtyinothershipments center nowrap">';

+	    			foreach ($alreadysent as $key => $val)

+	    			{

+	    			    if ($lines[$i]->fk_origin_line == $key)

+	    			    {

+	    			        $j = 0;

+	    			        foreach ($val as $shipmentline_id=> $shipmentline_var)

+	    			        {

+	    			            if ($shipmentline_var['shipment_id'] == $lines[$i]->fk_expedition) continue; // We want to show only "other shipments"

+

+	    			            $j++;

+	    			            if ($j > 1) print '<br>';

+	    			            $shipment_static->fetch($shipmentline_var['shipment_id']);

+	    			            print $shipment_static->getNomUrl(1);

+	    			            print ' - '.$shipmentline_var['qty_shipped'];

+	    			            $htmltext = $langs->trans("DateValidation").' : '.(empty($shipmentline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($shipmentline_var['date_valid'], 'dayhour'));

+	    			            if (!empty($conf->stock->enabled) && $shipmentline_var['warehouse'] > 0)

+	    			            {

+	    			                $warehousestatic->fetch($shipmentline_var['warehouse']);

+	    			                $htmltext .= '<br>'.$langs->trans("FromLocation").' : '.$warehousestatic->getNomUrl(1, '', 0, 1);

+	    			            }

+	    			            print ' '.$form->textwithpicto('', $htmltext, 1);

+	    			        }

+	    			    }

+	    			}

+	    			print '</td>';

+	    		}

+

+				if ($action == 'editline' && $lines[$i]->id == $line_id)

+				{

+					// edit mode

+					print '<td colspan="'.$editColspan.'" class="center"><table class="nobordernopadding">';

+					if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0)

+					{

+						print '<!-- case edit 1 -->';

+						$line = new ExpeditionLigne($db);

+						foreach ($lines[$i]->detail_batch as $detail_batch)

+						{

+							print '<tr>';

+							// Qty to ship or shipped

+							print '<td><input name="qtyl'.$detail_batch->fk_expeditiondet.'_'.$detail_batch->id.'" id="qtyl'.$line_id.'_'.$detail_batch->id.'" type="text" size="4" value="'.$detail_batch->qty.'"></td>';

+							// Batch number managment

+							if ($lines[$i]->entrepot_id == 0)

+							{

+								// only show lot numbers from src warehouse when shipping from multiple warehouses

+								$line->fetch($detail_batch->fk_expeditiondet);

+							}

+							print '<td>'.$formproduct->selectLotStock($detail_batch->fk_origin_stock, 'batchl'.$detail_batch->fk_expeditiondet.'_'.$detail_batch->fk_origin_stock, '', 1, 0, $lines[$i]->fk_product, $line->entrepot_id).'</td>';

+							print '</tr>';

@@ -2432,16 +2307 @@
-						if ($j) {

-							$htmltooltip = $langs->trans("QtyInOtherShipments").'...<br><br>'.$htmltooltip.'<br><input type="submit" name="dummyhiddenbuttontogetfocus" style="display:none" autofocus>';

-						}

-					}

-				}

-				print $form->textwithpicto($qtyalreadysent, $htmltooltip, 1, 'info', '', 0, 3, 'tooltip'.$lines[$i]->id);

-				print '</td>';

-			}

-

-			if ($action == 'editline' && $lines[$i]->id == $line_id) {

-				// edit mode

-				print '<td colspan="'.$editColspan.'" class="center"><table class="nobordernopadding centpercent">';

-				if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) {

-					print '<!-- case edit 1 -->';

-					$line = new ExpeditionLigne($db);

-					foreach ($lines[$i]->detail_batch as $detail_batch) {

+						// add a 0 qty lot row to be able to add a lot

@@ -2450 +2310 @@
-						print '<td><input class="qtyl right" name="qtyl'.$detail_batch->fk_expeditiondet.'_'.$detail_batch->id.'" id="qtyl'.$line_id.'_'.$detail_batch->id.'" type="text" size="4" value="'.$detail_batch->qty.'"></td>';

+						print '<td><input name="qtyl'.$line_id.'_0" id="qtyl'.$line_id.'_0" type="text" size="4" value="0"></td>';

@@ -2452,6 +2312 @@
-						if ($lines[$i]->entrepot_id == 0) {

-							// only show lot numbers from src warehouse when shipping from multiple warehouses

-							$line->fetch($detail_batch->fk_expeditiondet);

-						}

-						$entrepot_id = !empty($detail_batch->entrepot_id) ? $detail_batch->entrepot_id : $lines[$i]->entrepot_id;

-						print '<td>'.$formproduct->selectLotStock($detail_batch->fk_origin_stock, 'batchl'.$detail_batch->fk_expeditiondet.'_'.$detail_batch->fk_origin_stock, '', 1, 0, $lines[$i]->fk_product, $entrepot_id).'</td>';

+						print '<td>'.$formproduct->selectLotStock('', 'batchl'.$line_id.'_0', '', 1, 0, $lines[$i]->fk_product).'</td>';

@@ -2460,22 +2315,7 @@
-					// add a 0 qty lot row to be able to add a lot

-					print '<tr>';

-					// Qty to ship or shipped

-					print '<td><input class="qtyl" name="qtyl'.$line_id.'_0" id="qtyl'.$line_id.'_0" type="text" size="4" value="0"></td>';

-					// Batch number managment

-					print '<td>'.$formproduct->selectLotStock('', 'batchl'.$line_id.'_0', '', 1, 0, $lines[$i]->fk_product).'</td>';

-					print '</tr>';

-				} elseif (isModEnabled('stock')) {

-					if ($lines[$i]->fk_product > 0) {

-						if ($lines[$i]->entrepot_id > 0) {

-							print '<!-- case edit 2 -->';

-							print '<tr>';

-							// Qty to ship or shipped

-							print '<td><input class="qtyl right" name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'">'.$unit_order.'</td>';

-							// Warehouse source

-							print '<td>'.$formproduct->selectWarehouses($lines[$i]->entrepot_id, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'</td>';

-							// Batch number managment

-							print '<td> - '.$langs->trans("NA").'</td>';

-							print '</tr>';

-						} elseif (count($lines[$i]->details_entrepot) > 1) {

-							print '<!-- case edit 3 -->';

-							foreach ($lines[$i]->details_entrepot as $detail_entrepot) {

+					elseif (!empty($conf->stock->enabled))

+					{

+						if ($lines[$i]->fk_product > 0)

+						{

+							if ($lines[$i]->entrepot_id > 0)

+							{

+								print '<!-- case edit 2 -->';

@@ -2484 +2324 @@
-								print '<td><input class="qtyl right" name="qtyl'.$detail_entrepot->line_id.'" id="qtyl'.$detail_entrepot->line_id.'" type="text" size="4" value="'.$detail_entrepot->qty_shipped.'">'.$unit_order.'</td>';

+								print '<td><input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'"></td>';

@@ -2486 +2326 @@
-								print '<td>'.$formproduct->selectWarehouses($detail_entrepot->entrepot_id, 'entl'.$detail_entrepot->line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'</td>';

+								print '<td>'.$formproduct->selectWarehouses($lines[$i]->entrepot_id, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'</td>';

@@ -2491,2 +2331,24 @@
-						} elseif ($lines[$i]->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {

-							print '<!-- case edit 4 -->';

+							elseif (count($lines[$i]->details_entrepot) > 1)

+							{

+								print '<!-- case edit 3 -->';

+								foreach ($lines[$i]->details_entrepot as $detail_entrepot)

+								{

+									print '<tr>';

+									// Qty to ship or shipped

+									print '<td><input name="qtyl'.$detail_entrepot->line_id.'" id="qtyl'.$detail_entrepot->line_id.'" type="text" size="4" value="'.$detail_entrepot->qty_shipped.'"></td>';

+									// Warehouse source

+									print '<td>'.$formproduct->selectWarehouses($detail_entrepot->entrepot_id, 'entl'.$detail_entrepot->line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).'</td>';

+									// Batch number managment

+									print '<td> - '.$langs->trans("NA").'</td>';

+									print '</tr>';

+								}

+							}

+							else

+							{

+								print '<!-- case edit 4 -->';

+								print '<tr><td colspan="3">'.$langs->trans("NotEnoughStock").'</td></tr>';

+							}

+						}

+						else

+						{

+							print '<!-- case edit 5 -->';

@@ -2495,2 +2357,4 @@
-							print '<td><input class="qtyl right" name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'"></td>';

-							print '<td><span class="opacitymedium">('.$langs->trans("Service").')</span></td>';

+							print '<td><input name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'"></td>';

+							// Warehouse source

+							print '<td></td>';

+							// Batch number managment

@@ -2498,0 +2363,62 @@
+						}

+					}

+

+					print '</table></td>';

+				}

+				else

+				{

+					// Qty to ship or shipped

+					print '<td class="linecolqtytoship center">'.$lines[$i]->qty_shipped.'</td>';

+

+					// Warehouse source

+					if (!empty($conf->stock->enabled))

+					{

+						print '<td class="linecolwarehousesource left">';

+						if ($lines[$i]->entrepot_id > 0)

+						{

+							$entrepot = new Entrepot($db);

+							$entrepot->fetch($lines[$i]->entrepot_id);

+							print $entrepot->getNomUrl(1);

+						}

+						elseif (count($lines[$i]->details_entrepot) > 1)

+						{

+							$detail = '';

+							foreach ($lines[$i]->details_entrepot as $detail_entrepot)

+							{

+								if ($detail_entrepot->entrepot_id > 0)

+								{

+									$entrepot = new Entrepot($db);

+									$entrepot->fetch($detail_entrepot->entrepot_id);

+									$detail .= $langs->trans("DetailWarehouseFormat", $entrepot->libelle, $detail_entrepot->qty_shipped).'<br/>';

+								}

+							}

+							print $form->textwithtooltip(img_picto('', 'object_stock').' '.$langs->trans("DetailWarehouseNumber"), $detail);

+						}

+						print '</td>';

+					}

+

+					// Batch number managment

+					if (!empty($conf->productbatch->enabled))

+					{

+						if (isset($lines[$i]->detail_batch))

+						{

+							print '<!-- Detail of lot -->';

+							print '<td class="linecolbatch">';

+							if ($lines[$i]->product_tobatch)

+							{

+								$detail = '';

+								foreach ($lines[$i]->detail_batch as $dbatch)	// $dbatch is instance of ExpeditionLineBatch

+								{

+									$detail .= $langs->trans("Batch").': '.$dbatch->batch;

+									$detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day");

+									$detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby, "day");

+									$detail .= ' - '.$langs->trans("Qty").': '.$dbatch->qty;

+									$detail .= '<br>';

+								}

+								print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $detail);

+							}

+							else

+							{

+								print $langs->trans("NA");

+							}

+							print '</td>';

@@ -2500,2 +2426 @@
-							print '<!-- case edit 5 -->';

-							print '<tr><td colspan="3">'.$langs->trans("NotEnoughStock").'</td></tr>';

+							print '<td class="linecolbatch" ></td>';

@@ -2503,21 +2428 @@
-					} else {

-						print '<!-- case edit 6 -->';

-						print '<tr>';

-						// Qty to ship or shipped

-						print '<td><input class="qtyl right" name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'">'.$unit_order.'</td>';

-						// Warehouse source

-						print '<td></td>';

-						// Batch number managment

-						print '<td></td>';

-						print '</tr>';

-					}

-				} elseif (!isModEnabled('stock') && empty($conf->productbatch->enabled)) { // both product batch and stock are not activated.

-					print '<!-- case edit 7 -->';

-					print '<tr>';

-					// Qty to ship or shipped

-					print '<td><input class="qtyl right" name="qtyl'.$line_id.'" id="qtyl'.$line_id.'" type="text" size="4" value="'.$lines[$i]->qty_shipped.'"></td>';

-					// Warehouse source

-					print '<td></td>';

-					// Batch number managment

-					print '<td></td>';

-					print '</tr>';

+					}

@@ -2526,25 +2431,20 @@
-				print '</table></td>';

-			} else {

-				// Qty to ship or shipped

-				print '<td class="linecolqtytoship center">'.$lines[$i]->qty_shipped.' '.$unit_order.'</td>';

-

-				// Warehouse source

-				if (isModEnabled('stock')) {

-					print '<td class="linecolwarehousesource tdoverflowmax200">';

-					if ($lines[$i]->product_type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {

-						print '<span class="opacitymedium">('.$langs->trans("Service").')</span>';

-					} elseif ($lines[$i]->entrepot_id > 0) {

-						$entrepot = new Entrepot($db);

-						$entrepot->fetch($lines[$i]->entrepot_id);

-						print $entrepot->getNomUrl(1);

-					} elseif (count($lines[$i]->details_entrepot) > 1) {

-						$detail = '';

-						foreach ($lines[$i]->details_entrepot as $detail_entrepot) {

-							if ($detail_entrepot->entrepot_id > 0) {

-								$entrepot = new Entrepot($db);

-								$entrepot->fetch($detail_entrepot->entrepot_id);

-								$detail .= $langs->trans("DetailWarehouseFormat", $entrepot->label, $detail_entrepot->qty_shipped).'<br>';

-							}

-						}

-						print $form->textwithtooltip(img_picto('', 'object_stock').' '.$langs->trans("DetailWarehouseNumber"), $detail);

-					}

+				// Weight

+				print '<td class="center linecolweight">';

+				if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->weight * $lines[$i]->qty_shipped.' '.measuringUnitString(0, "weight", $lines[$i]->weight_units);

+				else print '&nbsp;';

+				print '</td>';

+

+				// Volume

+				print '<td class="center linecolvolume">';

+				if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->volume * $lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units);

+				else print '&nbsp;';

+				print '</td>';

+

+				// Size

+				//print '<td class="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units).'</td>';

+

+				if ($action == 'editline' && $lines[$i]->id == $line_id)

+				{

+					print '<td class="center" colspan="2" valign="middle">';

+					print '<input type="submit" class="button" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';

+					print '<input type="submit" class="button" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"><br>';

@@ -2553,26 +2453,16 @@
-

-				// Batch number managment

-				if (isModEnabled('productbatch')) {

-					if (isset($lines[$i]->detail_batch)) {

-						print '<!-- Detail of lot -->';

-						print '<td class="linecolbatch">';

-						if ($lines[$i]->product_tobatch) {

-							$detail = '';

-							foreach ($lines[$i]->detail_batch as $dbatch) {	// $dbatch is instance of ExpeditionLineBatch

-								$detail .= $langs->trans("Batch").': '.$dbatch->batch;

-								if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {

-									$detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day");

-								}

-								if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {

-									$detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby, "day");

-								}

-								$detail .= ' - '.$langs->trans("Qty").': '.$dbatch->qty;

-								$detail .= '<br>';

-							}

-							print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"), $detail);

-						} else {

-							print $langs->trans("NA");

-						}

-						print '</td>';

-					} else {

-						print '<td class="linecolbatch" ></td>';

+				elseif ($object->statut == Expedition::STATUS_DRAFT)

+				{

+					// edit-delete buttons

+					print '<td class="linecoledit center">';

+					print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;lineid='.$lines[$i]->id.'">'.img_edit().'</a>';

+					print '</td>';

+					print '<td class="linecoldelete" width="10">';

+					print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=deleteline&amp;lineid='.$lines[$i]->id.'">'.img_delete().'</a>';

+					print '</td>';

+

+					// Display lines extrafields

+					if (!empty($rowExtrafieldsStart))

+					{

+						print $rowExtrafieldsStart;

+						print $rowExtrafieldsView;

+						print $rowEnd;

@@ -2581,36 +2471 @@
-			}

-

-			// Weight

-			print '<td class="center linecolweight">';

-			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {

-				print $lines[$i]->weight * $lines[$i]->qty_shipped.' '.measuringUnitString(0, "weight", $lines[$i]->weight_units);

-			} else {

-				print '&nbsp;';

-			}

-			print '</td>';

-

-			// Volume

-			print '<td class="center linecolvolume">';

-			if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) {

-				print $lines[$i]->volume * $lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units);

-			} else {

-				print '&nbsp;';

-			}

-			print '</td>';

-

-			// Size

-			//print '<td class="center">'.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units).'</td>';

-

-			if ($action == 'editline' && $lines[$i]->id == $line_id) {

-				print '<td class="center" colspan="2" valign="middle">';

-				print '<input type="submit" class="button button-save" id="savelinebutton marginbottomonly" name="save" value="'.$langs->trans("Save").'"><br>';

-				print '<input type="submit" class="button button-cancel" id="cancellinebutton" name="cancel" value="'.$langs->trans("Cancel").'"><br>';

-				print '</td>';

-			} elseif ($object->statut == Expedition::STATUS_DRAFT) {

-				// edit-delete buttons

-				print '<td class="linecoledit center">';

-				print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&lineid='.$lines[$i]->id.'">'.img_edit().'</a>';

-				print '</td>';

-				print '<td class="linecoldelete" width="10">';

-				print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteline&token='.newToken().'&lineid='.$lines[$i]->id.'">'.img_delete().'</a>';

-				print '</td>';

+				print "</tr>";

@@ -2619,4 +2474,17 @@
-				if (!empty($rowExtrafieldsStart)) {

-					print $rowExtrafieldsStart;

-					print $rowExtrafieldsView;

-					print $rowEnd;

+				if (!empty($extrafields)) {

+					$colspan = 6;

+					if ($origin && $origin_id > 0) $colspan++;

+					if (!empty($conf->productbatch->enabled)) $colspan++;

+					if (!empty($conf->stock->enabled)) $colspan++;

+

+					$line = $lines[$i];

+					$line->fetch_optionals();

+

+					if ($action == 'editline' && $line->id == $line_id)

+					{

+						print $lines[$i]->showOptionals($extrafields, 'edit', array('colspan'=>$colspan), $indiceAsked);

+					}

+					else

+					{

+						print $lines[$i]->showOptionals($extrafields, 'view', array('colspan'=>$colspan), $indiceAsked);

+					}

@@ -2625,27 +2493,7 @@
-			print "</tr>";

-

-			// Display lines extrafields.

-			// $line is a line of shipment

-			if (!empty($extrafields)) {

-				$colspan = 6;

-				if ($origin && $origin_id > 0) {

-					$colspan++;

-				}

-				if (isModEnabled('productbatch')) {

-					$colspan++;

-				}

-				if (isModEnabled('stock')) {

-					$colspan++;

-				}

-

-				$line = $lines[$i];

-				$line->fetch_optionals();

-

-				// TODO Show all in same line by setting $display_type = 'line'

-				if ($action == 'editline' && $line->id == $line_id) {

-					print $lines[$i]->showOptionals($extrafields, 'edit', array('colspan'=>$colspan), !empty($indiceAsked) ? $indiceAsked : '', '', 0, 'card');

-				} else {

-					print $lines[$i]->showOptionals($extrafields, 'view', array('colspan'=>$colspan), !empty($indiceAsked) ? $indiceAsked : '', '', 0, 'card');

-				}

-			}

-		}

+		}

+

+		// TODO Show also lines ordered but not delivered

+

+		print "</table>\n";

+		print '</tbody>';

+		print '</div>';

@@ -2654,12 +2502,2 @@
-	// TODO Show also lines ordered but not delivered

-

-	if (empty($num_prod)) {

-		print '<tr><td colspan="8"><span class="opacitymedium">'.$langs->trans("NoLineGoOnTabToAddSome", $langs->transnoentitiesnoconv("ShipmentDistribution")).'</span></td></tr>';

-	}

-

-	print "</table>\n";

-	print '</tbody>';

-	print '</div>';

-

-

-	print dol_get_fiche_end();

+

+	dol_fiche_end();

@@ -2675 +2513,2 @@
-	if (($user->socid == 0) && ($action != 'presend')) {

+	if (($user->socid == 0) && ($action != 'presend'))

+	{

@@ -2680,8 +2519,9 @@
-		// modified by hook

-		if (empty($reshook)) {

-			if ($object->statut == Expedition::STATUS_DRAFT && $num_prod > 0) {

-				if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'creer'))

-				 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'shipping_advance', 'validate'))) {

-					print dolGetButtonAction('', $langs->trans('Validate'), 'default', $_SERVER["PHP_SELF"].'?action=valid&token='.newToken().'&id='.$object->id, '');

-				} else {

-					print dolGetButtonAction($langs->trans('NotAllowed'), $langs->trans('Validate'), 'default', $_SERVER['PHP_SELF']. '#', '', false);

+		                                                                                               // modified by hook

+		if (empty($reshook))

+		{

+			if ($object->statut == Expedition::STATUS_DRAFT && $num_prod > 0)

+			{

+				if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer))

+	  		     || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate)))

+				{

+					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';

@@ -2689,6 +2529,3 @@
-			}

-

-			// 0=draft, 1=validated/delivered, 2=closed/delivered

-			if ($object->statut == Expedition::STATUS_VALIDATED && !getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) {

-				if ($user->hasRight('expedition', 'creer')) {

-					print dolGetButtonAction('', $langs->trans('SetToDraft'), 'default', $_SERVER["PHP_SELF"].'?action=setdraft&token='.newToken().'&id='.$object->id, '');

+				else

+				{

+					print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("Validate").'</a>';

@@ -2697,3 +2534,12 @@
-			if ($object->statut == Expedition::STATUS_CLOSED) {

-				if ($user->hasRight('expedition', 'creer')) {

-					print dolGetButtonAction('', $langs->trans('ReOpen'), 'default', $_SERVER["PHP_SELF"].'?action=reopen&token='.newToken().'&id='.$object->id, '');

+

+			// TODO add alternative status

+			// 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order)

+			if ($object->statut == Expedition::STATUS_CLOSED && $user->rights->expedition->creer)

+			{

+				if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?

+				{

+					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ClassifyUnbilled").'</a>';

+				}

+				else

+				{

+			    	print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=reopen">'.$langs->trans("ReOpen").'</a>';

@@ -2705,6 +2551,7 @@
-				if ($object->statut > 0) {

-					if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('expedition', 'shipping_advance', 'send')) {

-						print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?action=presend&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '');

-					} else {

-						print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER['PHP_SELF']. '#', '', false);

-					}

+				if ($object->statut > 0)

+				{

+					if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send)

+					{

+						print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>';

+					}

+					else print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a>';

@@ -2715,5 +2562,7 @@
-			if (isModEnabled('facture') && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED)) {

-				if ($user->hasRight('facture', 'creer')) {

-					if (getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT') !== '0') {

-						print dolGetButtonAction('', $langs->trans('CreateBill'), 'default', DOL_URL_ROOT.'/compta/facture/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->socid, '');

-					}

+			if (!empty($conf->facture->enabled) && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED))

+			{

+				if ($user->rights->facture->creer)

+				{

+					// TODO show button only   if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))

+					// If we do that, we must also make this option official.

+					print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("CreateBill").'</a>';

@@ -2725,11 +2574,17 @@
-			if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED) && $user->hasRight('expedition', 'delivery', 'creer') && empty($object->linkedObjectsIds['delivery'])) {

-				print dolGetButtonAction('', $langs->trans('CreateDeliveryOrder'), 'default', $_SERVER["PHP_SELF"].'?action=create_delivery&token='.newToken().'&id='.$object->id, '');

-			}

-

-			// Set Billed and Closed

-			if ($object->statut == Expedition::STATUS_VALIDATED) {

-				if ($user->hasRight('expedition', 'creer') && $object->statut > 0) {

-					if (!$object->billed && getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT') !== '0') {

-						print dolGetButtonAction('', $langs->trans('ClassifyBilled'), 'default', $_SERVER["PHP_SELF"].'?action=classifybilled&token='.newToken().'&id='.$object->id, '');

-					}

-					print dolGetButtonAction('', $langs->trans("Close"), 'default', $_SERVER["PHP_SELF"].'?action=classifyclosed&token='.newToken().'&id='.$object->id, '');

+			if ($conf->livraison_bon->enabled && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED) && $user->rights->expedition->livraison->creer && empty($object->linkedObjectsIds['delivery']))

+			{

+				print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=create_delivery">'.$langs->trans("CreateDeliveryOrder").'</a>';

+			}

+			// Close

+			if ($object->statut == Expedition::STATUS_VALIDATED)

+			{

+				if ($user->rights->expedition->creer && $object->statut > 0 && !$object->billed)

+				{

+					$label = "Close"; $paramaction = 'classifyclosed'; // = Transferred/Received

+					// Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders

+					if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))  // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ?

+					{

+					    $label = "ClassifyBilled";

+					    $paramaction = 'classifybilled';

+					}

+					print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$paramaction.'">'.$langs->trans($label).'</a>';

@@ -2740,4 +2595,6 @@
-			if ($object->statut == Expedition::STATUS_VALIDATED) {

-				if ($user->hasRight('expedition', 'creer')) {

-					print dolGetButtonAction('', $langs->trans('Cancel'), 'danger', $_SERVER["PHP_SELF"].'?action=cancel&token='.newToken().'&id='.$object->id.'&mode=init#formmailbeforetitle', '');

-				}

+			if ($object->statut == Expedition::STATUS_VALIDATED)

+			{

+    			if ($user->rights->expedition->supprimer)

+    			{

+    				print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=cancel">'.$langs->trans("Cancel").'</a>';

+    			}

@@ -2747,2 +2604,3 @@
-			if ($user->hasRight('expedition', 'supprimer')) {

-				print dolGetButtonAction('', $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '');

+			if ($user->rights->expedition->supprimer)

+			{

+				print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';

@@ -2760,4 +2618,5 @@
-	if ($action != 'presend' && $action != 'editline') {

-		print '<div class="fichecenter"><div class="fichehalfleft">';

-

-		$objectref = dol_sanitizeFileName($object->ref);

+	if ($action != 'presend' && $action != 'editline')

+	{

+        print '<div class="fichecenter"><div class="fichehalfleft">';

+

+        $objectref = dol_sanitizeFileName($object->ref);

@@ -2771 +2630 @@
-		print $formfile->showdocuments('expedition', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);

+		print $formfile->showdocuments('expedition', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);

@@ -2775,5 +2634,5 @@
-		$linktoelem = $form->showLinkToObjectBlock($object, null, array('shipping'));

-		$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);

-

-

-		print '</div><div class="fichehalfright">';

+		//$linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));

+		$somethingshown = $form->showLinkedObjectBlock($object, '');

+

+

+		print '</div><div class="fichehalfright"><div class="ficheaddleft">';

@@ -2786 +2645 @@
-		print '</div></div>';

+		print '</div></div></div>';

--- /tmp/dsg/dolibarr/htdocs/expedition/github_19.0.3_contact.php
+++ /tmp/dsg/dolibarr/htdocs/expedition/client_contact.php
@@ -5 +4,0 @@
- * Copyright (C) 2023      Christian Foellmann  <christian@foellmann.de>

@@ -27 +25,0 @@
-// Load Dolibarr environment

@@ -34,3 +32,3 @@
-if (isModEnabled('project')) {

-	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';

-	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';

+if (!empty($conf->projet->enabled)) {

+    require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';

+    require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';

@@ -44 +42,5 @@
-$action = GETPOST('action', 'aZ09');

+$action = GETPOST('action', 'alpha');

+

+// Security check

+if ($user->socid) $socid = $user->socid;

+$result = restrictedArea($user, 'expedition', $id, '');

@@ -47,27 +49,25 @@
-if ($id > 0 || !empty($ref)) {

-	$object->fetch($id, $ref);

-	$object->fetch_thirdparty();

-

-	if (!empty($object->origin)) {

-		$typeobject = $object->origin;

-		$origin = $object->origin;

-		$object->fetch_origin();

-	}

-

-	// Linked documents

-	if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {

-		$objectsrc = new Commande($db);

-		$objectsrc->fetch($object->$typeobject->id);

-	}

-	if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {

-		$objectsrc = new Propal($db);

-		$objectsrc->fetch($object->$typeobject->id);

-	}

-}

-

-// Security check

-if ($user->socid) {

-	$socid = $user->socid;

-}

-$result = restrictedArea($user, 'expedition', $object->id, '');

-$hookmanager->initHooks(array('shipmentcontactcard', 'globalcard'));

+if ($id > 0 || !empty($ref))

+{

+    $object->fetch($id, $ref);

+    $object->fetch_thirdparty();

+

+    if (!empty($object->origin))

+    {

+        $typeobject = $object->origin;

+        $origin = $object->origin;

+        $object->fetch_origin();

+    }

+

+    // Linked documents

+    if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))

+    {

+        $objectsrc = new Commande($db);

+        $objectsrc->fetch($object->$typeobject->id);

+    }

+    if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))

+    {

+        $objectsrc = new Propal($db);

+        $objectsrc->fetch($object->$typeobject->id);

+    }

+}

+

@@ -79,12 +79,21 @@
-$parameters = array('id'=>$id);

-$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);

-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

-

-if (empty($reshook)) {

-	if ($action == 'addcontact' && $user->hasRight('expedition', 'creer')) {

-		if ($result > 0 && $id > 0) {

-			$contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));

-			$typeid    = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));

-			$result    = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));

+if ($action == 'addcontact' && $user->rights->expedition->creer)

+{

+    if ($result > 0 && $id > 0)

+    {

+  		$result = $objectsrc->add_contact(GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'), $_POST["type"], $_POST["source"]);

+    }

+

+	if ($result >= 0)

+	{

+		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

+		exit;

+	}

+	else

+	{

+		if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')

+		{

+			$langs->load("errors");

+			$mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");

+		} else {

+			$mesg = $objectsrc->error;

+			$mesgs = $objectsrc->errors;

@@ -92,29 +101,32 @@
-

-		if ($result >= 0) {

-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

-			exit;

-		} else {

-			if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {

-				$langs->load("errors");

-				$mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");

-			} else {

-				$mesg  = $objectsrc->error;

-				$mesgs = $objectsrc->errors;

-			}

-			setEventMessages($mesg, $mesgs, 'errors');

-		}

-	} elseif ($action == 'swapstatut' && $user->hasRight('expedition', 'creer')) {

-		// bascule du statut d'un contact

-		$result = $objectsrc->swapContactStatus(GETPOST('ligne', 'int'));

-	} elseif ($action == 'deletecontact' && $user->hasRight('expedition', 'creer')) {

-		// Efface un contact

-		$result = $objectsrc->delete_contact(GETPOST("lineid", 'int'));

-

-		if ($result >= 0) {

-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

-			exit;

-		} else {

-			dol_print_error($db);

-		}

-	}

-}

+		setEventMessages($mesg, $mesgs, 'errors');

+	}

+}

+

+// bascule du statut d'un contact

+elseif ($action == 'swapstatut' && $user->rights->expedition->creer)

+{

+    $result = $objectsrc->swapContactStatus(GETPOST('ligne'));

+}

+

+// Efface un contact

+elseif ($action == 'deletecontact' && $user->rights->expedition->creer)

+{

+	$result = $objectsrc->delete_contact(GETPOST("lineid"));

+

+	if ($result >= 0)

+	{

+		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);

+		exit;

+	}

+	else {

+		dol_print_error($db);

+	}

+}

+/*

+elseif ($action == 'setaddress' && $user->rights->expedition->creer)

+{

+	$object->fetch($id);

+	$result=$object->setDeliveryAddress($_POST['fk_address']);

+	if ($result < 0) dol_print_error($db,$object->error);

+}*/

+

@@ -126,4 +138 @@
-

-$help_url = 'EN:Module_Shipments|FR:Module_Expéditions|ES:M&oacute;dulo_Expediciones|DE:Modul_Lieferungen';

-

-llxHeader('', $langs->trans('Order'), $help_url);

+llxHeader('', $langs->trans('Order'), 'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');

@@ -144 +153,2 @@
-if ($id > 0 || !empty($ref)) {

+if ($id > 0 || !empty($ref))

+{

@@ -148 +158 @@
-	print dol_get_fiche_head($head, 'contact', $langs->trans("Shipment"), -1, $object->picto);

+	dol_fiche_head($head, 'contact', $langs->trans("Shipment"), -1, 'sending');

@@ -156,2 +166,2 @@
-	$morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string', '', 0, 1);

-	$morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string', '', null, null, '', 1);

+	$morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);

+	$morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);

@@ -159,22 +169,35 @@
-	$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);

-	// Project

-	if (isModEnabled('project')) {

-		$langs->load("projects");

-		$morehtmlref .= '<br>';

-		if (0) {	// Do not change on shipment

-			$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');

-			if ($action != 'classify') {

-				$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';

-			}

-			$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');

-		} else {

-			if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {

-				$proj = new Project($db);

-				$proj->fetch($objectsrc->fk_project);

-				$morehtmlref .= $proj->getNomUrl(1);

-				if ($proj->title) {

-					$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';

-				}

-			}

-		}

-	}

+    $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);

+    // Project

+    if (!empty($conf->projet->enabled)) {

+        $langs->load("projects");

+        $morehtmlref .= '<br>'.$langs->trans('Project').' ';

+        if (0) {    // Do not change on shipment

+            if ($action != 'classify') {

+                $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';

+            }

+            if ($action == 'classify') {

+                // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);

+                $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

+                $morehtmlref .= '<input type="hidden" name="action" value="classin">';

+                $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';

+                $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);

+                $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';

+                $morehtmlref .= '</form>';

+            } else {

+                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);

+            }

+        } else {

+            // We don't have project on shipment, so we will use the project or source object instead

+            // TODO Add project on shipment

+            $morehtmlref .= ' : ';

+            if (!empty($objectsrc->fk_project)) {

+                $proj = new Project($db);

+                $proj->fetch($objectsrc->fk_project);

+                $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';

+                $morehtmlref .= $proj->ref;

+                $morehtmlref .= '</a>';

+            } else {

+                $morehtmlref .= '';

+            }

+        }

+    }

@@ -188 +211 @@
-	//print '<div class="fichehalfleft">';

+    //print '<div class="fichehalfleft">';

@@ -191,22 +214,24 @@
-	print '<table class="border centpercent tableforfield">';

-

-	// Linked documents

-	if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {

-		print '<tr><td class="titlefield">';

-		$objectsrc = new Commande($db);

-		$objectsrc->fetch($object->$typeobject->id);

-		print $langs->trans("RefOrder").'</td>';

-		print '<td colspan="3">';

-		print $objectsrc->getNomUrl(1, 'commande');

-		print "</td>\n";

-		print '</tr>';

-	}

-	if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {

-		print '<tr><td class="titlefield">';

-		$objectsrc = new Propal($db);

-		$objectsrc->fetch($object->$typeobject->id);

-		print $langs->trans("RefProposal").'</td>';

-		print '<td colspan="3">';

-		print $objectsrc->getNomUrl(1, 'expedition');

-		print "</td>\n";

-		print '</tr>';

+    print '<table class="border centpercent tableforfield">';

+

+    // Linked documents

+	if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))

+	{

+	    print '<tr><td class="titlefield">';

+	    $objectsrc = new Commande($db);

+	    $objectsrc->fetch($object->$typeobject->id);

+	    print $langs->trans("RefOrder").'</td>';

+	    print '<td colspan="3">';

+	    print $objectsrc->getNomUrl(1, 'commande');

+	    print "</td>\n";

+	    print '</tr>';

+	}

+	if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))

+	{

+	    print '<tr><td class="titlefield">';

+	    $objectsrc = new Propal($db);

+	    $objectsrc->fetch($object->$typeobject->id);

+	    print $langs->trans("RefProposal").'</td>';

+	    print '<td colspan="3">';

+	    print $objectsrc->getNomUrl(1, 'expedition');

+	    print "</td>\n";

+	    print '</tr>';

@@ -219,0 +245 @@
+	//print '<div class="ficheaddleft">';

@@ -222,0 +249 @@
+	//print '</div>';

@@ -229 +256 @@
-	print dol_get_fiche_end();

+	dol_fiche_end();

@@ -237,5 +264,4 @@
-	foreach ($dirtpls as $reldir) {

-		$res = @include dol_buildpath($reldir.'/contacts.tpl.php');

-		if ($res) {

-			break;

-		}

+	foreach ($dirtpls as $reldir)

+	{

+	    $res = @include dol_buildpath($reldir.'/contacts.tpl.php');

+	    if ($res) break;

--- /tmp/dsg/dolibarr/htdocs/expedition/github_19.0.3_document.php
+++ /tmp/dsg/dolibarr/htdocs/expedition/client_document.php
@@ -29 +28,0 @@
-// Load Dolibarr environment

@@ -37 +36 @@
-if (isModEnabled('project')) {

+if (!empty($conf->projet->enabled)) {

@@ -48,0 +48,7 @@
+// Security check

+if ($user->socid)

+{

+	$socid = $user->socid;

+}

+$result = restrictedArea($user, 'expedition', $id, '');

+

@@ -51,2 +57,2 @@
-$sortfield = GETPOST('sortfield', 'aZ09comma');

-$sortorder = GETPOST('sortorder', 'aZ09comma');

+$sortfield = GETPOST("sortfield", 'alpha');

+$sortorder = GETPOST("sortorder", 'alpha');

@@ -54,3 +60 @@
-if (empty($page) || $page == -1) {

-	$page = 0;

-}     // If $page is not defined, or '' or -1

+if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1

@@ -60,6 +64,2 @@
-if (!$sortorder) {

-	$sortorder = "ASC";

-}

-if (!$sortfield) {

-	$sortfield = "name";

-}

+if (!$sortorder) $sortorder = "ASC";

+if (!$sortfield) $sortfield = "name";

@@ -68,31 +67,0 @@
-

-if ($id > 0 || !empty($ref)) {

-	$object->fetch($id, $ref);

-	$object->fetch_thirdparty();

-

-	if (!empty($object->origin)) {

-		$typeobject = $object->origin;

-		$origin = $object->origin;

-		$object->fetch_origin();

-	}

-

-	// Linked documents

-	if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {

-		$objectsrc = new Commande($db);

-		$objectsrc->fetch($object->$typeobject->id);

-	}

-	if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {

-		$objectsrc = new Propal($db);

-		$objectsrc->fetch($object->$typeobject->id);

-	}

-

-	$upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($object->ref);

-}

-

-// Security check

-if ($user->socid) {

-	$socid = $user->socid;

-}

-$result = restrictedArea($user, 'expedition', $object->id, '');

-

-$permissiontoadd = $user->rights->expedition->creer;	// Used by the include of actions_dellink.inc.php

@@ -103,0 +73,5 @@
+if ($object->fetch($id))

+{

+	$object->fetch_thirdparty();

+	$upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($object->ref);

+}

@@ -105 +79 @@
-include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';

+include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';

@@ -123 +97 @@
-		print dol_get_fiche_head($head, 'documents', $langs->trans("Shipment"), -1, $object->picto);

+		dol_fiche_head($head, 'documents', $langs->trans("Shipment"), -1, 'sending');

@@ -127 +101 @@
-		$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);

+		$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);

@@ -130 +104 @@
-			$totalsize += $file['size'];

+		    $totalsize += $file['size'];

@@ -139,2 +113,2 @@
-		$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);

-		$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1);

+		$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);

+		$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);

@@ -142 +116 @@
-		$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);

+		$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);

@@ -145 +119 @@
-		if (isModEnabled('project')) {

+		if (!empty($conf->projet->enabled)) {

@@ -147,3 +121,2 @@
-			$morehtmlref .= '<br>';

-			if (0) {	// Do not change on shipment

-				$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');

+			$morehtmlref .= '<br>'.$langs->trans('Project').' ';

+			if (0) {    // Do not change on shipment

@@ -151 +124 @@
-					$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';

+					$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';

@@ -153 +126,11 @@
-				$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');

+				if ($action == 'classify') {

+					// $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);

+					$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

+					$morehtmlref .= '<input type="hidden" name="action" value="classin">';

+					$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';

+					$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);

+					$morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';

+					$morehtmlref .= '</form>';

+				} else {

+					$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);

+				}

@@ -154,0 +138,3 @@
+				// We don't have project on shipment, so we will use the project or source object instead

+				// TODO Add project on shipment

+				$morehtmlref .= ' : ';

@@ -158,4 +144,5 @@
-					$morehtmlref .= $proj->getNomUrl(1);

-					if ($proj->title) {

-						$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';

-					}

+					$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';

+					$morehtmlref .= $proj->ref;

+					$morehtmlref .= '</a>';

+				} else {

+					$morehtmlref .= '';

@@ -185 +172 @@
-		print dol_get_fiche_end();

+		dol_fiche_end();

@@ -188 +175 @@
-		$permissiontoadd = $user->rights->expedition->creer;

+		$permission = $user->rights->expedition->creer;

@@ -191,2 +178,3 @@
-		include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';

-	} else {

+		include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';

+	}

+	else {

@@ -195 +183,2 @@
-} else {

+}

+else {

--- /tmp/dsg/dolibarr/htdocs/expedition/github_19.0.3_index.php
+++ /tmp/dsg/dolibarr/htdocs/expedition/client_index.php
@@ -6 +5,0 @@
- * Copyright (C) 2020      Tobias Sekan         <tobias.sekan@startmail.com>

@@ -28 +26,0 @@
-// Load Dolibarr environment

@@ -35,2 +32,0 @@
-$socid = GETPOST('socid', 'int');

-

@@ -57,0 +54,13 @@
+

+

+if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo

+{

+    print '<form method="post" action="list.php">';

+    print '<input type="hidden" name="token" value="'.newToken().'">';

+    print '<div class="div-table-responsive-no-min">';

+    print '<table class="noborder nohover centpercent">';

+    print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';

+    print '<tr class="oddeven"><td>';

+    print $langs->trans("Shipment").':</td><td><input type="text" class="flat" name="sall" size="18"></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';

+    print "</table></div></form><br>\n";

+}

@@ -72 +81,2 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

+if (!$user->rights->societe->client->voir && !$socid)

+{

@@ -74 +84 @@
-	$sql .= $clause." sc.fk_user = ".((int) $user->id);

+	$sql .= $clause." sc.fk_user = ".$user->id;

@@ -77 +87 @@
-$sql .= $clause." e.fk_statut = ".Expedition::STATUS_DRAFT;

+$sql .= $clause." e.fk_statut = 0";

@@ -79,3 +89 @@
-if ($socid) {

-	$sql .= " AND c.fk_soc = ".((int) $socid);

-}

+if ($socid) $sql .= " AND c.fk_soc = ".$socid;

@@ -84 +92,2 @@
-if ($resql) {

+if ($resql)

+{

@@ -90,9 +99,4 @@
-	print '<th colspan="3">';

-	print $langs->trans("SendingsToValidate").' ';

-	print '<a href="'.DOL_URL_ROOT.'/expedition/list.php?search_status='.Expedition::STATUS_DRAFT.'">';

-	print '<span class="badge">'.$num.'</span>';

-	print '</a>';

-	print '</th>';

-	print '</tr>';

-

-	if ($num) {

+	print '<th colspan="3">'.$langs->trans("SendingsToValidate").'</th></tr>';

+

+	if ($num)

+	{

@@ -100 +104,2 @@
-		while ($i < $num) {

+		while ($i < $num)

+		{

@@ -114,3 +119 @@
-			if ($obj->commande_id) {

-				print '<a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a>';

-			}

+			if ($obj->commande_id) print '<a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a>';

@@ -120 +123,2 @@
-	} else {

+	} else

+	{

@@ -130 +134 @@
-print '</div><div class="fichetwothirdright">';

+print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';

@@ -144,3 +148 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";

@@ -148,3 +150 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " AND sc.fk_user = ".((int) $user->id);

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;

@@ -152,3 +152 @@
-if ($socid) {

-	$sql .= " AND c.fk_soc = ".((int) $socid);

-}

+if ($socid) $sql .= " AND c.fk_soc = ".$socid;

@@ -159 +157,2 @@
-if ($resql) {

+if ($resql)

+{

@@ -161,13 +160,2 @@
-

-	print '<div class="div-table-responsive-no-min">';

-	print '<table class="noborder centpercent">';

-	print '<tr class="liste_titre">';

-	print '<th colspan="4">';

-	print $langs->trans("LastSendings").' ';

-	print '<a href="'.DOL_URL_ROOT.'/expedition/list.php?search_status='.Expedition::STATUS_VALIDATED.'">';

-	print '<span class="badge">'.$num.'</span>';

-	print '</a>';

-	print '</th>';

-	print '</tr>';

-

-	if ($num) {

+	if ($num)

+	{

@@ -175 +163,6 @@
-		while ($i < $num) {

+		print '<div class="div-table-responsive-no-min">';

+		print '<table class="noborder centpercent">';

+		print '<tr class="liste_titre">';

+		print '<th colspan="4">'.$langs->trans("LastSendings", $num).'</th></tr>';

+		while ($i < $num)

+		{

@@ -187 +180,2 @@
-			if ($obj->commande_id > 0) {

+			if ($obj->commande_id > 0)

+			{

@@ -199,2 +193 @@
-	} else {

-		print '<tr><td>'.$langs->trans("None").'</td><td></td><td></td><td></td></tr>';

+		print "</table></div><br>";

@@ -202 +194,0 @@
-	print "</table></div><br>";

@@ -204,3 +196,2 @@
-} else {

-	dol_print_error($db);

-}

+}

+else dol_print_error($db);

@@ -214,3 +205 @@
-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

-}

+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

@@ -220,6 +209,2 @@
-if ($socid > 0) {

-	$sql .= " AND c.fk_soc = ".((int) $socid);

-}

-if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {

-	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);

-}

+if ($socid > 0) $sql .= " AND c.fk_soc = ".$socid;

+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;

@@ -229 +214,2 @@
-if ($resql) {

+if ($resql)

+{

@@ -233,13 +219,2 @@
-

-	print '<div class="div-table-responsive-no-min">';

-	print '<table class="noborder centpercent">';

-

-	print '<tr class="liste_titre">';

-	print '<th colspan="3">'.$langs->trans("OrdersToProcess").' ';

-	print '<a href="'.DOL_URL_ROOT.'/commande/list.php?search_status='.Commande::STATUS_VALIDATED.','.Commande::STATUS_ACCEPTED.'">';

-	print '<span class="badge">'.$num.'</span>';

-	print '</a>';

-	print '</th>';

-	print '</tr>';

-

-	if ($num) {

+	if ($num)

+	{

@@ -247 +222,6 @@
-		while ($i < $num && $i < 10) {

+        print '<div class="div-table-responsive-no-min">';

+		print '<table class="noborder centpercent">';

+		print '<tr class="liste_titre">';

+		print '<th colspan="3">'.$langs->trans("OrdersToProcess").' <span class="badge">'.$num.'</span></th></tr>';

+		while ($i < $num && $i < 10)

+		{

@@ -250 +230 @@
-			$orderstatic->id = $obj->rowid;

+		    $orderstatic->id = $obj->rowid;

@@ -254,3 +234,3 @@
-			$orderstatic->billed = $obj->billed;

-

-			$companystatic->name = $obj->name;

+            $orderstatic->billed = $obj->billed;

+

+            $companystatic->name = $obj->name;

@@ -265,4 +245,4 @@
-			print '<td class="right">';

-			print $orderstatic->getLibStatut(3);

-			print '</td>';

-			print '</tr>';

+            print '<td class="right">';

+            print $orderstatic->getLibStatut(3);

+            print '</td>';

+            print '</tr>';

@@ -279,2 +259,2 @@
-	} else {

-		print '<tr><td>'.$langs->trans("None").'</td><td></td><td></td></tr>';

+

+		print "</table></div><br>";

@@ -282,8 +262,5 @@
-

-	print "</table></div><br>";

-} else {

-	dol_print_error($db);

-}

-

-

-print '</div></div>';

+}

+else dol_print_error($db);

+

+

+print '</div></div></div>';

--- /tmp/dsg/dolibarr/htdocs/expedition/github_19.0.3_list.php
+++ /tmp/dsg/dolibarr/htdocs/expedition/client_list.php
@@ -5 +5 @@
- * Copyright (C) 2016-2021 Ferran Marcet        <fmarcet@2byte.es>

+ * Copyright (C) 2016-2018 Ferran Marcet        <fmarcet@2byte.es>

@@ -8 +7,0 @@
- * Copyright (C) 2023      Christophe Battarel	<christophe@altairis.fr>

@@ -30 +28,0 @@
-// Load Dolibarr environment

@@ -41,3 +39,3 @@
-$langs->loadLangs(array("sendings", "deliveries", 'companies', 'bills', 'products'));

-

-$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'shipmentlist'; // To manage different context of search

+$langs->loadLangs(array("sendings", "deliveries", 'companies', 'bills'));

+

+$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'shipmentlist'; // To manage different context of search

@@ -51,2 +49,5 @@
-$optioncss = GETPOST('optioncss', 'alpha');

-$mode = GETPOST('mode', 'alpha');

+

+// Security check

+$expeditionid = GETPOST('id', 'int');

+if ($user->socid) $socid = $user->socid;

+$result = restrictedArea($user, 'expedition', $expeditionid, '');

@@ -58,2 +58,0 @@
-$search_shipping_method_id = GETPOST('search_shipping_method_id');

-$search_tracking = GETPOST("search_tracking", 'alpha');

@@ -62 +61 @@
-$search_state = GETPOST("search_state");

+$search_state = trim(GETPOST("search_state"));

@@ -70 +69,2 @@
-$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));

+$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));

+$socid = GETPOST('socid', 'int');

@@ -73 +73 @@
-$search_categ_cus = GETPOST("search_categ_cus", 'int');

+$search_categ_cus = trim(GETPOST("search_categ_cus", 'int'));

@@ -75,4 +75,5 @@
-

-$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;

-$sortfield = GETPOST('sortfield', 'aZ09comma');

-$sortorder = GETPOST('sortorder', 'aZ09comma');

+$optioncss = GETPOST('optioncss', 'alpha');

+

+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;

+$sortfield = GETPOST('sortfield', 'alpha');

+$sortorder = GETPOST('sortorder', 'alpha');

@@ -80,10 +81,3 @@
-if (!$sortfield) {

-	$sortfield = "e.ref";

-}

-if (!$sortorder) {

-	$sortorder = "DESC";

-}

-if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {

-	// If $page is not defined, or '' or -1 or if we click on clear filters

-	$page = 0;

-}

+if (!$sortfield) $sortfield = "e.ref";

+if (!$sortorder) $sortorder = "DESC";

+if (empty($page) || $page == -1 || (empty($toselect) && $massaction === '0')) { $page = 0; }     // If $page is not defined, or '' or -1

@@ -94 +88 @@
-$search_status = GETPOST('search_status', 'intcomma');

+$search_status = GETPOST('search_status');

@@ -98,0 +93 @@
+$form = new Form($db);

@@ -104 +99 @@
-// Fetch optionals attributes and labels

+// fetch optionals attributes and labels

@@ -114,2 +108,0 @@
-	//'e.fk_shipping_method'=>'SendingMethod', // TODO fix this, does not work

-	'e.tracking_number'=>"TrackingNumber",

@@ -117,3 +110 @@
-if (empty($user->socid)) {

-	$fieldstosearchall["e.note_private"] = "NotePrivate";

-}

+if (empty($user->socid)) $fieldstosearchall["e.note_private"] = "NotePrivate";

@@ -123,12 +114,10 @@
-	'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1, 'position'=>1),

-	'e.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1, 'position'=>2),

-	's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>3),

-	's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1, 'position'=>4),

-	's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1, 'position'=>5),

-	'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0, 'position'=>6),

-	'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0, 'position'=>7),

-	'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers, 'position'=>8),

-	'e.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1, 'position'=>9),

-	'e.fk_shipping_method'=>array('label'=>$langs->trans('SendingMethod'), 'checked'=>1, 'position'=>10),

-	'e.tracking_number'=>array('label'=>$langs->trans("TrackingNumber"), 'checked'=>1, 'position'=>11),

-	'e.weight'=>array('label'=>$langs->trans("Weight"), 'checked'=>0, 'position'=>12),

+	'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),

+	'e.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),

+	's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),

+	's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),

+	's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),

+	'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),

+	'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),

+	'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),

+	'e.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1),

+	'e.weight'=>array('label'=>$langs->trans("Weight"), 'checked'=>0),

@@ -138,3 +127,3 @@
-	'l.ref'=>array('label'=>$langs->trans("DeliveryRef"), 'checked'=>1, 'position'=>1010, 'enabled'=>(getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') ? 1 : 0)),

-	'l.date_delivery'=>array('label'=>$langs->trans("DateReceived"), 'position'=>1020, 'checked'=>1, 'enabled'=>(getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') ? 1 : 0)),

-	'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1100, 'enabled'=>'getDolGlobalString("WORKFLOW_BILL_ON_SHIPMENT") !== "0"')

+	'l.ref'=>array('label'=>$langs->trans("DeliveryRef"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled) ? 0 : 1)),

+	'l.date_delivery'=>array('label'=>$langs->trans("DateReceived"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled) ? 0 : 1)),

+	'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(!empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)))

@@ -144,2 +133,8 @@
-include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';

-

+if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0)

+{

+	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val)

+	{

+		if (!empty($extrafields->attributes[$object->table_element]['list'][$key]))

+			$arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$object->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key]));

+	}

+}

@@ -148,8 +142,0 @@
-

-// Security check

-$expeditionid = GETPOST('id', 'int');

-if ($user->socid) {

-	$socid = $user->socid;

-}

-$result = restrictedArea($user, 'expedition', $expeditionid, '');

-

@@ -163,7 +150,2 @@
-if (GETPOST('cancel', 'alpha')) {

-	$action = 'list';

-	$massaction = '';

-}

-if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {

-	$massaction = '';

-}

+if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }

+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }

@@ -173,3 +155 @@
-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

@@ -180 +160,3 @@
-if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers

+if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers

+{

+	$search_categ = '';

@@ -193,2 +174,0 @@
-	$search_tracking = '';

-	$search_shipping_method_id = '';

@@ -202 +182 @@
-	$toselect = array();

+    $toselect = '';

@@ -207 +187,2 @@
-if (empty($reshook)) {

+if (empty($reshook))

+{

@@ -215,30 +196,2 @@
-

-	// If massaction is close

-	if ($massaction == 'classifyclose') {

-		$error=0;

-		$selectids = GETPOST('toselect', 'array');

-		foreach ($selectids as $selectid) {

-			//	$object->fetch($selectid);

-			$object->fetch($selectid);

-			$result = $object->setClosed();

-		}

-

-		$massaction = $action = 'classifyclose';

-

-		if ($result < 0) {

-			$error++;

-		}

-

-

-		if (!$error) {

-			$db->commit();

-

-			setEventMessage($langs->trans("Close Done"));

-			header('Location: '.$_SERVER["PHP_SELF"]);

-			exit;

-		} else {

-			$db->rollback();

-			exit;

-		}

-	}

-}

+}

+

@@ -263,8 +216,2 @@
-if ($search_all || $search_user > 0) {

-	$sql = 'SELECT DISTINCT';

-}

-$sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_delivery as delivery_date, e.fk_statut, e.billed, e.tracking_number, e.fk_shipping_method,";

-if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {

-	// Link for delivery fields ref and date. Does not duplicate the line because we should always have ony 1 link or 0 per shipment

-	$sql .= " l.date_delivery as date_reception,";

-}

+if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';

+$sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_delivery as date_livraison, l.date_delivery as date_reception, e.fk_statut, e.billed,";

@@ -275,0 +223 @@
+if ($search_categ_cus) $sql .= ", cc.fk_categorie, cc.fk_soc";

@@ -278,3 +226 @@
-	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {

-		$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');

-	}

+	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');

@@ -284 +230 @@
-$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook

@@ -286,3 +231,0 @@
-

-$sqlfields = $sql; // $sql fields to remove for count total

-

@@ -290,4 +233,2 @@
-if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {

-	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";

-}

-if ($search_all) {

+if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)";

+if ($sall || $search_product_category > 0) {

@@ -296,0 +238 @@
+if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';

@@ -297,0 +240 @@
+if (!empty($search_categ_cus)) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ

@@ -301,5 +244,2 @@
-if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {

-	// Link for delivery fields ref and date. Does not duplicate the line because we should always have ony 1 link or 0 per shipment

-	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'";

-	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."delivery as l ON l.rowid = ee.fk_target";

-}

+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'";

+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";

@@ -307,4 +247,5 @@
-if ($search_user > 0) {		// Get link to order to get the order id in eesource.fk_source

-	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as eesource ON eesource.fk_target = e.rowid AND eesource.targettype = 'shipping' AND eesource.sourcetype = 'commande'";

-}

-if ($search_user > 0) {

+

+// We'll need this table joined to the select in order to filter by sale

+if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";

+if ($search_user > 0)

+{

@@ -314,6 +254,0 @@
-

-// Add table from hooks

-$parameters = array();

-$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-$sql .= $hookmanager->resPrint;

-

@@ -321,135 +256,33 @@
-

-if ($socid > 0) {

-	$sql .= " AND s.rowid = ".((int) $socid);

-}

-if ($socid) {

-	$sql .= " AND e.fk_soc = ".((int) $socid);

-}

-if ($search_status != '' && $search_status >= 0) {

-	$sql .= " AND e.fk_statut = ".((int) $search_status);

-}

-if ($search_ref_customer != '') {

-	$sql .= natural_search('e.ref_customer', $search_ref_customer);

-}

-if ($search_billed != '' && $search_billed >= 0) {

-	$sql .= ' AND e.billed = '.((int) $search_billed);

-}

-if ($search_town) {

-	$sql .= natural_search('s.town', $search_town);

-}

-if ($search_zip) {

-	$sql .= natural_search("s.zip", $search_zip);

-}

-if ($search_state) {

-	$sql .= natural_search("state.nom", $search_state);

-}

-if ($search_country) {

-	$sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';

-}

-if ($search_shipping_method_id > 0) {

-	$sql .= " AND e.fk_shipping_method = ".((int) $search_shipping_method_id);

-}

-if ($search_tracking) {

-	$sql .= natural_search("e.tracking_number", $search_tracking);

-}

-if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {

-	$sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';

-}

-if ($search_user > 0) {

-	// The contact on a shipment is also the contact of the order.

-	$sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = eesource.fk_source AND ec.fk_socpeople = ".((int) $search_user);

-}

-if ($search_company) {

-	$sql .= natural_search('s.nom', $search_company);

-}

-if ($search_ref_exp) {

-	$sql .= natural_search('e.ref', $search_ref_exp);

-}

-if ($search_datedelivery_start) {

-	$sql .= " AND e.date_delivery >= '".$db->idate($search_datedelivery_start)."'";

-}

-if ($search_datedelivery_end) {

-	$sql .= " AND e.date_delivery <= '".$db->idate($search_datedelivery_end)."'";

-}

-if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {

-	if ($search_ref_liv) {

-		$sql .= natural_search('l.ref', $search_ref_liv);

-	}

-	if ($search_datereceipt_start) {

-		$sql .= " AND l.date_delivery >= '".$db->idate($search_datereceipt_start)."'";

-	}

-	if ($search_datereceipt_end) {

-		$sql .= " AND l.date_delivery <= '".$db->idate($search_datereceipt_end)."'";

-	}

-}

-if ($search_all) {

-	$sql .= natural_search(array_keys($fieldstosearchall), $search_all);

-}

-// Search on sale representative

-if ($search_sale && $search_sale != '-1') {

-	if ($search_sale == -2) {

-		$sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = e.fk_soc)";

-	} elseif ($search_sale > 0) {

-		$sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = e.fk_soc AND sc.fk_user = ".((int) $search_sale).")";

-	}

-}

-// Search for tag/category ($searchCategoryCustomerList is an array of ID)

-$searchCategoryCustomerOperator = -1;

-$searchCategoryCustomerList = array($search_categ_cus);

-if (!empty($searchCategoryCustomerList)) {

-	$searchCategoryCustomerSqlList = array();

-	$listofcategoryid = '';

-	foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {

-		if (intval($searchCategoryCustomer) == -2) {

-			$searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc)";

-		} elseif (intval($searchCategoryCustomer) > 0) {

-			if ($searchCategoryCustomerOperator == 0) {

-				$searchCategoryCustomerSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc AND cs.fk_categorie = ".((int) $searchCategoryCustomer).")";

-			} else {

-				$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);

-			}

-		}

-	}

-	if ($listofcategoryid) {

-		$searchCategoryCustomerSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc AND cs.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";

-	}

-	if ($searchCategoryCustomerOperator == 1) {

-		if (!empty($searchCategoryCustomerSqlList)) {

-			$sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";

-		}

-	} else {

-		if (!empty($searchCategoryCustomerSqlList)) {

-			$sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";

-		}

-	}

-}

-// Search for tag/category ($searchCategoryProductList is an array of ID)

-$searchCategoryProductOperator = -1;

-$searchCategoryProductList = array($search_product_category);

-if (!empty($searchCategoryProductList)) {

-	$searchCategoryProductSqlList = array();

-	$listofcategoryid = '';

-	foreach ($searchCategoryProductList as $searchCategoryProduct) {

-		if (intval($searchCategoryProduct) == -2) {

-			$searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product)";

-		} elseif (intval($searchCategoryProduct) > 0) {

-			if ($searchCategoryProductOperator == 0) {

-				$searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";

-			} else {

-				$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);

-			}

-		}

-	}

-	if ($listofcategoryid) {

-		$searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";

-	}

-	if ($searchCategoryProductOperator == 1) {

-		if (!empty($searchCategoryProductSqlList)) {

-			$sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";

-		}

-	} else {

-		if (!empty($searchCategoryProductSqlList)) {

-			$sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";

-		}

-	}

-}

+if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category;

+if ($socid > 0) $sql .= ' AND s.rowid = '.$socid;

+if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all

+{

+	$sql .= " AND e.fk_soc = sc.fk_soc";

+	$sql .= " AND sc.fk_user = ".$user->id;

+}

+if ($socid)

+{

+	$sql .= " AND e.fk_soc = ".$socid;

+}

+if ($search_status <> '' && $search_status >= 0) {

+	$sql .= " AND e.fk_statut = ".$search_status;

+}

+if ($search_ref_customer != '') $sql .= natural_search('e.ref_customer', $search_ref_customer);

+if ($search_billed != '' && $search_billed >= 0) $sql .= ' AND e.billed = '.$search_billed;

+if ($search_town)  $sql .= natural_search('s.town', $search_town);

+if ($search_zip)   $sql .= natural_search("s.zip", $search_zip);

+if ($search_state) $sql .= natural_search("state.nom", $search_state);

+if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';

+if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';

+if ($search_sale > 0)                        $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$search_sale;

+if ($search_ref_exp) $sql .= natural_search('e.ref', $search_ref_exp);

+if ($search_ref_liv) $sql .= natural_search('l.ref', $search_ref_liv);

+if ($search_company) $sql .= natural_search('s.nom', $search_company);

+if ($search_datedelivery_start)	$sql .= " AND e.date_delivery >= '".$db->idate($search_datedelivery_start)."'";

+if ($search_datedelivery_end)	$sql .= " AND e.date_delivery <= '".$db->idate($search_datedelivery_end)."'";

+if ($search_datereceipt_start)	$sql .= " AND l.date_delivery >= '".$db->idate($search_datereceipt_start)."'";

+if ($search_datereceipt_end)	$sql .= " AND l.date_delivery <= '".$db->idate($search_datereceipt_end)."'";

+if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);

+if ($search_categ_cus > 0)                   $sql .= " AND cc.fk_categorie = ".$db->escape($search_categ_cus);

+if ($search_categ_cus == -2)                 $sql .= " AND cc.fk_categorie IS NULL";

+

@@ -461 +294 @@
-$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook

@@ -464,4 +297 @@
-// Add HAVING from hooks

-$parameters = array();

-$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;

+$sql .= $db->order($sortfield, $sortorder);

@@ -470,13 +300,6 @@
-if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {

-	/* The fast and low memory method to get and count full list converts the sql into a sql count */

-	$sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);

-	$sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);

-	$resql = $db->query($sqlforcount);

-	if ($resql) {

-		$objforcount = $db->fetch_object($resql);

-		$nbtotalofrecords = $objforcount->nbtotalofrecords;

-	} else {

-		dol_print_error($db);

-	}

-

-	if (($page * $limit) > $nbtotalofrecords) {	// if total resultset is smaller then paging size (filtering), goto and load page 0

+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))

+{

+	$result = $db->query($sql);

+	$nbtotalofrecords = $db->num_rows($result);

+	if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0

+	{

@@ -486,8 +309,3 @@
-	$db->free($resql);

-}

-

-// Complete request and execute it with limit

-$sql .= $db->order($sortfield, $sortorder);

-if ($limit) {

-	$sql .= $db->plimit($limit + 1, $offset);

-}

+}

+

+$sql .= $db->plimit($limit + 1, $offset);

@@ -497,205 +315,252 @@
-if (!$resql) {

-	dol_print_error($db);

-	exit;

-}

-

-$num = $db->num_rows($resql);

-

-$arrayofselected = is_array($toselect) ? $toselect : array();

-

-$expedition = new Expedition($db);

-

-$param = '';

-if (!empty($mode)) {

-	$param .= '&mode='.urlencode($mode);

-}

-if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {

-	$param .= '&contextpage='.urlencode($contextpage);

-}

-if ($limit > 0 && $limit != $conf->liste_limit) {

-	$param .= '&limit='.((int) $limit);

-}

-if ($search_all) {

-	$param .= "&search_all=".urlencode($search_all);

-}

-if ($search_ref_exp) {

-	$param .= "&search_ref_exp=".urlencode($search_ref_exp);

-}

-if ($search_ref_liv) {

-	$param .= "&search_ref_liv=".urlencode($search_ref_liv);

-}

-if ($search_ref_customer) {

-	$param .= "&search_ref_customer=".urlencode($search_ref_customer);

-}

-if ($search_user > 0) {

-	$param .= '&search_user='.urlencode($search_user);

-}

-if ($search_sale > 0) {

-	$param .= '&search_sale='.urlencode($search_sale);

-}

-if ($search_company) {

-	$param .= "&search_company=".urlencode($search_company);

-}

-if ($search_shipping_method_id) {

-	$param .= "&search_shipping_method_id=".urlencode($search_shipping_method_id);

-}

-if ($search_tracking) {

-	$param .= "&search_tracking=".urlencode($search_tracking);

-}

-if ($search_town) {

-	$param .= '&search_town='.urlencode($search_town);

-}

-if ($search_zip) {

-	$param .= '&search_zip='.urlencode($search_zip);

-}

-if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {

-	$param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);

-}

-if ($search_datedelivery_start) {

-	$param .= '&search_datedelivery_startday='.urlencode(dol_print_date($search_datedelivery_start, '%d')).'&search_datedelivery_startmonth='.urlencode(dol_print_date($search_datedelivery_start, '%m')).'&search_datedelivery_startyear='.urlencode(dol_print_date($search_datedelivery_start, '%Y'));

-}

-if ($search_datedelivery_end) {

-	$param .= '&search_datedelivery_endday='.urlencode(dol_print_date($search_datedelivery_end, '%d')).'&search_datedelivery_endmonth='.urlencode(dol_print_date($search_datedelivery_end, '%m')).'&search_datedelivery_endyear='.urlencode(dol_print_date($search_datedelivery_end, '%Y'));

-}

-if ($search_datereceipt_start) {

-	$param .= '&search_datereceipt_startday='.urlencode(dol_print_date($search_datereceipt_start, '%d')).'&search_datereceipt_startmonth='.urlencode(dol_print_date($search_datereceipt_start, '%m')).'&search_datereceipt_startyear='.urlencode(dol_print_date($search_datereceipt_start, '%Y'));

-}

-if ($search_datereceipt_end) {

-	$param .= '&search_datereceipt_endday='.urlencode(dol_print_date($search_datereceipt_end, '%d')).'&search_datereceipt_endmonth='.urlencode(dol_print_date($search_datereceipt_end, '%m')).'&search_datereceipt_endyear='.urlencode(dol_print_date($search_datereceipt_end, '%Y'));

-}

-if ($search_product_category != '') {

-	$param .= '&search_product_category='.urlencode($search_product_category);

-}

-if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {

-	$param .= '&search_categ_cus='.urlencode($search_categ_cus);

-}

-if ($search_status != '') {

-	$param .= '&search_status='.urlencode($search_status);

-}

-if ($optioncss != '') {

-	$param .= '&optioncss='.urlencode($optioncss);

-}

-// Add $param from extra fields

-include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';

-

-// Add $param from hooks

-$parameters = array('param' => &$param);

-$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-$param .= $hookmanager->resPrint;

-

-$arrayofmassactions = array(

-	'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),

-	'classifyclose' => img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("Close"),

-	'presend'  => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),

-);

-if (in_array($massaction, array('presend'))) {

-	$arrayofmassactions = array();

-}

-$massactionbutton = $form->selectMassAction('', $arrayofmassactions);

-

-// Currently: a sending can't create from sending list

-// $url = DOL_URL_ROOT.'/expedition/card.php?action=create';

-// if (!empty($socid)) $url .= '&socid='.$socid;

-// $newcardbutton = dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', $url, '', $user->rights->expedition->creer);

-$newcardbutton  = '';

-$newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));

-$newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));

-$newcardbutton .= dolGetButtonTitleSeparator();

-$newcardbutton .= dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/expedition/card.php?action=create2', '', $user->hasRight('expedition', 'creer'));

-

-$i = 0;

-print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";

-if ($optioncss != '') {

-	print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';

-}

-print '<input type="hidden" name="token" value="'.newToken().'">';

-print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';

-print '<input type="hidden" name="action" value="list">';

-print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';

-print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';

-print '<input type="hidden" name="mode" value="'.$mode.'">';

-

-print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dolly', 0, $newcardbutton, '', $limit, 0, 0, 1);

-

-$topicmail = "SendShippingRef";

-$modelmail = "shipping_send";

-$objecttmp = new Expedition($db);

-$trackid = 'shi'.$object->id;

-include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';

-

-if ($search_all) {

-	foreach ($fieldstosearchall as $key => $val) {

-		$fieldstosearchall[$key] = $langs->trans($val);

-	}

-	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';

-}

-

-$moreforfilter = '';

-

-// If the user can view prospects other than his'

-if ($user->hasRight('user', 'user', 'lire')) {

-	$langs->load("commercial");

-	$moreforfilter .= '<div class="divsearchfield">';

-	$tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');

-	$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"');

-	$moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');

-	$moreforfilter .= '</div>';

-}

-// If the user can view other users

-if ($user->hasRight('user', 'user', 'lire')) {

-	$moreforfilter .= '<div class="divsearchfield">';

-	$tmptitle = $langs->trans('LinkedToSpecificUsers');

-	$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"');

-	$moreforfilter .= $form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');

-	$moreforfilter .= '</div>';

-}

-// If the user can view prospects other than his'

-if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {

-	include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';

-	$moreforfilter .= '<div class="divsearchfield">';

-	$tmptitle = $langs->trans('IncludingProductWithTag');

-	$moreforfilter .= img_picto($tmptitle, 'category');

-	//$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);

-	//$moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);

-	$moreforfilter .= $formother->select_categories(Categorie::TYPE_PRODUCT, $search_product_category, 'search_product_category', 1, $tmptitle);

-

-	$moreforfilter .= '</div>';

-}

-if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {

-	require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';

-	$moreforfilter .= '<div class="divsearchfield">';

-	$tmptitle = $langs->trans('CustomersProspectsCategoriesShort');

-	$moreforfilter .= img_picto($tmptitle, 'category');

-	$moreforfilter .= $formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle);

-	$moreforfilter .= '</div>';

-}

-$parameters = array();

-$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-if (empty($reshook)) {

-	$moreforfilter .= $hookmanager->resPrint;

-} else {

-	$moreforfilter = $hookmanager->resPrint;

-}

-

-if (!empty($moreforfilter)) {

-	print '<div class="liste_titre liste_titre_bydiv centpercent">';

-	print $moreforfilter;

-	print '</div>';

-}

-

-$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;

-$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', ''));

-if ($massactionbutton) {

-	$selectedfields .= $form->showCheckAddButtons('checkforselect', 1); // This also change content of $arrayfields

-}

-

-print '<div class="div-table-responsive">';

-print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";

-

-// Fields title search

-// --------------------------------------------------------------------

-print '<tr class="liste_titre_filter">';

-// Action column

-if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print '<td class="liste_titre center maxwidthsearch">';

-	$searchpicto = $form->showFilterButtons('left');

+if ($resql)

+{

+	$num = $db->num_rows($resql);

+

+	$arrayofselected = is_array($toselect) ? $toselect : array();

+

+	$expedition = new Expedition($db);

+

+	$param = '';

+	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);

+	if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);

+	if ($sall) $param .= "&amp;sall=".urlencode($sall);

+	if ($search_ref_exp)  $param .= "&amp;search_ref_exp=".urlencode($search_ref_exp);

+	if ($search_ref_liv)  $param .= "&amp;search_ref_liv=".urlencode($search_ref_liv);

+	if ($search_ref_customer) $param .= "&amp;search_ref_customer=".urlencode($search_ref_customer);

+	if ($search_user > 0) 			$param .= '&search_user='.urlencode($search_user);

+	if ($search_sale > 0) 			$param .= '&search_sale='.urlencode($search_sale);

+	if ($search_company)   $param .= "&amp;search_company=".urlencode($search_company);

+	if ($search_town)      $param .= '&search_town='.urlencode($search_town);

+	if ($search_zip)       $param .= '&search_zip='.urlencode($search_zip);

+

+	if ($search_datedelivery_start)	$param .= '&search_datedelivery_start='.urlencode($search_datedelivery_start);

+	if ($search_datedelivery_end)	$param .= '&search_datedelivery_end='.urlencode($search_datedelivery_end);

+	if ($search_datereceipt_start)	$param .= '&search_datereceipt_start='.urlencode($search_datereceipt_start);

+	if ($search_datereceipt_end)	$param .= '&search_datereceipt_end='.urlencode($search_datereceipt_end);

+

+	if ($search_product_category != '') $param .= '&search_product_category='.urlencode($search_product_category);

+	if ($search_categ_cus > 0)      $param .= '&search_categ_cus='.urlencode($search_categ_cus);

+	if ($search_status != '') $param .= '&viewstatut='.urlencode($search_status);

+	if ($optioncss != '')  $param .= '&optioncss='.urlencode($optioncss);

+	// Add $param from extra fields

+	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';

+

+	$arrayofmassactions = array(

+		'builddoc' => $langs->trans("PDFMerge"),

+		//'classifyclose'=>$langs->trans("Close"), TODO massive close shipment ie: when truck is charged

+		'presend'  => $langs->trans("SendByMail"),

+	);

+	if (in_array($massaction, array('presend'))) $arrayofmassactions = array();

+	$massactionbutton = $form->selectMassAction('', $arrayofmassactions);

+

+	$newcardbutton = '';

+	if ($user->rights->expedition->creer)

+	{

+		$newcardbutton .= dolGetButtonTitle($langs->trans('NewSending'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/expedition/card.php?action=create2');

+	}

+

+	$i = 0;

+	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";

+	if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';

+	print '<input type="hidden" name="token" value="'.newToken().'">';

+	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';

+	print '<input type="hidden" name="action" value="list">';

+	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';

+	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';

+

+	print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'dolly', 0, $newcardbutton, '', $limit, 0, 0, 1);

+

+	$topicmail = "SendShippingRef";

+	$modelmail = "shipping_send";

+	$objecttmp = new Expedition($db);

+	$trackid = 'shi'.$object->id;

+	include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';

+

+	if ($sall)

+	{

+		foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);

+		print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';

+	}

+

+	$moreforfilter = '';

+

+ 	// If the user can view prospects other than his'

+ 	if ($user->rights->societe->client->voir || $socid)

+ 	{

+ 		$langs->load("commercial");

+		$moreforfilter .= '<div class="divsearchfield">';

+ 		$moreforfilter .= $langs->trans('ThirdPartiesOfSaleRepresentative').': ';

+		$moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');

+	 	$moreforfilter .= '</div>';

+ 	}

+	// If the user can view other users

+	if ($user->rights->user->user->lire)

+	{

+		$moreforfilter .= '<div class="divsearchfield">';

+		$moreforfilter .= $langs->trans('LinkedToSpecificUsers').': ';

+		$moreforfilter .= $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');

+	 	$moreforfilter .= '</div>';

+	}

+	// If the user can view prospects other than his'

+	if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))

+	{

+		include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';

+		$moreforfilter .= '<div class="divsearchfield">';

+		$moreforfilter .= $langs->trans('IncludingProductWithTag').': ';

+		$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);

+		$moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);

+		$moreforfilter .= '</div>';

+	}

+	if (!empty($conf->categorie->enabled))

+	{

+		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';

+		$moreforfilter .= '<div class="divsearchfield">';

+	 	$moreforfilter .= $langs->trans('CustomersProspectsCategoriesShort').': ';

+		$moreforfilter .= $formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1);

+	 	$moreforfilter .= '</div>';

+	}

+	$parameters = array();

+	$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook

+	if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;

+	else $moreforfilter = $hookmanager->resPrint;

+

+	if (!empty($moreforfilter))

+	{

+		print '<div class="liste_titre liste_titre_bydiv centpercent">';

+		print $moreforfilter;

+		print '</div>';

+	}

+

+	$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;

+	$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);

+	if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); // This also change content of $arrayfields

+

+	print '<div class="div-table-responsive">';

+	print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";

+

+	// Fields title search

+	print '<tr class="liste_titre_filter">';

+	// Ref

+	if (!empty($arrayfields['e.ref']['checked']))

+	{

+		print '<td class="liste_titre">';

+		print '<input class="flat" size="6" type="text" name="search_ref_exp" value="'.$search_ref_exp.'">';

+		print '</td>';

+	}

+	// Ref customer

+	if (!empty($arrayfields['e.ref_customer']['checked']))

+	{

+		print '<td class="liste_titre">';

+		print '<input class="flat" size="6" type="text" name="search_ref_customer" value="'.$search_ref_customer.'">';

+		print '</td>';

+	}

+	// Thirdparty

+	if (!empty($arrayfields['s.nom']['checked']))

+	{

+		print '<td class="liste_titre left">';

+		print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';

+		print '</td>';

+	}

+	// Town

+	if (!empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';

+	// Zip

+	if (!empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';

+	// State

+	if (!empty($arrayfields['state.nom']['checked']))

+	{

+		print '<td class="liste_titre">';

+		print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';

+		print '</td>';

+	}

+	// Country

+	if (!empty($arrayfields['country.code_iso']['checked']))

+	{

+		print '<td class="liste_titre center">';

+		print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');

+		print '</td>';

+	}

+	// Company type

+	if (!empty($arrayfields['typent.code']['checked']))

+	{

+		print '<td class="liste_titre maxwidthonsmartphone center">';

+		print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));

+		print '</td>';

+	}

+	// Weight

+	if (!empty($arrayfields['e.weight']['checked']))

+	{

+		print '<td class="liste_titre maxwidthonsmartphone center">';

+

+		print '</td>';

+	}

+	// Date delivery planned

+	if (!empty($arrayfields['e.date_delivery']['checked']))

+	{

+		print '<td class="liste_titre center">';

+		print '<div class="nowrap">';

+		print $langs->trans('From').' ';

+		print $form->selectDate($search_delivery_start ? $search_delivery_start : -1, 'search_delivery_start', 0, 0, 1);

+		print '</div>';

+		print '<div class="nowrap">';

+		print $langs->trans('to').' ';

+		print $form->selectDate($search_delivery_end ? $search_delivery_end : -1, 'search_delivery_end', 0, 0, 1);

+		print '</div>';

+		print '</td>';

+	}

+	if (!empty($arrayfields['l.ref']['checked']))

+	{

+		// Delivery ref

+		print '<td class="liste_titre">';

+		print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';

+		print '</td>';

+	}

+	if (!empty($arrayfields['l.date_delivery']['checked']))

+	{

+		// Date received

+		print '<td class="liste_titre center">';

+		print '<div class="nowrap">';

+		print $langs->trans('From').' ';

+		print $form->selectDate($search_receipt_start ? $search_receipt_start : -1, 'search_receipt_start', 0, 0, 1);

+		print '</div>';

+		print '<div class="nowrap">';

+		print $langs->trans('to').' ';

+		print $form->selectDate($search_receipt_end ? $search_receipt_end : -1, 'search_receipt_end', 0, 0, 1);

+		print '</div>';

+		print '</td>';

+	}

+	// Extra fields

+	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';

+

+	// Fields from hook

+	$parameters = array('arrayfields'=>$arrayfields);

+	$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook

+	print $hookmanager->resPrint;

+	// Date creation

+	if (!empty($arrayfields['e.datec']['checked']))

+	{

+		print '<td class="liste_titre">';

+		print '</td>';

+	}

+	// Date modification

+	if (!empty($arrayfields['e.tms']['checked']))

+	{

+		print '<td class="liste_titre">';

+		print '</td>';

+	}

+	// Status

+	if (!empty($arrayfields['e.fk_statut']['checked']))

+	{

+		print '<td class="liste_titre maxwidthonsmartphone right">';

+		print $form->selectarray('search_status', array('0'=>$langs->trans('StatusSendingDraftShort'), '1'=>$langs->trans('StatusSendingValidatedShort'), '2'=>$langs->trans('StatusSendingProcessedShort')), $search_status, 1);

+		print '</td>';

+	}

+	// Status billed

+	if (!empty($arrayfields['e.billed']['checked']))

+	{

+		print '<td class="liste_titre maxwidthonsmartphone center">';

+		print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);

+		print '</td>';

+	}

+	// Action column

+	print '<td class="liste_titre middle">';

+	$searchpicto = $form->showFilterAndCheckAddButtons(0);

@@ -704,138 +569,25 @@
-}

-// Ref

-if (!empty($arrayfields['e.ref']['checked'])) {

-	print '<td class="liste_titre">';

-	print '<input class="flat" size="6" type="text" name="search_ref_exp" value="'.$search_ref_exp.'">';

-	print '</td>';

-}

-// Ref customer

-if (!empty($arrayfields['e.ref_customer']['checked'])) {

-	print '<td class="liste_titre">';

-	print '<input class="flat" size="6" type="text" name="search_ref_customer" value="'.$search_ref_customer.'">';

-	print '</td>';

-}

-// Thirdparty

-if (!empty($arrayfields['s.nom']['checked'])) {

-	print '<td class="liste_titre left">';

-	print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';

-	print '</td>';

-}

-// Town

-if (!empty($arrayfields['s.town']['checked'])) {

-	print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';

-}

-// Zip

-if (!empty($arrayfields['s.zip']['checked'])) {

-	print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';

-}

-// State

-if (!empty($arrayfields['state.nom']['checked'])) {

-	print '<td class="liste_titre">';

-	print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';

-	print '</td>';

-}

-// Country

-if (!empty($arrayfields['country.code_iso']['checked'])) {

-	print '<td class="liste_titre center">';

-	print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');

-	print '</td>';

-}

-// Company type

-if (!empty($arrayfields['typent.code']['checked'])) {

-	print '<td class="liste_titre maxwidthonsmartphone center">';

-	print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);

-	print '</td>';

-}

-// Weight

-if (!empty($arrayfields['e.weight']['checked'])) {

-	print '<td class="liste_titre maxwidthonsmartphone center">';

-

-	print '</td>';

-}

-// Date delivery planned

-if (!empty($arrayfields['e.date_delivery']['checked'])) {

-	print '<td class="liste_titre center">';

-	print '<div class="nowrapfordate">';

-	print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));

-	print '</div>';

-	print '<div class="nowrapfordate">';

-	print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));

-	print '</div>';

-	print '</td>';

-}

-if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {

-	// Delivery method

-	print '<td class="liste_titre center">';

-	$shipment->fetch_delivery_methods();

-	print $form->selectarray("search_shipping_method_id", $shipment->meths, $search_shipping_method_id, 1, 0, 0, "", 1, 0, 0, '', 'maxwidth150');

-	print "</td>\n";

-}

-// Tracking number

-if (!empty($arrayfields['e.tracking_number']['checked'])) {

-	print '<td class="liste_titre center">';

-	print '<input class="flat" size="6" type="text" name="search_tracking" value="'.dol_escape_htmltag($search_tracking).'">';

-	print '</td>';

-}

-if (!empty($arrayfields['l.ref']['checked'])) {

-	// Delivery ref

-	print '<td class="liste_titre">';

-	print '<input class="flat width75" type="text" name="search_ref_liv" value="'.dol_escape_htmltag($search_ref_liv).'"';

-	print '</td>';

-}

-if (!empty($arrayfields['l.date_delivery']['checked'])) {

-	// Date received

-	print '<td class="liste_titre center">';

-	print '<div class="nowrapfordate">';

-	print $form->selectDate($search_datereceipt_start ? $search_datereceipt_start : -1, 'search_datereceipt_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));

-	print '</div>';

-	print '<div class="nowrapfordate">';

-	print $form->selectDate($search_datereceipt_end ? $search_datereceipt_end : -1, 'search_datereceipt_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));

-	print '</div>';

-	print '</td>';

-}

-// Extra fields

-include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';

-

-// Fields from hook

-$parameters = array('arrayfields'=>$arrayfields);

-$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-print $hookmanager->resPrint;

-// Date creation

-if (!empty($arrayfields['e.datec']['checked'])) {

-	print '<td class="liste_titre">';

-	print '</td>';

-}

-// Date modification

-if (!empty($arrayfields['e.tms']['checked'])) {

-	print '<td class="liste_titre">';

-	print '</td>';

-}

-// Status

-if (!empty($arrayfields['e.fk_statut']['checked'])) {

-	print '<td class="liste_titre right parentonrightofpage">';

-	print $form->selectarray('search_status', array('0'=>$langs->trans('StatusSendingDraftShort'), '1'=>$langs->trans('StatusSendingValidatedShort'), '2'=>$langs->trans('StatusSendingProcessedShort')), $search_status, 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');

-	print '</td>';

-}

-// Status billed

-if (!empty($arrayfields['e.billed']['checked'])) {

-	print '<td class="liste_titre maxwidthonsmartphone center">';

-	print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);

-	print '</td>';

-}

-// Action column

-if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print '<td class="liste_titre center maxwidthsearch">';

-	$searchpicto = $form->showFilterButtons();

-	print $searchpicto;

-	print '</td>';

-}

-print '</tr>'."\n";

-

-$totalarray = array();

-$totalarray['nbfield'] = 0;

-

-// Fields title label

-// --------------------------------------------------------------------

-print '<tr class="liste_titre">';

-// Action column

-if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

+	print "</tr>\n";

+

+	print '<tr class="liste_titre">';

+	if (!empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);

+	if (!empty($arrayfields['e.ref_customer']['checked']))   print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"], "e.ref_customer", "", $param, '', $sortfield, $sortorder);

+	if (!empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');

+	if (!empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);

+	if (!empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);

+	if (!empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);

+	if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');

+	if (!empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');

+	if (!empty($arrayfields['e.weight']['checked']))         print_liste_field_titre($arrayfields['e.weight']['label'], $_SERVER["PHP_SELF"], "e.weight", "", $param, '', $sortfield, $sortorder, 'center ');

+	if (!empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');

+	if (!empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);

+	if (!empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');

+	// Extra fields

+	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';

+	// Hook fields

+	$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);

+	$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook

+	print $hookmanager->resPrint;

+	if (!empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

+	if (!empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

+	if (!empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');

+	if (!empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');

@@ -843,135 +595,18 @@
-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['e.ref']['checked'])) {

-	print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['e.ref_customer']['checked'])) {

-	print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"], "e.ref_customer", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['s.nom']['checked'])) {

-	print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left ');

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['s.town']['checked'])) {

-	print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['s.zip']['checked'])) {

-	print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['state.nom']['checked'])) {

-	print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['country.code_iso']['checked'])) {

-	print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['typent.code']['checked'])) {

-	print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['e.weight']['checked'])) {

-	print_liste_field_titre($arrayfields['e.weight']['label'], $_SERVER["PHP_SELF"], "e.weight", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['e.date_delivery']['checked'])) {

-	print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {

-	print_liste_field_titre($arrayfields['e.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "e.fk_shipping_method", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['e.tracking_number']['checked'])) {

-	print_liste_field_titre($arrayfields['e.tracking_number']['label'], $_SERVER["PHP_SELF"], "e.tracking_number", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['l.ref']['checked'])) {

-	print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['l.date_delivery']['checked'])) {

-	print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;

-}

-// Extra fields

-include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';

-// Hook fields

-$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, '$totalarray'=>&$totalarray);

-$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-print $hookmanager->resPrint;

-if (!empty($arrayfields['e.datec']['checked'])) {

-	print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['e.tms']['checked'])) {

-	print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['e.fk_statut']['checked'])) {

-	print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');

-	$totalarray['nbfield']++;

-}

-if (!empty($arrayfields['e.billed']['checked'])) {

-	print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center ');

-	$totalarray['nbfield']++;

-}

-// Action column

-if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');

-	$totalarray['nbfield']++;

-}

-print "</tr>\n";

-

-$typenArray = $formcompany->typent_array(1);

-

-// Loop on record

-// --------------------------------------------------------------------

-$i = 0;

-$savnbfield = $totalarray['nbfield'];

-$totalarray = array();

-$totalarray['nbfield'] = 0;

-$imaxinloop = ($limit ? min($num, $limit) : $num);

-while ($i < $imaxinloop) {

-	$obj = $db->fetch_object($resql);

-	if (empty($obj)) {

-		break; // Should not happen

-	}

-

-	$shipment->id = $obj->rowid;

-	$shipment->ref = $obj->ref;

-	$shipment->shipping_method_id=$obj->fk_shipping_method;

-

-	$companystatic->id = $obj->socid;

-	$companystatic->ref = $obj->name;

-	$companystatic->name = $obj->name;

-

-	$object = new Expedition($db);

-	$object->fetch($obj->rowid);

-

-	if ($mode == 'kanban') {

-		if ($i == 0) {

-			print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';

-			print '<div class="box-flex-container kanban">';

-		}

-		$object->date_delivery = $obj->delivery_date;

-		$object->town = $obj->town;

-

-		// Output Kanban

-		$selected = -1;

-		if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined

-			$selected = 0;

-			if (in_array($object->id, $arrayofselected)) {

-				$selected = 1;

-			}

-		}

-		print $object->getKanbanView('', array('thirdparty' => $companystatic->getNomUrl(1), 'selected' => $selected));

-		if ($i == min($num, $limit) - 1) {

-			print '</div>';

-			print '</td></tr>';

-		}

-	} else {

+	print "</tr>\n";

+

+	$typenArray = $formcompany->typent_array(1);

+	$i = 0;

+	$totalarray = array();

+	while ($i < min($num, $limit))

+	{

+		$obj = $db->fetch_object($resql);

+

+		$shipment->id = $obj->rowid;

+		$shipment->ref = $obj->ref;

+

+		$companystatic->id = $obj->socid;

+		$companystatic->ref = $obj->name;

+		$companystatic->name = $obj->name;

+

+		$object = new Expedition($db);

+		$object->fetch($obj->rowid);

@@ -980,12 +614,0 @@
-		// Action column

-		if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-			print '<td class="nowrap center">';

-			if ($massactionbutton || $massaction) {   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined

-				$selected = 0;

-				if (in_array($obj->rowid, $arrayofselected)) {

-					$selected = 1;

-				}

-				print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';

-			}

-			print '</td>';

-		}

@@ -993,2 +616,3 @@
-		if (!empty($arrayfields['e.ref']['checked'])) {

-			print '<td class="nowraponall">';

+		if (!empty($arrayfields['e.ref']['checked']))

+		{

+			print "<td>";

@@ -997,3 +621 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1003,3 +625,4 @@
-		if (!empty($arrayfields['e.ref_customer']['checked'])) {

-			print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->ref_customer).'">';

-			print dol_escape_htmltag($obj->ref_customer);

+		if (!empty($arrayfields['e.ref_customer']['checked']))

+		{

+			print "<td>";

+			print $obj->ref_customer;

@@ -1007,3 +630 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1013,2 +634,3 @@
-		if (!empty($arrayfields['s.nom']['checked'])) {

-			print '<td class="tdoverflowmax150">';

+		if (!empty($arrayfields['s.nom']['checked']))

+		{

+			print '<td>';

@@ -1017,3 +639 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1022 +642,2 @@
-		if (!empty($arrayfields['s.town']['checked'])) {

+		if (!empty($arrayfields['s.town']['checked']))

+		{

@@ -1024 +645 @@
-			print dol_escape_htmltag($obj->town);

+			print $obj->town;

@@ -1026,3 +647 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1031,3 +650,4 @@
-		if (!empty($arrayfields['s.zip']['checked'])) {

-			print '<td class="nocellnopadd center">';

-			print dol_escape_htmltag($obj->zip);

+		if (!empty($arrayfields['s.zip']['checked']))

+		{

+			print '<td class="nocellnopadd">';

+			print $obj->zip;

@@ -1035,3 +655 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1040,5 +658,4 @@
-		if (!empty($arrayfields['state.nom']['checked'])) {

-			print '<td class="center">'.$obj->state_name."</td>\n";

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+		if (!empty($arrayfields['state.nom']['checked']))

+		{

+			print "<td>".$obj->state_name."</td>\n";

+			if (!$i) $totalarray['nbfield']++;

@@ -1047 +664,2 @@
-		if (!empty($arrayfields['country.code_iso']['checked'])) {

+		if (!empty($arrayfields['country.code_iso']['checked']))

+		{

@@ -1050 +668 @@
-			print dol_escape_htmltag($tmparray['label']);

+			print $tmparray['label'];

@@ -1052,3 +670 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1057 +673,2 @@
-		if (!empty($arrayfields['typent.code']['checked'])) {

+		if (!empty($arrayfields['typent.code']['checked']))

+		{

@@ -1059,3 +676 @@
-			if (isset($typenArray[$obj->typent_code])) {

-				print $typenArray[$obj->typent_code];

-			}

+			if (isset($typenArray[$obj->typent_code]))  print $typenArray[$obj->typent_code];

@@ -1063,3 +678 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1068 +681,2 @@
-		if (!empty($arrayfields['e.weight']['checked'])) {

+		if (!empty($arrayfields['e.weight']['checked']))

+		{

@@ -1070 +684,2 @@
-			if (empty($object->trueWeight)) {

+			if (empty($object->trueWeight))

+			{

@@ -1074 +689,3 @@
-			} else {

+			}

+			else

+			{

@@ -1079,3 +696 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1084,3 +699,8 @@
-		if (!empty($arrayfields['e.date_delivery']['checked'])) {

-			print '<td class="center nowraponall">';

-			print dol_print_date($db->jdate($obj->delivery_date), "dayhour");

+		if (!empty($arrayfields['e.date_delivery']['checked']))

+		{

+			print '<td class="center">';

+			print dol_print_date($db->jdate($obj->date_livraison), "day");

+			/*$now = time();

+    		if ( ($now - $db->jdate($obj->date_expedition)) > $conf->warnings->lim && $obj->statutid == 1 )

+    		{

+    		}*/

@@ -1088,27 +708,4 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		if (!empty($arrayfields['e.fk_shipping_method']['checked'])) {

-			// Get code using getLabelFromKey

-			$code=$langs->getLabelFromKey($db, $shipment->shipping_method_id, 'c_shipment_mode', 'rowid', 'code');

-			print '<td class="center tdoverflowmax150" title="'.dol_escape_htmltag($langs->trans("SendingMethod".strtoupper($code))).'">';

-			if ($shipment->shipping_method_id > 0) {

-				print $langs->trans("SendingMethod".strtoupper($code));

-			}

-			print '</td>';

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-		// Tracking number

-		if (!empty($arrayfields['e.tracking_number']['checked'])) {

-			$shipment->getUrlTrackingStatus($obj->tracking_number);

-			print '<td class="center">'.$shipment->tracking_url."</td>\n";

-			//print $form->editfieldval("TrackingNumber", 'tracking_number', $obj->tracking_url, $obj, $user->rights->expedition->creer, 'string', $obj->tracking_number);

-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

-		}

-

-		if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) {

+		}

+

+		if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked']))

+		{

@@ -1117,5 +714,4 @@
-			if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) {

-				$receiving = reset($shipment->linkedObjects['delivery']);

-			}

-

-			if (!empty($arrayfields['l.ref']['checked'])) {

+			if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) $receiving = reset($shipment->linkedObjects['delivery']);

+

+			if (!empty($arrayfields['l.ref']['checked']))

+			{

@@ -1128 +724,2 @@
-			if (!empty($arrayfields['l.date_delivery']['checked'])) {

+			if (!empty($arrayfields['l.date_delivery']['checked']))

+			{

@@ -1130 +727 @@
-				print '<td class="center nowraponall">';

+				print '<td class="center">';

@@ -1140 +737 @@
-		$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

+		$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook

@@ -1143,3 +740,4 @@
-		if (!empty($arrayfields['e.datec']['checked'])) {

-			print '<td class="center nowraponall">';

-			print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuserrel');

+		if (!empty($arrayfields['e.datec']['checked']))

+		{

+			print '<td class="center nowrap">';

+			print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');

@@ -1147,3 +745 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1152,2 +748,3 @@
-		if (!empty($arrayfields['e.tms']['checked'])) {

-			print '<td class="center nowraponall">';

+		if (!empty($arrayfields['e.tms']['checked']))

+		{

+			print '<td class="center nowrap">';

@@ -1156,3 +753 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1161 +756,2 @@
-		if (!empty($arrayfields['e.fk_statut']['checked'])) {

+		if (!empty($arrayfields['e.fk_statut']['checked']))

+		{

@@ -1163,3 +759 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1168 +762,2 @@
-		if (!empty($arrayfields['e.billed']['checked'])) {

+		if (!empty($arrayfields['e.billed']['checked']))

+		{

@@ -1170,3 +765 @@
-			if (!$i) {

-				$totalarray['nbfield']++;

-			}

+			if (!$i) $totalarray['nbfield']++;

@@ -1176,14 +769,9 @@
-		if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {

-			print '<td class="nowrap center">';

-			if ($massactionbutton || $massaction) {   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined

-				$selected = 0;

-				if (in_array($obj->rowid, $arrayofselected)) {

-					$selected = 1;

-				}

-				print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';

-			}

-			print '</td>';

-		}

-		if (!$i) {

-			$totalarray['nbfield']++;

-		}

+		print '<td class="nowrap" align="center">';

+		if ($massactionbutton || $massaction)   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined

+		{

+			$selected = 0;

+			if (in_array($obj->rowid, $arrayofselected)) $selected = 1;

+			print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';

+		}

+		print '</td>';

+		if (!$i) $totalarray['nbfield']++;

@@ -1192,40 +780,31 @@
-	}

-	$i++;

-}

-

-// If no record found

-if ($num == 0) {

-	$colspan = 1;

-	foreach ($arrayfields as $key => $val) {

-		if (!empty($val['checked'])) {

-			$colspan++;

-		}

-	}

-	print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';

-}

-

-$db->free($resql);

-

-$parameters = array('arrayfields'=>$arrayfields, 'totalarray' => $totalarray, 'sql'=>$sql);

-$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook

-print $hookmanager->resPrint;

-

-print "</table>";

-print "</div>";

-print '</form>';

-

-$hidegeneratedfilelistifempty = 1;

-if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {

-	$hidegeneratedfilelistifempty = 0;

-}

-

-// Show list of available documents

-$urlsource  = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;

-$urlsource .= str_replace('&amp;', '&', $param);

-

-$filedir    = $diroutputmassaction;

-$genallowed = $user->rights->expedition->lire;

-$delallowed = $user->rights->expedition->creer;

-$title      = '';

-

-print $formfile->showdocuments('massfilesarea_sendings', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);

+

+		$i++;

+	}

+	$db->free($resql);

+

+	$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);

+	$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook

+	print $hookmanager->resPrint;

+

+	print "</table>";

+	print "</div>";

+	print '</form>';

+

+	$hidegeneratedfilelistifempty = 1;

+	if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)   $hidegeneratedfilelistifempty = 0;

+

+	// Show list of available documents

+	$urlsource  = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;

+	$urlsource .= str_replace('&amp;', '&', $param);

+

+	$filedir    = $diroutputmassaction;

+	$genallowed = $user->rights->expedition->lire;

+	$delallowed = $user->rights->expedition->creer;

+	$title      = '';

+

+	print $formfile->showdocuments('massfilesarea_sendings', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);

+}

+else

+{

+	dol_print_error($db);

+}

--- /tmp/dsg/dolibarr/htdocs/expedition/github_19.0.3_note.php
+++ /tmp/dsg/dolibarr/htdocs/expedition/client_note.php
@@ -27 +26,0 @@
-// Load Dolibarr environment

@@ -31,3 +30,3 @@
-if (isModEnabled('project')) {

-	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';

-	require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';

+if (!empty($conf->projet->enabled)) {

+    require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';

+    require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';

@@ -39 +38 @@
-$id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility

+$id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility

@@ -41 +40,6 @@
-$action = GETPOST('action', 'aZ09');

+$action = GETPOST('action', 'alpha');

+

+// Security check

+$socid = '';

+if ($user->socid) $socid = $user->socid;

+$result = restrictedArea($user, $origin, $origin_id);

@@ -44,3 +48,4 @@
-if ($id > 0 || !empty($ref)) {

-	$object->fetch($id, $ref);

-	$object->fetch_thirdparty();

+if ($id > 0 || !empty($ref))

+{

+    $object->fetch($id, $ref);

+    $object->fetch_thirdparty();

@@ -48,5 +53,6 @@
-	if (!empty($object->origin)) {

-		$typeobject = $object->origin;

-		$origin = $object->origin;

-		$object->fetch_origin();

-	}

+    if (!empty($object->origin))

+    {

+        $typeobject = $object->origin;

+        $origin = $object->origin;

+        $object->fetch_origin();

+    }

@@ -54,11 +60,11 @@
-	// Linked documents

-	if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {

-		$objectsrc = new Commande($db);

-		$objectsrc->fetch($object->$typeobject->id);

-	}

-	if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {

-		$objectsrc = new Propal($db);

-		$objectsrc->fetch($object->$typeobject->id);

-	}

-

-	$upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($object->ref);

+    // Linked documents

+    if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))

+    {

+        $objectsrc = new Commande($db);

+        $objectsrc->fetch($object->$typeobject->id);

+    }

+    if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))

+    {

+        $objectsrc = new Propal($db);

+        $objectsrc->fetch($object->$typeobject->id);

+    }

@@ -68,8 +73,0 @@
-

-// Security check

-if ($user->socid) {

-	$socid = $user->socid;

-}

-

-$hookmanager->initHooks(array('expeditionnote'));

-$result = restrictedArea($user, 'expedition', $object->id, '');

@@ -82,7 +80 @@
-$reshook = $hookmanager->executeHooks('doActions', array(), $object, $action); // Note that $action and $object may have been modified by some hooks

-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

-if (empty($reshook)) {

-	include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once

-}

+include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once

@@ -99 +91,2 @@
-if ($id > 0 || !empty($ref)) {

+if ($id > 0 || !empty($ref))

+{

@@ -101 +94 @@
-	print dol_get_fiche_head($head, 'note', $langs->trans("Shipment"), -1, $object->picto);

+	dol_fiche_head($head, 'note', $langs->trans("Shipment"), -1, 'sending');

@@ -109,2 +102,2 @@
-	$morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string', '', 0, 1);

-	$morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->hasRight('expedition', 'creer'), 'string', '', null, null, '', 1);

+	$morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);

+	$morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);

@@ -112,23 +105,36 @@
-	$morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);

-	// Project

-	if (isModEnabled('project')) {

-		$langs->load("projects");

-		$morehtmlref .= '<br>';

-		if (0) {	// Do not change on shipment

-			$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');

-			if ($action != 'classify') {

-				$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';

-			}

-			$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');

-		} else {

-			if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {

-				$proj = new Project($db);

-				$proj->fetch($objectsrc->fk_project);

-				$morehtmlref .= $proj->getNomUrl(1);

-				if ($proj->title) {

-					$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';

-				}

-			}

-		}

-	}

-	$morehtmlref .= '</div>';

+	$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);

+    // Project

+    if (!empty($conf->projet->enabled)) {

+        $langs->load("projects");

+        $morehtmlref .= '<br>'.$langs->trans('Project').' ';

+        if (0) {    // Do not change on shipment

+            if ($action != 'classify') {

+                $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';

+            }

+            if ($action == 'classify') {

+                // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);

+                $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

+                $morehtmlref .= '<input type="hidden" name="action" value="classin">';

+                $morehtmlref .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';

+                $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);

+                $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';

+                $morehtmlref .= '</form>';

+            } else {

+                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);

+            }

+        } else {

+            // We don't have project on shipment, so we will use the project or source object instead

+            // TODO Add project on shipment

+            $morehtmlref .= ' : ';

+            if (!empty($objectsrc->fk_project)) {

+                $proj = new Project($db);

+                $proj->fetch($objectsrc->fk_project);

+                $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';

+                $morehtmlref .= $proj->ref;

+                $morehtmlref .= '</a>';

+            } else {

+                $morehtmlref .= '';

+            }

+        }

+    }

+    $morehtmlref .= '</div>';

@@ -137 +143 @@
-	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);

+    dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);

@@ -140 +146 @@
-	print '<div class="underbanner clearboth"></div>';

+    print '<div class="underbanner clearboth"></div>';

@@ -145 +151 @@
-	print dol_get_fiche_end();

+	dol_fiche_end();

--- /tmp/dsg/dolibarr/htdocs/expedition/github_19.0.3_shipment.php
+++ /tmp/dsg/dolibarr/htdocs/expedition/client_shipment.php
@@ -6,2 +6,2 @@
- * Copyright (C) 2018-2021  Frédéric France         <frederic.france@netlogic.fr>

- * Copyright (C) 2018-2022  Philippe Grand          <philippe.grand@atoo-net.com>

+ * Copyright (C) 2018       Frédéric France         <frederic.france@netlogic.fr>

+ * Copyright (C) 2018       Philippe Grand          <philippe.grand@atoo-net.com>

@@ -29 +28,0 @@
-// Load Dolibarr environment

@@ -37 +36 @@
-if (isModEnabled('project')) {

+if (!empty($conf->projet->enabled)) {

@@ -41,9 +40,3 @@
-if (isModEnabled('stock')) {

-	require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';

-}

-if (isModEnabled("propal")) {

-	require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';

-}

-if (isModEnabled("product") || isModEnabled("service")) {

-	require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';

-}

+if (!empty($conf->stock->enabled))  require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';

+if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';

+if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) 	require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';

@@ -52 +45 @@
-$langs->loadLangs(array('orders', 'sendings', 'companies', 'bills', 'propal', 'deliveries', 'stocks', 'productbatch', 'incoterm', 'other'));

+$langs->loadLangs(array('orders', "companies", "bills", 'propal', 'deliveries', 'stocks', "productbatch", 'incoterm', 'other'));

@@ -56 +49 @@
-$action = GETPOST('action', 'aZ09');

+$action = GETPOST('action', 'alpha');

@@ -63,3 +56 @@
-if (!empty($user->socid)) {

-	$socid = $user->socid;

-}

+if (!empty($user->socid)) $socid = $user->socid;

@@ -69 +59,0 @@
-$shipment = new Expedition($db);

@@ -78,6 +67,0 @@
-// Security check

-if ($user->socid) {

-	$socid = $user->socid;

-}

-

-$result = restrictedArea($user, 'expedition', 0, '');	// We use 0 for id, because there is no particular shipment on this tab, only id of order is known

@@ -93,110 +77,124 @@
-if ($reshook < 0) {

-	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-}

-

-if (empty($reshook)) {

-	// Categorisation dans projet

-	if ($action == 'classin') {

-		$object->fetch($id);

-		$object->setProject(GETPOST('projectid', 'int'));

-	}

-

-	if ($action == 'confirm_cloture' && GETPOST('confirm', 'alpha') == 'yes') {

-		$object->fetch($id);

-		$result = $object->cloture($user);

-	} elseif ($action == 'setref_client' && $user->hasRight('commande', 'creer')) {

-		// Positionne ref commande client

-		$result = $object->set_ref_client($user, GETPOST('ref_client'));

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	}

-

-	if ($action == 'setdatedelivery' && $user->hasRight('commande', 'creer')) {

-		$datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));

-

-		$object->fetch($id);

-		$result = $object->setDeliveryDate($user, $datedelivery);

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	}

-	/*

-	if ($action == 'setdeliveryaddress' && $user->hasRight('commande', 'creer'))

-	{

-		$object = new Commande($db);

-		$object->fetch($id);

-		$object->setDeliveryAddress(GETPOST('delivery_address_id','int'));

-		if ($result < 0)

-			setEventMessages($object->error, $object->errors, 'errors');

-	}

-	*/

-	if ($action == 'setmode' && $user->hasRight('commande', 'creer')) {

-		$object->fetch($id);

-		$result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	}

-

-	if ($action == 'setavailability' && $user->hasRight('commande', 'creer')) {

-		$object->fetch($id);

-		$result = $object->availability(GETPOST('availability_id'));

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	}

-

-	if ($action == 'setdemandreason' && $user->hasRight('commande', 'creer')) {

-		$object->fetch($id);

-		$result = $object->demand_reason(GETPOST('demand_reason_id'));

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	}

-

-	if ($action == 'setconditions' && $user->hasRight('commande', 'creer')) {

-		$object->fetch($id);

-		$result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	} elseif ($action == 'set_incoterms' && isModEnabled('incoterm')) {

-		// Set incoterm

-		$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	}

-

-	// shipping method

-	if ($action == 'setshippingmethod' && $user->hasRight('commande', 'creer')) {

-		$object->fetch($id);

-		$result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int'));

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	}

-

-	// warehouse

-	if ($action == 'setwarehouse' && $user->hasRight('commande', 'creer')) {

-		$object->fetch($id);

-		$result = $object->setWarehouse(GETPOST('warehouse_id', 'int'));

-		if ($result < 0) {

-			setEventMessages($object->error, $object->errors, 'errors');

-		}

-	}

-

-	if ($action == 'update_extras') {

-		$object->oldcopy = dol_clone($object, 2);

-

-		// Fill array 'array_options' with data from update form

-		$ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));

-		if ($ret < 0) {

-			$error++;

-		}

-

-		if (!$error) {

-			// Actions on extra fields

-			$result = $object->insertExtraFields('SHIPMENT_MODIFY');

-			if ($result < 0) {

+if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

+

+if (empty($reshook))

+{

+    // Categorisation dans projet

+    if ($action == 'classin')

+    {

+    	$object = new Commande($db);

+    	$object->fetch($id);

+    	$object->setProject(GETPOST('projectid', 'int'));

+    }

+

+    if ($action == 'confirm_cloture' && GETPOST('confirm', 'alpha') == 'yes')

+    {

+    	$object = new Commande($db);

+    	$object->fetch($id);

+    	$result = $object->cloture($user);

+    }

+

+    // Positionne ref commande client

+    elseif ($action == 'setref_client' && $user->rights->commande->creer) {

+        $result = $object->set_ref_client($user, GETPOST('ref_client'));

+        if ($result < 0)

+        {

+            setEventMessages($object->error, $object->errors, 'errors');

+        }

+    }

+

+    if ($action == 'setdatedelivery' && $user->rights->commande->creer)

+    {

+    	//print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year'];

+    	$datelivraison = dol_mktime(0, 0, 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));

+

+    	$object = new Commande($db);

+    	$object->fetch($id);

+    	$result = $object->set_date_livraison($user, $datelivraison);

+    	if ($result < 0)

+    		setEventMessages($object->error, $object->errors, 'errors');

+    }

+    /*

+    if ($action == 'setdeliveryaddress' && $user->rights->commande->creer)

+    {

+    	$object = new Commande($db);

+    	$object->fetch($id);

+    	$object->setDeliveryAddress(GETPOST('delivery_address_id','int'));

+    	if ($result < 0)

+    		setEventMessages($object->error, $object->errors, 'errors');

+    }

+    */

+    if ($action == 'setmode' && $user->rights->commande->creer)

+    {

+    	$object = new Commande($db);

+    	$object->fetch($id);

+    	$result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));

+    	if ($result < 0)

+    		setEventMessages($object->error, $object->errors, 'errors');

+    }

+

+    if ($action == 'setavailability' && $user->rights->commande->creer) {

+        $object = new Commande($db);

+        $object->fetch($id);

+        $result = $object->availability(GETPOST('availability_id'));

+        if ($result < 0)

+            setEventMessages($object->error, $object->errors, 'errors');

+    }

+

+    if ($action == 'setdemandreason' && $user->rights->commande->creer) {

+        $object = new Commande($db);

+        $object->fetch($id);

+        $result = $object->demand_reason(GETPOST('demand_reason_id'));

+        if ($result < 0)

+            setEventMessages($object->error, $object->errors, 'errors');

+    }

+

+    if ($action == 'setconditions' && $user->rights->commande->creer)

+    {

+    	$object = new Commande($db);

+    	$object->fetch($id);

+    	$result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));

+    	if ($result < 0)

+    		setEventMessages($object->error, $object->errors, 'errors');

+    }

+

+    // Set incoterm

+    elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))

+    {

+    	$result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));

+    	if ($result < 0) {

+    		setEventMessages($object->error, $object->errors, 'errors');

+    	}

+    }

+

+    // shipping method

+    if ($action == 'setshippingmethod' && $user->rights->commande->creer) {

+        $object = new Commande($db);

+        $object->fetch($id);

+        $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int'));

+    	if ($result < 0)

+    		setEventMessages($object->error, $object->errors, 'errors');

+    }

+

+    // warehouse

+    if ($action == 'setwarehouse' && $user->rights->commande->creer) {

+        $object = new Commande($db);

+        $object->fetch($id);

+        $result = $object->setWarehouse(GETPOST('warehouse_id', 'int'));

+        if ($result < 0)

+            setEventMessages($object->error, $object->errors, 'errors');

+    }

+

+    if ($action == 'update_extras')

+    {

+    	$object->oldcopy = dol_clone($object);

+

+    	// Fill array 'array_options' with data from update form

+        $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none'));

+        if ($ret < 0) $error++;

+

+        if (!$error)

+        {

+            // Actions on extra fields

+            $result = $object->insertExtraFields('SHIPMENT_MODIFY');

+			if ($result < 0)

+			{

@@ -206,16 +204,16 @@
-		}

-

-		if ($error) {

-			$action = 'edit_extras';

-		}

-	}

-

-	if ($action == 'set_thirdparty' && $user->hasRight('commande', 'creer')) {

-		$object->fetch($id);

-		$object->setValueFrom('fk_soc', $socid, '', '', 'date', '', $user, 'ORDER_MODIFY');

-

-		header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);

-		exit();

-	}

-

-	include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';

+        }

+

+        if ($error)

+            $action = 'edit_extras';

+    }

+

+    if ($action == 'set_thirdparty' && $user->rights->commande->creer)

+    {

+        $object->fetch($id);

+        $object->setValueFrom('fk_soc', $socid, '', '', 'date', '', $user, 'ORDER_MODIFY');

+

+        header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);

+        exit();

+    }

+

+    include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';

@@ -231,10 +229,7 @@
-if (isModEnabled('project')) {

-	$formproject = new FormProjets($db);

-}

-

-$title = $object->ref." - ".$langs->trans('Shipments');

-$help_url = 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';

-llxHeader('', $title, $help_url);

-

-

-if ($id > 0 || !empty($ref)) {

+if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); }

+

+llxHeader('', $langs->trans('OrderCard'), '');

+

+

+if ($id > 0 || !empty($ref))

+{

@@ -242 +237,2 @@
-	if ($object->fetch($id, $ref) > 0) {

+	if ($object->fetch($id, $ref) > 0)

+	{

@@ -256 +252 @@
-		print dol_get_fiche_head($head, 'shipping', $langs->trans("CustomerOrder"), -1, 'order');

+		dol_fiche_head($head, 'shipping', $langs->trans("CustomerOrder"), -1, 'order');

@@ -262,2 +258,3 @@
-		if ($action == 'cloture') {

-			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".urlencode($id), $langs->trans("CloseShipment"), $langs->trans("ConfirmCloseShipment"), "confirm_cloture");

+		if ($action == 'cloture')

+		{

+			$formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id, $langs->trans("CloseShipment"), $langs->trans("ConfirmCloseShipment"), "confirm_cloture");

@@ -269,5 +266,2 @@
-		if (empty($reshook)) {

-			$formconfirm .= $hookmanager->resPrint;

-		} elseif ($reshook > 0) {

-			$formconfirm = $hookmanager->resPrint;

-		}

+		if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;

+		elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;

@@ -286,36 +280,48 @@
-		$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_client, $object, $user->hasRight('commande', 'creer'), 'string', '', 0, 1);

-		$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_client, $object, $user->hasRight('commande', 'creer'), 'string', '', null, null, '', 1);

-		// Thirdparty

-		$morehtmlref .= '<br>'.$soc->getNomUrl(1);

-		// Project

-		if (isModEnabled('project')) {

-			$langs->load("projects");

-			$morehtmlref .= '<br>';

-			if (0) {	// Do not change on shipment

-				$morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');

-				if ($action != 'classify') {

-					$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';

-				}

-				$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $objectsrc->socid, $objectsrc->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');

-			} else {

-				if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {

-					$proj = new Project($db);

-					$proj->fetch($objectsrc->fk_project);

-					$morehtmlref .= $proj->getNomUrl(1);

-					if ($proj->title) {

-						$morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';

-					}

-				}

-			}

-		}

-		$morehtmlref .= '</div>';

-

-

-		dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);

-

-

-		print '<div class="fichecenter">';

-		print '<div class="fichehalfleft">';

-		print '<div class="underbanner clearboth"></div>';

-

-		print '<table class="border centpercent tableforfield">';

+		$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', 0, 1);

+		$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', null, null, '', 1);

+	    // Thirdparty

+	    $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$soc->getNomUrl(1);

+	    // Project

+	    if (!empty($conf->projet->enabled))

+	    {

+	        $langs->load("projects");

+	        $morehtmlref .= '<br>'.$langs->trans('Project').' ';

+	        if ($user->rights->commande->creer)

+	        {

+	            if ($action != 'classify') {

+					$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';

+                }

+                if ($action == 'classify') {

+                    //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);

+                    $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';

+                    $morehtmlref .= '<input type="hidden" name="action" value="classin">';

+                    $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';

+                    $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);

+                    $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';

+                    $morehtmlref .= '</form>';

+                } else {

+                    $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);

+                }

+	        } else {

+	            if (!empty($object->fk_project)) {

+	                $proj = new Project($db);

+	                $proj->fetch($object->fk_project);

+	                $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';

+	                $morehtmlref .= $proj->ref;

+	                $morehtmlref .= '</a>';

+	            } else {

+	                $morehtmlref .= '';

+	            }

+	        }

+	    }

+	    $morehtmlref .= '</div>';

+

+

+	    dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);

+

+

+	    print '<div class="fichecenter">';

+	    print '<div class="fichehalfleft">';

+	    print '<div class="underbanner clearboth"></div>';

+

+	    print '<table class="border centpercent tableforfield">';

@@ -324,9 +330,9 @@
-		if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS')) {

-			$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice

-			$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice

-		} else {

-			$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";

-			$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";

-		}

-

-		print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td colspan="2">';

+	    if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {

+	    	$filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice

+	    	$filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice

+	    } else {

+	    	$filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')";

+	    	$filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')";

+	    }

+

+		print '<tr><td class="titlefield">'.$langs->trans('Discounts').'</td><td colspan="3">';

@@ -349,3 +355,3 @@
-		print dol_print_date($object->date, 'day');

-		if ($object->hasDelay() && empty($object->delivery_date)) {	// If there is a delivery date planned, warning should be on this date

-			print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");

+		print dol_print_date($object->date, 'daytext');

+		if ($object->hasDelay() && empty($object->date_livraison)) {

+		    print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");

@@ -362,3 +368 @@
-		if ($action != 'editdate_livraison') {

-			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>';

-		}

+		if ($action != 'editdate_livraison') 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>';

@@ -367 +371,2 @@
-		if ($action == 'editdate_livraison') {

+		if ($action == 'editdate_livraison')

+		{

@@ -371,2 +376,2 @@
-			print $form->selectDate($object->delivery_date ? $object->delivery_date : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0);

-			print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';

+			print $form->selectDate($object->date_livraison > 0 ? $object->date_livraison : -1, 'liv_', '', '', '', "setdatedelivery");

+			print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';

@@ -374,4 +379,6 @@
-		} else {

-			print dol_print_date($object->delivery_date, 'dayhour');

-			if ($object->hasDelay() && !empty($object->delivery_date)) {

-				print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");

+		}

+		else

+		{

+			print dol_print_date($object->date_livraison, 'daytext');

+			if ($object->hasDelay() && !empty($object->date_livraison)) {

+			    print ' '.img_picto($langs->trans("Late").' : '.$object->showDelay(), "warning");

@@ -380,0 +388,4 @@
+		// Note on several rows

+		//print '<td rowspan="'.$nbrow.'" valign="top">'.$langs->trans('NotePublic').' :<br>';

+		//print nl2br($object->note_public);

+		//print '</td>';

@@ -383,72 +394,37 @@
-		// Delivery delay

-		print '<tr><td height="10">';

-		print '<table class="nobordernopadding" width="100%"><tr><td>';

-		print $langs->trans('AvailabilityPeriod');

-		print '</td>';

-		if ($action != 'editavailability') {

-			print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editavailability&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetAvailability'), 1).'</a></td>';

-		}

-		print '</tr></table>';

-		print '</td><td colspan="2">';

-		if ($action == 'editavailability') {

-			$form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1);

-		} else {

-			$form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1);

-		}

-		print '</td></tr>';

-

-		// Shipping Method

-		print '<tr><td>';

-		print '<table width="100%" class="nobordernopadding"><tr><td>';

-		print $langs->trans('SendingMethod');

-		print '</td>';

-		if ($action != 'editshippingmethod' && $user->hasRight('expedition', 'creer')) {

-			print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshippingmethod&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetShippingMode'), 1).'</a></td>';

-		}

-		print '</tr></table>';

-		print '</td><td colspan="2">';

-		if ($action == 'editshippingmethod') {

-			$form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);

-		} else {

-			$form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none');

-		}

-		print '</td>';

-		print '</tr>';

-

-		// Warehouse

-		if (isModEnabled('stock') && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {

-			require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';

-			$formproduct = new FormProduct($db);

-			print '<tr><td>';

-			print '<table width="100%" class="nobordernopadding"><tr><td>';

-			print $langs->trans('Warehouse');

-			print '</td>';

-			if ($action != 'editwarehouse' && $user->hasRight('commande', 'creer')) {

-				print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editwarehouse&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetWarehouse'), 1).'</a></td>';

-			}

-			print '</tr></table>';

-			print '</td><td colspan="2">';

-			if ($action == 'editwarehouse') {

-				$formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1);

-			} else {

-				$formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none');

-			}

-			print '</td>';

-			print '</tr>';

-		}

-

-		// Source reason (why we have an order)

-		print '<tr><td height="10">';

-		print '<table class="nobordernopadding" width="100%"><tr><td>';

-		print $langs->trans('Source');

-		print '</td>';

-		if ($action != 'editdemandreason') {

-			print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetDemandReason'), 1).'</a></td>';

-		}

-		print '</tr></table>';

-		print '</td><td colspan="2">';

-		if ($action == 'editdemandreason') {

-			$form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1);

-		} else {

-			$form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none');

-		}

+        // Shipping Method

+        print '<tr><td>';

+        print '<table width="100%" class="nobordernopadding"><tr><td>';

+        print $langs->trans('SendingMethod');

+        print '</td>';

+        if ($action != 'editshippingmethod' && $user->rights->expedition->creer)

+            print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshippingmethod&amp;id='.$object->id.'">'.img_edit($langs->trans('SetShippingMode'), 1).'</a></td>';

+        print '</tr></table>';

+        print '</td><td colspan="2">';

+        if ($action == 'editshippingmethod') {

+            $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);

+        } else {

+            $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?id='.$object->id, $object->shipping_method_id, 'none');

+        }

+        print '</td>';

+        print '</tr>';

+

+        // Warehouse

+        if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {

+            require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';

+            $formproduct = new FormProduct($db);

+            print '<tr><td>';

+            print '<table width="100%" class="nobordernopadding"><tr><td>';

+            print $langs->trans('Warehouse');

+            print '</td>';

+            if ($action != 'editwarehouse' && $user->rights->commande->creer)

+                print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editwarehouse&amp;id='.$object->id.'">'.img_edit($langs->trans('SetWarehouse'), 1).'</a></td>';

+            print '</tr></table>';

+            print '</td><td colspan="2">';

+            if ($action == 'editwarehouse') {

+                $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'warehouse_id', 1);

+            } else {

+                $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->warehouse_id, 'none');

+            }

+            print '</td>';

+            print '</tr>';

+        }

@@ -463 +439 @@
-		if ($action != 'editconditions' && $object->statut == Expedition::STATUS_VALIDATED) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';

+		if ($action != 'editconditions' && $object->statut == Expedition::STATUS_VALIDATED) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';

@@ -481 +457 @@
-		if ($action != 'editmode' && $object->statut == Expedition::STATUS_VALIDATED) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';

+		if ($action != 'editmode' && $object->statut == Expedition::STATUS_VALIDATED) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';

@@ -493,0 +470,31 @@
+		// Availability

+		print '<tr><td height="10">';

+		print '<table class="nobordernopadding" width="100%"><tr><td>';

+		print $langs->trans('AvailabilityPeriod');

+		print '</td>';

+		if ($action != 'editavailability')

+			print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editavailability&amp;id='.$object->id.'">'.img_edit($langs->trans('SetAvailability'), 1).'</a></td>';

+		print '</tr></table>';

+		print '</td><td colspan="3">';

+		if ($action == 'editavailability') {

+			$form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'availability_id', 1);

+		} else {

+			$form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id, $object->availability_id, 'none', 1);

+		}

+		print '</td></tr>';

+

+		// Source

+		print '<tr><td height="10">';

+		print '<table class="nobordernopadding" width="100%"><tr><td>';

+		print $langs->trans('Source');

+		print '</td>';

+		if ($action != 'editdemandreason')

+			print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDemandReason'), 1).'</a></td>';

+		print '</tr></table>';

+		print '</td><td colspan="3">';

+		if ($action == 'editdemandreason') {

+			$form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'demand_reason_id', 1);

+		} else {

+			$form->formInputReason($_SERVER['PHP_SELF'].'?id='.$object->id, $object->demand_reason_id, 'none');

+		}

+

@@ -497,9 +504,10 @@
-		if ($totalWeight || $totalVolume) {

-			print '<tr><td>'.$langs->trans("CalculatedWeight").'</td>';

-			print '<td colspan="2">';

-			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');

-			print '</td></tr>';

-			print '<tr><td>'.$langs->trans("CalculatedVolume").'</td>';

-			print '<td colspan="2">';

-			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');

-			print '</td></tr>';

+		if ($totalWeight || $totalVolume)

+		{

+		    print '<tr><td>'.$langs->trans("CalculatedWeight").'</td>';

+		    print '<td>';

+		    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');

+		    print '</td></tr>';

+		    print '<tr><td>'.$langs->trans("CalculatedVolume").'</td>';

+		    print '<td>';

+		    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');

+		    print '</td></tr>';

@@ -511,19 +519,20 @@
-		if (isModEnabled('incoterm')) {

-			print '<tr><td>';

-			print '<table width="100%" class="nobordernopadding"><tr><td>';

-			print $langs->trans('IncotermLabel');

-			print '<td><td class="right">';

-			if ($user->hasRight('commande', 'creer')) {

-				print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'/expedition/shipment.php?id='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';

-			} else {

-				print '&nbsp;';

-			}

-			print '</td></tr></table>';

-			print '</td>';

-			print '<td colspan="2">';

-			if ($action != 'editincoterm') {

-				print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);

-			} else {

-				print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);

-			}

-			print '</td></tr>';

+		if (!empty($conf->incoterm->enabled))

+		{

+		    print '<tr><td>';

+		    print '<table width="100%" class="nobordernopadding"><tr><td>';

+		    print $langs->trans('IncotermLabel');

+		    print '<td><td class="right">';

+		    if ($user->rights->commande->creer) print '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'/expedition/shipment.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';

+		    else print '&nbsp;';

+		    print '</td></tr></table>';

+		    print '</td>';

+		    print '<td colspan="3">';

+		    if ($action != 'editincoterm')

+		    {

+		        print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);

+		    }

+		    else

+		    {

+		        print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);

+		    }

+		    print '</td></tr>';

@@ -542,0 +552 @@
+		print '<div class="ficheaddleft">';

@@ -547,15 +557,16 @@
-		if (isModEnabled("multicurrency") && ($object->multicurrency_code != $conf->currency)) {

-			// Multicurrency Amount HT

-			print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';

-			print '<td class="nowrap">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';

-			print '</tr>';

-

-			// Multicurrency Amount VAT

-			print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>';

-			print '<td class="nowrap">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';

-			print '</tr>';

-

-			// Multicurrency Amount TTC

-			print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>';

-			print '<td class="nowrap">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';

-			print '</tr>';

+		if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency))

+		{

+		    // Multicurrency Amount HT

+		    print '<tr><td class="titlefieldmiddle">'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).'</td>';

+		    print '<td class="nowrap">'.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';

+		    print '</tr>';

+

+		    // Multicurrency Amount VAT

+		    print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountVAT', 'multicurrency_total_tva', '', $object, 0).'</td>';

+		    print '<td class="nowrap">'.price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';

+		    print '</tr>';

+

+		    // Multicurrency Amount TTC

+		    print '<tr><td>'.$form->editfieldkey('MulticurrencyAmountTTC', 'multicurrency_total_ttc', '', $object, 0).'</td>';

+		    print '<td class="nowrap">'.price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'</td>';

+		    print '</tr>';

@@ -574,7 +585,9 @@
-		if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { 		// Localtax1

-			print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';

-			print '<td>'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';

-		}

-		if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { 		// Localtax2 IRPF

-			print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';

-			print '<td>'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';

+		if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) 		// Localtax1

+		{

+		    print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';

+		    print '<td>'.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';

+		}

+		if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) 		// Localtax2 IRPF

+		{

+		    print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';

+		    print '<td>'.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';

@@ -590,0 +604 @@
+		print '</div>';

@@ -592,0 +607 @@
+

@@ -599 +614 @@
-		print '<table id="tablelines" class="noborder noshadow" width="100%">';

+		print '<table class="noborder noshadow" width="100%">';

@@ -603 +618 @@
-		$sql .= " cd.qty, cd.fk_unit,";

+		$sql .= " cd.qty,";

@@ -610,2 +624,0 @@
-		$sql .= ', p.tobatch, p.tosell, p.tobuy, p.barcode';

-		$sql .= ', u.short_label as unit_order';

@@ -614,2 +627 @@
-		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units as u ON cd.fk_unit = u.rowid";

-		$sql .= " WHERE cd.fk_commande = ".((int) $object->id);

+		$sql .= " WHERE cd.fk_commande = ".$object->id;

@@ -621 +633,2 @@
-		if ($resql) {

+		if ($resql)

+		{

@@ -624 +637 @@
-			print '<thead>';

+

@@ -626,8 +639,11 @@
-			print '<th>'.$langs->trans("Description").'</th>';

-			print '<th class="center">'.$langs->trans("QtyOrdered").'</th>';

-			print '<th class="center">'.$langs->trans("QtyShipped").'</th>';

-			print '<th class="center">'.$langs->trans("KeepToShip").'</th>';

-			if (isModEnabled('stock')) {

-				print '<th class="center">'.$langs->trans("RealStock").'</th>';

-			} else {

-				print '<th>&nbsp;</th>';

+			print '<td>'.$langs->trans("Description").'</td>';

+			print '<td class="center">'.$langs->trans("QtyOrdered").'</td>';

+			print '<td class="center">'.$langs->trans("QtyShipped").'</td>';

+			print '<td class="center">'.$langs->trans("KeepToShip").'</td>';

+			if (!empty($conf->stock->enabled))

+			{

+				print '<td class="center">'.$langs->trans("RealStock").'</td>';

+			}

+			else

+			{

+				print '<td>&nbsp;</td>';

@@ -636 +651,0 @@
-			print '</thead>';

@@ -640 +655,2 @@
-			while ($i < $num) {

+			while ($i < $num)

+			{

@@ -645,5 +661,4 @@
-				if ($reshook < 0) {

-					setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

-				}

-

-				if (empty($reshook)) {

+				if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

+

+				if (empty($reshook))

+				{

@@ -655,6 +670,2 @@
-					if (!empty($objp->date_start)) {

-						$type = 1;

-					}

-					if (!empty($objp->date_end)) {

-						$type = 1;

-					}

+					if (!empty($objp->date_start)) $type = 1;

+					if (!empty($objp->date_end)) $type = 1;

@@ -665 +676,2 @@
-					if ($objp->fk_product > 0) {

+					if ($objp->fk_product > 0)

+					{

@@ -667 +679,2 @@
-						if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {

+						if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))

+						{

@@ -671,2 +684,2 @@
-							$prod->id = $objp->fk_product;

-							$prod->entity = $objp->entity;

+	                        $prod->id = $objp->fk_product;

+	                        $prod->entity = $objp->entity;

@@ -677,7 +690,4 @@
-							if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {

-								$newlang = GETPOST('lang_id', 'aZ09');

-							}

-							if (empty($newlang)) {

-								$newlang = $object->thirdparty->default_lang;

-							}

-							if (!empty($newlang)) {

+							if (empty($newlang) && !empty($_REQUEST['lang_id'])) $newlang = $_REQUEST['lang_id'];

+							if (empty($newlang)) $newlang = $object->thirdparty->default_lang;

+							if (!empty($newlang))

+							{

@@ -689 +699,2 @@
-						} else {

+						}

+						else

@@ -691 +701,0 @@
-						}

@@ -700,18 +710,14 @@
-						$product_static->entity = $objp->entity;

-						$product_static->status = $objp->tosell;

-						$product_static->status_buy = $objp->tobuy;

-						$product_static->status_batch = $objp->tobatch;

-						$product_static->barcode = $objp->barcode;

-

-						$product_static->weight = $objp->weight;

-						$product_static->weight_units = $objp->weight_units;

-						$product_static->length = $objp->length;

-						$product_static->length_units = $objp->length_units;

-						$product_static->width = $objp->width;

-						$product_static->width_units = $objp->width_units;

-						$product_static->height = $objp->height;

-						$product_static->height_units = $objp->height_units;

-						$product_static->surface = $objp->surface;

-						$product_static->surface_units = $objp->surface_units;

-						$product_static->volume = $objp->volume;

-						$product_static->volume_units = $objp->volume_units;

+	                    $product_static->entity = $objp->entity;

+

+	                    $product_static->weight = $objp->weight;

+	                    $product_static->weight_units = $objp->weight_units;

+	                    $product_static->length = $objp->length;

+	                    $product_static->length_units = $objp->length_units;

+	                    $product_static->width = $objp->width;

+	                    $product_static->width_units = $objp->width_units;

+	                    $product_static->height = $objp->height;

+	                    $product_static->height_units = $objp->height_units;

+	                    $product_static->surface = $objp->surface;

+	                    $product_static->surface_units = $objp->surface_units;

+	                    $product_static->volume = $objp->volume;

+	                    $product_static->volume_units = $objp->volume_units;

@@ -721,2 +727,2 @@
-						$description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description)).'<br>';

-						$description .= $product_static->show_photos('product', $conf->product->multidir_output[$product_static->entity], 1, 1, 0, 0, 0, 80);

+						$description = ($conf->global->PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr($objp->description)).'<br>';

+	                    $description .= $product_static->show_photos('product', $conf->product->multidir_output[$product_static->entity], 1, 1, 0, 0, 0, 80);

@@ -729 +735,2 @@
-						if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {

+						if (!empty($conf->global->PRODUIT_DESC_IN_FORM))

+						{

@@ -734 +741,3 @@
-					} else {

+					}

+					else

+					{

@@ -736,5 +745,2 @@
-						if ($type == 1) {

-							$text = img_object($langs->trans('Service'), 'service');

-						} else {

-							$text = img_object($langs->trans('Product'), 'product');

-						}

+						if ($type == 1) $text = img_object($langs->trans('Service'), 'service');

+						else $text = img_object($langs->trans('Product'), 'product');

@@ -755 +761 @@
-					print '<td class="center">'.$objp->qty.($objp->unit_order ? ' '.$objp->unit_order : '').'</td>';

+					print '<td class="center">'.$objp->qty.'</td>';

@@ -763 +769 @@
-					print($objp->unit_order ? ' '.$objp->unit_order : '').'</td>';

+					print '</td>';

@@ -767 +773,2 @@
-					if ($type == 0 || getDolGlobalString('STOCK_SUPPORTS_SERVICES')|| getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) {

+					if ($type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES))

+					{

@@ -771,2 +777,0 @@
-					} else {

-						print '0 <span class="opacitymedium">('.$langs->trans("Service").')</span>';

@@ -774,3 +779,8 @@
-					print($objp->unit_order ? ' '.$objp->unit_order : '').'</td>';

-

-					if ($objp->fk_product > 0) {

+					else

+					{

+						print '0 ('.$langs->trans("Service").')';

+					}

+					print '</td>';

+

+					if ($objp->fk_product > 0)

+					{

@@ -782 +792,2 @@
-					if ($objp->fk_product > 0 && ($type == Product::TYPE_PRODUCT || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) && isModEnabled('stock')) {

+					if ($objp->fk_product > 0 && ($type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && !empty($conf->stock->enabled))

+					{

@@ -785 +796,2 @@
-						if ($product->stock_reel < $toBeShipped[$objp->fk_product]) {

+						if ($product->stock_reel < $toBeShipped[$objp->fk_product])

+						{

@@ -787,4 +798,0 @@
-							if (getDolGlobalString('STOCK_CORRECT_STOCK_IN_SHIPMENT')) {

-								$nbPiece = $toBeShipped[$objp->fk_product] - $product->stock_reel;

-								print ' &nbsp; '.$langs->trans("GoTo").' <a href="'.DOL_URL_ROOT.'/product/stock/product.php?id='.((int) $product->id).'&action=correction&nbpiece='.urlencode($nbPiece).'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.((int) $object->id)).'">'.$langs->trans("CorrectStock").'</a>';

-							}

@@ -793,3 +801,3 @@
-					} elseif ($objp->fk_product > 0 && $type == Product::TYPE_SERVICE && getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES') && isModEnabled('stock')) {

-						print '<td class="center"><span class="opacitymedium">('.$langs->trans("Service").')</span></td>';

-					} else {

+					}

+					else

+					{

@@ -801 +809,2 @@
-					if ($objp->fk_product > 0 && getDolGlobalString('PRODUIT_SOUSPRODUITS')) {

+					if ($objp->fk_product > 0 && !empty($conf->global->PRODUIT_SOUSPRODUITS))

+					{

@@ -809,2 +818,4 @@
-						if (count($prods_arbo) > 0) {

-							foreach ($prods_arbo as $key => $value) {

+						if (count($prods_arbo) > 0)

+						{

+							foreach ($prods_arbo as $key => $value)

+							{

@@ -812 +823,2 @@
-								if ($value['stock'] < $value['stock_alert']) {

+								if ($value['stock'] < $value['stock_alert'])

+								{

@@ -817,2 +829,2 @@
-								print '<td>&nbsp;</td>';

-								print '<td>&nbsp;</td>';

+								print '<td>&nbsp</td>';

+								print '<td>&nbsp</td>';

@@ -828 +840,2 @@
-			if (!$num) {

+			if (!$num)

+			{

@@ -833 +846,3 @@
-		} else {

+		}

+		else

+		{

@@ -844 +859,2 @@
-		if (empty($user->socid)) {

+		if (empty($user->socid))

+		{

@@ -847,3 +863,5 @@
-			// Bouton expedier sans gestion des stocks

-			if (!isModEnabled('stock') && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED)) {

-				if ($user->hasRight('expedition', 'creer')) {

+            // Bouton expedier sans gestion des stocks

+            if (empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED))

+			{

+				if ($user->rights->expedition->creer)

+				{

@@ -851 +869,2 @@
-					if ($toBeShippedTotal <= 0) {

+					if ($toBeShippedTotal <= 0)

+					{

@@ -854 +873,3 @@
-				} else {

+				}

+				else

+				{

@@ -862,8 +883,11 @@
-		// Button to create a shipment

-

-		if (isModEnabled('stock') && $object->statut == Commande::STATUS_DRAFT) {

-			print $langs->trans("ValidateOrderFirstBeforeShipment");

-		}

-

-		if (isModEnabled('stock') && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED)) {

-			if ($user->hasRight('expedition', 'creer')) {

+        // Bouton expedier avec gestion des stocks

+

+        if (!empty($conf->stock->enabled) && $object->statut == Commande::STATUS_DRAFT)

+        {

+            print $langs->trans("ValidateOrderFirstBeforeShipment");

+        }

+

+		if (!empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED))

+		{

+			if ($user->rights->expedition->creer)

+			{

@@ -871 +895 @@
-				print '<div class="tabsAction">';

+                print '<div class="tabsAction">';

@@ -876 +900 @@
-				print '<input type="hidden" name="shipping_method_id" value="'.$object->shipping_method_id.'">';

+                print '<input type="hidden" name="shipping_method_id" value="'.$object->shipping_method_id.'">';

@@ -886 +910,2 @@
-				if (isModEnabled('stock')) {

+				if (!empty($conf->stock->enabled))

+				{

@@ -892 +917,2 @@
-					if (count($formproduct->cache_warehouses) <= 0) {

+					if (count($formproduct->cache_warehouses) <= 0)

+					{

@@ -899 +925,2 @@
-				if ($toBeShippedTotal <= 0) {

+				if ($toBeShippedTotal <= 0)

+				{

@@ -910 +937,3 @@
-			} else {

+			}

+			else

+			{

@@ -912 +941 @@
-				print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'">'.$langs->trans("CreateShipment").'</a>';

+				print '<a class="butActionRefused classfortooltip" href="#">'.$langs->trans("CreateShipment").'</a>';

@@ -918 +947,3 @@
-	} else {

+	}

+	else

+	{