calculateStartAndEndDates($this->scheduler->parameters); $data = $this->scheduler->parameters; $data['start_date'] = $start_end_dates[0]; $data['end_date'] = $start_end_dates[1]; $data['date_range'] = $data['date_range'] ?? 'all'; $data['report_keys'] = $data['report_keys'] ?? []; $export = false; match($this->scheduler->parameters['report_name']) { 'product_sales' => $export = (new ProductSalesExport($this->scheduler->company, $data)), 'ar_detailed' => $export = (new ARDetailReport($this->scheduler->company, $data)), 'ar_summary' => $export = (new ARSummaryReport($this->scheduler->company, $data)), 'tax_summary' => $export = (new TaxSummaryReport($this->scheduler->company, $data)), 'client_balance' => $export = (new ClientBalanceReport($this->scheduler->company, $data)), '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)), 'client' => $export = (new ClientExport($this->scheduler->company, $data)), 'client_contact' => $export = (new ContactExport($this->scheduler->company, $data)), 'credit' => $export = (new CreditExport($this->scheduler->company, $data)), 'document' => $export = (new DocumentExport($this->scheduler->company, $data)), 'expense' => $export = (new ExpenseExport($this->scheduler->company, $data)), 'invoice' => $export = (new InvoiceExport($this->scheduler->company, $data)), 'invoice_item' => $export = (new InvoiceItemExport($this->scheduler->company, $data)), 'quote' => $export = (new QuoteExport($this->scheduler->company, $data)), 'quote_item' => $export = (new QuoteItemExport($this->scheduler->company, $data)), 'recurring_invoice' => $export = (new RecurringInvoiceExport($this->scheduler->company, $data)), 'payment' => $export = (new PaymentExport($this->scheduler->company, $data)), 'product' => $export = (new ProductExport($this->scheduler->company, $data)), 'task' => $export = (new TaskExport($this->scheduler->company, $data)), default => $export = false, }; if(!$export) { $this->cancelSchedule(); return; } $csv = $export->run(); //todo - potentially we send this to more than one user. $nmo = new NinjaMailerObject(); $nmo->mailable = new DownloadReport($this->scheduler->company, $csv, $this->file_name); $nmo->company = $this->scheduler->company; $nmo->settings = $this->scheduler->company->settings; $nmo->to_user = $this->scheduler->user; NinjaMailerJob::dispatch($nmo); //calculate next run dates; $this->scheduler->calculateNextRun(); } private function cancelSchedule() { $this->scheduler->forceDelete(); } }