Spaces:
Runtime error
Runtime error
| import { Injectable } from '@nestjs/common'; | |
| () | |
| export class ParserService { | |
| parseInvoice(text: string) { | |
| const invoiceNumber = text.match(/invoice\s*#?\s*([A-Z0-9-]+)/i); | |
| const total = text.match(/total\s*[:$]?\s*([0-9.]+)/i); | |
| const subtotal = text.match(/subtotal\s*[:$]?\s*([0-9.]+)/i); | |
| const tax = text.match(/tax\s*[:$]?\s*([0-9.]+)/i); | |
| const date = text.match(/\d{1,2}\/\d{1,2}\/\d{2,4}/); | |
| return { | |
| vendor_name: text.split('\n')[0], | |
| invoice_number: invoiceNumber?.[1] || null, | |
| invoice_date: date ? new Date(date[0]) : null, | |
| subtotal: subtotal ? parseFloat(subtotal[1]) : null, | |
| tax: tax ? parseFloat(tax[1]) : null, | |
| total: total ? parseFloat(total[1]) : null, | |
| currency: 'USD', | |
| }; | |
| } | |
| } |