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

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