-- 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.

-- Mahnvorgaenge zu Kundenrechnungen

CREATE TABLE llx_mahnung_mahnung (
    rowid                  INTEGER AUTO_INCREMENT PRIMARY KEY,
    entity                 INTEGER DEFAULT 1 NOT NULL,
    ref                    VARCHAR(30) NOT NULL,
    fk_facture             INTEGER NOT NULL,
    fk_soc                 INTEGER NOT NULL,
    stufe                  TINYINT NOT NULL,
    date_mahnung           DATE NOT NULL,
    date_lim_reglement_alt DATE,
    date_lim_reglement_neu DATE,
    betrag_offen           DOUBLE(24,8) DEFAULT 0,
    mahngebuehr            DOUBLE(10,2) DEFAULT 0,
    pauschale_b2b          DOUBLE(10,2) DEFAULT 0,
    verzugszinsen          DOUBLE(10,2) DEFAULT 0,
    -- Kumulierte Gebuehren/Pauschalen der Vorstufen zu derselben Rechnung
    kosten_vorstufen       DOUBLE(10,2) DEFAULT 0,
    summe_mahnung          DOUBLE(24,8) DEFAULT 0,
    versandart             VARCHAR(20) DEFAULT 'pdf',
    customertype           VARCHAR(3),
    -- DECIMAL(6,3): das alte DECIMAL(5,4) konnte max. 9,9999 abbilden
    basiszins_snapshot     DECIMAL(6,3),
    pdf_path               VARCHAR(255),
    note_private           TEXT,
    status                 TINYINT DEFAULT 0 NOT NULL,
    date_versand           DATETIME,
    versandweg             VARCHAR(30),
    tracking_nr            VARCHAR(50),
    tracking_provider      VARCHAR(20),
    datec                  DATETIME,
    tms                    TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    fk_user_creat          INTEGER,
    fk_user_modif          INTEGER
) ENGINE=InnoDB;
