forked from Siemienik/XToolset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimporter.ts
26 lines (20 loc) · 793 Bytes
/
importer.ts
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
import {ImporterFactory} from 'xlsx-import/lib/ImporterFactory';
import {getInvoiceConfig, IBuyer, IItem, IMisc, ISeller} from './configs/invoiceConfig';
const factory = new ImporterFactory();
export const importInvoice = async (invoicePath: string) => {
const config = getInvoiceConfig();
const importer = await factory.from(invoicePath);
const {date, dueDate} = importer.getAllItems<IMisc>(config.misc)[0];
const seller = importer.getAllItems<ISeller>(config.seller)[0];
const buyer = importer.getAllItems<IBuyer>(config.buyer)[0];
const items = importer.getAllItems<IItem>(config.items);
const total = items.reduce((p, c) => p + c.price, 0);
return {
buyer,
date,
dueDate,
items,
seller,
total
};
};