Added extrafield support to the product supplier price lines
This commit is contained in:
parent
0f02a621ba
commit
54d0b94b6d
@ -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)
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
-- ===================================================================
|
||||
-- Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
--
|
||||
-- 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 <http://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- ===================================================================
|
||||
|
||||
|
||||
ALTER TABLE llx_product_fournisseur_price_extrafields ADD INDEX idx_product_fournisseur_price_extrafields (fk_object);
|
||||
@ -0,0 +1,24 @@
|
||||
-- ============================================================================
|
||||
-- Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
--
|
||||
-- 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 <http://www.gnu.org/licenses/>.
|
||||
--
|
||||
-- ============================================================================
|
||||
|
||||
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;
|
||||
@ -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)
|
||||
132
htdocs/product/admin/product_supplier_extrafields.php
Normal file
132
htdocs/product/admin/product_supplier_extrafields.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?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 Marcos García <marcosgdf@gmail.com>
|
||||
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
|
||||
* Copyright (C) 2019 Tim Otte <otte@meuser.it>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \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='<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();
|
||||
|
||||
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 '<div class="tabsAction">';
|
||||
print "<a class=\"butAction\" href=\"".$_SERVER["PHP_SELF"]."?action=create#newattrib\">".$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();
|
||||
@ -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 '</tr>';
|
||||
}
|
||||
|
||||
$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 '<tr><td>' . $langs->trans($value) . '</td><td>' . $extrafields->showInputField($key, '', '', '', '', '', 0, 'product_fournisseur_price') . '</td></tr>';
|
||||
}
|
||||
} else {
|
||||
$resql = $db->fetch_object($resql);
|
||||
foreach ($extralabels as $key => $value) {
|
||||
print '<tr><td>' . $langs->trans($value) . '</td><td>' . $extrafields->showInputField($key, $resql->{$key}, '', '', '', '', 0, 'product_fournisseur_price') . '</td></tr>';
|
||||
}
|
||||
}
|
||||
|
||||
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 '</td>';
|
||||
|
||||
// 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 "<td></td>";
|
||||
}
|
||||
} else {
|
||||
$resql = $db->fetch_object($resql);
|
||||
foreach ($extralabels as $key => $value) {
|
||||
print "<td>" . $extrafields->showOutputField($key, $resql->{$key}) . "</td>";
|
||||
}
|
||||
}
|
||||
|
||||
if (is_object($hookmanager))
|
||||
{
|
||||
$parameters=array('id_pfp'=>$productfourn->product_fourn_price_id,'id_fourn'=>$id_fourn,'prod_id'=>$object->id);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user