dolibarr  16.0.5
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-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 
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  // Show more tabs from modules
50  // Entries must be declared in modules descriptor with line
51  //$this->tabs = array(
52  // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
53  //); // to add new tab
54  //$this->tabs = array(
55  // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
56  //); // to remove a tab
57  complete_head_from_modules($conf, $langs, null, $head, $h, 'bom@mrp');
58 
59  complete_head_from_modules($conf, $langs, null, $head, $h, 'bom@mrp', 'remove');
60 
61  return $head;
62 }
63 
64 
65 
66 
73 function bomPrepareHead($object)
74 {
75  global $db, $langs, $conf;
76 
77  $langs->load("mrp");
78 
79  $h = 0;
80  $head = array();
81 
82  $head[$h][0] = DOL_URL_ROOT."/bom/bom_card.php?id=".$object->id;
83  $head[$h][1] = $langs->trans("BOM");
84  $head[$h][2] = 'card';
85  $h++;
86 
87  $head[$h][0] = DOL_URL_ROOT."/bom/bom_net_needs.php?id=".$object->id;
88  $head[$h][1] = $langs->trans("BOMNetNeeds");
89  $head[$h][2] = 'net_needs';
90  $h++;
91 
92  if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
93  $nbNote = 0;
94  if (!empty($object->note_private)) {
95  $nbNote++;
96  }
97  if (!empty($object->note_public)) {
98  $nbNote++;
99  }
100  $head[$h][0] = DOL_URL_ROOT.'/bom/bom_note.php?id='.$object->id;
101  $head[$h][1] = $langs->trans('Notes');
102  if ($nbNote > 0) {
103  $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
104  }
105  $head[$h][2] = 'note';
106  $h++;
107  }
108 
109  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
110  require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
111  $upload_dir = $conf->bom->dir_output."/bom/".dol_sanitizeFileName($object->ref);
112  $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
113  $nbLinks = Link::count($db, $object->element, $object->id);
114  $head[$h][0] = DOL_URL_ROOT.'/bom/bom_document.php?id='.$object->id;
115  $head[$h][1] = $langs->trans('Documents');
116  if (($nbFiles + $nbLinks) > 0) {
117  $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>' : '');
118  }
119  $head[$h][2] = 'document';
120  $h++;
121 
122  $head[$h][0] = DOL_URL_ROOT.'/bom/bom_agenda.php?id='.$object->id;
123  $head[$h][1] = $langs->trans("Events");
124  $head[$h][2] = 'agenda';
125  $h++;
126 
127  // Show more tabs from modules
128  // Entries must be declared in modules descriptor with line
129  //$this->tabs = array(
130  // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
131  //); // to add new tab
132  //$this->tabs = array(
133  // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
134  //); // to remove a tab
135  complete_head_from_modules($conf, $langs, $object, $head, $h, 'bom');
136 
137  return $head;
138 }
139 
146 {
147  ?>
148 
149  <script type="text/javascript" language="javascript">
150 
151  $(document).ready(function () {
152  // When clicking on collapse
153  $(".collapse_bom").click(function() {
154  console.log("We click on collapse");
155  var id_bom_line = $(this).attr('id').replace('collapse-', '');
156  console.log($(this).html().indexOf('folder-open'));
157  if($(this).html().indexOf('folder-open') <= 0) {
158  $('[parentid="'+ id_bom_line +'"]').show();
159  $(this).html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
160  }
161  else {
162  $('[parentid="'+ id_bom_line +'"]').hide();
163  $(this).html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
164  }
165 
166  return false;
167  });
168 
169  // To Show all the sub bom lines
170  $("#show_all").click(function() {
171  console.log("We click on show all");
172  $("[class^=sub_bom_lines]").show();
173  $("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
174  return false;
175  });
176 
177  // To Hide all the sub bom lines
178  $("#hide_all").click(function() {
179  console.log("We click on hide all");
180  $("[class^=sub_bom_lines]").hide();
181  $("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
182  return false;
183  });
184  });
185 
186  </script>
187 
188  <?php
189 }
190 
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
complete_head_from_modules
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add')
Complete or removed entries into a head array (used to build tabs).
Definition: functions.lib.php:9038
mrpCollapseBomManagement
mrpCollapseBomManagement()
Manage collapse bom display.
Definition: bom.lib.php:145
bomPrepareHead
bomPrepareHead($object)
Prepare array of tabs for BillOfMaterials.
Definition: bom.lib.php:73
bomAdminPrepareHead
bomAdminPrepareHead()
Prepare admin pages header.
Definition: bom.lib.php:30
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119