improved disable/delete with relationships

This commit is contained in:
denisdulici
2017-10-16 10:51:43 +03:00
parent ae52ce5a43
commit b1b36d8a64
16 changed files with 131 additions and 311 deletions

View File

@ -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.
*

View File

@ -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;
}
}

View File

@ -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;
}
}