-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c2dab70
Showing
12 changed files
with
509 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.idea/ | ||
tests/receipts/ | ||
vendor/ | ||
.DS_Store | ||
composer.lock | ||
examples/test.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Kristian Stöckel | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Lidl eReceipt Parser | ||
|
||
## Installation | ||
|
||
``` | ||
$ composer require mrkriskrisu/lidl-ereceipt-parser | ||
``` | ||
|
||
```json | ||
{ | ||
"require": { | ||
"mrkriskrisu/lidl-ereceipt-parser": "^0.1" | ||
} | ||
} | ||
``` | ||
|
||
## Example Usage | ||
```php | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
use LidlParser\Parser; | ||
|
||
$receipt = Parser::parse('receipt.jpg'); | ||
|
||
echo "You've paid " . $receipt->getTotal() . " Euros."; | ||
``` | ||
|
||
## Requirements | ||
This library requires Tesseract OCR v3.02 or later. | ||
|
||
## Get the eReceipt | ||
To receive the eReceipt you need do download the App "Lidl Plus". | ||
At your checkout you have to scan your customer card within the App | ||
and you'll can download the receipt in the app later. | ||
|
||
## Contribution | ||
I'm glad that you want to help this library to be perfect. | ||
Just do your magic und make a Pull Request. ✨ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "mrkriskrisu/lidl-ereceipt-parser", | ||
"description": "Library for parsing digital receipts from Lidl (supermarket)", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Kristian Stöckel", | ||
"email": "git@k118.de" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.1", | ||
"nesbot/carbon": "^2.38", | ||
"thiagoalessio/tesseract_ocr": "^2.9" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"LidlParser\\": "src/" | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use LidlParser\Exception\ReceiptParseException; | ||
use LidlParser\Parser; | ||
use thiagoalessio\TesseractOCR\TesseractOcrException; | ||
|
||
require_once '../vendor/autoload.php'; | ||
|
||
try { | ||
$receipt = Parser::parse('../tests/receipts/receipt.jpg'); | ||
|
||
echo "The receipt was made " . $receipt->getTimestamp()->diffForHumans() . ". \n"; | ||
echo "You've bought " . count($receipt->getPositions()) . " Products for a total of " . $receipt->getTotal() . "€. \n"; | ||
|
||
} catch (ReceiptParseException $e) { | ||
echo "There is something weird with the receipt... Maybe it's not compatible?\n"; | ||
echo "Error: " . $e->getMessage(); | ||
} catch (TesseractOcrException $e) { | ||
echo "The given Image cant be read successfully: " . $e->getMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace LidlParser\Exception; | ||
|
||
class PositionNotFoundException extends \Exception | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace LidlParser\Exception; | ||
|
||
class ReceiptParseException extends \Exception | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace LidlParser; | ||
|
||
use thiagoalessio\TesseractOCR\TesseractOcrException; | ||
|
||
class Parser | ||
{ | ||
/** | ||
* @param string $imagePath | ||
* @return Receipt | ||
* @throws TesseractOcrException | ||
*/ | ||
public static function parse(string $imagePath): Receipt | ||
{ | ||
return new Receipt($imagePath); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace LidlParser; | ||
|
||
use LidlParser\Exception\ReceiptParseException; | ||
|
||
class Position | ||
{ | ||
|
||
private $name; | ||
private $priceTotal; | ||
private $priceSingle; | ||
private $taxCode; | ||
|
||
private $weight; | ||
private $amount; | ||
|
||
/** | ||
* The name of the product. | ||
* @return string|NULL | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* The total sum of the position | ||
* @return float | ||
* @throws ReceiptParseException | ||
*/ | ||
public function getPriceTotal() | ||
{ | ||
if ($this->priceTotal !== NULL) | ||
return $this->priceTotal; | ||
if ($this->priceSingle !== NULL && $this->amount !== NULL) | ||
return $this->priceSingle * $this->amount; | ||
if ($this->priceSingle !== NULL && $this->weight !== NULL) | ||
return $this->priceSingle * $this->weight; | ||
throw new ReceiptParseException(); | ||
} | ||
|
||
/** | ||
* The single value for one unit of the product | ||
* @return float | ||
* @throws ReceiptParseException | ||
*/ | ||
public function getPriceSingle() | ||
{ | ||
if ($this->priceSingle !== NULL) | ||
return $this->priceSingle; | ||
if ($this->priceTotal !== NULL && $this->amount !== NULL) | ||
return $this->priceTotal / $this->amount; | ||
if ($this->priceTotal !== NULL && $this->weight !== NULL) | ||
return $this->priceTotal / $this->weight; | ||
if ($this->priceTotal !== NULL) | ||
return $this->priceTotal; | ||
throw new ReceiptParseException(); | ||
} | ||
|
||
/** | ||
* The Tax Code of the position (e.g. "A" or "B") | ||
* @return string|NULL | ||
*/ | ||
public function getTaxCode() | ||
{ | ||
return $this->taxCode; | ||
} | ||
|
||
/** | ||
* The weight of the position (if the product is weightable) | ||
* @return float|NULL | ||
*/ | ||
public function getWeight() | ||
{ | ||
return $this->weight; | ||
} | ||
|
||
/** | ||
* The amount of the position (if the product is countable) | ||
* @return int|NULL | ||
*/ | ||
public function getAmount() | ||
{ | ||
if ($this->amount === NULL && $this->weight === NULL) | ||
return 1; | ||
return $this->amount; | ||
} | ||
|
||
public function setName(string $name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function setPriceTotal(float $priceTotal) | ||
{ | ||
$this->priceTotal = $priceTotal; | ||
} | ||
|
||
public function setPriceSingle(float $priceSingle) | ||
{ | ||
$this->priceSingle = $priceSingle; | ||
} | ||
|
||
public function setTaxCode(string $taxCode) | ||
{ | ||
$this->taxCode = $taxCode; | ||
} | ||
|
||
public function setWeight(float $weight) | ||
{ | ||
$this->weight = $weight; | ||
} | ||
|
||
public function setAmount(int $amount) | ||
{ | ||
$this->amount = $amount; | ||
} | ||
|
||
} |
Oops, something went wrong.