63 lines
1.6 KiB
PHP
63 lines
1.6 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');
|
|
}
|
|
|
|
public function addon()
|
|
{
|
|
return $this->belongsTo(Addon::class, 'addon_id');
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Helpers
|
|
// -------------------------------------------------------------------------
|
|
|
|
public function getBillingLabelAttribute(): string
|
|
{
|
|
return match ((int) $this->months) {
|
|
0 => 'Một lần',
|
|
1 => 'Hàng tháng',
|
|
3 => 'Hàng quý',
|
|
6 => 'Nửa năm',
|
|
12 => 'Hàng năm',
|
|
24 => '2 năm',
|
|
36 => '3 năm',
|
|
default => $this->months . ' tháng',
|
|
};
|
|
}
|
|
|
|
public function getTypeLabelAttribute(): string
|
|
{
|
|
return match ($this->type) {
|
|
'service' => 'Dịch vụ',
|
|
'addon' => 'Addon',
|
|
'upgrade' => 'Nâng cấp',
|
|
default => ucfirst($this->type),
|
|
};
|
|
}
|
|
}
|