Fix filters and other methods that used deprecated methods.

This commit is contained in:
James Cole 2016-05-20 08:09:53 +02:00
parent dda3082c7e
commit 70d936bb8f
10 changed files with 81 additions and 18 deletions

View File

@ -215,6 +215,9 @@ class TagRepository implements TagRepositoryInterface
}
/**
* The incoming journal ($journal)'s accounts (source accounts for a withdrawal, destination accounts for a deposit)
* must match the already existing transaction's accounts exactly.
*
* @param TransactionJournal $journal
* @param Tag $tag
*
@ -223,16 +226,21 @@ class TagRepository implements TagRepositoryInterface
*/
protected function matchAll(TransactionJournal $journal, Tag $tag): bool
{
$checkSources = join(',', TransactionJournal::sourceAccountList($journal)->pluck('id')->toArray());
$checkDestinations = join(',', TransactionJournal::destinationAccountList($journal)->pluck('id')->toArray());
$match = true;
/** @var TransactionJournal $check */
foreach ($tag->transactionjournals as $check) {
// $checkAccount is the source_account for a withdrawal
// $checkAccount is the destination_account for a deposit
$thisSources = join(',', TransactionJournal::sourceAccountList($check)->pluck('id')->toArray());
$thisDestinations = join(',', TransactionJournal::destinationAccountList($check)->pluck('id')->toArray());
if ($check->isWithdrawal() && TransactionJournal::sourceAccount($check)->id != TransactionJournal::destinationAccount($journal)->id) {
if ($check->isWithdrawal() && $thisSources !== $checkSources) {
$match = false;
}
if ($check->isDeposit() && TransactionJournal::destinationAccount($check)->id != TransactionJournal::destinationAccount($journal)->id) {
if ($check->isDeposit() && $thisDestinations !== $checkDestinations) {
$match = false;
}

View File

@ -10,6 +10,7 @@ declare(strict_types = 1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
/**
@ -52,9 +53,15 @@ final class FromAccountContains extends AbstractTrigger implements TriggerInterf
*/
public function triggered(TransactionJournal $journal): bool
{
$fromAccountName = strtolower($journal->source_account_name ?? TransactionJournal::sourceAccount($journal)->name);
$search = strtolower($this->triggerValue);
$strpos = strpos($fromAccountName, $search);
$fromAccountName = '';
/** @var Account $account */
foreach (TransactionJournal::sourceAccountList($journal) as $account) {
$fromAccountName .= strtolower($account->name);
}
$search = strtolower($this->triggerValue);
$strpos = strpos($fromAccountName, $search);
if (!($strpos === false)) {
return true;

View File

@ -10,6 +10,7 @@ declare(strict_types = 1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
/**
@ -52,7 +53,13 @@ final class FromAccountEnds extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$name = strtolower($journal->source_account_name ?? TransactionJournal::sourceAccount($journal)->name);
$name = '';
/** @var Account $account */
foreach (TransactionJournal::sourceAccountList($journal) as $account) {
$name .= strtolower($account->name);
}
$nameLength = strlen($name);
$search = strtolower($this->triggerValue);
$searchLength = strlen($search);

View File

@ -10,6 +10,7 @@ declare(strict_types = 1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
/**
@ -52,7 +53,13 @@ final class FromAccountIs extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$name = strtolower($journal->source_account_name ?? TransactionJournal::sourceAccount($journal)->name);
$name = '';
/** @var Account $account */
foreach (TransactionJournal::sourceAccountList($journal) as $account) {
$name .= strtolower($account->name);
}
$search = strtolower($this->triggerValue);
if ($name == $search) {

View File

@ -10,6 +10,7 @@ declare(strict_types = 1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
/**
@ -52,7 +53,13 @@ final class FromAccountStarts extends AbstractTrigger implements TriggerInterfac
*/
public function triggered(TransactionJournal $journal): bool
{
$name = strtolower($journal->source_account_name ?? TransactionJournal::sourceAccount($journal)->name);
$name = '';
/** @var Account $account */
foreach (TransactionJournal::sourceAccountList($journal) as $account) {
$name .= strtolower($account->name);
}
$search = strtolower($this->triggerValue);
$part = substr($name, 0, strlen($search));

View File

@ -10,6 +10,7 @@ declare(strict_types = 1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
/**
@ -52,9 +53,15 @@ final class ToAccountContains extends AbstractTrigger implements TriggerInterfac
*/
public function triggered(TransactionJournal $journal): bool
{
$toAccountName = strtolower($journal->destination_account_name ?? TransactionJournal::destinationAccount($journal)->name);
$search = strtolower($this->triggerValue);
$strpos = strpos($toAccountName, $search);
$toAccountName = '';
/** @var Account $account */
foreach (TransactionJournal::destinationAccountList($journal) as $account) {
$toAccountName .= strtolower($account->name);
}
$search = strtolower($this->triggerValue);
$strpos = strpos($toAccountName, $search);
if (!($strpos === false)) {
return true;

View File

@ -10,6 +10,7 @@ declare(strict_types = 1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
/**
@ -52,7 +53,13 @@ final class ToAccountEnds extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$toAccountName = strtolower($journal->destination_account_name ?? TransactionJournal::destinationAccount($journal)->name);
$toAccountName = '';
/** @var Account $account */
foreach (TransactionJournal::destinationAccountList($journal) as $account) {
$toAccountName .= strtolower($account->name);
}
$toAccountNameLength = strlen($toAccountName);
$search = strtolower($this->triggerValue);
$searchLength = strlen($search);

View File

@ -10,6 +10,7 @@ declare(strict_types = 1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
/**
@ -52,7 +53,13 @@ final class ToAccountIs extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$toAccountName = strtolower($journal->destination_account_name ?? TransactionJournal::destinationAccount($journal)->name);
$toAccountName = '';
/** @var Account $account */
foreach (TransactionJournal::destinationAccountList($journal) as $account) {
$toAccountName .= strtolower($account->name);
}
$search = strtolower($this->triggerValue);
if ($toAccountName == $search) {

View File

@ -10,6 +10,7 @@ declare(strict_types = 1);
namespace FireflyIII\Rules\Triggers;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionJournal;
/**
@ -52,10 +53,15 @@ final class ToAccountStarts extends AbstractTrigger implements TriggerInterface
*/
public function triggered(TransactionJournal $journal): bool
{
$toAccountName = strtolower($journal->destination_account_name ?? TransactionJournal::destinationAccount($journal)->name);
$search = strtolower($this->triggerValue);
$toAccountName = '';
$part = substr($toAccountName, 0, strlen($search));
/** @var Account $account */
foreach (TransactionJournal::destinationAccountList($journal) as $account) {
$toAccountName .= strtolower($account->name);
}
$search = strtolower($this->triggerValue);
$part = substr($toAccountName, 0, strlen($search));
if ($part == $search) {
return true;

View File

@ -172,7 +172,7 @@ class TransactionJournalSupport extends Model
if ($cache->has()) {
return $cache->get();
}
$transactions = $journal->transactions()->where('amount', '>', 0)->with('account')->get();
$transactions = $journal->transactions()->where('amount', '>', 0)->orderBy('transactions.account_id')->with('account')->get();
$list = new Collection;
/** @var Transaction $t */
foreach ($transactions as $t) {
@ -316,7 +316,7 @@ class TransactionJournalSupport extends Model
if ($cache->has()) {
return $cache->get();
}
$transactions = $journal->transactions()->where('amount', '<', 0)->with('account')->get();
$transactions = $journal->transactions()->where('amount', '<', 0)->orderBy('transactions.account_id')->with('account')->get();
$list = new Collection;
/** @var Transaction $t */
foreach ($transactions as $t) {