All checks were successful
Deploy mahnung / deploy (push) Successful in 14s
Umlaute in allen lang-Dateien korrigiert. Alle hardcodierten deutschen Strings
in 22 PHP-Dateien durch $langs->trans('Key') ersetzt. Neue Schlüssel für
Cron-Meldungen, Dokument-Aktionen, Bonität, Vorschlag-Status, Template-Vars u.a.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
231 lines
6.5 KiB
PHP
231 lines
6.5 KiB
PHP
<?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, version 3.
|
|
*/
|
|
|
|
/**
|
|
* \file htdocs/custom/mahnung/class/mahnungstufe.class.php
|
|
* \ingroup mahnung
|
|
* \brief Konfigurations-Klasse für Mahnstufen (llx_mahnung_stufe).
|
|
*/
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
|
|
|
|
/**
|
|
* Eine Mahnstufe (1..3): Frist-Konfiguration, Gebühren, optionaler Zinssatz-Override,
|
|
* Versandart-Default, E-Mail-/PDF-Templates.
|
|
*/
|
|
class MahnungStufe extends CommonObject
|
|
{
|
|
/** @var string */
|
|
public $element = 'mahnungstufe';
|
|
|
|
/** @var string */
|
|
public $table_element = 'mahnung_stufe';
|
|
|
|
/** @var int */
|
|
public $entity;
|
|
|
|
/** @var int 1..3 */
|
|
public $stufe;
|
|
|
|
/** @var string */
|
|
public $label;
|
|
|
|
/** @var int Tage nach Fälligkeit (Stufe 1) bzw. nach Vorgängerstufe (>1) */
|
|
public $frist_tage = 0;
|
|
|
|
/** @var int Neue Zahlungsfrist im Mahnschreiben (Tage) */
|
|
public $neue_frist_tage = 7;
|
|
|
|
/** @var float */
|
|
public $mahngebuehr_b2c = 0;
|
|
|
|
/** @var float */
|
|
public $mahngebuehr_b2b = 0;
|
|
|
|
/** @var int 1 = nur in dieser Stufe Pauschale §288 Abs. 5 berechnen */
|
|
public $pauschale_b2b_einmalig = 0;
|
|
|
|
/** @var float|null Override Basiszins+5 % B2C-Default */
|
|
public $zinssatz_b2c_uebersteuern;
|
|
|
|
/** @var float|null Override Basiszins+9 % B2B-Default */
|
|
public $zinssatz_b2b_uebersteuern;
|
|
|
|
/** @var string pdf|mail|druck|none */
|
|
public $versandart_default = 'pdf';
|
|
|
|
/** @var string */
|
|
public $email_subject;
|
|
|
|
/** @var string */
|
|
public $email_body;
|
|
|
|
/** @var string */
|
|
public $pdf_intro;
|
|
|
|
/** @var int 0|1 */
|
|
public $active = 1;
|
|
|
|
/** @var int Unix-Zeit */
|
|
public $datec;
|
|
|
|
/** @var int Unix-Zeit */
|
|
public $tms;
|
|
|
|
/**
|
|
* @param DoliDB $db Datenbank-Handler
|
|
*/
|
|
public function __construct($db)
|
|
{
|
|
global $conf;
|
|
$this->db = $db;
|
|
$this->entity = $conf->entity;
|
|
}
|
|
|
|
/**
|
|
* @param int $stufe 1..3
|
|
* @return int -1 Fehler, 0 nicht gefunden, >0 OK
|
|
*/
|
|
public function fetchByStufe($stufe)
|
|
{
|
|
$sql = "SELECT t.* FROM ".MAIN_DB_PREFIX."mahnung_stufe as t";
|
|
$sql .= " WHERE t.entity = ".((int) $this->entity);
|
|
$sql .= " AND t.stufe = ".((int) $stufe);
|
|
|
|
$resql = $this->db->query($sql);
|
|
if (!$resql) {
|
|
$this->error = $this->db->lasterror();
|
|
return -1;
|
|
}
|
|
if (!$this->db->num_rows($resql)) {
|
|
$this->db->free($resql);
|
|
return 0;
|
|
}
|
|
$obj = $this->db->fetch_object($resql);
|
|
$this->loadFromObj($obj);
|
|
$this->db->free($resql);
|
|
return 1;
|
|
}
|
|
|
|
/**
|
|
* Alle aktiven Stufen geordnet nach stufe ASC.
|
|
*
|
|
* @return MahnungStufe[]
|
|
*/
|
|
public function fetchAllActive()
|
|
{
|
|
$sql = "SELECT t.* FROM ".MAIN_DB_PREFIX."mahnung_stufe as t";
|
|
$sql .= " WHERE t.entity = ".((int) $this->entity);
|
|
$sql .= " AND t.active = 1";
|
|
$sql .= " ORDER BY t.stufe ASC";
|
|
|
|
$resql = $this->db->query($sql);
|
|
$result = array();
|
|
if (!$resql) {
|
|
$this->error = $this->db->lasterror();
|
|
return $result;
|
|
}
|
|
while ($obj = $this->db->fetch_object($resql)) {
|
|
$s = new self($this->db);
|
|
$s->loadFromObj($obj);
|
|
$result[] = $s;
|
|
}
|
|
$this->db->free($resql);
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* @param User $user
|
|
* @return int <0 Fehler, sonst rowid
|
|
*/
|
|
public function update($user)
|
|
{
|
|
if (empty($this->id)) {
|
|
$this->error = 'MahnungStufe::update — id missing';
|
|
return -1;
|
|
}
|
|
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."mahnung_stufe SET";
|
|
$sql .= " label = '".$this->db->escape($this->label)."'";
|
|
$sql .= ", frist_tage = ".((int) $this->frist_tage);
|
|
$sql .= ", neue_frist_tage = ".((int) $this->neue_frist_tage);
|
|
$sql .= ", mahngebuehr_b2c = ".((float) $this->mahngebuehr_b2c);
|
|
$sql .= ", mahngebuehr_b2b = ".((float) $this->mahngebuehr_b2b);
|
|
$sql .= ", pauschale_b2b_einmalig = ".((int) (!empty($this->pauschale_b2b_einmalig) ? 1 : 0));
|
|
$sql .= ", zinssatz_b2c_uebersteuern = ".($this->zinssatz_b2c_uebersteuern !== null && $this->zinssatz_b2c_uebersteuern !== '' ? ((float) $this->zinssatz_b2c_uebersteuern) : "NULL");
|
|
$sql .= ", zinssatz_b2b_uebersteuern = ".($this->zinssatz_b2b_uebersteuern !== null && $this->zinssatz_b2b_uebersteuern !== '' ? ((float) $this->zinssatz_b2b_uebersteuern) : "NULL");
|
|
$sql .= ", versandart_default = '".$this->db->escape($this->versandart_default ?: 'pdf')."'";
|
|
$sql .= ", email_subject = ".($this->email_subject ? "'".$this->db->escape($this->email_subject)."'" : "NULL");
|
|
$sql .= ", email_body = ".($this->email_body ? "'".$this->db->escape($this->email_body)."'" : "NULL");
|
|
$sql .= ", pdf_intro = ".($this->pdf_intro ? "'".$this->db->escape($this->pdf_intro)."'" : "NULL");
|
|
$sql .= ", active = ".((int) (!empty($this->active) ? 1 : 0));
|
|
$sql .= " WHERE rowid = ".((int) $this->id);
|
|
|
|
dol_syslog(get_class($this).'::update', LOG_DEBUG);
|
|
$resql = $this->db->query($sql);
|
|
if (!$resql) {
|
|
$this->error = $this->db->lasterror();
|
|
return -1;
|
|
}
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* Mahngebühr für einen Kundentyp aus dieser Stufe lesen.
|
|
*
|
|
* @param string $kundentyp 'B2C'|'B2B'
|
|
* @return float
|
|
*/
|
|
public function getMahngebuehr($kundentyp)
|
|
{
|
|
return $kundentyp === Mahnung::KUNDENTYP_B2B
|
|
? (float) $this->mahngebuehr_b2b
|
|
: (float) $this->mahngebuehr_b2c;
|
|
}
|
|
|
|
/**
|
|
* Override-Zinssatz für einen Kundentyp (oder null falls Default gewünscht).
|
|
*
|
|
* @param string $kundentyp
|
|
* @return float|null
|
|
*/
|
|
public function getZinssatzOverride($kundentyp)
|
|
{
|
|
$value = $kundentyp === Mahnung::KUNDENTYP_B2B
|
|
? $this->zinssatz_b2b_uebersteuern
|
|
: $this->zinssatz_b2c_uebersteuern;
|
|
return ($value === null || $value === '') ? null : (float) $value;
|
|
}
|
|
|
|
/**
|
|
* Properties aus DB-Object-Reihe laden.
|
|
*
|
|
* @param object $obj
|
|
* @return void
|
|
*/
|
|
private function loadFromObj($obj)
|
|
{
|
|
$this->id = $obj->rowid;
|
|
$this->entity = $obj->entity;
|
|
$this->stufe = (int) $obj->stufe;
|
|
$this->label = $obj->label;
|
|
$this->frist_tage = (int) $obj->frist_tage;
|
|
$this->neue_frist_tage = (int) $obj->neue_frist_tage;
|
|
$this->mahngebuehr_b2c = $obj->mahngebuehr_b2c;
|
|
$this->mahngebuehr_b2b = $obj->mahngebuehr_b2b;
|
|
$this->pauschale_b2b_einmalig = (int) $obj->pauschale_b2b_einmalig;
|
|
$this->zinssatz_b2c_uebersteuern = $obj->zinssatz_b2c_uebersteuern;
|
|
$this->zinssatz_b2b_uebersteuern = $obj->zinssatz_b2b_uebersteuern;
|
|
$this->versandart_default = $obj->versandart_default;
|
|
$this->email_subject = $obj->email_subject;
|
|
$this->email_body = $obj->email_body;
|
|
$this->pdf_intro = $obj->pdf_intro;
|
|
$this->active = (int) $obj->active;
|
|
$this->datec = $this->db->jdate($obj->datec);
|
|
$this->tms = $this->db->jdate($obj->tms);
|
|
}
|
|
}
|