Allow negative balance for AR.
This commit is contained in:
35
hasura/migrations/1706207204357_run_sql_migration/down.sql
Normal file
35
hasura/migrations/1706207204357_run_sql_migration/down.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
-- 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,
|
||||
-- j.shopid
|
||||
-- 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$;
|
||||
33
hasura/migrations/1706207204357_run_sql_migration/up.sql
Normal file
33
hasura/migrations/1706207204357_run_sql_migration/up.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
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,
|
||||
j.shopid
|
||||
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$;
|
||||
35
hasura/migrations/1706207267558_run_sql_migration/down.sql
Normal file
35
hasura/migrations/1706207267558_run_sql_migration/down.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
-- 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,
|
||||
-- j.shopid
|
||||
-- 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$;
|
||||
33
hasura/migrations/1706207267558_run_sql_migration/up.sql
Normal file
33
hasura/migrations/1706207267558_run_sql_migration/up.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
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,
|
||||
j.shopid
|
||||
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$;
|
||||
Reference in New Issue
Block a user