-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport-data.js
More file actions
executable file
·39 lines (31 loc) · 1.17 KB
/
Copy pathexport-data.js
File metadata and controls
executable file
·39 lines (31 loc) · 1.17 KB
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
const fs = require("fs");
const reader = require("xlsx");
let invoicesSA = [];
let invoicesFee = [];
let receivedPayments = [];
if (!fs.existsSync("./data")) {
fs.mkdirSync("./data");
console.log("----------CREATED DATA DIRECTORY------------");
}
const file = reader.readFile("./qbo.xlsx");
let sheetData = [];
let customers = [];
const sheets = file.SheetNames;
for (let i = 0; i < sheets.length; i++) {
const temp = reader.utils.sheet_to_json(file.Sheets[file.SheetNames[i]]);
sheetData.push(temp);
}
console.log("----------------READING SHEET------------------");
sheetData[0].forEach((row) => {
customers.push({ DisplayName: row.Customer });
invoicesSA.push(row);
});
sheetData[1].forEach((row) => {
invoicesFee.push(row);
});
console.log("------------CREATING CUSTOMERS.JSON------------");
fs.writeFileSync("data/customers.json", JSON.stringify(customers));
console.log("-----------CREATING INVOICES-SA.JSON-----------");
fs.writeFileSync("data/invoices-sa.json", JSON.stringify(invoicesSA));
console.log("-----------CREATING INVOICES-FEE.JSON-----------");
fs.writeFileSync("data/invoices-fee.json", JSON.stringify(invoicesFee));