From f8316f879afe50cbf86fce660f0404c3f64b6080 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 29 May 2024 09:05:42 +1000 Subject: [PATCH] Refactor to support include deleted record logic for exports --- app/Export/CSV/ClientExport.php | 6 ++++-- app/Export/CSV/ExpenseExport.php | 8 ++++++-- app/Export/CSV/InvoiceExport.php | 7 +++++-- app/Export/CSV/InvoiceItemExport.php | 7 +++++-- app/Export/CSV/ProductExport.php | 8 ++++++-- app/Export/CSV/PurchaseOrderExport.php | 7 +++++-- app/Export/CSV/PurchaseOrderItemExport.php | 7 +++++-- app/Export/CSV/QuoteExport.php | 7 +++++-- app/Export/CSV/QuoteItemExport.php | 7 +++++-- app/Export/CSV/RecurringInvoiceExport.php | 7 +++++-- app/Export/CSV/TaskExport.php | 7 +++++-- app/Export/CSV/VendorExport.php | 7 +++++-- app/Http/Requests/Report/GenericReportRequest.php | 12 +++++++++++- 13 files changed, 72 insertions(+), 25 deletions(-) diff --git a/app/Export/CSV/ClientExport.php b/app/Export/CSV/ClientExport.php index 736b2285c098..fd5b35e97670 100644 --- a/app/Export/CSV/ClientExport.php +++ b/app/Export/CSV/ClientExport.php @@ -125,8 +125,10 @@ class ClientExport extends BaseExport $query = Client::query()->with('contacts') ->withTrashed() - ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->where('company_id', $this->company->id); + + if(!$this->input['include_deleted']) + $query->where('is_deleted', 0); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/ExpenseExport.php b/app/Export/CSV/ExpenseExport.php index fe1db16d1b2b..32cfa9b49ebf 100644 --- a/app/Export/CSV/ExpenseExport.php +++ b/app/Export/CSV/ExpenseExport.php @@ -82,8 +82,12 @@ class ExpenseExport extends BaseExport $query = Expense::query() ->with('client') ->withTrashed() - ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->where('company_id', $this->company->id); + + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Export/CSV/InvoiceExport.php b/app/Export/CSV/InvoiceExport.php index 5d9fd4442253..534a9a96978b 100644 --- a/app/Export/CSV/InvoiceExport.php +++ b/app/Export/CSV/InvoiceExport.php @@ -60,8 +60,11 @@ class InvoiceExport extends BaseExport ->whereHas('client', function ($q){ $q->where('is_deleted', false); }) - ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->where('company_id', $this->company->id); + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index fcc0470400da..1a621fec7de3 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -73,8 +73,11 @@ class InvoiceItemExport extends BaseExport ->whereHas('client', function ($q){ $q->where('is_deleted', false); }) - ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->where('company_id', $this->company->id); + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Export/CSV/ProductExport.php b/app/Export/CSV/ProductExport.php index b1ef871c2522..81fb42dcfbce 100644 --- a/app/Export/CSV/ProductExport.php +++ b/app/Export/CSV/ProductExport.php @@ -73,8 +73,12 @@ class ProductExport extends BaseExport $query = Product::query() ->withTrashed() - ->where('company_id', $this->company->id) - ->where('is_deleted', 0); + ->where('company_id', $this->company->id); + + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Export/CSV/PurchaseOrderExport.php b/app/Export/CSV/PurchaseOrderExport.php index ff092f3fbd3e..6dc38d175f6f 100644 --- a/app/Export/CSV/PurchaseOrderExport.php +++ b/app/Export/CSV/PurchaseOrderExport.php @@ -61,8 +61,11 @@ class PurchaseOrderExport extends BaseExport ->whereHas('vendor', function ($q){ $q->where('is_deleted', false); }) - ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->where('company_id', $this->company->id); + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Export/CSV/PurchaseOrderItemExport.php b/app/Export/CSV/PurchaseOrderItemExport.php index d7839448bcec..4ef9d4ce541a 100644 --- a/app/Export/CSV/PurchaseOrderItemExport.php +++ b/app/Export/CSV/PurchaseOrderItemExport.php @@ -65,8 +65,11 @@ class PurchaseOrderItemExport extends BaseExport ->whereHas('vendor', function ($q){ $q->where('is_deleted', false); }) - ->with('vendor')->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->with('vendor')->where('company_id', $this->company->id); + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Export/CSV/QuoteExport.php b/app/Export/CSV/QuoteExport.php index ceaafeffce6f..3110bcb87274 100644 --- a/app/Export/CSV/QuoteExport.php +++ b/app/Export/CSV/QuoteExport.php @@ -67,8 +67,11 @@ class QuoteExport extends BaseExport ->whereHas('client', function ($q){ $q->where('is_deleted', false); }) - ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->where('company_id', $this->company->id); + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Export/CSV/QuoteItemExport.php b/app/Export/CSV/QuoteItemExport.php index d3c004c1c201..af9e53cc1304 100644 --- a/app/Export/CSV/QuoteItemExport.php +++ b/app/Export/CSV/QuoteItemExport.php @@ -68,8 +68,11 @@ class QuoteItemExport extends BaseExport ->whereHas('client', function ($q){ $q->where('is_deleted', false); }) - ->with('client')->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->with('client')->where('company_id', $this->company->id); + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Export/CSV/RecurringInvoiceExport.php b/app/Export/CSV/RecurringInvoiceExport.php index df80d2d2a92b..74adf2424641 100644 --- a/app/Export/CSV/RecurringInvoiceExport.php +++ b/app/Export/CSV/RecurringInvoiceExport.php @@ -59,8 +59,11 @@ class RecurringInvoiceExport extends BaseExport ->whereHas('client', function ($q){ $q->where('is_deleted', false); }) - ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->where('company_id', $this->company->id); + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Export/CSV/TaskExport.php b/app/Export/CSV/TaskExport.php index 7830114f260a..f562f742fa2e 100644 --- a/app/Export/CSV/TaskExport.php +++ b/app/Export/CSV/TaskExport.php @@ -68,8 +68,11 @@ class TaskExport extends BaseExport $query = Task::query() ->withTrashed() - ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->where('company_id', $this->company->id); + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Export/CSV/VendorExport.php b/app/Export/CSV/VendorExport.php index 5037e4d43b7f..2bff1c34f7f2 100644 --- a/app/Export/CSV/VendorExport.php +++ b/app/Export/CSV/VendorExport.php @@ -62,8 +62,11 @@ class VendorExport extends BaseExport $query = Vendor::query()->with('contacts') ->withTrashed() - ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted'] ?? false); + ->where('company_id', $this->company->id); + + if(!$this->input['include_deleted']) { + $query->where('is_deleted', 0); + } $query = $this->addDateRange($query); diff --git a/app/Http/Requests/Report/GenericReportRequest.php b/app/Http/Requests/Report/GenericReportRequest.php index 7c8521a19305..03663c5df946 100644 --- a/app/Http/Requests/Report/GenericReportRequest.php +++ b/app/Http/Requests/Report/GenericReportRequest.php @@ -26,7 +26,8 @@ class GenericReportRequest extends Request */ public function authorize(): bool { - return $this->checkAuthority(); + return true; + // return $this->checkAuthority(); } public function rules() @@ -68,6 +69,15 @@ class GenericReportRequest extends Request $input['user_id'] = auth()->user()->id; + if(!$this->checkAuthority()){ + $input['date_range'] = ''; + $input['start_date'] = ''; + $input['end_date'] = ''; + $input['send_email'] = true; + $input['report_keys'] = []; + $input['document_email_attachment'] = false; + } + $this->replace($input); }