user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); } public function test_finance_page_renders_with_comparison_rules(): void { $this->seedStatement('晨丰', [ $this->statementRow('ZSJ-1', '128.00', '2', '256.00'), ]); $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'supplier-reconciliation', 'page' => 'finance-data', 'supplier' => '晨丰', ])) ->assertOk() ->assertSeeText('供应商对账') ->assertSeeText('财务端数据') ->assertSeeText('厂家端数据') ->assertSeeText('厂家多') ->assertSeeText('取金额低的一方结算') ->assertSeeText('采购单号 + 商品编码 + 日期') ->assertSeeText('商品编码 + 数量') ->assertSeeText('快递单号 + 商品编码') ->assertSee('list="finance-supplier-options"', false) ->assertSeeText('对账人') ->assertSeeText('下载对账单模板'); } public function test_finance_page_overview_counts_and_links_supplier_details(): void { $companyId = (int) $this->company->id; $store = app(SupplierPayableOverrideStore::class); foreach ([ '汇总厂家甲' => ['qty' => '2', 'amount' => '200'], '汇总厂家乙' => ['qty' => '3', 'amount' => '300'], '汇总厂家丙' => ['qty' => '4', 'amount' => '400'], '汇总厂家丁' => ['qty' => '5', 'amount' => '500'], ] as $supplier => $amounts) { $store->save( 'final:supplier:payment-reconciliation', 'overview:' . $supplier, [ 'summary_month' => '2026-11', 'purchaseNo' => 'OVERVIEW-' . md5($supplier), 'date' => '2026-11-30', 'supplier' => $supplier, 'skuCode' => 'OVERVIEW-' . $supplier, 'productCode' => 'OVERVIEW-' . $supplier, 'qty' => $amounts['qty'], 'unitPrice' => '100', 'amount' => $amounts['amount'], ], $companyId, null, ); } $this->seedStatement('汇总厂家甲', [ array_merge($this->statementRow('OVERVIEW-汇总厂家甲', '100', '2', '200'), [ 'purchaseNo' => 'OVERVIEW-' . md5('汇总厂家甲'), 'createdAt' => '2026-11-30', 'supplier' => '汇总厂家甲', ]), ]); $this->seedStatement('汇总厂家乙', [ array_merge($this->statementRow('OVERVIEW-汇总厂家乙', '80', '3', '240'), [ 'purchaseNo' => 'OVERVIEW-' . md5('汇总厂家乙'), 'createdAt' => '2026-11-30', 'supplier' => '汇总厂家乙', ]), ]); $confirmations = app(SupplierSummaryConfirmation::class); foreach (['甲', '乙'] as $suffix) { $supplier = '汇总厂家' . $suffix; $requestId = 'supplier-summary-c' . $companyId . '-' . substr(hash('sha256', $supplier), 0, 32); $confirmations->create( $requestId, $supplier, '2026-11', 'settlement', (float) ($suffix === '甲' ? 2 : 3), (float) ($suffix === '甲' ? 200 : 300), $companyId, null, ); $confirmations->markSent($requestId, $companyId); } $failedRequest = 'supplier-summary-c' . $companyId . '-' . substr(hash('sha256', '汇总厂家丙'), 0, 32); $confirmations->create( $failedRequest, '汇总厂家丙', '2026-11', 'settlement', 4, 400, $companyId, null, ); $confirmations->markFailed($failedRequest, $companyId, '测试发送失败'); $pendingRequest = 'supplier-summary-c' . $companyId . '-' . substr(hash('sha256', '汇总厂家丁'), 0, 32); $confirmations->create( $pendingRequest, '汇总厂家丁', '2026-11', 'settlement', 5, 500, $companyId, null, ); $response = $this->loginAs()->get(route('business.pages.show', [ 'section' => 'supplier-reconciliation', 'page' => 'finance-data', 'month' => '2026-11', ]))->assertOk(); $html = (string) $response->getContent(); $section = static function (string $key) use ($html): string { preg_match( '/
(.*?)<\/details>/s', $html, $matches, ); return (string) ($matches[1] ?? ''); }; $this->assertStringContainsString('4 家', $section('total')); $this->assertStringContainsString('2 家', $section('confirmed')); $this->assertStringContainsString('1 家', $section('difference')); $this->assertStringContainsString('2 家', $section('not_uploaded')); $this->assertStringContainsString('汇总厂家甲', $section('confirmed')); $this->assertStringContainsString('汇总厂家乙', $section('confirmed')); $this->assertStringContainsString('汇总厂家乙', $section('difference')); $this->assertStringContainsString('汇总厂家丙', $section('not_uploaded')); $this->assertStringContainsString('汇总厂家丁', $section('not_uploaded')); } public function test_finance_page_defaults_to_previous_accounting_month(): void { Carbon::setTestNow(Carbon::parse('2026-12-04 10:00:00', 'Asia/Shanghai')); $companyId = (int) $this->company->id; $store = app(SupplierPayableOverrideStore::class); foreach ([ '十月厂家' => '2026-10', '十一月厂家' => '2026-11', ] as $supplier => $month) { $store->save( 'final:supplier:payment-reconciliation', 'default-month:' . $supplier, [ 'summary_month' => $month, 'purchaseNo' => 'DEFAULT-' . $supplier, 'date' => $month . '-30', 'supplier' => $supplier, 'skuCode' => 'DEFAULT-' . $supplier, 'productCode' => 'DEFAULT-' . $supplier, 'qty' => '1', 'unitPrice' => '10', 'amount' => '10', ], $companyId, null, ); } try { $this->loginAs()->get(route('business.pages.show', [ 'section' => 'supplier-reconciliation', 'page' => 'finance-data', ])) ->assertOk() ->assertSee('