diff --git a/client/src/components/production-list-detail/production-list-detail.component.jsx b/client/src/components/production-list-detail/production-list-detail.component.jsx index 292e426af..95a8b19f6 100644 --- a/client/src/components/production-list-detail/production-list-detail.component.jsx +++ b/client/src/components/production-list-detail/production-list-detail.component.jsx @@ -106,85 +106,89 @@ export function ProductionListDetail({ {error && } {!loading && data && (
- - - - - - - {theJob.ro_number || ""} - - - - {data.jobs_by_pk.alt_transport || ""} - - - - - {theJob.clm_no || ""} - - - {theJob.ins_co_nm || ""} - - - - - {!technician ? ( - <> - - - - ) : ( - <> - - {data.jobs_by_pk.ownr_ph1} - - - {data.jobs_by_pk.ownr_ph2} - - - )} - - - - {`${theJob.v_model_yr || ""} ${theJob.v_color || ""} ${ - theJob.v_make_desc || "" - } ${theJob.v_model_desc || ""}`} - - - {theJob.clm_total} - - - {theJob.actual_in} - - - {theJob.scheduled_completion} - - - - - {!bodyshop.uselocalmediaserver && ( + + + +
+ + + {theJob.ro_number || ""} + + + + {data.jobs_by_pk.alt_transport || ""} + + + + + {theJob.clm_no || ""} + + + {theJob.ins_co_nm || ""} + + + + + {!technician ? ( + <> + + + + ) : ( + <> + + {data.jobs_by_pk.ownr_ph1} + + + {data.jobs_by_pk.ownr_ph2} + + + )} + + + + {`${theJob.v_model_yr || ""} ${theJob.v_color || ""} ${ + theJob.v_make_desc || "" + } ${theJob.v_model_desc || ""}`} + + + {theJob.clm_total} + + + {theJob.actual_in} + + + {theJob.scheduled_completion} + + +
+ +
+ + {!bodyshop.uselocalmediaserver && ( + <> +
- )} - + + )}
)} diff --git a/hasura/metadata/functions.yaml b/hasura/metadata/functions.yaml index 3ef10184a..5dd1b8640 100644 --- a/hasura/metadata/functions.yaml +++ b/hasura/metadata/functions.yaml @@ -1,3 +1,6 @@ +- function: + name: jobs_ar_summary + schema: public - function: name: search_bills schema: public diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index f4e4d99a7..fda2aa44a 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -2673,6 +2673,9 @@ - table: name: ioevents schema: public +- table: + name: job_ar_schema + schema: public - table: name: job_conversations schema: public @@ -3812,6 +3815,7 @@ - referral_source - referral_source_extra - regie_number + - remove_from_ar - ro_number - scheduled_completion - scheduled_delivery @@ -4093,6 +4097,7 @@ - referral_source - referral_source_extra - regie_number + - remove_from_ar - ro_number - scheduled_completion - scheduled_delivery diff --git a/hasura/migrations/1705693552101_run_sql_migration/down.sql b/hasura/migrations/1705693552101_run_sql_migration/down.sql new file mode 100644 index 000000000..8fd036e68 --- /dev/null +++ b/hasura/migrations/1705693552101_run_sql_migration/down.sql @@ -0,0 +1,33 @@ +-- 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$; diff --git a/hasura/migrations/1705693552101_run_sql_migration/up.sql b/hasura/migrations/1705693552101_run_sql_migration/up.sql new file mode 100644 index 000000000..56f2ff938 --- /dev/null +++ b/hasura/migrations/1705693552101_run_sql_migration/up.sql @@ -0,0 +1,31 @@ +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$; diff --git a/hasura/migrations/1705693852612_create_table_public_job_ar_schema/down.sql b/hasura/migrations/1705693852612_create_table_public_job_ar_schema/down.sql new file mode 100644 index 000000000..1ef08bca9 --- /dev/null +++ b/hasura/migrations/1705693852612_create_table_public_job_ar_schema/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."job_ar_schema"; diff --git a/hasura/migrations/1705693852612_create_table_public_job_ar_schema/up.sql b/hasura/migrations/1705693852612_create_table_public_job_ar_schema/up.sql new file mode 100644 index 000000000..fe574a140 --- /dev/null +++ b/hasura/migrations/1705693852612_create_table_public_job_ar_schema/up.sql @@ -0,0 +1 @@ +CREATE TABLE "public"."job_ar_schema" ("id" uuid NOT NULL, "ro_number" text, "clm_total" numeric NOT NULL, "total_payments" numeric NOT NULL DEFAULT 0, "balance" numeric NOT NULL DEFAULT 0, PRIMARY KEY ("id") ); diff --git a/hasura/migrations/1705693896379_run_sql_migration/down.sql b/hasura/migrations/1705693896379_run_sql_migration/down.sql new file mode 100644 index 000000000..a180c91a5 --- /dev/null +++ b/hasura/migrations/1705693896379_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: +-- DROP FUNCTION public.jobs_ar_summary; +-- +-- 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, +-- 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$; diff --git a/hasura/migrations/1705693896379_run_sql_migration/up.sql b/hasura/migrations/1705693896379_run_sql_migration/up.sql new file mode 100644 index 000000000..48c04c38f --- /dev/null +++ b/hasura/migrations/1705693896379_run_sql_migration/up.sql @@ -0,0 +1,32 @@ +DROP FUNCTION public.jobs_ar_summary; + +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, + 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$; diff --git a/hasura/migrations/1705694146809_run_sql_migration/down.sql b/hasura/migrations/1705694146809_run_sql_migration/down.sql new file mode 100644 index 000000000..0a84cd97e --- /dev/null +++ b/hasura/migrations/1705694146809_run_sql_migration/down.sql @@ -0,0 +1,32 @@ +-- 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, +-- p.total_payments, +-- j.clm_total - p.total_payments as balance +-- 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 ; +-- +-- +-- END +-- $function$; diff --git a/hasura/migrations/1705694146809_run_sql_migration/up.sql b/hasura/migrations/1705694146809_run_sql_migration/up.sql new file mode 100644 index 000000000..8b6779a91 --- /dev/null +++ b/hasura/migrations/1705694146809_run_sql_migration/up.sql @@ -0,0 +1,30 @@ +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, + p.total_payments, + j.clm_total - p.total_payments as balance +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 ; + + +END +$function$; diff --git a/hasura/migrations/1705694176838_run_sql_migration/down.sql b/hasura/migrations/1705694176838_run_sql_migration/down.sql new file mode 100644 index 000000000..0a84cd97e --- /dev/null +++ b/hasura/migrations/1705694176838_run_sql_migration/down.sql @@ -0,0 +1,32 @@ +-- 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, +-- p.total_payments, +-- j.clm_total - p.total_payments as balance +-- 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 ; +-- +-- +-- END +-- $function$; diff --git a/hasura/migrations/1705694176838_run_sql_migration/up.sql b/hasura/migrations/1705694176838_run_sql_migration/up.sql new file mode 100644 index 000000000..8b6779a91 --- /dev/null +++ b/hasura/migrations/1705694176838_run_sql_migration/up.sql @@ -0,0 +1,30 @@ +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, + p.total_payments, + j.clm_total - p.total_payments as balance +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 ; + + +END +$function$; diff --git a/hasura/migrations/1705696451631_run_sql_migration/down.sql b/hasura/migrations/1705696451631_run_sql_migration/down.sql new file mode 100644 index 000000000..0826360f9 --- /dev/null +++ b/hasura/migrations/1705696451631_run_sql_migration/down.sql @@ -0,0 +1,32 @@ +-- 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 +-- 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 ; +-- +-- +-- END +-- $function$; diff --git a/hasura/migrations/1705696451631_run_sql_migration/up.sql b/hasura/migrations/1705696451631_run_sql_migration/up.sql new file mode 100644 index 000000000..a78f18383 --- /dev/null +++ b/hasura/migrations/1705696451631_run_sql_migration/up.sql @@ -0,0 +1,30 @@ +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 +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 ; + + +END +$function$; diff --git a/hasura/migrations/1705696927199_alter_table_public_jobs_add_column_remove_from_ar/down.sql b/hasura/migrations/1705696927199_alter_table_public_jobs_add_column_remove_from_ar/down.sql new file mode 100644 index 000000000..676aeaafd --- /dev/null +++ b/hasura/migrations/1705696927199_alter_table_public_jobs_add_column_remove_from_ar/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."jobs" add column "remove_from_ar" boolean +-- not null default 'false'; diff --git a/hasura/migrations/1705696927199_alter_table_public_jobs_add_column_remove_from_ar/up.sql b/hasura/migrations/1705696927199_alter_table_public_jobs_add_column_remove_from_ar/up.sql new file mode 100644 index 000000000..562618ab9 --- /dev/null +++ b/hasura/migrations/1705696927199_alter_table_public_jobs_add_column_remove_from_ar/up.sql @@ -0,0 +1,2 @@ +alter table "public"."jobs" add column "remove_from_ar" boolean + not null default 'false'; diff --git a/hasura/migrations/1705698426997_run_sql_migration/down.sql b/hasura/migrations/1705698426997_run_sql_migration/down.sql new file mode 100644 index 000000000..c564b5e7c --- /dev/null +++ b/hasura/migrations/1705698426997_run_sql_migration/down.sql @@ -0,0 +1,33 @@ +-- 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 +-- 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; +-- +-- +-- END +-- $function$; diff --git a/hasura/migrations/1705698426997_run_sql_migration/up.sql b/hasura/migrations/1705698426997_run_sql_migration/up.sql new file mode 100644 index 000000000..f1854fcac --- /dev/null +++ b/hasura/migrations/1705698426997_run_sql_migration/up.sql @@ -0,0 +1,31 @@ +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 +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; + + +END +$function$; diff --git a/hasura/migrations/1705698476261_alter_table_public_job_ar_schema_add_column_date_invoiced/down.sql b/hasura/migrations/1705698476261_alter_table_public_job_ar_schema_add_column_date_invoiced/down.sql new file mode 100644 index 000000000..aff5d0afe --- /dev/null +++ b/hasura/migrations/1705698476261_alter_table_public_job_ar_schema_add_column_date_invoiced/down.sql @@ -0,0 +1,4 @@ +-- Could not auto-generate a down migration. +-- Please write an appropriate down migration for the SQL below: +-- alter table "public"."job_ar_schema" add column "date_invoiced" timestamptz +-- null; diff --git a/hasura/migrations/1705698476261_alter_table_public_job_ar_schema_add_column_date_invoiced/up.sql b/hasura/migrations/1705698476261_alter_table_public_job_ar_schema_add_column_date_invoiced/up.sql new file mode 100644 index 000000000..bd8f477ec --- /dev/null +++ b/hasura/migrations/1705698476261_alter_table_public_job_ar_schema_add_column_date_invoiced/up.sql @@ -0,0 +1,2 @@ +alter table "public"."job_ar_schema" add column "date_invoiced" timestamptz + null; diff --git a/hasura/migrations/1705698534883_run_sql_migration/down.sql b/hasura/migrations/1705698534883_run_sql_migration/down.sql new file mode 100644 index 000000000..a68a79058 --- /dev/null +++ b/hasura/migrations/1705698534883_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, +-- j.date_invoiced, +-- coalesce (p.total_payments,0) as total_payments, +-- j.clm_total - coalesce (p.total_payments,0) as balance +-- 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; +-- +-- +-- END +-- $function$; diff --git a/hasura/migrations/1705698534883_run_sql_migration/up.sql b/hasura/migrations/1705698534883_run_sql_migration/up.sql new file mode 100644 index 000000000..9961003f7 --- /dev/null +++ b/hasura/migrations/1705698534883_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, + j.date_invoiced, + coalesce (p.total_payments,0) as total_payments, + j.clm_total - coalesce (p.total_payments,0) as balance +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; + + +END +$function$; diff --git a/hasura/migrations/1705698593644_run_sql_migration/down.sql b/hasura/migrations/1705698593644_run_sql_migration/down.sql new file mode 100644 index 000000000..c11116ffb --- /dev/null +++ b/hasura/migrations/1705698593644_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; +-- +-- +-- END +-- $function$; diff --git a/hasura/migrations/1705698593644_run_sql_migration/up.sql b/hasura/migrations/1705698593644_run_sql_migration/up.sql new file mode 100644 index 000000000..729ee69d9 --- /dev/null +++ b/hasura/migrations/1705698593644_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; + + +END +$function$; diff --git a/hasura/migrations/1705698876975_run_sql_migration/down.sql b/hasura/migrations/1705698876975_run_sql_migration/down.sql new file mode 100644 index 000000000..190511742 --- /dev/null +++ b/hasura/migrations/1705698876975_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 balance > 0; +-- +-- +-- END +-- $function$; diff --git a/hasura/migrations/1705698876975_run_sql_migration/up.sql b/hasura/migrations/1705698876975_run_sql_migration/up.sql new file mode 100644 index 000000000..4979c0a5e --- /dev/null +++ b/hasura/migrations/1705698876975_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 balance > 0; + + +END +$function$; 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$;