35 lines
836 B
PHP
35 lines
836 B
PHP
<?php
|
|
|
|
namespace Modules\Expense\Entities;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class Expense extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
public function category() {
|
|
return $this->belongsTo(ExpenseCategory::class, 'category_id', 'id');
|
|
}
|
|
|
|
public function getDateAttribute($value) {
|
|
return Carbon::parse($value)->format('d M, Y');
|
|
}
|
|
|
|
public function setAmountAttribute($value) {
|
|
$this->attributes['amount'] = ($value * 100);
|
|
}
|
|
|
|
public function getAmountAttribute($value) {
|
|
return ($value / 100);
|
|
}
|
|
|
|
public function getReferenceAttribute($value) {
|
|
return strtoupper($value) . '_' . str_pad($this->attributes['id'], 6, '0', STR_PAD_LEFT );
|
|
}
|
|
}
|