CaiWuXiTong/tests/Feature/Business/KukaReconciliationPageTest.php
chenxi bfb668f5db feat(顾家对账): 增加灵珊对账单打印页 (#1353)
新增灵珊对账单表二格式预览和A4横向自动打印页,按料号透视数据生成明细、地址分组、合计与盖章区。
2026-11-21 17:09:19 +08:00

461 lines
21 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature\Business;
use Illuminate\Support\Facades\DB;
use Tests\Feature\FeatureTestCase;
class KukaReconciliationPageTest extends FeatureTestCase
{
public function test_renders_all_kuka_reconciliation_tabs_with_the_first_tab_active(): void
{
$response = $this->loginAs()
->get(route('business.pages.show', [
'section' => 'posting-data',
'page' => 'kuka-reconciliation',
]))
->assertOk()
->assertSeeText('顾家对账')
->assertSeeText('顾家过账数据')
->assertSeeText('TOC订单')
->assertSeeText('灵珊虚拟过账')
->assertSeeText('顾家ERP商品导入')
->assertSeeText('开票填写模板-货物-灵珊')
->assertSeeText('库存管理模板')
->assertSeeText('灵珊对账单')
->assertSeeText('欧伯娜对账单')
->assertSee('data-kuka-reconciliation-tabs', false)
->assertSee('data-kuka-reconciliation-panel="posting-data"', false)
->assertSee('data-kuka-reconciliation-panel="oberna-statement"', false)
->assertSee('id="kuka-reconciliation-tab-posting-data"', false)
->assertSee('class="kuka-reconciliation-subnav__tab is-active"', false)
->assertSee('data-kuka-reconciliation-template="顾家过账数据"', false)
->assertSee('data-kuka-reconciliation-template="TOC订单"', false)
->assertSee('data-kuka-reconciliation-template="灵珊虚拟过账"', false)
->assertSee('data-kuka-reconciliation-template="顾家ERP商品导入"', false)
->assertSee('data-kuka-reconciliation-template="开票填写模板-货物-灵珊"', false)
->assertSee('data-kuka-reconciliation-template="库存管理模版"', false)
->assertSee('class="kuka-source-table__grid is-wide-spacing"', false)
->assertSee('width: 100%;', false)
->assertSee('table-layout: fixed;', false)
->assertSee('width: 20%;', false)
->assertSee('data-kuka-posting-export', false)
->assertSee('data-kuka-posting-card="quantity"', false)
->assertSee('data-kuka-posting-card="supplier-amount"', false)
->assertSee('data-kuka-toc-quantity-card', false)
->assertSee('data-kuka-virtual-summary-card="quantity"', false)
->assertSee('data-kuka-virtual-summary-card="supplier-amount"', false)
->assertSee('data-kuka-virtual-summary-card="sales-amount"', false)
->assertSee('data-kuka-erp-summary-card="quantity"', false)
->assertSee('data-kuka-erp-summary-card="amount"', false)
->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单号')
->assertSeeText('装载号')
->assertSeeText('导入时间')
->assertSeeText('nationalSubsidySubject')
->assertSeeText('提交人电话(手机)')
->assertSeeText('toElsAccount')
->assertSeeText('实际可用库存数量')
->assertSeeText('欧伯娜对账单页面已建立');
$html = $response->getContent();
$this->assertSame([
'posting-data' => 7,
'toc-orders' => 6,
'lingshan-virtual-posting' => 16,
'erp-product-import' => 34,
'invoice-entry-template' => 20,
'inventory-management-template' => 28,
], [
'posting-data' => $this->headerCount($html, 'posting-data'),
'toc-orders' => $this->headerCount($html, 'toc-orders'),
'lingshan-virtual-posting' => $this->headerCount($html, 'lingshan-virtual-posting'),
'erp-product-import' => $this->headerCount($html, 'erp-product-import'),
'invoice-entry-template' => $this->headerCount($html, 'invoice-entry-template'),
'inventory-management-template' => $this->headerCount($html, 'inventory-management-template'),
]);
$postingPanelStart = strpos($html, 'data-kuka-reconciliation-panel="posting-data"');
$postingPanelEnd = strpos($html, '</section>', $postingPanelStart);
$this->assertNotFalse($postingPanelStart);
$this->assertNotFalse($postingPanelEnd);
$postingPanel = substr($html, $postingPanelStart, $postingPanelEnd - $postingPanelStart);
$this->assertStringNotContainsString('kuka-source-table__header', $postingPanel);
$tocPanelStart = strpos($html, 'data-kuka-reconciliation-panel="toc-orders"');
$tocPanelEnd = strpos($html, 'data-kuka-reconciliation-panel="', $tocPanelStart + 20);
$this->assertNotFalse($tocPanelStart);
$this->assertNotFalse($tocPanelEnd);
$tocPanel = substr($html, $tocPanelStart, $tocPanelEnd - $tocPanelStart);
$this->assertStringNotContainsString('<header class="kuka-source-table__header">', $tocPanel);
$virtualPanelStart = strpos($html, 'data-kuka-reconciliation-panel="lingshan-virtual-posting"');
$virtualPanelEnd = strpos($html, 'data-kuka-reconciliation-panel="', $virtualPanelStart + 20);
$this->assertNotFalse($virtualPanelStart);
$this->assertNotFalse($virtualPanelEnd);
$virtualPanel = substr($html, $virtualPanelStart, $virtualPanelEnd - $virtualPanelStart);
$this->assertStringNotContainsString('<header class="kuka-source-table__header">', $virtualPanel);
$erpPanelStart = strpos($html, 'data-kuka-reconciliation-panel="erp-product-import"');
$erpPanelEnd = strpos($html, 'data-kuka-reconciliation-panel="', $erpPanelStart + 20);
$this->assertNotFalse($erpPanelStart);
$this->assertNotFalse($erpPanelEnd);
$erpPanel = substr($html, $erpPanelStart, $erpPanelEnd - $erpPanelStart);
$this->assertStringNotContainsString('<header class="kuka-source-table__header">', $erpPanel);
$invoicePanelStart = strpos($html, 'data-kuka-reconciliation-panel="invoice-entry-template"');
$invoicePanelEnd = strpos($html, 'data-kuka-reconciliation-panel="', $invoicePanelStart + 20);
$this->assertNotFalse($invoicePanelStart);
$this->assertNotFalse($invoicePanelEnd);
$invoicePanel = substr($html, $invoicePanelStart, $invoicePanelEnd - $invoicePanelStart);
$this->assertStringNotContainsString('<header class="kuka-source-table__header">', $invoicePanel);
}
public function test_kuka_reconciliation_tab_can_open_directly_from_the_url(): void
{
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'posting-data',
'page' => 'kuka-reconciliation',
'reconciliation_view' => 'toc-orders',
]))
->assertOk()
->assertSee('id="kuka-reconciliation-tab-toc-orders"', false)
->assertSee('class="kuka-reconciliation-subnav__tab is-active"', false)
->assertSee('data-kuka-reconciliation-panel="toc-orders"', false)
->assertSee('data-kuka-reconciliation-template="TOC订单"', false)
->assertSeeText('订单号')
->assertSeeText('型号')
->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');
$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,
]);
}
$response = $this->loginAs()
->get(route('business.pages.show', [
'section' => 'posting-data',
'page' => 'kuka-reconciliation',
'period' => '2026-10',
'reconciliation_view' => 'lingshan-virtual-posting',
]))
->assertOk()
->assertDontSeeText('销售金额尾差调整');
$html = $response->getContent();
$this->assertMatchesRegularExpression(
'/data-kuka-virtual-summary-card="quantity".*?<strong>2<\/strong>/s',
$html,
);
$this->assertMatchesRegularExpression(
'/data-kuka-virtual-summary-card="sales-amount".*?<strong>0\.11<\/strong>/s',
$html,
);
}
public function test_reconciliation_panels_render_rows_generated_from_shipment_rules(): void
{
$connection = DB::connection('business_mirror');
$payload = [
'内部订单号' => 'INTERNAL-1',
'线上订单号' => 'ONLINE-1',
'原始线上订单号' => 'ONLINE-1',
'订单状态' => '已发货',
'发货仓' => '测试仓',
'店铺' => '天猫-HX旗舰店101',
'买家账号' => 'buyer-1',
'卖家备注' => '测试备注',
'订单日期' => '2026-10-31 10:00:00',
'付款日期' => '2026-10-31 10:05:00',
'发货日期' => '2026-10-31 18:00:00',
'省' => '江苏省',
'市' => '常州市',
'区县' => '武进区',
'订单快递公司' => '测试快递',
'订单快递单号' => 'EXPRESS-1',
'收货人' => '张三',
'商品编码' => 'PRODUCT-1',
'款式编码' => 'STYLE-1',
'货号' => 'ITEM-1',
'型号' => '测试物料描述',
'商品名称' => '测试商品',
'颜色规格' => '测试颜色',
'材质' => '板材',
'业务员' => '业务员A',
'运费支出' => '5.00',
'物料编号' => 'MATERIAL-1',
'成本' => '100.00',
'实发数量' => '2',
'过账标签' => '是',
'发货金额' => '200.00',
];
$encoded = json_encode(
$payload,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR,
);
$now = now();
$connection->table('kuka_posting_base_imports')->insert([
'company_id' => $this->company->id,
'period' => '2026-10',
'row_count' => 1,
'store_count' => 1,
'order_count' => 1,
'store_counts' => '{"天猫-HX旗舰店101":1}',
'file_name' => 'test.xlsx',
'file_sha256' => str_repeat('a', 64),
'source_sheet' => '发货明细表',
'completed_at' => $now,
'created_at' => $now,
'updated_at' => $now,
]);
$connection->table('kuka_posting_base_rows')->insert([
'company_id' => $this->company->id,
'period' => '2026-10',
'store_name' => '天猫-HX旗舰店101',
'internal_order_no' => 'INTERNAL-1',
'online_order_no' => 'ONLINE-1',
'product_code' => 'PRODUCT-1',
'order_status' => '已发货',
'row_hash' => hash('sha256', $encoded),
'source_values' => $encoded,
'source_row_number' => 2,
'imported_at' => $now,
]);
$connection->table('kuka_posting_quotation_rows')->insert([
'company_id' => $this->company->id,
'material_number' => 'MATERIAL-1',
'material_desc' => '测试物料描述',
'supplier_account' => '435421',
'supplier_name' => '常州欧伯娜家居有限公司',
'record_status' => '生效',
'price_including_tax' => '100.0000',
'price_excluding_tax' => '88.5000',
'row_hash' => str_repeat('b', 64),
'source_values' => '{}',
'source_row_number' => 3,
'imported_at' => $now,
]);
$connection->table('jst_oms_shipping')->insert([
'trade_no' => 'ONLINE-1',
'barcode' => 'PRODUCT-1',
'product_code' => 'STYLE-1',
'receiver_name' => '张三',
'receiver_state' => '江苏省',
'receiver_city' => '常州市',
'receiver_district' => '武进区',
'receiver_address' => '江苏省常州市武进区测试路1号',
'receiver_mobile' => '13800000000',
'express_no' => 'EXPRESS-1',
'express_name1' => '测试快递',
'freight' => '5.00',
]);
$connection->table('kuka_posting_erp_recipient_rows')->insert([
'company_id' => $this->company->id,
'sort_order' => 1,
'receiver_name' => '张三',
'receiver_mobile' => '13800000000',
'receiver_state' => '江苏省',
'receiver_city' => '常州市',
'receiver_district' => '武进区',
'receiver_address' => '江苏省常州市武进区测试路1号',
'buyer_nick' => 'buyer-1',
'source_row_number' => 2,
'row_hash' => str_repeat('d', 64),
'imported_at' => $now,
'created_at' => $now,
'updated_at' => $now,
]);
$response = $this->loginAs()
->get(route('business.pages.show', [
'section' => 'posting-data',
'page' => 'kuka-reconciliation',
'period' => '2026-10',
]))
->assertOk()
->assertSeeText('MATERIAL-1')
->assertSeeText('测试物料描述')
->assertSeeText('222.22')
->assertSeeText('常州欧伯娜家居有限公司')
->assertSeeText('435421')
->assertSeeText('宁波顾家望业家居有限公司')
->assertSeeText('yuechenna@dingtalk.com')
->assertSeeText('15061959991')
->assertSeeText('江苏省常州市武进区测试路1号')
->assertSeeText('13800000000');
$html = $response->getContent();
$this->assertMatchesRegularExpression(
'/data-kuka-posting-card="quantity".*?<strong>2<\/strong>/s',
$html,
);
$this->assertMatchesRegularExpression(
'/data-kuka-posting-card="supplier-amount".*?<strong>200\.00<\/strong>/s',
$html,
);
$this->assertMatchesRegularExpression(
'/data-kuka-toc-quantity-card.*?<strong>2<\/strong>/s',
$html,
);
$export = $this->get(route('business.kuka-reconciliation.posting-data.export', [
'period' => '2026-10',
]))
->assertOk()
->assertDownload('kuka_posting_data_2026-10.csv')
->assertHeader('content-type', 'text/csv; charset=UTF-8');
$csv = $export->streamedContent();
$this->assertStringStartsWith("\xEF\xBB\xBF", $csv);
$this->assertStringContainsString('年份,月份,物料编号,物料描述,采购数量,单价,供货商金额', $csv);
$this->assertStringContainsString('2026,10,MATERIAL-1,测试物料描述,2,100.00,200.00', $csv);
}
private function headerCount(string $html, string $slug): int
{
$panelStart = strpos($html, 'data-kuka-reconciliation-panel="'.$slug.'"');
$this->assertNotFalse($panelStart);
$panelEnd = strpos($html, '</section>', $panelStart);
$this->assertNotFalse($panelEnd);
$panel = substr($html, $panelStart, $panelEnd - $panelStart);
preg_match_all('/<th scope="col">/', $panel, $matches);
return count($matches[0]);
}
}