/
formatReport.js
executable file
·62 lines (53 loc) · 1.62 KB
/
formatReport.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
"use strict"
const path = require('path');
const fs = require('fs');
const os = require('os');
const {
info,
warn,
error
} = require('@pingleware/bestbooks-core');
const report_list = {
balanceSheet: "balance-sheet.xslt",
customerEstimate: "customer-estimate.xslt",
incomeStatement: "income-statement.xslt",
purchaseOrder: "purchase-order.xslt",
statementChangeInEquity: "statement-in-change-in-equity.xslt",
statementCashFlows: "statement-of-cash-flows.xslt",
trialBalance: "trial-balance.xslt",
retainedEarnings: "retained-earnings.xslt"
};
function getReportFileName(reportName) {
return report_list[reportName];
}
function getReportRootFileName(reportName) {
return report_list[reportName].split(".")[0];
}
function transform_xml_xslt(xml_content, xslt_content) {
const {xsltProcess, xmlParse} = require('xslt-processor');
return xsltProcess(xmlParse(xml_content),xmlParse(xslt_content.toString()));
}
function format(reportName,formattedData) {
try {
if (report_list[reportName]) {
var xsltString = fs.readFileSync(path.join(os.homedir(),`.bestbooks/${report_list[reportName]}`));
return transform_xml_xslt(formattedData,xsltString);
} else {
// report does not exist?
}
} catch(err) {
//console.error(formattedData)
console.error(err);
}
}
function array2xml(topLevel, obj) {
const js2xmlparser = require("js2xmlparser");
return js2xmlparser.parse(topLevel, obj)
}
module.exports = {
getReportFileName,
getReportRootFileName,
transform_xml_xslt,
format,
array2xml
}