Files
voltcerto/app/Models/CPE.php
Luis Medon e488ae3342 Add feature tests, unit tests, and configuration for Laravel application
- Created ExampleTest and RoutesTest for basic application response and route testing.
- Implemented IsolatedDatabaseTestCase for isolated database testing.
- Added unit tests for various models and services including Contract, CPE, and LeadDetail.
- Developed request validation tests for CreateClientRequest, UpdateClientRequest, and ContractRequest.
- Introduced Vite configuration for asset management in the Laravel application.
2026-10-29 11:30:06 +00:00

88 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CPE extends Model
{
use HasFactory;
protected $table = 'cpe';
protected $fillable = [
'client_id',
'pvp',
'net',
'power',
'tier',
'annual_consumption',
'contract_type_id',
'validity',
'activation_date',
'renewal_date',
'notes',
'payment_date',
'previous_supplier',
'status_id',
];
protected $dates = [
'validity',
'activation_date',
'renewal_date',
'payment_date',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'id'
];
public function client()
{
return $this->belongsTo(Clients::class, 'client_id');
}
public function contractType()
{
return $this->belongsTo(ContractType::class, 'contract_type_id');
}
public function status()
{
return $this->belongsTo(ContractStatus::class, 'status_id');
}
public function payments()
{
return $this->hasMany(CpePayment::class, 'cpe_id');
}
public function totalPaid()
{
return $this->payments()->where('status', 'paid')->sum('amount');
}
public function isPaid()
{
return $this->totalPaid() >= $this->pvp;
}
public function isCurrentRenewalPaid()
{
return $this->payments()
->where('reference_period', $this->renewal_date?->format('Y-m-d'))
->where('status', 'paid')
->exists();
}
}