-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathreportBuilder.js
106 lines (93 loc) · 3.17 KB
/
reportBuilder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const PROJECT_DATA = 'Project Information';
/**
* @typedef ProjectData
* @type {object}
* @property {number} amountSpent - total expenditure
* @property {string} category - arpa expenditure category e.g. '1.5-Personal Protective Equipment'
* @property {string} description - text description of the project
* @property {string} name - project name
* @property {string} recipient - organization which ran this project
* @property {string} website
* @property {string} impactStatement - the impact statement we're generating based off their data
*/
/**
* Pulls the information relevant to the docx generator out of the excel workbook
* @param book
* @returns {ProjectData}
*/
const genericTemplateParser = (book) => {
const projectSheet = book.Sheets[PROJECT_DATA];
const impactSheet = book.Sheets['Impact Statement'];
// This is the editable one, and should be preferred
const editableImpactStatement = impactSheet.E16;
let impactStatement;
if (editableImpactStatement) {
impactStatement = editableImpactStatement.v;
} else {
impactStatement = impactSheet.E8.v;
}
return {
name: projectSheet.C9.v,
recipient: projectSheet.C10.v,
category: projectSheet.C19.v,
description: projectSheet.C21.v,
amountSpent: projectSheet.C17.v,
website: projectSheet.C24.v,
impactStatement,
};
};
/**
* Pulls the information relevant to the docx generator out of the excel workbook
* @param book
* @returns {ProjectData}
*/
const tulsaTemplateParser = (book) => {
const projectSheet = book.Sheets[PROJECT_DATA];
const impactSheet = book.Sheets['Impact Statement'];
// This is the editable one, and should be preferred
const editableImpactStatement = impactSheet.E16;
let impactStatement;
if (editableImpactStatement) {
impactStatement = editableImpactStatement.v;
} else {
impactStatement = impactSheet.E8.v;
}
return {
name: projectSheet.C9.v,
recipient: projectSheet.C10.v,
// All of Tulsa's programs fall into EC 6
category: '6 - Revenue Replacement',
description: '', // not on Tulsa's template
amountSpent: projectSheet.C18.v, // Differs between templates
website: '', // not on Tulsa's template
impactStatement,
};
};
/**
*
* @param book
* @param fullAnnualData {{
* category: {
* totalExpenditure: int,
* projects: [ProjectData]
* }
* }}
*/
const parseDataFromWorkbook = (book, fullAnnualData) => {
const projectSheet = book.Sheets[PROJECT_DATA];
let projectData;
const isTulsa = !projectSheet.B19;
if (isTulsa) {
projectData = tulsaTemplateParser(book);
} else {
projectData = genericTemplateParser(book);
}
const { category } = projectData;
// I am not at all worried about prototype key collisions in this case
if (!(category in fullAnnualData)) {
fullAnnualData[category] = { totalExpenditure: 0, projects: [] };
}
fullAnnualData[category].totalExpenditure += projectData.amountSpent;
fullAnnualData[category].projects.push(projectData);
};
module.exports = { parseDataFromWorkbook };