Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2022-12-06 19:55:16 +01:00
commit 3228945547
12 changed files with 202 additions and 18 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";

View File

@ -592,6 +592,9 @@ if (!$error && $massaction == 'confirm_presend') {
$objectobj2->actionmsg2 = $actionmsg2; // Short text
$objectobj2->fk_element = $objid2;
$objectobj2->elementtype = $objectobj2->element;
if (!empty($conf->global->MAIN_MAIL_REPLACE_EVENT_TITLE_BY_EMAIL_SUBJECT)) {
$objectobj2->actionmsg2 = $subjectreplaced; // Short text
}
$triggername = strtoupper(get_class($objectobj2)).'_SENTBYMAIL';
if ($triggername == 'SOCIETE_SENTBYMAIL') {

View File

@ -382,6 +382,9 @@ if (($action == 'send' || $action == 'relance') && !GETPOST('addfile') && !GETPO
$object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...)
$object->actionmsg = $message; // Long text
$object->actionmsg2 = $actionmsg2; // Short text ($langs->transnoentities('MailSentBy')...);
if (!empty($conf->global->MAIN_MAIL_REPLACE_EVENT_TITLE_BY_EMAIL_SUBJECT)) {
$object->actionmsg2 = $subject; // Short text
}
$object->trackid = $trackid;
$object->fk_element = $object->id;

View File

@ -360,7 +360,8 @@ if ($massaction == 'preapproveleave') {
// Allow Pre-Mass-Action hook (eg for confirmation dialog)
$parameters = array(
'toselect' => isset($toselect) ? $toselect : array(),
'uploaddir' => isset($uploaddir) ? $uploaddir : null
'uploaddir' => isset($uploaddir) ? $uploaddir : null,
'massaction' => $massaction
);
$reshook = $hookmanager->executeHooks('doPreMassActions', $parameters, $object, $action);

View File

@ -419,7 +419,7 @@ if (empty($reshook)) {
$localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
$localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
foreach ($object->lines as $line) {
$result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $line->info_bits, $line->product_type, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice);
$result = $object->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $line->info_bits, $line->product_type, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier);
}
} elseif ($action == 'addline' && $usercancreate) {
$db->begin();

View File

@ -465,7 +465,7 @@ if ($usevirtualstock) {
$sqlProductionToConsume .= " ".MAIN_DB_PREFIX."mrp_production as mp5";
$sqlProductionToConsume .= " WHERE mm5.rowid = mp5.fk_mo AND mm5.entity IN (".getEntity(!empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mo').")";
$sqlProductionToConsume .= " AND mp5.fk_product = p.rowid";
$sqlProductionToConsume .= " AND mp5.role IN ('toconsume', 'consummed')";
$sqlProductionToConsume .= " AND mp5.role IN ('toconsume', 'consumed')";
$sqlProductionToConsume .= " AND mm5.status IN (1,2))";
$sqlProductionToProduce = "(SELECT GREATEST(0, ".$db->ifsql("SUM(".$db->ifsql("mp5.role = 'toproduce'", 'mp5.qty', '- mp5.qty').") IS NULL", "0", "SUM(".$db->ifsql("mp5.role = 'toproduce'", 'mp5.qty', '- mp5.qty').")").") as qty"; // We need the ifsql because if result is 0 for product p.rowid, we must return 0 and not NULL