mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-20 11:33:59 +00:00
First code for #2723
This commit is contained in:
@@ -150,6 +150,21 @@ class Account extends Model
|
|||||||
return $this->belongsTo(AccountType::class);
|
return $this->belongsTo(AccountType::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the account number.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAccountNumberAttribute(): ?string
|
||||||
|
{
|
||||||
|
/** @var AccountMeta $metaValue */
|
||||||
|
$metaValue = $this->accountMeta()
|
||||||
|
->where('name', 'account_number')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
return $metaValue ? $metaValue->data : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Note;
|
use FireflyIII\Models\Note;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionGroup;
|
use FireflyIII\Models\TransactionGroup;
|
||||||
@@ -377,4 +378,26 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getSourceAccount(TransactionJournal $journal): Account
|
||||||
|
{
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
$transaction = $journal->transactions()->with('account')->where('amount', '<', 0)->first();
|
||||||
|
|
||||||
|
return $transaction->account;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getDestinationAccount(TransactionJournal $journal): Account
|
||||||
|
{
|
||||||
|
/** @var Transaction $transaction */
|
||||||
|
$transaction = $journal->transactions()->with('account')->where('amount', '>', 0)->first();
|
||||||
|
|
||||||
|
return $transaction->account;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\TransactionGroup;
|
use FireflyIII\Models\TransactionGroup;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionJournalLink;
|
use FireflyIII\Models\TransactionJournalLink;
|
||||||
@@ -109,6 +110,22 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getJournalSourceAccounts(TransactionJournal $journal): Collection;
|
public function getJournalSourceAccounts(TransactionJournal $journal): Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the source account of the journal.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @return Account
|
||||||
|
*/
|
||||||
|
public function getSourceAccount(TransactionJournal $journal): Account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the destination account of the journal.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
* @return Account
|
||||||
|
*/
|
||||||
|
public function getDestinationAccount(TransactionJournal $journal): Account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return total amount of journal. Is always positive.
|
* Return total amount of journal. Is always positive.
|
||||||
*
|
*
|
||||||
|
@@ -22,7 +22,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\TransactionRules\Triggers;
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -72,21 +71,18 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
|
|||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$fromAccountName = '';
|
|
||||||
|
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$source = $repository->getSourceAccount($journal);
|
||||||
/** @var Account $account */
|
$strpos = stripos($source->name, $this->triggerValue);
|
||||||
foreach ($repository->getJournalSourceAccounts($journal, false) as $account) {
|
|
||||||
$fromAccountName .= strtolower($account->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$search = strtolower($this->triggerValue);
|
|
||||||
$strpos = strpos($fromAccountName, $search);
|
|
||||||
|
|
||||||
if (!(false === $strpos)) {
|
if (!(false === $strpos)) {
|
||||||
Log::debug(sprintf('RuleTrigger FromAccountContains for journal #%d: "%s" contains "%s", return true.', $journal->id, $fromAccountName, $search));
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger FromAccountContains for journal #%d: "%s" contains "%s", return true.',
|
||||||
|
$journal->id, $source->name, $this->triggerValue
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -95,8 +91,8 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
|
|||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountContains for journal #%d: "%s" does not contain "%s", return false.',
|
'RuleTrigger FromAccountContains for journal #%d: "%s" does not contain "%s", return false.',
|
||||||
$journal->id,
|
$journal->id,
|
||||||
$fromAccountName,
|
$source->name,
|
||||||
$search
|
$this->triggerValue
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -22,7 +22,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\TransactionRules\Triggers;
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -72,19 +71,13 @@ final class FromAccountEnds extends AbstractTrigger implements TriggerInterface
|
|||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$name = '';
|
|
||||||
|
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$source = $repository->getSourceAccount($journal);
|
||||||
/** @var Account $account */
|
$nameLength = strlen($source->name);
|
||||||
foreach ($repository->getJournalSourceAccounts($journal, false) as $account) {
|
$search = $this->triggerValue;
|
||||||
$name .= strtolower($account->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$nameLength = strlen($name);
|
|
||||||
$search = strtolower($this->triggerValue);
|
|
||||||
$searchLength = strlen($search);
|
$searchLength = strlen($search);
|
||||||
|
$part = substr($source->name, $searchLength * -1);
|
||||||
|
|
||||||
// if the string to search for is longer than the account name,
|
// if the string to search for is longer than the account name,
|
||||||
// it will never be in the account name.
|
// it will never be in the account name.
|
||||||
@@ -94,9 +87,7 @@ final class FromAccountEnds extends AbstractTrigger implements TriggerInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$part = substr($name, $searchLength * -1);
|
if (strtolower($part) === strtolower($search)) {
|
||||||
|
|
||||||
if ($part === $search) {
|
|
||||||
Log::debug(sprintf('RuleTrigger FromAccountEnds for journal #%d: "%s" ends with "%s", return true.', $journal->id, $name, $search));
|
Log::debug(sprintf('RuleTrigger FromAccountEnds for journal #%d: "%s" ends with "%s", return true.', $journal->id, $name, $search));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -22,7 +22,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\TransactionRules\Triggers;
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -72,19 +71,12 @@ final class FromAccountIs extends AbstractTrigger implements TriggerInterface
|
|||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$name = '';
|
|
||||||
|
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$source = $repository->getSourceAccount($journal);
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($repository->getJournalSourceAccounts($journal, false) as $account) {
|
|
||||||
$name .= strtolower($account->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$search = strtolower($this->triggerValue);
|
$search = strtolower($this->triggerValue);
|
||||||
|
|
||||||
if ($name === $search) {
|
if (strtolower($source->name) === $search) {
|
||||||
Log::debug(sprintf('RuleTrigger FromAccountIs for journal #%d: "%s" is "%s", return true.', $journal->id, $name, $search));
|
Log::debug(sprintf('RuleTrigger FromAccountIs for journal #%d: "%s" is "%s", return true.', $journal->id, $name, $search));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
103
app/TransactionRules/Triggers/FromAccountNumberContains.php
Normal file
103
app/TransactionRules/Triggers/FromAccountNumberContains.php
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FromAccountContains.php
|
||||||
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FromAccountContains.
|
||||||
|
*/
|
||||||
|
final class FromAccountNumberContains extends AbstractTrigger implements TriggerInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A trigger is said to "match anything", or match any given transaction,
|
||||||
|
* when the trigger value is very vague or has no restrictions. Easy examples
|
||||||
|
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
|
||||||
|
* has an amount of more than zero! Other examples are all the "Description"-triggers
|
||||||
|
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
|
||||||
|
*
|
||||||
|
* If the user tries to create such a trigger, this method MUST return true so Firefly III
|
||||||
|
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
|
||||||
|
* (even if it will still include 99.9% of the users transactions), this method MUST return
|
||||||
|
* false.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function willMatchEverything($value = null): bool
|
||||||
|
{
|
||||||
|
if (null !== $value) {
|
||||||
|
$res = '' === (string)$value;
|
||||||
|
if (true === $res) {
|
||||||
|
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
Log::error(sprintf('Cannot use %s with a null value.', self::class));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when from-account contains X
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function triggered(TransactionJournal $journal): bool
|
||||||
|
{
|
||||||
|
/** @var JournalRepositoryInterface $repository */
|
||||||
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$source = $repository->getSourceAccount($journal);
|
||||||
|
$strpos1 = stripos($source->iban, $this->triggerValue);
|
||||||
|
$strpos2 = stripos($source->account_number, $this->triggerValue);
|
||||||
|
|
||||||
|
if (!(false === $strpos1) || !(false === $strpos2)) {
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger FromAccountContains for journal #%d: "%s" or "%s" contains "%s", return true.',
|
||||||
|
$journal->id, $source->iban, $source->account_number, $this->triggerValue
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger FromAccountContains for journal #%d: "%s" and "%s" does not contain "%s", return false.',
|
||||||
|
$journal->id,
|
||||||
|
$source->iban,
|
||||||
|
$source->account_number,
|
||||||
|
$this->triggerValue
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
104
app/TransactionRules/Triggers/FromAccountNumberEnds.php
Normal file
104
app/TransactionRules/Triggers/FromAccountNumberEnds.php
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FromAccountEnds.php
|
||||||
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FromAccountNumberEnds.
|
||||||
|
*/
|
||||||
|
final class FromAccountNumberEnds extends AbstractTrigger implements TriggerInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A trigger is said to "match anything", or match any given transaction,
|
||||||
|
* when the trigger value is very vague or has no restrictions. Easy examples
|
||||||
|
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
|
||||||
|
* has an amount of more than zero! Other examples are all the "Description"-triggers
|
||||||
|
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
|
||||||
|
*
|
||||||
|
* If the user tries to create such a trigger, this method MUST return true so Firefly III
|
||||||
|
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
|
||||||
|
* (even if it will still include 99.9% of the users transactions), this method MUST return
|
||||||
|
* false.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function willMatchEverything($value = null): bool
|
||||||
|
{
|
||||||
|
if (null !== $value) {
|
||||||
|
$res = '' === (string)$value;
|
||||||
|
if (true === $res) {
|
||||||
|
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
Log::error(sprintf('Cannot use %s with a null value.', self::class));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when from account ends with X
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function triggered(TransactionJournal $journal): bool
|
||||||
|
{
|
||||||
|
/** @var JournalRepositoryInterface $repository */
|
||||||
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$source = $repository->getSourceAccount($journal);
|
||||||
|
$search = $this->triggerValue;
|
||||||
|
$searchLength = strlen($search);
|
||||||
|
|
||||||
|
$part1 = substr($source->iban, $searchLength * -1);
|
||||||
|
$part2 = substr($source->account_number, $searchLength * -1);
|
||||||
|
|
||||||
|
if (strtolower($part1) === strtolower($search)
|
||||||
|
|| strtolower($part2) === strtolower($search)) {
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger FromAccountEnds for journal #%d: "%s" or "%s" ends with "%s", return true.',
|
||||||
|
$journal->id, $part1, $part2, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger FromAccountEnds for journal #%d: "%s" and "%s" do not end with "%s", return false.',
|
||||||
|
$journal->id, $part1, $part2, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
99
app/TransactionRules/Triggers/FromAccountNumberIs.php
Normal file
99
app/TransactionRules/Triggers/FromAccountNumberIs.php
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FromAccountNumberIs.php
|
||||||
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FromAccountNumberIs.
|
||||||
|
*/
|
||||||
|
final class FromAccountNumberIs extends AbstractTrigger implements TriggerInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A trigger is said to "match anything", or match any given transaction,
|
||||||
|
* when the trigger value is very vague or has no restrictions. Easy examples
|
||||||
|
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
|
||||||
|
* has an amount of more than zero! Other examples are all the "Description"-triggers
|
||||||
|
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
|
||||||
|
*
|
||||||
|
* If the user tries to create such a trigger, this method MUST return true so Firefly III
|
||||||
|
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
|
||||||
|
* (even if it will still include 99.9% of the users transactions), this method MUST return
|
||||||
|
* false.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function willMatchEverything($value = null): bool
|
||||||
|
{
|
||||||
|
if (null !== $value) {
|
||||||
|
$res = '' === (string)$value;
|
||||||
|
if (true === $res) {
|
||||||
|
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
Log::error(sprintf('Cannot use %s with a null value.', self::class));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when from-account is X.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function triggered(TransactionJournal $journal): bool
|
||||||
|
{
|
||||||
|
/** @var JournalRepositoryInterface $repository */
|
||||||
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$source = $repository->getSourceAccount($journal);
|
||||||
|
$search = strtolower($this->triggerValue);
|
||||||
|
|
||||||
|
if (strtolower($source->iban) === $search || strtolower($source->account_number) === $search) {
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger FromAccountIs for journal #%d: "%s" or "%s" is "%s", return true.', $journal->id,
|
||||||
|
$source->iban, $source->account_number, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger FromAccountIs for journal #%d: "%s" and "%s" is NOT "%s", return false.', $journal->id, $source->iban, $source->account_number,
|
||||||
|
$search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
101
app/TransactionRules/Triggers/FromAccountNumberStarts.php
Normal file
101
app/TransactionRules/Triggers/FromAccountNumberStarts.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* FromAccountNumberStarts.php
|
||||||
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
||||||
|
*
|
||||||
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class FromAccountNumberStarts.
|
||||||
|
*/
|
||||||
|
final class FromAccountNumberStarts extends AbstractTrigger implements TriggerInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A trigger is said to "match anything", or match any given transaction,
|
||||||
|
* when the trigger value is very vague or has no restrictions. Easy examples
|
||||||
|
* are the "AmountMore"-trigger combined with an amount of 0: any given transaction
|
||||||
|
* has an amount of more than zero! Other examples are all the "Description"-triggers
|
||||||
|
* which have hard time handling empty trigger values such as "" or "*" (wild cards).
|
||||||
|
*
|
||||||
|
* If the user tries to create such a trigger, this method MUST return true so Firefly III
|
||||||
|
* can stop the storing / updating the trigger. If the trigger is in any way restrictive
|
||||||
|
* (even if it will still include 99.9% of the users transactions), this method MUST return
|
||||||
|
* false.
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function willMatchEverything($value = null): bool
|
||||||
|
{
|
||||||
|
if (null !== $value) {
|
||||||
|
$res = '' === (string)$value;
|
||||||
|
if (true === $res) {
|
||||||
|
Log::error(sprintf('Cannot use %s with "" as a value.', self::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
Log::error(sprintf('Cannot use %s with a null value.', self::class));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true when from-account starts with X.
|
||||||
|
*
|
||||||
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function triggered(TransactionJournal $journal): bool
|
||||||
|
{
|
||||||
|
/** @var JournalRepositoryInterface $repository */
|
||||||
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$source = $repository->getSourceAccount($journal);
|
||||||
|
$search = strtolower($this->triggerValue);
|
||||||
|
$part1 = strtolower(substr($source->iban, 0, strlen($search)));
|
||||||
|
$part2 = strtolower(substr($source->account_number, 0, strlen($search)));
|
||||||
|
|
||||||
|
if ($part1 === $search || $part2 === $search) {
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger FromAccountStarts for journal #%d: "%s" or "%s" starts with "%s", return true.', $journal->id,
|
||||||
|
$part1, $part2, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger FromAccountStarts for journal #%d: "%s" and "%s" do not start with "%s", return false.',
|
||||||
|
$journal->id, $part1, $part2, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -22,7 +22,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\TransactionRules\Triggers;
|
namespace FireflyIII\TransactionRules\Triggers;
|
||||||
|
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -72,18 +71,11 @@ final class FromAccountStarts extends AbstractTrigger implements TriggerInterfac
|
|||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$name = '';
|
|
||||||
|
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$source = $repository->getSourceAccount($journal);
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($repository->getJournalSourceAccounts($journal, false) as $account) {
|
|
||||||
$name .= strtolower($account->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$search = strtolower($this->triggerValue);
|
$search = strtolower($this->triggerValue);
|
||||||
$part = substr($name, 0, strlen($search));
|
$part = substr($source->name, 0, strlen($search));
|
||||||
|
|
||||||
if ($part === $search) {
|
if ($part === $search) {
|
||||||
Log::debug(sprintf('RuleTrigger FromAccountStarts for journal #%d: "%s" starts with "%s", return true.', $journal->id, $name, $search));
|
Log::debug(sprintf('RuleTrigger FromAccountStarts for journal #%d: "%s" starts with "%s", return true.', $journal->id, $name, $search));
|
||||||
|
@@ -90,6 +90,10 @@ use FireflyIII\TransactionRules\Triggers\DescriptionStarts;
|
|||||||
use FireflyIII\TransactionRules\Triggers\FromAccountContains;
|
use FireflyIII\TransactionRules\Triggers\FromAccountContains;
|
||||||
use FireflyIII\TransactionRules\Triggers\FromAccountEnds;
|
use FireflyIII\TransactionRules\Triggers\FromAccountEnds;
|
||||||
use FireflyIII\TransactionRules\Triggers\FromAccountIs;
|
use FireflyIII\TransactionRules\Triggers\FromAccountIs;
|
||||||
|
use FireflyIII\TransactionRules\Triggers\FromAccountNumberContains;
|
||||||
|
use FireflyIII\TransactionRules\Triggers\FromAccountNumberEnds;
|
||||||
|
use FireflyIII\TransactionRules\Triggers\FromAccountNumberIs;
|
||||||
|
use FireflyIII\TransactionRules\Triggers\FromAccountNumberStarts;
|
||||||
use FireflyIII\TransactionRules\Triggers\FromAccountStarts;
|
use FireflyIII\TransactionRules\Triggers\FromAccountStarts;
|
||||||
use FireflyIII\TransactionRules\Triggers\HasAnyBudget;
|
use FireflyIII\TransactionRules\Triggers\HasAnyBudget;
|
||||||
use FireflyIII\TransactionRules\Triggers\HasAnyCategory;
|
use FireflyIII\TransactionRules\Triggers\HasAnyCategory;
|
||||||
@@ -409,10 +413,18 @@ return [
|
|||||||
'from_account_ends' => FromAccountEnds::class,
|
'from_account_ends' => FromAccountEnds::class,
|
||||||
'from_account_is' => FromAccountIs::class,
|
'from_account_is' => FromAccountIs::class,
|
||||||
'from_account_contains' => FromAccountContains::class,
|
'from_account_contains' => FromAccountContains::class,
|
||||||
|
'from_account_nr_starts' => FromAccountNumberStarts::class,
|
||||||
|
'from_account_nr_ends' => FromAccountNumberEnds::class,
|
||||||
|
'from_account_nr_is' => FromAccountNumberIs::class,
|
||||||
|
'from_account_nr_contains' => FromAccountNumberContains::class,
|
||||||
'to_account_starts' => ToAccountStarts::class,
|
'to_account_starts' => ToAccountStarts::class,
|
||||||
'to_account_ends' => ToAccountEnds::class,
|
'to_account_ends' => ToAccountEnds::class,
|
||||||
'to_account_is' => ToAccountIs::class,
|
'to_account_is' => ToAccountIs::class,
|
||||||
'to_account_contains' => ToAccountContains::class,
|
'to_account_contains' => ToAccountContains::class,
|
||||||
|
//'to_account_nr_starts' => ToAccountNumberStarts::class,
|
||||||
|
//'to_account_nr_ends' => ToAccountNumberEnds::class,
|
||||||
|
//'to_account_nr_is' => ToAccountNumberIs::class,
|
||||||
|
//'to_account_nr_contains' => ToAccountNumberContains::class,
|
||||||
'amount_less' => AmountLess::class,
|
'amount_less' => AmountLess::class,
|
||||||
'amount_exactly' => AmountExactly::class,
|
'amount_exactly' => AmountExactly::class,
|
||||||
'amount_more' => AmountMore::class,
|
'amount_more' => AmountMore::class,
|
||||||
|
@@ -352,22 +352,43 @@ return [
|
|||||||
|
|
||||||
// actions and triggers
|
// actions and triggers
|
||||||
'rule_trigger_user_action' => 'User action is ":trigger_value"',
|
'rule_trigger_user_action' => 'User action is ":trigger_value"',
|
||||||
'rule_trigger_from_account_starts_choice' => 'Source account starts with..',
|
|
||||||
'rule_trigger_from_account_starts' => 'Source account starts with ":trigger_value"',
|
'rule_trigger_from_account_starts_choice' => 'Source account name starts with..',
|
||||||
'rule_trigger_from_account_ends_choice' => 'Source account ends with..',
|
'rule_trigger_from_account_starts' => 'Source account name starts with ":trigger_value"',
|
||||||
'rule_trigger_from_account_ends' => 'Source account ends with ":trigger_value"',
|
'rule_trigger_from_account_ends_choice' => 'Source account name ends with..',
|
||||||
'rule_trigger_from_account_is_choice' => 'Source account is..',
|
'rule_trigger_from_account_ends' => 'Source account name ends with ":trigger_value"',
|
||||||
'rule_trigger_from_account_is' => 'Source account is ":trigger_value"',
|
'rule_trigger_from_account_is_choice' => 'Source account name is..',
|
||||||
'rule_trigger_from_account_contains_choice' => 'Source account contains..',
|
'rule_trigger_from_account_is' => 'Source account name is ":trigger_value"',
|
||||||
'rule_trigger_from_account_contains' => 'Source account contains ":trigger_value"',
|
'rule_trigger_from_account_contains_choice' => 'Source account name contains..',
|
||||||
'rule_trigger_to_account_starts_choice' => 'Destination account starts with..',
|
'rule_trigger_from_account_contains' => 'Source account name contains ":trigger_value"',
|
||||||
'rule_trigger_to_account_starts' => 'Destination account starts with ":trigger_value"',
|
|
||||||
'rule_trigger_to_account_ends_choice' => 'Destination account ends with..',
|
'rule_trigger_from_account_nr_starts_choice' => 'Source account number / IBAN starts with..',
|
||||||
'rule_trigger_to_account_ends' => 'Destination account ends with ":trigger_value"',
|
'rule_trigger_from_account_nr_starts' => 'Source account number / IBAN starts with ":trigger_value"',
|
||||||
'rule_trigger_to_account_is_choice' => 'Destination account is..',
|
'rule_trigger_from_account_nr_ends_choice' => 'Source account number / IBAN ends with..',
|
||||||
'rule_trigger_to_account_is' => 'Destination account is ":trigger_value"',
|
'rule_trigger_from_account_nr_ends' => 'Source account number / IBAN ends with ":trigger_value"',
|
||||||
'rule_trigger_to_account_contains_choice' => 'Destination account contains..',
|
'rule_trigger_from_account_nr_is_choice' => 'Source account number / IBAN is..',
|
||||||
'rule_trigger_to_account_contains' => 'Destination account contains ":trigger_value"',
|
'rule_trigger_from_account_nr_is' => 'Source account number / IBAN is ":trigger_value"',
|
||||||
|
'rule_trigger_from_account_nr_contains_choice' => 'Source account number / IBAN contains..',
|
||||||
|
'rule_trigger_from_account_nr_contains' => 'Source account number / IBAN contains ":trigger_value"',
|
||||||
|
|
||||||
|
'rule_trigger_to_account_starts_choice' => 'Destination account name starts with..',
|
||||||
|
'rule_trigger_to_account_starts' => 'Destination account name starts with ":trigger_value"',
|
||||||
|
'rule_trigger_to_account_ends_choice' => 'Destination account name ends with..',
|
||||||
|
'rule_trigger_to_account_ends' => 'Destination account name ends with ":trigger_value"',
|
||||||
|
'rule_trigger_to_account_is_choice' => 'Destination account name is..',
|
||||||
|
'rule_trigger_to_account_is' => 'Destination account name is ":trigger_value"',
|
||||||
|
'rule_trigger_to_account_contains_choice' => 'Destination account name contains..',
|
||||||
|
'rule_trigger_to_account_contains' => 'Destination account name contains ":trigger_value"',
|
||||||
|
|
||||||
|
'rule_trigger_to_account_nr_starts_choice' => 'Destination account number / IBAN starts with..',
|
||||||
|
'rule_trigger_to_account_nr_starts' => 'Destination account number / IBAN starts with ":trigger_value"',
|
||||||
|
'rule_trigger_to_account_nr_ends_choice' => 'Destination account number / IBAN ends with..',
|
||||||
|
'rule_trigger_to_account_nr_ends' => 'Destination account number / IBAN ends with ":trigger_value"',
|
||||||
|
'rule_trigger_to_account_nr_is_choice' => 'Destination account number / IBAN is..',
|
||||||
|
'rule_trigger_to_account_nr_is' => 'Destination account number / IBAN is ":trigger_value"',
|
||||||
|
'rule_trigger_to_account_nr_contains_choice' => 'Destination account number / IBAN contains..',
|
||||||
|
'rule_trigger_to_account_nr_contains' => 'Destination account number / IBAN contains ":trigger_value"',
|
||||||
|
|
||||||
'rule_trigger_transaction_type_choice' => 'Transaction is of type..',
|
'rule_trigger_transaction_type_choice' => 'Transaction is of type..',
|
||||||
'rule_trigger_transaction_type' => 'Transaction is of type ":trigger_value"',
|
'rule_trigger_transaction_type' => 'Transaction is of type ":trigger_value"',
|
||||||
'rule_trigger_category_is_choice' => 'Category is..',
|
'rule_trigger_category_is_choice' => 'Category is..',
|
||||||
|
Reference in New Issue
Block a user