diff --git a/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php b/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php new file mode 100644 index 00000000..072dfa15 --- /dev/null +++ b/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php @@ -0,0 +1,47 @@ +user = $user; + $this->booking = $booking; + $this->file = $file; + } + + + public function handle() + { + $this->user->notify(new PaymentProofUploadedEmail($this->user, $this->booking, $this->file)); + } +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php index fdda9019..46534d77 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php @@ -14,6 +14,7 @@ use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\CompanyType; use App\Classes\ValueObjects\Constants\DocumentType; +use App\Classes\Jobs\SendUserPaymentProofUploadedEmail; use App\Models\Company; use App\Models\Document; use Illuminate\Http\JsonResponse; @@ -50,6 +51,9 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic /** @var CreateInvoiceTransactionProcessor */ private $createInvoiceTransactionProcessor; + /** @var SendUserPaymentProofUploadedEmail */ + private $sendUserPaymentProofUploadedEmail; + /** * CreatePaymentProofDocumentLogic constructor. * @param FetchesTransaction $fetchesTransaction @@ -58,13 +62,14 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic * @param UpdatesTransactionStatus $updatesTransactionStatus * @param CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor */ - public function __construct(FetchesTransaction $fetchesTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus, CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor) + public function __construct(FetchesTransaction $fetchesTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus, CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor, SendUserPaymentProofUploadedEmail $sendUserPaymentProofUploadedEmail) { $this->fetchesTransaction = $fetchesTransaction; $this->createsDocument = $createsDocument; $this->createsFile = $createsFile; $this->updatesTransactionStatus = $updatesTransactionStatus; $this->createInvoiceTransactionProcessor = $createInvoiceTransactionProcessor; + $this->sendUserPaymentProofUploadedEmail = $sendUserPaymentProofUploadedEmail; } /** @@ -82,12 +87,21 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic /** @var Document $document */ $document = $this->createsDocument->execute($transaction, $object); - $this->createsFile->execute($document, $object); + $file = $this->createsFile->execute($document, $object); $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED); $this->createInvoiceTransactionProcessor->execute($transaction->owner->booking); + // send email to customer + // todo: a function to send a proof to the receipiant, they have to give us a email of the receipiant and also need to submiited purchase order + $companyEmployee = $transaction->owner->booking->company->employees; + foreach ($companyEmployee as $employee) { + if (app()->environment('production') || in_array($employee->email, ['cief.enquirycntr@gmail.com', 'tech.ciefmalaysia@gmail.com'])) { + $this->sendUserPaymentProofUploadedEmail::dispatch($employee, $transaction->owner->booking, $file[0]); + } + } + return $this->response([]); } diff --git a/app/Classes/Notifications/PaymentProofUploadedEmail.php b/app/Classes/Notifications/PaymentProofUploadedEmail.php new file mode 100644 index 00000000..1fdc8e14 --- /dev/null +++ b/app/Classes/Notifications/PaymentProofUploadedEmail.php @@ -0,0 +1,54 @@ +user = $user; + $this->booking = $booking; + $this->file = $file; + } + + + public function toMail() + { + $attachedFile = null; + $file_info = $this->file->getFileAttribute($this->file)->file->file_info; + foreach ($file_info as $fileCount => $fileVal) { + if (isset($fileVal->original)) { + $file_path = $fileVal->original->file; + $attachedFile = storage_path('app/documents/' . $file_path); + } + } + + return (new MailMessage) + ->subject('Transfer Completed (REF: ' . $this->booking->marking . ')') + // ->attach($attachedFile) // todo-new: add attachement + ->view('emails.accounts.payment_proof_email', ['user' => $this->user, 'booking' => $this->booking]); + } + + +} diff --git a/resources/views/emails/accounts/payment_proof_email.blade.php b/resources/views/emails/accounts/payment_proof_email.blade.php new file mode 100644 index 00000000..b3653cdb --- /dev/null +++ b/resources/views/emails/accounts/payment_proof_email.blade.php @@ -0,0 +1,11 @@ +@extends('emails.layout.base') + +@section('content') +
Thank you for using CIEF Exchange service!
+We have completed your transfer transaction for the ref. no {{$booking->marking}}. If you would like to view the transaction, please click on the following link:
+ +