| 
									
										
										
										
											2020-03-13 21:15:21 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2020-06-30 19:05:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:21 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * AutoBudget.php | 
					
						
							| 
									
										
										
										
											2020-06-30 19:05:35 +02:00
										 |  |  |  * Copyright (c) 2020 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:21 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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/>. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 19:05:35 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-14 07:01:31 +01:00
										 |  |  | namespace FireflyIII\Models; | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  | use FireflyIII\Support\Models\ReturnsIntegerIdTrait; | 
					
						
							| 
									
										
										
										
											2023-01-01 13:55:14 +01:00
										 |  |  | use Illuminate\Database\Eloquent\Casts\Attribute; | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:21 +01:00
										 |  |  | use Illuminate\Database\Eloquent\Model; | 
					
						
							| 
									
										
										
										
											2020-03-13 21:35:22 +01:00
										 |  |  | use Illuminate\Database\Eloquent\Relations\BelongsTo; | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:21 +01:00
										 |  |  | use Illuminate\Database\Eloquent\SoftDeletes; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AutoBudget extends Model | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  |     use ReturnsIntegerIdTrait; | 
					
						
							| 
									
										
										
										
											2022-10-30 14:24:28 +01:00
										 |  |  |     use SoftDeletes; | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-29 06:32:50 +01:00
										 |  |  |     #[\Deprecated] /** @deprecated  */
 | 
					
						
							| 
									
										
										
										
											2023-12-02 12:56:48 +01:00
										 |  |  |     public const int AUTO_BUDGET_ADJUSTED = 3; | 
					
						
							| 
									
										
										
										
											2024-11-07 03:36:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-29 06:32:50 +01:00
										 |  |  |     #[\Deprecated] /** @deprecated  */
 | 
					
						
							| 
									
										
										
										
											2023-12-02 12:56:48 +01:00
										 |  |  |     public const int AUTO_BUDGET_RESET    = 1; | 
					
						
							| 
									
										
										
										
											2024-11-07 03:36:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-29 06:32:50 +01:00
										 |  |  |     #[\Deprecated] /** @deprecated  */
 | 
					
						
							| 
									
										
										
										
											2023-12-02 12:56:48 +01:00
										 |  |  |     public const int AUTO_BUDGET_ROLLOVER = 2; | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |     protected $casts | 
					
						
							|  |  |  |                                           = [ | 
					
						
							| 
									
										
										
										
											2024-12-30 04:12:18 +01:00
										 |  |  |             'amount'        => 'string', | 
					
						
							| 
									
										
										
										
											2024-12-29 06:32:50 +01:00
										 |  |  |             'native_amount' => 'string', | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2024-12-30 04:12:18 +01:00
										 |  |  |     protected $fillable                   = ['budget_id', 'amount', 'period', 'native_amount']; | 
					
						
							| 
									
										
										
										
											2023-05-07 20:17:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 21:35:22 +01:00
										 |  |  |     public function budget(): BelongsTo | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->belongsTo(Budget::class); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-14 07:01:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function transactionCurrency(): BelongsTo | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->belongsTo(TransactionCurrency::class); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-01-01 13:55:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     protected function amount(): Attribute | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return Attribute::make( | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |             get: static fn ($value) => (string) $value, | 
					
						
							| 
									
										
										
										
											2023-01-01 13:55:14 +01:00
										 |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     protected function budgetId(): Attribute | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return Attribute::make( | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |             get: static fn ($value) => (int) $value, | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |     protected function casts(): array | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return [ | 
					
						
							|  |  |  |             // 'auto_budget_type' => AutoBudgetType::class,
 | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  |     protected function transactionCurrencyId(): Attribute | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return Attribute::make( | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |             get: static fn ($value) => (int) $value, | 
					
						
							| 
									
										
										
										
											2023-11-05 19:41:37 +01:00
										 |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-13 21:15:21 +01:00
										 |  |  | } |