From bbcda12bcdcbe900f826c5b8d55511c3a0782a65 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Thu, 25 Nov 2021 01:37:53 +0800 Subject: [PATCH] add command for sending do to vt --- app/Console/Commands/EmailDoToVTCommand.php | 11 +++++------ app/Console/Kernel.php | 10 ++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/EmailDoToVTCommand.php b/app/Console/Commands/EmailDoToVTCommand.php index 665ab903..d9d463f0 100644 --- a/app/Console/Commands/EmailDoToVTCommand.php +++ b/app/Console/Commands/EmailDoToVTCommand.php @@ -60,11 +60,11 @@ class EmailDoToVTCommand extends Command { Auth::login(User::findOrFail(1)); - $zip_file = 'do_from_11_nov_to_23_nov.zip'; + $zip_file = 'do_'.Carbon::yesterday()->format('Y_m_d').'.zip'; $attachment = storage_path().'/'.$zip_file; $zip = new ZipArchive(); - if ($zip->open($attachment, ZIPARCHIVE::CREATE)) { - $bookings = \App\Models\Booking::where('status', ApprovalStatus::COMPLETED)->whereDate('updated_at', '>=', Carbon::parse('12-11-2021'))->whereDate('updated_at', '<=', Carbon::parse('23-11-2021')) + if ($zip->open($attachment, ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE)) { + $bookings = \App\Models\Booking::where('status', ApprovalStatus::COMPLETED)->whereDate('updated_at', Carbon::yesterday()) ->whereHas('transactions', function ($query){ return $query->where('type', TransactionType::BILL)->where('issuer', 2); })->get(); @@ -79,12 +79,11 @@ class EmailDoToVTCommand extends Command $zip->close(); - Mail::raw( "Attention to VT Admin team:\r\n\r\nKindly refer to the attachment for our DAILY DO COMPILATION from 12-11-2021 to 23-11-2021.\r\n\r\n**This is an automatically generated email – please do not reply to it. If you have any queries kindly contact our admin team through Wechat.\r\n\r\n\r\nCIEF WORLDWIDE SDN BHD", function($message) use ($attachment){ + Mail::raw( "Attention to VT Admin team:\r\n\r\nKindly refer to the attachment for our DAILY DO COMPILATION ".Carbon::yesterday()->format('d-m-Y').".\r\n\r\n**This is an automatically generated email – please do not reply to it. If you have any queries kindly contact our admin team through Wechat.\r\n\r\n\r\nCIEF WORLDWIDE SDN BHD", function($message) use ($attachment){ $message->from('exchange@cief-malaysia.com'); -// $message->to(['uldvstar@gmail.com']); $message->to(['vtnation16@gmail.com', 'vtnation@gmail.com', 'atvantic04@gmail.com', 'vtnation2@gmail.com']); $message->cc(['shafiqa_sukeri@cief-malaysia.com', 'frontendcief@gmail.com', 'pm@cief-malaysia.com', 'hasan@cief-malaysia.com', 'shipping_admin@cief-malaysia.com', 'hasanakbar27@gmail.com', 'pmwong2019@gmail.com']); - $message->subject('CIEF DO COMPILATION from 12-11-2021 to 23-11-2021'); + $message->subject('CIEF DO COMPILATION '.Carbon::yesterday()->format('d-m-Y')); $message->attach($attachment); }); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 16f673e8..75c6edf1 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,8 +2,15 @@ namespace App\Console; +use App\Models\User; +use Carbon\Carbon; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Facades\Storage; +use ZipArchive; class Kernel extends ConsoleKernel { @@ -23,7 +30,10 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { + // $schedule->command('inspire')->hourly(); + $schedule->command('mail:EmailDoToVTCommand')->dailyAt('10:00'); + } /**