bom_card.php 30 KB

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