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';
42$langs->loadLangs(array(
"mrp",
"other",
"stocks"));
48$action =
GETPOST(
'action',
'aZ09');
49$confirm =
GETPOST(
'confirm',
'alpha');
50$cancel =
GETPOST(
'cancel',
'aZ09');
51$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'bomnet_needs';
52$backtopage =
GETPOST(
'backtopage',
'alpha');
60$hookmanager->initHooks(array(
'bomnetneeds'));
63$diroutputmassaction =
$conf->bom->dir_output.
'/temp/massgeneration/'.$user->id;
66$extrafields->fetch_name_optionals_label(
$object->table_element);
67$search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
70$search_all =
GETPOST(
"search_all",
'alpha');
72foreach (
$object->fields as $key => $val) {
73 if (
GETPOST(
'search_'.$key,
'alpha')) {
74 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
78if (empty($action) && empty($id) && empty($ref)) {
83include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
92$isdraft = ((
$object->status == $object::STATUS_DRAFT) ? 1 : 0);
96$permissionnote = $user->hasRight(
'bom',
'write');
97$permissiondellink = $user->hasRight(
'bom',
'write');
98$permissiontoadd = $user->hasRight(
'bom',
'write');
99$permissiontodelete = $user->hasRight(
'bom',
'delete') || ($permissiontoadd && isset(
$object->status) &&
$object->status == $object::STATUS_DRAFT);
107$parameters = array();
108$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
113if (empty($reshook)) {
116 $backurlforlist = DOL_URL_ROOT.
'/bom/bom_list.php';
118 if (empty($backtopage) || ($cancel && empty($id))) {
119 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
120 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
121 $backtopage = $backurlforlist;
123 $backtopage = DOL_URL_ROOT.
'/bom/bom_net_needs.php?id='.(
$id > 0 ?
$id :
'__ID__');
134$form =
new Form($db);
137$title = $langs->trans(
'BOM');
138$help_url =
'EN:Module_BOM';
140llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-bom page-net_needs');
144if ($action ==
'treeview') {
145 $object->getNetNeedsTree($TChildBom, 1);
147 $object->getNetNeeds($TChildBom, 1);
152if (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
154 print
dol_get_fiche_head($head,
'net_needs', $langs->trans(
"BillOfMaterials"), -1,
'bom');
159 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
160 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
161 if (empty($reshook)) {
162 $formconfirm .= $hookmanager->resPrint;
163 } elseif ($reshook > 0) {
164 $formconfirm = $hookmanager->resPrint;
173 $linkback =
'<a href="'.DOL_URL_ROOT.
'/bom/bom_list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
175 $morehtmlref =
'<div class="refidno">';
177 $morehtmlref .=
'</div>';
180 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
183 print
'<div class="fichecenter">';
184 print
'<div class="fichehalfleft">';
185 print
'<div class="underbanner clearboth"></div>';
186 print
'<table class="border centpercent tableforfield">'.
"\n";
189 $keyforbreak =
'duration';
190 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
193 print
'<tr><td>'.$form->textwithpicto($langs->trans(
"ManufacturingCost"), $langs->trans(
"BOMTotalCost")).
'</td><td><span class="amount">';
197 print
' <span class="opacitymedium">('.$form->textwithpicto(
price(
$object->unit_cost), $langs->trans(
"ManufacturingUnitCost"), 1,
'help',
'').
')</span>';
203 $manufacturedvalued =
'';
204 if (!empty(
$object->product)) {
206 $tmparray =
$object->product->getSellPrice($mysoc, $mysoc);
207 $manufacturedvalued = $tmparray[
'pu_ht'] *
$object->qty;
209 print
'<tr><td>'.$langs->trans(
"ManufacturingGeneratedValue").
'</td><td>'.
price($manufacturedvalued).
'</td></tr>';
212 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
218 print
'<div class="clearboth"></div>';
222 $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' :
'')));
223 $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' :
'')));
230 $text_stock_options = $langs->trans(
"RealStockDesc").
'<br>';
231 $text_stock_options .= $langs->trans(
"RealStockWillAutomaticallyWhen").
'<br>';
232 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT') ||
getDolGlobalString(
'STOCK_CALCULATE_ON_SHIPMENT_CLOSE') ?
'- '.$langs->trans(
"DeStockOnShipment").
'<br>' :
'');
233 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_VALIDATE_ORDER') ?
'- '.$langs->trans(
"DeStockOnValidateOrder").
'<br>' :
'');
234 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL') ?
'- '.$langs->trans(
"DeStockOnBill").
'<br>' :
'');
235 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_BILL') ?
'- '.$langs->trans(
"ReStockOnBill").
'<br>' :
'');
236 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') ?
'- '.$langs->trans(
"ReStockOnValidateOrder").
'<br>' :
'');
237 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') ?
'- '.$langs->trans(
"ReStockOnDispatchOrder").
'<br>' :
'');
238 $text_stock_options .= (
getDolGlobalString(
'STOCK_CALCULATE_ON_RECEPTION') ||
getDolGlobalString(
'STOCK_CALCULATE_ON_RECEPTION_CLOSE') ?
'- '.$langs->trans(
"StockOnReception").
'<br>' :
'');
240 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
242 print
'<tr class="liste_titre nodrag nodrop">';
243 print
'<td class="linecoldescription">'.$langs->trans(
'Product');
245 print
' <a id="show_all" href="#">'.img_picto(
'',
'folder-open',
'class="paddingright"').$langs->trans(
"ExpandAll").
'</a> ';
246 print
'<a id="hide_all" href="#">'.img_picto(
'',
'folder',
'class="paddingright"').$langs->trans(
"UndoExpandAll").
'</a> ';
249 if ($action ==
'treeview') {
250 print
'<td class="left">'.$langs->trans(
'ProducedBy').
'</td>';
252 print
'<td class="linecolqty right">'.$langs->trans(
'Quantity').
'</td>';
254 print
'<td class="linecolstock right">'.$form->textwithpicto($langs->trans(
"PhysicalStock"), $text_stock_options, 1).
'</td>';
255 print
'<td class="linecoltheoricalstock right">'.$form->textwithpicto($langs->trans(
"VirtualStock"), $langs->trans(
"VirtualStockDesc")).
'</td>';
260 if (count($TChildBom) > 0) {
261 if ($action ==
'treeview') {
262 foreach ($TChildBom as $fk_bom => $TProduct) {
263 $repeatChar =
' ';
264 if (!empty($TProduct[
'bom'])) {
266 $prod->fetch($TProduct[
'bom']->fk_product);
267 if ($TProduct[
'parentid'] !=
$object->id) {
268 print
'<tr class="sub_bom_lines oddeven" parentid="'.$TProduct[
'parentid'].
'">';
270 print
'<tr class="oddeven">';
272 if ($action ==
'treeview') {
273 print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TProduct[
'level']).$prod->getNomUrl(1);
275 print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TProduct[
'level']).$TProduct[
'bom']->getNomUrl(1);
277 print
' <a class="collapse_bom" id="collapse-'.$fk_bom.
'" href="#">';
281 if ($action ==
'treeview') {
282 print
'<td class="left">'.$TProduct[
'bom']->getNomUrl(1).
'</td>';
284 print
'<td class="linecolqty right">'.$TProduct[
'qty'].
'</td>';
287 print
'<td class="linecolstock right"></td>';
288 print
'<td class="linecoltheoricalstock right"></td>';
291 if (!empty($TProduct[
'product'])) {
292 foreach ($TProduct[
'product'] as $fk_product => $TInfos) {
294 $prod->fetch($fk_product);
295 $prod->load_virtual_stock();
296 if (empty($prod->stock_reel)) {
297 $prod->stock_reel = 0;
300 print
'<tr class="sub_bom_lines oddeven" parentid="'.$fk_bom.
'">';
302 print
'<tr class="oddeven">';
304 print
'<td class="linecoldescription">'.str_repeat($repeatChar, $TInfos[
'level']).$prod->getNomUrl(1).
'</td>';
305 if ($action ==
'treeview') {
308 print
'<td class="linecolqty right">'.$TInfos[
'qty'].
'</td>';
311 print
'<td class="linecolstock right">'.price2num($prod->stock_reel,
'MS').
'</td>';
312 print
'<td class="linecoltheoricalstock right">'.$prod->stock_theorique.
'</td>';
318 foreach ($TChildBom as $fk_product => $elem) {
320 $prod->fetch($fk_product);
321 $prod->load_virtual_stock();
322 if (empty($prod->stock_reel)) {
323 $prod->stock_reel = 0;
325 print
'<tr class="oddeven">';
326 print
'<td class="linecoldescription">'.$prod->getNomUrl(1).
'</td>';
327 print
'<td class="linecolqty right">'.$elem[
'qty'].
'</td>';
331 require_once DOL_DOCUMENT_ROOT.
'/core/class/cunits.class.php';
333 $unit->fetch($elem[
'fk_unit']);
334 print(isset($unit->label) ?
" ".$langs->trans(ucwords($unit->label)).
" " :
'');
337 print
'<td class="linecolstock right">'.price2num($prod->stock_reel,
'MS').
'</td>';
338 print
'<td class="linecoltheoricalstock right">'.$prod->stock_theorique.
'</td>';
351 print
'<div class="tabsAction">'.
"\n";
352 $parameters = array();
353 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
359 <script
type=
"text/javascript" language=
"javascript">
360 $(document).ready(
function() {
362 function folderManage(element) {
363 var id_bom_line = element.attr(
'id').replace(
'collapse-',
'');
364 let TSubLines = $(
'[parentid="'+ id_bom_line +
'"]');
366 if(element.html().indexOf(
'folder-open') <= 0) {
367 $(
'[parentid="'+ id_bom_line +
'"]').show();
368 element.html(
'<?php echo dol_escape_js(img_picto('', 'folder-open
')); ?>');
371 for (let i = 0; i < TSubLines.length; i++) {
372 let subBomFolder = $(TSubLines[i]).children(
'.linecoldescription').children(
'.collapse_bom');
373 if (subBomFolder.length > 0) {
374 folderManage(subBomFolder);
378 element.html(
'<?php echo dol_escape_js(img_picto('', 'folder
')); ?>');
383 $(
".collapse_bom").click(
function() {
384 folderManage($(
this));
389 $(
"#show_all").click(
function() {
390 console.log(
"We click on show all");
391 $(
"[class^=sub_bom_lines]").show();
392 $(
"[class^=collapse_bom]").html(
'<?php echo dol_escape_js(img_picto('', 'folder-open
')); ?>');
397 $(
"#hide_all").click(
function() {
398 console.log(
"We click on hide all");
399 $(
"[class^=sub_bom_lines]").hide();
400 $(
"[class^=collapse_bom]").html(
'<?php echo dol_escape_js(img_picto('', 'folder
')); ?>');
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
bomPrepareHead($object)
Prepare array of tabs for BillOfMaterials.
Class of dictionary type of thirdparty (used by imports)
Class to manage products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.