dispatch.php 47 KB

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