From a6a13481fedcaabaf10781470c4104420596b2b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= <53110792+CihanSenturk@users.noreply.github.com> Date: Thu, 20 Jul 2023 15:44:03 +0300 Subject: [PATCH] added recurring scope to document models --- app/Models/Document/DocumentHistory.php | 16 ++++++++++++++++ app/Models/Document/DocumentItem.php | 16 ++++++++++++++++ app/Models/Document/DocumentItemTax.php | 16 ++++++++++++++++ app/Models/Document/DocumentTotal.php | 16 ++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/app/Models/Document/DocumentHistory.php b/app/Models/Document/DocumentHistory.php index ea9ac38c1..e00292e2b 100644 --- a/app/Models/Document/DocumentHistory.php +++ b/app/Models/Document/DocumentHistory.php @@ -30,8 +30,24 @@ class DocumentHistory extends Model return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE); } + public function scopeInvoiceRecurring(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_RECURRING_TYPE) + ->whereHas('document.recurring', function (Builder $query) { + $query->whereNull('deleted_at'); + }); + } + public function scopeBill(Builder $query) { return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE); } + + public function scopeBillRecurring(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), '=', Document::BILL_RECURRING_TYPE) + ->whereHas('document.recurring', function (Builder $query) { + $query->whereNull('deleted_at'); + }); + } } diff --git a/app/Models/Document/DocumentItem.php b/app/Models/Document/DocumentItem.php index ffaa3c7da..547247664 100644 --- a/app/Models/Document/DocumentItem.php +++ b/app/Models/Document/DocumentItem.php @@ -100,11 +100,27 @@ class DocumentItem extends Model return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE); } + public function scopeInvoiceRecurring(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_RECURRING_TYPE) + ->whereHas('document.recurring', function (Builder $query) { + $query->whereNull('deleted_at'); + }); + } + public function scopeBill(Builder $query) { return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE); } + public function scopeBillRecurring(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), '=', Document::BILL_RECURRING_TYPE) + ->whereHas('document.recurring', function (Builder $query) { + $query->whereNull('deleted_at'); + }); + } + public function getDiscountAttribute(): string { if (setting('localisation.percent_position', 'after') === 'after') { diff --git a/app/Models/Document/DocumentItemTax.php b/app/Models/Document/DocumentItemTax.php index 0594b087c..5e7b40e31 100644 --- a/app/Models/Document/DocumentItemTax.php +++ b/app/Models/Document/DocumentItemTax.php @@ -41,11 +41,27 @@ class DocumentItemTax extends Model return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE); } + public function scopeInvoiceRecurring(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_RECURRING_TYPE) + ->whereHas('document.recurring', function (Builder $query) { + $query->whereNull('deleted_at'); + }); + } + public function scopeBill(Builder $query) { return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE); } + public function scopeBillRecurring(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), '=', Document::BILL_RECURRING_TYPE) + ->whereHas('document.recurring', function (Builder $query) { + $query->whereNull('deleted_at'); + }); + } + public function onCloned($src) { $document_item = DocumentItem::find($this->document_item_id); diff --git a/app/Models/Document/DocumentTotal.php b/app/Models/Document/DocumentTotal.php index ea0f3e89d..ae3a8590b 100644 --- a/app/Models/Document/DocumentTotal.php +++ b/app/Models/Document/DocumentTotal.php @@ -33,11 +33,27 @@ class DocumentTotal extends Model return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_TYPE); } + public function scopeInvoiceRecurring(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), '=', Document::INVOICE_RECURRING_TYPE) + ->whereHas('document.recurring', function (Builder $query) { + $query->whereNull('deleted_at'); + }); + } + public function scopeBill(Builder $query) { return $query->where($this->qualifyColumn('type'), '=', Document::BILL_TYPE); } + public function scopeBillRecurring(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), '=', Document::BILL_RECURRING_TYPE) + ->whereHas('document.recurring', function (Builder $query) { + $query->whereNull('deleted_at'); + }); + } + public function scopeCode($query, $code) { return $query->where('code', '=', $code);