账单导出

This commit is contained in:
2026-10-30 11:17:15 +08:00
parent 7366d88baf
commit f91939f1f0
137 changed files with 1227 additions and 74 deletions
+34 -9
View File
@@ -139,13 +139,18 @@ class BillExportTest extends ProcurementTestCase
);
}
/** 批量导出:同一门店多张账单合并在一张工作表,不同门店拆分工作表 */
/** 批量导出:同一门店多账单的同商品与费用合并为一张表,不同门店拆分工作表 */
public function test_batch_export_groups_bills_by_store(): void
{
$root = ProductCategoryModel::create(['name' => '蔬菜', 'parent_id' => 0, 'sort' => 0, 'status' => 1]);
$storeA = StoreModel::factory()->create(['name' => '门店A']);
$storeB = StoreModel::factory()->create(['name' => '门店B']);
$product = ProductModel::factory()->create(['category_id' => $root->id]);
$product = ProductModel::factory()->create([
'category_id' => $root->id,
'spec' => '10',
'unit' => '斤/箱',
'price_unit' => '元/斤',
]);
$billA1 = $this->makeBill($storeA);
$billA2 = $this->makeBill($storeA);
@@ -161,7 +166,7 @@ class BillExportTest extends ProcurementTestCase
Excel::assertDownloaded(
'门店账单_批量导出.xlsx',
static function (BillBatchExport $export) use ($billA1, $billA2, $billB): bool {
static function (BillBatchExport $export) use ($billB, $product): bool {
$sheets = collect($export->sheets());
if ($sheets->count() !== 2) {
return false;
@@ -174,12 +179,32 @@ class BillExportTest extends ProcurementTestCase
}
$rowsA = $sheetA->collection()->values();
$billTitlesA = $rowsA->filter(static fn (array $row): bool => str_contains((string) $row[0], '门店账单 '));
if ($rowsA->count() !== 21 || $billTitlesA->count() !== 2) {
$headersA = $rowsA->filter(static fn (array $row): bool => $row[0] === '序号');
if ($rowsA->count() !== 10 || $headersA->count() !== 1) {
return false;
}
if (! str_contains((string) $rowsA[0][0], $billA1->bill_no)
|| ! str_contains((string) $rowsA[11][0], $billA2->bill_no)) {
if (! str_contains((string) $rowsA[0][0], '合并导出(2张)')
|| ! str_contains((string) $rowsA[1][0], '账单数量:2')) {
return false;
}
// 同商品合并:数量 2+3=5、重量 20+30=50、金额 4+9=13;加权单价 2.60,折算 0.26元/斤
$detail = $rowsA[4];
if ($detail[1] !== $product->name || $detail[4] !== '0.26元/斤'
|| (int) $detail[5] !== 5 || (float) $detail[6] !== 50.0 || (float) $detail[7] !== 13.0) {
return false;
}
$summary = $rowsA->slice(5)->values();
if ((int) $summary[0][5] !== 5 || (float) $summary[0][7] !== 13.0) {
return false;
}
// 配送费 10×2=20;附加 30×2=60(筐 4 / 托盘 2);总金额 13+20+60=93
if ((float) $summary[1][7] !== 20.0 || (float) $summary[2][7] !== 60.0
|| ! str_contains((string) $summary[2][0], '筐 4 个 / 周转托盘 2 个')) {
return false;
}
if ((float) $summary[4][7] !== 93.0) {
return false;
}
@@ -290,7 +315,7 @@ class BillExportTest extends ProcurementTestCase
->assertJsonPath('success', false);
}
/** 小程序端批量导出:本店多账单合并工作表,混入他店账单时整批拒绝 */
/** 小程序端批量导出:本店多账单数据合并为一张表,混入他店账单时整批拒绝 */
public function test_mini_batch_export_scoped_to_own_store(): void
{
$root = ProductCategoryModel::create(['name' => '蔬菜', 'parent_id' => 0, 'sort' => 0, 'status' => 1]);
@@ -316,7 +341,7 @@ class BillExportTest extends ProcurementTestCase
return count($sheets) === 1
&& $sheets[0]->title() === '门店A'
&& $sheets[0]->collection()->count() === 21;
&& $sheets[0]->collection()->count() === 10;
}
);