Files
xin-procurement/app/Exports/BillBatchExport.php
T
2026-10-30 10:51:09 +08:00

38 lines
1.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Exports;
use App\Models\BillModel;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
/**
* 门店账单批量导出:同一门店的账单合并在一张工作表,不同门店拆分为多个工作表
*/
class BillBatchExport implements WithMultipleSheets
{
/**
* @param Collection<int, BillModel> $bills 导出账单(with store)
*/
public function __construct(private readonly Collection $bills)
{
}
/**
* @return array<int, BillExport>
*/
public function sheets(): array
{
$usedNames = [];
$sheets = [];
foreach ($this->bills->groupBy('store_id') as $storeBills) {
$store = $storeBills->first()->store;
$storeId = (int) $storeBills->first()->store_id;
$sheetTitle = SheetName::make($store->name ?? ('门店#' . $storeId), $storeId, $usedNames);
$sheets[] = new BillExport($storeBills->values(), 0, $sheetTitle);
}
return $sheets;
}
}