mindee
Version:
Mindee Client Library for Node.js
192 lines (191 loc) • 8.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvoiceV4Document = void 0;
const common_1 = require("../../parsing/common");
const invoiceV4LineItem_1 = require("./invoiceV4LineItem");
const standard_1 = require("../../parsing/standard");
/**
* Invoice API version 4.11 document data.
*/
class InvoiceV4Document {
constructor(rawPrediction, pageId) {
/** List of company registration numbers associated to the customer. */
this.customerCompanyRegistrations = [];
/** List of all the line items present on the invoice. */
this.lineItems = [];
/** List of all reference numbers on the invoice, including the purchase order number. */
this.referenceNumbers = [];
/** List of company registration numbers associated to the supplier. */
this.supplierCompanyRegistrations = [];
/** List of payment details associated to the supplier of the invoice. */
this.supplierPaymentDetails = [];
this.billingAddress = new standard_1.AddressField({
prediction: rawPrediction["billing_address"],
pageId: pageId,
});
this.category = new standard_1.ClassificationField({
prediction: rawPrediction["category"],
});
this.customerAddress = new standard_1.AddressField({
prediction: rawPrediction["customer_address"],
pageId: pageId,
});
rawPrediction["customer_company_registrations"] &&
rawPrediction["customer_company_registrations"].map((itemPrediction) => this.customerCompanyRegistrations.push(new standard_1.CompanyRegistrationField({
prediction: itemPrediction,
pageId: pageId,
})));
this.customerId = new standard_1.StringField({
prediction: rawPrediction["customer_id"],
pageId: pageId,
});
this.customerName = new standard_1.StringField({
prediction: rawPrediction["customer_name"],
pageId: pageId,
});
this.date = new standard_1.DateField({
prediction: rawPrediction["date"],
pageId: pageId,
});
this.documentType = new standard_1.ClassificationField({
prediction: rawPrediction["document_type"],
});
this.documentTypeExtended = new standard_1.ClassificationField({
prediction: rawPrediction["document_type_extended"],
});
this.dueDate = new standard_1.DateField({
prediction: rawPrediction["due_date"],
pageId: pageId,
});
this.invoiceNumber = new standard_1.StringField({
prediction: rawPrediction["invoice_number"],
pageId: pageId,
});
rawPrediction["line_items"] &&
rawPrediction["line_items"].map((itemPrediction) => this.lineItems.push(new invoiceV4LineItem_1.InvoiceV4LineItem({
prediction: itemPrediction,
pageId: pageId,
})));
this.locale = new standard_1.LocaleField({
prediction: rawPrediction["locale"],
});
this.paymentDate = new standard_1.DateField({
prediction: rawPrediction["payment_date"],
pageId: pageId,
});
this.poNumber = new standard_1.StringField({
prediction: rawPrediction["po_number"],
pageId: pageId,
});
rawPrediction["reference_numbers"] &&
rawPrediction["reference_numbers"].map((itemPrediction) => this.referenceNumbers.push(new standard_1.StringField({
prediction: itemPrediction,
pageId: pageId,
})));
this.shippingAddress = new standard_1.AddressField({
prediction: rawPrediction["shipping_address"],
pageId: pageId,
});
this.subcategory = new standard_1.ClassificationField({
prediction: rawPrediction["subcategory"],
});
this.supplierAddress = new standard_1.AddressField({
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.supplierEmail = new standard_1.StringField({
prediction: rawPrediction["supplier_email"],
pageId: pageId,
});
this.supplierName = new standard_1.StringField({
prediction: rawPrediction["supplier_name"],
pageId: pageId,
});
rawPrediction["supplier_payment_details"] &&
rawPrediction["supplier_payment_details"].map((itemPrediction) => this.supplierPaymentDetails.push(new standard_1.PaymentDetailsField({
prediction: itemPrediction,
pageId: pageId,
})));
this.supplierPhoneNumber = new standard_1.StringField({
prediction: rawPrediction["supplier_phone_number"],
pageId: pageId,
});
this.supplierWebsite = new standard_1.StringField({
prediction: rawPrediction["supplier_website"],
pageId: pageId,
});
this.taxes = new standard_1.Taxes().init(rawPrediction["taxes"], 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 referenceNumbers = this.referenceNumbers.join("\n ");
const supplierPaymentDetails = this.supplierPaymentDetails.join("\n ");
const supplierCompanyRegistrations = this.supplierCompanyRegistrations.join("\n ");
const customerCompanyRegistrations = this.customerCompanyRegistrations.join("\n ");
let lineItemsSummary = "";
if (this.lineItems && this.lineItems.length > 0) {
const lineItemsColSizes = [38, 14, 10, 12, 14, 14, 17, 12];
lineItemsSummary += "\n" + (0, common_1.lineSeparator)(lineItemsColSizes, "-") + "\n ";
lineItemsSummary += "| Description ";
lineItemsSummary += "| Product code ";
lineItemsSummary += "| Quantity ";
lineItemsSummary += "| Tax Amount ";
lineItemsSummary += "| Tax Rate (%) ";
lineItemsSummary += "| Total Amount ";
lineItemsSummary += "| Unit of measure ";
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 = `:Locale: ${this.locale}
:Invoice Number: ${this.invoiceNumber}
:Purchase Order Number: ${this.poNumber}
:Reference Numbers: ${referenceNumbers}
:Purchase Date: ${this.date}
:Due Date: ${this.dueDate}
:Payment Date: ${this.paymentDate}
:Total Net: ${this.totalNet}
:Total Amount: ${this.totalAmount}
:Total Tax: ${this.totalTax}
:Taxes: ${this.taxes}
:Supplier Payment Details: ${supplierPaymentDetails}
:Supplier Name: ${this.supplierName}
:Supplier Company Registrations: ${supplierCompanyRegistrations}
:Supplier Address: ${this.supplierAddress}
:Supplier Phone Number: ${this.supplierPhoneNumber}
:Supplier Website: ${this.supplierWebsite}
:Supplier Email: ${this.supplierEmail}
:Customer Name: ${this.customerName}
:Customer Company Registrations: ${customerCompanyRegistrations}
:Customer Address: ${this.customerAddress}
:Customer ID: ${this.customerId}
:Shipping Address: ${this.shippingAddress}
:Billing Address: ${this.billingAddress}
:Document Type: ${this.documentType}
:Document Type Extended: ${this.documentTypeExtended}
:Purchase Subcategory: ${this.subcategory}
:Purchase Category: ${this.category}
:Line Items: ${lineItemsSummary}`.trimEnd();
return (0, common_1.cleanOutString)(outStr);
}
}
exports.InvoiceV4Document = InvoiceV4Document;