Kritische Bugfixes: - FIX: Produktmatching korrigiert (qty→quantity, status→tosell in SQL) Vorher wurden alle Artikel als Freitext importiert, jetzt korrekte Verknüpfung mit Dolibarr-Produkten über product_fournisseur_price Neue Features: - FEAT: Sonepar NetPrice-Heuristik implementiert Erkennt automatisch ob NetPrice für PriceBasis (IDS-Standard) oder Order-Qty (Sonepar-Variante) ist. 2-Pass-Algorithmus vergleicht beide Interpretationen mit DB-Preis und wählt korrekte aus. Löst +100% Preisabweichungs-Problem bei Sonepar-Warenkörben. - FEAT: Preis-Vergleich in cart_review.php und tab_supplierorder.php Zeigt Abweichungen zwischen Shop-Preisen und gespeicherten Dolibarr-Preisen mit farbiger Markierung (rot >10%, gelb 2-10%, grün ≤2%) Manuelle Preis-Aktualisierung über Checkboxen (keine Automatik) - Admin-Option IDSCONNECT_PRICE_UPDATE_ENABLED mit konfigurierbarem Schwellwert - Übersetzungen für de_DE und en_US erweitert Dateien: - class/idsconnect.class.php: matchProducts() qty→quantity Fix - cart_review.php: Heuristik + Preis-Vergleich UI - tab_supplierorder.php: Preis-Vergleich für Bestellungen - admin/setup.php: Neue Preis-Update-Optionen - CHANGELOG.md: Dokumentation v2.9 und v3.1 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
310 lines
12 KiB
PHP
Executable file
310 lines
12 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.
|
|
*/
|
|
|
|
/**
|
|
* \file idsconnect/admin/setup.php
|
|
* \ingroup idsconnect
|
|
* \brief IDS Connect Konfigurationsseite
|
|
*/
|
|
|
|
// Dolibarr laden
|
|
$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/idsconnect.lib.php';
|
|
|
|
/**
|
|
* @var Conf $conf
|
|
* @var DoliDB $db
|
|
* @var HookManager $hookmanager
|
|
* @var Translate $langs
|
|
* @var User $user
|
|
*/
|
|
|
|
$langs->loadLangs(array("admin", "idsconnect@idsconnect"));
|
|
|
|
// Zugriffskontrolle
|
|
if (!$user->admin) {
|
|
accessforbidden();
|
|
}
|
|
|
|
$action = GETPOST('action', 'aZ09');
|
|
$backtopage = GETPOST('backtopage', 'alpha');
|
|
|
|
$error = 0;
|
|
|
|
|
|
/*
|
|
* Actions
|
|
*/
|
|
|
|
if ($action == 'update' && $user->admin) {
|
|
// CSRF-Schutz
|
|
if (!verifCond(GETPOST('token', 'alpha') == newToken())) {
|
|
accessforbidden('Bad CSRF token');
|
|
}
|
|
|
|
// Öffentliche URL
|
|
dolibarr_set_const($db, 'IDSCONNECT_PUBLIC_URL', trim(GETPOST('IDSCONNECT_PUBLIC_URL', 'alphanohtml')), 'chaine', 0, '', $conf->entity);
|
|
// Testmodus
|
|
dolibarr_set_const($db, 'IDSCONNECT_TESTMODE', GETPOSTINT('IDSCONNECT_TESTMODE'), 'chaine', 0, '', $conf->entity);
|
|
// Logging
|
|
dolibarr_set_const($db, 'IDSCONNECT_LOG_ENABLED', GETPOSTINT('IDSCONNECT_LOG_ENABLED'), 'chaine', 0, '', $conf->entity);
|
|
// WKS-Warnschwellen
|
|
dolibarr_set_const($db, 'IDSCONNECT_WKS_WARN_QTY', GETPOSTINT('IDSCONNECT_WKS_WARN_QTY'), 'chaine', 0, '', $conf->entity);
|
|
dolibarr_set_const($db, 'IDSCONNECT_WKS_WARN_VALUE', GETPOST('IDSCONNECT_WKS_WARN_VALUE', 'alphanohtml'), 'chaine', 0, '', $conf->entity);
|
|
// WKS-PIN (nur speichern wenn neue eingegeben)
|
|
$new_pin = GETPOST('IDSCONNECT_WKS_PIN', 'none');
|
|
if (!empty($new_pin)) {
|
|
$pin_hash = password_hash($new_pin, PASSWORD_DEFAULT);
|
|
dolibarr_set_const($db, 'IDSCONNECT_WKS_PIN', $pin_hash, 'chaine', 0, '', $conf->entity);
|
|
}
|
|
// Preis-Update (manuell)
|
|
dolibarr_set_const($db, 'IDSCONNECT_PRICE_UPDATE_ENABLED', GETPOSTINT('IDSCONNECT_PRICE_UPDATE_ENABLED'), 'chaine', 0, '', $conf->entity);
|
|
dolibarr_set_const($db, 'IDSCONNECT_PRICE_UPDATE_THRESHOLD', GETPOST('IDSCONNECT_PRICE_UPDATE_THRESHOLD', 'alphanohtml'), 'chaine', 0, '', $conf->entity);
|
|
|
|
if (!$error) {
|
|
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
|
|
}
|
|
|
|
$action = 'edit';
|
|
}
|
|
|
|
|
|
/*
|
|
* View
|
|
*/
|
|
|
|
$form = new Form($db);
|
|
$title = "IdsconnectSetup";
|
|
|
|
llxHeader('', $langs->trans($title), '', '', 0, 0, '', '', '', 'mod-idsconnect page-admin');
|
|
|
|
$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
|
|
print load_fiche_titre($langs->trans($title), $linkback, 'title_setup');
|
|
|
|
$head = idsconnectAdminPrepareHead();
|
|
print dol_get_fiche_head($head, 'settings', $langs->trans($title), -1, "fa-plug");
|
|
|
|
print '<span class="opacitymedium">'.$langs->trans("IdsconnectSetupPage").'</span><br><br>';
|
|
|
|
|
|
// Formular
|
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
|
print '<input type="hidden" name="action" value="update">';
|
|
|
|
print '<table class="noborder centpercent">';
|
|
|
|
// Überschrift: Allgemein
|
|
print '<tr class="liste_titre">';
|
|
print '<td colspan="2">'.$langs->trans("IdsconnectGeneralSettings").'</td>';
|
|
print '</tr>';
|
|
|
|
// Öffentliche URL (für HOOKURL bei Reverse-Proxy)
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("IdsconnectPublicUrl").'</td>';
|
|
print '<td>';
|
|
print '<input type="text" name="IDSCONNECT_PUBLIC_URL" class="minwidth500" value="'.htmlspecialchars(getDolGlobalString('IDSCONNECT_PUBLIC_URL')).'" placeholder="https://awl.data-it-solution.de">';
|
|
print '<br><span class="opacitymedium">'.$langs->trans("IdsconnectPublicUrlHelp").'</span>';
|
|
print '</td></tr>';
|
|
|
|
// Testmodus
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("IdsconnectTestMode").'</td>';
|
|
print '<td>';
|
|
print $form->selectyesno('IDSCONNECT_TESTMODE', getDolGlobalInt('IDSCONNECT_TESTMODE', 1), 1);
|
|
print ' <span class="opacitymedium">'.$langs->trans("IdsconnectTestModeHelp").'</span>';
|
|
print '</td></tr>';
|
|
|
|
// Logging
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("IdsconnectLogEnabled").'</td>';
|
|
print '<td>';
|
|
print $form->selectyesno('IDSCONNECT_LOG_ENABLED', getDolGlobalInt('IDSCONNECT_LOG_ENABLED', 1), 1);
|
|
print '</td></tr>';
|
|
|
|
// Überschrift: Preis-Verwaltung
|
|
print '<tr class="liste_titre">';
|
|
print '<td colspan="2">'.$langs->trans("IdsconnectPriceManagement").'</td>';
|
|
print '</tr>';
|
|
|
|
// Preis-Update aktivieren
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("IdsconnectPriceUpdateEnabled").'</td>';
|
|
print '<td>';
|
|
print $form->selectyesno('IDSCONNECT_PRICE_UPDATE_ENABLED', getDolGlobalInt('IDSCONNECT_PRICE_UPDATE_ENABLED', 0), 1);
|
|
print ' <span class="opacitymedium">'.$langs->trans("IdsconnectPriceUpdateEnabledHelp").'</span>';
|
|
print '</td></tr>';
|
|
|
|
// Preis-Update Schwellwert
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("IdsconnectPriceUpdateThreshold").'</td>';
|
|
print '<td>';
|
|
print '<input type="number" name="IDSCONNECT_PRICE_UPDATE_THRESHOLD" value="'.getDolGlobalString('IDSCONNECT_PRICE_UPDATE_THRESHOLD', '5').'" min="0" max="100" step="0.1" class="width100">';
|
|
print ' % <span class="opacitymedium">'.$langs->trans("IdsconnectPriceUpdateThresholdHelp").'</span>';
|
|
print '</td></tr>';
|
|
|
|
// Überschrift: WKS-Sicherheit
|
|
print '<tr class="liste_titre">';
|
|
print '<td colspan="2">'.$langs->trans("IdsconnectWksSecuritySettings").'</td>';
|
|
print '</tr>';
|
|
|
|
// Mengen-Warnschwelle
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("IdsconnectWksWarnQty").'</td>';
|
|
print '<td>';
|
|
print '<input type="number" name="IDSCONNECT_WKS_WARN_QTY" value="'.getDolGlobalInt('IDSCONNECT_WKS_WARN_QTY', 100).'" min="0" class="width100">';
|
|
print ' <span class="opacitymedium">'.$langs->trans("IdsconnectWksWarnQtyHelp").'</span>';
|
|
print '</td></tr>';
|
|
|
|
// Wert-Warnschwelle
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("IdsconnectWksWarnValueLabel").'</td>';
|
|
print '<td>';
|
|
print '<input type="number" name="IDSCONNECT_WKS_WARN_VALUE" value="'.getDolGlobalString('IDSCONNECT_WKS_WARN_VALUE', '10000').'" min="0" step="100" class="width100">';
|
|
print ' € <span class="opacitymedium">'.$langs->trans("IdsconnectWksWarnValueHelp").'</span>';
|
|
print '</td></tr>';
|
|
|
|
// WKS-PIN
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("IdsconnectWksPinLabel").'</td>';
|
|
print '<td>';
|
|
print '<input type="password" name="IDSCONNECT_WKS_PIN" value="" class="width100" autocomplete="new-password" placeholder="'.$langs->trans("IdsconnectWksPinPlaceholder").'">';
|
|
$has_pin = !empty(getDolGlobalString('IDSCONNECT_WKS_PIN'));
|
|
if ($has_pin) {
|
|
print ' <span class="badge badge-status4">'.$langs->trans("IdsconnectWksPinSet").'</span>';
|
|
} else {
|
|
print ' <span class="badge badge-status8">'.$langs->trans("IdsconnectWksPinNotSet").'</span>';
|
|
}
|
|
print ' <span class="opacitymedium">'.$langs->trans("IdsconnectWksPinHelp").'</span>';
|
|
print '</td></tr>';
|
|
|
|
// Callback-URL anzeigen (nur lesen, berechnet aus öffentlicher URL)
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("IdsconnectCallbackUrl").'</td>';
|
|
print '<td>';
|
|
global $dolibarr_main_url_root;
|
|
$public_url = getDolGlobalString('IDSCONNECT_PUBLIC_URL');
|
|
$url_base = !empty($public_url) ? rtrim($public_url, '/') : $dolibarr_main_url_root;
|
|
$callback_url = $url_base.'/custom/idsconnect/callback.php';
|
|
print '<input type="text" class="minwidth500" value="'.htmlspecialchars($callback_url).'" readonly onclick="this.select()">';
|
|
if (empty($public_url)) {
|
|
print ' <span class="badge badge-warning">Intern - '.$langs->trans("IdsconnectPublicUrlMissing").'</span>';
|
|
}
|
|
print '<br><span class="opacitymedium">'.$langs->trans("IdsconnectCallbackUrlHelp").'</span>';
|
|
print '</td></tr>';
|
|
|
|
// Mock-Server URL anzeigen (nur lesen, immer intern)
|
|
print '<tr class="oddeven">';
|
|
print '<td>'.$langs->trans("IdsconnectMockServerUrl").'</td>';
|
|
print '<td>';
|
|
$mock_url = $dolibarr_main_url_root.'/custom/idsconnect/mockserver.php';
|
|
print '<input type="text" class="minwidth500" value="'.htmlspecialchars($mock_url).'" readonly onclick="this.select()">';
|
|
print ' <span class="opacitymedium">'.$langs->trans("IdsconnectMockServerHelp").'</span>';
|
|
print '</td></tr>';
|
|
|
|
print '</table>';
|
|
|
|
print '<div class="center">';
|
|
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
|
|
print '</div>';
|
|
|
|
print '</form>';
|
|
|
|
|
|
// Sicherheitsinfo
|
|
print '<br>';
|
|
print '<div class="info">';
|
|
print '<strong>'.$langs->trans("IdsconnectSecurityInfo").'</strong><br>';
|
|
print $langs->trans("IdsconnectSecurityInfoText");
|
|
print '</div>';
|
|
|
|
|
|
// ============================================================
|
|
// Großhändler-Schnellübersicht mit Versionscheck
|
|
// ============================================================
|
|
dol_include_once('/idsconnect/class/idssupplier.class.php');
|
|
$supplierObj = new IdsSupplier($db);
|
|
$allSuppliers = $supplierObj->fetchAll(0);
|
|
|
|
if (is_array($allSuppliers) && count($allSuppliers) > 0) {
|
|
print '<br>';
|
|
print '<table class="noborder centpercent">';
|
|
print '<tr class="liste_titre">';
|
|
print '<th>'.$langs->trans("IdsconnectSuppliers").'</th>';
|
|
print '<th>'.$langs->trans("IdsconnectSupplierUrl").'</th>';
|
|
print '<th>'.$langs->trans("IdsconnectSupplierVersion").'</th>';
|
|
print '<th>'.$langs->trans("Status").'</th>';
|
|
print '<th class="right">'.$langs->trans("Action").'</th>';
|
|
print '</tr>';
|
|
|
|
foreach ($allSuppliers as $sup) {
|
|
print '<tr class="oddeven">';
|
|
print '<td>';
|
|
print '<a href="'.DOL_URL_ROOT.'/custom/idsconnect/supplier_card.php?id='.$sup->id.'">';
|
|
print '<strong>'.htmlspecialchars($sup->label).'</strong>';
|
|
print '</a>';
|
|
print ' <span class="opacitymedium">('.htmlspecialchars($sup->ref).')</span>';
|
|
print '</td>';
|
|
print '<td class="tdoverflowmax300">'.htmlspecialchars($sup->ids_url).'</td>';
|
|
print '<td>'.htmlspecialchars($sup->ids_version).'</td>';
|
|
print '<td>';
|
|
if ($sup->active) {
|
|
print '<span class="badge badge-status4">'.$langs->trans("Enabled").'</span>';
|
|
} else {
|
|
print '<span class="badge badge-status8">'.$langs->trans("Disabled").'</span>';
|
|
}
|
|
if ($sup->testmode) {
|
|
print ' <span class="badge badge-warning">Test</span>';
|
|
}
|
|
print '</td>';
|
|
print '<td class="right nowrap">';
|
|
if ($sup->active) {
|
|
print '<a class="butAction butActionSmall" href="'.DOL_URL_ROOT.'/custom/idsconnect/launch.php?supplier_id='.$sup->id.'&ids_action=SV&token='.newToken().'" target="_blank">';
|
|
print $langs->trans("IdsconnectCheckVersion");
|
|
print '</a>';
|
|
}
|
|
print '</td>';
|
|
print '</tr>';
|
|
}
|
|
print '</table>';
|
|
}
|
|
|
|
|
|
print dol_get_fiche_end();
|
|
|
|
llxFooter();
|
|
$db->close();
|