dispatch.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  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-2022 Ferran Marcet <fmarcet@2byte.es>
  10. * Copyright (C) 2018-2022 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 3 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. */
  26. /**
  27. * \file htdocs/expedition/dispatch.php
  28. * \ingroup expedition
  29. * \brief Page to dispatch shipments
  30. */
  31. // Load Dolibarr environment
  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. require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
  41. if (isModEnabled('project')) {
  42. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  43. }
  44. // Load translation files required by the page
  45. $langs->loadLangs(array("sendings", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal'));
  46. if (isModEnabled('productbatch')) {
  47. $langs->load('productbatch');
  48. }
  49. // Security check
  50. $id = GETPOST("id", 'int');
  51. $ref = GETPOST('ref');
  52. $lineid = GETPOST('lineid', 'int');
  53. $action = GETPOST('action', 'aZ09');
  54. $fk_default_warehouse = GETPOST('fk_default_warehouse', 'int');
  55. $cancel = GETPOST('cancel', 'alpha');
  56. $confirm = GETPOST('confirm', 'alpha');
  57. if ($user->socid) {
  58. $socid = $user->socid;
  59. }
  60. $hookmanager->initHooks(array('expeditiondispatch'));
  61. // Recuperation de l'id de projet
  62. $projectid = 0;
  63. if (GETPOSTISSET("projectid")) {
  64. $projectid = GETPOST("projectid", 'int');
  65. }
  66. $object = new Expedition($db);
  67. $objectorder = new Commande($db);
  68. if ($id > 0 || !empty($ref)) {
  69. $result = $object->fetch($id, $ref);
  70. if ($result < 0) {
  71. setEventMessages($object->error, $object->errors, 'errors');
  72. }
  73. $result = $object->fetch_thirdparty();
  74. if ($result < 0) {
  75. setEventMessages($object->error, $object->errors, 'errors');
  76. }
  77. if (!empty($object->origin)) {
  78. $origin = $object->origin;
  79. $object->fetch_origin();
  80. $typeobject = $object->origin;
  81. }
  82. }
  83. // $id is id of a purchase order.
  84. $result = restrictedArea($user, 'expedition', $object, '');
  85. if (!isModEnabled('stock')) {
  86. accessforbidden();
  87. }
  88. $usercancreate = $user->hasRight('expedition', 'creer');
  89. $permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php
  90. /*
  91. * Actions
  92. */
  93. $parameters = array();
  94. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  95. if ($reshook < 0) {
  96. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  97. }
  98. // Update a dispatched line
  99. if ($action == 'updatelines' && $usercancreate) {
  100. $db->begin();
  101. $error = 0;
  102. $expeditiondispatch = new ExpeditionLigne($db);
  103. $expeditionlinebatch = new ExpeditionLineBatch($db);
  104. $pos = 0;
  105. foreach ($_POST as $key => $value) {
  106. // without batch module enabled
  107. $reg = array();
  108. if (preg_match('/^product_.*([0-9]+)_([0-9]+)$/i', $key, $reg)) {
  109. $pos++;
  110. if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) {
  111. $modebatch = "barcode";
  112. } elseif (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) { // With batchmode enabled
  113. $modebatch = "batch";
  114. }
  115. $numline = $pos;
  116. if ($modebatch == "barcode") {
  117. $prod = "product_".$reg[1].'_'.$reg[2];
  118. } else {
  119. $prod = 'product_batch_'.$reg[1].'_'.$reg[2];
  120. }
  121. $qty = "qty_".$reg[1].'_'.$reg[2];
  122. $ent = "entrepot_".$reg[1].'_'.$reg[2];
  123. $fk_commandedet = "fk_commandedet_".$reg[1].'_'.$reg[2];
  124. $idline = GETPOST("idline_".$reg[1].'_'.$reg[2]);
  125. $pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount
  126. $lot = '';
  127. $dDLUO = '';
  128. $dDLC = '';
  129. if ($modebatch == "batch") { //TODO: Make impossible to input non existing batchcode
  130. $lot = GETPOST('lot_number_'.$reg[1].'_'.$reg[2]);
  131. $dDLUO = dol_mktime(12, 0, 0, GETPOST('dluo_'.$reg[1].'_'.$reg[2].'month', 'int'), GETPOST('dluo_'.$reg[1].'_'.$reg[2].'day', 'int'), GETPOST('dluo_'.$reg[1].'_'.$reg[2].'year', 'int'));
  132. $dDLC = dol_mktime(12, 0, 0, GETPOST('dlc_'.$reg[1].'_'.$reg[2].'month', 'int'), GETPOST('dlc_'.$reg[1].'_'.$reg[2].'day', 'int'), GETPOST('dlc_'.$reg[1].'_'.$reg[2].'year', 'int'));
  133. }
  134. // We ask to move a qty
  135. if (($modebatch == "batch" && GETPOST($qty) > 0) || ($modebatch == "barcode" && GETPOST($qty) != 0)) {
  136. if (!(GETPOST($ent, 'int') > 0)) {
  137. dol_syslog('No dispatch for line '.$key.' as no warehouse was chosen.');
  138. $text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' '.($numline);
  139. setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors');
  140. $error++;
  141. }
  142. if ($modebatch == "batch") {
  143. $sql = "SELECT pb.rowid ";
  144. $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb";
  145. $sql .= " JOIN ".MAIN_DB_PREFIX."product_stock as ps";
  146. $sql .= " ON ps.rowid = pb.fk_product_stock";
  147. $sql .= " WHERE pb.batch ='".$db->escape($lot)."'";
  148. $sql .= " AND ps.fk_product =".((int) GETPOST($prod, 'int')) ;
  149. $sql .= " AND ps.fk_entrepot =".((int) GETPOST($ent, 'int')) ;
  150. $resql = $db->query($sql);
  151. if ($resql) {
  152. $num = $db->num_rows($resql);
  153. if ($num > 1) {
  154. dol_syslog('No dispatch for line '.$key.' as too many combination warehouse, product, batch code was found ('.$num.').');
  155. setEventMessages($langs->trans('ErrorTooManyCombinationBatchcode', $numline, $num), null, 'errors');
  156. $error++;
  157. } elseif ($num < 1) {
  158. dol_syslog('No dispatch for line '.$key.' as no combination warehouse, product, batch code was found.');
  159. setEventMessages($langs->trans('ErrorNoCombinationBatchcode', $numline), null, 'errors');
  160. $error++;
  161. }
  162. $db->free($resql);
  163. }
  164. }
  165. if (!$error) {
  166. $qtystart = 0;
  167. if ($idline > 0) {
  168. $result = $expeditiondispatch->fetch($idline);
  169. if ($result < 0) {
  170. setEventMessages($expeditiondispatch->error, $expeditiondispatch->errors, 'errors');
  171. $error++;
  172. } else {
  173. $qtystart = $expeditiondispatch->qty;
  174. $expeditiondispatch->qty = GETPOST($qty);
  175. $expeditiondispatch->entrepot_id = GETPOST($ent, 'int');
  176. $result = $expeditiondispatch->update($user);
  177. if ($result < 0) {
  178. setEventMessages($expeditiondispatch->error, $expeditiondispatch->errors, 'errors');
  179. $error++;
  180. }
  181. if (!$error && $modebatch == "batch") {
  182. $sql = "UPDATE ".MAIN_DB_PREFIX.$expeditionlinebatch->table_element." SET";
  183. $sql .= " eatby = ".($eatby ? "'".$db->idate($eatby)."'" : "null");
  184. $sql .= " , sellby = ".($sellby ? "'".$db->idate($sellby)."'" : "null");
  185. $sql .= " , qty = ".((float) price2num(GETPOST($qty, 'int'), 'MS'));
  186. $sql .= " WHERE fk_expeditiondet = ".((int) $idline);
  187. $sql .= " AND batch = ".((int) $idline);
  188. $resql = $db->query($sql);
  189. if (!$db->query($sql)) {
  190. dol_print_error($db);
  191. $error++;
  192. }
  193. }
  194. }
  195. } else {
  196. $expeditiondispatch->fk_expedition = $object->id;
  197. $expeditiondispatch->entrepot_id = GETPOST($ent, 'int');
  198. $expeditiondispatch->fk_origin_line = GETPOST($fk_commandedet, 'int');
  199. $expeditiondispatch->qty = GETPOST($qty, 'int');
  200. $idline = $expeditiondispatch->insert($user);
  201. if ($idline < 0) {
  202. setEventMessages($expeditiondispatch->error, $expeditiondispatch->errors, 'errors');
  203. $error++;
  204. }
  205. if ($modebatch == "batch" && !$error) {
  206. $expeditionlinebatch->sellby = $dDLUO;
  207. $expeditionlinebatch->eatby = $dDLC;
  208. $expeditionlinebatch->batch = $lot;
  209. $expeditionlinebatch->qty = GETPOST($qty, 'int');
  210. $expeditionlinebatch->fk_origin_stock = 0;
  211. $result = $expeditionlinebatch->create($idline);
  212. if ($result < 0) {
  213. setEventMessages($expeditionlinebatch->error, $expeditionlinebatch->errors, 'errors');
  214. $error++;
  215. }
  216. }
  217. }
  218. // If module stock is enabled and the stock increase is done on purchase order dispatching
  219. if (!$error && GETPOST($ent, 'int') > 0 && isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
  220. $mouv = new MouvementStock($db);
  221. $product = GETPOST($prod, 'int');
  222. $entrepot = GETPOST($ent, 'int');
  223. $qtymouv = GETPOST($qty) - $qtystart;
  224. $price = GETPOST($pu);
  225. $comment = GETPOST('comment');
  226. $inventorycode = dol_print_date(dol_now(), 'dayhourlog');
  227. $now = dol_now();
  228. $eatby = '';
  229. $sellby = '';
  230. $batch = '';
  231. if ($modebatch == "batch") {
  232. $eatby = $dDLUO;
  233. $sellby = $dDLC;
  234. $batch = $lot ;
  235. }
  236. if ($product > 0 && $qtymouv != 0) {
  237. // $price should take into account discount (except if option STOCK_EXCLUDE_DISCOUNT_FOR_PMP is on)
  238. $mouv->origin = $objectorder;
  239. $mouv->setOrigin($objectorder->element, $objectorder->id);
  240. // Method change if qty < 0
  241. if (!empty($conf->global->SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN) && $qtymouv < 0) {
  242. $result = $mouv->reception($user, $product, $entrepot, $qtymouv*(-1), $price, $comment, $eatby, $sellby, $batch, '', 0, $inventorycode);
  243. } else {
  244. $result = $mouv->livraison($user, $product, $entrepot, $qtymouv, $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
  245. }
  246. if ($result < 0) {
  247. setEventMessages($mouv->error, $mouv->errors, 'errors');
  248. $error++;
  249. }
  250. }
  251. }
  252. }
  253. }
  254. }
  255. }
  256. if ($error > 0) {
  257. $db->rollback();
  258. setEventMessages($error, $errors, 'errors');
  259. } else {
  260. $db->commit();
  261. setEventMessages($langs->trans("ReceptionUpdated"), null);
  262. }
  263. } elseif ($action == 'setdate_livraison' && $usercancreate) {
  264. $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));
  265. $object->fetch($id);
  266. $result = $object->setDeliveryDate($user, $datedelivery);
  267. if ($result < 0) {
  268. setEventMessages($object->error, $object->errors, 'errors');
  269. }
  270. }
  271. /*
  272. * View
  273. */
  274. $now = dol_now();
  275. $form = new Form($db);
  276. $formproduct = new FormProduct($db);
  277. $warehouse_static = new Entrepot($db);
  278. $title = $object->ref." - ".$langs->trans('ShipmentDistribution');
  279. $help_url = 'EN:Module_Shipments|FR:Module_Expéditions|ES:M&oacute;dulo_Expediciones|DE:Modul_Lieferungen';
  280. $morejs = array('/expedition/js/lib_dispatch.js.php');
  281. llxHeader('', $title, $help_url, '', 0, 0, $morejs);
  282. if ($id > 0 || !empty($ref)) {
  283. $lines = $object->lines;
  284. $num_prod = count($lines);
  285. if (!empty($object->origin) && $object->origin_id > 0) {
  286. $object->origin = 'commande';
  287. $typeobject = $object->origin;
  288. $origin = $object->origin;
  289. $origin_id = $object->origin_id;
  290. $object->fetch_origin(); // Load property $object->commande, $object->propal, ...
  291. }
  292. $soc = new Societe($db);
  293. $soc->fetch($object->socid);
  294. $author = new User($db);
  295. $author->fetch($object->user_author_id);
  296. $head = shipping_prepare_head($object);
  297. print dol_get_fiche_head($head, 'dispatch', $langs->trans("Shipment"), -1, $object->picto);
  298. $formconfirm = '';
  299. // Confirmation to delete line
  300. if ($action == 'ask_deleteline') {
  301. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  302. }
  303. // Call Hook formConfirm
  304. $parameters = array('lineid' => $lineid);
  305. // Note that $action and $object may be modified by hook
  306. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action);
  307. if (empty($reshook)) {
  308. $formconfirm .= $hookmanager->resPrint;
  309. } elseif ($reshook > 0) {
  310. $formconfirm = $hookmanager->resPrint;
  311. }
  312. // Print form confirm
  313. print $formconfirm;
  314. if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {
  315. $objectsrc = new Commande($db);
  316. $objectsrc->fetch($object->$typeobject->id);
  317. }
  318. if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {
  319. $objectsrc = new Propal($db);
  320. $objectsrc->fetch($object->$typeobject->id);
  321. }
  322. // Shipment card
  323. $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  324. $morehtmlref = '<div class="refidno">';
  325. // Ref customer shipment
  326. $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
  327. $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->expedition->creer, 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE : ''), '', null, null, '', 1);
  328. // Thirdparty
  329. $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
  330. // Project
  331. if (isModEnabled('project')) {
  332. $langs->load("projects");
  333. $morehtmlref .= '<br>';
  334. if (0) { // Do not change on reception
  335. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  336. if ($action != 'classify' && $permissiontoadd) {
  337. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  338. }
  339. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  340. } else {
  341. if (!empty($objectsrc) && !empty($objectsrc->fk_project)) {
  342. $proj = new Project($db);
  343. $proj->fetch($objectsrc->fk_project);
  344. $morehtmlref .= $proj->getNomUrl(1);
  345. if ($proj->title) {
  346. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  347. }
  348. }
  349. }
  350. }
  351. $morehtmlref .= '</div>';
  352. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  353. print '<div class="fichecenter">';
  354. print '<div class="underbanner clearboth"></div>';
  355. print '<table class="border tableforfield" width="100%">';
  356. // Linked documents
  357. if ($typeobject == 'commande' && $object->$typeobject->id && isModEnabled('commande')) {
  358. print '<tr><td>';
  359. print $langs->trans("RefOrder").'</td>';
  360. print '<td colspan="3">';
  361. print $objectsrc->getNomUrl(1, 'commande');
  362. print "</td>\n";
  363. print '</tr>';
  364. }
  365. if ($typeobject == 'propal' && $object->$typeobject->id && isModEnabled("propal")) {
  366. print '<tr><td>';
  367. print $langs->trans("RefProposal").'</td>';
  368. print '<td colspan="3">';
  369. print $objectsrc->getNomUrl(1, 'expedition');
  370. print "</td>\n";
  371. print '</tr>';
  372. }
  373. // Date creation
  374. print '<tr><td class="titlefield">'.$langs->trans("DateCreation").'</td>';
  375. print '<td colspan="3">'.dol_print_date($object->date_creation, "dayhour", "tzuserrel")."</td>\n";
  376. print '</tr>';
  377. // Delivery date planned
  378. print '<tr><td height="10">';
  379. print '<table class="nobordernopadding" width="100%"><tr><td>';
  380. print $langs->trans('DateDeliveryPlanned');
  381. print '</td>';
  382. if ($action != 'editdate_livraison') {
  383. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
  384. }
  385. print '</tr></table>';
  386. print '</td><td colspan="2">';
  387. if ($action == 'editdate_livraison') {
  388. print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  389. print '<input type="hidden" name="token" value="'.newToken().'">';
  390. print '<input type="hidden" name="action" value="setdate_livraison">';
  391. print $form->selectDate($object->date_delivery ? $object->date_delivery : -1, 'liv_', 1, 1, '', "setdate_livraison", 1, 0);
  392. print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';
  393. print '</form>';
  394. } else {
  395. print $object->date_delivery ? dol_print_date($object->date_delivery, 'dayhour') : '&nbsp;';
  396. }
  397. print '</td>';
  398. print '</tr></table>';
  399. print '<br><center>';
  400. print '<a href="#" id="resetalltoexpected" class="marginrightonly paddingright marginleftonly paddingleft">'.img_picto("", 'autofill', 'class="pictofixedwidth"').$langs->trans("RestoreWithCurrentQtySaved").'</a></td>';
  401. // Link to clear qty
  402. print '<a href="#" id="autoreset" class="marginrightonly paddingright marginleftonly paddingleft">'.img_picto("", 'eraser', 'class="pictofixedwidth"').$langs->trans("ClearQtys").'</a></td>';
  403. print '<center>';
  404. print '<br>';
  405. $disabled = 0; // This is used to disable or not the bulk selection of target warehouse. No reason to have it disabled so forced to 0.
  406. if ($object->statut == Reception::STATUS_DRAFT) {
  407. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  408. $formproduct = new FormProduct($db);
  409. $formproduct->loadWarehouses();
  410. $entrepot = new Entrepot($db);
  411. $listwarehouses = $entrepot->list_array(1);
  412. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  413. print '<input type="hidden" name="token" value="'.newToken().'">';
  414. print '<input type="hidden" name="action" value="updatelines">';
  415. print '<input type="hidden" name="id" value="'.$object->id.'">';
  416. print '<div class="div-table-responsive-no-min">';
  417. print '<table class="noborder centpercent">';
  418. // Get list of lines from the shipments $products_dispatched with qty dispatched for each product id
  419. $products_dispatched = array();
  420. $sql = "SELECT ed.fk_origin_line as rowid, sum(ed.qty) as qty";
  421. $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
  422. $sql .= " WHERE ed.fk_expedition = ".((int) $object->id);
  423. $sql .= " GROUP BY ed.fk_origin_line";
  424. $resql = $db->query($sql);
  425. if ($resql) {
  426. $num = $db->num_rows($resql);
  427. $i = 0;
  428. if ($num) {
  429. while ($i < $num) {
  430. $objd = $db->fetch_object($resql);
  431. $products_dispatched[$objd->rowid] = price2num($objd->qty, 'MS');
  432. $i++;
  433. }
  434. }
  435. $db->free($resql);
  436. }
  437. //$sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref AS sref, SUM(l.qty) as qty,";
  438. $sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, '' AS sref, l.qty as qty,";
  439. $sql .= " p.ref, p.label, p.tobatch, p.fk_default_warehouse";
  440. // Enable hooks to alter the SQL query (SELECT)
  441. $parameters = array();
  442. $reshook = $hookmanager->executeHooks(
  443. 'printFieldListSelect',
  444. $parameters,
  445. $object,
  446. $action
  447. );
  448. if ($reshook < 0) {
  449. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  450. }
  451. $sql .= $hookmanager->resPrint;
  452. $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as l";
  453. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid";
  454. $sql .= " WHERE l.fk_commande = ".((int) $objectsrc->id);
  455. if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  456. $sql .= " AND l.product_type = 0";
  457. }
  458. // Enable hooks to alter the SQL query (WHERE)
  459. $parameters = array();
  460. $reshook = $hookmanager->executeHooks(
  461. 'printFieldListWhere',
  462. $parameters,
  463. $object,
  464. $action
  465. );
  466. if ($reshook < 0) {
  467. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  468. }
  469. $sql .= $hookmanager->resPrint;
  470. //$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
  471. $sql .= " ORDER BY l.rang, p.ref, p.label";
  472. $resql = $db->query($sql);
  473. if ($resql) {
  474. $num = $db->num_rows($resql);
  475. $i = 0;
  476. $numline = 1;
  477. if ($num) {
  478. print '<tr class="liste_titre">';
  479. print '<td>'.$langs->trans("Description").'</td>';
  480. if (isModEnabled('productbatch')) {
  481. print '<td class="dispatch_batch_number_title">'.$langs->trans("batch_number").'</td>';
  482. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  483. print '<td class="dispatch_dlc_title">'.$langs->trans("SellByDate").'</td>';
  484. }
  485. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  486. print '<td class="dispatch_dluo_title">'.$langs->trans("EatByDate").'</td>';
  487. }
  488. } else {
  489. print '<td></td>';
  490. print '<td></td>';
  491. print '<td></td>';
  492. }
  493. print '<td class="right">'.$langs->trans("QtyOrdered").'</td>';
  494. print '<td class="right">'.$langs->trans("QtyDispatchedShort").'</td>';
  495. print ' <td class="right">'.$langs->trans("QtyToDispatchShort");
  496. print '<td width="32"></td>';
  497. if (!empty($conf->global->SUPPLIER_ORDER_CAN_UPDATE_BUYINGPRICE_DURING_RECEIPT)) {
  498. if (!isModEnabled("multicurrency") && empty($conf->dynamicprices->enabled)) {
  499. print '<td class="right">'.$langs->trans("Price").'</td>';
  500. print '<td class="right">'.$langs->trans("ReductionShort").' (%)</td>';
  501. print '<td class="right">'.$langs->trans("UpdatePrice").'</td>';
  502. }
  503. }
  504. print '<td align="right">'.$langs->trans("Warehouse");
  505. // Select warehouse to force it everywhere
  506. if (count($listwarehouses) > 1) {
  507. print '<br><span class="opacitymedium">'.$langs->trans("ForceTo").'</span> '.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 1, 0, 0, '', 0, 0, $disabled, '', 'minwidth100 maxwidth300', 1);
  508. } elseif (count($listwarehouses) == 1) {
  509. print '<br><span class="opacitymedium">'.$langs->trans("ForceTo").'</span> '.$form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0, '', 0, 0, $disabled, '', 'minwidth100 maxwidth300', 1);
  510. }
  511. print '</td>';
  512. // Enable hooks to append additional columns
  513. $parameters = array();
  514. $reshook = $hookmanager->executeHooks(
  515. 'printFieldListTitle',
  516. $parameters,
  517. $object,
  518. $action
  519. );
  520. if ($reshook < 0) {
  521. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  522. }
  523. print $hookmanager->resPrint;
  524. print "</tr>\n";
  525. }
  526. $nbfreeproduct = 0; // Nb of lins of free products/services
  527. $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)
  528. // or nb of line that remain to dispatch if SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED is on.
  529. $conf->cache['product'] = array();
  530. while ($i < $num) {
  531. $objp = $db->fetch_object($resql);
  532. // On n'affiche pas les produits libres
  533. if (!$objp->fk_product > 0) {
  534. $nbfreeproduct++;
  535. } else {
  536. $alreadydispatched = isset($products_dispatched[$objp->rowid])?$products_dispatched[$objp->rowid]:0;
  537. $remaintodispatch = price2num($objp->qty, 5); // Calculation of dispatched
  538. if ($remaintodispatch < 0 && empty($conf->global->SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN)) {
  539. $remaintodispatch = 0;
  540. }
  541. if ($remaintodispatch || empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) {
  542. $nbproduct++;
  543. // To show detail cref and description value, we must make calculation by cref
  544. // print ($objp->cref?' ('.$objp->cref.')':'');
  545. // if ($objp->description) print '<br>'.nl2br($objp->description);
  546. $suffix = '_0_'.$i;
  547. print "\n";
  548. print '<!-- Line to dispatch '.$suffix.' -->'."\n";
  549. // hidden fields for js function
  550. print '<input id="qty_ordered'.$suffix.'" type="hidden" value="'.$objp->qty.'">';
  551. print '<input id="qty_dispatched'.$suffix.'" type="hidden" data-dispatched="'.((float) $alreadydispatched).'" value="'.(float) $alreadydispatched.'">';
  552. print '<tr class="oddeven">';
  553. if (empty($conf->cache['product'][$objp->fk_product])) {
  554. $tmpproduct = new Product($db);
  555. $tmpproduct->fetch($objp->fk_product);
  556. $conf->cache['product'][$objp->fk_product] = $tmpproduct;
  557. } else {
  558. $tmpproduct = $conf->cache['product'][$objp->fk_product];
  559. }
  560. $linktoprod = $tmpproduct->getNomUrl(1);
  561. $linktoprod .= ' - '.$objp->label."\n";
  562. if (isModEnabled('productbatch')) {
  563. if ($objp->tobatch) {
  564. // Product
  565. print '<td>';
  566. print $linktoprod;
  567. print "</td>";
  568. print '<td class="dispatch_batch_number"></td>';
  569. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  570. print '<td class="dispatch_dlc"></td>';
  571. }
  572. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  573. print '<td class="dispatch_dluo"></td>';
  574. }
  575. } else {
  576. // Product
  577. print '<td>';
  578. print $linktoprod;
  579. print "</td>";
  580. print '<td class="dispatch_batch_number">';
  581. print '<span class="opacitymedium small">'.$langs->trans("ProductDoesNotUseBatchSerial").'</span>';
  582. print '</td>';
  583. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  584. print '<td class="dispatch_dlc"></td>';
  585. }
  586. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  587. print '<td class="dispatch_dluo"></td>';
  588. }
  589. }
  590. } else {
  591. print '<td colspan="4">';
  592. print $linktoprod;
  593. print "</td>";
  594. }
  595. // Define unit price for PMP calculation
  596. $up_ht_disc = $objp->subprice;
  597. if (!empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) {
  598. $up_ht_disc = price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU');
  599. }
  600. // Qty ordered
  601. print '<td class="right">'.$objp->qty.'</td>';
  602. // Already dispatched
  603. print '<td class="right">'.$alreadydispatched.'</td>';
  604. print '<td class="right">';
  605. print '</td>'; // Qty to dispatch
  606. print '<td>';
  607. print '</td>'; // Dispatch column
  608. print '<td></td>'; // Warehouse column
  609. /*$sql = "SELECT cfd.rowid, cfd.qty, cfd.fk_entrepot, cfd.batch, cfd.eatby, cfd.sellby, cfd.fk_product";
  610. $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd";
  611. $sql .= " WHERE cfd.fk_commandefourndet = ".(int) $objp->rowid;*/
  612. $sql = "SELECT ed.rowid, ed.qty, ed.fk_entrepot, eb.batch, eb.eatby, eb.sellby, cd.fk_product FROM ".MAIN_DB_PREFIX."expeditiondet as ed";
  613. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as eb on ed.rowid = eb.fk_expeditiondet";
  614. $sql .= " JOIN ".MAIN_DB_PREFIX."commandedet as cd on ed.fk_origin_line = cd.rowid";
  615. $sql .= " WHERE ed.fk_origin_line =".(int) $objp->rowid;
  616. $sql .= " AND ed.fk_expedition =".(int) $object->id;
  617. $sql .= " ORDER BY ed.rowid, ed.fk_origin_line";
  618. $resultsql = $db->query($sql);
  619. $j = 0;
  620. if ($resultsql) {
  621. $numd = $db->num_rows($resultsql);
  622. while ($j < $numd) {
  623. $suffix = "_".$j."_".$i;
  624. $objd = $db->fetch_object($resultsql);
  625. if (isModEnabled('productbatch') && !empty($objd->batch)) {
  626. $type = 'batch';
  627. // Enable hooks to append additional columns
  628. $parameters = array(
  629. // allows hook to distinguish between the rows with information and the rows with dispatch form input
  630. 'is_information_row' => true,
  631. 'j' => $j,
  632. 'suffix' => $suffix,
  633. 'objd' => $objd,
  634. );
  635. $reshook = $hookmanager->executeHooks(
  636. 'printFieldListValue',
  637. $parameters,
  638. $object,
  639. $action
  640. );
  641. if ($reshook < 0) {
  642. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  643. }
  644. print $hookmanager->resPrint;
  645. print '</tr>';
  646. print '<!-- line for batch '.$numline.' -->';
  647. print '<tr class="oddeven autoresettr" name="'.$type.$suffix.'" data-remove="clear">';
  648. print '<td>';
  649. print '<input id="fk_commandedet'.$suffix.'" name="fk_commandedet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
  650. print '<input id="idline'.$suffix.'" name="idline'.$suffix.'" type="hidden" value="'.$objd->rowid.'">';
  651. print '<input name="product_batch'.$suffix.'" type="hidden" value="'.$objd->fk_product.'">';
  652. print '<!-- This is a U.P. (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
  653. print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
  654. print '</td>';
  655. print '<td>';
  656. print '<input disabled="" type="text" class="inputlotnumber quatrevingtquinzepercent" id="lot_number'.$suffix.'" name="lot_number'.$suffix.'" value="'.$objd->batch.'">';
  657. //print '<input type="hidden" class="inputlotnumber quatrevingtquinzepercent" id="lot_number'.$suffix.'" name="lot_number'.$suffix.'" value="'.$objd->batch.'">';
  658. print '</td>';
  659. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  660. print '<td class="nowraponall">';
  661. $dlcdatesuffix = !empty($objd->sellby) ? dol_stringtotime($objd->sellby) : dol_mktime(0, 0, 0, GETPOST('dlc'.$suffix.'month'), GETPOST('dlc'.$suffix.'day'), GETPOST('dlc'.$suffix.'year'));
  662. print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, '', '', 1, '');
  663. print '</td>';
  664. }
  665. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  666. print '<td class="nowraponall">';
  667. $dluodatesuffix = !empty($objd->eatby) ? dol_stringtotime($objd->eatby) : dol_mktime(0, 0, 0, GETPOST('dluo'.$suffix.'month'), GETPOST('dluo'.$suffix.'day'), GETPOST('dluo'.$suffix.'year'));
  668. print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, '', '', 1, '');
  669. print '</td>';
  670. }
  671. print '<td colspan="2">&nbsp;</td>'; // Supplier ref + Qty ordered + qty already dispatched
  672. } else {
  673. $type = 'dispatch';
  674. $colspan = 6;
  675. $colspan = (!empty($conf->global->PRODUCT_DISABLE_SELLBY)) ? --$colspan : $colspan;
  676. $colspan = (!empty($conf->global->PRODUCT_DISABLE_EATBY)) ? --$colspan : $colspan;
  677. // Enable hooks to append additional columns
  678. $parameters = array(
  679. // allows hook to distinguish between the rows with information and the rows with dispatch form input
  680. 'is_information_row' => true,
  681. 'j' => $j,
  682. 'suffix' => $suffix,
  683. 'objd' => $objd,
  684. );
  685. $reshook = $hookmanager->executeHooks(
  686. 'printFieldListValue',
  687. $parameters,
  688. $object,
  689. $action
  690. );
  691. if ($reshook < 0) {
  692. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  693. }
  694. print $hookmanager->resPrint;
  695. print '</tr>';
  696. print '<!-- line no batch '.$numline.' -->';
  697. print '<tr class="oddeven autoresettr" name="'.$type.$suffix.'" data-remove="clear">';
  698. print '<td colspan="'.$colspan.'">';
  699. print '<input id="fk_commandedet'.$suffix.'" name="fk_commandedet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
  700. print '<input id="idline'.$suffix.'" name="idline'.$suffix.'" type="hidden" value="'.$objd->rowid.'">';
  701. print '<input name="product'.$suffix.'" type="hidden" value="'.$objd->fk_product.'">';
  702. print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
  703. print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
  704. print '</td>';
  705. }
  706. // Qty to dispatch
  707. print '<td class="right">';
  708. print '<a href="#" id="reset'.$suffix.'" class="resetline">'.img_picto($langs->trans("Reset"), 'eraser', 'class="pictofixedwidth opacitymedium"').'</a>';
  709. print '<input id="qty'.$suffix.'" onchange="onChangeDispatchLineQty($(this))" name="qty'.$suffix.'" data-type="'.$type.'" data-index="'.$i.'" class="width50 right qtydispatchinput" value="'.(GETPOSTISSET('qty'.$suffix) ? GETPOST('qty'.$suffix, 'int') : $objd->qty).'" data-expected="'.$objd->qty.'">';
  710. print '</td>';
  711. print '<td>';
  712. if (isModEnabled('productbatch') && $objp->tobatch > 0) {
  713. $type = 'batch';
  714. print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" '.($numd != $j+1 ? 'style="display:none"' : '').' onClick="addDispatchLine('.$i.', \''.$type.'\')"');
  715. } else {
  716. $type = 'dispatch';
  717. print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" '.($numd != $j+1 ? 'style="display:none"' : '').' onClick="addDispatchLine('.$i.', \''.$type.'\')"');
  718. }
  719. print '</td>';
  720. // Warehouse
  721. print '<td class="right">';
  722. if (count($listwarehouses) > 1) {
  723. print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ?GETPOST("entrepot".$suffix) : $objd->fk_entrepot, "entrepot".$suffix, '', 1, 0, $objp->fk_product, '', 1, 0, null, 'csswarehouse'.$suffix);
  724. } elseif (count($listwarehouses) == 1) {
  725. print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix) ?GETPOST("entrepot".$suffix) : $objd->fk_entrepot, "entrepot".$suffix, '', 0, 0, $objp->fk_product, '', 1, 0, null, 'csswarehouse'.$suffix);
  726. } else {
  727. $langs->load("errors");
  728. print $langs->trans("ErrorNoWarehouseDefined");
  729. }
  730. print "</td>\n";
  731. // Enable hooks to append additional columns
  732. $parameters = array(
  733. 'is_information_row' => false, // this is a dispatch form row
  734. 'i' => $i,
  735. 'suffix' => $suffix,
  736. 'objp' => $objp,
  737. );
  738. $reshook = $hookmanager->executeHooks(
  739. 'printFieldListValue',
  740. $parameters,
  741. $object,
  742. $action
  743. );
  744. if ($reshook < 0) {
  745. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  746. }
  747. print $hookmanager->resPrint;
  748. print "</tr>\n";
  749. $j++;
  750. $numline++;
  751. }
  752. $suffix = "_".$j."_".$i;
  753. }
  754. if ($j == 0) {
  755. if (isModEnabled('productbatch') && !empty($objp->tobatch)) {
  756. $type = 'batch';
  757. // Enable hooks to append additional columns
  758. $parameters = array(
  759. // allows hook to distinguish between the rows with information and the rows with dispatch form input
  760. 'is_information_row' => true,
  761. 'j' => $j,
  762. 'suffix' => $suffix,
  763. 'objp' => $objp,
  764. );
  765. $reshook = $hookmanager->executeHooks(
  766. 'printFieldListValue',
  767. $parameters,
  768. $object,
  769. $action
  770. );
  771. if ($reshook < 0) {
  772. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  773. }
  774. print $hookmanager->resPrint;
  775. print '</tr>';
  776. print '<!-- line for batch '.$numline.' (not dispatched line yet for this order line) -->';
  777. print '<tr class="oddeven autoresettr" name="'.$type.$suffix.'">';
  778. print '<td>';
  779. print '<input id="fk_commandedet'.$suffix.'" name="fk_commandedet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
  780. print '<input id="idline'.$suffix.'" name="idline'.$suffix.'" type="hidden" value="-1">';
  781. print '<input name="product_batch'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
  782. print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
  783. print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
  784. print '</td>';
  785. print '<td>';
  786. print '<input type="text" class="inputlotnumber quatrevingtquinzepercent" id="lot_number'.$suffix.'" name="lot_number'.$suffix.'" value="'.GETPOST('lot_number'.$suffix).'">';
  787. print '</td>';
  788. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  789. print '<td class="nowraponall">';
  790. $dlcdatesuffix = dol_mktime(0, 0, 0, GETPOST('dlc'.$suffix.'month'), GETPOST('dlc'.$suffix.'day'), GETPOST('dlc'.$suffix.'year'));
  791. print $form->selectDate($dlcdatesuffix, 'dlc'.$suffix, '', '', 1, '');
  792. print '</td>';
  793. }
  794. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  795. print '<td class="nowraponall">';
  796. $dluodatesuffix = dol_mktime(0, 0, 0, GETPOST('dluo'.$suffix.'month'), GETPOST('dluo'.$suffix.'day'), GETPOST('dluo'.$suffix.'year'));
  797. print $form->selectDate($dluodatesuffix, 'dluo'.$suffix, '', '', 1, '');
  798. print '</td>';
  799. }
  800. print '<td colspan="2">&nbsp;</td>'; // Supplier ref + Qty ordered + qty already dispatched
  801. } else {
  802. $type = 'dispatch';
  803. $colspan = 6;
  804. $colspan = (!empty($conf->global->PRODUCT_DISABLE_SELLBY)) ? --$colspan : $colspan;
  805. $colspan = (!empty($conf->global->PRODUCT_DISABLE_EATBY)) ? --$colspan : $colspan;
  806. // Enable hooks to append additional columns
  807. $parameters = array(
  808. // allows hook to distinguish between the rows with information and the rows with dispatch form input
  809. 'is_information_row' => true,
  810. 'j' => $j,
  811. 'suffix' => $suffix,
  812. 'objp' => $objp,
  813. );
  814. $reshook = $hookmanager->executeHooks(
  815. 'printFieldListValue',
  816. $parameters,
  817. $object,
  818. $action
  819. );
  820. if ($reshook < 0) {
  821. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  822. }
  823. print $hookmanager->resPrint;
  824. print '</tr>';
  825. print '<!-- line no batch '.$numline.' (not dispatched line yet for this order line) -->';
  826. print '<tr class="oddeven autoresettr" name="'.$type.$suffix.'" data-remove="clear">';
  827. print '<td colspan="'.$colspan.'">';
  828. print '<input id="fk_commandedet'.$suffix.'" name="fk_commandedet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
  829. print '<input id="idline'.$suffix.'" name="idline'.$suffix.'" type="hidden" value="-1">';
  830. print '<input name="product'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
  831. print '<!-- This is a up (may include discount or not depending on STOCK_EXCLUDE_DISCOUNT_FOR_PMP. will be used for PMP calculation) -->';
  832. print '<input class="maxwidth75" name="pu'.$suffix.'" type="hidden" value="'.price2num($up_ht_disc, 'MU').'">';
  833. print '</td>';
  834. }
  835. // Qty to dispatch
  836. print '<td class="right">';
  837. print '<a href="#" id="reset'.$suffix.'" class="resetline">'.img_picto($langs->trans("Reset"), 'eraser', 'class="pictofixedwidth opacitymedium"').'</a>';
  838. print '<input id="qty'.$suffix.'" onchange="onChangeDispatchLineQty($(this))" name="qty'.$suffix.'" data-index="'.$i.'" data-type="text" class="width50 right qtydispatchinput" value="'.(GETPOSTISSET('qty'.$suffix) ? GETPOST('qty'.$suffix, 'int') : (empty($conf->global->SUPPLIER_ORDER_DISPATCH_FORCE_QTY_INPUT_TO_ZERO) ? $remaintodispatch : 0)).'" data-expected="'.$remaintodispatch.'">';
  839. print '</td>';
  840. print '<td>';
  841. if (isModEnabled('productbatch') && $objp->tobatch > 0) {
  842. $type = 'batch';
  843. print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"');
  844. } else {
  845. $type = 'dispatch';
  846. print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$i.', \''.$type.'\')"');
  847. }
  848. print '</td>';
  849. // Warehouse
  850. print '<td class="right">';
  851. if (count($listwarehouses) > 1) {
  852. 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);
  853. } elseif (count($listwarehouses) == 1) {
  854. 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);
  855. } else {
  856. $langs->load("errors");
  857. print $langs->trans("ErrorNoWarehouseDefined");
  858. }
  859. print "</td>\n";
  860. // Enable hooks to append additional columns
  861. $parameters = array(
  862. 'is_information_row' => false, // this is a dispatch form row
  863. 'i' => $i,
  864. 'suffix' => $suffix,
  865. 'objp' => $objp,
  866. );
  867. $reshook = $hookmanager->executeHooks(
  868. 'printFieldListValue',
  869. $parameters,
  870. $object,
  871. $action
  872. );
  873. if ($reshook < 0) {
  874. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  875. }
  876. print $hookmanager->resPrint;
  877. print "</tr>\n";
  878. }
  879. }
  880. }
  881. $i++;
  882. }
  883. $db->free($resql);
  884. } else {
  885. dol_print_error($db);
  886. }
  887. print "</table>\n";
  888. print '</div>';
  889. if ($nbproduct) {
  890. $checkboxlabel = $langs->trans("CloseReceivedSupplierOrdersAutomatically", $langs->transnoentitiesnoconv('StatusOrderReceivedAll'));
  891. print '<div class="center">';
  892. $parameters = array();
  893. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  894. // modified by hook
  895. if (empty($reshook)) {
  896. if (empty($conf->reception->enabled)) {
  897. print $langs->trans("Comment").' : ';
  898. print '<input type="text" class="minwidth400" maxlength="128" name="comment" value="';
  899. print GETPOSTISSET("comment") ? GETPOST("comment") : $langs->trans("DispatchSupplierOrder", $object->ref);
  900. // print ' / '.$object->ref_supplier; // Not yet available
  901. print '" class="flat"><br>';
  902. print '<input type="checkbox" checked="checked" name="closeopenorder"> '.$checkboxlabel;
  903. }
  904. $dispatchBt = empty($conf->reception->enabled) ? $langs->trans("Receive") : $langs->trans("CreateReception");
  905. print '<br>';
  906. print '<input type="submit" id="submitform" class="button" name="dispatch" value="'.$langs->trans("Save").'"';
  907. $disabled = 0;
  908. if (!$usercancreate) {
  909. $disabled = 1;
  910. }
  911. if (count($listwarehouses) <= 0) {
  912. $disabled = 1;
  913. }
  914. if ($disabled) {
  915. print ' disabled';
  916. }
  917. print '>';
  918. }
  919. print '</div>';
  920. }
  921. // Message if nothing to dispatch
  922. if (!$nbproduct) {
  923. print "<br>\n";
  924. if (empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) {
  925. print '<div class="opacitymedium">'.$langs->trans("NoPredefinedProductToDispatch").'</div>'; // No predefined line at all
  926. } else {
  927. print '<div class="opacitymedium">'.$langs->trans("NoMorePredefinedProductToDispatch").'</div>'; // No predefined line that remain to be dispatched.
  928. }
  929. }
  930. print '</form>';
  931. }
  932. print dol_get_fiche_end();
  933. // traitement entrepot par défaut
  934. print '<script type="text/javascript">
  935. $(document).ready(function () {
  936. $("select[name=fk_default_warehouse]").change(function() {
  937. var fk_default_warehouse = $("option:selected", this).val();
  938. $("select[name^=entrepot_]").val(fk_default_warehouse).change();
  939. });
  940. $("#autoreset").click(function() {
  941. $(".autoresettr").each(function(){
  942. id = $(this).attr("name");
  943. idtab = id.split("_");
  944. if ($(this).data("remove") == "clear"){
  945. console.log("We clear the object to expected value")
  946. $("#qty_"+idtab[1]+"_"+idtab[2]).val("");
  947. /*
  948. qtyexpected = $("#qty_"+idtab[1]+"_"+idtab[2]).data("expected")
  949. console.log(qtyexpected);
  950. $("#qty_"+idtab[1]+"_"+idtab[2]).val(qtyexpected);
  951. qtydispatched = $("#qty_dispatched_0_"+idtab[2]).data("dispatched")
  952. $("#qty_dispatched_0_"+idtab[2]).val(qtydispatched);
  953. */
  954. } else {
  955. console.log("We remove the object")
  956. $(this).remove();
  957. $("tr[name^=\'"+idtab[0]+"_\'][name$=\'_"+idtab[2]+"\']:last .splitbutton").show();
  958. }
  959. });
  960. return false;
  961. });
  962. $("#resetalltoexpected").click(function(){
  963. $(".qtydispatchinput").each(function(){
  964. console.log("We reset to expected "+$(this).attr("id")+" qty to dispatch");
  965. $(this).val($(this).data("expected"));
  966. });
  967. return false;
  968. });
  969. $(".resetline").click(function(){
  970. id = $(this).attr("id");
  971. id = id.split("reset_");
  972. console.log("Reset trigger for id = qty_"+id[1]);
  973. $("#qty_"+id[1]).val("");
  974. });
  975. });
  976. </script>';
  977. }
  978. // End of page
  979. llxFooter();
  980. $db->close();