done restructure calculation retribution
This commit is contained in:
@@ -2,10 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\HasRetributionCalculation;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
|
||||
/**
|
||||
* Class SpatialPlanning
|
||||
@@ -26,6 +25,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
*/
|
||||
class SpatialPlanning extends Model
|
||||
{
|
||||
use HasRetributionCalculation;
|
||||
|
||||
protected $perPage = 20;
|
||||
|
||||
@@ -44,45 +44,7 @@ class SpatialPlanning extends Model
|
||||
'date' => 'date'
|
||||
];
|
||||
|
||||
/**
|
||||
* Retribution proposals relationship (1:many)
|
||||
*/
|
||||
public function retributionProposals(): HasMany
|
||||
{
|
||||
return $this->hasMany(RetributionProposal::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Building function relationship (if building_function becomes FK in future)
|
||||
*/
|
||||
public function buildingFunctionRelation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(BuildingFunction::class, 'building_function_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if spatial planning has retribution proposals
|
||||
*/
|
||||
public function hasRetributionProposals(): bool
|
||||
{
|
||||
return $this->retributionProposals()->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest retribution proposal
|
||||
*/
|
||||
public function getLatestRetributionProposal()
|
||||
{
|
||||
return $this->retributionProposals()->latest()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all retribution proposals
|
||||
*/
|
||||
public function getAllRetributionProposals()
|
||||
{
|
||||
return $this->retributionProposals()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get building function text for detection
|
||||
@@ -100,21 +62,7 @@ class SpatialPlanning extends Model
|
||||
return (float) ($this->area ?? $this->land_area ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope: Without retribution proposals
|
||||
*/
|
||||
public function scopeWithoutRetributionProposals($query)
|
||||
{
|
||||
return $query->whereDoesntHave('retributionProposals');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope: With retribution proposals
|
||||
*/
|
||||
public function scopeWithRetributionProposals($query)
|
||||
{
|
||||
return $query->whereHas('retributionProposals');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user