dolibarr 24.0.0-beta
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-2026 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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
32{
33 global $langs, $conf, $extrafields;
34
35 $extrafields->fetch_name_optionals_label('bom_bom');
36 $extrafields->fetch_name_optionals_label('bom_bomline');
37
38 $langs->load("mrp");
39
40 $h = 0;
41 $head = array();
42
43 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/bom.php");
44 $head[$h][1] = $langs->trans("Settings");
45 $head[$h][2] = 'settings';
46 $h++;
47
48 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/bom_extrafields.php");
49 $head[$h][1] = $langs->trans("ExtraFields");
50 $nbExtrafields = (isset($extrafields->attributes['bom_bom']['label']) && is_countable($extrafields->attributes['bom_bom']['label'])) ? count($extrafields->attributes['bom_bom']['label']) : 0;
51 if ($nbExtrafields > 0) {
52 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
53 }
54 $head[$h][2] = 'bom_extrafields';
55 $h++;
56
57 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/admin/bomline_extrafields.php");
58 $head[$h][1] = $langs->trans("ExtraFieldsLines");
59 $nbExtrafields = (isset($extrafields->attributes['bom_bomline']['label']) && is_countable($extrafields->attributes['bom_bomline']['label'])) ? count($extrafields->attributes['bom_bomline']['label']) : 0;
60 if ($nbExtrafields > 0) {
61 $head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbExtrafields . '</span>';
62 }
63 $head[$h][2] = 'bomline_extrafields';
64 $h++;
65
66 // Show more tabs from modules
67 // Entries must be declared in modules descriptor with line
68 //$this->tabs = array(
69 // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
70 //); // to add new tab
71 //$this->tabs = array(
72 // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
73 //); // to remove a tab
74 complete_head_from_modules($conf, $langs, null, $head, $h, 'bom@mrp');
75
76 complete_head_from_modules($conf, $langs, null, $head, $h, 'bom@mrp', 'remove');
77
78 return $head;
79}
80
81
82
83
91{
92 global $db, $langs, $conf;
93
94 $langs->load("mrp");
95
96 $h = 0;
97 $head = array();
98
99 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/bom/bom_card.php', ['id' => $object->id]);
100 $head[$h][1] = $langs->trans("BOM");
101 $head[$h][2] = 'card';
102 $h++;
103
104 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/bom/bom_net_needs.php', ['id' => $object->id]);
105 $head[$h][1] = $langs->trans("BOMNetNeeds");
106 $head[$h][2] = 'net_needs';
107 $h++;
108
109 if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) {
110 $nbNote = 0;
111 if (!empty($object->note_private)) {
112 $nbNote++;
113 }
114 if (!empty($object->note_public)) {
115 $nbNote++;
116 }
117 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/bom/bom_note.php', ['id' => $object->id]);
118 $head[$h][1] = $langs->trans('Notes');
119 if ($nbNote > 0) {
120 $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : '');
121 }
122 $head[$h][2] = 'note';
123 $h++;
124 }
125
126 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
127 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
128 $upload_dir = getMultidirOutput($object) . "/".dol_sanitizeFileName($object->ref);
129 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
130 $nbLinks = Link::count($db, $object->element, $object->id);
131 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/bom/bom_document.php', ['id' => $object->id]);
132 $head[$h][1] = $langs->trans('Documents');
133 if (($nbFiles + $nbLinks) > 0) {
134 $head[$h][1] .= (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>' : '');
135 }
136 $head[$h][2] = 'document';
137 $h++;
138
139 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/bom/bom_agenda.php', ['id' => $object->id]);
140 $head[$h][1] = $langs->trans("Events");
141 $head[$h][2] = 'agenda';
142 $h++;
143
144 // Show more tabs from modules
145 // Entries must be declared in modules descriptor with line
146 //$this->tabs = array(
147 // 'entity:+tabname:Title:@bom:/bom/mypage.php?id=__ID__'
148 //); // to add new tab
149 //$this->tabs = array(
150 // 'entity:-tabname:Title:@bom:/bom/mypage.php?id=__ID__'
151 //); // to remove a tab
152 complete_head_from_modules($conf, $langs, $object, $head, $h, 'bom');
153
154 complete_head_from_modules($conf, $langs, $object, $head, $h, 'bom', 'remove');
155
156 return $head;
157}
158
165{
166 ?>
167
168 <script type="text/javascript" language="javascript">
169
170 $(document).ready(function () {
171 function folderManage(element, onClose = 0) {
172 let id_bom_line = element.attr('id').replace('collapse-', '');
173 let TSubLines = $('[parentid="'+ id_bom_line +'"]');
174
175 if(element.html().indexOf('folder-open') <= 0 && onClose < 1) {
176 $('[parentid="'+ id_bom_line +'"]').show();
177 element.html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
178 }
179 else {
180 for (let i = 0; i < TSubLines.length; i++) {
181 let subBomFolder = $(TSubLines[i]).children('.linecoldescription').children('.collapse_bom');
182
183 if (subBomFolder.length > 0) {
184 onClose = 1
185 folderManage(subBomFolder, onClose);
186 }
187 }
188 TSubLines.hide();
189 element.html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
190 }
191 }
192
193 // When clicking on collapse
194 $(".collapse_bom").click(function() {
195 folderManage($(this));
196 return false;
197 });
198
199 // To Show all the sub bom lines
200 $("#show_all").click(function() {
201 console.log("We click on show all");
202 $("[class^=sub_bom_lines]").show();
203 $("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder-open')); ?>');
204 return false;
205 });
206
207 // To Hide all the sub bom lines
208 $("#hide_all").click(function() {
209 console.log("We click on hide all");
210 $("[class^=sub_bom_lines]").hide();
211 $("[class^=collapse_bom]").html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
212 return false;
213 });
214 });
215
216 </script>
217
218 <?php
219}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
mrpCollapseBomManagement()
Manage collapse bom display.
Definition bom.lib.php:164
bomAdminPrepareHead()
Prepare admin pages header.
Definition bom.lib.php:31
bomPrepareHead($object)
Prepare array of tabs for BillOfMaterials.
Definition bom.lib.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
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:64
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
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 a Dolibarr global constant string value.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:130