dolibarr  20.0.0-alpha
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 = GETPOSTINT('id');
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 = GETPOSTINT('lineid');
57 $socid = GETPOSTINT("socid");
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 criteria
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 (GETPOSTINT('fk_bom') > 0) {
89  $objectbom->fetch(GETPOSTINT('fk_bom'));
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->hasRight('mrp', 'write'); // Used by the include of actions_setnotes.inc.php
109 $permissiondellink = $user->hasRight('mrp', 'write'); // Used by the include of actions_dellink.inc.php
110 $permissiontoadd = $user->hasRight('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 Children
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) $mo_parent->id), 1));
176  exit;
177  } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && !empty($permissiontoadd)) {
178  $also_cancel_consumed_and_produced_lines = (GETPOST('alsoCancelConsumedAndProducedLines', 'alpha') ? 1 : 0);
179  $result = $object->cancel($user, 0, $also_cancel_consumed_and_produced_lines);
180  if ($result > 0) {
181  header("Location: " . dol_buildpath('/mrp/mo_card.php?id=' . $object->id, 1));
182  exit;
183  } else {
184  $action = '';
185  setEventMessages($object->error, $object->errors, 'errors');
186  }
187  } elseif ($action == 'confirm_delete' && $confirm == 'yes' && !empty($permissiontodelete)) {
188  $also_cancel_consumed_and_produced_lines = (GETPOST('alsoCancelConsumedAndProducedLines', 'alpha') ? 1 : 0);
189  $result = $object->delete($user, 0, $also_cancel_consumed_and_produced_lines);
190  if ($result > 0) {
191  header("Location: " . $backurlforlist);
192  exit;
193  } else {
194  $action = '';
195  setEventMessages($object->error, $object->errors, 'errors');
196  }
197  }
198 
199  if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
200  if (!($object->id > 0)) {
201  dol_print_error(null, 'Error, object must be fetched before being deleted');
202  exit;
203  }
204 
205  $error = 0;
206  $deleteChilds = GETPOST('deletechilds', 'aZ');
207 
208  // Start the database transaction
209  $db->begin();
210 
211  if ($deleteChilds === 'on') {
212  $TMoChildren = $object->getAllMoChilds();
213 
214  foreach ($TMoChildren as $id => $childObject) {
215  if ($childObject->delete($user) == -1) {
216  $error++;
217  if (!empty($childObject->errors)) {
218  setEventMessages(null, $childObject->errors, 'errors');
219  } else {
220  setEventMessages($childObject->error, null, 'errors');
221  }
222  }
223  }
224  }
225 
226  if (!$error) {
227  $result = $object->delete($user);
228 
229  if ($result > 0) {
230  setEventMessages("RecordDeleted", null, 'mesgs');
231 
232  if ($deleteChilds === 'on') {
233  setEventMessages("MoChildsDeleted", null, 'mesgs');
234  }
235 
236  if (empty($noback)) {
237  header("Location: " . $backurlforlist);
238  exit;
239  }
240  } else {
241  $error++;
242  if (!empty($object->errors)) {
243  setEventMessages(null, $object->errors, 'errors');
244  } else {
245  setEventMessages($object->error, null, 'errors');
246  }
247  }
248  }
249 
250  // Commit or rollback the database transaction based on whether there was an error
251  if ($error) {
252  $db->rollback();
253  } else {
254  $db->commit();
255  }
256  }
257 
258 
259  // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
260  include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
261 
262  // Actions when linking object each other
263  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
264 
265  // Actions when printing a doc from card
266  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
267 
268  // Action to build doc
269  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
270 
271  if ($action == 'set_thirdparty' && $permissiontoadd) {
272  $object->setValueFrom('fk_soc', GETPOSTINT('fk_soc'), '', '', 'date', '', $user, $triggermodname);
273  }
274  if ($action == 'classin' && $permissiontoadd) {
275  $object->setProject(GETPOSTINT('projectid'));
276  }
277 
278  // Actions to send emails
279  $triggersendname = 'MO_SENTBYMAIL';
280  $autocopy = 'MAIN_MAIL_AUTOCOPY_MO_TO';
281  $trackid = 'mo'.$object->id;
282  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
283 
284  // Action to move up and down lines of object
285  //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
286 
287  // Action close produced
288  if ($action == 'confirm_produced' && $confirm == 'yes' && $permissiontoadd) {
289  $result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
290  if ($result >= 0) {
291  // Define output language
292  if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
293  $outputlangs = $langs;
294  $newlang = '';
295  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
296  $newlang = GETPOST('lang_id', 'aZ09');
297  }
298  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
299  $newlang = $object->thirdparty->default_lang;
300  }
301  if (!empty($newlang)) {
302  $outputlangs = new Translate("", $conf);
303  $outputlangs->setDefaultLang($newlang);
304  }
305  $model = $object->model_pdf;
306  $ret = $object->fetch($id); // Reload to get new records
307 
308  $object->generateDocument($model, $outputlangs, 0, 0, 0);
309  }
310  } else {
311  setEventMessages($object->error, $object->errors, 'errors');
312  }
313  }
314 }
315 
316 
317 
318 
319 /*
320  * View
321  */
322 
323 $form = new Form($db);
324 $formfile = new FormFile($db);
325 $formproject = new FormProjets($db);
326 
327 $title = $langs->trans('ManufacturingOrder')." - ".$langs->trans("Card");
328 
329 llxHeader('', $title, '');
330 
331 
332 
333 // Part to create
334 if ($action == 'create') {
335  if (GETPOSTINT('fk_bom') > 0) {
336  $titlelist = $langs->trans("ToConsume");
337  if ($objectbom->bomtype == 1) {
338  $titlelist = $langs->trans("ToObtain");
339  }
340  }
341 
342  print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Mo")), '', 'mrp');
343 
344  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
345  print '<input type="hidden" name="token" value="'.newToken().'">';
346  print '<input type="hidden" name="action" value="add">';
347  if ($backtopage) {
348  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
349  }
350  if ($backtopageforcancel) {
351  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
352  }
353 
354  print dol_get_fiche_head(array(), '');
355 
356  print '<table class="border centpercent tableforfieldcreate">'."\n";
357 
358  // Common attributes
359  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
360 
361  // Other attributes
362  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
363 
364  print '</table>'."\n";
365 
366  print dol_get_fiche_end();
367 
369  <script>
370  $(document).ready(function () {
371  jQuery('#fk_bom').change(function() {
372  console.log('We change value of BOM with BOM of id '+jQuery('#fk_bom').val());
373  if (jQuery('#fk_bom').val() > 0)
374  {
375  // Redirect to page with fk_bom set
376  window.location.href = '<?php echo $_SERVER["PHP_SELF"] ?>?action=create&token=<?php echo newToken(); ?>&fk_bom='+jQuery('#fk_bom').val();
377  /*
378  $.getJSON('<?php echo DOL_URL_ROOT ?>/mrp/ajax/ajax_bom.php?action=getBoms&idbom='+jQuery('#fk_bom').val(), function(data) {
379  console.log(data);
380  if (typeof data.rowid != "undefined") {
381  console.log("New BOM loaded, we set values in form");
382  console.log(data);
383  $('#qty').val(data.qty);
384  $("#mrptype").val(data.bomtype); // We set bomtype into mrptype
385  $('#mrptype').trigger('change'); // Notify any JS components that the value changed
386  $("#fk_product").val(data.fk_product);
387  $('#fk_product').trigger('change'); // Notify any JS components that the value changed
388  $('#note_private').val(data.description);
389  $('#note_private').trigger('change'); // Notify any JS components that the value changed
390  $('#fk_warehouse').val(data.fk_warehouse);
391  $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
392  if (typeof CKEDITOR != "undefined") {
393  if (typeof CKEDITOR.instances != "undefined") {
394  if (typeof CKEDITOR.instances.note_private != "undefined") {
395  console.log(CKEDITOR.instances.note_private);
396  CKEDITOR.instances.note_private.setData(data.description);
397  }
398  }
399  }
400  } else {
401  console.log("Failed to get BOM");
402  }
403  });*/
404  }
405  else if (jQuery('#fk_bom').val() < 0) {
406  // Redirect to page with all fields defined except fk_bom set
407  console.log(jQuery('#fk_product').val());
408  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();
409  /*
410  $('#qty').val('');
411  $("#fk_product").val('');
412  $('#fk_product').trigger('change'); // Notify any JS components that the value changed
413  $('#note_private').val('');
414  $('#note_private').trigger('change'); // Notify any JS components that the value changed
415  $('#fk_warehouse').val('');
416  $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
417  */
418  }
419  });
420 
421  //jQuery('#fk_bom').trigger('change');
422  })
423  </script>
424  <?php
425 
426  print $form->buttonsSaveCancel("Create");
427 
428  if ($objectbom->id > 0) {
429  print load_fiche_titre($titlelist);
430 
431  print '<!-- list of product/services to consume -->'."\n";
432  print '<div class="div-table-responsive-no-min">';
433  print '<table class="noborder centpercent">';
434 
435  $arrayOfMoLines = array();
436  foreach ($objectbom->lines as $key => $val) {
437  $moLine = new MoLine($db);
438  $moLine->id = $objectbom->lines[$key]->id;
439  $moLine->position = $objectbom->lines[$key]->position;
440  $moLine->fk_product = $objectbom->lines[$key]->fk_product;
441  $moLine->fk_unit = $objectbom->lines[$key]->fk_unit;
442  $moLine->qty = $objectbom->lines[$key]->qty;
443  $moLine->qty_frozen = $objectbom->lines[$key]->qty_frozen;
444  $moLine->disable_stock_change = $objectbom->lines[$key]->disable_stock_change;
445 
446  $arrayOfMoLines[] = $moLine;
447  }
448  $object->lines = $arrayOfMoLines;
449  $object->mrptype = $objectbom->bomtype;
450  $object->bom = $objectbom;
451 
452  $object->printOriginLinesList('', array());
453 
454  print '</table>';
455  print '</div>';
456  }
457 
458  print '</form>';
459 }
460 
461 // Part to edit record
462 if (($id || $ref) && $action == 'edit') {
463  print load_fiche_titre($langs->trans("ManufacturingOrder"), '', 'mrp');
464 
465  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
466  print '<input type="hidden" name="token" value="'.newToken().'">';
467  print '<input type="hidden" name="action" value="update">';
468  print '<input type="hidden" name="id" value="'.$object->id.'">';
469  if ($backtopage) {
470  print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
471  }
472  if ($backtopageforcancel) {
473  print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
474  }
475 
476  print dol_get_fiche_head();
477 
478  $object->fields['fk_bom']['disabled'] = 1;
479 
480  print '<table class="border centpercent tableforfieldedit">'."\n";
481 
482  // Common attributes
483  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
484 
485  // Other attributes
486  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
487 
488  print '</table>';
489 
490  print dol_get_fiche_end();
491 
492  print $form->buttonsSaveCancel();
493 
494  print '</form>';
495 }
496 
497 // Part to show record
498 if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
499  $res = $object->fetch_thirdparty();
500 
501  $head = moPrepareHead($object);
502 
503  print dol_get_fiche_head($head, 'card', $langs->trans("ManufacturingOrder"), -1, $object->picto);
504 
505  $formconfirm = '';
506 
507  // Confirmation to delete
508  if ($action == 'delete') {
509  $numberofmochilds = count($object->getAllMoChilds());
510 
511  if ($numberofmochilds > 0) {
512  $label = $langs->trans("DeleteMoChild", '('.strval($numberofmochilds).')');
513  } else {
514  $label = $langs->trans("DeleteMoChild");
515  }
516 
517  $formquestion = array(
518  array('type' => 'checkbox', 'name' => 'deletechilds', 'label' => $label, 'value' => 0),
519  array(
520  'label' => $langs->trans('MoCancelConsumedAndProducedLines'),
521  'name' => 'alsoCancelConsumedAndProducedLines',
522  'type' => 'checkbox',
523  'value' => !getDolGlobalString('MO_ALSO_CANCEL_CONSUMED_AND_PRODUCED_LINES_BY_DEFAULT') ? 0 : 1
524  )
525  );
526  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', $formquestion, 0, 1);
527  }
528  // Confirmation to delete line
529  if ($action == 'deleteline') {
530  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
531  }
532 
533  // Confirmation of validation
534  if ($action == 'validate') {
535  // We check that object has a temporary ref
536  $ref = substr($object->ref, 1, 4);
537  if ($ref == 'PROV') {
538  $object->fetch_product();
539  $numref = $object->getNextNumRef($object->product);
540  } else {
541  $numref = $object->ref;
542  }
543 
544  $text = $langs->trans('ConfirmValidateMo', $numref);
545  /*if (isModEnabled('notification'))
546  {
547  require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
548  $notify = new Notify($db);
549  $text .= '<br>';
550  $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
551  }*/
552 
553  $formquestion = array();
554  if (isModEnabled('mrp')) {
555  $langs->load("mrp");
556  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
557  $formproduct = new FormProduct($db);
558  $forcecombo = 0;
559  if ($conf->browser->name == 'ie') {
560  $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
561  }
562  $formquestion = array(
563  // 'text' => $langs->trans("ConfirmClone"),
564  // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
565  // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
566  );
567  }
568 
569  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
570  }
571 
572  // Confirmation to cancel
573  if ($action == 'cancel') {
574  $formquestion = array(
575  array(
576  'label' => $langs->trans('MoCancelConsumedAndProducedLines'),
577  'name' => 'alsoCancelConsumedAndProducedLines',
578  'type' => 'checkbox',
579  'value' => 0
580  ),
581  );
582  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CancelMo'), $langs->trans('ConfirmCancelMo'), 'confirm_cancel', $formquestion, 0, 1);
583  }
584 
585  // Clone confirmation
586  if ($action == 'clone') {
587  // Create an array for form
588  $formquestion = array();
589  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
590  }
591 
592  // Call Hook formConfirm
593  $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
594  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
595  if (empty($reshook)) {
596  $formconfirm .= $hookmanager->resPrint;
597  } elseif ($reshook > 0) {
598  $formconfirm = $hookmanager->resPrint;
599  }
600 
601  // Print form confirm
602  print $formconfirm;
603 
604 
605  // Object card
606  // ------------------------------------------------------------
607  $linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
608 
609  $morehtmlref = '<div class="refidno">';
610  /*
611  // Ref bis
612  $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', 0, 1);
613  $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', null, null, '', 1);*/
614  // Thirdparty
615  if (is_object($object->thirdparty)) {
616  $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
617  if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
618  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
619  }
620  }
621  // Project
622  if (isModEnabled('project')) {
623  $langs->load("projects");
624  if (is_object($object->thirdparty)) {
625  $morehtmlref .= '<br>';
626  }
627  if ($permissiontoadd) {
628  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
629  if ($action != 'classify') {
630  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
631  }
632  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
633  } else {
634  if (!empty($object->fk_project)) {
635  $proj = new Project($db);
636  $proj->fetch($object->fk_project);
637  $morehtmlref .= $proj->getNomUrl(1);
638  if ($proj->title) {
639  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
640  }
641  }
642  }
643  }
644  $morehtmlref .= '</div>';
645 
646 
647  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
648 
649 
650  print '<div class="fichecenter">';
651  print '<div class="fichehalfleft">';
652  print '<div class="underbanner clearboth"></div>';
653  print '<table class="border centpercent tableforfield">'."\n";
654 
655  //Mo Parent
656  $mo_parent = $object->getMoParent();
657  if (is_object($mo_parent)) {
658  print '<tr class="field_fk_mo_parent">';
659  print '<td class="titlefield fieldname_fk_mo_parent">' . $langs->trans('ParentMo') . '</td>';
660  print '<td class="valuefield fieldname_fk_mo_parent">' .$mo_parent->getNomUrl(1).'</td>';
661  print '</tr>';
662  }
663 
664  // Common attributes
665  $keyforbreak = 'fk_warehouse';
666  unset($object->fields['fk_project']);
667  unset($object->fields['fk_soc']);
668  include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
669 
670  // Other attributes
671  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
672 
673  print '</table>';
674  print '</div>';
675  print '</div>';
676 
677  print '<div class="clearboth"></div>';
678 
679  print dol_get_fiche_end();
680 
681 
682  /*
683  * Lines
684  */
685 
686  if (!empty($object->table_element_line)) {
687  // Show object lines
688  //$result = $object->getLinesArray();
689  $object->fetchLines();
690 
691  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOSTINT('lineid')).'" method="POST">
692  <input type="hidden" name="token" value="' . newToken().'">
693  <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
694  <input type="hidden" name="mode" value="">
695  <input type="hidden" name="page_y" value="">
696  <input type="hidden" name="id" value="' . $object->id.'">
697  ';
698 
699  /*if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
700  include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
701  }*/
702 
703  if (!empty($object->lines)) {
704  print '<div class="div-table-responsive-no-min">';
705  print '<table id="tablelines" class="noborder noshadow" width="100%">';
706 
707  print '<tr class="liste_titre">';
708  print '<td class="liste_titre">'.$langs->trans("Summary").'</td>';
709  print '<td></td>';
710  print '</tr>';
711 
712  print '<tr class="oddeven">';
713  print '<td>'.$langs->trans("ProductsToConsume").'</td>';
714  print '<td>';
715  if (!empty($object->lines)) {
716  $i = 0;
717  foreach ($object->lines as $line) {
718  if ($line->role == 'toconsume') {
719  if ($i) {
720  print ', ';
721  }
722  $tmpproduct = new Product($db);
723  $tmpproduct->fetch($line->fk_product);
724  print $tmpproduct->getNomUrl(1);
725  $i++;
726  }
727  }
728  }
729  print '</td>';
730  print '</tr>';
731 
732  print '<tr class="oddeven">';
733  print '<td>'.$langs->trans("ProductsToProduce").'</td>';
734  print '<td>';
735  if (!empty($object->lines)) {
736  $i = 0;
737  foreach ($object->lines as $line) {
738  if ($line->role == 'toproduce') {
739  if ($i) {
740  print ', ';
741  }
742  $tmpproduct = new Product($db);
743  $tmpproduct->fetch($line->fk_product);
744  print $tmpproduct->getNomUrl(1);
745  $i++;
746  }
747  }
748  }
749  print '</td>';
750  print '</tr>';
751 
752  print '</table>';
753  print '</div>';
754  }
755 
756  print "</form>\n";
757  }
758 
759 
760  // Buttons for actions
761 
762  if ($action != 'presend' && $action != 'editline') {
763  print '<div class="tabsAction">'."\n";
764  $parameters = array();
765  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
766  if ($reshook < 0) {
767  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
768  }
769 
770  if (empty($reshook)) {
771  // Send
772  //if (empty($user->socid)) {
773  // print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
774  //}
775 
776  // Back to draft
777  if ($object->status == $object::STATUS_VALIDATED) {
778  if ($permissiontoadd) {
779  // TODO Add test that production has not started
780  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken().'">'.$langs->trans("SetToDraft").'</a>';
781  }
782  }
783 
784  // Modify
785  if ($object->status == $object::STATUS_DRAFT) {
786  if ($permissiontoadd) {
787  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
788  } else {
789  print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
790  }
791  }
792 
793  // Validate
794  if ($object->status == $object::STATUS_DRAFT) {
795  if ($permissiontoadd) {
796  if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
797  print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate">'.$langs->trans("Validate").'</a>';
798  } else {
799  $langs->load("errors");
800  print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
801  }
802  }
803  }
804 
805  // Clone
806  if ($permissiontoadd) {
807  print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : "").'&action=clone&object=mo', 'clone', $permissiontoadd);
808  }
809 
810  // Cancel - Reopen
811  if ($permissiontoadd) {
812  if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS) {
813  $arrayproduced = $object->fetchLinesLinked('produced', 0);
814  $nbProduced = 0;
815  foreach ($arrayproduced as $lineproduced) {
816  $nbProduced += $lineproduced['qty'];
817  }
818  if ($nbProduced > 0) { // If production has started, we can close it
819  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_produced&confirm=yes&token='.newToken().'">'.$langs->trans("Close").'</a>'."\n";
820  } else {
821  print '<a class="butActionRefused" href="#" title="'.$langs->trans("GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv("Production")).'">'.$langs->trans("Close").'</a>'."\n";
822  }
823 
824  print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'">'.$langs->trans("Cancel").'</a>'."\n";
825  }
826 
827  if ($object->status == $object::STATUS_PRODUCED || $object->status == $object::STATUS_CANCELED) {
828  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken().'">'.$langs->trans("ReOpen").'</a>'."\n";
829  }
830  }
831 
832  // Delete
833  print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
834  }
835  print '</div>'."\n";
836  }
837 
838 
839  // Select mail models is same action as presend
840  if (GETPOST('modelselected')) {
841  $action = 'presend';
842  }
843 
844  if ($action != 'presend') {
845  print '<div class="fichecenter"><div class="fichehalfleft">';
846  print '<a name="builddoc"></a>'; // ancre
847 
848  // Documents
849  $objref = dol_sanitizeFileName($object->ref);
850  $relativepath = $objref.'/'.$objref.'.pdf';
851  $filedir = $conf->mrp->dir_output.'/'.$objref;
852  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
853  $genallowed = $user->hasRight('mrp', 'read'); // If you can read, you can build the PDF to read content
854  $delallowed = $user->hasRight("mrp", "creer"); // If you can create/edit, you can remove a file on card
855  print $formfile->showdocuments('mrp:mo', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $mysoc->default_lang);
856 
857  // Show links to link elements
858  $linktoelem = $form->showLinkToObjectBlock($object, null, array('mo'));
859  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, false);
860 
861 
862  print '</div><div class="fichehalfright">';
863 
864  $MAXEVENT = 10;
865 
866  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/mrp/mo_agenda.php?id='.$object->id);
867 
868  // List of actions on element
869  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
870  $formactions = new FormActions($db);
871  $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT, '', $morehtmlcenter);
872 
873  print '</div></div>';
874  }
875 
876  //Select mail models is same action as presend
877  if (GETPOST('modelselected')) {
878  $action = 'presend';
879  }
880 
881  // Presend form
882  $modelmail = 'mo';
883  $defaulttopic = 'InformationMessage';
884  $diroutput = $conf->mrp->dir_output;
885  $trackid = 'mo'.$object->id;
886 
887  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
888 }
889 
890 // End of page
891 llxFooter();
892 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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:45
Class for BOMLine.
Definition: bom.class.php:1670
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage building of HTML components.
Class for Mo.
Definition: mo.class.php:36
Class MoLine.
Definition: mo.class.php:1990
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
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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 a Dolibarr global constant int value.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
$formconfirm
if ($action == 'delbookkeepingyear') {
moPrepareHead($object)
Prepare array of tabs for Mo.
Definition: mrp_mo.lib.php:31
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.