mo_card.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  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. $object->oldQty = $object->qty;
  102. if (empty($backtopage) || ($cancel && empty($id))) {
  103. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  104. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  105. $backtopage = $backurlforlist;
  106. } else {
  107. $backtopage = DOL_URL_ROOT.'/mrp/mo_card.php?id='.($id > 0 ? $id : '__ID__');
  108. }
  109. }
  110. }
  111. if ($cancel && !empty($backtopageforcancel)) {
  112. $backtopage = $backtopageforcancel;
  113. }
  114. $triggermodname = 'MO_MODIFY'; // Name of trigger action code to execute when we modify record
  115. // Create MO with Childs
  116. if ($action == 'add' && empty($id) && !empty($TBomLineId)) {
  117. $noback = 1;
  118. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  119. $mo_parent = $object;
  120. $moline = new MoLine($db);
  121. $objectbomchildline = new BOMLine($db);
  122. foreach ($TBomLineId as $id_bom_line) {
  123. $object = new Mo($db); // modified by the actions_addupdatedelete.inc.php
  124. $objectbomchildline->fetch($id_bom_line);
  125. $TMoLines = $moline->fetchAll('DESC', 'rowid', '1', '', array('origin_id' => $id_bom_line));
  126. foreach ($TMoLines as $tmpmoline) {
  127. $_POST['fk_bom'] = $objectbomchildline->fk_bom_child;
  128. $_POST['fk_parent_line'] = $tmpmoline->id;
  129. $_POST['qty'] = $tmpmoline->qty;
  130. $_POST['fk_product'] = $tmpmoline->fk_product;
  131. }
  132. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  133. $res = $object->add_object_linked('mo', $mo_parent->id);
  134. }
  135. header("Location: ".dol_buildpath('/mrp/mo_card.php?id='.((int) $moline->fk_mo), 1));
  136. exit;
  137. }
  138. // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
  139. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  140. // Actions when linking object each other
  141. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  142. // Actions when printing a doc from card
  143. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  144. // Action to build doc
  145. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  146. if ($action == 'set_thirdparty' && $permissiontoadd) {
  147. $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
  148. }
  149. if ($action == 'classin' && $permissiontoadd) {
  150. $object->setProject(GETPOST('projectid', 'int'));
  151. }
  152. // Actions to send emails
  153. $triggersendname = 'MO_SENTBYMAIL';
  154. $autocopy = 'MAIN_MAIL_AUTOCOPY_MO_TO';
  155. $trackid = 'mo'.$object->id;
  156. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  157. // Action to move up and down lines of object
  158. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
  159. // Action close produced
  160. if ($action == 'confirm_produced' && $confirm == 'yes' && $permissiontoadd) {
  161. $result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
  162. if ($result >= 0) {
  163. // Define output language
  164. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  165. $outputlangs = $langs;
  166. $newlang = '';
  167. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  168. $newlang = GETPOST('lang_id', 'aZ09');
  169. }
  170. if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
  171. $newlang = $object->thirdparty->default_lang;
  172. }
  173. if (!empty($newlang)) {
  174. $outputlangs = new Translate("", $conf);
  175. $outputlangs->setDefaultLang($newlang);
  176. }
  177. $model = $object->model_pdf;
  178. $ret = $object->fetch($id); // Reload to get new records
  179. $object->generateDocument($model, $outputlangs, 0, 0, 0);
  180. }
  181. } else {
  182. setEventMessages($object->error, $object->errors, 'errors');
  183. }
  184. }
  185. }
  186. /*
  187. * View
  188. */
  189. $form = new Form($db);
  190. $formfile = new FormFile($db);
  191. $formproject = new FormProjets($db);
  192. $title = $langs->trans('ManufacturingOrder')." - ".$langs->trans("Card");
  193. llxHeader('', $title, '');
  194. // Part to create
  195. if ($action == 'create') {
  196. if (GETPOST('fk_bom', 'int') > 0) {
  197. $titlelist = $langs->trans("ToConsume");
  198. if ($objectbom->bomtype == 1) {
  199. $titlelist = $langs->trans("ToObtain");
  200. }
  201. }
  202. print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Mo")), '', 'mrp');
  203. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  204. print '<input type="hidden" name="token" value="'.newToken().'">';
  205. print '<input type="hidden" name="action" value="add">';
  206. if ($backtopage) {
  207. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  208. }
  209. if ($backtopageforcancel) {
  210. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  211. }
  212. print dol_get_fiche_head(array(), '');
  213. print '<table class="border centpercent tableforfieldcreate">'."\n";
  214. // Common attributes
  215. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  216. // Other attributes
  217. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  218. print '</table>'."\n";
  219. print dol_get_fiche_end();
  220. mrpCollapseBomManagement();
  221. ?>
  222. <script>
  223. $(document).ready(function () {
  224. jQuery('#fk_bom').change(function() {
  225. console.log('We change value of BOM with BOM of id '+jQuery('#fk_bom').val());
  226. if (jQuery('#fk_bom').val() > 0)
  227. {
  228. // Redirect to page with fk_bom set
  229. window.location.href = '<?php echo $_SERVER["PHP_SELF"] ?>?action=create&token=<?php echo newToken(); ?>&fk_bom='+jQuery('#fk_bom').val();
  230. /*
  231. $.getJSON('<?php echo DOL_URL_ROOT ?>/mrp/ajax/ajax_bom.php?action=getBoms&idbom='+jQuery('#fk_bom').val(), function(data) {
  232. console.log(data);
  233. if (typeof data.rowid != "undefined") {
  234. console.log("New BOM loaded, we set values in form");
  235. console.log(data);
  236. $('#qty').val(data.qty);
  237. $("#mrptype").val(data.bomtype); // We set bomtype into mrptype
  238. $('#mrptype').trigger('change'); // Notify any JS components that the value changed
  239. $("#fk_product").val(data.fk_product);
  240. $('#fk_product').trigger('change'); // Notify any JS components that the value changed
  241. $('#note_private').val(data.description);
  242. $('#note_private').trigger('change'); // Notify any JS components that the value changed
  243. $('#fk_warehouse').val(data.fk_warehouse);
  244. $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
  245. if (typeof CKEDITOR != "undefined") {
  246. if (typeof CKEDITOR.instances != "undefined") {
  247. if (typeof CKEDITOR.instances.note_private != "undefined") {
  248. console.log(CKEDITOR.instances.note_private);
  249. CKEDITOR.instances.note_private.setData(data.description);
  250. }
  251. }
  252. }
  253. } else {
  254. console.log("Failed to get BOM");
  255. }
  256. });*/
  257. }
  258. else if (jQuery('#fk_bom').val() < 0) {
  259. // Redirect to page with all fields defined except fk_bom set
  260. console.log(jQuery('#fk_product').val());
  261. 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();
  262. /*
  263. $('#qty').val('');
  264. $("#fk_product").val('');
  265. $('#fk_product').trigger('change'); // Notify any JS components that the value changed
  266. $('#note_private').val('');
  267. $('#note_private').trigger('change'); // Notify any JS components that the value changed
  268. $('#fk_warehouse').val('');
  269. $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
  270. */
  271. }
  272. });
  273. //jQuery('#fk_bom').trigger('change');
  274. })
  275. </script>
  276. <?php
  277. print $form->buttonsSaveCancel("Create");
  278. if ($objectbom->id > 0) {
  279. print load_fiche_titre($titlelist);
  280. print '<div class="div-table-responsive-no-min">';
  281. print '<table class="noborder centpercent">';
  282. $object->lines = $objectbom->lines;
  283. $object->mrptype = $objectbom->bomtype;
  284. $object->bom = $objectbom;
  285. $object->printOriginLinesList('', array());
  286. print '</table>';
  287. print '</div>';
  288. }
  289. print '</form>';
  290. }
  291. // Part to edit record
  292. if (($id || $ref) && $action == 'edit') {
  293. print load_fiche_titre($langs->trans("ManufacturingOrder"), '', 'mrp');
  294. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  295. print '<input type="hidden" name="token" value="'.newToken().'">';
  296. print '<input type="hidden" name="action" value="update">';
  297. print '<input type="hidden" name="id" value="'.$object->id.'">';
  298. if ($backtopage) {
  299. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  300. }
  301. if ($backtopageforcancel) {
  302. print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
  303. }
  304. print dol_get_fiche_head();
  305. $object->fields['fk_bom']['disabled'] = 1;
  306. print '<table class="border centpercent tableforfieldedit">'."\n";
  307. // Common attributes
  308. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  309. // Other attributes
  310. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  311. print '</table>';
  312. print dol_get_fiche_end();
  313. print $form->buttonsSaveCancel();
  314. print '</form>';
  315. }
  316. // Part to show record
  317. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  318. $res = $object->fetch_thirdparty();
  319. $head = moPrepareHead($object);
  320. print dol_get_fiche_head($head, 'card', $langs->trans("ManufacturingOrder"), -1, $object->picto);
  321. $formconfirm = '';
  322. // Confirmation to delete
  323. if ($action == 'delete') {
  324. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', '', 0, 1);
  325. }
  326. // Confirmation to delete line
  327. if ($action == 'deleteline') {
  328. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  329. }
  330. // Confirmation of validation
  331. if ($action == 'validate') {
  332. // We check that object has a temporary ref
  333. $ref = substr($object->ref, 1, 4);
  334. if ($ref == 'PROV') {
  335. $object->fetch_product();
  336. $numref = $object->getNextNumRef($object->fk_product);
  337. } else {
  338. $numref = $object->ref;
  339. }
  340. $text = $langs->trans('ConfirmValidateMo', $numref);
  341. /*if (isModEnabled('notification'))
  342. {
  343. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  344. $notify = new Notify($db);
  345. $text .= '<br>';
  346. $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
  347. }*/
  348. $formquestion = array();
  349. if (isModEnabled('mrp')) {
  350. $langs->load("mrp");
  351. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  352. $formproduct = new FormProduct($db);
  353. $forcecombo = 0;
  354. if ($conf->browser->name == 'ie') {
  355. $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  356. }
  357. $formquestion = array(
  358. // 'text' => $langs->trans("ConfirmClone"),
  359. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  360. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  361. );
  362. }
  363. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
  364. }
  365. // Clone confirmation
  366. if ($action == 'clone') {
  367. // Create an array for form
  368. $formquestion = array();
  369. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  370. }
  371. // Call Hook formConfirm
  372. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  373. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  374. if (empty($reshook)) {
  375. $formconfirm .= $hookmanager->resPrint;
  376. } elseif ($reshook > 0) {
  377. $formconfirm = $hookmanager->resPrint;
  378. }
  379. // Print form confirm
  380. print $formconfirm;
  381. // Object card
  382. // ------------------------------------------------------------
  383. $linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  384. $morehtmlref = '<div class="refidno">';
  385. /*
  386. // Ref bis
  387. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', 0, 1);
  388. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', null, null, '', 1);*/
  389. // Thirdparty
  390. if (is_object($object->thirdparty)) {
  391. $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
  392. if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
  393. $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
  394. }
  395. }
  396. // Project
  397. if (isModEnabled('project')) {
  398. $langs->load("projects");
  399. if (is_object($object->thirdparty)) {
  400. $morehtmlref .= '<br>';
  401. }
  402. if ($permissiontoadd) {
  403. $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
  404. if ($action != 'classify') {
  405. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
  406. }
  407. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
  408. } else {
  409. if (!empty($object->fk_project)) {
  410. $proj = new Project($db);
  411. $proj->fetch($object->fk_project);
  412. $morehtmlref .= $proj->getNomUrl(1);
  413. if ($proj->title) {
  414. $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
  415. }
  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 dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : "").'&action=clone&object=mo', 'clone', $permissiontoadd);
  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
  575. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
  576. }
  577. print '</div>'."\n";
  578. }
  579. // Select mail models is same action as presend
  580. if (GETPOST('modelselected')) {
  581. $action = 'presend';
  582. }
  583. if ($action != 'presend') {
  584. print '<div class="fichecenter"><div class="fichehalfleft">';
  585. print '<a name="builddoc"></a>'; // ancre
  586. // Documents
  587. $objref = dol_sanitizeFileName($object->ref);
  588. $relativepath = $objref.'/'.$objref.'.pdf';
  589. $filedir = $conf->mrp->dir_output.'/'.$objref;
  590. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  591. $genallowed = $user->rights->mrp->read; // If you can read, you can build the PDF to read content
  592. $delallowed = $user->hasRight("mrp", "creer"); // If you can create/edit, you can remove a file on card
  593. print $formfile->showdocuments('mrp:mo', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $mysoc->default_lang);
  594. // Show links to link elements
  595. $linktoelem = $form->showLinkToObjectBlock($object, null, array('mo'));
  596. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, false);
  597. print '</div><div class="fichehalfright">';
  598. $MAXEVENT = 10;
  599. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/mrp/mo_agenda.php?id='.$object->id);
  600. // List of actions on element
  601. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  602. $formactions = new FormActions($db);
  603. $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT, '', $morehtmlcenter);
  604. print '</div></div>';
  605. }
  606. //Select mail models is same action as presend
  607. if (GETPOST('modelselected')) {
  608. $action = 'presend';
  609. }
  610. // Presend form
  611. $modelmail = 'mo';
  612. $defaulttopic = 'InformationMessage';
  613. $diroutput = $conf->mrp->dir_output;
  614. $trackid = 'mo'.$object->id;
  615. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  616. }
  617. // End of page
  618. llxFooter();
  619. $db->close();