Expand match to include expense account.

This commit is contained in:
Sander Dorigo 2014-10-14 07:24:59 +02:00
parent 849b711b79
commit b7517b49ed

View File

@ -41,20 +41,36 @@ class EloquentRecurringTrigger
$wordMatch = false;
$matches = explode(' ', $recurring->match);
$description = strtolower($journal->description);
/*
* Attach expense account to description for more narrow matching.
*/
$transactions = $journal->transactions()->get();
/** @var \Transaction $transaction */
foreach ($transactions as $transaction) {
/** @var \Account $account */
$account = $transaction->account()->first();
/** @var \AccountType $type */
$type = $account->accountType()->first();
if ($type->type == 'Expense account' || $type->type == 'Beneficiary account') {
$description .= ' ' . strtolower($account->name);
}
}
$count = 0;
foreach ($matches as $word) {
if (!(strpos($description, strtolower($word)) === false)) {
$count++;
}
}
if ($count > 0) {
if ($count >= count($matches)) {
$wordMatch = true;
}
/*
* Match amount.
*/
$transactions = $journal->transactions()->get();
$amountMatch = false;
if (count($transactions) > 1) {
@ -73,6 +89,7 @@ class EloquentRecurringTrigger
$journal->recurringTransaction()->associate($recurring);
$journal->save();
}
}
/**