-- Migration 012: Add is_own_invoice flag to filter outgoing invoices
-- BMC's own CVR: 29522790

-- Add column to track outgoing invoices (BMC's own invoices to customers)
ALTER TABLE incoming_files 
ADD COLUMN IF NOT EXISTS is_own_invoice BOOLEAN DEFAULT FALSE;

-- Mark existing files with BMC's CVR as outgoing invoices
UPDATE incoming_files 
SET is_own_invoice = TRUE 
WHERE detected_cvr = '29522790';

-- Add index for faster filtering
CREATE INDEX IF NOT EXISTS idx_incoming_files_is_own_invoice 
ON incoming_files(is_own_invoice) 
WHERE is_own_invoice = TRUE;

-- Add comment
COMMENT ON COLUMN incoming_files.is_own_invoice IS 
'TRUE hvis filen er en udgående faktura fra BMC (CVR 29522790), FALSE hvis leverandør faktura';
