Files
shipping-portal/app/Classes/Notifications/InvoiceIssuedEmail.php
T
2024-05-04 17:51:57 +08:00

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]);
}
}