bom.lib.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. // Show more tabs from modules
  43. // Entries must be declared in modules descriptor with line
  44. //$this->tabs = array(
  45. // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
  46. //); // to add new tab
  47. //$this->tabs = array(
  48. // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
  49. //); // to remove a tab
  50. complete_head_from_modules($conf, $langs, null, $head, $h, 'bom@mrp');
  51. complete_head_from_modules($conf, $langs, null, $head, $h, 'bom@mrp', 'remove');
  52. return $head;
  53. }
  54. /**
  55. * Prepare array of tabs for BillOfMaterials
  56. *
  57. * @param BOM $object BillOfMaterials
  58. * @return array Array of tabs
  59. */
  60. function bomPrepareHead($object)
  61. {
  62. global $db, $langs, $conf;
  63. $langs->load("mrp");
  64. $h = 0;
  65. $head = array();
  66. $head[$h][0] = DOL_URL_ROOT."/bom/bom_card.php?id=".$object->id;
  67. $head[$h][1] = $langs->trans("BOM");
  68. $head[$h][2] = 'card';
  69. $h++;
  70. $head[$h][0] = DOL_URL_ROOT."/bom/bom_net_needs.php?id=".$object->id;
  71. $head[$h][1] = $langs->trans("BOMNetNeeds");
  72. $head[$h][2] = 'net_needs';
  73. $h++;
  74. if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
  75. $nbNote = 0;
  76. if (!empty($object->note_private)) {
  77. $nbNote++;
  78. }
  79. if (!empty($object->note_public)) {
  80. $nbNote++;
  81. }
  82. $head[$h][0] = DOL_URL_ROOT.'/bom/bom_note.php?id='.$object->id;
  83. $head[$h][1] = $langs->trans('Notes');
  84. if ($nbNote > 0) {
  85. $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
  86. }
  87. $head[$h][2] = 'note';
  88. $h++;
  89. }
  90. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  91. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  92. $upload_dir = $conf->bom->dir_output."/bom/".dol_sanitizeFileName($object->ref);
  93. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  94. $nbLinks = Link::count($db, $object->element, $object->id);
  95. $head[$h][0] = DOL_URL_ROOT.'/bom/bom_document.php?id='.$object->id;
  96. $head[$h][1] = $langs->trans('Documents');
  97. if (($nbFiles + $nbLinks) > 0) {
  98. $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>' : '');
  99. }
  100. $head[$h][2] = 'document';
  101. $h++;
  102. $head[$h][0] = DOL_URL_ROOT.'/bom/bom_agenda.php?id='.$object->id;
  103. $head[$h][1] = $langs->trans("Events");
  104. $head[$h][2] = 'agenda';
  105. $h++;
  106. // Show more tabs from modules
  107. // Entries must be declared in modules descriptor with line
  108. //$this->tabs = array(
  109. // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
  110. //); // to add new tab
  111. //$this->tabs = array(
  112. // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
  113. //); // to remove a tab
  114. complete_head_from_modules($conf, $langs, $object, $head, $h, 'bom');
  115. complete_head_from_modules($conf, $langs, $object, $head, $h, 'bom', 'remove');
  116. return $head;
  117. }
  118. /**
  119. * Manage collapse bom display
  120. *
  121. * @return void
  122. */
  123. function mrpCollapseBomManagement()
  124. {
  125. ?>
  126. <script type="text/javascript" language="javascript">
  127. $(document).ready(function () {
  128. // When clicking on collapse
  129. $(".collapse_bom").click(function() {
  130. console.log("We click on collapse");
  131. var id_bom_line = $(this).attr('id').replace('collapse-', '');
  132. console.log($(this).html().indexOf('folder-open'));
  133. if($(this).html().indexOf('folder-open') <= 0) {
  134. $('[parentid="'+ id_bom_line +'"]').show();
  135. $(this).html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
  136. }
  137. else {
  138. $('[parentid="'+ id_bom_line +'"]').hide();
  139. $(this).html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
  140. }
  141. return false;
  142. });
  143. // To Show all the sub bom lines
  144. $("#show_all").click(function() {
  145. console.log("We click on show all");
  146. $("[class^=sub_bom_lines]").show();
  147. $("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
  148. return false;
  149. });
  150. // To Hide all the sub bom lines
  151. $("#hide_all").click(function() {
  152. console.log("We click on hide all");
  153. $("[class^=sub_bom_lines]").hide();
  154. $("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
  155. return false;
  156. });
  157. });
  158. </script>
  159. <?php
  160. }