| 
									
										
										
										
											2016-05-20 08:57:45 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * TransactionJournal.php | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * Copyright (c) 2017 thegrumpydictator@gmail.com | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * This file is part of Firefly III. | 
					
						
							| 
									
										
										
										
											2016-10-05 06:52:15 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * Firefly III is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Firefly III 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 General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							| 
									
										
										
										
											2017-12-17 14:44:05 +01:00
										 |  |  |  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-04-09 07:44:22 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2016-05-20 08:57:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Models; | 
					
						
							| 
									
										
										
										
											2015-02-06 04:52:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2019-04-08 20:31:31 +02:00
										 |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							| 
									
										
										
										
											2018-03-02 16:31:02 +01:00
										 |  |  | use FireflyIII\User; | 
					
						
							| 
									
										
										
										
											2018-07-25 07:11:04 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Builder; | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  | use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | 
					
						
							| 
									
										
										
										
											2017-03-04 07:18:35 +01:00
										 |  |  | use Illuminate\Database\Eloquent\Model; | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\BelongsTo; | 
					
						
							| 
									
										
										
										
											2017-06-05 11:12:50 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\BelongsToMany; | 
					
						
							| 
									
										
										
										
											2015-02-22 08:38:46 +01:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\HasMany; | 
					
						
							| 
									
										
										
										
											2018-07-26 06:10:17 +02:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\MorphMany; | 
					
						
							| 
									
										
										
										
											2015-02-07 23:19:28 +01:00
										 |  |  | use Illuminate\Database\Eloquent\SoftDeletes; | 
					
						
							| 
									
										
										
										
											2018-06-30 06:14:39 +02:00
										 |  |  | use Illuminate\Support\Collection; | 
					
						
							| 
									
										
										
										
											2016-01-09 15:53:11 +01:00
										 |  |  | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | 
					
						
							| 
									
										
										
										
											2018-07-25 06:45:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-18 20:06:08 +01:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |  * Class TransactionJournal. | 
					
						
							| 
									
										
										
										
											2018-03-10 22:34:02 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-03-23 08:10:59 +01:00
										 |  |  |  * @property User                                                                                      $user | 
					
						
							|  |  |  |  * @property int                                                                                       $bill_id | 
					
						
							|  |  |  |  * @property Collection                                                                                $categories | 
					
						
							|  |  |  |  * @property bool                                                                                      $completed | 
					
						
							|  |  |  |  * @property string                                                                                    $description | 
					
						
							|  |  |  |  * @property int                                                                                       $transaction_type_id | 
					
						
							|  |  |  |  * @property int                                                                                       transaction_currency_id | 
					
						
							|  |  |  |  * @property TransactionCurrency                                                                       $transactionCurrency | 
					
						
							|  |  |  |  * @property Collection                                                                                $tags | 
					
						
							|  |  |  |  * @property int                                                                                       user_id | 
					
						
							|  |  |  |  * @property Collection                                                                                transactions | 
					
						
							|  |  |  |  * @property int                                                                                       transaction_count | 
					
						
							|  |  |  |  * @property Carbon                                                                                    interest_date | 
					
						
							|  |  |  |  * @property Carbon                                                                                    book_date | 
					
						
							|  |  |  |  * @property Carbon                                                                                    process_date | 
					
						
							|  |  |  |  * @property bool                                                                                      encrypted | 
					
						
							|  |  |  |  * @property int                                                                                       order | 
					
						
							|  |  |  |  * @property int                                                                                       budget_id | 
					
						
							|  |  |  |  * @property string                                                                                    period_marker | 
					
						
							|  |  |  |  * @property Carbon                                                                                    $date | 
					
						
							|  |  |  |  * @property string                                                                                    $transaction_type_type | 
					
						
							|  |  |  |  * @property int                                                                                       $id | 
					
						
							|  |  |  |  * @property TransactionType                                                                           $transactionType | 
					
						
							|  |  |  |  * @property Collection                                                                                budgets | 
					
						
							|  |  |  |  * @property Bill                                                                                      $bill | 
					
						
							|  |  |  |  * @property Collection                                                                                transactionJournalMeta | 
					
						
							|  |  |  |  * @property TransactionGroup                                                                          transactionGroup | 
					
						
							|  |  |  |  * @property int                                                                                       transaction_group_id | 
					
						
							| 
									
										
										
										
											2019-03-05 17:26:49 +01:00
										 |  |  |  * @SuppressWarnings (PHPMD.TooManyPublicMethods) | 
					
						
							|  |  |  |  * @SuppressWarnings (PHPMD.CouplingBetweenObjects) | 
					
						
							| 
									
										
										
										
											2019-03-23 08:10:59 +01:00
										 |  |  |  * @property \Illuminate\Support\Carbon|null                                                           $created_at | 
					
						
							|  |  |  |  * @property \Illuminate\Support\Carbon|null                                                           $updated_at | 
					
						
							|  |  |  |  * @property \Illuminate\Support\Carbon|null                                                           $deleted_at | 
					
						
							|  |  |  |  * @property int                                                                                       $tag_count | 
					
						
							|  |  |  |  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Attachment[]             $attachments | 
					
						
							|  |  |  |  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Note[]                   $notes | 
					
						
							|  |  |  |  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBankEvent[]         $piggyBankEvents | 
					
						
							| 
									
										
										
										
											2019-03-05 17:26:49 +01:00
										 |  |  |  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\TransactionJournalLink[] $sourceJournalLinks | 
					
						
							| 
									
										
										
										
											2019-03-23 08:10:59 +01:00
										 |  |  |  * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Category[]               $transactionGroups | 
					
						
							| 
									
										
										
										
											2019-03-05 17:26:49 +01:00
										 |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal after(\Carbon\Carbon $date) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal before(\Carbon\Carbon $date) | 
					
						
							|  |  |  |  * @method static bool|null forceDelete() | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal newModelQuery() | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal newQuery() | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal onlyTrashed() | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal query() | 
					
						
							|  |  |  |  * @method static bool|null restore() | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal transactionTypes($types) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereBillId($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereBookDate($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereCompleted($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereCreatedAt($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereDate($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereDeletedAt($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereDescription($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereEncrypted($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereId($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereInterestDate($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereOrder($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereProcessDate($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereTagCount($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereTransactionCurrencyId($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereTransactionTypeId($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereUpdatedAt($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\TransactionJournal whereUserId($value) | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal withTrashed() | 
					
						
							|  |  |  |  * @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\TransactionJournal withoutTrashed() | 
					
						
							|  |  |  |  * @mixin \Eloquent | 
					
						
							| 
									
										
										
										
											2016-11-18 20:06:08 +01:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-04 07:18:35 +01:00
										 |  |  | class TransactionJournal extends Model | 
					
						
							| 
									
										
										
										
											2015-02-06 05:04:06 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-25 06:45:25 +02:00
										 |  |  |     use SoftDeletes; | 
					
						
							| 
									
										
										
										
											2015-02-09 07:56:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-24 17:36:51 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * The attributes that should be casted to native types. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $casts | 
					
						
							|  |  |  |         = [ | 
					
						
							| 
									
										
										
										
											2017-11-03 16:04:17 +01:00
										 |  |  |             'created_at'    => 'datetime', | 
					
						
							|  |  |  |             'updated_at'    => 'datetime', | 
					
						
							|  |  |  |             'deleted_at'    => 'datetime', | 
					
						
							| 
									
										
										
										
											2019-02-08 07:14:45 +01:00
										 |  |  |             'date'          => 'datetime', | 
					
						
							| 
									
										
										
										
											2016-12-24 17:36:51 +01:00
										 |  |  |             'interest_date' => 'date', | 
					
						
							|  |  |  |             'book_date'     => 'date', | 
					
						
							|  |  |  |             'process_date'  => 'date', | 
					
						
							|  |  |  |             'order'         => 'int', | 
					
						
							|  |  |  |             'tag_count'     => 'int', | 
					
						
							|  |  |  |             'encrypted'     => 'boolean', | 
					
						
							|  |  |  |             'completed'     => 'boolean', | 
					
						
							|  |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2018-02-04 09:22:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |     /** @var array Fields that can be filled */ | 
					
						
							| 
									
										
										
										
											2015-06-14 11:52:07 +02:00
										 |  |  |     protected $fillable | 
					
						
							| 
									
										
										
										
											2019-04-06 08:10:50 +02:00
										 |  |  |         = ['user_id', 'transaction_type_id', 'bill_id', 'tag_count','transaction_currency_id', 'description', 'completed', 'order', | 
					
						
							|  |  |  |            'date']; | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |     /** @var array Hidden from view */ | 
					
						
							| 
									
										
										
										
											2015-06-14 11:52:07 +02:00
										 |  |  |     protected $hidden = ['encrypted']; | 
					
						
							| 
									
										
										
										
											2015-02-06 04:52:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-25 07:11:04 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * Checks if tables are joined. | 
					
						
							| 
									
										
										
										
											2019-07-26 17:48:24 +02:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-07-25 07:11:04 +02:00
										 |  |  |      * @param Builder $query | 
					
						
							|  |  |  |      * @param string  $table | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public static function isJoined(Builder $query, string $table): bool | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $joins = $query->getQuery()->joins; | 
					
						
							|  |  |  |         if (null === $joins) { | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         foreach ($joins as $join) { | 
					
						
							|  |  |  |             if ($join->table === $table) { | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * Route binder. Converts the key in the URL to the specified object (or throw 404). | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @param string $value | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @return TransactionJournal | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @throws NotFoundHttpException | 
					
						
							| 
									
										
										
										
											2019-04-08 20:31:31 +02:00
										 |  |  |      * @throws FireflyException | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-02-09 19:24:15 +01:00
										 |  |  |     public static function routeBinder(string $value): TransactionJournal | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-02-09 19:28:16 +01:00
										 |  |  |         if (auth()->check()) { | 
					
						
							| 
									
										
										
										
											2018-04-02 15:10:40 +02:00
										 |  |  |             $journalId = (int)$value; | 
					
						
							| 
									
										
										
										
											2018-07-22 16:35:46 +02:00
										 |  |  |             /** @var User $user */ | 
					
						
							|  |  |  |             $user = auth()->user(); | 
					
						
							|  |  |  |             /** @var TransactionJournal $journal */ | 
					
						
							| 
									
										
										
										
											2019-07-20 06:47:34 +02:00
										 |  |  |             $journal = $user->transactionJournals()->where('transaction_journals.id', $journalId)->first(['transaction_journals.*']); | 
					
						
							| 
									
										
										
										
											2018-04-02 15:10:40 +02:00
										 |  |  |             if (null !== $journal) { | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |                 return $journal; | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         throw new NotFoundHttpException; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:30 +02:00
										 |  |  |      * @return MorphMany | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-06 19:14:30 +02:00
										 |  |  |     public function attachments(): MorphMany | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->morphMany(Attachment::class, 'attachable'); | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @return BelongsTo | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |     public function bill(): BelongsTo | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->belongsTo(Bill::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @return BelongsToMany | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-06-05 11:12:50 +02:00
										 |  |  |     public function budgets(): BelongsToMany | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->belongsToMany(Budget::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @return BelongsToMany | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-06-05 11:12:50 +02:00
										 |  |  |     public function categories(): BelongsToMany | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->belongsToMany(Category::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2019-07-26 17:48:24 +02:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-06-05 11:12:50 +02:00
										 |  |  |     public function isDeposit(): bool | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (null !== $this->transaction_type_type) { | 
					
						
							|  |  |  |             return TransactionType::DEPOSIT === $this->transaction_type_type; | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->transactionType->isDeposit(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-06-05 11:12:50 +02:00
										 |  |  |     public function isOpeningBalance(): bool | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (null !== $this->transaction_type_type) { | 
					
						
							|  |  |  |             return TransactionType::OPENING_BALANCE === $this->transaction_type_type; | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->transactionType->isOpeningBalance(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-06-05 11:12:50 +02:00
										 |  |  |     public function isTransfer(): bool | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (null !== $this->transaction_type_type) { | 
					
						
							|  |  |  |             return TransactionType::TRANSFER === $this->transaction_type_type; | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->transactionType->isTransfer(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |      * @return bool | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-06-05 11:12:50 +02:00
										 |  |  |     public function isWithdrawal(): bool | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (null !== $this->transaction_type_type) { | 
					
						
							|  |  |  |             return TransactionType::WITHDRAWAL === $this->transaction_type_type; | 
					
						
							| 
									
										
										
										
											2016-01-27 18:31:44 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $this->transactionType->isWithdrawal(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-03 10:30:56 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2017-10-03 10:30:56 +02:00
										 |  |  |      * Get all of the notes. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-26 06:10:17 +02:00
										 |  |  |     public function notes(): MorphMany | 
					
						
							| 
									
										
										
										
											2017-10-03 10:30:56 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->morphMany(Note::class, 'noteable'); | 
					
						
							| 
									
										
										
										
											2017-10-03 10:30:56 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @return HasMany | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-06-05 11:12:50 +02:00
										 |  |  |     public function piggyBankEvents(): HasMany | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasMany(PiggyBankEvent::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2017-12-29 09:05:35 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  |      * @param EloquentBuilder $query | 
					
						
							|  |  |  |      * @param Carbon          $date | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-26 18:57:31 +00:00
										 |  |  |      * @return EloquentBuilder | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-22 16:35:46 +02:00
										 |  |  |     public function scopeAfter(EloquentBuilder $query, Carbon $date): EloquentBuilder | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         return $query->where('transaction_journals.date', '>=', $date->format('Y-m-d 00:00:00')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2017-12-29 09:05:35 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  |      * @param EloquentBuilder $query | 
					
						
							|  |  |  |      * @param Carbon          $date | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-05-26 18:57:31 +00:00
										 |  |  |      * @return EloquentBuilder | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-22 16:35:46 +02:00
										 |  |  |     public function scopeBefore(EloquentBuilder $query, Carbon $date): EloquentBuilder | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         return $query->where('transaction_journals.date', '<=', $date->format('Y-m-d 00:00:00')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2017-12-29 09:05:35 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  |      * @param EloquentBuilder $query | 
					
						
							|  |  |  |      * @param array           $types | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-22 16:35:46 +02:00
										 |  |  |     public function scopeTransactionTypes(EloquentBuilder $query, array $types): void | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-03-02 12:52:36 +01:00
										 |  |  |         if (!self::isJoined($query, 'transaction_types')) { | 
					
						
							| 
									
										
										
										
											2016-03-02 12:47:15 +01:00
										 |  |  |             $query->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-05-30 12:31:19 +02:00
										 |  |  |         if (count($types) > 0) { | 
					
						
							| 
									
										
										
										
											2016-11-01 18:40:35 +01:00
										 |  |  |             $query->whereIn('transaction_types.type', $types); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-05-15 18:36:40 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-02-07 08:23:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-21 07:13:03 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2017-08-21 07:13:03 +02:00
										 |  |  |      * @return HasMany | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function sourceJournalLinks(): HasMany | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasMany(TransactionJournalLink::class, 'source_id'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @return BelongsToMany | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-07-22 16:35:46 +02:00
										 |  |  |     public function tags(): BelongsToMany | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->belongsToMany(Tag::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @return BelongsTo | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |     public function transactionCurrency(): BelongsTo | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->belongsTo(TransactionCurrency::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-13 17:38:41 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2019-03-23 08:10:59 +01:00
										 |  |  |      * @return BelongsTo | 
					
						
							| 
									
										
										
										
											2019-02-13 17:38:41 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2019-04-16 16:20:46 +02:00
										 |  |  |     public function transactionGroup(): BelongsTo | 
					
						
							| 
									
										
										
										
											2019-02-13 17:38:41 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-03-23 08:10:59 +01:00
										 |  |  |         return $this->belongsTo(TransactionGroup::class); | 
					
						
							| 
									
										
										
										
											2019-02-13 17:38:41 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2016-09-09 11:19:40 +02:00
										 |  |  |      * @return HasMany | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-09-09 11:19:40 +02:00
										 |  |  |     public function transactionJournalMeta(): HasMany | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasMany(TransactionJournalMeta::class); | 
					
						
							| 
									
										
										
										
											2015-02-06 05:14:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-10 16:26:42 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @return BelongsTo | 
					
						
							| 
									
										
										
										
											2016-02-10 16:26:42 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |     public function transactionType(): BelongsTo | 
					
						
							| 
									
										
										
										
											2016-02-10 16:26:42 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->belongsTo(TransactionType::class); | 
					
						
							| 
									
										
										
										
											2016-02-10 16:26:42 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-11 07:35:10 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2017-06-05 11:12:50 +02:00
										 |  |  |      * @return HasMany | 
					
						
							| 
									
										
										
										
											2015-12-09 22:39:50 -02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-06-05 11:12:50 +02:00
										 |  |  |     public function transactions(): HasMany | 
					
						
							| 
									
										
										
										
											2015-12-09 22:39:50 -02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->hasMany(Transaction::class); | 
					
						
							| 
									
										
										
										
											2015-12-09 22:39:50 -02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-01-09 15:53:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-12-25 08:45:23 +01:00
										 |  |  |      * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |      * @return BelongsTo | 
					
						
							| 
									
										
										
										
											2016-01-09 15:53:11 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2018-08-04 17:30:06 +02:00
										 |  |  |     public function user(): BelongsTo | 
					
						
							| 
									
										
										
										
											2016-01-09 15:53:11 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-04-28 06:23:13 +02:00
										 |  |  |         return $this->belongsTo(User::class); | 
					
						
							| 
									
										
										
										
											2016-01-09 15:53:11 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-02-06 04:52:16 +01:00
										 |  |  | } |