Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #2332 - fix audit report expenditures #2333

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,179 @@ describe('audit report generation', () => {
];
expect(headers[1]).to.equal(headersExpected[1]);
});

it('getRecordsByProject should group with a mapping', async () => {
const records = [
{
type: 'awards50k',
subcategory: 'Subcategory 1',
upload: {
filename: 'filename.xlsm',
created_at: '2023-07-13T02:24:07.848Z',
reporting_period_id: 1,
user_id: 1,
agency_id: 0,
validated_at: '2023-07-13T02:24:08.252Z',
validated_by: 1,
ec_code: '1.00',
tenant_id: 1,
id: '601a2011-91d5-4acb-b83e-f47ee8ae462f',
notes: null,
invalidated_at: null,
invalidated_by: null,
created_by: '[email protected]',
agency_code: 'USDR',
},
content: {
Recipient_UEI__c: 'TEST-UEI',
Recipient_EIN__c: 'TEST-EIN',
Entity_Type_2__c: 'Contractor',
Project_Identification_Number__c: 'ProjectID 1',
Award_No__c: 'AWARD 1',
Award_Type__c: 'Contract',
Award_Amount__c: 300000,
Award_Date__c: '2022-03-29T04:00:00.000Z',
Primary_Sector__c: 'Sector',
Purpose_of_Funds__c: 'A sample fund',
Period_of_Performance_Start__c: '2022-02-01T05:00:00.000Z',
Period_of_Performance_End__c: '2022-08-31T04:00:00.000Z',
Place_of_Performance_Address_1__c: '',
Place_of_Performance_Address_2__c: '',
Place_of_Performance_City__c: '',
State_Abbreviated__c: '',
Place_of_Performance_Zip__c: '',
Description__c: 'Sample description',
Subaward_Changed__c: 'No',
},
},
{
type: 'awards50k',
subcategory: 'Subcategory 2',
upload: {
filename: 'filename.xlsm',
created_at: '2023-07-13T02:24:07.848Z',
reporting_period_id: 1,
user_id: 1,
agency_id: 0,
validated_at: '2023-07-13T02:24:08.252Z',
validated_by: 1,
ec_code: '1.00',
tenant_id: 1,
id: '601a2011-91d5-4acb-b83e-f47ee8ae462f',
notes: null,
invalidated_at: null,
invalidated_by: null,
created_by: '[email protected]',
agency_code: 'USDR',
},
content: {
Recipient_UEI__c: 'TEST-UEI2',
Recipient_EIN__c: 'TEST-EIN2',
Entity_Type_2__c: 'Contractor',
Project_Identification_Number__c: 'ProjectID 2',
Award_No__c: 'AWARD 2',
Award_Type__c: 'Contract',
Award_Amount__c: 300000,
Award_Date__c: '2022-03-29T04:00:00.000Z',
Primary_Sector__c: 'Sector',
Purpose_of_Funds__c: 'A sample fund',
Period_of_Performance_Start__c: '2022-02-01T05:00:00.000Z',
Period_of_Performance_End__c: '2022-08-31T04:00:00.000Z',
Place_of_Performance_Address_1__c: '',
Place_of_Performance_Address_2__c: '',
Place_of_Performance_City__c: '',
State_Abbreviated__c: '',
Place_of_Performance_Zip__c: '',
Description__c: 'Sample description',
Subaward_Changed__c: 'No',
},
},
{
type: 'expenditures50k',
subcategory: 'Subcategory',
upload: {
filename: 'filename.xlsm',
created_at: '2023-07-13T02:24:07.848Z',
reporting_period_id: 2,
user_id: 1,
agency_id: 0,
validated_at: '2023-07-13T02:24:08.252Z',
validated_by: 1,
ec_code: '2.32',
tenant_id: 1,
id: '601a2011-91d5-4acb-b83e-f47ee8ae462f',
notes: null,
invalidated_at: null,
invalidated_by: null,
created_by: '[email protected]',
agency_code: 'USDR',
},
content: {
Sub_Award_Lookup__c: 'AWARD 1',
Expenditure_Start__c: '2022-03-04T05:00:00.000Z',
Expenditure_End__c: '2022-03-29T04:00:00.000Z',
Expenditure_Amount__c: 150000,
},
},
{
type: 'expenditures50k',
subcategory: '2.32-Business Incubators and Start-Up or Expansion Assistance',
upload: {
filename: 'filename.xlsm',
created_at: '2023-07-13T02:24:07.848Z',
reporting_period_id: 2,
user_id: 1,
agency_id: 0,
validated_at: '2023-07-13T02:24:08.252Z',
validated_by: 1,
ec_code: '2.32',
tenant_id: 1,
id: '601a2011-91d5-4acb-b83e-f47ee8ae462f',
notes: null,
invalidated_at: null,
invalidated_by: null,
created_by: '[email protected]',
agency_code: 'USDR',
},
content: {
Sub_Award_Lookup__c: 'AWARD 2',
Expenditure_Start__c: '2022-03-04T05:00:00.000Z',
Expenditure_End__c: '2022-03-29T04:00:00.000Z',
Expenditure_Amount__c: 150000,
},
},
// different filename to test missing
{
type: 'expenditures50k',
subcategory: '2.32-Business Incubators and Start-Up or Expansion Assistance',
upload: {
filename: 'filename2.xlsm',
created_at: '2023-07-13T02:24:07.848Z',
reporting_period_id: 2,
user_id: 1,
agency_id: 0,
validated_at: '2023-07-13T02:24:08.252Z',
validated_by: 1,
ec_code: '2.32',
tenant_id: 1,
id: '601a2011-91d5-4acb-b83e-f47ee8ae462f',
notes: null,
invalidated_at: null,
invalidated_by: null,
created_by: '[email protected]',
agency_code: 'USDR',
},
content: {
Sub_Award_Lookup__c: 'AWARD 2',
Expenditure_Start__c: '2022-03-04T05:00:00.000Z',
Expenditure_End__c: '2022-03-29T04:00:00.000Z',
Expenditure_Amount__c: 150000,
},
},
];
const groups = audit_report.getRecordsByProject(records);
expect(groups['ProjectID 1'].length).to.equal(2);
expect(groups['ProjectID 2'].length).to.equal(2);
expect(groups['MISSING PROJECT'].length).to.equal(1);
});
});
24 changes: 23 additions & 1 deletion packages/server/src/arpa_reporter/lib/audit-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,26 @@ async function createProjectSummaries(periodId, domain, tenantId, logger = log)
}

function getRecordsByProject(records) {
// the expenditures50k tab does not have a project id, but we can pull that
// information using the awards50k tab and make a mapping from subaward -> project.
// the expenditures50k has subawards, so that then gets used to map to project.
// missing info is indicated with a MISSING PROJECT
const subawardProjectMap = records.filter((x) => x.type === 'awards50k').reduce((map, value) => {
if (!(value.upload.filename in map)) {
map[value.upload.filename] = {};
}
map[value.upload.filename][value.content.Award_No__c] = value.content.Project_Identification_Number__c;
return map;
}, {});
return records.reduce((groupByProject, item) => {
const project = item.content.Project_Identification_Number__c;
let project = item.content.Project_Identification_Number__c;
if (item.type === 'expenditures50k' && project == null) {
const subawardMap = subawardProjectMap[item.upload.filename];
if (subawardMap != null) {
project = subawardMap[item.content.Sub_Award_Lookup__c];
}
}
project = project ?? 'MISSING PROJECT';
const group = (groupByProject[project] || []);
group.push(item);
groupByProject[project] = group;
Expand Down Expand Up @@ -265,6 +283,7 @@ async function createReportsGroupedByProject(periodId, tenantId, dateFormat = RE
const projectLogger = logger.child({
project: { id: projectId, totalRecords: projectRecords.length },
});

projectLogger.debug('populating row from records in project');

// set values for columns that are common across all records of projectId
Expand Down Expand Up @@ -568,6 +587,9 @@ module.exports = {
processSQSMessageRequest,
sendEmailWithLink,
createHeadersProjectSummariesV2,

// export for testing
getRecordsByProject,
};

// NOTE: This file was copied from src/server/lib/audit-report.js (git @ ada8bfdc98) in the arpa-reporter repo on 2022-09-23T20:05:47.735Z
Loading