hour = date('H',time()); // $this->hour = '08'; $from_date = Carbon::now()->startOfMonth()->toDateString(); $to_date = Carbon::now()->toDateString(); // ------------------- Morning merchants MIS reports ------------------ if($this->hour == $this->morning){ $merchants = Merchant::whereNull('deleted_at')->where('mis_frequency','>',0)->where('status','active')->where('pre_status',0)->where('is_guest_active',1)->where('email','!=',null)->get()->toArray(); if($merchants != null ){ foreach($merchants as $merchant){ try{ $payload = array("queue"=>true); $payload['from_date'] = $from_date; $payload['merchant_id'] = $merchant['id']; $payload['to_date'] = $to_date; $mer_email = wall_decrypt($merchant['email']); $emails = null; if($mer_email != null){ $mer_emails = explode(",", $mer_email); $emails = $mer_emails; } $rcp_email = $merchant['rcp_email']; if($rcp_email != null){ $rcp_emails = explode(",", $rcp_email); $emails = $rcp_emails; } if($mer_email != null && $rcp_email != null){ $emails = array_merge($mer_emails,$rcp_emails); } $payload['auth_email'] = $emails; $payload['is_daily']=true; $payload['name'] = $merchant['merchant_name']; $response = new MerchantController(); $flag = $response->getMISReport($merchant['id'], (new Request($payload))); if(!$flag){ $error_ids[] = $merchant['merchant_name']; }else{ $sended_ids[] = $merchant['merchant_name']; } }catch(\Exception $e){ $error_ids[] = $merchant['merchant_name']; unset($payload); continue; } } if(isset($error_ids)){ $error_names = implode("\n",$error_ids); (new Slack(new Request(['title' => 'Mis sending error', 'fields' => ['names' => $error_names]])))->send(); }else{ (new Slack(new Request(['title' => 'All Mis sent successfully', 'fields' => []])))->send(); } }else{ (new Slack(new Request(['title' => 'No merchants to send mis', 'fields' => []])))->send(); } } //------------------- Evening Merchant MIS reports ---------------------------- if($this->hour == $this->evening){ $merchants = Merchant::whereNull('deleted_at')->where('mis_frequency',2)->where('status','active')->where('pre_status',0)->where('is_guest_active',1)->where('email','!=',null)->get()->toArray(); if($merchants != null ){ foreach($merchants as $merchant){ try{ $payload = array("queue"=>true); $payload['from_date'] = $from_date; $payload['merchant_id'] = $merchant['id']; $payload['to_date'] = $to_date; $mer_email = wall_decrypt($merchant['email']); $emails = null; if($mer_email != null){ $mer_emails = explode(",", $mer_email); $emails = $mer_emails; } $rcp_email = $merchant['rcp_email']; if($rcp_email != null){ $rcp_emails = explode(",", $rcp_email); $emails = $rcp_emails; } if($mer_email != null && $rcp_email != null){ $emails = array_merge($mer_emails,$rcp_emails); } $payload['auth_email'] = $emails; $payload['is_daily']=true; $payload['name'] = $merchant['merchant_name']; $response = new MerchantController(); $flag = $response->getMISReport($merchant['id'], (new Request($payload))); if(!$flag){ $error_ids[] = $merchant['merchant_name']; }else{ $sended_ids[] = $merchant['merchant_name']; } }catch(\Exception $e){ $error_ids[] = $merchant['merchant_name']; unset($payload); continue; } } if(isset($error_ids)){ $error_names = implode("\n",$error_ids); (new Slack(new Request(['title' => 'Mis sending error', 'fields' => ['names' => $error_names]])))->send(); }else{ (new Slack(new Request(['title' => 'All Mis sent successfully', 'fields' => []])))->send(); } }else{ (new Slack(new Request(['title' => 'No merchants to send mis', 'fields' => []])))->send(); } } } }