Fixed some bugs in the recurring transactions trigger

This commit is contained in:
James Cole 2014-09-09 07:10:37 +02:00
parent 9965297f36
commit 77f4111b09

View File

@ -22,10 +22,11 @@ class EloquentJournalTrigger
{ {
// select all reminders for recurring transactions: // select all reminders for recurring transactions:
if ($journal->transaction_type->type == 'Withdrawal') { if ($journal->transaction_type->type == 'Withdrawal') {
\Log::debug('Trigger on the creation of a withdrawal');
$transaction = $journal->transactions()->orderBy('amount', 'DESC')->first(); $transaction = $journal->transactions()->orderBy('amount', 'DESC')->first();
$amount = floatval($transaction->amount); $amount = floatval($transaction->amount);
$description = $journal->description; $description = strtolower($journal->description);
$beneficiary = $transaction->account->name; $beneficiary = strtolower($transaction->account->name);
// make an array of parts: // make an array of parts:
$parts = explode(' ', $description); $parts = explode(' ', $description);
@ -40,10 +41,13 @@ class EloquentJournalTrigger
->where('amount_min', '<=', $amount) ->where('amount_min', '<=', $amount)
->where('amount_max', '>=', $amount)->get(['reminders.*']); ->where('amount_max', '>=', $amount)->get(['reminders.*']);
/** @var \RecurringTransctionReminder $reminder */ /** @var \RecurringTransctionReminder $reminder */
foreach ($set as $reminder) { \Log::debug('Have these parts to search for: ' . join('/',$parts));
\Log::debug('Found ' . count($set).' possible matching recurring transactions');
foreach ($set as $index => $reminder) {
/** @var \RecurringTransaction $RT */ /** @var \RecurringTransaction $RT */
$RT = $reminder->recurring_transaction; $RT = $reminder->recurring_transaction;
$matches = explode(' ', $RT->match); $matches = explode(' ', strtolower($RT->match));
\Log::debug($index.': ' . join('/',$matches));
$matchCount = 0; $matchCount = 0;
foreach ($parts as $part) { foreach ($parts as $part) {
if (in_array($part, $matches)) { if (in_array($part, $matches)) {