From 6b73f319937898bde5bb14c4589ca6fc1f976a62 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 3 Jun 2023 15:48:33 +0800 Subject: [PATCH 1/8] email payment proof --- .../SendUserPaymentProofUploadedEmail.php | 42 +++++++++++++++++++ .../CreatePaymentProofDocumentLogic.php | 15 ++++++- .../PaymentProofUploadedEmail.php | 41 ++++++++++++++++++ .../accounts/payment_proof_email.blade.php | 12 ++++++ routes/web.php | 38 ++++++++++++++++- 5 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php create mode 100644 app/Classes/Notifications/PaymentProofUploadedEmail.php create mode 100644 resources/views/emails/accounts/payment_proof_email.blade.php diff --git a/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php b/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php new file mode 100644 index 00000000..8aa94ce8 --- /dev/null +++ b/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php @@ -0,0 +1,42 @@ +user = $user; + $this->booking = $booking; + } + + + public function handle() + { + $this->user->notify(new PaymentProofUploadedEmail($this->user, $this->booking)); + } +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php index fdda9019..b4448729 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; } /** @@ -88,6 +93,14 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic $this->createInvoiceTransactionProcessor->execute($transaction->owner->booking); + // send email to customer + // todo: send them the file also + // 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) { + $this->sendUserPaymentProofUploadedEmail::dispatch($employee, $transaction->owner->booking); + } + return $this->response([]); } diff --git a/app/Classes/Notifications/PaymentProofUploadedEmail.php b/app/Classes/Notifications/PaymentProofUploadedEmail.php new file mode 100644 index 00000000..d0bf21f0 --- /dev/null +++ b/app/Classes/Notifications/PaymentProofUploadedEmail.php @@ -0,0 +1,41 @@ +user = $user; + $this->booking = $booking; + } + + + public function toMail() + { + return (new MailMessage) + ->subject('Transfer Completed (REF: ' . $this->booking->marking . ')') + ->to('edmond.wuiming2021@gmail.com') // testing email + // ->attach('/path/to/file') // 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..8d888671 --- /dev/null +++ b/resources/views/emails/accounts/payment_proof_email.blade.php @@ -0,0 +1,12 @@ +@extends('emails.layout.base') + +@section('content') +

Dear {{$user->name}},

+

Thank you for using CIEF Exchange service!

+

We have completed your RMB transfer transaction for the ref. no {{$booking->marking}}. The RMB bank slip has been attached to this email. If you would like to view the transaction, please click on the following link:

+
+ +
+ + +@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 2547d087..3116a479 100644 --- a/routes/web.php +++ b/routes/web.php @@ -600,4 +600,40 @@ Route::get('/po/outsource/check', function(){ Route::get('/upload-honey-trap', function () { return view('pages.honey_trap'); -})->name('upload_honey_trap'); \ No newline at end of file +})->name('upload_honey_trap'); + +Route::get('/text-transfer-email', function () { + $booking = Booking::where('marking', '25760')->first(); + $mployee = $booking->company->employees->first(); + return view('emails.accounts.payment_proof_email', ['booking' => $booking, 'user' => $mployee, ]); +}); + +use Illuminate\Support\Facades\Mail; + +Route::get('/show-email', function () { + // Send some emails using MailMessage + // Retrieve the Swift Mailer instance + $mailer = Mail::getSwiftMailer(); + // Retrieve the Transport instance + $transport = $mailer->getTransport(); + // Retrieve the sent messages + $messages = $transport->getMessages(); + // Loop through the sent messages + foreach ($messages as $message) { + // Access the email details + $subject = $message->getSubject(); + $from = $message->getFrom(); + $to = $message->getTo(); + $cc = $message->getCc(); + $bcc = $message->getBcc(); + // ...and so on + + // Output the email details + echo "Subject: $subject\n"; + echo "From: $from\n"; + echo "To: $to\n"; + echo "Cc: $cc\n"; + echo "Bcc: $bcc\n"; + echo "\n"; + } +}); From f1ce5c6a86b56f2c900b665ba8c2c8c1bf6ba7e2 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 3 Jun 2023 15:58:13 +0800 Subject: [PATCH 2/8] update email payment proof --- app/Classes/Notifications/PaymentProofUploadedEmail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Classes/Notifications/PaymentProofUploadedEmail.php b/app/Classes/Notifications/PaymentProofUploadedEmail.php index d0bf21f0..ff39c3c3 100644 --- a/app/Classes/Notifications/PaymentProofUploadedEmail.php +++ b/app/Classes/Notifications/PaymentProofUploadedEmail.php @@ -32,7 +32,7 @@ class PaymentProofUploadedEmail extends AbstractEmail { return (new MailMessage) ->subject('Transfer Completed (REF: ' . $this->booking->marking . ')') - ->to('edmond.wuiming2021@gmail.com') // testing email + // ->to('edmond.wuiming2021@gmail.com') // testing email // ->attach('/path/to/file') // todo-new: add attachement ->view('emails.accounts.payment_proof_email', ['user' => $this->user, 'booking' => $this->booking]); } From ec85ec07ab2e4224e0576769a7d3ee27a5162c87 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 3 Jun 2023 17:01:15 +0800 Subject: [PATCH 3/8] send email payment proof --- .../SendUserPaymentProofUploadedEmail.php | 9 +++-- .../CreatePaymentProofDocumentLogic.php | 4 +-- .../PaymentProofUploadedEmail.php | 19 ++++++++-- routes/web.php | 36 ------------------- 4 files changed, 25 insertions(+), 43 deletions(-) diff --git a/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php b/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php index 8aa94ce8..072dfa15 100644 --- a/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php +++ b/app/Classes/Jobs/SendUserPaymentProofUploadedEmail.php @@ -5,6 +5,7 @@ namespace App\Classes\Jobs; use App\Classes\Notifications\PaymentProofUploadedEmail; use App\Models\Booking; use App\Models\User; +use App\Models\File; use App\Models\UserEmailVerification; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -23,20 +24,24 @@ class SendUserPaymentProofUploadedEmail implements ShouldQueue /** @var Booking */ private $booking; + /** @var File */ + private $file; + /** * SendUserVerificationEmail constructor. * @param User $user * @param UserEmailVerification $attempt */ - public function __construct(User $user, Booking $booking) + public function __construct(User $user, Booking $booking, File $file) { $this->user = $user; $this->booking = $booking; + $this->file = $file; } public function handle() { - $this->user->notify(new PaymentProofUploadedEmail($this->user, $this->booking)); + $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 b4448729..778362aa 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php @@ -87,7 +87,7 @@ 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); @@ -98,7 +98,7 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic // 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) { - $this->sendUserPaymentProofUploadedEmail::dispatch($employee, $transaction->owner->booking); + $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 index ff39c3c3..cc611236 100644 --- a/app/Classes/Notifications/PaymentProofUploadedEmail.php +++ b/app/Classes/Notifications/PaymentProofUploadedEmail.php @@ -4,6 +4,7 @@ namespace App\Classes\Notifications; use App\Models\Booking; use App\Models\User; +use App\Models\File; use App\Models\UserEmailVerification; use Illuminate\Notifications\Messages\MailMessage; @@ -16,24 +17,36 @@ class PaymentProofUploadedEmail extends AbstractEmail /** @var Booking */ private $booking; + /** @var File */ + private $file; + /** * UserVerificationEmail constructor. * @param User $user * @param UserEmailVerification $attempt */ - public function __construct(User $user, Booking $booking) + public function __construct(User $user, Booking $booking, File $file) { $this->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 . ')') - // ->to('edmond.wuiming2021@gmail.com') // testing email - // ->attach('/path/to/file') // todo-new: add attachement + ->attach($attachedFile) // todo-new: add attachement ->view('emails.accounts.payment_proof_email', ['user' => $this->user, 'booking' => $this->booking]); } diff --git a/routes/web.php b/routes/web.php index 3116a479..7ba6d068 100644 --- a/routes/web.php +++ b/routes/web.php @@ -601,39 +601,3 @@ Route::get('/po/outsource/check', function(){ Route::get('/upload-honey-trap', function () { return view('pages.honey_trap'); })->name('upload_honey_trap'); - -Route::get('/text-transfer-email', function () { - $booking = Booking::where('marking', '25760')->first(); - $mployee = $booking->company->employees->first(); - return view('emails.accounts.payment_proof_email', ['booking' => $booking, 'user' => $mployee, ]); -}); - -use Illuminate\Support\Facades\Mail; - -Route::get('/show-email', function () { - // Send some emails using MailMessage - // Retrieve the Swift Mailer instance - $mailer = Mail::getSwiftMailer(); - // Retrieve the Transport instance - $transport = $mailer->getTransport(); - // Retrieve the sent messages - $messages = $transport->getMessages(); - // Loop through the sent messages - foreach ($messages as $message) { - // Access the email details - $subject = $message->getSubject(); - $from = $message->getFrom(); - $to = $message->getTo(); - $cc = $message->getCc(); - $bcc = $message->getBcc(); - // ...and so on - - // Output the email details - echo "Subject: $subject\n"; - echo "From: $from\n"; - echo "To: $to\n"; - echo "Cc: $cc\n"; - echo "Bcc: $bcc\n"; - echo "\n"; - } -}); From dc5b96403c7bd4a34c71861b4d204fbf78126c82 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 3 Jun 2023 19:02:41 +0800 Subject: [PATCH 4/8] update email payment proof --- resources/views/emails/accounts/payment_proof_email.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/emails/accounts/payment_proof_email.blade.php b/resources/views/emails/accounts/payment_proof_email.blade.php index 8d888671..eb1357ea 100644 --- a/resources/views/emails/accounts/payment_proof_email.blade.php +++ b/resources/views/emails/accounts/payment_proof_email.blade.php @@ -1,7 +1,7 @@ @extends('emails.layout.base') @section('content') -

Dear {{$user->name}},

+

Dear {{ucwords($user->name)}},

Thank you for using CIEF Exchange service!

We have completed your RMB transfer transaction for the ref. no {{$booking->marking}}. The RMB bank slip has been attached to this email. If you would like to view the transaction, please click on the following link:

From 763902879d68ea340c61fa8f03fe71ef411af6eb Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 3 Jun 2023 19:19:35 +0800 Subject: [PATCH 5/8] update send email payment proof, send email only in production --- .../ControllersLogic/CreatePaymentProofDocumentLogic.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php index 778362aa..00ca9a85 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php @@ -94,11 +94,12 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic $this->createInvoiceTransactionProcessor->execute($transaction->owner->booking); // send email to customer - // todo: send them the file also // 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) { - $this->sendUserPaymentProofUploadedEmail::dispatch($employee, $transaction->owner->booking, $file[0]); + if (app()->environment('production')) { + $companyEmployee = $transaction->owner->booking->company->employees; + foreach ($companyEmployee as $employee) { + $this->sendUserPaymentProofUploadedEmail::dispatch($employee, $transaction->owner->booking, $file[0]); + } } return $this->response([]); From 6a3b8884f8086664594e6ae98953dfa72c49b834 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 12 Jun 2023 15:08:27 +0800 Subject: [PATCH 6/8] update send email payment proof, add testing email --- .../ControllersLogic/CreatePaymentProofDocumentLogic.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php index 00ca9a85..46534d77 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentProofDocumentLogic.php @@ -95,9 +95,9 @@ class CreatePaymentProofDocumentLogic extends AbstractControllerLogic // 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 - if (app()->environment('production')) { - $companyEmployee = $transaction->owner->booking->company->employees; - foreach ($companyEmployee as $employee) { + $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]); } } From ce9f641995b9e564601aa3a789536490aff17fb1 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Mon, 12 Jun 2023 15:59:52 +0800 Subject: [PATCH 7/8] update senf payment proof - disable attachement file - update the text --- app/Classes/Notifications/PaymentProofUploadedEmail.php | 2 +- resources/views/emails/accounts/payment_proof_email.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Classes/Notifications/PaymentProofUploadedEmail.php b/app/Classes/Notifications/PaymentProofUploadedEmail.php index cc611236..1fdc8e14 100644 --- a/app/Classes/Notifications/PaymentProofUploadedEmail.php +++ b/app/Classes/Notifications/PaymentProofUploadedEmail.php @@ -46,7 +46,7 @@ class PaymentProofUploadedEmail extends AbstractEmail return (new MailMessage) ->subject('Transfer Completed (REF: ' . $this->booking->marking . ')') - ->attach($attachedFile) // todo-new: add attachement + // ->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 index eb1357ea..0682f65e 100644 --- a/resources/views/emails/accounts/payment_proof_email.blade.php +++ b/resources/views/emails/accounts/payment_proof_email.blade.php @@ -3,7 +3,7 @@ @section('content')

Dear {{ucwords($user->name)}},

Thank you for using CIEF Exchange service!

-

We have completed your RMB transfer transaction for the ref. no {{$booking->marking}}. The RMB bank slip has been attached to this email. If you would like to view the transaction, please click on the following link:

+

We have completed your transfer transaction for the ref. no {{$booking->marking}}. The bank slip has been attached to this email. If you would like to view the transaction, please click on the following link:

From 1b6bf18a4df31be18016b0cd2fa0643b7a44c1e9 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 21 Jun 2023 15:17:30 +0800 Subject: [PATCH 8/8] update send payment proof email --- .../views/emails/accounts/payment_proof_email.blade.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/resources/views/emails/accounts/payment_proof_email.blade.php b/resources/views/emails/accounts/payment_proof_email.blade.php index 0682f65e..b3653cdb 100644 --- a/resources/views/emails/accounts/payment_proof_email.blade.php +++ b/resources/views/emails/accounts/payment_proof_email.blade.php @@ -3,10 +3,9 @@ @section('content')

Dear {{ucwords($user->name)}},

Thank you for using CIEF Exchange service!

-

We have completed your transfer transaction for the ref. no {{$booking->marking}}. The bank slip has been attached to this email. If you would like to view the transaction, please click on the following link:

+

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:

- - +
If you have questions, contact us at here. We truly appreciate your trust in our services and look forward to serving you in the future.
@endsection \ No newline at end of file