Browse Source

New add extrafields for mo line (#26395)

* added recursive deletion option for child MOs + added recursive recovery method for child MOs

* add number of MOs in form_confirm

* update to delete number of mo childs if is null

* added checking of an infinity loop

* review PR

* add extrafields for mo lines

* update

* update for travis

* Update 18.0.0-19.0.0.sql

* Update functions.sql

* Delete htdocs/install/mysql/tables/llx_mrp_production_extrafields.key.sql

* Delete htdocs/install/mysql/tables/llx_mrp_production_extrafields.sql

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
atm-sami 1 year ago
parent
commit
5a5483a610

+ 113 - 0
htdocs/admin/mrp_production_extrafields.php

@@ -0,0 +1,113 @@
+<?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/mrp_production_extrafields.php
+ *		\ingroup    mrp
+ *		\brief      Page to setup extra fields of MOs lines
+ */
+
+// Load Dolibarr environment
+require '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/mrp/lib/mrp.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 = 'mrp_production';
+
+if (!$user->admin) {
+	accessforbidden();
+}
+
+
+/*
+ * Actions
+ */
+
+require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
+
+
+
+/*
+ * View
+ */
+
+$help_url = '';
+llxHeader('', $langs->trans("MrpSetupPage"), $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("MrpSetupPage"), $linkback, 'title_setup');
+
+
+$head = mrpAdminPrepareHead();
+
+print dol_get_fiche_head($head, 'mrp_production_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();

+ 1 - 3
htdocs/mrp/class/mo.class.php

@@ -817,7 +817,6 @@ class Mo extends CommonObject
 				}
 			}
 		}
-
 		if (!$error) {
 			$this->db->commit();
 			return 1;
@@ -881,7 +880,6 @@ class Mo extends CommonObject
 			$this->error = 'ErrorDeleteLineNotAllowedByObjectStatus';
 			return -2;
 		}
-
 		$productstatic = new Product($this->db);
 		$fk_movement = GETPOST('fk_movement', 'int');
 		$arrayoflines = $this->fetchLinesLinked('consumed', $idline);
@@ -1972,7 +1970,7 @@ class MoLine extends CommonObjectLine
 	/**
 	 * @var int  Does moline support extrafields ? 0=No, 1=Yes
 	 */
-	public $isextrafieldmanaged = 0;
+	public $isextrafieldmanaged = 1;
 
 	public $fields = array(
 		'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10),

+ 4 - 0
htdocs/mrp/lib/mrp.lib.php

@@ -52,6 +52,10 @@ function mrpAdminPrepareHead()
 	$head[$h][2] = 'mrp_extrafields';
 	$h++;
 
+	$head[$h][0] = dol_buildpath("/admin/mrp_production_extrafields.php", 1);
+	$head[$h][1] = $langs->trans("ExtraFieldsLines");
+	$head[$h][2] = 'mrp_production_extrafields';
+	$h++;
 	// Show more tabs from modules
 	// Entries must be declared in modules descriptor with line
 	//$this->tabs = array(

+ 55 - 1
htdocs/mrp/mo_production.php

@@ -61,6 +61,7 @@ $collapse = GETPOST('collapse', 'aZ09comma');
 $object = new Mo($db);
 $extrafields = new ExtraFields($db);
 $diroutputmassaction = $conf->mrp->dir_output.'/temp/massgeneration/'.$user->id;
+$objectline = new MoLine($db);
 
 $hookmanager->initHooks(array('mocard', 'globalcard')); // Note that conf->hooks_modules contains array
 
@@ -205,6 +206,17 @@ if (empty($reshook)) {
 			$moline->disable_stock_change = ($tmpproduct->type == Product::TYPE_SERVICE ? 1 : 0);
 			if ($conf->global->PRODUCT_USE_UNITS) $moline->fk_unit = $tmpproduct->fk_unit;
 		}
+		// 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]);
+			}
+		}
+		if (is_array($array_options) && count($array_options) > 0) $moline->array_options = $array_options;
 
 		$resultline = $moline->create($user, false); // Never use triggers here
 		if ($resultline <= 0) {
@@ -462,8 +474,18 @@ if (empty($reshook)) {
 		$moline = new MoLine($db);
 		$res = $moline->fetch(GETPOST('lineid', 'int'));
 		if ($result > 0) {
+			$extrafields->fetch_name_optionals_label($moline->element);
+			foreach ($extrafields->attributes[$moline->table_element]['label'] as $key => $label) {
+				$value = GETPOST('options_'.$key, 'alphanohtml');
+				$moline->array_options["options_".$key] = $value;
+			}
 			$moline->qty = GETPOST('qty_lineProduce', 'int');
-			$moline->update($user);
+			$res = $moline->update($user);
+			if ($res < 0) {
+				setEventMessages($moline->error, $moline->errors, 'errors');
+				header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
+				exit;
+			}
 			header("Location: ".$_SERVER["PHP_SELF"].'?id='.$object->id);
 			exit;
 		}
@@ -915,6 +937,17 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
 				print '<td></td>';
 			}
 			print '</tr>';
+
+			// Extrafields Line
+			if (is_object($objectline)) {
+				$extrafields->fetch_name_optionals_label($object->table_element_line);
+				$temps = $objectline->showOptionals($extrafields, 'edit', array(), '', '', 1, 'line');
+				if (!empty($temps)) {
+					print '<tr class="liste_titre"><td style="padding-top: 20px" colspan="9" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">';
+					print $temps;
+					print '</td></tr>';
+				}
+			}
 		}
 
 		// Lines to consume
@@ -1025,6 +1058,17 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
 						}
 						print '<td></td>';
 						print '</tr>';
+
+						// Extrafields Line
+						if (!empty($extrafields)) {
+							$line->fetch_optionals();
+							$temps = $line->showOptionals($extrafields, 'edit', array(), '', '', 1, 'line');
+							if (!empty($temps)) {
+								print '<td colspan="10"><div style="padding-top: 20px" id="extrafield_lines_area_edit" name="extrafield_lines_area_edit">';
+								print $temps;
+								print '</div></td>';
+							}
+						}
 					} else {
 						$suffix = '_' . $line->id;
 						print '<!-- Line to dispatch ' . $suffix . ' -->' . "\n";
@@ -1152,6 +1196,16 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
 						}
 
 						print '</tr>';
+						// Extrafields Line
+						if (!empty($extrafields)) {
+							$line->fetch_optionals();
+							$temps = $line->showOptionals($extrafields, 'view', array(), '', '', 1, 'line');
+							if (!empty($temps)) {
+								print '<td colspan="10"><div id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
+								print $temps;
+								print '</div></td>';
+							}
+						}
 					}
 					// Show detailed of already consumed with js code to collapse
 					foreach ($arrayoflines as $line2) {