dolibarr/htdocs/mrp/mo_card.php

768 lines
28 KiB
PHP
Raw Normal View History

2019-10-15 19:59:16 +02:00
<?php
/* Copyright (C) 2017-2020 Laurent Destailleur <eldy@users.sourceforge.net>
2019-10-15 19:59:16 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2019-10-15 19:59:16 +02:00
*/
/**
* \file mo_card.php
* \ingroup mrp
* \brief Page to create/edit/view mo
*/
// Load Dolibarr environment
2019-10-22 13:52:18 +02:00
require '../main.inc.php';
2019-10-15 19:59:16 +02:00
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
2019-11-12 01:48:12 +01:00
require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp_mo.lib.php';
require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
2022-02-15 16:08:18 +01:00
require_once DOL_DOCUMENT_ROOT.'/bom/lib/bom.lib.php';
2019-10-15 19:59:16 +02:00
// Load translation files required by the page
$langs->loadLangs(array("mrp", "other"));
// Get parameters
$id = GETPOST('id', 'int');
2020-11-05 22:25:14 +01:00
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
2020-11-05 22:25:14 +01:00
$confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'aZ09');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'mocard'; // To manage different context of search
2019-10-15 19:59:16 +02:00
$backtopage = GETPOST('backtopage', 'alpha');
2020-01-08 17:56:02 +01:00
$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
2022-02-08 15:54:31 +01:00
$TBomLineId = GETPOST('bomlineid', 'array');
2019-10-15 19:59:16 +02:00
//$lineid = GETPOST('lineid', 'int');
// Initialize technical objects
$object = new Mo($db);
2019-11-12 01:48:12 +01:00
$objectbom = new BOM($db);
2019-10-15 19:59:16 +02:00
$extrafields = new ExtraFields($db);
$diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
$hookmanager->initHooks(array('mocard', 'globalcard')); // Note that conf->hooks_modules contains array
2019-10-15 19:59:16 +02:00
// Fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
2019-10-15 19:59:16 +02:00
// Initialize array of search criterias
$search_all = GETPOST("search_all", 'alpha');
$search = array();
2021-02-26 18:26:44 +01:00
foreach ($object->fields as $key => $val) {
if (GETPOST('search_'.$key, 'alpha')) {
$search[$key] = GETPOST('search_'.$key, 'alpha');
}
2019-10-15 19:59:16 +02:00
}
2021-02-26 18:26:44 +01:00
if (empty($action) && empty($id) && empty($ref)) {
$action = 'view';
}
2019-10-15 19:59:16 +02:00
// Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
2019-10-15 19:59:16 +02:00
if (GETPOST('fk_bom', 'int') > 0) {
2019-11-12 01:48:12 +01:00
$objectbom->fetch(GETPOST('fk_bom', 'int'));
2019-12-08 23:45:06 +01:00
if ($action != 'add') {
// We force calling parameters if we are not in the submit of creation of MO
$_POST['fk_product'] = $objectbom->fk_product;
$_POST['qty'] = $objectbom->qty;
$_POST['mrptype'] = $objectbom->bomtype;
2019-12-08 23:45:06 +01:00
$_POST['fk_warehouse'] = $objectbom->fk_warehouse;
$_POST['note_private'] = $objectbom->note_private;
}
2019-11-12 01:48:12 +01:00
}
2019-10-15 19:59:16 +02:00
// Security check - Protection if external user
2019-11-22 15:35:19 +01:00
//if ($user->socid > 0) accessforbidden();
//if ($user->socid > 0) $socid = $user->socid;
2020-06-07 23:00:38 +02:00
$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
2020-06-18 01:09:30 +02:00
$result = restrictedArea($user, 'mrp', $object->id, 'mrp_mo', '', 'fk_soc', 'rowid', $isdraft);
2019-10-15 19:59:16 +02:00
$permissionnote = $user->rights->mrp->write; // Used by the include of actions_setnotes.inc.php
$permissiondellink = $user->rights->mrp->write; // Used by the include of actions_dellink.inc.php
$permissiontoadd = $user->rights->mrp->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
2019-11-04 14:13:36 +01:00
$permissiontodelete = $user->rights->mrp->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
$upload_dir = $conf->mrp->multidir_output[isset($object->entity) ? $object->entity : 1];
2019-10-15 19:59:16 +02:00
/*
* Actions
*/
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2021-02-26 18:26:44 +01:00
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
2019-10-15 19:59:16 +02:00
2021-02-26 18:26:44 +01:00
if (empty($reshook)) {
$error = 0;
$backurlforlist = dol_buildpath('/mrp/mo_list.php', 1);
if (empty($backtopage) || ($cancel && empty($id))) {
if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
2021-02-26 18:26:44 +01:00
if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
$backtopage = $backurlforlist;
} else {
$backtopage = DOL_URL_ROOT.'/mrp/mo_card.php?id='.($id > 0 ? $id : '__ID__');
}
}
}
if ($cancel && !empty($backtopageforcancel)) {
$backtopage = $backtopageforcancel;
}
$triggermodname = 'MRP_MO_MODIFY'; // Name of trigger action code to execute when we modify record
2022-02-15 16:24:39 +01:00
//Create MO with Childs
2022-02-15 16:08:18 +01:00
if ($action == 'add' && empty($id) && !empty($TBomLineId)) {
2022-06-14 10:41:32 +02:00
$noback = 1;
2022-02-08 15:54:31 +01:00
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
$mo_parent = $object;
$moline = new MoLine($db);
$objectbomchildline = new BOMLine($db);
2022-02-08 16:37:23 +01:00
foreach ($TBomLineId as $id_bom_line) {
2022-02-08 15:54:31 +01:00
$object = new Mo($db);
$objectbomchildline->fetch($id_bom_line);
$TMoLines = $moline->fetchAll('DESC', 'rowid', '1', '', array('origin_id' => $id_bom_line));
2022-02-08 15:54:31 +01:00
2022-02-08 16:37:23 +01:00
foreach ($TMoLines as $moline) {
2022-02-08 15:54:31 +01:00
$_POST['fk_bom'] = $objectbomchildline->fk_bom_child;
$_POST['fk_parent_line'] = $moline->id;
$_POST['qty'] = $moline->qty;
$_POST['fk_product'] = $moline->fk_product;
}
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
2022-02-15 11:46:30 +01:00
$res = $object->add_object_linked('mo', $mo_parent->id);
2022-02-08 15:54:31 +01:00
}
header("Location: ".dol_buildpath('/mrp/mo_card.php?id='.$moline->fk_mo, 1));
2022-02-08 15:54:31 +01:00
exit;
}
// Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
// Actions when linking object each other
include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php';
// Actions when printing a doc from card
include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
// Action to build doc
include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
if ($action == 'set_thirdparty' && $permissiontoadd) {
$object->setValueFrom('fk_soc', GETPOST('fk_soc', 'int'), '', '', 'date', '', $user, 'MO_MODIFY');
}
if ($action == 'classin' && $permissiontoadd) {
$object->setProject(GETPOST('projectid', 'int'));
}
// Actions to send emails
$triggersendname = 'MO_SENTBYMAIL';
$autocopy = 'MAIN_MAIL_AUTOCOPY_MO_TO';
$trackid = 'mo'.$object->id;
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
// Action to move up and down lines of object
//include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
// Action close produced
2021-02-26 18:26:44 +01:00
if ($action == 'confirm_produced' && $confirm == 'yes' && $permissiontoadd) {
$result = $object->setStatut($object::STATUS_PRODUCED, 0, '', 'MRP_MO_PRODUCED');
2021-02-26 18:26:44 +01:00
if ($result >= 0) {
// Define output language
2021-02-26 18:26:44 +01:00
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
$outputlangs = $langs;
$newlang = '';
2021-02-26 18:26:44 +01:00
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
$newlang = GETPOST('lang_id', 'aZ09');
}
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
$newlang = $object->thirdparty->default_lang;
}
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
$model = $object->model_pdf;
$ret = $object->fetch($id); // Reload to get new records
$object->generateDocument($model, $outputlangs, 0, 0, 0);
}
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
2019-10-15 19:59:16 +02:00
}
/*
* View
*/
$form = new Form($db);
$formfile = new FormFile($db);
$formproject = new FormProjets($db);
2019-10-15 19:59:16 +02:00
2021-09-16 17:13:03 +02:00
$title = $langs->trans('ManufacturingOrder')." - ".$langs->trans("Card");
llxHeader('', $title, '');
2019-10-15 19:59:16 +02:00
// Part to create
if ($action == 'create') {
if (GETPOST('fk_bom', 'int') > 0) {
$titlelist = $langs->trans("ToConsume");
if ($objectbom->bomtype == 1) {
$titlelist = $langs->trans("ToObtain");
}
}
2020-04-12 19:56:50 +02:00
print load_fiche_titre($langs->trans("NewObject", $langs->transnoentitiesnoconv("Mo")), '', 'mrp');
2019-10-15 19:59:16 +02:00
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2019-10-15 19:59:16 +02:00
print '<input type="hidden" name="action" value="add">';
2021-02-26 18:26:44 +01:00
if ($backtopage) {
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
}
if ($backtopageforcancel) {
print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
}
2019-10-15 19:59:16 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head(array(), '');
2019-10-15 19:59:16 +02:00
print '<table class="border centpercent tableforfieldcreate">'."\n";
// Common attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_add.tpl.php';
2019-10-15 19:59:16 +02:00
// Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
2019-10-15 19:59:16 +02:00
print '</table>'."\n";
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2019-10-15 19:59:16 +02:00
2022-06-11 21:47:00 +02:00
mrpCollapseBomManagement();
2022-02-15 16:08:18 +01:00
2019-10-21 11:38:35 +02:00
?>
2019-10-15 19:59:16 +02:00
<script>
2021-02-26 18:26:44 +01:00
$(document).ready(function () {
2022-02-07 16:28:58 +01:00
jQuery('#fk_bom').change(function() {
2019-10-21 11:38:35 +02:00
console.log('We change value of BOM with BOM of id '+jQuery('#fk_bom').val());
2019-11-11 20:56:28 +01:00
if (jQuery('#fk_bom').val() > 0)
{
2019-11-12 01:48:12 +01:00
// Redirect to page with fk_bom set
2022-06-11 21:50:30 +02:00
window.location.href = '<?php echo $_SERVER["PHP_SELF"] ?>?action=create&token=<?php echo newToken(); ?>&fk_bom='+jQuery('#fk_bom').val();
2019-11-12 01:48:12 +01:00
/*
2019-11-11 20:56:28 +01:00
$.getJSON('<?php echo DOL_URL_ROOT ?>/mrp/ajax/ajax_bom.php?action=getBoms&idbom='+jQuery('#fk_bom').val(), function(data) {
console.log(data);
if (typeof data.rowid != "undefined") {
console.log("New BOM loaded, we set values in form");
console.log(data);
2019-11-11 20:56:28 +01:00
$('#qty').val(data.qty);
$("#mrptype").val(data.bomtype); // We set bomtype into mrptype
$('#mrptype').trigger('change'); // Notify any JS components that the value changed
2019-11-11 20:56:28 +01:00
$("#fk_product").val(data.fk_product);
$('#fk_product').trigger('change'); // Notify any JS components that the value changed
$('#note_private').val(data.description);
$('#note_private').trigger('change'); // Notify any JS components that the value changed
$('#fk_warehouse').val(data.fk_warehouse);
$('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
if (typeof CKEDITOR != "undefined") {
if (typeof CKEDITOR.instances != "undefined") {
if (typeof CKEDITOR.instances.note_private != "undefined") {
console.log(CKEDITOR.instances.note_private);
CKEDITOR.instances.note_private.setData(data.description);
}
2019-10-21 11:38:35 +02:00
}
}
2019-11-11 20:56:28 +01:00
} else {
console.log("Failed to get BOM");
2019-10-21 11:38:35 +02:00
}
2019-11-12 01:48:12 +01:00
});*/
2019-11-11 20:56:28 +01:00
}
2019-11-17 00:37:08 +01:00
else if (jQuery('#fk_bom').val() < 0) {
// Redirect to page with all fields defined except fk_bom set
console.log(jQuery('#fk_product').val());
2022-06-11 21:50:30 +02:00
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();
2019-11-11 20:56:28 +01:00
/*
$('#qty').val('');
$("#fk_product").val('');
$('#fk_product').trigger('change'); // Notify any JS components that the value changed
$('#note_private').val('');
$('#note_private').trigger('change'); // Notify any JS components that the value changed
$('#fk_warehouse').val('');
$('#fk_warehouse').trigger('change'); // Notify any JS components that the value changed
*/
}
2021-02-26 18:26:44 +01:00
});
2019-11-11 20:56:28 +01:00
2019-11-12 01:48:12 +01:00
//jQuery('#fk_bom').trigger('change');
2019-10-15 19:59:16 +02:00
})
</script>
2019-10-21 11:38:35 +02:00
<?php
2019-10-15 19:59:16 +02:00
print $form->buttonsSaveCancel("Create");
2019-10-15 19:59:16 +02:00
if ($objectbom->id > 0) {
print load_fiche_titre($titlelist);
2019-11-12 01:48:12 +01:00
2019-11-17 00:37:08 +01:00
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
2019-11-12 01:48:12 +01:00
2019-11-17 00:37:08 +01:00
$object->lines = $objectbom->lines;
$object->mrptype = $objectbom->bomtype;
2020-04-22 12:56:52 +02:00
$object->bom = $objectbom;
2019-11-12 01:48:12 +01:00
2019-11-17 00:37:08 +01:00
$object->printOriginLinesList('', array());
2019-11-12 01:48:12 +01:00
2019-11-17 00:37:08 +01:00
print '</table>';
print '</div>';
}
2019-11-12 01:48:12 +01:00
2019-10-15 19:59:16 +02:00
print '</form>';
}
// Part to edit record
2021-02-26 18:26:44 +01:00
if (($id || $ref) && $action == 'edit') {
print load_fiche_titre($langs->trans("ManufacturingOrder"), '', 'mrp');
2019-10-15 19:59:16 +02:00
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2019-10-15 19:59:16 +02:00
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
2021-02-26 18:26:44 +01:00
if ($backtopage) {
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
}
if ($backtopageforcancel) {
print '<input type="hidden" name="backtopageforcancel" value="'.$backtopageforcancel.'">';
}
2019-10-15 19:59:16 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head();
2019-10-15 19:59:16 +02:00
$object->fields['fk_bom']['disabled'] = 1;
print '<table class="border centpercent tableforfieldedit">'."\n";
2019-10-15 19:59:16 +02:00
// Common attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_edit.tpl.php';
2019-10-15 19:59:16 +02:00
// Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
2019-10-15 19:59:16 +02:00
print '</table>';
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2019-10-15 19:59:16 +02:00
print $form->buttonsSaveCancel();
2019-10-15 19:59:16 +02:00
print '</form>';
}
// Part to show record
2021-02-26 18:26:44 +01:00
if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) {
2019-10-24 13:09:50 +02:00
$res = $object->fetch_thirdparty();
$res = $object->fetch_optionals();
2019-10-15 19:59:16 +02:00
$head = moPrepareHead($object);
Merge branch '12.0' of git@github.com:Dolibarr/dolibarr.git into develop Conflicts: htdocs/core/lib/product.lib.php htdocs/langs/am_ET/mrp.lang htdocs/langs/ar_SA/mrp.lang htdocs/langs/az_AZ/mrp.lang htdocs/langs/bg_BG/mrp.lang htdocs/langs/bn_BD/mrp.lang htdocs/langs/bn_IN/mrp.lang htdocs/langs/bs_BA/mrp.lang htdocs/langs/ca_ES/mrp.lang htdocs/langs/cs_CZ/mrp.lang htdocs/langs/da_DK/mrp.lang htdocs/langs/de_DE/mrp.lang htdocs/langs/el_GR/mrp.lang htdocs/langs/en_US/mrp.lang htdocs/langs/es_ES/mrp.lang htdocs/langs/et_EE/mrp.lang htdocs/langs/eu_ES/mrp.lang htdocs/langs/fa_IR/mrp.lang htdocs/langs/fi_FI/mrp.lang htdocs/langs/fr_FR/mrp.lang htdocs/langs/gl_ES/mrp.lang htdocs/langs/he_IL/mrp.lang htdocs/langs/hi_IN/mrp.lang htdocs/langs/hr_HR/mrp.lang htdocs/langs/hu_HU/mrp.lang htdocs/langs/id_ID/mrp.lang htdocs/langs/is_IS/mrp.lang htdocs/langs/it_IT/mrp.lang htdocs/langs/ja_JP/mrp.lang htdocs/langs/ka_GE/mrp.lang htdocs/langs/km_KH/mrp.lang htdocs/langs/kn_IN/mrp.lang htdocs/langs/ko_KR/mrp.lang htdocs/langs/lo_LA/mrp.lang htdocs/langs/lt_LT/mrp.lang htdocs/langs/lv_LV/mrp.lang htdocs/langs/mk_MK/mrp.lang htdocs/langs/mn_MN/mrp.lang htdocs/langs/nb_NO/mrp.lang htdocs/langs/ne_NP/mrp.lang htdocs/langs/nl_NL/mrp.lang htdocs/langs/pl_PL/mrp.lang htdocs/langs/pt_PT/mrp.lang htdocs/langs/ro_RO/mrp.lang htdocs/langs/ru_RU/mrp.lang htdocs/langs/sk_SK/mrp.lang htdocs/langs/sl_SI/mrp.lang htdocs/langs/sq_AL/mrp.lang htdocs/langs/sr_RS/mrp.lang htdocs/langs/sv_SE/mrp.lang htdocs/langs/sw_SW/mrp.lang htdocs/langs/th_TH/mrp.lang htdocs/langs/tr_TR/mrp.lang htdocs/langs/uk_UA/mrp.lang htdocs/langs/uz_UZ/mrp.lang htdocs/langs/vi_VN/mrp.lang htdocs/langs/zh_CN/mrp.lang htdocs/langs/zh_HK/mrp.lang htdocs/langs/zh_TW/mrp.lang htdocs/mrp/class/mo.class.php htdocs/mrp/mo_agenda.php htdocs/mrp/mo_card.php htdocs/mrp/mo_document.php htdocs/mrp/mo_movements.php htdocs/mrp/mo_note.php htdocs/mrp/mo_production.php
2020-10-27 02:55:22 +01:00
print dol_get_fiche_head($head, 'card', $langs->trans("ManufacturingOrder"), -1, $object->picto);
2019-10-15 19:59:16 +02:00
$formconfirm = '';
// Confirmation to delete
2021-02-26 18:26:44 +01:00
if ($action == 'delete') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteMo'), $langs->trans('ConfirmDeleteMo'), 'confirm_delete', '', 0, 1);
2019-10-15 19:59:16 +02:00
}
// Confirmation to delete line
2021-02-26 18:26:44 +01:00
if ($action == 'deleteline') {
2019-10-15 19:59:16 +02:00
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_deleteline', '', 0, 1);
}
2019-11-04 14:13:36 +01:00
// Confirmation of validation
2021-02-26 18:26:44 +01:00
if ($action == 'validate') {
2019-11-04 14:13:36 +01:00
// We check that object has a temporary ref
$ref = substr($object->ref, 1, 4);
if ($ref == 'PROV') {
$object->fetch_product();
2019-12-20 15:31:05 +01:00
$numref = $object->getNextNumRef($object->fk_product);
2019-11-04 14:13:36 +01:00
} else {
$numref = $object->ref;
}
$text = $langs->trans('ConfirmValidateMo', $numref);
/*if (! empty($conf->notification->enabled))
{
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
$notify = new Notify($db);
$text .= '<br>';
$text .= $notify->confirmMessage('BOM_VALIDATE', $object->socid, $object);
}*/
$formquestion = array();
2021-02-26 18:26:44 +01:00
if (!empty($conf->mrp->enabled)) {
2019-11-04 14:13:36 +01:00
$langs->load("mrp");
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2019-11-04 14:13:36 +01:00
$formproduct = new FormProduct($db);
$forcecombo = 0;
2021-02-26 18:26:44 +01:00
if ($conf->browser->name == 'ie') {
$forcecombo = 1; // There is a bug in IE10 that make combo inside popup crazy
}
2019-11-04 14:13:36 +01:00
$formquestion = array(
// 'text' => $langs->trans("ConfirmClone"),
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
// array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
);
}
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
2019-11-04 14:13:36 +01:00
}
2019-10-15 19:59:16 +02:00
// Clone confirmation
if ($action == 'clone') {
// Create an array for form
$formquestion = array();
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneMo', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
2019-10-15 19:59:16 +02:00
}
// Call Hook formConfirm
$parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
2019-10-15 19:59:16 +02:00
$reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2021-02-26 18:26:44 +01:00
if (empty($reshook)) {
$formconfirm .= $hookmanager->resPrint;
} elseif ($reshook > 0) {
$formconfirm = $hookmanager->resPrint;
}
2019-10-15 19:59:16 +02:00
// Print form confirm
print $formconfirm;
// Object card
// ------------------------------------------------------------
$linkback = '<a href="'.dol_buildpath('/mrp/mo_list.php', 1).'?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
2019-10-15 19:59:16 +02:00
$morehtmlref = '<div class="refidno">';
2019-10-15 19:59:16 +02:00
/*
// Ref bis
$morehtmlref.=$form->editfieldkey("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', 0, 1);
$morehtmlref.=$form->editfieldval("RefBis", 'ref_client', $object->ref_client, $object, $user->rights->mrp->creer, 'string', '', null, null, '', 1);*/
2019-10-15 19:59:16 +02:00
// Thirdparty
2020-05-05 18:53:41 +02:00
$morehtmlref .= $langs->trans('ThirdParty').' ';
$morehtmlref .= ': '.(is_object($object->thirdparty) ? $object->thirdparty->getNomUrl(1) : '');
2019-10-15 19:59:16 +02:00
// Project
2022-06-14 17:53:17 +02:00
if (!empty($conf->project->enabled)) {
$langs->load("projects");
$morehtmlref .= '<br>'.$langs->trans('Project').' ';
2021-02-26 18:26:44 +01:00
if ($permissiontoadd) {
if ($action != 'classify') {
2021-09-18 22:09:55 +02:00
$morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
2021-02-26 18:26:44 +01:00
}
if ($action == 'classify') {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->fk_soc, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
$morehtmlref .= '<input type="hidden" name="action" value="classin">';
$morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
$morehtmlref .= $formproject->select_projects($object->fk_soc, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1);
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$morehtmlref .= '</form>';
} else {
$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_soc, $object->fk_project, 'none', 0, 0, 0, 1);
}
} else {
if (!empty($object->fk_project)) {
$proj = new Project($db);
$proj->fetch($object->fk_project);
$morehtmlref .= ' : '.$proj->getNomUrl();
} else {
$morehtmlref .= '';
}
}
2019-10-15 19:59:16 +02:00
}
$morehtmlref .= '</div>';
2019-10-15 19:59:16 +02:00
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>';
2019-11-04 14:13:36 +01:00
print '<table class="border centpercent tableforfield">'."\n";
2019-10-15 19:59:16 +02:00
2022-02-15 11:46:30 +01:00
//Mo Parent
$mo_parent = $object->getMoParent();
2022-02-15 12:46:50 +01:00
if (is_object($mo_parent)) {
2022-02-15 11:46:30 +01:00
print '<tr class="field_fk_mo_parent">';
2022-02-15 16:24:39 +01:00
print '<td class="titlefield fieldname_fk_mo_parent">' . $langs->trans('ParentMo') . '</td>';
2022-02-15 11:46:30 +01:00
print '<td class="valuefield fieldname_fk_mo_parent">' .$mo_parent->getNomUrl(1).'</td>';
print '</tr>';
}
2019-10-15 19:59:16 +02:00
// Common attributes
$keyforbreak = 'fk_warehouse';
unset($object->fields['fk_project']);
unset($object->fields['fk_soc']);
include DOL_DOCUMENT_ROOT.'/core/tpl/commonfields_view.tpl.php';
2019-10-15 19:59:16 +02:00
// Other attributes
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
2019-10-15 19:59:16 +02:00
print '</table>';
print '</div>';
print '</div>';
print '<div class="clearboth"></div>';
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end();
2019-10-15 19:59:16 +02:00
/*
* Lines
*/
2021-02-26 18:26:44 +01:00
if (!empty($object->table_element_line)) {
// Show object lines
2019-12-20 15:31:05 +01:00
//$result = $object->getLinesArray();
$object->fetchLines();
2019-10-15 19:59:16 +02:00
2021-07-04 21:14:46 +02:00
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
2020-03-24 13:10:35 +01:00
<input type="hidden" name="token" value="' . newToken().'">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
2019-10-15 19:59:16 +02:00
<input type="hidden" name="mode" value="">
2021-07-04 21:14:46 +02:00
<input type="hidden" name="page_y" value="">
<input type="hidden" name="id" value="' . $object->id.'">
2019-10-15 19:59:16 +02:00
';
/*if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
2021-02-26 18:26:44 +01:00
include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
}*/
2019-10-15 19:59:16 +02:00
2021-02-26 18:26:44 +01:00
if (!empty($object->lines)) {
print '<div class="div-table-responsive-no-min">';
print '<table id="tablelines" class="noborder noshadow" width="100%">';
print '<tr class="liste_titre">';
print '<td class="liste_titre">'.$langs->trans("Summary").'</td>';
print '<td></td>';
print '</tr>';
print '<tr class="oddeven">';
print '<td>'.$langs->trans("ProductsToConsume").'</td>';
print '<td>';
2021-02-26 18:26:44 +01:00
if (!empty($object->lines)) {
$i = 0;
foreach ($object->lines as $line) {
if ($line->role == 'toconsume') {
2021-02-26 18:26:44 +01:00
if ($i) {
print ', ';
}
$tmpproduct = new Product($db);
$tmpproduct->fetch($line->fk_product);
print $tmpproduct->getNomUrl(1);
$i++;
}
}
}
print '</td>';
print '</tr>';
print '<tr class="oddeven">';
print '<td>'.$langs->trans("ProductsToProduce").'</td>';
print '<td>';
2021-02-26 18:26:44 +01:00
if (!empty($object->lines)) {
$i = 0;
foreach ($object->lines as $line) {
if ($line->role == 'toproduce') {
2021-02-26 18:26:44 +01:00
if ($i) {
print ', ';
}
$tmpproduct = new Product($db);
$tmpproduct->fetch($line->fk_product);
print $tmpproduct->getNomUrl(1);
$i++;
}
}
}
print '</td>';
print '</tr>';
print '</table>';
print '</div>';
}
print "</form>\n";
2019-10-15 19:59:16 +02:00
}
// Buttons for actions
if ($action != 'presend' && $action != 'editline') {
print '<div class="tabsAction">'."\n";
$parameters = array();
$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2021-02-26 18:26:44 +01:00
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
2021-02-26 18:26:44 +01:00
if (empty($reshook)) {
// Send
//if (empty($user->socid)) {
// print '<a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle">' . $langs->trans('SendMail') . '</a>'."\n";
//}
// Back to draft
2021-02-26 18:26:44 +01:00
if ($object->status == $object::STATUS_VALIDATED) {
if ($permissiontoadd) {
// TODO Add test that production has not started
2022-05-23 12:43:30 +02:00
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes&token='.newToken().'">'.$langs->trans("SetToDraft").'</a>';
}
}
// Modify
if ($object->status == $object::STATUS_DRAFT) {
2021-02-26 18:26:44 +01:00
if ($permissiontoadd) {
2021-09-27 12:24:01 +02:00
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>'."\n";
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
}
}
// Validate
2021-02-26 18:26:44 +01:00
if ($object->status == $object::STATUS_DRAFT) {
if ($permissiontoadd) {
if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0)) {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate">'.$langs->trans("Validate").'</a>';
} else {
$langs->load("errors");
print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
}
}
}
// Clone
2021-02-26 18:26:44 +01:00
if ($permissiontoadd) {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->fk_soc.'&action=clone&object=mo">'.$langs->trans("ToClone").'</a>';
}
// Cancel - Reopen
2021-02-26 18:26:44 +01:00
if ($permissiontoadd) {
if ($object->status == $object::STATUS_VALIDATED || $object->status == $object::STATUS_INPROGRESS) {
$arrayproduced = $object->fetchLinesLinked('produced', 0);
$nbProduced = 0;
foreach ($arrayproduced as $lineproduced) {
$nbProduced += $lineproduced['qty'];
}
if ($nbProduced > 0) { // If production has started, we can close it
2022-05-23 12:43:30 +02:00
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_produced&confirm=yes&token='.newToken().'">'.$langs->trans("Close").'</a>'."\n";
} else {
print '<a class="butActionRefused" href="#" title="'.$langs->trans("GoOnTabProductionToProduceFirst", $langs->transnoentitiesnoconv("Production")).'">'.$langs->trans("Close").'</a>'."\n";
}
2022-05-23 12:43:30 +02:00
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_close&confirm=yes&token='.newToken().'">'.$langs->trans("Cancel").'</a>'."\n";
}
2021-02-26 18:26:44 +01:00
if ($object->status == $object::STATUS_PRODUCED || $object->status == $object::STATUS_CANCELED) {
2022-05-23 12:43:30 +02:00
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_reopen&confirm=yes&token='.newToken().'">'.$langs->trans("ReOpen").'</a>'."\n";
}
}
// Delete (need delete permission, or if draft, just need create/modify permission)
2021-02-26 18:26:44 +01:00
if ($permissiontodelete || ($object->status == $object::STATUS_DRAFT && $permissiontoadd)) {
print '<a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>'."\n";
} else {
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Delete').'</a>'."\n";
}
}
print '</div>'."\n";
2019-10-15 19:59:16 +02:00
}
// Select mail models is same action as presend
if (GETPOST('modelselected')) {
$action = 'presend';
}
2021-02-26 18:26:44 +01:00
if ($action != 'presend') {
print '<div class="fichecenter"><div class="fichehalfleft">';
print '<a name="builddoc"></a>'; // ancre
2019-10-15 19:59:16 +02:00
// Documents
$objref = dol_sanitizeFileName($object->ref);
$relativepath = $objref.'/'.$objref.'.pdf';
$filedir = $conf->mrp->dir_output.'/'.$objref;
$urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
$genallowed = $user->rights->mrp->read; // If you can read, you can build the PDF to read content
$delallowed = $user->rights->mrp->create; // If you can create/edit, you can remove a file on card
print $formfile->showdocuments('mrp:mo', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $mysoc->default_lang);
2019-10-15 19:59:16 +02:00
// Show links to link elements
$linktoelem = $form->showLinkToObjectBlock($object, null, array('mo'));
2022-11-08 09:46:55 +01:00
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, false);
2019-10-15 19:59:16 +02:00
2021-10-23 17:18:35 +02:00
print '</div><div class="fichehalfright">';
2019-10-15 19:59:16 +02:00
$MAXEVENT = 10;
2019-10-15 19:59:16 +02:00
2022-05-18 23:11:59 +02:00
$morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/mrp/mo_agenda.php?id='.$object->id);
2019-10-15 19:59:16 +02:00
// List of actions on element
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
$formactions = new FormActions($db);
2021-11-12 14:57:36 +01:00
$somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT, '', $morehtmlcenter);
2019-10-15 19:59:16 +02:00
2021-10-23 17:18:35 +02:00
print '</div></div>';
2019-10-15 19:59:16 +02:00
}
//Select mail models is same action as presend
2021-02-26 18:26:44 +01:00
if (GETPOST('modelselected')) {
$action = 'presend';
}
2019-10-15 19:59:16 +02:00
2019-10-30 01:35:41 +01:00
// Presend form
$modelmail = 'mo';
$defaulttopic = 'InformationMessage';
2019-10-30 01:35:41 +01:00
$diroutput = $conf->mrp->dir_output;
$trackid = 'mo'.$object->id;
2019-10-15 19:59:16 +02:00
2019-10-30 01:35:41 +01:00
include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2019-10-15 19:59:16 +02:00
}
// End of page
llxFooter();
$db->close();