mo_card.php 27 KB

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