75 lines
1.4 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Models\Expense;
use App\Models\Model;
use Sofa\Eloquence\Eloquence;
class Vendor extends Model
{
use Eloquence;
protected $table = 'vendors';
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'name', 'email', 'tax_number', 'phone', 'address', 'website', 'currency_code', 'enabled'];
/**
* Sortable columns.
*
* @var array
*/
public $sortable = ['name', 'email', 'phone', 'enabled'];
/**
* Searchable rules.
*
* @var array
*/
protected $searchableColumns = [
'name' => 10,
'email' => 5,
'phone' => 2,
'website' => 2,
'address' => 1,
];
public function bills()
{
return $this->hasMany('App\Models\Expense\Bill');
}
public function payments()
{
return $this->hasMany('App\Models\Expense\Payments');
}
public function currency()
{
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
}
public function canDelete()
{
$error = false;
2017-09-26 01:05:21 +03:00
if ($bills = $this->bills()->count()) {
$error['bills'] = $bills;
2017-09-14 22:21:00 +03:00
}
2017-09-26 01:05:21 +03:00
if ($payments = $this->payments()->count()) {
$error['payments'] = $payments;
2017-09-14 22:21:00 +03:00
}
if ($error) {
return $error;
}
return true;
}
}