Files
firefly-iii/app/Models/AutoBudget.php

77 lines
2.1 KiB
PHP
Raw Normal View History

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);
namespace FireflyIII\Models;
2020-03-13 21:15:21 +01:00
2023-11-05 19:41:37 +01:00
use FireflyIII\Support\Models\ReturnsIntegerIdTrait;
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;
2024-07-31 08:26:43 +02:00
/**
* @mixin IdeHelperAutoBudget
*/
2020-03-13 21:15:21 +01:00
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
2023-12-02 12:56:48 +01:00
public const int AUTO_BUDGET_ADJUSTED = 3;
public const int AUTO_BUDGET_RESET = 1;
public const int AUTO_BUDGET_ROLLOVER = 2;
protected $fillable = ['budget_id', 'amount', 'period'];
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);
}
public function transactionCurrency(): BelongsTo
{
return $this->belongsTo(TransactionCurrency::class);
}
protected function amount(): Attribute
{
return Attribute::make(
2023-12-20 19:35:52 +01:00
get: static fn ($value) => (string)$value,
);
}
2023-11-05 19:41:37 +01:00
protected function budgetId(): Attribute
{
return Attribute::make(
2023-12-20 19:35:52 +01:00
get: static fn ($value) => (int)$value,
2023-11-05 19:41:37 +01:00
);
}
protected function transactionCurrencyId(): Attribute
{
return Attribute::make(
2023-12-20 19:35:52 +01:00
get: static fn ($value) => (int)$value,
2023-11-05 19:41:37 +01:00
);
}
2020-03-13 21:15:21 +01:00
}