D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
forge
/
developers.ghanempharmacy.com
/
app
/
Exports
/
Filename :
RefundRequestExport.php
back
Copy
<?php namespace App\Exports; use Illuminate\Contracts\View\View; use Maatwebsite\Excel\Concerns\Exportable; use Maatwebsite\Excel\Concerns\FromView; use Maatwebsite\Excel\Events\AfterSheet; use Maatwebsite\Excel\Concerns\WithEvents; use Maatwebsite\Excel\Concerns\WithStyles; use Maatwebsite\Excel\Concerns\WithHeadings; use Maatwebsite\Excel\Concerns\ShouldAutoSize; use Maatwebsite\Excel\Concerns\WithColumnWidths; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Alignment; class RefundRequestExport implements FromView, ShouldAutoSize, WithStyles, WithColumnWidths, WithHeadings, WithEvents { use Exportable; protected $data; public function __construct($data) { $this->data = $data; } public function view(): View { return view('file-exports.refund-request-list', [ 'data' => $this->data, ]); } public function columnWidths(): array { return [ 'A' => 15, 'D' => 25, 'J' => 25, ]; } public function styles(Worksheet $sheet) { $sheet->getStyle('A1:A2')->getFont()->setBold(true); $sheet->getStyle('A3:J3')->getFont()->setBold(true)->getColor() ->setARGB('FFFFFF'); $sheet->getStyle('A3:J3')->getFill()->applyFromArray([ 'fillType' => 'solid', 'rotation' => 0, 'color' => ['rgb' => '063C93'], ]); $sheet->setShowGridlines(false); return [ // Define the style for cells with data 'A1:J' . ($this->data['refundList']->count() + 3) => [ 'borders' => [ 'allBorders' => [ 'borderStyle' => Border::BORDER_THIN, 'color' => ['argb' => '000000'], // Specify the color of the border (optional) ], ], 'alignment' => [ 'wrapText' => true, ], ], ]; } public function registerEvents(): array { return [ AfterSheet::class => function (AfterSheet $event) { $event->sheet->getStyle('A1:J1') // Adjust the range as per your needs ->getAlignment() ->setHorizontal(Alignment::HORIZONTAL_CENTER) ->setVertical(Alignment::VERTICAL_CENTER); $event->sheet->getStyle('A3:J' . ($this->data['refundList']->count() + 3)) // Adjust the range as per your needs ->getAlignment() ->setHorizontal(Alignment::HORIZONTAL_CENTER) ->setVertical(Alignment::VERTICAL_CENTER); $event->sheet->getStyle('A2:J2') // Adjust the range as per your needs ->getAlignment() ->setHorizontal(Alignment::HORIZONTAL_LEFT) ->setVertical(Alignment::VERTICAL_CENTER); $event->sheet->getStyle('D4:D' . ($this->data['refundList']->count() + 3)) // Adjust the range as per your needs ->getAlignment() ->setHorizontal(Alignment::HORIZONTAL_LEFT) ->setVertical(Alignment::VERTICAL_CENTER); if (isset($this->data['data-from']) && $this->data['data-from'] == 'vendor') { $event->sheet->mergeCells('I3:J3'); $this->data['refundList']->each(function ($item, $index) use ($event) { $index += 4; $event->sheet->mergeCells("I$index:J$index"); }); } $event->sheet->mergeCells('A1:J1'); $event->sheet->mergeCells('A2:B2'); $event->sheet->mergeCells('C2:J2'); $event->sheet->getRowDimension(1)->setRowHeight(30); $event->sheet->getRowDimension(2)->setRowHeight(100); $event->sheet->getRowDimension(3)->setRowHeight(30); $event->sheet->getDefaultRowDimension()->setRowHeight(50); }, ]; } public function headings(): array { return [ '1' ]; } }