dolibarr.metallzuschlag/core/modules/modMetallzuschlag.class.php
data 2e2cb5b710 fix: Kupferzuschlag mit Mindestmenge berechnen und auf 2 Stellen runden
- Formel: Kupfergehalt × CU-Notiz / 100.000 × Mindestmenge
- Ergebnis auf 2 Nachkommastellen gerundet
- Cronjob und Trigger angepasst
- Dokumentation aktualisiert
- Version auf 1.2 erhöht

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-24 09:25:05 +01:00

335 lines
8.7 KiB
PHP
Executable file

<?php
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
*
* 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/>.
*/
/**
* \defgroup metallzuschlag Module Metallzuschlag
* \brief Metallnotierungen (Kupfer/Aluminium) von Großhändlern abrufen und verwalten
*
* \file htdocs/metallzuschlag/core/modules/modMetallzuschlag.class.php
* \ingroup metallzuschlag
*/
include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
/**
* Modul-Deskriptor fuer Metallzuschlag
*/
class modMetallzuschlag extends DolibarrModules
{
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
global $conf, $langs;
$this->db = $db;
$this->numero = 500027;
$this->rights_class = 'metallzuschlag';
$this->family = "products";
$this->module_position = '90';
$this->name = preg_replace('/^mod/i', '', get_class($this));
$this->description = "MetallzuschlagDescription";
$this->descriptionlong = "MetallzuschlagDescriptionLong";
$this->editor_name = 'Alles Watt laeuft';
$this->editor_url = '';
$this->version = '1.2';
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
$this->picto = 'fa-coins';
$this->module_parts = array(
'triggers' => 1,
'login' => 0,
'substitutions' => 0,
'menus' => 0,
'tpl' => 0,
'barcode' => 0,
'models' => 0,
'printing' => 0,
'theme' => 0,
'css' => array(),
'js' => array(),
'hooks' => array(),
'moduleforexternal' => 0,
'websitetemplates' => 0,
'captcha' => 0
);
$this->dirs = array("/metallzuschlag/temp");
$this->config_page_url = array("setup.php@metallzuschlag");
// Abhaengigkeiten
$this->hidden = getDolGlobalInt('MODULE_METALLZUSCHLAG_DISABLED');
$this->depends = array();
$this->requiredby = array();
$this->conflictwith = array();
$this->langfiles = array("metallzuschlag@metallzuschlag");
$this->phpmin = array(7, 1);
$this->need_dolibarr_version = array(19, -3);
$this->need_javascript_ajax = 0;
$this->warnings_activation = array();
$this->warnings_activation_ext = array();
// Konstanten
$this->const = array(
0 => array('METALLZUSCHLAG_API_URL', 'chaine', 'https://www.sonepar.de/api/content/metalnote', 'Basis-URL fuer Metallnotiz-API', 1),
1 => array('METALLZUSCHLAG_AUTO_FETCH', 'chaine', '1', 'Automatischer Abruf aktiviert', 1),
);
if (!isModEnabled("metallzuschlag")) {
$conf->metallzuschlag = new stdClass();
$conf->metallzuschlag->enabled = 0;
}
// Tabs
$this->tabs = array();
// Dictionaries
$this->dictionaries = array();
// Widgets
$this->boxes = array();
// Cronjobs
$this->cronjobs = array(
// Metallnotierungen woechentlich abrufen
0 => array(
'label' => 'MetallzuschlagFetch',
'jobtype' => 'method',
'class' => '/metallzuschlag/class/metallzuschlagapi.class.php',
'objectname' => 'MetallzuschlagApi',
'method' => 'fetchMetalNotes',
'parameters' => '',
'comment' => 'Metallnotierungen (CU/AL) von Sonepar abrufen und in DB speichern',
'frequency' => 1,
'unitfrequency' => 604800,
'status' => 0,
'test' => 'isModEnabled("metallzuschlag") && getDolGlobalInt("METALLZUSCHLAG_AUTO_FETCH")',
'priority' => 50,
),
// Kupferzuschlag auf allen Einkaufspreisen woechentlich neu berechnen
1 => array(
'label' => 'MetallzuschlagRecalcKupferzuschlag',
'jobtype' => 'method',
'class' => '/metallzuschlag/class/metallzuschlagapi.class.php',
'objectname' => 'MetallzuschlagApi',
'method' => 'recalcAllKupferzuschlag',
'parameters' => '',
'comment' => 'Kupferzuschlag (EUR/m) auf allen Einkaufspreisen mit Kupfergehalt neu berechnen',
'frequency' => 1,
'unitfrequency' => 604800,
'status' => 0,
'test' => 'isModEnabled("metallzuschlag")',
'priority' => 60,
),
);
// Berechtigungen
$this->rights = array();
$r = 0;
$this->rights[$r][0] = $this->numero.'01';
$this->rights[$r][1] = 'MetallzuschlagPermRead';
$this->rights[$r][4] = 'read';
$this->rights[$r][5] = '';
$r++;
$this->rights[$r][0] = $this->numero.'02';
$this->rights[$r][1] = 'MetallzuschlagPermConfig';
$this->rights[$r][4] = 'config';
$this->rights[$r][5] = '';
$r++;
// Hauptmenue
$this->menu = array();
$r = 0;
$this->menu[$r++] = array(
'fk_menu' => '',
'type' => 'top',
'titre' => 'ModuleMetallzuschlagName',
'prefix' => img_picto('', $this->picto, 'class="pictofixedwidth valignmiddle"'),
'mainmenu' => 'metallzuschlag',
'leftmenu' => '',
'url' => '/metallzuschlag/metallzuschlagindex.php',
'langs' => 'metallzuschlag@metallzuschlag',
'position' => 1000 + $r,
'enabled' => 'isModEnabled("metallzuschlag")',
'perms' => '$user->hasRight("metallzuschlag", "read")',
'target' => '',
'user' => 2,
);
}
/**
* Modul aktivieren: Tabellen + Extrafields erstellen
*
* @param string $options Optionen
* @return int 1 wenn OK, -1 bei Fehler
*/
public function init($options = '')
{
global $conf, $langs;
$result = $this->_load_tables('/metallzuschlag/sql/');
if ($result < 0) {
return -1;
}
// Extrafields auf Lieferantenkarte (thirdparty) erstellen
include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
// Separator
$extrafields->addExtraField(
'metallzuschlag_sep',
'MetallzuschlagSeparator',
'separator',
200, 0,
'thirdparty',
0, 0, '', array('options' => array(1 => 1)),
1, '', 1, 0, '', '',
'metallzuschlag@metallzuschlag',
'isModEnabled("metallzuschlag")'
);
// Kupferzuschlag
// Signatur: $attrname, $label, $type, $pos, $size, $elementtype,
// $unique, $required, $default_value, $param,
// $alwayseditable, $perms, $list, $help, $computed, $entity, $langfile, $enabled
$extrafields->addExtraField(
'metallzuschlag_cu',
'MetallzuschlagCU',
'price',
201, '24,8',
'thirdparty',
0, 0, '', '',
1, '', 1, 'MetallzuschlagCUHelp',
'', '',
'metallzuschlag@metallzuschlag',
'isModEnabled("metallzuschlag")'
);
// Aluminiumzuschlag
$extrafields->addExtraField(
'metallzuschlag_al',
'MetallzuschlagAL',
'price',
202, '24,8',
'thirdparty',
0, 0, '', '',
1, '', 1, 'MetallzuschlagALHelp',
'', '',
'metallzuschlag@metallzuschlag',
'isModEnabled("metallzuschlag")'
);
// Datum der letzten Aktualisierung
$extrafields->addExtraField(
'metallzuschlag_date',
'MetallzuschlagDate',
'date',
203, 0,
'thirdparty',
0, 0, '', '',
1, '', 1, '',
'', '',
'metallzuschlag@metallzuschlag',
'isModEnabled("metallzuschlag")'
);
// Quelle
$extrafields->addExtraField(
'metallzuschlag_source',
'MetallzuschlagSource',
'select',
204, 0,
'thirdparty',
0, 0, '',
array('options' => array('sonepar' => 'Sonepar', 'kluxen' => 'Kluxen', 'manuell' => 'Manuell')),
1, '', 1, '',
'', '',
'metallzuschlag@metallzuschlag',
'isModEnabled("metallzuschlag")'
);
// Extrafields auf Produkten fuer Kupferberechnung
// Aderanzahl
$extrafields->addExtraField(
'aderanzahl',
'Aderanzahl',
'int',
126, 11,
'product',
0, 0, '', '',
1, '', 1, 'AderanzahlHelp',
'', '',
'metallzuschlag@metallzuschlag',
'isModEnabled("metallzuschlag")'
);
// Querschnitt (mm²)
$extrafields->addExtraField(
'querschnitt',
'Querschnitt',
'double',
127, '10,2',
'product',
0, 0, '', '',
1, '', 1, 'QuerschnittHelp',
'', '',
'metallzuschlag@metallzuschlag',
'isModEnabled("metallzuschlag")'
);
// Kupfergehalt (kg/km) - wird per Trigger berechnet
$extrafields->addExtraField(
'kupfergehalt',
'Kupfergehalt',
'double',
128, '24,8',
'product',
0, 0, '', '',
1, '', 1, 'KupfergehaltHelp',
'', '',
'metallzuschlag@metallzuschlag',
'isModEnabled("metallzuschlag")'
);
$this->remove($options);
$sql = array();
return $this->_init($sql, $options);
}
/**
* Modul deaktivieren
*
* @param string $options Optionen
* @return int 1 wenn OK, -1 bei Fehler
*/
public function remove($options = '')
{
$sql = array();
return $this->_remove($sql, $options);
}
}