user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail() ); $payableReport = \Mockery::mock(SupplierPayableReportRepository::class); $payableReport->shouldReceive('latestOutBillDates')->andReturn([]); $this->app->instance(SupplierPayableReportRepository::class, $payableReport); } public function test_negative_alerts_is_a_payables_section_with_two_subpage_groups(): void { $navigation = collect(BusinessNavigation::all())->keyBy('slug'); $alertSection = $navigation->get('negative-alerts'); $this->assertNotNull($alertSection); $this->assertSame('负数预警', $alertSection['title']); $this->assertSame( ['supplier-negative-alert', 'courier-negative-alert'], array_column($alertSection['pages'], 'slug'), ); $this->assertSame( ['supplier-negative-alert-data', 'supplier-payable-forecast'], array_column($alertSection['pages'][0]['children'], 'slug'), ); $this->assertSame( ['courier-negative-alert-data', 'courier-freight-forecast'], array_column($alertSection['pages'][1]['children'], 'slug'), ); $this->assertTrue($alertSection['pages'][0]['children_inherit_parent_access']); $this->assertTrue($alertSection['pages'][1]['children_inherit_parent_access']); $this->assertContains('negative-alerts/supplier-payable-forecast', SidebarPermissions::allKeys()); $this->assertContains('negative-alerts/courier-freight-forecast', SidebarPermissions::allKeys()); $this->assertNotContains( 'supplier-negative-alert', array_column($navigation->get('supplier-reconciliation')['pages'], 'slug'), ); $grouped = ShowInAdmin::groupPayables(BusinessNavigation::all()); $payables = collect($grouped)->firstWhere('slug', 'payable-items'); $this->assertSame('negative-alerts', $payables['sections'][0]['slug']); } public function test_negative_alert_parent_pages_redirect_to_their_data_pages(): void { $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'negative-alerts', 'page' => 'supplier-negative-alert', ])) ->assertRedirect(route('business.pages.show', [ 'section' => 'negative-alerts', 'page' => 'supplier-negative-alert-data', ])); $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'negative-alerts', 'page' => 'courier-negative-alert', ])) ->assertRedirect(route('business.pages.show', [ 'section' => 'negative-alerts', 'page' => 'courier-negative-alert-data', ])); } public function test_supplier_and_courier_negative_alert_pages_render_as_tabs(): void { $this->saveSupplierPayable('negative:1', '负余额供应商', '-128.50', '2026-09', [ 'company' => '测试供应商有限公司', 'negative_reason' => '历史多付款', 'company_bear_amount' => '28.50', ]); $this->saveSupplierPayable('positive:1', '正余额供应商', '88.00', '2026-09'); $this->saveSupplierPayable('formula:1', '公式命中供应商', '100.00', '2026-09', [ 'should_pay' => '180.00', 'estimated_price' => '50.00', ]); $this->saveSupplierPayable('formula:exclude', '负余额但公式为正供应商', '-100.00', '2026-09', [ 'should_pay' => '-500.00', 'estimated_price' => '50.00', ]); $supplierManagement = \Mockery::mock(SupplierManagementMirrorRepository::class); $supplierManagement->shouldReceive('suppliersByNames') ->once() ->withArgs(static fn (array $names): bool => count($names) === 2 && in_array('负余额供应商', $names, true) && in_array('公式命中供应商', $names, true)) ->andReturn([ (object) ['scmname' => '负余额供应商', 'buyer' => '采购甲'], (object) ['scmname' => '公式命中供应商', 'buyer' => '采购乙'], ]); $this->app->instance(SupplierManagementMirrorRepository::class, $supplierManagement); $payableReport = \Mockery::mock(SupplierPayableReportRepository::class); $payableReport->shouldReceive('latestOutBillDates') ->once() ->withArgs(static fn (array $suppliers): bool => count($suppliers) === 2 && in_array('负余额供应商', $suppliers, true) && in_array('公式命中供应商', $suppliers, true)) ->andReturn([ [ 'supplier' => '负余额供应商', 'out_bill_date' => '2026-11-09', ], [ 'supplier' => '公式命中供应商', 'out_bill_date' => '2026-11-09', ], ]); $this->app->instance(SupplierPayableReportRepository::class, $payableReport); $response = $this->loginAs() ->get(route('business.pages.show', [ 'section' => 'negative-alerts', 'page' => 'supplier-negative-alert-data', ])) ->assertOk() ->assertSeeText('供应商负数预警') ->assertSeeText('快递负数预警') ->assertSeeText('供应商货款预估') ->assertSeeText('快递运费预估') ->assertSee(route('business.pages.show', [ 'section' => 'negative-alerts', 'page' => 'supplier-payable-forecast', ]), false) ->assertSee(route('business.pages.show', [ 'section' => 'negative-alerts', 'page' => 'courier-freight-forecast', ]), false) ->assertSeeText('按负数预警公式筛出的终版数据') ->assertSeeText('供应商余额 - 应付余额 + 预估金额 < 0') ->assertSeeText('负余额供应商') ->assertSeeText('公式命中供应商') ->assertSeeText('-128.50') ->assertSeeText('历史多付款') ->assertSeeText('情况说明') ->assertSeeText('公司承担金额') ->assertSeeText('28.50') ->assertDontSeeText('负数原因') ->assertSeeText('采购甲') ->assertSeeText('采购乙') ->assertDontSeeText('正余额供应商') ->assertDontSeeText('负余额但公式为正供应商'); $fields = app(PayablesFinalRegistry::class)->fields( PayablesFinalRegistry::SECTION_SUPPLIER, 'supplier-payables-report', ); $html = (string) $response->getContent(); preg_match_all('/