From 91907067a2d2d272bbf2451167e87c1272db3b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Fri, 10 Sep 2021 09:41:15 +0300 Subject: [PATCH] used qualifyColumn to prefix columns --- app/Abstracts/Model.php | 18 +++++++++--------- app/Models/Auth/User.php | 6 +++--- app/Models/Banking/Transaction.php | 6 +++--- app/Models/Common/Company.php | 6 +++--- app/Models/Common/Contact.php | 6 +++--- app/Models/Document/Document.php | 6 +++--- app/Models/Document/DocumentHistory.php | 6 +++--- app/Models/Document/DocumentItem.php | 6 +++--- app/Models/Document/DocumentItemTax.php | 6 +++--- app/Models/Document/DocumentTotal.php | 6 +++--- app/Models/Setting/Category.php | 10 +++++----- app/Models/Setting/Currency.php | 2 +- app/Models/Setting/Setting.php | 2 +- app/Models/Setting/Tax.php | 14 +++++++------- 14 files changed, 50 insertions(+), 50 deletions(-) diff --git a/app/Abstracts/Model.php b/app/Abstracts/Model.php index 47f751cf9..8cf32b4f3 100644 --- a/app/Abstracts/Model.php +++ b/app/Abstracts/Model.php @@ -103,7 +103,7 @@ abstract class Model extends Eloquent implements Ownable */ public function scopeCompanyId($query, $company_id) { - return $query->where($this->table . '.company_id', '=', $company_id); + return $query->where($this->getTable() . '.company_id', '=', $company_id); } /** @@ -177,7 +177,7 @@ abstract class Model extends Eloquent implements Ownable */ public function scopeEnabled($query) { - return $query->where($this->table . '.enabled', 1); + return $query->where($this->qualifyColumn('enabled'), 1); } /** @@ -188,7 +188,7 @@ abstract class Model extends Eloquent implements Ownable */ public function scopeDisabled($query) { - return $query->where($this->table . '.enabled', 0); + return $query->where($this->qualifyColumn('enabled'), 0); } /** @@ -200,7 +200,7 @@ abstract class Model extends Eloquent implements Ownable */ public function scopeReconciled($query, $value = 1) { - return $query->where($this->table . '.reconciled', $value); + return $query->where($this->qualifyColumn('reconciled'), $value); } public function scopeAccount($query, $accounts) @@ -209,7 +209,7 @@ abstract class Model extends Eloquent implements Ownable return $query; } - return $query->whereIn($this->table . '.account_id', (array) $accounts); + return $query->whereIn($this->qualifyColumn('account_id'), (array) $accounts); } public function scopeContact($query, $contacts) @@ -218,22 +218,22 @@ abstract class Model extends Eloquent implements Ownable return $query; } - return $query->whereIn($this->table . '.contact_id', (array) $contacts); + return $query->whereIn($this->qualifyColumn('contact_id'), (array) $contacts); } public function scopeSource($query, $source) { - return $query->where($this->table . '.created_from', $source); + return $query->where($this->qualifyColumn('created_from'), $source); } public function scopeIsOwner($query) { - return $query->where($this->table . '.created_by', user_id()); + return $query->where($this->qualifyColumn('created_by'), user_id()); } public function scopeIsNotOwner($query) { - return $query->where($this->table . '.created_by', '<>', user_id()); + return $query->where($this->qualifyColumn('created_by'), '<>', user_id()); } public function ownerKey($owner) diff --git a/app/Models/Auth/User.php b/app/Models/Auth/User.php index 40c161874..944453b20 100644 --- a/app/Models/Auth/User.php +++ b/app/Models/Auth/User.php @@ -262,17 +262,17 @@ class User extends Authenticatable implements HasLocalePreference public function scopeSource($query, $source) { - return $query->where($this->table . '.created_from', $source); + return $query->where($this->qualifyColumn('created_from'), $source); } public function scopeIsOwner($query) { - return $query->where($this->table . '.created_by', user_id()); + return $query->where($this->qualifyColumn('created_by'), user_id()); } public function scopeIsNotOwner($query) { - return $query->where($this->table . '.created_by', '<>', user_id()); + return $query->where($this->qualifyColumn('created_by'), '<>', user_id()); } public function ownerKey($owner) diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index d1b4cb50c..701747bf7 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -139,7 +139,7 @@ class Transaction extends Model return $query; } - return $query->whereIn($this->table . '.type', (array) $types); + return $query->whereIn($this->qualifyColumn('type'), (array) $types); } /** @@ -150,7 +150,7 @@ class Transaction extends Model */ public function scopeIncome($query) { - return $query->whereIn($this->table . '.type', (array) $this->getIncomeTypes()); + return $query->whereIn($this->qualifyColumn('type'), (array) $this->getIncomeTypes()); } /** @@ -161,7 +161,7 @@ class Transaction extends Model */ public function scopeExpense($query) { - return $query->whereIn($this->table . '.type', (array) $this->getExpenseTypes()); + return $query->whereIn($this->qualifyColumn('type'), (array) $this->getExpenseTypes()); } /** diff --git a/app/Models/Common/Company.php b/app/Models/Common/Company.php index fdabd77ac..700472c81 100644 --- a/app/Models/Common/Company.php +++ b/app/Models/Common/Company.php @@ -557,17 +557,17 @@ class Company extends Eloquent implements Ownable public function scopeSource($query, $source) { - return $query->where($this->table . '.created_from', $source); + return $query->where($this->qualifyColumn('created_from'), $source); } public function scopeIsOwner($query) { - return $query->where($this->table . '.created_by', user_id()); + return $query->where($this->qualifyColumn('created_by'), user_id()); } public function scopeIsNotOwner($query) { - return $query->where($this->table . '.created_by', '<>', user_id()); + return $query->where($this->qualifyColumn('created_by'), '<>', user_id()); } public function ownerKey($owner) diff --git a/app/Models/Common/Contact.php b/app/Models/Common/Contact.php index 7c99f2691..10116db44 100644 --- a/app/Models/Common/Contact.php +++ b/app/Models/Common/Contact.php @@ -133,7 +133,7 @@ class Contact extends Model return $query; } - return $query->whereIn($this->table . '.type', (array) $types); + return $query->whereIn($this->qualifyColumn('type'), (array) $types); } /** @@ -144,7 +144,7 @@ class Contact extends Model */ public function scopeVendor($query) { - return $query->whereIn($this->table . '.type', (array) $this->getVendorTypes()); + return $query->whereIn($this->qualifyColumn('type'), (array) $this->getVendorTypes()); } /** @@ -155,7 +155,7 @@ class Contact extends Model */ public function scopeCustomer($query) { - return $query->whereIn($this->table . '.type', (array) $this->getCustomerTypes()); + return $query->whereIn($this->qualifyColumn('type'), (array) $this->getCustomerTypes()); } public function scopeEmail($query, $email) diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index c7f4a17a9..c8570e3be 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -172,17 +172,17 @@ class Document extends Model public function scopeType(Builder $query, string $type) { - return $query->where($this->table . '.type', '=', $type); + return $query->where($this->qualifyColumn('type'), '=', $type); } public function scopeInvoice(Builder $query) { - return $query->where($this->table . '.type', '=', self::INVOICE_TYPE); + return $query->where($this->qualifyColumn('type'), '=', self::INVOICE_TYPE); } public function scopeBill(Builder $query) { - return $query->where($this->table . '.type', '=', self::BILL_TYPE); + return $query->where($this->qualifyColumn('type'), '=', self::BILL_TYPE); } /** diff --git a/app/Models/Document/DocumentHistory.php b/app/Models/Document/DocumentHistory.php index cfb49975d..e7245862c 100644 --- a/app/Models/Document/DocumentHistory.php +++ b/app/Models/Document/DocumentHistory.php @@ -22,16 +22,16 @@ class DocumentHistory extends Model public function scopeType(Builder $query, string $type) { - return $query->where($this->table . '.type', '=', $type); + return $query->where($this->qualifyColumn('type'), '=', $type); } public function scopeInvoice(Builder $query) { - return $query->where($this->table . '.type', '=', Document::INVOICE_TYPE); + return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE); } public function scopeBill(Builder $query) { - return $query->where($this->table . '.type', '=', Document::BILL_TYPE); + return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE); } } diff --git a/app/Models/Document/DocumentItem.php b/app/Models/Document/DocumentItem.php index 9ce1bf91b..dc681291f 100644 --- a/app/Models/Document/DocumentItem.php +++ b/app/Models/Document/DocumentItem.php @@ -78,17 +78,17 @@ class DocumentItem extends Model public function scopeType(Builder $query, string $type) { - return $query->where($this->table . '.type', '=', $type); + return $query->where($this->qualifyColumn('type'), '=', $type); } public function scopeInvoice(Builder $query) { - return $query->where($this->table . '.type', '=', Document::INVOICE_TYPE); + return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE); } public function scopeBill(Builder $query) { - return $query->where($this->table . '.type', '=', Document::BILL_TYPE); + return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE); } public function getDiscountAttribute(): string diff --git a/app/Models/Document/DocumentItemTax.php b/app/Models/Document/DocumentItemTax.php index cef7a5ccd..1db6aa2f8 100644 --- a/app/Models/Document/DocumentItemTax.php +++ b/app/Models/Document/DocumentItemTax.php @@ -41,16 +41,16 @@ class DocumentItemTax extends Model public function scopeType(Builder $query, string $type) { - return $query->where($this->table . '.type', '=', $type); + return $query->where($this->qualifyColumn('type'), '=', $type); } public function scopeInvoice(Builder $query) { - return $query->where($this->table . '.type', '=', Document::INVOICE_TYPE); + return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE); } public function scopeBill(Builder $query) { - return $query->where($this->table . '.type', '=', Document::BILL_TYPE); + return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE); } } diff --git a/app/Models/Document/DocumentTotal.php b/app/Models/Document/DocumentTotal.php index e6b0795ea..c6e2a4c18 100644 --- a/app/Models/Document/DocumentTotal.php +++ b/app/Models/Document/DocumentTotal.php @@ -34,17 +34,17 @@ class DocumentTotal extends Model public function scopeType(Builder $query, string $type) { - return $query->where($this->table . '.type', '=', $type); + return $query->where($this->qualifyColumn('type'), '=', $type); } public function scopeInvoice(Builder $query) { - return $query->where($this->table . '.type', '=', Document::INVOICE_TYPE); + return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE); } public function scopeBill(Builder $query) { - return $query->where($this->table . '.type', '=', Document::BILL_TYPE); + return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE); } public function scopeCode($query, $code) diff --git a/app/Models/Setting/Category.php b/app/Models/Setting/Category.php index 5f8b75c28..c708907ca 100644 --- a/app/Models/Setting/Category.php +++ b/app/Models/Setting/Category.php @@ -84,7 +84,7 @@ class Category extends Model return $query; } - return $query->whereIn($this->table . '.type', (array) $types); + return $query->whereIn($this->qualifyColumn('type'), (array) $types); } /** @@ -95,7 +95,7 @@ class Category extends Model */ public function scopeIncome($query) { - return $query->where($this->table . '.type', '=', 'income'); + return $query->where($this->qualifyColumn('type'), '=', 'income'); } /** @@ -106,7 +106,7 @@ class Category extends Model */ public function scopeExpense($query) { - return $query->where($this->table . '.type', '=', 'expense'); + return $query->where($this->qualifyColumn('type'), '=', 'expense'); } /** @@ -117,7 +117,7 @@ class Category extends Model */ public function scopeItem($query) { - return $query->where($this->table . '.type', '=', 'item'); + return $query->where($this->qualifyColumn('type'), '=', 'item'); } /** @@ -128,7 +128,7 @@ class Category extends Model */ public function scopeOther($query) { - return $query->where($this->table . '.type', '=', 'other'); + return $query->where($this->qualifyColumn('type'), '=', 'other'); } public function scopeName($query, $name) diff --git a/app/Models/Setting/Currency.php b/app/Models/Setting/Currency.php index 878c8c76b..c037bab3c 100644 --- a/app/Models/Setting/Currency.php +++ b/app/Models/Setting/Currency.php @@ -180,7 +180,7 @@ class Currency extends Model */ public function scopeCode($query, $code) { - return $query->where($this->table . '.code', $code); + return $query->where($this->qualifyColumn('code'), $code); } /** diff --git a/app/Models/Setting/Setting.php b/app/Models/Setting/Setting.php index 63be4e078..4bec01b31 100644 --- a/app/Models/Setting/Setting.php +++ b/app/Models/Setting/Setting.php @@ -77,6 +77,6 @@ class Setting extends Eloquent */ public function scopeCompanyId($query, $company_id) { - return $query->where($this->table . '.company_id', '=', $company_id); + return $query->where($this->qualifyColumn('company_id'), '=', $company_id); } } diff --git a/app/Models/Setting/Tax.php b/app/Models/Setting/Tax.php index 627f19c66..2a341120a 100644 --- a/app/Models/Setting/Tax.php +++ b/app/Models/Setting/Tax.php @@ -84,37 +84,37 @@ class Tax extends Model return $query; } - return $query->whereIn($this->table . '.type', (array) $types); + return $query->whereIn($this->qualifyColumn('type'), (array) $types); } public function scopeFixed($query) { - return $query->where($this->table . '.type', '=', 'fixed'); + return $query->where($this->qualifyColumn('type'), '=', 'fixed'); } public function scopeNormal($query) { - return $query->where($this->table . '.type', '=', 'normal'); + return $query->where($this->qualifyColumn('type'), '=', 'normal'); } public function scopeInclusive($query) { - return $query->where($this->table . '.type', '=', 'inclusive'); + return $query->where($this->qualifyColumn('type'), '=', 'inclusive'); } public function scopeCompound($query) { - return $query->where($this->table . '.type', '=', 'compound'); + return $query->where($this->qualifyColumn('type'), '=', 'compound'); } public function scopeWithholding($query) { - return $query->where($this->table . '.type', '=', 'withholding'); + return $query->where($this->qualifyColumn('type'), '=', 'withholding'); } public function scopeNotWithholding($query) { - return $query->where($this->table . '.type', '<>', 'withholding'); + return $query->where($this->qualifyColumn('type'), '<>', 'withholding'); } /**