mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Final modifiers.
This commit is contained in:
		| @@ -12,6 +12,8 @@ declare(strict_types = 1); | ||||
| namespace FireflyIII\Support\Search; | ||||
|  | ||||
|  | ||||
| use Carbon\Carbon; | ||||
| use Exception; | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Models\Transaction; | ||||
| use Log; | ||||
| @@ -71,12 +73,82 @@ class Modifier | ||||
|                 $res = Modifier::budget($transaction, $modifier['value']); | ||||
|                 Log::debug(sprintf('Budget is %s? %s', $modifier['value'], var_export($res, true))); | ||||
|                 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; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @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 $needle | ||||
|   | ||||
| @@ -75,7 +75,7 @@ class Search implements SearchInterface | ||||
|     public function parseQuery(string $query) | ||||
|     { | ||||
|         $filteredQuery = $query; | ||||
|         $pattern       = '/[a-z_]*:[0-9a-z.]*/i'; | ||||
|         $pattern       = '/[a-z_]*:[0-9a-z-.]*/i'; | ||||
|         $matches       = []; | ||||
|         preg_match_all($pattern, $query, $matches); | ||||
|  | ||||
| @@ -84,7 +84,9 @@ class Search implements SearchInterface | ||||
|             $filteredQuery = str_replace($match, '', $filteredQuery); | ||||
|         } | ||||
|         $filteredQuery = trim(str_replace(['"', "'"], '', $filteredQuery)); | ||||
|         $this->words   = array_map('trim', explode(' ', $filteredQuery)); | ||||
|         if (strlen($filteredQuery) > 0) { | ||||
|             $this->words = array_map('trim', explode(' ', $filteredQuery)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -194,9 +196,10 @@ class Search implements SearchInterface | ||||
|             $collector = app(JournalCollectorInterface::class); | ||||
|             $collector->setUser($this->user); | ||||
|             $collector->setAllAssetAccounts()->setLimit($pageSize)->setPage($page); | ||||
|             if($this->hasModifiers()) { | ||||
|             if ($this->hasModifiers()) { | ||||
|                 $collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation(); | ||||
|             } | ||||
|             $collector->disableInternalFilter(); | ||||
|             $set   = $collector->getPaginatedJournals()->getCollection(); | ||||
|             $words = $this->words; | ||||
|  | ||||
| @@ -287,7 +290,8 @@ class Search implements SearchInterface | ||||
|         Log::debug(sprintf('Now at transaction #%d', $transaction->id)); | ||||
|         // first "modifier" is always the text of the search: | ||||
|         // 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) | ||||
|         ) { | ||||
|             Log::debug('Description does not match', $this->words); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user