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