diff --git a/admin/about.php b/admin/about.php
new file mode 100644
index 0000000..5019998
--- /dev/null
+++ b/admin/about.php
@@ -0,0 +1,97 @@
+
+ *
+ * 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 dynamicsprices/admin/about.php
+ * \ingroup dynamicsprices
+ * \brief About page of DynamicsPrices module.
+ */
+
+$res = 0;
+if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
+ $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
+}
+$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
+$tmp2 = realpath(__FILE__);
+$i = strlen($tmp) - 1;
+$j = strlen($tmp2) - 1;
+while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
+ $i--;
+ $j--;
+}
+if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
+ $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
+}
+if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
+ $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
+}
+if (!$res && file_exists("../../main.inc.php")) {
+ $res = @include "../../main.inc.php";
+}
+if (!$res && file_exists("../../../main.inc.php")) {
+ $res = @include "../../../main.inc.php";
+}
+if (!$res) {
+ die("Include of main fails");
+}
+
+require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
+require_once '../lib/dynamicsprices.lib.php';
+require_once '../core/modules/modDynamicsPrices.class.php';
+
+$langs->loadLangs(array("admin", "dynamicsprices@dynamicsprices"));
+
+if (!$user->admin) {
+ accessforbidden();
+}
+
+$title = $langs->trans('LMDB_AboutTitle');
+$help_url = '';
+$moduleDescriptor = new modDynamicsPrices($db);
+
+llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-dynamicsprices page-admin');
+
+$linkback = ''.$langs->trans("BackToModuleList").'';
+print load_fiche_titre($title, $linkback, 'title_setup');
+
+$head = dynamicspricesAdminPrepareHead();
+print dol_get_fiche_head($head, 'about', $title, -1, "dynamicsprices@dynamicsprices");
+
+print '
'.$langs->trans('LMDB_AboutDescription').'
';
+print '
';
+print '';
+print '
';
+print '| '.$langs->trans('LMDB_AboutGeneral').' |
';
+print '| '.$langs->trans('Module').' | '.$langs->trans('ModuleDynamicsPricesName').' |
';
+print '| '.$langs->trans('Description').' | '.dol_escape_htmltag($langs->trans($moduleDescriptor->description)).' |
';
+print '| '.$langs->trans('Version').' | '.dol_escape_htmltag((string) $moduleDescriptor->version).' |
';
+print '| '.$langs->trans('Author').' | '.dol_escape_htmltag((string) $moduleDescriptor->editor_name).' |
';
+print '| '.$langs->trans('Website').' | '.dol_escape_htmltag((string) $moduleDescriptor->editor_url).' |
';
+print '
';
+print '
';
+print '
';
+print '';
+
+print dol_get_fiche_end();
+llxFooter();
+$db->close();
diff --git a/admin/setup.php b/admin/setup.php
index 5520bc0..494c90c 100644
--- a/admin/setup.php
+++ b/admin/setup.php
@@ -97,22 +97,6 @@
// Actions on module constants
include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
-// Ensure commercial category code columns exist for dictionaries compatibility.
-// This keeps setup page functional before/after SQL migration scripts execution.
-$resql = $db->query("SHOW COLUMNS FROM ".MAIN_DB_PREFIX."c_coefprice LIKE 'code_commercial_category'");
-if ($resql && $db->num_rows($resql) == 0) {
- $db->query("ALTER TABLE ".MAIN_DB_PREFIX."c_coefprice ADD COLUMN code_commercial_category VARCHAR(50) DEFAULT NULL");
-}
-$db->query("INSERT INTO ".MAIN_DB_PREFIX."c_commercial_category (code, label, active) SELECT DISTINCT t.fk_nature, t.fk_nature, 1 FROM ".MAIN_DB_PREFIX."c_coefprice as t LEFT JOIN ".MAIN_DB_PREFIX."c_commercial_category as cc ON cc.code = t.fk_nature WHERE t.fk_nature IS NOT NULL AND t.fk_nature <> '' AND cc.rowid IS NULL");
-$db->query("UPDATE ".MAIN_DB_PREFIX."c_coefprice SET code_commercial_category = fk_nature WHERE (code_commercial_category IS NULL OR code_commercial_category = '') AND fk_nature IS NOT NULL AND fk_nature <> ''");
-
-$resql = $db->query("SHOW COLUMNS FROM ".MAIN_DB_PREFIX."c_margin_on_cost LIKE 'code_commercial_category'");
-if ($resql && $db->num_rows($resql) == 0) {
- $db->query("ALTER TABLE ".MAIN_DB_PREFIX."c_margin_on_cost ADD COLUMN code_commercial_category VARCHAR(50) DEFAULT NULL");
-}
-$db->query("INSERT INTO ".MAIN_DB_PREFIX."c_commercial_category (code, label, active) SELECT DISTINCT t.code_nature, t.code_nature, 1 FROM ".MAIN_DB_PREFIX."c_margin_on_cost as t LEFT JOIN ".MAIN_DB_PREFIX."c_commercial_category as cc ON cc.code = t.code_nature WHERE t.code_nature IS NOT NULL AND t.code_nature <> '' AND cc.rowid IS NULL");
-$db->query("UPDATE ".MAIN_DB_PREFIX."c_margin_on_cost SET code_commercial_category = code_nature WHERE (code_commercial_category IS NULL OR code_commercial_category = '') AND code_nature IS NOT NULL AND code_nature <> ''");
-
// Load dictionary definitions
$module = new modDynamicsPrices($db);
$taborder = empty($module->dictionaries['taborder']) ? array() : $module->dictionaries['taborder'];
diff --git a/core/modules/modDynamicsPrices.class.php b/core/modules/modDynamicsPrices.class.php
index 6ecb81a..9b4bd00 100644
--- a/core/modules/modDynamicsPrices.class.php
+++ b/core/modules/modDynamicsPrices.class.php
@@ -253,6 +253,12 @@ public function __construct($db)
);
*/
/* BEGIN MODULEBUILDER DICTIONARIES */
+ $commercialCategoryHasEntity = $this->columnExists(MAIN_DB_PREFIX."c_commercial_category", 'entity');
+ $commercialCategorySelectSql = $commercialCategoryHasEntity
+ ? 'SELECT t.rowid as rowid, t.entity, t.code, t.label, t.active FROM '.MAIN_DB_PREFIX.'c_commercial_category AS t WHERE t.entity = '.((int) $conf->entity)
+ : 'SELECT t.rowid as rowid, t.code, t.label, t.active FROM '.MAIN_DB_PREFIX.'c_commercial_category AS t';
+ $commercialCategoryFieldValue = $commercialCategoryHasEntity ? "code,entity,label" : "code,label";
+
$this->dictionaries = array(
'langs' => 'dynamicsprices@dynamicsprices',
'tabname' => array(MAIN_DB_PREFIX."c_coefprice", MAIN_DB_PREFIX."c_margin_on_cost", MAIN_DB_PREFIX."c_commercial_category"),
@@ -260,7 +266,7 @@ public function __construct($db)
'tabsql' => array(
'SELECT t.rowid as rowid, t.entity, t.code, t.code_commercial_category, cc.label as commercial_category_label, t.pricelevel, t.minrate, t.targetrate, t.active FROM '.MAIN_DB_PREFIX.'c_coefprice AS t LEFT JOIN '.MAIN_DB_PREFIX.'c_commercial_category as cc ON cc.code = t.code_commercial_category WHERE t.entity = '.((int) $conf->entity),
'SELECT t.rowid as rowid, t.entity, t.code, t.code_commercial_category, cc.label as commercial_category_label, t.margin_on_cost_percent, t.active FROM '.MAIN_DB_PREFIX.'c_margin_on_cost AS t LEFT JOIN '.MAIN_DB_PREFIX.'c_commercial_category as cc ON cc.code = t.code_commercial_category WHERE t.entity = '.((int) $conf->entity),
- 'SELECT t.rowid as rowid, t.code, t.label, t.active FROM '.MAIN_DB_PREFIX.'c_commercial_category AS t',
+ $commercialCategorySelectSql,
),
'tabsqlsort' => array(
"code ASC",
@@ -275,12 +281,12 @@ public function __construct($db)
'tabfieldvalue' => array(
"code,entity,code_commercial_category,pricelevel,targetrate,minrate",
"code,entity,code_commercial_category,margin_on_cost_percent",
- "code,label",
+ $commercialCategoryFieldValue,
),
'tabfieldinsert' => array(
"code,entity,code_commercial_category,pricelevel,targetrate,minrate",
"code,entity,code_commercial_category,margin_on_cost_percent",
- "code,label",
+ $commercialCategoryFieldValue,
),
'tabrowid' => array('rowid', 'rowid', 'rowid'),
'tabcond' => array(
@@ -536,7 +542,7 @@ public function __construct($db)
*/
public function init($options = '')
{
- global $conf, $langs;
+ global $conf;
// Create tables of module at module activation
//$result = $this->_load_tables('/install/mysql/', 'dynamicsprices');
@@ -545,9 +551,6 @@ public function init($options = '')
return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default')
}
- // Ensure migration columns exist when module is activated/updated.
- $this->ensureCommercialCategoryColumns();
-
// Create product/service extrafield during init.
include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
@@ -578,9 +581,9 @@ public function init($options = '')
return -1;
}
}
-
- // Permissions
- $this->remove($options);
+
+ // Permissions
+ $this->remove($options);
$sql = array();
@@ -619,29 +622,22 @@ public function init($options = '')
}
/**
- * Ensure commercial category columns exist and are populated.
+ * Check if a column exists on a table.
*
- * @return void
+ * @param string $tableName Table name
+ * @param string $columnName Column name
+ * @return bool
*/
- private function ensureCommercialCategoryColumns()
+ private function columnExists($tableName, $columnName)
{
- $resql = $this->db->query("SHOW COLUMNS FROM ".$this->db->prefix()."c_coefprice LIKE 'code_commercial_category'");
- if ($resql && $this->db->num_rows($resql) == 0) {
- $this->db->query("ALTER TABLE ".$this->db->prefix()."c_coefprice ADD COLUMN code_commercial_category VARCHAR(50) DEFAULT NULL");
- }
- $this->db->query("INSERT INTO ".$this->db->prefix()."c_commercial_category (code, label, active) SELECT DISTINCT t.fk_nature, t.fk_nature, 1 FROM ".$this->db->prefix()."c_coefprice as t LEFT JOIN ".$this->db->prefix()."c_commercial_category as cc ON cc.code = t.fk_nature WHERE t.fk_nature IS NOT NULL AND t.fk_nature <> '' AND cc.rowid IS NULL");
- $this->db->query("UPDATE ".$this->db->prefix()."c_coefprice SET code_commercial_category = fk_nature WHERE (code_commercial_category IS NULL OR code_commercial_category = '') AND fk_nature IS NOT NULL AND fk_nature <> ''");
+ $sql = "SHOW COLUMNS FROM ".$tableName." LIKE '".$this->db->escape($columnName)."'";
+ $resql = $this->db->query($sql);
- $resql = $this->db->query("SHOW COLUMNS FROM ".$this->db->prefix()."c_margin_on_cost LIKE 'code_commercial_category'");
- if ($resql && $this->db->num_rows($resql) == 0) {
- $this->db->query("ALTER TABLE ".$this->db->prefix()."c_margin_on_cost ADD COLUMN code_commercial_category VARCHAR(50) DEFAULT NULL");
- }
- $this->db->query("INSERT INTO ".$this->db->prefix()."c_commercial_category (code, label, active) SELECT DISTINCT t.code_nature, t.code_nature, 1 FROM ".$this->db->prefix()."c_margin_on_cost as t LEFT JOIN ".$this->db->prefix()."c_commercial_category as cc ON cc.code = t.code_nature WHERE t.code_nature IS NOT NULL AND t.code_nature <> '' AND cc.rowid IS NULL");
- $this->db->query("UPDATE ".$this->db->prefix()."c_margin_on_cost SET code_commercial_category = code_nature WHERE (code_commercial_category IS NULL OR code_commercial_category = '') AND code_nature IS NOT NULL AND code_nature <> ''");
+ return ($resql && $this->db->num_rows($resql) > 0);
}
-
- /**
- * Function called when module is disabled.
+
+ /**
+ * Function called when module is disabled.
* Remove from database constants, boxes and permissions from Dolibarr database.
* Data directories are not deleted
*
diff --git a/core/triggers/interface_99_modDynamicsPrices_DynamicsPricesTriggers.class.php b/core/triggers/interface_99_modDynamicsPrices_DynamicsPricesTriggers.class.php
index 784a017..d4247d1 100644
--- a/core/triggers/interface_99_modDynamicsPrices_DynamicsPricesTriggers.class.php
+++ b/core/triggers/interface_99_modDynamicsPrices_DynamicsPricesTriggers.class.php
@@ -81,7 +81,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
$productId = $this->resolveProductIdFromTriggerAction($db, $action, $object);
$product = new Product($db);
if ($productId > 0 && $product->fetch($productId) > 0) {
- if ((int) $product->type !== Product::TYPE_PRODUCT) {
+ if (!in_array((int) $product->type, array(Product::TYPE_PRODUCT, Product::TYPE_SERVICE), true)) {
return 0;
}
}
diff --git a/langs/de_DE/dynamicsprices.lang b/langs/de_DE/dynamicsprices.lang
index 788174f..13ae59c 100644
--- a/langs/de_DE/dynamicsprices.lang
+++ b/langs/de_DE/dynamicsprices.lang
@@ -27,7 +27,7 @@ LMDB_ErrorUpdate = Fehler bei der Aktualisierung:
LMDB_NbLinesUpdated = Anzahl der aktualisierten Verkaufspreise:
Fk_nature = Kommerzielle Kategorie
Fk_commercial_category = Kommerzielle Kategorie
-Code_commercial_category = Kommerzielle Kategorie
+Code_commercial_category = Code der kommerziellen Kategorie
Margin_on_cost_percent = Margensatz auf Selbstkostenpreis
Code_nature = Kommerzielle Kategorie
Pricelevel = Preisstufen-ID
@@ -75,3 +75,11 @@ LMDB_PriceDirectionUp = ERHÖHUNG
LMDB_PriceDirectionDown = SENKUNG
LMDB_PriceDirectionSame = UNVERÄNDERT
LMDB_AvailabilityId = Verfügbarkeits-ID
+
+
+LMDB_About = Über
+LMDB_AboutTitle = Über das Modul
+LMDB_AboutDescription = Allgemeine Informationen zum DynamicsPrices-Modul.
+
+LMDB_AboutGeneral = Allgemeine Informationen
+LMDB_AboutResources = Ressourcen
diff --git a/langs/en_US/dynamicsprices.lang b/langs/en_US/dynamicsprices.lang
index f18ddd4..f3f1cb4 100644
--- a/langs/en_US/dynamicsprices.lang
+++ b/langs/en_US/dynamicsprices.lang
@@ -27,7 +27,7 @@ LMDB_ErrorUpdate = Error while updating:
LMDB_NbLinesUpdated = Number of sales prices updated:
Fk_nature = Commercial category
Fk_commercial_category = Commercial category
-Code_commercial_category = Commercial category
+Code_commercial_category = Commercial category code
Margin_on_cost_percent = Margin rate on cost price
Code_nature = Commercial category
Pricelevel = Price level ID
@@ -75,3 +75,11 @@ LMDB_PriceDirectionUp = INCREASE
LMDB_PriceDirectionDown = DECREASE
LMDB_PriceDirectionSame = UNCHANGED
LMDB_AvailabilityId = Availability ID
+
+
+LMDB_About = About
+LMDB_AboutTitle = About module
+LMDB_AboutDescription = General information about DynamicsPrices module.
+
+LMDB_AboutGeneral = General information
+LMDB_AboutResources = Resources
diff --git a/langs/es_ES/dynamicsprices.lang b/langs/es_ES/dynamicsprices.lang
index 82ee391..38af6ee 100644
--- a/langs/es_ES/dynamicsprices.lang
+++ b/langs/es_ES/dynamicsprices.lang
@@ -27,7 +27,7 @@ LMDB_ErrorUpdate = Error al actualizar:
LMDB_NbLinesUpdated = Número de precios de venta actualizados:
Fk_nature = Categoría comercial
Fk_commercial_category = Categoría comercial
-Code_commercial_category = Categoría comercial
+Code_commercial_category = Código de la categoría comercial
Margin_on_cost_percent = Tasa de margen sobre el precio de coste
Code_nature = Categoría comercial
Pricelevel = Código del nivel de precios
@@ -75,3 +75,11 @@ LMDB_PriceDirectionUp = SUBIDA
LMDB_PriceDirectionDown = BAJADA
LMDB_PriceDirectionSame = SIN CAMBIOS
LMDB_AvailabilityId = ID disponibilidad
+
+
+LMDB_About = Acerca de
+LMDB_AboutTitle = Acerca del módulo
+LMDB_AboutDescription = Información general sobre el módulo DynamicsPrices.
+
+LMDB_AboutGeneral = Información general
+LMDB_AboutResources = Recursos
diff --git a/langs/fr_FR/dynamicsprices.lang b/langs/fr_FR/dynamicsprices.lang
index a494b98..aeae0a7 100644
--- a/langs/fr_FR/dynamicsprices.lang
+++ b/langs/fr_FR/dynamicsprices.lang
@@ -30,7 +30,7 @@ LMDB_ErrorUpdate = Erreur lors de la mise à jour :
LMDB_NbLinesUpdated = Nombre de prix de vente mis à jour :
Fk_nature = Catégorie commerciale
Fk_commercial_category = Catégorie commerciale
-Code_commercial_category = Catégorie commerciale
+Code_commercial_category = Code de la Catégorie Commerciale
Margin_on_cost_percent = Taux de marge sur le prix de revient
Code_nature = Catégorie commerciale
Pricelevel = ID du Niveau de prix
@@ -77,3 +77,11 @@ LMDB_PriceDirectionUp = HAUSSE
LMDB_PriceDirectionDown = BAISSE
LMDB_PriceDirectionSame = INCHANGÉ
LMDB_AvailabilityId = ID disponibilité
+
+
+LMDB_About = A propos
+LMDB_AboutTitle = A propos du module
+LMDB_AboutDescription = Informations generales sur le module DynamicsPrices.
+
+LMDB_AboutGeneral = Informations generales
+LMDB_AboutResources = Ressources
diff --git a/langs/it_IT/dynamicsprices.lang b/langs/it_IT/dynamicsprices.lang
index c7fac96..ba72872 100644
--- a/langs/it_IT/dynamicsprices.lang
+++ b/langs/it_IT/dynamicsprices.lang
@@ -27,7 +27,7 @@ LMDB_ErrorUpdate = Errore durante l'aggiornamento:
LMDB_NbLinesUpdated = Numero di prezzi di vendita aggiornati:
Fk_nature = Categoria commerciale
Fk_commercial_category = Categoria commerciale
-Code_commercial_category = Categoria commerciale
+Code_commercial_category = Codice della categoria commerciale
Margin_on_cost_percent = Aliquota di margine sul prezzo di costo
Code_nature = Categoria commerciale
Pricelevel = ID del livello di prezzo
@@ -75,3 +75,11 @@ LMDB_PriceDirectionUp = AUMENTO
LMDB_PriceDirectionDown = DIMINUZIONE
LMDB_PriceDirectionSame = INVARIATO
LMDB_AvailabilityId = ID disponibilità
+
+
+LMDB_About = Informazioni
+LMDB_AboutTitle = Informazioni sul modulo
+LMDB_AboutDescription = Informazioni generali sul modulo DynamicsPrices.
+
+LMDB_AboutGeneral = Informazioni generali
+LMDB_AboutResources = Risorse
diff --git a/lib/dynamicsprices.lib.php b/lib/dynamicsprices.lib.php
index c82a2f8..4eeb79b 100644
--- a/lib/dynamicsprices.lib.php
+++ b/lib/dynamicsprices.lib.php
@@ -63,12 +63,12 @@ function dynamicspricesAdminPrepareHead()
$head[$h][2] = 'myobject_extrafieldsline';
$h++;
*/
- /*
- $head[$h][0] = dol_buildpath("/dynamicsprices/admin/other.php", 1);
- $head[$h][1] = $langs->trans("About");
+ $head[$h][0] = dol_buildpath("/dynamicsprices/admin/about.php", 1);
+ $head[$h][1] = $langs->trans("LMDB_About");
$head[$h][2] = 'about';
$h++;
+ /*
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
//$this->tabs = array(
@@ -85,7 +85,6 @@ function dynamicspricesAdminPrepareHead()
return $head;
}
-
// Check if a product is a Kit using product associations
function dynamicsprices_is_kit($db, $productId)
{
@@ -410,30 +409,30 @@ function update_customer_prices_from_suppliers($db, $user, $langs, $conf, $produ
$entity = $conf->entity;
if ($productid > 0) {
- $product = new Product($db);
- if ($product->fetch($productid) > 0 && (int) $product->type !== Product::TYPE_PRODUCT) {
- return 0;
- }
- $products[] = $productid;
+ $product = new Product($db);
+ if ($product->fetch($productid) > 0 && !in_array((int) $product->type, array(Product::TYPE_PRODUCT, Product::TYPE_SERVICE), true)) {
+ return 0;
+ }
+ $products[] = $productid;
} else {
- $sql = "SELECT p.rowid, cc.code as code_commercial_category";
- $sql .= " FROM ".MAIN_DB_PREFIX."product";
- $sql .= " as p";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef ON ef.fk_object = p.rowid";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_commercial_category as cc ON (cc.rowid = ef.lmdb_commercial_category OR BINARY cc.code = BINARY ef.lmdb_commercial_category)";
- $sql .= " WHERE p.tosell = 1";
- $sql .= " AND p.fk_product_type = 0";
- $sql .= " AND p.entity IN (".getEntity('product').")";
-
- $resql = $db->query($sql);
- if ($resql === false) {
- dol_print_error($db);
- return 0;
- }
-
- while ($obj = $db->fetch_object($resql)) {
- $products[] = array('id' => $obj->rowid, 'commercial_category' => $obj->code_commercial_category);
- }
+ $sql = "SELECT p.rowid, cc.code as code_commercial_category";
+ $sql .= " FROM ".MAIN_DB_PREFIX."product";
+ $sql .= " as p";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef ON ef.fk_object = p.rowid";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_commercial_category as cc ON (cc.rowid = ef.lmdb_commercial_category OR BINARY cc.code = BINARY ef.lmdb_commercial_category)";
+ $sql .= " WHERE p.tosell = 1";
+ $sql .= " AND p.fk_product_type IN (0,1)";
+ $sql .= " AND p.entity IN (".getEntity('product').")";
+
+ $resql = $db->query($sql);
+ if ($resql === false) {
+ dol_print_error($db);
+ return 0;
+ }
+
+ while ($obj = $db->fetch_object($resql)) {
+ $products[] = array('id' => $obj->rowid, 'commercial_category' => $obj->code_commercial_category);
+ }
}
foreach ($products as $prod) {
@@ -441,8 +440,8 @@ function update_customer_prices_from_suppliers($db, $user, $langs, $conf, $produ
$commercialCategoryId = is_array($prod) ? ((int) $prod['commercial_category']) : dynamicsprices_get_product_commercial_category($db, $prodid);
$product = new Product($db);
$product->fetch($prodid);
- if ((int) $product->type !== Product::TYPE_PRODUCT) {
- continue;
+ if (!in_array((int) $product->type, array(Product::TYPE_PRODUCT, Product::TYPE_SERVICE), true)) {
+ continue;
}
$tva_tx = (float) $product->tva_tx;
@@ -504,30 +503,30 @@ function update_customer_prices_from_cost_price($db, $user, $langs, $conf, $prod
$entity = $conf->entity;
if ($productid > 0) {
- $product = new Product($db);
- if ($product->fetch($productid) > 0 && (int) $product->type !== Product::TYPE_PRODUCT) {
- return 0;
- }
- $products[] = $productid;
+ $product = new Product($db);
+ if ($product->fetch($productid) > 0 && !in_array((int) $product->type, array(Product::TYPE_PRODUCT, Product::TYPE_SERVICE), true)) {
+ return 0;
+ }
+ $products[] = $productid;
} else {
- $sql = "SELECT p.rowid, p.cost_price, cc.code as code_commercial_category";
- $sql .= " FROM ".MAIN_DB_PREFIX."product";
- $sql .= " as p";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef ON ef.fk_object = p.rowid";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_commercial_category as cc ON (cc.rowid = ef.lmdb_commercial_category OR BINARY cc.code = BINARY ef.lmdb_commercial_category)";
- $sql .= " WHERE p.tosell = 1";
- $sql .= " AND p.fk_product_type = 0";
- $sql .= " AND p.entity IN (".getEntity('product').")";
-
- $resql = $db->query($sql);
- if ($resql === false) {
- dol_print_error($db);
- return 0;
- }
-
- while ($obj = $db->fetch_object($resql)) {
- $products[] = array('id' => $obj->rowid, 'commercial_category' => $obj->code_commercial_category, 'cost_price' => $obj->cost_price);
- }
+ $sql = "SELECT p.rowid, p.cost_price, cc.code as code_commercial_category";
+ $sql .= " FROM ".MAIN_DB_PREFIX."product";
+ $sql .= " as p";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef ON ef.fk_object = p.rowid";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_commercial_category as cc ON (cc.rowid = ef.lmdb_commercial_category OR BINARY cc.code = BINARY ef.lmdb_commercial_category)";
+ $sql .= " WHERE p.tosell = 1";
+ $sql .= " AND p.fk_product_type IN (0,1)";
+ $sql .= " AND p.entity IN (".getEntity('product').")";
+
+ $resql = $db->query($sql);
+ if ($resql === false) {
+ dol_print_error($db);
+ return 0;
+ }
+
+ while ($obj = $db->fetch_object($resql)) {
+ $products[] = array('id' => $obj->rowid, 'commercial_category' => $obj->code_commercial_category, 'cost_price' => $obj->cost_price);
+ }
}
foreach ($products as $prod) {
@@ -536,8 +535,8 @@ function update_customer_prices_from_cost_price($db, $user, $langs, $conf, $prod
$currentCost = is_array($prod) ? $prod['cost_price'] : 0;
$product = new Product($db);
$product->fetch($prodid);
- if ((int) $product->type !== Product::TYPE_PRODUCT) {
- continue;
+ if (!in_array((int) $product->type, array(Product::TYPE_PRODUCT, Product::TYPE_SERVICE), true)) {
+ continue;
}
$tva_tx = (float) $product->tva_tx;
diff --git a/sql/dolibarr_allversions.sql b/sql/dolibarr_allversions.sql
index 7153bbb..3f8dd1b 100644
--- a/sql/dolibarr_allversions.sql
+++ b/sql/dolibarr_allversions.sql
@@ -26,6 +26,7 @@ CREATE TABLE IF NOT EXISTS `llx_c_margin_on_cost`(
CREATE TABLE IF NOT EXISTS `llx_c_commercial_category`(
`rowid`INTEGER AUTO_INCREMENT PRIMARY KEY NOT NULL,
+`entity`INTEGER NOT NULL DEFAULT '1',
`code`VARCHAR(50) NOT NULL,
`label`VARCHAR(255) NOT NULL,
`active`TINYINT NOT NULL DEFAULT '1'
@@ -33,6 +34,7 @@ CREATE TABLE IF NOT EXISTS `llx_c_commercial_category`(
ALTER TABLE `llx_c_coefprice` ADD COLUMN `code_commercial_category` VARCHAR(50) DEFAULT NULL;
ALTER TABLE `llx_c_margin_on_cost` ADD COLUMN `code_commercial_category` VARCHAR(50) DEFAULT NULL;
+ALTER TABLE `llx_c_commercial_category` ADD COLUMN `entity` INTEGER NOT NULL DEFAULT 1;
UPDATE `llx_c_coefprice` as t
LEFT JOIN `llx_c_commercial_category` as cc ON cc.code = t.fk_nature
@@ -44,14 +46,14 @@ LEFT JOIN `llx_c_commercial_category` as cc ON cc.code = t.code_nature
SET t.`code_commercial_category` = t.code_nature
WHERE (t.`code_commercial_category` IS NULL OR t.`code_commercial_category` = '') AND t.`code_nature` IS NOT NULL AND t.`code_nature` <> '';
-INSERT INTO `llx_c_commercial_category` (`code`, `label`, `active`)
-SELECT DISTINCT t.fk_nature, t.fk_nature, 1
+INSERT INTO `llx_c_commercial_category` (`entity`, `code`, `label`, `active`)
+SELECT DISTINCT 1, t.fk_nature, t.fk_nature, 1
FROM `llx_c_coefprice` as t
LEFT JOIN `llx_c_commercial_category` as cc ON cc.code = t.fk_nature
WHERE t.fk_nature IS NOT NULL AND t.fk_nature <> '' AND cc.rowid IS NULL;
-INSERT INTO `llx_c_commercial_category` (`code`, `label`, `active`)
-SELECT DISTINCT t.code_nature, t.code_nature, 1
+INSERT INTO `llx_c_commercial_category` (`entity`, `code`, `label`, `active`)
+SELECT DISTINCT 1, t.code_nature, t.code_nature, 1
FROM `llx_c_margin_on_cost` as t
LEFT JOIN `llx_c_commercial_category` as cc ON cc.code = t.code_nature
WHERE t.code_nature IS NOT NULL AND t.code_nature <> '' AND cc.rowid IS NULL;
diff --git a/sql/llx_c_commercial_category.sql b/sql/llx_c_commercial_category.sql
index 2d62538..463e58a 100644
--- a/sql/llx_c_commercial_category.sql
+++ b/sql/llx_c_commercial_category.sql
@@ -1,5 +1,6 @@
CREATE TABLE IF NOT EXISTS `llx_c_commercial_category`(
`rowid`INTEGER AUTO_INCREMENT PRIMARY KEY NOT NULL,
+`entity`INTEGER NOT NULL DEFAULT '1',
`code`VARCHAR(50) NOT NULL,
`label`VARCHAR(255) NOT NULL,
`active`TINYINT NOT NULL DEFAULT '1'