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