mindee 3.1.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +4 -4
- package/package.json +1 -1
- package/src/api/endpoint.d.ts +2 -0
- package/src/api/endpoint.js +12 -3
- package/src/cli.js +70 -53
- package/src/client.d.ts +41 -5
- package/src/client.js +20 -4
- package/src/documents/cropper/cropperV1.d.ts +2 -2
- package/src/documents/cropper/cropperV1.js +1 -1
- package/src/documents/document.d.ts +2 -2
- package/src/documents/document.js +1 -1
- package/src/documents/eu/index.d.ts +1 -0
- package/src/documents/eu/index.js +5 -0
- package/src/documents/eu/licensePlate/licensePlateV1.d.ts +8 -0
- package/src/documents/eu/licensePlate/licensePlateV1.js +29 -0
- package/src/documents/fr/bankAccountDetails/bankAccountDetailsV1.d.ts +12 -0
- package/src/documents/fr/bankAccountDetails/bankAccountDetailsV1.js +37 -0
- package/src/documents/fr/carteVitale/carteVitaleV1.d.ts +14 -0
- package/src/documents/fr/carteVitale/carteVitaleV1.js +44 -0
- package/src/documents/fr/idCard/idCardV1.d.ts +11 -0
- package/src/documents/fr/idCard/idCardV1.js +1 -0
- package/src/documents/fr/index.d.ts +2 -0
- package/src/documents/fr/index.js +5 -1
- package/src/documents/index.d.ts +3 -0
- package/src/documents/index.js +6 -1
- package/src/documents/invoice/checks.d.ts +5 -0
- package/src/documents/invoice/checks.js +87 -0
- package/src/documents/invoice/invoiceLineItem.d.ts +29 -0
- package/src/documents/invoice/invoiceLineItem.js +66 -0
- package/src/documents/invoice/invoiceV3.d.ts +27 -8
- package/src/documents/invoice/invoiceV3.js +33 -159
- package/src/documents/invoice/invoiceV4.d.ts +44 -0
- package/src/documents/invoice/invoiceV4.js +168 -0
- package/src/documents/invoice/reconstruction.d.ts +6 -0
- package/src/documents/invoice/reconstruction.js +77 -0
- package/src/documents/passport/passportV1.d.ts +13 -0
- package/src/documents/passport/passportV1.js +1 -0
- package/src/documents/receipt/receiptV3.d.ts +9 -1
- package/src/documents/receipt/receiptV3.js +1 -0
- package/src/documents/shipping_container/shippingContainerV1.d.ts +12 -0
- package/src/documents/shipping_container/shippingContainerV1.js +37 -0
- package/src/documents/us/bankCheck/bankCheckV1.d.ts +20 -1
- package/src/documents/us/bankCheck/bankCheckV1.js +57 -0
- package/src/fields/amount.d.ts +1 -0
- package/src/fields/apiBuilder.d.ts +1 -0
- package/src/fields/companyRegistration.d.ts +1 -1
- package/src/fields/field.d.ts +1 -0
- package/src/fields/field.js +1 -0
- package/src/fields/index.d.ts +1 -1
- package/src/fields/index.js +3 -3
- package/src/fields/locale.d.ts +3 -0
- package/src/fields/paymentDetails.d.ts +4 -0
- package/src/fields/{cropper.d.ts → position.d.ts} +8 -3
- package/src/fields/{cropper.js → position.js} +4 -6
- package/src/index.d.ts +1 -1
- package/src/index.js +4 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IdCardV1 = void 0;
|
|
3
|
+
exports.CarteVitaleV1 = exports.BankAccountDetailsV1 = exports.IdCardV1 = void 0;
|
|
4
4
|
var idCardV1_1 = require("./idCard/idCardV1");
|
|
5
5
|
Object.defineProperty(exports, "IdCardV1", { enumerable: true, get: function () { return idCardV1_1.IdCardV1; } });
|
|
6
|
+
var bankAccountDetailsV1_1 = require("./bankAccountDetails/bankAccountDetailsV1");
|
|
7
|
+
Object.defineProperty(exports, "BankAccountDetailsV1", { enumerable: true, get: function () { return bankAccountDetailsV1_1.BankAccountDetailsV1; } });
|
|
8
|
+
var carteVitaleV1_1 = require("./carteVitale/carteVitaleV1");
|
|
9
|
+
Object.defineProperty(exports, "CarteVitaleV1", { enumerable: true, get: function () { return carteVitaleV1_1.CarteVitaleV1; } });
|
package/src/documents/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export { InvoiceV3 } from "./invoice/invoiceV3";
|
|
2
|
+
export { InvoiceV4 } from "./invoice/invoiceV4";
|
|
2
3
|
export { ReceiptV3 } from "./receipt/receiptV3";
|
|
3
4
|
export { ReceiptV4 } from "./receipt/receiptV4";
|
|
4
5
|
export { PassportV1 } from "./passport/passportV1";
|
|
5
6
|
export { FinancialDocumentV1 } from "./financialDocument/financialDocumentV1";
|
|
6
7
|
export { CustomV1 } from "./custom";
|
|
7
8
|
export { CropperV1 } from "./cropper/cropperV1";
|
|
9
|
+
export { ShippingContainerV1 } from "./shipping_container/shippingContainerV1";
|
|
8
10
|
export { Document, DocumentConstructorProps, DocumentSig } from "./document";
|
|
9
11
|
export * as fr from "./fr";
|
|
10
12
|
export * as us from "./us";
|
|
13
|
+
export * as eu from "./eu";
|
package/src/documents/index.js
CHANGED
|
@@ -23,9 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.us = exports.fr = exports.Document = exports.CropperV1 = exports.CustomV1 = exports.FinancialDocumentV1 = exports.PassportV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.InvoiceV3 = void 0;
|
|
26
|
+
exports.eu = exports.us = exports.fr = exports.Document = exports.ShippingContainerV1 = exports.CropperV1 = exports.CustomV1 = exports.FinancialDocumentV1 = exports.PassportV1 = exports.ReceiptV4 = exports.ReceiptV3 = exports.InvoiceV4 = exports.InvoiceV3 = void 0;
|
|
27
27
|
var invoiceV3_1 = require("./invoice/invoiceV3");
|
|
28
28
|
Object.defineProperty(exports, "InvoiceV3", { enumerable: true, get: function () { return invoiceV3_1.InvoiceV3; } });
|
|
29
|
+
var invoiceV4_1 = require("./invoice/invoiceV4");
|
|
30
|
+
Object.defineProperty(exports, "InvoiceV4", { enumerable: true, get: function () { return invoiceV4_1.InvoiceV4; } });
|
|
29
31
|
var receiptV3_1 = require("./receipt/receiptV3");
|
|
30
32
|
Object.defineProperty(exports, "ReceiptV3", { enumerable: true, get: function () { return receiptV3_1.ReceiptV3; } });
|
|
31
33
|
var receiptV4_1 = require("./receipt/receiptV4");
|
|
@@ -38,7 +40,10 @@ var custom_1 = require("./custom");
|
|
|
38
40
|
Object.defineProperty(exports, "CustomV1", { enumerable: true, get: function () { return custom_1.CustomV1; } });
|
|
39
41
|
var cropperV1_1 = require("./cropper/cropperV1");
|
|
40
42
|
Object.defineProperty(exports, "CropperV1", { enumerable: true, get: function () { return cropperV1_1.CropperV1; } });
|
|
43
|
+
var shippingContainerV1_1 = require("./shipping_container/shippingContainerV1");
|
|
44
|
+
Object.defineProperty(exports, "ShippingContainerV1", { enumerable: true, get: function () { return shippingContainerV1_1.ShippingContainerV1; } });
|
|
41
45
|
var document_1 = require("./document");
|
|
42
46
|
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
|
|
43
47
|
exports.fr = __importStar(require("./fr"));
|
|
44
48
|
exports.us = __importStar(require("./us"));
|
|
49
|
+
exports.eu = __importStar(require("./eu"));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { InvoiceV3 } from "./invoiceV3";
|
|
2
|
+
import { InvoiceV4 } from "./invoiceV4";
|
|
3
|
+
export declare function taxesMatchTotalIncl(document: InvoiceV4 | InvoiceV3): boolean;
|
|
4
|
+
export declare function taxesMatchTotalExcl(document: InvoiceV4 | InvoiceV3): boolean;
|
|
5
|
+
export declare function taxesAndTotalExclMatchTotalIncl(document: InvoiceV4 | InvoiceV3): boolean;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.taxesAndTotalExclMatchTotalIncl = exports.taxesMatchTotalExcl = exports.taxesMatchTotalIncl = void 0;
|
|
4
|
+
function taxesMatchTotalIncl(document) {
|
|
5
|
+
// Check taxes and total include exist
|
|
6
|
+
if (document.taxes.length === 0 || document.totalAmount.value === undefined)
|
|
7
|
+
return false;
|
|
8
|
+
// Reconstruct totalIncl from taxes
|
|
9
|
+
let totalVat = 0;
|
|
10
|
+
let reconstructedTotal = 0;
|
|
11
|
+
document.taxes.forEach((tax) => {
|
|
12
|
+
if (tax.value === undefined || !tax.rate)
|
|
13
|
+
return false;
|
|
14
|
+
totalVat += tax.value;
|
|
15
|
+
reconstructedTotal += tax.value + (100 * tax.value) / tax.rate;
|
|
16
|
+
});
|
|
17
|
+
// Sanity check
|
|
18
|
+
if (totalVat <= 0)
|
|
19
|
+
return false;
|
|
20
|
+
// Crate epsilon
|
|
21
|
+
const eps = 1 / (100 * totalVat);
|
|
22
|
+
if (document.totalAmount.value * (1 - eps) - 0.02 <= reconstructedTotal &&
|
|
23
|
+
reconstructedTotal <= document.totalAmount.value * (1 + eps) + 0.02) {
|
|
24
|
+
document.taxes.forEach((tax) => {
|
|
25
|
+
tax.confidence = 1.0;
|
|
26
|
+
});
|
|
27
|
+
document.totalTax.confidence = 1.0;
|
|
28
|
+
document.totalAmount.confidence = 1.0;
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
exports.taxesMatchTotalIncl = taxesMatchTotalIncl;
|
|
34
|
+
function taxesMatchTotalExcl(document) {
|
|
35
|
+
// Check taxes and total amount exist
|
|
36
|
+
if (document.taxes.length === 0 || document.totalNet.value === undefined) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
// Reconstruct total_incl from taxes
|
|
40
|
+
let totalVat = 0;
|
|
41
|
+
let reconstructedTotal = 0;
|
|
42
|
+
document.taxes.forEach((tax) => {
|
|
43
|
+
if (tax.value === undefined || !tax.rate) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
totalVat += tax.value;
|
|
47
|
+
reconstructedTotal += (100 * tax.value) / tax.rate;
|
|
48
|
+
});
|
|
49
|
+
// Sanity check
|
|
50
|
+
if (totalVat <= 0)
|
|
51
|
+
return false;
|
|
52
|
+
// Crate epsilon
|
|
53
|
+
const eps = 1 / (100 * totalVat);
|
|
54
|
+
if (document.totalNet.value * (1 - eps) - 0.02 <= reconstructedTotal &&
|
|
55
|
+
reconstructedTotal <= document.totalNet.value * (1 + eps) + 0.02) {
|
|
56
|
+
document.taxes.forEach((tax) => {
|
|
57
|
+
tax.confidence = 1.0;
|
|
58
|
+
});
|
|
59
|
+
document.totalTax.confidence = 1.0;
|
|
60
|
+
document.totalNet.confidence = 1.0;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
exports.taxesMatchTotalExcl = taxesMatchTotalExcl;
|
|
66
|
+
function taxesAndTotalExclMatchTotalIncl(document) {
|
|
67
|
+
if (document.totalNet.value === undefined ||
|
|
68
|
+
document.taxes.length === 0 ||
|
|
69
|
+
document.totalAmount.value === undefined)
|
|
70
|
+
return false;
|
|
71
|
+
let totalVat = 0;
|
|
72
|
+
document.taxes.forEach((tax) => (totalVat += tax.value || 0));
|
|
73
|
+
const reconstructedTotal = totalVat + document.totalNet.value;
|
|
74
|
+
if (totalVat <= 0)
|
|
75
|
+
return false;
|
|
76
|
+
if (document.totalAmount.value - 0.01 <= reconstructedTotal &&
|
|
77
|
+
reconstructedTotal <= document.totalAmount.value + 0.01) {
|
|
78
|
+
document.taxes.forEach((tax) => {
|
|
79
|
+
tax.confidence = 1.0;
|
|
80
|
+
});
|
|
81
|
+
document.totalTax.confidence = 1.0;
|
|
82
|
+
document.totalAmount.confidence = 1.0;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
exports.taxesAndTotalExclMatchTotalIncl = taxesAndTotalExclMatchTotalIncl;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { stringDict } from "../../fields";
|
|
2
|
+
import { Polygon } from "../../geometry";
|
|
3
|
+
export declare class InvoiceLineItem {
|
|
4
|
+
/** The product code referring to the item. */
|
|
5
|
+
productCode: string;
|
|
6
|
+
/** The item description. */
|
|
7
|
+
description: string;
|
|
8
|
+
/** The item quantity */
|
|
9
|
+
quantity: number | null;
|
|
10
|
+
/** The item unit price. */
|
|
11
|
+
unitPrice: number | null;
|
|
12
|
+
/** The item total amount. */
|
|
13
|
+
totalAmount: number | null;
|
|
14
|
+
/** The item tax rate in percentage. */
|
|
15
|
+
taxRate: number | null;
|
|
16
|
+
/** The item tax amount. */
|
|
17
|
+
taxAmount: number | null;
|
|
18
|
+
/** Confidence score */
|
|
19
|
+
confidence: number;
|
|
20
|
+
/** The document page on which the information was found. */
|
|
21
|
+
pageId: number;
|
|
22
|
+
/**
|
|
23
|
+
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
24
|
+
* the field in the document.
|
|
25
|
+
*/
|
|
26
|
+
polygon: Polygon;
|
|
27
|
+
constructor({ prediction }: stringDict);
|
|
28
|
+
toString(): string;
|
|
29
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvoiceLineItem = void 0;
|
|
4
|
+
const amount_1 = require("../../fields/amount");
|
|
5
|
+
class InvoiceLineItem {
|
|
6
|
+
constructor({ prediction }) {
|
|
7
|
+
/** Confidence score */
|
|
8
|
+
this.confidence = 0.0;
|
|
9
|
+
/**
|
|
10
|
+
* Contains the relative vertices coordinates (points) of a polygon containing
|
|
11
|
+
* the field in the document.
|
|
12
|
+
*/
|
|
13
|
+
this.polygon = [];
|
|
14
|
+
this.productCode = prediction.product_code;
|
|
15
|
+
this.description = prediction.description;
|
|
16
|
+
this.quantity = +parseFloat(prediction.quantity).toFixed(3);
|
|
17
|
+
if (isNaN(this.quantity)) {
|
|
18
|
+
this.quantity = null;
|
|
19
|
+
}
|
|
20
|
+
this.unitPrice = +parseFloat(prediction.unit_price).toFixed(3);
|
|
21
|
+
if (isNaN(this.unitPrice)) {
|
|
22
|
+
this.unitPrice = null;
|
|
23
|
+
}
|
|
24
|
+
this.totalAmount = +parseFloat(prediction.total_amount).toFixed(3);
|
|
25
|
+
if (isNaN(this.totalAmount)) {
|
|
26
|
+
this.totalAmount = null;
|
|
27
|
+
}
|
|
28
|
+
this.taxRate = +parseFloat(prediction.tax_rate).toFixed(3);
|
|
29
|
+
if (isNaN(this.taxRate)) {
|
|
30
|
+
this.taxRate = null;
|
|
31
|
+
}
|
|
32
|
+
this.taxAmount = +parseFloat(prediction.tax_amount).toFixed(3);
|
|
33
|
+
if (isNaN(this.taxAmount)) {
|
|
34
|
+
this.taxAmount = null;
|
|
35
|
+
}
|
|
36
|
+
this.pageId = prediction.page_id;
|
|
37
|
+
this.confidence = prediction.confidence ? prediction.confidence : 0.0;
|
|
38
|
+
if (prediction.polygon) {
|
|
39
|
+
this.polygon = prediction.polygon;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
toString() {
|
|
43
|
+
const productCode = this.productCode ?? "";
|
|
44
|
+
const quantity = this.quantity !== null ? (0, amount_1.floatToString)(this.quantity) : "";
|
|
45
|
+
const unitPrice = this.unitPrice !== null ? (0, amount_1.floatToString)(this.unitPrice) : "";
|
|
46
|
+
const totalAmount = this.totalAmount !== null ? (0, amount_1.floatToString)(this.totalAmount) : "";
|
|
47
|
+
let tax = this.taxAmount !== null ? (0, amount_1.floatToString)(this.taxAmount) : "";
|
|
48
|
+
tax += this.taxRate !== null ? ` (${this.taxRate} %)` : "";
|
|
49
|
+
let description = this.description ?? "";
|
|
50
|
+
if (description.length > 32) {
|
|
51
|
+
description = this.description.substring(0, 32) + "...";
|
|
52
|
+
}
|
|
53
|
+
return (productCode.padEnd(14) +
|
|
54
|
+
" | " +
|
|
55
|
+
quantity.padEnd(6) +
|
|
56
|
+
" | " +
|
|
57
|
+
unitPrice.padEnd(7) +
|
|
58
|
+
" | " +
|
|
59
|
+
totalAmount.padEnd(8) +
|
|
60
|
+
" | " +
|
|
61
|
+
tax.padEnd(14) +
|
|
62
|
+
" | " +
|
|
63
|
+
description);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.InvoiceLineItem = InvoiceLineItem;
|
|
@@ -2,29 +2,48 @@ import { Document, DocumentConstructorProps } from "../document";
|
|
|
2
2
|
import { BaseField, TaxField, PaymentDetails, Locale, Amount, Field, DateField, CompanyRegistration } from "../../fields";
|
|
3
3
|
export declare class InvoiceV3 extends Document {
|
|
4
4
|
#private;
|
|
5
|
+
/** Total amount with the tax amount of the purchase. */
|
|
5
6
|
locale: Locale;
|
|
7
|
+
/** The nature of the invoice. */
|
|
6
8
|
documentType: BaseField;
|
|
7
|
-
totalIncl
|
|
9
|
+
/** The total amount with tax included. Same as totalIncl. */
|
|
10
|
+
totalAmount: Amount;
|
|
11
|
+
/** The creation date of the invoice. */
|
|
8
12
|
date: DateField;
|
|
13
|
+
/** The due date of the invoice. */
|
|
9
14
|
dueDate: DateField;
|
|
15
|
+
/** The created time of the invoice */
|
|
10
16
|
time: Field;
|
|
17
|
+
/** The total tax. */
|
|
11
18
|
totalTax: Amount;
|
|
12
|
-
totalExcl
|
|
19
|
+
/** The total amount without the tax value. Same as totalExcl. */
|
|
20
|
+
totalNet: Amount;
|
|
21
|
+
/** The supplier name. */
|
|
13
22
|
supplier: Field;
|
|
23
|
+
/** The supplier address. */
|
|
14
24
|
supplierAddress: Field;
|
|
25
|
+
/** The invoice number. */
|
|
15
26
|
invoiceNumber: Field;
|
|
27
|
+
/** The company regitration information. */
|
|
16
28
|
companyRegistration: CompanyRegistration[];
|
|
29
|
+
/** The name of the customer. */
|
|
17
30
|
customerName: Field;
|
|
31
|
+
/** The address of the customer. */
|
|
18
32
|
customerAddress: Field;
|
|
33
|
+
/** The list of the taxes. */
|
|
19
34
|
taxes: TaxField[];
|
|
35
|
+
/** The payment information. */
|
|
20
36
|
paymentDetails: PaymentDetails[];
|
|
37
|
+
/** The company registration information for the customer. */
|
|
21
38
|
customerCompanyRegistration: CompanyRegistration[];
|
|
39
|
+
/** The total amount without the tax value. */
|
|
40
|
+
get totalExcl(): Amount;
|
|
41
|
+
/** The total amount without the tax value. */
|
|
42
|
+
set totalExcl(value: Amount);
|
|
43
|
+
/** The total amount with tax included. */
|
|
44
|
+
get totalIncl(): Amount;
|
|
45
|
+
/** The total amount with tax included. */
|
|
46
|
+
set totalIncl(value: Amount);
|
|
22
47
|
constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
|
|
23
48
|
toString(): string;
|
|
24
|
-
private taxesMatchTotalIncl;
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
private taxesMatchTotalExcl;
|
|
29
|
-
private taxesAndTotalExclMatchTotalIncl;
|
|
30
49
|
}
|
|
@@ -4,11 +4,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
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");
|
|
5
5
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
6
|
};
|
|
7
|
-
var _InvoiceV3_instances, _InvoiceV3_initFromApiPrediction, _InvoiceV3_checklist, _InvoiceV3_reconstruct
|
|
7
|
+
var _InvoiceV3_instances, _InvoiceV3_initFromApiPrediction, _InvoiceV3_checklist, _InvoiceV3_reconstruct;
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.InvoiceV3 = void 0;
|
|
10
10
|
const document_1 = require("../document");
|
|
11
11
|
const fields_1 = require("../../fields");
|
|
12
|
+
const checks_1 = require("./checks");
|
|
13
|
+
const reconstruction_1 = require("./reconstruction");
|
|
12
14
|
class InvoiceV3 extends document_1.Document {
|
|
13
15
|
constructor({ prediction, orientation = undefined, extras = undefined, inputSource = undefined, fullText = undefined, pageId = undefined, }) {
|
|
14
16
|
super({
|
|
@@ -19,14 +21,34 @@ class InvoiceV3 extends document_1.Document {
|
|
|
19
21
|
extras: extras,
|
|
20
22
|
});
|
|
21
23
|
_InvoiceV3_instances.add(this);
|
|
24
|
+
/** The company regitration information. */
|
|
22
25
|
this.companyRegistration = [];
|
|
26
|
+
/** The list of the taxes. */
|
|
23
27
|
this.taxes = [];
|
|
28
|
+
/** The payment information. */
|
|
24
29
|
this.paymentDetails = [];
|
|
30
|
+
/** The company registration information for the customer. */
|
|
25
31
|
this.customerCompanyRegistration = [];
|
|
26
32
|
__classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_initFromApiPrediction).call(this, prediction, pageId);
|
|
27
33
|
__classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_checklist).call(this);
|
|
28
34
|
__classPrivateFieldGet(this, _InvoiceV3_instances, "m", _InvoiceV3_reconstruct).call(this);
|
|
29
35
|
}
|
|
36
|
+
/** The total amount without the tax value. */
|
|
37
|
+
get totalExcl() {
|
|
38
|
+
return this.totalNet;
|
|
39
|
+
}
|
|
40
|
+
/** The total amount without the tax value. */
|
|
41
|
+
set totalExcl(value) {
|
|
42
|
+
this.totalNet = value;
|
|
43
|
+
}
|
|
44
|
+
/** The total amount with tax included. */
|
|
45
|
+
get totalIncl() {
|
|
46
|
+
return this.totalAmount;
|
|
47
|
+
}
|
|
48
|
+
/** The total amount with tax included. */
|
|
49
|
+
set totalIncl(value) {
|
|
50
|
+
this.totalAmount = value;
|
|
51
|
+
}
|
|
30
52
|
toString() {
|
|
31
53
|
const taxes = this.taxes.map((item) => item.toString()).join("\n ");
|
|
32
54
|
const paymentDetails = this.paymentDetails
|
|
@@ -38,7 +60,7 @@ class InvoiceV3 extends document_1.Document {
|
|
|
38
60
|
const companyRegistration = this.companyRegistration
|
|
39
61
|
.map((item) => item.toString())
|
|
40
62
|
.join("; ");
|
|
41
|
-
const outStr = `-----Invoice
|
|
63
|
+
const outStr = `----- Invoice V3 -----
|
|
42
64
|
Filename: ${this.filename}
|
|
43
65
|
Invoice number: ${this.invoiceNumber}
|
|
44
66
|
Total amount including taxes: ${this.totalIncl}
|
|
@@ -59,90 +81,6 @@ Locale: ${this.locale}
|
|
|
59
81
|
`;
|
|
60
82
|
return InvoiceV3.cleanOutString(outStr);
|
|
61
83
|
}
|
|
62
|
-
taxesMatchTotalIncl() {
|
|
63
|
-
// Check taxes and total include exist
|
|
64
|
-
if (this.taxes.length === 0 || this.totalIncl.value === undefined)
|
|
65
|
-
return false;
|
|
66
|
-
// Reconstruct totalIncl from taxes
|
|
67
|
-
let totalVat = 0;
|
|
68
|
-
let reconstructedTotal = 0;
|
|
69
|
-
this.taxes.forEach((tax) => {
|
|
70
|
-
if (tax.value === undefined || !tax.rate)
|
|
71
|
-
return false;
|
|
72
|
-
totalVat += tax.value;
|
|
73
|
-
reconstructedTotal += tax.value + (100 * tax.value) / tax.rate;
|
|
74
|
-
});
|
|
75
|
-
// Sanity check
|
|
76
|
-
if (totalVat <= 0)
|
|
77
|
-
return false;
|
|
78
|
-
// Crate epsilon
|
|
79
|
-
const eps = 1 / (100 * totalVat);
|
|
80
|
-
if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
|
|
81
|
-
reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
|
|
82
|
-
this.taxes.forEach((tax) => {
|
|
83
|
-
tax.confidence = 1.0;
|
|
84
|
-
});
|
|
85
|
-
this.totalTax.confidence = 1.0;
|
|
86
|
-
this.totalIncl.confidence = 1.0;
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
93
|
-
*/
|
|
94
|
-
taxesMatchTotalExcl() {
|
|
95
|
-
// Check taxes and total amount exist
|
|
96
|
-
if (this.taxes.length === 0 || this.totalExcl.value === undefined) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
// Reconstruct total_incl from taxes
|
|
100
|
-
let totalVat = 0;
|
|
101
|
-
let reconstructedTotal = 0;
|
|
102
|
-
this.taxes.forEach((tax) => {
|
|
103
|
-
if (tax.value === undefined || !tax.rate) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
totalVat += tax.value;
|
|
107
|
-
reconstructedTotal += (100 * tax.value) / tax.rate;
|
|
108
|
-
});
|
|
109
|
-
// Sanity check
|
|
110
|
-
if (totalVat <= 0)
|
|
111
|
-
return false;
|
|
112
|
-
// Crate epsilon
|
|
113
|
-
const eps = 1 / (100 * totalVat);
|
|
114
|
-
if (this.totalExcl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
|
|
115
|
-
reconstructedTotal <= this.totalExcl.value * (1 + eps) + 0.02) {
|
|
116
|
-
this.taxes.forEach((tax) => {
|
|
117
|
-
tax.confidence = 1.0;
|
|
118
|
-
});
|
|
119
|
-
this.totalTax.confidence = 1.0;
|
|
120
|
-
this.totalExcl.confidence = 1.0;
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
taxesAndTotalExclMatchTotalIncl() {
|
|
126
|
-
if (this.totalExcl.value === undefined ||
|
|
127
|
-
this.taxes.length === 0 ||
|
|
128
|
-
this.totalIncl.value === undefined)
|
|
129
|
-
return false;
|
|
130
|
-
let totalVat = 0;
|
|
131
|
-
this.taxes.forEach((tax) => (totalVat += tax.value || 0));
|
|
132
|
-
const reconstructedTotal = totalVat + this.totalExcl.value;
|
|
133
|
-
if (totalVat <= 0)
|
|
134
|
-
return false;
|
|
135
|
-
if (this.totalIncl.value - 0.01 <= reconstructedTotal &&
|
|
136
|
-
reconstructedTotal <= this.totalIncl.value + 0.01) {
|
|
137
|
-
this.taxes.forEach((tax) => {
|
|
138
|
-
tax.confidence = 1.0;
|
|
139
|
-
});
|
|
140
|
-
this.totalTax.confidence = 1.0;
|
|
141
|
-
this.totalIncl.confidence = 1.0;
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
84
|
}
|
|
147
85
|
exports.InvoiceV3 = InvoiceV3;
|
|
148
86
|
_InvoiceV3_instances = new WeakSet(), _InvoiceV3_initFromApiPrediction = function _InvoiceV3_initFromApiPrediction(apiPrediction, pageId) {
|
|
@@ -159,12 +97,13 @@ _InvoiceV3_instances = new WeakSet(), _InvoiceV3_initFromApiPrediction = functio
|
|
|
159
97
|
valueKey: "value",
|
|
160
98
|
pageId: pageId,
|
|
161
99
|
});
|
|
100
|
+
this.totalAmount = this.totalIncl;
|
|
162
101
|
this.totalTax = new fields_1.Amount({
|
|
163
102
|
prediction: { value: undefined, confidence: 0.0 },
|
|
164
103
|
valueKey: "value",
|
|
165
104
|
pageId: pageId,
|
|
166
105
|
});
|
|
167
|
-
this.
|
|
106
|
+
this.totalNet = new fields_1.Amount({
|
|
168
107
|
prediction: apiPrediction.total_excl,
|
|
169
108
|
valueKey: "value",
|
|
170
109
|
pageId: pageId,
|
|
@@ -220,78 +159,13 @@ _InvoiceV3_instances = new WeakSet(), _InvoiceV3_initFromApiPrediction = functio
|
|
|
220
159
|
})));
|
|
221
160
|
}, _InvoiceV3_checklist = function _InvoiceV3_checklist() {
|
|
222
161
|
this.checklist = {
|
|
223
|
-
taxesMatchTotalIncl:
|
|
224
|
-
taxesMatchTotalExcl:
|
|
225
|
-
taxesAndTotalExclMatchTotalIncl:
|
|
162
|
+
taxesMatchTotalIncl: (0, checks_1.taxesMatchTotalIncl)(this),
|
|
163
|
+
taxesMatchTotalExcl: (0, checks_1.taxesMatchTotalExcl)(this),
|
|
164
|
+
taxesAndTotalExclMatchTotalIncl: (0, checks_1.taxesAndTotalExclMatchTotalIncl)(this),
|
|
226
165
|
};
|
|
227
166
|
}, _InvoiceV3_reconstruct = function _InvoiceV3_reconstruct() {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}, _InvoiceV3_reconstructTotalTax = function _InvoiceV3_reconstructTotalTax() {
|
|
233
|
-
if (this.taxes.length > 0) {
|
|
234
|
-
const totalTax = {
|
|
235
|
-
value: this.taxes.reduce((acc, tax) => {
|
|
236
|
-
return tax.value !== undefined ? acc + tax.value : acc;
|
|
237
|
-
}, 0),
|
|
238
|
-
confidence: fields_1.Field.arrayConfidence(this.taxes),
|
|
239
|
-
};
|
|
240
|
-
if (totalTax.value > 0)
|
|
241
|
-
this.totalTax = new fields_1.Amount({
|
|
242
|
-
prediction: totalTax,
|
|
243
|
-
valueKey: "value",
|
|
244
|
-
reconstructed: true,
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}, _InvoiceV3_reconstructTotalTaxFromTotals = function _InvoiceV3_reconstructTotalTaxFromTotals() {
|
|
248
|
-
if (this.totalTax.value !== undefined ||
|
|
249
|
-
this.totalExcl.value === undefined ||
|
|
250
|
-
this.totalIncl.value === undefined) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const totalTax = {
|
|
254
|
-
value: this.totalIncl.value - this.totalExcl.value,
|
|
255
|
-
confidence: this.totalIncl.confidence * this.totalExcl.confidence,
|
|
256
|
-
};
|
|
257
|
-
if (totalTax.value >= 0) {
|
|
258
|
-
this.totalTax = new fields_1.Amount({
|
|
259
|
-
prediction: totalTax,
|
|
260
|
-
valueKey: "value",
|
|
261
|
-
reconstructed: true,
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
}, _InvoiceV3_reconstructTotalExcl = function _InvoiceV3_reconstructTotalExcl() {
|
|
265
|
-
if (this.totalIncl.value === undefined ||
|
|
266
|
-
this.taxes.length === 0 ||
|
|
267
|
-
this.totalExcl.value !== undefined) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
const totalExcl = {
|
|
271
|
-
value: this.totalIncl.value - fields_1.Field.arraySum(this.taxes),
|
|
272
|
-
confidence: fields_1.Field.arrayConfidence(this.taxes) *
|
|
273
|
-
this.totalIncl.confidence,
|
|
274
|
-
};
|
|
275
|
-
this.totalExcl = new fields_1.Amount({
|
|
276
|
-
prediction: totalExcl,
|
|
277
|
-
valueKey: "value",
|
|
278
|
-
reconstructed: true,
|
|
279
|
-
});
|
|
280
|
-
}, _InvoiceV3_reconstructTotalIncl = function _InvoiceV3_reconstructTotalIncl() {
|
|
281
|
-
if (!(this.totalExcl.value === undefined ||
|
|
282
|
-
this.taxes.length === 0 ||
|
|
283
|
-
this.totalIncl.value !== undefined)) {
|
|
284
|
-
const totalIncl = {
|
|
285
|
-
value: this.totalExcl.value +
|
|
286
|
-
this.taxes.reduce((acc, tax) => {
|
|
287
|
-
return tax.value ? acc + tax.value : acc;
|
|
288
|
-
}, 0.0),
|
|
289
|
-
confidence: fields_1.Field.arrayConfidence(this.taxes) * this.totalExcl.confidence,
|
|
290
|
-
};
|
|
291
|
-
this.totalIncl = new fields_1.Amount({
|
|
292
|
-
prediction: totalIncl,
|
|
293
|
-
valueKey: "value",
|
|
294
|
-
reconstructed: true,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
167
|
+
(0, reconstruction_1.reconstructTotalTax)(this);
|
|
168
|
+
(0, reconstruction_1.reconstructTotalExcl)(this);
|
|
169
|
+
(0, reconstruction_1.reconstructTotalIncl)(this);
|
|
170
|
+
(0, reconstruction_1.reconstructTotalTaxFromTotals)(this);
|
|
297
171
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Document, DocumentConstructorProps } from "../document";
|
|
2
|
+
import { TaxField, PaymentDetails, Locale, Amount, Field, DateField, CompanyRegistration, BaseField } from "../../fields";
|
|
3
|
+
import { InvoiceLineItem } from "./invoiceLineItem";
|
|
4
|
+
export declare class InvoiceV4 extends Document {
|
|
5
|
+
#private;
|
|
6
|
+
/** Locale information. */
|
|
7
|
+
locale: Locale;
|
|
8
|
+
/** The nature of the invoice. */
|
|
9
|
+
documentType: BaseField;
|
|
10
|
+
/** The total amount with tax included. */
|
|
11
|
+
totalAmount: Amount;
|
|
12
|
+
/** The creation date of the invoice. */
|
|
13
|
+
date: DateField;
|
|
14
|
+
/** The due date of the invoice. */
|
|
15
|
+
dueDate: DateField;
|
|
16
|
+
/** The created time of the invoice */
|
|
17
|
+
time: Field;
|
|
18
|
+
/** The total tax. */
|
|
19
|
+
totalTax: Amount;
|
|
20
|
+
/** The total amount without the tax value. */
|
|
21
|
+
totalNet: Amount;
|
|
22
|
+
/** The supplier name. */
|
|
23
|
+
supplierName: Field;
|
|
24
|
+
/** The supplier address. */
|
|
25
|
+
supplierAddress: Field;
|
|
26
|
+
/** The payment information. */
|
|
27
|
+
supplierPaymentDetails: PaymentDetails[];
|
|
28
|
+
/** The supplier company regitration information. */
|
|
29
|
+
supplierCompanyRegistrations: CompanyRegistration[];
|
|
30
|
+
/** The invoice number. */
|
|
31
|
+
invoiceNumber: Field;
|
|
32
|
+
/** The name of the customer. */
|
|
33
|
+
customerName: Field;
|
|
34
|
+
/** The address of the customer. */
|
|
35
|
+
customerAddress: Field;
|
|
36
|
+
/** The company registration information for the customer. */
|
|
37
|
+
customerCompanyRegistrations: CompanyRegistration[];
|
|
38
|
+
/** The list of the taxes. */
|
|
39
|
+
taxes: TaxField[];
|
|
40
|
+
/** Line items details. */
|
|
41
|
+
lineItems: InvoiceLineItem[];
|
|
42
|
+
constructor({ prediction, orientation, extras, inputSource, fullText, pageId, }: DocumentConstructorProps);
|
|
43
|
+
toString(): string;
|
|
44
|
+
}
|