mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Final modifiers.
This commit is contained in:
@@ -12,6 +12,8 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Support\Search;
|
namespace FireflyIII\Support\Search;
|
||||||
|
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Exception;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use Log;
|
use Log;
|
||||||
@@ -71,12 +73,82 @@ class Modifier
|
|||||||
$res = Modifier::budget($transaction, $modifier['value']);
|
$res = Modifier::budget($transaction, $modifier['value']);
|
||||||
Log::debug(sprintf('Budget is %s? %s', $modifier['value'], var_export($res, true)));
|
Log::debug(sprintf('Budget is %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
break;
|
break;
|
||||||
|
case 'bill':
|
||||||
|
$res = Modifier::stringCompare(strval($transaction->bill_name), $modifier['value']);
|
||||||
|
Log::debug(sprintf('Bill is %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
|
case 'type':
|
||||||
|
$res = Modifier::stringCompare($transaction->transaction_type_type, $modifier['value']);
|
||||||
|
Log::debug(sprintf('Transaction type is %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
|
case 'date':
|
||||||
|
$res = Modifier::sameDate($transaction->date, $modifier['value']);
|
||||||
|
Log::debug(sprintf('Date is %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
|
case 'date_before':
|
||||||
|
$res = Modifier::dateBefore($transaction->date, $modifier['value']);
|
||||||
|
Log::debug(sprintf('Date is %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
|
case 'date_after':
|
||||||
|
$res = Modifier::dateAfter($transaction->date, $modifier['value']);
|
||||||
|
Log::debug(sprintf('Date is %s? %s', $modifier['value'], var_export($res, true)));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Carbon $date
|
||||||
|
* @param string $compare
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function dateAfter(Carbon $date, string $compare): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$compareDate = new Carbon($compare);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $date->greaterThanOrEqualTo($compareDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Carbon $date
|
||||||
|
* @param string $compare
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function dateBefore(Carbon $date, string $compare): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$compareDate = new Carbon($compare);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $date->lessThanOrEqualTo($compareDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Carbon $date
|
||||||
|
* @param string $compare
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function sameDate(Carbon $date, string $compare): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$compareDate = new Carbon($compare);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $compareDate->isSameDay($date);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $haystack
|
* @param string $haystack
|
||||||
* @param string $needle
|
* @param string $needle
|
||||||
|
@@ -75,7 +75,7 @@ class Search implements SearchInterface
|
|||||||
public function parseQuery(string $query)
|
public function parseQuery(string $query)
|
||||||
{
|
{
|
||||||
$filteredQuery = $query;
|
$filteredQuery = $query;
|
||||||
$pattern = '/[a-z_]*:[0-9a-z.]*/i';
|
$pattern = '/[a-z_]*:[0-9a-z-.]*/i';
|
||||||
$matches = [];
|
$matches = [];
|
||||||
preg_match_all($pattern, $query, $matches);
|
preg_match_all($pattern, $query, $matches);
|
||||||
|
|
||||||
@@ -84,8 +84,10 @@ class Search implements SearchInterface
|
|||||||
$filteredQuery = str_replace($match, '', $filteredQuery);
|
$filteredQuery = str_replace($match, '', $filteredQuery);
|
||||||
}
|
}
|
||||||
$filteredQuery = trim(str_replace(['"', "'"], '', $filteredQuery));
|
$filteredQuery = trim(str_replace(['"', "'"], '', $filteredQuery));
|
||||||
|
if (strlen($filteredQuery) > 0) {
|
||||||
$this->words = array_map('trim', explode(' ', $filteredQuery));
|
$this->words = array_map('trim', explode(' ', $filteredQuery));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection
|
* @return Collection
|
||||||
@@ -197,6 +199,7 @@ class Search implements SearchInterface
|
|||||||
if ($this->hasModifiers()) {
|
if ($this->hasModifiers()) {
|
||||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||||
}
|
}
|
||||||
|
$collector->disableInternalFilter();
|
||||||
$set = $collector->getPaginatedJournals()->getCollection();
|
$set = $collector->getPaginatedJournals()->getCollection();
|
||||||
$words = $this->words;
|
$words = $this->words;
|
||||||
|
|
||||||
@@ -287,7 +290,8 @@ class Search implements SearchInterface
|
|||||||
Log::debug(sprintf('Now at transaction #%d', $transaction->id));
|
Log::debug(sprintf('Now at transaction #%d', $transaction->id));
|
||||||
// first "modifier" is always the text of the search:
|
// first "modifier" is always the text of the search:
|
||||||
// check descr of journal:
|
// check descr of journal:
|
||||||
if (!$this->strpos_arr(strtolower(strval($transaction->description)), $this->words)
|
if (count($this->words) > 0
|
||||||
|
&& !$this->strpos_arr(strtolower(strval($transaction->description)), $this->words)
|
||||||
&& !$this->strpos_arr(strtolower(strval($transaction->transaction_description)), $this->words)
|
&& !$this->strpos_arr(strtolower(strval($transaction->transaction_description)), $this->words)
|
||||||
) {
|
) {
|
||||||
Log::debug('Description does not match', $this->words);
|
Log::debug('Description does not match', $this->words);
|
||||||
|
@@ -209,6 +209,7 @@ return [
|
|||||||
],
|
],
|
||||||
'default_currency' => 'EUR',
|
'default_currency' => 'EUR',
|
||||||
'default_language' => 'en_US',
|
'default_language' => 'en_US',
|
||||||
'search_modifiers' => ['amount_is', 'amount_less', 'amount_more', 'source', 'destination', 'category', 'budget', 'tag', 'bill', 'type', 'date_on',
|
'search_modifiers' => ['amount_is', 'amount_less', 'amount_more', 'source', 'destination', 'category', 'budget', 'bill', 'type', 'date',
|
||||||
'date_before', 'date_after', 'has_attachments', 'notes',],
|
'date_before', 'date_after'],
|
||||||
|
// tag notes has_attachments
|
||||||
];
|
];
|
||||||
|
Reference in New Issue
Block a user