CREATE TABLE IF NOT EXISTS encaissements (
    id INT AUTO_INCREMENT PRIMARY KEY,
    client_id INT NOT NULL,
    facture_id INT NOT NULL,
    date_encaissement DATE NOT NULL,
    mode_reglement VARCHAR(50) NOT NULL DEFAULT 'Espèces',
    reference_reglement VARCHAR(100) NULL,
    montant DECIMAL(12,2) NOT NULL DEFAULT 0,
    observations TEXT,
    actif TINYINT(1) DEFAULT 1,
    date_creation DATETIME DEFAULT CURRENT_TIMESTAMP,
    date_modification DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_encaissements_client (client_id),
    INDEX idx_encaissements_facture (facture_id),
    INDEX idx_encaissements_date (date_encaissement),
    CONSTRAINT fk_encaissements_client FOREIGN KEY (client_id) REFERENCES clients(id),
    CONSTRAINT fk_encaissements_facture FOREIGN KEY (facture_id) REFERENCES factures(id)
);


