* * 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 mahnung/admin/setup.php * \ingroup mahnung * \brief Setup: Mahnstufen, Basiszins, B2C/B2B-Aufschlaege, Pauschale, Ntfy-Topic. */ $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 DOL_DOCUMENT_ROOT.'/custom/mahnung/class/mahnung.class.php'; require_once DOL_DOCUMENT_ROOT.'/custom/mahnung/class/mahnungstufe.class.php'; global $langs, $user, $conf, $db; $langs->loadLangs(array('admin', 'mahnung@mahnung')); if (!$user->admin && !$user->hasRight('mahnung', 'setup')) { accessforbidden(); } $action = GETPOST('action', 'aZ09'); // --------------------------------------------------------------- // POST: Allgemeine Konstanten speichern // --------------------------------------------------------------- if ($action === 'save_consts' && $user->hasRight('mahnung', 'setup')) { $basis = str_replace(',', '.', GETPOST('MAHNUNG_BASISZINS', 'alphanohtml')); $b2c = str_replace(',', '.', GETPOST('MAHNUNG_AUFSCHLAG_B2C', 'alphanohtml')); $b2b = str_replace(',', '.', GETPOST('MAHNUNG_AUFSCHLAG_B2B', 'alphanohtml')); $pau = str_replace(',', '.', GETPOST('MAHNUNG_PAUSCHALE_B2B', 'alphanohtml')); $topic = GETPOST('MAHNUNG_NTFY_TOPIC', 'alphanohtml'); dolibarr_set_const($db, 'MAHNUNG_BASISZINS', (string) (float) $basis, 'chaine', 0, '', 0); dolibarr_set_const($db, 'MAHNUNG_AUFSCHLAG_B2C', (string) (float) $b2c, 'chaine', 0, '', 0); dolibarr_set_const($db, 'MAHNUNG_AUFSCHLAG_B2B', (string) (float) $b2b, 'chaine', 0, '', 0); dolibarr_set_const($db, 'MAHNUNG_PAUSCHALE_B2B', (string) (float) $pau, 'chaine', 0, '', 0); dolibarr_set_const($db, 'MAHNUNG_NTFY_TOPIC', (string) $topic, 'chaine', 0, '', $conf->entity); setEventMessages($langs->trans('MahnungSettingsSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF']); exit; } // --------------------------------------------------------------- // POST: Stufen-Tabelle speichern (Bulk-Update aller 3 Stufen) // --------------------------------------------------------------- if ($action === 'save_stufen' && $user->hasRight('mahnung', 'setup')) { $stufeObj = new MahnungStufe($db); $alle = $stufeObj->fetchAllActive(); // Auch inaktive laden (active=0) — fetchAllActive filtert; hier inkl. inaktive: $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."mahnung_stufe WHERE entity = ".((int) $conf->entity)." ORDER BY stufe"; $resql = $db->query($sql); $ids = array(); if ($resql) { while ($obj = $db->fetch_object($resql)) { $ids[] = (int) $obj->rowid; } $db->free($resql); } $ok = true; foreach ($ids as $id) { $s = loadStufeById($db, $id, $conf->entity); if (!$s) { continue; } $prefix = 'stufe_'.$s->stufe.'_'; $s->label = GETPOST($prefix.'label', 'alphanohtml'); $s->frist_tage = (int) GETPOST($prefix.'frist_tage', 'int'); $s->neue_frist_tage = (int) GETPOST($prefix.'neue_frist_tage', 'int'); $s->mahngebuehr_b2c = (float) str_replace(',', '.', GETPOST($prefix.'mahngebuehr_b2c', 'alphanohtml')); $s->mahngebuehr_b2b = (float) str_replace(',', '.', GETPOST($prefix.'mahngebuehr_b2b', 'alphanohtml')); $s->pauschale_b2b_einmalig = GETPOSTISSET($prefix.'pauschale_b2b_einmalig') ? 1 : 0; $ovB2c = trim((string) GETPOST($prefix.'zinssatz_b2c', 'alphanohtml')); $ovB2b = trim((string) GETPOST($prefix.'zinssatz_b2b', 'alphanohtml')); $s->zinssatz_b2c_uebersteuern = $ovB2c === '' ? null : (float) str_replace(',', '.', $ovB2c); $s->zinssatz_b2b_uebersteuern = $ovB2b === '' ? null : (float) str_replace(',', '.', $ovB2b); $s->versandart_default = GETPOST($prefix.'versandart', 'alphanohtml') ?: 'pdf'; $s->pdf_intro = GETPOST($prefix.'pdf_intro', 'restricthtml'); $s->email_subject = GETPOST($prefix.'email_subject', 'alphanohtml'); $s->email_body = GETPOST($prefix.'email_body', 'restricthtml'); $s->active = GETPOSTISSET($prefix.'active') ? 1 : 0; if ($s->update($user) <= 0) { $ok = false; setEventMessages($s->error, null, 'errors'); } } if ($ok) { setEventMessages($langs->trans('MahnungSettingsSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF']); exit; } } /** * Helfer: Stufe per rowid + entity laden (CRUD-Klasse hat nur fetchByStufe). * * @param DoliDB $db * @param int $id * @param int $entity * @return MahnungStufe|null */ function loadStufeById($db, $id, $entity) { $sql = "SELECT t.* FROM ".MAIN_DB_PREFIX."mahnung_stufe as t"; $sql .= " WHERE t.rowid = ".((int) $id); $sql .= " AND t.entity = ".((int) $entity); $resql = $db->query($sql); if (!$resql || !$db->num_rows($resql)) { return null; } $obj = $db->fetch_object($resql); $s = new MahnungStufe($db); $s->id = (int) $obj->rowid; $s->entity = (int) $obj->entity; $s->stufe = (int) $obj->stufe; $s->label = $obj->label; $s->frist_tage = (int) $obj->frist_tage; $s->neue_frist_tage = (int) $obj->neue_frist_tage; $s->mahngebuehr_b2c = $obj->mahngebuehr_b2c; $s->mahngebuehr_b2b = $obj->mahngebuehr_b2b; $s->pauschale_b2b_einmalig = (int) $obj->pauschale_b2b_einmalig; $s->zinssatz_b2c_uebersteuern = $obj->zinssatz_b2c_uebersteuern; $s->zinssatz_b2b_uebersteuern = $obj->zinssatz_b2b_uebersteuern; $s->versandart_default = $obj->versandart_default; $s->email_subject = $obj->email_subject; $s->email_body = $obj->email_body; $s->pdf_intro = $obj->pdf_intro; $s->active = (int) $obj->active; $db->free($resql); return $s; } // --------------------------------------------------------------- // View // --------------------------------------------------------------- llxHeader('', $langs->trans('MahnungSetupPage')); print load_fiche_titre($langs->trans('MahnungSetupPage'), '', 'fa-envelope-open-text'); print ''.$langs->trans('MahnungSetupDescription').'

'; // --- Block: Konstanten ------------------------------------------------------- print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans('MahnungSetup').'
'.$langs->trans('MahnungBasiszins').' %'; print ' '.$langs->trans('MahnungBasiszinsHelp').'
'.$langs->trans('MahnungAufschlagB2C').' %
'.$langs->trans('MahnungAufschlagB2B').' %
'.$langs->trans('MahnungPauschaleB2BLabel').' EUR
'.$langs->trans('MahnungNtfyTopic').''; print ' '.$langs->trans('MahnungNtfyTopicHelp').'
'; print '
'; print '
'; // --- Block: Stufen ----------------------------------------------------------- $stufeObj = new MahnungStufe($db); $stufen = array(); $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."mahnung_stufe WHERE entity = ".((int) $conf->entity)." ORDER BY stufe ASC"; $resql = $db->query($sql); if ($resql) { while ($obj = $db->fetch_object($resql)) { $s = loadStufeById($db, (int) $obj->rowid, (int) $conf->entity); if ($s) { $stufen[] = $s; } } $db->free($resql); } print '

'; print '
'; print ''; print ''; print ''; print ''; foreach ($stufen as $s) { $prefix = 'stufe_'.$s->stufe.'_'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $va = $s->versandart_default ?: 'pdf'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; } print '
'.$langs->trans('MahnungStufe').'
'.dol_escape_htmltag('Stufe '.$s->stufe).' '; print 'active ? ' checked' : '').'> '.$langs->trans('Active'); print '
'.$langs->trans('MahnungStufeLabel').'
'.$langs->trans('MahnungStufeFristTage').'
'.$langs->trans('MahnungStufeNeueFristTage').'
'.$langs->trans('MahnungStufeGebuehrB2C').' EUR
'.$langs->trans('MahnungStufeGebuehrB2B').' EUR
'.$langs->trans('MahnungPauschaleB2B').' (§288 Abs. 5)pauschale_b2b_einmalig ? ' checked' : '').'>
'.$langs->trans('MahnungStufeZinssatzB2C').' %
'.$langs->trans('MahnungStufeZinssatzB2B').' %
'.$langs->trans('MahnungStufeVersandartDefault').'
'.$langs->trans('MahnungStufePdfIntro').'
'.$langs->trans('MahnungStufeEmailSubject').'
'.$langs->trans('MahnungStufeEmailBody').'
'; print '
'; print '
'; llxFooter(); $db->close();