Done ticket GEPAFINBE-194

This commit is contained in:
nisha
2025-03-27 13:08:32 +05:30
parent 3b5bc00502
commit 4958dd549c
14 changed files with 450 additions and 32 deletions

View File

@@ -2675,4 +2675,9 @@
</insert>
</changeSet>
<changeSet id="25-03-2025_NK_160730" author="Nisha Kashyap">
<sqlFile dbms="postgresql"
path="db/dump/create_application_view.sql"/>
</changeSet>
</databaseChangeLog>

View File

@@ -13,10 +13,13 @@
BEGIN
-- Loop through all tables in the schema that have the 'updated_date' column
FOR r IN (
SELECT table_name
FROM information_schema.columns
WHERE column_name = 'updated_date'
AND table_schema = 'gepafin_schema'
SELECT c.table_name
FROM information_schema.columns c
JOIN information_schema.tables t
ON c.table_name = t.table_name AND c.table_schema = t.table_schema
WHERE c.column_name = 'updated_date'
AND c.table_schema = 'gepafin_schema'
AND t.table_type = 'BASE TABLE' -- Excludes views
)
LOOP
EXECUTE format(
@@ -30,10 +33,13 @@
-- Loop through all tables in the schema that have the 'created_date' column
FOR r IN (
SELECT table_name
FROM information_schema.columns
WHERE column_name = 'created_date'
AND table_schema = 'gepafin_schema'
SELECT c.table_name
FROM information_schema.columns c
JOIN information_schema.tables t
ON c.table_name = t.table_name AND c.table_schema = t.table_schema
WHERE c.column_name = 'created_date'
AND c.table_schema = 'gepafin_schema'
AND t.table_type = 'BASE TABLE' -- Excludes views
)
LOOP
EXECUTE format(

View File

@@ -0,0 +1,81 @@
CREATE OR REPLACE VIEW application_view AS
SELECT
a.id,
a.status,
a.submission_date,
a.comments,
a.amount_requested,
a.amount_accepted,
a.date_accepted,
a.date_rejected,
a.is_deleted,
a.hub_id,
a.user_id,
a.evaluation_version AS evaluation_version,
a.updated_date AS modified_date,
a.created_date AS created_date,
-- Call Details
a.call_id AS call_id,
cl.name AS call_title,
cl.end_date AS call_end_date,
cl.end_time AS call_end_time,
-- Company Details
a.COMPANY_ID AS company_id,
c.company_name AS company_name,
-- Protocol Details
p.protocol_number AS protocol_number,
-- Assigned User Details from ASSIGNED_APPLICATION and GEPPAFIN_USER
COALESCE(aa.user_id, NULL) AS assigned_user_id,
COALESCE(
NULLIF(
TRIM(CONCAT(
COALESCE(u.first_name, ''), ' ',
COALESCE(u.last_name, '')
)),
''
),
''
) AS assigned_user_name,
-- User with Company Details (From Application's User)
COALESCE(uwc.id, NULL) AS user_with_company_id
FROM gepafin_schema.APPLICATION a
-- Join Call Entity
LEFT JOIN gepafin_schema.CALL cl
ON a.CALL_ID = cl.id
-- Join Company Entity (Ensuring it is not deleted)
LEFT JOIN gepafin_schema.COMPANY c
ON a.COMPANY_ID = c.id
-- Join Protocol Entity
LEFT JOIN gepafin_schema.PROTOCOL p
ON a.PROTOCOL_NUMBER = p.id
-- Join Assigned Application Entity (Ensuring it is not deleted)
LEFT JOIN gepafin_schema.assigned_applications aa
ON a.id = aa.APPLICATION_ID
AND (aa.IS_DELETED IS FALSE OR aa.IS_DELETED IS NULL)
-- Join User Entity (Get First & Last Name Combined)
LEFT JOIN gepafin_schema.GEPAFIN_USER u
ON aa.user_id = u.id
-- Get User With Company ID (From Application's User & Company)
LEFT JOIN gepafin_schema.USER_WITH_COMPANY uwc
ON a.user_id = uwc.user_id
AND a.COMPANY_ID = uwc.company_id
AND uwc.is_deleted = FALSE -- Ensuring the user is active
WHERE a.IS_DELETED IS FALSE OR a.IS_DELETED IS NULL;