-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df396e2
commit 4e1798c
Showing
6 changed files
with
63 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
schema/deploy/computed_columns/form_change_total_project_value_001.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
begin; | ||
|
||
create or replace function cif.form_change_total_project_value(cif.form_change) | ||
returns numeric | ||
as | ||
$computed_column$ | ||
|
||
with additional_funding_sources as | ||
( | ||
select * from jsonb_to_recordset( | ||
(select (new_form_data ->> 'additionalFundingSources') | ||
from cif.form_change fc | ||
where fc.project_revision_id = $1.project_revision_id | ||
and fc.form_data_table_name = 'funding_parameter' | ||
and operation != 'archive' | ||
)::jsonb | ||
) as x(source text, amount numeric, status text) | ||
) | ||
select | ||
case | ||
when | ||
( | ||
($1.new_form_data ->> 'proponentCost')::numeric IS NULL | ||
OR | ||
($1.new_form_data ->> 'maxFundingAmount')::numeric IS NULL | ||
OR | ||
(select sum(amount::numeric) from additional_funding_sources where status = 'Approved') IS NULL | ||
) THEN NULL | ||
else | ||
( | ||
coalesce(($1.new_form_data ->> 'proponentCost')::numeric, 0) | ||
+ | ||
coalesce(($1.new_form_data ->> 'maxFundingAmount')::numeric, 0) | ||
+ | ||
coalesce((select sum(amount::numeric) from additional_funding_sources where status = 'Approved'), 0) | ||
) | ||
end; | ||
$computed_column$ language sql stable; | ||
|
||
grant execute on function cif.form_change_total_project_value to cif_internal, cif_external, cif_admin; | ||
|
||
comment on function cif.form_change_total_project_value is | ||
$$ | ||
Computed column to return the total project value. | ||
Calculation: | ||
- Total Project Value = Maximum Funding Amount + Proponent Cost + approved Additional Funding Amount(s) | ||
Only returns the total project value if all values are present. If any value is missing, returns NULL. | ||
$$; | ||
|
||
commit; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,3 +357,4 @@ functions/handle_milestone_form_change_commit [functions/handle_milestone_form_c | |
@1.13.0 2023-09-05T22:09:47Z Sepehr Sobhani <[email protected]> # release v1.13.0 | ||
tables/attachment_002_delete_permission 2023-07-31T18:06:38Z Brianna Cerkiewicz <briannacerkiewicz@pop-os> # Allow hard deletion of attachments | ||
mutations/discard_project_attachment_form_change [mutations/[email protected]] 2023-07-31T18:05:23Z Brianna Cerkiewicz <briannacerkiewicz@pop-os> # Remove loop from discard mutation | ||
computed_columns/form_change_total_project_value_001 2023-07-21T00:06:15Z Gurjeet Matharu <[email protected]> # Modified cif.form_change_total_project_value function to return null if any input values are missing |
2 changes: 1 addition & 1 deletion
2
[email protected] → ...s/form_change_total_project_value_001.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters