UNPKG

mindee

Version:

Mindee Client Library for Node.js

117 lines (116 loc) 4.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReceiptV5Document = void 0; const common_1 = require("../../parsing/common"); const receiptV5LineItem_1 = require("./receiptV5LineItem"); const standard_1 = require("../../parsing/standard"); /** * Receipt API version 5.4 document data. */ class ReceiptV5Document { constructor(rawPrediction, pageId) { /** List of all line items on the receipt. */ this.lineItems = []; /** List of company registration numbers associated to the supplier. */ this.supplierCompanyRegistrations = []; this.category = new standard_1.ClassificationField({ prediction: rawPrediction["category"], }); this.date = new standard_1.DateField({ prediction: rawPrediction["date"], pageId: pageId, }); this.documentType = new standard_1.ClassificationField({ prediction: rawPrediction["document_type"], }); rawPrediction["line_items"] && rawPrediction["line_items"].map((itemPrediction) => this.lineItems.push(new receiptV5LineItem_1.ReceiptV5LineItem({ prediction: itemPrediction, pageId: pageId, }))); this.locale = new standard_1.LocaleField({ prediction: rawPrediction["locale"], }); this.receiptNumber = new standard_1.StringField({ prediction: rawPrediction["receipt_number"], pageId: pageId, }); this.subcategory = new standard_1.ClassificationField({ prediction: rawPrediction["subcategory"], }); this.supplierAddress = new standard_1.StringField({ prediction: rawPrediction["supplier_address"], pageId: pageId, }); rawPrediction["supplier_company_registrations"] && rawPrediction["supplier_company_registrations"].map((itemPrediction) => this.supplierCompanyRegistrations.push(new standard_1.CompanyRegistrationField({ prediction: itemPrediction, pageId: pageId, }))); this.supplierName = new standard_1.StringField({ prediction: rawPrediction["supplier_name"], pageId: pageId, }); this.supplierPhoneNumber = new standard_1.StringField({ prediction: rawPrediction["supplier_phone_number"], pageId: pageId, }); this.taxes = new standard_1.Taxes().init(rawPrediction["taxes"], pageId); this.time = new standard_1.StringField({ prediction: rawPrediction["time"], pageId: pageId, }); this.tip = new standard_1.AmountField({ prediction: rawPrediction["tip"], pageId: pageId, }); this.totalAmount = new standard_1.AmountField({ prediction: rawPrediction["total_amount"], pageId: pageId, }); this.totalNet = new standard_1.AmountField({ prediction: rawPrediction["total_net"], pageId: pageId, }); this.totalTax = new standard_1.AmountField({ prediction: rawPrediction["total_tax"], pageId: pageId, }); } /** * Default string representation. */ toString() { const supplierCompanyRegistrations = this.supplierCompanyRegistrations.join("\n "); let lineItemsSummary = ""; if (this.lineItems && this.lineItems.length > 0) { const lineItemsColSizes = [38, 10, 14, 12]; lineItemsSummary += "\n" + (0, common_1.lineSeparator)(lineItemsColSizes, "-") + "\n "; lineItemsSummary += "| Description "; lineItemsSummary += "| Quantity "; lineItemsSummary += "| Total Amount "; lineItemsSummary += "| Unit Price "; lineItemsSummary += "|\n" + (0, common_1.lineSeparator)(lineItemsColSizes, "="); lineItemsSummary += this.lineItems.map((item) => "\n " + item.toTableLine() + "\n" + (0, common_1.lineSeparator)(lineItemsColSizes, "-")).join(""); } const outStr = `:Expense Locale: ${this.locale} :Purchase Category: ${this.category} :Purchase Subcategory: ${this.subcategory} :Document Type: ${this.documentType} :Purchase Date: ${this.date} :Purchase Time: ${this.time} :Total Amount: ${this.totalAmount} :Total Net: ${this.totalNet} :Total Tax: ${this.totalTax} :Tip and Gratuity: ${this.tip} :Taxes: ${this.taxes} :Supplier Name: ${this.supplierName} :Supplier Company Registrations: ${supplierCompanyRegistrations} :Supplier Address: ${this.supplierAddress} :Supplier Phone Number: ${this.supplierPhoneNumber} :Receipt Number: ${this.receiptNumber} :Line Items: ${lineItemsSummary}`.trimEnd(); return (0, common_1.cleanOutString)(outStr); } } exports.ReceiptV5Document = ReceiptV5Document;