Added import transit export excel file page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 16s
Laravel Pint / pint (pull_request) Successful in 2m14s
Laravel Larastan / larastan (pull_request) Failing after 3m38s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 16s
Laravel Pint / pint (pull_request) Successful in 2m14s
Laravel Larastan / larastan (pull_request) Failing after 3m38s
This commit is contained in:
97
app/Exports/ImportTransitReportExport.php
Normal file
97
app/Exports/ImportTransitReportExport.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
|
||||
class ImportTransitReportExport implements FromCollection, WithHeadings, WithMapping, WithEvents
|
||||
{
|
||||
protected $data;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'No',
|
||||
'CRI RFQ Number',
|
||||
'Requestor',
|
||||
'Shipper',
|
||||
'Shipper Location',
|
||||
'Shipper Invoice',
|
||||
'Shipper Invoice Date',
|
||||
'Custom Agent Name',
|
||||
'ETA',
|
||||
'Status',
|
||||
'Delivery Location',
|
||||
'ETD Date',
|
||||
'Remark',
|
||||
];
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
return collect($this->data);
|
||||
}
|
||||
|
||||
public function map($row): array
|
||||
{
|
||||
static $srNo = 0;
|
||||
$srNo++;
|
||||
|
||||
return [
|
||||
$srNo,
|
||||
$row->cri_rfq_number,
|
||||
$row->requester,
|
||||
$row->shipper,
|
||||
$row->shipper_location,
|
||||
$row->shipper_invoice,
|
||||
$row->shipper_invoice_date,
|
||||
$row->customs_agent_name,
|
||||
$row->eta_date,
|
||||
$row->status,
|
||||
$row->delivery_location,
|
||||
$row->etd_date,
|
||||
$row->remark,
|
||||
];
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
|
||||
$rowNumber = 2; // Excel row starts after header
|
||||
|
||||
foreach ($this->data as $row) {
|
||||
|
||||
if ((int) $row->is_transit_identified == 1) {
|
||||
|
||||
$event->sheet
|
||||
->getStyle("A{$rowNumber}:M{$rowNumber}")
|
||||
->applyFromArray([
|
||||
'fill' => [
|
||||
'fillType' => Fill::FILL_SOLID,
|
||||
'startColor' => [
|
||||
'rgb' => 'FFFF00',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$rowNumber++;
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user