Added import transit excel attachment logic in mail
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 18s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 15s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 19s
Laravel Pint / pint (pull_request) Successful in 2m11s
Laravel Larastan / larastan (pull_request) Failing after 3m28s

This commit is contained in:
dhanabalan
2026-06-12 09:20:03 +05:30
parent 3c5f9f7273
commit 05a3c9f7ac
2 changed files with 60 additions and 34 deletions

View File

@@ -7,6 +7,8 @@ use App\Models\AlertMailRule;
use App\Models\ImportTransit; use App\Models\ImportTransit;
use App\Models\Plant; use App\Models\Plant;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\ImportTransitReportExport;
class SendImportTransit extends Command class SendImportTransit extends Command
{ {
@@ -58,38 +60,41 @@ class SendImportTransit extends Command
// return; // return;
// } // }
$tableData = ImportTransit::select([ // $tableData = ImportTransit::select([
'cri_rfq_number', // 'cri_rfq_number',
'mail_received_date', // 'mail_received_date',
'pricol_ref_number', // 'pricol_ref_number',
'requester', // 'requester',
'shipper', // 'shipper',
'shipper_location', // 'shipper_location',
'shipper_invoice', // 'shipper_invoice',
'shipper_invoice_date', // 'shipper_invoice_date',
'customs_agent_name', // 'customs_agent_name',
'eta_date', // 'eta_date',
'status', // 'status',
'delivery_location', // 'delivery_location',
'etd_date', // 'etd_date',
'mode', // 'mode',
'inco_terms', // 'inco_terms',
'port_of_loading', // 'port_of_loading',
'port_of_discharge', // 'port_of_discharge',
'delivery_city', // 'delivery_city',
'packages', // 'packages',
'type_of_package', // 'type_of_package',
'gross_weight', // 'gross_weight',
'volume', // 'volume',
'bill_number', // 'bill_number',
'bill_received_date', // 'bill_received_date',
'vessel_number', // 'vessel_number',
'remark', // 'remark',
'is_transit_identified', // 'is_transit_identified',
]) // ])
->where('status', '!=', 'Delivered') // ->where('status', '!=', 'Delivered')
->get(); // ->get();
$tableData = ImportTransit::where('status', '!=', 'Delivered')->get();
if ($tableData->isEmpty()) { if ($tableData->isEmpty()) {
$this->info('No pending Import Transit records found. Mail skipped.'); $this->info('No pending Import Transit records found. Mail skipped.');
return; return;
@@ -101,10 +106,19 @@ class SendImportTransit extends Command
$mailSubject = 'Daily Import Transit Report'; $mailSubject = 'Daily Import Transit Report';
$fileName = 'reports/pending_import_shipment_' . now()->format('Ymd_His') . '.xlsx';
Excel::store(
new ImportTransitReportExport($tableData),
$fileName,
'local'
);
$mail = new ImportTransitMail( $mail = new ImportTransitMail(
$scheduleType, $scheduleType,
$tableData, $tableData,
$mailSubject $mailSubject,
$fileName
); );
$toEmails = collect(explode(',', $rule->email)) $toEmails = collect(explode(',', $rule->email))

View File

@@ -9,6 +9,7 @@ use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content; use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope; use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Mail\Mailables\Attachment;
class ImportTransitMail extends Mailable class ImportTransitMail extends Mailable
{ {
@@ -20,14 +21,17 @@ class ImportTransitMail extends Mailable
public $mailSubject; public $mailSubject;
public $excelPath;
/** /**
* Create a new message instance. * Create a new message instance.
*/ */
public function __construct($scheduleType, $tableData, $mailSubject) public function __construct($scheduleType, $tableData, $mailSubject, $excelPath)
{ {
$this->scheduleType = $scheduleType; $this->scheduleType = $scheduleType;
$this->tableData = $tableData ?? []; $this->tableData = $tableData ?? [];
$this->mailSubject = $mailSubject ?? 'Import Transit'; $this->mailSubject = $mailSubject ?? 'Import Transit';
$this->excelPath = $excelPath;
} }
/** /**
@@ -90,6 +94,14 @@ class ImportTransitMail extends Mailable
*/ */
public function attachments(): array public function attachments(): array
{ {
return []; return [
Attachment::fromStorageDisk(
'local',
$this->excelPath
)->as('Import_Transit_Report.xlsx')
->withMime(
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
),
];
} }
} }