Files
accounted/supabase/migrations/20240101000048_supplier_invoice_overdue_cron.sql
T
Jakob WennbergandClaude Opus 4.6 66a4027f1e feat: BAS data overhaul, currency revaluation, expenses, UI polish, and cleanup
- Update BAS account catalog with comprehensive SRU codes and K2 flags
- Add currency revaluation service with tests and API route
- Add expenses page and account deletion API
- Enhance booking templates with new patterns and improved tests
- Improve transaction categorization with template picker and description matching
- Polish dashboard, onboarding, import, and transaction UIs
- Refactor year-end service for multi-step closing
- Move SRU generator to ne-bilaga, remove standalone SRU export
- Remove unused dev docs, mock data, and extension hooks
- Add invoice delivery note sequences migration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 14:19:56 +01:00

31 lines
848 B
PL/PgSQL

-- Migration: supplier_invoice_overdue_cron
-- Sets overdue status on supplier invoices past due_date via pg_cron
-- Enable pg_cron extension
CREATE EXTENSION IF NOT EXISTS pg_cron WITH SCHEMA pg_catalog;
-- Grant usage to postgres role (required by Supabase)
GRANT USAGE ON SCHEMA cron TO postgres;
-- Function to update overdue supplier invoices
CREATE OR REPLACE FUNCTION public.update_overdue_supplier_invoices()
RETURNS void
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
BEGIN
UPDATE supplier_invoices
SET status = 'overdue',
updated_at = NOW()
WHERE due_date < CURRENT_DATE
AND status IN ('registered', 'approved');
END;
$$;
-- Schedule daily at 06:00 UTC (matches existing banking sync timing)
SELECT cron.schedule(
'update-overdue-supplier-invoices',
'0 6 * * *',
$$SELECT public.update_overdue_supplier_invoices()$$
);