Premier commit
This commit is contained in:
60
app/Models/Contract.php
Normal file
60
app/Models/Contract.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Contract extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'reference',
|
||||
'provider',
|
||||
'status',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'amount',
|
||||
'currency',
|
||||
'notes',
|
||||
'type',
|
||||
'municipality_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
'amount' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function meta(): HasMany
|
||||
{
|
||||
return $this->hasMany(ContractMeta::class);
|
||||
}
|
||||
|
||||
public function documents(): HasMany
|
||||
{
|
||||
return $this->hasMany(Document::class);
|
||||
}
|
||||
|
||||
public function municipality(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Municipality::class);
|
||||
}
|
||||
|
||||
// Helpers
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('status', 'active');
|
||||
}
|
||||
|
||||
public function scopeExpiringSoon($query, $days = 30)
|
||||
{
|
||||
return $query->where('end_date', '<=', now()->addDays($days))
|
||||
->where('end_date', '>=', now())
|
||||
->where('status', '!=', 'expired');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user