| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-29 14:55:51 +02:00
										 |  |  | /* | 
					
						
							|  |  |  |  * AttachmentCollection.php | 
					
						
							|  |  |  |  * Copyright (c) 2022 james@firefly-iii.org | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  | namespace FireflyIII\Helpers\Collector\Extensions; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use FireflyIII\Helpers\Collector\GroupCollectorInterface; | 
					
						
							|  |  |  | use FireflyIII\Models\Attachment; | 
					
						
							|  |  |  | use FireflyIII\Models\TransactionJournal; | 
					
						
							| 
									
										
										
										
											2022-05-04 20:49:54 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Builder; | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Trait AttachmentCollection | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | trait AttachmentCollection | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function attachmentNameContains(string $name): GroupCollectorInterface | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($name): bool { | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     $result = str_contains(strtolower($attachment['filename']), strtolower($name)) || str_contains( | 
					
						
							|  |  |  |                         strtolower($attachment['title']), | 
					
						
							|  |  |  |                         strtolower($name) | 
					
						
							|  |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                     if (true === $result) { | 
					
						
							|  |  |  |                         return true; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Has attachments | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function hasAttachments(): GroupCollectorInterface | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |         app('log')->debug('Add filter on attachment ID.'); | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |         $this->joinAttachmentTables(); | 
					
						
							|  |  |  |         $this->query->whereNotNull('attachments.attachable_id'); | 
					
						
							| 
									
										
										
										
											2022-11-06 18:15:53 +01:00
										 |  |  |         $this->query->whereNull('attachments.deleted_at'); | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Join table to get attachment information. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function joinAttachmentTables(): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (false === $this->hasJoinedAttTables) { | 
					
						
							|  |  |  |             // join some extra tables:
 | 
					
						
							|  |  |  |             $this->hasJoinedAttTables = true; | 
					
						
							|  |  |  |             $this->query->leftJoin('attachments', 'attachments.attachable_id', '=', 'transaction_journals.id') | 
					
						
							|  |  |  |                         ->where( | 
					
						
							| 
									
										
										
										
											2023-11-04 11:31:14 +01:00
										 |  |  |                             static function (EloquentBuilder $q1) { // @phpstan-ignore-line
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                                 $q1->where('attachments.attachable_type', TransactionJournal::class); | 
					
						
							| 
									
										
										
										
											2023-04-15 10:19:54 +02:00
										 |  |  |                                 $q1->where('attachments.uploaded', true); | 
					
						
							|  |  |  |                                 $q1->whereNull('attachments.deleted_at'); | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                                 $q1->orWhereNull('attachments.attachable_type'); | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                         ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @inheritDoc | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function withAttachmentInformation(): GroupCollectorInterface | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->fields[] = 'attachments.id as attachment_id'; | 
					
						
							|  |  |  |         $this->fields[] = 'attachments.filename as attachment_filename'; | 
					
						
							|  |  |  |         $this->fields[] = 'attachments.title as attachment_title'; | 
					
						
							|  |  |  |         $this->fields[] = 'attachments.uploaded as attachment_uploaded'; | 
					
						
							|  |  |  |         $this->joinAttachmentTables(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     public function attachmentNameDoesNotContain(string $name): GroupCollectorInterface | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($name): bool { | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     $result = !str_contains(strtolower($attachment['filename']), strtolower($name)) && !str_contains( | 
					
						
							|  |  |  |                         strtolower($attachment['title']), | 
					
						
							|  |  |  |                         strtolower($name) | 
					
						
							|  |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                     if (true === $result) { | 
					
						
							|  |  |  |                         return true; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function attachmentNameDoesNotEnd(string $name): GroupCollectorInterface | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($name): bool { | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     $result = !str_ends_with(strtolower($attachment['filename']), strtolower($name)) && !str_ends_with( | 
					
						
							|  |  |  |                         strtolower($attachment['title']), | 
					
						
							|  |  |  |                         strtolower($name) | 
					
						
							|  |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                     if (true === $result) { | 
					
						
							|  |  |  |                         return true; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     public function attachmentNameDoesNotStart(string $name): GroupCollectorInterface | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($name): bool { | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     $result = !str_starts_with(strtolower($attachment['filename']), strtolower($name)) && !str_starts_with( | 
					
						
							|  |  |  |                         strtolower($attachment['title']), | 
					
						
							|  |  |  |                         strtolower($name) | 
					
						
							|  |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                     if (true === $result) { | 
					
						
							|  |  |  |                         return true; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     public function attachmentNameEnds(string $name): GroupCollectorInterface | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($name): bool { | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     $result = str_ends_with(strtolower($attachment['filename']), strtolower($name)) || str_ends_with( | 
					
						
							|  |  |  |                         strtolower($attachment['title']), | 
					
						
							|  |  |  |                         strtolower($name) | 
					
						
							|  |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                     if (true === $result) { | 
					
						
							|  |  |  |                         return true; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     public function attachmentNameIs(string $name): GroupCollectorInterface | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($name): bool { | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     $result = $attachment['filename'] === $name || $attachment['title'] === $name; | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                     if (true === $result) { | 
					
						
							|  |  |  |                         return true; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     public function attachmentNameIsNot(string $name): GroupCollectorInterface | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($name): bool { | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							|  |  |  |                     $result = $attachment['filename'] !== $name && $attachment['title'] !== $name; | 
					
						
							|  |  |  |                     if (true === $result) { | 
					
						
							|  |  |  |                         return true; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $name | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function attachmentNameStarts(string $name): GroupCollectorInterface | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($name): bool { | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     $result = str_starts_with(strtolower($attachment['filename']), strtolower($name)) || str_starts_with( | 
					
						
							|  |  |  |                         strtolower($attachment['title']), | 
					
						
							|  |  |  |                         strtolower($name) | 
					
						
							|  |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                     if (true === $result) { | 
					
						
							|  |  |  |                         return true; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function attachmentNotesAre(string $value): GroupCollectorInterface | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($value): bool { | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     /** @var Attachment|null $object */ | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                     $object = auth()->user()->attachments()->find($attachment['id']); | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     $notes  = (string)$object?->notes()->first()?->text; | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                     return $notes !== '' && $notes === $value; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function attachmentNotesAreNot(string $value): GroupCollectorInterface | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($value): bool { | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     /** @var Attachment|null $object */ | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                     $object = auth()->user()->attachments()->find($attachment['id']); | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     $notes  = (string)$object?->notes()->first()?->text; | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                     return $notes !== '' && $notes !== $value; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function attachmentNotesContains(string $value): GroupCollectorInterface | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($value): bool { | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     /** @var Attachment|null $object */ | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                     $object = auth()->user()->attachments()->find($attachment['id']); | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     $notes  = (string)$object?->notes()->first()?->text; | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                     return $notes !== '' && str_contains(strtolower($notes), strtolower($value)); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function attachmentNotesDoNotContain(string $value): GroupCollectorInterface | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($value): bool { | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     /** @var Attachment|null $object */ | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                     $object = auth()->user()->attachments()->find($attachment['id']); | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     $notes  = (string)$object?->notes()->first()?->text; | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                     return $notes !== '' && !str_contains(strtolower($notes), strtolower($value)); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     public function attachmentNotesDoNotEnd(string $value): GroupCollectorInterface | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($value): bool { | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     /** @var Attachment|null $object */ | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                     $object = auth()->user()->attachments()->find($attachment['id']); | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     $notes  = (string)$object?->notes()->first()?->text; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     return $notes !== '' && !str_ends_with(strtolower($notes), strtolower($value)); | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     public function attachmentNotesDoNotStart(string $value): GroupCollectorInterface | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($value): bool { | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     /** @var Attachment|null $object */ | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                     $object = auth()->user()->attachments()->find($attachment['id']); | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     $notes  = (string)$object?->notes()->first()?->text; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     return $notes !== '' && !str_starts_with(strtolower($notes), strtolower($value)); | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     public function attachmentNotesEnds(string $value): GroupCollectorInterface | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($value): bool { | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     /** @var Attachment|null $object */ | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                     $object = auth()->user()->attachments()->find($attachment['id']); | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     $notes  = (string)$object?->notes()->first()?->text; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     return $notes !== '' && str_ends_with(strtolower($notes), strtolower($value)); | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2023-06-21 12:34:58 +02:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2023-07-15 16:02:42 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |     public function attachmentNotesStarts(string $value): GroupCollectorInterface | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         $this->hasAttachments(); | 
					
						
							|  |  |  |         $this->withAttachmentInformation(); | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $filter              = static function (int $index, array $object) use ($value): bool { | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |             /** @var array $transaction */ | 
					
						
							|  |  |  |             foreach ($object['transactions'] as $transaction) { | 
					
						
							|  |  |  |                 /** @var array $attachment */ | 
					
						
							|  |  |  |                 foreach ($transaction['attachments'] as $attachment) { | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     /** @var Attachment|null $object */ | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                     $object = auth()->user()->attachments()->find($attachment['id']); | 
					
						
							| 
									
										
										
										
											2023-01-03 06:48:53 +01:00
										 |  |  |                     $notes  = (string)$object?->notes()->first()?->text; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:41:57 +01:00
										 |  |  |                     return $notes !== '' && str_starts_with(strtolower($notes), strtolower($value)); | 
					
						
							| 
									
										
										
										
											2022-09-28 07:35:57 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         $this->postFilters[] = $filter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Has attachments | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return GroupCollectorInterface | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function hasNoAttachments(): GroupCollectorInterface | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:33:43 +01:00
										 |  |  |         app('log')->debug('Add filter on no attachments.'); | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  |         $this->joinAttachmentTables(); | 
					
						
							| 
									
										
										
										
											2022-05-04 20:49:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |         $this->query->where(static function (Builder $q1) { // @phpstan-ignore-line
 | 
					
						
							| 
									
										
										
										
											2022-05-04 20:49:54 +02:00
										 |  |  |             $q1 | 
					
						
							|  |  |  |                 ->whereNull('attachments.attachable_id') | 
					
						
							| 
									
										
										
										
											2023-11-04 14:18:49 +01:00
										 |  |  |                 ->orWhere(static function (Builder $q2) { | 
					
						
							| 
									
										
										
										
											2022-05-04 20:49:54 +02:00
										 |  |  |                     $q2 | 
					
						
							|  |  |  |                         ->whereNotNull('attachments.attachable_id') | 
					
						
							|  |  |  |                         ->whereNotNull('attachments.deleted_at'); | 
					
						
							|  |  |  |                     // id is not null
 | 
					
						
							|  |  |  |                     // deleted at is not null.
 | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-28 07:54:52 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $this; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-03-29 14:55:51 +02:00
										 |  |  | } |