mindee 1.1.0 → 1.1.2
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 +12 -0
- package/README.md +13 -13
- package/coverage.lcov +0 -0
- package/lib/api/financialDocument.js +1 -1
- package/lib/api/invoice.js +1 -1
- package/lib/api/request.js +1 -1
- package/lib/api/response.js +1 -3
- package/lib/documents/fields/field.js +2 -4
- package/lib/documents/financialDocument.js +53 -10
- package/lib/documents/invoice.js +48 -9
- package/lib/documents/receipt.js +5 -5
- package/mindee/api/financialDocument.js +1 -1
- package/mindee/api/invoice.js +1 -1
- package/mindee/api/response.js +1 -2
- package/mindee/documents/fields/field.js +2 -5
- package/mindee/documents/financialDocument.js +43 -7
- package/mindee/documents/invoice.js +52 -6
- package/mindee/documents/receipt.js +5 -5
- package/mindee/inputs.js +0 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v1.1.2
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- fix: 🐛 Fix returned probability value
|
|
8
|
+
- fix: 🐛 Fix returned bbox value
|
|
9
|
+
|
|
10
|
+
### new
|
|
11
|
+
|
|
12
|
+
- new: ✨ New Mindee Invoice API V3 support
|
|
13
|
+
- new: ✨ Add new supplier and customer fields
|
|
14
|
+
|
|
3
15
|
## v1.1.0 (2022-01-03)
|
|
4
16
|
|
|
5
17
|
### new
|
package/README.md
CHANGED
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
# Installation
|
|
4
4
|
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
The SDK is officially supported on Node.js LTS _active_ and _maintenance_
|
|
8
|
+
[versions](https://nodejs.org/en/about/releases/).
|
|
9
|
+
|
|
5
10
|
## From source code
|
|
6
11
|
|
|
7
|
-
Download and decompress or clone the source code from
|
|
12
|
+
Download and decompress or clone the source code from GitHub and then do in your Node.js project:
|
|
8
13
|
|
|
9
14
|
```sh
|
|
10
15
|
npm install mindee
|
|
@@ -12,7 +17,7 @@ npm install mindee
|
|
|
12
17
|
|
|
13
18
|
# Usage
|
|
14
19
|
|
|
15
|
-
You can use the SDK easily by creating a Client like this
|
|
20
|
+
You can use the SDK easily by creating a Client like this:
|
|
16
21
|
|
|
17
22
|
```js
|
|
18
23
|
const { Client } = require("mindee");
|
|
@@ -32,11 +37,14 @@ mindeeClient.financialDocument.parse({
|
|
|
32
37
|
|
|
33
38
|
Three apis are actually supported : invoice (`ìnvoice`), receipt (`receipt`) and financial document (`financialDocument`)
|
|
34
39
|
|
|
35
|
-
You can find more examples on how to use the SDK into the folder `examples
|
|
40
|
+
You can find more examples on how to use the SDK into the folder `examples`.
|
|
36
41
|
|
|
37
42
|
## Client
|
|
38
43
|
|
|
39
|
-
The
|
|
44
|
+
The Mindee client can take multiple parameters to be initialize.
|
|
45
|
+
Some this parameters can also be set with env variables.
|
|
46
|
+
If the env variable and the parameter are both set, the parameter will be the one chosen by the client.
|
|
47
|
+
This is a list of them:
|
|
40
48
|
|
|
41
49
|
- invoiceToken (env variable : `MINDEE_INVOICE_TOKEN`) The expense api token
|
|
42
50
|
- receiptToken (env variable : `MINDEE_RECEIPT_TOKEN`) The invoice api token
|
|
@@ -118,15 +126,6 @@ mindeeClient.financialDocument
|
|
|
118
126
|
|
|
119
127
|
# Tests
|
|
120
128
|
|
|
121
|
-
First, link your package to the test repository by linking the node package to the tests :
|
|
122
|
-
|
|
123
|
-
```sh
|
|
124
|
-
cd mindee-api-nodejs/
|
|
125
|
-
npm link
|
|
126
|
-
cd tests/
|
|
127
|
-
npm link mindee
|
|
128
|
-
```
|
|
129
|
-
|
|
130
129
|
To run the tests, use the command `npm run test`
|
|
131
130
|
|
|
132
131
|
# Documentation
|
|
@@ -135,3 +134,4 @@ A basic documentation of the sdk has been done with the help of JSDoc.
|
|
|
135
134
|
If you want to generate it, you can use the command `npm run documentation`.
|
|
136
135
|
A folder `docs` will be created with generated documentation.
|
|
137
136
|
Open the `index.html` in your browser to read the documentation.
|
|
137
|
+
|
package/coverage.lcov
CHANGED
|
File without changes
|
|
@@ -46,7 +46,7 @@ class APIFinancialDocument extends APIObject {
|
|
|
46
46
|
});
|
|
47
47
|
yield inputFile.init();
|
|
48
48
|
_this.apiToken = inputFile.fileExtension === "application/pdf" ? _this.invoiceToken : _this.receiptToken;
|
|
49
|
-
var url = inputFile.fileExtension === "application/pdf" ? "/invoices/
|
|
49
|
+
var url = inputFile.fileExtension === "application/pdf" ? "/invoices/v3/predict" : "/expense_receipts/v3/predict";
|
|
50
50
|
|
|
51
51
|
_superprop_getParse().call(_this);
|
|
52
52
|
|
package/lib/api/invoice.js
CHANGED
package/lib/api/request.js
CHANGED
package/lib/api/response.js
CHANGED
|
@@ -14,8 +14,6 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
14
14
|
|
|
15
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
16
|
|
|
17
|
-
var Document = require("../documents").document;
|
|
18
|
-
|
|
19
17
|
var Receipt = require("../documents").receipt;
|
|
20
18
|
|
|
21
19
|
var Invoice = require("../documents").invoice;
|
|
@@ -84,7 +82,7 @@ class Response {
|
|
|
84
82
|
this[this.documentType] = constructors[this.documentType]({
|
|
85
83
|
apiPrediction: this.httpResponse.data.document.inference.prediction,
|
|
86
84
|
inputFile: this.input,
|
|
87
|
-
pageNumber:
|
|
85
|
+
pageNumber: this.httpResponse.data.document.n_pages,
|
|
88
86
|
level: "document"
|
|
89
87
|
});
|
|
90
88
|
}
|
|
@@ -19,13 +19,11 @@ class Field {
|
|
|
19
19
|
this.pageNumber = pageNumber;
|
|
20
20
|
this.reconstructed = reconstructed;
|
|
21
21
|
this.value = undefined;
|
|
22
|
-
this.probability = 0.0;
|
|
23
|
-
this.bbox = [];
|
|
22
|
+
this.probability = prediction.confidence ? prediction.confidence : 0.0;
|
|
23
|
+
this.bbox = prediction.polygon ? prediction.polygon : [];
|
|
24
24
|
|
|
25
25
|
if (valueKey in prediction && prediction[valueKey] !== null) {
|
|
26
26
|
this.value = prediction[valueKey];
|
|
27
|
-
if (prediction.probability) this.probability = prediction.probability;
|
|
28
|
-
if (prediction.segmentation) this.bbox = prediction.segmentation.bounding_box || [];
|
|
29
27
|
|
|
30
28
|
if (extraFields) {
|
|
31
29
|
for (var fieldName of extraFields) {
|
|
@@ -45,13 +45,17 @@ class FinancialDocument extends Document {
|
|
|
45
45
|
* @param {Object} Date - date value for creating FinancialDocument object from scratch
|
|
46
46
|
* @param {Object} InvoiceNumber - Invoice number value for creating FinancialDocument object from scratch
|
|
47
47
|
* @param {Object} taxes - taxes value for creating FinancialDocument object from scratch
|
|
48
|
-
* @param {Object}
|
|
48
|
+
* @param {Object} supplier - supplier value for creating FinancialDocument object from scratch
|
|
49
|
+
* @param {Object} supplierAddress - supplier address value for creating FinancialDocument object from scratch
|
|
49
50
|
* @param {Object} paymentDetails - payment details value for creating FinancialDocument object from scratch
|
|
50
51
|
* @param {Object} companyNumber - company number value for creating FinancialDocument object from scratch
|
|
51
52
|
* @param {Object} vatNumber - vat number value for creating FinancialDocument object from scratch
|
|
52
53
|
* @param {Object} orientation - orientation value for creating FinancialDocument object from scratch
|
|
53
54
|
* @param {Object} totalTax - total tax value for creating FinancialDocument object from scratch
|
|
54
55
|
* @param {Object} time - time value for creating FinancialDocument object from scratch
|
|
56
|
+
* @param {Object} customerName - customer name value for creating FinancialDocument object from scratch
|
|
57
|
+
* @param {Object} customerAddress - customer address value for creating FinancialDocument object from scratch
|
|
58
|
+
* @param {Object} customerCompanyRegistration - customer company registration value for creating FinancialDocument object from scratch
|
|
55
59
|
* @param {Object} pageNumber - pageNumber for multi pages pdf input
|
|
56
60
|
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
57
61
|
*/
|
|
@@ -66,13 +70,17 @@ class FinancialDocument extends Document {
|
|
|
66
70
|
invoiceNumber: _invoiceNumber = undefined,
|
|
67
71
|
dueDate: _dueDate = undefined,
|
|
68
72
|
taxes: _taxes = undefined,
|
|
69
|
-
|
|
73
|
+
supplier: _supplier = undefined,
|
|
74
|
+
supplierAddress: _supplierAddress = undefined,
|
|
70
75
|
paymentDetails: _paymentDetails = undefined,
|
|
71
76
|
companyNumber: _companyNumber = undefined,
|
|
72
77
|
vatNumber: _vatNumber = undefined,
|
|
73
78
|
orientation: _orientation = undefined,
|
|
74
79
|
totalTax: _totalTax = undefined,
|
|
75
80
|
time: _time = undefined,
|
|
81
|
+
customerName: _customerName = undefined,
|
|
82
|
+
customerAddress: _customerAddress = undefined,
|
|
83
|
+
customerCompanyRegistration: _customerCompanyRegistration = undefined,
|
|
76
84
|
pageNumber: _pageNumber = 0,
|
|
77
85
|
level = "page"
|
|
78
86
|
} = _ref;
|
|
@@ -97,14 +105,18 @@ class FinancialDocument extends Document {
|
|
|
97
105
|
invoiceNumber: _invoiceNumber,
|
|
98
106
|
dueDate: _dueDate,
|
|
99
107
|
taxes: _taxes,
|
|
100
|
-
supplier,
|
|
108
|
+
supplier: _supplier,
|
|
109
|
+
supplierAddress: _supplierAddress,
|
|
101
110
|
paymentDetails: _paymentDetails,
|
|
102
111
|
companyNumber: _companyNumber,
|
|
103
112
|
vatNumber: _vatNumber,
|
|
104
113
|
orientation: _orientation,
|
|
105
114
|
pageNumber: _pageNumber,
|
|
106
115
|
totalTax: _totalTax,
|
|
107
|
-
time: _time
|
|
116
|
+
time: _time,
|
|
117
|
+
customerName: _customerName,
|
|
118
|
+
customerAddress: _customerAddress,
|
|
119
|
+
customerCompanyRegistration: _customerCompanyRegistration
|
|
108
120
|
});
|
|
109
121
|
} else {
|
|
110
122
|
_classPrivateMethodGet(this, _initFromApiPrediction, _initFromApiPrediction2).call(this, _apiPrediction, _inputFile, _pageNumber);
|
|
@@ -135,7 +147,11 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
|
|
|
135
147
|
orientation,
|
|
136
148
|
pageNumber,
|
|
137
149
|
supplier,
|
|
138
|
-
|
|
150
|
+
supplierAddress,
|
|
151
|
+
time,
|
|
152
|
+
customerName,
|
|
153
|
+
customerAddress,
|
|
154
|
+
customerCompanyRegistration
|
|
139
155
|
} = _ref2;
|
|
140
156
|
|
|
141
157
|
var constructPrediction = function constructPrediction(item) {
|
|
@@ -155,12 +171,16 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
|
|
|
155
171
|
this.date = new Date(constructPrediction(date));
|
|
156
172
|
this.dueDate = new Date(constructPrediction(dueDate));
|
|
157
173
|
this.supplier = new Field(constructPrediction(supplier));
|
|
174
|
+
this.supplierAddress = new Field(this.constructPrediction(supplierAddress));
|
|
158
175
|
this.time = new Field(constructPrediction(time));
|
|
159
176
|
this.orientation = new Orientation(constructPrediction(orientation));
|
|
160
177
|
this.invoiceNumber = new Field(constructPrediction(invoiceNumber));
|
|
161
178
|
this.paymentDetails = new Field(constructPrediction(paymentDetails));
|
|
162
179
|
this.companyNumber = new Field(constructPrediction(companyNumber));
|
|
163
180
|
this.vatNumber = new Field(constructPrediction(vatNumber));
|
|
181
|
+
this.customerName = new Field(this.constructPrediction(customerName));
|
|
182
|
+
this.customerAddress = new Field(this.constructPrediction(customerAddress));
|
|
183
|
+
this.customerCompanyRegistration = new Field(this.constructPrediction(customerCompanyRegistration));
|
|
164
184
|
|
|
165
185
|
if (taxes !== undefined) {
|
|
166
186
|
this.taxes = [];
|
|
@@ -195,6 +215,7 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, in
|
|
|
195
215
|
this.dueDate = invoice.dueDate;
|
|
196
216
|
this.taxes = invoice.taxes;
|
|
197
217
|
this.supplier = invoice.supplier;
|
|
218
|
+
this.supplierAddress = invoice.supplierAddress;
|
|
198
219
|
this.paymentDetails = invoice.paymentDetails;
|
|
199
220
|
this.companyNumber = invoice.companyNumber;
|
|
200
221
|
this.orientation = invoice.orientation;
|
|
@@ -202,9 +223,12 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, in
|
|
|
202
223
|
this.time = new Field({
|
|
203
224
|
prediction: {
|
|
204
225
|
value: undefined,
|
|
205
|
-
|
|
226
|
+
confidence: 0.0
|
|
206
227
|
}
|
|
207
228
|
});
|
|
229
|
+
this.customerName = invoice.customerName;
|
|
230
|
+
this.customerAddress = invoice.customerAddress;
|
|
231
|
+
this.customerCompanyRegistration = invoice.customerCompanyRegistration;
|
|
208
232
|
} else {
|
|
209
233
|
var receipt = new Receipt({
|
|
210
234
|
apiPrediction,
|
|
@@ -220,26 +244,45 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, in
|
|
|
220
244
|
this.totalIncl = receipt.totalIncl;
|
|
221
245
|
this.totalExcl = receipt.totalExcl;
|
|
222
246
|
this.supplier = receipt.merchantName;
|
|
247
|
+
this.supplierAddress = new Field({
|
|
248
|
+
prediction: {
|
|
249
|
+
value: undefined,
|
|
250
|
+
confidence: 0.0
|
|
251
|
+
}
|
|
252
|
+
});
|
|
223
253
|
this.time = receipt.time;
|
|
224
254
|
this.totalTax = receipt.totalTax;
|
|
225
255
|
this.invoiceNumber = new Field({
|
|
226
256
|
prediction: {
|
|
227
257
|
value: undefined,
|
|
228
|
-
|
|
258
|
+
confidence: 0.0
|
|
229
259
|
}
|
|
230
260
|
});
|
|
231
261
|
this.paymentDetails = new Field({
|
|
232
262
|
prediction: {
|
|
233
263
|
value: undefined,
|
|
234
|
-
|
|
264
|
+
confidence: 0.0
|
|
235
265
|
}
|
|
236
266
|
});
|
|
237
267
|
this.companyNumber = new Field({
|
|
238
268
|
prediction: {
|
|
239
269
|
value: undefined,
|
|
240
|
-
|
|
270
|
+
confidence: 0.0
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
this.customerName = new Field({
|
|
274
|
+
prediction: {
|
|
275
|
+
value: undefined,
|
|
276
|
+
confidence: 0.0
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
this.customerAddress = new Field({
|
|
280
|
+
prediction: {
|
|
281
|
+
value: undefined,
|
|
282
|
+
confidence: 0.0
|
|
241
283
|
}
|
|
242
284
|
});
|
|
285
|
+
this.customerCompanyRegistration = [];
|
|
243
286
|
}
|
|
244
287
|
};
|
|
245
288
|
|
|
@@ -267,7 +310,7 @@ var _taxesMatchTotalIncl2 = function _taxesMatchTotalIncl2() {
|
|
|
267
310
|
|
|
268
311
|
if (this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal && reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02) {
|
|
269
312
|
this.taxes = this.taxes.map(tax => _objectSpread(_objectSpread({}, tax), {}, {
|
|
270
|
-
|
|
313
|
+
confidence: 1.0
|
|
271
314
|
}));
|
|
272
315
|
this.totalTax.probability = 1.0;
|
|
273
316
|
this.totalIncl.probability = 1.0;
|
package/lib/documents/invoice.js
CHANGED
|
@@ -57,11 +57,15 @@ class Invoice extends Document {
|
|
|
57
57
|
* @param {Object} invoiceNumber - invoice number value for creating Invoice object from scratch
|
|
58
58
|
* @param {Object} taxes - taxes value for creating Invoice object from scratch
|
|
59
59
|
* @param {Object} supplier - supplier value for creating Invoice object from scratch
|
|
60
|
+
* @param {Object} supplierAddress - supplier address value for creating Invoice object from scratch
|
|
60
61
|
* @param {Object} paymentDetails - payment details value for creating Invoice object from scratch
|
|
61
62
|
* @param {Object} companyNumber - company number value for creating Invoice object from scratch
|
|
62
63
|
* @param {Object} vatNumber - vat number value for creating Invoice object from scratch
|
|
63
64
|
* @param {Object} orientation - orientation value for creating Invoice object from scratch
|
|
64
65
|
* @param {Object} totalTax - total tax value for creating Invoice object from scratch
|
|
66
|
+
* @param {Object} customerName - customer name value for creating Invoice object from scratch
|
|
67
|
+
* @param {Object} customerAddress - customer address value for creating Invoice object from scratch
|
|
68
|
+
* @param {Object} customerCompanyRegistration - customer company registration value for creating Invoice object from scratch
|
|
65
69
|
* @param {Number} pageNumber - pageNumber for multi pages pdf input
|
|
66
70
|
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
67
71
|
*/
|
|
@@ -77,11 +81,15 @@ class Invoice extends Document {
|
|
|
77
81
|
dueDate: _dueDate = undefined,
|
|
78
82
|
taxes: _taxes = undefined,
|
|
79
83
|
supplier: _supplier = undefined,
|
|
84
|
+
supplierAddress: _supplierAddress = undefined,
|
|
80
85
|
paymentDetails: _paymentDetails = undefined,
|
|
81
86
|
companyNumber: _companyNumber = undefined,
|
|
82
87
|
vatNumber: _vatNumber = undefined,
|
|
83
88
|
orientation: _orientation = undefined,
|
|
84
89
|
totalTax: _totalTax = undefined,
|
|
90
|
+
customerName: _customerName = undefined,
|
|
91
|
+
customerAddress: _customerAddress = undefined,
|
|
92
|
+
customerCompanyRegistration: _customerCompanyRegistration = undefined,
|
|
85
93
|
pageNumber: _pageNumber = 0,
|
|
86
94
|
level = "page"
|
|
87
95
|
} = _ref;
|
|
@@ -131,12 +139,16 @@ class Invoice extends Document {
|
|
|
131
139
|
dueDate: _dueDate,
|
|
132
140
|
taxes: _taxes,
|
|
133
141
|
supplier: _supplier,
|
|
142
|
+
supplierAddress: _supplierAddress,
|
|
134
143
|
paymentDetails: _paymentDetails,
|
|
135
144
|
companyNumber: _companyNumber,
|
|
136
145
|
vatNumber: _vatNumber,
|
|
137
146
|
orientation: _orientation,
|
|
138
147
|
pageNumber: _pageNumber,
|
|
139
|
-
totalTax: _totalTax
|
|
148
|
+
totalTax: _totalTax,
|
|
149
|
+
customerName: _customerName,
|
|
150
|
+
customerAddress: _customerAddress,
|
|
151
|
+
customerCompanyRegistration: _customerCompanyRegistration
|
|
140
152
|
});
|
|
141
153
|
} else {
|
|
142
154
|
_classPrivateMethodGet(this, _initFromApiPrediction, _initFromApiPrediction2).call(this, _apiPrediction, _pageNumber);
|
|
@@ -148,7 +160,7 @@ class Invoice extends Document {
|
|
|
148
160
|
}
|
|
149
161
|
|
|
150
162
|
toString() {
|
|
151
|
-
return "\n -----Invoice data-----\n Filename: ".concat(this.filename, "\n Invoice number: ").concat(this.invoiceNumber.value, "\n Total amount including taxes: ").concat(this.totalIncl.value, "\n Total amount excluding taxes: ").concat(this.totalExcl.value, "\n Invoice Date: ").concat(this.invoiceDate.value, "\n Supplier name: ").concat(this.supplier.value, "\n Taxes: ").concat(this.taxes.map(tax => tax.toString()).join(" - "), "\n Total taxes: ").concat(this.totalTax.value, "\n ");
|
|
163
|
+
return "\n -----Invoice data-----\n Filename: ".concat(this.filename, "\n Invoice number: ").concat(this.invoiceNumber.value, "\n Total amount including taxes: ").concat(this.totalIncl.value, "\n Total amount excluding taxes: ").concat(this.totalExcl.value, "\n Invoice Date: ").concat(this.invoiceDate.value, "\n Supplier name: ").concat(this.supplier.value, "\n Supplier address: ").concat(this.supplierAddress.value, "\n Customer name: ").concat(this.customerName.value, "\n Customer address: ").concat(this.customerAddress.value, "\n Taxes: ").concat(this.taxes.map(tax => tax.toString()).join(" - "), "\n Total taxes: ").concat(this.totalTax.value, "\n ");
|
|
152
164
|
}
|
|
153
165
|
|
|
154
166
|
}
|
|
@@ -164,11 +176,15 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
|
|
|
164
176
|
dueDate,
|
|
165
177
|
taxes,
|
|
166
178
|
supplier,
|
|
179
|
+
supplierAddress,
|
|
167
180
|
paymentDetails,
|
|
168
181
|
companyNumber,
|
|
169
182
|
vatNumber,
|
|
170
183
|
orientation,
|
|
171
|
-
pageNumber
|
|
184
|
+
pageNumber,
|
|
185
|
+
customerName,
|
|
186
|
+
customerAddress,
|
|
187
|
+
customerCompanyRegistration
|
|
172
188
|
} = _ref2;
|
|
173
189
|
this.locale = new Locale(this.constructPrediction(locale));
|
|
174
190
|
this.totalIncl = new Amount(this.constructPrediction(totalIncl));
|
|
@@ -178,10 +194,14 @@ var _initFromScratch2 = function _initFromScratch2(_ref2) {
|
|
|
178
194
|
this.invoiceDate = new Date(this.constructPrediction(invoiceDate));
|
|
179
195
|
this.dueDate = new Date(this.constructPrediction(dueDate));
|
|
180
196
|
this.supplier = new Field(this.constructPrediction(supplier));
|
|
197
|
+
this.supplierAddress = new Field(this.constructPrediction(supplierAddress));
|
|
181
198
|
this.invoiceNumber = new Field(this.constructPrediction(invoiceNumber));
|
|
182
199
|
this.paymentDetails = new Field(this.constructPrediction(paymentDetails));
|
|
183
200
|
this.companyNumber = new Field(this.constructPrediction(companyNumber));
|
|
184
201
|
this.vatNumber = new Field(this.constructPrediction(vatNumber));
|
|
202
|
+
this.customerName = new Field(this.constructPrediction(customerName));
|
|
203
|
+
this.customerAddress = new Field(this.constructPrediction(customerAddress));
|
|
204
|
+
this.customerCompanyRegistration = new Field(this.constructPrediction(customerCompanyRegistration));
|
|
185
205
|
|
|
186
206
|
if (taxes !== undefined) {
|
|
187
207
|
this.taxes = [];
|
|
@@ -218,7 +238,7 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
|
|
|
218
238
|
this.totalTax = new Amount({
|
|
219
239
|
prediction: {
|
|
220
240
|
value: undefined,
|
|
221
|
-
|
|
241
|
+
confidence: 0.0
|
|
222
242
|
},
|
|
223
243
|
valueKey: "value",
|
|
224
244
|
pageNumber
|
|
@@ -267,6 +287,25 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
|
|
|
267
287
|
prediction: apiPrediction.supplier,
|
|
268
288
|
pageNumber
|
|
269
289
|
});
|
|
290
|
+
this.supplierAddress = new Field({
|
|
291
|
+
prediction: apiPrediction.supplier_address,
|
|
292
|
+
pageNumber
|
|
293
|
+
});
|
|
294
|
+
this.customerName = new Field({
|
|
295
|
+
prediction: apiPrediction.customer,
|
|
296
|
+
pageNumber
|
|
297
|
+
});
|
|
298
|
+
this.customerAddress = new Field({
|
|
299
|
+
prediction: apiPrediction.customer_address,
|
|
300
|
+
pageNumber
|
|
301
|
+
});
|
|
302
|
+
this.customerCompanyRegistration = apiPrediction.customer_company_registration.map(function (customerCompanyRegistration) {
|
|
303
|
+
return new Field({
|
|
304
|
+
prediction: customerCompanyRegistration,
|
|
305
|
+
pageNumber,
|
|
306
|
+
extraFields: ["type"]
|
|
307
|
+
});
|
|
308
|
+
});
|
|
270
309
|
this.paymentDetails = apiPrediction.payment_details.map(function (paymentDetail) {
|
|
271
310
|
return new PaymentDetails({
|
|
272
311
|
prediction: paymentDetail,
|
|
@@ -283,7 +322,7 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
|
|
|
283
322
|
this.orientation = new Orientation(this.constructPrediction({
|
|
284
323
|
prediction: {
|
|
285
324
|
value: undefined,
|
|
286
|
-
|
|
325
|
+
confidence: 0.0,
|
|
287
326
|
degrees: undefined
|
|
288
327
|
}
|
|
289
328
|
}));
|
|
@@ -392,7 +431,7 @@ var _reconstructTotalTax2 = function _reconstructTotalTax2() {
|
|
|
392
431
|
value: this.taxes.reduce((acc, tax) => {
|
|
393
432
|
return tax.value !== undefined ? acc + tax.value : acc;
|
|
394
433
|
}, 0),
|
|
395
|
-
|
|
434
|
+
confidence: Field.arrayProbability(this.taxes)
|
|
396
435
|
};
|
|
397
436
|
if (totalTax.value > 0) this.totalTax = new Amount({
|
|
398
437
|
prediction: totalTax,
|
|
@@ -406,7 +445,7 @@ var _reconstructTotalTaxFromTotals2 = function _reconstructTotalTaxFromTotals2()
|
|
|
406
445
|
if (this.totalTax.value === undefined && this.totalIncl.value > 0 && this.totalExcl.value > 0 && this.totalExcl.value <= this.totalIncl.value) {
|
|
407
446
|
var totalTax = {
|
|
408
447
|
value: this.totalIncl.value - this.totalExcl.value,
|
|
409
|
-
|
|
448
|
+
confidence: this.totalIncl.probability * this.totalExcl.probability
|
|
410
449
|
};
|
|
411
450
|
if (totalTax.value > 0) this.totalTax = new Amount({
|
|
412
451
|
prediction: totalTax,
|
|
@@ -422,7 +461,7 @@ var _reconstructTotalExcl2 = function _reconstructTotalExcl2() {
|
|
|
422
461
|
value: this.totalIncl.value - this.taxes.reduce((acc, tax) => {
|
|
423
462
|
return tax.value !== undefined ? acc + tax.value : acc;
|
|
424
463
|
}, 0),
|
|
425
|
-
|
|
464
|
+
confidence: Field.arrayProbability(this.taxes) * this.totalIncl.probability
|
|
426
465
|
};
|
|
427
466
|
this.totalExcl = new Amount({
|
|
428
467
|
prediction: totalExcl,
|
|
@@ -438,7 +477,7 @@ var _reconstructTotalIncl2 = function _reconstructTotalIncl2() {
|
|
|
438
477
|
value: this.totalExcl.value + this.taxes.reduce((acc, tax) => {
|
|
439
478
|
return tax.value ? acc + tax.value : acc;
|
|
440
479
|
}, 0.0),
|
|
441
|
-
|
|
480
|
+
confidence: Field.arrayProbability(this.taxes) * this.totalExcl.probability
|
|
442
481
|
};
|
|
443
482
|
this.totalIncl = new Amount({
|
|
444
483
|
prediction: totalIncl,
|
package/lib/documents/receipt.js
CHANGED
|
@@ -229,7 +229,7 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
|
|
|
229
229
|
this.totalTax = new Amount({
|
|
230
230
|
prediction: {
|
|
231
231
|
value: undefined,
|
|
232
|
-
|
|
232
|
+
confidence: 0
|
|
233
233
|
},
|
|
234
234
|
valueKey: "value",
|
|
235
235
|
pageNumber
|
|
@@ -237,7 +237,7 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
|
|
|
237
237
|
this.totalExcl = new Amount({
|
|
238
238
|
prediction: {
|
|
239
239
|
value: undefined,
|
|
240
|
-
|
|
240
|
+
confidence: 0
|
|
241
241
|
},
|
|
242
242
|
valueKey: "value",
|
|
243
243
|
pageNumber
|
|
@@ -252,7 +252,7 @@ var _initFromApiPrediction2 = function _initFromApiPrediction2(apiPrediction, pa
|
|
|
252
252
|
this.orientation = new Orientation(this.constructPrediction({
|
|
253
253
|
prediction: {
|
|
254
254
|
value: undefined,
|
|
255
|
-
|
|
255
|
+
confidence: 0.0,
|
|
256
256
|
degrees: undefined
|
|
257
257
|
}
|
|
258
258
|
}));
|
|
@@ -305,7 +305,7 @@ var _reconstructTotalExclFromTCCAndTaxes2 = function _reconstructTotalExclFromTC
|
|
|
305
305
|
if (this.taxes.length && this.totalIncl.value != null) {
|
|
306
306
|
var totalExcl = {
|
|
307
307
|
value: this.totalIncl.value - Field.arraySum(this.taxes),
|
|
308
|
-
|
|
308
|
+
confidence: Field.arrayProbability(this.taxes) * this.totalIncl.probability
|
|
309
309
|
};
|
|
310
310
|
this.totalExcl = new Amount({
|
|
311
311
|
prediction: totalExcl,
|
|
@@ -319,7 +319,7 @@ var _reconstructTotalTax2 = function _reconstructTotalTax2() {
|
|
|
319
319
|
if (this.taxes.length && this.totalTax.value == null) {
|
|
320
320
|
var totalTax = {
|
|
321
321
|
value: this.taxes.map(tax => tax.value || 0).reduce((a, b) => a + b, 0),
|
|
322
|
-
|
|
322
|
+
confidence: Field.arrayProbability(this.taxes)
|
|
323
323
|
};
|
|
324
324
|
if (totalTax.value > 0) this.totalTax = new Amount({
|
|
325
325
|
prediction: totalTax,
|
|
@@ -37,7 +37,7 @@ class APIFinancialDocument extends APIObject {
|
|
|
37
37
|
: this.receiptToken;
|
|
38
38
|
const url =
|
|
39
39
|
inputFile.fileExtension === "application/pdf"
|
|
40
|
-
? "/invoices/
|
|
40
|
+
? "/invoices/v3/predict"
|
|
41
41
|
: "/expense_receipts/v3/predict";
|
|
42
42
|
super.parse();
|
|
43
43
|
return await super._request(url, inputFile, version, includeWords);
|
package/mindee/api/invoice.js
CHANGED
package/mindee/api/response.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const Document = require("../documents").document;
|
|
2
1
|
const Receipt = require("../documents").receipt;
|
|
3
2
|
const Invoice = require("../documents").invoice;
|
|
4
3
|
const FinancialDocument = require("../documents").financialDocument;
|
|
@@ -56,7 +55,7 @@ class Response {
|
|
|
56
55
|
this[this.documentType] = constructors[this.documentType]({
|
|
57
56
|
apiPrediction: this.httpResponse.data.document.inference.prediction,
|
|
58
57
|
inputFile: this.input,
|
|
59
|
-
pageNumber:
|
|
58
|
+
pageNumber: this.httpResponse.data.document.n_pages,
|
|
60
59
|
level: "document",
|
|
61
60
|
});
|
|
62
61
|
}
|
|
@@ -16,13 +16,10 @@ class Field {
|
|
|
16
16
|
this.pageNumber = pageNumber;
|
|
17
17
|
this.reconstructed = reconstructed;
|
|
18
18
|
this.value = undefined;
|
|
19
|
-
this.probability = 0.0;
|
|
20
|
-
this.bbox = [];
|
|
19
|
+
this.probability = prediction.confidence ? prediction.confidence : 0.0;
|
|
20
|
+
this.bbox = prediction.polygon ? prediction.polygon : [];
|
|
21
21
|
if (valueKey in prediction && prediction[valueKey] !== null) {
|
|
22
22
|
this.value = prediction[valueKey];
|
|
23
|
-
if (prediction.probability) this.probability = prediction.probability;
|
|
24
|
-
if (prediction.segmentation)
|
|
25
|
-
this.bbox = prediction.segmentation.bounding_box || [];
|
|
26
23
|
if (extraFields) {
|
|
27
24
|
for (const fieldName of extraFields) {
|
|
28
25
|
this[fieldName] = prediction[fieldName];
|
|
@@ -19,13 +19,17 @@ class FinancialDocument extends Document {
|
|
|
19
19
|
* @param {Object} Date - date value for creating FinancialDocument object from scratch
|
|
20
20
|
* @param {Object} InvoiceNumber - Invoice number value for creating FinancialDocument object from scratch
|
|
21
21
|
* @param {Object} taxes - taxes value for creating FinancialDocument object from scratch
|
|
22
|
-
* @param {Object}
|
|
22
|
+
* @param {Object} supplier - supplier value for creating FinancialDocument object from scratch
|
|
23
|
+
* @param {Object} supplierAddress - supplier address value for creating FinancialDocument object from scratch
|
|
23
24
|
* @param {Object} paymentDetails - payment details value for creating FinancialDocument object from scratch
|
|
24
25
|
* @param {Object} companyNumber - company number value for creating FinancialDocument object from scratch
|
|
25
26
|
* @param {Object} vatNumber - vat number value for creating FinancialDocument object from scratch
|
|
26
27
|
* @param {Object} orientation - orientation value for creating FinancialDocument object from scratch
|
|
27
28
|
* @param {Object} totalTax - total tax value for creating FinancialDocument object from scratch
|
|
28
29
|
* @param {Object} time - time value for creating FinancialDocument object from scratch
|
|
30
|
+
* @param {Object} customerName - customer name value for creating FinancialDocument object from scratch
|
|
31
|
+
* @param {Object} customerAddress - customer address value for creating FinancialDocument object from scratch
|
|
32
|
+
* @param {Object} customerCompanyRegistration - customer company registration value for creating FinancialDocument object from scratch
|
|
29
33
|
* @param {Object} pageNumber - pageNumber for multi pages pdf input
|
|
30
34
|
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
31
35
|
*/
|
|
@@ -39,13 +43,17 @@ class FinancialDocument extends Document {
|
|
|
39
43
|
invoiceNumber = undefined,
|
|
40
44
|
dueDate = undefined,
|
|
41
45
|
taxes = undefined,
|
|
42
|
-
|
|
46
|
+
supplier = undefined,
|
|
47
|
+
supplierAddress = undefined,
|
|
43
48
|
paymentDetails = undefined,
|
|
44
49
|
companyNumber = undefined,
|
|
45
50
|
vatNumber = undefined,
|
|
46
51
|
orientation = undefined,
|
|
47
52
|
totalTax = undefined,
|
|
48
53
|
time = undefined,
|
|
54
|
+
customerName = undefined,
|
|
55
|
+
customerAddress = undefined,
|
|
56
|
+
customerCompanyRegistration = undefined,
|
|
49
57
|
pageNumber = 0,
|
|
50
58
|
level = "page",
|
|
51
59
|
}) {
|
|
@@ -61,6 +69,7 @@ class FinancialDocument extends Document {
|
|
|
61
69
|
dueDate,
|
|
62
70
|
taxes,
|
|
63
71
|
supplier,
|
|
72
|
+
supplierAddress,
|
|
64
73
|
paymentDetails,
|
|
65
74
|
companyNumber,
|
|
66
75
|
vatNumber,
|
|
@@ -68,6 +77,9 @@ class FinancialDocument extends Document {
|
|
|
68
77
|
pageNumber,
|
|
69
78
|
totalTax,
|
|
70
79
|
time,
|
|
80
|
+
customerName,
|
|
81
|
+
customerAddress,
|
|
82
|
+
customerCompanyRegistration,
|
|
71
83
|
});
|
|
72
84
|
} else {
|
|
73
85
|
this.#initFromApiPrediction(apiPrediction, inputFile, pageNumber);
|
|
@@ -90,7 +102,11 @@ class FinancialDocument extends Document {
|
|
|
90
102
|
orientation,
|
|
91
103
|
pageNumber,
|
|
92
104
|
supplier,
|
|
105
|
+
supplierAddress,
|
|
93
106
|
time,
|
|
107
|
+
customerName,
|
|
108
|
+
customerAddress,
|
|
109
|
+
customerCompanyRegistration,
|
|
94
110
|
}) {
|
|
95
111
|
const constructPrediction = function (item) {
|
|
96
112
|
return { prediction: { value: item }, valueKey: "value", pageNumber };
|
|
@@ -102,12 +118,18 @@ class FinancialDocument extends Document {
|
|
|
102
118
|
this.date = new Date(constructPrediction(date));
|
|
103
119
|
this.dueDate = new Date(constructPrediction(dueDate));
|
|
104
120
|
this.supplier = new Field(constructPrediction(supplier));
|
|
121
|
+
this.supplierAddress = new Field(this.constructPrediction(supplierAddress));
|
|
105
122
|
this.time = new Field(constructPrediction(time));
|
|
106
123
|
this.orientation = new Orientation(constructPrediction(orientation));
|
|
107
124
|
this.invoiceNumber = new Field(constructPrediction(invoiceNumber));
|
|
108
125
|
this.paymentDetails = new Field(constructPrediction(paymentDetails));
|
|
109
126
|
this.companyNumber = new Field(constructPrediction(companyNumber));
|
|
110
127
|
this.vatNumber = new Field(constructPrediction(vatNumber));
|
|
128
|
+
this.customerName = new Field(this.constructPrediction(customerName));
|
|
129
|
+
this.customerAddress = new Field(this.constructPrediction(customerAddress));
|
|
130
|
+
this.customerCompanyRegistration = new Field(
|
|
131
|
+
this.constructPrediction(customerCompanyRegistration)
|
|
132
|
+
);
|
|
111
133
|
if (taxes !== undefined) {
|
|
112
134
|
this.taxes = [];
|
|
113
135
|
for (const t of taxes) {
|
|
@@ -139,13 +161,17 @@ class FinancialDocument extends Document {
|
|
|
139
161
|
this.dueDate = invoice.dueDate;
|
|
140
162
|
this.taxes = invoice.taxes;
|
|
141
163
|
this.supplier = invoice.supplier;
|
|
164
|
+
this.supplierAddress = invoice.supplierAddress;
|
|
142
165
|
this.paymentDetails = invoice.paymentDetails;
|
|
143
166
|
this.companyNumber = invoice.companyNumber;
|
|
144
167
|
this.orientation = invoice.orientation;
|
|
145
168
|
this.totalTax = invoice.totalTax;
|
|
146
169
|
this.time = new Field({
|
|
147
|
-
prediction: { value: undefined,
|
|
170
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
148
171
|
});
|
|
172
|
+
this.customerName = invoice.customerName;
|
|
173
|
+
this.customerAddress = invoice.customerAddress;
|
|
174
|
+
this.customerCompanyRegistration = invoice.customerCompanyRegistration;
|
|
149
175
|
} else {
|
|
150
176
|
const receipt = new Receipt({
|
|
151
177
|
apiPrediction,
|
|
@@ -161,17 +187,27 @@ class FinancialDocument extends Document {
|
|
|
161
187
|
this.totalIncl = receipt.totalIncl;
|
|
162
188
|
this.totalExcl = receipt.totalExcl;
|
|
163
189
|
this.supplier = receipt.merchantName;
|
|
190
|
+
this.supplierAddress = new Field({
|
|
191
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
192
|
+
});
|
|
164
193
|
this.time = receipt.time;
|
|
165
194
|
this.totalTax = receipt.totalTax;
|
|
166
195
|
this.invoiceNumber = new Field({
|
|
167
|
-
prediction: { value: undefined,
|
|
196
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
168
197
|
});
|
|
169
198
|
this.paymentDetails = new Field({
|
|
170
|
-
prediction: { value: undefined,
|
|
199
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
171
200
|
});
|
|
172
201
|
this.companyNumber = new Field({
|
|
173
|
-
prediction: { value: undefined,
|
|
202
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
203
|
+
});
|
|
204
|
+
this.customerName = new Field({
|
|
205
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
206
|
+
});
|
|
207
|
+
this.customerAddress = new Field({
|
|
208
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
174
209
|
});
|
|
210
|
+
this.customerCompanyRegistration = [];
|
|
175
211
|
}
|
|
176
212
|
}
|
|
177
213
|
|
|
@@ -216,7 +252,7 @@ class FinancialDocument extends Document {
|
|
|
216
252
|
this.totalIncl.value * (1 - eps) - 0.02 <= reconstructedTotal &&
|
|
217
253
|
reconstructedTotal <= this.totalIncl.value * (1 + eps) + 0.02
|
|
218
254
|
) {
|
|
219
|
-
this.taxes = this.taxes.map((tax) => ({ ...tax,
|
|
255
|
+
this.taxes = this.taxes.map((tax) => ({ ...tax, confidence: 1.0 }));
|
|
220
256
|
this.totalTax.probability = 1.0;
|
|
221
257
|
this.totalIncl.probability = 1.0;
|
|
222
258
|
return true;
|
|
@@ -18,11 +18,15 @@ class Invoice extends Document {
|
|
|
18
18
|
* @param {Object} invoiceNumber - invoice number value for creating Invoice object from scratch
|
|
19
19
|
* @param {Object} taxes - taxes value for creating Invoice object from scratch
|
|
20
20
|
* @param {Object} supplier - supplier value for creating Invoice object from scratch
|
|
21
|
+
* @param {Object} supplierAddress - supplier address value for creating Invoice object from scratch
|
|
21
22
|
* @param {Object} paymentDetails - payment details value for creating Invoice object from scratch
|
|
22
23
|
* @param {Object} companyNumber - company number value for creating Invoice object from scratch
|
|
23
24
|
* @param {Object} vatNumber - vat number value for creating Invoice object from scratch
|
|
24
25
|
* @param {Object} orientation - orientation value for creating Invoice object from scratch
|
|
25
26
|
* @param {Object} totalTax - total tax value for creating Invoice object from scratch
|
|
27
|
+
* @param {Object} customerName - customer name value for creating Invoice object from scratch
|
|
28
|
+
* @param {Object} customerAddress - customer address value for creating Invoice object from scratch
|
|
29
|
+
* @param {Object} customerCompanyRegistration - customer company registration value for creating Invoice object from scratch
|
|
26
30
|
* @param {Number} pageNumber - pageNumber for multi pages pdf input
|
|
27
31
|
* @param {String} level - specify whether object is built from "page" level or "document" level prediction
|
|
28
32
|
*/
|
|
@@ -37,11 +41,15 @@ class Invoice extends Document {
|
|
|
37
41
|
dueDate = undefined,
|
|
38
42
|
taxes = undefined,
|
|
39
43
|
supplier = undefined,
|
|
44
|
+
supplierAddress = undefined,
|
|
40
45
|
paymentDetails = undefined,
|
|
41
46
|
companyNumber = undefined,
|
|
42
47
|
vatNumber = undefined,
|
|
43
48
|
orientation = undefined,
|
|
44
49
|
totalTax = undefined,
|
|
50
|
+
customerName = undefined,
|
|
51
|
+
customerAddress = undefined,
|
|
52
|
+
customerCompanyRegistration = undefined,
|
|
45
53
|
pageNumber = 0,
|
|
46
54
|
level = "page",
|
|
47
55
|
}) {
|
|
@@ -60,12 +68,16 @@ class Invoice extends Document {
|
|
|
60
68
|
dueDate,
|
|
61
69
|
taxes,
|
|
62
70
|
supplier,
|
|
71
|
+
supplierAddress,
|
|
63
72
|
paymentDetails,
|
|
64
73
|
companyNumber,
|
|
65
74
|
vatNumber,
|
|
66
75
|
orientation,
|
|
67
76
|
pageNumber,
|
|
68
77
|
totalTax,
|
|
78
|
+
customerName,
|
|
79
|
+
customerAddress,
|
|
80
|
+
customerCompanyRegistration,
|
|
69
81
|
});
|
|
70
82
|
} else {
|
|
71
83
|
this.#initFromApiPrediction(apiPrediction, pageNumber);
|
|
@@ -84,11 +96,15 @@ class Invoice extends Document {
|
|
|
84
96
|
dueDate,
|
|
85
97
|
taxes,
|
|
86
98
|
supplier,
|
|
99
|
+
supplierAddress,
|
|
87
100
|
paymentDetails,
|
|
88
101
|
companyNumber,
|
|
89
102
|
vatNumber,
|
|
90
103
|
orientation,
|
|
91
104
|
pageNumber,
|
|
105
|
+
customerName,
|
|
106
|
+
customerAddress,
|
|
107
|
+
customerCompanyRegistration,
|
|
92
108
|
}) {
|
|
93
109
|
this.locale = new Locale(this.constructPrediction(locale));
|
|
94
110
|
this.totalIncl = new Amount(this.constructPrediction(totalIncl));
|
|
@@ -98,10 +114,16 @@ class Invoice extends Document {
|
|
|
98
114
|
this.invoiceDate = new Date(this.constructPrediction(invoiceDate));
|
|
99
115
|
this.dueDate = new Date(this.constructPrediction(dueDate));
|
|
100
116
|
this.supplier = new Field(this.constructPrediction(supplier));
|
|
117
|
+
this.supplierAddress = new Field(this.constructPrediction(supplierAddress));
|
|
101
118
|
this.invoiceNumber = new Field(this.constructPrediction(invoiceNumber));
|
|
102
119
|
this.paymentDetails = new Field(this.constructPrediction(paymentDetails));
|
|
103
120
|
this.companyNumber = new Field(this.constructPrediction(companyNumber));
|
|
104
121
|
this.vatNumber = new Field(this.constructPrediction(vatNumber));
|
|
122
|
+
this.customerName = new Field(this.constructPrediction(customerName));
|
|
123
|
+
this.customerAddress = new Field(this.constructPrediction(customerAddress));
|
|
124
|
+
this.customerCompanyRegistration = new Field(
|
|
125
|
+
this.constructPrediction(customerCompanyRegistration)
|
|
126
|
+
);
|
|
105
127
|
if (taxes !== undefined) {
|
|
106
128
|
this.taxes = [];
|
|
107
129
|
for (const t of taxes) {
|
|
@@ -129,7 +151,7 @@ class Invoice extends Document {
|
|
|
129
151
|
pageNumber,
|
|
130
152
|
});
|
|
131
153
|
this.totalTax = new Amount({
|
|
132
|
-
prediction: { value: undefined,
|
|
154
|
+
prediction: { value: undefined, confidence: 0.0 },
|
|
133
155
|
valueKey: "value",
|
|
134
156
|
pageNumber,
|
|
135
157
|
});
|
|
@@ -179,6 +201,27 @@ class Invoice extends Document {
|
|
|
179
201
|
prediction: apiPrediction.supplier,
|
|
180
202
|
pageNumber,
|
|
181
203
|
});
|
|
204
|
+
this.supplierAddress = new Field({
|
|
205
|
+
prediction: apiPrediction.supplier_address,
|
|
206
|
+
pageNumber,
|
|
207
|
+
});
|
|
208
|
+
this.customerName = new Field({
|
|
209
|
+
prediction: apiPrediction.customer,
|
|
210
|
+
pageNumber,
|
|
211
|
+
});
|
|
212
|
+
this.customerAddress = new Field({
|
|
213
|
+
prediction: apiPrediction.customer_address,
|
|
214
|
+
pageNumber,
|
|
215
|
+
});
|
|
216
|
+
this.customerCompanyRegistration = apiPrediction.customer_company_registration.map(
|
|
217
|
+
function (customerCompanyRegistration) {
|
|
218
|
+
return new Field({
|
|
219
|
+
prediction: customerCompanyRegistration,
|
|
220
|
+
pageNumber,
|
|
221
|
+
extraFields: ["type"],
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
);
|
|
182
225
|
this.paymentDetails = apiPrediction.payment_details.map(function (
|
|
183
226
|
paymentDetail
|
|
184
227
|
) {
|
|
@@ -194,7 +237,7 @@ class Invoice extends Document {
|
|
|
194
237
|
this.constructPrediction({
|
|
195
238
|
prediction: {
|
|
196
239
|
value: undefined,
|
|
197
|
-
|
|
240
|
+
confidence: 0.0,
|
|
198
241
|
degrees: undefined,
|
|
199
242
|
},
|
|
200
243
|
})
|
|
@@ -213,6 +256,9 @@ class Invoice extends Document {
|
|
|
213
256
|
Total amount excluding taxes: ${this.totalExcl.value}
|
|
214
257
|
Invoice Date: ${this.invoiceDate.value}
|
|
215
258
|
Supplier name: ${this.supplier.value}
|
|
259
|
+
Supplier address: ${this.supplierAddress.value}
|
|
260
|
+
Customer name: ${this.customerName.value}
|
|
261
|
+
Customer address: ${this.customerAddress.value}
|
|
216
262
|
Taxes: ${this.taxes.map((tax) => tax.toString()).join(" - ")}
|
|
217
263
|
Total taxes: ${this.totalTax.value}
|
|
218
264
|
`;
|
|
@@ -330,7 +376,7 @@ class Invoice extends Document {
|
|
|
330
376
|
value: this.taxes.reduce((acc, tax) => {
|
|
331
377
|
return tax.value !== undefined ? acc + tax.value : acc;
|
|
332
378
|
}, 0),
|
|
333
|
-
|
|
379
|
+
confidence: Field.arrayProbability(this.taxes),
|
|
334
380
|
};
|
|
335
381
|
if (totalTax.value > 0)
|
|
336
382
|
this.totalTax = new Amount({
|
|
@@ -350,7 +396,7 @@ class Invoice extends Document {
|
|
|
350
396
|
) {
|
|
351
397
|
const totalTax = {
|
|
352
398
|
value: this.totalIncl.value - this.totalExcl.value,
|
|
353
|
-
|
|
399
|
+
confidence: this.totalIncl.probability * this.totalExcl.probability,
|
|
354
400
|
};
|
|
355
401
|
if (totalTax.value > 0)
|
|
356
402
|
this.totalTax = new Amount({
|
|
@@ -373,7 +419,7 @@ class Invoice extends Document {
|
|
|
373
419
|
this.taxes.reduce((acc, tax) => {
|
|
374
420
|
return tax.value !== undefined ? acc + tax.value : acc;
|
|
375
421
|
}, 0),
|
|
376
|
-
|
|
422
|
+
confidence:
|
|
377
423
|
Field.arrayProbability(this.taxes) * this.totalIncl.probability,
|
|
378
424
|
};
|
|
379
425
|
this.totalExcl = new Amount({
|
|
@@ -396,7 +442,7 @@ class Invoice extends Document {
|
|
|
396
442
|
this.taxes.reduce((acc, tax) => {
|
|
397
443
|
return tax.value ? acc + tax.value : acc;
|
|
398
444
|
}, 0.0),
|
|
399
|
-
|
|
445
|
+
confidence:
|
|
400
446
|
Field.arrayProbability(this.taxes) * this.totalExcl.probability,
|
|
401
447
|
};
|
|
402
448
|
this.totalIncl = new Amount({
|
|
@@ -146,12 +146,12 @@ class Receipt extends Document {
|
|
|
146
146
|
})
|
|
147
147
|
);
|
|
148
148
|
this.totalTax = new Amount({
|
|
149
|
-
prediction: { value: undefined,
|
|
149
|
+
prediction: { value: undefined, confidence: 0 },
|
|
150
150
|
valueKey: "value",
|
|
151
151
|
pageNumber,
|
|
152
152
|
});
|
|
153
153
|
this.totalExcl = new Amount({
|
|
154
|
-
prediction: { value: undefined,
|
|
154
|
+
prediction: { value: undefined, confidence: 0 },
|
|
155
155
|
valueKey: "value",
|
|
156
156
|
pageNumber,
|
|
157
157
|
});
|
|
@@ -165,7 +165,7 @@ class Receipt extends Document {
|
|
|
165
165
|
this.constructPrediction({
|
|
166
166
|
prediction: {
|
|
167
167
|
value: undefined,
|
|
168
|
-
|
|
168
|
+
confidence: 0.0,
|
|
169
169
|
degrees: undefined,
|
|
170
170
|
},
|
|
171
171
|
})
|
|
@@ -250,7 +250,7 @@ class Receipt extends Document {
|
|
|
250
250
|
if (this.taxes.length && this.totalIncl.value != null) {
|
|
251
251
|
const totalExcl = {
|
|
252
252
|
value: this.totalIncl.value - Field.arraySum(this.taxes),
|
|
253
|
-
|
|
253
|
+
confidence:
|
|
254
254
|
Field.arrayProbability(this.taxes) * this.totalIncl.probability,
|
|
255
255
|
};
|
|
256
256
|
this.totalExcl = new Amount({
|
|
@@ -272,7 +272,7 @@ class Receipt extends Document {
|
|
|
272
272
|
value: this.taxes
|
|
273
273
|
.map((tax) => tax.value || 0)
|
|
274
274
|
.reduce((a, b) => a + b, 0),
|
|
275
|
-
|
|
275
|
+
confidence: Field.arrayProbability(this.taxes),
|
|
276
276
|
};
|
|
277
277
|
if (totalTax.value > 0)
|
|
278
278
|
this.totalTax = new Amount({
|
package/mindee/inputs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mindee",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Mindee API SDK for Node.js",
|
|
5
5
|
"main": "mindee/index.js",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "babel mindee -d lib",
|
|
9
9
|
"test": "npm run build && mocha tests/**/*.js",
|