https://github.com/sebwalk/statement
:money_with_wings: Read, parse and match bank statements
https://github.com/sebwalk/statement
bank-statement csv import matching parser
Last synced: 2 months ago
JSON representation
:money_with_wings: Read, parse and match bank statements
- Host: GitHub
- URL: https://github.com/sebwalk/statement
- Owner: sebwalk
- Created: 2018-02-28T16:00:41.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-09T11:41:08.000Z (almost 8 years ago)
- Last Synced: 2024-11-21T04:57:14.875Z (over 1 year ago)
- Topics: bank-statement, csv, import, matching, parser
- Language: PHP
- Homepage:
- Size: 48.8 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# statement
A **PHP library** to **read, parse and match** bank account exports.
You can use statement to
- Parse CSV bank statements into usable PHP classes
- Guess column mappings
- Match domain objects with transaction descriptions (e.g. for payment processing)
## Installation
```
composer require sebastianwalker/statement
```
## Transactions
```php
// Transaction ($amount, $description, $payer, $iban, $date)
$transaction = new \SebastianWalker\Statement\Transaction(12.34, "Desc", "John Doe", "DE...00", new \Carbon\Carbon("2018-02-12"));
$transaction->getAmount(); // float
$transaction->getDescription(); // string
$transaction->getPayer(); // string
$transaction->getIban(); // string | null
$transaction->getDate(); // Carbon instance: http://carbon.nesbot.com/docs/
```
## Importing statements
### From CSV
```php
// FromCsv($filename, $delimiter, $known_mapping, $known_offset)
$importer = new \SebastianWalker\Statement\Importers\FromCsv("file.csv");
// Get the imported transactions
$transactions = $importer->getTransactions();
// Get the mapping used (guessed + known_mapping)
$mapping = $importer->getMapping();
/*[
"amount"=>"Amount",
"description"=>"Description",
"payer"=>"Payer/Payee",
"iban"=>"IBAN",
"date"=>"Valuta Date"
]*/
// Get the column titles usable for mapping as an array
$columns = $importer->getColumns();
```
### From Array
```php
// FromArray($transactions)
$importer = new \SebastianWalker\Statement\Importers\FromArray([/*Array of Transactions*/]);
// Get the imported transactions
$transactions = $importer->getTransactions();
```
## Matching Transactions with Domain Objects
### Matching by Prefix
Ask your payers to include a transaction description of {Your Prefix}{Your Object Identifier} when sending the funds.
_Example Description: PFIX-12345678_
```php
$matcher = new \SebastianWalker\Statement\Matchers\PrefixMatcher("PFIX-");
// Get all matching entities that are referenced in a given transaction
$matches = $matcher->getEntities($transaction);
```
The prefix matcher looks for occurrences in the transaction's description of the given prefix and returns the appended part of each of them.
### Matching by Entity List
Ask your payers to include an object identifier (e.g. their record's id) in the transaction description when sending the funds.
_Example Description: 12345678_
```php
// Pass basic strings
$matcher = new \SebastianWalker\Statement\Matchers\ListMatcher(["1234","5678","9012"]);
// OR set a property which will be matched
$matcher = new \SebastianWalker\Statement\Matchers\ListMatcher([
["id"=>"1234"],
["id"=>"5678"],
["id"=>"9012"]
], "id");
// Get all matching entities that are referenced in a given transaction
$matches = $matcher->getEntities($transaction);
```
The list matcher looks for occurences in the transaction's description of the items contained in the given list and returns all matching items.