feat: support view contracts (#947)
Reviewed-on: daoyoucloud/tachybase#947
This commit is contained in:
parent
5a15fd1ff1
commit
882a1a95a5
@ -0,0 +1,21 @@
|
||||
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,
|
||||
contract_plan_fee_items.id
|
||||
FROM
|
||||
contract_plan_fee_items
|
||||
WHERE
|
||||
contract_plan_fee_items.lease_item_id IS NULL
|
||||
AND contract_plan_fee_items.contract_id IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT
|
||||
(
|
||||
'P'::TEXT || contract_plan_fee_items.contract_plan_id
|
||||
)::CHARACTER VARYING AS effect_contract_id,
|
||||
contract_plan_fee_items.id
|
||||
FROM
|
||||
contract_plan_fee_items
|
||||
WHERE
|
||||
contract_plan_fee_items.lease_item_id IS NULL
|
||||
AND contract_plan_fee_items.contract_plan_id IS NOT NULL;
|
@ -0,0 +1,21 @@
|
||||
CREATE OR REPLACE VIEW
|
||||
public.view_effect_contract_lease_items AS
|
||||
SELECT
|
||||
(
|
||||
'C'::TEXT || contract_plan_lease_items.contract_id
|
||||
)::CHARACTER VARYING AS effect_contract_id,
|
||||
contract_plan_lease_items.id
|
||||
FROM
|
||||
contract_plan_lease_items
|
||||
WHERE
|
||||
contract_plan_lease_items.contract_id IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT
|
||||
(
|
||||
'P'::TEXT || contract_plan_lease_items.contract_plan_id
|
||||
)::CHARACTER VARYING AS effect_contract_id,
|
||||
contract_plan_lease_items.id
|
||||
FROM
|
||||
contract_plan_lease_items
|
||||
WHERE
|
||||
contract_plan_lease_items.contract_plan_id IS NOT NULL;
|
@ -0,0 +1,49 @@
|
||||
CREATE OR REPLACE VIEW
|
||||
public.view_effect_contracts AS
|
||||
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,
|
||||
contracts.tax_included,
|
||||
contracts.record_category,
|
||||
contracts.first_party_id,
|
||||
contracts.party_b_id,
|
||||
contracts.date_range,
|
||||
contracts.status,
|
||||
LOWER(contracts.date_range) AS start_date,
|
||||
UPPER(contracts.date_range) - '1 day'::INTERVAL AS end_date
|
||||
FROM
|
||||
contracts
|
||||
WHERE
|
||||
contracts.effectiveness::TEXT = '1'::TEXT
|
||||
UNION ALL
|
||||
SELECT
|
||||
(
|
||||
(contracts.name::TEXT || '-'::TEXT) || contract_plans.name::TEXT
|
||||
)::CHARACTER VARYING AS NAME,
|
||||
(
|
||||
(('L-'::TEXT || contracts.id) || '-'::TEXT) || contract_plans.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,
|
||||
contracts.tax_included,
|
||||
contracts.record_category,
|
||||
contracts.first_party_id,
|
||||
contracts.party_b_id,
|
||||
contract_items.date_range,
|
||||
contracts.status,
|
||||
LOWER(contract_items.date_range) AS start_date,
|
||||
UPPER(contract_items.date_range) - '1 day'::INTERVAL AS end_date
|
||||
FROM
|
||||
contracts
|
||||
JOIN contract_items ON contracts.id = contract_items.id
|
||||
JOIN contract_plans ON contract_plans.id = contract_items.contract_plan_id
|
||||
WHERE
|
||||
contracts.effectiveness::TEXT = '0'::TEXT;
|
Loading…
Reference in New Issue
Block a user