first commit
This commit is contained in:
84
app/Models/ServiceEntry.php
Normal file
84
app/Models/ServiceEntry.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\ServiceEntryFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable([
|
||||
'report_period_id',
|
||||
'service_catalog_id',
|
||||
'provider_department_id',
|
||||
'recipient_department_id',
|
||||
'quantity',
|
||||
'unit_price',
|
||||
])]
|
||||
class ServiceEntry extends Model
|
||||
{
|
||||
/** @use HasFactory<ServiceEntryFactory> */
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Get the period that owns the service entry.
|
||||
*
|
||||
* @return BelongsTo<ReportPeriod, $this>
|
||||
*/
|
||||
public function reportPeriod(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ReportPeriod::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the service definition for the entry.
|
||||
*
|
||||
* @return BelongsTo<ServiceCatalog, $this>
|
||||
*/
|
||||
public function serviceCatalog(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ServiceCatalog::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the provider department.
|
||||
*
|
||||
* @return BelongsTo<Department, $this>
|
||||
*/
|
||||
public function providerDepartment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'provider_department_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the recipient department.
|
||||
*
|
||||
* @return BelongsTo<Department, $this>
|
||||
*/
|
||||
public function recipientDepartment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Department::class, 'recipient_department_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total amount for the entry.
|
||||
*/
|
||||
public function totalAmount(): float
|
||||
{
|
||||
return round((float) $this->quantity * (float) $this->unit_price, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'quantity' => 'decimal:2',
|
||||
'unit_price' => 'decimal:2',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user