mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Notifications;
|
|
|
|
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\TransactionType;
|
|
use App\Models\PackingList;
|
|
use App\Models\User;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class InvoiceIssuedEmail extends AbstractEmail
|
|
{
|
|
|
|
/** @var User */
|
|
private $user;
|
|
|
|
/** @var PackingList */
|
|
private $packingList;
|
|
|
|
/**
|
|
* @param User $user
|
|
* @param PackingList $packingList
|
|
*/
|
|
public function __construct(User $user, PackingList $packingList)
|
|
{
|
|
$this->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;
|
|
|
|
// $fileContent = Storage::disk('documents')->get($invoiceDocument->first()->file->file_info->original->file);
|
|
$filePath = storage_path('app/documents/' . $invoiceDocument->first()->file->file_info->original->file);
|
|
|
|
Log::info('InvoiceIssuedEmail sent - Att: '.$this->user->name.' - Invoice for order no.'. $this->packingList->owner->reference);
|
|
|
|
return (new MailMessage)
|
|
->subject('Att: '.$this->user->name.' - Invoice for order no.'. $this->packingList->owner->reference)
|
|
->attach($filePath, [
|
|
'as' => 'name.pdf',
|
|
'mime' => 'application/pdf',
|
|
])->view('emails.shipment.invoice', ['user' => $this->user, 'packingList' => $this->packingList]);
|
|
}
|
|
|
|
|
|
}
|