Fix some rule things.

This commit is contained in:
James Cole
2016-09-24 09:12:17 +02:00
parent 4dcaa96d16
commit f3b9798216
3 changed files with 17 additions and 14 deletions

View File

@@ -248,7 +248,7 @@ class JournalRepository implements JournalRepositoryInterface
/** @var Collection $transactions */
$transactions = $journal->transactions()
->groupBy('transactions.id')
->groupBy($groupBy)
->orderBy('transactions.id')->get($fields);
break;
case TransactionType::WITHDRAWAL:

View File

@@ -15,6 +15,7 @@ namespace FireflyIII\Rules\Actions;
use FireflyIII\Models\Budget;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Log;
@@ -55,13 +56,22 @@ class SetBudget implements ActionInterface
return $current->name == $search;
}
)->first();
if (!is_null($budget)) {
Log::debug(sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal->id, $budget->id, $budget->name));
if (is_null($budget)) {
Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.', $journal->id, $search));
$journal->budgets()->sync([$budget->id]);
return true;
}
Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.', $journal->id, $search));
if ($journal->transactionType->type == TransactionType::TRANSFER) {
Log::debug(sprintf('RuleAction SetBudget could not set budget of journal #%d to "%s" because journal is a transfer.', $journal->id, $search));
return true;
}
Log::debug(sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal->id, $budget->id, $budget->name));
$journal->budgets()->sync([$budget->id]);
return true;
}

View File

@@ -63,14 +63,6 @@ final class Processor
Log::debug(sprintf('Making new rule from Rule %d', $rule->id));
$self = new self;
$self->rule = $rule;
/*
* The number of "found triggers" must start at -1, because the first
* trigger is "create-journal" or "update-journal" when this Processor
* is called from a Rule.
*/
$self->setFoundTriggers(-1);
$triggerSet = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
/** @var RuleTrigger $trigger */
foreach ($triggerSet as $trigger) {
@@ -189,7 +181,7 @@ final class Processor
foreach ($this->actions as $action) {
/** @var ActionInterface $actionClass */
$actionClass = ActionFactory::getAction($action);
Log::debug(sprintf('Fire action %s on journal #%d', $actionClass, $this->journal->id));
Log::debug(sprintf('Fire action %s on journal #%d', get_class($actionClass), $this->journal->id));
$actionClass->act($this->journal);
if ($action->stop_processing) {
Log::debug('Stop processing now and break.');
@@ -212,6 +204,7 @@ final class Processor
Log::debug('start of Processor::triggered()');
$foundTriggers = $this->getFoundTriggers();
$hitTriggers = 0;
Log::debug(sprintf('Found triggers starts at %d', $foundTriggers));
/** @var AbstractTrigger $trigger */
foreach ($this->triggers as $trigger) {
$foundTriggers++;