product = $product; $this->template_id = $mail; $this->type = $type; } /** * Execute the job. * * @return void */ public function handle() { $setting = Setting::where('key','setting')->first(); $product = null; switch ($this->type) { case 3: $product = ModuleHosting::with('Customer')->find($this->product); break; case 4: $product = ModuleVmware::with('IpAddress','Customer')->find($this->product); break; } $data = [ 'company_name' => json_decode($setting->value)->company, 'company_logo' => json_decode($setting->value)->logo, 'client_name' => (string) $product->Customer->fullname, 'product_name' => $product->GetInvoiceItem()->GetItemProduct()->name, 'service_due_exp' => Carbon::parse($product->next_due_date)->format('d/m/Y'), 'service_remaining' => (int) Carbon::now()->diffInDays(Carbon::parse($product->next_due_date), false) + 1 ]; try { $email = new ExpiryService($this->template_id,$data); if (Mail::to($product->Customer->email)->send($email) === null) { return; } \App\Models\Mail::create([ 'template_id' => $this->template_id, 'subject' => $email->envelope()->subject, 'to' => $product->Customer->email, 'customer_id' => $product->Customer->id, 'message' => $email->render() ]); } catch (\Exception $exception) { throw new \Exception( $exception->getMessage()); } } public function failed(\Throwable $exception, Telegram $telegram) { Log::channel('Custom')->info("================================="); Log::channel('Custom')->info("Thông báo lỗi lúc: " .Carbon::now()); Log::channel('Custom')->info("Notification Send Expiry Product: "); Log::channel('Custom')->info("========"); Log::channel('Custom')->info($exception->getMessage()); Log::channel('Custom')->info("================================="); $telegram->SendErrorMessage(json_decode($exception->getMessage())); } }