mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 18:40:12 +00:00
All rules for #2723, untested.
This commit is contained in:
@@ -155,14 +155,14 @@ class Account extends Model
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getAccountNumberAttribute(): ?string
|
public function getAccountNumberAttribute(): string
|
||||||
{
|
{
|
||||||
/** @var AccountMeta $metaValue */
|
/** @var AccountMeta $metaValue */
|
||||||
$metaValue = $this->accountMeta()
|
$metaValue = $this->accountMeta()
|
||||||
->where('name', 'account_number')
|
->where('name', 'account_number')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
return $metaValue ? $metaValue->data : null;
|
return $metaValue ? $metaValue->data : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -79,8 +79,8 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
|
|||||||
if (!(false === $strpos)) {
|
if (!(false === $strpos)) {
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountContains for journal #%d: "%s" contains "%s", return true.',
|
'RuleTrigger %s for journal #%d: "%s" contains "%s", return true.',
|
||||||
$journal->id, $source->name, $this->triggerValue
|
get_class($this), $journal->id, $source->name, $this->triggerValue
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -89,10 +89,8 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
|
|||||||
|
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountContains for journal #%d: "%s" does not contain "%s", return false.',
|
'RuleTrigger %s for journal #%d: "%s" does not contain "%s", return false.',
|
||||||
$journal->id,
|
get_class($this), $journal->id, $source->name, $this->triggerValue
|
||||||
$source->name,
|
|
||||||
$this->triggerValue
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -82,18 +82,33 @@ final class FromAccountEnds extends AbstractTrigger implements TriggerInterface
|
|||||||
// 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.
|
||||||
if ($searchLength > $nameLength) {
|
if ($searchLength > $nameLength) {
|
||||||
Log::debug(sprintf('RuleTrigger FromAccountEnds for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $name, $search));
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" does not end with "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $source->name, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strtolower($part) === strtolower($search)) {
|
if (strtolower($part) === strtolower($search)) {
|
||||||
Log::debug(sprintf('RuleTrigger FromAccountEnds for journal #%d: "%s" ends with "%s", return true.', $journal->id, $name, $search));
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" ends with "%s", return true.',
|
||||||
|
get_class($this), $journal->id, $source->name, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug(sprintf('RuleTrigger FromAccountEnds for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $name, $search));
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" does not end with "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $source->name, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -77,12 +77,14 @@ final class FromAccountIs extends AbstractTrigger implements TriggerInterface
|
|||||||
$search = strtolower($this->triggerValue);
|
$search = strtolower($this->triggerValue);
|
||||||
|
|
||||||
if (strtolower($source->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 %s for journal #%d: "%s" is "%s", return true.',
|
||||||
|
get_class($this), $journal->id, $source->name, $search));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug(sprintf('RuleTrigger FromAccountIs for journal #%d: "%s" is NOT "%s", return false.', $journal->id, $name, $search));
|
Log::debug(sprintf('RuleTrigger %s for journal #%d: "%s" is NOT "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $source->name, $search));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -80,8 +80,8 @@ final class FromAccountNumberContains extends AbstractTrigger implements Trigger
|
|||||||
if (!(false === $strpos1) || !(false === $strpos2)) {
|
if (!(false === $strpos1) || !(false === $strpos2)) {
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountContains for journal #%d: "%s" or "%s" contains "%s", return true.',
|
'RuleTrigger %s for journal #%d: "%s" or "%s" contains "%s", return true.',
|
||||||
$journal->id, $source->iban, $source->account_number, $this->triggerValue
|
get_class($this), $journal->id, $source->iban, $source->account_number, $this->triggerValue
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -90,11 +90,8 @@ final class FromAccountNumberContains extends AbstractTrigger implements Trigger
|
|||||||
|
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountContains for journal #%d: "%s" and "%s" does not contain "%s", return false.',
|
'RuleTrigger %s for journal #%d: "%s" and "%s" does not contain "%s", return false.',
|
||||||
$journal->id,
|
get_class($this), $journal->id, $source->iban, $source->account_number, $this->triggerValue
|
||||||
$source->iban,
|
|
||||||
$source->account_number,
|
|
||||||
$this->triggerValue
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -74,18 +74,18 @@ final class FromAccountNumberEnds extends AbstractTrigger implements TriggerInte
|
|||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
$source = $repository->getSourceAccount($journal);
|
$source = $repository->getSourceAccount($journal);
|
||||||
$search = $this->triggerValue;
|
$search = strtolower($this->triggerValue);
|
||||||
$searchLength = strlen($search);
|
$searchLength = strlen($search);
|
||||||
|
|
||||||
$part1 = substr($source->iban, $searchLength * -1);
|
$part1 = substr($source->iban, $searchLength * -1);
|
||||||
$part2 = substr($source->account_number, $searchLength * -1);
|
$part2 = substr($source->account_number, $searchLength * -1);
|
||||||
|
|
||||||
if (strtolower($part1) === strtolower($search)
|
if (strtolower($part1) === $search
|
||||||
|| strtolower($part2) === strtolower($search)) {
|
|| strtolower($part2) === $search) {
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountEnds for journal #%d: "%s" or "%s" ends with "%s", return true.',
|
'RuleTrigger %s for journal #%d: "%s" or "%s" ends with "%s", return true.',
|
||||||
$journal->id, $part1, $part2, $search
|
get_class($this), $journal->id, $part1, $part2, $search
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -94,8 +94,8 @@ final class FromAccountNumberEnds extends AbstractTrigger implements TriggerInte
|
|||||||
|
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountEnds for journal #%d: "%s" and "%s" do not end with "%s", return false.',
|
'RuleTrigger %s for journal #%d: "%s" and "%s" do not end with "%s", return false.',
|
||||||
$journal->id, $part1, $part2, $search
|
get_class($this), $journal->id, $part1, $part2, $search
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -79,8 +79,8 @@ final class FromAccountNumberIs extends AbstractTrigger implements TriggerInterf
|
|||||||
if (strtolower($source->iban) === $search || strtolower($source->account_number) === $search) {
|
if (strtolower($source->iban) === $search || strtolower($source->account_number) === $search) {
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountIs for journal #%d: "%s" or "%s" is "%s", return true.', $journal->id,
|
'RuleTrigger %s for journal #%d: "%s" or "%s" is "%s", return true.', $journal->id,
|
||||||
$source->iban, $source->account_number, $search
|
get_class($this), $source->iban, $source->account_number, $search
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -89,8 +89,8 @@ final class FromAccountNumberIs extends AbstractTrigger implements TriggerInterf
|
|||||||
|
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountIs for journal #%d: "%s" and "%s" is NOT "%s", return false.', $journal->id, $source->iban, $source->account_number,
|
'RuleTrigger %s for journal #%d: "%s" and "%s" are NOT "%s", return false.',
|
||||||
$search
|
get_class($this), $journal->id, $source->iban, $source->account_number, $search
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -81,8 +81,8 @@ final class FromAccountNumberStarts extends AbstractTrigger implements TriggerIn
|
|||||||
if ($part1 === $search || $part2 === $search) {
|
if ($part1 === $search || $part2 === $search) {
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountStarts for journal #%d: "%s" or "%s" starts with "%s", return true.', $journal->id,
|
'RuleTrigger %s for journal #%d: "%s" or "%s" starts with "%s", return true.',
|
||||||
$part1, $part2, $search
|
get_class($this), $journal->id, $part1, $part2, $search
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -91,8 +91,8 @@ final class FromAccountNumberStarts extends AbstractTrigger implements TriggerIn
|
|||||||
|
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger FromAccountStarts for journal #%d: "%s" and "%s" do not start with "%s", return false.',
|
'RuleTrigger %s for journal #%d: "%s" and "%s" do not start with "%s", return false.',
|
||||||
$journal->id, $part1, $part2, $search
|
get_class($this), $journal->id, $part1, $part2, $search
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -78,12 +78,22 @@ final class FromAccountStarts extends AbstractTrigger implements TriggerInterfac
|
|||||||
$part = substr($source->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 %s for journal #%d: "%s" starts with "%s", return true.',
|
||||||
|
get_class($this), $journal->id, $source->name, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug(sprintf('RuleTrigger FromAccountStarts for journal #%d: "%s" does not start with "%s", return false.', $journal->id, $name, $search));
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" does not start with "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $source->name, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
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;
|
||||||
@@ -65,39 +64,32 @@ final class ToAccountContains extends AbstractTrigger implements TriggerInterfac
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true when to-account contains X
|
* Returns true when to-account contains X
|
||||||
* TODO
|
|
||||||
*
|
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$toAccountName = '';
|
|
||||||
|
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$dest = $repository->getDestinationAccount($journal);
|
||||||
/** @var Account $account */
|
$strpos = stripos($dest->name, $this->triggerValue);
|
||||||
foreach ($repository->getJournalDestinationAccounts($journal, false) as $account) {
|
|
||||||
$toAccountName .= strtolower($account->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$search = strtolower($this->triggerValue);
|
|
||||||
$strpos = strpos($toAccountName, $search);
|
|
||||||
|
|
||||||
if (!(false === $strpos)) {
|
if (!(false === $strpos)) {
|
||||||
Log::debug(sprintf('RuleTrigger ToAccountContains for journal #%d: "%s" contains "%s", return true.', $journal->id, $toAccountName, $search));
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" contains "%s", return true.',
|
||||||
|
get_class($this), $journal->id, $dest->name, $this->triggerValue
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug(
|
Log::debug(
|
||||||
sprintf(
|
sprintf(
|
||||||
'RuleTrigger ToAccountContains for journal #%d: "%s" does not contain "%s", return false.',
|
'RuleTrigger %s for journal #%d: "%s" does not contain "%s", return false.',
|
||||||
$journal->id,
|
get_class($this), $journal->id, $dest->name, $this->triggerValue
|
||||||
$toAccountName,
|
|
||||||
$search
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -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,37 +71,44 @@ final class ToAccountEnds extends AbstractTrigger implements TriggerInterface
|
|||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$toAccountName = '';
|
|
||||||
|
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$dest = $repository->getDestinationAccount($journal);
|
||||||
/** @var Account $account */
|
$nameLength = strlen($dest->name);
|
||||||
foreach ($repository->getJournalDestinationAccounts($journal, false) as $account) {
|
$search = $this->triggerValue;
|
||||||
$toAccountName .= strtolower($account->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$toAccountNameLength = strlen($toAccountName);
|
|
||||||
$search = strtolower($this->triggerValue);
|
|
||||||
$searchLength = strlen($search);
|
$searchLength = strlen($search);
|
||||||
|
$part = substr($dest->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,
|
||||||
// return false
|
// it will never be in the account name.
|
||||||
if ($searchLength > $toAccountNameLength) {
|
if ($searchLength > $nameLength) {
|
||||||
Log::debug(sprintf('RuleTrigger ToAccountEnds for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $toAccountName, $search));
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" does not end with "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $dest->name, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$part = substr($toAccountName, $searchLength * -1);
|
if (strtolower($part) === strtolower($search)) {
|
||||||
|
Log::debug(
|
||||||
if ($part === $search) {
|
sprintf(
|
||||||
Log::debug(sprintf('RuleTrigger ToAccountEnds for journal #%d: "%s" ends with "%s", return true.', $journal->id, $toAccountName, $search));
|
'RuleTrigger %s for journal #%d: "%s" ends with "%s", return true.',
|
||||||
|
get_class($this), $journal->id, $dest->name, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug(sprintf('RuleTrigger ToAccountEnds for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $toAccountName, $search));
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" does not end with "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $dest->name, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -72,25 +72,20 @@ final class ToAccountIs extends AbstractTrigger implements TriggerInterface
|
|||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$toAccountName = '';
|
|
||||||
|
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$dest = $repository->getDestinationAccount($journal);
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($repository->getJournalDestinationAccounts($journal, false) as $account) {
|
|
||||||
$toAccountName .= strtolower($account->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$search = strtolower($this->triggerValue);
|
$search = strtolower($this->triggerValue);
|
||||||
|
|
||||||
if ($toAccountName === $search) {
|
if (strtolower($dest->name) === $search) {
|
||||||
Log::debug(sprintf('RuleTrigger ToAccountIs for journal #%d: "%s" is "%s", return true.', $journal->id, $toAccountName, $search));
|
Log::debug(sprintf('RuleTrigger %s for journal #%d: "%s" is "%s", return true.',
|
||||||
|
get_class($this), $journal->id, $dest->name, $search));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug(sprintf('RuleTrigger ToAccountIs for journal #%d: "%s" is NOT "%s", return false.', $journal->id, $toAccountName, $search));
|
Log::debug(sprintf('RuleTrigger %s for journal #%d: "%s" is NOT "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $dest->name, $search));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
100
app/TransactionRules/Triggers/ToAccountNumberContains.php
Normal file
100
app/TransactionRules/Triggers/ToAccountNumberContains.php
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ToAccountNumberContains.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 ToAccountNumberContains.
|
||||||
|
*/
|
||||||
|
final class ToAccountNumberContains 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);
|
||||||
|
$dest = $repository->getDestinationAccount($journal);
|
||||||
|
$strpos1 = stripos($dest->iban, $this->triggerValue);
|
||||||
|
$strpos2 = stripos($dest->account_number, $this->triggerValue);
|
||||||
|
|
||||||
|
if (!(false === $strpos1) || !(false === $strpos2)) {
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" or "%s" contains "%s", return true.',
|
||||||
|
get_class($this), $journal->id, $dest->iban, $dest->account_number, $this->triggerValue
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" and "%s" does not contain "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $dest->iban, $dest->account_number, $this->triggerValue
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
104
app/TransactionRules/Triggers/ToAccountNumberEnds.php
Normal file
104
app/TransactionRules/Triggers/ToAccountNumberEnds.php
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ToAccountNumberEnds.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 ToAccountNumberEnds.
|
||||||
|
*/
|
||||||
|
final class ToAccountNumberEnds 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);
|
||||||
|
$dest = $repository->getDestinationAccount($journal);
|
||||||
|
$search = strtolower($this->triggerValue);
|
||||||
|
$searchLength = strlen($search);
|
||||||
|
|
||||||
|
$part1 = substr($dest->iban, $searchLength * -1);
|
||||||
|
$part2 = substr($dest->account_number, $searchLength * -1);
|
||||||
|
|
||||||
|
if (strtolower($part1) === $search
|
||||||
|
|| strtolower($part2) === $search) {
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" or "%s" ends with "%s", return true.',
|
||||||
|
get_class($this), $journal->id, $part1, $part2, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" and "%s" do not end with "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $part1, $part2, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
99
app/TransactionRules/Triggers/ToAccountNumberIs.php
Normal file
99
app/TransactionRules/Triggers/ToAccountNumberIs.php
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ToAccountNumberIs.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 ToAccountNumberIs.
|
||||||
|
*/
|
||||||
|
final class ToAccountNumberIs 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);
|
||||||
|
$dest = $repository->getDestinationAccount($journal);
|
||||||
|
$search = strtolower($this->triggerValue);
|
||||||
|
|
||||||
|
if (strtolower($dest->iban) === $search || strtolower($dest->account_number) === $search) {
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" or "%s" is "%s", return true.', $journal->id,
|
||||||
|
get_class($this), $dest->iban, $dest->account_number, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" and "%s" are NOT "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $dest->iban, $dest->account_number, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
101
app/TransactionRules/Triggers/ToAccountNumberStarts.php
Normal file
101
app/TransactionRules/Triggers/ToAccountNumberStarts.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ToAccountNumberStarts.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 ToAccountNumberStarts 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);
|
||||||
|
$dest = $repository->getDestinationAccount($journal);
|
||||||
|
$search = strtolower($this->triggerValue);
|
||||||
|
$part1 = strtolower(substr($dest->iban, 0, strlen($search)));
|
||||||
|
$part2 = strtolower(substr($dest->account_number, 0, strlen($search)));
|
||||||
|
|
||||||
|
if ($part1 === $search || $part2 === $search) {
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" or "%s" starts with "%s", return true.',
|
||||||
|
get_class($this), $journal->id, $part1, $part2, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" and "%s" do not start with "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $part1, $part2, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@@ -72,25 +72,29 @@ final class ToAccountStarts extends AbstractTrigger implements TriggerInterface
|
|||||||
*/
|
*/
|
||||||
public function triggered(TransactionJournal $journal): bool
|
public function triggered(TransactionJournal $journal): bool
|
||||||
{
|
{
|
||||||
$toAccountName = '';
|
|
||||||
|
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app(JournalRepositoryInterface::class);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
$dest = $repository->getDestinationAccount($journal);
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($repository->getJournalDestinationAccounts($journal, false) as $account) {
|
|
||||||
$toAccountName .= strtolower($account->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
$search = strtolower($this->triggerValue);
|
$search = strtolower($this->triggerValue);
|
||||||
$part = substr($toAccountName, 0, strlen($search));
|
$part = substr($dest->name, 0, strlen($search));
|
||||||
|
|
||||||
if ($part === $search) {
|
if ($part === $search) {
|
||||||
Log::debug(sprintf('RuleTrigger ToAccountStarts for journal #%d: "%s" starts with "%s", return true.', $journal->id, $toAccountName, $search));
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" starts with "%s", return true.',
|
||||||
|
get_class($this), $journal->id, $dest->name, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Log::debug(sprintf('RuleTrigger ToAccountStarts for journal #%d: "%s" does not start with "%s", return false.', $journal->id, $toAccountName, $search));
|
|
||||||
|
Log::debug(
|
||||||
|
sprintf(
|
||||||
|
'RuleTrigger %s for journal #%d: "%s" does not start with "%s", return false.',
|
||||||
|
get_class($this), $journal->id, $dest->name, $search
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -112,6 +112,10 @@ use FireflyIII\TransactionRules\Triggers\TagIs;
|
|||||||
use FireflyIII\TransactionRules\Triggers\ToAccountContains;
|
use FireflyIII\TransactionRules\Triggers\ToAccountContains;
|
||||||
use FireflyIII\TransactionRules\Triggers\ToAccountEnds;
|
use FireflyIII\TransactionRules\Triggers\ToAccountEnds;
|
||||||
use FireflyIII\TransactionRules\Triggers\ToAccountIs;
|
use FireflyIII\TransactionRules\Triggers\ToAccountIs;
|
||||||
|
use FireflyIII\TransactionRules\Triggers\ToAccountNumberContains;
|
||||||
|
use FireflyIII\TransactionRules\Triggers\ToAccountNumberEnds;
|
||||||
|
use FireflyIII\TransactionRules\Triggers\ToAccountNumberIs;
|
||||||
|
use FireflyIII\TransactionRules\Triggers\ToAccountNumberStarts;
|
||||||
use FireflyIII\TransactionRules\Triggers\ToAccountStarts;
|
use FireflyIII\TransactionRules\Triggers\ToAccountStarts;
|
||||||
use FireflyIII\TransactionRules\Triggers\TransactionType;
|
use FireflyIII\TransactionRules\Triggers\TransactionType;
|
||||||
use FireflyIII\TransactionRules\Triggers\UserAction;
|
use FireflyIII\TransactionRules\Triggers\UserAction;
|
||||||
@@ -421,10 +425,10 @@ return [
|
|||||||
'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_starts' => ToAccountNumberStarts::class,
|
||||||
//'to_account_nr_ends' => ToAccountNumberEnds::class,
|
'to_account_nr_ends' => ToAccountNumberEnds::class,
|
||||||
//'to_account_nr_is' => ToAccountNumberIs::class,
|
'to_account_nr_is' => ToAccountNumberIs::class,
|
||||||
//'to_account_nr_contains' => ToAccountNumberContains::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,
|
||||||
|
Reference in New Issue
Block a user