All rules for #2723, untested.

This commit is contained in:
James Cole
2019-12-21 06:37:41 +01:00
parent be2794406c
commit 2a110185a1
18 changed files with 531 additions and 104 deletions

View File

@@ -79,8 +79,8 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
if (!(false === $strpos)) {
Log::debug(
sprintf(
'RuleTrigger FromAccountContains for journal #%d: "%s" contains "%s", return true.',
$journal->id, $source->name, $this->triggerValue
'RuleTrigger %s for journal #%d: "%s" contains "%s", return true.',
get_class($this), $journal->id, $source->name, $this->triggerValue
)
);
@@ -89,10 +89,8 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
Log::debug(
sprintf(
'RuleTrigger FromAccountContains for journal #%d: "%s" does not contain "%s", return false.',
$journal->id,
$source->name,
$this->triggerValue
'RuleTrigger %s for journal #%d: "%s" does not contain "%s", return false.',
get_class($this), $journal->id, $source->name, $this->triggerValue
)
);

View File

@@ -82,18 +82,33 @@ final class FromAccountEnds extends AbstractTrigger implements TriggerInterface
// if the string to search for is longer than the account name,
// it will never be in the account name.
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;
}
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;
}
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;
}

View File

@@ -77,12 +77,14 @@ final class FromAccountIs extends AbstractTrigger implements TriggerInterface
$search = strtolower($this->triggerValue);
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;
}
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;
}

View File

@@ -80,8 +80,8 @@ final class FromAccountNumberContains extends AbstractTrigger implements Trigger
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
'RuleTrigger %s for journal #%d: "%s" or "%s" contains "%s", return true.',
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(
sprintf(
'RuleTrigger FromAccountContains for journal #%d: "%s" and "%s" does not contain "%s", return false.',
$journal->id,
$source->iban,
$source->account_number,
$this->triggerValue
'RuleTrigger %s for journal #%d: "%s" and "%s" does not contain "%s", return false.',
get_class($this), $journal->id, $source->iban, $source->account_number, $this->triggerValue
)
);

View File

@@ -74,18 +74,18 @@ final class FromAccountNumberEnds extends AbstractTrigger implements TriggerInte
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$source = $repository->getSourceAccount($journal);
$search = $this->triggerValue;
$search = strtolower($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)) {
if (strtolower($part1) === $search
|| strtolower($part2) === $search) {
Log::debug(
sprintf(
'RuleTrigger FromAccountEnds for journal #%d: "%s" or "%s" ends with "%s", return true.',
$journal->id, $part1, $part2, $search
'RuleTrigger %s for journal #%d: "%s" or "%s" ends with "%s", return true.',
get_class($this), $journal->id, $part1, $part2, $search
)
);
@@ -94,8 +94,8 @@ final class FromAccountNumberEnds extends AbstractTrigger implements TriggerInte
Log::debug(
sprintf(
'RuleTrigger FromAccountEnds for journal #%d: "%s" and "%s" do not end with "%s", return false.',
$journal->id, $part1, $part2, $search
'RuleTrigger %s for journal #%d: "%s" and "%s" do not end with "%s", return false.',
get_class($this), $journal->id, $part1, $part2, $search
)
);

View File

@@ -79,8 +79,8 @@ final class FromAccountNumberIs extends AbstractTrigger implements TriggerInterf
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
'RuleTrigger %s for journal #%d: "%s" or "%s" is "%s", return true.', $journal->id,
get_class($this), $source->iban, $source->account_number, $search
)
);
@@ -89,8 +89,8 @@ final class FromAccountNumberIs extends AbstractTrigger implements TriggerInterf
Log::debug(
sprintf(
'RuleTrigger FromAccountIs for journal #%d: "%s" and "%s" is NOT "%s", return false.', $journal->id, $source->iban, $source->account_number,
$search
'RuleTrigger %s for journal #%d: "%s" and "%s" are NOT "%s", return false.',
get_class($this), $journal->id, $source->iban, $source->account_number, $search
)
);

View File

@@ -81,8 +81,8 @@ final class FromAccountNumberStarts extends AbstractTrigger implements TriggerIn
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
'RuleTrigger %s for journal #%d: "%s" or "%s" starts with "%s", return true.',
get_class($this), $journal->id, $part1, $part2, $search
)
);
@@ -91,8 +91,8 @@ final class FromAccountNumberStarts extends AbstractTrigger implements TriggerIn
Log::debug(
sprintf(
'RuleTrigger FromAccountStarts for journal #%d: "%s" and "%s" do not start with "%s", return false.',
$journal->id, $part1, $part2, $search
'RuleTrigger %s for journal #%d: "%s" and "%s" do not start with "%s", return false.',
get_class($this), $journal->id, $part1, $part2, $search
)
);

View File

@@ -78,12 +78,22 @@ final class FromAccountStarts extends AbstractTrigger implements TriggerInterfac
$part = substr($source->name, 0, strlen($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;
}
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;
}

View File

@@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Log;
@@ -65,39 +64,32 @@ final class ToAccountContains extends AbstractTrigger implements TriggerInterfac
/**
* Returns true when to-account contains X
* TODO
*
* @param TransactionJournal $journal
*
* @return bool
*/
public function triggered(TransactionJournal $journal): bool
{
$toAccountName = '';
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
/** @var Account $account */
foreach ($repository->getJournalDestinationAccounts($journal, false) as $account) {
$toAccountName .= strtolower($account->name);
}
$search = strtolower($this->triggerValue);
$strpos = strpos($toAccountName, $search);
$dest = $repository->getDestinationAccount($journal);
$strpos = stripos($dest->name, $this->triggerValue);
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;
}
Log::debug(
sprintf(
'RuleTrigger ToAccountContains for journal #%d: "%s" does not contain "%s", return false.',
$journal->id,
$toAccountName,
$search
'RuleTrigger %s for journal #%d: "%s" does not contain "%s", return false.',
get_class($this), $journal->id, $dest->name, $this->triggerValue
)
);

View File

@@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Triggers;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Log;
@@ -72,37 +71,44 @@ final class ToAccountEnds extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$toAccountName = '';
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
/** @var Account $account */
foreach ($repository->getJournalDestinationAccounts($journal, false) as $account) {
$toAccountName .= strtolower($account->name);
}
$toAccountNameLength = strlen($toAccountName);
$search = strtolower($this->triggerValue);
$searchLength = strlen($search);
$repository = app(JournalRepositoryInterface::class);
$dest = $repository->getDestinationAccount($journal);
$nameLength = strlen($dest->name);
$search = $this->triggerValue;
$searchLength = strlen($search);
$part = substr($dest->name, $searchLength * -1);
// if the string to search for is longer than the account name,
// return false
if ($searchLength > $toAccountNameLength) {
Log::debug(sprintf('RuleTrigger ToAccountEnds for journal #%d: "%s" does not end with "%s", return false.', $journal->id, $toAccountName, $search));
// it will never be in the account name.
if ($searchLength > $nameLength) {
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;
}
$part = substr($toAccountName, $searchLength * -1);
if ($part === $search) {
Log::debug(sprintf('RuleTrigger ToAccountEnds for journal #%d: "%s" ends with "%s", return true.', $journal->id, $toAccountName, $search));
if (strtolower($part) === strtolower($search)) {
Log::debug(
sprintf(
'RuleTrigger %s for journal #%d: "%s" ends with "%s", return true.',
get_class($this), $journal->id, $dest->name, $search
)
);
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;
}

View File

@@ -72,25 +72,20 @@ final class ToAccountIs extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$toAccountName = '';
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$dest = $repository->getDestinationAccount($journal);
$search = strtolower($this->triggerValue);
/** @var Account $account */
foreach ($repository->getJournalDestinationAccounts($journal, false) as $account) {
$toAccountName .= strtolower($account->name);
}
$search = strtolower($this->triggerValue);
if ($toAccountName === $search) {
Log::debug(sprintf('RuleTrigger ToAccountIs for journal #%d: "%s" is "%s", return true.', $journal->id, $toAccountName, $search));
if (strtolower($dest->name) === $search) {
Log::debug(sprintf('RuleTrigger %s for journal #%d: "%s" is "%s", return true.',
get_class($this), $journal->id, $dest->name, $search));
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;
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View 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;
}
}

View File

@@ -72,25 +72,29 @@ final class ToAccountStarts extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$toAccountName = '';
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
/** @var Account $account */
foreach ($repository->getJournalDestinationAccounts($journal, false) as $account) {
$toAccountName .= strtolower($account->name);
}
$search = strtolower($this->triggerValue);
$part = substr($toAccountName, 0, strlen($search));
$dest = $repository->getDestinationAccount($journal);
$search = strtolower($this->triggerValue);
$part = substr($dest->name, 0, strlen($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;
}
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;
}