From 54d0b94b6db0e579cac20794145b1e91e7c584e5 Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Wed, 4 Sep 2019 15:13:42 +0200 Subject: [PATCH 01/11] Added extrafield support to the product supplier price lines --- .../core/class/commondocgenerator.class.php | 12 +- htdocs/core/lib/product.lib.php | 5 + ...duct_fournisseur_price_extrafields.key.sql | 20 +++ ..._product_fournisseur_price_extrafields.sql | 24 ++++ htdocs/langs/de_DE/products.lang | 1 + .../admin/product_supplier_extrafields.php | 132 ++++++++++++++++++ htdocs/product/fournisseurs.php | 68 +++++++++ 7 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 htdocs/install/mysql/tables/llx_product_fournisseur_price_extrafields.key.sql create mode 100644 htdocs/install/mysql/tables/llx_product_fournisseur_price_extrafields.sql create mode 100644 htdocs/product/admin/product_supplier_extrafields.php diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index fadd0c02fde..28b1dc9d4c1 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -577,7 +577,7 @@ abstract class CommonDocGenerator { $resarray['line_unit']=$outputlangs->trans($line->getLabelOfUnit('long')); $resarray['line_unit_short']=$outputlangs->trans($line->getLabelOfUnit('short')); - } + } // Retrieve extrafields $extrafieldkey=$line->element; @@ -588,6 +588,16 @@ abstract class CommonDocGenerator $line->fetch_optionals(); $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs); + + // Add the product supplier extrafields to the substitutions + $resql = $this->db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = " . $line->ref_fourn); + if ($this->db->num_rows($resql) > 0) { + $resql = $this->db->fetch_object($resql); + $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); + foreach ($extralabels as $key => $value) { + $resarray['line_product_supplier_'.$key] = $resql->{$key}; + } + } // Load product data optional fields to the line -> enables to use "line_options_{extrafield}" if (isset($line->fk_product) && $line->fk_product > 0) diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 68a6d9082f2..38541bc8fe3 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -292,6 +292,11 @@ function product_admin_prepare_head() $head[$h][2] = 'attributes'; $h++; + $head[$h][0] = DOL_URL_ROOT.'/product/admin/product_supplier_extrafields.php'; + $head[$h][1] = $langs->trans("ProductSupplierExtraFields"); + $head[$h][2] = 'supplierAttributes'; + $h++; + complete_head_from_modules($conf, $langs, null, $head, $h, 'product_admin', 'remove'); return $head; diff --git a/htdocs/install/mysql/tables/llx_product_fournisseur_price_extrafields.key.sql b/htdocs/install/mysql/tables/llx_product_fournisseur_price_extrafields.key.sql new file mode 100644 index 00000000000..b0d9345b604 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_product_fournisseur_price_extrafields.key.sql @@ -0,0 +1,20 @@ +-- =================================================================== +-- Copyright (C) 2011 Laurent Destailleur +-- +-- 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 . +-- +-- =================================================================== + + +ALTER TABLE llx_product_fournisseur_price_extrafields ADD INDEX idx_product_fournisseur_price_extrafields (fk_object); diff --git a/htdocs/install/mysql/tables/llx_product_fournisseur_price_extrafields.sql b/htdocs/install/mysql/tables/llx_product_fournisseur_price_extrafields.sql new file mode 100644 index 00000000000..51d5499e825 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_product_fournisseur_price_extrafields.sql @@ -0,0 +1,24 @@ +-- ============================================================================ +-- Copyright (C) 2011 Laurent Destailleur +-- +-- 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 . +-- +-- ============================================================================ + +Create Table llx_product_fournisseur_price_extrafields ( + rowid integer AUTO_INCREMENT PRIMARY KEY, + tms timestamp, + fk_object integer NOT NULL, + import_key varchar(14) -- import key +) ENGINE=innodb; \ No newline at end of file diff --git a/htdocs/langs/de_DE/products.lang b/htdocs/langs/de_DE/products.lang index c21d97aeafe..7e81f96de25 100644 --- a/htdocs/langs/de_DE/products.lang +++ b/htdocs/langs/de_DE/products.lang @@ -341,3 +341,4 @@ ErrorDestinationProductNotFound=Zielprodukt nicht gefunden ErrorProductCombinationNotFound=Produktvariante nicht gefunden ActionAvailableOnVariantProductOnly=Action only available on the variant of product ProductsPricePerCustomer=Product prices per customers +ProductSupplierExtraFields=Ergänzende Attribute (Lieferantenpreise) \ No newline at end of file diff --git a/htdocs/product/admin/product_supplier_extrafields.php b/htdocs/product/admin/product_supplier_extrafields.php new file mode 100644 index 00000000000..149178ead36 --- /dev/null +++ b/htdocs/product/admin/product_supplier_extrafields.php @@ -0,0 +1,132 @@ + + * Copyright (C) 2003 Jean-Louis Bergamo + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2012 Marcos García + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2019 Tim Otte + * + * 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 . + */ + +/** + * \file htdocs/product/admin/product_supplier_extrafields.php + * \ingroup product + * \brief Page to setup extra fields of products + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + +// Load translation files required by the page +$langs->loadLangs(array('companies', 'admin', 'products')); + +$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', 'alpha'); +$attrname=GETPOST('attrname', 'alpha'); +$elementtype='product_fournisseur_price'; //Must be the $element of the class that manage extrafield + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php'; + + + +/* + * View + */ + +$title = $langs->trans('ProductServiceSetup'); +$textobject = $langs->trans("ProductsAndServices"); +if (empty($conf->product->enabled)) +{ + $title = $langs->trans('ServiceSetup'); + $textobject = $langs->trans('Services'); +} +elseif (empty($conf->service->enabled)) +{ + $title = $langs->trans('ProductSetup'); + $textobject = $langs->trans('Products'); +} + +//$help_url='EN:Module Third Parties setup|FR:Paramétrage_du_module_Tiers'; +$help_url=''; +llxHeader('', $title, $help_url); + + +$linkback=''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($title, $linkback, 'title_setup'); + + +$head = product_admin_prepare_head(); + +dol_fiche_head($head, 'supplierAttributes', $textobject, -1, 'product'); + +require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; + +dol_fiche_end(); + + +// Buttons +if ($action != 'create' && $action != 'edit') +{ + print '
'; + print "".$langs->trans("NewAttribute").""; + print "
"; +} + + +/* ************************************************************************** */ +/* */ +/* Creation of an optional field */ +/* */ +/* ************************************************************************** */ + +if ($action == 'create') +{ + print '
'; + 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 "
"; + 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(); diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 587d494a51f..0771f0ab108 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -33,6 +33,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php'; @@ -53,6 +54,8 @@ $cost_price=GETPOST('cost_price', 'alpha'); $backtopage=GETPOST('backtopage', 'alpha'); $error=0; +$extrafields = new ExtraFields($db); + // If socid provided by ajax company selector if (! empty($_REQUEST['search_fourn_id'])) { @@ -138,6 +141,7 @@ if (empty($reshook)) $action = ''; $result=$object->remove_product_fournisseur_price($rowid); if($result > 0){ + $db->query("DELETE FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = $rowid"); setEventMessages($langs->trans("PriceRemoved"), null, 'mesgs'); }else{ $error++; @@ -257,6 +261,36 @@ if (empty($reshook)) if (isset($_POST['ref_fourn_price_id'])) $object->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']); + $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); + $extrafield_values = $extrafields->getOptionalsFromPost("product_fournisseur_price"); + + $sql = ""; + $resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $object->product_fourn_price_id); + // Insert a new extrafields row, if none exists + if ($db->num_rows($resql) != 1) { + + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields (fk_object, "; + foreach ($extrafield_values as $key => $value) { + $sql .= str_replace('options_', '', $key) . ', '; + } + $sql = substr($sql, 0, strlen($sql)-2) . ") VALUES (" . $object->product_fourn_price_id . ", "; + foreach ($extrafield_values as $key => $value) { + $sql .= '"' . $value . '", '; + } + $sql = substr($sql, 0, strlen($sql)-2) . ')'; + } + // else update the existing one + else { + $sql = "UPDATE " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields SET "; + foreach ($extrafield_values as $key => $value) { + $sql .= str_replace('options_', '', $key) . ' = "' . $value . '", '; + } + $sql = substr($sql, 0, strlen($sql)-2) . ' WHERE fk_object = ' . $object->product_fourn_price_id; + } + + // Execute the sql command from above + $db->query($sql); + $newprice = price2num(GETPOST("price", "alpha")); if ($conf->multicurrency->enabled) @@ -723,6 +757,20 @@ SCRIPT; print ''; } + $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); + // Extrafields + $resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $rowid); + if ($db->num_rows($resql) != 1) { + foreach ($extralabels as $key => $value) { + print '' . $langs->trans($value) . '' . $extrafields->showInputField($key, '', '', '', '', '', 0, 'product_fournisseur_price') . ''; + } + } else { + $resql = $db->fetch_object($resql); + foreach ($extralabels as $key => $value) { + print '' . $langs->trans($value) . '' . $extrafields->showInputField($key, $resql->{$key}, '', '', '', '', 0, 'product_fournisseur_price') . ''; + } + } + if (is_object($hookmanager)) { $parameters=array('id_fourn'=>$id_fourn,'prod_id'=>$object->id); @@ -810,6 +858,13 @@ SCRIPT; print_liste_field_titre("BarcodeType", $_SERVER["PHP_SELF"], "pfp.fk_barcode_type", "", $param, '', $sortfield, $sortorder, 'center '); } print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "pfp.tms", "", $param, '', $sortfield, $sortorder, 'right '); + + // fetch optionals attributes and labels + $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); + foreach ($extralabels as $extrafield) { + print_liste_field_titre($langs->trans($extrafield), $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); + } + if (is_object($hookmanager)) { $parameters=array('id_fourn'=>$id_fourn, 'prod_id'=>$object->id); @@ -924,6 +979,19 @@ SCRIPT; print dol_print_date(($productfourn->fourn_date_modification ? $productfourn->fourn_date_modification : $productfourn->date_modification), "dayhour"); print ''; + // Extrafields + $resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $productfourn->product_fourn_price_id); + if ($db->num_rows($resql) != 1) { + foreach ($extralabels as $extrafield) { + print ""; + } + } else { + $resql = $db->fetch_object($resql); + foreach ($extralabels as $key => $value) { + print "" . $extrafields->showOutputField($key, $resql->{$key}) . ""; + } + } + if (is_object($hookmanager)) { $parameters=array('id_pfp'=>$productfourn->product_fourn_price_id,'id_fourn'=>$id_fourn,'prod_id'=>$object->id); From fbafbc3e19f4dab00bda2b7a527021538fc0f3fb Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Wed, 4 Sep 2019 15:16:29 +0200 Subject: [PATCH 02/11] Added myself to the author list --- htdocs/product/fournisseurs.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 0771f0ab108..ca9e36832e4 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -8,7 +8,8 @@ * Copyright (C) 2014 Ion Agorria * Copyright (C) 2015 Alexandre Spangaro * Copyright (C) 2016 Ferran Marcet - * Copyright (C) 2019 Frédéric France + * Copyright (C) 2019 Frédéric France + * Copyright (C) 2019 Tim Otte * * 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 From be000b96ee72926b2e1a0933a383783764f61118 Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Wed, 4 Sep 2019 16:42:13 +0200 Subject: [PATCH 03/11] Fixed error that occurred in the travis CI build --- htdocs/product/fournisseurs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index ca9e36832e4..3d8585ecfc4 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -863,7 +863,7 @@ SCRIPT; // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); foreach ($extralabels as $extrafield) { - print_liste_field_titre($langs->trans($extrafield), $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); + print_liste_field_titre($extrafield, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); } if (is_object($hookmanager)) From 0f9b01cd5b4f7829b49c495fd5cd1be4180e5bad Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Thu, 5 Sep 2019 09:47:40 +0200 Subject: [PATCH 04/11] Added support for extrafield styling options: - visibility now implemented - fieldrequired now implemented --- htdocs/product/fournisseurs.php | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 3d8585ecfc4..f4431d7bf77 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -151,7 +151,7 @@ if (empty($reshook)) } } - if ($action == 'updateprice') + if ($action == 'save_price') { $id_fourn=GETPOST("id_fourn"); if (empty($id_fourn)) $id_fourn=GETPOST("search_id_fourn"); @@ -437,7 +437,7 @@ if ($id > 0 || $ref) // Form to add or update a price - if (($action == 'add_price' || $action == 'updateprice' ) && $usercancreate) + if (($action == 'add_price' || $action == 'update_price' ) && $usercancreate) { $langs->load("suppliers"); @@ -453,7 +453,7 @@ if ($id > 0 || $ref) print '
'; print ''; - print ''; + print ''; dol_fiche_head(); @@ -763,12 +763,16 @@ SCRIPT; $resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $rowid); if ($db->num_rows($resql) != 1) { foreach ($extralabels as $key => $value) { - print '' . $langs->trans($value) . '' . $extrafields->showInputField($key, '', '', '', '', '', 0, 'product_fournisseur_price') . ''; + if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) { + print 'attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '') . '>' . $langs->trans($value) . '' . $extrafields->showInputField($key, '', '', '', '', '', 0, 'product_fournisseur_price') . ''; + } } } else { $resql = $db->fetch_object($resql); foreach ($extralabels as $key => $value) { - print '' . $langs->trans($value) . '' . $extrafields->showInputField($key, $resql->{$key}, '', '', '', '', 0, 'product_fournisseur_price') . ''; + if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) { + print 'attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '') . '>' . $langs->trans($value) . '' . $extrafields->showInputField($key, $resql->{$key}, '', '', '', '', 0, 'product_fournisseur_price') . ''; + } } } @@ -796,7 +800,7 @@ SCRIPT; print "\n
\n"; - if ($action != 'add_price' && $action != 'updateprice') + if ($action != 'add_price' && $action != 'update_price') { $parameters=array(); $reshook=$hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -862,8 +866,11 @@ SCRIPT; // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); - foreach ($extralabels as $extrafield) { - print_liste_field_titre($extrafield, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); + foreach ($extralabels as $key => $value) { + // Show field if not hidden + if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { + print_liste_field_titre($value, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); + } } if (is_object($hookmanager)) @@ -983,13 +990,17 @@ SCRIPT; // Extrafields $resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $productfourn->product_fourn_price_id); if ($db->num_rows($resql) != 1) { - foreach ($extralabels as $extrafield) { - print ""; + foreach ($extralabels as $key => $value) { + if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { + print ""; + } } } else { $resql = $db->fetch_object($resql); foreach ($extralabels as $key => $value) { - print "" . $extrafields->showOutputField($key, $resql->{$key}) . ""; + if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { + print '' . $extrafields->showOutputField($key, $resql->{$key}) . ""; + } } } @@ -1003,7 +1014,7 @@ SCRIPT; print ''; if ($usercancreate) { - print ''.img_edit().""; + print ''.img_edit().""; print '   '; print ''.img_picto($langs->trans("Remove"), 'delete').''; } From 0c68a7b0e6362c2fad4a4fc9995b91e43bdd4873 Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Tue, 10 Sep 2019 09:11:31 +0200 Subject: [PATCH 05/11] Possible solution for the problem "SELECT * is forbidden by SQL rules" --- htdocs/core/class/commondocgenerator.class.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 28b1dc9d4c1..1b0a9df9a92 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -590,10 +590,15 @@ abstract class CommonDocGenerator $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs); // Add the product supplier extrafields to the substitutions - $resql = $this->db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = " . $line->ref_fourn); + $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); + $columns = ""; + foreach ($extralabels as $key => $value) { + $columns .= "$key, "; + } + substr($columns, 0, strlen($columns) - 2); + $resql = $this->db->query("SELECT $columns FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = " . $line->ref_fourn); if ($this->db->num_rows($resql) > 0) { $resql = $this->db->fetch_object($resql); - $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); foreach ($extralabels as $key => $value) { $resarray['line_product_supplier_'.$key] = $resql->{$key}; } From 8f4b2436e480f8c5fd83cae3b581e84c1bf47b75 Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Tue, 10 Sep 2019 09:13:42 +0200 Subject: [PATCH 06/11] Ooops --- htdocs/core/class/commondocgenerator.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 1b0a9df9a92..b671653a9b0 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -595,7 +595,7 @@ abstract class CommonDocGenerator foreach ($extralabels as $key => $value) { $columns .= "$key, "; } - substr($columns, 0, strlen($columns) - 2); + $columns = substr($columns, 0, strlen($columns) - 2); $resql = $this->db->query("SELECT $columns FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = " . $line->ref_fourn); if ($this->db->num_rows($resql) > 0) { $resql = $this->db->fetch_object($resql); From b673c88fab0493c4a236c013309866c82529946c Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Wed, 25 Sep 2019 10:25:00 +0200 Subject: [PATCH 07/11] Fixed sql error --- htdocs/core/class/commondocgenerator.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index b671653a9b0..cca7f4da2a9 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -596,7 +596,7 @@ abstract class CommonDocGenerator $columns .= "$key, "; } $columns = substr($columns, 0, strlen($columns) - 2); - $resql = $this->db->query("SELECT $columns FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = " . $line->ref_fourn); + $resql = $this->db->query("SELECT $columns FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '" . $line->ref_fourn . "'"); if ($this->db->num_rows($resql) > 0) { $resql = $this->db->fetch_object($resql); foreach ($extralabels as $key => $value) { From 10f7bd34947faa227b4a63caea5fa3f480216f89 Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Fri, 27 Sep 2019 15:42:57 +0200 Subject: [PATCH 08/11] Restricted query of ExtraFields for supplier orders --- .../core/class/commondocgenerator.class.php | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index cca7f4da2a9..29f740593b6 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -587,21 +587,25 @@ abstract class CommonDocGenerator $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true); $line->fetch_optionals(); - $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs); + $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs); - // Add the product supplier extrafields to the substitutions - $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); - $columns = ""; - foreach ($extralabels as $key => $value) { - $columns .= "$key, "; - } - $columns = substr($columns, 0, strlen($columns) - 2); - $resql = $this->db->query("SELECT $columns FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '" . $line->ref_fourn . "'"); - if ($this->db->num_rows($resql) > 0) { - $resql = $this->db->fetch_object($resql); + // Check if the current line belongs to a supplier order + if (get_class($line) == 'CommandeFournisseurLigne') { + // Add the product supplier extrafields to the substitutions + $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); + $columns = ""; foreach ($extralabels as $key => $value) { - $resarray['line_product_supplier_'.$key] = $resql->{$key}; + $columns .= "$key, "; } + $columns = substr($columns, 0, strlen($columns) - 2); + $resql = $this->db->query("SELECT $columns FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '" . $line->ref_fourn . "'"); + if ($this->db->num_rows($resql) > 0) { + $resql = $this->db->fetch_object($resql); + foreach ($extralabels as $key => $value) { + $resarray['line_product_supplier_'.$key] = $resql->{$key}; + } + } + } // Load product data optional fields to the line -> enables to use "line_options_{extrafield}" From a8e73533b9ffb5658a1475a33fb0ad1fa2882945 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 27 Sep 2019 13:43:11 +0000 Subject: [PATCH 09/11] Fixing style errors. --- htdocs/core/class/commondocgenerator.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 29f740593b6..d158d9756dd 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -605,7 +605,6 @@ abstract class CommonDocGenerator $resarray['line_product_supplier_'.$key] = $resql->{$key}; } } - } // Load product data optional fields to the line -> enables to use "line_options_{extrafield}" From 8ce6197314cbf75a2afbb3c4500d51852b6939ec Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 20 Oct 2019 14:37:15 +0200 Subject: [PATCH 10/11] Update commondocgenerator.class.php --- htdocs/core/class/commondocgenerator.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index d158d9756dd..16919677260 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -598,7 +598,7 @@ abstract class CommonDocGenerator $columns .= "$key, "; } $columns = substr($columns, 0, strlen($columns) - 2); - $resql = $this->db->query("SELECT $columns FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '" . $line->ref_fourn . "'"); + $resql = $this->db->query("SELECT $columns FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '" . $line->ref_supplier . "'"); if ($this->db->num_rows($resql) > 0) { $resql = $this->db->fetch_object($resql); foreach ($extralabels as $key => $value) { From ceb34822048f2c8d1fedc0a554b2493275499ed1 Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Tue, 22 Oct 2019 11:36:28 +0200 Subject: [PATCH 11/11] Requested changes implemented --- .../core/class/commondocgenerator.class.php | 25 +++++++++++-------- htdocs/langs/en_US/products.lang | 1 + htdocs/product/fournisseurs.php | 6 +++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index d158d9756dd..6d046645f9a 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -590,19 +590,24 @@ abstract class CommonDocGenerator $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs); // Check if the current line belongs to a supplier order - if (get_class($line) == 'CommandeFournisseurLigne') { + if (get_class($line) == 'CommandeFournisseurLigne') + { // Add the product supplier extrafields to the substitutions - $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); + $extrafields->fetch_name_optionals_label("product_fournisseur_price"); + $extralabels=$extrafields->attributes["product_fournisseur_price"]['label']; $columns = ""; - foreach ($extralabels as $key => $value) { + foreach ($extralabels as $key => $value) $columns .= "$key, "; - } - $columns = substr($columns, 0, strlen($columns) - 2); - $resql = $this->db->query("SELECT $columns FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '" . $line->ref_fourn . "'"); - if ($this->db->num_rows($resql) > 0) { - $resql = $this->db->fetch_object($resql); - foreach ($extralabels as $key => $value) { - $resarray['line_product_supplier_'.$key] = $resql->{$key}; + + if ($columns != "") + { + $columns = substr($columns, 0, strlen($columns) - 2); + $resql = $this->db->query("SELECT $columns FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields AS ex INNER JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '" . $line->ref_fourn . "'"); + if ($this->db->num_rows($resql) > 0) { + $resql = $this->db->fetch_object($resql); + + foreach ($extralabels as $key => $value) + $resarray['line_product_supplier_'.$key] = $resql->{$key}; } } } diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 73e672284de..9ae9c30cf0d 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -341,3 +341,4 @@ ErrorDestinationProductNotFound=Destination product not found ErrorProductCombinationNotFound=Product variant not found ActionAvailableOnVariantProductOnly=Action only available on the variant of product ProductsPricePerCustomer=Product prices per customers +ProductSupplierExtraFields=Additional Attributes (Supplier Prices) \ No newline at end of file diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index f4431d7bf77..9fbdf8418ed 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -758,7 +758,8 @@ SCRIPT; print ''; } - $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); + $extrafields->fetch_name_optionals_label("product_fournisseur_price"); + $extralabels=$extrafields->attributes["product_fournisseur_price"]['label']; // Extrafields $resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $rowid); if ($db->num_rows($resql) != 1) { @@ -865,7 +866,8 @@ SCRIPT; print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "pfp.tms", "", $param, '', $sortfield, $sortorder, 'right '); // fetch optionals attributes and labels - $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); + $extrafields->fetch_name_optionals_label("product_fournisseur_price"); + $extralabels=$extrafields->attributes["product_fournisseur_price"]['label']; foreach ($extralabels as $key => $value) { // Show field if not hidden if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) {