Files
portal-api/app/Models/InvoiceItem.php
T

58 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class InvoiceItem extends Model
{
use HasFactory;
protected $table = 'invoice_items';
protected $guarded = [];
// -------------------------------------------------------------------------
// Relationships
// -------------------------------------------------------------------------
public function invoice()
{
return $this->belongsTo(Invoice::class, 'invoice_id');
}
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
public function getBillingLabelAttribute(): string
{
return match ((int) $this->months) {
0 => 'One Time',
1 => 'Monthly',
3 => 'Quarterly',
6 => 'Semi-Annually',
12 => 'Annually',
24 => '2 Years',
36 => '3 Years',
default => $this->months . ' Months',
};
}
public function getTypeLabelAttribute(): string
{
return match ($this->type) {
'service' => 'Dịch vụ',
'addon' => 'Addon',
'upgrade' => 'Nâng cấp',
default => ucfirst($this->type),
};
}
}