Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions admin/about.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/* Copyright (C) 2026 Pierre Ardoin <developpeur@lesmetiersdubatiment.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 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 = '<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 = dynamicspricesAdminPrepareHead();
print dol_get_fiche_head($head, 'about', $title, -1, "dynamicsprices@dynamicsprices");

print '<div class="opacitymedium">'.$langs->trans('LMDB_AboutDescription').'</div>';
print '<br>';
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans('LMDB_AboutGeneral').'</td></tr>';
print '<tr class="oddeven"><td class="titlefield">'.$langs->trans('Module').'</td><td>'.$langs->trans('ModuleDynamicsPricesName').'</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans('Description').'</td><td>'.dol_escape_htmltag($langs->trans($moduleDescriptor->description)).'</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans('Version').'</td><td>'.dol_escape_htmltag((string) $moduleDescriptor->version).'</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans('Author').'</td><td>'.dol_escape_htmltag((string) $moduleDescriptor->editor_name).'</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans('Website').'</td><td><a href="https://'.dol_escape_htmltag((string) $moduleDescriptor->editor_url).'" target="_blank" rel="noopener noreferrer">'.dol_escape_htmltag((string) $moduleDescriptor->editor_url).'</a></td></tr>';
print '</table>';
print '</div>';
print '<br>';
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans('LMDB_AboutResources').'</td></tr>';
print '<tr class="oddeven"><td class="titlefield">'.$langs->trans('Documentation').'</td><td><a href="https://wiki.dolibarr.org/" target="_blank" rel="noopener noreferrer">wiki.dolibarr.org</a></td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans('Support').'</td><td><a href="https://'.dol_escape_htmltag((string) $moduleDescriptor->editor_url).'" target="_blank" rel="noopener noreferrer">'.dol_escape_htmltag((string) $moduleDescriptor->editor_url).'</a></td></tr>';
print '</table>';
print '</div>';

print dol_get_fiche_end();
llxFooter();
$db->close();
16 changes: 0 additions & 16 deletions admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
52 changes: 24 additions & 28 deletions core/modules/modDynamicsPrices.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,20 @@ 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"),
'tablib' => array("LMDB_coefprice", "LMDB_marginoncost", "LMDB_commercialcategories"),
'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",
Expand All @@ -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(
Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand Down Expand Up @@ -578,9 +581,9 @@ public function init($options = '')
return -1;
}
}
// Permissions
$this->remove($options);

// Permissions
$this->remove($options);

$sql = array();

Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
10 changes: 9 additions & 1 deletion langs/de_DE/dynamicsprices.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 9 additions & 1 deletion langs/en_US/dynamicsprices.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 9 additions & 1 deletion langs/es_ES/dynamicsprices.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 9 additions & 1 deletion langs/fr_FR/dynamicsprices.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
10 changes: 9 additions & 1 deletion langs/it_IT/dynamicsprices.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading
Loading