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