From 6c966da9c2c22aef833d7412a35884d45cb17f88 Mon Sep 17 00:00:00 2001 From: omair saleh Date: Fri, 13 Nov 2020 13:46:37 +0800 Subject: [PATCH] test sending booking do to email --- app/Console/Kernel.php | 32 +++++++++++++++++++++- app/Http/Controllers/InvoiceController.php | 27 ------------------ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 05a83096..8dd4e658 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,8 +2,14 @@ namespace App\Console; +use App\Http\Controllers\InvoiceController; +use App\InvoiceStatuses; +use Carbon\Carbon; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; +use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Mail; +use ZipArchive; class Kernel extends ConsoleKernel { @@ -25,7 +31,31 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { $schedule->call(function(){ - echo 'working...'; + $zipname = 'do_'.Carbon::today()->format('Y_m_d').'.zip'; + $zip = new ZipArchive; + $zip->open($zipname, ZipArchive::CREATE); + $approvedInvoices = InvoiceStatuses::where('status', 'approve')->whereDate('created_at', Carbon::today())->distinct()->get(['invoice_id']); + $bookings = []; + foreach($approvedInvoices as $approved){ + $bookings[] = $approved->invoice->booking->id; + } + foreach ($bookings as $id) { + $do = (new InvoiceController())->generateSupplierDo($id); + $zip->addFromString('do_'.Carbon::today()->format('Y_m_d').'_'.$id.'.pdf', $do->Output('do.pdf', 'S')); + } + + $zip->close(); + $attachment = public_path($zipname); + + Mail::raw( 'DO for bookings po approved on '.Carbon::today(), function($message) use ($attachment){ + $message->from('exchange@cief-malaysia.com'); + $message->to('uldvstar@gmail.com'); + $message->subject('DO for bookings on'.Carbon::today()); + + $message->attach($attachment); + }); + + File::delete($zipname); })->everyMinute(); } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index ee3932ca..912dcc99 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -352,33 +352,6 @@ class InvoiceController extends Controller $booking->admin_status = 7; $booking->save(); - $zipname = 'do_'.Carbon::today()->format('Y_m_d').'.zip'; - $zip = new ZipArchive; - $zip->open($zipname, ZipArchive::CREATE); - $approvedInvoices = InvoiceStatuses::where('status', 'approve')->whereDate('created_at', Carbon::today())->distinct()->get(['invoice_id']); - $bookings = []; - foreach($approvedInvoices as $approved){ - $bookings[] = $approved->invoice->booking->id; - } - foreach ($bookings as $id) { - $do = $this->generateSupplierDo($id); - $zip->addFromString('do_'.Carbon::today()->format('Y_m_d').'_'.$id.'.pdf', $do->Output('do.pdf', 'S')); - } - - $zip->close(); -// $attachment = chunk_split(base64_encode(File::get($zipname))); - $attachment = public_path($zipname); - - Mail::raw( 'DO for bookings po approved on '.Carbon::today(), function($message) use ($attachment){ - $message->from('exchange@cief-malaysia.com'); - $message->to('uldvstar@gmail.com'); - $message->subject('DO for bookings on'.Carbon::today()); - - $message->attach($attachment); - }); - - File::delete($zipname); - if(!$booking) { return response()->json(['message' => 'Unable to Complete Booking. Please Approve Again'], 500); }