dolibarr  17.0.3
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  $object->oldQty = $object->qty;
127 
128  if (empty($backtopage) || ($cancel && empty($id))) {
129  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
130  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
131  $backtopage = $backurlforlist;
132  } else {
133  $backtopage = DOL_URL_ROOT.'/mrp/mo_card.php?id='.($id > 0 ? $id : '__ID__');
134  }
135  }
136  }
137  if ($cancel && !empty($backtopageforcancel)) {
138  $backtopage = $backtopageforcancel;
139  }
140  $triggermodname = 'MO_MODIFY'; // Name of trigger action code to execute when we modify record
141 
142  // Create MO with Childs
143  if ($action == 'add' && empty($id) && !empty($TBomLineId)) {
144  $noback = 1;
145  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
146 
147  $mo_parent = $object;
148 
149  $moline = new MoLine($db);
150  $objectbomchildline = new BOMLine($db);
151 
152  foreach ($TBomLineId as $id_bom_line) {
153  $object = new Mo($db);
154 
155  $objectbomchildline->fetch($id_bom_line);
156 
157  $TMoLines = $moline->fetchAll('DESC', 'rowid', '1', '', array('origin_id' => $id_bom_line));
158 
159  foreach ($TMoLines as $moline) {
160  $_POST['fk_bom'] = $objectbomchildline->fk_bom_child;
161  $_POST['fk_parent_line'] = $moline->id;
162  $_POST['qty'] = $moline->qty;
163  $_POST['fk_product'] = $moline->fk_product;
164  }
165 
166  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
167 
168  $res = $object->add_object_linked('mo', $mo_parent->id);
169  }
170 
171  header("Location: ".dol_buildpath('/mrp/mo_card.php?id='.((int) $moline->fk_mo), 1));
172  exit;
173  }
174 
175  // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
176  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
177 
178  // Actions when linking object each other
179  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
180 
181  // Actions when printing a doc from card
182  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
183 
184  // Action to build doc
185  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
186 
187  if ($action == 'set_thirdparty' && $permissiontoadd) {
188  $object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, $triggermodname);
189  }
190  if ($action == 'classin' && $permissiontoadd) {
191  $object->setProject(GETPOST('projectid', 'int'));
192  }
193 
194  // Actions to send emails
195  $triggersendname = 'MO_SENTBYMAIL';
196  $autocopy = 'MAIN_MAIL_AUTOCOPY_MO_TO';
197  $trackid = 'mo'.$object->id;
198  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
199 
200  // Action to move up and down lines of object
201  //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
202 
203  // Action close produced
204  if ($action == 'confirm_produced' && $confirm == 'yes' && $permissiontoadd) {
205  $result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
206  if ($result >= 0) {
207  // Define output language
208  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
209  $outputlangs = $langs;
210  $newlang = '';
211  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
212  $newlang = GETPOST('lang_id', 'aZ09');
213  }
214  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
215  $newlang = $object->thirdparty->default_lang;
216  }
217  if (!empty($newlang)) {
218  $outputlangs = new Translate("", $conf);
219  $outputlangs->setDefaultLang($newlang);
220  }
221  $model = $object->model_pdf;
222  $ret = $object->fetch($id); // Reload to get new records
223 
224  $object->generateDocument($model, $outputlangs, 0, 0, 0);
225  }
226  } else {
227  setEventMessages($object->error, $object->errors, 'errors');
228  }
229  }
230 }
231 
232 
233 
234 
235 /*
236  * View
237  */
238 
239 $form = new Form($db);
240 $formfile = new FormFile($db);
241 $formproject = new FormProjets($db);
242 
243 $title = $langs->trans('ManufacturingOrder')." - ".$langs->trans("Card");
244 
245 llxHeader('', $title, '');
246 
247 
248 
249 // Part to create
250 if ($action == 'create') {
251  if (GETPOST('fk_bom', 'int') > 0) {
252  $titlelist = $langs->trans("ToConsume");
253  if ($objectbom->bomtype == 1) {
254  $titlelist = $langs->trans("ToObtain");
255  }
256  }
257 
258  print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Mo")), '', 'mrp');
259 
260  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
261  print '<input type="hidden" name="token" value="'.newToken().'">';
262  print '<input type="hidden" name="action" value="add">';
263  if ($backtopage) {
264  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
265  }
266  if ($backtopageforcancel) {
267  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
268  }
269 
270  print dol_get_fiche_head(array(), '');
271 
272  print '<table class="border centpercent tableforfieldcreate">'."\n";
273 
274  // Common attributes
275  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
276 
277  // Other attributes
278  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
279 
280  print '</table>'."\n";
281 
282  print dol_get_fiche_end();
283 
285 
286  ?>
287  <script>
288  $(document).ready(function () {
289  jQuery('#fk_bom').change(function() {
290  console.log('We change value of BOM with BOM of id '+jQuery('#fk_bom').val());
291  if (jQuery('#fk_bom').val() > 0)
292  {
293  // Redirect to page with fk_bom set
294  window.location.href = '<?php echo $_SERVER["PHP_SELF"] ?>?action=create&token=<?php echo newToken(); ?>&fk_bom='+jQuery('#fk_bom').val();
295  /*
296  $.getJSON('<?php echo DOL_URL_ROOT ?>/mrp/ajax/ajax_bom.php?action=getBoms&idbom='+jQuery('#fk_bom').val(), function(data) {
297  console.log(data);
298  if (typeof data.rowid != "undefined") {
299  console.log("New BOM loaded, we set values in form");
300  console.log(data);
301  $('#qty').val(data.qty);
302  $("#mrptype").val(data.bomtype); // We set bomtype into mrptype
303  $('#mrptype').trigger('change'); // Notify any JS components that the value changed
304  $("#fk_product").val(data.fk_product);
305  $('#fk_product').trigger('change'); // Notify any JS components that the value changed
306  $('#note_private').val(data.description);
307  $('#note_private').trigger('change'); // Notify any JS components that the value changed
308  $('#fk_warehouse').val(data.fk_warehouse);
309  $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
310  if (typeof CKEDITOR != "undefined") {
311  if (typeof CKEDITOR.instances != "undefined") {
312  if (typeof CKEDITOR.instances.note_private != "undefined") {
313  console.log(CKEDITOR.instances.note_private);
314  CKEDITOR.instances.note_private.setData(data.description);
315  }
316  }
317  }
318  } else {
319  console.log("Failed to get BOM");
320  }
321  });*/
322  }
323  else if (jQuery('#fk_bom').val() < 0) {
324  // Redirect to page with all fields defined except fk_bom set
325  console.log(jQuery('#fk_product').val());
326  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();
327  /*
328  $('#qty').val('');
329  $("#fk_product").val('');
330  $('#fk_product').trigger('change'); // Notify any JS components that the value changed
331  $('#note_private').val('');
332  $('#note_private').trigger('change'); // Notify any JS components that the value changed
333  $('#fk_warehouse').val('');
334  $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
335  */
336  }
337  });
338 
339  //jQuery('#fk_bom').trigger('change');
340  })
341  </script>
342  <?php
343 
344  print $form->buttonsSaveCancel("Create");
345 
346  if ($objectbom->id > 0) {
347  print load_fiche_titre($titlelist);
348 
349  print '<div class="div-table-responsive-no-min">';
350  print '<table class="noborder centpercent">';
351 
352  $object->lines = $objectbom->lines;
353  $object->mrptype = $objectbom->bomtype;
354  $object->bom = $objectbom;
355 
356  $object->printOriginLinesList('', array());
357 
358  print '</table>';
359  print '</div>';
360  }
361 
362  print '</form>';
363 }
364 
365 // Part to edit record
366 if (($id || $ref) && $action == 'edit') {
367  print load_fiche_titre($langs->trans("ManufacturingOrder"), '', 'mrp');
368 
369  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
370  print '<input type="hidden" name="token" value="'.newToken().'">';
371  print '<input type="hidden" name="action" value="update">';
372  print '<input type="hidden" name="id" value="'.$object->id.'">';
373  if ($backtopage) {
374  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
375  }
376  if ($backtopageforcancel) {
377  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
378  }
379 
380  print dol_get_fiche_head();
381 
382  $object->fields['fk_bom']['disabled'] = 1;
383 
384  print '<table class="border centpercent tableforfieldedit">'."\n";
385 
386  // Common attributes
387  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
388 
389  // Other attributes
390  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
391 
392  print '</table>';
393 
394  print dol_get_fiche_end();
395 
396  print $form->buttonsSaveCancel();
397 
398  print '</form>';
399 }
400 
401 // Part to show record
402 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
403  $res = $object->fetch_thirdparty();
404 
405  $head = moPrepareHead($object);
406 
407  print dol_get_fiche_head($head, 'card', $langs->trans("ManufacturingOrder"), -1, $object->picto);
408 
409  $formconfirm = '';
410 
411  // Confirmation to delete
412  if ($action == 'delete') {
413  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', '', 0, 1);
414  }
415  // Confirmation to delete line
416  if ($action == 'deleteline') {
417  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
418  }
419 
420  // Confirmation of validation
421  if ($action == 'validate') {
422  // We check that object has a temporary ref
423  $ref = substr($object->ref, 1, 4);
424  if ($ref == 'PROV') {
425  $object->fetch_product();
426  $numref = $object->getNextNumRef($object->fk_product);
427  } else {
428  $numref = $object->ref;
429  }
430 
431  $text = $langs->trans('ConfirmValidateMo', $numref);
432  /*if (isModEnabled('notification'))
433  {
434  require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
435  $notify = new Notify($db);
436  $text .= '<br>';
437  $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
438  }*/
439 
440  $formquestion = array();
441  if (isModEnabled('mrp')) {
442  $langs->load("mrp");
443  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
444  $formproduct = new FormProduct($db);
445  $forcecombo = 0;
446  if ($conf->browser->name == 'ie') {
447  $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
448  }
449  $formquestion = array(
450  // 'text' => $langs->trans("ConfirmClone"),
451  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
452  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
453  );
454  }
455 
456  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
457  }
458 
459  // Clone confirmation
460  if ($action == 'clone') {
461  // Create an array for form
462  $formquestion = array();
463  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
464  }
465 
466  // Call Hook formConfirm
467  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
468  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
469  if (empty($reshook)) {
470  $formconfirm .= $hookmanager->resPrint;
471  } elseif ($reshook > 0) {
472  $formconfirm = $hookmanager->resPrint;
473  }
474 
475  // Print form confirm
476  print $formconfirm;
477 
478 
479  // Object card
480  // ------------------------------------------------------------
481  $linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
482 
483  $morehtmlref = '<div class="refidno">';
484  /*
485  // Ref bis
486  $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', 0, 1);
487  $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', null, null, '', 1);*/
488  // Thirdparty
489  if (is_object($object->thirdparty)) {
490  $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
491  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
492  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
493  }
494  }
495  // Project
496  if (isModEnabled('project')) {
497  $langs->load("projects");
498  if (is_object($object->thirdparty)) {
499  $morehtmlref .= '<br>';
500  }
501  if ($permissiontoadd) {
502  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
503  if ($action != 'classify') {
504  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
505  }
506  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
507  } else {
508  if (!empty($object->fk_project)) {
509  $proj = new Project($db);
510  $proj->fetch($object->fk_project);
511  $morehtmlref .= $proj->getNomUrl(1);
512  if ($proj->title) {
513  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
514  }
515  }
516  }
517  }
518  $morehtmlref .= '</div>';
519 
520 
521  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
522 
523 
524  print '<div class="fichecenter">';
525  print '<div class="fichehalfleft">';
526  print '<div class="underbanner clearboth"></div>';
527  print '<table class="border centpercent tableforfield">'."\n";
528 
529  //Mo Parent
530  $mo_parent = $object->getMoParent();
531  if (is_object($mo_parent)) {
532  print '<tr class="field_fk_mo_parent">';
533  print '<td class="titlefield fieldname_fk_mo_parent">' . $langs->trans('ParentMo') . '</td>';
534  print '<td class="valuefield fieldname_fk_mo_parent">' .$mo_parent->getNomUrl(1).'</td>';
535  print '</tr>';
536  }
537 
538  // Common attributes
539  $keyforbreak = 'fk_warehouse';
540  unset($object->fields['fk_project']);
541  unset($object->fields['fk_soc']);
542  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
543 
544  // Other attributes
545  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
546 
547  print '</table>';
548  print '</div>';
549  print '</div>';
550 
551  print '<div class="clearboth"></div>';
552 
553  print dol_get_fiche_end();
554 
555 
556  /*
557  * Lines
558  */
559 
560  if (!empty($object->table_element_line)) {
561  // Show object lines
562  //$result = $object->getLinesArray();
563  $object->fetchLines();
564 
565  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
566  <input type="hidden" name="token" value="' . newToken().'">
567  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
568  <input type="hidden" name="mode" value="">
569  <input type="hidden" name="page_y" value="">
570  <input type="hidden" name="id" value="' . $object->id.'">
571  ';
572 
573  /*if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
574  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
575  }*/
576 
577  if (!empty($object->lines)) {
578  print '<div class="div-table-responsive-no-min">';
579  print '<table id="tablelines" class="noborder noshadow" width="100%">';
580 
581  print '<tr class="liste_titre">';
582  print '<td class="liste_titre">'.$langs->trans("Summary").'</td>';
583  print '<td></td>';
584  print '</tr>';
585 
586  print '<tr class="oddeven">';
587  print '<td>'.$langs->trans("ProductsToConsume").'</td>';
588  print '<td>';
589  if (!empty($object->lines)) {
590  $i = 0;
591  foreach ($object->lines as $line) {
592  if ($line->role == 'toconsume') {
593  if ($i) {
594  print ', ';
595  }
596  $tmpproduct = new Product($db);
597  $tmpproduct->fetch($line->fk_product);
598  print $tmpproduct->getNomUrl(1);
599  $i++;
600  }
601  }
602  }
603  print '</td>';
604  print '</tr>';
605 
606  print '<tr class="oddeven">';
607  print '<td>'.$langs->trans("ProductsToProduce").'</td>';
608  print '<td>';
609  if (!empty($object->lines)) {
610  $i = 0;
611  foreach ($object->lines as $line) {
612  if ($line->role == 'toproduce') {
613  if ($i) {
614  print ', ';
615  }
616  $tmpproduct = new Product($db);
617  $tmpproduct->fetch($line->fk_product);
618  print $tmpproduct->getNomUrl(1);
619  $i++;
620  }
621  }
622  }
623  print '</td>';
624  print '</tr>';
625 
626  print '</table>';
627  print '</div>';
628  }
629 
630  print "</form>\n";
631  }
632 
633 
634  // Buttons for actions
635 
636  if ($action != 'presend' && $action != 'editline') {
637  print '<div class="tabsAction">'."\n";
638  $parameters = array();
639  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
640  if ($reshook < 0) {
641  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
642  }
643 
644  if (empty($reshook)) {
645  // Send
646  //if (empty($user->socid)) {
647  // print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
648  //}
649 
650  // Back to draft
651  if ($object->status == $object::STATUS_VALIDATED) {
652  if ($permissiontoadd) {
653  // TODO Add test that production has not started
654  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken().'">'.$langs->trans("SetToDraft").'</a>';
655  }
656  }
657 
658  // Modify
659  if ($object->status == $object::STATUS_DRAFT) {
660  if ($permissiontoadd) {
661  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
662  } else {
663  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
664  }
665  }
666 
667  // Validate
668  if ($object->status == $object::STATUS_DRAFT) {
669  if ($permissiontoadd) {
670  if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
671  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate">'.$langs->trans("Validate").'</a>';
672  } else {
673  $langs->load("errors");
674  print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
675  }
676  }
677  }
678 
679  // Clone
680  if ($permissiontoadd) {
681  print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : "").'&action=clone&object=mo', 'clone', $permissiontoadd);
682  }
683 
684  // Cancel - Reopen
685  if ($permissiontoadd) {
686  if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS) {
687  $arrayproduced = $object->fetchLinesLinked('produced', 0);
688  $nbProduced = 0;
689  foreach ($arrayproduced as $lineproduced) {
690  $nbProduced += $lineproduced['qty'];
691  }
692  if ($nbProduced > 0) { // If production has started, we can close it
693  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_produced&confirm=yes&token='.newToken().'">'.$langs->trans("Close").'</a>'."\n";
694  } else {
695  print '<a class="butActionRefused" href="#" title="'.$langs->trans("GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv("Production")).'">'.$langs->trans("Close").'</a>'."\n";
696  }
697 
698  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_close&confirm=yes&token='.newToken().'">'.$langs->trans("Cancel").'</a>'."\n";
699  }
700 
701  if ($object->status == $object::STATUS_PRODUCED || $object->status == $object::STATUS_CANCELED) {
702  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken().'">'.$langs->trans("ReOpen").'</a>'."\n";
703  }
704  }
705 
706  // Delete
707  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
708  }
709  print '</div>'."\n";
710  }
711 
712 
713  // Select mail models is same action as presend
714  if (GETPOST('modelselected')) {
715  $action = 'presend';
716  }
717 
718  if ($action != 'presend') {
719  print '<div class="fichecenter"><div class="fichehalfleft">';
720  print '<a name="builddoc"></a>'; // ancre
721 
722  // Documents
723  $objref = dol_sanitizeFileName($object->ref);
724  $relativepath = $objref.'/'.$objref.'.pdf';
725  $filedir = $conf->mrp->dir_output.'/'.$objref;
726  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
727  $genallowed = $user->rights->mrp->read; // If you can read, you can build the PDF to read content
728  $delallowed = $user->hasRight("mrp", "creer"); // If you can create/edit, you can remove a file on card
729  print $formfile->showdocuments('mrp:mo', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $mysoc->default_lang);
730 
731  // Show links to link elements
732  $linktoelem = $form->showLinkToObjectBlock($object, null, array('mo'));
733  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, false);
734 
735 
736  print '</div><div class="fichehalfright">';
737 
738  $MAXEVENT = 10;
739 
740  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/mrp/mo_agenda.php?id='.$object->id);
741 
742  // List of actions on element
743  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
744  $formactions = new FormActions($db);
745  $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT, '', $morehtmlcenter);
746 
747  print '</div></div>';
748  }
749 
750  //Select mail models is same action as presend
751  if (GETPOST('modelselected')) {
752  $action = 'presend';
753  }
754 
755  // Presend form
756  $modelmail = 'mo';
757  $defaulttopic = 'InformationMessage';
758  $diroutput = $conf->mrp->dir_output;
759  $trackid = 'mo'.$object->id;
760 
761  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
762 }
763 
764 // End of page
765 llxFooter();
766 $db->close();
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1225
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
Project
Class to manage projects.
Definition: project.class.php:35
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5360
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:520
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
MoLine
Class MoLine.
Definition: mo.class.php:1608
BOMLine
Class for BOMLine.
Definition: bom.class.php:1544
Translate
Class to manage translations.
Definition: translate.class.php:30
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1061
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
Mo
Class for Mo.
Definition: mo.class.php:35
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4538
BOM
Class for BOM.
Definition: bom.class.php:36
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:2082
mrpCollapseBomManagement
mrpCollapseBomManagement()
Manage collapse bom display.
Definition: bom.lib.php:152
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:4024
llxHeader
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
$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:179
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:614
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:11021
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:1858
restrictedArea
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.
Definition: security.lib.php:346
FormProduct
Class with static methods for building HTML components related to products Only components common to ...
Definition: html.formproduct.class.php:30
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11294
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2054
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
dolGetButtonAction
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
Definition: functions.lib.php:10857
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:53
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8465
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
moPrepareHead
moPrepareHead($object)
Prepare array of tabs for Mo.
Definition: mrp_mo.lib.php:30