账单导出

This commit is contained in:
liu
2026-09-25 00:30:02 +08:00
parent 9831355386
commit 5123065def
5 changed files with 86 additions and 57 deletions
+23 -14
View File
@@ -60,13 +60,14 @@ class BillExportTest extends ProcurementTestCase
]);
}
/** 单独导出:账单内同商品合并(数量累加、单价加权平均),费用行取账单自身字段 */
/** 单独导出:账单内同商品合并(数量累加、单价加权平均),费用行取账单自身字段;
* 包规列=包规+单位合并;单价列=每件价÷包规斤数 折算零售价+单价单位(散装无法折算按原价) */
public function test_export_merges_items_within_bill(): void
{
$root = ProductCategoryModel::create(['name' => '蔬菜', 'parent_id' => 0, 'sort' => 0, 'status' => 1]);
$store = StoreModel::factory()->create();
$productA = ProductModel::factory()->create(['category_id' => $root->id]);
$productB = ProductModel::factory()->create(['category_id' => $root->id]);
$productA = ProductModel::factory()->create(['category_id' => $root->id, 'spec' => '10', 'unit' => '斤/箱']);
$productB = ProductModel::factory()->create(['category_id' => $root->id, 'spec' => '散装', 'unit' => '筐']);
$bill = $this->makeBill($store, ['after_sale' => '-8.00']);
// 同一商品两条明细:10×2.00 + 6×3.00 → 数量 16、金额 38.00、加权单价 2.37
@@ -97,30 +98,38 @@ class BillExportTest extends ProcurementTestCase
if ($rowA === null || $rowB === null) {
return false;
}
// 账单内同商品合并:数量 16、加权单价 2.37、金额 38.00
if ((float) $rowA[4] !== 2.37 || (int) $rowA[5] !== 16 || (float) $rowA[7] !== 38.0) {
// 包规列=包规+单位合并;单价列=每件价÷每件斤数+单价单位(A:2.37÷10=0.23元/斤)
if ($rowA[2] !== '10斤/箱' || $rowA[3] !== '0.23元/斤') {
return false;
}
if ((int) $rowB[5] !== 4 || (float) $rowB[7] !== 20.0) {
// 散装无法折算 → 单价按每件原价显示(B:5.00元/斤)
if ($rowB[2] !== '散装筐' || $rowB[3] !== '5.00元/斤') {
return false;
}
// 账单内同商品合并:数量 16、金额 38.00
if ((int) $rowA[4] !== 16 || (float) $rowA[6] !== 38.0) {
return false;
}
if ((int) $rowB[4] !== 4 || (float) $rowB[6] !== 20.0) {
return false;
}
$summary = $rows->slice(6)->values();
// 合计:数量 20、商品金额 58.00;配送费 10.00;附加 30.00(筐 2 / 托盘 1);售后 -8.00;总金额 90.00
if ((int) $summary[0][5] !== 20 || (float) $summary[0][7] !== 58.0) {
if ((int) $summary[0][4] !== 20 || (float) $summary[0][6] !== 58.0) {
return false;
}
if ($summary[1][0] !== '配送费' || (float) $summary[1][7] !== 10.0) {
if ($summary[1][0] !== '配送费' || (float) $summary[1][6] !== 10.0) {
return false;
}
if (! str_contains((string) $summary[2][0], '筐 2 个 / 周转托盘 1 个') || (float) $summary[2][7] !== 30.0) {
if (! str_contains((string) $summary[2][0], '筐 2 个 / 周转托盘 1 个') || (float) $summary[2][6] !== 30.0) {
return false;
}
if (! str_contains((string) $summary[3][0], '售后金额') || (float) $summary[3][7] !== -8.0) {
if (! str_contains((string) $summary[3][0], '售后金额') || (float) $summary[3][6] !== -8.0) {
return false;
}
return (float) $summary[4][7] === 90.0;
return (float) $summary[4][6] === 90.0;
}
);
}
@@ -160,14 +169,14 @@ class BillExportTest extends ProcurementTestCase
$summary = $rows->slice(5)->values();
// 商品金额合计 20.00(仅蔬菜);配送费 10.00 / 附加 30.00 / 售后 0.00 全额;总金额 60.00
if ((float) $summary[0][7] !== 20.0) {
if ((float) $summary[0][6] !== 20.0) {
return false;
}
if ((float) $summary[1][7] !== 10.0 || (float) $summary[2][7] !== 30.0 || (float) $summary[3][7] !== 0.0) {
if ((float) $summary[1][6] !== 10.0 || (float) $summary[2][6] !== 30.0 || (float) $summary[3][6] !== 0.0) {
return false;
}
return (float) $summary[4][7] === 60.0;
return (float) $summary[4][6] === 60.0;
}
);
}