feat(顾家对账): 增加灵珊销售金额尾差调整 (#1334)

This commit is contained in:
chenxi 2026-11-21 09:14:13 +08:00
parent 5a27e64aaa
commit fe19763ffd
5 changed files with 124 additions and 0 deletions

View File

@ -144,6 +144,7 @@ class KukaReconciliationPageData
$orders = [];
$postingQuantityTotal = '0';
$postingSupplierAmountTotal = '0.00';
$postingRowSalesAmountTotal = '0.00';
$postingSalesAmountTotal = '0.00';
$supplierAmountTotal = '0.00';
$salesAmountTotal = '0.00';
@ -304,6 +305,10 @@ class KukaReconciliationPageData
$postingSupplierAmountTotal,
$supplierAmount,
);
$postingRowSalesAmountTotal = $this->addMoney(
$postingRowSalesAmountTotal,
$salesAmount,
);
}
if (! isset($inventory[$materialNumber])) {
@ -336,6 +341,10 @@ class KukaReconciliationPageData
$postingSupplierAmountTotal,
self::SALES_MARKUP_DIVISOR,
);
$virtualSalesRoundingAdjustment = $this->subtractMoney(
$postingSalesAmountTotal,
$postingRowSalesAmountTotal,
);
$postingRows = array_map(fn (array $row): array => [
$row['year'],
@ -423,6 +432,8 @@ class KukaReconciliationPageData
'posting_quantity_total' => $this->formatQuantity($postingQuantityTotal),
'posting_supplier_amount_total' => $postingSupplierAmountTotal,
'posting_sales_amount_total' => $postingSalesAmountTotal,
'posting_row_sales_amount_total' => $postingRowSalesAmountTotal,
'virtual_sales_rounding_adjustment' => $virtualSalesRoundingAdjustment,
'toc_quantity_total' => $this->formatQuantity($postingQuantityTotal),
'order_count' => count($orders),
'skipped_missing_material_rows' => $skippedMissingMaterial,
@ -739,6 +750,8 @@ class KukaReconciliationPageData
'posting_quantity_total' => '0',
'posting_supplier_amount_total' => '0.00',
'posting_sales_amount_total' => '0.00',
'posting_row_sales_amount_total' => '0.00',
'virtual_sales_rounding_adjustment' => '0.00',
'toc_quantity_total' => '0',
'order_count' => 0,
'skipped_missing_material_rows' => 0,
@ -860,6 +873,15 @@ class KukaReconciliationPageData
);
}
private function subtractMoney(string $left, string $right): string
{
$value = function_exists('bcsub')
? bcsub($left, $right, 4)
: (string) ((float) $left - (float) $right);
return number_format((float) $value, 2, '.', '');
}
private function connection(): ConnectionInterface
{
return $this->databases->connection($this->connectionName());

View File

@ -209,6 +209,12 @@
'pagination' => $viewData,
'numericColumns' => $tab['numeric_columns'],
'moneyColumns' => $tab['money_columns'] ?? [],
'salesRoundingAdjustment' => $tab['slug'] === 'lingshan-virtual-posting'
? ($kukaReconciliation['summary']['virtual_sales_rounding_adjustment'] ?? '0.00')
: null,
'salesRoundingAdjustmentColumn' => $tab['slug'] === 'lingshan-virtual-posting'
? 9
: null,
'viewSlug' => $tab['slug'],
'notice' => $tab['slug'] === 'erp-product-import'
? ($kukaReconciliation['notices']['erp'] ?? null)

View File

@ -1,3 +1,7 @@
@php
$salesRoundingAdjustment = $salesRoundingAdjustment ?? null;
$salesRoundingAdjustmentColumn = $salesRoundingAdjustmentColumn ?? null;
@endphp
<section
class="kuka-source-table"
data-kuka-reconciliation-template="{{ $sourceSheet }}"
@ -62,6 +66,24 @@
</tr>
@endforelse
</tbody>
@if (
$salesRoundingAdjustment !== null
&& $salesRoundingAdjustmentColumn !== null
&& abs((float) $salesRoundingAdjustment) > 0.00001
&& $pagination['page'] === $pagination['last_page']
)
<tfoot>
<tr class="is-adjustment" aria-label="销售金额尾差调整">
<td colspan="{{ $salesRoundingAdjustmentColumn }}">销售金额尾差调整</td>
<td class="is-number">
{{ number_format((float) $salesRoundingAdjustment, 2, '.', '') }}
</td>
@if (count($headers) - $salesRoundingAdjustmentColumn - 1 > 0)
<td colspan="{{ count($headers) - $salesRoundingAdjustmentColumn - 1 }}"></td>
@endif
</tr>
</tfoot>
@endif
</table>
</div>
@ -222,6 +244,13 @@
.kuka-source-table__grid tbody tr:hover td {
background: var(--vip-content-accent-soft, #f7f0de);
}
.kuka-source-table__grid tfoot tr.is-adjustment td {
border-top: 2px solid var(--vip-content-accent, #b9954f);
border-bottom: 0;
background: var(--vip-content-accent-soft, #f7f0de);
color: var(--vip-content-accent-dark, #856632);
font-weight: 600;
}
.kuka-source-table__grid td:last-child {
border-right: 0;
}

View File

@ -112,6 +112,71 @@ class KukaReconciliationPageTest extends FeatureTestCase
->assertSeeText('发货数量');
}
public function test_virtual_posting_renders_dynamic_sales_rounding_adjustment(): void
{
$connection = DB::connection('business_mirror');
$now = now();
$connection->table('kuka_posting_base_imports')->insert([
'company_id' => $this->company->id,
'period' => '2026-10',
'row_count' => 2,
'store_count' => 1,
'order_count' => 2,
'store_counts' => '{"天猫-HX旗舰店101":2}',
'file_name' => 'test.xlsx',
'file_sha256' => str_repeat('c', 64),
'source_sheet' => '发货明细表',
'completed_at' => $now,
'created_at' => $now,
'updated_at' => $now,
]);
foreach ([2, 3] as $rowNumber) {
$payload = [
'内部订单号' => 'INTERNAL-'.$rowNumber,
'线上订单号' => 'ONLINE-'.$rowNumber,
'订单状态' => '已发货',
'发货仓' => '测试仓',
'店铺' => '天猫-HX旗舰店101',
'商品编码' => 'PRODUCT-'.$rowNumber,
'物料编号' => 'MATERIAL-1',
'型号' => '测试物料',
'商品名称' => '测试商品',
'成本' => '0.05',
'实发数量' => '1',
'过账标签' => '是',
];
$encoded = json_encode(
$payload,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR,
);
$connection->table('kuka_posting_base_rows')->insert([
'company_id' => $this->company->id,
'period' => '2026-10',
'store_name' => '天猫-HX旗舰店101',
'internal_order_no' => $payload['内部订单号'],
'online_order_no' => $payload['线上订单号'],
'product_code' => $payload['商品编码'],
'order_status' => '已发货',
'row_hash' => hash('sha256', $encoded),
'source_values' => $encoded,
'source_row_number' => $rowNumber,
'imported_at' => $now,
]);
}
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'posting-data',
'page' => 'kuka-reconciliation',
'period' => '2026-10',
'reconciliation_view' => 'lingshan-virtual-posting',
]))
->assertOk()
->assertSeeText('销售金额尾差调整')
->assertSeeText('-0.01');
}
public function test_reconciliation_panels_render_rows_generated_from_shipment_rules(): void
{
$connection = DB::connection('business_mirror');

View File

@ -232,6 +232,8 @@ class KukaReconciliationPageDataTest extends TestCase
$this->assertNull($data['error']);
$this->assertSame('0.10', $data['summary']['posting_supplier_amount_total']);
$this->assertSame('0.11', $data['summary']['posting_sales_amount_total']);
$this->assertSame('0.12', $data['summary']['posting_row_sales_amount_total']);
$this->assertSame('-0.01', $data['summary']['virtual_sales_rounding_adjustment']);
}
public function test_money_fields_round_to_two_decimals_without_truncating(): void