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