improved disable/delete with relationships
This commit is contained in:
@ -37,29 +37,6 @@ class Category extends Model
|
||||
return $this->hasMany('App\Models\Item\Item');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
if ($items = $this->items()->count()) {
|
||||
$error['items'] = $items;
|
||||
}
|
||||
|
||||
if ($payments = $this->payments()->count()) {
|
||||
$error['payments'] = $payments;
|
||||
}
|
||||
|
||||
if ($revenues = $this->revenues()->count()) {
|
||||
$error['revenues'] = $revenues;
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include categories of a given type.
|
||||
*
|
||||
|
@ -63,43 +63,4 @@ class Currency extends Model
|
||||
{
|
||||
$this->attributes['rate'] = (float) $value;
|
||||
}
|
||||
|
||||
public function canDisable()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
if ($this->code == setting('general.default_currency')) {
|
||||
$error['company'] = 1;
|
||||
}
|
||||
|
||||
if ($accounts = $this->accounts()->count()) {
|
||||
$error['accounts'] = $accounts;
|
||||
}
|
||||
|
||||
if ($customers = $this->customers()->count()) {
|
||||
$error['customers'] = $customers;
|
||||
}
|
||||
|
||||
if ($invoices = $this->invoices()->count()) {
|
||||
$error['invoices'] = $invoices;
|
||||
}
|
||||
|
||||
if ($revenues = $this->revenues()->count()) {
|
||||
$error['revenues'] = $revenues;
|
||||
}
|
||||
|
||||
if ($bills = $this->bills()->count()) {
|
||||
$error['bills'] = $bills;
|
||||
}
|
||||
|
||||
if ($payments = $this->payments()->count()) {
|
||||
$error['payments'] = $payments;
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -37,27 +37,4 @@ class Tax extends Model
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceItem');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
if ($items = $this->items()->count()) {
|
||||
$error['items'] = $items;
|
||||
}
|
||||
|
||||
if ($bills = $this->bill_items()->count()) {
|
||||
$error['bills'] = $bills;
|
||||
}
|
||||
|
||||
if ($invoices = $this->invoice_items()->count()) {
|
||||
$error['invoices'] = $invoices;
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user