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

View File

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