dolibarr  16.0.5
bom_card.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 require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp.lib.php';
32 
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("mrp", "other"));
36 
37 // Get parameters
38 $id = GETPOST('id', 'int');
39 $ref = GETPOST('ref', 'alpha');
40 $action = GETPOST('action', 'aZ09');
41 $confirm = GETPOST('confirm', 'alpha');
42 $cancel = GETPOST('cancel', 'aZ09');
43 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bomcard'; // To manage different context of search
44 $backtopage = GETPOST('backtopage', 'alpha');
45 $lineid = GETPOST('lineid', 'int');
46 
47 // PDF
48 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
49 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
50 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
51 
52 // Initialize technical objects
53 $object = new BOM($db);
54 $extrafields = new ExtraFields($db);
55 $diroutputmassaction = $conf->bom->dir_output.'/temp/massgeneration/'.$user->id;
56 $hookmanager->initHooks(array('bomcard', 'globalcard')); // Note that conf->hooks_modules contains array
57 // Fetch optionals attributes and labels
58 $extrafields->fetch_name_optionals_label($object->table_element);
59 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
60 
61 // Initialize array of search criterias
62 $search_all = GETPOST("search_all", 'alpha');
63 $search = array();
64 foreach ($object->fields as $key => $val) {
65  if (GETPOST('search_'.$key, 'alpha')) {
66  $search[$key] = GETPOST('search_'.$key, 'alpha');
67  }
68 }
69 
70 if (empty($action) && empty($id) && empty($ref)) {
71  $action = 'view';
72 }
73 
74 // Load object
75 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
76 if ($object->id > 0) {
77  $object->calculateCosts();
78 }
79 
80 
81 // Security check - Protection if external user
82 //if ($user->socid > 0) accessforbidden();
83 //if ($user->socid > 0) $socid = $user->socid;
84 $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
85 $result = restrictedArea($user, 'bom', $object->id, 'bom_bom', '', '', 'rowid', $isdraft);
86 
87 $permissionnote = $user->rights->bom->write; // Used by the include of actions_setnotes.inc.php
88 $permissiondellink = $user->rights->bom->write; // Used by the include of actions_dellink.inc.php
89 $permissiontoadd = $user->rights->bom->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
90 $permissiontodelete = $user->rights->bom->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
91 $upload_dir = $conf->bom->multidir_output[isset($object->entity) ? $object->entity : 1];
92 
93 
94 /*
95  * Actions
96  */
97 
98 $parameters = array();
99 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
100 if ($reshook < 0) {
101  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
102 }
103 
104 if (empty($reshook)) {
105  $error = 0;
106 
107  $backurlforlist = DOL_URL_ROOT.'/bom/bom_list.php';
108 
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;
113  } else {
114  $backtopage = DOL_URL_ROOT.'/bom/bom_card.php?id='.($id > 0 ? $id : '__ID__');
115  }
116  }
117  }
118 
119  $triggermodname = 'BOM_MODIFY'; // Name of trigger action code to execute when we modify record
120 
121 
122  // Actions cancel, add, update, delete or clone
123  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
124  // The fetch/fetch_lines was redone into the inc.php so we must recall the calculateCosts()
125  if ($action == 'confirm_validate' && $object->id > 0) {
126  $object->calculateCosts();
127  }
128 
129  // Actions when linking object each other
130  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
131 
132  // Actions when printing a doc from card
133  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
134 
135  // Action to move up and down lines of object
136  //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php';
137 
138  // Action to build doc
139  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
140 
141  // Actions to send emails
142  $triggersendname = 'BOM_SENTBYMAIL';
143  $autocopy = 'MAIN_MAIL_AUTOCOPY_BOM_TO';
144  $trackid = 'bom'.$object->id;
145  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
146 
147  // Add line
148  if ($action == 'addline' && $user->rights->bom->write) {
149  $langs->load('errors');
150  $error = 0;
151 
152  // Set if we used free entry or predefined product
153  $bom_child_id = (int) GETPOST('bom_id', 'int');
154  if ($bom_child_id > 0) {
155  $bom_child = new BOM($db);
156  $res = $bom_child->fetch($bom_child_id);
157  if ($res) {
158  $idprod = $bom_child->fk_product;
159  }
160  } else {
161  $idprod = (int) GETPOST('idprod', 'int');
162  }
163 
164  $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
165  $qty_frozen = price2num(GETPOST('qty_frozen', 'alpha'), 'MS');
166  $disable_stock_change = GETPOST('disable_stock_change', 'int');
167  $efficiency = price2num(GETPOST('efficiency', 'alpha'));
168 
169  if ($qty == '') {
170  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
171  $error++;
172  }
173  if (!($idprod > 0)) {
174  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Product')), null, 'errors');
175  $error++;
176  }
177 
178  if ($object->fk_product == $idprod) {
179  setEventMessages($langs->trans('TheProductXIsAlreadyTheProductToProduce'), null, 'errors');
180  $error++;
181  }
182 
183  // We check if we're allowed to add this bom
184  $TParentBom=array();
185  $object->getParentBomTreeRecursive($TParentBom);
186  if ($bom_child_id > 0 && !empty($TParentBom) && in_array($bom_child_id, $TParentBom)) {
187  $n_child = new BOM($db);
188  $n_child->fetch($bom_child_id);
189  setEventMessages($langs->transnoentities('BomCantAddChildBom', $n_child->getNomUrl(1), $object->getNomUrl(1)), null, 'errors');
190  $error++;
191  }
192 
193  if (!$error) {
194  $bomline = new BOMLine($db);
195  $bomline->fk_bom = $id;
196  $bomline->fk_product = $idprod;
197  $bomline->fk_bom_child = $bom_child_id;
198  $bomline->qty = $qty;
199  $bomline->qty_frozen = (int) $qty_frozen;
200  $bomline->disable_stock_change = (int) $disable_stock_change;
201  $bomline->efficiency = $efficiency;
202 
203  // Rang to use
204  $rangmax = $object->line_max(0);
205  $ranktouse = $rangmax + 1;
206 
207  $bomline->position = ($ranktouse + 1);
208 
209  $result = $bomline->create($user);
210  if ($result <= 0) {
211  setEventMessages($bomline->error, $bomline->errors, 'errors');
212  $action = '';
213  } else {
214  unset($_POST['idprod']);
215  unset($_POST['qty']);
216  unset($_POST['qty_frozen']);
217  unset($_POST['disable_stock_change']);
218 
219  $object->fetchLines();
220 
221  $object->calculateCosts();
222  }
223  }
224  }
225 
226  // Add line
227  if ($action == 'updateline' && $user->rights->bom->write) {
228  $langs->load('errors');
229  $error = 0;
230 
231  // Set if we used free entry or predefined product
232  $qty = price2num(GETPOST('qty', 'alpha'), 'MS');
233  $qty_frozen = price2num(GETPOST('qty_frozen', 'alpha'), 'MS');
234  $disable_stock_change = GETPOST('disable_stock_change', 'int');
235  $efficiency = price2num(GETPOST('efficiency', 'alpha'));
236 
237  if ($qty == '') {
238  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
239  $error++;
240  }
241 
242  $bomline = new BOMLine($db);
243  $bomline->fetch($lineid);
244  $bomline->qty = $qty;
245  $bomline->qty_frozen = (int) $qty_frozen;
246  $bomline->disable_stock_change = (int) $disable_stock_change;
247  $bomline->efficiency = $efficiency;
248 
249  $result = $bomline->update($user);
250  if ($result <= 0) {
251  setEventMessages($bomline->error, $bomline->errors, 'errors');
252  $action = '';
253  } else {
254  unset($_POST['idprod']);
255  unset($_POST['qty']);
256  unset($_POST['qty_frozen']);
257  unset($_POST['disable_stock_change']);
258 
259  $object->fetchLines();
260 
261  $object->calculateCosts();
262  }
263  }
264 }
265 
266 
267 
268 /*
269  * View
270  */
271 
272 $form = new Form($db);
273 $formfile = new FormFile($db);
274 
275 
276 $title = $langs->trans('BOM');
277 $help_url ='EN:Module_BOM';
278 llxHeader('', $title, $help_url);
279 
280 // Part to create
281 if ($action == 'create') {
282  print load_fiche_titre($langs->trans("NewBOM"), '', 'bom');
283 
284  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
285  print '<input type="hidden" name="token" value="'.newToken().'">';
286  print '<input type="hidden" name="action" value="add">';
287  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
288 
289  print dol_get_fiche_head(array(), '');
290 
291  print '<table class="border centpercent tableforfieldcreate">'."\n";
292 
293  // Common attributes
294  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
295 
296  // Other attributes
297  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
298 
299  print '</table>'."\n";
300 
301  print dol_get_fiche_end();
302 
303  print $form->buttonsSaveCancel("Create");
304 
305  print '</form>';
306 }
307 
308 // Part to edit record
309 if (($id || $ref) && $action == 'edit') {
310  print load_fiche_titre($langs->trans("BillOfMaterials"), '', 'cubes');
311 
312  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
313  print '<input type="hidden" name="token" value="'.newToken().'">';
314  print '<input type="hidden" name="action" value="update">';
315  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
316  print '<input type="hidden" name="id" value="'.$object->id.'">';
317 
318  print dol_get_fiche_head();
319 
320  //$object->fields['keyfield']['disabled'] = 1;
321 
322  print '<table class="border centpercent tableforfieldedit">'."\n";
323 
324  // Common attributes
325  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
326 
327  // Other attributes
328  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
329 
330  print '</table>';
331 
332  print dol_get_fiche_end();
333 
334  print $form->buttonsSaveCancel("Create");
335 
336  print '</form>';
337 }
338 
339 // Part to show record
340 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
341  $head = bomPrepareHead($object);
342  print dol_get_fiche_head($head, 'card', $langs->trans("BillOfMaterials"), -1, 'bom');
343 
344  $formconfirm = '';
345 
346  // Confirmation to delete
347  if ($action == 'delete') {
348  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBillOfMaterials'), $langs->trans('ConfirmDeleteBillOfMaterials'), 'confirm_delete', '', 0, 1);
349  }
350  // Confirmation to delete line
351  if ($action == 'deleteline') {
352  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
353  }
354 
355  // Confirmation of validation
356  if ($action == 'validate') {
357  // We check that object has a temporary ref
358  $ref = substr($object->ref, 1, 4);
359  if ($ref == 'PROV') {
360  $object->fetch_product();
361  $numref = $object->getNextNumRef($object->product);
362  } else {
363  $numref = $object->ref;
364  }
365 
366  $text = $langs->trans('ConfirmValidateBom', $numref);
367  /*if (! empty($conf->notification->enabled))
368  {
369  require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
370  $notify = new Notify($db);
371  $text .= '<br>';
372  $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
373  }*/
374 
375  $formquestion = array();
376  if (!empty($conf->bom->enabled)) {
377  $langs->load("mrp");
378  $forcecombo = 0;
379  if ($conf->browser->name == 'ie') {
380  $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
381  }
382  $formquestion = array(
383  // 'text' => $langs->trans("ConfirmClone"),
384  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
385  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
386  );
387  }
388 
389  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
390  }
391 
392  // Confirmation of closing
393  if ($action == 'close') {
394  $text = $langs->trans('ConfirmCloseBom', $object->ref);
395  /*if (! empty($conf->notification->enabled))
396  {
397  require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
398  $notify = new Notify($db);
399  $text .= '<br>';
400  $text .= $notify->confirmMessage('BOM_CLOSE', $object->socid, $object);
401  }*/
402 
403  $formquestion = array();
404  if (!empty($conf->bom->enabled)) {
405  $langs->load("mrp");
406  $forcecombo = 0;
407  if ($conf->browser->name == 'ie') {
408  $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
409  }
410  $formquestion = array(
411  // 'text' => $langs->trans("ConfirmClone"),
412  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
413  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
414  );
415  }
416 
417  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Close'), $text, 'confirm_close', $formquestion, 0, 1, 220);
418  }
419 
420  // Confirmation of reopen
421  if ($action == 'reopen') {
422  $text = $langs->trans('ConfirmReopenBom', $object->ref);
423  /*if (! empty($conf->notification->enabled))
424  {
425  require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
426  $notify = new Notify($db);
427  $text .= '<br>';
428  $text .= $notify->confirmMessage('BOM_CLOSE', $object->socid, $object);
429  }*/
430 
431  $formquestion = array();
432  if (!empty($conf->bom->enabled)) {
433  $langs->load("mrp");
434  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
435  $forcecombo = 0;
436  if ($conf->browser->name == 'ie') {
437  $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
438  }
439  $formquestion = array(
440  // 'text' => $langs->trans("ConfirmClone"),
441  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
442  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
443  );
444  }
445 
446  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $text, 'confirm_reopen', $formquestion, 0, 1, 220);
447  }
448 
449  // Clone confirmation
450  if ($action == 'clone') {
451  // Create an array for form
452  $formquestion = array();
453  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneBillOfMaterials', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
454  }
455 
456  // Confirmation of action xxxx
457  if ($action == 'setdraft') {
458  $text = $langs->trans('ConfirmSetToDraft', $object->ref);
459 
460  $formquestion = array();
461  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('SetToDraft'), $text, 'confirm_setdraft', $formquestion, 0, 1, 220);
462  }
463 
464  // Call Hook formConfirm
465  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
466  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
467  if (empty($reshook)) {
468  $formconfirm .= $hookmanager->resPrint;
469  } elseif ($reshook > 0) {
470  $formconfirm = $hookmanager->resPrint;
471  }
472 
473  // Print form confirm
474  print $formconfirm;
475 
476 
477  // Object card
478  // ------------------------------------------------------------
479  $linkback = '<a href="'.DOL_URL_ROOT.'/bom/bom_list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
480 
481  $morehtmlref = '<div class="refidno">';
482  /*
483  // Ref bis
484  $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->bom->creer, 'string', '', 0, 1);
485  $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->bom->creer, 'string', '', null, null, '', 1);
486  // Thirdparty
487  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
488  // Project
489  if (! empty($conf->project->enabled))
490  {
491  $langs->load("projects");
492  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
493  if ($permissiontoadd)
494  {
495  if ($action != 'classify')
496  $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
497  if ($action == 'classify') {
498  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
499  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
500  $morehtmlref.='<input type="hidden" name="action" value="classin">';
501  $morehtmlref.='<input type="hidden" name="token" value="'.newToken().'">';
502  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
503  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
504  $morehtmlref.='</form>';
505  } else {
506  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
507  }
508  } else {
509  if (! empty($object->fk_project)) {
510  $proj = new Project($db);
511  $proj->fetch($object->fk_project);
512  $morehtmlref.=$proj->getNomUrl();
513  } else {
514  $morehtmlref.='';
515  }
516  }
517  }
518  */
519  $morehtmlref .= '</div>';
520 
521 
522  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
523 
524 
525  print '<div class="fichecenter">';
526  print '<div class="fichehalfleft">';
527  print '<div class="underbanner clearboth"></div>';
528  print '<table class="border centpercent tableforfield">'."\n";
529 
530  // Common attributes
531  $keyforbreak = 'duration';
532  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
533  $object->calculateCosts();
534  print '<tr><td>'.$form->textwithpicto($langs->trans("TotalCost"), $langs->trans("BOMTotalCost")).'</td><td><span class="amount">'.price($object->total_cost).'</span></td></tr>';
535  print '<tr><td>'.$langs->trans("UnitCost").'</td><td>'.price($object->unit_cost).'</td></tr>';
536 
537  // Other attributes
538  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
539 
540  print '</table>';
541  print '</div>';
542  print '</div>';
543 
544  print '<div class="clearboth"></div>';
545 
546  print dol_get_fiche_end();
547 
548 
549 
550  /*
551  * Lines
552  */
553 
554  if (!empty($object->table_element_line)) {
555  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '').'" method="POST">
556  <input type="hidden" name="token" value="' . newToken().'">
557  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
558  <input type="hidden" name="mode" value="">
559  <input type="hidden" name="page_y" value="">
560  <input type="hidden" name="id" value="' . $object->id.'">
561  ';
562 
563  if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
564  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
565  }
566 
567  print '<div class="div-table-responsive-no-min">';
568  if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
569  print '<table id="tablelines" class="noborder noshadow" width="100%">';
570  }
571 
572  if (!empty($object->lines)) {
573  $object->printObjectLines($action, $mysoc, null, GETPOST('lineid', 'int'), 1, '/bom/tpl');
574  }
575 
576  // Form to add new line
577  if ($object->status == 0 && $permissiontoadd && $action != 'selectlines') {
578  if ($action != 'editline') {
579  // Add products/services form
580 
581 
582  $parameters = array();
583  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
584  if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
585  if (empty($reshook))
586  $object->formAddObjectLine(1, $mysoc, null, '/bom/tpl');
587  }
588  }
589 
590  if (!empty($object->lines) || ($object->status == $object::STATUS_DRAFT && $permissiontoadd && $action != 'selectlines' && $action != 'editline')) {
591  print '</table>';
592  }
593  print '</div>';
594 
595  print "</form>\n";
596 
598  }
599 
600 
601  // Buttons for actions
602 
603  if ($action != 'presend' && $action != 'editline') {
604  print '<div class="tabsAction">'."\n";
605  $parameters = array();
606  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
607  if ($reshook < 0) {
608  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
609  }
610 
611  if (empty($reshook)) {
612  // Send
613  //if (empty($user->socid)) {
614  // print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
615  //}
616 
617  // Back to draft
618  if ($object->status == $object::STATUS_VALIDATED) {
619  if ($permissiontoadd) {
620  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=setdraft&token='.newToken().'">'.$langs->trans("SetToDraft").'</a>'."\n";
621  }
622  }
623 
624  // Modify
625  if ($object->status == $object::STATUS_DRAFT) {
626  if ($permissiontoadd) {
627  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
628  } else {
629  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
630  }
631  }
632 
633  // Validate
634  if ($object->status == $object::STATUS_DRAFT) {
635  if ($permissiontoadd) {
636  if (is_array($object->lines) && count($object->lines) > 0) {
637  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=validate&amp;token='.newToken().'">'.$langs->trans("Validate").'</a>'."\n";
638  } else {
639  $langs->load("errors");
640  print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>'."\n";
641  }
642  }
643  }
644 
645  // Re-open
646  if ($permissiontoadd && $object->status == $object::STATUS_CANCELED) {
647  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a>'."\n";
648  }
649 
650  // Create MO
651  if (isModEnabled('mrp')) {
652  if ($object->status == $object::STATUS_VALIDATED && !empty($user->rights->mrp->write)) {
653  print '<a class="butAction" href="'.DOL_URL_ROOT.'/mrp/mo_card.php?action=create&fk_bom='.$object->id.'&token='.newToken().'&backtopageforcancel='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id).'">'.$langs->trans("CreateMO").'</a>'."\n";
654  }
655  }
656 
657  // Clone
658  if ($permissiontoadd) {
659  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&object=bom&token='.newToken().'">'.$langs->trans("ToClone").'</a>'."\n";
660  }
661 
662  // Close / Cancel
663  if ($permissiontoadd && $object->status == $object::STATUS_VALIDATED) {
664  print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=close&token='.newToken().'">'.$langs->trans("Disable").'</a>'."\n";
665  }
666 
667  /*
668  if ($user->rights->bom->write)
669  {
670  if ($object->status == 1)
671  {
672  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=disable&token='.newToken().'">'.$langs->trans("Disable").'</a>'."\n";
673  }
674  else
675  {
676  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=enable&token='.newToken().'">'.$langs->trans("Enable").'</a>'."\n";
677  }
678  }
679  */
680 
681  if ($permissiontodelete) {
682  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>'."\n";
683  } else {
684  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
685  }
686  }
687  print '</div>'."\n";
688  }
689 
690 
691  // Select mail models is same action as presend
692  if (GETPOST('modelselected')) {
693  $action = 'presend';
694  }
695 
696  if ($action != 'presend') {
697  print '<div class="fichecenter"><div class="fichehalfleft">';
698  print '<a name="builddoc"></a>'; // ancre
699 
700  // Documents
701  $objref = dol_sanitizeFileName($object->ref);
702  $relativepath = $objref.'/'.$objref.'.pdf';
703  $filedir = $conf->bom->dir_output.'/'.$objref;
704  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
705  $genallowed = $user->rights->bom->read; // If you can read, you can build the PDF to read content
706  $delallowed = $user->rights->bom->write; // If you can create/edit, you can remove a file on card
707  print $formfile->showdocuments('bom', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
708 
709  // Show links to link elements
710  $linktoelem = $form->showLinkToObjectBlock($object, null, array('bom'));
711  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
712 
713 
714  print '</div><div class="fichehalfright">';
715 
716  $MAXEVENT = 10;
717 
718  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/bom/bom_agenda.php?id='.$object->id);
719 
720  // List of actions on element
721  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
722  $formactions = new FormActions($db);
723  $somethingshown = $formactions->showactions($object, $object->element, 0, 1, '', $MAXEVENT, '', $morehtmlcenter);
724 
725  print '</div></div>';
726  }
727 
728  //Select mail models is same action as presend
729  if (GETPOST('modelselected')) {
730  $action = 'presend';
731  }
732 
733  // Presend form
734  $modelmail = 'bom';
735  $defaulttopic = 'InformationMessage';
736  $diroutput = $conf->bom->dir_output;
737  $trackid = 'bom'.$object->id;
738 
739  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
740 }
741 
742 // End of page
743 llxFooter();
744 $db->close();
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
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
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
BOMLine
Class for BOMLine.
Definition: bom.class.php:1202
$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
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
mrpCollapseBomManagement
mrpCollapseBomManagement()
Manage collapse bom display.
Definition: bom.lib.php:145
$formactions
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
Definition: agenda_other.php:178
$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
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
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
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