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 e5019fd6..b91c818b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -618,39 +618,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"; - } -});