authorize('view', $customer); $this->authorize('view report', $customer->company); $type = $request->validated('type'); $statement = $this->customerStatementQuery->statement( $customer, $type, Carbon::createFromFormat('Y-m-d', $request->validated('from_date')), Carbon::createFromFormat('Y-m-d', $request->validated($type === CustomerStatementQuery::TYPE_OUTSTANDING ? 'as_of' : 'to_date')), PHP_INT_MAX, ); $pdf = $this->customerStatementPdfRenderer->render($statement); $this->mailConfigurator->applyCompanyConfig($customer->company_id); $mail = Mail::to($request->validated('to')); if ($request->filled('cc')) { $mail->cc($request->validated('cc')); } if ($request->filled('bcc')) { $mail->bcc($request->validated('bcc')); } $mail->send(new SendCustomerStatementMail([ ...$request->safe()->only(['to', 'cc', 'bcc', 'subject', 'body']), 'from' => config('mail.from.address'), 'from_name' => config('mail.from.name'), 'customer' => $customer, 'pdf' => $pdf, 'filename' => __('Customer Statement').' '.$customer->name.'.pdf', ])); return response()->json(['success' => true]); } }