bom_card.php 30 KB

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