PageRenderTime 73ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/fourn/commande/dispatch.php

http://github.com/Dolibarr/dolibarr
PHP | 1340 lines | 1133 code | 121 blank | 86 comment | 209 complexity | 941561b9eb77b4ed02f70a0299f190dc MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT

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

Large files files are truncated, but you can click here to view the full file