mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Code cleanup.
This commit is contained in:
@@ -34,14 +34,15 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
/**
|
||||
* FireflyIII\Models\PiggyBankRepetition
|
||||
*
|
||||
* @property int $id
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property int $piggy_bank_id
|
||||
* @property Carbon|null $startdate
|
||||
* @property Carbon|null $targetdate
|
||||
* @property string $currentamount
|
||||
* @property-read PiggyBank $piggyBank
|
||||
* @property int $id
|
||||
* @property null|Carbon $created_at
|
||||
* @property null|Carbon $updated_at
|
||||
* @property int $piggy_bank_id
|
||||
* @property null|Carbon $startdate
|
||||
* @property null|Carbon $targetdate
|
||||
* @property string $currentamount
|
||||
* @property PiggyBank $piggyBank
|
||||
*
|
||||
* @method static EloquentBuilder|PiggyBankRepetition newModelQuery()
|
||||
* @method static EloquentBuilder|PiggyBankRepetition newQuery()
|
||||
* @method static EloquentBuilder|PiggyBankRepetition onDates(Carbon $start, Carbon $target)
|
||||
@@ -54,6 +55,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
* @method static EloquentBuilder|PiggyBankRepetition whereStartdate($value)
|
||||
* @method static EloquentBuilder|PiggyBankRepetition whereTargetdate($value)
|
||||
* @method static EloquentBuilder|PiggyBankRepetition whereUpdatedAt($value)
|
||||
*
|
||||
* @mixin Eloquent
|
||||
*/
|
||||
class PiggyBankRepetition extends Model
|
||||
@@ -70,32 +72,17 @@ class PiggyBankRepetition extends Model
|
||||
|
||||
protected $fillable = ['piggy_bank_id', 'startdate', 'targetdate', 'currentamount'];
|
||||
|
||||
/**
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function piggyBank(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PiggyBank::class);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param EloquentBuilder $query
|
||||
* @param Carbon $start
|
||||
* @param Carbon $target
|
||||
*
|
||||
* @return EloquentBuilder
|
||||
*/
|
||||
public function scopeOnDates(EloquentBuilder $query, Carbon $start, Carbon $target): EloquentBuilder
|
||||
{
|
||||
return $query->where('startdate', $start->format('Y-m-d'))->where('targetdate', $target->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param EloquentBuilder $query
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return EloquentBuilder
|
||||
*/
|
||||
public function scopeRelevantOnDate(EloquentBuilder $query, Carbon $date)
|
||||
@@ -106,16 +93,16 @@ class PiggyBankRepetition extends Model
|
||||
$q->orWhereNull('startdate');
|
||||
}
|
||||
)
|
||||
->where(
|
||||
static function (EloquentBuilder $q) use ($date) {
|
||||
$q->where('targetdate', '>=', $date->format('Y-m-d 00:00:00'));
|
||||
$q->orWhereNull('targetdate');
|
||||
}
|
||||
);
|
||||
->where(
|
||||
static function (EloquentBuilder $q) use ($date) {
|
||||
$q->where('targetdate', '>=', $date->format('Y-m-d 00:00:00'));
|
||||
$q->orWhereNull('targetdate');
|
||||
}
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setCurrentamountAttribute($value): void
|
||||
@@ -125,23 +112,18 @@ class PiggyBankRepetition extends Model
|
||||
|
||||
/**
|
||||
* Get the amount
|
||||
*
|
||||
* @return Attribute
|
||||
*/
|
||||
protected function currentamount(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: static fn($value) => (string)$value,
|
||||
get: static fn ($value) => (string)$value,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attribute
|
||||
*/
|
||||
protected function piggyBankId(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: static fn($value) => (int)$value,
|
||||
get: static fn ($value) => (int)$value,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user