Merge branch 'send-email-payment-proof' of gitlab.com:CIEFWorldwideSdnBhd/exchange-2.0

This commit is contained in:
edmondlang
2023-06-27 18:33:11 +08:00
4 changed files with 128 additions and 2 deletions
@@ -0,0 +1,47 @@
<?php
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;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SendUserPaymentProofUploadedEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/** @var User */
private $user;
/** @var Booking */
private $booking;
/** @var File */
private $file;
/**
* SendUserVerificationEmail constructor.
* @param User $user
* @param UserEmailVerification $attempt
*/
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->file));
}
}
@@ -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([]);
}
@@ -0,0 +1,54 @@
<?php
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;
class PaymentProofUploadedEmail extends AbstractEmail
{
/** @var User */
private $user;
/** @var Booking */
private $booking;
/** @var File */
private $file;
/**
* UserVerificationEmail constructor.
* @param User $user
* @param UserEmailVerification $attempt
*/
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 . ')')
// ->attach($attachedFile) // todo-new: add attachement
->view('emails.accounts.payment_proof_email', ['user' => $this->user, 'booking' => $this->booking]);
}
}
@@ -0,0 +1,11 @@
@extends('emails.layout.base')
@section('content')
<h4 style="font-size: 1em;">Dear {{ucwords($user->name)}},</h4>
<p style="font-size: 0.9em">Thank you for using CIEF Exchange service!</p>
<p style="margin-top: 30px; font-size: 0.8em">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:</p>
<div style="margin-top: 20px;">
<a href="{{route('booking.details', $booking->marking)}}"><button class="btn all-caps bg-primary no-border text-white pointer" style="font-size: 0.8em" >View</button></a>
</div>
<div class="all-caps hint-text" style="margin-top: 20px;"><small style="font-size: 0.7em">If you have questions, contact us at <a href="https://go.crisp.chat/chat/embed/?website_id=665dcd41-1edf-4451-8cb9-f1cf9ed35e15">here</a>. We truly appreciate your trust in our services and look forward to serving you in the future.</small></div>
@endsection