mo_card.php 27 KB

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