89 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Exports;
 | |
| 
 | |
| use Maatwebsite\Excel\Concerns\FromCollection;
 | |
| use Maatwebsite\Excel\Concerns\WithHeadings;
 | |
| use Maatwebsite\Excel\Concerns\WithTitle;
 | |
| use Maatwebsite\Excel\Concerns\WithStyles;
 | |
| use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
 | |
| 
 | |
| class DetailNampanExport implements FromCollection, WithHeadings, WithTitle, WithStyles
 | |
| {
 | |
|     private $data;
 | |
| 
 | |
|     public function __construct($data)
 | |
|     {
 | |
|         $this->data = $data;
 | |
|     }
 | |
| 
 | |
|     public function collection()
 | |
|     {
 | |
|         $collection = collect();
 | |
| 
 | |
|         // Add individual nampan data
 | |
|         if (isset($this->data['nampan'])) {
 | |
|             foreach ($this->data['nampan'] as $item) {
 | |
|                 $collection->push([
 | |
|                     $item['nama_nampan'],
 | |
|                     $item['jumlah_item_terjual'],
 | |
|                     $item['berat_terjual'],
 | |
|                     $item['pendapatan'],
 | |
|                 ]);
 | |
|             }
 | |
|         }
 | |
|         if (isset($this->data['rekap_harian'])) {
 | |
|             $rekap = $this->data['rekap_harian'];
 | |
|             $collection->push([
 | |
|                 'REKAP TOTAL',
 | |
|                 $rekap['total_item_terjual'],
 | |
|                 $rekap['total_berat_terjual'],
 | |
|                 $rekap['total_pendapatan'],
 | |
|             ]);
 | |
|         }
 | |
|         return $collection;
 | |
|     }
 | |
| 
 | |
|     public function headings(): array
 | |
|     {
 | |
|         return [
 | |
|             'Nama Nampan',
 | |
|             'Jumlah Item Terjual',
 | |
|             'Berat Terjual',
 | |
|             'Pendapatan'
 | |
|         ];
 | |
|     }
 | |
| 
 | |
|     public function title(): string
 | |
|     {
 | |
|         $filterInfo = $this->data['filter'] ?? [];
 | |
|         $tanggal = $filterInfo['tanggal'] ?? 'Unknown';
 | |
|         return "Detail Nampan {$tanggal}";
 | |
|     }
 | |
| 
 | |
|     public function styles(Worksheet $sheet)
 | |
|     {
 | |
|         $styles = [
 | |
|             1 => ['font' => ['bold' => true]],
 | |
|         ];
 | |
| 
 | |
|         if (isset($this->data['rekap_harian'])) {
 | |
|             $lastRow = 1;
 | |
|             if (isset($this->data['nampan'])) {
 | |
|                 $lastRow += count($this->data['nampan']);
 | |
|             }
 | |
|             $lastRow++;
 | |
| 
 | |
|             $styles[$lastRow] = [
 | |
|                 'font' => ['bold' => true],
 | |
|                 'fill' => [
 | |
|                     'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
 | |
|                     'startColor' => ['argb' => 'FFE2E3E5'],
 | |
|                 ],
 | |
|             ];
 | |
|         }
 | |
| 
 | |
|         return $styles;
 | |
|     }
 | |
| }
 |