-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- CREATE OR REPLACE FUNCTION public.jobs_ar_summary ()
-- 	RETURNS SETOF jobs
-- 	LANGUAGE plpgsql
-- 	STABLE
-- 	AS $function$
-- BEGIN
--
-- 		RETURN query
-- select
-- 	j.id,
-- 	j.shopid,
-- 	j.ro_number,
-- 	j.clm_total,
-- 	p.total_payments,
-- 	j.clm_total - p.total_payments as balance
-- from
-- 	jobs j
-- left join (
-- 	select
-- 		p.jobid,
-- 		sum(p.amount) as total_payments
-- 	from
-- 		payments p
-- 	group by
-- 		p.jobid
--   ) p on
-- 	j.id = p.jobid ;
-- 	
--
-- END
-- $function$;
