KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64
User : www-data ( 33)
PHP Version : 8.2.12
Disable Function : NONE
Directory :  /var/www/account.appointkrypt.com/app/Console/Commands/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/account.appointkrypt.com/app/Console/Commands/AppointmentReminder.php
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Business;
use App\Models\EmailTemplate;
use App\Models\Appointment;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;

class AppointmentReminder extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:appointment-reminder';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $businesses = Business::all();
        foreach($businesses as $business)
        {

            $company_settings = getCompanyAllSetting($business->created_by,$business->id);

            $timezone = $company_settings['defult_timezone'];
            $reminder = $company_settings['reminder_interval'] ?? null;
            
            if(!empty($reminder))
            {
                $date = Carbon::now()->timezone($timezone)->format('d-m-Y');
                $time = Carbon::now()->timezone($timezone)->format('H:i');

                $appointments = Appointment::where('business_id', $business->id)
                                ->orderBy('date','ASC')
                                ->whereRaw("STR_TO_DATE(date, '%d-%m-%Y') >= CURDATE()") // Get appointments for today or later
                                ->get(); 
    
                foreach ($appointments as $appointment) 
                {
                    $startTime = explode('-', $appointment->time)[0];
                    $appointment_date = $appointment->date;

                    $appointmentDateTime = Carbon::createFromFormat('d-m-Y H:i', $appointment_date . ' ' . $startTime);

                    $reminderDateTime = $appointmentDateTime->subMinutes($reminder);

                    $reminderdate = $reminderDateTime->format('d-m-Y');
                    $remindertime = $reminderDateTime->format('H:i');

                    if($appointment_date == $date && $time == $remindertime)
                    {
                        $appointment_number = Appointment::appointmentNumberFormat($appointment->id,$appointment->created_by,$appointment->business_id);
                        if( (!empty($company_settings['Appointment Reminder']) && $company_settings['Appointment Reminder']  == true ))
                        {
                            $uArr = [
                                'company_name'=>'-',
                                'customer'=>$appointment->CustomerData ? $appointment->CustomerData->name : $appointment->name,
                                'service'=>$appointment->ServiceData ? $appointment->ServiceData->name : '-',
                                'location'=>$appointment->LocationData ? $appointment->LocationData->name : '-',
                                'staff'=>$appointment->StaffData->user ? $appointment->StaffData->user->name : '-',
                                'appointment_date'=>$appointment->date,
                                'appointment_time'=>$appointment->time,
                                'appointment_number'=>$appointment_number,
                            ];
                            
                            $resp = EmailTemplate::sendEmailTemplate('Appointment Reminder', [$appointment->CustomerData ? $appointment->CustomerData->customer->email : $appointment->email], $uArr,$appointment->created_by);

                            if(!empty($resp) && $resp['is_success'] == false && !empty($resp['error']))
                            {
                                Log::channel('reminder_log')->info($resp['error']);
                            }
                            else
                            {
                                Log::channel('reminder_log')->info("success");
                            }
                            
                        }
                    }

                }

            }
            else
            {
                Log::channel('reminder_log')->info("Reminder time not set!");
            }
        }
    }
}

Anon7 - 2021