dolibarr 21.0.3
mo_card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28// Load Dolibarr environment
29require '../main.inc.php';
30
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
34require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
35require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
36require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
38require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php';
39
40if (isModEnabled('workstation')) {
41 require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
42}
43
44
54// Load translation files required by the page
55$langs->loadLangs(array('mrp', 'other'));
56
57
58// Get parameters
59$id = GETPOSTINT('id');
60$ref = GETPOST('ref', 'alpha');
61$action = GETPOST('action', 'aZ09');
62$confirm = GETPOST('confirm', 'alpha');
63$cancel = GETPOST('cancel', 'aZ09');
64$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'mocard'; // To manage different context of search
65$backtopage = GETPOST('backtopage', 'alpha');
66$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
67$TBomLineId = GETPOST('bomlineid', 'array');
68$lineid = GETPOSTINT('lineid');
69$socid = GETPOSTINT("socid");
70
71// Initialize a technical objects
72$object = new Mo($db);
73$objectbom = new BOM($db);
74
75$extrafields = new ExtraFields($db);
76$diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
77$hookmanager->initHooks(array('mocard', 'globalcard')); // Note that conf->hooks_modules contains array
78
79// Fetch optionals attributes and labels
80$extrafields->fetch_name_optionals_label($object->table_element);
81
82$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
83
84// Initialize array of search criteria
85$search_all = GETPOST("search_all", 'alpha');
86$search = array();
87foreach ($object->fields as $key => $val) {
88 if (GETPOST('search_'.$key, 'alpha')) {
89 $search[$key] = GETPOST('search_'.$key, 'alpha');
90 }
91}
92
93if (empty($action) && empty($id) && empty($ref)) {
94 $action = 'view';
95}
96
97// Load object
98include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
99
100if (GETPOSTINT('fk_bom') > 0) {
101 $objectbom->fetch(GETPOSTINT('fk_bom'));
102
103 if ($action != 'add') {
104 // We force calling parameters if we are not in the submit of creation of MO
105 $_POST['fk_product'] = $objectbom->fk_product;
106 $_POST['qty'] = $objectbom->qty;
107 $_POST['mrptype'] = $objectbom->bomtype;
108 $_POST['fk_warehouse'] = $objectbom->fk_warehouse;
109 $_POST['note_private'] = $objectbom->note_private;
110 }
111}
112
113// Security check - Protection if external user
114//if ($user->socid > 0) accessforbidden();
115//if ($user->socid > 0) $socid = $user->socid;
116$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
117$result = restrictedArea($user, 'mrp', $object->id, 'mrp_mo', '', 'fk_soc', 'rowid', $isdraft);
118
119// Permissions
120$permissionnote = $user->hasRight('mrp', 'write'); // Used by the include of actions_setnotes.inc.php
121$permissiondellink = $user->hasRight('mrp', 'write'); // Used by the include of actions_dellink.inc.php
122$permissiontoadd = $user->hasRight('mrp', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
123$permissiontodelete = $user->hasRight('mrp', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
124$upload_dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
125
126
127/*
128 * Actions
129 */
130
131$parameters = array();
132$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
133if ($reshook < 0) {
134 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
135}
136
137if (empty($reshook)) {
138 $error = 0;
139
140 $backurlforlist = dol_buildpath('/mrp/mo_list.php', 1);
141
142 $object->oldQty = $object->qty;
143
144 if (empty($backtopage) || ($cancel && empty($id))) {
145 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
146 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
147 $backtopage = $backurlforlist;
148 } else {
149 $backtopage = DOL_URL_ROOT.'/mrp/mo_card.php?id='.($id > 0 ? $id : '__ID__');
150 }
151 }
152 }
153 if ($cancel && !empty($backtopageforcancel)) {
154 $backtopage = $backtopageforcancel;
155 }
156 $triggermodname = 'MO_MODIFY'; // Name of trigger action code to execute when we modify record
157
158 // Create MO with Children
159 if ($action == 'add' && empty($id) && !empty($TBomLineId) && $permissiontoadd) {
160 $noback = 1;
161 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
162
163 $mo_parent = $object;
164
165 $moline = new MoLine($db);
166 $objectbomchildline = new BOMLine($db);
167
168 foreach ($TBomLineId as $id_bom_line) {
169 $object = new Mo($db); // modified by the actions_addupdatedelete.inc.php
170
171 $objectbomchildline->fetch($id_bom_line);
172
173 $TMoLines = $moline->fetchAll('DESC', 'rowid', '1', '', array('origin_id' => $id_bom_line));
174
175 foreach ($TMoLines as $tmpmoline) {
176 $_POST['fk_bom'] = $objectbomchildline->fk_bom_child;
177 $_POST['fk_parent_line'] = $tmpmoline->id;
178 $_POST['qty'] = $tmpmoline->qty;
179 $_POST['fk_product'] = $tmpmoline->fk_product;
180 }
181
182 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
183
184 $res = $object->add_object_linked('mo', $mo_parent->id);
185 }
186
187 header("Location: ".dol_buildpath('/mrp/mo_card.php?id='.((int) $mo_parent->id), 1));
188 exit;
189 } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && !empty($permissiontoadd)) {
190 $also_cancel_consumed_and_produced_lines = (GETPOST('alsoCancelConsumedAndProducedLines', 'alpha') ? 1 : 0);
191 $result = $object->cancel($user, 0, $also_cancel_consumed_and_produced_lines);
192 if ($result > 0) {
193 header("Location: " . dol_buildpath('/mrp/mo_card.php?id=' . $object->id, 1));
194 exit;
195 } else {
196 $action = '';
197 setEventMessages($object->error, $object->errors, 'errors');
198 }
199 } elseif ($action == 'confirm_delete' && $confirm == 'yes' && !empty($permissiontodelete)) {
200 $also_cancel_consumed_and_produced_lines = (GETPOST('alsoCancelConsumedAndProducedLines', 'alpha') ? 1 : 0);
201 $result = $object->delete($user, 0, $also_cancel_consumed_and_produced_lines);
202 if ($result > 0) {
203 header("Location: " . $backurlforlist);
204 exit;
205 } else {
206 $action = '';
207 setEventMessages($object->error, $object->errors, 'errors');
208 }
209 }
210
211 if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
212 if (!($object->id > 0)) {
213 dol_print_error(null, 'Error, object must be fetched before being deleted');
214 exit;
215 }
216
217 $error = 0;
218 $deleteChilds = GETPOST('deletechilds', 'aZ');
219
220 // Start the database transaction
221 $db->begin();
222
223 if ($deleteChilds === 'on') {
224 $TMoChildren = $object->getAllMoChilds();
225
226 foreach ($TMoChildren as $id => $childObject) {
227 if ($childObject->delete($user) == -1) {
228 $error++;
229 if (!empty($childObject->errors)) {
230 setEventMessages(null, $childObject->errors, 'errors');
231 } else {
232 setEventMessages($childObject->error, null, 'errors');
233 }
234 }
235 }
236 }
237
238 if (!$error) {
239 $result = $object->delete($user);
240
241 if ($result > 0) {
242 setEventMessages("RecordDeleted", null, 'mesgs');
243
244 if ($deleteChilds === 'on') {
245 setEventMessages("MoChildsDeleted", null, 'mesgs');
246 }
247
248 if (empty($noback)) {
249 header("Location: " . $backurlforlist);
250 exit;
251 }
252 } else {
253 $error++;
254 if (!empty($object->errors)) {
255 setEventMessages(null, $object->errors, 'errors');
256 } else {
257 setEventMessages($object->error, null, 'errors');
258 }
259 }
260 }
261
262 // Commit or rollback the database transaction based on whether there was an error
263 if ($error) {
264 $db->rollback();
265 } else {
266 $db->commit();
267 }
268 }
269
270
271 // Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
272 include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
273
274 // Actions when linking object each other
275 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
276
277 // Actions when printing a doc from card
278 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
279
280 // Action to build doc
281 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
282
283 if ($action == 'set_thirdparty' && $permissiontoadd) {
284 $object->setValueFrom('fk_soc', GETPOSTINT('fk_soc'), '', null, 'date', '', $user, $triggermodname);
285 }
286 if ($action == 'classin' && $permissiontoadd) {
287 $object->setProject(GETPOSTINT('projectid'));
288 }
289
290 // Actions to send emails
291 $triggersendname = 'MO_SENTBYMAIL';
292 $autocopy = 'MAIN_MAIL_AUTOCOPY_MO_TO';
293 $trackid = 'mo'.$object->id;
294 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
295
296 // Action to move up and down lines of object
297 //include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
298
299 // Action close produced
300 if ($action == 'confirm_produced' && $confirm == 'yes' && $permissiontoadd) {
301 $result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
302 if ($result >= 0) {
303 // Define output language
304 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
305 $outputlangs = $langs;
306 $newlang = '';
307 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
308 $newlang = GETPOST('lang_id', 'aZ09');
309 }
310 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
311 $newlang = $object->thirdparty->default_lang;
312 }
313 if (!empty($newlang)) {
314 $outputlangs = new Translate("", $conf);
315 $outputlangs->setDefaultLang($newlang);
316 }
317 $model = $object->model_pdf;
318 $ret = $object->fetch($id); // Reload to get new records
319
320 $object->generateDocument($model, $outputlangs, 0, 0, 0);
321 }
322 } else {
323 setEventMessages($object->error, $object->errors, 'errors');
324 }
325 }
326}
327
328
329
330
331/*
332 * View
333 */
334
335$form = new Form($db);
336$formfile = new FormFile($db);
337$formproject = new FormProjets($db);
338
339$title = $langs->trans('ManufacturingOrder')." - ".$langs->trans("Card");
340$help_url = 'EN:Module_Manufacturing_Orders|FR:Module_Ordres_de_Fabrication|DE:Modul_Fertigungsauftrag';
341
342llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-mrp page-card');
343
344
345
346// Part to create
347if ($action == 'create') {
348 if (GETPOSTINT('fk_bom') > 0) {
349 $titlelist = $langs->trans("ToConsume");
350 if ($objectbom->bomtype == 1) {
351 $titlelist = $langs->trans("ToObtain");
352 }
353 }
354
355 print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Mo")), '', 'mrp');
356
357 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
358 print '<input type="hidden" name="token" value="'.newToken().'">';
359 print '<input type="hidden" name="action" value="add">';
360 if ($backtopage) {
361 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
362 }
363 if ($backtopageforcancel) {
364 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
365 }
366
367 print dol_get_fiche_head(array(), '');
368
369 print '<table class="border centpercent tableforfieldcreate">'."\n";
370
371 // Common attributes
372 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
373
374 // Other attributes
375 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
376
377 print '</table>'."\n";
378
379 print dol_get_fiche_end();
380
382 <script>
383 $(document).ready(function () {
384 jQuery('#fk_bom').change(function() {
385 console.log('We change value of BOM with BOM of id '+jQuery('#fk_bom').val());
386 if (jQuery('#fk_bom').val() > 0)
387 {
388 // Redirect to page with fk_bom set
389 window.location.href = '<?php echo $_SERVER["PHP_SELF"] ?>?action=create&token=<?php echo newToken(); ?>&fk_bom='+jQuery('#fk_bom').val();
390 /*
391 $.getJSON('<?php echo DOL_URL_ROOT ?>/mrp/ajax/ajax_bom.php?action=getBoms&idbom='+jQuery('#fk_bom').val(), function(data) {
392 console.log(data);
393 if (typeof data.rowid != "undefined") {
394 console.log("New BOM loaded, we set values in form");
395 console.log(data);
396 $('#qty').val(data.qty);
397 $("#mrptype").val(data.bomtype); // We set bomtype into mrptype
398 $('#mrptype').trigger('change'); // Notify any JS components that the value changed
399 $("#fk_product").val(data.fk_product);
400 $('#fk_product').trigger('change'); // Notify any JS components that the value changed
401 $('#note_private').val(data.description);
402 $('#note_private').trigger('change'); // Notify any JS components that the value changed
403 $('#fk_warehouse').val(data.fk_warehouse);
404 $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
405 if (typeof CKEDITOR != "undefined") {
406 if (typeof CKEDITOR.instances != "undefined") {
407 if (typeof CKEDITOR.instances.note_private != "undefined") {
408 console.log(CKEDITOR.instances.note_private);
409 CKEDITOR.instances.note_private.setData(data.description);
410 }
411 }
412 }
413 } else {
414 console.log("Failed to get BOM");
415 }
416 });*/
417 }
418 else if (jQuery('#fk_bom').val() < 0) {
419 // Redirect to page with all fields defined except fk_bom set
420 console.log(jQuery('#fk_product').val());
421 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();
422 /*
423 $('#qty').val('');
424 $("#fk_product").val('');
425 $('#fk_product').trigger('change'); // Notify any JS components that the value changed
426 $('#note_private').val('');
427 $('#note_private').trigger('change'); // Notify any JS components that the value changed
428 $('#fk_warehouse').val('');
429 $('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
430 */
431 }
432 });
433
434 //jQuery('#fk_bom').trigger('change');
435 })
436 </script>
437 <?php
438
439 print $form->buttonsSaveCancel("Create");
440
441 if ($objectbom->id > 0) {
442 print load_fiche_titre($titlelist);
443
444 print '<!-- list of product/services to consume -->'."\n";
445 print '<div class="div-table-responsive-no-min">';
446 print '<table class="noborder centpercent">';
447
448 $arrayOfMoLines = array();
449 foreach ($objectbom->lines as $key => $val) {
450 $moLine = new MoLine($db);
451 $moLine->id = $objectbom->lines[$key]->id;
452 $moLine->position = $objectbom->lines[$key]->position;
453 $moLine->fk_product = $objectbom->lines[$key]->fk_product;
454 $moLine->fk_unit = $objectbom->lines[$key]->fk_unit;
455 $moLine->qty = $objectbom->lines[$key]->qty;
456 $moLine->qty_frozen = $objectbom->lines[$key]->qty_frozen;
457 $moLine->disable_stock_change = $objectbom->lines[$key]->disable_stock_change;
458 $moLine->fk_bom_child = $objectbom->lines[$key]->fk_bom_child;
459
460 $arrayOfMoLines[] = $moLine;
461 }
462 $object->lines = $arrayOfMoLines;
463 $object->mrptype = $objectbom->bomtype;
464 $object->bom = $objectbom;
465
466 $object->printOriginLinesList('', array());
467
468 print '</table>';
469 print '</div>';
470 }
471
472 print '</form>';
473}
474
475// Part to edit record
476if (($id || $ref) && $action == 'edit') {
477 print load_fiche_titre($langs->trans("ManufacturingOrder"), '', 'mrp');
478
479 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
480 print '<input type="hidden" name="token" value="'.newToken().'">';
481 print '<input type="hidden" name="action" value="update">';
482 print '<input type="hidden" name="id" value="'.$object->id.'">';
483 if ($backtopage) {
484 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
485 }
486 if ($backtopageforcancel) {
487 print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
488 }
489
490 print dol_get_fiche_head();
491
492 $object->fields['fk_bom']['disabled'] = 1;
493
494 print '<table class="border centpercent tableforfieldedit">'."\n";
495
496 // Common attributes
497 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
498
499 // Other attributes
500 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
501
502 print '</table>';
503
504 print dol_get_fiche_end();
505
506 print $form->buttonsSaveCancel();
507
508 print '</form>';
509}
510
511// Part to show record
512if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
513 $res = $object->fetch_thirdparty();
514
515 $head = moPrepareHead($object);
516
517 print dol_get_fiche_head($head, 'card', $langs->trans("ManufacturingOrder"), -1, $object->picto);
518
519 $formconfirm = '';
520
521 // Confirmation to delete
522 if ($action == 'delete') {
523 $numberofmochilds = count($object->getAllMoChilds());
524
525 if ($numberofmochilds > 0) {
526 $label = $langs->trans("DeleteMoChild", '('.strval($numberofmochilds).')');
527 } else {
528 $label = $langs->trans("DeleteMoChild");
529 }
530
531 $formquestion = array(
532 array('type' => 'checkbox', 'name' => 'deletechilds', 'label' => $label, 'value' => 0),
533 array(
534 'label' => $langs->trans('MoCancelConsumedAndProducedLines'),
535 'name' => 'alsoCancelConsumedAndProducedLines',
536 'type' => 'checkbox',
537 'value' => !getDolGlobalString('MO_ALSO_CANCEL_CONSUMED_AND_PRODUCED_LINES_BY_DEFAULT') ? 0 : 1
538 )
539 );
540 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', $formquestion, 0, 1);
541 }
542 // Confirmation to delete line
543 if ($action == 'deleteline') {
544 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
545 }
546
547 // Confirmation of validation
548 if ($action == 'validate') {
549 // We check that object has a temporary ref
550 $ref = substr($object->ref, 1, 4);
551 if ($ref == 'PROV') {
552 $object->fetch_product();
553 $numref = $object->getNextNumRef($object->product);
554 } else {
555 $numref = $object->ref;
556 }
557
558 $text = $langs->trans('ConfirmValidateMo', $numref);
559 /*if (isModEnabled('notification'))
560 {
561 require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
562 $notify = new Notify($db);
563 $text .= '<br>';
564 $text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
565 }*/
566
567 $formquestion = array();
568 if (isModEnabled('mrp')) {
569 $langs->load("mrp");
570 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
571 $formproduct = new FormProduct($db);
572 $forcecombo = 0;
573 if ($conf->browser->name == 'ie') {
574 $forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
575 }
576 $formquestion = array(
577 // 'text' => $langs->trans("ConfirmClone"),
578 // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
579 // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
580 );
581 }
582
583 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
584 }
585
586 // Confirmation to cancel
587 if ($action == 'cancel') {
588 $formquestion = array(
589 array(
590 'label' => $langs->trans('MoCancelConsumedAndProducedLines'),
591 'name' => 'alsoCancelConsumedAndProducedLines',
592 'type' => 'checkbox',
593 'value' => 0
594 ),
595 );
596 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('CancelMo'), $langs->trans('ConfirmCancelMo'), 'confirm_cancel', $formquestion, 0, 1);
597 }
598
599 // Clone confirmation
600 if ($action == 'clone') {
601 // Create an array for form
602 $formquestion = array();
603 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
604 }
605
606 // Call Hook formConfirm
607 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
608 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
609 if (empty($reshook)) {
610 $formconfirm .= $hookmanager->resPrint;
611 } elseif ($reshook > 0) {
612 $formconfirm = $hookmanager->resPrint;
613 }
614
615 // Print form confirm
616 print $formconfirm;
617
618
619 // Object card
620 // ------------------------------------------------------------
621 $linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
622
623 $morehtmlref = '<div class="refidno">';
624 /*
625 // Ref bis
626 $morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', 0, 1);
627 $morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', null, null, '', 1);*/
628 // Thirdparty
629 if (is_object($object->thirdparty)) {
630 $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
631 if (!getDolGlobalString('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
632 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
633 }
634 }
635 // Project
636 if (isModEnabled('project')) {
637 $langs->load("projects");
638 if (is_object($object->thirdparty)) {
639 $morehtmlref .= '<br>';
640 }
641 if ($permissiontoadd) {
642 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
643 if ($action != 'classify') {
644 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
645 }
646 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
647 } else {
648 if (!empty($object->fk_project)) {
649 $proj = new Project($db);
650 $proj->fetch($object->fk_project);
651 $morehtmlref .= $proj->getNomUrl(1);
652 if ($proj->title) {
653 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
654 }
655 }
656 }
657 }
658 $morehtmlref .= '</div>';
659
660
661 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
662
663
664 print '<div class="fichecenter">';
665 print '<div class="fichehalfleft">';
666 print '<div class="underbanner clearboth"></div>';
667 print '<table class="border centpercent tableforfield">'."\n";
668
669 //Mo Parent
670 $mo_parent = $object->getMoParent();
671 if (is_object($mo_parent)) {
672 print '<tr class="field_fk_mo_parent">';
673 print '<td class="titlefield fieldname_fk_mo_parent">' . $langs->trans('ParentMo') . '</td>';
674 print '<td class="valuefield fieldname_fk_mo_parent">' .$mo_parent->getNomUrl(1).'</td>';
675 print '</tr>';
676 }
677
678 // Common attributes
679 $keyforbreak = 'fk_warehouse';
680 unset($object->fields['fk_project']);
681 unset($object->fields['fk_soc']);
682 include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
683
684 // Other attributes
685 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
686
687 print '</table>';
688 print '</div>';
689 print '</div>';
690
691 print '<div class="clearboth"></div>';
692
693 print dol_get_fiche_end();
694
695
696 /*
697 * Lines
698 */
699
700 if (!empty($object->table_element_line)) {
701 // Show object lines
702 //$result = $object->getLinesArray();
703 $object->fetchLines();
704
705 print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOSTINT('lineid')).'" method="POST">
706 <input type="hidden" name="token" value="' . newToken().'">
707 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
708 <input type="hidden" name="mode" value="">
709 <input type="hidden" name="page_y" value="">
710 <input type="hidden" name="id" value="' . $object->id.'">
711 ';
712
713 /*if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
714 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
715 }*/
716
717 if (!empty($object->lines)) {
718 print '<div class="div-table-responsive-no-min">';
719 print '<table id="tablelines" class="noborder noshadow" width="100%">';
720
721 print '<tr class="liste_titre">';
722 print '<td class="liste_titre">'.$langs->trans("Summary").'</td>';
723 print '<td></td>';
724 print '</tr>';
725
726 print '<tr class="oddeven">';
727 print '<td>'.$langs->trans("ProductsToConsume").'</td>';
728 print '<td>';
729 if (!empty($object->lines)) {
730 $i = 0;
731 foreach ($object->lines as $line) {
732 if ($line->role == 'toconsume') {
733 if ($i) {
734 print ', ';
735 }
736 $tmpproduct = new Product($db);
737 $tmpproduct->fetch($line->fk_product);
738 print $tmpproduct->getNomUrl(1);
739 $i++;
740 }
741 }
742 }
743 print '</td>';
744 print '</tr>';
745
746 print '<tr class="oddeven">';
747 print '<td>'.$langs->trans("ProductsToProduce").'</td>';
748 print '<td>';
749 if (!empty($object->lines)) {
750 $i = 0;
751 foreach ($object->lines as $line) {
752 if ($line->role == 'toproduce') {
753 if ($i) {
754 print ', ';
755 }
756 $tmpproduct = new Product($db);
757 $tmpproduct->fetch($line->fk_product);
758 print $tmpproduct->getNomUrl(1);
759 $i++;
760 }
761 }
762 }
763 print '</td>';
764 print '</tr>';
765
766 print '</table>';
767 print '</div>';
768 }
769
770 print "</form>\n";
771 }
772
773
774 // Buttons for actions
775
776 if ($action != 'presend' && $action != 'editline') {
777 print '<div class="tabsAction">'."\n";
778 $parameters = array();
779 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
780 if ($reshook < 0) {
781 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
782 }
783
784 if (empty($reshook)) {
785 // Send
786 //if (empty($user->socid)) {
787 // print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
788 //}
789
790 // Back to draft
791 if ($object->status == $object::STATUS_VALIDATED) {
792 if ($permissiontoadd) {
793 // TODO Add test that production has not started
794 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken().'">'.$langs->trans("SetToDraft").'</a>';
795 }
796 }
797
798 // Modify
799 if ($object->status == $object::STATUS_DRAFT) {
800 if ($permissiontoadd) {
801 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
802 } else {
803 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
804 }
805 }
806
807 // Validate
808 if ($object->status == $object::STATUS_DRAFT) {
809 if ($permissiontoadd) {
810 if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
811 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate&token='.newToken().'">'.$langs->trans("Validate").'</a>';
812 } else {
813 $langs->load("errors");
814 print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
815 }
816 }
817 }
818
819 // Clone
820 if ($permissiontoadd) {
821 print dolGetButtonAction($langs->trans("ToClone"), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.(!empty($object->socid) ? '&socid='.$object->socid : "").'&action=clone&token='.newToken().'&object=mo', 'clone', $permissiontoadd);
822 }
823
824 // Cancel - Reopen
825 if ($permissiontoadd) {
826 if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS) {
827 $arrayproduced = $object->fetchLinesLinked('produced', 0);
828 $nbProduced = 0;
829 foreach ($arrayproduced as $lineproduced) {
830 $nbProduced += $lineproduced['qty'];
831 }
832 if ($nbProduced > 0) { // If production has started, we can close it
833 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_produced&confirm=yes&token='.newToken().'">'.$langs->trans("Close").'</a>'."\n";
834 } else {
835 print '<a class="butActionRefused" href="#" title="'.$langs->trans("GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv("Production")).'">'.$langs->trans("Close").'</a>'."\n";
836 }
837
838 print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=cancel&token='.newToken().'">'.$langs->trans("Cancel").'</a>'."\n";
839 }
840
841 if ($object->status == $object::STATUS_PRODUCED || $object->status == $object::STATUS_CANCELED) {
842 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken().'">'.$langs->trans("ReOpen").'</a>'."\n";
843 }
844 }
845
846 // Delete
847 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', $permissiontodelete);
848 }
849 print '</div>'."\n";
850 }
851
852
853 // Select mail models is same action as presend
854 if (GETPOST('modelselected')) {
855 $action = 'presend';
856 }
857
858 if ($action != 'presend') {
859 print '<div class="fichecenter"><div class="fichehalfleft">';
860 print '<a name="builddoc"></a>'; // ancre
861
862 // Documents
863 $objref = dol_sanitizeFileName($object->ref);
864 $relativepath = $objref.'/'.$objref.'.pdf';
865 $filedir = $conf->mrp->dir_output.'/'.$objref;
866 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
867 $genallowed = $user->hasRight('mrp', 'read'); // If you can read, you can build the PDF to read content
868 $delallowed = $user->hasRight("mrp", "creer"); // If you can create/edit, you can remove a file on card
869 print $formfile->showdocuments('mrp:mo', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $mysoc->default_lang, '', $object);
870
871 // Show links to link elements
872 $tmparray = $form->showLinkToObjectBlock($object, array(), array('mo'), 1);
873 $linktoelem = $tmparray['linktoelem'];
874 $htmltoenteralink = $tmparray['htmltoenteralink'];
875 print $htmltoenteralink;
876
877 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, false);
878
879
880 print '</div><div class="fichehalfright">';
881
882 $MAXEVENT = 10;
883
884 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/mrp/mo_agenda.php?id='.$object->id);
885
886 // List of actions on element
887 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
888 $formactions = new FormActions($db);
889 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT, '', $morehtmlcenter);
890
891 print '</div></div>';
892 }
893
894 //Select mail models is same action as presend
895 if (GETPOST('modelselected')) {
896 $action = 'presend';
897 }
898
899 // Presend form
900 $modelmail = 'mo';
901 $defaulttopic = 'InformationMessage';
902 $diroutput = $conf->mrp->dir_output;
903 $trackid = 'mo'.$object->id;
904
905 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
906}
907
908// End of page
909llxFooter();
910$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
mrpCollapseBomManagement()
Manage collapse bom display.
Definition bom.lib.php:153
Class for BOM.
Definition bom.class.php:42
Class for BOMLine.
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.
Class to manage products or services.
Class to manage projects.
Class to manage translations.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
moPrepareHead($object)
Prepare array of tabs for Mo.
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.