diff --git a/app/Classes/Modules/Orders/Processors/UpdateDoFromYDPortalProcessor.php b/app/Classes/Modules/Orders/Processors/UpdateDoFromYDPortalProcessor.php index b5e7e171..f7d76adf 100644 --- a/app/Classes/Modules/Orders/Processors/UpdateDoFromYDPortalProcessor.php +++ b/app/Classes/Modules/Orders/Processors/UpdateDoFromYDPortalProcessor.php @@ -70,7 +70,6 @@ class UpdateDoFromYDPortalProcessor } catch (\Exception $exception){ - dd($exception); throw new InternalServerErrorException('failed to approve address due to an error related to YD portal'); } } diff --git a/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php b/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php index 83131a7f..dd90c7d3 100644 --- a/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php +++ b/app/Classes/Modules/PackingLists/Processors/FetchOrderListsFromYdPortalProcessor.php @@ -24,6 +24,7 @@ use App\Classes\Modules\Unity\Processors\AssignContractEntityProcessor; use App\Classes\Modules\Unity\Processors\CreateContractEntityProcessor; use App\Classes\Modules\Unity\Services\CreatesContract; use App\Classes\Modules\Unity\Services\UpdatesContractObligation; +use App\Classes\Notifications\ShipmentDepartureEmail; use App\Classes\Notifications\ShipmentRescheduleEmail; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\ContainerTypes; @@ -406,9 +407,10 @@ class FetchOrderListsFromYdPortalProcessor $etd = $transport->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first()->etd; $transport->schedules()->update(['status' => ApprovalStatus::EXPIRED]); $this->createsSchedule->execute($transport, new ScheduleObject($etd, $delayDate, ApprovalStatus::APPROVED)); - if($order instanceof Order) { - $user = $order->companyModule->employees()->first(); -// $user->notify(new ShipmentRescheduleEmail($user, $packingList)); + foreach ($container->packingLists as $packingList){ + if(!($packingList->owner instanceof Order)) continue; + $user = $packingList->owner->companyModule->employees()->first(); + $user->notify(new ShipmentRescheduleEmail($user, $packingList)); } } diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ApproveShippingInvoiceTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ApproveShippingInvoiceTransactionLogic.php index d038bae9..96ea1373 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/ApproveShippingInvoiceTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/ApproveShippingInvoiceTransactionLogic.php @@ -3,6 +3,7 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; +use App\Classes\Notifications\InvoiceIssuedEmail; use Illuminate\Http\Request; @@ -87,8 +88,9 @@ class ApproveShippingInvoiceTransactionLogic extends AbstractControllerLogic $document = $this->createsDocument->execute($invoice_transaction, $document_object); $this->createsFiles->execute($document, $document_object); - + $user = $packing_list->owner->companyModule->employees()->first(); + $user->notify(new InvoiceIssuedEmail($user, $packing_list)); return $this->response([]); } -} \ No newline at end of file +} diff --git a/app/Classes/Notifications/AbstractEmail.php b/app/Classes/Notifications/AbstractEmail.php index 83efa01c..0f798ac9 100644 --- a/app/Classes/Notifications/AbstractEmail.php +++ b/app/Classes/Notifications/AbstractEmail.php @@ -2,14 +2,17 @@ namespace App\Classes\Notifications; +use Illuminate\Bus\Queueable; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; -class AbstractEmail extends Notification +class AbstractEmail extends Notification implements ShouldQueue { + use Queueable; public function via() { return 'mail'; } -} \ No newline at end of file +} diff --git a/app/Classes/Notifications/InvoiceIssuedEmail.php b/app/Classes/Notifications/InvoiceIssuedEmail.php new file mode 100644 index 00000000..f3cb4b97 --- /dev/null +++ b/app/Classes/Notifications/InvoiceIssuedEmail.php @@ -0,0 +1,49 @@ +user = $user; + $this->packingList = $packingList; + } + + + public function toMail() + { + $invoice = $this->packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::APPROVED)->first(); + $invoiceDocument = $invoice->documents()->first()->files; + + + return (new MailMessage) + ->subject('Att: '.$this->user->name.' - Invoice for order no.'. $this->packingList->owner->reference) + ->attach(Storage::disk('documents')->get($invoiceDocument->file->file_info->original->file), [ + 'as' => 'name.pdf', + 'mime' => 'application/pdf', + ])->view('emails.shipment.invoice', ['user' => $this->user, 'packingList' => $this->packingList]); + } + + +} diff --git a/app/Classes/Notifications/ShipmentDepartureEmail.php b/app/Classes/Notifications/ShipmentDepartureEmail.php new file mode 100644 index 00000000..193f8eb9 --- /dev/null +++ b/app/Classes/Notifications/ShipmentDepartureEmail.php @@ -0,0 +1,51 @@ +user = $user; + $this->packingList = $packingList; + } + + + public function toMail() + { + $invoice = $this->packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::APPROVED)->first(); + + if(!$invoice) return false; + + $invoiceDocument = $invoice->documents()->first()->files; + + + return (new MailMessage) + ->subject('Your packages are on the way to malaysia - Invoice pending payment for order no.'. $this->packingList->owner->reference) + ->attach(Storage::disk('documents')->get($invoiceDocument->file->file_info->original->file), [ + 'as' => 'name.pdf', + 'mime' => 'application/pdf', + ])->view('emails.shipment.ETD', ['user' => $this->user, 'packingList' => $this->packingList]); + } + + +} diff --git a/app/Classes/Notifications/ShipmentRescheduleEmail.php b/app/Classes/Notifications/ShipmentRescheduleEmail.php new file mode 100644 index 00000000..7b4fe4df --- /dev/null +++ b/app/Classes/Notifications/ShipmentRescheduleEmail.php @@ -0,0 +1,39 @@ +user = $user; + $this->packingList = $packingList; + } + + + public function toMail() + { + return (new MailMessage) + ->subject('Update on your recent shipment(s)') + ->view('emails.shipment.reschedule', ['user' => $this->user, 'packingList' => $this->packingList]); + } + + +} diff --git a/app/Console/Commands/SendContainerDepartureEmailCommand.php b/app/Console/Commands/SendContainerDepartureEmailCommand.php new file mode 100644 index 00000000..c8f0ce43 --- /dev/null +++ b/app/Console/Commands/SendContainerDepartureEmailCommand.php @@ -0,0 +1,62 @@ +whereDate('dispatch_date', '=', Carbon::today()); + })->get(); + + foreach ($containers as $container){ + foreach ($container->packingLists as $packingList){ + if(!($packingList->owner instanceof Order)) continue; + $user = $packingList->owner->companyModule->employees()->first(); + $user->notify(new ShipmentDepartureEmail($user, $packingList)); + } + } + + + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 5fc88d3c..8817b51d 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -38,6 +38,11 @@ class Kernel extends ConsoleKernel ->withoutOverlapping() ->appendOutputTo (storage_path().'/logs/curlyd.log'); + $schedule->command('command:curlYdOrderListCommand') + ->cron('0 9 * * *') + ->withoutOverlapping() + ->appendOutputTo (storage_path().'/logs/departure_email.log'); + } diff --git a/resources/views/emails/shipment/ETD.blade.php b/resources/views/emails/shipment/ETD.blade.php new file mode 100644 index 00000000..72cf43f1 --- /dev/null +++ b/resources/views/emails/shipment/ETD.blade.php @@ -0,0 +1,8 @@ +@extends('emails.layout.base') + +@section('content') +
We wanted to send you an update on the recent shipment for you order no. {{ $packingList->owner->reference }} you have placed with us. We've just learned that your shipment has just departed from china's port and is estimated to arrive on {{ $packingList->containers()->first()->transports()->first()->schedules()->where('status', \App\Classes\ValueObjects\Constants\ApprovalStatus::APPROVED)->first()->eta->format('d-m-Y') }}.
+Meanwhile, we would appreciate if you could make the payment as soon as possible so we can deliver your packages as soon as the shipment arrives. please click here to pay your invoice.
+Attached is the invoice concerning order no. {{$packingList->owner->reference}}. If the attached file isn't loading, please click here to access your invoice.
+We would like to also inform you that your packages have been loaded into the container and is estimated to depart on: {{$schedule->etd->format('d-m-Y')}} and is estimated to arrive on {{$schedule->eta->format('d-m-Y')}}.
+We appreciate you choosing us here at CIEF Worldwide to fulfill your shipping needs. We look forward to doing business with you again in the future.
+We wanted to send you an update on the recent shipment for you order no. {{ $packingList->owner->reference }} you have placed with us. We've just learned that there has been a shipping delay from the shipping liner, and as a result your packages will arrive a few days later the estimated date we gave you when we shipped your order. The new estimated date for arrival will be {{ $packingList->containers()->first()->transports()->first()->schedules()->where('status', \App\Classes\ValueObjects\Constants\ApprovalStatus::APPROVED)->first()->eta->format('d-m-Y') }}.
+We're very sorry that you are experiencing this delay. and we wanted to let you know as soon as we learned about it. We are working directly with the shipping liner to minimize the impact, but we don't want you to worry your order is still on its way!
+Recently shipping liner facing very frequent delay, it's better to estimate longer ETA while purchase to avoid any inconvenience causes.
+ @if($packingList->transactions()->whereHas('transactions', function ($query){ + return $query->where('type', \App\Classes\ValueObjects\Constants\TransactionType::SHIPPING_INVOICE)->where('status', '=', 2); + })->get()) +Meanwhile, we would appreciate if you could make the payment as soon as possible so we can deliver your packages as soon as the shipment arrives. please click here to pay your invoice.
+ @endif +