mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 19:51:09 -04:00
init crater
This commit is contained in:
39
app/ExpenseCategory.php
Normal file
39
app/ExpenseCategory.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace Laraspace;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Laraspace\Expense;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ExpenseCategory extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'company_id', 'description'];
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['amount', 'formattedCreatedAt'];
|
||||
|
||||
public function expenses()
|
||||
{
|
||||
return $this->hasMany(Expense::class);
|
||||
}
|
||||
|
||||
public function getFormattedCreatedAtAttribute($value)
|
||||
{
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $this->company_id);
|
||||
return Carbon::parse($this->created_at)->format($dateFormat);
|
||||
}
|
||||
|
||||
public function getAmountAttribute()
|
||||
{
|
||||
return $this->expenses()->sum('amount');
|
||||
}
|
||||
|
||||
public function scopeWhereCompany($query, $company_id)
|
||||
{
|
||||
$query->where('company_id', $company_id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user