From 550abbbbe954315aa985ed2b75c85a081560ee2f Mon Sep 17 00:00:00 2001 From: omair saleh Date: Thu, 12 Nov 2020 13:42:23 +0800 Subject: [PATCH] test sending booking do to email --- app/Http/Controllers/InvoiceController.php | 26 ++++++++++++++++++---- routes/web.php | 18 --------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 33acc0e9..a7b83e46 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Mail; use Illuminate\Validation\Rule; use Illuminate\Routing\ResponseFactory; @@ -349,18 +350,35 @@ 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, $do->Output('do.pdf', 'S')); + } - $do = $this->generateSupplierDo($booking->id); - Mail::raw( 'DO for booking no'.$booking->id, function($message) use ($do, $booking){ + $zip->close(); + $attachment = base64_encode(File::get($zipname)); + +// $do = $this->generateSupplierDo($booking->id); + Mail::raw( 'DO for bookings po approved on '.Carbon::today(), function($message) use ($attachment){ $message->from('info@cief-malaysia.com'); $message->to('uldvstar@gmail.com'); - $message->subject('DO for booking no'.$booking->id); + $message->subject('DO for bookings on'.Carbon::today()); //Attach PDF doc - $message->attachData($do->Output('do.pdf', 'S'),'do_booking_no_'.$booking->id.'.pdf', [ + $message->attachData($attachment,'do_'.Carbon::today()->format('Y_m_d').'.zip', [ 'mime' => 'application/pdf', ]); }); + File::delete($zipname); + if(!$booking) { return response()->json(['message' => 'Unable to Complete Booking. Please Approve Again'], 500); } diff --git a/routes/web.php b/routes/web.php index 73792e3c..7c1c936c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -48,24 +48,6 @@ Route::get('/old-invoices', function(){ } })->name('invoice.old'); -Route::get('/approved-today', function(){ - $zipname = 'do_12_11_2020_01.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) { - $invoiceContoller = new InvoiceController(); - $do = $invoiceContoller->generateSupplierDo($id); - $zip->addFromString('do_12_11_2020_'.$id, $do->Output('do.pdf', 'S')); - } - dd(base64_encode(File::get($zipname))); - $zip->close(); - -}); Route::group(['middleware' => ['role:admin']], function() { Route::get('bulkBookings', function () {