Skip to content

Commit

Permalink
NEW: Management of extrafields on customer prices, level prices and d…
Browse files Browse the repository at this point in the history
…efault prices (Dolibarr#31313)

* ADD: Management of extrafields on customer prices, level prices and default prices

* ADD: sql table for managing extrafields on customer prices, level prices and default prices

* FIX: Add actions to update, add, delete extrafields and display extrafield

* FIX: colspan for customer price table

* ADD: Management of extrafields on customer prices

* FIX: Value and search for price label

* ADD: name in the files

* FIX: *

* FIX: PHP-cs fail

* FIX: comment in english, please

* FIX: variable naming and testing

* FIX: GETPOST array

* FIX: return is an array of strings, object array will be modified as well

* FIX: return array keys for Extrafields::fetch_name_optionals_label are string too

* FIX: do not mess with extrafields code and value

* Update llx_product_customer_price_extrafields.sql

* Update llx_product_price_extrafields.sql

* FIX: whooopsie

* FIX: PHP warnings

---------

Co-authored-by: Mélina JOUM <[email protected]>
Co-authored-by: Laurent Destailleur <[email protected]>
  • Loading branch information
3 people authored Oct 19, 2024
1 parent 0be87db commit a181031
Show file tree
Hide file tree
Showing 9 changed files with 899 additions and 11 deletions.
3 changes: 2 additions & 1 deletion htdocs/core/class/extrafields.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,8 @@ private function update_label($attrname, $label, $type, $size, $elementtype, $un
* @param string $elementtype Type of element ('all' = all or $object->table_element like 'adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...).
* @param boolean $forceload Force load of extra fields whatever is status of cache.
* @param string $attrname The name of the attribute.
* @return array{}|array{label:array<string,string>,type:array<string,string>,size:array<string,string>,default:array<string,string>,computed:array<string,string>,unique:array<string,int>,required:array<string,int>,param:array<string,mixed>,perms:array<string,mixed[]>,list:array<string,int>|array<string,string>,pos:array<string,int>,totalizable:array<string,int>,help:array<string,string>,printable:array<string,int>,enabled:array<string,int>,langfile:array<string,string>,css:array<string,string>,csslist:array<string,string>,hidden:array<string,int>,mandatoryfieldsofotherentities?:array<string,string>,loaded?:int,count:int} Array of attributes keys+label for all extra fields. Note: count set as present to avoid static analysis notices
* @return array<string,string> Array of attributes keys+label for all extra fields.
* in addition $this->attributes will be completed with array{label:array<string,string>,type:array<string,string>,size:array<string,string>,default:array<string,string>,computed:array<string,string>,unique:array<string,int>,required:array<string,int>,param:array<string,mixed>,perms:array<string,mixed[]>,list:array<string,int>|array<string,string>,pos:array<string,int>,totalizable:array<string,int>,help:array<string,string>,printable:array<string,int>,enabled:array<string,int>,langfile:array<string,string>,css:array<string,string>,csslist:array<string,string>,hidden:array<string,int>,mandatoryfieldsofotherentities?:array<string,string>,loaded?:int,count:int} Note: count set as present to avoid static analysis notices
*/
public function fetch_name_optionals_label($elementtype, $forceload = false, $attrname = '')
{
Expand Down
21 changes: 21 additions & 0 deletions htdocs/core/lib/product.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Copyright (C) 2023 Gauthier VERDOL <[email protected]>
* Copyright (C) 2024 Jean-Rémi TAPONIER <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024 Mélina Joum <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -331,6 +332,8 @@ function product_admin_prepare_head()

$extrafields = new ExtraFields($db);
$extrafields->fetch_name_optionals_label('product');
$extrafields->fetch_name_optionals_label('product_price');
$extrafields->fetch_name_optionals_label('product_customer_price');
$extrafields->fetch_name_optionals_label('product_fournisseur_price');

$h = 0;
Expand Down Expand Up @@ -365,6 +368,24 @@ function product_admin_prepare_head()
$head[$h][2] = 'attributes';
$h++;

$head[$h][0] = DOL_URL_ROOT.'/product/admin/product_price_extrafields.php';
$head[$h][1] = $langs->trans("ProductLevelExtraFields");
$nbExtrafields = $extrafields->attributes['product_price']['count'];
if ($nbExtrafields > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
}
$head[$h][2] = 'levelAttributes';
$h++;

$head[$h][0] = DOL_URL_ROOT.'/product/admin/product_customer_extrafields.php';
$head[$h][1] = $langs->trans("ProductCustomerExtraFields");
$nbExtrafields = $extrafields->attributes['product_customer_price']['count'];
if ($nbExtrafields > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
}
$head[$h][2] = 'customerAttributes';
$h++;

$head[$h][0] = DOL_URL_ROOT.'/product/admin/product_supplier_extrafields.php';
$head[$h][1] = $langs->trans("ProductSupplierExtraFields");
$nbExtrafields = $extrafields->attributes['product_fournisseur_price']['count'];
Expand Down
2 changes: 2 additions & 0 deletions htdocs/langs/en_US/products.lang
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ ErrorDestinationProductNotFound=Destination product not found
ErrorProductCombinationNotFound=Product variant not found
ActionAvailableOnVariantProductOnly=Action only available on the variant of product
ProductsPricePerCustomer=Product prices per customers
ProductLevelExtraFields=Additional Attributes (Level price)
ProductCustomerExtraFields=Additional Attributes (Customer price)
ProductSupplierExtraFields=Additional Attributes (Supplier Prices)
DeleteLinkedProduct=Delete the child product linked to the combination
AmountUsedToUpdateWAP=Unit amount to use to update the Weighted Average Price
Expand Down
2 changes: 2 additions & 0 deletions htdocs/langs/fr_FR/products.lang
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ ErrorDestinationProductNotFound=Produit destination non trouvé
ErrorProductCombinationNotFound=Variante du produit non trouvé
ActionAvailableOnVariantProductOnly=Action disponible uniquement sur la variante du produit
ProductsPricePerCustomer=Prix produit par clients
ProductLevelExtraFields=Attributs supplémentaires (Prix produit par niveau)
ProductCustomerExtraFields=Attributs supplémentaires (Prix produit par clients)
ProductSupplierExtraFields=Attributs supplémentaires (Prix fournisseur)
DeleteLinkedProduct=Supprimer le produit enfant lié à la combinaison
AmountUsedToUpdateWAP=Montant unitaire à utiliser pour mettre à jour le prix moyen pondéré
Expand Down
110 changes: 110 additions & 0 deletions htdocs/product/admin/product_customer_extrafields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <[email protected]>
* Copyright (C) 2003 Jean-Louis Bergamo <[email protected]>
* Copyright (C) 2004-2011 Laurent Destailleur <[email protected]>
* Copyright (C) 2012 Marcos García <[email protected]>
* Copyright (C) 2012 Regis Houssin <[email protected]>
* Copyright (C) 2019 Tim Otte <[email protected]>
* Copyright (C) 2024 Mélina Joum <[email protected]>
*
* 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/product/admin/product_customer_extrafields.php
* \ingroup product
* \brief Page to setup extra fields of products
*/

// Load Dolibarr environment
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
$type2label = ExtraFields::getListOfTypesLabels();

$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'product_customer_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->transnoentitiesnoconv("ProductsAndServices");
if (!isModEnabled("product")) {
$title = $langs->trans('ServiceSetup');
$textobject = $langs->trans('Services');
} elseif (!isModEnabled("service")) {
$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, '', 0, 0, '', '', '', 'mod-product page-admin_product_customer_extrafields');


$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($title, $linkback, 'title_setup');


$head = product_admin_prepare_head();

print dol_get_fiche_head($head, 'customerAttributes', $textobject, -1, 'product');

require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';

print dol_get_fiche_end();


// 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();
111 changes: 111 additions & 0 deletions htdocs/product/admin/product_price_extrafields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/* Copyright (C) 2001-2002 Rodolphe Quiedeville <[email protected]>
* Copyright (C) 2003 Jean-Louis Bergamo <[email protected]>
* Copyright (C) 2004-2011 Laurent Destailleur <[email protected]>
* Copyright (C) 2012 Marcos García <[email protected]>
* Copyright (C) 2012 Regis Houssin <[email protected]>
* Copyright (C) 2019 Tim Otte <[email protected]>
* Copyright (C) 2024 Mélina Joum <[email protected]>
*
* 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/product/admin/product_supplier_extrafields.php
* \ingroup product
* \brief Page to setup extra fields of products
*/

// Load Dolibarr environment
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
$type2label = ExtraFields::getListOfTypesLabels();

$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
$elementtype = 'product_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->transnoentitiesnoconv("ProductsAndServices");
if (!isModEnabled("product")) {
$title = $langs->trans('ServiceSetup');
$textobject = $langs->trans('Services');
} elseif (!isModEnabled("service")) {
$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, '', 0, 0, '', '', '', 'mod-product page-admin_product_supplier_extrafields');


$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($title, $linkback, 'title_setup');


$head = product_admin_prepare_head();

print dol_get_fiche_head($head, 'levelAttributes', $textobject, -1, 'product');

require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';

print dol_get_fiche_end();


// 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();
Loading

0 comments on commit a181031

Please sign in to comment.