dolibarr  x.y.z
mo_card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2017-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  */
17 
25 // Load Dolibarr environment
26 require '../main.inc.php';
27 
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php';
36 
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('mrp', 'other'));
40 
41 
42 // Get parameters
43 $id = GETPOST('id', 'int');
44 $ref = GETPOST('ref', 'alpha');
45 $action = GETPOST('action', 'aZ09');
46 $confirm = GETPOST('confirm', 'alpha');
47 $cancel = GETPOST('cancel', 'aZ09');
48 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'mocard'; // To manage different context of search
49 $backtopage = GETPOST('backtopage', 'alpha');
50 $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
51 $TBomLineId = GETPOST('bomlineid', 'array');
52 $lineid = GETPOST('lineid', 'int');
53 $socid = GETPOST("socid", 'int');
54 
55 // Initialize technical objects
56 $object = new Mo($db);
57 $objectbom = new BOM($db);
58 
59 $extrafields = new ExtraFields($db);
60 $diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
61 $hookmanager->initHooks(array('mocard', 'globalcard')); // Note that conf->hooks_modules contains array
62 
63 // Fetch optionals attributes and labels
64 $extrafields->fetch_name_optionals_label($object->table_element);
65 
66 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
67 
68 // Initialize array of search criterias
69 $search_all = GETPOST("search_all", 'alpha');
70 $search = array();
71 foreach ($object->fields as $key => $val) {
72  if (GETPOST('search_'.$key, 'alpha')) {
73  $search[$key] = GETPOST('search_'.$key, 'alpha');
74  }
75 }
76 
77 if (empty($action) && empty($id) && empty($ref)) {
78  $action = 'view';
79 }
80 
81 // Load object
82 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
83 
84 if (GETPOST('fk_bom', 'int') > 0) {
85  $objectbom->fetch(GETPOST('fk_bom', 'int'));
86 
87  if ($action != 'add') {
88  // We force calling parameters if we are not in the submit of creation of MO
89  $_POST['fk_product'] = $objectbom->fk_product;
90  $_POST['qty'] = $objectbom->qty;
91  $_POST['mrptype'] = $objectbom->bomtype;
92  $_POST['fk_warehouse'] = $objectbom->fk_warehouse;
93  $_POST['note_private'] = $objectbom->note_private;
94  }
95 }
96 
97 // Security check - Protection if external user
98 //if ($user->socid > 0) accessforbidden();
99 //if ($user->socid > 0) $socid = $user->socid;
100 $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
101 $result = restrictedArea($user, 'mrp', $object->id, 'mrp_mo', '', 'fk_soc', 'rowid', $isdraft);
102 
103 // Permissions
104 $permissionnote = $user->rights->mrp->write; // Used by the include of actions_setnotes.inc.php
105 $permissiondellink = $user->rights->mrp->write; // Used by the include of actions_dellink.inc.php
106 $permissiontoadd = $user->rights->mrp->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
107 $permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
108 $upload_dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
109 
110 
111 /*
112  * Actions
113  */
114 
115 $parameters = array();
116 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
117 if ($reshook < 0) {
118  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
119 }
120 
121 if (empty($reshook)) {
122  $error = 0;
123 
124  $backurlforlist = dol_buildpath('/mrp/mo_list.php', 1);
125 
126  if (empty($backtopage) || ($cancel && empty($id))) {
127  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
128  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
129  $backtopage = $backurlforlist;
130  } else {
131  $backtopage = DOL_URL_ROOT.'/mrp/mo_card.php?id='.($id > 0 ? $id : '__ID__');
132  }
133  }
134  }
135  if ($cancel && !empty($backtopageforcancel)) {
136  $backtopage = $backtopageforcancel;
137  }
138  $triggermodname = 'MO_MODIFY'; // Name of trigger action code to execute when we modify record
139 
140  // Create MO with Childs
141  if ($action == 'add' && empty($id) && !empty($TBomLineId)) {
142  $noback = 1;
143  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
144 
145  $mo_parent = $object;
146 
147  $moline = new MoLine($db);
148  $objectbomchildline = new BOMLine($db);
149 
150  foreach ($TBomLineId as $id_bom_line) {
151  $object = new Mo($db); // modified by the actions_addupdatedelete.inc.php
152 
153  $objectbomchildline->fetch($id_bom_line);
154 
155  $TMoLines = $moline->fetchAll('DESC', 'rowid', '1', '', array('origin_id' => $id_bom_line));
156 
157  foreach ($TMoLines as $tmpmoline) {
158  $_POST['fk_bom'] = $objectbomchildline->fk_bom_child;
159  $_POST['fk_parent_line'] = $tmpmoline->id;
160  $_POST['qty'] = $tmpmoline->qty;
161  $_POST['fk_product'] = $tmpmoline->fk_product;
162  }
163 
164  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
165 
166  $res = $object->add_object_linked('mo', $mo_parent->id);
167  }
168 
169  header("Location: ".dol_buildpath('/mrp/mo_card.php?id='.((int) $moline->fk_mo), 1));
170  exit;
171  }
172 
173  // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
174  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
175 
176  // Actions when linking object each other
177  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
178 
179  // Actions when printing a doc from card
180  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
181 
182  // Action to build doc
183  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
184 
185  if ($action == 'set_thirdparty' && $permissiontoadd) {
186  $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
187  }
188  if ($action == 'classin' && $permissiontoadd) {
189  $object->setProject(GETPOST('projectid', 'int'));
190  }
191 
192  // Actions to send emails
193  $triggersendname = 'MO_SENTBYMAIL';
194  $autocopy = 'MAIN_MAIL_AUTOCOPY_MO_TO';
195  $trackid = 'mo'.$object->id;
196  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
197 
198  // Action to move up and down lines of object
199  //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
200 
201  // Action close produced
202  if ($action == 'confirm_produced' && $confirm == 'yes' && $permissiontoadd) {
203  $result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
204  if ($result >= 0) {
205  // Define output language
206  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
207  $outputlangs = $langs;
208  $newlang = '';
209  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
210  $newlang = GETPOST('lang_id', 'aZ09');
211  }
212  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
213  $newlang = $object->thirdparty->default_lang;
214  }
215  if (!empty($newlang)) {
216  $outputlangs = new Translate("", $conf);
217  $outputlangs->setDefaultLang($newlang);
218  }
219  $model = $object->model_pdf;
220  $ret = $object->fetch($id); // Reload to get new records
221 
222  $object->generateDocument($model, $outputlangs, 0, 0, 0);
223  }
224  } else {
225  setEventMessages($object->error, $object->errors, 'errors');
226  }
227  }
228 }
229 
230 
231 
232 
233 /*
234  * View
235  */
236 
237 $form = new Form($db);
238 $formfile = new FormFile($db);
239 $formproject = new FormProjets($db);
240 
241 $title = $langs->trans('ManufacturingOrder')." - ".$langs->trans("Card");
242 
243 llxHeader('', $title, '');
244 
245 
246 
247 // Part to create
248 if ($action == 'create') {
249  if (GETPOST('fk_bom', 'int') > 0) {
250  $titlelist = $langs->trans("ToConsume");
251  if ($objectbom->bomtype == 1) {
252  $titlelist = $langs->trans("ToObtain");
253  }
254  }
255 
256  print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Mo")), '', 'mrp');
257 
258  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
259  print '<input type="hidden" name="token" value="'.newToken().'">';
260  print '<input type="hidden" name="action" value="add">';
261  if ($backtopage) {
262  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
263  }
264  if ($backtopageforcancel) {
265  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
266  }
267 
268  print dol_get_fiche_head(array(), '');
269 
270  print '<table class="border centpercent tableforfieldcreate">'."\n";
271 
272  // Common attributes
273  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
274 
275  // Other attributes
276  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
277 
278  print '</table>'."\n";
279 
280  print dol_get_fiche_end();
281 
283 
284  ?>
285  <script>
286  $(document).ready(function () {
287  jQuery('#fk_bom').change(function() {
288  console.log('We change value of BOM with BOM of id '+jQuery('#fk_bom').val());
289  if (jQuery('#fk_bom').val() > 0)
290  {
291  // Redirect to page with fk_bom set
292  window.location.href = '<?php echo $_SERVER["PHP_SELF"] ?>?action=create&token=<?php echo newToken(); ?>&fk_bom='+jQuery('#fk_bom').val();
293  /*
294  $.getJSON('<?php echo DOL_URL_ROOT ?>/mrp/ajax/ajax_bom.php?action=getBoms&idbom='+jQuery('#fk_bom').val(), function(data) {
295  console.log(data);
296  if (typeof data.rowid != "undefined") {
297  console.log("New BOM loaded, we set values in form");
298  console.log(data);
299  $('#qty').val(data.qty);
300  $("#mrptype").val(data.bomtype); // We set bomtype into mrptype
301  $('#mrptype').trigger('change'); // Notify any JS components that the value changed
302  $("#fk_product").val(data.fk_product);
303  $('#fk_product').trigger('change'); // Notify any JS components that the value changed
304  $('#note_private').val(data.description);
305  $('#note_private').trigger('change'); // Notify any JS components that the value changed
306  $('#fk_warehouse').val(data.fk_warehouse);
307  $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
308  if (typeof CKEDITOR != "undefined") {
309  if (typeof CKEDITOR.instances != "undefined") {
310  if (typeof CKEDITOR.instances.note_private != "undefined") {
311  console.log(CKEDITOR.instances.note_private);
312  CKEDITOR.instances.note_private.setData(data.description);
313  }
314  }
315  }
316  } else {
317  console.log("Failed to get BOM");
318  }
319  });*/
320  }
321  else if (jQuery('#fk_bom').val() < 0) {
322  // Redirect to page with all fields defined except fk_bom set
323  console.log(jQuery('#fk_product').val());
324  window.location.href = '<?php echo $_SERVER["PHP_SELF"] ?>?action=create&token=<?php echo newToken(); ?>&qty='+jQuery('#qty').val()+'&mrptype='+jQuery('#mrptype').val()+'&fk_product='+jQuery('#fk_product').val()+'&label='+jQuery('#label').val()+'&fk_project='+jQuery('#fk_project').val()+'&fk_warehouse='+jQuery('#fk_warehouse').val();
325  /*
326  $('#qty').val('');
327  $("#fk_product").val('');
328  $('#fk_product').trigger('change'); // Notify any JS components that the value changed
329  $('#note_private').val('');
330  $('#note_private').trigger('change'); // Notify any JS components that the value changed
331  $('#fk_warehouse').val('');
332  $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
333  */
334  }
335  });
336 
337  //jQuery('#fk_bom').trigger('change');
338  })
339  </script>
340  <?php
341 
342  print $form->buttonsSaveCancel("Create");
343 
344  if ($objectbom->id > 0) {
345  print load_fiche_titre($titlelist);
346 
347  print '<div class="div-table-responsive-no-min">';
348  print '<table class="noborder centpercent">';
349 
350  $object->lines = $objectbom->lines;
351  $object->mrptype = $objectbom->bomtype;
352  $object->bom = $objectbom;
353 
354  $object->printOriginLinesList('', array());
355 
356  print '</table>';
357  print '</div>';
358  }
359 
360  print '</form>';
361 }
362 
363 // Part to edit record
364 if (($id || $ref) && $action == 'edit') {
365  print load_fiche_titre($langs->trans("ManufacturingOrder"), '', 'mrp');
366 
367  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
368  print '<input type="hidden" name="token" value="'.newToken().'">';
369  print '<input type="hidden" name="action" value="update">';
370  print '<input type="hidden" name="id" value="'.$object->id.'">';
371  if ($backtopage) {
372  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
373  }
374  if ($backtopageforcancel) {
375  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
376  }
377 
378  print dol_get_fiche_head();
379 
380  $object->fields['fk_bom']['disabled'] = 1;
381 
382  print '<table class="border centpercent tableforfieldedit">'."\n";
383 
384  // Common attributes
385  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
386 
387  // Other attributes
388  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
389 
390  print '</table>';
391 
392  print dol_get_fiche_end();
393 
394  print $form->buttonsSaveCancel();
395 
396  print '</form>';
397 }
398 
399 // Part to show record
400 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
401  $res = $object->fetch_thirdparty();
402 
403  $head = moPrepareHead($object);
404 
405  print dol_get_fiche_head($head, 'card', $langs->trans("ManufacturingOrder"), -1, $object->picto);
406 
407  $formconfirm = '';
408 
409  // Confirmation to delete
410  if ($action == 'delete') {
411  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', '', 0, 1);
412  }
413  // Confirmation to delete line
414  if ($action == 'deleteline') {
415  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
416  }
417 
418  // Confirmation of validation
419  if ($action == 'validate') {
420  // We check that object has a temporary ref
421  $ref = substr($object->ref, 1, 4);
422  if ($ref == 'PROV') {
423  $object->fetch_product();
424  $numref = $object->getNextNumRef($object->fk_product);
425  } else {
426  $numref = $object->ref;
427  }
428 
429  $text = $langs->trans('ConfirmValidateMo', $numref);
430  /*if (isModEnabled('notification'))
431  {
432  require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
433  $notify = new Notify($db);
434  $text .= '<br>';
435  $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
436  }*/
437 
438  $formquestion = array();
439  if (isModEnabled('mrp')) {
440  $langs->load("mrp");
441  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
442  $formproduct = new FormProduct($db);
443  $forcecombo = 0;
444  if ($conf->browser->name == 'ie') {
445  $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
446  }
447  $formquestion = array(
448  // 'text' => $langs->trans("ConfirmClone"),
449  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
450  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
451  );
452  }
453 
454  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
455  }
456 
457  // Clone confirmation
458  if ($action == 'clone') {
459  // Create an array for form
460  $formquestion = array();
461  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
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_buildpath('/mrp/mo_list.php', 1).'?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->mrp->creer, 'string', '', 0, 1);
485  $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', null, null, '', 1);*/
486  // Thirdparty
487  if (is_object($object->thirdparty)) {
488  $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
489  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
490  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
491  }
492  }
493  // Project
494  if (isModEnabled('project')) {
495  $langs->load("projects");
496  if (is_object($object->thirdparty)) {
497  $morehtmlref .= '<br>';
498  }
499  if ($permissiontoadd) {
500  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
501  if ($action != 'classify') {
502  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
503  }
504  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, ($action == 'classify' ? 1 : 0), 0, 1, '');
505  } else {
506  if (!empty($object->fk_project)) {
507  $proj = new Project($db);
508  $proj->fetch($object->fk_project);
509  $morehtmlref .= $proj->getNomUrl(1);
510  if ($proj->title) {
511  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
512  }
513  }
514  }
515  }
516  $morehtmlref .= '</div>';
517 
518 
519  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
520 
521 
522  print '<div class="fichecenter">';
523  print '<div class="fichehalfleft">';
524  print '<div class="underbanner clearboth"></div>';
525  print '<table class="border centpercent tableforfield">'."\n";
526 
527  //Mo Parent
528  $mo_parent = $object->getMoParent();
529  if (is_object($mo_parent)) {
530  print '<tr class="field_fk_mo_parent">';
531  print '<td class="titlefield fieldname_fk_mo_parent">' . $langs->trans('ParentMo') . '</td>';
532  print '<td class="valuefield fieldname_fk_mo_parent">' .$mo_parent->getNomUrl(1).'</td>';
533  print '</tr>';
534  }
535 
536  // Common attributes
537  $keyforbreak = 'fk_warehouse';
538  unset($object->fields['fk_project']);
539  unset($object->fields['fk_soc']);
540  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
541 
542  // Other attributes
543  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
544 
545  print '</table>';
546  print '</div>';
547  print '</div>';
548 
549  print '<div class="clearboth"></div>';
550 
551  print dol_get_fiche_end();
552 
553 
554  /*
555  * Lines
556  */
557 
558  if (!empty($object->table_element_line)) {
559  // Show object lines
560  //$result = $object->getLinesArray();
561  $object->fetchLines();
562 
563  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
564  <input type="hidden" name="token" value="' . newToken().'">
565  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
566  <input type="hidden" name="mode" value="">
567  <input type="hidden" name="page_y" value="">
568  <input type="hidden" name="id" value="' . $object->id.'">
569  ';
570 
571  /*if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
572  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
573  }*/
574 
575  if (!empty($object->lines)) {
576  print '<div class="div-table-responsive-no-min">';
577  print '<table id="tablelines" class="noborder noshadow" width="100%">';
578 
579  print '<tr class="liste_titre">';
580  print '<td class="liste_titre">'.$langs->trans("Summary").'</td>';
581  print '<td></td>';
582  print '</tr>';
583 
584  print '<tr class="oddeven">';
585  print '<td>'.$langs->trans("ProductsToConsume").'</td>';
586  print '<td>';
587  if (!empty($object->lines)) {
588  $i = 0;
589  foreach ($object->lines as $line) {
590  if ($line->role == 'toconsume') {
591  if ($i) {
592  print ', ';
593  }
594  $tmpproduct = new Product($db);
595  $tmpproduct->fetch($line->fk_product);
596  print $tmpproduct->getNomUrl(1);
597  $i++;
598  }
599  }
600  }
601  print '</td>';
602  print '</tr>';
603 
604  print '<tr class="oddeven">';
605  print '<td>'.$langs->trans("ProductsToProduce").'</td>';
606  print '<td>';
607  if (!empty($object->lines)) {
608  $i = 0;
609  foreach ($object->lines as $line) {
610  if ($line->role == 'toproduce') {
611  if ($i) {
612  print ', ';
613  }
614  $tmpproduct = new Product($db);
615  $tmpproduct->fetch($line->fk_product);
616  print $tmpproduct->getNomUrl(1);
617  $i++;
618  }
619  }
620  }
621  print '</td>';
622  print '</tr>';
623 
624  print '</table>';
625  print '</div>';
626  }
627 
628  print "</form>\n";
629  }
630 
631 
632  // Buttons for actions
633 
634  if ($action != 'presend' && $action != 'editline') {
635  print '<div class="tabsAction">'."\n";
636  $parameters = array();
637  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
638  if ($reshook < 0) {
639  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
640  }
641 
642  if (empty($reshook)) {
643  // Send
644  //if (empty($user->socid)) {
645  // print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
646  //}
647 
648  // Back to draft
649  if ($object->status == $object::STATUS_VALIDATED) {
650  if ($permissiontoadd) {
651  // TODO Add test that production has not started
652  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken().'">'.$langs->trans("SetToDraft").'</a>';
653  }
654  }
655 
656  // Modify
657  if ($object->status == $object::STATUS_DRAFT) {
658  if ($permissiontoadd) {
659  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
660  } else {
661  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
662  }
663  }
664 
665  // Validate
666  if ($object->status == $object::STATUS_DRAFT) {
667  if ($permissiontoadd) {
668  if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
669  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate">'.$langs->trans("Validate").'</a>';
670  } else {
671  $langs->load("errors");
672  print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
673  }
674  }
675  }
676 
677  // Clone
678  if ($permissiontoadd) {
679  print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : "").'&action=clone&object=mo', 'clone', $permissiontoadd);
680  }
681 
682  // Cancel - Reopen
683  if ($permissiontoadd) {
684  if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS) {
685  $arrayproduced = $object->fetchLinesLinked('produced', 0);
686  $nbProduced = 0;
687  foreach ($arrayproduced as $lineproduced) {
688  $nbProduced += $lineproduced['qty'];
689  }
690  if ($nbProduced > 0) { // If production has started, we can close it
691  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_produced&confirm=yes&token='.newToken().'">'.$langs->trans("Close").'</a>'."\n";
692  } else {
693  print '<a class="butActionRefused" href="#" title="'.$langs->trans("GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv("Production")).'">'.$langs->trans("Close").'</a>'."\n";
694  }
695 
696  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_close&confirm=yes&token='.newToken().'">'.$langs->trans("Cancel").'</a>'."\n";
697  }
698 
699  if ($object->status == $object::STATUS_PRODUCED || $object->status == $object::STATUS_CANCELED) {
700  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken().'">'.$langs->trans("ReOpen").'</a>'."\n";
701  }
702  }
703 
704  // Delete
705  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
706  }
707  print '</div>'."\n";
708  }
709 
710 
711  // Select mail models is same action as presend
712  if (GETPOST('modelselected')) {
713  $action = 'presend';
714  }
715 
716  if ($action != 'presend') {
717  print '<div class="fichecenter"><div class="fichehalfleft">';
718  print '<a name="builddoc"></a>'; // ancre
719 
720  // Documents
721  $objref = dol_sanitizeFileName($object->ref);
722  $relativepath = $objref.'/'.$objref.'.pdf';
723  $filedir = $conf->mrp->dir_output.'/'.$objref;
724  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
725  $genallowed = $user->rights->mrp->read; // If you can read, you can build the PDF to read content
726  $delallowed = $user->hasRight("mrp", "creer"); // If you can create/edit, you can remove a file on card
727  print $formfile->showdocuments('mrp:mo', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $mysoc->default_lang);
728 
729  // Show links to link elements
730  $linktoelem = $form->showLinkToObjectBlock($object, null, array('mo'));
731  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, false);
732 
733 
734  print '</div><div class="fichehalfright">';
735 
736  $MAXEVENT = 10;
737 
738  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/mrp/mo_agenda.php?id='.$object->id);
739 
740  // List of actions on element
741  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
742  $formactions = new FormActions($db);
743  $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT, '', $morehtmlcenter);
744 
745  print '</div></div>';
746  }
747 
748  //Select mail models is same action as presend
749  if (GETPOST('modelselected')) {
750  $action = 'presend';
751  }
752 
753  // Presend form
754  $modelmail = 'mo';
755  $defaulttopic = 'InformationMessage';
756  $diroutput = $conf->mrp->dir_output;
757  $trackid = 'mo'.$object->id;
758 
759  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
760 }
761 
762 // End of page
763 llxFooter();
764 $db->close();
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.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
mrpCollapseBomManagement()
Manage collapse bom display.
Definition: bom.lib.php:152
Class for BOM.
Definition: bom.class.php:36
Class for BOMLine.
Definition: bom.class.php:1567
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage building of HTML components.
Class for Mo.
Definition: mo.class.php:36
Class MoLine.
Definition: mo.class.php:1565
Class to manage products or services.
Class to manage projects.
Class to manage translations.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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='')
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
$formconfirm
if ($action == 'delbookkeepingyear') {
moPrepareHead($object)
Prepare array of tabs for Mo.
Definition: mrp_mo.lib.php:30
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.