Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:43:56 +01:00
parent 1368aafe5f
commit f963ac63f1
443 changed files with 3668 additions and 3672 deletions

View File

@@ -52,9 +52,9 @@ class AddTag implements ActionInterface
$factory = app(TagFactory::class);
/** @var User $user */
$user = User::find($journal['user_id']);
$user = User::find($journal['user_id']);
$factory->setUser($user);
$tag = $factory->findOrCreate($this->action->action_value);
$tag = $factory->findOrCreate($this->action->action_value);
if (null === $tag) {
// could not find, could not create tag.
@@ -63,7 +63,7 @@ class AddTag implements ActionInterface
return false;
}
$count = \DB::table('tag_transaction_journal')
$count = \DB::table('tag_transaction_journal')
->where('tag_id', $tag->id)
->where('transaction_journal_id', $journal['transaction_journal_id'])
->count()

View File

@@ -49,7 +49,7 @@ class AppendDescription implements ActionInterface
// event for audit log entry
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $object, 'update_description', $journal['description'], $description));
return true;

View File

@@ -55,9 +55,9 @@ class AppendDescriptionToNotes implements ActionInterface
return false;
}
$note = $object->notes()->first();
$note = $object->notes()->first();
if (null === $note) {
$note = new Note();
$note = new Note();
$note->noteable()->associate($object);
$note->text = '';
}
@@ -68,7 +68,7 @@ class AppendDescriptionToNotes implements ActionInterface
if ('' === $note->text) {
$note->text = (string)$object->description;
}
$after = $note->text;
$after = $note->text;
// event for audit log entry
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $before, $after));

View File

@@ -45,7 +45,7 @@ class AppendNotes implements ActionInterface
public function actOnArray(array $journal): bool
{
$dbNote = Note::where('noteable_id', (int)$journal['transaction_journal_id'])
$dbNote = Note::where('noteable_id', (int)$journal['transaction_journal_id'])
->where('noteable_type', TransactionJournal::class)
->first(['notes.*'])
;
@@ -62,7 +62,7 @@ class AppendNotes implements ActionInterface
$dbNote->save();
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $before, $text));

View File

@@ -60,10 +60,10 @@ class AppendNotesToDescription implements ActionInterface
return false;
}
$note = $object->notes()->first();
$note = $object->notes()->first();
if (null === $note) {
app('log')->debug('Journal has no notes.');
$note = new Note();
$note = new Note();
$note->noteable()->associate($object);
$note->text = '';
}

View File

@@ -50,7 +50,7 @@ class ClearNotes implements ActionInterface
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
/** @var null|Note $notes */
$notes = $object->notes()->first();
$notes = $object->notes()->first();
if (null === $notes) {
app('log')->debug(sprintf('RuleAction ClearNotes, journal #%d has no notes.', $journal['transaction_journal_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_already_no_notes')));

View File

@@ -54,7 +54,7 @@ class ConvertToDeposit implements ActionInterface
{
// make object from array (so the data is fresh).
/** @var null|TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
app('log')->error(sprintf('Cannot find journal #%d, cannot convert to deposit.', $journal['transaction_journal_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_not_found')));
@@ -70,7 +70,7 @@ class ConvertToDeposit implements ActionInterface
}
app('log')->debug(sprintf('Convert journal #%d to deposit.', $journal['transaction_journal_id']));
$type = $object->transactionType->type;
$type = $object->transactionType->type;
if (TransactionType::DEPOSIT === $type) {
app('log')->error(sprintf('Journal #%d is already a deposit (rule #%d).', $journal['transaction_journal_id'], $this->action->rule_id));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.is_already_deposit')));
@@ -124,22 +124,22 @@ class ConvertToDeposit implements ActionInterface
*/
private function convertWithdrawalArray(TransactionJournal $journal): bool
{
$user = $journal->user;
$user = $journal->user;
// find or create revenue account.
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory = app(AccountFactory::class);
$factory->setUser($user);
$repository = app(AccountRepositoryInterface::class);
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($user);
$destAccount = $this->getDestinationAccount($journal);
$sourceAccount = $this->getSourceAccount($journal);
$destAccount = $this->getDestinationAccount($journal);
$sourceAccount = $this->getSourceAccount($journal);
// get the action value, or use the original destination name in case the action value is empty:
// this becomes a new or existing (revenue) account, which is the source of the new deposit.
$opposingName = '' === $this->action->action_value ? $destAccount->name : $this->action->action_value;
$opposingName = '' === $this->action->action_value ? $destAccount->name : $this->action->action_value;
// we check all possible source account types if one exists:
$validTypes = config('firefly.expected_source_types.source.Deposit');
$opposingAccount = $repository->findByName($opposingName, $validTypes);
@@ -164,7 +164,7 @@ class ConvertToDeposit implements ActionInterface
;
// change transaction type of journal:
$newType = TransactionType::whereType(TransactionType::DEPOSIT)->first();
$newType = TransactionType::whereType(TransactionType::DEPOSIT)->first();
\DB::table('transaction_journals')
->where('id', '=', $journal->id)
@@ -213,21 +213,21 @@ class ConvertToDeposit implements ActionInterface
*/
private function convertTransferArray(TransactionJournal $journal): bool
{
$user = $journal->user;
$user = $journal->user;
// find or create revenue account.
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory = app(AccountFactory::class);
$factory->setUser($user);
$repository = app(AccountRepositoryInterface::class);
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($user);
$sourceAccount = $this->getSourceAccount($journal);
$sourceAccount = $this->getSourceAccount($journal);
// get the action value, or use the original source name in case the action value is empty:
// this becomes a new or existing (revenue) account, which is the source of the new deposit.
$opposingName = '' === $this->action->action_value ? $sourceAccount->name : $this->action->action_value;
$opposingName = '' === $this->action->action_value ? $sourceAccount->name : $this->action->action_value;
// we check all possible source account types if one exists:
$validTypes = config('firefly.expected_source_types.source.Deposit');
$opposingAccount = $repository->findByName($opposingName, $validTypes);
@@ -245,7 +245,7 @@ class ConvertToDeposit implements ActionInterface
;
// change transaction type of journal:
$newType = TransactionType::whereType(TransactionType::DEPOSIT)->first();
$newType = TransactionType::whereType(TransactionType::DEPOSIT)->first();
\DB::table('transaction_journals')
->where('id', '=', $journal->id)

View File

@@ -57,14 +57,14 @@ class ConvertToTransfer implements ActionInterface
{
// make object from array (so the data is fresh).
/** @var null|TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
app('log')->error(sprintf('Cannot find journal #%d, cannot convert to transfer.', $journal['transaction_journal_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_not_found')));
return false;
}
$groupCount = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
$groupCount = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
if ($groupCount > 1) {
app('log')->error(sprintf('Group #%d has more than one transaction in it, cannot convert to transfer.', $journal['transaction_group_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.split_group')));
@@ -72,9 +72,9 @@ class ConvertToTransfer implements ActionInterface
return false;
}
$type = $object->transactionType->type;
$user = $object->user;
$journalId = $object->id;
$type = $object->transactionType->type;
$user = $object->user;
$journalId = $object->id;
if (TransactionType::TRANSFER === $type) {
app('log')->error(
sprintf('Journal #%d is already a transfer so cannot be converted (rule #%d).', $object->id, $this->action->rule_id)
@@ -91,7 +91,7 @@ class ConvertToTransfer implements ActionInterface
// find the asset account in the action value.
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($user);
$expectedType = null;
if (TransactionType::WITHDRAWAL === $type) {
@@ -102,7 +102,7 @@ class ConvertToTransfer implements ActionInterface
$expectedType = $this->getDestinationType($journalId);
// Deposit? Replace source with account with same type as destination.
}
$opposing = $repository->findByName($this->action->action_value, [$expectedType]);
$opposing = $repository->findByName($this->action->action_value, [$expectedType]);
if (null === $opposing) {
app('log')->error(
@@ -212,7 +212,7 @@ class ConvertToTransfer implements ActionInterface
;
// change transaction type of journal:
$newType = TransactionType::whereType(TransactionType::TRANSFER)->first();
$newType = TransactionType::whereType(TransactionType::TRANSFER)->first();
\DB::table('transaction_journals')
->where('id', '=', $journal->id)
@@ -267,7 +267,7 @@ class ConvertToTransfer implements ActionInterface
;
// change transaction type of journal:
$newType = TransactionType::whereType(TransactionType::TRANSFER)->first();
$newType = TransactionType::whereType(TransactionType::TRANSFER)->first();
\DB::table('transaction_journals')
->where('id', '=', $journal->id)

View File

@@ -54,7 +54,7 @@ class ConvertToWithdrawal implements ActionInterface
{
// make object from array (so the data is fresh).
/** @var null|TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
app('log')->error(sprintf('Cannot find journal #%d, cannot convert to withdrawal.', $journal['transaction_journal_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_not_found')));
@@ -69,7 +69,7 @@ class ConvertToWithdrawal implements ActionInterface
return false;
}
$type = $object->transactionType->type;
$type = $object->transactionType->type;
if (TransactionType::WITHDRAWAL === $type) {
app('log')->error(sprintf('Journal #%d is already a withdrawal (rule #%d).', $journal['transaction_journal_id'], $this->action->rule_id));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.is_already_withdrawal')));
@@ -119,21 +119,21 @@ class ConvertToWithdrawal implements ActionInterface
*/
private function convertDepositArray(TransactionJournal $journal): bool
{
$user = $journal->user;
$user = $journal->user;
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory = app(AccountFactory::class);
$factory->setUser($user);
$repository = app(AccountRepositoryInterface::class);
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($user);
$sourceAccount = $this->getSourceAccount($journal);
$destAccount = $this->getDestinationAccount($journal);
$sourceAccount = $this->getSourceAccount($journal);
$destAccount = $this->getDestinationAccount($journal);
// get the action value, or use the original source name in case the action value is empty:
// this becomes a new or existing (expense) account, which is the destination of the new withdrawal.
$opposingName = '' === $this->action->action_value ? $sourceAccount->name : $this->action->action_value;
$opposingName = '' === $this->action->action_value ? $sourceAccount->name : $this->action->action_value;
// we check all possible source account types if one exists:
$validTypes = config('firefly.expected_source_types.destination.Withdrawal');
$opposingAccount = $repository->findByName($opposingName, $validTypes);
@@ -158,7 +158,7 @@ class ConvertToWithdrawal implements ActionInterface
;
// change transaction type of journal:
$newType = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
$newType = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
\DB::table('transaction_journals')
->where('id', '=', $journal->id)
->update(['transaction_type_id' => $newType->id])
@@ -206,20 +206,20 @@ class ConvertToWithdrawal implements ActionInterface
private function convertTransferArray(TransactionJournal $journal): bool
{
// find or create expense account.
$user = $journal->user;
$user = $journal->user;
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory = app(AccountFactory::class);
$factory->setUser($user);
$repository = app(AccountRepositoryInterface::class);
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($user);
$destAccount = $this->getDestinationAccount($journal);
$destAccount = $this->getDestinationAccount($journal);
// get the action value, or use the original source name in case the action value is empty:
// this becomes a new or existing (expense) account, which is the destination of the new withdrawal.
$opposingName = '' === $this->action->action_value ? $destAccount->name : $this->action->action_value;
$opposingName = '' === $this->action->action_value ? $destAccount->name : $this->action->action_value;
// we check all possible source account types if one exists:
$validTypes = config('firefly.expected_source_types.destination.Withdrawal');
$opposingAccount = $repository->findByName($opposingName, $validTypes);
@@ -237,7 +237,7 @@ class ConvertToWithdrawal implements ActionInterface
;
// change transaction type of journal:
$newType = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
$newType = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
\DB::table('transaction_journals')
->where('id', '=', $journal->id)
->update(['transaction_type_id' => $newType->id])

View File

@@ -47,7 +47,7 @@ class DeleteTransaction implements ActionInterface
public function actOnArray(array $journal): bool
{
$count = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
$count = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
// destroy entire group.
if (1 === $count) {

View File

@@ -49,16 +49,16 @@ class LinkToBill implements ActionInterface
public function actOnArray(array $journal): bool
{
/** @var User $user */
$user = User::find($journal['user_id']);
$user = User::find($journal['user_id']);
/** @var BillRepositoryInterface $repository */
$repository = app(BillRepositoryInterface::class);
$repository->setUser($user);
$billName = (string)$this->action->action_value;
$bill = $repository->findByName($billName);
$billName = (string)$this->action->action_value;
$bill = $repository->findByName($billName);
if (null !== $bill && TransactionType::WITHDRAWAL === $journal['transaction_type_type']) {
$count = \DB::table('transaction_journals')->where('id', '=', $journal['transaction_journal_id'])
$count = \DB::table('transaction_journals')->where('id', '=', $journal['transaction_journal_id'])
->where('bill_id', $bill->id)->count()
;
if (0 !== $count) {

View File

@@ -48,7 +48,7 @@ class MoveDescriptionToNotes implements ActionInterface
public function actOnArray(array $journal): bool
{
/** @var null|TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
app('log')->error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_other_user')));
@@ -57,9 +57,9 @@ class MoveDescriptionToNotes implements ActionInterface
}
/** @var null|Note $note */
$note = $object->notes()->first();
$note = $object->notes()->first();
if (null === $note) {
$note = new Note();
$note = new Note();
$note->noteable()->associate($object);
$note->text = '';
}
@@ -73,7 +73,7 @@ class MoveDescriptionToNotes implements ActionInterface
$note->text = (string)$object->description;
$object->description = '(no description)';
}
$after = $note->text;
$after = $note->text;
event(new TriggeredAuditLog($this->action->rule, $object, 'update_description', $beforeDescription, $object->description));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $before, $after));

View File

@@ -54,14 +54,14 @@ class MoveNotesToDescription implements ActionInterface
public function actOnArray(array $journal): bool
{
/** @var null|TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
app('log')->error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_other_user')));
return false;
}
$note = $object->notes()->first();
$note = $object->notes()->first();
if (null === $note) {
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_notes_to_move')));

View File

@@ -45,7 +45,7 @@ class PrependNotes implements ActionInterface
public function actOnArray(array $journal): bool
{
$dbNote = Note::where('noteable_id', (int)$journal['transaction_journal_id'])
$dbNote = Note::where('noteable_id', (int)$journal['transaction_journal_id'])
->where('noteable_type', TransactionJournal::class)
->first(['notes.*'])
;
@@ -55,7 +55,7 @@ class PrependNotes implements ActionInterface
$dbNote->noteable_type = TransactionJournal::class;
$dbNote->text = '';
}
$before = $dbNote->text;
$before = $dbNote->text;
app('log')->debug(sprintf('RuleAction PrependNotes prepended "%s" to "%s".', $this->action->action_value, $dbNote->text));
$text = sprintf('%s%s', $this->action->action_value, $dbNote->text);
$dbNote->text = $text;
@@ -63,7 +63,7 @@ class PrependNotes implements ActionInterface
// journal
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
// audit log
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $before, $text));

View File

@@ -46,7 +46,7 @@ class RemoveAllTags implements ActionInterface
public function actOnArray(array $journal): bool
{
\DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal['transaction_journal_id'])->delete();
$count = \DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal['transaction_journal_id'])->count();
$count = \DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal['transaction_journal_id'])->count();
if (0 === $count) {
app('log')->debug(sprintf('RuleAction RemoveAllTags, journal #%d has no tags.', $journal['transaction_journal_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_tags_to_remove')));

View File

@@ -47,11 +47,11 @@ class RemoveTag implements ActionInterface
public function actOnArray(array $journal): bool
{
// if tag does not exist, no need to continue:
$name = $this->action->action_value;
$name = $this->action->action_value;
/** @var User $user */
$user = User::find($journal['user_id']);
$tag = $user->tags()->where('tag', $name)->first();
$user = User::find($journal['user_id']);
$tag = $user->tags()->where('tag', $name)->first();
if (null === $tag) {
app('log')->debug(
@@ -61,7 +61,7 @@ class RemoveTag implements ActionInterface
return false;
}
$count = \DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal['transaction_journal_id'])->where('tag_id', $tag->id)->count();
$count = \DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal['transaction_journal_id'])->where('tag_id', $tag->id)->count();
if (0 === $count) {
app('log')->debug(
sprintf('RuleAction RemoveTag tried to remove tag "%s" from journal #%d but no such tag is linked.', $name, $journal['transaction_journal_id'])

View File

@@ -48,10 +48,10 @@ class SetBudget implements ActionInterface
public function actOnArray(array $journal): bool
{
/** @var User $user */
$user = User::find($journal['user_id']);
$search = $this->action->action_value;
$user = User::find($journal['user_id']);
$search = $this->action->action_value;
$budget = $user->budgets()->where('name', $search)->first();
$budget = $user->budgets()->where('name', $search)->first();
if (null === $budget) {
app('log')->debug(
sprintf(
@@ -98,7 +98,7 @@ class SetBudget implements ActionInterface
\DB::table('budget_transaction_journal')->insert(['transaction_journal_id' => $journal['transaction_journal_id'], 'budget_id' => $budget->id]);
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $object, 'set_budget', $oldBudgetName, $budget->name));
return true;

View File

@@ -48,8 +48,8 @@ class SetCategory implements ActionInterface
public function actOnArray(array $journal): bool
{
/** @var null|User $user */
$user = User::find($journal['user_id']);
$search = $this->action->action_value;
$user = User::find($journal['user_id']);
$search = $this->action->action_value;
if (null === $user) {
app('log')->error(sprintf('Journal has no valid user ID so action SetCategory("%s") cannot be applied', $search), $journal);
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_such_journal')));
@@ -58,9 +58,9 @@ class SetCategory implements ActionInterface
}
/** @var CategoryFactory $factory */
$factory = app(CategoryFactory::class);
$factory = app(CategoryFactory::class);
$factory->setUser($user);
$category = $factory->findOrCreate(null, $search);
$category = $factory->findOrCreate(null, $search);
if (null === $category) {
app('log')->debug(
sprintf(
@@ -98,7 +98,7 @@ class SetCategory implements ActionInterface
\DB::table('category_transaction_journal')->insert(['transaction_journal_id' => $journal['transaction_journal_id'], 'category_id' => $category->id]);
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $object, 'set_category', $oldCategoryName, $category->name));
return true;

View File

@@ -52,7 +52,7 @@ class SetDestinationAccount implements ActionInterface
public function actOnArray(array $journal): bool
{
/** @var User $user */
$user = User::find($journal['user_id']);
$user = User::find($journal['user_id']);
/** @var null|TransactionJournal $object */
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
@@ -64,11 +64,11 @@ class SetDestinationAccount implements ActionInterface
return false;
}
$type = $object->transactionType->type;
$type = $object->transactionType->type;
$this->repository->setUser($user);
// if this is a transfer or a deposit, the new destination account must be an asset account or a default account, and it MUST exist:
$newAccount = $this->findAssetAccount($type);
$newAccount = $this->findAssetAccount($type);
if ((TransactionType::DEPOSIT === $type || TransactionType::TRANSFER === $type) && null === $newAccount) {
app('log')->error(
sprintf(
@@ -84,7 +84,7 @@ class SetDestinationAccount implements ActionInterface
// new destination account must be different from the current source account:
/** @var null|Transaction $source */
$source = $object->transactions()->where('amount', '<', 0)->first();
$source = $object->transactions()->where('amount', '<', 0)->first();
if (null === $source) {
app('log')->error('Could not find source transaction.');
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_source_transaction')));

View File

@@ -50,11 +50,11 @@ class SetDestinationToCashAccount implements ActionInterface
public function actOnArray(array $journal): bool
{
/** @var User $user */
$user = User::find($journal['user_id']);
$user = User::find($journal['user_id']);
/** @var null|TransactionJournal $object */
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
$repository = app(AccountRepositoryInterface::class);
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
$repository = app(AccountRepositoryInterface::class);
if (null === $object) {
app('log')->error('Could not find journal.');
@@ -62,7 +62,7 @@ class SetDestinationToCashAccount implements ActionInterface
return false;
}
$type = $object->transactionType->type;
$type = $object->transactionType->type;
if (TransactionType::WITHDRAWAL !== $type) {
app('log')->error('Transaction must be withdrawal.');
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.not_withdrawal')));
@@ -76,7 +76,7 @@ class SetDestinationToCashAccount implements ActionInterface
// new destination account must be different from the current source account:
/** @var null|Transaction $source */
$source = $object->transactions()->where('amount', '<', 0)->first();
$source = $object->transactions()->where('amount', '<', 0)->first();
if (null === $source) {
app('log')->error('Could not find source transaction.');
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_source_transaction')));

View File

@@ -45,7 +45,7 @@ class SetNotes implements ActionInterface
public function actOnArray(array $journal): bool
{
$dbNote = Note::where('noteable_id', $journal['transaction_journal_id'])
$dbNote = Note::where('noteable_id', $journal['transaction_journal_id'])
->where('noteable_type', TransactionJournal::class)->first()
;
if (null === $dbNote) {
@@ -68,7 +68,7 @@ class SetNotes implements ActionInterface
);
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $oldNotes, $this->action->action_value));

View File

@@ -52,7 +52,7 @@ class SetSourceAccount implements ActionInterface
public function actOnArray(array $journal): bool
{
/** @var User $user */
$user = User::find($journal['user_id']);
$user = User::find($journal['user_id']);
/** @var null|TransactionJournal $object */
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
@@ -63,11 +63,11 @@ class SetSourceAccount implements ActionInterface
return false;
}
$type = $object->transactionType->type;
$type = $object->transactionType->type;
$this->repository->setUser($user);
// if this is a transfer or a withdrawal, the new source account must be an asset account or a default account, and it MUST exist:
$newAccount = $this->findAssetAccount($type);
$newAccount = $this->findAssetAccount($type);
if ((TransactionType::WITHDRAWAL === $type || TransactionType::TRANSFER === $type) && null === $newAccount) {
app('log')->error(
sprintf('Cant change source account of journal #%d because no asset account with name "%s" exists.', $object->id, $this->action->action_value)
@@ -79,7 +79,7 @@ class SetSourceAccount implements ActionInterface
// new source account must be different from the current destination account:
/** @var null|Transaction $destination */
$destination = $object->transactions()->where('amount', '>', 0)->first();
$destination = $object->transactions()->where('amount', '>', 0)->first();
if (null === $destination) {
app('log')->error('Could not find destination transaction.');
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_destination_transaction')));

View File

@@ -50,11 +50,11 @@ class SetSourceToCashAccount implements ActionInterface
public function actOnArray(array $journal): bool
{
/** @var User $user */
$user = User::find($journal['user_id']);
$user = User::find($journal['user_id']);
/** @var null|TransactionJournal $object */
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
$repository = app(AccountRepositoryInterface::class);
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
$repository = app(AccountRepositoryInterface::class);
if (null === $object) {
app('log')->error('Could not find journal.');
@@ -62,7 +62,7 @@ class SetSourceToCashAccount implements ActionInterface
return false;
}
$type = $object->transactionType->type;
$type = $object->transactionType->type;
if (TransactionType::DEPOSIT !== $type) {
app('log')->error('Transaction must be deposit.');
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.not_deposit')));

View File

@@ -49,14 +49,14 @@ class SwitchAccounts implements ActionInterface
{
// make object from array (so the data is fresh).
/** @var null|TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
app('log')->error(sprintf('Cannot find journal #%d, cannot switch accounts.', $journal['transaction_journal_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_such_journal')));
return false;
}
$groupCount = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
$groupCount = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
if ($groupCount > 1) {
app('log')->error(sprintf('Group #%d has more than one transaction in it, cannot switch accounts.', $journal['transaction_group_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.split_group')));
@@ -64,7 +64,7 @@ class SwitchAccounts implements ActionInterface
return false;
}
$type = $object->transactionType->type;
$type = $object->transactionType->type;
if (TransactionType::TRANSFER !== $type) {
app('log')->error(sprintf('Journal #%d is NOT a transfer (rule #%d), cannot switch accounts.', $journal['transaction_journal_id'], $this->action->rule_id));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.is_not_transfer')));
@@ -73,10 +73,10 @@ class SwitchAccounts implements ActionInterface
}
/** @var null|Transaction $sourceTransaction */
$sourceTransaction = $object->transactions()->where('amount', '<', 0)->first();
$sourceTransaction = $object->transactions()->where('amount', '<', 0)->first();
/** @var null|Transaction $destTransaction */
$destTransaction = $object->transactions()->where('amount', '>', 0)->first();
$destTransaction = $object->transactions()->where('amount', '>', 0)->first();
if (null === $sourceTransaction || null === $destTransaction) {
app('log')->error(sprintf('Journal #%d has no source or destination transaction (rule #%d), cannot switch accounts.', $journal['transaction_journal_id'], $this->action->rule_id));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_accounts')));

View File

@@ -54,12 +54,12 @@ class UpdatePiggybank implements ActionInterface
// refresh the transaction type.
/** @var User $user */
$user = User::find($journal['user_id']);
$user = User::find($journal['user_id']);
/** @var TransactionJournal $journalObj */
$journalObj = $user->transactionJournals()->find($journal['transaction_journal_id']);
$journalObj = $user->transactionJournals()->find($journal['transaction_journal_id']);
$piggyBank = $this->findPiggyBank($user);
$piggyBank = $this->findPiggyBank($user);
if (null === $piggyBank) {
app('log')->info(
sprintf('No piggy bank named "%s", cant execute action #%d of rule #%d', $this->action->action_value, $this->action->id, $this->action->rule_id)
@@ -72,7 +72,7 @@ class UpdatePiggybank implements ActionInterface
app('log')->debug(sprintf('Found piggy bank #%d ("%s")', $piggyBank->id, $piggyBank->name));
/** @var Transaction $source */
$source = $journalObj->transactions()->where('amount', '<', 0)->first();
$source = $journalObj->transactions()->where('amount', '<', 0)->first();
/** @var Transaction $destination */
$destination = $journalObj->transactions()->where('amount', '>', 0)->first();
@@ -142,11 +142,11 @@ class UpdatePiggybank implements ActionInterface
$repository->setUser($journal->user);
// how much can we remove from this piggy bank?
$toRemove = $repository->getCurrentAmount($piggyBank);
$toRemove = $repository->getCurrentAmount($piggyBank);
app('log')->debug(sprintf('Amount is %s, max to remove is %s', $amount, $toRemove));
// if $amount is bigger than $toRemove, shrink it.
$amount = -1 === bccomp($amount, $toRemove) ? $amount : $toRemove;
$amount = -1 === bccomp($amount, $toRemove) ? $amount : $toRemove;
app('log')->debug(sprintf('Amount is now %s', $amount));
// if amount is zero, stop.
@@ -174,7 +174,7 @@ class UpdatePiggybank implements ActionInterface
// how much can we add to the piggy bank?
if (0 !== bccomp($piggyBank->targetamount, '0')) {
$toAdd = bcsub($piggyBank->targetamount, $repository->getCurrentAmount($piggyBank));
$toAdd = bcsub($piggyBank->targetamount, $repository->getCurrentAmount($piggyBank));
app('log')->debug(sprintf('Max amount to add to piggy bank is %s, amount is %s', $toAdd, $amount));
// update amount to fit:

View File

@@ -50,10 +50,10 @@ class SearchRuleEngine implements RuleEngineInterface
public function __construct()
{
$this->rules = new Collection();
$this->groups = new Collection();
$this->operators = [];
$this->resultCount = [];
$this->rules = new Collection();
$this->groups = new Collection();
$this->operators = [];
$this->resultCount = [];
// always collect the triggers from the database, unless indicated otherwise.
$this->refreshTriggers = true;
@@ -70,7 +70,7 @@ class SearchRuleEngine implements RuleEngineInterface
app('log')->debug('SearchRuleEngine::find()');
$collection = new Collection();
foreach ($this->rules as $rule) {
$found = new Collection();
$found = new Collection();
if (true === $rule->strict) {
$found = $this->findStrictRule($rule);
}
@@ -168,8 +168,8 @@ class SearchRuleEngine implements RuleEngineInterface
private function findStrictRule(Rule $rule): Collection
{
app('log')->debug(sprintf('Now in findStrictRule(#%d)', $rule->id ?? 0));
$searchArray = [];
$triggers = [];
$searchArray = [];
$triggers = [];
if ($this->refreshTriggers) {
$triggers = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
}
@@ -200,7 +200,7 @@ class SearchRuleEngine implements RuleEngineInterface
app('log')->debug(sprintf('SearchRuleEngine:: add local added operator: %s:"%s"', $operator['type'], $operator['value']));
$searchArray[$operator['type']][] = sprintf('"%s"', $operator['value']);
}
$date = today(config('app.timezone'));
$date = today(config('app.timezone'));
if ($this->hasSpecificJournalTrigger($searchArray)) {
$date = $this->setDateFromJournalTrigger($searchArray);
}
@@ -220,7 +220,7 @@ class SearchRuleEngine implements RuleEngineInterface
}
}
$result = $searchEngine->searchTransactions();
$result = $searchEngine->searchTransactions();
return $result->getCollection();
}
@@ -245,7 +245,7 @@ class SearchRuleEngine implements RuleEngineInterface
$dateTrigger = true;
}
}
$result = $journalTrigger && $dateTrigger;
$result = $journalTrigger && $dateTrigger;
app('log')->debug(sprintf('Result of hasSpecificJournalTrigger is %s.', var_export($result, true)));
return $result;
@@ -264,7 +264,7 @@ class SearchRuleEngine implements RuleEngineInterface
if (0 !== $journalId) {
$repository = app(JournalRepositoryInterface::class);
$repository->setUser($this->user);
$journal = $repository->find($journalId);
$journal = $repository->find($journalId);
if (null !== $journal) {
$date = $journal->date;
app('log')->debug(sprintf('Found journal #%d with date %s.', $journal->id, $journal->date->format('Y-m-d')));
@@ -327,10 +327,10 @@ class SearchRuleEngine implements RuleEngineInterface
$searchEngine->parseQuery(sprintf('%s:%s', $type, $value));
}
$result = $searchEngine->searchTransactions();
$collection = $result->getCollection();
$result = $searchEngine->searchTransactions();
$collection = $result->getCollection();
app('log')->debug(sprintf('Found in this run, %d transactions', $collection->count()));
$total = $total->merge($collection);
$total = $total->merge($collection);
app('log')->debug(sprintf('Total collection is now %d transactions', $total->count()));
++$count;
// if trigger says stop processing, do so.
@@ -344,7 +344,7 @@ class SearchRuleEngine implements RuleEngineInterface
app('log')->debug(sprintf('Done running %d trigger(s)', $count));
// make collection unique
$unique = $total->unique(
$unique = $total->unique(
static function (array $group) {
$str = '';
foreach ($group['transactions'] as $transaction) {
@@ -397,7 +397,7 @@ class SearchRuleEngine implements RuleEngineInterface
$this->processResults($rule, $collection);
app('log')->debug(sprintf('SearchRuleEngine:: done processing strict rule #%d', $rule->id));
$result = $collection->count() > 0;
$result = $collection->count() > 0;
if (true === $result) {
app('log')->debug(sprintf('SearchRuleEngine:: rule #%d was triggered (on %d transaction(s)).', $rule->id, $collection->count()));

View File

@@ -67,7 +67,7 @@ class ActionFactory
throw new FireflyException('No such action exists ("'.e($actionType).'").');
}
$class = $actionTypes[$actionType];
$class = $actionTypes[$actionType];
if (!class_exists($class)) {
throw new FireflyException('Could not instantiate class for rule action type "'.e($actionType).'" ('.e($class).').');
}