导出优化
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Models\StoreModel;
|
||||
use App\Models\StoreOrderModel;
|
||||
use App\Models\SupplierModel;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
|
||||
/**
|
||||
* 采购单导出(仅 Excel 表格,全品类):xlsx Content-Type /
|
||||
@@ -188,6 +189,48 @@ class ExportTest extends ProcurementTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/** 商品明细导出:序号/分类/包规/单位/成本/单价/实际称重/金额列在表格中默认隐藏(数据照常导出) */
|
||||
public function test_export_hides_detail_columns_by_default(): void
|
||||
{
|
||||
[$purchase] = $this->buildPurchaseWithSuppliers();
|
||||
|
||||
$export = new PurchaseOrderExport($purchase);
|
||||
$sheet = (new Spreadsheet())->getActiveSheet();
|
||||
$export->styles($sheet);
|
||||
|
||||
// 序号A/分类B/包规F/单位G/成本H/单价I/实际称重K/金额L 默认隐藏
|
||||
foreach (['A', 'B', 'F', 'G', 'H', 'I', 'K', 'L'] as $column) {
|
||||
$this->assertFalse($sheet->getColumnDimension($column)->getVisible(), "列 {$column} 应默认隐藏");
|
||||
}
|
||||
// 品名/供应商/市场/数量与门店列保持可见
|
||||
foreach (['C', 'D', 'E', 'J', 'M', 'N'] as $column) {
|
||||
$this->assertTrue($sheet->getColumnDimension($column)->getVisible(), "列 {$column} 应保持可见");
|
||||
}
|
||||
// 数据照常导出:列头与合计行仍含隐藏列数据
|
||||
$rows = $export->collection()->values();
|
||||
$header = $rows[3];
|
||||
$this->assertSame('序号', $header[0]);
|
||||
$this->assertSame('金额', $header[11]);
|
||||
$total = $rows->last();
|
||||
$this->assertSame('合计', $total[2]);
|
||||
$this->assertSame(45.0, (float) $total[11]);
|
||||
}
|
||||
|
||||
/** 商品明细导出:范围=全部未删除商品(含下架)∪ 本采购单有订货商品;已删除且无订货的商品不导出 */
|
||||
public function test_export_scope_includes_off_shelf_but_not_deleted(): void
|
||||
{
|
||||
[$purchase] = $this->buildPurchaseWithSuppliers();
|
||||
$offShelf = ProductModel::factory()->create(['status' => ProductModel::STATUS_OFF, 'cost_price' => '8.00']);
|
||||
$deleted = ProductModel::factory()->create(['status' => ProductModel::STATUS_ON, 'cost_price' => '9.00']);
|
||||
$deleted->delete();
|
||||
|
||||
$rows = (new PurchaseOrderExport($purchase))->collection()->values();
|
||||
$names = $rows->slice(4, -1)->map(static fn ($row) => $row[2])->all();
|
||||
|
||||
$this->assertContains($offShelf->name, $names);
|
||||
$this->assertNotContains($deleted->name, $names);
|
||||
}
|
||||
|
||||
/** 商品明细导出:按供应商筛选(范围行标注供应商,仅含其商品行) */
|
||||
public function test_export_supplier_filter(): void
|
||||
{
|
||||
@@ -307,8 +350,9 @@ class ExportTest extends ProcurementTestCase
|
||||
|| (int) $vegRow[3] !== 2 || (int) $vegRow[4] !== 3) {
|
||||
return false;
|
||||
}
|
||||
$totalA = $rowsA->last();
|
||||
if ($totalA[0] !== '合计' || (int) $totalA[1] !== 5 || (int) $totalA[3] !== 2 || (int) $totalA[4] !== 3) {
|
||||
// 无合计行:末行即最后一条明细
|
||||
$lastA = $rowsA->last();
|
||||
if ($lastA[0] === '合计') {
|
||||
return false;
|
||||
}
|
||||
// 供应商乙·岳各庄:肉 1 件;门店列仅门店A
|
||||
@@ -366,10 +410,10 @@ class ExportTest extends ProcurementTestCase
|
||||
if ($titles !== [$supplier->name . '·岳各庄', $supplier->name . '·新发地', $supplier->name . '·未设置']) {
|
||||
return false;
|
||||
}
|
||||
// 每个工作表仅含本市场商品
|
||||
// 每个工作表仅含本市场商品(无合计行,明细自第 4 行起)
|
||||
foreach ($sheets as $sheet) {
|
||||
$rows = $sheet->collection()->values();
|
||||
$names = $rows->slice(3, -1)->map(static fn ($row) => $row[0])->values()->all();
|
||||
$names = $rows->slice(3)->map(static fn ($row) => $row[0])->values()->all();
|
||||
$expected = match (true) {
|
||||
str_ends_with($sheet->title(), '新发地') => [$vegA->name],
|
||||
str_ends_with($sheet->title(), '岳各庄') => [$vegB->name],
|
||||
|
||||
Reference in New Issue
Block a user