-
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.
Merge pull request #1815 from bcgov/1802-project-summary-bug
Fix:1802 project summary bug
- Loading branch information
Showing
20 changed files
with
574 additions
and
49 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
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
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
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
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
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
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
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,89 @@ | ||
-- Deploy cif:functions/handle_project_summary_report_form_change_commit to pg | ||
-- requires: tables/form_change | ||
|
||
begin; | ||
|
||
create or replace function cif_private.handle_project_summary_report_form_change_commit(fc cif.form_change) | ||
returns int as $$ | ||
declare | ||
reporting_requirement_record_id int; | ||
begin | ||
-- If there is no change in the form data, return the form_change record and do not touch the associated table. | ||
if (fc.new_form_data = '{}') then | ||
return fc.form_data_record_id; | ||
end if; | ||
|
||
if (fc.change_status = 'committed') then | ||
raise exception 'Cannot commit form_change. It has already been committed.'; | ||
end if; | ||
|
||
if fc.operation = 'create' then | ||
insert into cif.reporting_requirement( | ||
project_id, | ||
report_type, | ||
report_due_date, | ||
submitted_date, | ||
comments, | ||
reporting_requirement_index, | ||
description | ||
) values ( | ||
(select form_data_record_id from cif.form_change pfc where form_data_table_name = 'project' and pfc.project_revision_id = fc.project_revision_id), | ||
(fc.new_form_data->>'reportType'), | ||
(fc.new_form_data->>'reportDueDate')::timestamptz, | ||
(fc.new_form_data->>'submittedDate')::timestamptz, | ||
(fc.new_form_data->>'comments'), | ||
(fc.new_form_data->>'reportingRequirementIndex')::int, | ||
(fc.new_form_data->>'description') | ||
) returning id into reporting_requirement_record_id; | ||
|
||
insert into cif.payment( | ||
reporting_requirement_id, | ||
gross_amount, | ||
net_amount, | ||
date_sent_to_csnr | ||
) values ( | ||
reporting_requirement_record_id, | ||
(fc.new_form_data->>'projectSummaryReportPayment')::numeric, | ||
(fc.new_form_data->>'projectSummaryReportPayment')::numeric, | ||
(fc.new_form_data->>'dateSentToCsnr')::timestamptz | ||
); | ||
|
||
update cif.form_change set form_data_record_id = reporting_requirement_record_id where id = fc.id; | ||
|
||
elsif fc.operation = 'update' then | ||
|
||
update cif.reporting_requirement rr set | ||
report_type = (fc.new_form_data->>'reportType'), | ||
report_due_date = (fc.new_form_data->>'reportDueDate')::timestamptz, | ||
submitted_date = (fc.new_form_data->>'submittedDate')::timestamptz, | ||
comments = (fc.new_form_data->>'comments'), | ||
reporting_requirement_index = (fc.new_form_data->>'reportingRequirementIndex')::int, | ||
description = (fc.new_form_data->>'description') | ||
where rr.id = fc.form_data_record_id; | ||
|
||
update cif.payment py set | ||
gross_amount = (fc.new_form_data->>'projectSummaryReportPayment')::numeric, | ||
net_amount = (fc.new_form_data->>'projectSummaryReportPayment')::numeric, | ||
date_sent_to_csnr = (fc.new_form_data->>'dateSentToCsnr')::timestamptz | ||
where py.reporting_requirement_id = fc.form_data_record_id; | ||
|
||
elsif fc.operation = 'archive' then | ||
|
||
update cif.reporting_requirement set archived_at = now() where id = fc.form_data_record_id; | ||
update cif.payment set archived_at = now() where reporting_requirement_id = fc.form_data_record_id; | ||
|
||
end if; | ||
|
||
return reporting_requirement_record_id; | ||
end; | ||
$$ language plpgsql volatile; | ||
|
||
grant execute on function cif_private.handle_project_summary_report_form_change_commit to cif_internal, cif_external, cif_admin; | ||
|
||
comment on function cif_private.handle_project_summary_report_form_change_commit | ||
is $$ | ||
The custom function used to parse project summary form_change data into table data. | ||
The data within the single form_change record is parsed into the reporting_requirement, and payment tables. | ||
$$; | ||
|
||
commit; |
27 changes: 27 additions & 0 deletions
27
schema/deploy/functions/migration_rebuild_project_summary_report_history.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,27 @@ | ||
-- Deploy cif:migration_rebuild_project_summary_report_history to pg | ||
|
||
begin; | ||
|
||
create or replace function cif_private.migration_rebuild_project_summary_report_history() | ||
returns void as | ||
$migration$ | ||
|
||
with records as ( | ||
select fc1.id as id1,fc1.previous_form_change_id as prfid, fc2.form_data_record_id as fdrid, fc2.id as id2 | ||
from cif.form_change as fc1 | ||
join cif.form_change as fc2 | ||
on fc1.previous_form_change_id=fc2.id | ||
and fc1.json_schema_name='project_summary_report' | ||
) | ||
|
||
update cif.form_change fc set form_data_record_id= | ||
( | ||
select fdrid from records where fc.id=id1 | ||
) | ||
where form_data_record_id is null | ||
and change_status='committed' | ||
and json_schema_name='project_summary_report'; | ||
|
||
$migration$ language sql volatile; | ||
|
||
commit; |
11 changes: 11 additions & 0 deletions
11
schema/deploy/migrations/009_rebuild_project_summary_history.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,11 @@ | ||
-- Deploy cif:migrations/009_rebuild_project_summary_history to pg | ||
|
||
begin; | ||
|
||
alter table cif.form_change disable trigger _100_committed_changes_are_immutable, disable trigger _set_previous_form_change_id, disable trigger _100_timestamps; | ||
|
||
select cif_private.migration_rebuild_project_summary_report_history(); | ||
|
||
alter table cif.form_change enable trigger _100_committed_changes_are_immutable, enable trigger _set_previous_form_change_id, enable trigger _100_timestamps; | ||
|
||
commit; |
Oops, something went wrong.