improved disable/delete with relationships
This commit is contained in:
@ -81,33 +81,6 @@ class Account extends Model
|
||||
$this->attributes['opening_balance'] = (float) $value;
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
if ($bill_payments = $this->bill_payments()->count()) {
|
||||
$error['bills'] = $bill_payments;
|
||||
}
|
||||
|
||||
if ($payments = $this->payments()->count()) {
|
||||
$error['payments'] = $payments;
|
||||
}
|
||||
|
||||
if ($invoice_payments = $this->invoice_payments()->count()) {
|
||||
$error['invoices'] = $invoice_payments;
|
||||
}
|
||||
|
||||
if ($revenues = $this->revenues()->count()) {
|
||||
$error['revenues'] = $revenues;
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current balance.
|
||||
*
|
||||
|
@ -52,23 +52,4 @@ class Vendor extends Model
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
if ($bills = $this->bills()->count()) {
|
||||
$error['bills'] = $bills;
|
||||
}
|
||||
|
||||
if ($payments = $this->payments()->count()) {
|
||||
$error['payments'] = $payments;
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -59,23 +59,4 @@ class Customer extends Model
|
||||
{
|
||||
return $this->belongsTo('App\Models\Auth\User', 'customer_id', 'id');
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
if ($invoices = $this->invoices()->count()) {
|
||||
$error['invoices'] = $invoices;
|
||||
}
|
||||
|
||||
if ($revenues = $this->revenues()->count()) {
|
||||
$error['revenues'] = $revenues;
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -81,25 +81,6 @@ class Item extends Model
|
||||
$this->attributes['purchase_price'] = (float) $value;
|
||||
}
|
||||
|
||||
public function canDelete()
|
||||
{
|
||||
$error = false;
|
||||
|
||||
if ($bills = $this->bill_items()->count()) {
|
||||
$error['bills'] = $bills;
|
||||
}
|
||||
|
||||
if ($invoices = $this->invoice_items()->count()) {
|
||||
$error['invoices'] = $invoices;
|
||||
}
|
||||
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getItems($filter_data = array())
|
||||
{
|
||||
if (empty($filter_data)) {
|
||||
|
@ -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