Skip to content

Commit

Permalink
Merge pull request #3566 from bcgov/NDT-319-Add-FNHA-funding-source
Browse files Browse the repository at this point in the history
chore: import fnha funding from sow tab 7
  • Loading branch information
RRanath authored Sep 26, 2024
2 parents ddb3f75 + ab9583c commit 960c72c
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## [1.193.2](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.193.1...v1.193.2) (2024-09-26)

## [1.193.1](https://github.com/bcgov/CONN-CCBC-portal/compare/v1.193.0...v1.193.1) (2024-09-18)

### Bug Fixes
Expand Down
36 changes: 35 additions & 1 deletion app/backend/lib/sow_import/tab_7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const readBudget = async (sow_id, wb, sheet_name) => {
fundingFromAllOtherSources: '',
amountRequestedFromProvince: '',
totalInfrastructureBankFunding: '',
totalFNHAFunding: '',
totalFundingRequestedCCBC: '',
},
detailedBudget: {
Expand Down Expand Up @@ -126,6 +127,13 @@ const readBudget = async (sow_id, wb, sheet_name) => {
2627: '',
total: '',
},
fnhaFunding: {
2324: '',
2425: '',
2526: '',
2627: '',
total: '',
},
otherFundingPartners: [],
totalFinancialContribution: {
2324: '',
Expand Down Expand Up @@ -472,6 +480,7 @@ const readBudget = async (sow_id, wb, sheet_name) => {
budget[row]['K'];
row++;
// next 7 are possible other
let fnhaFundingRow = {};
for (let otherRow = row; otherRow < row + 7; otherRow++) {
const otherSuspect = budget[otherRow]['B'];
let otherValue;
Expand All @@ -483,8 +492,14 @@ const readBudget = async (sow_id, wb, sheet_name) => {
}
// if we don't have the predefined phrase, we have a custom other
if (
otherValue.indexOf('Identify other source of funding by name') === -1
otherValue.indexOf('Identify other source of funding by name') > -1
) {
continue;
} else if (
otherValue.indexOf('First Nations Health Authority (FNHA)') > -1
) {
fnhaFundingRow = budget[otherRow];
} else {
detailedBudget.summaryOfEstimatedProjectFunding.otherFundingPartners.push(
{
fundingPartnersName: budget[otherRow]['B'],
Expand All @@ -497,6 +512,19 @@ const readBudget = async (sow_id, wb, sheet_name) => {
);
}
}

// FNHA Funding
detailedBudget.summaryOfEstimatedProjectFunding.fnhaFunding[2324] =
fnhaFundingRow['G'] ?? 0;
detailedBudget.summaryOfEstimatedProjectFunding.fnhaFunding[2425] =
fnhaFundingRow['H'] ?? 0;
detailedBudget.summaryOfEstimatedProjectFunding.fnhaFunding[2526] =
fnhaFundingRow['I'] ?? 0;
detailedBudget.summaryOfEstimatedProjectFunding.fnhaFunding[2627] =
fnhaFundingRow['J'] ?? 0;
detailedBudget.summaryOfEstimatedProjectFunding.fnhaFunding.total =
fnhaFundingRow['K'] ?? 0;
detailedBudget.summaryTable.totalFNHAFunding = fnhaFundingRow['K'] ?? 0;
}
// get totals
if (value.indexOf('Total Financial Contributions') > -1) {
Expand Down Expand Up @@ -632,6 +660,12 @@ const ValidateData = (data) => {
error: 'Invalid data: Amount CIB will contribute',
});
}
if (typeof data.totalFNHAFunding !== 'number') {
errors.push({
level: 'cell',
error: 'Invalid data: First Nations Health Authority (FNHA)',
});
}
if (typeof data.fundingFromAllOtherSources !== 'number') {
errors.push({
level: 'cell',
Expand Down
5 changes: 4 additions & 1 deletion app/lib/helpers/ccbcSummaryGenerateFormData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ const getSowData = (sowData, baseSowData) => {
cibFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalInfrastructureBankFunding,
fhnaFunding: null,
fhnaFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.totalFNHAFunding,
otherFunding:
sowData?.nodes[0]?.sowTab7SBySowId?.nodes[0]?.jsonData?.summaryTable
?.fundingFromAllOtherSources,
Expand Down Expand Up @@ -203,6 +205,7 @@ const getSowData = (sowData, baseSowData) => {
fundingRequestedCcbc: 'SOW',
applicantAmount: 'SOW',
cibFunding: 'SOW',
fhnaFunding: 'SOW',
otherFunding: 'SOW',
totalProjectBudget: 'SOW',
effectiveStartDate: 'SOW',
Expand Down
221 changes: 211 additions & 10 deletions app/tests/backend/lib/sow_tab_7.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import LoadTab7Data from '../../../backend/lib/sow_import/tab_7';

jest.mock('../../../backend/lib/graphql');

const tab7 = [
const getTab7 = (includesFNHA = false) => [
{ B: 'Universal Broadband Fund' },
{ B: 'Step 7. Detailed Budget' },
{
Expand Down Expand Up @@ -1624,14 +1624,23 @@ const tab7 = [
K: 0,
},
{ B: 'Other Funding Source', G: 1, H: 2, I: 3, J: 4, K: 10 },
{
B: 'Identify other source of funding by name',
G: 0,
H: 0,
I: 0,
J: 0,
K: 0,
},
includesFNHA
? {
B: 'First Nations Health Authority (FNHA)',
G: 10000,
H: 25000,
I: 35000,
J: 10000,
K: 80000,
}
: {
B: 'Identify other source of funding by name',
G: 0,
H: 0,
I: 0,
J: 0,
K: 0,
},
{
B: 'Identify other source of funding by name',
G: 0,
Expand Down Expand Up @@ -1735,6 +1744,9 @@ const tab7 = [
},
];

const tab7 = getTab7();
const tab7WithFNHA = getTab7(true);

describe('sow tab 7 tests', () => {
beforeEach(() => {
mocked(performQuery).mockImplementation(async () => {
Expand Down Expand Up @@ -1762,6 +1774,7 @@ describe('sow tab 7 tests', () => {
amountRequestedFromProvince: 225000,
totalInfrastructureBankFunding: 0,
totalFundingRequestedCCBC: 450000,
totalFNHAFunding: 0,
},
detailedBudget: {
federalSharingRatio: 0.45,
Expand Down Expand Up @@ -1838,6 +1851,13 @@ describe('sow tab 7 tests', () => {
'2627': 25000,
total: 225000,
},
fnhaFunding: {
'2324': 0,
'2425': 0,
'2526': 0,
'2627': 0,
total: 0,
},
infrastructureBankFunding: {
'2324': 0,
'2425': 0,
Expand Down Expand Up @@ -1915,14 +1935,15 @@ describe('sow tab 7 tests', () => {
});

it('should parse the worksheet and return expected errors', async () => {
const broken = { ...tab7 };
const broken = structuredClone(tab7WithFNHA);
broken[23]['H'] = 'garbage'; // Total Eligible Costs
broken[24]['H'] = 'garbage'; // Total Ineligible Costs
broken[25]['H'] = 'garbage'; // Total Project Cost
broken[27]['H'] = 'garbage'; // Amount requested from the Federal Governmentt
broken[27]['J'] = 'garbage'; // Amount requested from the Province
broken[28]['H'] = 'garbage'; // Amount Applicant will contribute
broken[28]['J'] = 'garbage'; // Amount CIB will contribute
broken[1088]['K'] = 'garbage'; // Total FNHA Contributions
broken[29]['H'] = 'garbage'; // Funding from all other sources
broken[29]['J'] = 'garbage'; // Total requested from the CCBC Program

Expand All @@ -1944,6 +1965,10 @@ describe('sow tab 7 tests', () => {
error: 'Invalid data: Amount Applicant will contribute',
},
{ level: 'cell', error: 'Invalid data: Amount CIB will contribute' },
{
level: 'cell',
error: 'Invalid data: First Nations Health Authority (FNHA)',
},
{
level: 'cell',
error: 'Invalid data: Funding from all other sources',
Expand All @@ -1961,6 +1986,182 @@ describe('sow tab 7 tests', () => {
expect(data).toEqual(expectedError);
});

it('should parse the worksheet and return fnha funding figures', async () => {
const expectedInput = {
input: {
sowId: 1,
jsonData: {
summaryTable: {
targetingVeryRemoteOrIndigenousOrSatelliteDependentCommunity: false,
totalEligibleCosts: 500000,
totalIneligibleCosts: 250000,
totalProjectCost: 750000,
amountRequestedFromFederalGovernment: 225000,
totalApplicantContribution: 300000,
fundingFromAllOtherSources: 225000,
amountRequestedFromProvince: 225000,
totalInfrastructureBankFunding: 0,
totalFundingRequestedCCBC: 450000,
totalFNHAFunding: 80000,
},
detailedBudget: {
federalSharingRatio: 0.45,
provincialSharingRatio: 0.45,
},
summaryOfEstimatedProjectCosts: {
estimatedProjectCosts: {
eligibleRuralBroadband: 500000,
eligibleVeryRemoteSatelliteIndigenousBroadband: 0,
eligibleMobile: 0,
totalEligibleCosts: 500000,
totalIneligibleCosts: 250000,
totalProjectCost: '',
},
totalCostsPerCostCategory: {
directLabour: { cost: 80000, percentOfTotalEligibleCosts: 0.16 },
directEquipment: {
cost: 140000,
percentOfTotalEligibleCosts: 0.28,
},
directMaterials: {
cost: 180000,
percentOfTotalEligibleCosts: 0.36,
},
directSatellite: { cost: 0, percentOfTotalEligibleCosts: 0 },
directTravel: { cost: 0, percentOfTotalEligibleCosts: 0 },
directOther: { cost: 100000, percentOfTotalEligibleCosts: 0.2 },
totalEligible: { cost: 500000, percentOfTotalEligibleCosts: 1 },
},
thirtyPercentOfTotalEligibleCosts: 150000,
projectCosts: {
totalEligibleCosts: {
'2324': 100000,
'2425': 150000,
'2526': 150000,
'2627': 100000,
total: 500000,
},
totalIneligibleCosts: {
'2324': 50000,
'2425': 100000,
'2526': 100000,
'2627': 0,
total: 250000,
},
totalProjectCost: {
'2324': 100000,
'2425': 0.2,
'2526': undefined,
'2627': undefined,
total: undefined,
},
},
},
summaryOfEstimatedProjectFunding: {
federalContribution: {
'2324': 0,
'2425': 75000,
'2526': 75000,
'2627': 75000,
total: 225000,
},
applicationContribution: {
'2324': 125000,
'2425': 100000,
'2526': 75000,
'2627': 0,
total: 300000,
},
provincialContribution: {
'2324': 25000,
'2425': 75000,
'2526': 100000,
'2627': 25000,
total: 225000,
},
fnhaFunding: {
'2324': 10000,
'2425': 25000,
'2526': 35000,
'2627': 10000,
total: 80000,
},
infrastructureBankFunding: {
'2324': 0,
'2425': 0,
'2526': 0,
'2627': 0,
total: 0,
},
otherFundingPartners: [
{
'2324': 1,
'2425': 2,
'2526': 3,
'2627': 4,
fundingPartnersName: 'Other Funding Source',
total: 10,
},
],
totalFinancialContribution: {
'2324': 150001,
'2425': 250002,
'2526': 250003,
'2627': 100004,
total: 750010,
},
},
currentFiscalProvincialContributionForecastByQuarter: {
aprilToJune: {
'2324': 0,
'2425': 18750,
'2526': 25000,
'2627': 8333.333333333334,
total: 52083.333333333336,
},
julyToSeptember: {
'2324': 8333.333333333334,
'2425': 18750,
'2526': 25000,
'2627': 8333.333333333334,
total: 60416.66666666667,
},
octoberToDecember: {
'2324': 8333.333333333334,
'2425': 18750,
'2526': 25000,
'2627': 8333.333333333334,
total: 60416.66666666667,
},
januaryToMarch: {
'2324': 8333.333333333334,
'2425': 18750,
'2526': 25000,
'2627': undefined,
total: 52083.333333333336,
},
fiscalYearTotal: {
'2324': 25000,
'2425': 75000,
'2526': 100000,
'2627': 25000,
total: 225000,
},
},
},
},
};
jest.spyOn(XLSX.utils, 'sheet_to_json').mockReturnValue(tab7WithFNHA);
const wb = XLSX.read(null);

await LoadTab7Data(1, wb, '7', request);
expect(performQuery).toHaveBeenCalledWith(
expect.anything(),
expectedInput,
expect.anything()
);
});

afterEach(() => {
jest.clearAllMocks();
});
Expand Down
1 change: 1 addition & 0 deletions db/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,4 @@ tables/cbc_data_003_include_change_reason 2024-09-04T15:14:09Z Anthony Bushara <
computed_columns/cbc_history 2024-09-03T15:16:07Z Anthony Bushara <anthony@button.is> # Computed column to get application history on cbc project
@1.193.0 2024-09-16T23:48:28Z CCBC Service Account <ccbc@button.is> # release v1.193.0
@1.193.1 2024-09-18T15:03:37Z CCBC Service Account <ccbc@button.is> # release v1.193.1
@1.193.2 2024-09-26T16:15:41Z CCBC Service Account <ccbc@button.is> # release v1.193.2
Loading

0 comments on commit 960c72c

Please sign in to comment.