导出
This commit is contained in:
@@ -22,7 +22,8 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
/**
|
||||
* 采购单商品明细导出:系统全部未删除商品行(含本采购单无订货的商品,数量 0),
|
||||
* 支持按供应商筛选;行尾合计 + 门店列合计;数量/金额/门店数量按值条件填色;
|
||||
* 序号/分类/包规/单位/成本/单价/实际称重/金额列在表格中默认隐藏(数据照常导出,Excel 中可取消隐藏)
|
||||
* 序号/分类/包规/单位/成本/单价/实际称重/金额列在表格中默认隐藏(数据照常导出,Excel 中可取消隐藏);
|
||||
* 市场/数量/门店列列宽减半、列头自动换行;门店数量无数据显示空白(不显示 0)
|
||||
*/
|
||||
class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, WithStyles
|
||||
{
|
||||
@@ -222,7 +223,10 @@ class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, W
|
||||
$item['quantity'],
|
||||
$item['weight'],
|
||||
$item['amount'],
|
||||
], array_values($item['store_quantities']));
|
||||
], array_map(
|
||||
static fn (int $qty): int|string => $qty > 0 ? $qty : '',
|
||||
array_values($item['store_quantities']),
|
||||
));
|
||||
$totalQuantity = bcadd($totalQuantity, (string) $item['quantity'], 2);
|
||||
$totalWeight = bcadd($totalWeight, (string) $item['weight'], 3);
|
||||
$totalAmount = bcadd($totalAmount, (string) $item['amount'], 2);
|
||||
@@ -231,10 +235,10 @@ class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, W
|
||||
}
|
||||
}
|
||||
|
||||
// 合计行(行合计 + 门店列合计)
|
||||
// 合计行(行合计 + 门店列合计;门店无数据显示空白)
|
||||
$rows[] = array_merge(
|
||||
['', '', '合计', '', '', '', '', '', '', (float) $totalQuantity, (float) $totalWeight, (float) $totalAmount],
|
||||
array_values($storeTotals),
|
||||
array_map(static fn (int $qty): int|string => $qty > 0 ? $qty : '', array_values($storeTotals)),
|
||||
);
|
||||
$this->specialRows[++$rowIndex] = 'summary';
|
||||
$this->lastRow = $rowIndex;
|
||||
@@ -256,7 +260,8 @@ class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, W
|
||||
$this->collection();
|
||||
|
||||
$sheet->freezePane('A' . ($this->headerRow + 1));
|
||||
$widths = [6, 10, 20, 12, 12, 12, 8, 10, 12, 10, 12, 12];
|
||||
// 市场/数量列宽减半
|
||||
$widths = [6, 10, 20, 12, 6, 12, 8, 10, 12, 5, 12, 12];
|
||||
foreach ($widths as $index => $width) {
|
||||
$sheet->getColumnDimension(Coordinate::stringFromColumnIndex($index + 1))->setWidth($width);
|
||||
}
|
||||
@@ -265,7 +270,7 @@ class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, W
|
||||
$storeCount = count($storeIds);
|
||||
$lastColumn = Coordinate::stringFromColumnIndex(12 + max($storeCount, 1));
|
||||
foreach ($storeIds as $i => $storeId) {
|
||||
$sheet->getColumnDimension(Coordinate::stringFromColumnIndex(13 + $i))->setWidth(12);
|
||||
$sheet->getColumnDimension(Coordinate::stringFromColumnIndex(13 + $i))->setWidth(6);
|
||||
}
|
||||
|
||||
// 默认隐藏列:序号/分类/包规/单位/成本/单价/实际称重/金额(数据照常导出,Excel 中可取消隐藏)
|
||||
@@ -279,6 +284,11 @@ class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, W
|
||||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||||
->setVertical(Alignment::VERTICAL_CENTER);
|
||||
|
||||
// 列头自动换行(市场/数量/门店列较窄,表头文字折行显示)
|
||||
$sheet->getStyle('A' . $this->headerRow . ':' . $lastColumn . $this->headerRow)
|
||||
->getAlignment()
|
||||
->setWrapText(true);
|
||||
|
||||
// 表格区域(列头 → 合计行)添加所有边框
|
||||
$sheet->getStyle('A' . $this->headerRow . ':' . $lastColumn . $this->lastRow)
|
||||
->getBorders()
|
||||
|
||||
Reference in New Issue
Block a user