mo_production.php 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  1. <?php
  2. /* Copyright (C) 2019-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  3. /* Copyright (C) 2023 Christian Humpel <christian.humpel@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file mo_production.php
  20. * \ingroup mrp
  21. * \brief Page to make production on a MO
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
  34. dol_include_once('/mrp/class/mo.class.php');
  35. dol_include_once('/bom/class/bom.class.php');
  36. dol_include_once('/mrp/lib/mrp_mo.lib.php');
  37. // Load translation files required by the page
  38. $langs->loadLangs(array("mrp", "stocks", "other", "product", "productbatch"));
  39. // Get parameters
  40. $id = GETPOST('id', 'int');
  41. $ref = GETPOST('ref', 'alpha');
  42. $action = GETPOST('action', 'aZ09');
  43. $confirm = GETPOST('confirm', 'alpha');
  44. $cancel = GETPOST('cancel', 'aZ09');
  45. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'mocard'; // To manage different context of search
  46. $backtopage = GETPOST('backtopage', 'alpha');
  47. $lineid = GETPOST('lineid', 'int');
  48. $fk_movement = GETPOST('fk_movement', 'int');
  49. $fk_default_warehouse = GETPOST('fk_default_warehouse', 'int');
  50. $collapse = GETPOST('collapse', 'aZ09comma');
  51. // Initialize technical objects
  52. $object = new Mo($db);
  53. $extrafields = new ExtraFields($db);
  54. $diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
  55. $hookmanager->initHooks(array('mocard', 'globalcard')); // Note that conf->hooks_modules contains array
  56. // Fetch optionals attributes and labels
  57. $extrafields->fetch_name_optionals_label($object->table_element);
  58. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  59. // Initialize array of search criterias
  60. $search_all = GETPOST("search_all", 'alpha');
  61. $search = array();
  62. foreach ($object->fields as $key => $val) {
  63. if (GETPOST('search_'.$key, 'alpha')) {
  64. $search[$key] = GETPOST('search_'.$key, 'alpha');
  65. }
  66. }
  67. if (empty($action) && empty($id) && empty($ref)) {
  68. $action = 'view';
  69. }
  70. // Load object
  71. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  72. // Security check - Protection if external user
  73. //if ($user->socid > 0) accessforbidden();
  74. //if ($user->socid > 0) $socid = $user->socid;
  75. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  76. $result = restrictedArea($user, 'mrp', $object->id, 'mrp_mo', '', 'fk_soc', 'rowid', $isdraft);
  77. $permissionnote = $user->rights->mrp->write; // Used by the include of actions_setnotes.inc.php
  78. $permissiondellink = $user->rights->mrp->write; // Used by the include of actions_dellink.inc.php
  79. $permissiontoadd = $user->rights->mrp->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  80. $permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  81. $upload_dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
  82. $permissiontoproduce = $permissiontoadd;
  83. $permissiontoupdatecost = $user->rights->bom->read; // User who can define cost must have knowledge of pricing
  84. /*
  85. * Actions
  86. */
  87. $parameters = array();
  88. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  89. if ($reshook < 0) {
  90. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  91. }
  92. if (empty($reshook)) {
  93. $error = 0;
  94. $backurlforlist = dol_buildpath('/mrp/mo_list.php', 1);
  95. if (empty($backtopage) || ($cancel && empty($id))) {
  96. //var_dump($backurlforlist);exit;
  97. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  98. $backtopage = $backurlforlist;
  99. } else {
  100. $backtopage = DOL_URL_ROOT.'/mrp/mo_production.php?id='.($id > 0 ? $id : '__ID__');
  101. }
  102. }
  103. $triggermodname = 'MO_MODIFY'; // Name of trigger action code to execute when we modify record
  104. // Actions cancel, add, update, delete or clone
  105. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  106. // Actions when linking object each other
  107. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  108. // Actions when printing a doc from card
  109. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  110. // Actions to send emails
  111. $triggersendname = 'MO_SENTBYMAIL';
  112. $autocopy = 'MAIN_MAIL_AUTOCOPY_MO_TO';
  113. $trackid = 'mo'.$object->id;
  114. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  115. // Action to move up and down lines of object
  116. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
  117. if ($action == 'set_thirdparty' && $permissiontoadd) {
  118. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  119. }
  120. if ($action == 'classin' && $permissiontoadd) {
  121. $object->setProject(GETPOST('projectid', 'int'));
  122. }
  123. if ($action == 'confirm_reopen' && $permissiontoadd) {
  124. $result = $object->setStatut($object::STATUS_INPROGRESS, 0, '', 'MRP_REOPEN');
  125. }
  126. if (($action == 'confirm_addconsumeline' && GETPOST('addconsumelinebutton') && $permissiontoadd)
  127. || ($action == 'confirm_addproduceline' && GETPOST('addproducelinebutton') && $permissiontoadd)) {
  128. $moline = new MoLine($db);
  129. // Line to produce
  130. $moline->fk_mo = $object->id;
  131. $moline->qty = GETPOST('qtytoadd', 'int'); ;
  132. $moline->fk_product = GETPOST('productidtoadd', 'int');
  133. if (GETPOST('addconsumelinebutton')) {
  134. $moline->role = 'toconsume';
  135. } else {
  136. $moline->role = 'toproduce';
  137. }
  138. $moline->origin_type = 'free'; // free consume line
  139. $moline->position = 0;
  140. $resultline = $moline->create($user, false); // Never use triggers here
  141. if ($resultline <= 0) {
  142. $error++;
  143. setEventMessages($moline->error, $molines->errors, 'errors');
  144. }
  145. $action = '';
  146. // Redirect to refresh the tab information
  147. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
  148. }
  149. if (in_array($action, array('confirm_consumeorproduce', 'confirm_consumeandproduceall')) && $permissiontoproduce) {
  150. $stockmove = new MouvementStock($db);
  151. $labelmovement = GETPOST('inventorylabel', 'alphanohtml');
  152. $codemovement = GETPOST('inventorycode', 'alphanohtml');
  153. $db->begin();
  154. $pos = 0;
  155. // Process line to consume
  156. foreach ($object->lines as $line) {
  157. if ($line->role == 'toconsume') {
  158. $tmpproduct = new Product($db);
  159. $tmpproduct->fetch($line->fk_product);
  160. $i = 1;
  161. while (GETPOSTISSET('qty-'.$line->id.'-'.$i)) {
  162. $qtytoprocess = price2num(GETPOST('qty-'.$line->id.'-'.$i));
  163. if ($qtytoprocess != 0) {
  164. // Check warehouse is set if we should have to
  165. if (GETPOSTISSET('idwarehouse-'.$line->id.'-'.$i)) { // If there is a warehouse to set
  166. if (!(GETPOST('idwarehouse-'.$line->id.'-'.$i) > 0)) { // If there is no warehouse set.
  167. $langs->load("errors");
  168. setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref), null, 'errors');
  169. $error++;
  170. }
  171. if ($tmpproduct->status_batch && (!GETPOST('batch-'.$line->id.'-'.$i))) {
  172. $langs->load("errors");
  173. setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref), null, 'errors');
  174. $error++;
  175. }
  176. }
  177. $idstockmove = 0;
  178. if (!$error && GETPOST('idwarehouse-'.$line->id.'-'.$i) > 0) {
  179. // Record stock movement
  180. $id_product_batch = 0;
  181. $stockmove->setOrigin($object->element, $object->id);
  182. if ($qtytoprocess >= 0) {
  183. $idstockmove = $stockmove->livraison($user, $line->fk_product, GETPOST('idwarehouse-'.$line->id.'-'.$i), $qtytoprocess, 0, $labelmovement, dol_now(), '', '', GETPOST('batch-'.$line->id.'-'.$i), $id_product_batch, $codemovement);
  184. } else {
  185. $idstockmove = $stockmove->reception($user, $line->fk_product, GETPOST('idwarehouse-'.$line->id.'-'.$i), $qtytoprocess * -1, 0, $labelmovement, dol_now(), '', '', GETPOST('batch-'.$line->id.'-'.$i), $id_product_batch, $codemovement);
  186. }
  187. if ($idstockmove < 0) {
  188. $error++;
  189. setEventMessages($stockmove->error, $stockmove->errors, 'errors');
  190. }
  191. }
  192. if (!$error) {
  193. // Record consumption
  194. $moline = new MoLine($db);
  195. $moline->fk_mo = $object->id;
  196. $moline->position = $pos;
  197. $moline->fk_product = $line->fk_product;
  198. $moline->fk_warehouse = GETPOST('idwarehouse-'.$line->id.'-'.$i);
  199. $moline->qty = $qtytoprocess;
  200. $moline->batch = GETPOST('batch-'.$line->id.'-'.$i);
  201. $moline->role = 'consumed';
  202. $moline->fk_mrp_production = $line->id;
  203. $moline->fk_stock_movement = $idstockmove == 0 ? null : $idstockmove;
  204. $moline->fk_user_creat = $user->id;
  205. $resultmoline = $moline->create($user);
  206. if ($resultmoline <= 0) {
  207. $error++;
  208. setEventMessages($moline->error, $moline->errors, 'errors');
  209. }
  210. $pos++;
  211. }
  212. }
  213. $i++;
  214. }
  215. }
  216. }
  217. // Process line to produce
  218. $pos = 0;
  219. foreach ($object->lines as $line) {
  220. if ($line->role == 'toproduce') {
  221. $tmpproduct = new Product($db);
  222. $tmpproduct->fetch($line->fk_product);
  223. $i = 1;
  224. while (GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i)) {
  225. $qtytoprocess = price2num(GETPOST('qtytoproduce-'.$line->id.'-'.$i));
  226. $pricetoprocess = GETPOST('pricetoproduce-'.$line->id.'-'.$i) ? price2num(GETPOST('pricetoproduce-'.$line->id.'-'.$i)) : 0;
  227. if ($qtytoprocess != 0) {
  228. // Check warehouse is set if we should have to
  229. if (GETPOSTISSET('idwarehousetoproduce-'.$line->id.'-'.$i)) { // If there is a warehouse to set
  230. if (!(GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) > 0)) { // If there is no warehouse set.
  231. $langs->load("errors");
  232. setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Warehouse"), $tmpproduct->ref), null, 'errors');
  233. $error++;
  234. }
  235. if (isModEnabled('productbatch') && $tmpproduct->status_batch && (!GETPOST('batchtoproduce-'.$line->id.'-'.$i))) {
  236. $langs->load("errors");
  237. setEventMessages($langs->trans("ErrorFieldRequiredForProduct", $langs->transnoentitiesnoconv("Batch"), $tmpproduct->ref), null, 'errors');
  238. $error++;
  239. }
  240. }
  241. $idstockmove = 0;
  242. if (!$error && GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) > 0) {
  243. // Record stock movement
  244. $id_product_batch = 0;
  245. $stockmove->origin_type = $object->element;
  246. $stockmove->origin_id = $object->id;
  247. $idstockmove = $stockmove->reception($user, $line->fk_product, GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i), $qtytoprocess, $pricetoprocess, $labelmovement, '', '', GETPOST('batchtoproduce-'.$line->id.'-'.$i), dol_now(), $id_product_batch, $codemovement);
  248. if ($idstockmove < 0) {
  249. $error++;
  250. setEventMessages($stockmove->error, $stockmove->errors, 'errors');
  251. }
  252. }
  253. if (!$error) {
  254. // Record production
  255. $moline = new MoLine($db);
  256. $moline->fk_mo = $object->id;
  257. $moline->position = $pos;
  258. $moline->fk_product = $line->fk_product;
  259. $moline->fk_warehouse = GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i);
  260. $moline->qty = $qtytoprocess;
  261. $moline->batch = GETPOST('batchtoproduce-'.$line->id.'-'.$i);
  262. $moline->role = 'produced';
  263. $moline->fk_mrp_production = $line->id;
  264. $moline->fk_stock_movement = $idstockmove;
  265. $moline->fk_user_creat = $user->id;
  266. $resultmoline = $moline->create($user);
  267. if ($resultmoline <= 0) {
  268. $error++;
  269. setEventMessages($moline->error, $moline->errors, 'errors');
  270. }
  271. $pos++;
  272. }
  273. }
  274. $i++;
  275. }
  276. }
  277. }
  278. if (!$error) {
  279. $consumptioncomplete = true;
  280. $productioncomplete = true;
  281. if (GETPOST('autoclose', 'int')) {
  282. foreach ($object->lines as $line) {
  283. if ($line->role == 'toconsume') {
  284. $arrayoflines = $object->fetchLinesLinked('consumed', $line->id);
  285. $alreadyconsumed = 0;
  286. foreach ($arrayoflines as $line2) {
  287. $alreadyconsumed += $line2['qty'];
  288. }
  289. if ($alreadyconsumed < $line->qty) {
  290. $consumptioncomplete = false;
  291. }
  292. }
  293. if ($line->role == 'toproduce') {
  294. $arrayoflines = $object->fetchLinesLinked('produced', $line->id);
  295. $alreadyproduced = 0;
  296. foreach ($arrayoflines as $line2) {
  297. $alreadyproduced += $line2['qty'];
  298. }
  299. if ($alreadyproduced < $line->qty) {
  300. $productioncomplete = false;
  301. }
  302. }
  303. }
  304. } else {
  305. $consumptioncomplete = false;
  306. $productioncomplete = false;
  307. }
  308. // Update status of MO
  309. dol_syslog("consumptioncomplete = ".$consumptioncomplete." productioncomplete = ".$productioncomplete);
  310. //var_dump("consumptioncomplete = ".$consumptioncomplete." productioncomplete = ".$productioncomplete);
  311. if ($consumptioncomplete && $productioncomplete) {
  312. $result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
  313. } else {
  314. $result = $object->setStatut($object::STATUS_INPROGRESS, 0, '', 'MRP_MO_PRODUCED');
  315. }
  316. if ($result <= 0) {
  317. $error++;
  318. setEventMessages($object->error, $object->errors, 'errors');
  319. }
  320. }
  321. if ($error) {
  322. $action = str_replace('confirm_', '', $action);
  323. $db->rollback();
  324. } else {
  325. $db->commit();
  326. // Redirect to avoid to action done a second time if we make a back from browser
  327. header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
  328. exit;
  329. }
  330. }
  331. // Action close produced
  332. if ($action == 'confirm_produced' && $confirm == 'yes' && $permissiontoadd) {
  333. $result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
  334. if ($result >= 0) {
  335. // Define output language
  336. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  337. $outputlangs = $langs;
  338. $newlang = '';
  339. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  340. $newlang = GETPOST('lang_id', 'aZ09');
  341. }
  342. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  343. $newlang = $object->thirdparty->default_lang;
  344. }
  345. if (!empty($newlang)) {
  346. $outputlangs = new Translate("", $conf);
  347. $outputlangs->setDefaultLang($newlang);
  348. }
  349. $model = $object->model_pdf;
  350. $ret = $object->fetch($id); // Reload to get new records
  351. $object->generateDocument($model, $outputlangs, 0, 0, 0);
  352. }
  353. } else {
  354. setEventMessages($object->error, $object->errors, 'errors');
  355. }
  356. }
  357. }
  358. /*
  359. * View
  360. */
  361. $form = new Form($db);
  362. $formproject = new FormProjets($db);
  363. $formproduct = new FormProduct($db);
  364. $tmpwarehouse = new Entrepot($db);
  365. $tmpbatch = new Productlot($db);
  366. $tmpstockmovement = new MouvementStock($db);
  367. $help_url = 'EN:Module_Manufacturing_Orders|FR:Module_Ordres_de_Fabrication';
  368. llxHeader('', $langs->trans('Mo'), $help_url, '', 0, 0, array('/mrp/js/lib_dispatch.js.php'));
  369. $newToken = newToken();
  370. // Part to show record
  371. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  372. $res = $object->fetch_thirdparty();
  373. $res = $object->fetch_optionals();
  374. $head = moPrepareHead($object);
  375. print dol_get_fiche_head($head, 'production', $langs->trans("ManufacturingOrder"), -1, $object->picto);
  376. $formconfirm = '';
  377. // Confirmation to delete
  378. if ($action == 'delete') {
  379. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', '', 0, 1);
  380. }
  381. // Confirmation to delete line
  382. if ($action == 'deleteline') {
  383. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid.'&fk_movement='.$fk_movement, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  384. }
  385. // Clone confirmation
  386. if ($action == 'clone') {
  387. // Create an array for form
  388. $formquestion = array();
  389. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  390. }
  391. // Confirmation of validation
  392. if ($action == 'validate') {
  393. // We check that object has a temporary ref
  394. $ref = substr($object->ref, 1, 4);
  395. if ($ref == 'PROV') {
  396. $object->fetch_product();
  397. $numref = $object->getNextNumRef($object->fk_product);
  398. } else {
  399. $numref = $object->ref;
  400. }
  401. $text = $langs->trans('ConfirmValidateMo', $numref);
  402. /*if (isModEnabled('notification'))
  403. {
  404. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  405. $notify = new Notify($db);
  406. $text .= '<br>';
  407. $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
  408. }*/
  409. $formquestion = array();
  410. if (isModEnabled('mrp')) {
  411. $langs->load("mrp");
  412. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  413. $formproduct = new FormProduct($db);
  414. $forcecombo = 0;
  415. if ($conf->browser->name == 'ie') {
  416. $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  417. }
  418. $formquestion = array(
  419. // 'text' => $langs->trans("ConfirmClone"),
  420. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  421. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  422. );
  423. }
  424. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
  425. }
  426. // Call Hook formConfirm
  427. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  428. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  429. if (empty($reshook)) {
  430. $formconfirm .= $hookmanager->resPrint;
  431. } elseif ($reshook > 0) {
  432. $formconfirm = $hookmanager->resPrint;
  433. }
  434. // Print form confirm
  435. print $formconfirm;
  436. // MO file
  437. // ------------------------------------------------------------
  438. $linkback = '<a href="'.DOL_URL_ROOT.'/mrp/mo_list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  439. $morehtmlref = '<div class="refidno">';
  440. /*
  441. // Ref bis
  442. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', 0, 1);
  443. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', null, null, '', 1);*/
  444. // Thirdparty
  445. if (is_object($object->thirdparty)) {
  446. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
  447. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  448. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
  449. }
  450. }
  451. // Project
  452. if (isModEnabled('project')) {
  453. $langs->load("projects");
  454. if (is_object($object->thirdparty)) {
  455. $morehtmlref .= '<br>';
  456. }
  457. if ($permissiontoadd) {
  458. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  459. if ($action != 'classify') {
  460. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  461. }
  462. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  463. } else {
  464. if (!empty($object->fk_project)) {
  465. $proj = new Project($db);
  466. $proj->fetch($object->fk_project);
  467. $morehtmlref .= $proj->getNomUrl(1);
  468. if ($proj->title) {
  469. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  470. }
  471. }
  472. }
  473. }
  474. $morehtmlref .= '</div>';
  475. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  476. print '<div class="fichecenter">';
  477. print '<div class="fichehalfleft">';
  478. print '<div class="underbanner clearboth"></div>';
  479. print '<table class="border centpercent tableforfield">'."\n";
  480. // Common attributes
  481. $keyforbreak = 'fk_warehouse';
  482. unset($object->fields['fk_project']);
  483. unset($object->fields['fk_soc']);
  484. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  485. // Other attributes
  486. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  487. print '</table>';
  488. print '</div>';
  489. print '</div>';
  490. print '<div class="clearboth"></div>';
  491. print dol_get_fiche_end();
  492. if (!in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
  493. print '<div class="tabsAction">';
  494. $parameters = array();
  495. // Note that $action and $object may be modified by hook
  496. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
  497. if (empty($reshook)) {
  498. // Validate
  499. if ($object->status == $object::STATUS_DRAFT) {
  500. if ($permissiontoadd) {
  501. if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
  502. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate&token='.$newToken.'">'.$langs->trans("Validate").'</a>';
  503. } else {
  504. $langs->load("errors");
  505. print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
  506. }
  507. }
  508. }
  509. // Consume or produce
  510. if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
  511. if ($permissiontoproduce) {
  512. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=consumeorproduce&token='.$newToken.'">'.$langs->trans('ConsumeOrProduce').'</a>';
  513. } else {
  514. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('ConsumeOrProduce').'</a>';
  515. }
  516. } elseif ($object->status == Mo::STATUS_DRAFT) {
  517. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ValidateBefore").'">'.$langs->trans('ConsumeOrProduce').'</a>';
  518. }
  519. // ConsumeAndProduceAll
  520. if ($object->status == Mo::STATUS_VALIDATED || $object->status == Mo::STATUS_INPROGRESS) {
  521. if ($permissiontoproduce) {
  522. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=consumeandproduceall&token='.$newToken.'">'.$langs->trans('ConsumeAndProduceAll').'</a>';
  523. } else {
  524. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('ConsumeAndProduceAll').'</a>';
  525. }
  526. } elseif ($object->status == Mo::STATUS_DRAFT) {
  527. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("ValidateBefore").'">'.$langs->trans('ConsumeAndProduceAll').'</a>';
  528. }
  529. // Cancel - Reopen
  530. if ($permissiontoadd) {
  531. if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS) {
  532. $arrayproduced = $object->fetchLinesLinked('produced', 0);
  533. $nbProduced = 0;
  534. foreach ($arrayproduced as $lineproduced) {
  535. $nbProduced += $lineproduced['qty'];
  536. }
  537. if ($nbProduced > 0) { // If production has started, we can close it
  538. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_produced&confirm=yes&token='.$newToken.'">'.$langs->trans("Close").'</a>'."\n";
  539. } else {
  540. print '<a class="butActionRefused" href="#" title="'.$langs->trans("GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv("Production")).'">'.$langs->trans("Close").'</a>'."\n";
  541. }
  542. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_close&confirm=yes&token='.$newToken.'">'.$langs->trans("Cancel").'</a>'."\n";
  543. }
  544. if ($object->status == $object::STATUS_CANCELED) {
  545. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.$newToken.'">'.$langs->trans("Re-Open").'</a>'."\n";
  546. }
  547. if ($object->status == $object::STATUS_PRODUCED) {
  548. if ($permissiontoproduce) {
  549. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&token='.$newToken.'">'.$langs->trans('ReOpen').'</a>';
  550. } else {
  551. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('ReOpen').'</a>';
  552. }
  553. }
  554. }
  555. }
  556. print '</div>';
  557. }
  558. if (in_array($action, array('consumeorproduce', 'consumeandproduceall', 'addconsumeline', 'addproduceline'))) {
  559. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  560. print '<input type="hidden" name="token" value="'.newToken().'">';
  561. print '<input type="hidden" name="action" value="confirm_'.$action.'">';
  562. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  563. print '<input type="hidden" name="id" value="'.$id.'">';
  564. // Note: closing form is add end of page
  565. if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
  566. $defaultstockmovementlabel = GETPOST('inventorylabel', 'alphanohtml') ? GETPOST('inventorylabel', 'alphanohtml') : $langs->trans("ProductionForRef", $object->ref);
  567. $defaultstockmovementcode = GETPOST('inventorycode', 'alphanohtml') ? GETPOST('inventorycode', 'alphanohtml') : dol_print_date(dol_now(), 'dayhourlog');
  568. print '<div class="center'.(in_array($action, array('consumeorproduce', 'consumeandproduceall')) ? ' formconsumeproduce' : '').'">';
  569. print '<div class="opacitymedium hideonsmartphone paddingbottom">'.$langs->trans("ConfirmProductionDesc", $langs->transnoentitiesnoconv("Confirm")).'<br></div>';
  570. print '<span class="fieldrequired">'.$langs->trans("InventoryCode").':</span> <input type="text" class="minwidth200 maxwidth250" name="inventorycode" value="'.$defaultstockmovementcode.'"> &nbsp; ';
  571. print '<span class="clearbothonsmartphone"></span>';
  572. print $langs->trans("MovementLabel").': <input type="text" class="minwidth300" name="inventorylabel" value="'.$defaultstockmovementlabel.'"><br><br>';
  573. print '<input type="checkbox" id="autoclose" name="autoclose" value="1"'.(GETPOSTISSET('inventorylabel') ? (GETPOST('autoclose') ? ' checked="checked"' : '') : ' checked="checked"').'> <label for="autoclose">'.$langs->trans("AutoCloseMO").'</label><br>';
  574. print '<input type="submit" class="button" value="'.$langs->trans("Confirm").'" name="confirm">';
  575. print ' &nbsp; ';
  576. print '<input class="button button-cancel" type="submit" value="'.$langs->trans("Cancel").'" name="cancel">';
  577. print '<br><br>';
  578. print '</div>';
  579. print '<br>';
  580. }
  581. }
  582. /*
  583. * Lines
  584. */
  585. $collapse = 1;
  586. if (!empty($object->table_element_line)) {
  587. // Show object lines
  588. $object->fetchLines();
  589. $bomcost = 0;
  590. if ($object->fk_bom > 0) {
  591. $bom = new Bom($db);
  592. $res = $bom->fetch($object->fk_bom);
  593. if ($res > 0) {
  594. $bom->calculateCosts();
  595. $bomcost = $bom->unit_cost;
  596. }
  597. }
  598. // Lines to consume
  599. print '<div class="fichecenter">';
  600. print '<div class="fichehalfleft">';
  601. print '<div class="clearboth"></div>';
  602. $url = $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addconsumeline&token='.newToken();
  603. $permissiontoaddaconsumeline = $object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED;
  604. $parameters = array('morecss'=>'reposition');
  605. $newcardbutton = '';
  606. if ($action != 'consumeorproduce' && $action != 'consumeandproduceall') {
  607. $newcardbutton = dolGetButtonTitle($langs->trans('AddNewConsumeLines'), '', 'fa fa-plus-circle size15x', $url, '', $permissiontoaddaconsumeline, $parameters);
  608. }
  609. print load_fiche_titre($langs->trans('Consumption'), $newcardbutton, '', 0, '', '', '');
  610. print '<div class="div-table-responsive-no-min">';
  611. print '<table class="noborder noshadow centpercent nobottom">';
  612. print '<tr class="liste_titre">';
  613. print '<td>'.$langs->trans("Product").'</td>';
  614. // Qty
  615. print '<td class="right">'.$langs->trans("Qty").'</td>';
  616. // Cost price
  617. if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
  618. print '<td class="right">'.$langs->trans("UnitCost").'</td>';
  619. }
  620. // Qty already consumed
  621. print '<td class="right">'.$langs->trans("QtyAlreadyConsumed").'</td>';
  622. // Warehouse
  623. print '<td>';
  624. if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
  625. print $langs->trans("Warehouse");
  626. // Select warehouse to force it everywhere
  627. if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
  628. $listwarehouses = $tmpwarehouse->list_array(1);
  629. if (count($listwarehouses) > 1) {
  630. print '<br><span class="opacitymedium">' . $langs->trans("ForceTo") . '</span> ' . $form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth300', 1);
  631. } elseif (count($listwarehouses) == 1) {
  632. print '<br><span class="opacitymedium">' . $langs->trans("ForceTo") . '</span> ' . $form->selectarray('fk_default_warehouse', $listwarehouses, $fk_default_warehouse, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth300', 1);
  633. }
  634. }
  635. }
  636. print '</td>';
  637. if (isModEnabled('stock')) {
  638. // Available
  639. print '<td align="right">';
  640. if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
  641. print $langs->trans("Stock");
  642. }
  643. print '</td>';
  644. }
  645. // Lot - serial
  646. if (isModEnabled('productbatch')) {
  647. print '<td>';
  648. if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
  649. print $langs->trans("Batch");
  650. }
  651. print '</td>';
  652. }
  653. // Action
  654. if ($permissiontodelete) {
  655. print '<td></td>';
  656. }
  657. // Split
  658. print '<td></td>';
  659. // SplitAll
  660. print '<td></td>';
  661. print '</tr>';
  662. if ($action == 'addconsumeline') {
  663. print '<!-- Add line to consume -->'."\n";
  664. print '<tr class="liste_titre">';
  665. print '<td>';
  666. print $form->select_produits('', 'productidtoadd', '', 0, 0, -1, 2, '', 1, array(), 0, '1', 0, 'maxwidth300');
  667. print '</td>';
  668. // Qty
  669. print '<td class="right"><input type="text" name="qtytoadd" value="1" class="width50 right"></td>';
  670. // Cost price
  671. if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
  672. print '<td></td>';
  673. }
  674. // Qty already consumed
  675. print '<td colspan="2">';
  676. // Warehouse
  677. print '<input type="submit" class="button buttongen button-add" name="addconsumelinebutton" value="'.$langs->trans("Add").'">';
  678. print '<input type="submit" class="button buttongen button-cancel" name="canceladdconsumelinebutton" value="'.$langs->trans("Cancel").'">';
  679. print '</td>';
  680. if (isModEnabled('stock')) {
  681. print '<td></td>';
  682. }
  683. // Lot - serial
  684. if (isModEnabled('productbatch')) {
  685. print '<td></td>';
  686. }
  687. // Action
  688. if ($permissiontodelete) {
  689. print '<td></td>';
  690. }
  691. // Split
  692. print '<td></td>';
  693. // SplitAll
  694. print '<td></td>';
  695. print '</tr>';
  696. }
  697. // Lines to consume
  698. $bomcostupdated = 0; // We will recalculate the unitary cost to produce a product using the real "products to consume into MO"
  699. if (!empty($object->lines)) {
  700. $nblinetoconsume = 0;
  701. foreach ($object->lines as $line) {
  702. if ($line->role == 'toconsume') {
  703. $nblinetoconsume++;
  704. }
  705. }
  706. $nblinetoconsumecursor = 0;
  707. foreach ($object->lines as $line) {
  708. if ($line->role == 'toconsume') {
  709. $nblinetoconsumecursor++;
  710. $tmpproduct = new Product($db);
  711. $tmpproduct->fetch($line->fk_product);
  712. $linecost = price2num($tmpproduct->pmp, 'MT');
  713. if ($object->qty > 0) {
  714. // add free consume line cost to $bomcostupdated
  715. $costprice = price2num((!empty($tmpproduct->cost_price)) ? $tmpproduct->cost_price : $tmpproduct->pmp);
  716. if (empty($costprice)) {
  717. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  718. $productFournisseur = new ProductFournisseur($db);
  719. if ($productFournisseur->find_min_price_product_fournisseur($line->fk_product) > 0) {
  720. $costprice = $productFournisseur->fourn_unitprice;
  721. } else {
  722. $costprice = 0;
  723. }
  724. }
  725. $linecost = price2num(($line->qty * $costprice) / $object->qty, 'MT'); // price for line for all quantities
  726. $bomcostupdated += price2num(($line->qty * $costprice) / $object->qty, 'MU'); // same but with full accuracy
  727. }
  728. $bomcostupdated = price2num($bomcostupdated, 'MU');
  729. $arrayoflines = $object->fetchLinesLinked('consumed', $line->id);
  730. $alreadyconsumed = 0;
  731. foreach ($arrayoflines as $line2) {
  732. $alreadyconsumed += $line2['qty'];
  733. }
  734. $suffix = '_'.$line->id;
  735. print '<!-- Line to dispatch '.$suffix.' -->'."\n";
  736. // hidden fields for js function
  737. print '<input id="qty_ordered'.$suffix.'" type="hidden" value="'.$line->qty.'">';
  738. print '<input id="qty_dispatched'.$suffix.'" type="hidden" value="'.$alreadyconsumed.'">';
  739. print '<tr data-line-id="'.$line->id.'">';
  740. // Product
  741. print '<td>'.$tmpproduct->getNomUrl(1);
  742. print '<br><span class="opacitymedium small">'.$tmpproduct->label.'</span>';
  743. print '</td>';
  744. // Qty
  745. print '<td class="right nowraponall">';
  746. $help = ''; $picto = 'help';
  747. if ($line->qty_frozen) {
  748. $help = ($help ? '<br>' : '').'<strong>'.$langs->trans("QuantityFrozen").'</strong>: '.yn(1).' ('.$langs->trans("QuantityConsumedInvariable").')';
  749. print $form->textwithpicto('', $help, -1, 'lock').' ';
  750. }
  751. if ($line->disable_stock_change) {
  752. $help = ($help ? '<br>' : '').'<strong>'.$langs->trans("DisableStockChange").'</strong>: '.yn(1).' ('.(($tmpproduct->type == Product::TYPE_SERVICE && empty($conf->global->STOCK_SUPPORTS_SERVICES)) ? $langs->trans("NoStockChangeOnServices") : $langs->trans("DisableStockChangeHelp")).')';
  753. print $form->textwithpicto('', $help, -1, 'help').' ';
  754. }
  755. print price2num($line->qty, 'MS');
  756. print '</td>';
  757. // Cost price
  758. if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
  759. print '<td class="right nowraponall">';
  760. print price($linecost);
  761. print '</td>';
  762. }
  763. // Already consumed
  764. print '<td class="right">';
  765. if ($alreadyconsumed) {
  766. print '<script>';
  767. print 'jQuery(document).ready(function() {
  768. jQuery("#expandtoproduce'.$line->id.'").click(function() {
  769. console.log("Expand mrp_production line '.$line->id.'");
  770. jQuery(".expanddetail'.$line->id.'").toggle();';
  771. if ($nblinetoconsume == $nblinetoconsumecursor) { // If it is the last line
  772. print 'if (jQuery("#tablelines").hasClass("nobottom")) { jQuery("#tablelines").removeClass("nobottom"); } else { jQuery("#tablelines").addClass("nobottom"); }';
  773. }
  774. print '
  775. });
  776. });';
  777. print '</script>';
  778. if (empty($conf->use_javascript_ajax)) {
  779. print '<a href="'.$_SERVER["PHP_SELF"].'?collapse='.$collapse.','.$line->id.'">';
  780. }
  781. print img_picto($langs->trans("ShowDetails"), "chevron-down", 'id="expandtoproduce'.$line->id.'"');
  782. if (empty($conf->use_javascript_ajax)) {
  783. print '</a>';
  784. }
  785. } else {
  786. if ($nblinetoconsume == $nblinetoconsumecursor) { // If it is the last line
  787. print '<script>jQuery("#tablelines").removeClass("nobottom");</script>';
  788. }
  789. }
  790. print ' '.price2num($alreadyconsumed, 'MS');
  791. print '</td>';
  792. // Warehouse
  793. print '<td>';
  794. print '</td>';
  795. // Stock
  796. if (isModEnabled('stock')) {
  797. print '<td class="nowraponall right">';
  798. if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $tmpproduct->type != PRODUCT::TYPE_SERVICE) {
  799. if (!$line->disable_stock_change && $tmpproduct->stock_reel < ($line->qty - $alreadyconsumed)) {
  800. print img_warning($langs->trans('StockTooLow')) . ' ';
  801. }
  802. print price2num($tmpproduct->stock_reel, 'MS'); // Available
  803. }
  804. print '</td>';
  805. }
  806. // Lot
  807. if (isModEnabled('productbatch')) {
  808. print '<td></td>';
  809. }
  810. // Split
  811. print '<td></td>';
  812. // Split All
  813. print '<td></td>';
  814. // Action delete line
  815. if ($permissiontodelete) {
  816. $href = $_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=deleteline&token='.newToken().'&lineid='.((int) $line->id);
  817. print '<td class="center">';
  818. print '<a class="reposition" href="'.$href.'">';
  819. print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), 'delete');
  820. print '</a>';
  821. print '</td>';
  822. }
  823. print '</tr>';
  824. // Show detailed of already consumed with js code to collapse
  825. foreach ($arrayoflines as $line2) {
  826. print '<tr class="expanddetail'.$line->id.' hideobject opacitylow">';
  827. // Date
  828. print '<td>';
  829. $tmpstockmovement->id = $line2['fk_stock_movement'];
  830. print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?search_ref='.$tmpstockmovement->id.'">'.img_picto($langs->trans("StockMovement"), 'movement', 'class="paddingright"').'</a>';
  831. print dol_print_date($line2['date'], 'dayhour', 'tzuserrel');
  832. print '</td>';
  833. // Already consumed
  834. print '<td></td>';
  835. // Qty
  836. print '<td class="right">'.$line2['qty'].'</td>';
  837. // Cost price
  838. if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
  839. print '<td></td>';
  840. }
  841. // Warehouse
  842. print '<td class="tdoverflowmax150">';
  843. if ($line2['fk_warehouse'] > 0) {
  844. $result = $tmpwarehouse->fetch($line2['fk_warehouse']);
  845. if ($result > 0) {
  846. print $tmpwarehouse->getNomUrl(1);
  847. }
  848. }
  849. print '</td>';
  850. // Stock
  851. if (isModEnabled('stock')) {
  852. print '<td></td>';
  853. }
  854. // Lot Batch
  855. if (isModEnabled('productbatch')) {
  856. print '<td>';
  857. if ($line2['batch'] != '') {
  858. $tmpbatch->fetch(0, $line2['fk_product'], $line2['batch']);
  859. print $tmpbatch->getNomUrl(1);
  860. }
  861. print '</td>';
  862. }
  863. // Split
  864. print '<td></td>';
  865. // Split All
  866. print '<td></td>';
  867. // Action delete line
  868. if ($permissiontodelete) {
  869. $href = $_SERVER["PHP_SELF"].'?id='.((int) $object->id).'&action=deleteline&token='.newToken().'&lineid='.((int) $line2['rowid']).'&fk_movement='.((int) $line2['fk_stock_movement']);
  870. print '<td class="center">';
  871. print '<a class="reposition" href="'.$href.'">';
  872. print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), 'delete');
  873. print '</a>';
  874. print '</td>';
  875. }
  876. print '</tr>';
  877. }
  878. if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
  879. $i = 1;
  880. print '<!-- Enter line to consume -->'."\n";
  881. $maxQty = 1;
  882. print '<tr data-max-qty="'.$maxQty.'" name="batch_'.$line->id.'_'.$i.'">';
  883. // Ref
  884. print '<td><span class="opacitymedium">'.$langs->trans("ToConsume").'</span></td>';
  885. $preselected = (GETPOSTISSET('qty-'.$line->id.'-'.$i) ? GETPOST('qty-'.$line->id.'-'.$i) : max(0, $line->qty - $alreadyconsumed));
  886. if ($action == 'consumeorproduce' && !GETPOSTISSET('qty-'.$line->id.'-'.$i)) {
  887. $preselected = 0;
  888. }
  889. $disable = '';
  890. if (!empty($conf->global->MRP_NEVER_CONSUME_MORE_THAN_EXPECTED) && ($line->qty - $alreadyconsumed) <= 0) {
  891. $disable = 'disabled';
  892. }
  893. // input hidden with fk_product of line
  894. print '<input type="hidden" name="product-'.$line->id.'-'.$i.'" value="'.$line->fk_product.'">';
  895. // Qty
  896. print '<td class="right"><input type="text" class="width50 right" id="qtytoconsume-'.$line->id.'-'.$i.'" name="qty-'.$line->id.'-'.$i.'" value="'.$preselected.'" '.$disable.'></td>';
  897. // Cost
  898. if ($permissiontoupdatecost && !empty($conf->global->MRP_SHOW_COST_FOR_CONSUMPTION)) {
  899. print '<td></td>';
  900. }
  901. // Already consumed
  902. print '<td></td>';
  903. // Warehouse
  904. print '<td>';
  905. if ($tmpproduct->type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  906. if (empty($line->disable_stock_change)) {
  907. $preselected = (GETPOSTISSET('idwarehouse-'.$line->id.'-'.$i) ? GETPOST('idwarehouse-'.$line->id.'-'.$i) : ($tmpproduct->fk_default_warehouse > 0 ? $tmpproduct->fk_default_warehouse : 'ifone'));
  908. print $formproduct->selectWarehouses($preselected, 'idwarehouse-'.$line->id.'-'.$i, '', 1, 0, $line->fk_product, '', 1, 0, null, 'maxwidth200 csswarehouse_'.$line->id.'_'.$i);
  909. } else {
  910. print '<span class="opacitymedium">'.$langs->trans("DisableStockChange").'</span>';
  911. }
  912. } else {
  913. print '<span class="opacitymedium">'.$langs->trans("NoStockChangeOnServices").'</span>';
  914. }
  915. print '</td>';
  916. // Stock
  917. if (isModEnabled('stock')) {
  918. print '<td></td>';
  919. }
  920. // Lot / Batch
  921. if (isModEnabled('productbatch')) {
  922. print '<td class="nowraponall">';
  923. if ($tmpproduct->status_batch) {
  924. $preselected = (GETPOSTISSET('batch-'.$line->id.'-'.$i) ? GETPOST('batch-'.$line->id.'-'.$i) : '');
  925. print '<input type="text" class="width50" name="batch-'.$line->id.'-'.$i.'" value="'.$preselected.'" list="batch-'.$line->id.'-'.$i.'">';
  926. print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 0, $line->fk_product, '', '');
  927. }
  928. print '</td>';
  929. }
  930. // Split
  931. $type = 'batch';
  932. print '<td align="right" class="split">';
  933. print ' '.img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.((int) $line->id).', \''.dol_escape_js($type).'\', \'qtymissingconsume\')"');
  934. print '</td>';
  935. // Split All
  936. print '<td align="right" class="splitall">';
  937. if (($action == 'consumeorproduce' || $action == 'consumeandproduceall') && $tmpproduct->status_batch == 2) {
  938. print img_picto($langs->trans('SplitAllQuantity'), 'split.png', 'class="splitbutton splitallbutton field-error-icon" data-max-qty="1" onClick="addDispatchLine('.$line->id.', \'batch\', \'allmissingconsume\')"');
  939. }
  940. print '</td>';
  941. // Action delete line
  942. if ($permissiontodelete) {
  943. print '<td></td>';
  944. }
  945. print '</tr>';
  946. }
  947. }
  948. }
  949. }
  950. print '</table>';
  951. print '</div>';
  952. // default warehouse processing
  953. print '<script type="text/javascript">
  954. $(document).ready(function () {
  955. $("select[name=fk_default_warehouse]").change(function() {
  956. var fk_default_warehouse = $("option:selected", this).val();
  957. $("select[name^=idwarehouse-]").val(fk_default_warehouse).change();
  958. });
  959. });
  960. </script>';
  961. // Lines to produce
  962. print '</div>';
  963. print '<div class="fichehalfright">';
  964. print '<div class="clearboth"></div>';
  965. $nblinetoproduce = 0;
  966. foreach ($object->lines as $line) {
  967. if ($line->role == 'toproduce') {
  968. $nblinetoproduce++;
  969. }
  970. }
  971. $newcardbutton = '';
  972. $url = $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=addproduceline&token='.newToken();
  973. $permissiontoaddaproductline = $object->status != $object::STATUS_PRODUCED && $object->status != $object::STATUS_CANCELED;
  974. $parameters = array('morecss'=>'reposition');
  975. if ($action != 'consumeorproduce' && $action != 'consumeandproduceall') {
  976. if ($nblinetoproduce == 0 || $object->mrptype == 1) {
  977. $newcardbutton = dolGetButtonTitle($langs->trans('AddNewProduceLines'), '', 'fa fa-plus-circle size15x', $url, '', $permissiontoaddaproductline, $parameters);
  978. }
  979. }
  980. print load_fiche_titre($langs->trans('Production'), $newcardbutton, '', 0, '', '');
  981. print '<div class="div-table-responsive-no-min">';
  982. print '<table id="tablelinestoproduce" class="noborder noshadow nobottom centpercent">';
  983. print '<tr class="liste_titre">';
  984. // Product
  985. print '<td>'.$langs->trans("Product").'</td>';
  986. // Qty
  987. print '<td class="right">'.$langs->trans("Qty").'</td>';
  988. // Cost price
  989. if ($permissiontoupdatecost) {
  990. if (empty($bomcostupdated)) {
  991. print '<td class="right">'.$form->textwithpicto($langs->trans("UnitCost"), $langs->trans("AmountUsedToUpdateWAP")).'</td>';
  992. } else {
  993. print '<td class="right">'.$form->textwithpicto($langs->trans("ManufacturingPrice"), $langs->trans("AmountUsedToUpdateWAP")).'</td>';
  994. }
  995. }
  996. // Already produced
  997. print '<td class="right">'.$langs->trans("QtyAlreadyProduced").'</td>';
  998. // Warehouse
  999. print '<td>';
  1000. if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
  1001. print $langs->trans("Warehouse");
  1002. }
  1003. print '</td>';
  1004. // Lot
  1005. if (isModEnabled('productbatch')) {
  1006. print '<td>';
  1007. if ($collapse || in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
  1008. print $langs->trans("Batch");
  1009. }
  1010. print '</td>';
  1011. // Split
  1012. print '<td></td>';
  1013. // Split All
  1014. print '<td></td>';
  1015. }
  1016. // Action delete
  1017. if ($permissiontodelete) {
  1018. print '<td></td>';
  1019. }
  1020. print '</tr>';
  1021. if ($action == 'addproduceline') {
  1022. print '<!-- Add line to produce -->'."\n";
  1023. print '<tr class="liste_titre">';
  1024. // Product
  1025. print '<td>';
  1026. print $form->select_produits('', 'productidtoadd', '', 0, 0, -1, 2, '', 1, array(), 0, '1', 0, 'maxwidth300');
  1027. print '</td>';
  1028. // Qty
  1029. print '<td class="right"><input type="text" name="qtytoadd" value="1" class="width50 right"></td>';
  1030. // Cost price
  1031. if ($permissiontoupdatecost) {
  1032. print '<td></td>';
  1033. }
  1034. // Action (cost price + already produced)
  1035. print '<td colspan="2">';
  1036. print '<input type="submit" class="button buttongen button-add" name="addproducelinebutton" value="'.$langs->trans("Add").'">';
  1037. print '<input type="submit" class="button buttongen button-cancel" name="canceladdproducelinebutton" value="'.$langs->trans("Cancel").'">';
  1038. print '</td>';
  1039. // Lot - serial
  1040. if (isModEnabled('productbatch')) {
  1041. print '<td></td>';
  1042. // Split
  1043. print '<td></td>';
  1044. // Split All
  1045. print '<td></td>';
  1046. }
  1047. // Action delete
  1048. if ($permissiontodelete) {
  1049. print '<td></td>';
  1050. }
  1051. print '</tr>';
  1052. }
  1053. if (!empty($object->lines)) {
  1054. $nblinetoproduce = 0;
  1055. foreach ($object->lines as $line) {
  1056. if ($line->role == 'toproduce') {
  1057. $nblinetoproduce++;
  1058. }
  1059. }
  1060. $nblinetoproducecursor = 0;
  1061. foreach ($object->lines as $line) {
  1062. if ($line->role == 'toproduce') {
  1063. $i = 1;
  1064. $nblinetoproducecursor++;
  1065. $tmpproduct = new Product($db);
  1066. $tmpproduct->fetch($line->fk_product);
  1067. $arrayoflines = $object->fetchLinesLinked('produced', $line->id);
  1068. $alreadyproduced = 0;
  1069. foreach ($arrayoflines as $line2) {
  1070. $alreadyproduced += $line2['qty'];
  1071. }
  1072. $suffix = '_'.$line->id;
  1073. print '<!-- Line to dispatch '.$suffix.' -->'."\n";
  1074. // hidden fields for js function
  1075. print '<input id="qty_ordered'.$suffix.'" type="hidden" value="'.$line->qty.'">';
  1076. print '<input id="qty_dispatched'.$suffix.'" type="hidden" value="'.$alreadyproduced.'">';
  1077. print '<tr>';
  1078. // Product
  1079. print '<td>'.$tmpproduct->getNomUrl(1);
  1080. print '<br><span class="opacitymedium small">'.$tmpproduct->label.'</span>';
  1081. print '</td>';
  1082. // Qty
  1083. print '<td class="right">'.$line->qty.'</td>';
  1084. // Cost price
  1085. if ($permissiontoupdatecost) {
  1086. // Defined $manufacturingcost
  1087. $manufacturingcost = 0;
  1088. $manufacturingcostsrc = '';
  1089. if ($object->mrptype == 0) { // If MO is a "Manufacture" type (and not "Disassemble")
  1090. $manufacturingcost = $bomcostupdated;
  1091. $manufacturingcostsrc = $langs->trans("CalculatedFromProductsToConsume");
  1092. if (empty($manufacturingcost)) {
  1093. $manufacturingcost = $bomcost;
  1094. $manufacturingcostsrc = $langs->trans("ValueFromBom");
  1095. }
  1096. if (empty($manufacturingcost)) {
  1097. $manufacturingcost = price2num($tmpproduct->cost_price, 'MU');
  1098. $manufacturingcostsrc = $langs->trans("CostPrice");
  1099. }
  1100. if (empty($manufacturingcost)) {
  1101. $manufacturingcost = price2num($tmpproduct->pmp, 'MU');
  1102. $manufacturingcostsrc = $langs->trans("PMPValue");
  1103. }
  1104. }
  1105. print '<td class="right nowraponall" title="'.dol_escape_htmltag($manufacturingcostsrc).'">';
  1106. if ($manufacturingcost) {
  1107. print price($manufacturingcost);
  1108. }
  1109. print '</td>';
  1110. }
  1111. // Already produced
  1112. print '<td class="right nowraponall">';
  1113. if ($alreadyproduced) {
  1114. print '<script>';
  1115. print 'jQuery(document).ready(function() {
  1116. jQuery("#expandtoproduce'.$line->id.'").click(function() {
  1117. console.log("Expand mrp_production line '.$line->id.'");
  1118. jQuery(".expanddetailtoproduce'.$line->id.'").toggle();';
  1119. if ($nblinetoproduce == $nblinetoproducecursor) {
  1120. print 'if (jQuery("#tablelinestoproduce").hasClass("nobottom")) { jQuery("#tablelinestoproduce").removeClass("nobottom"); } else { jQuery("#tablelinestoproduce").addClass("nobottom"); }';
  1121. }
  1122. print '
  1123. });
  1124. });';
  1125. print '</script>';
  1126. if (empty($conf->use_javascript_ajax)) {
  1127. print '<a href="'.$_SERVER["PHP_SELF"].'?collapse='.$collapse.','.$line->id.'">';
  1128. }
  1129. print img_picto($langs->trans("ShowDetails"), "chevron-down", 'id="expandtoproduce'.$line->id.'"');
  1130. if (empty($conf->use_javascript_ajax)) {
  1131. print '</a>';
  1132. }
  1133. }
  1134. print ' '.$alreadyproduced;
  1135. print '</td>';
  1136. // Warehouse
  1137. print '<td>';
  1138. print '</td>';
  1139. // Lot
  1140. if (isModEnabled('productbatch')) {
  1141. print '<td></td>';
  1142. // Split
  1143. print '<td></td>';
  1144. // Split All
  1145. print '<td></td>';
  1146. }
  1147. // Delete
  1148. if ($permissiontodelete) {
  1149. if ($line->origin_type == 'free') {
  1150. $href = $_SERVER["PHP_SELF"];
  1151. $href .= '?id='.$object->id;
  1152. $href .= '&action=deleteline';
  1153. $href .= '&lineid='.$line->id;
  1154. print '<td class="center">';
  1155. print '<a class="reposition" href="'.$href.'">';
  1156. print img_picto($langs->trans('TooltipDeleteAndRevertStockMovement'), "delete");
  1157. print '</a>';
  1158. print '</td>';
  1159. } else {
  1160. print '<td></td>';
  1161. }
  1162. }
  1163. print '</tr>';
  1164. // Show detailed of already consumed with js code to collapse
  1165. foreach ($arrayoflines as $line2) {
  1166. print '<tr class="expanddetailtoproduce'.$line->id.' hideobject opacitylow">';
  1167. // Product
  1168. print '<td>';
  1169. $tmpstockmovement->id = $line2['fk_stock_movement'];
  1170. print '<a href="'.DOL_URL_ROOT.'/product/stock/movement_list.php?search_ref='.$tmpstockmovement->id.'">'.img_picto($langs->trans("StockMovement"), 'movement', 'class="paddingright"').'</a>';
  1171. print dol_print_date($line2['date'], 'dayhour', 'tzuserrel');
  1172. print '</td>';
  1173. // Qty
  1174. print '<td></td>';
  1175. // Cost price
  1176. if ($permissiontoupdatecost) {
  1177. print '<td></td>';
  1178. }
  1179. // Already produced
  1180. print '<td class="right">'.$line2['qty'].'</td>';
  1181. // Warehouse
  1182. print '<td class="tdoverflowmax150">';
  1183. if ($line2['fk_warehouse'] > 0) {
  1184. $result = $tmpwarehouse->fetch($line2['fk_warehouse']);
  1185. if ($result > 0) {
  1186. print $tmpwarehouse->getNomUrl(1);
  1187. }
  1188. }
  1189. print '</td>';
  1190. // Lot
  1191. if (isModEnabled('productbatch')) {
  1192. print '<td>';
  1193. if ($line2['batch'] != '') {
  1194. $tmpbatch->fetch(0, $line2['fk_product'], $line2['batch']);
  1195. print $tmpbatch->getNomUrl(1);
  1196. }
  1197. print '</td>';
  1198. // Split
  1199. print '<td></td>';
  1200. // Split All
  1201. print '<td></td>';
  1202. }
  1203. // Action delete
  1204. if ($permissiontodelete) {
  1205. print '<td></td>';
  1206. }
  1207. print '</tr>';
  1208. }
  1209. if (in_array($action, array('consumeorproduce', 'consumeandproduceall'))) {
  1210. print '<!-- Enter line to produce -->'."\n";
  1211. $maxQty = 1;
  1212. print '<tr data-max-qty="'.$maxQty.'" name="batch_'.$line->id.'_'.$i.'">';
  1213. // Product
  1214. print '<td><span class="opacitymedium">'.$langs->trans("ToProduce").'</span></td>';
  1215. $preselected = (GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i) ? GETPOST('qtytoproduce-'.$line->id.'-'.$i) : max(0, $line->qty - $alreadyproduced));
  1216. if ($action == 'consumeorproduce' && !GETPOSTISSET('qtytoproduce-'.$line->id.'-'.$i)) {
  1217. $preselected = 0;
  1218. }
  1219. // Qty
  1220. print '<td class="right"><input type="text" class="width50 right" id="qtytoproduce-'.$line->id.'-'.$i.'" name="qtytoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
  1221. // Cost
  1222. if ($permissiontoupdatecost) {
  1223. // Defined $manufacturingcost
  1224. $manufacturingcost = 0;
  1225. $manufacturingcostsrc = '';
  1226. if ($object->mrptype == 0) { // If MO is a "Manufacture" type (and not "Disassemble")
  1227. $manufacturingcost = $bomcostupdated;
  1228. $manufacturingcostsrc = $langs->trans("CalculatedFromProductsToConsume");
  1229. if (empty($manufacturingcost)) {
  1230. $manufacturingcost = $bomcost;
  1231. $manufacturingcostsrc = $langs->trans("ValueFromBom");
  1232. }
  1233. if (empty($manufacturingcost)) {
  1234. $manufacturingcost = price2num($tmpproduct->cost_price, 'MU');
  1235. $manufacturingcostsrc = $langs->trans("CostPrice");
  1236. }
  1237. if (empty($manufacturingcost)) {
  1238. $manufacturingcost = price2num($tmpproduct->pmp, 'MU');
  1239. $manufacturingcostsrc = $langs->trans("PMPValue");
  1240. }
  1241. }
  1242. if ($tmpproduct->type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  1243. $preselected = (GETPOSTISSET('pricetoproduce-'.$line->id.'-'.$i) ? GETPOST('pricetoproduce-'.$line->id.'-'.$i) : ($manufacturingcost ? price($manufacturingcost) : ''));
  1244. print '<td class="right"><input type="text" class="width75 right" name="pricetoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'"></td>';
  1245. } else {
  1246. print '<td><input type="hidden" class="width50 right" name="pricetoproduce-'.$line->id.'-'.$i.'" value="'.($manufacturingcost ? $manufacturingcost : '').'"></td>';
  1247. }
  1248. }
  1249. // Already produced
  1250. print '<td></td>';
  1251. // Warehouse
  1252. print '<td>';
  1253. if ($tmpproduct->type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
  1254. $preselected = (GETPOSTISSET('idwarehousetoproduce-'.$line->id.'-'.$i) ? GETPOST('idwarehousetoproduce-'.$line->id.'-'.$i) : ($object->fk_warehouse > 0 ? $object->fk_warehouse : 'ifone'));
  1255. print $formproduct->selectWarehouses($preselected, 'idwarehousetoproduce-'.$line->id.'-'.$i, '', 1, 0, $line->fk_product, '', 1, 0, null, 'maxwidth200 csswarehouse_'.$line->id.'_'.$i);
  1256. } else {
  1257. print '<span class="opacitymedium">'.$langs->trans("NoStockChangeOnServices").'</span>';
  1258. }
  1259. print '</td>';
  1260. // Lot
  1261. if (isModEnabled('productbatch')) {
  1262. print '<td>';
  1263. if ($tmpproduct->status_batch) {
  1264. $preselected = (GETPOSTISSET('batchtoproduce-'.$line->id.'-'.$i) ? GETPOST('batchtoproduce-'.$line->id.'-'.$i) : '');
  1265. print '<input type="text" class="width50" name="batchtoproduce-'.$line->id.'-'.$i.'" value="'.$preselected.'">';
  1266. }
  1267. print '</td>';
  1268. // Batch number in same column than the stock movement picto
  1269. if ($tmpproduct->status_batch) {
  1270. $type = 'batch';
  1271. print '<td align="right" class="split">';
  1272. print img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'class="splitbutton" onClick="addDispatchLine('.$line->id.', \''.$type.'\', \'qtymissing\')"');
  1273. print '</td>';
  1274. print '<td align="right" class="splitall">';
  1275. if (($action == 'consumeorproduce' || $action == 'consumeandproduceall') && $tmpproduct->status_batch == 2) print img_picto($langs->trans('SplitAllQuantity'), 'split.png', 'class="splitbutton splitallbutton field-error-icon" onClick="addDispatchLine('.$line->id.', \'batch\', \'alltoproduce\')"'); //
  1276. print '</td>';
  1277. } else {
  1278. print '<td></td>';
  1279. print '<td></td>';
  1280. }
  1281. }
  1282. // Action delete
  1283. print '<td></td>';
  1284. print '</tr>';
  1285. }
  1286. }
  1287. }
  1288. }
  1289. print '</table>';
  1290. print '</div>';
  1291. print '</div>';
  1292. print '</div>';
  1293. }
  1294. if (in_array($action, array('consumeorproduce', 'consumeandproduceall', 'addconsumeline'))) {
  1295. print "</form>\n";
  1296. }
  1297. }
  1298. // End of page
  1299. llxFooter();
  1300. $db->close();