user->attachPermission(
Permission::where('name', 'read-admin-panel')->firstOrFail()
);
$payableReport = \Mockery::mock(SupplierPayableReportRepository::class);
$payableReport->shouldReceive('latestOutBillDates')->andReturn([]);
$this->app->instance(SupplierPayableReportRepository::class, $payableReport);
}
protected function tearDown(): void
{
Carbon::setTestNow();
parent::tearDown();
}
public function test_negative_alert_pages_expose_visible_forecast_subtabs(): 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(
['alert', 'payable-forecast'],
array_column($alertSection['pages'][0]['tabs'], 'slug'),
);
$this->assertSame(
['alert', 'freight-forecast'],
array_column($alertSection['pages'][1]['tabs'], 'slug'),
);
$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_routes_open_the_alert_tab_and_legacy_subpages_redirect(): 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',
'tab' => 'alert',
]));
$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',
'tab' => 'alert',
]));
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-payable-forecast',
]))
->assertRedirect(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-negative-alert',
'tab' => 'payable-forecast',
]));
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'courier-freight-forecast',
]))
->assertRedirect(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'courier-negative-alert',
'tab' => 'freight-forecast',
]));
}
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',
'tab' => 'alert',
]))
->assertOk()
->assertSeeText('供应商负数预警')
->assertSeeText('快递负数预警')
->assertSeeText('供应商货款预估')
->assertSee(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-negative-alert',
'tab' => 'payable-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('/
)/', $html, $headers);
// 序号 + 隐藏主体名称后的原字段 + 最晚出账单时间 + 动态匹配的采购 + 处理结果。
$this->assertCount(count($fields) + 3, $headers[0]);
preg_match_all('/ | ]*>(.*?)<\/th>/s', $html, $headerMatches);
$labels = array_map(
static fn (string $label): string => trim(html_entity_decode(strip_tags($label), ENT_QUOTES | ENT_HTML5, 'UTF-8')),
$headerMatches[1],
);
$latestBillTimeIndex = array_search('最晚出账单时间', $labels, true);
$situationIndex = array_search('情况说明', $labels, true);
$companyBearAmountIndex = array_search('公司承担金额', $labels, true);
$this->assertNotFalse($latestBillTimeIndex);
$this->assertNotFalse($situationIndex);
$this->assertNotFalse($companyBearAmountIndex);
$this->assertSame($latestBillTimeIndex + 1, $situationIndex);
$this->assertSame($situationIndex + 1, $companyBearAmountIndex);
$this->assertSame('采购', $labels[$companyBearAmountIndex + 1]);
$this->assertSame('处理结果', $labels[$companyBearAmountIndex + 2]);
$this->assertStringContainsString('2026-11-09', $html);
$this->assertStringContainsString('待采购处理', $html);
$this->assertStringNotContainsString('供应商公司主体名称', $html);
$this->assertStringNotContainsString('测试供应商有限公司', $html);
preg_match_all('/ | ]*data-fixed-column="([^"]+)"/', $html, $fixedHeaders);
$this->assertSame(
['index', 'summary_month', 'checker', 'settlement_method', 'supplier'],
$fixedHeaders[1],
);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'courier-negative-alert',
'tab' => 'alert',
]))
->assertOk()
->assertSeeText('供应商负数预警')
->assertSeeText('快递负数预警')
->assertSeeText('快递负数判定口径待确认')
->assertSeeText('待接入')
->assertSee(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'courier-negative-alert',
'tab' => 'freight-forecast',
]), false);
}
public function test_supplier_and_courier_negative_alert_forecast_subpages_render(): void
{
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-negative-alert',
'tab' => 'payable-forecast',
]))
->assertOk()
->assertSeeText('供应商负数预警')
->assertSeeText('供应商货款预估')
->assertSeeText('供应商货款明细镜像初始化中')
->assertSeeText('采购入库共享镜像尚未就绪')
->assertSeeText('供应商汇总共享镜像尚未就绪')
->assertSeeText('货款明细')
->assertSeeText('退货明细')
->assertSeeText('汇总')
->assertSee('data-payable-forecast', false)
->assertSee('data-npf-tab="goods"', false)
->assertSee('data-npf-tab="returns"', false)
->assertSee('data-npf-tab="summary"', false)
->assertSee('forecast_view', false);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'courier-negative-alert',
'tab' => 'freight-forecast',
]))
->assertOk()
->assertSeeText('快递负数预警')
->assertSeeText('快递运费预估')
->assertSeeText('快递运费预估数据待接入')
->assertSeeText('运费')
->assertSeeText('记账')
->assertSeeText('面单')
->assertSeeText('借支')
->assertSeeText('违约金')
->assertSeeText('其他附加费')
->assertSeeText('汇总')
->assertSee('data-courier-freight-forecast', false)
->assertSee('data-cf-tab="freight"', false)
->assertSee('data-cf-tab="bookkeeping"', false)
->assertSee('data-cf-tab="waybill"', false)
->assertSee('data-cf-tab="advance"', false)
->assertSee('data-cf-tab="penalty"', false)
->assertSee('data-cf-tab="other-surcharge"', false)
->assertSee('data-cf-tab="summary"', false);
}
public function test_courier_freight_forecast_direct_subpage_state_is_rendered(): void
{
$response = $this->loginAs()
->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'courier-negative-alert',
'tab' => 'freight-forecast',
'freight_view' => 'summary',
]))
->assertOk()
->assertSeeText('快递运费汇总数据待接入')
->assertSeeText('汇总维度')
->assertSeeText('余额口径');
$html = (string) $response->getContent();
$this->assertMatchesRegularExpression('/id="cf-tab-summary"[^>]*aria-selected="true"/s', $html);
$this->assertMatchesRegularExpression('/id="cf-tab-freight"[^>]*aria-selected="false"/s', $html);
$this->assertMatchesRegularExpression('/id="cf-panel-freight"[^>]*hidden/s', $html);
$this->assertDoesNotMatchRegularExpression('/id="cf-panel-summary"[^>]*hidden/s', $html);
}
public function test_supplier_payable_forecast_direct_subpage_state_is_rendered(): void
{
$response = $this->loginAs()
->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-negative-alert',
'tab' => 'payable-forecast',
'forecast_view' => 'returns',
]))
->assertOk()
->assertSeeText('采购入库')
->assertSeeText('采购退货共享镜像尚未就绪')
->assertSeeText('预估金额×0.8合计(万元)');
$html = (string) $response->getContent();
$this->assertMatchesRegularExpression('/id="npf-tab-returns"[^>]*aria-selected="true"/s', $html);
$this->assertMatchesRegularExpression('/id="npf-tab-goods"[^>]*aria-selected="false"/s', $html);
$this->assertMatchesRegularExpression('/id="npf-panel-goods"[^>]*hidden/s', $html);
$this->assertDoesNotMatchRegularExpression('/id="npf-panel-returns"[^>]*hidden/s', $html);
}
public function test_supplier_payable_forecast_summary_uses_screenshot_headers_and_formulas(): void
{
Carbon::setTestNow(Carbon::parse('2026-11-30 12:00:00', 'Asia/Shanghai'));
$this->createSupplierPayableForecastTables();
$now = now();
DB::connection('business_mirror')->table('business_mirror_table_states')->insert([
['dataset_key' => SupplierPayableForecastRepository::HEAD_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
['dataset_key' => SupplierPayableForecastRepository::ITEM_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
['dataset_key' => SupplierPayableForecastRepository::PRICE_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
['dataset_key' => SupplierPayableForecastRepository::RETURN_HEAD_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
['dataset_key' => SupplierPayableForecastRepository::RETURN_ITEM_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::HEAD_TABLE)->insert([
[
'Id' => 101,
'io_id' => 'IN-YZH',
'po_id' => 1001,
'io_date' => '2026-11-10 10:00:00',
'warehouse' => '正常仓',
'supplier_name' => '亿之航',
],
[
'Id' => 102,
'io_id' => 'IN-CY',
'po_id' => 1002,
'io_date' => '2026-11-11 10:00:00',
'warehouse' => '正常仓',
'supplier_name' => '彩艺',
],
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::ITEM_TABLE)->insert([
[
'Id' => 101,
'io_id' => 'IN-YZH',
'ioi_id' => 'ITEM-YZH',
'sku_id' => 'SKU-YZH-GOODS',
'i_id' => 'STYLE-YZH',
'name' => '亿之航货款',
'qty' => 1,
'cost_price' => 58665,
'cost_amount' => 58665,
],
[
'Id' => 102,
'io_id' => 'IN-CY',
'ioi_id' => 'ITEM-CY',
'sku_id' => 'SKU-CY-GOODS',
'i_id' => 'STYLE-CY',
'name' => '彩艺货款',
'qty' => 1,
'cost_price' => 178523,
'cost_amount' => 178523,
],
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRICE_TABLE)->insert([
['Id' => 101, 'skucode' => 'SKU-YZH-GOODS', 'priceType' => '1', 'afterPrice' => 58665, 'effectStartTime' => '2026-11-01 00:00:00'],
['Id' => 102, 'skucode' => 'SKU-YZH-RETURN', 'priceType' => '1', 'afterPrice' => 4554.50, 'effectStartTime' => '2026-11-01 00:00:00'],
['Id' => 103, 'skucode' => 'SKU-CY-GOODS', 'priceType' => '1', 'afterPrice' => 178523, 'effectStartTime' => '2026-11-01 00:00:00'],
['Id' => 104, 'skucode' => 'SKU-CY-RETURN', 'priceType' => '1', 'afterPrice' => 19096, 'effectStartTime' => '2026-11-01 00:00:00'],
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRODUCT_TABLE)->insert([
['autoid' => 101, 'sku_id' => 'SKU-YZH-RETURN', 'sku_type' => 'normal', 'supplier_name' => '亿之航', 'cost_price' => 4554.50],
['autoid' => 102, 'sku_id' => 'SKU-CY-RETURN', 'sku_type' => 'normal', 'supplier_name' => '彩艺', 'cost_price' => 19096],
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::RETURN_HEAD_TABLE)->insert([
'Id' => 201,
'io_id' => 6201,
'io_date' => '2026-11-20 10:00:00',
'status' => 'Confirmed',
'warehouse' => '正常仓',
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::RETURN_ITEM_TABLE)->insert([
[
'Id' => 201,
'io_id' => 6201,
'ioi_id' => 'RETURN-YZH',
'sku_id' => 'SKU-YZH-RETURN',
'i_id' => 'STYLE-YZH-RETURN',
'name' => '亿之航退货',
'qty' => 1,
'cost_price' => 4554.50,
'cost_amount' => 4554.50,
],
[
'Id' => 202,
'io_id' => 6201,
'ioi_id' => 'RETURN-CY',
'sku_id' => 'SKU-CY-RETURN',
'i_id' => 'STYLE-CY-RETURN',
'name' => '彩艺退货',
'qty' => 1,
'cost_price' => 19096,
'cost_amount' => 19096,
],
]);
DB::connection('business_mirror')->table(SupplierPayableForecastSummaryRepository::METADATA_TABLE)->insert([
[
'id' => 101,
'Month' => '2026-11',
'company' => '常州市亿之航家具科技有限公司',
'supplier' => '亿之航',
'ExpFieght' => 0,
'loan' => 999999,
'refund' => 888888,
'advloan' => 0,
'invoiceDct' => 0,
'boardDct' => 49190,
'specimenDct' => 0,
'guessPrice' => 12345,
'unpriced' => 0,
],
[
'id' => 102,
'Month' => '2026-11',
'company' => '曹县美莱客木制品有限公司',
'supplier' => '彩艺',
'ExpFieght' => 0,
'loan' => 0,
'refund' => 0,
'advloan' => 0,
'invoiceDct' => 0,
'boardDct' => 0,
'specimenDct' => 0,
'guessPrice' => 0,
'unpriced' => 0,
],
]);
$response = $this->loginAs()->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-negative-alert',
'tab' => 'payable-forecast',
'forecast_view' => 'summary',
]))
->assertOk()
->assertSeeText('亿之航')
->assertSeeText('54,110.50')
->assertSeeText('4,920.50')
->assertSeeText('159,427.00');
$html = (string) $response->getContent();
$tableStart = strpos($html, 'data-summary-table');
$tableEnd = $tableStart === false ? false : strpos($html, '', $tableStart);
$this->assertNotFalse($tableStart);
$this->assertNotFalse($tableEnd);
preg_match_all('/ | ]*>(.*?)<\/th>/s', substr($html, $tableStart, $tableEnd - $tableStart), $headers);
$labels = array_map(
static fn (string $label): string => trim(html_entity_decode(strip_tags($label), ENT_QUOTES | ENT_HTML5, 'UTF-8')),
$headers[1],
);
$this->assertSame([
'月份',
'供应商简称',
'运费',
'货款金额',
'退货金额',
'预支借款',
'小计',
'发票扣款',
'板材扣款',
'预估板材扣款',
'样品扣款',
'预估金额',
'未定价-本月定价',
'供应商余额',
], $labels);
$this->assertStringContainsString('title="预估金额逻辑待接入"', $html);
$this->assertStringContainsString('data-estimated-amount-pending', $html);
$this->assertStringContainsString('position: sticky', $html);
$filteredHtml = (string) $this->loginAs()->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-negative-alert',
'tab' => 'payable-forecast',
'forecast_view' => 'summary',
'summary_month' => '2026-11',
'summary_keyword' => '彩艺',
]))
->assertOk()
->getContent();
$filteredStart = strpos($filteredHtml, 'data-summary-table');
$filteredEnd = $filteredStart === false ? false : strpos($filteredHtml, '', $filteredStart);
$this->assertNotFalse($filteredEnd);
$filteredSummary = substr($filteredHtml, $filteredStart, $filteredEnd - $filteredStart);
$this->assertStringContainsString('彩艺', $filteredSummary);
$this->assertStringNotContainsString('亿之航', $filteredSummary);
}
public function test_supplier_negative_alert_filters_by_month_and_supplier(): void
{
$this->saveSupplierPayable('negative:sep', '九月负余额供应商', '-99.00', '2026-09');
$this->saveSupplierPayable('negative:aug', '八月负余额供应商', '-66.00', '2026-08');
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-negative-alert',
'tab' => 'alert',
'month' => '2026-08',
'supplier' => '八月负余额',
]))
->assertOk()
->assertSeeText('八月负余额供应商')
->assertSeeText('-66.00')
->assertDontSeeText('九月负余额供应商');
}
public function test_supplier_negative_alert_filters_by_checker_settlement_and_purchaser(): void
{
$this->saveSupplierPayable('filter:target', '目标供应商', '-50.00', '2026-09', [
'checker' => '李萌',
'settlement_method' => '订单合同',
]);
$this->saveSupplierPayable('filter:other', '其他供应商', '-60.00', '2026-09', [
'checker' => '陈亲园',
'settlement_method' => '终止合作',
]);
$supplierManagement = \Mockery::mock(SupplierManagementMirrorRepository::class);
$supplierManagement->shouldReceive('suppliersByNames')
->andReturn([
(object) ['scmname' => '目标供应商', 'buyer' => '采购甲'],
(object) ['scmname' => '其他供应商', 'buyer' => '采购乙'],
]);
$this->app->instance(SupplierManagementMirrorRepository::class, $supplierManagement);
app(SupplierNegativeAlertDingTalkWorkflow::class)->saveConfiguration(
'https://oapi.dingtalk.com/robot/send?access_token=test-token',
'SEC-test',
'财务&采购沟通群',
);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-negative-alert',
'tab' => 'alert',
]))
->assertOk()
->assertSeeText('一键发送待处理采购(2 人)');
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-negative-alert',
'tab' => 'alert',
'checker' => '李萌',
'settlement_method' => '订单合同',
'purchaser' => '采购甲',
]))
->assertOk()
->assertSeeText('目标供应商')
->assertSeeText('采购甲')
->assertSeeText('发送给 采购甲(1 家待处理)')
->assertDontSeeText('其他供应商');
}
public function test_supplier_negative_alert_route_no_longer_renders_under_supplier_reconciliation(): void
{
$this->withExceptionHandling()
->loginAs()
->get(route('business.pages.show', [
'section' => 'supplier-reconciliation',
'page' => 'supplier-negative-alert',
]))
->assertRedirect();
}
public function test_goods_details_render_payment_reconciliation_headers_from_shared_mirror(): void
{
$this->createSupplierPayableForecastTables();
$now = now();
DB::connection('business_mirror')->table('business_mirror_table_states')->insert([
['dataset_key' => SupplierPayableForecastRepository::HEAD_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
['dataset_key' => SupplierPayableForecastRepository::ITEM_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
['dataset_key' => SupplierPayableForecastRepository::PRICE_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::HEAD_TABLE)->insert([
'Id' => 1,
'io_id' => 'IN-20261001',
'po_id' => 20261001,
'io_date' => '2026-10-01 10:00:00',
'warehouse' => '简尚-崔桥工厂仓进货仓',
'supplier_name' => '测试供应商',
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::ITEM_TABLE)->insert([
'Id' => 1,
'io_id' => 'IN-20261001',
'ioi_id' => 'ITEM-1',
'sku_id' => 'SKU-20261001',
'i_id' => 'STYLE-20261001',
'name' => '测试商品',
'qty' => 2,
'cost_price' => 10,
'cost_amount' => 20,
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRICE_TABLE)->insert([
'Id' => 1,
'skucode' => 'SKU-20261001',
'priceType' => '1',
'afterPrice' => 12,
'effectStartTime' => '2026-10-01 08:00:00',
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRICE_TABLE)->insert([
'Id' => 2,
'skucode' => 'SKU-DAIFA',
'priceType' => '1',
'afterPrice' => 15,
'effectStartTime' => '2026-10-01 08:00:00',
]);
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::SHIPPING_TABLE)->insert([
'id' => 1,
'source_id' => 9001,
'sku_source_id' => 101,
'ship_time' => '2026-10-01 11:00:00',
'warehouse_name' => '工厂-河北雅柏代发仓',
'supplier_name' => '代发测试供应商',
'barcode' => 'SKU-DAIFA',
'product_code' => 'STYLE-DAIFA',
'product_name' => '代发测试商品',
'qty' => 4,
'express_name1' => '代发测试快递',
'express_no' => 'SF-DAIFA-001',
'seller_memo' => '代发测试备注',
]);
$syncRuns = app(SupplierPayableForecastSyncRunStore::class);
$monthlyRunId = $syncRuns->start(
'monthly',
now('Asia/Shanghai')->subMonthNoOverflow()->startOfMonth(),
now('Asia/Shanghai')->subMonthNoOverflow()->endOfMonth(),
);
$syncRuns->complete(
$monthlyRunId,
['total' => 10, 'quantity' => 10, 'amount' => 1000, 'estimated_amount_after_discount' => 100],
['total' => 12, 'quantity' => 13, 'amount' => 1200, 'estimated_amount_after_discount' => 160],
);
$response = $this->loginAs()->get(route('business.pages.show', [
'section' => 'negative-alerts',
'page' => 'supplier-negative-alert',
'tab' => 'payable-forecast',
]))->assertOk()
->assertSeeText('供应商货款明细已接入')
->assertSeeText('IN-20261001')
->assertSeeText('20261001')
->assertSeeText('STYLE-20261001')
->assertSeeText('SKU-20261001')
->assertSeeText('测试供应商')
->assertSeeText('STYLE-DAIFA')
->assertSeeText('SKU-DAIFA')
->assertSeeText('代发测试供应商')
->assertSeeText('代发测试供应商SKU-DAIFA')
->assertSeeText('工厂-河北雅柏代发仓')
->assertSeeText('代发测试快递')
->assertSeeText('SF-DAIFA-001')
->assertSeeText('2026-10')
->assertSeeText('测试供应商SKU-20261001')
->assertSeeTextInOrder([
'金额合计(万元)',
'0.01',
'预估金额×0.8合计(万元)',
'0.00',
])
->assertSeeText('24.00')
->assertSeeText('60.00')
->assertSeeText('数据来源')
->assertSeeText('最近入库')
->assertSeeText('最近发货')
->assertSeeText('上月重跑')
->assertSeeText('+2 行')
->assertSeeText('+3.00 件')
->assertSeeText('+0.02 万元');
$html = (string) $response->getContent();
$closedThrough = now('Asia/Shanghai')->subDay()->endOfDay()->format('Y-m-d H:i:s');
$this->assertStringContainsString(
'name="goods_date_to" value="' . $closedThrough . '"',
$html,
);
$this->assertStringContainsString('data-date-picker', $html);
$this->assertStringContainsString('data-date-input', $html);
$this->assertStringContainsString('data-date-time', $html);
$this->assertStringContainsString('data-date-end-of-day', $html);
$this->assertStringContainsString("timeField('hour', '时', 23", $html);
$this->assertStringContainsString("timeField('second', '秒', 59", $html);
$this->assertStringContainsString('业务日期起', $html);
$this->assertStringContainsString('2026-10-01 00:00:00', $html);
$this->assertStringContainsString('name="goods_source"', $html);
$this->assertStringContainsString(' |