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