Merge pull request #23104 from atm-lena/develop_ExtrafieldsBomLineManagement

Extrafields BomLine Management
This commit is contained in:
Laurent Destailleur 2022-12-06 19:47:31 +01:00 committed by GitHub
commit 1eaae71a1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 192 additions and 15 deletions

View File

@ -0,0 +1,114 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
*
* 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/>.
*/
/**
* \file htdocs/admin/bomline_extrafields.php
* \ingroup bom
* \brief Page to setup extra fields of BOM
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/bom/lib/bom.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
// Load translation files required by the page
$langs->loadLangs(array('mrp', 'admin'));
$extrafields = new ExtraFields($db);
$form = new Form($db);
// List of supported format
$tmptype2label = ExtraFields::$type2label;
$type2label = array('');
foreach ($tmptype2label as $key => $val) {
$type2label[$key] = $langs->transnoentitiesnoconv($val);
}
$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'bom_bomline';
if (!$user->admin) {
accessforbidden();
}
/*
* Actions
*/
require DOL_DOCUMENT_ROOT . '/core/actions_extrafields.inc.php';
/*
* View
*/
$help_url = '';
llxHeader('', $langs->trans("BOMLinesSetup"), $help_url);
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
print load_fiche_titre($langs->trans("BOMLinesSetup"), $linkback, 'title_setup');
$head = bomAdminPrepareHead();
print dol_get_fiche_head($head, 'bomline_extrafields', $langs->trans("ExtraFields"), -1, 'account');
require DOL_DOCUMENT_ROOT . '/core/tpl/admin_extrafields_view.tpl.php';
print dol_get_fiche_end();
// Buttons
if ($action != 'create' && $action != 'edit') {
print '<div class="tabsAction">';
print '<a class="butAction reposition" href="' . $_SERVER["PHP_SELF"] . '?action=create">' . $langs->trans("NewAttribute") . '</a>';
print "</div>";
}
/*
* Creation of an optional field
*/
if ($action == 'create') {
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
require DOL_DOCUMENT_ROOT . '/core/tpl/admin_extrafields_add.tpl.php';
}
/*
* Edition of an optional field
*/
if ($action == 'edit' && !empty($attrname)) {
print "<br>";
print load_fiche_titre($langs->trans("FieldEdition", $attrname));
require DOL_DOCUMENT_ROOT . '/core/tpl/admin_extrafields_edit.tpl.php';
}
// End of page
llxFooter();
$db->close();

View File

@ -151,6 +151,7 @@ if (empty($reshook)) {
if ($action == 'addline' && $user->rights->bom->write) {
$langs->load('errors');
$error = 0;
$predef = '';
// Set if we used free entry or predefined product
$bom_child_id = (int) GETPOST('bom_id', 'int');
@ -194,7 +195,18 @@ if (empty($reshook)) {
}
if (!$error) {
$result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null, $fk_unit);
// Extrafields
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
$array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
// Unset extrafield
if (is_array($extralabelsline)) {
// Get extra fields
foreach ($extralabelsline as $key => $value) {
unset($_POST["options_".$key]);
}
}
$result = $object->addLine($idprod, $qty, $qty_frozen, $disable_stock_change, $efficiency, -1, $bom_child_id, null, $fk_unit, $array_options);
if ($result <= 0) {
setEventMessages($object->error, $object->errors, 'errors');
@ -231,10 +243,21 @@ if (empty($reshook)) {
}
if (!$error) {
// Extrafields
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
$array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
// Unset extrafield
if (is_array($extralabelsline)) {
// Get extra fields
foreach ($extralabelsline as $key => $value) {
unset($_POST["options_".$key]);
}
}
$bomline = new BOMLine($db);
$bomline->fetch($lineid);
$result = $object->updateLine($lineid, $qty, (int) $qty_frozen, (int) $disable_stock_change, $efficiency, $bomline->position, $bomline->import_key, $fk_unit);
$result = $object->updateLine($lineid, $qty, (int) $qty_frozen, (int) $disable_stock_change, $efficiency, $bomline->position, $bomline->import_key, $fk_unit, $array_options);
if ($result <= 0) {
setEventMessages($object->error, $object->errors, 'errors');

View File

@ -568,9 +568,10 @@ class BOM extends CommonObject
* @param int $fk_bom_child Id of BOM Child
* @param string $import_key Import Key
* @param string $fk_unit Unit
* @param array $array_options extrafields array
* @return int <0 if KO, Id of created object if OK
*/
public function addLine($fk_product, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child = null, $import_key = null, $fk_unit = '')
public function addLine($fk_product, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $fk_bom_child = null, $import_key = null, $fk_unit = '', $array_options = 0)
{
global $mysoc, $conf, $langs, $user;
@ -640,6 +641,10 @@ class BOM extends CommonObject
$this->line->position = $rankToUse;
$this->line->fk_unit = $fk_unit;
if (is_array($array_options) && count($array_options) > 0) {
$this->line->array_options = $array_options;
}
$result = $this->line->create($user);
if ($result > 0) {
@ -668,10 +673,11 @@ class BOM extends CommonObject
* @param float $efficiency Efficiency in MO
* @param int $position Position of BOM-Line in BOM-Lines
* @param string $import_key Import Key
* @param int $fk_unit Unit of line
* @param int $fk_unit Unit of line
* @param array $array_options extrafields array
* @return int <0 if KO, Id of updated BOM-Line if OK
*/
public function updateLine($rowid, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $import_key = null, $fk_unit = 0)
public function updateLine($rowid, $qty, $qty_frozen = 0, $disable_stock_change = 0, $efficiency = 1.0, $position = -1, $import_key = null, $fk_unit = 0, $array_options = 0)
{
global $mysoc, $conf, $langs, $user;
@ -745,6 +751,13 @@ class BOM extends CommonObject
$this->line->fk_unit = $fk_unit;
}
if (is_array($array_options) && count($array_options) > 0) {
// We replace values in this->line->array_options only for entries defined into $array_options
foreach ($array_options as $key => $value) {
$this->line->array_options[$key] = $array_options[$key];
}
}
$result = $this->line->update($user);
if ($result > 0) {

View File

@ -46,6 +46,11 @@ function bomAdminPrepareHead()
$head[$h][2] = 'bom_extrafields';
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/bomline_extrafields.php";
$head[$h][1] = $langs->trans("ExtraFieldsLines");
$head[$h][2] = 'bomline_extrafields';
$h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
//$this->tabs = array(

View File

@ -126,6 +126,17 @@ if (!empty($conf->global->BOM_SUB_BOM) && $filtertype!=1) {
// TODO Add component to select a BOM
$form->select_bom();
}
if (is_object($objectline)) {
$temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
if (!empty($temps)) {
print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
print $temps;
print '</div>';
}
}
print '</td>';

View File

@ -93,6 +93,16 @@ if (is_object($hookmanager)) {
$reshook = $hookmanager->executeHooks('formEditProductOptions', $parameters, $this, $action);
}
//Line extrafield
if (is_object($objectline) && !empty($extrafields)) {
$temps = $line->showOptionals($extrafields, 'edit', array('class'=>'tredited'), '', '', 1, 'line');
if (!empty($temps)) {
print '<div style="padding-top: 10px" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">';
print $temps;
print '</div>';
}
}
print '</td>';
/*if ($object->element == 'supplier_proposal' || $object->element == 'order_supplier' || $object->element == 'invoice_supplier') // We must have same test in printObjectLines
@ -160,8 +170,4 @@ print '<input type="submit" class="button buttongen margintoponly marginbottomon
print '</td>';
print '</tr>';
if (is_object($objectline)) {
print $objectline->showOptionals($extrafields, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', 1, 'line');
}
print "<!-- END PHP TEMPLATE objectline_edit.tpl.php -->\n";

View File

@ -100,6 +100,17 @@ if ($tmpbom->id > 0) {
print $tmpproduct->getNomUrl(1);
print ' - '.$tmpproduct->label;
}
// Line extrafield
if (!empty($extrafields)) {
$temps = $line->showOptionals($extrafields, 'view', array(), '', '', 1, 'line');
if (!empty($temps)) {
print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
print $temps;
print '</div>';
}
}
print '</td>';
print '<td class="linecolqty nowrap right">';
@ -309,10 +320,4 @@ if ($total_cost > 0) {
<?php
}
//Line extrafield
if (!empty($extrafields)) {
print $line->showOptionals($extrafields, 'view', array('style'=>'class="drag drop oddeven"', 'colspan'=>$coldisplay), '', '', 1, 'line');
}
print "<!-- END PHP TEMPLATE objectline_view.tpl.php -->\n";