create or replace function public.get_next_sub_invoice_number()
returns text
language sql
security definer
set search_path = public
as $$
  select 'INVSUB-' || extract(year from now())::text || '-' || lpad((count(*) + 1)::text, 3, '0')
  from public.subcontractor_invoices;
$$;
