mo_card.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  1. <?php
  2. /* Copyright (C) 2017-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/mrp/mo_card.php
  19. * \ingroup mrp
  20. * \brief Page to create/edit/view MO Manufacturing Order
  21. */
  22. // Load Dolibarr environment
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php';
  32. if (isModEnabled('workstation')) {
  33. require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
  34. }
  35. // Load translation files required by the page
  36. $langs->loadLangs(array('mrp', 'other'));
  37. // Get parameters
  38. $id = GETPOST('id', 'int');
  39. $ref = GETPOST('ref', 'alpha');
  40. $action = GETPOST('action', 'aZ09');
  41. $confirm = GETPOST('confirm', 'alpha');
  42. $cancel = GETPOST('cancel', 'aZ09');
  43. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'mocard'; // To manage different context of search
  44. $backtopage = GETPOST('backtopage', 'alpha');
  45. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  46. $TBomLineId = GETPOST('bomlineid', 'array');
  47. $lineid = GETPOST('lineid', 'int');
  48. $socid = GETPOST("socid", 'int');
  49. // Initialize technical objects
  50. $object = new Mo($db);
  51. $objectbom = new BOM($db);
  52. $extrafields = new ExtraFields($db);
  53. $diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
  54. $hookmanager->initHooks(array('mocard', 'globalcard')); // Note that conf->hooks_modules contains array
  55. // Fetch optionals attributes and labels
  56. $extrafields->fetch_name_optionals_label($object->table_element);
  57. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  58. // Initialize array of search criterias
  59. $search_all = GETPOST("search_all", 'alpha');
  60. $search = array();
  61. foreach ($object->fields as $key => $val) {
  62. if (GETPOST('search_'.$key, 'alpha')) {
  63. $search[$key] = GETPOST('search_'.$key, 'alpha');
  64. }
  65. }
  66. if (empty($action) && empty($id) && empty($ref)) {
  67. $action = 'view';
  68. }
  69. // Load object
  70. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  71. if (GETPOST('fk_bom', 'int') > 0) {
  72. $objectbom->fetch(GETPOST('fk_bom', 'int'));
  73. if ($action != 'add') {
  74. // We force calling parameters if we are not in the submit of creation of MO
  75. $_POST['fk_product'] = $objectbom->fk_product;
  76. $_POST['qty'] = $objectbom->qty;
  77. $_POST['mrptype'] = $objectbom->bomtype;
  78. $_POST['fk_warehouse'] = $objectbom->fk_warehouse;
  79. $_POST['note_private'] = $objectbom->note_private;
  80. }
  81. }
  82. // Security check - Protection if external user
  83. //if ($user->socid > 0) accessforbidden();
  84. //if ($user->socid > 0) $socid = $user->socid;
  85. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  86. $result = restrictedArea($user, 'mrp', $object->id, 'mrp_mo', '', 'fk_soc', 'rowid', $isdraft);
  87. // Permissions
  88. $permissionnote = $user->rights->mrp->write; // Used by the include of actions_setnotes.inc.php
  89. $permissiondellink = $user->rights->mrp->write; // Used by the include of actions_dellink.inc.php
  90. $permissiontoadd = $user->rights->mrp->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  91. $permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  92. $upload_dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
  93. /*
  94. * Actions
  95. */
  96. $parameters = array();
  97. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  98. if ($reshook < 0) {
  99. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  100. }
  101. if (empty($reshook)) {
  102. $error = 0;
  103. $backurlforlist = dol_buildpath('/mrp/mo_list.php', 1);
  104. $object->oldQty = $object->qty;
  105. if (empty($backtopage) || ($cancel && empty($id))) {
  106. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  107. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  108. $backtopage = $backurlforlist;
  109. } else {
  110. $backtopage = DOL_URL_ROOT.'/mrp/mo_card.php?id='.($id > 0 ? $id : '__ID__');
  111. }
  112. }
  113. }
  114. if ($cancel && !empty($backtopageforcancel)) {
  115. $backtopage = $backtopageforcancel;
  116. }
  117. $triggermodname = 'MO_MODIFY'; // Name of trigger action code to execute when we modify record
  118. // Create MO with Childs
  119. if ($action == 'add' && empty($id) && !empty($TBomLineId)) {
  120. $noback = 1;
  121. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  122. $mo_parent = $object;
  123. $moline = new MoLine($db);
  124. $objectbomchildline = new BOMLine($db);
  125. foreach ($TBomLineId as $id_bom_line) {
  126. $object = new Mo($db); // modified by the actions_addupdatedelete.inc.php
  127. $objectbomchildline->fetch($id_bom_line);
  128. $TMoLines = $moline->fetchAll('DESC', 'rowid', '1', '', array('origin_id' => $id_bom_line));
  129. foreach ($TMoLines as $tmpmoline) {
  130. $_POST['fk_bom'] = $objectbomchildline->fk_bom_child;
  131. $_POST['fk_parent_line'] = $tmpmoline->id;
  132. $_POST['qty'] = $tmpmoline->qty;
  133. $_POST['fk_product'] = $tmpmoline->fk_product;
  134. }
  135. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  136. $res = $object->add_object_linked('mo', $mo_parent->id);
  137. }
  138. header("Location: ".dol_buildpath('/mrp/mo_card.php?id='.((int) $mo_parent->id), 1));
  139. exit;
  140. } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && !empty($permissiontoadd)) {
  141. $also_cancel_consumed_and_produced_lines = (GETPOST('alsoCancelConsumedAndProducedLines', 'alpha') ? 1 : 0);
  142. $result = $object->cancel($user, 0, $also_cancel_consumed_and_produced_lines);
  143. if ($result > 0) {
  144. header("Location: " . dol_buildpath('/mrp/mo_card.php?id=' . $object->id, 1));
  145. exit;
  146. } else {
  147. $action = '';
  148. setEventMessages($object->error, $object->errors, 'errors');
  149. }
  150. } elseif ($action == 'confirm_delete' && $confirm == 'yes' && !empty($permissiontodelete)) {
  151. $also_cancel_consumed_and_produced_lines = (GETPOST('alsoCancelConsumedAndProducedLines', 'alpha') ? 1 : 0);
  152. $result = $object->delete($user, 0, $also_cancel_consumed_and_produced_lines);
  153. if ($result > 0) {
  154. header("Location: " . $backurlforlist);
  155. exit;
  156. } else {
  157. $action = '';
  158. setEventMessages($object->error, $object->errors, 'errors');
  159. }
  160. }
  161. if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
  162. if (!($object->id > 0)) {
  163. dol_print_error('', 'Error, object must be fetched before being deleted');
  164. exit;
  165. }
  166. $error = 0;
  167. $deleteChilds = GETPOST('deletechilds', 'boolean');
  168. // Start the database transaction
  169. $db->begin();
  170. if ($deleteChilds === 'on') {
  171. $TMoChildren = $object->getAllMoChilds();
  172. foreach ($TMoChildren as $id => $childObject) {
  173. if ($childObject->delete($user) == -1) {
  174. $error++;
  175. if (!empty($childObject->errors)) {
  176. setEventMessages(null, $childObject->errors, 'errors');
  177. } else {
  178. setEventMessages($childObject->error, null, 'errors');
  179. }
  180. }
  181. }
  182. }
  183. if (!$error) {
  184. $result = $object->delete($user);
  185. if ($result > 0) {
  186. setEventMessages("RecordDeleted", null, 'mesgs');
  187. if ($deleteChilds === 'on') {
  188. setEventMessages("MoChildsDeleted", null, 'mesgs');
  189. }
  190. if (empty($noback)) {
  191. header("Location: " . $backurlforlist);
  192. exit;
  193. }
  194. } else {
  195. $error++;
  196. if (!empty($object->errors)) {
  197. setEventMessages(null, $object->errors, 'errors');
  198. } else {
  199. setEventMessages($object->error, null, 'errors');
  200. }
  201. }
  202. }
  203. // Commit or rollback the database transaction based on whether there was an error
  204. if ($error) {
  205. $db->rollback();
  206. } else {
  207. $db->commit();
  208. }
  209. }
  210. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  211. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  212. // Actions when linking object each other
  213. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  214. // Actions when printing a doc from card
  215. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  216. // Action to build doc
  217. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  218. if ($action == 'set_thirdparty' && $permissiontoadd) {
  219. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  220. }
  221. if ($action == 'classin' && $permissiontoadd) {
  222. $object->setProject(GETPOST('projectid', 'int'));
  223. }
  224. // Actions to send emails
  225. $triggersendname = 'MO_SENTBYMAIL';
  226. $autocopy = 'MAIN_MAIL_AUTOCOPY_MO_TO';
  227. $trackid = 'mo'.$object->id;
  228. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  229. // Action to move up and down lines of object
  230. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
  231. // Action close produced
  232. if ($action == 'confirm_produced' && $confirm == 'yes' && $permissiontoadd) {
  233. $result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
  234. if ($result >= 0) {
  235. // Define output language
  236. if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
  237. $outputlangs = $langs;
  238. $newlang = '';
  239. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  240. $newlang = GETPOST('lang_id', 'aZ09');
  241. }
  242. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  243. $newlang = $object->thirdparty->default_lang;
  244. }
  245. if (!empty($newlang)) {
  246. $outputlangs = new Translate("", $conf);
  247. $outputlangs->setDefaultLang($newlang);
  248. }
  249. $model = $object->model_pdf;
  250. $ret = $object->fetch($id); // Reload to get new records
  251. $object->generateDocument($model, $outputlangs, 0, 0, 0);
  252. }
  253. } else {
  254. setEventMessages($object->error, $object->errors, 'errors');
  255. }
  256. }
  257. }
  258. /*
  259. * View
  260. */
  261. $form = new Form($db);
  262. $formfile = new FormFile($db);
  263. $formproject = new FormProjets($db);
  264. $title = $langs->trans('ManufacturingOrder')." - ".$langs->trans("Card");
  265. llxHeader('', $title, '');
  266. // Part to create
  267. if ($action == 'create') {
  268. if (GETPOST('fk_bom', 'int') > 0) {
  269. $titlelist = $langs->trans("ToConsume");
  270. if ($objectbom->bomtype == 1) {
  271. $titlelist = $langs->trans("ToObtain");
  272. }
  273. }
  274. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Mo")), '', 'mrp');
  275. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  276. print '<input type="hidden" name="token" value="'.newToken().'">';
  277. print '<input type="hidden" name="action" value="add">';
  278. if ($backtopage) {
  279. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  280. }
  281. if ($backtopageforcancel) {
  282. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  283. }
  284. print dol_get_fiche_head(array(), '');
  285. print '<table class="border centpercent tableforfieldcreate">'."\n";
  286. // Common attributes
  287. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  288. // Other attributes
  289. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  290. print '</table>'."\n";
  291. print dol_get_fiche_end();
  292. mrpCollapseBomManagement(); ?>
  293. <script>
  294. $(document).ready(function () {
  295. jQuery('#fk_bom').change(function() {
  296. console.log('We change value of BOM with BOM of id '+jQuery('#fk_bom').val());
  297. if (jQuery('#fk_bom').val() > 0)
  298. {
  299. // Redirect to page with fk_bom set
  300. window.location.href = '<?php echo $_SERVER["PHP_SELF"] ?>?action=create&token=<?php echo newToken(); ?>&fk_bom='+jQuery('#fk_bom').val();
  301. /*
  302. $.getJSON('<?php echo DOL_URL_ROOT ?>/mrp/ajax/ajax_bom.php?action=getBoms&idbom='+jQuery('#fk_bom').val(), function(data) {
  303. console.log(data);
  304. if (typeof data.rowid != "undefined") {
  305. console.log("New BOM loaded, we set values in form");
  306. console.log(data);
  307. $('#qty').val(data.qty);
  308. $("#mrptype").val(data.bomtype); // We set bomtype into mrptype
  309. $('#mrptype').trigger('change'); // Notify any JS components that the value changed
  310. $("#fk_product").val(data.fk_product);
  311. $('#fk_product').trigger('change'); // Notify any JS components that the value changed
  312. $('#note_private').val(data.description);
  313. $('#note_private').trigger('change'); // Notify any JS components that the value changed
  314. $('#fk_warehouse').val(data.fk_warehouse);
  315. $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
  316. if (typeof CKEDITOR != "undefined") {
  317. if (typeof CKEDITOR.instances != "undefined") {
  318. if (typeof CKEDITOR.instances.note_private != "undefined") {
  319. console.log(CKEDITOR.instances.note_private);
  320. CKEDITOR.instances.note_private.setData(data.description);
  321. }
  322. }
  323. }
  324. } else {
  325. console.log("Failed to get BOM");
  326. }
  327. });*/
  328. }
  329. else if (jQuery('#fk_bom').val() < 0) {
  330. // Redirect to page with all fields defined except fk_bom set
  331. console.log(jQuery('#fk_product').val());
  332. window.location.href = '<?php echo $_SERVER["PHP_SELF"] ?>?action=create&token=<?php echo newToken(); ?>&qty='+jQuery('#qty').val()+'&mrptype='+jQuery('#mrptype').val()+'&fk_product='+jQuery('#fk_product').val()+'&label='+jQuery('#label').val()+'&fk_project='+jQuery('#fk_project').val()+'&fk_warehouse='+jQuery('#fk_warehouse').val();
  333. /*
  334. $('#qty').val('');
  335. $("#fk_product").val('');
  336. $('#fk_product').trigger('change'); // Notify any JS components that the value changed
  337. $('#note_private').val('');
  338. $('#note_private').trigger('change'); // Notify any JS components that the value changed
  339. $('#fk_warehouse').val('');
  340. $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
  341. */
  342. }
  343. });
  344. //jQuery('#fk_bom').trigger('change');
  345. })
  346. </script>
  347. <?php
  348. print $form->buttonsSaveCancel("Create");
  349. if ($objectbom->id > 0) {
  350. print load_fiche_titre($titlelist);
  351. print '<!-- list of product/services to consume -->'."\n";
  352. print '<div class="div-table-responsive-no-min">';
  353. print '<table class="noborder centpercent">';
  354. $object->lines = $objectbom->lines;
  355. $object->mrptype = $objectbom->bomtype;
  356. $object->bom = $objectbom;
  357. $object->printOriginLinesList('', array());
  358. print '</table>';
  359. print '</div>';
  360. }
  361. print '</form>';
  362. }
  363. // Part to edit record
  364. if (($id || $ref) && $action == 'edit') {
  365. print load_fiche_titre($langs->trans("ManufacturingOrder"), '', 'mrp');
  366. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  367. print '<input type="hidden" name="token" value="'.newToken().'">';
  368. print '<input type="hidden" name="action" value="update">';
  369. print '<input type="hidden" name="id" value="'.$object->id.'">';
  370. if ($backtopage) {
  371. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  372. }
  373. if ($backtopageforcancel) {
  374. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  375. }
  376. print dol_get_fiche_head();
  377. $object->fields['fk_bom']['disabled'] = 1;
  378. print '<table class="border centpercent tableforfieldedit">'."\n";
  379. // Common attributes
  380. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  381. // Other attributes
  382. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  383. print '</table>';
  384. print dol_get_fiche_end();
  385. print $form->buttonsSaveCancel();
  386. print '</form>';
  387. }
  388. // Part to show record
  389. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  390. $res = $object->fetch_thirdparty();
  391. $head = moPrepareHead($object);
  392. print dol_get_fiche_head($head, 'card', $langs->trans("ManufacturingOrder"), -1, $object->picto);
  393. $formconfirm = '';
  394. // Confirmation to delete
  395. if ($action == 'delete') {
  396. $numberofmochilds = count($object->getAllMoChilds());
  397. if ($numberofmochilds > 0) {
  398. $label = $langs->trans("DeleteMoChild", '('.strval($numberofmochilds).')');
  399. } else {
  400. $label = $langs->trans("DeleteMoChild");
  401. }
  402. $formquestion = array(
  403. array('type' => 'checkbox', 'name' => 'deletechilds', 'label' => $label, 'value' => 0),
  404. array(
  405. 'label' => $langs->trans('MoCancelConsumedAndProducedLines'),
  406. 'name' => 'alsoCancelConsumedAndProducedLines',
  407. 'type' => 'checkbox',
  408. 'value' => !getDolGlobalString('MO_ALSO_CANCEL_CONSUMED_AND_PRODUCED_LINES_BY_DEFAULT') ? 0 : 1
  409. )
  410. );
  411. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', $formquestion, 0, 1);
  412. }
  413. // Confirmation to delete line
  414. if ($action == 'deleteline') {
  415. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  416. }
  417. // Confirmation of validation
  418. if ($action == 'validate') {
  419. // We check that object has a temporary ref
  420. $ref = substr($object->ref, 1, 4);
  421. if ($ref == 'PROV') {
  422. $object->fetch_product();
  423. $numref = $object->getNextNumRef($object->product);
  424. } else {
  425. $numref = $object->ref;
  426. }
  427. $text = $langs->trans('ConfirmValidateMo', $numref);
  428. /*if (isModEnabled('notification'))
  429. {
  430. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  431. $notify = new Notify($db);
  432. $text .= '<br>';
  433. $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
  434. }*/
  435. $formquestion = array();
  436. if (isModEnabled('mrp')) {
  437. $langs->load("mrp");
  438. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  439. $formproduct = new FormProduct($db);
  440. $forcecombo = 0;
  441. if ($conf->browser->name == 'ie') {
  442. $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  443. }
  444. $formquestion = array(
  445. // 'text' => $langs->trans("ConfirmClone"),
  446. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  447. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  448. );
  449. }
  450. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
  451. }
  452. // Confirmation to cancel
  453. if ($action == 'cancel') {
  454. $formquestion = array(
  455. array(
  456. 'label' => $langs->trans('MoCancelConsumedAndProducedLines'),
  457. 'name' => 'alsoCancelConsumedAndProducedLines',
  458. 'type' => 'checkbox',
  459. 'value' => 0
  460. ),
  461. );
  462. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CancelMo'), $langs->trans('ConfirmCancelMo'), 'confirm_cancel', $formquestion, 0, 1);
  463. }
  464. // Clone confirmation
  465. if ($action == 'clone') {
  466. // Create an array for form
  467. $formquestion = array();
  468. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  469. }
  470. // Call Hook formConfirm
  471. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  472. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  473. if (empty($reshook)) {
  474. $formconfirm .= $hookmanager->resPrint;
  475. } elseif ($reshook > 0) {
  476. $formconfirm = $hookmanager->resPrint;
  477. }
  478. // Print form confirm
  479. print $formconfirm;
  480. // Object card
  481. // ------------------------------------------------------------
  482. $linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  483. $morehtmlref = '<div class="refidno">';
  484. /*
  485. // Ref bis
  486. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', 0, 1);
  487. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', null, null, '', 1);*/
  488. // Thirdparty
  489. if (is_object($object->thirdparty)) {
  490. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
  491. if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
  492. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
  493. }
  494. }
  495. // Project
  496. if (isModEnabled('project')) {
  497. $langs->load("projects");
  498. if (is_object($object->thirdparty)) {
  499. $morehtmlref .= '<br>';
  500. }
  501. if ($permissiontoadd) {
  502. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  503. if ($action != 'classify') {
  504. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  505. }
  506. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  507. } else {
  508. if (!empty($object->fk_project)) {
  509. $proj = new Project($db);
  510. $proj->fetch($object->fk_project);
  511. $morehtmlref .= $proj->getNomUrl(1);
  512. if ($proj->title) {
  513. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  514. }
  515. }
  516. }
  517. }
  518. $morehtmlref .= '</div>';
  519. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  520. print '<div class="fichecenter">';
  521. print '<div class="fichehalfleft">';
  522. print '<div class="underbanner clearboth"></div>';
  523. print '<table class="border centpercent tableforfield">'."\n";
  524. //Mo Parent
  525. $mo_parent = $object->getMoParent();
  526. if (is_object($mo_parent)) {
  527. print '<tr class="field_fk_mo_parent">';
  528. print '<td class="titlefield fieldname_fk_mo_parent">' . $langs->trans('ParentMo') . '</td>';
  529. print '<td class="valuefield fieldname_fk_mo_parent">' .$mo_parent->getNomUrl(1).'</td>';
  530. print '</tr>';
  531. }
  532. // Common attributes
  533. $keyforbreak = 'fk_warehouse';
  534. unset($object->fields['fk_project']);
  535. unset($object->fields['fk_soc']);
  536. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  537. // Other attributes
  538. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  539. print '</table>';
  540. print '</div>';
  541. print '</div>';
  542. print '<div class="clearboth"></div>';
  543. print dol_get_fiche_end();
  544. /*
  545. * Lines
  546. */
  547. if (!empty($object->table_element_line)) {
  548. // Show object lines
  549. //$result = $object->getLinesArray();
  550. $object->fetchLines();
  551. print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
  552. <input type="hidden" name="token" value="' . newToken().'">
  553. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
  554. <input type="hidden" name="mode" value="">
  555. <input type="hidden" name="page_y" value="">
  556. <input type="hidden" name="id" value="' . $object->id.'">
  557. ';
  558. /*if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  559. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  560. }*/
  561. if (!empty($object->lines)) {
  562. print '<div class="div-table-responsive-no-min">';
  563. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  564. print '<tr class="liste_titre">';
  565. print '<td class="liste_titre">'.$langs->trans("Summary").'</td>';
  566. print '<td></td>';
  567. print '</tr>';
  568. print '<tr class="oddeven">';
  569. print '<td>'.$langs->trans("ProductsToConsume").'</td>';
  570. print '<td>';
  571. if (!empty($object->lines)) {
  572. $i = 0;
  573. foreach ($object->lines as $line) {
  574. if ($line->role == 'toconsume') {
  575. if ($i) {
  576. print ', ';
  577. }
  578. $tmpproduct = new Product($db);
  579. $tmpproduct->fetch($line->fk_product);
  580. print $tmpproduct->getNomUrl(1);
  581. $i++;
  582. }
  583. }
  584. }
  585. print '</td>';
  586. print '</tr>';
  587. print '<tr class="oddeven">';
  588. print '<td>'.$langs->trans("ProductsToProduce").'</td>';
  589. print '<td>';
  590. if (!empty($object->lines)) {
  591. $i = 0;
  592. foreach ($object->lines as $line) {
  593. if ($line->role == 'toproduce') {
  594. if ($i) {
  595. print ', ';
  596. }
  597. $tmpproduct = new Product($db);
  598. $tmpproduct->fetch($line->fk_product);
  599. print $tmpproduct->getNomUrl(1);
  600. $i++;
  601. }
  602. }
  603. }
  604. print '</td>';
  605. print '</tr>';
  606. print '</table>';
  607. print '</div>';
  608. }
  609. print "</form>\n";
  610. }
  611. // Buttons for actions
  612. if ($action != 'presend' && $action != 'editline') {
  613. print '<div class="tabsAction">'."\n";
  614. $parameters = array();
  615. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  616. if ($reshook < 0) {
  617. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  618. }
  619. if (empty($reshook)) {
  620. // Send
  621. //if (empty($user->socid)) {
  622. // print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
  623. //}
  624. // Back to draft
  625. if ($object->status == $object::STATUS_VALIDATED) {
  626. if ($permissiontoadd) {
  627. // TODO Add test that production has not started
  628. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken().'">'.$langs->trans("SetToDraft").'</a>';
  629. }
  630. }
  631. // Modify
  632. if ($object->status == $object::STATUS_DRAFT) {
  633. if ($permissiontoadd) {
  634. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
  635. } else {
  636. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
  637. }
  638. }
  639. // Validate
  640. if ($object->status == $object::STATUS_DRAFT) {
  641. if ($permissiontoadd) {
  642. if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
  643. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate">'.$langs->trans("Validate").'</a>';
  644. } else {
  645. $langs->load("errors");
  646. print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
  647. }
  648. }
  649. }
  650. // Clone
  651. if ($permissiontoadd) {
  652. print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : "").'&action=clone&object=mo', 'clone', $permissiontoadd);
  653. }
  654. // Cancel - Reopen
  655. if ($permissiontoadd) {
  656. if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS) {
  657. $arrayproduced = $object->fetchLinesLinked('produced', 0);
  658. $nbProduced = 0;
  659. foreach ($arrayproduced as $lineproduced) {
  660. $nbProduced += $lineproduced['qty'];
  661. }
  662. if ($nbProduced > 0) { // If production has started, we can close it
  663. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_produced&confirm=yes&token='.newToken().'">'.$langs->trans("Close").'</a>'."\n";
  664. } else {
  665. print '<a class="butActionRefused" href="#" title="'.$langs->trans("GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv("Production")).'">'.$langs->trans("Close").'</a>'."\n";
  666. }
  667. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'">'.$langs->trans("Cancel").'</a>'."\n";
  668. }
  669. if ($object->status == $object::STATUS_PRODUCED || $object->status == $object::STATUS_CANCELED) {
  670. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken().'">'.$langs->trans("ReOpen").'</a>'."\n";
  671. }
  672. }
  673. // Delete
  674. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
  675. }
  676. print '</div>'."\n";
  677. }
  678. // Select mail models is same action as presend
  679. if (GETPOST('modelselected')) {
  680. $action = 'presend';
  681. }
  682. if ($action != 'presend') {
  683. print '<div class="fichecenter"><div class="fichehalfleft">';
  684. print '<a name="builddoc"></a>'; // ancre
  685. // Documents
  686. $objref = dol_sanitizeFileName($object->ref);
  687. $relativepath = $objref.'/'.$objref.'.pdf';
  688. $filedir = $conf->mrp->dir_output.'/'.$objref;
  689. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  690. $genallowed = $user->rights->mrp->read; // If you can read, you can build the PDF to read content
  691. $delallowed = $user->hasRight("mrp", "creer"); // If you can create/edit, you can remove a file on card
  692. print $formfile->showdocuments('mrp:mo', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $mysoc->default_lang);
  693. // Show links to link elements
  694. $linktoelem = $form->showLinkToObjectBlock($object, null, array('mo'));
  695. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, false);
  696. print '</div><div class="fichehalfright">';
  697. $MAXEVENT = 10;
  698. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/mrp/mo_agenda.php?id='.$object->id);
  699. // List of actions on element
  700. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  701. $formactions = new FormActions($db);
  702. $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT, '', $morehtmlcenter);
  703. print '</div></div>';
  704. }
  705. //Select mail models is same action as presend
  706. if (GETPOST('modelselected')) {
  707. $action = 'presend';
  708. }
  709. // Presend form
  710. $modelmail = 'mo';
  711. $defaulttopic = 'InformationMessage';
  712. $diroutput = $conf->mrp->dir_output;
  713. $trackid = 'mo'.$object->id;
  714. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  715. }
  716. // End of page
  717. llxFooter();
  718. $db->close();