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