add spatial plannings retribution calculations
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
@@ -44,11 +45,11 @@ class SpatialPlanning extends Model
|
||||
];
|
||||
|
||||
/**
|
||||
* Retribution calculation relationship (1:1)
|
||||
* Retribution proposals relationship (1:many)
|
||||
*/
|
||||
public function retributionCalculation(): HasOne
|
||||
public function retributionProposals(): HasMany
|
||||
{
|
||||
return $this->hasOne(RetributionCalculation::class);
|
||||
return $this->hasMany(RetributionProposal::class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,11 +61,27 @@ class SpatialPlanning extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if spatial planning has retribution calculation
|
||||
* Check if spatial planning has retribution proposals
|
||||
*/
|
||||
public function hasRetributionCalculation(): bool
|
||||
public function hasRetributionProposals(): bool
|
||||
{
|
||||
return $this->retributionCalculation()->exists();
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,18 +101,20 @@ class SpatialPlanning extends Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope: Without retribution calculation
|
||||
* Scope: Without retribution proposals
|
||||
*/
|
||||
public function scopeWithoutRetributionCalculation($query)
|
||||
public function scopeWithoutRetributionProposals($query)
|
||||
{
|
||||
return $query->whereDoesntHave('retributionCalculation');
|
||||
return $query->whereDoesntHave('retributionProposals');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope: With retribution calculation
|
||||
* Scope: With retribution proposals
|
||||
*/
|
||||
public function scopeWithRetributionCalculation($query)
|
||||
public function scopeWithRetributionProposals($query)
|
||||
{
|
||||
return $query->whereHas('retributionCalculation');
|
||||
return $query->whereHas('retributionProposals');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user