UNPKG

mindee

Version:

Mindee Client Library for Node.js

146 lines (145 loc) 7.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EnergyBillV1Document = void 0; const common_1 = require("../../../parsing/common"); const energyBillV1EnergySupplier_1 = require("./energyBillV1EnergySupplier"); const energyBillV1EnergyConsumer_1 = require("./energyBillV1EnergyConsumer"); const energyBillV1Subscription_1 = require("./energyBillV1Subscription"); const energyBillV1EnergyUsage_1 = require("./energyBillV1EnergyUsage"); const energyBillV1TaxesAndContribution_1 = require("./energyBillV1TaxesAndContribution"); const energyBillV1MeterDetail_1 = require("./energyBillV1MeterDetail"); const standard_1 = require("../../../parsing/standard"); /** * Energy Bill API version 1.2 document data. */ class EnergyBillV1Document { constructor(rawPrediction, pageId) { /** Details of energy consumption. */ this.energyUsage = []; /** The subscription details fee for the energy service. */ this.subscription = []; /** Details of Taxes and Contributions. */ this.taxesAndContributions = []; this.contractId = new standard_1.StringField({ prediction: rawPrediction["contract_id"], pageId: pageId, }); this.deliveryPoint = new standard_1.StringField({ prediction: rawPrediction["delivery_point"], pageId: pageId, }); this.dueDate = new standard_1.DateField({ prediction: rawPrediction["due_date"], pageId: pageId, }); this.energyConsumer = new energyBillV1EnergyConsumer_1.EnergyBillV1EnergyConsumer({ prediction: rawPrediction["energy_consumer"], pageId: pageId, }); this.energySupplier = new energyBillV1EnergySupplier_1.EnergyBillV1EnergySupplier({ prediction: rawPrediction["energy_supplier"], pageId: pageId, }); rawPrediction["energy_usage"] && rawPrediction["energy_usage"].map((itemPrediction) => this.energyUsage.push(new energyBillV1EnergyUsage_1.EnergyBillV1EnergyUsage({ prediction: itemPrediction, pageId: pageId, }))); this.invoiceDate = new standard_1.DateField({ prediction: rawPrediction["invoice_date"], pageId: pageId, }); this.invoiceNumber = new standard_1.StringField({ prediction: rawPrediction["invoice_number"], pageId: pageId, }); this.meterDetails = new energyBillV1MeterDetail_1.EnergyBillV1MeterDetail({ prediction: rawPrediction["meter_details"], pageId: pageId, }); rawPrediction["subscription"] && rawPrediction["subscription"].map((itemPrediction) => this.subscription.push(new energyBillV1Subscription_1.EnergyBillV1Subscription({ prediction: itemPrediction, pageId: pageId, }))); rawPrediction["taxes_and_contributions"] && rawPrediction["taxes_and_contributions"].map((itemPrediction) => this.taxesAndContributions.push(new energyBillV1TaxesAndContribution_1.EnergyBillV1TaxesAndContribution({ prediction: itemPrediction, pageId: pageId, }))); this.totalAmount = new standard_1.AmountField({ prediction: rawPrediction["total_amount"], pageId: pageId, }); this.totalBeforeTaxes = new standard_1.AmountField({ prediction: rawPrediction["total_before_taxes"], pageId: pageId, }); this.totalTaxes = new standard_1.AmountField({ prediction: rawPrediction["total_taxes"], pageId: pageId, }); } /** * Default string representation. */ toString() { let subscriptionSummary = ""; if (this.subscription && this.subscription.length > 0) { const subscriptionColSizes = [38, 12, 12, 10, 11, 12]; subscriptionSummary += "\n" + (0, common_1.lineSeparator)(subscriptionColSizes, "-") + "\n "; subscriptionSummary += "| Description "; subscriptionSummary += "| End Date "; subscriptionSummary += "| Start Date "; subscriptionSummary += "| Tax Rate "; subscriptionSummary += "| Total "; subscriptionSummary += "| Unit Price "; subscriptionSummary += "|\n" + (0, common_1.lineSeparator)(subscriptionColSizes, "="); subscriptionSummary += this.subscription.map((item) => "\n " + item.toTableLine() + "\n" + (0, common_1.lineSeparator)(subscriptionColSizes, "-")).join(""); } let energyUsageSummary = ""; if (this.energyUsage && this.energyUsage.length > 0) { const energyUsageColSizes = [13, 38, 12, 12, 10, 11, 17, 12]; energyUsageSummary += "\n" + (0, common_1.lineSeparator)(energyUsageColSizes, "-") + "\n "; energyUsageSummary += "| Consumption "; energyUsageSummary += "| Description "; energyUsageSummary += "| End Date "; energyUsageSummary += "| Start Date "; energyUsageSummary += "| Tax Rate "; energyUsageSummary += "| Total "; energyUsageSummary += "| Unit of Measure "; energyUsageSummary += "| Unit Price "; energyUsageSummary += "|\n" + (0, common_1.lineSeparator)(energyUsageColSizes, "="); energyUsageSummary += this.energyUsage.map((item) => "\n " + item.toTableLine() + "\n" + (0, common_1.lineSeparator)(energyUsageColSizes, "-")).join(""); } let taxesAndContributionsSummary = ""; if (this.taxesAndContributions && this.taxesAndContributions.length > 0) { const taxesAndContributionsColSizes = [38, 12, 12, 10, 11, 12]; taxesAndContributionsSummary += "\n" + (0, common_1.lineSeparator)(taxesAndContributionsColSizes, "-") + "\n "; taxesAndContributionsSummary += "| Description "; taxesAndContributionsSummary += "| End Date "; taxesAndContributionsSummary += "| Start Date "; taxesAndContributionsSummary += "| Tax Rate "; taxesAndContributionsSummary += "| Total "; taxesAndContributionsSummary += "| Unit Price "; taxesAndContributionsSummary += "|\n" + (0, common_1.lineSeparator)(taxesAndContributionsColSizes, "="); taxesAndContributionsSummary += this.taxesAndContributions.map((item) => "\n " + item.toTableLine() + "\n" + (0, common_1.lineSeparator)(taxesAndContributionsColSizes, "-")).join(""); } const outStr = `:Invoice Number: ${this.invoiceNumber} :Contract ID: ${this.contractId} :Delivery Point: ${this.deliveryPoint} :Invoice Date: ${this.invoiceDate} :Due Date: ${this.dueDate} :Total Before Taxes: ${this.totalBeforeTaxes} :Total Taxes: ${this.totalTaxes} :Total Amount: ${this.totalAmount} :Energy Supplier: ${this.energySupplier.toFieldList()} :Energy Consumer: ${this.energyConsumer.toFieldList()} :Subscription: ${subscriptionSummary} :Energy Usage: ${energyUsageSummary} :Taxes and Contributions: ${taxesAndContributionsSummary} :Meter Details: ${this.meterDetails.toFieldList()}`.trimEnd(); return (0, common_1.cleanOutString)(outStr); } } exports.EnergyBillV1Document = EnergyBillV1Document;