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