From 9b4c85c9e3669d4505b7084306921559e01f3aa5 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Fri, 19 Jan 2024 13:50:14 -0800 Subject: [PATCH] IO-2543 additional schema correction. --- .../1705700945994_run_sql_migration/down.sql | 34 +++++++++++++++++++ .../1705700945994_run_sql_migration/up.sql | 32 +++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 hasura/migrations/1705700945994_run_sql_migration/down.sql create mode 100644 hasura/migrations/1705700945994_run_sql_migration/up.sql diff --git a/hasura/migrations/1705700945994_run_sql_migration/down.sql b/hasura/migrations/1705700945994_run_sql_migration/down.sql new file mode 100644 index 000000000..d1ca7dbe0 --- /dev/null +++ b/hasura/migrations/1705700945994_run_sql_migration/down.sql @@ -0,0 +1,34 @@ +-- 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 job_ar_schema +-- LANGUAGE plpgsql +-- STABLE +-- AS $function$ +-- BEGIN +-- +-- RETURN query +-- select +-- j.id, +-- j.ro_number, +-- j.clm_total, +-- coalesce (p.total_payments,0) as total_payments, +-- j.clm_total - coalesce (p.total_payments,0) as balance, +-- j.date_invoiced +-- from +-- jobs j +-- left join ( +-- select +-- p.jobid, +-- coalesce (sum(p.amount),0) as total_payments +-- from +-- payments p +-- group by +-- p.jobid +-- ) p on +-- j.id = p.jobid +-- where j.remove_from_ar = false and j.date_invoiced is not null and j.clm_total - coalesce (p.total_payments,0) > 0; +-- +-- +-- END +-- $function$; diff --git a/hasura/migrations/1705700945994_run_sql_migration/up.sql b/hasura/migrations/1705700945994_run_sql_migration/up.sql new file mode 100644 index 000000000..25c2b3e1e --- /dev/null +++ b/hasura/migrations/1705700945994_run_sql_migration/up.sql @@ -0,0 +1,32 @@ +CREATE OR REPLACE FUNCTION public.jobs_ar_summary () + RETURNS SETOF job_ar_schema + LANGUAGE plpgsql + STABLE + AS $function$ +BEGIN + + RETURN query +select + j.id, + j.ro_number, + j.clm_total, + coalesce (p.total_payments,0) as total_payments, + j.clm_total - coalesce (p.total_payments,0) as balance, + j.date_invoiced +from + jobs j +left join ( + select + p.jobid, + coalesce (sum(p.amount),0) as total_payments + from + payments p + group by + p.jobid + ) p on + j.id = p.jobid +where j.remove_from_ar = false and j.date_invoiced is not null and j.clm_total - coalesce (p.total_payments,0) > 0; + + +END +$function$;