-- VendorOS - Migration pour le wizard de facturation Qonto-style
-- Version simplifiée - Compatible MySQL 5.7+
-- Date: 2026-01-13

-- =====================================================
-- VENDOROS_INVOICE_ITEMS - Ajout direct (ignore si existe)
-- =====================================================
ALTER TABLE vendoros_invoice_items ADD COLUMN description TEXT DEFAULT NULL;
ALTER TABLE vendoros_invoice_items ADD COLUMN unit_type VARCHAR(50) DEFAULT 'unité';
ALTER TABLE vendoros_invoice_items ADD COLUMN discount_amount DECIMAL(10,2) DEFAULT NULL;
ALTER TABLE vendoros_invoice_items ADD COLUMN discount_type ENUM('EUR','percent') DEFAULT NULL;
ALTER TABLE vendoros_invoice_items ADD COLUMN is_section TINYINT(1) DEFAULT 0;

-- =====================================================
-- VENDOROS_QUOTE_ITEMS
-- =====================================================
ALTER TABLE vendoros_quote_items ADD COLUMN description TEXT DEFAULT NULL;
ALTER TABLE vendoros_quote_items ADD COLUMN unit_type VARCHAR(50) DEFAULT 'unité';
ALTER TABLE vendoros_quote_items ADD COLUMN discount_amount DECIMAL(10,2) DEFAULT NULL;
ALTER TABLE vendoros_quote_items ADD COLUMN discount_type ENUM('EUR','percent') DEFAULT NULL;
ALTER TABLE vendoros_quote_items ADD COLUMN is_section TINYINT(1) DEFAULT 0;

-- =====================================================
-- VENDOROS_INVOICES
-- =====================================================
ALTER TABLE vendoros_invoices ADD COLUMN header_note TEXT DEFAULT NULL;
ALTER TABLE vendoros_invoices ADD COLUMN footer_note TEXT DEFAULT NULL;
ALTER TABLE vendoros_invoices ADD COLUMN po_number VARCHAR(100) DEFAULT NULL;
ALTER TABLE vendoros_invoices ADD COLUMN invoice_type ENUM('standard','recurring','proforma','deposit') DEFAULT 'standard';
ALTER TABLE vendoros_invoices ADD COLUMN period_start DATE DEFAULT NULL;
ALTER TABLE vendoros_invoices ADD COLUMN period_end DATE DEFAULT NULL;
ALTER TABLE vendoros_invoices ADD COLUMN attachment_path VARCHAR(500) DEFAULT NULL;

-- =====================================================
-- VENDOROS_QUOTES
-- =====================================================
ALTER TABLE vendoros_quotes ADD COLUMN header_note TEXT DEFAULT NULL;
ALTER TABLE vendoros_quotes ADD COLUMN footer_note TEXT DEFAULT NULL;
ALTER TABLE vendoros_quotes ADD COLUMN po_number VARCHAR(100) DEFAULT NULL;
ALTER TABLE vendoros_quotes ADD COLUMN quote_type ENUM('standard','detailed') DEFAULT 'standard';
ALTER TABLE vendoros_quotes ADD COLUMN period_start DATE DEFAULT NULL;
ALTER TABLE vendoros_quotes ADD COLUMN period_end DATE DEFAULT NULL;
ALTER TABLE vendoros_quotes ADD COLUMN attachment_path VARCHAR(500) DEFAULT NULL;

SELECT 'Migration terminée' AS status;
