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');
48 $object =
new BOM($db);
50 $diroutputmassaction = $conf->bom->dir_output.
'/temp/massgeneration/'.$user->id;
51 $hookmanager->initHooks(array(
'bomnetneeds'));
53 $extrafields->fetch_name_optionals_label($object->table_element);
54 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
57 $search_all =
GETPOST(
"search_all",
'alpha');
59 foreach ($object->fields as $key => $val) {
60 if (
GETPOST(
'search_'.$key,
'alpha')) {
61 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
65 if (empty($action) && empty($id) && empty($ref)) {
70 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
71 if ($object->id > 0) {
72 $object->calculateCosts();
80 $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
81 $result =
restrictedArea($user,
'bom', $object->id,
'bom_bom',
'',
'',
'rowid', $isdraft);
83 $permissionnote = $user->rights->bom->write;
84 $permissiondellink = $user->rights->bom->write;
85 $permissiontoadd = $user->rights->bom->write;
86 $permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
87 $upload_dir = $conf->bom->multidir_output[isset($object->entity) ? $object->entity : 1];
94 $parameters = array();
95 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
100 if (empty($reshook)) {
103 $backurlforlist = DOL_URL_ROOT.
'/bom/bom_list.php';
105 if (empty($backtopage) || ($cancel && empty($id))) {
106 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
107 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
108 $backtopage = $backurlforlist;
110 $backtopage = DOL_URL_ROOT.
'/bom/bom_net_needs.php?id='.($id > 0 ? $id :
'__ID__');
114 if ($action ==
'treeview') $object->getNetNeedsTree($TChildBom, 1);
115 else $object->getNetNeeds($TChildBom, 1);
127 $title = $langs->trans(
'BOM');
134 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
136 print
dol_get_fiche_head($head,
'net_needs', $langs->trans(
"BillOfMaterials"), -1,
'bom');
141 $parameters = array(
'formConfirm' =>
$formconfirm,
'lineid' => $lineid);
142 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
143 if (empty($reshook)) {
145 } elseif ($reshook > 0) {
155 $linkback =
'<a href="'.DOL_URL_ROOT.
'/bom/bom_list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
157 $morehtmlref =
'<div class="refidno">';
159 $morehtmlref .=
'</div>';
162 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
165 print
'<div class="fichecenter">';
166 print
'<div class="fichehalfleft">';
167 print
'<div class="underbanner clearboth"></div>';
168 print
'<table class="border centpercent tableforfield">'.
"\n";
171 $keyforbreak =
'duration';
172 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
174 print
'<tr><td>'.$form->textwithpicto($langs->trans(
"TotalCost"), $langs->trans(
"BOMTotalCost")).
'</td><td><span class="amount">'.
price($object->total_cost).
'</span></td></tr>';
175 print
'<tr><td>'.$langs->trans(
"UnitCost").
'</td><td>'.
price($object->unit_cost).
'</td></tr>';
178 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
184 print
'<div class="clearboth"></div>';
188 $viewlink =
dolGetButtonTitle($langs->trans(
'GroupByProduct'),
'',
'fa fa-bars imgforviewmode', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&token='.
newToken(),
'', 1, array(
'morecss' =>
'reposition '.($action !==
'treeview' ?
'btnTitleSelected':
'')));
189 $viewlink .=
dolGetButtonTitle($langs->trans(
'TreeStructure'),
'',
'fa fa-stream imgforviewmode', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=treeview&token='.
newToken(),
'', 1, array(
'morecss' =>
'reposition marginleftonly '.($action ==
'treeview' ?
'btnTitleSelected':
'')));
196 $text_stock_options = $langs->trans(
"RealStockDesc").
'<br>';
197 $text_stock_options .= $langs->trans(
"RealStockWillAutomaticallyWhen").
'<br>';
198 $text_stock_options .= (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE) ?
'- '.$langs->trans(
"DeStockOnShipment").
'<br>' :
'');
199 $text_stock_options .= (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) ?
'- '.$langs->trans(
"DeStockOnValidateOrder").
'<br>' :
'');
200 $text_stock_options .= (! empty($conf->global->STOCK_CALCULATE_ON_BILL) ?
'- '.$langs->trans(
"DeStockOnBill").
'<br>' :
'');
201 $text_stock_options .= (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) ?
'- '.$langs->trans(
"ReStockOnBill").
'<br>' :
'');
202 $text_stock_options .= (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) ?
'- '.$langs->trans(
"ReStockOnValidateOrder").
'<br>' :
'');
203 $text_stock_options .= (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) ?
'- '.$langs->trans(
"ReStockOnDispatchOrder").
'<br>' :
'');
204 $text_stock_options .= (!empty($conf->global->STOCK_CALCULATE_ON_RECEPTION) || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE) ?
'- '.$langs->trans(
"StockOnReception").
'<br>' :
'');
206 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
208 print
'<tr class="liste_titre nodrag nodrop">';
209 print
'<td class="linecoldescription">'.$langs->trans(
'Product');
210 if (! empty($conf->global->BOM_SUB_BOM) && $action ==
'treeview') {
211 print
' <a id="show_all" href="#">'.img_picto(
'',
'folder-open',
'class="paddingright"').$langs->trans(
"ExpandAll").
'</a> ';
212 print
'<a id="hide_all" href="#">'.img_picto(
'',
'folder',
'class="paddingright"').$langs->trans(
"UndoExpandAll").
'</a> ';
215 print
'<td class="linecolqty right">'.$langs->trans(
'Quantity').
'</td>';
216 print
'<td class="linecolstock right">'.$form->textwithpicto($langs->trans(
"PhysicalStock"), $text_stock_options, 1).
'</td>';
217 print
'<td class="linecoltheoricalstock right">'.$form->textwithpicto($langs->trans(
"VirtualStock"), $langs->trans(
"VirtualStockDesc")).
'</td>';
219 if (! empty($TChildBom)) {
220 if ($action ==
'treeview') {
221 foreach ($TChildBom as $fk_bom => $TProduct) {
222 $repeatChar =
' ';
223 if (! empty($TProduct[
'bom'])) {
224 if ($TProduct[
'parentid'] != $object->id) print
'<tr class="sub_bom_lines oddeven" parentid="'.$TProduct[
'parentid'].
'">';
225 else print
'<tr class="oddeven">';
226 print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TProduct[
'level']).$TProduct[
'bom']->getNomUrl(1);
227 print
' <a class="collapse_bom" id="collapse-'.$fk_bom.
'" href="#">';
231 print
'<td class="linecolqty right">'.$TProduct[
'qty'].
'</td>';
232 print
'<td class="linecolstock right"></td>';
233 print
'<td class="linecoltheoricalstock right"></td>';
236 if (! empty($TProduct[
'product'])) {
237 foreach ($TProduct[
'product'] as $fk_product => $TInfos) {
239 $prod->fetch($fk_product);
240 $prod->load_virtual_stock();
241 if (empty($prod->stock_reel)) $prod->stock_reel = 0;
242 if ($fk_bom != $object->id) print
'<tr class="sub_bom_lines oddeven" parentid="'.$fk_bom.
'">';
243 else print
'<tr class="oddeven">';
244 print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TInfos[
'level']).$prod->getNomUrl(1).
'</td>';
245 print
'<td class="linecolqty right">'.$TInfos[
'qty'].
'</td>';
246 print
'<td class="linecolstock right">'.price2num($prod->stock_reel,
'MS').
'</td>';
247 print
'<td class="linecoltheoricalstock right">'.$prod->stock_theorique.
'</td>';
253 foreach ($TChildBom as $fk_product => $qty) {
255 $prod->fetch($fk_product);
256 $prod->load_virtual_stock();
257 if (empty($prod->stock_reel)) $prod->stock_reel = 0;
258 print
'<tr class="oddeven">';
259 print
'<td class="linecoldescription">'.$prod->getNomUrl(1).
'</td>';
260 print
'<td class="linecolqty right">'.$qty.
'</td>';
261 print
'<td class="linecolstock right">'.price2num($prod->stock_reel,
'MS').
'</td>';
262 print
'<td class="linecoltheoricalstock right">'.$prod->stock_theorique.
'</td>';
275 print
'<div class="tabsAction">'.
"\n";
276 $parameters = array();
277 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
286 <script
type=
"text/javascript" language=
"javascript">
287 $(document).ready(
function() {
289 $(
".collapse_bom").click(
function() {
290 console.log(
"We click on collapse");
291 var id_bom_line = $(
this).attr(
'id').replace(
'collapse-',
'');
292 console.log($(
this).html().indexOf(
'folder-open'));
293 if($(
this).html().indexOf(
'folder-open') <= 0) {
294 $(
'[parentid="'+ id_bom_line +
'"]').show();
295 $(
this).html(
'<?php echo dol_escape_js(img_picto('', 'folder-open
')); ?>');
298 $(
'[parentid="'+ id_bom_line +
'"]').hide();
299 $(
this).html(
'<?php echo dol_escape_js(img_picto('', 'folder
')); ?>');
306 $(
"#show_all").click(
function() {
307 console.log(
"We click on show all");
308 $(
"[class^=sub_bom_lines]").show();
309 $(
"[class^=collapse_bom]").html(
'<?php echo dol_escape_js(img_picto('', 'folder-open
')); ?>');
314 $(
"#hide_all").click(
function() {
315 console.log(
"We click on hide all");
316 $(
"[class^=sub_bom_lines]").hide();
317 $(
"[class^=collapse_bom]").html(
'<?php echo dol_escape_js(img_picto('', 'folder
')); ?>');