diff --git a/app/Models/Expense/BillStatus.php b/app/Models/Expense/BillStatus.php index 57349a93b..b758c78f3 100644 --- a/app/Models/Expense/BillStatus.php +++ b/app/Models/Expense/BillStatus.php @@ -9,10 +9,40 @@ class BillStatus extends Model protected $table = 'bill_statuses'; + /** + * The accessors to append to the model's array form. + * + * @var array + */ + protected $appends = ['label']; + /** * Attributes that should be mass-assignable. * * @var array */ protected $fillable = ['company_id', 'name', 'code']; + + /** + * Get the status label. + * + * @return string + */ + public function getLabelAttribute() + { + switch ($this->code) { + case 'paid': + $label = 'label-success'; + break; + case 'partial': + case 'received': + $label = 'label-warning'; + break; + default: + $label = 'bg-aqua'; + break; + } + + return $label; + } } diff --git a/app/Models/Income/InvoiceStatus.php b/app/Models/Income/InvoiceStatus.php index e11365453..bbcbf3c0d 100644 --- a/app/Models/Income/InvoiceStatus.php +++ b/app/Models/Income/InvoiceStatus.php @@ -9,10 +9,40 @@ class InvoiceStatus extends Model protected $table = 'invoice_statuses'; + /** + * The accessors to append to the model's array form. + * + * @var array + */ + protected $appends = ['label']; + /** * Attributes that should be mass-assignable. * * @var array */ protected $fillable = ['company_id', 'name', 'code']; + + /** + * Get the status label. + * + * @return string + */ + public function getLabelAttribute() + { + switch ($this->code) { + case 'paid': + $label = 'label-success'; + break; + case 'partial': + case 'sent': + $label = 'label-warning'; + break; + default: + $label = 'bg-aqua'; + break; + } + + return $label; + } } diff --git a/resources/views/expenses/bills/index.blade.php b/resources/views/expenses/bills/index.blade.php index 751b73f03..f1936972a 100644 --- a/resources/views/expenses/bills/index.blade.php +++ b/resources/views/expenses/bills/index.blade.php @@ -45,26 +45,13 @@
@foreach($bills as $item) - @php - switch ($item->status->code) { - case 'paid': - $label = 'label-success'; - break; - case 'partial': - $label = 'label-warning'; - break; - default: - $label = 'bg-aqua'; - break; - } - @endphp