mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-21 13:34:00 +00:00
74 lines
2.3 KiB
PHP
74 lines
2.3 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;
|
|
|
|
$mailMessage = (new MailMessage) ->subject('Att: '.$this->user->name.' - Invoice for order no.'. $this->packingList->owner->reference);
|
|
|
|
$filesystemDriver = Storage::getDefaultDriver();
|
|
$filename = $invoiceDocument->first()->file->file_info->original->file;
|
|
Log::info('ShipmentDepartureEmail file name: '.$filename);
|
|
if($filesystemDriver === 's3'){
|
|
$fileContent = null;
|
|
$fileContent = Storage::disk('s3')->get($filename);
|
|
if ($fileContent) {
|
|
$mailMessage->attachData($fileContent, 'invoice.pdf', [
|
|
'mime' => 'application/pdf',
|
|
]);
|
|
}
|
|
}
|
|
else{
|
|
$filePath = '';
|
|
// $fileContent = Storage::disk('documents')->get($invoiceDocument->first()->file->file_info->original->file);
|
|
$filePath = storage_path('app/documents/' . $filename);
|
|
if ($filePath) {
|
|
$mailMessage->attach($filePath, [
|
|
'as' => 'invoice.pdf',
|
|
'mime' => 'application/pdf',
|
|
]);
|
|
}
|
|
}
|
|
|
|
Log::info('InvoiceIssuedEmail sent - Att: '.$this->user->name.' - Invoice for order no.'. $this->packingList->owner->reference);
|
|
|
|
$mailMessage->view('emails.shipment.invoice', ['user' => $this->user, 'packingList' => $this->packingList]);
|
|
return $mailMessage;
|
|
}
|
|
|
|
|
|
}
|