PageRenderTime 73ms CodeModel.GetById 22ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/fourn/commande/dispatch.php

https://github.com/atm-maxime/dolibarr
PHP | 1090 lines | 824 code | 164 blank | 102 comment | 194 complexity | 285e0dce5f0b89ebc66b4101325df3ea MD5 | raw file
   1<?php
   2/* Copyright (C) 2004-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3 * Copyright (C) 2004-2016 Laurent Destailleur  <eldy@users.sourceforge.net>
   4 * Copyright (C) 2005      Eric Seigne          <eric.seigne@ryxeo.com>
   5 * Copyright (C) 2005-2009 Regis Houssin        <regis.houssin@inodbox.com>
   6 * Copyright (C) 2010-2019 Juanjo Menent        <jmenent@2byte.es>
   7 * Copyright (C) 2014      Cedric Gross         <c.gross@kreiz-it.fr>
   8 * Copyright (C) 2016      Florian Henry        <florian.henry@atm-consulting.fr>
   9 * Copyright (C) 2017      Ferran Marcet        <fmarcet@2byte.es>
  10 * Copyright (C) 2018      Frédéric France      <frederic.france@netlogic.fr>
  11 * Copyright (C) 2019      Christophe Battarel	<christophe@altairis.fr>
  12 *
  13 * This	program	is free	software; you can redistribute it and/or modify
  14 * it under the	terms of the GNU General Public	License	as published by
  15 * the Free Software Foundation; either	version	2 of the License, or
  16 * (at your option) any later version.
  17 *
  18 * This	program	is distributed in the hope that	it will	be useful,
  19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21 * GNU General Public License for more details.
  22 *
  23 * You should have received a copy of the GNU General Public License
  24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
  25 * or see https://www.gnu.org/
  26 */
  27
  28/**
  29 * \file htdocs/fourn/commande/dispatch.php
  30 * \ingroup commande
  31 * \brief Page to dispatch receiving
  32 */
  33
  34require '../../main.inc.php';
  35require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
  36require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  37require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  38require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  39require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
  40require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  41if (!empty($conf->projet->enabled))
  42	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  43
  44// Load translation files required by the page
  45$langs->loadLangs(array("bills", "orders", "sendings", "companies", "deliveries", "products", "stocks", "receptions"));
  46
  47if (!empty($conf->productbatch->enabled))
  48	$langs->load('productbatch');
  49
  50	// Security check
  51$id = GETPOST("id", 'int');
  52$ref = GETPOST('ref');
  53$lineid = GETPOST('lineid', 'int');
  54$action = GETPOST('action', 'aZ09');
  55$fk_default_warehouse = GETPOST('fk_default_warehouse', 'int');
  56
  57if ($user->socid)
  58	$socid = $user->socid;
  59$result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande');
  60
  61if (empty($conf->stock->enabled)) {
  62	accessforbidden();
  63}
  64
  65$hookmanager->initHooks(array('ordersupplierdispatch'));
  66
  67// Recuperation de l'id de projet
  68$projectid = 0;
  69if ($_GET["projectid"])
  70	$projectid = GETPOST("projectid", 'int');
  71
  72$object = new CommandeFournisseur($db);
  73
  74if ($id > 0 || !empty($ref)) {
  75	$result = $object->fetch($id, $ref);
  76	if ($result < 0) {
  77		setEventMessages($object->error, $object->errors, 'errors');
  78	}
  79	$result = $object->fetch_thirdparty();
  80	if ($result < 0) {
  81		setEventMessages($object->error, $object->errors, 'errors');
  82	}
  83}
  84
  85
  86/*
  87 * Actions
  88 */
  89
  90$parameters = array();
  91$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  92if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  93
  94if ($action == 'checkdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))))
  95{
  96	$error = 0;
  97	$supplierorderdispatch = new CommandeFournisseurDispatch($db);
  98
  99	$db->begin();
 100
 101	$result = $supplierorderdispatch->fetch($lineid);
 102	if (!$result)
 103	{
 104		$error++;
 105		setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
 106		$action = '';
 107	}
 108
 109	if (!$error)
 110	{
 111		$result = $supplierorderdispatch->setStatut(1);
 112		if ($result < 0) {
 113			setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
 114			$error++;
 115			$action = '';
 116		}
 117	}
 118
 119	if (!$error)
 120	{
 121		$result = $object->calcAndSetStatusDispatch($user);
 122		if ($result < 0) {
 123			setEventMessages($object->error, $object->errors, 'errors');
 124			$error++;
 125			$action = '';
 126		}
 127	}
 128	if (!$error)
 129	{
 130		$db->commit();
 131	}
 132	else
 133	{
 134		$db->rollback();
 135	}
 136}
 137
 138if ($action == 'uncheckdispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))))
 139{
 140	$error = 0;
 141	$supplierorderdispatch = new CommandeFournisseurDispatch($db);
 142
 143	$db->begin();
 144
 145	$result = $supplierorderdispatch->fetch($lineid);
 146	if (!$result)
 147	{
 148		$error++;
 149		setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
 150		$action = '';
 151	}
 152
 153	if (!$error)
 154	{
 155		$result = $supplierorderdispatch->setStatut(0);
 156		if ($result < 0) {
 157			setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
 158			$error++;
 159			$action = '';
 160		}
 161	}
 162	if (!$error)
 163	{
 164		$result = $object->calcAndSetStatusDispatch($user);
 165		if ($result < 0) {
 166			setEventMessages($object->error, $object->errors, 'errors');
 167			$error++;
 168			$action = '';
 169		}
 170	}
 171	if (!$error)
 172	{
 173		$db->commit();
 174	}
 175	else
 176	{
 177		$db->rollback();
 178	}
 179}
 180
 181if ($action == 'denydispatchline' && !((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))))
 182{
 183	$error = 0;
 184	$supplierorderdispatch = new CommandeFournisseurDispatch($db);
 185
 186	$db->begin();
 187
 188	$result = $supplierorderdispatch->fetch($lineid);
 189	if (!$result)
 190	{
 191		$error++;
 192		setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
 193		$action = '';
 194	}
 195
 196	if (!$error)
 197	{
 198		$result = $supplierorderdispatch->setStatut(2);
 199		if ($result < 0) {
 200			setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors');
 201			$error++;
 202			$action = '';
 203		}
 204	}
 205	if (!$error)
 206	{
 207		$result = $object->calcAndSetStatusDispatch($user);
 208		if ($result < 0) {
 209			setEventMessages($object->error, $object->errors, 'errors');
 210			$error++;
 211			$action = '';
 212		}
 213	}
 214	if (!$error)
 215	{
 216		$db->commit();
 217	}
 218	else
 219	{
 220		$db->rollback();
 221	}
 222}
 223
 224if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) {
 225	$error = 0;
 226
 227	$db->begin();
 228
 229	$pos = 0;
 230	foreach ($_POST as $key => $value)
 231	{
 232		// without batch module enabled
 233		if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg))
 234		{
 235			$pos++;
 236
 237			// $numline=$reg[2] + 1; // line of product
 238			$numline = $pos;
 239			$prod = "product_".$reg[1].'_'.$reg[2];
 240			$qty = "qty_".$reg[1].'_'.$reg[2];
 241			$ent = "entrepot_".$reg[1].'_'.$reg[2];
 242			if (empty(GETPOST($ent))) $ent = $fk_default_warehouse;
 243			$pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount
 244			$fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2];
 245
 246			if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
 247				if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) {
 248					$dto = GETPOST("dto_".$reg[1].'_'.$reg[2]);
 249					if (!empty($dto)) {
 250						$unit_price = price2num(GETPOST("pu_".$reg[1]) * (100 - $dto) / 100, 'MU');
 251					}
 252					$saveprice = "saveprice_".$reg[1].'_'.$reg[2];
 253				}
 254			}
 255
 256			// We ask to move a qty
 257			if (GETPOST($qty) != 0) {
 258				if (!(GETPOST($ent, 'int') > 0)) {
 259					dol_syslog('No dispatch for line '.$key.' as no warehouse was chosen.');
 260					$text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' '.($numline);
 261					setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
 262					$error++;
 263				}
 264
 265				if (!$error) {
 266					$result = $object->dispatchProduct($user, GETPOST($prod, 'int'), GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), '', '', '', GETPOST($fk_commandefourndet, 'int'), $notrigger);
 267					if ($result < 0) {
 268						setEventMessages($object->error, $object->errors, 'errors');
 269						$error++;
 270					}
 271
 272					if (!$error && !empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
 273						if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) {
 274							$dto = GETPOST("dto_".$reg[1].'_'.$reg[2]);
 275							//update supplier price
 276							if (GETPOSTISSET($saveprice)) {
 277								// TODO Use class
 278								$sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
 279								$sql .= " SET unitprice='".GETPOST($pu)."'";
 280								$sql .= ", price=".GETPOST($pu)."*quantity";
 281								$sql .= ", remise_percent='".$dto."'";
 282								$sql .= " WHERE fk_soc=".$object->socid;
 283								$sql .= " AND fk_product=".GETPOST($prod, 'int');
 284
 285								$resql = $db->query($sql);
 286							}
 287						}
 288					}
 289				}
 290			}
 291		}
 292		// with batch module enabled
 293		if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg))
 294		{
 295			$pos++;
 296
 297			// eat-by date dispatch
 298			// $numline=$reg[2] + 1; // line of product
 299			$numline = $pos;
 300			$prod = 'product_batch_'.$reg[1].'_'.$reg[2];
 301			$qty = 'qty_'.$reg[1].'_'.$reg[2];
 302			$ent = 'entrepot_'.$reg[1].'_'.$reg[2];
 303			$pu = 'pu_'.$reg[1].'_'.$reg[2];
 304			$fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2];
 305			$lot = 'lot_number_'.$reg[1].'_'.$reg[2];
 306			$dDLUO = dol_mktime(12, 0, 0, $_POST['dluo_'.$reg[1].'_'.$reg[2].'month'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'day'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'year']);
 307			$dDLC = dol_mktime(12, 0, 0, $_POST['dlc_'.$reg[1].'_'.$reg[2].'month'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'day'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'year']);
 308
 309			$fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2];
 310
 311			// We ask to move a qty
 312			if (GETPOST($qty) > 0) {
 313				if (!(GETPOST($ent, 'int') > 0)) {
 314					dol_syslog('No dispatch for line '.$key.' as no warehouse was chosen.');
 315					$text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' '.($numline).'-'.($reg[1] + 1);
 316					setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
 317					$error++;
 318				}
 319
 320				if (!(GETPOST($lot, 'alpha') || $dDLUO || $dDLC)) {
 321					dol_syslog('No dispatch for line '.$key.' as serial/eat-by/sellby date are not set');
 322					$text = $langs->transnoentities('atleast1batchfield').', '.$langs->transnoentities('Line').' '.($numline).'-'.($reg[1] + 1);
 323					setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
 324					$error++;
 325				}
 326
 327				if (!$error) {
 328					$result = $object->dispatchProduct($user, GETPOST($prod, 'int'), GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), $dDLC, $dDLUO, GETPOST($lot, 'alpha'), GETPOST($fk_commandefourndet, 'int'), $notrigger);
 329					if ($result < 0) {
 330						setEventMessages($object->error, $object->errors, 'errors');
 331						$error++;
 332					}
 333				}
 334			}
 335		}
 336	}
 337
 338	if (!$error) {
 339		$result = $object->calcAndSetStatusDispatch($user, GETPOST('closeopenorder') ? 1 : 0, GETPOST('comment'));
 340		if ($result < 0) {
 341			setEventMessages($object->error, $object->errors, 'errors');
 342			$error++;
 343		}
 344	}
 345
 346	if (!$notrigger && !$error) {
 347		global $conf, $langs, $user;
 348		// Call trigger
 349
 350		$result = $object->call_trigger('ORDER_SUPPLIER_DISPATCH', $user);
 351		// End call triggers
 352
 353		if ($result < 0) {
 354			setEventMessages($object->error, $object->errors, 'errors');
 355			$error++;
 356		}
 357	}
 358
 359	if ($result >= 0 && !$error) {
 360		$db->commit();
 361
 362		header("Location: dispatch.php?id=".$id);
 363		exit();
 364	} else {
 365		$db->rollback();
 366	}
 367}
 368
 369
 370/*
 371 * View
 372 */
 373
 374$now = dol_now();
 375
 376$form = new Form($db);
 377$formproduct = new FormProduct($db);
 378$warehouse_static = new Entrepot($db);
 379$supplierorderdispatch = new CommandeFournisseurDispatch($db);
 380
 381$help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
 382llxHeader('', $langs->trans("Order"), $help_url, '', 0, 0, array('/fourn/js/lib_dispatch.js.php'));
 383
 384if ($id > 0 || !empty($ref)) {
 385	$soc = new Societe($db);
 386	$soc->fetch($object->socid);
 387
 388	$author = new User($db);
 389	$author->fetch($object->user_author_id);
 390
 391	$head = ordersupplier_prepare_head($object);
 392
 393	$title = $langs->trans("SupplierOrder");
 394	dol_fiche_head($head, 'dispatch', $title, -1, 'order');
 395
 396
 397	// Supplier order card
 398
 399	$linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
 400
 401	$morehtmlref = '<div class="refidno">';
 402	// Ref supplier
 403	$morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
 404	$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
 405	// Thirdparty
 406	$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
 407	// Project
 408	if (!empty($conf->projet->enabled))
 409	{
 410	    $langs->load("projects");
 411	    $morehtmlref .= '<br>'.$langs->trans('Project').' ';
 412	    if ($user->rights->fournisseur->commande->creer)
 413	    {
 414	        if ($action != 'classify') {
 415	            //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
 416				$morehtmlref .= ' : ';
 417            }
 418	        if ($action == 'classify') {
 419                //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
 420                $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
 421                $morehtmlref .= '<input type="hidden" name="action" value="classin">';
 422                $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
 423                $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
 424                $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
 425                $morehtmlref .= '</form>';
 426            } else {
 427                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
 428            }
 429	    } else {
 430	        if (!empty($object->fk_project)) {
 431	            $proj = new Project($db);
 432	            $proj->fetch($object->fk_project);
 433	            $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
 434	            $morehtmlref .= $proj->ref;
 435	            $morehtmlref .= '</a>';
 436	        } else {
 437	            $morehtmlref .= '';
 438	        }
 439	    }
 440	}
 441	$morehtmlref .= '</div>';
 442
 443
 444	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
 445
 446
 447	print '<div class="fichecenter">';
 448	print '<div class="underbanner clearboth"></div>';
 449
 450	print '<table class="border tableforfield" width="100%">';
 451
 452	// Date
 453	if ($object->methode_commande_id > 0) {
 454		print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>';
 455		if ($object->date_commande) {
 456			print dol_print_date($object->date_commande, "dayhour")."\n";
 457		}
 458		print "</td></tr>";
 459
 460		if ($object->methode_commande) {
 461			print '<tr><td>'.$langs->trans("Method").'</td><td>'.$object->getInputMethod().'</td></tr>';
 462		}
 463	}
 464
 465	// Author
 466	print '<tr><td class="titlefield">'.$langs->trans("AuthorRequest").'</td>';
 467	print '<td>'.$author->getNomUrl(1, '', 0, 0, 0).'</td>';
 468	print '</tr>';
 469
 470    $parameters = array();
 471    $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
 472
 473	print "</table>";
 474
 475	print '</div>';
 476
 477	// if ($mesg) print $mesg;
 478	print '<br>';
 479
 480	$disabled = 1;
 481	if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER))
 482		$disabled = 0;
 483
 484	// Line of orders
 485	if ($object->statut <= CommandeFournisseur::STATUS_ACCEPTED || $object->statut >= CommandeFournisseur::STATUS_CANCELED) {
 486		print '<br><span class="opacitymedium">'.$langs->trans("OrderStatusNotReadyToDispatch").'</span>';
 487	}
 488
 489	if ($object->statut == CommandeFournisseur::STATUS_ORDERSENT
 490		|| $object->statut == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY
 491		|| $object->statut == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY)
 492	{
 493		require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
 494		$formproduct = new FormProduct($db);
 495		$formproduct->loadWarehouses();
 496
 497		if (empty($conf->reception->enabled))print '<form method="POST" action="dispatch.php?id='.$object->id.'">';
 498        else print '<form method="post" action="'.dol_buildpath('/reception/card.php', 1).'?originid='.$object->id.'&origin=supplierorder">';
 499
 500		print '<input type="hidden" name="token" value="'.newToken().'">';
 501		if (empty($conf->reception->enabled))print '<input type="hidden" name="action" value="dispatch">';
 502		else print '<input type="hidden" name="action" value="create">';
 503
 504		print '<div class="div-table-responsive-no-min">';
 505		print '<table class="noborder centpercent">';
 506
 507		// Set $products_dispatched with qty dispatched for each product id
 508		$products_dispatched = array();
 509		$sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty";
 510		$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd";
 511		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_commandefourndet";
 512		$sql .= " WHERE cfd.fk_commande = ".$object->id;
 513		$sql .= " GROUP BY l.rowid, cfd.fk_product";
 514
 515		$resql = $db->query($sql);
 516		if ($resql) {
 517			$num = $db->num_rows($resql);
 518			$i = 0;
 519
 520			if ($num) {
 521				while ($i < $num) {
 522					$objd = $db->fetch_object($resql);
 523					$products_dispatched[$objd->rowid] = price2num($objd->qty, 5);
 524					$i++;
 525				}
 526			}
 527			$db->free($resql);
 528		}
 529
 530		$sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, SUM(l.qty) as qty,";
 531		$sql .= " p.ref, p.label, p.tobatch, p.fk_default_warehouse";
 532
 533        // Enable hooks to alter the SQL query (SELECT)
 534        $parameters = array();
 535        $reshook = $hookmanager->executeHooks(
 536            'printFieldListSelect',
 537            $parameters,
 538            $object,
 539            $action
 540        );
 541        if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 542        $sql .= $hookmanager->resPrint;
 543
 544		$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
 545		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid";
 546		$sql .= " WHERE l.fk_commande = ".$object->id;
 547		if (empty($conf->global->STOCK_SUPPORTS_SERVICES))
 548			$sql .= " AND l.product_type = 0";
 549
 550        // Enable hooks to alter the SQL query (WHERE)
 551        $parameters = array();
 552        $reshook = $hookmanager->executeHooks(
 553            'printFieldListWhere',
 554            $parameters,
 555            $object,
 556            $action
 557        );
 558        if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 559        $sql .= $hookmanager->resPrint;
 560
 561		$sql .= " GROUP BY p.ref, p.label, p.tobatch, l.rowid, l.fk_product, l.subprice, l.remise_percent, p.fk_default_warehouse"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product
 562		$sql .= " ORDER BY p.ref, p.label";
 563
 564		$resql = $db->query($sql);
 565		if ($resql) {
 566			$num = $db->num_rows($resql);
 567			$i = 0;
 568
 569			if ($num) {
 570				$entrepot = new Entrepot($db);
 571				$listwarehouses = $entrepot->list_array(1);
 572
 573				print '<tr class="liste_titre">';
 574
 575				print '<td>'.$langs->trans("Description").'</td>';
 576				if (!empty($conf->productbatch->enabled))
 577				{
 578					print '<td class="dispatch_batch_number_title">'.$langs->trans("batch_number").'</td>';
 579					print '<td class="dispatch_dluo_title">'.$langs->trans("EatByDate").'</td>';
 580					print '<td class="dispatch_dlc_title">'.$langs->trans("SellByDate").'</td>';
 581				}
 582				else
 583				{
 584					print '<td></td>';
 585					print '<td></td>';
 586					print '<td></td>';
 587				}
 588				print '<td class="right">'.$langs->trans("SupplierRef").'</td>';
 589				print '<td class="right">'.$langs->trans("QtyOrdered").'</td>';
 590				print '<td class="right">'.$langs->trans("QtyDispatchedShort").'</td>';
 591				print '<td class="right">'.$langs->trans("QtyToDispatchShort").'</td>';
 592				print '<td width="32"></td>';
 593
 594				if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
 595					if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) {
 596						print '<td class="right">'.$langs->trans("Price").'</td>';
 597						print '<td class="right">'.$langs->trans("ReductionShort").' (%)</td>';
 598						print '<td class="right">'.$langs->trans("UpdatePrice").'</td>';
 599					}
 600				}
 601
 602				print '<td align="right">'.$langs->trans("Warehouse");
 603
 604				// Select warehouse to force it everywhere
 605				if (count($listwarehouses) > 1)
 606				{
 607					print '<br>'.$langs->trans("ForceTo").' '.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 1, 0, 0, '', 0, 0, $disabled);
 608				}
 609				elseif (count($listwarehouses) == 1)
 610				{
 611					print '<br>'.$langs->trans("ForceTo").' '.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0, '', 0, 0, $disabled);
 612				}
 613
 614				print '</td>';
 615
 616                // Enable hooks to append additional columns
 617                $parameters = array();
 618                $reshook = $hookmanager->executeHooks(
 619                    'printFieldListTitle',
 620                    $parameters,
 621                    $object,
 622                    $action
 623                );
 624                if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 625                print $hookmanager->resPrint;
 626
 627				print "</tr>\n";
 628			}
 629
 630			$nbfreeproduct = 0; // Nb of lins of free products/services
 631			$nbproduct = 0; // Nb of predefined product lines to dispatch (already done or not) if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is off (default)
 632									// or nb of line that remain to dispatch if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is on.
 633
 634			while ($i < $num) {
 635				$objp = $db->fetch_object($resql);
 636
 637				// On n'affiche pas les produits libres
 638				if (!$objp->fk_product > 0) {
 639					$nbfreeproduct++;
 640				} else {
 641					$remaintodispatch = price2num($objp->qty - ((float) $products_dispatched[$objp->rowid]), 5); // Calculation of dispatched
 642					if ($remaintodispatch < 0)
 643						$remaintodispatch = 0;
 644
 645					if ($remaintodispatch || empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) {
 646						$nbproduct++;
 647
 648						// To show detail cref and description value, we must make calculation by cref
 649						// print ($objp->cref?' ('.$objp->cref.')':'');
 650						// if ($objp->description) print '<br>'.nl2br($objp->description);
 651						$suffix = '_0_'.$i;
 652
 653						print "\n";
 654						print '<!-- Line to dispatch '.$suffix.' -->'."\n";
 655						// hidden fields for js function
 656						print '<input id="qty_ordered'.$suffix.'" type="hidden" value="'.$objp->qty.'">';
 657						print '<input id="qty_dispatched'.$suffix.'" type="hidden" value="'.(float) $products_dispatched[$objp->rowid].'">';
 658						print '<tr class="oddeven">';
 659
 660						$linktoprod = '<a href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"), 'product').' '.$objp->ref.'</a>';
 661						$linktoprod .= ' - '.$objp->label."\n";
 662
 663						if (!empty($conf->productbatch->enabled)) {
 664							if ($objp->tobatch) {
 665								print '<td>';
 666								print $linktoprod;
 667								print "</td>";
 668								print '<td class="dispatch_batch_number"></td>';
 669								print '<td class="dispatch_dluo"></td>';
 670								print '<td class="dispatch_dlc"></td>';
 671							} else {
 672								print '<td>';
 673								print $linktoprod;
 674								print "</td>";
 675								print '<td class="dispatch_batch_number">';
 676								print $langs->trans("ProductDoesNotUseBatchSerial");
 677								print '</td>';
 678								print '<td class="dispatch_dluo"></td>';
 679								print '<td class="dispatch_dlc"></td>';
 680							}
 681						} else {
 682							print '<td colspan="4">';
 683							print $linktoprod;
 684							print "</td>";
 685						}
 686
 687						// Define unit price for PMP calculation
 688						$up_ht_disc = $objp->subprice;
 689						if (!empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP))
 690							$up_ht_disc = price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU');
 691
 692						// Supplier ref
 693						print '<td class="right">'.$objp->sref.'</td>';
 694
 695						// Qty ordered
 696						print '<td class="right">'.$objp->qty.'</td>';
 697
 698						// Already dispatched
 699						print '<td class="right">'.$products_dispatched[$objp->rowid].'</td>';
 700
 701						if (!empty($conf->productbatch->enabled) && $objp->tobatch == 1) {
 702							$type = 'batch';
 703							print '<td class="right">';
 704							print '</td>'; // Qty to dispatch
 705							print '<td>';
 706							//print img_picto($langs->trans('AddDispatchBatchLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"');
 707							print '</td>'; // Dispatch column
 708							print '<td></td>'; // Warehouse column
 709
 710                            // Enable hooks to append additional columns
 711                            $parameters = array(
 712                                'is_information_row' => true, // allows hook to distinguish between the
 713                                                              // rows with information and the rows with
 714                                                              // dispatch form input
 715                                'objp' => $objp
 716                            );
 717                            $reshook = $hookmanager->executeHooks(
 718                                'printFieldListValue',
 719                                $parameters,
 720                                $object,
 721                                $action
 722                            );
 723                            if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 724                            print $hookmanager->resPrint;
 725
 726							print '</tr>';
 727
 728							print '<tr class="oddeven" name="'.$type.$suffix.'">';
 729							print '<td>';
 730							print '<input name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
 731							print '<input name="product_batch'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
 732
 733							print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
 734							if (!empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) // Not tested !
 735							{
 736							    print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" type="text" value="'.price2num($up_ht_disc, 'MU').'">';
 737							}
 738							else
 739							{
 740							    print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
 741							}
 742
 743							print '</td>';
 744
 745							print '<td>';
 746							print '<input type="text" class="inputlotnumber quatrevingtquinzepercent" id="lot_number'.$suffix.'" name="lot_number'.$suffix.'" value="'.GETPOST('lot_number'.$suffix).'">';
 747							print '</td>';
 748							print '<td class="nowraponall">';
 749							$dlcdatesuffix = dol_mktime(0, 0, 0, GETPOST('dlc'.$suffix.'month'), GETPOST('dlc'.$suffix.'day'), GETPOST('dlc'.$suffix.'year'));
 750							print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, '', '', 1, '');
 751							print '</td>';
 752							print '<td class="nowraponall">';
 753							$dluodatesuffix = dol_mktime(0, 0, 0, GETPOST('dluo'.$suffix.'month'), GETPOST('dluo'.$suffix.'day'), GETPOST('dluo'.$suffix.'year'));
 754							print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, '', '', 1, '');
 755							print '</td>';
 756							print '<td colspan="3">&nbsp</td>'; // Supplier ref + Qty ordered + qty already dispatched
 757						} else {
 758							$type = 'dispatch';
 759							print '<td class="right">';
 760							print '</td>'; // Qty to dispatch
 761							print '<td>';
 762							//print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"');
 763							print '</td>'; // Dispatch column
 764							print '<td></td>'; // Warehouse column
 765
 766                            // Enable hooks to append additional columns
 767                            $parameters = array(
 768                                'is_information_row' => true, // allows hook to distinguish between the
 769                                                              // rows with information and the rows with
 770                                                              // dispatch form input
 771                                'objp' => $objp
 772                            );
 773                            $reshook = $hookmanager->executeHooks(
 774                                'printFieldListValue',
 775                                $parameters,
 776                                $object,
 777                                $action
 778                            );
 779                            if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 780                            print $hookmanager->resPrint;
 781
 782							print '</tr>';
 783
 784							print '<tr class="oddeven" name="'.$type.$suffix.'">';
 785							print '<td colspan="7">';
 786							print '<input name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
 787							print '<input name="product'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
 788
 789							print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
 790							if (!empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) // Not tested !
 791							{
 792							    print $langs->trans("BuyingPrice").': <input class="maxwidth75" name="pu'.$suffix.'" type="text" value="'.price2num($up_ht_disc, 'MU').'">';
 793							}
 794							else
 795							{
 796							    print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
 797							}
 798
 799							print '</td>';
 800						}
 801
 802						// Qty to dispatch
 803						print '<td class="right">';
 804						print '<input id="qty'.$suffix.'" name="qty'.$suffix.'" type="text" class="width50 right" value="'.(GETPOSTISSET('qty'.$suffix) ? GETPOST('qty'.$suffix, 'int') : (empty($conf->global->SUPPLIER_ORDER_DISPATCH_FORCE_QTY_INPUT_TO_ZERO) ? $remaintodispatch : 0)).'">';
 805						print '</td>';
 806
 807						print '<td>';
 808						if (!empty($conf->productbatch->enabled) && $objp->tobatch == 1) {
 809						    $type = 'batch';
 810						    print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"');
 811						}
 812						else
 813						{
 814						    $type = 'dispatch';
 815						    print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"');
 816						}
 817						print '</td>';
 818
 819						if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
 820							if (empty($conf->multicurrency->enabled) && empty($conf->dynamicprices->enabled)) {
 821								// Price
 822								print '<td class="right">';
 823								print '<input id="pu'.$suffix.'" name="pu'.$suffix.'" type="text" size="8" value="'.price((GETPOST('pu'.$suffix) != '' ? GETPOST('pu'.$suffix) : $up_ht_disc)).'">';
 824								print '</td>';
 825
 826								// Discount
 827								print '<td class="right">';
 828								print '<input id="pu'.$suffix.'" name="dto'.$suffix.'" type="text" size="8" value="'.(GETPOST('dto'.$suffix) != '' ? GETPOST('dto'.$suffix) : '').'">';
 829								print '</td>';
 830
 831								// Save price
 832								print '<td class="center">';
 833								print '<input class="flat checkformerge" type="checkbox" name="saveprice'.$suffix.'" value="'.(GETPOST('saveprice'.$suffix) != '' ? GETPOST('saveprice'.$suffix) : '').'">';
 834								print '</td>';
 835							}
 836						}
 837
 838						// Warehouse
 839						print '<td class="right">';
 840						if (count($listwarehouses) > 1) {
 841							print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ?GETPOST("entrepot".$suffix) : ($objp->fk_default_warehouse ? $objp->fk_default_warehouse : ''), "entrepot".$suffix, '', 1, 0, $objp->fk_product, '', 1, 0, null, 'csswarehouse'.$suffix);
 842						} elseif (count($listwarehouses) == 1) {
 843							print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ?GETPOST("entrepot".$suffix) : ($objp->fk_default_warehouse ? $objp->fk_default_warehouse : ''), "entrepot".$suffix, '', 0, 0, $objp->fk_product, '', 1, 0, null, 'csswarehouse'.$suffix);
 844						} else {
 845							$langs->load("errors");
 846							print $langs->trans("ErrorNoWarehouseDefined");
 847						}
 848						print "</td>\n";
 849
 850                        // Enable hooks to append additional columns
 851                        $parameters = array(
 852                            'is_information_row' => false // this is a dispatch form row
 853                        );
 854                        $reshook = $hookmanager->executeHooks(
 855                            'printFieldListValue',
 856                            $parameters,
 857                            $object,
 858                            $action
 859                        );
 860                        if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
 861                        print $hookmanager->resPrint;
 862
 863						print "</tr>\n";
 864					}
 865				}
 866				$i++;
 867			}
 868			$db->free($resql);
 869		} else {
 870			dol_print_error($db);
 871		}
 872
 873		print "</table>\n";
 874		print '</div>';
 875
 876		if ($nbproduct)
 877		{
 878			$checkboxlabel = $langs->trans("CloseReceivedSupplierOrdersAutomatically", $langs->transnoentitiesnoconv('StatusOrderReceivedAll'));
 879
 880			print '<div class="center">';
 881			$parameters = array();
 882			$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
 883			// modified by hook
 884			if (empty($reshook))
 885			{
 886                if (empty($conf->reception->enabled)) {
 887                    print $langs->trans("Comment").' : ';
 888                    print '<input type="text" class="minwidth400" maxlength="128" name="comment" value="';
 889                    print $_POST["comment"] ? GETPOST("comment") : $langs->trans("DispatchSupplierOrder", $object->ref);
 890                    // print ' / '.$object->ref_supplier; // Not yet available
 891                    print '" class="flat"><br>';
 892
 893                    print '<input type="checkbox" checked="checked" name="closeopenorder"> '.$checkboxlabel;
 894                }
 895
 896                $dispatchBt = empty($conf->reception->enabled) ? $langs->trans("Receive") : $langs->trans("CreateReception");
 897
 898                print '<br><input type="submit" class="button" name="dispatch" value="'.dol_escape_htmltag($dispatchBt).'"';
 899                if (count($listwarehouses) <= 0)
 900					print ' disabled';
 901				print '>';
 902			}
 903			print '</div>';
 904		}
 905
 906		// Message if nothing to dispatch
 907		if (!$nbproduct) {
 908		    print "<br>\n";
 909		    if (empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED))
 910				print '<div class="opacitymedium">'.$langs->trans("NoPredefinedProductToDispatch").'</div>'; // No predefined line at all
 911			else
 912				print '<div class="opacitymedium">'.$langs->trans("NoMorePredefinedProductToDispatch").'</div>'; // No predefined line that remain to be dispatched.
 913		}
 914
 915		print '</form>';
 916	}
 917
 918	dol_fiche_end();
 919
 920	// traitement entrepot par défaut
 921	print '<script type="text/javascript">
 922			$(document).ready(function () {
 923				$("select[name=fk_default_warehouse]").change(function() {
 924					var fk_default_warehouse = $("option:selected", this).val();
 925					$("select[name^=entrepot_]").val(fk_default_warehouse).change();
 926				});
 927			});
 928		</script>';
 929
 930	// List of lines already dispatched
 931	$sql = "SELECT p.ref, p.label,";
 932	$sql .= " e.rowid as warehouse_id, e.ref as entrepot,";
 933	$sql .= " cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.datec";
 934	if ($conf->reception->enabled)$sql .= " ,cfd.fk_reception, r.date_delivery";
 935	$sql .= " FROM ".MAIN_DB_PREFIX."product as p,";
 936	$sql .= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd";
 937	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid";
 938	if ($conf->reception->enabled)$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."reception as r ON cfd.fk_reception = r.rowid";
 939	$sql .= " WHERE cfd.fk_commande = ".$object->id;
 940	$sql .= " AND cfd.fk_product = p.rowid";
 941	$sql .= " ORDER BY cfd.rowid ASC";
 942
 943	$resql = $db->query($sql);
 944	if ($resql) {
 945		$num = $db->num_rows($resql);
 946		$i = 0;
 947
 948		if ($num > 0) {
 949			print "<br>\n";
 950
 951			print load_fiche_titre($langs->trans("ReceivingForSameOrder"));
 952
 953			print '<div class="div-table-responsive">';
 954			print '<table id="dispatch_received_products" class="noborder centpercent">';
 955
 956			print '<tr class="liste_titre">';
 957			if ($conf->reception->enabled)print '<td>'.$langs->trans("Reception").'</td>';
 958
 959			print '<td>'.$langs->trans("Product").'</td>';
 960			print '<td>'.$langs->trans("DateCreation").'</td>';
 961			print '<td>'.$langs->trans("DateDeliveryPlanned").'</td>';
 962			if (!empty($conf->productbatch->enabled)) {
 963				print '<td class="dispatch_batch_number_title">'.$langs->trans("batch_number").'</td>';
 964				print '<td class="dispatch_dluo_title">'.$langs->trans("EatByDate").'</td>';
 965				print '<td class="dispatch_dlc_title">'.$langs->trans("SellByDate").'</td>';
 966			}
 967			print '<td class="right">'.$langs->trans("QtyDispatched").'</td>';
 968			print '<td></td>';
 969			print '<td>'.$langs->trans("Warehouse").'</td>';
 970			print '<td>'.$langs->trans("Comment").'</td>';
 971
 972			// Status
 973			if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS) && empty($reception->rowid)) {
 974				print '<td class="center" colspan="2">'.$langs->trans("Status").'</td>';
 975			}
 976			elseif (!empty($conf->reception->enabled)) {
 977				print '<td class="center"></td>';
 978			}
 979
 980			print '<td class="center"></td>';
 981
 982			print "</tr>\n";
 983
 984			while ($i < $num) {
 985				$objp = $db->fetch_object($resql);
 986
 987				print "<tr ".$bc[$var].">";
 988
 989				if (!empty($conf->reception->enabled)) {
 990					print '<td>';
 991					if (!empty($objp->fk_reception)) {
 992						$reception = new Reception($db);
 993						$reception->fetch($objp->fk_reception);
 994						print $reception->getNomUrl(1);
 995					}
 996
 997					print "</td>";
 998				}
 999
1000				print '<td>';
1001				print '<a href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"), 'product').' '.$objp->ref.'</a>';
1002				print ' - '.$objp->label;
1003				print "</td>\n";
1004				print '<td>'.dol_print_date($db->jdate($objp->datec), 'day').'</td>';
1005				print '<td>'.dol_print_date($db->jdate($objp->date_delivery), 'day').'</td>';
1006
1007				if (!empty($conf->productbatch->enabled)) {
1008					print '<td class="dispatch_batch_number">'.$objp->batch.'</td>';
1009					print '<td class="dispatch_dluo">'.dol_print_date($db->jdate($objp->eatby), 'day').'</td>';
1010					print '<td class="dispatch_dlc">'.dol_print_date($db->jdate($objp->sellby), 'day').'</td>';
1011				}
1012
1013				// Qty
1014				print '<td class="right">'.$objp->qty.'</td>';
1015				print '<td>&nbsp;</td>';
1016
1017				// Warehouse
1018				print '<td>';
1019				$warehouse_static->id = $objp->warehouse_id;
1020				$warehouse_static->libelle = $objp->entrepot;
1021				print $warehouse_static->getNomUrl(1);
1022				print '</td>';
1023
1024				// Comment
1025				print '<td class="tdoverflowmax300" style="white-space: pre;">'.$objp->comment.'</td>';
1026
1027				// Status
1028				if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS) && empty($reception->rowid)) {
1029					print '<td class="right">';
1030					$supplierorderdispatch->status = (empty($objp->status) ? 0 : $objp->status);
1031					// print $supplierorderdispatch->status;
1032					print $supplierorderdispatch->getLibStatut(5);
1033					print '</td>';
1034
1035					// Add button to check/uncheck disaptching
1036					print '<td class="center">';
1037					if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))
1038					{
1039						if (empty($objp->status)) {
1040							print '<a class="button buttonRefused" href="#">'.$langs->trans("Approve").'</a>';
1041							print '<a class="button buttonRefused" href="#">'.$langs->trans("Deny").'</a>';
1042						} else {
1043							print '<a class="button buttonRefused" href="#">'.$langs->trans("Disapprove").'</a>';
1044							print '<a class="button buttonRefused" href="#">'.$langs->trans("Deny").'</a>';
1045						}
1046					} else {
1047						$disabled = '';
1048						if ($object->statut == 5)
1049							$disabled = 1;
1050						if (empty($objp->status)) {
1051							print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=checkdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Approve").'</a>';
1052							print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=denydispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Deny").'</a>';
1053						}
1054						if ($objp->status == 1) {
1055							print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=uncheckdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Reinit").'</a>';
1056							print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=denydispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Deny").'</a>';
1057						}
1058						if ($objp->status == 2) {
1059							print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=uncheckdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Reinit").'</a>';
1060							print '<a class="button'.($disabled ? ' buttonRefused' : '').'" href="'.$_SERVER["PHP_SELF"]."?id=".$id."&action=checkdispatchline&lineid=".$objp->dispatchlineid.'">'.$langs->trans("Approve").'</a>';
1061						}
1062					}
1063					print '</td>';
1064				} elseif (!empty($conf->reception->enabled)) {
1065					print '<td class="right">';
1066					if (!empty($reception->id)) {
1067						print $reception->getLibStatut(5);
1068					}
1069					print '</td>';
1070				}
1071
1072				print '<td class="center"></td>';
1073
1074				print "</tr>\n";
1075
1076				$i++;
1077			}
1078			$db->free($resql);
1079
1080			print "</table>\n";
1081			print '</div>';
1082		}
1083	} else {
1084		dol_print_error($db);
1085	}
1086}
1087
1088// End of page
1089llxFooter();
1090$db->close();