Skip to content

Commit 3652f3f

Browse files
⬆️ update invoice version to 4.4 (#21)
1 parent c7bde54 commit 3652f3f

6 files changed

Lines changed: 72 additions & 6 deletions

File tree

docs/extras/guide/invoices_v4.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ echo strval($apiResponse->document);
3030
########
3131
Document
3232
########
33-
:Mindee ID: 16bd8752-8c4d-450f-8213-f33b2097504c
33+
:Mindee ID: 80f2328c-58a5-486a-9599-eb2d738680f0
3434
:Filename: default_sample.jpg
3535
3636
Inference
3737
#########
38-
:Product: mindee/invoices v4.2
38+
:Product: mindee/invoices v4.4
3939
:Rotation applied: Yes
4040
4141
Prediction
@@ -47,14 +47,15 @@ Prediction
4747
:Due Date: 2018-09-25
4848
:Total Net:
4949
:Total Amount: 2608.20
50+
:Total Tax: 193.20
5051
:Taxes:
5152
+---------------+--------+----------+---------------+
5253
| Base | Code | Rate (%) | Amount |
5354
+===============+========+==========+===============+
5455
| | | 8.00 | 193.20 |
5556
+---------------+--------+----------+---------------+
5657
:Supplier Payment Details:
57-
:Supplier Name: TURNPIKE DESIGNS CO.
58+
:Supplier Name: TURNPIKE DESIGNS
5859
:Supplier Company Registrations:
5960
:Supplier Address: 156 University Ave, Toronto ON, Canada M5H 2H7
6061
:Customer Name: JIRO DOI
@@ -84,14 +85,15 @@ Page 0
8485
:Due Date: 2018-09-25
8586
:Total Net:
8687
:Total Amount: 2608.20
88+
:Total Tax: 193.20
8789
:Taxes:
8890
+---------------+--------+----------+---------------+
8991
| Base | Code | Rate (%) | Amount |
9092
+===============+========+==========+===============+
9193
| | | 8.00 | 193.20 |
9294
+---------------+--------+----------+---------------+
9395
:Supplier Payment Details:
94-
:Supplier Name: TURNPIKE DESIGNS CO.
96+
:Supplier Name: TURNPIKE DESIGNS
9597
:Supplier Company Registrations:
9698
:Supplier Address: 156 University Ave, Toronto ON, Canada M5H 2H7
9799
:Customer Name: JIRO DOI
@@ -342,5 +344,12 @@ echo $result->document->inference->prediction->totalAmount->value;
342344
echo $result->document->inference->prediction->totalNet->value;
343345
```
344346

347+
## Total Tax
348+
**totalTax** : The total tax: includes all the taxes paid for this invoice.
349+
350+
```php
351+
echo $result->document->inference->prediction->totalTax->value;
352+
```
353+
345354
# Questions?
346355
[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-1jv6nawjq-FDgFcF2T5CmMmRpl9LLptw)

src/Parsing/Standard/StringField.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ class StringField extends BaseField
1111
use FieldConfidenceMixin;
1212

1313
/**
14-
* @var string|null The value.
14+
* @var string|null Value as string.
1515
*/
1616
public $value;
17+
/**
18+
* @var string|null The value as it appears on the document.
19+
*/
20+
public $rawValue;
1721

1822

1923
/**
@@ -30,5 +34,6 @@ public function __construct(
3034
) {
3135
parent::__construct($rawPrediction, $pageId, $reconstructed, $valueKey);
3236
$this->setPosition($rawPrediction);
37+
$this->rawValue = array_key_exists('raw_value', $rawPrediction) ? $rawPrediction['raw_value'] : null;
3338
}
3439
}

src/Product/Invoice/InvoiceV4Document.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class InvoiceV4Document extends Prediction
8787
* @var AmountField The net amount paid: does not include taxes, fees, and discounts.
8888
*/
8989
public AmountField $totalNet;
90+
/**
91+
* @var AmountField The total tax: includes all the taxes paid for this invoice.
92+
*/
93+
public AmountField $totalTax;
9094
/**
9195
* @param array $rawPrediction Raw prediction from HTTP response.
9296
* @param integer|null $pageId Page number for multi pages document.
@@ -213,6 +217,13 @@ public function __construct(array $rawPrediction, ?int $pageId = null)
213217
$rawPrediction["total_net"],
214218
$pageId
215219
);
220+
if (!isset($rawPrediction["total_tax"])) {
221+
throw new MindeeUnsetException();
222+
}
223+
$this->totalTax = new AmountField(
224+
$rawPrediction["total_tax"],
225+
$pageId
226+
);
216227
}
217228

218229
/**
@@ -245,6 +256,7 @@ public function __toString(): string
245256
:Due Date: $this->dueDate
246257
:Total Net: $this->totalNet
247258
:Total Amount: $this->totalAmount
259+
:Total Tax: $this->totalTax
248260
:Taxes: $this->taxes
249261
:Supplier Payment Details: $supplierPaymentDetails
250262
:Supplier Name: $this->supplierName

tests/Parsing/Standard/StringFieldTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,43 @@ public function testConstructorFail()
3636
$field = new StringField($fieldArray);
3737
$this->assertNull($field->value);
3838
}
39+
40+
public function testConstructorNoRawValue()
41+
{
42+
$fieldArray = [
43+
"value" => "hello world",
44+
"confidence" => 0.1,
45+
"polygon" => [
46+
[0.016, 0.707],
47+
[0.414, 0.707],
48+
[0.414, 0.831],
49+
[0.016, 0.831],
50+
],
51+
];
52+
53+
$field = new StringField($fieldArray);
54+
55+
$this->assertEquals("hello world", $field->value);
56+
$this->assertNull($field->rawValue);
57+
}
58+
59+
public function testConstructorRawValue()
60+
{
61+
$fieldArray = [
62+
"value" => "hello world",
63+
"raw_value" => "HelLO wOrld",
64+
"confidence" => 0.1,
65+
"polygon" => [
66+
[0.016, 0.707],
67+
[0.414, 0.707],
68+
[0.414, 0.831],
69+
[0.016, 0.831],
70+
],
71+
];
72+
73+
$field = new StringField($fieldArray);
74+
75+
$this->assertEquals("hello world", $field->value);
76+
$this->assertEquals("HelLO wOrld", $field->rawValue);
77+
}
3978
}

tests/Product/Invoice/InvoiceV4Test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function testEmptyDoc()
4040
$this->assertNull($prediction->dueDate->value);
4141
$this->assertNull($prediction->totalNet->value);
4242
$this->assertNull($prediction->totalAmount->value);
43+
$this->assertNull($prediction->totalTax->value);
4344
$this->assertEquals(0, count($prediction->taxes));
4445
$this->assertEquals(0, count($prediction->supplierPaymentDetails));
4546
$this->assertNull($prediction->supplierName->value);

tests/resources

Submodule resources updated 31 files

0 commit comments

Comments
 (0)