50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use App\Models\IamPrincipal;
|
|
use App\Models\OrderedPassport;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithStyles;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
|
|
|
|
class dashboard_export_user implements FromCollection , WithHeadings , WithStyles
|
|
{
|
|
protected $recentTransactions;
|
|
|
|
public function __construct(array $recentTransactions)
|
|
{
|
|
$this->recentTransactions = collect($recentTransactions);
|
|
}
|
|
|
|
public function collection()
|
|
{
|
|
return $this->recentTransactions->map(function ($transaction) {
|
|
return [
|
|
$transaction['iam_principal']['first_name'] ?? 'Unknown',
|
|
$transaction['is_cart_order'] == 1 ? $transaction['carts']['passport']['passport_name'] : $transaction['order_passport']['passport_name'],
|
|
$transaction['is_cart_order'] == 1 ? $transaction['carts']['passport']['price'] : $transaction['order_passport']['price'],
|
|
];
|
|
});
|
|
}
|
|
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
'Name',
|
|
'Passport Name',
|
|
'Amount',
|
|
];
|
|
}
|
|
|
|
public function styles(Worksheet $sheet)
|
|
{
|
|
return [
|
|
// Style the first row (headings)
|
|
1 => ['font' => ['bold' => true]],
|
|
];
|
|
}
|
|
}
|