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

-- Table for individual transaction lines parsed from PDF bank statements

CREATE TABLE llx_bankimport_statement_line (
    rowid           INTEGER AUTO_INCREMENT PRIMARY KEY,
    fk_statement    INTEGER NOT NULL,               -- Link to llx_bankimport_statement
    entity          INTEGER DEFAULT 1 NOT NULL,
    line_number     INTEGER DEFAULT 0,              -- Position within statement (1, 2, 3...)

    -- Transaction data from PDF
    date_booking    DATE NOT NULL,                   -- Buchungstag (Bu-Tag)
    date_value      DATE,                            -- Wertstellungstag (Wert)
    transaction_type VARCHAR(100),                   -- Vorgangsart (e.g. Überweisungsgutschr., Basislastschrift)
    amount          DOUBLE(24,8) NOT NULL,           -- Amount (positive = credit, negative = debit)
    currency        VARCHAR(3) DEFAULT 'EUR',

    -- Counterparty and description
    name            VARCHAR(255),                    -- Counterparty name (first detail line)
    description     TEXT,                            -- Full description (all detail lines)

    -- Matching
    fk_bank         INTEGER,                         -- Link to llx_bank when reconciled
    match_status    VARCHAR(20) DEFAULT NULL,         -- NULL=unmatched, reconciled=auto, pending_review=needs approval

    -- Timestamps
    datec           DATETIME,
    tms             TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB;
