导出
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -22,7 +22,8 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|||||||
/**
|
/**
|
||||||
* 采购单商品明细导出:系统全部未删除商品行(含本采购单无订货的商品,数量 0),
|
* 采购单商品明细导出:系统全部未删除商品行(含本采购单无订货的商品,数量 0),
|
||||||
* 支持按供应商筛选;行尾合计 + 门店列合计;数量/金额/门店数量按值条件填色;
|
* 支持按供应商筛选;行尾合计 + 门店列合计;数量/金额/门店数量按值条件填色;
|
||||||
* 序号/分类/包规/单位/成本/单价/实际称重/金额列在表格中默认隐藏(数据照常导出,Excel 中可取消隐藏)
|
* 序号/分类/包规/单位/成本/单价/实际称重/金额列在表格中默认隐藏(数据照常导出,Excel 中可取消隐藏);
|
||||||
|
* 市场/数量/门店列列宽减半、列头自动换行;门店数量无数据显示空白(不显示 0)
|
||||||
*/
|
*/
|
||||||
class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, WithStyles
|
class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, WithStyles
|
||||||
{
|
{
|
||||||
@@ -222,7 +223,10 @@ class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, W
|
|||||||
$item['quantity'],
|
$item['quantity'],
|
||||||
$item['weight'],
|
$item['weight'],
|
||||||
$item['amount'],
|
$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);
|
$totalQuantity = bcadd($totalQuantity, (string) $item['quantity'], 2);
|
||||||
$totalWeight = bcadd($totalWeight, (string) $item['weight'], 3);
|
$totalWeight = bcadd($totalWeight, (string) $item['weight'], 3);
|
||||||
$totalAmount = bcadd($totalAmount, (string) $item['amount'], 2);
|
$totalAmount = bcadd($totalAmount, (string) $item['amount'], 2);
|
||||||
@@ -231,10 +235,10 @@ class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, W
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 合计行(行合计 + 门店列合计)
|
// 合计行(行合计 + 门店列合计;门店无数据显示空白)
|
||||||
$rows[] = array_merge(
|
$rows[] = array_merge(
|
||||||
['', '', '合计', '', '', '', '', '', '', (float) $totalQuantity, (float) $totalWeight, (float) $totalAmount],
|
['', '', '合计', '', '', '', '', '', '', (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->specialRows[++$rowIndex] = 'summary';
|
||||||
$this->lastRow = $rowIndex;
|
$this->lastRow = $rowIndex;
|
||||||
@@ -256,7 +260,8 @@ class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, W
|
|||||||
$this->collection();
|
$this->collection();
|
||||||
|
|
||||||
$sheet->freezePane('A' . ($this->headerRow + 1));
|
$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) {
|
foreach ($widths as $index => $width) {
|
||||||
$sheet->getColumnDimension(Coordinate::stringFromColumnIndex($index + 1))->setWidth($width);
|
$sheet->getColumnDimension(Coordinate::stringFromColumnIndex($index + 1))->setWidth($width);
|
||||||
}
|
}
|
||||||
@@ -265,7 +270,7 @@ class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, W
|
|||||||
$storeCount = count($storeIds);
|
$storeCount = count($storeIds);
|
||||||
$lastColumn = Coordinate::stringFromColumnIndex(12 + max($storeCount, 1));
|
$lastColumn = Coordinate::stringFromColumnIndex(12 + max($storeCount, 1));
|
||||||
foreach ($storeIds as $i => $storeId) {
|
foreach ($storeIds as $i => $storeId) {
|
||||||
$sheet->getColumnDimension(Coordinate::stringFromColumnIndex(13 + $i))->setWidth(12);
|
$sheet->getColumnDimension(Coordinate::stringFromColumnIndex(13 + $i))->setWidth(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 默认隐藏列:序号/分类/包规/单位/成本/单价/实际称重/金额(数据照常导出,Excel 中可取消隐藏)
|
// 默认隐藏列:序号/分类/包规/单位/成本/单价/实际称重/金额(数据照常导出,Excel 中可取消隐藏)
|
||||||
@@ -279,6 +284,11 @@ class PurchaseOrderExport implements FromCollection, WithStrictNullComparison, W
|
|||||||
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
->setHorizontal(Alignment::HORIZONTAL_CENTER)
|
||||||
->setVertical(Alignment::VERTICAL_CENTER);
|
->setVertical(Alignment::VERTICAL_CENTER);
|
||||||
|
|
||||||
|
// 列头自动换行(市场/数量/门店列较窄,表头文字折行显示)
|
||||||
|
$sheet->getStyle('A' . $this->headerRow . ':' . $lastColumn . $this->headerRow)
|
||||||
|
->getAlignment()
|
||||||
|
->setWrapText(true);
|
||||||
|
|
||||||
// 表格区域(列头 → 合计行)添加所有边框
|
// 表格区域(列头 → 合计行)添加所有边框
|
||||||
$sheet->getStyle('A' . $this->headerRow . ':' . $lastColumn . $this->lastRow)
|
$sheet->getStyle('A' . $this->headerRow . ':' . $lastColumn . $this->lastRow)
|
||||||
->getBorders()
|
->getBorders()
|
||||||
|
|||||||
@@ -403,7 +403,8 @@ const PurchaseOrderPage: React.FC = () => {
|
|||||||
|
|
||||||
const res = await updatePurchaseRow(detail.purchase.id!, row.product_id, params);
|
const res = await updatePurchaseRow(detail.purchase.id!, row.product_id, params);
|
||||||
message.success(`已更新 ${res.data.data?.count ?? 0} 条订货明细`);
|
message.success(`已更新 ${res.data.data?.count ?? 0} 条订货明细`);
|
||||||
await loadDetail(detail.purchase.id!);
|
const res1 = await getPurchaseDetail(detail.purchase.id!);
|
||||||
|
setDetail(res1.data.data ?? null);
|
||||||
await tableRef.current?.reload();
|
await tableRef.current?.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user