bom.lib.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. /* Copyright (C) 2019 Maxime Kohlhaas <maxime@atm-consulting.fr>
  3. * Copyright (C) 2019-2021 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/lib/bom.lib.php
  20. * \ingroup bom
  21. * \brief Library files with common functions for BillOfMaterials
  22. */
  23. /**
  24. * Prepare admin pages header
  25. *
  26. * @return array
  27. */
  28. function bomAdminPrepareHead()
  29. {
  30. global $langs, $conf;
  31. $langs->load("mrp");
  32. $h = 0;
  33. $head = array();
  34. $head[$h][0] = DOL_URL_ROOT."/admin/bom.php";
  35. $head[$h][1] = $langs->trans("Settings");
  36. $head[$h][2] = 'settings';
  37. $h++;
  38. $head[$h][0] = DOL_URL_ROOT."/admin/bom_extrafields.php";
  39. $head[$h][1] = $langs->trans("ExtraFields");
  40. $head[$h][2] = 'bom_extrafields';
  41. $h++;
  42. $head[$h][0] = DOL_URL_ROOT."/admin/bomline_extrafields.php";
  43. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  44. $head[$h][2] = 'bomline_extrafields';
  45. $h++;
  46. // Show more tabs from modules
  47. // Entries must be declared in modules descriptor with line
  48. //$this->tabs = array(
  49. // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
  50. //); // to add new tab
  51. //$this->tabs = array(
  52. // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
  53. //); // to remove a tab
  54. complete_head_from_modules($conf, $langs, null, $head, $h, 'bom@mrp');
  55. complete_head_from_modules($conf, $langs, null, $head, $h, 'bom@mrp', 'remove');
  56. return $head;
  57. }
  58. /**
  59. * Prepare array of tabs for BillOfMaterials
  60. *
  61. * @param BOM $object BillOfMaterials
  62. * @return array Array of tabs
  63. */
  64. function bomPrepareHead($object)
  65. {
  66. global $db, $langs, $conf;
  67. $langs->load("mrp");
  68. $h = 0;
  69. $head = array();
  70. $head[$h][0] = DOL_URL_ROOT."/bom/bom_card.php?id=".$object->id;
  71. $head[$h][1] = $langs->trans("BOM");
  72. $head[$h][2] = 'card';
  73. $h++;
  74. $head[$h][0] = DOL_URL_ROOT."/bom/bom_net_needs.php?id=".$object->id;
  75. $head[$h][1] = $langs->trans("BOMNetNeeds");
  76. $head[$h][2] = 'net_needs';
  77. $h++;
  78. if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
  79. $nbNote = 0;
  80. if (!empty($object->note_private)) {
  81. $nbNote++;
  82. }
  83. if (!empty($object->note_public)) {
  84. $nbNote++;
  85. }
  86. $head[$h][0] = DOL_URL_ROOT.'/bom/bom_note.php?id='.$object->id;
  87. $head[$h][1] = $langs->trans('Notes');
  88. if ($nbNote > 0) {
  89. $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
  90. }
  91. $head[$h][2] = 'note';
  92. $h++;
  93. }
  94. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  95. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  96. $upload_dir = $conf->bom->dir_output."/bom/".dol_sanitizeFileName($object->ref);
  97. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  98. $nbLinks = Link::count($db, $object->element, $object->id);
  99. $head[$h][0] = DOL_URL_ROOT.'/bom/bom_document.php?id='.$object->id;
  100. $head[$h][1] = $langs->trans('Documents');
  101. if (($nbFiles + $nbLinks) > 0) {
  102. $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>' : '');
  103. }
  104. $head[$h][2] = 'document';
  105. $h++;
  106. $head[$h][0] = DOL_URL_ROOT.'/bom/bom_agenda.php?id='.$object->id;
  107. $head[$h][1] = $langs->trans("Events");
  108. $head[$h][2] = 'agenda';
  109. $h++;
  110. // Show more tabs from modules
  111. // Entries must be declared in modules descriptor with line
  112. //$this->tabs = array(
  113. // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
  114. //); // to add new tab
  115. //$this->tabs = array(
  116. // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
  117. //); // to remove a tab
  118. complete_head_from_modules($conf, $langs, $object, $head, $h, 'bom');
  119. complete_head_from_modules($conf, $langs, $object, $head, $h, 'bom', 'remove');
  120. return $head;
  121. }
  122. /**
  123. * Manage collapse bom display
  124. *
  125. * @return void
  126. */
  127. function mrpCollapseBomManagement()
  128. {
  129. ?>
  130. <script type="text/javascript" language="javascript">
  131. $(document).ready(function () {
  132. function folderManage(element, onClose = 0) {
  133. let id_bom_line = element.attr('id').replace('collapse-', '');
  134. let TSubLines = $('[parentid="'+ id_bom_line +'"]');
  135. if(element.html().indexOf('folder-open') <= 0 && onClose < 1) {
  136. $('[parentid="'+ id_bom_line +'"]').show();
  137. element.html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
  138. }
  139. else {
  140. for (let i = 0; i < TSubLines.length; i++) {
  141. let subBomFolder = $(TSubLines[i]).children('.linecoldescription').children('.collapse_bom');
  142. if (subBomFolder.length > 0) {
  143. onClose = 1
  144. folderManage(subBomFolder, onClose);
  145. }
  146. }
  147. TSubLines.hide();
  148. element.html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
  149. }
  150. }
  151. // When clicking on collapse
  152. $(".collapse_bom").click(function() {
  153. folderManage($(this));
  154. return false;
  155. });
  156. // To Show all the sub bom lines
  157. $("#show_all").click(function() {
  158. console.log("We click on show all");
  159. $("[class^=sub_bom_lines]").show();
  160. $("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
  161. return false;
  162. });
  163. // To Hide all the sub bom lines
  164. $("#hide_all").click(function() {
  165. console.log("We click on hide all");
  166. $("[class^=sub_bom_lines]").hide();
  167. $("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
  168. return false;
  169. });
  170. });
  171. </script>
  172. <?php
  173. }