bom_card.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. <?php
  2. /* Copyright (C) 2017-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/bom/bom_card.php
  20. * \ingroup bom
  21. * \brief Page to create/edit/view bom
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("mrp", "other"));
  32. // Get parameters
  33. $id = GETPOST('id', 'int');
  34. $ref = GETPOST('ref', 'alpha');
  35. $action = GETPOST('action', 'aZ09');
  36. $confirm = GETPOST('confirm', 'alpha');
  37. $cancel = GETPOST('cancel', 'aZ09');
  38. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bomcard'; // To manage different context of search
  39. $backtopage = GETPOST('backtopage', 'alpha');
  40. $lineid = GETPOST('lineid', 'int');
  41. // PDF
  42. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  43. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  44. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  45. // Initialize technical objects
  46. $object = new BOM($db);
  47. $extrafields = new ExtraFields($db);
  48. $diroutputmassaction = $conf->bom->dir_output.'/temp/massgeneration/'.$user->id;
  49. $hookmanager->initHooks(array('bomcard', 'globalcard')); // Note that conf->hooks_modules contains array
  50. // Fetch optionals attributes and labels
  51. $extrafields->fetch_name_optionals_label($object->table_element);
  52. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  53. // Initialize array of search criterias
  54. $search_all = GETPOST("search_all", 'alpha');
  55. $search = array();
  56. foreach ($object->fields as $key => $val) {
  57. if (GETPOST('search_'.$key, 'alpha')) {
  58. $search[$key] = GETPOST('search_'.$key, 'alpha');
  59. }
  60. }
  61. if (empty($action) && empty($id) && empty($ref)) {
  62. $action = 'view';
  63. }
  64. // Load object
  65. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  66. if ($object->id > 0) {
  67. $object->calculateCosts();
  68. }
  69. // Security check - Protection if external user
  70. //if ($user->socid > 0) accessforbidden();
  71. //if ($user->socid > 0) $socid = $user->socid;
  72. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  73. $result = restrictedArea($user, 'bom', $object->id, 'bom_bom', '', '', 'rowid', $isdraft);
  74. $permissionnote = $user->rights->bom->write; // Used by the include of actions_setnotes.inc.php
  75. $permissiondellink = $user->rights->bom->write; // Used by the include of actions_dellink.inc.php
  76. $permissiontoadd = $user->rights->bom->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  77. $permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  78. $upload_dir = $conf->bom->multidir_output[isset($object->entity) ? $object->entity : 1];
  79. /*
  80. * Actions
  81. */
  82. $parameters = array();
  83. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  84. if ($reshook < 0) {
  85. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  86. }
  87. if (empty($reshook)) {
  88. $error = 0;
  89. $backurlforlist = DOL_URL_ROOT.'/bom/bom_list.php';
  90. if (empty($backtopage) || ($cancel && empty($id))) {
  91. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  92. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  93. $backtopage = $backurlforlist;
  94. } else {
  95. $backtopage = DOL_URL_ROOT.'/bom/bom_card.php?id='.($id > 0 ? $id : '__ID__');
  96. }
  97. }
  98. }
  99. $triggermodname = 'BOM_MODIFY'; // Name of trigger action code to execute when we modify record
  100. // Actions cancel, add, update, delete or clone
  101. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  102. // The fetch/fetch_lines was redone into the inc.php so we must recall the calculateCosts()
  103. if ($action == 'confirm_validate' && $object->id > 0) {
  104. $object->calculateCosts();
  105. }
  106. // Actions when linking object each other
  107. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  108. // Actions when printing a doc from card
  109. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  110. // Action to move up and down lines of object
  111. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  112. // Action to build doc
  113. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  114. // Actions to send emails
  115. $triggersendname = 'BOM_SENTBYMAIL';
  116. $autocopy = 'MAIN_MAIL_AUTOCOPY_BOM_TO';
  117. $trackid = 'bom'.$object->id;
  118. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  119. // Add line
  120. if ($action == 'addline' && $user->rights->bom->write) {
  121. $langs->load('errors');
  122. $error = 0;
  123. // Set if we used free entry or predefined product
  124. $bom_child_id = (int) GETPOST('bom_id', 'int');
  125. if ($bom_child_id > 0) {
  126. $bom_child = new BOM($db);
  127. $res = $bom_child->fetch($bom_child_id);
  128. if ($res) {
  129. $idprod = $bom_child->fk_product;
  130. }
  131. } else {
  132. $idprod = (int) GETPOST('idprod', 'int');
  133. }
  134. $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
  135. $qty_frozen = price2num(GETPOST('qty_frozen', 'alpha'), 'MS');
  136. $disable_stock_change = GETPOST('disable_stock_change', 'int');
  137. $efficiency = price2num(GETPOST('efficiency', 'alpha'));
  138. if ($qty == '') {
  139. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
  140. $error++;
  141. }
  142. if (!($idprod > 0)) {
  143. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Product')), null, 'errors');
  144. $error++;
  145. }
  146. if ($object->fk_product == $idprod) {
  147. setEventMessages($langs->trans('TheProductXIsAlreadyTheProductToProduce'), null, 'errors');
  148. $error++;
  149. }
  150. // We check if we're allowed to add this bom
  151. $TParentBom=array();
  152. $object->getParentBomTreeRecursive($TParentBom);
  153. if ($bom_child_id > 0 && !empty($TParentBom) && in_array($bom_child_id, $TParentBom)) {
  154. $n_child = new BOM($db);
  155. $n_child->fetch($bom_child_id);
  156. setEventMessages($langs->transnoentities('BomCantAddChildBom', $n_child->getNomUrl(1), $object->getNomUrl(1)), null, 'errors');
  157. $error++;
  158. }
  159. if (!$error) {
  160. $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null);
  161. if ($result <= 0) {
  162. setEventMessages($object->error, $object->errors, 'errors');
  163. $action = '';
  164. } else {
  165. unset($_POST['idprod']);
  166. unset($_POST['qty']);
  167. unset($_POST['qty_frozen']);
  168. unset($_POST['disable_stock_change']);
  169. $object->fetchLines();
  170. }
  171. }
  172. }
  173. // Update line
  174. if ($action == 'updateline' && $user->rights->bom->write) {
  175. $langs->load('errors');
  176. $error = 0;
  177. // Set if we used free entry or predefined product
  178. $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
  179. $qty_frozen = price2num(GETPOST('qty_frozen', 'alpha'), 'MS');
  180. $disable_stock_change = GETPOST('disable_stock_change', 'int');
  181. $efficiency = price2num(GETPOST('efficiency', 'alpha'));
  182. if ($qty == '') {
  183. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
  184. $error++;
  185. }
  186. if (!$error) {
  187. $bomline = new BOMLine($db);
  188. $bomline->fetch($lineid);
  189. $result = $object->updateLine($lineid, $qty, (int) $qty_frozen, (int) $disable_stock_change, $efficiency, $bomline->position, $bomline->import_key);
  190. if ($result <= 0) {
  191. setEventMessages($object->error, $object->errors, 'errors');
  192. $action = '';
  193. } else {
  194. unset($_POST['idprod']);
  195. unset($_POST['qty']);
  196. unset($_POST['qty_frozen']);
  197. unset($_POST['disable_stock_change']);
  198. $object->fetchLines();
  199. }
  200. }
  201. }
  202. }
  203. /*
  204. * View
  205. */
  206. $form = new Form($db);
  207. $formfile = new FormFile($db);
  208. $title = $langs->trans('BOM');
  209. $help_url ='EN:Module_BOM';
  210. llxHeader('', $title, $help_url);
  211. // Part to create
  212. if ($action == 'create') {
  213. print load_fiche_titre($langs->trans("NewBOM"), '', 'bom');
  214. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  215. print '<input type="hidden" name="token" value="'.newToken().'">';
  216. print '<input type="hidden" name="action" value="add">';
  217. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  218. print dol_get_fiche_head(array(), '');
  219. print '<table class="border centpercent tableforfieldcreate">'."\n";
  220. // Common attributes
  221. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  222. // Other attributes
  223. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  224. print '</table>'."\n";
  225. print dol_get_fiche_end();
  226. print $form->buttonsSaveCancel("Create");
  227. print '</form>';
  228. }
  229. // Part to edit record
  230. if (($id || $ref) && $action == 'edit') {
  231. print load_fiche_titre($langs->trans("BillOfMaterials"), '', 'cubes');
  232. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  233. print '<input type="hidden" name="token" value="'.newToken().'">';
  234. print '<input type="hidden" name="action" value="update">';
  235. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  236. print '<input type="hidden" name="id" value="'.$object->id.'">';
  237. print dol_get_fiche_head();
  238. //$object->fields['keyfield']['disabled'] = 1;
  239. print '<table class="border centpercent tableforfieldedit">'."\n";
  240. // Common attributes
  241. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  242. // Other attributes
  243. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  244. print '</table>';
  245. print dol_get_fiche_end();
  246. print $form->buttonsSaveCancel("Create");
  247. print '</form>';
  248. }
  249. // Part to show record
  250. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  251. $head = bomPrepareHead($object);
  252. print dol_get_fiche_head($head, 'card', $langs->trans("BillOfMaterials"), -1, 'bom');
  253. $formconfirm = '';
  254. // Confirmation to delete
  255. if ($action == 'delete') {
  256. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBillOfMaterials'), $langs->trans('ConfirmDeleteBillOfMaterials'), 'confirm_delete', '', 0, 1);
  257. }
  258. // Confirmation to delete line
  259. if ($action == 'deleteline') {
  260. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  261. }
  262. // Confirmation of validation
  263. if ($action == 'validate') {
  264. // We check that object has a temporary ref
  265. $ref = substr($object->ref, 1, 4);
  266. if ($ref == 'PROV') {
  267. $object->fetch_product();
  268. $numref = $object->getNextNumRef($object->product);
  269. } else {
  270. $numref = $object->ref;
  271. }
  272. $text = $langs->trans('ConfirmValidateBom', $numref);
  273. /*if (!empty($conf->notification->enabled))
  274. {
  275. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  276. $notify = new Notify($db);
  277. $text .= '<br>';
  278. $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
  279. }*/
  280. $formquestion = array();
  281. if (!empty($conf->bom->enabled)) {
  282. $langs->load("mrp");
  283. $forcecombo = 0;
  284. if ($conf->browser->name == 'ie') {
  285. $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  286. }
  287. $formquestion = array(
  288. // 'text' => $langs->trans("ConfirmClone"),
  289. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  290. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  291. );
  292. }
  293. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
  294. }
  295. // Confirmation of closing
  296. if ($action == 'close') {
  297. $text = $langs->trans('ConfirmCloseBom', $object->ref);
  298. /*if (!empty($conf->notification->enabled))
  299. {
  300. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  301. $notify = new Notify($db);
  302. $text .= '<br>';
  303. $text .= $notify->confirmMessage('BOM_CLOSE', $object->socid, $object);
  304. }*/
  305. $formquestion = array();
  306. if (!empty($conf->bom->enabled)) {
  307. $langs->load("mrp");
  308. $forcecombo = 0;
  309. if ($conf->browser->name == 'ie') {
  310. $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  311. }
  312. $formquestion = array(
  313. // 'text' => $langs->trans("ConfirmClone"),
  314. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  315. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  316. );
  317. }
  318. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Close'), $text, 'confirm_close', $formquestion, 0, 1, 220);
  319. }
  320. // Confirmation of reopen
  321. if ($action == 'reopen') {
  322. $text = $langs->trans('ConfirmReopenBom', $object->ref);
  323. /*if (!empty($conf->notification->enabled))
  324. {
  325. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  326. $notify = new Notify($db);
  327. $text .= '<br>';
  328. $text .= $notify->confirmMessage('BOM_CLOSE', $object->socid, $object);
  329. }*/
  330. $formquestion = array();
  331. if (!empty($conf->bom->enabled)) {
  332. $langs->load("mrp");
  333. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  334. $forcecombo = 0;
  335. if ($conf->browser->name == 'ie') {
  336. $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  337. }
  338. $formquestion = array(
  339. // 'text' => $langs->trans("ConfirmClone"),
  340. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  341. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  342. );
  343. }
  344. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $text, 'confirm_reopen', $formquestion, 0, 1, 220);
  345. }
  346. // Clone confirmation
  347. if ($action == 'clone') {
  348. // Create an array for form
  349. $formquestion = array();
  350. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneBillOfMaterials', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  351. }
  352. // Confirmation of action xxxx
  353. if ($action == 'setdraft') {
  354. $text = $langs->trans('ConfirmSetToDraft', $object->ref);
  355. $formquestion = array();
  356. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetToDraft'), $text, 'confirm_setdraft', $formquestion, 0, 1, 220);
  357. }
  358. // Call Hook formConfirm
  359. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  360. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  361. if (empty($reshook)) {
  362. $formconfirm .= $hookmanager->resPrint;
  363. } elseif ($reshook > 0) {
  364. $formconfirm = $hookmanager->resPrint;
  365. }
  366. // Print form confirm
  367. print $formconfirm;
  368. // Object card
  369. // ------------------------------------------------------------
  370. $linkback = '<a href="'.DOL_URL_ROOT.'/bom/bom_list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  371. $morehtmlref = '<div class="refidno">';
  372. /*
  373. // Ref bis
  374. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->bom->creer, 'string', '', 0, 1);
  375. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->bom->creer, 'string', '', null, null, '', 1);
  376. // Thirdparty
  377. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
  378. // Project
  379. if (isModEnabled('project'))
  380. {
  381. $langs->load("projects");
  382. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  383. if ($permissiontoadd)
  384. {
  385. if ($action != 'classify')
  386. $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  387. if ($action == 'classify') {
  388. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  389. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  390. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  391. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  392. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
  393. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  394. $morehtmlref.='</form>';
  395. } else {
  396. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  397. }
  398. } else {
  399. if (!empty($object->fk_project)) {
  400. $proj = new Project($db);
  401. $proj->fetch($object->fk_project);
  402. $morehtmlref.=$proj->getNomUrl();
  403. } else {
  404. $morehtmlref.='';
  405. }
  406. }
  407. }
  408. */
  409. $morehtmlref .= '</div>';
  410. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  411. print '<div class="fichecenter">';
  412. print '<div class="fichehalfleft">';
  413. print '<div class="underbanner clearboth"></div>';
  414. print '<table class="border centpercent tableforfield">'."\n";
  415. // Common attributes
  416. $keyforbreak = 'duration';
  417. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
  418. $object->calculateCosts();
  419. print '<tr><td>'.$form->textwithpicto($langs->trans("TotalCost"), $langs->trans("BOMTotalCost")).'</td><td><span class="amount">'.price($object->total_cost).'</span></td></tr>';
  420. print '<tr><td>'.$langs->trans("UnitCost").'</td><td>'.price($object->unit_cost).'</td></tr>';
  421. // Other attributes
  422. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  423. print '</table>';
  424. print '</div>';
  425. print '</div>';
  426. print '<div class="clearboth"></div>';
  427. print dol_get_fiche_end();
  428. /*
  429. * Lines
  430. */
  431. if (!empty($object->table_element_line)) {
  432. print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '').'" method="POST">
  433. <input type="hidden" name="token" value="' . newToken().'">
  434. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
  435. <input type="hidden" name="mode" value="">
  436. <input type="hidden" name="page_y" value="">
  437. <input type="hidden" name="id" value="' . $object->id.'">
  438. ';
  439. if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  440. include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
  441. }
  442. print '<div class="div-table-responsive-no-min">';
  443. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  444. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  445. }
  446. if (!empty($object->lines)) {
  447. $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1, '/bom/tpl');
  448. }
  449. // Form to add new line
  450. if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
  451. if ($action != 'editline') {
  452. // Add products/services form
  453. $parameters = array();
  454. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  455. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  456. if (empty($reshook))
  457. $object->formAddObjectLine(1, $mysoc, null, '/bom/tpl');
  458. }
  459. }
  460. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  461. print '</table>';
  462. }
  463. print '</div>';
  464. print "</form>\n";
  465. mrpCollapseBomManagement();
  466. }
  467. // Buttons for actions
  468. if ($action != 'presend' && $action != 'editline') {
  469. print '<div class="tabsAction">'."\n";
  470. $parameters = array();
  471. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  472. if ($reshook < 0) {
  473. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  474. }
  475. if (empty($reshook)) {
  476. // Send
  477. //if (empty($user->socid)) {
  478. // print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
  479. //}
  480. // Back to draft
  481. if ($object->status == $object::STATUS_VALIDATED) {
  482. if ($permissiontoadd) {
  483. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=setdraft&token='.newToken().'">'.$langs->trans("SetToDraft").'</a>'."\n";
  484. }
  485. }
  486. // Modify
  487. if ($object->status == $object::STATUS_DRAFT) {
  488. if ($permissiontoadd) {
  489. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
  490. } else {
  491. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
  492. }
  493. }
  494. // Validate
  495. if ($object->status == $object::STATUS_DRAFT) {
  496. if ($permissiontoadd) {
  497. if (is_array($object->lines) && count($object->lines) > 0) {
  498. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=validate&amp;token='.newToken().'">'.$langs->trans("Validate").'</a>'."\n";
  499. } else {
  500. $langs->load("errors");
  501. print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>'."\n";
  502. }
  503. }
  504. }
  505. // Re-open
  506. if ($permissiontoadd && $object->status == $object::STATUS_CANCELED) {
  507. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a>'."\n";
  508. }
  509. // Create MO
  510. if (isModEnabled('mrp')) {
  511. if ($object->status == $object::STATUS_VALIDATED && !empty($user->rights->mrp->write)) {
  512. print '<a class="butAction" href="'.DOL_URL_ROOT.'/mrp/mo_card.php?action=create&fk_bom='.$object->id.'&token='.newToken().'&backtopageforcancel='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'">'.$langs->trans("CreateMO").'</a>'."\n";
  513. }
  514. }
  515. // Clone
  516. if ($permissiontoadd) {
  517. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&object=bom&token='.newToken().'">'.$langs->trans("ToClone").'</a>'."\n";
  518. }
  519. // Close / Cancel
  520. if ($permissiontoadd && $object->status == $object::STATUS_VALIDATED) {
  521. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken().'">'.$langs->trans("Disable").'</a>'."\n";
  522. }
  523. /*
  524. if ($user->rights->bom->write)
  525. {
  526. if ($object->status == 1)
  527. {
  528. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable&token='.newToken().'">'.$langs->trans("Disable").'</a>'."\n";
  529. }
  530. else
  531. {
  532. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Enable").'</a>'."\n";
  533. }
  534. }
  535. */
  536. if ($permissiontodelete) {
  537. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>'."\n";
  538. } else {
  539. print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
  540. }
  541. }
  542. print '</div>'."\n";
  543. }
  544. // Select mail models is same action as presend
  545. if (GETPOST('modelselected')) {
  546. $action = 'presend';
  547. }
  548. if ($action != 'presend') {
  549. print '<div class="fichecenter"><div class="fichehalfleft">';
  550. print '<a name="builddoc"></a>'; // ancre
  551. // Documents
  552. $objref = dol_sanitizeFileName($object->ref);
  553. $relativepath = $objref.'/'.$objref.'.pdf';
  554. $filedir = $conf->bom->dir_output.'/'.$objref;
  555. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  556. $genallowed = $user->rights->bom->read; // If you can read, you can build the PDF to read content
  557. $delallowed = $user->rights->bom->write; // If you can create/edit, you can remove a file on card
  558. print $formfile->showdocuments('bom', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  559. // Show links to link elements
  560. $linktoelem = $form->showLinkToObjectBlock($object, null, array('bom'));
  561. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  562. print '</div><div class="fichehalfright">';
  563. $MAXEVENT = 10;
  564. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/bom/bom_agenda.php?id='.$object->id);
  565. // List of actions on element
  566. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  567. $formactions = new FormActions($db);
  568. $somethingshown = $formactions->showactions($object, $object->element, 0, 1, '', $MAXEVENT, '', $morehtmlcenter);
  569. print '</div></div>';
  570. }
  571. //Select mail models is same action as presend
  572. if (GETPOST('modelselected')) {
  573. $action = 'presend';
  574. }
  575. // Presend form
  576. $modelmail = 'bom';
  577. $defaulttopic = 'InformationMessage';
  578. $diroutput = $conf->bom->dir_output;
  579. $trackid = 'bom'.$object->id;
  580. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  581. }
  582. // End of page
  583. llxFooter();
  584. $db->close();