first commit
This commit is contained in:
83
app/Models/Income/Customer.php
Normal file
83
app/Models/Income/Customer.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Sofa\Eloquence\Eloquence;
|
||||
|
||||
class Customer extends Model
|
||||
{
|
||||
use Eloquence;
|
||||
use Notifiable;
|
||||
|
||||
protected $table = 'customers';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'user_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 invoices()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function revenues()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\Revenue');
|
||||
}
|
||||
|
||||
public function currency()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Auth\User', 'customer_id', 'id');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
$invoices = $this->invoices();
|
||||
if ($invoices->count()) {
|
||||
$error['invoices'] = $invoices->count();
|
||||
}
|
||||
|
||||
$revenues = $this->revenues();
|
||||
if ($revenues->count()) {
|
||||
$error['revenues'] = $revenues->count();
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user