69 lines
1.3 KiB
PHP
69 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Traits;
|
|
|
|
trait HasProjectionStatus
|
|
{
|
|
public function initializeHasProjectionStatus(): void
|
|
{
|
|
$this->fillable = array_merge($this->fillable ?? [], [
|
|
'is_projected',
|
|
]);
|
|
|
|
$this->casts = array_merge($this->casts ?? [], [
|
|
'is_projected' => 'boolean',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Scope to filter projected transactions
|
|
*/
|
|
public function scopeProjected($query)
|
|
{
|
|
return $query->where('is_projected', true);
|
|
}
|
|
|
|
/**
|
|
* Scope to filter actual transactions
|
|
*/
|
|
public function scopeActual($query)
|
|
{
|
|
return $query->where('is_projected', false);
|
|
}
|
|
|
|
/**
|
|
* Check if this transaction is projected
|
|
*/
|
|
public function isProjected(): bool
|
|
{
|
|
return $this->is_projected;
|
|
}
|
|
|
|
/**
|
|
* Check if this transaction is actual
|
|
*/
|
|
public function isActual(): bool
|
|
{
|
|
return ! $this->is_projected;
|
|
}
|
|
|
|
/**
|
|
* Mark transaction as projected
|
|
*/
|
|
public function markAsProjected(): self
|
|
{
|
|
$this->update(['is_projected' => true]);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Mark transaction as actual
|
|
*/
|
|
public function markAsActual(): self
|
|
{
|
|
$this->update(['is_projected' => false]);
|
|
|
|
return $this;
|
|
}
|
|
}
|