-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract.ts
32 lines (29 loc) · 996 Bytes
/
extract.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
27
28
29
30
31
32
function scanInvoices(): void {
scanInvoiceFolder(invoicesFolder());
}
// TODO: Rename
function scanInvoiceFolder(folder: Folder): void {
const expenseInvoicePatterns = getExpenseInvoicePatterns();
const expenseInvoices = getConvertedExpenseInvoices(folder)
forEach(expenseInvoices, (invoices, expense): void => {
const patterns = expenseInvoicePatterns[expense]
if (!patterns) {
throw `Invoice patterns missing for ${expense}`
}
extractInvoices(invoices, patterns)
})
}
function extractInvoices(invoices: Invoices, patterns: InvoicePatterns): void {
while (invoices.files.hasNext()) {
const invoice = invoices.files.next()
extractInvoice(invoice, patterns)
}
}
function extractInvoice(invoice: File, patterns: InvoicePatterns): void {
// @ts-ignore
console.log('Extracting invoice: %s', invoice.getName())
const text = getDocumentText(invoice.getId())
const date = patterns.matchDate(text)
// @ts-ignore
console.log('Date: %s', date)
}