Refactor to support include deleted record logic for exports

This commit is contained in:
David Bomba 2024-05-29 09:05:42 +10:00
parent e967373f85
commit f8316f879a
13 changed files with 72 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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