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);