From 9840a461076d03e678b848bf48b856dacfc2bb6e Mon Sep 17 00:00:00 2001 From: omair saleh Date: Fri, 13 Nov 2020 14:10:58 +0800 Subject: [PATCH] test sending booking do to email --- app/Http/Controllers/InvoiceController.php | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 912dcc99..ee3932ca 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -352,6 +352,33 @@ 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); }