From cc89bcecd200c2ee5f46a7e09400cd845f01400f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 10 Mar 2024 10:13:00 +1100 Subject: [PATCH] allow plural for report names in scheduler --- app/Export/CSV/ClientExport.php | 2 +- app/Export/CSV/CreditExport.php | 2 +- app/Export/CSV/ExpenseExport.php | 2 +- app/Export/CSV/InvoiceExport.php | 2 +- app/Export/CSV/InvoiceItemExport.php | 2 +- app/Export/CSV/PurchaseOrderExport.php | 2 +- app/Export/CSV/PurchaseOrderItemExport.php | 2 +- app/Export/CSV/QuoteExport.php | 2 +- app/Export/CSV/QuoteItemExport.php | 2 +- app/Export/CSV/RecurringInvoiceExport.php | 2 +- app/Export/CSV/TaskExport.php | 2 +- app/Export/CSV/VendorExport.php | 2 +- .../TaskScheduler/StoreSchedulerRequest.php | 2 +- .../TaskScheduler/UpdateSchedulerRequest.php | 4 +- app/Jobs/Ninja/TaskScheduler.php | 1 + app/Services/Scheduler/EmailReport.php | 63 ++++++++++++------- 16 files changed, 55 insertions(+), 39 deletions(-) diff --git a/app/Export/CSV/ClientExport.php b/app/Export/CSV/ClientExport.php index 87171a8dc8e2..37928d44f351 100644 --- a/app/Export/CSV/ClientExport.php +++ b/app/Export/CSV/ClientExport.php @@ -127,7 +127,7 @@ class ClientExport extends BaseExport $query = Client::query()->with('contacts') ->withTrashed() ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/CreditExport.php b/app/Export/CSV/CreditExport.php index 9d2885c7d107..dc402741bd0e 100644 --- a/app/Export/CSV/CreditExport.php +++ b/app/Export/CSV/CreditExport.php @@ -103,7 +103,7 @@ class CreditExport extends BaseExport ->withTrashed() ->with('client') ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/ExpenseExport.php b/app/Export/CSV/ExpenseExport.php index 8713a4b2db69..07ba62c88a90 100644 --- a/app/Export/CSV/ExpenseExport.php +++ b/app/Export/CSV/ExpenseExport.php @@ -83,7 +83,7 @@ class ExpenseExport extends BaseExport ->with('client') ->withTrashed() ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/InvoiceExport.php b/app/Export/CSV/InvoiceExport.php index e7b08a7ec3ac..267ae158a14a 100644 --- a/app/Export/CSV/InvoiceExport.php +++ b/app/Export/CSV/InvoiceExport.php @@ -58,7 +58,7 @@ class InvoiceExport extends BaseExport ->withTrashed() ->with('client') ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/InvoiceItemExport.php b/app/Export/CSV/InvoiceItemExport.php index 791bfeddad17..19a976e828c5 100644 --- a/app/Export/CSV/InvoiceItemExport.php +++ b/app/Export/CSV/InvoiceItemExport.php @@ -71,7 +71,7 @@ class InvoiceItemExport extends BaseExport ->withTrashed() ->with('client') ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/PurchaseOrderExport.php b/app/Export/CSV/PurchaseOrderExport.php index 2a1a77956e44..3451bb7be88e 100644 --- a/app/Export/CSV/PurchaseOrderExport.php +++ b/app/Export/CSV/PurchaseOrderExport.php @@ -59,7 +59,7 @@ class PurchaseOrderExport extends BaseExport ->withTrashed() ->with('vendor') ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/PurchaseOrderItemExport.php b/app/Export/CSV/PurchaseOrderItemExport.php index 358af941509f..76107e04158c 100644 --- a/app/Export/CSV/PurchaseOrderItemExport.php +++ b/app/Export/CSV/PurchaseOrderItemExport.php @@ -63,7 +63,7 @@ class PurchaseOrderItemExport extends BaseExport $query = PurchaseOrder::query() ->withTrashed() ->with('vendor')->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/QuoteExport.php b/app/Export/CSV/QuoteExport.php index 195354419c67..a279d5a67b40 100644 --- a/app/Export/CSV/QuoteExport.php +++ b/app/Export/CSV/QuoteExport.php @@ -65,7 +65,7 @@ class QuoteExport extends BaseExport ->withTrashed() ->with('client') ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/QuoteItemExport.php b/app/Export/CSV/QuoteItemExport.php index e4be3a330bdd..566b811029d5 100644 --- a/app/Export/CSV/QuoteItemExport.php +++ b/app/Export/CSV/QuoteItemExport.php @@ -66,7 +66,7 @@ class QuoteItemExport extends BaseExport $query = Quote::query() ->withTrashed() ->with('client')->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/RecurringInvoiceExport.php b/app/Export/CSV/RecurringInvoiceExport.php index c56338c6b3e1..87afe6e7d90e 100644 --- a/app/Export/CSV/RecurringInvoiceExport.php +++ b/app/Export/CSV/RecurringInvoiceExport.php @@ -57,7 +57,7 @@ class RecurringInvoiceExport extends BaseExport ->withTrashed() ->with('client') ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/TaskExport.php b/app/Export/CSV/TaskExport.php index 861ea68bb6df..33685b5092c2 100644 --- a/app/Export/CSV/TaskExport.php +++ b/app/Export/CSV/TaskExport.php @@ -68,7 +68,7 @@ class TaskExport extends BaseExport $query = Task::query() ->withTrashed() ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Export/CSV/VendorExport.php b/app/Export/CSV/VendorExport.php index 86fef19f7336..5b328da387f3 100644 --- a/app/Export/CSV/VendorExport.php +++ b/app/Export/CSV/VendorExport.php @@ -62,7 +62,7 @@ class VendorExport extends BaseExport $query = Vendor::query()->with('contacts') ->withTrashed() ->where('company_id', $this->company->id) - ->where('is_deleted', $this->input['include_deleted']); + ->where('is_deleted', $this->input['include_deleted'] ?? false); $query = $this->addDateRange($query); diff --git a/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php b/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php index 158a9d37cf4e..579474c116a6 100644 --- a/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php +++ b/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php @@ -66,7 +66,7 @@ class StoreSchedulerRequest extends Request 'parameters.end_date' => ['bail', 'sometimes', 'date:Y-m-d', 'required_if:parameters.date_rate,custom', 'after_or_equal:parameters.start_date'], 'parameters.entity' => ['bail', 'sometimes', 'string', 'in:invoice,credit,quote,purchase_order'], 'parameters.entity_id' => ['bail', 'sometimes', 'string'], - 'parameters.report_name' => ['bail','sometimes', 'string', 'required_if:template,email_report','in:vendor,purchase_order_item,purchase_order,ar_detailed,ar_summary,client_balance,tax_summary,profitloss,client_sales,user_sales,product_sales,activity,client,contact,client_contact,credit,document,expense,invoice,invoice_item,quote,quote_item,recurring_invoice,payment,product,task'], + 'parameters.report_name' => ['bail','sometimes', 'string', 'required_if:template,email_report','in:vendor,purchase_order_item,purchase_order,ar_detailed,ar_summary,client_balance,tax_summary,profitloss,client_sales,user_sales,product_sales,activity,activities,client,clients,client_contact,client_contacts,credit,credits,document,documents,expense,expenses,invoice,invoices,invoice_item,invoice_items,quote,quotes,quote_item,quote_items,recurring_invoice,recurring_invoices,payment,payments,product,products,task,tasks'], 'parameters.date_key' => ['bail','sometimes', 'string'], 'parameters.status' => ['bail','sometimes', 'nullable', 'string'], ]; diff --git a/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php b/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php index 9a21d7183003..ef3843008fc2 100644 --- a/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php +++ b/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php @@ -66,9 +66,9 @@ class UpdateSchedulerRequest extends Request 'parameters.end_date' => ['bail', 'sometimes', 'date:Y-m-d', 'required_if:parameters.date_rate,custom', 'after_or_equal:parameters.start_date'], 'parameters.entity' => ['bail', 'sometimes', 'string', 'in:invoice,credit,quote,purchase_order'], 'parameters.entity_id' => ['bail', 'sometimes', 'string'], - 'parameters.report_name' => ['bail','sometimes', 'string', 'required_if:template,email_report','in:vendor,purchase_order_item,purchase_order,ar_detailed,ar_summary,client_balance,tax_summary,profitloss,client_sales,user_sales,product_sales,activity,client,contact,client_contact,credit,document,expense,invoice,invoice_item,quote,quote_item,recurring_invoice,payment,product,task'], + 'parameters.report_name' => ['bail','sometimes', 'string', 'required_if:template,email_report','in:vendor,purchase_order_item,purchase_order,ar_detailed,ar_summary,client_balance,tax_summary,profitloss,client_sales,user_sales,product_sales,activity,activities,client,clients,client_contact,client_contacts,credit,credits,document,documents,expense,expenses,invoice,invoices,invoice_item,invoice_items,quote,quotes,quote_item,quote_items,recurring_invoice,recurring_invoices,payment,payments,product,products,task,tasks'], 'parameters.date_key' => ['bail','sometimes', 'string'], - 'parameters.status' => ['bail','sometimes', 'string'], + 'parameters.status' => ['bail','sometimes', 'nullable', 'string'], ]; return $rules; diff --git a/app/Jobs/Ninja/TaskScheduler.php b/app/Jobs/Ninja/TaskScheduler.php index ff200ba0f2ba..84189f98f04e 100644 --- a/app/Jobs/Ninja/TaskScheduler.php +++ b/app/Jobs/Ninja/TaskScheduler.php @@ -60,6 +60,7 @@ class TaskScheduler implements ShouldQueue nlog("Doing job {$scheduler->name}"); try { + //@var \App\Models\Schedule $scheduler $scheduler->service()->runTask(); } catch(\Exception $e) { nlog($e->getMessage()); diff --git a/app/Services/Scheduler/EmailReport.php b/app/Services/Scheduler/EmailReport.php index 2351153bfff1..b4d5b0809321 100644 --- a/app/Services/Scheduler/EmailReport.php +++ b/app/Services/Scheduler/EmailReport.php @@ -11,34 +11,35 @@ namespace App\Services\Scheduler; -use App\Export\CSV\ClientExport; -use App\Export\CSV\ContactExport; -use App\Export\CSV\CreditExport; -use App\Export\CSV\DocumentExport; -use App\Export\CSV\ExpenseExport; -use App\Export\CSV\InvoiceExport; -use App\Export\CSV\InvoiceItemExport; -use App\Export\CSV\PaymentExport; -use App\Export\CSV\ProductExport; -use App\Export\CSV\ProductSalesExport; -use App\Export\CSV\QuoteExport; -use App\Export\CSV\QuoteItemExport; -use App\Export\CSV\RecurringInvoiceExport; -use App\Export\CSV\TaskExport; -use App\Jobs\Mail\NinjaMailerJob; -use App\Jobs\Mail\NinjaMailerObject; -use App\Mail\DownloadReport; use App\Models\Client; use App\Models\Scheduler; +use App\Mail\DownloadReport; +use App\Export\CSV\TaskExport; +use App\Export\CSV\QuoteExport; +use App\Utils\Traits\MakesHash; +use App\Export\CSV\ClientExport; +use App\Export\CSV\CreditExport; +use App\Utils\Traits\MakesDates; +use App\Export\CSV\ContactExport; +use App\Export\CSV\ExpenseExport; +use App\Export\CSV\InvoiceExport; +use App\Export\CSV\PaymentExport; +use App\Export\CSV\ProductExport; +use App\Jobs\Mail\NinjaMailerJob; +use App\Export\CSV\ActivityExport; +use App\Export\CSV\DocumentExport; +use App\Export\CSV\QuoteItemExport; +use App\Services\Report\ProfitLoss; +use App\Jobs\Mail\NinjaMailerObject; +use App\Export\CSV\InvoiceItemExport; +use App\Export\CSV\ProductSalesExport; use App\Services\Report\ARDetailReport; use App\Services\Report\ARSummaryReport; -use App\Services\Report\ClientBalanceReport; -use App\Services\Report\ClientSalesReport; -use App\Services\Report\ProfitLoss; -use App\Services\Report\TaxSummaryReport; use App\Services\Report\UserSalesReport; -use App\Utils\Traits\MakesDates; -use App\Utils\Traits\MakesHash; +use App\Services\Report\TaxSummaryReport; +use App\Export\CSV\RecurringInvoiceExport; +use App\Services\Report\ClientSalesReport; +use App\Services\Report\ClientBalanceReport; class EmailReport { @@ -77,19 +78,33 @@ class EmailReport 'client_sales' => $export = (new ClientSalesReport($this->scheduler->company, $data)), 'user_sales' => $export = (new UserSalesReport($this->scheduler->company, $data)), 'profitloss' => $export = (new ProfitLoss($this->scheduler->company, $data)), + 'activity' => $export = (new ActivityExport($this->scheduler->company, $data)), + 'activities' => $export = (new ActivityExport($this->scheduler->company, $data)), 'client' => $export = (new ClientExport($this->scheduler->company, $data)), + 'clients' => $export = (new ClientExport($this->scheduler->company, $data)), 'client_contact' => $export = (new ContactExport($this->scheduler->company, $data)), + 'client_contacts' => $export = (new ContactExport($this->scheduler->company, $data)), 'credit' => $export = (new CreditExport($this->scheduler->company, $data)), + 'credits' => $export = (new CreditExport($this->scheduler->company, $data)), 'document' => $export = (new DocumentExport($this->scheduler->company, $data)), + 'documents' => $export = (new DocumentExport($this->scheduler->company, $data)), 'expense' => $export = (new ExpenseExport($this->scheduler->company, $data)), + 'expenses' => $export = (new ExpenseExport($this->scheduler->company, $data)), 'invoice' => $export = (new InvoiceExport($this->scheduler->company, $data)), + 'invoices' => $export = (new InvoiceExport($this->scheduler->company, $data)), 'invoice_item' => $export = (new InvoiceItemExport($this->scheduler->company, $data)), + 'invoice_items' => $export = (new InvoiceItemExport($this->scheduler->company, $data)), 'quote' => $export = (new QuoteExport($this->scheduler->company, $data)), + 'quotes' => $export = (new QuoteExport($this->scheduler->company, $data)), 'quote_item' => $export = (new QuoteItemExport($this->scheduler->company, $data)), + 'quote_items' => $export = (new QuoteItemExport($this->scheduler->company, $data)), 'recurring_invoice' => $export = (new RecurringInvoiceExport($this->scheduler->company, $data)), + 'recurring_invoices' => $export = (new RecurringInvoiceExport($this->scheduler->company, $data)), 'payment' => $export = (new PaymentExport($this->scheduler->company, $data)), + 'payments' => $export = (new PaymentExport($this->scheduler->company, $data)), 'product' => $export = (new ProductExport($this->scheduler->company, $data)), - 'task' => $export = (new TaskExport($this->scheduler->company, $data)), + 'products' => $export = (new ProductExport($this->scheduler->company, $data)), + 'tasks' => $export = (new TaskExport($this->scheduler->company, $data)), default => $export = false, };