dolibarr  16.0.5
bom_net_needs.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
25 // Load Dolibarr environment
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';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("mrp", "other", "stocks"));
34 
35 // Get parameters
36 $id = GETPOST('id', 'int');
37 $lineid = GETPOST('lineid', 'int');
38 $ref = GETPOST('ref', 'alpha');
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'; // To manage different context of search
43 $backtopage = GETPOST('backtopage', 'alpha');
44 
45 
46 
47 // Initialize technical objects
48 $object = new BOM($db);
49 $extrafields = new ExtraFields($db);
50 $diroutputmassaction = $conf->bom->dir_output.'/temp/massgeneration/'.$user->id;
51 $hookmanager->initHooks(array('bomnetneeds')); // Note that conf->hooks_modules contains array
52 // Fetch optionals attributes and labels
53 $extrafields->fetch_name_optionals_label($object->table_element);
54 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
55 
56 // Initialize array of search criterias
57 $search_all = GETPOST("search_all", 'alpha');
58 $search = array();
59 foreach ($object->fields as $key => $val) {
60  if (GETPOST('search_'.$key, 'alpha')) {
61  $search[$key] = GETPOST('search_'.$key, 'alpha');
62  }
63 }
64 
65 if (empty($action) && empty($id) && empty($ref)) {
66  $action = 'view';
67 }
68 
69 // Load object
70 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
71 if ($object->id > 0) {
72  $object->calculateCosts();
73 }
74 
75 
76 
77 // Security check - Protection if external user
78 //if ($user->socid > 0) accessforbidden();
79 //if ($user->socid > 0) $socid = $user->socid;
80 $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
81 $result = restrictedArea($user, 'bom', $object->id, 'bom_bom', '', '', 'rowid', $isdraft);
82 
83 $permissionnote = $user->rights->bom->write; // Used by the include of actions_setnotes.inc.php
84 $permissiondellink = $user->rights->bom->write; // Used by the include of actions_dellink.inc.php
85 $permissiontoadd = $user->rights->bom->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
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];
88 
89 
90 /*
91  * Actions
92  */
93 
94 $parameters = array();
95 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
96 if ($reshook < 0) {
97  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
98 }
99 
100 if (empty($reshook)) {
101  $error = 0;
102 
103  $backurlforlist = DOL_URL_ROOT.'/bom/bom_list.php';
104 
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;
109  } else {
110  $backtopage = DOL_URL_ROOT.'/bom/bom_net_needs.php?id='.($id > 0 ? $id : '__ID__');
111  }
112  }
113  }
114  if ($action == 'treeview') $object->getNetNeedsTree($TChildBom, 1);
115  else $object->getNetNeeds($TChildBom, 1);
116 }
117 
118 
119 /*
120  * View
121  */
122 
123 $form = new Form($db);
124 $formfile = new FormFile($db);
125 
126 
127 $title = $langs->trans('BOM');
128 $help_url ='EN:Module_BOM';
129 llxHeader('', $title, $help_url);
130 
131 
132 
133 // Part to show record
134 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
135  $head = bomPrepareHead($object);
136  print dol_get_fiche_head($head, 'net_needs', $langs->trans("BillOfMaterials"), -1, 'bom');
137 
138  $formconfirm = '';
139 
140  // Call Hook formConfirm
141  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
142  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
143  if (empty($reshook)) {
144  $formconfirm .= $hookmanager->resPrint;
145  } elseif ($reshook > 0) {
146  $formconfirm = $hookmanager->resPrint;
147  }
148 
149  // Print form confirm
150  print $formconfirm;
151 
152 
153  // Object card
154  // ------------------------------------------------------------
155  $linkback = '<a href="'.DOL_URL_ROOT.'/bom/bom_list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
156 
157  $morehtmlref = '<div class="refidno">';
158 
159  $morehtmlref .= '</div>';
160 
161 
162  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
163 
164 
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";
169 
170  // Common attributes
171  $keyforbreak = 'duration';
172  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
173 
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>';
176 
177  // Other attributes
178  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
179 
180  print '</table>';
181  print '</div>';
182  print '</div>';
183 
184  print '<div class="clearboth"></div>';
185 
186  print dol_get_fiche_end();
187 
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':'')));
190 
191  print load_fiche_titre($langs->trans("BOMNetNeeds"), $viewlink, '');
192 
193  /*
194  * Lines
195  */
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>' : '');
205 
206  print '<table id="tablelines" class="noborder noshadow" width="100%">';
207  print "<thead>\n";
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 ' &nbsp; <a id="show_all" href="#">'.img_picto('', 'folder-open', 'class="paddingright"').$langs->trans("ExpandAll").'</a>&nbsp;&nbsp;';
212  print '<a id="hide_all" href="#">'.img_picto('', 'folder', 'class="paddingright"').$langs->trans("UndoExpandAll").'</a>&nbsp;';
213  }
214  print '</td>';
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>';
218  print '</tr>';
219  if (! empty($TChildBom)) {
220  if ($action == 'treeview') {
221  foreach ($TChildBom as $fk_bom => $TProduct) {
222  $repeatChar = '&emsp;';
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="#">';
228  print img_picto('', 'folder-open');
229  print '</a>';
230  print '</td>';
231  print '<td class="linecolqty right">'.$TProduct['qty'].'</td>';
232  print '<td class="linecolstock right"></td>';
233  print '<td class="linecoltheoricalstock right"></td>';
234  print '</tr>';
235  }
236  if (! empty($TProduct['product'])) {
237  foreach ($TProduct['product'] as $fk_product => $TInfos) {
238  $prod = new Product($db);
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>';
248  print '</tr>';
249  }
250  }
251  }
252  } else {
253  foreach ($TChildBom as $fk_product => $qty) {
254  $prod = new Product($db);
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>';
263  print '</tr>';
264  }
265  }
266  }
267  print '</thead>';
268  print '</table>';
269 
270 
271 
272  /*
273  * ButAction
274  */
275  print '<div class="tabsAction">'."\n";
276  $parameters = array();
277  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
278  if ($reshook < 0) {
279  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
280  }
281  print '</div>';
282 
283 
284  ?>
285 
286  <script type="text/javascript" language="javascript">
287  $(document).ready(function() {
288  // When clicking on collapse
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')); ?>');
296  }
297  else {
298  $('[parentid="'+ id_bom_line +'"]').hide();
299  $(this).html('<?php echo dol_escape_js(img_picto('', 'folder')); ?>');
300  }
301 
302  return false;
303  });
304 
305  // To Show all the sub bom lines
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')); ?>');
310  return false;
311  });
312 
313  // To Hide all the sub bom lines
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')); ?>');
318  return false;
319  });
320 
321  });
322  </script>
323 
324  <?php
325 }
326 
327 // End of page
328 llxFooter();
329 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
BOM
Class for BOM.
Definition: bom.class.php:34
dol_banner_tab
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.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:576
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
dolGetButtonTitle
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.
Definition: functions.lib.php:10605
bomPrepareHead
bomPrepareHead($object)
Prepare array of tabs for BillOfMaterials.
Definition: bom.lib.php:73
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
price
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.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59