mindee 1.3.0 → 1.3.3
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 +47 -32
- package/dist/api/financialDocument.js +51 -0
- package/dist/api/index.js +13 -0
- package/dist/api/invoice.js +59 -0
- package/dist/api/object.js +80 -0
- package/dist/api/receipt.js +45 -0
- package/dist/api/request.js +90 -0
- package/dist/api/response.js +91 -0
- package/dist/documents/document.js +80 -0
- package/dist/documents/fields/amount.js +21 -0
- package/dist/documents/fields/date.js +17 -0
- package/dist/documents/fields/field.js +85 -0
- package/dist/documents/fields/index.js +17 -0
- package/dist/documents/fields/locale.js +25 -0
- package/dist/documents/fields/orientation.js +22 -0
- package/dist/documents/fields/paymentDetails.js +50 -0
- package/dist/documents/fields/tax.js +42 -0
- package/dist/documents/financialDocument.js +216 -0
- package/dist/documents/index.js +13 -0
- package/dist/documents/invoice.js +361 -0
- package/dist/documents/receipt.js +231 -0
- package/dist/errors/handler.js +17 -0
- package/dist/index.js +23 -0
- package/dist/inputs.js +208 -0
- package/dist/logger.js +34 -0
- package/lib/index.js +29 -30
- package/mindee/api/request.js +1 -1
- package/mindee/inputs.js +1 -4
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Amount = void 0;
|
|
4
|
+
const field_1 = require("@fields/field");
|
|
5
|
+
class Amount extends field_1.Field {
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
8
|
+
* @param {String} valueKey - Key to use in the prediction dict
|
|
9
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
10
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
11
|
+
*/
|
|
12
|
+
constructor({ prediction, valueKey = "amount", reconstructed = false, pageNumber = 0, }) {
|
|
13
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
14
|
+
this.value = +parseFloat(prediction[valueKey]).toFixed(3);
|
|
15
|
+
if (isNaN(this.value)) {
|
|
16
|
+
this.value = undefined;
|
|
17
|
+
this.probability = 0;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.Amount = Amount;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DateField = void 0;
|
|
4
|
+
const field_1 = require("@fields/field");
|
|
5
|
+
class DateField extends field_1.Field {
|
|
6
|
+
constructor({ prediction, valueKey = "iso", reconstructed = false, pageNumber = 0, }) {
|
|
7
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
8
|
+
this.dateObject = new Date(this.value);
|
|
9
|
+
if (!(this.dateObject instanceof Date) ||
|
|
10
|
+
isNaN(this.dateObject.valueOf())) {
|
|
11
|
+
this.dateObject = undefined;
|
|
12
|
+
this.probability = 0.0;
|
|
13
|
+
this.value = undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.DateField = DateField;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Field = void 0;
|
|
4
|
+
class Field {
|
|
5
|
+
/**
|
|
6
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
7
|
+
* @param {String} valueKey - Key to use in the prediction dict
|
|
8
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
9
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
10
|
+
* @param {Array<String>} extraFields - Extra fields to get from the prediction and to set as attribute of the Field
|
|
11
|
+
*/
|
|
12
|
+
constructor({ prediction, valueKey = "value", reconstructed = false, extraFields, pageNumber, }) {
|
|
13
|
+
this.pageNumber = pageNumber;
|
|
14
|
+
this.reconstructed = reconstructed;
|
|
15
|
+
this.value = undefined;
|
|
16
|
+
this.probability = prediction.confidence ? prediction.confidence : 0.0;
|
|
17
|
+
this.bbox = prediction.polygon ? prediction.polygon : [];
|
|
18
|
+
if (valueKey in prediction && prediction[valueKey] !== null) {
|
|
19
|
+
this.value = prediction[valueKey];
|
|
20
|
+
if (extraFields) {
|
|
21
|
+
for (const fieldName of extraFields) {
|
|
22
|
+
this[fieldName] = prediction[fieldName];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
compare(other) {
|
|
28
|
+
if (this.value == null && other.value == null)
|
|
29
|
+
return true;
|
|
30
|
+
else if (this.value == null || other.value == null)
|
|
31
|
+
return false;
|
|
32
|
+
else {
|
|
33
|
+
if (typeof this.value == "string") {
|
|
34
|
+
return this.value.toLowerCase() === other.value.toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return this.value === other.value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
@param {Array<Field>} array1 - first Array of Fields
|
|
43
|
+
@param {Array<Field>} array2 - second Array of Fields
|
|
44
|
+
@param {String} attr - Attribute to compare
|
|
45
|
+
@returns {Boolean} - true if all elements in array1 exist in array2 and vice-versa, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
static compareArrays(array1, array2, attr = "value") {
|
|
48
|
+
const list1 = array1.map((item) => item[attr]);
|
|
49
|
+
const list2 = array2.map((item) => item[attr]);
|
|
50
|
+
if (list1.length !== list2.length)
|
|
51
|
+
return false;
|
|
52
|
+
for (const item1 of list1) {
|
|
53
|
+
if (!list2.includes(item1))
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @param {Array<Field>} array - Array of Fields
|
|
60
|
+
* @returns {Number} product of all the fields probaility
|
|
61
|
+
*/
|
|
62
|
+
static arrayProbability(array) {
|
|
63
|
+
let total = 1.0;
|
|
64
|
+
for (const field of array) {
|
|
65
|
+
total *= field.probability;
|
|
66
|
+
if (isNaN(total))
|
|
67
|
+
return 0.0;
|
|
68
|
+
}
|
|
69
|
+
return total;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @param {Array<Field>} array - Array of Fields
|
|
73
|
+
* @returns {Number} Sum of all the Fields values in the array
|
|
74
|
+
*/
|
|
75
|
+
static arraySum(array) {
|
|
76
|
+
let total = 0;
|
|
77
|
+
for (const field of array) {
|
|
78
|
+
total += field.value;
|
|
79
|
+
if (isNaN(total))
|
|
80
|
+
return 0.0;
|
|
81
|
+
}
|
|
82
|
+
return total;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.Field = Field;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Field = exports.DateField = exports.Amount = exports.Locale = exports.Orientation = exports.PaymentDetails = exports.Tax = void 0;
|
|
4
|
+
var tax_1 = require("@fields/tax");
|
|
5
|
+
Object.defineProperty(exports, "Tax", { enumerable: true, get: function () { return tax_1.Tax; } });
|
|
6
|
+
var paymentDetails_1 = require("@fields/paymentDetails");
|
|
7
|
+
Object.defineProperty(exports, "PaymentDetails", { enumerable: true, get: function () { return paymentDetails_1.PaymentDetails; } });
|
|
8
|
+
var orientation_1 = require("@fields/orientation");
|
|
9
|
+
Object.defineProperty(exports, "Orientation", { enumerable: true, get: function () { return orientation_1.Orientation; } });
|
|
10
|
+
var locale_1 = require("@fields/locale");
|
|
11
|
+
Object.defineProperty(exports, "Locale", { enumerable: true, get: function () { return locale_1.Locale; } });
|
|
12
|
+
var amount_1 = require("@fields/amount");
|
|
13
|
+
Object.defineProperty(exports, "Amount", { enumerable: true, get: function () { return amount_1.Amount; } });
|
|
14
|
+
var date_1 = require("@fields/date");
|
|
15
|
+
Object.defineProperty(exports, "DateField", { enumerable: true, get: function () { return date_1.DateField; } });
|
|
16
|
+
var field_1 = require("@fields/field");
|
|
17
|
+
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return field_1.Field; } });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Locale = void 0;
|
|
4
|
+
const field_1 = require("@fields/field");
|
|
5
|
+
class Locale extends field_1.Field {
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
8
|
+
* @param {String} valueKey - Key to use in the prediction dict
|
|
9
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
10
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
11
|
+
*/
|
|
12
|
+
constructor({ prediction, valueKey = "value", reconstructed = false, pageNumber = 0, }) {
|
|
13
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
14
|
+
this.language = undefined;
|
|
15
|
+
this.country = undefined;
|
|
16
|
+
this.currency = undefined;
|
|
17
|
+
if ("language" in prediction && prediction.language !== "N/A")
|
|
18
|
+
this.language = prediction.language;
|
|
19
|
+
if ("country" in prediction && prediction.country !== "N/A")
|
|
20
|
+
this.country = prediction.country;
|
|
21
|
+
if ("currency" in prediction && prediction.currency !== "N/A")
|
|
22
|
+
this.currency = prediction.currency;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Locale = Locale;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Orientation = void 0;
|
|
4
|
+
const field_1 = require("@fields/field");
|
|
5
|
+
class Orientation extends field_1.Field {
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
8
|
+
* @param {String} valueKey - Key to use in the prediction dict
|
|
9
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
10
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
11
|
+
*/
|
|
12
|
+
constructor({ prediction, valueKey = "degrees", reconstructed = false, pageNumber = 0, }) {
|
|
13
|
+
const orientations = [0, 90, 180, 270];
|
|
14
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
15
|
+
this.value = parseInt(prediction[valueKey]);
|
|
16
|
+
if (isNaN(this.value))
|
|
17
|
+
this.probability = 0.0;
|
|
18
|
+
if (!orientations.includes(this.value))
|
|
19
|
+
this.value = 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.Orientation = Orientation;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
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
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _PaymentDetails_instances, _PaymentDetails_setKey;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PaymentDetails = void 0;
|
|
10
|
+
const field_1 = require("@fields/field");
|
|
11
|
+
class PaymentDetails extends field_1.Field {
|
|
12
|
+
/**
|
|
13
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
14
|
+
* @param {String} valueKey - Key to use in the prediction dict to get the iban
|
|
15
|
+
* @param {String} accountNumberKey - Key to use to get the account number in the prediction dict
|
|
16
|
+
* @param {String} ibanKey - Key to use to get the IBAN in the prediction dict
|
|
17
|
+
* @param {String} routingNumberKey - Key to use to get the routing number in the prediction dict
|
|
18
|
+
* @param {String} swiftKey - Key to use to get the SWIFT in the prediction dict
|
|
19
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
20
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
21
|
+
*/
|
|
22
|
+
constructor({ prediction, valueKey = "iban", accountNumberKey = "account_number", ibanKey = "iban", routingNumberKey = "routing_number", swiftKey = "swift", reconstructed = false, pageNumber = 0, }) {
|
|
23
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
24
|
+
_PaymentDetails_instances.add(this);
|
|
25
|
+
this.accountNumber = undefined;
|
|
26
|
+
this.iban = undefined;
|
|
27
|
+
this.routingNumber = undefined;
|
|
28
|
+
this.swift = undefined;
|
|
29
|
+
__classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[accountNumberKey], "accountNumber");
|
|
30
|
+
__classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[ibanKey], "iban");
|
|
31
|
+
__classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[routingNumberKey], "routingNumber");
|
|
32
|
+
__classPrivateFieldGet(this, _PaymentDetails_instances, "m", _PaymentDetails_setKey).call(this, prediction[swiftKey], "swift");
|
|
33
|
+
}
|
|
34
|
+
toString() {
|
|
35
|
+
let str = "";
|
|
36
|
+
const keys = ["accountNumber", "iban", "routingNumber", "swift"];
|
|
37
|
+
for (const key of keys) {
|
|
38
|
+
if (this[key])
|
|
39
|
+
str += `${this[key]}; `;
|
|
40
|
+
}
|
|
41
|
+
return str;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.PaymentDetails = PaymentDetails;
|
|
45
|
+
_PaymentDetails_instances = new WeakSet(), _PaymentDetails_setKey = function _PaymentDetails_setKey(value, key) {
|
|
46
|
+
if (typeof value === "string" && value !== "N/A")
|
|
47
|
+
this[key] = value;
|
|
48
|
+
else
|
|
49
|
+
this[key] = undefined;
|
|
50
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tax = void 0;
|
|
4
|
+
const field_1 = require("@fields/field");
|
|
5
|
+
class Tax extends field_1.Field {
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} prediction - Prediction object from HTTP response
|
|
8
|
+
* @param {String} valueKey - Key to use in the prediction dict to get the tax value
|
|
9
|
+
* @param {String} rateKey - Key to use to get the tax rate in the prediction dict
|
|
10
|
+
* @param {String} codeKey - Key to use to get the tax code in the prediction dict
|
|
11
|
+
* @param {Boolean} reconstructed - Does the object is reconstructed (not extracted by the API)
|
|
12
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf
|
|
13
|
+
*/
|
|
14
|
+
constructor({ prediction, valueKey = "value", rateKey = "rate", codeKey = "code", reconstructed = false, pageNumber = 0, }) {
|
|
15
|
+
var _a;
|
|
16
|
+
super({ prediction, valueKey, reconstructed, pageNumber });
|
|
17
|
+
this.rate = parseFloat(prediction[rateKey]);
|
|
18
|
+
if (isNaN(this.rate))
|
|
19
|
+
this.rate = undefined;
|
|
20
|
+
this.code = (_a = prediction[codeKey]) === null || _a === void 0 ? void 0 : _a.toString();
|
|
21
|
+
if (this.code === "N/A")
|
|
22
|
+
this.code = undefined;
|
|
23
|
+
this.value = parseFloat(prediction[valueKey]);
|
|
24
|
+
if (isNaN(this.value)) {
|
|
25
|
+
this.value = undefined;
|
|
26
|
+
this.probability = 0.0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
toString() {
|
|
30
|
+
let str = "";
|
|
31
|
+
const keys = ["value", "rate", "code"];
|
|
32
|
+
for (const [i, key] of keys.entries()) {
|
|
33
|
+
const value = this[key] === undefined ? "_" : this[key].toString();
|
|
34
|
+
if (i < keys.length - 1)
|
|
35
|
+
str += `${value}${key === "rate" ? "%" : ""}; `;
|
|
36
|
+
else
|
|
37
|
+
str += value;
|
|
38
|
+
}
|
|
39
|
+
return str;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Tax = Tax;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
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
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _FinancialDocument_instances, _FinancialDocument_initFromScratch, _FinancialDocument_initFromApiPrediction, _FinancialDocument_checklist, _FinancialDocument_taxesMatchTotalIncl;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.FinancialDocument = void 0;
|
|
10
|
+
const document_1 = require("@documents/document");
|
|
11
|
+
const invoice_1 = require("@documents/invoice");
|
|
12
|
+
const receipt_1 = require("@documents/receipt");
|
|
13
|
+
const fields_1 = require("@documents/fields");
|
|
14
|
+
class FinancialDocument extends document_1.Document {
|
|
15
|
+
/**
|
|
16
|
+
* @param {Object} apiPrediction - Json parsed prediction from HTTP response
|
|
17
|
+
* @param {Input} input - Input object
|
|
18
|
+
* @param {Integer} pageNumber - Page number for multi pages pdf input
|
|
19
|
+
* @param {Object} locale - locale value for creating FinancialDocument object from scratch
|
|
20
|
+
* @param {Object} totalIncl - total tax included value for creating FinancialDocument object from scratch
|
|
21
|
+
* @param {Object} totalExcl - total tax excluded value for creating FinancialDocument object from scratch
|
|
22
|
+
* @param {Object} Date - date value for creating FinancialDocument object from scratch
|
|
23
|
+
* @param {Object} InvoiceNumber - Invoice number value for creating FinancialDocument object from scratch
|
|
24
|
+
* @param {Object} taxes - taxes value for creating FinancialDocument object from scratch
|
|
25
|
+
* @param {Object} supplier - supplier value for creating FinancialDocument object from scratch
|
|
26
|
+
* @param {Object} supplierAddress - supplier address value for creating FinancialDocument object from scratch
|
|
27
|
+
* @param {Object} paymentDetails - payment details value for creating FinancialDocument object from scratch
|
|
28
|
+
* @param {Object} companyNumber - company number value for creating FinancialDocument object from scratch
|
|
29
|
+
* @param {Object} vatNumber - vat number value for creating FinancialDocument object from scratch
|
|
30
|
+
* @param {Object} orientation - orientation value for creating FinancialDocument object from scratch
|
|
31
|
+
* @param {Object} totalTax - total tax value for creating FinancialDocument object from scratch
|
|
32
|
+
* @param {Object} time - time value for creating FinancialDocument object from scratch
|
|
33
|
+
* @param {Object} customerName - customer name value for creating FinancialDocument object from scratch
|
|
34
|
+
* @param {Object} customerAddress - customer address value for creating FinancialDocument object from scratch
|
|
35
|
+
* @param {Object} customerCompanyRegistration - customer company registration value for creating FinancialDocument object from scratch
|
|
36
|
+
* @param {Object} pageNumber - pageNumber for multi pages pdf input
|
|
37
|
+
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
38
|
+
*/
|
|
39
|
+
constructor({ apiPrediction = undefined, inputFile = undefined, locale = undefined, totalIncl = undefined, totalExcl = undefined, date = undefined, invoiceNumber = undefined, dueDate = undefined, taxes = undefined, supplier = undefined, supplierAddress = undefined, paymentDetails = undefined, companyNumber = undefined, vatNumber = undefined, orientation = undefined, totalTax = undefined, time = undefined, customerName = undefined, customerAddress = undefined, customerCompanyRegistration = undefined, words = undefined, pageNumber = 0, level = "page", }) {
|
|
40
|
+
super(inputFile);
|
|
41
|
+
_FinancialDocument_instances.add(this);
|
|
42
|
+
this.level = level;
|
|
43
|
+
if (apiPrediction === undefined) {
|
|
44
|
+
__classPrivateFieldGet(this, _FinancialDocument_instances, "m", _FinancialDocument_initFromScratch).call(this, {
|
|
45
|
+
locale,
|
|
46
|
+
totalIncl,
|
|
47
|
+
totalExcl,
|
|
48
|
+
date,
|
|
49
|
+
invoiceNumber,
|
|
50
|
+
dueDate,
|
|
51
|
+
taxes,
|
|
52
|
+
supplier,
|
|
53
|
+
supplierAddress,
|
|
54
|
+
paymentDetails,
|
|
55
|
+
companyNumber,
|
|
56
|
+
vatNumber,
|
|
57
|
+
orientation,
|
|
58
|
+
pageNumber,
|
|
59
|
+
totalTax,
|
|
60
|
+
time,
|
|
61
|
+
customerName,
|
|
62
|
+
customerAddress,
|
|
63
|
+
customerCompanyRegistration,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
__classPrivateFieldGet(this, _FinancialDocument_instances, "m", _FinancialDocument_initFromApiPrediction).call(this, apiPrediction, inputFile, pageNumber, words);
|
|
68
|
+
}
|
|
69
|
+
__classPrivateFieldGet(this, _FinancialDocument_instances, "m", _FinancialDocument_checklist).call(this);
|
|
70
|
+
}
|
|
71
|
+
toString() {
|
|
72
|
+
return `
|
|
73
|
+
-----Financial document-----
|
|
74
|
+
Filename: ${this.filename}
|
|
75
|
+
Total amount: ${this.totalIncl.value}
|
|
76
|
+
Date: ${this.date.value}
|
|
77
|
+
Supplier: ${this.supplier.value}
|
|
78
|
+
Total taxes: ${this.totalTax.value}
|
|
79
|
+
`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.FinancialDocument = FinancialDocument;
|
|
83
|
+
_FinancialDocument_instances = new WeakSet(), _FinancialDocument_initFromScratch = function _FinancialDocument_initFromScratch({ locale, totalIncl, totalExcl, totalTax, date, invoiceNumber, dueDate, taxes, paymentDetails, companyNumber, vatNumber, orientation, pageNumber, supplier, supplierAddress, time, customerName, customerAddress, customerCompanyRegistration, }) {
|
|
84
|
+
const constructPrediction = function (item) {
|
|
85
|
+
return { prediction: { value: item }, valueKey: "value", pageNumber };
|
|
86
|
+
};
|
|
87
|
+
this.locale = new fields_1.Locale(constructPrediction(locale));
|
|
88
|
+
this.totalIncl = new fields_1.Amount(constructPrediction(totalIncl));
|
|
89
|
+
this.totalExcl = new fields_1.Amount(constructPrediction(totalExcl));
|
|
90
|
+
this.totalTax = new fields_1.Amount(constructPrediction(totalTax));
|
|
91
|
+
this.date = new fields_1.DateField(constructPrediction(date));
|
|
92
|
+
this.dueDate = new fields_1.DateField(constructPrediction(dueDate));
|
|
93
|
+
this.supplier = new fields_1.Field(constructPrediction(supplier));
|
|
94
|
+
this.supplierAddress = new fields_1.Field(this.constructPrediction(supplierAddress));
|
|
95
|
+
this.time = new fields_1.Field(constructPrediction(time));
|
|
96
|
+
this.orientation = new fields_1.Orientation(constructPrediction(orientation));
|
|
97
|
+
this.invoiceNumber = new fields_1.Field(constructPrediction(invoiceNumber));
|
|
98
|
+
this.paymentDetails = new fields_1.Field(constructPrediction(paymentDetails));
|
|
99
|
+
this.companyNumber = new fields_1.Field(constructPrediction(companyNumber));
|
|
100
|
+
this.vatNumber = new fields_1.Field(constructPrediction(vatNumber));
|
|
101
|
+
this.customerName = new fields_1.Field(this.constructPrediction(customerName));
|
|
102
|
+
this.customerAddress = new fields_1.Field(this.constructPrediction(customerAddress));
|
|
103
|
+
this.customerCompanyRegistration = new fields_1.Field(this.constructPrediction(customerCompanyRegistration));
|
|
104
|
+
if (taxes !== undefined) {
|
|
105
|
+
this.taxes = [];
|
|
106
|
+
for (const t of taxes) {
|
|
107
|
+
this.taxes.push(new fields_1.Tax({
|
|
108
|
+
prediction: { value: t[0], rate: t[1] },
|
|
109
|
+
pageNumber,
|
|
110
|
+
valueKey: "value",
|
|
111
|
+
rateKey: "rate",
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}, _FinancialDocument_initFromApiPrediction = function _FinancialDocument_initFromApiPrediction(apiPrediction, inputFile, pageNumber, words) {
|
|
116
|
+
if (Object.keys(apiPrediction).includes("invoice_number")) {
|
|
117
|
+
const invoice = new invoice_1.Invoice({
|
|
118
|
+
apiPrediction,
|
|
119
|
+
inputFile,
|
|
120
|
+
pageNumber,
|
|
121
|
+
level: this.level,
|
|
122
|
+
words: words,
|
|
123
|
+
});
|
|
124
|
+
this.locale = invoice.locale;
|
|
125
|
+
this.totalIncl = invoice.totalIncl;
|
|
126
|
+
this.totalExcl = invoice.totalExcl;
|
|
127
|
+
this.date = invoice.invoiceDate;
|
|
128
|
+
this.invoiceNumber = invoice.invoiceNumber;
|
|
129
|
+
this.dueDate = invoice.dueDate;
|
|
130
|
+
this.taxes = invoice.taxes;
|
|
131
|
+
this.supplier = invoice.supplier;
|
|
132
|
+
this.supplierAddress = invoice.supplierAddress;
|
|
133
|
+
this.paymentDetails = invoice.paymentDetails;
|
|
134
|
+
this.companyNumber = invoice.companyNumber;
|
|
135
|
+
this.orientation = invoice.orientation;
|
|
136
|
+
this.totalTax = invoice.totalTax;
|
|
137
|
+
if (invoice.words)
|
|
138
|
+
this.words = invoice.words;
|
|
139
|
+
this.time = new fields_1.Field({
|
|
140
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
141
|
+
});
|
|
142
|
+
this.customerName = invoice.customerName;
|
|
143
|
+
this.customerAddress = invoice.customerAddress;
|
|
144
|
+
this.customerCompanyRegistration = invoice.customerCompanyRegistration;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
const receipt = new receipt_1.Receipt({
|
|
148
|
+
apiPrediction,
|
|
149
|
+
inputFile,
|
|
150
|
+
pageNumber,
|
|
151
|
+
level: this.level,
|
|
152
|
+
words: words,
|
|
153
|
+
});
|
|
154
|
+
this.orientation = receipt.orientation;
|
|
155
|
+
this.date = receipt.date;
|
|
156
|
+
this.dueDate = receipt.date;
|
|
157
|
+
this.taxes = receipt.taxes;
|
|
158
|
+
this.locale = receipt.locale;
|
|
159
|
+
this.totalIncl = receipt.totalIncl;
|
|
160
|
+
this.totalExcl = receipt.totalExcl;
|
|
161
|
+
this.supplier = receipt.merchantName;
|
|
162
|
+
this.supplierAddress = new fields_1.Field({
|
|
163
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
164
|
+
});
|
|
165
|
+
this.time = receipt.time;
|
|
166
|
+
this.totalTax = receipt.totalTax;
|
|
167
|
+
this.invoiceNumber = new fields_1.Field({
|
|
168
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
169
|
+
});
|
|
170
|
+
this.paymentDetails = new fields_1.Field({
|
|
171
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
172
|
+
});
|
|
173
|
+
this.companyNumber = new fields_1.Field({
|
|
174
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
175
|
+
});
|
|
176
|
+
this.customerName = new fields_1.Field({
|
|
177
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
178
|
+
});
|
|
179
|
+
this.customerAddress = new fields_1.Field({
|
|
180
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
181
|
+
});
|
|
182
|
+
this.customerCompanyRegistration = [];
|
|
183
|
+
if (receipt.words)
|
|
184
|
+
this.words = receipt.words;
|
|
185
|
+
}
|
|
186
|
+
}, _FinancialDocument_checklist = function _FinancialDocument_checklist() {
|
|
187
|
+
this.checklist = {
|
|
188
|
+
taxesMatchTotalIncl: __classPrivateFieldGet(this, _FinancialDocument_instances, "m", _FinancialDocument_taxesMatchTotalIncl).call(this),
|
|
189
|
+
};
|
|
190
|
+
}, _FinancialDocument_taxesMatchTotalIncl = function _FinancialDocument_taxesMatchTotalIncl() {
|
|
191
|
+
// Check taxes and total include exist
|
|
192
|
+
if (this.taxes.length === 0 || this.totalIncl.value === undefined)
|
|
193
|
+
return false;
|
|
194
|
+
// Reconstruct totalIncl from taxes
|
|
195
|
+
let totalVat = 0;
|
|
196
|
+
let reconstructedTotal = 0;
|
|
197
|
+
this.taxes.forEach((tax) => {
|
|
198
|
+
if (tax.value === undefined || !tax.rate)
|
|
199
|
+
return false;
|
|
200
|
+
totalVat += tax.value;
|
|
201
|
+
reconstructedTotal += tax.value + (100 * tax.value) / tax.rate;
|
|
202
|
+
});
|
|
203
|
+
// Sanity check
|
|
204
|
+
if (totalVat <= 0)
|
|
205
|
+
return false;
|
|
206
|
+
// Crate epsilon
|
|
207
|
+
const eps = 1 / (100 * totalVat);
|
|
208
|
+
if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
|
|
209
|
+
reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
|
|
210
|
+
this.taxes = this.taxes.map((tax) => (Object.assign(Object.assign({}, tax), { confidence: 1.0 })));
|
|
211
|
+
this.totalTax.probability = 1.0;
|
|
212
|
+
this.totalIncl.probability = 1.0;
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FinancialDocument = exports.Invoice = exports.Receipt = exports.Document = exports.Field = void 0;
|
|
4
|
+
var fields_1 = require("@documents/fields");
|
|
5
|
+
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return fields_1.Field; } });
|
|
6
|
+
var document_1 = require("@documents/document");
|
|
7
|
+
Object.defineProperty(exports, "Document", { enumerable: true, get: function () { return document_1.Document; } });
|
|
8
|
+
var receipt_1 = require("@documents/receipt");
|
|
9
|
+
Object.defineProperty(exports, "Receipt", { enumerable: true, get: function () { return receipt_1.Receipt; } });
|
|
10
|
+
var invoice_1 = require("@documents/invoice");
|
|
11
|
+
Object.defineProperty(exports, "Invoice", { enumerable: true, get: function () { return invoice_1.Invoice; } });
|
|
12
|
+
var financialDocument_1 = require("@documents/financialDocument");
|
|
13
|
+
Object.defineProperty(exports, "FinancialDocument", { enumerable: true, get: function () { return financialDocument_1.FinancialDocument; } });
|