26require
'../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
30require_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');
63foreach ($object->fields as $key => $val) {
64 if (
GETPOST(
'search_'.$key,
'alpha')) {
65 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
69if (empty($action) && empty($id) && empty($ref)) {
74include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
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];
99$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
104if (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') {
119 $object->getNetNeedsTree($TChildBom, 1);
121 $object->getNetNeeds($TChildBom, 1);
130$form =
new Form($db);
133$title = $langs->trans(
'BOM');
134$help_url =
'EN:Module_BOM';
139if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
141 print
dol_get_fiche_head($head,
'net_needs', $langs->trans(
"BillOfMaterials"), -1,
'bom');
146 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
147 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
148 if (empty($reshook)) {
149 $formconfirm .= $hookmanager->resPrint;
150 } elseif ($reshook > 0) {
151 $formconfirm = $hookmanager->resPrint;
160 $linkback =
'<a href="'.DOL_URL_ROOT.
'/bom/bom_list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
162 $morehtmlref =
'<div class="refidno">';
164 $morehtmlref .=
'</div>';
167 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
170 print
'<div class="fichecenter">';
171 print
'<div class="fichehalfleft">';
172 print
'<div class="underbanner clearboth"></div>';
173 print
'<table class="border centpercent tableforfield">'.
"\n";
176 $keyforbreak =
'duration';
177 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
179 print
'<tr><td>'.$form->textwithpicto($langs->trans(
"TotalCost"), $langs->trans(
"BOMTotalCost")).
'</td><td><span class="amount">'.
price($object->total_cost).
'</span></td></tr>';
180 print
'<tr><td>'.$langs->trans(
"UnitCost").
'</td><td>'.
price($object->unit_cost).
'</td></tr>';
183 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
189 print
'<div class="clearboth"></div>';
193 $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' :
'')));
194 $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' :
'')));
201 $text_stock_options = $langs->trans(
"RealStockDesc").
'<br>';
202 $text_stock_options .= $langs->trans(
"RealStockWillAutomaticallyWhen").
'<br>';
203 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT') ||
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ?
'- '.$langs->trans(
"DeStockOnShipment").
'<br>' :
'');
204 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') ?
'- '.$langs->trans(
"DeStockOnValidateOrder").
'<br>' :
'');
205 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL') ?
'- '.$langs->trans(
"DeStockOnBill").
'<br>' :
'');
206 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') ?
'- '.$langs->trans(
"ReStockOnBill").
'<br>' :
'');
207 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ?
'- '.$langs->trans(
"ReStockOnValidateOrder").
'<br>' :
'');
208 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ?
'- '.$langs->trans(
"ReStockOnDispatchOrder").
'<br>' :
'');
209 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_RECEPTION') ||
getDolGlobalString(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') ?
'- '.$langs->trans(
"StockOnReception").
'<br>' :
'');
211 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
213 print
'<tr class="liste_titre nodrag nodrop">';
214 print
'<td class="linecoldescription">'.$langs->trans(
'Product');
216 print
' <a id="show_all" href="#">'.img_picto(
'',
'folder-open',
'class="paddingright"').$langs->trans(
"ExpandAll").
'</a> ';
217 print
'<a id="hide_all" href="#">'.img_picto(
'',
'folder',
'class="paddingright"').$langs->trans(
"UndoExpandAll").
'</a> ';
220 if ($action ==
'treeview') {
221 print
'<td class="left">'.$langs->trans(
'ProducedBy').
'</td>';
223 print
'<td class="linecolqty right">'.$langs->trans(
'Quantity').
'</td>';
224 print
'<td class="linecolstock right">'.$form->textwithpicto($langs->trans(
"PhysicalStock"), $text_stock_options, 1).
'</td>';
225 print
'<td class="linecoltheoricalstock right">'.$form->textwithpicto($langs->trans(
"VirtualStock"), $langs->trans(
"VirtualStockDesc")).
'</td>';
230 if (!empty($TChildBom)) {
231 if ($action ==
'treeview') {
232 foreach ($TChildBom as $fk_bom => $TProduct) {
233 $repeatChar =
' ';
234 if (!empty($TProduct[
'bom'])) {
236 $prod->fetch($TProduct[
'bom']->fk_product);
237 if ($TProduct[
'parentid'] != $object->id) {
238 print
'<tr class="sub_bom_lines oddeven" parentid="'.$TProduct[
'parentid'].
'">';
240 print
'<tr class="oddeven">';
242 if ($action ==
'treeview') {
243 print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TProduct[
'level']).$prod->getNomUrl(1);
245 print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TProduct[
'level']).$TProduct[
'bom']->getNomUrl(1);
247 print
' <a class="collapse_bom" id="collapse-'.$fk_bom.
'" href="#">';
251 if ($action ==
'treeview') {
252 print
'<td class="left">'.$TProduct[
'bom']->getNomUrl(1).
'</td>';
254 print
'<td class="linecolqty right">'.$TProduct[
'qty'].
'</td>';
255 print
'<td class="linecolstock right"></td>';
256 print
'<td class="linecoltheoricalstock right"></td>';
259 if (!empty($TProduct[
'product'])) {
260 foreach ($TProduct[
'product'] as $fk_product => $TInfos) {
262 $prod->fetch($fk_product);
263 $prod->load_virtual_stock();
264 if (empty($prod->stock_reel)) {
265 $prod->stock_reel = 0;
267 if ($fk_bom != $object->id) {
268 print
'<tr class="sub_bom_lines oddeven" parentid="'.$fk_bom.
'">';
270 print
'<tr class="oddeven">';
272 print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TInfos[
'level']).$prod->getNomUrl(1).
'</td>';
273 if ($action ==
'treeview') {
276 print
'<td class="linecolqty right">'.$TInfos[
'qty'].
'</td>';
277 print
'<td class="linecolstock right">'.price2num($prod->stock_reel,
'MS').
'</td>';
278 print
'<td class="linecoltheoricalstock right">'.$prod->stock_theorique.
'</td>';
284 foreach ($TChildBom as $fk_product => $qty) {
286 $prod->fetch($fk_product);
287 $prod->load_virtual_stock();
288 if (empty($prod->stock_reel)) {
289 $prod->stock_reel = 0;
291 print
'<tr class="oddeven">';
292 print
'<td class="linecoldescription">'.$prod->getNomUrl(1).
'</td>';
293 print
'<td class="linecolqty right">'.$qty.
'</td>';
294 print
'<td class="linecolstock right">'.price2num($prod->stock_reel,
'MS').
'</td>';
295 print
'<td class="linecoltheoricalstock right">'.$prod->stock_theorique.
'</td>';
308 print
'<div class="tabsAction">'.
"\n";
309 $parameters = array();
310 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
316 <script
type=
"text/javascript" language=
"javascript">
317 $(document).ready(
function() {
319 function folderManage(element) {
320 var id_bom_line = element.attr(
'id').replace(
'collapse-',
'');
321 let TSubLines = $(
'[parentid="'+ id_bom_line +
'"]');
323 if(element.html().indexOf(
'folder-open') <= 0) {
324 $(
'[parentid="'+ id_bom_line +
'"]').show();
325 element.html(
'<?php echo dol_escape_js(img_picto('', 'folder-open
')); ?>');
328 for (let i = 0; i < TSubLines.length; i++) {
329 let subBomFolder = $(TSubLines[i]).children(
'.linecoldescription').children(
'.collapse_bom');
330 if (subBomFolder.length > 0) {
331 folderManage(subBomFolder);
335 element.html(
'<?php echo dol_escape_js(img_picto('', 'folder
')); ?>');
340 $(
".collapse_bom").click(
function() {
341 folderManage($(
this));
346 $(
"#show_all").click(
function() {
347 console.log(
"We click on show all");
348 $(
"[class^=sub_bom_lines]").show();
349 $(
"[class^=collapse_bom]").html(
'<?php echo dol_escape_js(img_picto('', 'folder-open
')); ?>');
354 $(
"#hide_all").click(
function() {
355 console.log(
"We click on hide all");
356 $(
"[class^=sub_bom_lines]").hide();
357 $(
"[class^=collapse_bom]").html(
'<?php echo dol_escape_js(img_picto('', 'folder
')); ?>');
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
bomPrepareHead($object)
Prepare array of tabs for BillOfMaterials.
Class to manage products or services.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.