Files
numstation-web/app/Exports/BookkeepingDocumentLibraryExport.php

50 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2023-12-22 12:35:55 +08:00
<?php
declare(strict_types=1);
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Storage;
class BookkeepingDocumentLibraryExport implements FromCollection, WithMapping, WithHeadings
{
protected $documents;
public function __construct($documents)
{
$this->documents = $documents;
}
public function collection()
{
return $this->documents;
}
public function map($documents): array
{
return [
$documents->file_name,
(strtolower(app()->getLocale()) == 'zh_hk' ? $documents->name_chinese : $documents->name_english),
$documents->category_name,
$documents->user_name,
Storage::exists($documents->file_path) ? (round(Storage::size($documents->file_path) / 1000) . 'KB') : '-',
$documents->created_at->format('Ymd-H:i'),
];
}
public function headings(): array
{
return [
'Document Name',
'Company',
'Document Category',
'Upload User',
'Document Size',
'Date Uploaded',
];
}
}