akaunting/app/Models/Income/Revenue.php

101 lines
2.2 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Models\Income;
use App\Models\Model;
use App\Traits\Currencies;
use App\Traits\DateTime;
2017-11-26 15:20:17 +03:00
use Bkwld\Cloner\Cloneable;
2017-09-14 22:21:00 +03:00
use Sofa\Eloquence\Eloquence;
class Revenue extends Model
{
2017-11-26 15:20:17 +03:00
use Cloneable, Currencies, DateTime, Eloquence;
2017-09-14 22:21:00 +03:00
protected $table = 'revenues';
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'account_id', 'paid_at', 'amount', 'currency_code', 'currency_rate', 'customer_id', 'description', 'category_id', 'payment_method', 'reference', 'attachment'];
/**
* Sortable columns.
*
* @var array
*/
public $sortable = ['paid_at', 'amount','category_id', 'account', 'payment_method'];
/**
* Searchable rules.
*
* @var array
*/
protected $searchableColumns = [
'invoice_number' => 10,
'order_number' => 10,
'customer_name' => 10,
'customer_email' => 5,
'notes' => 2,
];
public function user()
{
return $this->belongsTo('App\Models\Auth\User', 'customer_id', 'id');
}
public function account()
{
return $this->belongsTo('App\Models\Banking\Account');
}
public function currency()
{
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
}
public function category()
{
return $this->belongsTo('App\Models\Setting\Category');
}
public function customer()
{
return $this->belongsTo('App\Models\Income\Customer');
}
public function transfers()
{
return $this->hasMany('App\Models\Banking\Transfer');
}
2017-10-04 01:25:03 +03:00
/**
2017-10-21 14:23:57 +03:00
* Convert amount to double.
2017-10-04 01:25:03 +03:00
*
* @param string $value
* @return void
*/
public function setAmountAttribute($value)
{
2017-10-21 14:23:57 +03:00
$this->attributes['amount'] = (double) $value;
2017-10-04 01:25:03 +03:00
}
/**
2017-10-21 14:23:57 +03:00
* Convert currency rate to double.
2017-10-04 01:25:03 +03:00
*
* @param string $value
* @return void
*/
public function setCurrencyRateAttribute($value)
{
2017-10-21 14:23:57 +03:00
$this->attributes['currency_rate'] = (double) $value;
2017-10-04 01:25:03 +03:00
}
2017-09-14 22:21:00 +03:00
public function scopeLatest($query)
{
return $query->orderBy('paid_at', 'desc');
}
}