26 require
'../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/bom/lib/bom.lib.php';
33 $langs->loadLangs(array(
"mrp",
"other",
"stocks"));
37 $lineid =
GETPOST(
'lineid',
'int');
39 $action =
GETPOST(
'action',
'aZ09');
40 $confirm =
GETPOST(
'confirm',
'alpha');
41 $cancel =
GETPOST(
'cancel',
'aZ09');
42 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'bomnet_needs';
43 $backtopage =
GETPOST(
'backtopage',
'alpha');
47 $object =
new BOM($db);
51 $hookmanager->initHooks(array(
'bomnetneeds'));
54 $diroutputmassaction = $conf->bom->dir_output.
'/temp/massgeneration/'.$user->id;
57 $extrafields->fetch_name_optionals_label($object->table_element);
58 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
61 $search_all =
GETPOST(
"search_all",
'alpha');
63 foreach ($object->fields as $key => $val) {
64 if (
GETPOST(
'search_'.$key,
'alpha')) {
65 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
69 if (empty($action) && empty($id) && empty($ref)) {
74 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
75 if ($object->id > 0) {
76 $object->calculateCosts();
83 $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
84 $result =
restrictedArea($user,
'bom', $object->id, $object->table_element,
'',
'',
'rowid', $isdraft);
87 $permissionnote = $user->hasRight(
'bom',
'write');
88 $permissiondellink = $user->hasRight(
'bom',
'write');
89 $permissiontoadd = $user->hasRight(
'bom',
'write');
90 $permissiontodelete = $user->hasRight(
'bom',
'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
91 $upload_dir = $conf->bom->multidir_output[isset($object->entity) ? $object->entity : 1];
98 $parameters = array();
99 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
104 if (empty($reshook)) {
107 $backurlforlist = DOL_URL_ROOT.
'/bom/bom_list.php';
109 if (empty($backtopage) || ($cancel && empty($id))) {
110 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
111 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
112 $backtopage = $backurlforlist;
114 $backtopage = DOL_URL_ROOT.
'/bom/bom_net_needs.php?id='.($id > 0 ? $id :
'__ID__');
118 if ($action ==
'treeview') $object->getNetNeedsTree($TChildBom, 1);
119 else $object->getNetNeeds($TChildBom, 1);
130 $title = $langs->trans(
'BOM');
136 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
138 print
dol_get_fiche_head($head,
'net_needs', $langs->trans(
"BillOfMaterials"), -1,
'bom');
143 $parameters = array(
'formConfirm' =>
$formconfirm,
'lineid' => $lineid);
144 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
145 if (empty($reshook)) {
147 } elseif ($reshook > 0) {
157 $linkback =
'<a href="'.DOL_URL_ROOT.
'/bom/bom_list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
159 $morehtmlref =
'<div class="refidno">';
161 $morehtmlref .=
'</div>';
164 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
167 print
'<div class="fichecenter">';
168 print
'<div class="fichehalfleft">';
169 print
'<div class="underbanner clearboth"></div>';
170 print
'<table class="border centpercent tableforfield">'.
"\n";
173 $keyforbreak =
'duration';
174 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
176 print
'<tr><td>'.$form->textwithpicto($langs->trans(
"TotalCost"), $langs->trans(
"BOMTotalCost")).
'</td><td><span class="amount">'.
price($object->total_cost).
'</span></td></tr>';
177 print
'<tr><td>'.$langs->trans(
"UnitCost").
'</td><td>'.
price($object->unit_cost).
'</td></tr>';
180 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
186 print
'<div class="clearboth"></div>';
190 $viewlink =
dolGetButtonTitle($langs->trans(
'GroupByX', $langs->transnoentitiesnoconv(
"Products")),
'',
'fa fa-bars imgforviewmode', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&token='.
newToken(),
'', 1, array(
'morecss' =>
'reposition '.($action !==
'treeview' ?
'btnTitleSelected':
'')));
191 $viewlink .=
dolGetButtonTitle($langs->trans(
'TreeView'),
'',
'fa fa-stream imgforviewmode', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=treeview&token='.
newToken(),
'', 1, array(
'morecss' =>
'reposition marginleftonly '.($action ==
'treeview' ?
'btnTitleSelected':
'')));
198 $text_stock_options = $langs->trans(
"RealStockDesc").
'<br>';
199 $text_stock_options .= $langs->trans(
"RealStockWillAutomaticallyWhen").
'<br>';
200 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) ?
'- '.$langs->trans(
"DeStockOnShipment").
'<br>' :
'');
201 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) ?
'- '.$langs->trans(
"DeStockOnValidateOrder").
'<br>' :
'');
202 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_BILL) ?
'- '.$langs->trans(
"DeStockOnBill").
'<br>' :
'');
203 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) ?
'- '.$langs->trans(
"ReStockOnBill").
'<br>' :
'');
204 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) ?
'- '.$langs->trans(
"ReStockOnValidateOrder").
'<br>' :
'');
205 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) ?
'- '.$langs->trans(
"ReStockOnDispatchOrder").
'<br>' :
'');
206 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE) ?
'- '.$langs->trans(
"StockOnReception").
'<br>' :
'');
208 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
210 print
'<tr class="liste_titre nodrag nodrop">';
211 print
'<td class="linecoldescription">'.$langs->trans(
'Product');
212 if (!empty($conf->global->BOM_SUB_BOM) && $action ==
'treeview') {
213 print
' <a id="show_all" href="#">'.img_picto(
'',
'folder-open',
'class="paddingright"').$langs->trans(
"ExpandAll").
'</a> ';
214 print
'<a id="hide_all" href="#">'.img_picto(
'',
'folder',
'class="paddingright"').$langs->trans(
"UndoExpandAll").
'</a> ';
217 if ($action ==
'treeview') print
'<td class="left">'.$langs->trans(
'ProducedBy').
'</td>';
218 print
'<td class="linecolqty right">'.$langs->trans(
'Quantity').
'</td>';
219 print
'<td class="linecolstock right">'.$form->textwithpicto($langs->trans(
"PhysicalStock"), $text_stock_options, 1).
'</td>';
220 print
'<td class="linecoltheoricalstock right">'.$form->textwithpicto($langs->trans(
"VirtualStock"), $langs->trans(
"VirtualStockDesc")).
'</td>';
225 if (!empty($TChildBom)) {
226 if ($action ==
'treeview') {
227 foreach ($TChildBom as $fk_bom => $TProduct) {
228 $repeatChar =
' ';
229 if (!empty($TProduct[
'bom'])) {
231 $prod->fetch($TProduct[
'bom']->fk_product);
232 if ($TProduct[
'parentid'] != $object->id) print
'<tr class="sub_bom_lines oddeven" parentid="'.$TProduct[
'parentid'].
'">';
233 else print
'<tr class="oddeven">';
234 if ($action ==
'treeview') print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TProduct[
'level']).$prod->getNomUrl(1);
235 else print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TProduct[
'level']).$TProduct[
'bom']->getNomUrl(1);
236 print
' <a class="collapse_bom" id="collapse-'.$fk_bom.
'" href="#">';
240 if ($action ==
'treeview') print
'<td class="left">'.$TProduct[
'bom']->getNomUrl(1).
'</td>';
241 print
'<td class="linecolqty right">'.$TProduct[
'qty'].
'</td>';
242 print
'<td class="linecolstock right"></td>';
243 print
'<td class="linecoltheoricalstock right"></td>';
246 if (!empty($TProduct[
'product'])) {
247 foreach ($TProduct[
'product'] as $fk_product => $TInfos) {
249 $prod->fetch($fk_product);
250 $prod->load_virtual_stock();
251 if (empty($prod->stock_reel)) $prod->stock_reel = 0;
252 if ($fk_bom != $object->id) print
'<tr class="sub_bom_lines oddeven" parentid="'.$fk_bom.
'">';
253 else print
'<tr class="oddeven">';
254 print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TInfos[
'level']).$prod->getNomUrl(1).
'</td>';
255 if ($action ==
'treeview') print
'<td></td>';
256 print
'<td class="linecolqty right">'.$TInfos[
'qty'].
'</td>';
257 print
'<td class="linecolstock right">'.price2num($prod->stock_reel,
'MS').
'</td>';
258 print
'<td class="linecoltheoricalstock right">'.$prod->stock_theorique.
'</td>';
264 foreach ($TChildBom as $fk_product => $qty) {
266 $prod->fetch($fk_product);
267 $prod->load_virtual_stock();
268 if (empty($prod->stock_reel)) $prod->stock_reel = 0;
269 print
'<tr class="oddeven">';
270 print
'<td class="linecoldescription">'.$prod->getNomUrl(1).
'</td>';
271 print
'<td class="linecolqty right">'.$qty.
'</td>';
272 print
'<td class="linecolstock right">'.price2num($prod->stock_reel,
'MS').
'</td>';
273 print
'<td class="linecoltheoricalstock right">'.$prod->stock_theorique.
'</td>';
286 print
'<div class="tabsAction">'.
"\n";
287 $parameters = array();
288 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
297 <script
type=
"text/javascript" language=
"javascript">
298 $(document).ready(
function() {
300 function folderManage(element) {
301 var id_bom_line = element.attr(
'id').replace(
'collapse-',
'');
302 let TSubLines = $(
'[parentid="'+ id_bom_line +
'"]');
304 if(element.html().indexOf(
'folder-open') <= 0) {
305 $(
'[parentid="'+ id_bom_line +
'"]').show();
306 element.html(
'<?php echo dol_escape_js(img_picto('', 'folder-open
')); ?>');
309 for (let i = 0; i < TSubLines.length; i++) {
310 let subBomFolder = $(TSubLines[i]).children(
'.linecoldescription').children(
'.collapse_bom');
311 if (subBomFolder.length > 0) {
312 folderManage(subBomFolder);
316 element.html(
'<?php echo dol_escape_js(img_picto('', 'folder
')); ?>');
321 $(
".collapse_bom").click(
function() {
322 folderManage($(
this));
327 $(
"#show_all").click(
function() {
328 console.log(
"We click on show all");
329 $(
"[class^=sub_bom_lines]").show();
330 $(
"[class^=collapse_bom]").html(
'<?php echo dol_escape_js(img_picto('', 'folder-open
')); ?>');
335 $(
"#hide_all").click(
function() {
336 console.log(
"We click on hide all");
337 $(
"[class^=sub_bom_lines]").hide();
338 $(
"[class^=collapse_bom]").html(
'<?php echo dol_escape_js(img_picto('', 'folder
')); ?>');