dolibarr  20.0.0-alpha
bom.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2019 Maxime Kohlhaas <maxime@atm-consulting.fr>
3  * Copyright (C) 2019-2023 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 
31 {
32  global $langs, $conf;
33 
34  $langs->load("mrp");
35 
36  $h = 0;
37  $head = array();
38 
39  $head[$h][0] = DOL_URL_ROOT."/admin/bom.php";
40  $head[$h][1] = $langs->trans("Settings");
41  $head[$h][2] = 'settings';
42  $h++;
43 
44  $head[$h][0] = DOL_URL_ROOT."/admin/bom_extrafields.php";
45  $head[$h][1] = $langs->trans("ExtraFields");
46  $head[$h][2] = 'bom_extrafields';
47  $h++;
48 
49  $head[$h][0] = DOL_URL_ROOT."/admin/bomline_extrafields.php";
50  $head[$h][1] = $langs->trans("ExtraFieldsLines");
51  $head[$h][2] = 'bomline_extrafields';
52  $h++;
53 
54  // Show more tabs from modules
55  // Entries must be declared in modules descriptor with line
56  //$this->tabs = array(
57  // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
58  //); // to add new tab
59  //$this->tabs = array(
60  // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
61  //); // to remove a tab
62  complete_head_from_modules($conf, $langs, null, $head, $h, 'bom@mrp');
63 
64  complete_head_from_modules($conf, $langs, null, $head, $h, 'bom@mrp', 'remove');
65 
66  return $head;
67 }
68 
69 
70 
71 
79 {
80  global $db, $langs, $conf;
81 
82  $langs->load("mrp");
83 
84  $h = 0;
85  $head = array();
86 
87  $head[$h][0] = DOL_URL_ROOT."/bom/bom_card.php?id=".$object->id;
88  $head[$h][1] = $langs->trans("BOM");
89  $head[$h][2] = 'card';
90  $h++;
91 
92  $head[$h][0] = DOL_URL_ROOT."/bom/bom_net_needs.php?id=".$object->id;
93  $head[$h][1] = $langs->trans("BOMNetNeeds");
94  $head[$h][2] = 'net_needs';
95  $h++;
96 
97  if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
98  $nbNote = 0;
99  if (!empty($object->note_private)) {
100  $nbNote++;
101  }
102  if (!empty($object->note_public)) {
103  $nbNote++;
104  }
105  $head[$h][0] = DOL_URL_ROOT.'/bom/bom_note.php?id='.$object->id;
106  $head[$h][1] = $langs->trans('Notes');
107  if ($nbNote > 0) {
108  $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
109  }
110  $head[$h][2] = 'note';
111  $h++;
112  }
113 
114  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
115  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
116  $upload_dir = $conf->bom->dir_output."/".dol_sanitizeFileName($object->ref);
117  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
118  $nbLinks = Link::count($db, $object->element, $object->id);
119  $head[$h][0] = DOL_URL_ROOT.'/bom/bom_document.php?id='.$object->id;
120  $head[$h][1] = $langs->trans('Documents');
121  if (($nbFiles + $nbLinks) > 0) {
122  $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>' : '');
123  }
124  $head[$h][2] = 'document';
125  $h++;
126 
127  $head[$h][0] = DOL_URL_ROOT.'/bom/bom_agenda.php?id='.$object->id;
128  $head[$h][1] = $langs->trans("Events");
129  $head[$h][2] = 'agenda';
130  $h++;
131 
132  // Show more tabs from modules
133  // Entries must be declared in modules descriptor with line
134  //$this->tabs = array(
135  // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
136  //); // to add new tab
137  //$this->tabs = array(
138  // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
139  //); // to remove a tab
140  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bom');
141 
142  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bom', 'remove');
143 
144  return $head;
145 }
146 
153 {
154  ?>
155 
156  <script type="text/javascript" language="javascript">
157 
158  $(document).ready(function () {
159  function folderManage(element, onClose = 0) {
160  let id_bom_line = element.attr('id').replace('collapse-', '');
161  let TSubLines = $('[parentid="'+ id_bom_line +'"]');
162 
163  if(element.html().indexOf('folder-open') <= 0 && onClose < 1) {
164  $('[parentid="'+ id_bom_line +'"]').show();
165  element.html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
166  }
167  else {
168  for (let i = 0; i < TSubLines.length; i++) {
169  let subBomFolder = $(TSubLines[i]).children('.linecoldescription').children('.collapse_bom');
170 
171  if (subBomFolder.length > 0) {
172  onClose = 1
173  folderManage(subBomFolder, onClose);
174  }
175  }
176  TSubLines.hide();
177  element.html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
178  }
179  }
180 
181  // When clicking on collapse
182  $(".collapse_bom").click(function() {
183  folderManage($(this));
184  return false;
185  });
186 
187  // To Show all the sub bom lines
188  $("#show_all").click(function() {
189  console.log("We click on show all");
190  $("[class^=sub_bom_lines]").show();
191  $("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
192  return false;
193  });
194 
195  // To Hide all the sub bom lines
196  $("#hide_all").click(function() {
197  console.log("We click on hide all");
198  $("[class^=sub_bom_lines]").hide();
199  $("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
200  return false;
201  });
202  });
203 
204  </script>
205 
206  <?php
207 }
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
mrpCollapseBomManagement()
Manage collapse bom display.
Definition: bom.lib.php:152
bomAdminPrepareHead()
Prepare admin pages header.
Definition: bom.lib.php:30
bomPrepareHead($object)
Prepare array of tabs for BillOfMaterials.
Definition: bom.lib.php:78
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:63
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:122