fix(顾家对账): 统一数量和金额显示精度 #1301

Merged
chenxi merged 1 commits from fix/chenxi-kuka-quantity-format into main 2026-11-20 11:03:32 +08:00
2 changed files with 37 additions and 18 deletions

View File

@ -296,16 +296,16 @@ class KukaReconciliationPageData
ksort($inventory, SORT_NATURAL);
$generatedAt = now()->format('Y-m-d H:i:s');
$postingRows = array_map(static fn (array $row): array => [
$postingRows = array_map(fn (array $row): array => [
$row['year'],
$row['month'],
$row['material_number'],
$row['description'],
$row['quantity'],
$this->formatQuantity($row['quantity']),
$row['unit_price'],
$row['supplier_amount'],
], array_values($posting));
$inventoryRows = array_map(static fn (array $row): array => [
$inventoryRows = array_map(fn (array $row): array => [
$row['year'],
$row['month'],
$row['supplier_account'],
@ -313,8 +313,8 @@ class KukaReconciliationPageData
$row['supplier_name'],
$row['material_number'],
$row['description'],
$row['quantity'],
$row['quantity'],
$this->formatQuantity($row['quantity']),
$this->formatQuantity($row['quantity']),
'',
'',
'',
@ -332,19 +332,19 @@ class KukaReconciliationPageData
'',
'',
$generatedAt,
$row['quantity'],
$row['quantity'],
$this->formatQuantity($row['quantity']),
$this->formatQuantity($row['quantity']),
], array_values($inventory));
$views = [
'posting-data' => $this->paginate($postingRows, $page),
'toc-orders' => $this->paginate(array_map(static fn (array $row): array => [
'toc-orders' => $this->paginate(array_map(fn (array $row): array => [
$row['year'],
$row['month'],
$row['order_no'],
$row['material_number'],
$row['description'],
$row['quantity'],
$this->formatQuantity($row['quantity']),
], $lineItems), $page),
'lingshan-virtual-posting' => $this->paginate(
$this->virtualRows($lineItems, $generatedAt),
@ -403,7 +403,7 @@ class KukaReconciliationPageData
(string) ($index + 1),
$row['material_number'],
$row['product_name'],
$row['quantity'],
$this->formatQuantity($row['quantity']),
$row['unit_price'],
$row['supplier_amount'],
$row['sales_unit_price'],
@ -426,13 +426,13 @@ class KukaReconciliationPageData
*/
private function erpRows(array $lineItems): array
{
return array_map(static fn (array $row): array => [
return array_map(fn (array $row): array => [
$row['year'],
$row['month'],
$row['store'],
$row['order_no'],
$row['product_code'],
$row['quantity'],
$this->formatQuantity($row['quantity']),
$row['internal_order_no'],
'0',
$row['sales_unit_price'],
@ -470,7 +470,7 @@ class KukaReconciliationPageData
*/
private function invoiceRows(array $lineItems): array
{
return array_map(static fn (array $row): array => [
return array_map(fn (array $row): array => [
$row['year'],
$row['month'],
self::INVOICE_COMPANY,
@ -480,7 +480,7 @@ class KukaReconciliationPageData
$row['model_spec'],
self::INVOICE_TAX_CLASSIFICATION,
'套',
$row['quantity'],
$this->formatQuantity($row['quantity']),
$row['sales_amount'],
'0.13',
self::INVOICE_TITLE,
@ -744,6 +744,18 @@ class KukaReconciliationPageData
return $number === null ? '' : number_format((float) $number, 2, '.', '');
}
private function formatQuantity(mixed $value): string
{
$number = $this->normalizeDecimal($value);
if ($number === null) {
return '';
}
$formatted = rtrim(rtrim(number_format((float) $number, 4, '.', ''), '0'), '.');
return (float) $formatted === 0.0 ? '0' : $formatted;
}
private function multiplyMoney(string $left, string $right): string
{
$value = function_exists('bcmul')

View File

@ -158,13 +158,16 @@ class KukaReconciliationPageDataTest extends TestCase
$this->assertNotContains((int) $numericOrderNo, $shippingBindings, true);
$this->assertSame([[
'2026', '10', 'M-1', '测试物料', '2.0000', '10.00', '20.00',
'2026', '10', 'M-1', '测试物料', '2', '10.00', '20.00',
]], $data['views']['posting-data']['rows']);
$this->assertSame(2, $data['views']['toc-orders']['total']);
$this->assertSame('2', $data['views']['toc-orders']['rows'][0][5]);
$virtual = $data['views']['lingshan-virtual-posting']['rows'][0];
$this->assertSame('1', $virtual[2]);
$this->assertSame('M-1', $virtual[3]);
$this->assertSame('2', $virtual[5]);
$this->assertSame('10.00', $virtual[6]);
$this->assertSame('20.00', $virtual[7]);
$this->assertSame('11.11', $virtual[8]);
$this->assertSame('22.22', $virtual[9]);
@ -175,6 +178,9 @@ class KukaReconciliationPageDataTest extends TestCase
$this->assertSame('EXPRESS-1', $virtual[14]);
$erp = $data['views']['erp-product-import']['rows'][0];
$this->assertSame('2', $erp[5]);
$this->assertSame('11.11', $erp[8]);
$this->assertSame('22.22', $erp[9]);
$this->assertSame('13800000000', $erp[18]);
$this->assertSame('江苏省常州市武进区测试路1号', $erp[25]);
$this->assertSame('顺丰', $erp[26]);
@ -184,6 +190,7 @@ class KukaReconciliationPageDataTest extends TestCase
$invoice = $data['views']['invoice-entry-template']['rows'][0];
$this->assertSame('宁波顾家望业家居有限公司', $invoice[2]);
$this->assertSame('1050201010000000000', $invoice[7]);
$this->assertSame('2', $invoice[9]);
$this->assertSame('22.22', $invoice[10]);
$this->assertSame('0.13', $invoice[11]);
@ -191,9 +198,9 @@ class KukaReconciliationPageDataTest extends TestCase
$this->assertSame('435421', $inventory[2]);
$this->assertSame('OA01207289', $inventory[3]);
$this->assertSame('M-1', $inventory[5]);
$this->assertSame('3.0000', $inventory[7]);
$this->assertSame('3.0000', $inventory[8]);
$this->assertSame('3.0000', $inventory[27]);
$this->assertSame('3', $inventory[7]);
$this->assertSame('3', $inventory[8]);
$this->assertSame('3', $inventory[27]);
}
/**