sebastianwalker/statement

读取、解析和匹配银行对账单

v1.6.2 2018-04-09 11:40 UTC

This package is not auto-updated.

Last update: 2024-09-24 17:39:55 UTC


README

一个用于 读取、解析和匹配 银行账户导出的 PHP 库

您可以使用 statement:

  • 将 CSV 银行对账单解析成可用的 PHP 类
  • 猜测列映射
  • 将域对象与交易描述匹配(例如,用于支付处理)

安装

composer require sebastianwalker/statement

交易

// 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/

导入对账单

从 CSV

// 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();

从数组

// FromArray($transactions)
$importer = new \SebastianWalker\Statement\Importers\FromArray([/*Array of Transactions*/]);

// Get the imported transactions
$transactions = $importer->getTransactions();

将交易与域对象匹配

通过前缀匹配

请您的付款方在发送资金时包含 {您的前缀}{您的对象标识符} 的交易描述。
示例描述:PFIX-12345678

$matcher = new \SebastianWalker\Statement\Matchers\PrefixMatcher("PFIX-");

// Get all matching entities that are referenced in a given transaction
$matches = $matcher->getEntities($transaction);

前缀匹配器在交易的描述中查找给定前缀的出现,并返回每个出现的附加部分。

通过实体列表匹配

请您的付款方在发送资金时在交易描述中包含一个对象标识符(例如,他们的记录的 id)。示例描述:12345678

// 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);

列表匹配器在交易的描述中查找给定列表中的项的出现,并返回所有匹配项。