app/Console/Commands/sendEmailAndSmsReminder.php
/**
     * Execute the console command.
     *
     * @return mixed
     */
Execute the console command.
@return mixed
Execute the console command . @return mixed
public function handle(){
        $current = Carbon::now();
        $future_date = $current->addDays(3);
        $incomplete_tasks = ClientTask::where([['status','=','incomplete'],['assigned_date','<=',$future_date]])->get();
        $incomplete_task_unique_users = $incomplete_tasks->unique('client_id');
        foreach ($incomplete_task_unique_users as $incomplete_task_unique_user_single){
            $user_client = User::find($incomplete_task_unique_user_single->client_id);
            $user_assignee = User::find($incomplete_task_unique_user_single->assignee_id);
            foreach ($incomplete_tasks as $a_single_task){
                if ($a_single_task->client_id == $incomplete_task_unique_user_single->client_id ){
                    $carbon_assigned_date = Carbon::now();
                    $assigned_date = new \DateTime($a_single_task->assigned_date);
                    $diff = $carbon_assigned_date->diffInDays($assigned_date);
                    $task_of_single_user_deadline = array();
                    $task_of_single_user_reminder = array();
                    if ( $diff<=0){
                        $single_user_task_full_info_deadline = ClientTask::find($a_single_task->task_id);
                        $task_of_single_user_deadline[] = $single_user_task_full_info_deadline->taskName->task_name;
                    }
                    if ( $diff>=2  && $diff <=3){
                        $single_user_task_name = ClientTask::find($a_single_task->task_id);
                        $task_of_single_user_reminder[] = $single_user_task_name->taskName->task_name;
                    }
                    $task_of_single_user[] = $task1->task_id;
                }
            }
            $data_of_single_client = [
                'name'              => $user_client->name,
                'email'             => $user_client->email,
                'mobile'            => $user_client->mobile,
                'assignee_role'     => $user_assignee->user_role,
                'assignee_email'    => $user_assignee->email,
                'assignee_mobile'   => $user_assignee->mobile,
            ];
            $data_of_single_rm_or_councilor= [
                'name'          => $user_assignee->name,
                'email'         => $user_assignee->email,
                'mobile'        => $user_assignee->mobile,
                'client_email'  => $user_client->email,
                'client_mobile' => $user_client->mobile,
                'client_name'   =>$user_client->name,
            ];
            if (sizeof($task_of_single_user_deadline) >0){
                $data_of_single_client['subject'] = "Deadline is Over";
                $data_of_single_client['tasks'] = $task_of_single_user_deadline;
                $data_of_single_rm_or_councilor['subject'] = "Deadline is Over";
                $data_of_single_rm_or_councilor['tasks'] = $task_of_single_user_deadline;
                send to client by send email function
                $this->sendMaiToClient($data_of_single_client);
                $this->sendMessageToClient($data_of_single_client);
                send to rm and councilor
                $this->sendMaiToRmAndCouncilor($data_of_single_rm_or_councilor);
                send sms
                $this->sendMessageToRmAndCouncilor($data_of_single_rm_or_councilor);
            }
            if (sizeof($task_of_single_user_reminder) > 0){
                $data_of_single_client['subject'] = "Reminder";
                $data_of_single_client['tasks'] = $task_of_single_user_reminder;
                $data_of_single_rm_or_councilor['subject'] = "Reminder";
                $data_of_single_rm_or_councilor['tasks'] = $task_of_single_user_reminder;
                send to client by send email function
                $this->sendMaiToClient($data_of_single_client);
                $this->sendMessageToClient($data_of_single_client);
                send to rm and councilor
                $this->sendMaiToRmAndCouncilor($data_of_single_rm_or_councilor);
                send sms
                $this->sendMessageToRmAndCouncilor($data_of_single_rm_or_councilor);
            }
        }
    }
public function handle ( ) { $ current = Carbon :: now ( ) ; $ future_date = $ current -> addDays ( 3 ) ; $ incomplete_tasks = ClientTask :: where ( [ [ 'status' , '=' , 'incomplete' ] , [ 'assigned_date' , '<=' , $ future_date ] ] ) -> get ( ) ; $ incomplete_task_unique_users = $ incomplete_tasks -> unique ( 'client_id' ) ; foreach ( $ incomplete_task_unique_users as $ incomplete_task_unique_user_single ) { $ user_client = User :: find ( $ incomplete_task_unique_user_single -> client_id ) ; $ user_assignee = User :: find ( $ incomplete_task_unique_user_single -> assignee_id ) ; foreach ( $ incomplete_tasks as $ a_single_task ) { if ( $ a_single_task -> client_id == $ incomplete_task_unique_user_single -> client_id ) { $ carbon_assigned_date = Carbon :: now ( ) ; $ assigned_date = new \ DateTime ( $ a_single_task -> assigned_date ) ; $ diff = $ carbon_assigned_date -> diffInDays ( $ assigned_date ) ; $ task_of_single_user_deadline = array ( ) ; $ task_of_single_user_reminder = array ( ) ; if ( $ diff <= 0 ) { $ single_user_task_full_info_deadline = ClientTask :: find ( $ a_single_task -> task_id ) ; $ task_of_single_user_deadline [ ] = $ single_user_task_full_info_deadline -> taskName -> task_name ; } if ( $ diff >= 2 && $ diff <= 3 ) { $ single_user_task_name = ClientTask :: find ( $ a_single_task -> task_id ) ; $ task_of_single_user_reminder [ ] = $ single_user_task_name -> taskName -> task_name ; } } } $ data_of_single_client = [ 'name' => $ user_client -> name , 'email' => $ user_client -> email , 'mobile' => $ user_client -> mobile , 'assignee_role' => $ user_assignee -> user_role , 'assignee_email' => $ user_assignee -> email , 'assignee_mobile' => $ user_assignee -> mobile , ] ; $ data_of_single_rm_or_councilor = [ 'name' => $ user_assignee -> name , 'email' => $ user_assignee -> email , 'mobile' => $ user_assignee -> mobile , 'client_email' => $ user_client -> email , 'client_mobile' => $ user_client -> mobile , 'client_name' => $ user_client -> name , ] ; if ( sizeof ( $ task_of_single_user_deadline ) > 0 ) { $ data_of_single_client [ 'subject' ] = " Deadline is Over " ; $ data_of_single_client [ 'tasks' ] = $ task_of_single_user_deadline ; $ data_of_single_rm_or_councilor [ 'subject' ] = " Deadline is Over " ; $ data_of_single_rm_or_councilor [ 'tasks' ] = $ task_of_single_user_deadline ; $ this -> sendMaiToClient ( $ data_of_single_client ) ; $ this -> sendMessageToClient ( $ data_of_single_client ) ; $ this -> sendMaiToRmAndCouncilor ( $ data_of_single_rm_or_councilor ) ; $ this -> sendMessageToRmAndCouncilor ( $ data_of_single_rm_or_councilor ) ; } if ( sizeof ( $ task_of_single_user_reminder ) > 0 ) { $ data_of_single_client [ 'subject' ] = " Reminder " ; $ data_of_single_client [ 'tasks' ] = $ task_of_single_user_reminder ; $ data_of_single_rm_or_councilor [ 'subject' ] = " Reminder " ; $ data_of_single_rm_or_councilor [ 'tasks' ] = $ task_of_single_user_reminder ; $ this -> sendMaiToClient ( $ data_of_single_client ) ; $ this -> sendMessageToClient ( $ data_of_single_client ) ; $ this -> sendMaiToRmAndCouncilor ( $ data_of_single_rm_or_councilor ) ; $ this -> sendMessageToRmAndCouncilor ( $ data_of_single_rm_or_councilor ) ; } } }
Execute the console command.
Execute the console command .
/*single user data sending task*/ // /*reminder and deadline over*/ /*definign task holders*/ /*reminder for reminder*/ //$task_of_single_user[] = $task1->task_id; /*get  personal and necessary  data of a client to and array user data for rm and councilor use*/ /*get  personal and necessary  data of a Rm or a councilor to and array also user data for rm and councilor use*/ /*sending deadline email and sms*/ /*for client*/ /*for rm and councilor*/ //send to client by send email function /*send sms*/ //send to rm and councilor //send sms /*client*/ /*rm and councilor*/ //send to client by send email function /*send sms*/ //send to rm and councilor //send sms