26 require
'../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/mrp/class/mo.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/mrp/lib/mrp_mo.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/bom/class/bom.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/bom/lib/bom.lib.php';
39 $langs->loadLangs(array(
'mrp',
'other'));
45 $action =
GETPOST(
'action',
'aZ09');
46 $confirm =
GETPOST(
'confirm',
'alpha');
47 $cancel =
GETPOST(
'cancel',
'aZ09');
48 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'mocard';
49 $backtopage =
GETPOST(
'backtopage',
'alpha');
50 $backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
51 $TBomLineId =
GETPOST(
'bomlineid',
'array');
52 $lineid =
GETPOST(
'lineid',
'int');
53 $socid =
GETPOST(
"socid",
'int');
56 $object =
new Mo($db);
57 $objectbom =
new BOM($db);
60 $diroutputmassaction = $conf->mrp->dir_output.
'/temp/massgeneration/'.$user->id;
61 $hookmanager->initHooks(array(
'mocard',
'globalcard'));
64 $extrafields->fetch_name_optionals_label($object->table_element);
66 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element,
'',
'search_');
69 $search_all =
GETPOST(
"search_all",
'alpha');
71 foreach ($object->fields as $key => $val) {
72 if (
GETPOST(
'search_'.$key,
'alpha')) {
73 $search[$key] =
GETPOST(
'search_'.$key,
'alpha');
77 if (empty($action) && empty($id) && empty($ref)) {
82 include DOL_DOCUMENT_ROOT.
'/core/actions_fetchobject.inc.php';
84 if (
GETPOST(
'fk_bom',
'int') > 0) {
85 $objectbom->fetch(
GETPOST(
'fk_bom',
'int'));
87 if ($action !=
'add') {
89 $_POST[
'fk_product'] = $objectbom->fk_product;
90 $_POST[
'qty'] = $objectbom->qty;
91 $_POST[
'mrptype'] = $objectbom->bomtype;
92 $_POST[
'fk_warehouse'] = $objectbom->fk_warehouse;
93 $_POST[
'note_private'] = $objectbom->note_private;
100 $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
101 $result =
restrictedArea($user,
'mrp', $object->id,
'mrp_mo',
'',
'fk_soc',
'rowid', $isdraft);
104 $permissionnote = $user->rights->mrp->write;
105 $permissiondellink = $user->rights->mrp->write;
106 $permissiontoadd = $user->rights->mrp->write;
107 $permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
108 $upload_dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
115 $parameters = array();
116 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
121 if (empty($reshook)) {
126 $object->oldQty = $object->qty;
128 if (empty($backtopage) || ($cancel && empty($id))) {
129 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
130 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
131 $backtopage = $backurlforlist;
133 $backtopage = DOL_URL_ROOT.
'/mrp/mo_card.php?id='.($id > 0 ? $id :
'__ID__');
137 if ($cancel && !empty($backtopageforcancel)) {
138 $backtopage = $backtopageforcancel;
140 $triggermodname =
'MO_MODIFY';
143 if ($action ==
'add' && empty($id) && !empty($TBomLineId)) {
145 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
147 $mo_parent = $object;
149 $moline =
new MoLine($db);
150 $objectbomchildline =
new BOMLine($db);
152 foreach ($TBomLineId as $id_bom_line) {
153 $object =
new Mo($db);
155 $objectbomchildline->fetch($id_bom_line);
157 $TMoLines = $moline->fetchAll(
'DESC',
'rowid',
'1',
'', array(
'origin_id' => $id_bom_line));
159 foreach ($TMoLines as $moline) {
160 $_POST[
'fk_bom'] = $objectbomchildline->fk_bom_child;
161 $_POST[
'fk_parent_line'] = $moline->id;
162 $_POST[
'qty'] = $moline->qty;
163 $_POST[
'fk_product'] = $moline->fk_product;
166 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
168 $res = $object->add_object_linked(
'mo', $mo_parent->id);
171 header(
"Location: ".
dol_buildpath(
'/mrp/mo_card.php?id='.((
int) $moline->fk_mo), 1));
176 include DOL_DOCUMENT_ROOT.
'/core/actions_addupdatedelete.inc.php';
179 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
182 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
185 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
187 if ($action ==
'set_thirdparty' && $permissiontoadd) {
188 $object->setValueFrom(
'fk_soc',
GETPOST(
'fk_soc',
'int'),
'',
'',
'date',
'', $user, $triggermodname);
190 if ($action ==
'classin' && $permissiontoadd) {
191 $object->setProject(
GETPOST(
'projectid',
'int'));
195 $triggersendname =
'MO_SENTBYMAIL';
196 $autocopy =
'MAIN_MAIL_AUTOCOPY_MO_TO';
197 $trackid =
'mo'.$object->id;
198 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
204 if ($action ==
'confirm_produced' && $confirm ==
'yes' && $permissiontoadd) {
205 $result = $object->setStatut($object::STATUS_PRODUCED, 0,
'',
'MRP_MO_PRODUCED');
208 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
209 $outputlangs = $langs;
212 $newlang =
GETPOST(
'lang_id',
'aZ09');
215 $newlang = $object->thirdparty->default_lang;
217 if (!empty($newlang)) {
219 $outputlangs->setDefaultLang($newlang);
221 $model = $object->model_pdf;
222 $ret = $object->fetch($id);
224 $object->generateDocument($model, $outputlangs, 0, 0, 0);
243 $title = $langs->trans(
'ManufacturingOrder').
" - ".$langs->trans(
"Card");
250 if ($action ==
'create') {
251 if (
GETPOST(
'fk_bom',
'int') > 0) {
252 $titlelist = $langs->trans(
"ToConsume");
253 if ($objectbom->bomtype == 1) {
254 $titlelist = $langs->trans(
"ToObtain");
258 print
load_fiche_titre($langs->trans(
"NewObject", $langs->transnoentitiesnoconv(
"Mo")),
'',
'mrp');
260 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
261 print
'<input type="hidden" name="token" value="'.newToken().
'">';
262 print
'<input type="hidden" name="action" value="add">';
264 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
266 if ($backtopageforcancel) {
267 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
272 print
'<table class="border centpercent tableforfieldcreate">'.
"\n";
275 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_add.tpl.php';
278 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_add.tpl.php';
280 print
'</table>'.
"\n";
288 $(document).ready(
function () {
289 jQuery(
'#fk_bom').change(
function() {
290 console.log(
'We change value of BOM with BOM of id '+jQuery(
'#fk_bom').val());
291 if (jQuery(
'#fk_bom').val() > 0)
294 window.location.href =
'<?php echo $_SERVER["PHP_SELF"] ?>?action=create&token=<?php echo newToken(); ?>&fk_bom='+jQuery(
'#fk_bom').val();
323 else if (jQuery(
'#fk_bom').val() < 0) {
325 console.log(jQuery(
'#fk_product').val());
326 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();
344 print
$form->buttonsSaveCancel(
"Create");
346 if ($objectbom->id > 0) {
349 print
'<div class="div-table-responsive-no-min">';
350 print
'<table class="noborder centpercent">';
352 $object->lines = $objectbom->lines;
353 $object->mrptype = $objectbom->bomtype;
354 $object->bom = $objectbom;
356 $object->printOriginLinesList(
'', array());
366 if (($id || $ref) && $action ==
'edit') {
369 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'">';
370 print
'<input type="hidden" name="token" value="'.newToken().
'">';
371 print
'<input type="hidden" name="action" value="update">';
372 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
374 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
376 if ($backtopageforcancel) {
377 print
'<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.
'">';
382 $object->fields[
'fk_bom'][
'disabled'] = 1;
384 print
'<table class="border centpercent tableforfieldedit">'.
"\n";
387 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_edit.tpl.php';
390 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_edit.tpl.php';
396 print
$form->buttonsSaveCancel();
402 if ($object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
403 $res = $object->fetch_thirdparty();
407 print
dol_get_fiche_head($head,
'card', $langs->trans(
"ManufacturingOrder"), -1, $object->picto);
412 if ($action ==
'delete') {
413 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'DeleteMo'), $langs->trans(
'ConfirmDeleteMo'),
'confirm_delete',
'', 0, 1);
416 if ($action ==
'deleteline') {
417 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&lineid='.$lineid, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_deleteline',
'', 0, 1);
421 if ($action ==
'validate') {
423 $ref = substr($object->ref, 1, 4);
424 if ($ref ==
'PROV') {
425 $object->fetch_product();
426 $numref = $object->getNextNumRef($object->fk_product);
428 $numref = $object->ref;
431 $text = $langs->trans(
'ConfirmValidateMo', $numref);
440 $formquestion = array();
443 require_once DOL_DOCUMENT_ROOT.
'/product/class/html.formproduct.class.php';
446 if ($conf->browser->name ==
'ie') {
449 $formquestion = array(
456 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'Validate'), $text,
'confirm_validate', $formquestion, 0, 1, 220);
460 if ($action ==
'clone') {
462 $formquestion = array();
463 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneMo', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
467 $parameters = array(
'formConfirm' =>
$formconfirm,
'lineid' => $lineid);
468 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
469 if (empty($reshook)) {
471 } elseif ($reshook > 0) {
481 $linkback =
'<a href="'.dol_buildpath(
'/mrp/mo_list.php', 1).
'?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
483 $morehtmlref =
'<div class="refidno">';
489 if (is_object($object->thirdparty)) {
490 $morehtmlref .= $object->thirdparty->getNomUrl(1,
'customer');
491 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
492 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/commande/list.php?socid='.$object->thirdparty->id.
'&search_societe='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherOrders").
'</a>)';
497 $langs->load(
"projects");
498 if (is_object($object->thirdparty)) {
499 $morehtmlref .=
'<br>';
501 if ($permissiontoadd) {
502 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
503 if ($action !=
'classify') {
504 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
506 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
508 if (!empty($object->fk_project)) {
510 $proj->fetch($object->fk_project);
511 $morehtmlref .= $proj->getNomUrl(1);
513 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
518 $morehtmlref .=
'</div>';
521 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'ref', $morehtmlref);
524 print
'<div class="fichecenter">';
525 print
'<div class="fichehalfleft">';
526 print
'<div class="underbanner clearboth"></div>';
527 print
'<table class="border centpercent tableforfield">'.
"\n";
530 $mo_parent = $object->getMoParent();
531 if (is_object($mo_parent)) {
532 print
'<tr class="field_fk_mo_parent">';
533 print
'<td class="titlefield fieldname_fk_mo_parent">' . $langs->trans(
'ParentMo') .
'</td>';
534 print
'<td class="valuefield fieldname_fk_mo_parent">' .$mo_parent->getNomUrl(1).
'</td>';
539 $keyforbreak =
'fk_warehouse';
540 unset($object->fields[
'fk_project']);
541 unset($object->fields[
'fk_soc']);
542 include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
545 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
551 print
'<div class="clearboth"></div>';
560 if (!empty($object->table_element_line)) {
563 $object->fetchLines();
565 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
566 <input type="hidden" name="token" value="' .
newToken().
'">
567 <input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline').
'">
568 <input type="hidden" name="mode" value="">
569 <input type="hidden" name="page_y" value="">
570 <input type="hidden" name="id" value="' . $object->id.
'">
577 if (!empty($object->lines)) {
578 print
'<div class="div-table-responsive-no-min">';
579 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
581 print
'<tr class="liste_titre">';
582 print
'<td class="liste_titre">'.$langs->trans(
"Summary").
'</td>';
586 print
'<tr class="oddeven">';
587 print
'<td>'.$langs->trans(
"ProductsToConsume").
'</td>';
589 if (!empty($object->lines)) {
591 foreach ($object->lines as $line) {
592 if ($line->role ==
'toconsume') {
596 $tmpproduct =
new Product($db);
597 $tmpproduct->fetch($line->fk_product);
598 print $tmpproduct->getNomUrl(1);
606 print
'<tr class="oddeven">';
607 print
'<td>'.$langs->trans(
"ProductsToProduce").
'</td>';
609 if (!empty($object->lines)) {
611 foreach ($object->lines as $line) {
612 if ($line->role ==
'toproduce') {
616 $tmpproduct =
new Product($db);
617 $tmpproduct->fetch($line->fk_product);
618 print $tmpproduct->getNomUrl(1);
636 if ($action !=
'presend' && $action !=
'editline') {
637 print
'<div class="tabsAction">'.
"\n";
638 $parameters = array();
639 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
644 if (empty($reshook)) {
651 if ($object->status == $object::STATUS_VALIDATED) {
652 if ($permissiontoadd) {
654 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=confirm_setdraft&confirm=yes&token='.
newToken().
'">'.$langs->trans(
"SetToDraft").
'</a>';
659 if ($object->status == $object::STATUS_DRAFT) {
660 if ($permissiontoadd) {
661 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=edit&token='.
newToken().
'">'.$langs->trans(
"Modify").
'</a>'.
"\n";
663 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotEnoughPermissions")).
'">'.$langs->trans(
'Modify').
'</a>'.
"\n";
668 if ($object->status == $object::STATUS_DRAFT) {
669 if ($permissiontoadd) {
670 if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
671 print
'<a class="butAction" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=validate">'.$langs->trans(
"Validate").
'</a>';
673 $langs->load(
"errors");
674 print
'<a class="butActionRefused" href="" title="'.$langs->trans(
"ErrorAddAtLeastOneLineFirst").
'">'.$langs->trans(
"Validate").
'</a>';
680 if ($permissiontoadd) {
681 print
dolGetButtonAction($langs->trans(
"ToClone"),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.(!empty($object->socid) ?
'&socid='.$object->socid :
"").
'&action=clone&object=mo',
'clone', $permissiontoadd);
685 if ($permissiontoadd) {
686 if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS) {
687 $arrayproduced = $object->fetchLinesLinked(
'produced', 0);
689 foreach ($arrayproduced as $lineproduced) {
690 $nbProduced += $lineproduced[
'qty'];
692 if ($nbProduced > 0) {
693 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=confirm_produced&confirm=yes&token='.
newToken().
'">'.$langs->trans(
"Close").
'</a>'.
"\n";
695 print
'<a class="butActionRefused" href="#" title="'.$langs->trans(
"GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv(
"Production")).
'">'.$langs->trans(
"Close").
'</a>'.
"\n";
698 print
'<a class="butActionDelete" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=confirm_close&confirm=yes&token='.
newToken().
'">'.$langs->trans(
"Cancel").
'</a>'.
"\n";
701 if ($object->status == $object::STATUS_PRODUCED || $object->status == $object::STATUS_CANCELED) {
702 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=confirm_reopen&confirm=yes&token='.
newToken().
'">'.$langs->trans(
"ReOpen").
'</a>'.
"\n";
707 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'delete', $permissiontodelete);
714 if (
GETPOST(
'modelselected')) {
718 if ($action !=
'presend') {
719 print
'<div class="fichecenter"><div class="fichehalfleft">';
720 print
'<a name="builddoc"></a>';
724 $relativepath = $objref.
'/'.$objref.
'.pdf';
725 $filedir = $conf->mrp->dir_output.
'/'.$objref;
726 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
727 $genallowed = $user->rights->mrp->read;
728 $delallowed = $user->hasRight(
"mrp",
"creer");
729 print $formfile->showdocuments(
'mrp:mo', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0,
'',
'',
'', $mysoc->default_lang);
732 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'mo'));
733 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem,
false);
736 print
'</div><div class="fichehalfright">';
740 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/mrp/mo_agenda.php?id='.$object->id);
743 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
745 $somethingshown =
$formactions->showactions($object, $object->element, $socid, 1,
'', $MAXEVENT,
'', $morehtmlcenter);
747 print
'</div></div>';
751 if (
GETPOST(
'modelselected')) {
757 $defaulttopic =
'InformationMessage';
758 $diroutput = $conf->mrp->dir_output;
759 $trackid =
'mo'.$object->id;
761 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';