bom_card.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  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 Bill Of Material
  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. $lineid = GETPOST('lineid', 'int');
  35. $ref = GETPOST('ref', 'alpha');
  36. $action = GETPOST('action', 'aZ09');
  37. $confirm = GETPOST('confirm', 'alpha');
  38. $cancel = GETPOST('cancel', 'aZ09');
  39. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bomcard'; // To manage different context of search
  40. $backtopage = GETPOST('backtopage', 'alpha');
  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. // Permissions
  75. $permissionnote = $user->rights->bom->write; // Used by the include of actions_setnotes.inc.php
  76. $permissiondellink = $user->rights->bom->write; // Used by the include of actions_dellink.inc.php
  77. $permissiontoadd = $user->rights->bom->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  78. $permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  79. $upload_dir = $conf->bom->multidir_output[isset($object->entity) ? $object->entity : 1];
  80. /*
  81. * Actions
  82. */
  83. $parameters = array();
  84. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  85. if ($reshook < 0) {
  86. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  87. }
  88. if (empty($reshook)) {
  89. $error = 0;
  90. $backurlforlist = DOL_URL_ROOT.'/bom/bom_list.php';
  91. if (empty($backtopage) || ($cancel && empty($id))) {
  92. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  93. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  94. $backtopage = $backurlforlist;
  95. } else {
  96. $backtopage = DOL_URL_ROOT.'/bom/bom_card.php?id='.($id > 0 ? $id : '__ID__');
  97. }
  98. }
  99. }
  100. $triggermodname = 'BOM_MODIFY'; // Name of trigger action code to execute when we modify record
  101. // Actions cancel, add, update, delete or clone
  102. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  103. // The fetch/fetch_lines was redone into the inc.php so we must recall the calculateCosts()
  104. if ($action == 'confirm_validate' && $object->id > 0) {
  105. $object->calculateCosts();
  106. }
  107. // Actions when linking object each other
  108. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
  109. // Actions when printing a doc from card
  110. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  111. // Action to move up and down lines of object
  112. //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
  113. // Action to build doc
  114. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  115. // Actions to send emails
  116. $triggersendname = 'BOM_SENTBYMAIL';
  117. $autocopy = 'MAIN_MAIL_AUTOCOPY_BOM_TO';
  118. $trackid = 'bom'.$object->id;
  119. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  120. // Add line
  121. if ($action == 'addline' && $user->rights->bom->write) {
  122. $langs->load('errors');
  123. $error = 0;
  124. $predef = '';
  125. // Set if we used free entry or predefined product
  126. $bom_child_id = (int) GETPOST('bom_id', 'int');
  127. if ($bom_child_id > 0) {
  128. $bom_child = new BOM($db);
  129. $res = $bom_child->fetch($bom_child_id);
  130. if ($res) {
  131. $idprod = $bom_child->fk_product;
  132. }
  133. } else {
  134. $idprod = (!empty(GETPOST('idprodservice', 'int')) ? GETPOST('idprodservice', 'int') : (int) GETPOST('idprod', 'int'));
  135. }
  136. $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
  137. $qty_frozen = price2num(GETPOST('qty_frozen', 'alpha'), 'MS');
  138. $disable_stock_change = GETPOST('disable_stock_change', 'int');
  139. $efficiency = price2num(GETPOST('efficiency', 'alpha'));
  140. $fk_unit = GETPOST('fk_unit', 'alphanohtml');
  141. if ($qty == '') {
  142. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
  143. $error++;
  144. }
  145. if (!($idprod > 0)) {
  146. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Product')), null, 'errors');
  147. $error++;
  148. }
  149. if ($object->fk_product == $idprod) {
  150. setEventMessages($langs->trans('TheProductXIsAlreadyTheProductToProduce'), null, 'errors');
  151. $error++;
  152. }
  153. // We check if we're allowed to add this bom
  154. $TParentBom=array();
  155. $object->getParentBomTreeRecursive($TParentBom);
  156. if ($bom_child_id > 0 && !empty($TParentBom) && in_array($bom_child_id, $TParentBom)) {
  157. $n_child = new BOM($db);
  158. $n_child->fetch($bom_child_id);
  159. setEventMessages($langs->transnoentities('BomCantAddChildBom', $n_child->getNomUrl(1), $object->getNomUrl(1)), null, 'errors');
  160. $error++;
  161. }
  162. if (!$error) {
  163. // Extrafields
  164. $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
  165. $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
  166. // Unset extrafield
  167. if (is_array($extralabelsline)) {
  168. // Get extra fields
  169. foreach ($extralabelsline as $key => $value) {
  170. unset($_POST["options_".$key]);
  171. }
  172. }
  173. $result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null, $fk_unit, $array_options);
  174. if ($result <= 0) {
  175. setEventMessages($object->error, $object->errors, 'errors');
  176. $action = '';
  177. } else {
  178. unset($_POST['idprod']);
  179. unset($_POST['idprodservice']);
  180. unset($_POST['qty']);
  181. unset($_POST['qty_frozen']);
  182. unset($_POST['disable_stock_change']);
  183. }
  184. $object->fetchLines();
  185. $object->calculateCosts();
  186. }
  187. }
  188. // Update line
  189. if ($action == 'updateline' && $user->rights->bom->write) {
  190. $langs->load('errors');
  191. $error = 0;
  192. // Set if we used free entry or predefined product
  193. $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
  194. $qty_frozen = price2num(GETPOST('qty_frozen', 'alpha'), 'MS');
  195. $disable_stock_change = GETPOST('disable_stock_change', 'int');
  196. $efficiency = price2num(GETPOST('efficiency', 'alpha'));
  197. $fk_unit = GETPOST('fk_unit', 'alphanohtml');
  198. if ($qty == '') {
  199. setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
  200. $error++;
  201. }
  202. if (!$error) {
  203. // Extrafields
  204. $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
  205. $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
  206. // Unset extrafield
  207. if (is_array($extralabelsline)) {
  208. // Get extra fields
  209. foreach ($extralabelsline as $key => $value) {
  210. unset($_POST["options_".$key]);
  211. }
  212. }
  213. $bomline = new BOMLine($db);
  214. $bomline->fetch($lineid);
  215. $result = $object->updateLine($lineid, $qty, (int) $qty_frozen, (int) $disable_stock_change, $efficiency, $bomline->position, $bomline->import_key, $fk_unit, $array_options);
  216. if ($result <= 0) {
  217. setEventMessages($object->error, $object->errors, 'errors');
  218. $action = '';
  219. } else {
  220. unset($_POST['idprod']);
  221. unset($_POST['idprodservice']);
  222. unset($_POST['qty']);
  223. unset($_POST['qty_frozen']);
  224. unset($_POST['disable_stock_change']);
  225. }
  226. $object->fetchLines();
  227. $object->calculateCosts();
  228. }
  229. }
  230. /*
  231. * View
  232. */
  233. $form = new Form($db);
  234. $formfile = new FormFile($db);
  235. $title = $langs->trans('BOM');
  236. $help_url ='EN:Module_BOM';
  237. llxHeader('', $title, $help_url);
  238. // Part to create
  239. if ($action == 'create') {
  240. print load_fiche_titre($langs->trans("NewBOM"), '', 'bom');
  241. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  242. print '<input type="hidden" name="token" value="'.newToken().'">';
  243. print '<input type="hidden" name="action" value="add">';
  244. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  245. print dol_get_fiche_head(array(), '');
  246. print '<table class="border centpercent tableforfieldcreate">'."\n";
  247. // Common attributes
  248. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
  249. // Other attributes
  250. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  251. print '</table>'."\n";
  252. print dol_get_fiche_end();
  253. print $form->buttonsSaveCancel("Create");
  254. print '</form>';
  255. }
  256. // Part to edit record
  257. if (($id || $ref) && $action == 'edit') {
  258. print load_fiche_titre($langs->trans("BillOfMaterials"), '', 'cubes');
  259. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  260. print '<input type="hidden" name="token" value="'.newToken().'">';
  261. print '<input type="hidden" name="action" value="update">';
  262. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  263. print '<input type="hidden" name="id" value="'.$object->id.'">';
  264. print dol_get_fiche_head();
  265. //$object->fields['keyfield']['disabled'] = 1;
  266. print '<table class="border centpercent tableforfieldedit">'."\n";
  267. // Common attributes
  268. include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
  269. // Other attributes
  270. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  271. print '</table>';
  272. print dol_get_fiche_end();
  273. print $form->buttonsSaveCancel("Create");
  274. print '</form>';
  275. }
  276. // Part to show record
  277. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
  278. $head = bomPrepareHead($object);
  279. print dol_get_fiche_head($head, 'card', $langs->trans("BillOfMaterials"), -1, 'bom');
  280. $formconfirm = '';
  281. // Confirmation to delete
  282. if ($action == 'delete') {
  283. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteBillOfMaterials'), $langs->trans('ConfirmDeleteBillOfMaterials'), 'confirm_delete', '', 0, 1);
  284. }
  285. // Confirmation to delete line
  286. if ($action == 'deleteline') {
  287. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
  288. }
  289. // Confirmation of validation
  290. if ($action == 'validate') {
  291. // We check that object has a temporary ref
  292. $ref = substr($object->ref, 1, 4);
  293. if ($ref == 'PROV') {
  294. $object->fetch_product();
  295. $numref = $object->getNextNumRef($object->product);
  296. } else {
  297. $numref = $object->ref;
  298. }
  299. $text = $langs->trans('ConfirmValidateBom', $numref);
  300. /*if (isModEnabled('notification'))
  301. {
  302. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  303. $notify = new Notify($db);
  304. $text .= '<br>';
  305. $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
  306. }*/
  307. $formquestion = array();
  308. if (isModEnabled('bom')) {
  309. $langs->load("mrp");
  310. $forcecombo = 0;
  311. if ($conf->browser->name == 'ie') {
  312. $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  313. }
  314. $formquestion = array(
  315. // 'text' => $langs->trans("ConfirmClone"),
  316. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  317. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  318. );
  319. }
  320. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
  321. }
  322. // Confirmation of closing
  323. if ($action == 'close') {
  324. $text = $langs->trans('ConfirmCloseBom', $object->ref);
  325. /*if (isModEnabled('notification'))
  326. {
  327. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  328. $notify = new Notify($db);
  329. $text .= '<br>';
  330. $text .= $notify->confirmMessage('BOM_CLOSE', $object->socid, $object);
  331. }*/
  332. $formquestion = array();
  333. if (isModEnabled('bom')) {
  334. $langs->load("mrp");
  335. $forcecombo = 0;
  336. if ($conf->browser->name == 'ie') {
  337. $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  338. }
  339. $formquestion = array(
  340. // 'text' => $langs->trans("ConfirmClone"),
  341. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  342. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  343. );
  344. }
  345. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('Close'), $text, 'confirm_close', $formquestion, 0, 1, 220);
  346. }
  347. // Confirmation of reopen
  348. if ($action == 'reopen') {
  349. $text = $langs->trans('ConfirmReopenBom', $object->ref);
  350. /*if (isModEnabled('notification'))
  351. {
  352. require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
  353. $notify = new Notify($db);
  354. $text .= '<br>';
  355. $text .= $notify->confirmMessage('BOM_CLOSE', $object->socid, $object);
  356. }*/
  357. $formquestion = array();
  358. if (isModEnabled('bom')) {
  359. $langs->load("mrp");
  360. require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
  361. $forcecombo = 0;
  362. if ($conf->browser->name == 'ie') {
  363. $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
  364. }
  365. $formquestion = array(
  366. // 'text' => $langs->trans("ConfirmClone"),
  367. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  368. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  369. );
  370. }
  371. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ReOpen'), $text, 'confirm_reopen', $formquestion, 0, 1, 220);
  372. }
  373. // Clone confirmation
  374. if ($action == 'clone') {
  375. // Create an array for form
  376. $formquestion = array();
  377. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneBillOfMaterials', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  378. }
  379. // Confirmation of action xxxx
  380. if ($action == 'setdraft') {
  381. $text = $langs->trans('ConfirmSetToDraft', $object->ref);
  382. $formquestion = array();
  383. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('SetToDraft'), $text, 'confirm_setdraft', $formquestion, 0, 1, 220);
  384. }
  385. // Call Hook formConfirm
  386. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  387. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  388. if (empty($reshook)) {
  389. $formconfirm .= $hookmanager->resPrint;
  390. } elseif ($reshook > 0) {
  391. $formconfirm = $hookmanager->resPrint;
  392. }
  393. // Print form confirm
  394. print $formconfirm;
  395. // Object card
  396. // ------------------------------------------------------------
  397. $linkback = '<a href="' . DOL_URL_ROOT . '/bom/bom_list.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
  398. $morehtmlref = '<div class="refidno">';
  399. /*
  400. // Ref bis
  401. $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->bom->creer, 'string', '', 0, 1);
  402. $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->bom->creer, 'string', '', null, null, '', 1);
  403. // Thirdparty
  404. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
  405. // Project
  406. if (isModEnabled('project'))
  407. {
  408. $langs->load("projects");
  409. $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
  410. if ($permissiontoadd)
  411. {
  412. if ($action != 'classify')
  413. $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
  414. if ($action == 'classify') {
  415. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  416. $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  417. $morehtmlref.='<input type="hidden" name="action" value="classin">';
  418. $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
  419. $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
  420. $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  421. $morehtmlref.='</form>';
  422. } else {
  423. $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  424. }
  425. } else {
  426. if (! empty($object->fk_project)) {
  427. $proj = new Project($db);
  428. $proj->fetch($object->fk_project);
  429. $morehtmlref.=$proj->getNomUrl();
  430. } else {
  431. $morehtmlref.='';
  432. }
  433. }
  434. }
  435. */
  436. $morehtmlref .= '</div>';
  437. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  438. print '<div class="fichecenter">';
  439. print '<div class="fichehalfleft">';
  440. print '<div class="underbanner clearboth"></div>';
  441. print '<table class="border centpercent tableforfield">' . "\n";
  442. // Common attributes
  443. $keyforbreak = 'duration';
  444. include DOL_DOCUMENT_ROOT . '/core/tpl/commonfields_view.tpl.php';
  445. $object->calculateCosts();
  446. print '<tr><td>' . $form->textwithpicto($langs->trans("TotalCost"), $langs->trans("BOMTotalCost")) . '</td><td><span class="amount">' . price($object->total_cost) . '</span></td></tr>';
  447. print '<tr><td>' . $langs->trans("UnitCost") . '</td><td>' . price($object->unit_cost) . '</td></tr>';
  448. // Other attributes
  449. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  450. print '</table>';
  451. print '</div>';
  452. print '</div>';
  453. print '<div class="clearboth"></div>';
  454. print dol_get_fiche_end();
  455. /*
  456. * Lines
  457. */
  458. if (!empty($object->table_element_line)) {
  459. //Products
  460. $res = $object->fetchLinesbytypeproduct(0);
  461. $object->calculateCosts();
  462. print ($res == 0 && $object->status >= $object::STATUS_VALIDATED) ? '' : load_fiche_titre($langs->trans('BOMProductsList'), '', 'product');
  463. print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '' : '') . '" method="POST">
  464. <input type="hidden" name="token" value="' . newToken() . '">
  465. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
  466. <input type="hidden" name="mode" value="">
  467. <input type="hidden" name="page_y" value="">
  468. <input type="hidden" name="id" value="' . $object->id . '">
  469. ';
  470. if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  471. include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
  472. }
  473. print '<div class="div-table-responsive-no-min">';
  474. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  475. print '<table id="tablelines" class="noborder noshadow" width="100%">';
  476. }
  477. if (!empty($object->lines)) {
  478. $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1, '/bom/tpl');
  479. }
  480. // Form to add new line
  481. if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
  482. if ($action != 'editline') {
  483. // Add products/services form
  484. $parameters = array();
  485. $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  486. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  487. if (empty($reshook))
  488. $object->formAddObjectLine(1, $mysoc, null, '/bom/tpl');
  489. }
  490. }
  491. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  492. print '</table>';
  493. }
  494. print '</div>';
  495. print "</form>\n";
  496. //Services
  497. $filtertype = 1;
  498. $res = $object->fetchLinesbytypeproduct(1);
  499. $object->calculateCosts();
  500. print ($res == 0 && $object->status >= $object::STATUS_VALIDATED) ? '' : load_fiche_titre($langs->trans('BOMServicesList'), '', 'service');
  501. print ' <form name="addservice" id="addservice" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '' : '') . '" method="POST">
  502. <input type="hidden" name="token" value="' . newToken() . '">
  503. <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
  504. <input type="hidden" name="mode" value="">
  505. <input type="hidden" name="page_y" value=""> <input type="hidden" name="id" value="' . $object->id . '">
  506. ';
  507. if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
  508. $tagidfortablednd = 'tablelinesservice';
  509. include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
  510. }
  511. print '<div class="div-table-responsive-no-min">';
  512. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  513. print '<table id="tablelinesservice" class="noborder noshadow" width="100%">';
  514. }
  515. if (!empty($object->lines)) {
  516. $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1, '/bom/tpl');
  517. }
  518. // Form to add new line
  519. if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
  520. if ($action != 'editline') {
  521. // Add services form
  522. $parameters = array();
  523. $reshook = $hookmanager->executeHooks('formAddObjectServiceLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  524. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  525. if (empty($reshook))
  526. $object->formAddObjectLine(1, $mysoc, null, '/bom/tpl');
  527. }
  528. }
  529. }
  530. if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
  531. print '</table>';
  532. }
  533. print '</div>';
  534. print "</form>\n";
  535. mrpCollapseBomManagement();
  536. $res = $object->fetchLines();
  537. // Buttons for actions
  538. if ($action != 'presend' && $action != 'editline') {
  539. print '<div class="tabsAction">' . "\n";
  540. $parameters = array();
  541. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  542. if ($reshook < 0) {
  543. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  544. }
  545. if (empty($reshook)) {
  546. // Send
  547. //if (empty($user->socid)) {
  548. // print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
  549. //}
  550. // Back to draft
  551. if ($object->status == $object::STATUS_VALIDATED) {
  552. if ($permissiontoadd) {
  553. print '<a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=setdraft&token=' . newToken() . '">' . $langs->trans("SetToDraft") . '</a>' . "\n";
  554. }
  555. }
  556. // Modify
  557. if ($object->status == $object::STATUS_DRAFT) {
  558. if ($permissiontoadd) {
  559. print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=edit&token=' . newToken() . '">' . $langs->trans("Modify") . '</a>' . "\n";
  560. } else {
  561. print '<a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag($langs->trans("NotEnoughPermissions")) . '">' . $langs->trans('Modify') . '</a>' . "\n";
  562. }
  563. }
  564. // Validate
  565. if ($object->status == $object::STATUS_DRAFT) {
  566. if ($permissiontoadd) {
  567. if (is_array($object->lines) && count($object->lines) > 0) {
  568. print '<a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&amp;action=validate&amp;token=' . newToken() . '">' . $langs->trans("Validate") . '</a>' . "\n";
  569. } else {
  570. $langs->load("errors");
  571. print '<a class="butActionRefused" href="" title="' . $langs->trans("ErrorAddAtLeastOneLineFirst") . '">' . $langs->trans("Validate") . '</a>' . "\n";
  572. }
  573. }
  574. }
  575. // Re-open
  576. if ($permissiontoadd && $object->status == $object::STATUS_CANCELED) {
  577. print '<a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=reopen&token=' . newToken() . '">' . $langs->trans("ReOpen") . '</a>' . "\n";
  578. }
  579. // Create MO
  580. if (isModEnabled('mrp')) {
  581. if ($object->status == $object::STATUS_VALIDATED && !empty($user->rights->mrp->write)) {
  582. 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";
  583. }
  584. }
  585. // Clone
  586. if ($permissiontoadd) {
  587. print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . (!empty($object->socid) ? '&socid=' . $object->socid : "") . '&action=clone&object=bom', 'clone', $permissiontoadd);
  588. }
  589. // Close / Cancel
  590. if ($permissiontoadd && $object->status == $object::STATUS_VALIDATED) {
  591. print '<a class="butActionDelete" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=close&token=' . newToken() . '">' . $langs->trans("Disable") . '</a>' . "\n";
  592. }
  593. /*
  594. if ($user->rights->bom->write)
  595. {
  596. if ($object->status == 1)
  597. {
  598. print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable&token='.newToken().'">'.$langs->trans("Disable").'</a>'."\n";
  599. }
  600. else
  601. {
  602. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Enable").'</a>'."\n";
  603. }
  604. }
  605. */
  606. // Delete
  607. print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=delete&token=' . newToken(), 'delete', $permissiontodelete);
  608. }
  609. print '</div>' . "\n";
  610. }
  611. // Select mail models is same action as presend
  612. if (GETPOST('modelselected')) {
  613. $action = 'presend';
  614. }
  615. if ($action != 'presend') {
  616. print '<div class="fichecenter"><div class="fichehalfleft">';
  617. print '<a name="builddoc"></a>'; // ancre
  618. // Documents
  619. $objref = dol_sanitizeFileName($object->ref);
  620. $relativepath = $objref . '/' . $objref . '.pdf';
  621. $filedir = $conf->bom->dir_output . '/' . $objref;
  622. $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
  623. $genallowed = $user->rights->bom->read; // If you can read, you can build the PDF to read content
  624. $delallowed = $user->rights->bom->write; // If you can create/edit, you can remove a file on card
  625. print $formfile->showdocuments('bom', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  626. // Show links to link elements
  627. $linktoelem = $form->showLinkToObjectBlock($object, null, array('bom'));
  628. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  629. print '</div><div class="fichehalfright">';
  630. $MAXEVENT = 10;
  631. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT . '/bom/bom_agenda.php?id=' . $object->id);
  632. // List of actions on element
  633. include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
  634. $formactions = new FormActions($db);
  635. $somethingshown = $formactions->showactions($object, $object->element, 0, 1, '', $MAXEVENT, '', $morehtmlcenter);
  636. print '</div></div>';
  637. }
  638. //Select mail models is same action as presend
  639. if (GETPOST('modelselected')) {
  640. $action = 'presend';
  641. }
  642. // Presend form
  643. $modelmail = 'bom';
  644. $defaulttopic = 'InformationMessage';
  645. $diroutput = $conf->bom->dir_output;
  646. $trackid = 'bom' . $object->id;
  647. include DOL_DOCUMENT_ROOT . '/core/tpl/card_presend.tpl.php';
  648. }
  649. }
  650. // End of page
  651. llxFooter();
  652. $db->close();