feat(顾家对账): 增加灵珊对账单打印页 (#1353)

新增灵珊对账单表二格式预览和A4横向自动打印页,按料号透视数据生成明细、地址分组、合计与盖章区。
This commit is contained in:
chenxi 2026-11-21 17:09:19 +08:00
parent e9d5163ca0
commit bfb668f5db
9 changed files with 631 additions and 4 deletions

View File

@ -41,6 +41,10 @@ class KukaReconciliationPageData
private const INVENTORY_SAP_CODE = 'OA01207289';
private const LINGSHAN_SECOND_ADDRESS_START = 44;
private const LINGSHAN_THIRD_ADDRESS_START = 84;
private const VIRTUAL_SUPPLIER_NAME = '欧伯娜';
private const VIRTUAL_SUPPLIER_CODE = self::INVENTORY_SAP_CODE;
@ -372,6 +376,15 @@ class KukaReconciliationPageData
$empty['period'] = $period;
$empty['generated_at'] = $generatedAt;
$empty['views'] = $views;
$empty['statement'] = [
'lingshan' => $this->lingshanStatement(
$period,
$virtualRows,
$erpRecipients,
$virtualQuantityTotal,
$virtualSalesAmountTotal,
),
];
$empty['summary'] = [
'source_rows' => $validMaterialRows + $skippedMissingMaterial,
'valid_material_rows' => $validMaterialRows,
@ -448,7 +461,6 @@ class KukaReconciliationPageData
);
}
ksort($groups, SORT_NATURAL);
$rows = [];
$serial = 0;
foreach ($groups as $materialNumber => $group) {
@ -480,6 +492,80 @@ class KukaReconciliationPageData
return $rows;
}
/**
* @param list<array<int, string>> $virtualRows
* @param list<object> $recipients
* @return array<string, mixed>
*/
private function lingshanStatement(
string $period,
array $virtualRows,
array $recipients,
string $quantityTotal,
string $amountTotal,
): array {
$rows = [];
foreach ($virtualRows as $row) {
$serial = (int) ($row[2] ?? (count($rows) + 1));
$recipientIndex = match (true) {
$serial >= self::LINGSHAN_THIRD_ADDRESS_START => 2,
$serial >= self::LINGSHAN_SECOND_ADDRESS_START => 1,
default => 0,
};
$lastRecipient = $recipients === [] ? null : $recipients[array_key_last($recipients)];
$recipient = $recipients[$recipientIndex] ?? $lastRecipient;
$rows[] = [
'serial' => $serial,
'code' => (string) ($row[3] ?? ''),
'product_name' => (string) ($row[4] ?? ''),
'specification' => '',
'unit' => '套',
'quantity' => (string) ($row[5] ?? '0'),
'unit_price' => (string) ($row[8] ?? '0.00'),
'amount' => (string) ($row[9] ?? '0.00'),
'delivery_address' => $this->fullAddress($recipient),
'status' => '已完成',
];
}
$year = substr($period, 0, 4);
$month = (int) substr($period, 5, 2);
return [
'title' => "常州灵珊家居有限公司对账单({$year}年{$month}月份)",
'period' => $period,
'rows' => $rows,
'quantity_total' => $this->formatQuantity($quantityTotal),
'amount_total' => $amountTotal,
];
}
private function fullAddress(?object $recipient): string
{
if ($recipient === null) {
return '';
}
$province = trim((string) ($recipient->receiver_state ?? ''));
$city = trim((string) ($recipient->receiver_city ?? ''));
$district = trim((string) ($recipient->receiver_district ?? ''));
$address = trim((string) ($recipient->receiver_address ?? ''));
$prefix = $province.$city.$district;
if ($address === '') {
return $prefix;
}
if (($province !== '' && str_starts_with($address, $province))
|| ($city !== '' && str_starts_with($address, $city))
|| ($district !== '' && str_starts_with($address, $district))) {
return ($province !== '' && ! str_starts_with($address, $province) ? $province : '')
.($city !== '' && ! str_starts_with($address, $province) && ! str_starts_with($address, $city) ? $city : '')
.$address;
}
return $prefix.$address;
}
/**
* @param list<array<int, string>> $virtualRows
* @return list<array<int, string>>
@ -814,6 +900,9 @@ class KukaReconciliationPageData
'periods' => $periods,
'page' => $page,
'views' => $views,
'statement' => [
'lingshan' => $this->lingshanStatement($period, [], [], '0', '0.00'),
],
'generated_at' => null,
'summary' => [
'source_rows' => 0,

View File

@ -8590,6 +8590,28 @@ class Pages extends Controller
]);
}
public function printKukaLingshanStatement(Request $request)
{
try {
$data = app(KukaReconciliationPageData::class)->build(
$request,
(int) (company_id() ?: 1),
);
} catch (Throwable $exception) {
report($exception);
abort(503, '灵珊对账单生成失败,请稍后重试。');
}
$statement = $data['statement']['lingshan'] ?? null;
if (! empty($data['error']) || ! is_array($statement)) {
abort(503, (string) ($data['error'] ?? '灵珊对账单数据尚未生成。'));
}
return view('business.pages.posting-data.lingshan-statement-print', [
'statement' => $statement,
]);
}
public function export(Request $request, string $section, string $page, string $tab)
{
if ($section === 'financial-operations' && $page === 'shop-flows') {

View File

@ -129,7 +129,7 @@
'slug' => 'lingshan-statement',
'title' => '灵珊对账单',
'icon' => 'receipt_long',
'description' => '灵珊对账单页面已建立,待接入对账数据。',
'description' => '按表二格式生成灵珊月度对账单,可直接打印。',
],
[
'slug' => 'oberna-statement',
@ -213,7 +213,14 @@
'amountTotal' => $kukaReconciliation['summary']['invoice_amount_total'] ?? '0.00',
])
@endif
@if (! empty($tab['headers']))
@if ($tab['slug'] === 'lingshan-statement' && empty($kukaReconciliation['error']))
@include('business.pages.posting-data.partials.kuka-lingshan-statement-tab', [
'statement' => $kukaReconciliation['statement']['lingshan'] ?? [],
'printUrl' => route('business.kuka-reconciliation.lingshan-statement.print', [
'period' => $kukaReconciliation['period'],
]),
])
@elseif (! empty($tab['headers']))
@include($sourceTable, [
'title' => $tab['title'],
'description' => $tab['description'],

View File

@ -0,0 +1,73 @@
<x-layouts.print>
<x-slot name="title">
{{ $statement['title'] ?? '灵珊对账单' }}
</x-slot>
<x-slot name="content">
@include('business.pages.posting-data.partials.kuka-lingshan-statement-sheet', [
'statement' => $statement,
])
<style>
@page {
size: A4 landscape;
margin: 7mm 8mm 10mm;
@bottom-center {
content: "第 " counter(page) " 页,共 " counter(pages) " 页";
color: #444;
font-size: 8pt;
}
}
html,
body {
margin: 0;
padding: 0;
background: #fff;
color: #111;
}
body {
font-family: "Firefly Sung", "CaiWu CJK", serif !important;
}
.kuka-lingshan-sheet {
width: 100%;
min-width: 0;
padding: 0;
}
.kuka-lingshan-sheet__title {
margin: 0 0 3mm;
font-size: 13pt;
}
.kuka-lingshan-sheet__table {
font-size: 7pt;
}
.kuka-lingshan-sheet__table thead {
display: table-header-group;
}
.kuka-lingshan-sheet__table tr {
page-break-inside: avoid;
break-inside: avoid;
}
.kuka-lingshan-sheet__table th,
.kuka-lingshan-sheet__table td {
padding: 1.05mm 1.2mm;
line-height: 1.25;
border-color: #111;
}
.kuka-lingshan-sheet__table th {
background: #f3f1ed;
}
.kuka-lingshan-sheet__total td {
background: #ece8df;
}
.kuka-lingshan-sheet__stamp {
min-height: 22mm;
padding-top: 8mm;
font-size: 10pt;
}
.kuka-lingshan-sheet__stamp-box {
width: 55mm;
height: 11mm;
}
</style>
</x-slot>
</x-layouts.print>

View File

@ -0,0 +1,149 @@
@php
$rows = $statement['rows'] ?? [];
@endphp
<div class="kuka-lingshan-sheet" data-kuka-lingshan-statement-sheet>
<h2 class="kuka-lingshan-sheet__title">{{ $statement['title'] ?? '常州灵珊家居有限公司对账单' }}</h2>
<table class="kuka-lingshan-sheet__table">
<colgroup>
<col class="is-serial">
<col class="is-code">
<col class="is-product">
<col class="is-specification">
<col class="is-unit">
<col class="is-quantity">
<col class="is-price">
<col class="is-amount">
<col class="is-address">
<col class="is-status">
</colgroup>
<thead>
<tr>
<th scope="col">序号</th>
<th scope="col">代码</th>
<th scope="col">产品名称</th>
<th scope="col">商品规格</th>
<th scope="col">单位</th>
<th scope="col">数量</th>
<th scope="col">单价</th>
<th scope="col">金额</th>
<th scope="col">交货地址</th>
<th scope="col">状态</th>
</tr>
</thead>
<tbody>
@forelse ($rows as $row)
<tr>
<td class="is-center">{{ $row['serial'] }}</td>
<td class="is-center">{{ $row['code'] }}</td>
<td>{{ $row['product_name'] }}</td>
<td>{{ $row['specification'] }}</td>
<td class="is-center">{{ $row['unit'] }}</td>
<td class="is-number">{{ $row['quantity'] }}</td>
<td class="is-number">{{ number_format((float) $row['unit_price'], 2, '.', ',') }}</td>
<td class="is-number">{{ number_format((float) $row['amount'], 2, '.', ',') }}</td>
<td>{{ $row['delivery_address'] }}</td>
<td class="is-center">{{ $row['status'] }}</td>
</tr>
@empty
<tr>
<td colspan="10" class="is-empty">当前账期没有可生成的对账单数据。</td>
</tr>
@endforelse
<tr class="kuka-lingshan-sheet__total">
<td colspan="5">总金额:</td>
<td class="is-number">{{ $statement['quantity_total'] ?? '0' }}</td>
<td></td>
<td class="is-number">{{ number_format((float) ($statement['amount_total'] ?? 0), 2, '.', ',') }}</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<div class="kuka-lingshan-sheet__stamp">
<span>公司盖章:</span>
<span class="kuka-lingshan-sheet__stamp-box" aria-label="公司盖章区域"></span>
</div>
</div>
<style>
.kuka-lingshan-sheet {
width: 1120px;
min-width: 1120px;
padding: 24px;
background: #fff;
color: #111;
font-family: "Firefly Sung", "CaiWu CJK", serif;
}
.kuka-lingshan-sheet__title {
margin: 0 0 12px;
font-size: 18px;
font-weight: 700;
line-height: 1.35;
text-align: center;
}
.kuka-lingshan-sheet__table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
font-size: 11px;
}
.kuka-lingshan-sheet__table col.is-serial { width: 4%; }
.kuka-lingshan-sheet__table col.is-code { width: 10%; }
.kuka-lingshan-sheet__table col.is-product { width: 26%; }
.kuka-lingshan-sheet__table col.is-specification { width: 10%; }
.kuka-lingshan-sheet__table col.is-unit { width: 4%; }
.kuka-lingshan-sheet__table col.is-quantity { width: 5%; }
.kuka-lingshan-sheet__table col.is-price { width: 7%; }
.kuka-lingshan-sheet__table col.is-amount { width: 9%; }
.kuka-lingshan-sheet__table col.is-address { width: 20%; }
.kuka-lingshan-sheet__table col.is-status { width: 5%; }
.kuka-lingshan-sheet__table th,
.kuka-lingshan-sheet__table td {
padding: 6px 7px;
border: 1px solid #222;
vertical-align: middle;
line-height: 1.35;
overflow-wrap: anywhere;
}
.kuka-lingshan-sheet__table th {
background: #f6f4ef;
font-weight: 700;
text-align: center;
white-space: nowrap;
}
.kuka-lingshan-sheet__table .is-center {
text-align: center;
}
.kuka-lingshan-sheet__table .is-number {
text-align: right;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.kuka-lingshan-sheet__table .is-empty {
height: 120px;
text-align: center;
color: #595959;
}
.kuka-lingshan-sheet__total td {
background: #eeeae2;
font-weight: 700;
}
.kuka-lingshan-sheet__stamp {
display: flex;
min-height: 72px;
align-items: center;
justify-content: center;
gap: 8px;
padding-top: 22px;
font-size: 14px;
font-weight: 600;
}
.kuka-lingshan-sheet__stamp-box {
display: block;
width: 58mm;
height: 12mm;
border: 1px solid #222;
}
</style>

View File

@ -0,0 +1,123 @@
<div class="kuka-lingshan-statement-tab">
<div class="kuka-lingshan-statement-tab__toolbar">
<div class="kuka-lingshan-statement-tab__heading">
<span class="material-icons-outlined" aria-hidden="true">receipt_long</span>
<div>
<strong>表二打印预览</strong>
<span>按当前账期数据实时生成,打印时使用 A4 横向版式。</span>
</div>
</div>
<a
class="kuka-lingshan-statement-tab__print"
href="{{ $printUrl }}"
target="_blank"
rel="noopener"
data-kuka-lingshan-statement-print
>
<span class="material-icons-outlined" aria-hidden="true">print</span>
打印对账单
</a>
</div>
<div class="kuka-lingshan-statement-tab__preview">
@include('business.pages.posting-data.partials.kuka-lingshan-statement-sheet', [
'statement' => $statement,
])
</div>
</div>
<style>
.kuka-lingshan-statement-tab {
display: grid;
min-width: 0;
gap: 12px;
}
.kuka-lingshan-statement-tab__toolbar {
display: flex;
min-width: 0;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 12px;
padding: 13px 16px;
border: 1px solid var(--vip-border, #d8d2c7);
border-radius: 12px;
background: var(--vip-surface, #fff);
}
.kuka-lingshan-statement-tab__heading {
display: flex;
min-width: 0;
align-items: center;
gap: 10px;
}
.kuka-lingshan-statement-tab__heading > .material-icons-outlined {
display: grid;
width: 32px;
height: 32px;
flex: 0 0 32px;
place-items: center;
border: 1px solid #d9c89c;
border-radius: 9px;
background: var(--vip-content-accent-soft, #f7f0de);
color: var(--vip-content-accent-dark, #856632);
font-size: 18px;
}
.kuka-lingshan-statement-tab__heading div {
display: grid;
min-width: 0;
gap: 2px;
}
.kuka-lingshan-statement-tab__heading strong {
color: var(--vip-content-ink, #171717);
font-size: 13px;
font-weight: 600;
}
.kuka-lingshan-statement-tab__heading span {
color: var(--vip-content-muted, #595959);
font-size: 11px;
line-height: 1.5;
}
.kuka-lingshan-statement-tab__print {
display: inline-flex;
min-height: 34px;
align-items: center;
justify-content: center;
gap: 6px;
padding: 0 14px;
border: 1px solid var(--vip-content-accent-dark, #856632);
border-radius: 8px;
background: var(--vip-content-accent-dark, #856632);
color: #fff;
font-size: 12px;
font-weight: 600;
text-decoration: none;
}
.kuka-lingshan-statement-tab__print:hover,
.kuka-lingshan-statement-tab__print:focus-visible {
background: #6a5129;
color: #fff;
text-decoration: none;
}
.kuka-lingshan-statement-tab__print:focus-visible {
outline: 0;
box-shadow: 0 0 0 3px rgba(133, 102, 50, 0.20);
}
.kuka-lingshan-statement-tab__print .material-icons-outlined {
font-size: 17px;
}
.kuka-lingshan-statement-tab__preview {
max-width: 100%;
overflow: auto;
padding: 18px;
border: 1px solid var(--vip-border, #d8d2c7);
border-radius: 12px;
background: #ece9e2;
scrollbar-color: var(--vip-content-accent, #b9954f) #efede8;
scrollbar-width: thin;
}
@media (max-width: 720px) {
.kuka-lingshan-statement-tab__print {
width: 100%;
}
}
</style>

View File

@ -681,6 +681,10 @@ Route::get('workspace/posting-data/kuka-reconciliation/posting-data/export', 'Bu
->middleware('business.page:posting-data,kuka-reconciliation')
->name('business.kuka-reconciliation.posting-data.export');
Route::get('workspace/posting-data/kuka-reconciliation/lingshan-statement/print', 'Business\Pages@printKukaLingshanStatement')
->middleware('business.page:posting-data,kuka-reconciliation')
->name('business.kuka-reconciliation.lingshan-statement.print');
Route::get('workspace/invoice-management/invoice-quota/export', 'Business\Pages@exportInvoiceQuota')
->middleware('business.page:invoice-management,invoice-quota')
->name('business.invoice-quota.export');

View File

@ -51,6 +51,9 @@ class KukaReconciliationPageTest extends FeatureTestCase
->assertSee('data-kuka-erp-summary-card="paid-amount"', false)
->assertSee('data-kuka-invoice-summary-card="quantity"', false)
->assertSee('data-kuka-invoice-summary-card="amount"', false)
->assertSee('data-kuka-lingshan-statement-sheet', false)
->assertSee('data-kuka-lingshan-statement-print', false)
->assertSeeText('表二打印预览')
->assertDontSeeText('有效物料行')
->assertSeeText('供货商金额')
->assertSeeText('N单号')
@ -60,7 +63,6 @@ class KukaReconciliationPageTest extends FeatureTestCase
->assertSeeText('提交人电话(手机)')
->assertSeeText('toElsAccount')
->assertSeeText('实际可用库存数量')
->assertSeeText('灵珊对账单页面已建立')
->assertSeeText('欧伯娜对账单页面已建立');
$html = $response->getContent();
@ -129,6 +131,89 @@ class KukaReconciliationPageTest extends FeatureTestCase
->assertSeeText('发货数量');
}
public function test_lingshan_statement_preview_and_print_page_use_table_two_layout(): 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('e', 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-1',
'物料编号' => 'MATERIAL-1',
'型号' => '测试物料',
'商品名称' => '测试商品',
'成本' => '10.00',
'实发数量' => '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' => 'PRODUCT-1',
'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-statement',
]))
->assertOk()
->assertSeeText('常州灵珊家居有限公司对账单(2026年10月份)')
->assertSeeText('表二打印预览')
->assertSeeText('打印对账单')
->assertSeeText('代码')
->assertSeeText('产品名称')
->assertSeeText('交货地址')
->assertSeeText('公司盖章:')
->assertSee('data-kuka-lingshan-statement-sheet', false)
->assertSee('data-kuka-lingshan-statement-print', false);
$this->loginAs()
->get(route('business.kuka-reconciliation.lingshan-statement.print', [
'period' => '2026-10',
]))
->assertOk()
->assertSee('onload="window.print();"', false)
->assertSeeText('常州灵珊家居有限公司对账单(2026年10月份)')
->assertSeeText('公司盖章:')
->assertSeeText('2')
->assertSeeText('22.22');
}
public function test_virtual_posting_renders_material_pivot_without_rounding_footer(): void
{
$connection = DB::connection('business_mirror');

View File

@ -329,6 +329,24 @@ class KukaReconciliationPageDataTest extends TestCase
'2',
'',
], $data['views']['inventory-management-template']['rows'][0]);
$statement = $data['statement']['lingshan'];
$this->assertSame('常州灵珊家居有限公司对账单(2026年10月份)', $statement['title']);
$this->assertCount(1, $statement['rows']);
$this->assertSame('2', $statement['quantity_total']);
$this->assertSame('22.22', $statement['amount_total']);
$this->assertSame([
'serial' => 1,
'code' => 'M-1',
'product_name' => '测试物料',
'specification' => '',
'unit' => '套',
'quantity' => '2',
'unit_price' => '11.11',
'amount' => '22.22',
'delivery_address' => '江苏省常州市武进区测试路1号',
'status' => '已完成',
], $statement['rows'][0]);
}
public function test_virtual_sales_summary_uses_pivoted_supplier_amount(): void
@ -482,6 +500,63 @@ class KukaReconciliationPageDataTest extends TestCase
}
}
public function test_virtual_pivot_preserves_source_material_order(): void
{
$connection = DB::connection('business_mirror');
$connection->table('kuka_posting_base_imports')->insert([
'company_id' => 1,
'period' => '2026-10',
'completed_at' => '2026-11-01 08:00:00',
]);
$this->insertBaseRow(2, $this->payload('O-1', 'P-2', 'S-2', 'I-2', 'M-2', '1', '10.00'));
$this->insertBaseRow(3, $this->payload('O-2', 'P-1', 'S-1', 'I-1', 'M-1', '1', '10.00'));
$data = app(KukaReconciliationPageData::class)->build(
Request::create('/', 'GET', ['period' => '2026-10']),
1,
);
$this->assertSame(['M-2', 'M-1'], array_column($data['views']['lingshan-virtual-posting']['rows'], 3));
$this->assertSame(['M-2', 'M-1'], array_column($data['statement']['lingshan']['rows'], 'code'));
}
public function test_statement_uses_three_consecutive_delivery_address_groups(): void
{
$connection = DB::connection('business_mirror');
$connection->table('kuka_posting_base_imports')->insert([
'company_id' => 1,
'period' => '2026-10',
'completed_at' => '2026-11-01 08:00:00',
]);
for ($index = 1; $index <= 84; $index++) {
$this->insertBaseRow(
$index + 1,
$this->payload(
'O-'.$index,
'P-'.$index,
'S-'.$index,
'I-'.$index,
sprintf('M-%03d', $index),
'1',
'10.00',
),
);
}
$data = app(KukaReconciliationPageData::class)->build(
Request::create('/', 'GET', ['period' => '2026-10']),
1,
);
$rows = $data['statement']['lingshan']['rows'];
$this->assertCount(84, $rows);
$this->assertSame('江苏省常州市武进区测试路1号', $rows[0]['delivery_address']);
$this->assertSame('江苏省常州市武进区测试路1号', $rows[42]['delivery_address']);
$this->assertSame('浙江省杭州市西湖区测试路2号', $rows[43]['delivery_address']);
$this->assertSame('浙江省杭州市西湖区测试路2号', $rows[82]['delivery_address']);
$this->assertSame('上海市浦东新区测试路3号', $rows[83]['delivery_address']);
}
public function test_posting_export_returns_every_material_row_without_pagination(): void
{
$connection = DB::connection('business_mirror');