UNPKG

mindee

Version:

Mindee Client Library for Node.js

145 lines (144 loc) 6.05 kB
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _InvoiceV4LineItem_instances, _InvoiceV4LineItem_printableValues; Object.defineProperty(exports, "__esModule", { value: true }); exports.InvoiceV4LineItem = void 0; const common_1 = require("../../parsing/common"); const geometry_1 = require("../../geometry"); /** * List of all the line items present on the invoice. */ class InvoiceV4LineItem { constructor({ prediction = {} }) { _InvoiceV4LineItem_instances.add(this); /** Confidence score */ this.confidence = 0.0; /** * Contains the relative vertices coordinates (points) of a polygon containing * the field in the document. */ this.polygon = new geometry_1.Polygon(); this.description = prediction["description"]; this.productCode = prediction["product_code"]; if (prediction["quantity"] !== undefined && prediction["quantity"] !== null && !isNaN(prediction["quantity"])) { this.quantity = +parseFloat(prediction["quantity"]); } else { this.quantity = null; } if (prediction["tax_amount"] !== undefined && prediction["tax_amount"] !== null && !isNaN(prediction["tax_amount"])) { this.taxAmount = +parseFloat(prediction["tax_amount"]); } else { this.taxAmount = null; } if (prediction["tax_rate"] !== undefined && prediction["tax_rate"] !== null && !isNaN(prediction["tax_rate"])) { this.taxRate = +parseFloat(prediction["tax_rate"]); } else { this.taxRate = null; } if (prediction["total_amount"] !== undefined && prediction["total_amount"] !== null && !isNaN(prediction["total_amount"])) { this.totalAmount = +parseFloat(prediction["total_amount"]); } else { this.totalAmount = null; } this.unitMeasure = prediction["unit_measure"]; if (prediction["unit_price"] !== undefined && prediction["unit_price"] !== null && !isNaN(prediction["unit_price"])) { this.unitPrice = +parseFloat(prediction["unit_price"]); } else { this.unitPrice = null; } this.pageId = prediction["page_id"]; this.confidence = prediction["confidence"] ? prediction.confidence : 0.0; if (prediction["polygon"]) { this.polygon = prediction.polygon; } } /** * Default string representation. */ toString() { const printable = __classPrivateFieldGet(this, _InvoiceV4LineItem_instances, "m", _InvoiceV4LineItem_printableValues).call(this); return ("Description: " + printable.description + ", Product code: " + printable.productCode + ", Quantity: " + printable.quantity + ", Tax Amount: " + printable.taxAmount + ", Tax Rate (%): " + printable.taxRate + ", Total Amount: " + printable.totalAmount + ", Unit of measure: " + printable.unitMeasure + ", Unit Price: " + printable.unitPrice); } /** * Output in a format suitable for inclusion in an rST table. */ toTableLine() { const printable = __classPrivateFieldGet(this, _InvoiceV4LineItem_instances, "m", _InvoiceV4LineItem_printableValues).call(this); return ("| " + printable.description.padEnd(36) + " | " + printable.productCode.padEnd(12) + " | " + printable.quantity.padEnd(8) + " | " + printable.taxAmount.padEnd(10) + " | " + printable.taxRate.padEnd(12) + " | " + printable.totalAmount.padEnd(12) + " | " + printable.unitMeasure.padEnd(15) + " | " + printable.unitPrice.padEnd(10) + " |"); } } exports.InvoiceV4LineItem = InvoiceV4LineItem; _InvoiceV4LineItem_instances = new WeakSet(), _InvoiceV4LineItem_printableValues = function _InvoiceV4LineItem_printableValues() { return { description: this.description ? this.description.length <= 36 ? (0, common_1.cleanSpecialChars)(this.description) : (0, common_1.cleanSpecialChars)(this.description).slice(0, 33) + "..." : "", productCode: this.productCode ? this.productCode.length <= 12 ? (0, common_1.cleanSpecialChars)(this.productCode) : (0, common_1.cleanSpecialChars)(this.productCode).slice(0, 9) + "..." : "", quantity: this.quantity !== undefined ? (0, common_1.floatToString)(this.quantity) : "", taxAmount: this.taxAmount !== undefined ? (0, common_1.floatToString)(this.taxAmount) : "", taxRate: this.taxRate !== undefined ? (0, common_1.floatToString)(this.taxRate) : "", totalAmount: this.totalAmount !== undefined ? (0, common_1.floatToString)(this.totalAmount) : "", unitMeasure: this.unitMeasure ? this.unitMeasure.length <= 15 ? (0, common_1.cleanSpecialChars)(this.unitMeasure) : (0, common_1.cleanSpecialChars)(this.unitMeasure).slice(0, 12) + "..." : "", unitPrice: this.unitPrice !== undefined ? (0, common_1.floatToString)(this.unitPrice) : "", }; };