diff --git a/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contract_fee_items.sql b/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contract_fee_items.sql index eefc7a9bd..fa1d2970b 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contract_fee_items.sql +++ b/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contract_fee_items.sql @@ -1,7 +1,7 @@ CREATE OR REPLACE VIEW public.view_effect_contract_fee_items AS SELECT - ('C'::TEXT || contract_plan_fee_items.contract_id)::CHARACTER VARYING AS effect_contract_id, + ('S-'::TEXT || contract_plan_fee_items.contract_id)::CHARACTER VARYING AS effect_contract_id, contract_plan_fee_items.id FROM contract_plan_fee_items @@ -11,11 +11,16 @@ WHERE UNION ALL SELECT ( - 'P'::TEXT || contract_plan_fee_items.contract_plan_id + ( + ('L-'::TEXT || contract_items.contract_id) || '-'::TEXT + ) || contract_items.id )::CHARACTER VARYING AS effect_contract_id, contract_plan_fee_items.id FROM contract_plan_fee_items + JOIN contract_plans ON contract_plans.id = contract_plan_fee_items.contract_plan_id + JOIN contract_items ON contract_items.contract_plan_id = contract_plans.id WHERE contract_plan_fee_items.lease_item_id IS NULL - AND contract_plan_fee_items.contract_plan_id IS NOT NULL; + AND contract_plan_fee_items.contract_plan_id IS NOT NULL + AND contract_items.contract_id IS NOT NULL; diff --git a/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contract_lease_items.sql b/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contract_lease_items.sql index b61d9b8d7..72aef048b 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contract_lease_items.sql +++ b/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contract_lease_items.sql @@ -2,7 +2,7 @@ CREATE OR REPLACE VIEW public.view_effect_contract_lease_items AS SELECT ( - 'C'::TEXT || contract_plan_lease_items.contract_id + 'S-'::TEXT || contract_plan_lease_items.contract_id )::CHARACTER VARYING AS effect_contract_id, contract_plan_lease_items.id FROM @@ -12,10 +12,15 @@ WHERE UNION ALL SELECT ( - 'P'::TEXT || contract_plan_lease_items.contract_plan_id + ( + ('L-'::TEXT || contract_items.contract_id) || '-'::TEXT + ) || contract_items.id )::CHARACTER VARYING AS effect_contract_id, contract_plan_lease_items.id FROM contract_plan_lease_items + JOIN contract_plans ON contract_plans.id = contract_plan_lease_items.contract_plan_id + JOIN contract_items ON contract_items.contract_plan_id = contract_plans.id WHERE - contract_plan_lease_items.contract_plan_id IS NOT NULL; + contract_plan_lease_items.contract_plan_id IS NOT NULL + AND contract_items.contract_id IS NOT NULL; diff --git a/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contracts.sql b/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contracts.sql index daeb5e1db..1de4c6691 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contracts.sql +++ b/packages/plugins/@hera/plugin-rental/src/server/sqls/view_effect_contracts.sql @@ -4,7 +4,6 @@ SELECT contracts.name, ('S-'::TEXT || contracts.id)::CHARACTER VARYING AS id, contracts.id AS contract_id, - ('C'::TEXT || contracts.id)::CHARACTER VARYING AS effect_contract_id, contracts.project_id, contracts.tax_rate, contracts.calc_type, @@ -26,10 +25,9 @@ SELECT (contracts.name::TEXT || '-'::TEXT) || contract_plans.name::TEXT )::CHARACTER VARYING AS NAME, ( - (('L-'::TEXT || contracts.id) || '-'::TEXT) || contract_plans.id + (('L-'::TEXT || contracts.id) || '-'::TEXT) || contract_items.id )::CHARACTER VARYING AS id, contracts.id AS contract_id, - ('P'::TEXT || contract_plans.id)::CHARACTER VARYING AS effect_contract_id, contracts.project_id, contracts.tax_rate, contracts.calc_type, @@ -43,7 +41,7 @@ SELECT UPPER(contract_items.date_range) - '1 day'::INTERVAL AS end_date FROM contracts - JOIN contract_items ON contracts.id = contract_items.id + JOIN contract_items ON contracts.id = contract_items.contract_id JOIN contract_plans ON contract_plans.id = contract_items.contract_plan_id WHERE contracts.effectiveness::TEXT = '0'::TEXT;