CaiWuXiTong/tests/Feature/Business/FinanceLedgerNavigationTest.php
shanshi 1114349ac7 feat(财务台账): 增加银行余额页与直连余额滚动 (#1399)
资金台账新增银行余额页、直连余额滚动、日期筛选、列设置和页内余额校正。
2026-11-25 12:01:46 +08:00

868 lines
37 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 App\Models\Auth\Permission;
use App\Models\Auth\Role;
use App\Models\Auth\User;
use App\Utilities\BusinessNavigation;
use App\Utilities\SidebarMenu;
use App\Utilities\SidebarPermissions;
use Illuminate\Support\Facades\DB;
use Modules\EcommerceFinance\View\FinanceLedgerPageData;
use Tests\Feature\FeatureTestCase;
class FinanceLedgerNavigationTest extends FeatureTestCase
{
public function test_shop_flows_follows_ledger_under_financial_operations(): void
{
$navigation = collect(BusinessNavigation::all())->keyBy('slug');
$financialOperations = $navigation->get('financial-operations');
$this->assertNotNull($financialOperations);
$this->assertSame(
['ledger', 'fund-ledger', 'shop-flows'],
collect($financialOperations['pages'])->pluck('slug')->slice(-3)->values()->all(),
);
$this->assertSame('店铺收支明细', collect($financialOperations['pages'])->last()['title']);
$this->assertFalse($navigation->has('financial-ledger'));
}
public function test_fund_management_groups_account_funds_and_fund_ledger(): void
{
$this->loginAs();
$fundManagement = collect(BusinessNavigation::all())->firstWhere('slug', 'fund-management');
$reports = collect(SidebarMenu::groups($this->user))->firstWhere('title', '经营报表');
$this->assertNotNull($fundManagement);
$visiblePages = array_values(array_filter(
$fundManagement['pages'],
static fn (array $page): bool => ($page['show_in_section_menu'] ?? true) !== false,
));
$this->assertSame([
'账户资金管理',
'资金台账',
], array_column($visiblePages, 'title'));
$this->assertSame('financial-operations', $visiblePages[0]['route_section']);
$this->assertSame('ledger', $visiblePages[0]['route_page']);
$this->assertEmpty($visiblePages[1]['children'] ?? []);
$this->assertSame('financial-operations', $visiblePages[1]['route_section']);
$this->assertSame('fund-ledger', $visiblePages[1]['route_page']);
$this->assertNotNull($reports);
$this->assertSame([
'section' => 'financial-operations',
'page' => 'shop-flows',
'title' => '店铺收支明细',
'icon' => 'receipt_long',
], $reports['items'][0]);
$this->assertSame([
'section' => 'financial-operations',
'page' => 'service-company-reconciliation',
'title' => '服务公司对账',
'icon' => 'fact_check',
], $reports['items'][1]);
}
public function test_company_cost_arrangement_is_not_shown_in_operating_report_shortcuts(): void
{
$this->loginAs();
$reports = collect(SidebarMenu::groups($this->user))->firstWhere('title', '经营报表');
$this->assertNotNull($reports);
$this->assertNotContains(
'company-cost-arrangement',
collect($reports['items'])->pluck('page')->all(),
);
$this->get(route('business.pages.show', [
'section' => 'company-management',
'page' => 'tax-forecast',
]))
->assertOk()
->assertDontSee(
'href="' . route('business.pages.show', [
'section' => 'company-management',
'page' => 'company-cost-arrangement',
]) . '"',
false,
);
}
public function test_service_company_reconciliation_page_opens_from_operating_reports(): void
{
$this->loginAs();
$target = route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'service-company-reconciliation',
]);
$this->get($target)
->assertOk()
->assertSeeText('财务经营报表')
->assertSeeText('服务公司对账')
->assertSeeText('服务公司总览')
->assertSee('prototype-tag-link is-active', false);
$this->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'independent-company-reconciliation',
]) . '?source=legacy')
->assertRedirect($target . '?source=legacy');
}
public function test_ledger_page_and_legacy_link_open_under_financial_operations(): void
{
$this->loginAs();
$target = route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'ledger',
]);
$response = $this->get($target . '?tab=overview')
->assertOk()
->assertSeeText('财务经营报表')
->assertSeeText('账户资金管理')
->assertSee('data-ledger-page', false)
->assertSee('data-ledger-tab="overview"', false)
->assertDontSee('data-ledger-tab="flows"', false)
->assertSee($target . '?tab=accounts', false);
$this->assertSame(1, substr_count($response->getContent(), 'href="' . e($target) . '"'));
$legacy = route('business.pages.show', [
'section' => 'financial-ledger',
'page' => 'ledger',
]);
$this->get($legacy . '?tab=flows')->assertRedirect($target . '?tab=flows');
$this->get($legacy . '/flows')->assertRedirect($target . '?tab=flows');
$this->get(route('business.financial-ledger.accounts.template'))->assertOk();
}
public function test_retired_fund_summary_is_hidden_and_overview_is_default(): void
{
$this->loginAs();
$html = $this->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'ledger',
]))
->assertOk()
->getContent();
$this->assertSame(1, preg_match('/<nav class="ledger-tabbar"[^>]*>(.*?)<\/nav>/s', $html, $tabBar));
$this->assertSame(
['overview', 'bills', 'shops', 'mapping', 'sources'],
preg_match_all('/data-ledger-tab="([^"]+)"/', $tabBar[1], $tabKeys) ? $tabKeys[1] : []
);
$this->assertStringNotContainsString('账户总表', $tabBar[1]);
$this->assertStringNotContainsString('账户资金汇总', $tabBar[1]);
$this->assertMatchesRegularExpression(
'/aria-selected="true"[^>]*data-ledger-tab="overview"|data-ledger-tab="overview"[^>]*aria-selected="true"/',
$html,
);
}
public function test_account_basics_is_a_card_index_for_account_types(): void
{
$this->loginAs();
$html = $this->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'ledger',
]) . '?tab=flows&flows_view=basic')
->assertOk()
->assertSeeText('账户基本信息')
->assertSeeText('银行账户')
->assertSeeText('支付宝')
->assertSeeText('网商银行')
->assertSeeText('旧网银钱包')
->assertSeeText('其他账户')
->assertSee('data-account-type-card="bank"', false)
->assertSee('data-account-type-card="non_store"', false)
->assertSee('data-account-type-card="wangshang"', false)
->assertSee('data-account-type-card="wallet"', false)
->assertSee('data-account-type-card="other"', false);
$content = $html->getContent();
$accountsStart = strpos($content, 'id="ledger-panel-accounts"');
$shopsStart = strpos($content, 'id="ledger-panel-shops"', $accountsStart ?: 0);
$flowsStart = strpos($content, 'id="ledger-panel-flows"', $shopsStart ?: 0);
$transactionsStart = strpos($content, 'id="ledger-panel-transactions"', $flowsStart ?: 0);
$this->assertIsInt($accountsStart);
$this->assertIsInt($shopsStart);
$this->assertIsInt($flowsStart);
$this->assertIsInt($transactionsStart);
$this->assertStringNotContainsString(
'data-account-type-card=',
substr($content, $accountsStart, $shopsStart - $accountsStart),
);
$this->assertStringContainsString(
'data-account-type-card="bank"',
substr($content, $flowsStart, $transactionsStart - $flowsStart),
);
$this->assertStringContainsString('accounts_view=bank', $content);
$this->assertStringContainsString('accounts_view=wallet', $content);
$this->assertStringContainsString('accounts_view=other', $content);
foreach (array_keys(FinanceLedgerPageData::ACCOUNT_TYPE_VIEWS) as $view) {
$this->assertStringContainsString(
'href="' . e(route('business.financial-ledger.account-basic', ['view' => $view])) . '"',
$content,
);
}
}
public function test_account_type_cards_open_standalone_account_pages(): void
{
$this->loginAs();
$backUrl = route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'ledger',
]) . '?tab=overview';
foreach (FinanceLedgerPageData::ACCOUNT_TYPE_VIEWS as $view => $definition) {
$url = route('business.financial-ledger.account-basic', ['view' => $view]);
$html = $this->get($url)
->assertOk()
->assertSeeText($definition['title'])
->assertSeeText('返回账户总览')
->getContent();
$this->assertStringContainsString('data-ledger-standalone-account="' . $view . '"', $html);
$this->assertStringNotContainsString('data-ledger-tab="flows"', $html);
$this->assertStringNotContainsString('aria-label="账户总表账户分类"', $html);
$this->assertStringContainsString('账户基本信息 - ' . $definition['title'], $html);
if ($view === 'wallet') {
$this->assertStringContainsString('data-ledger-wallet-account-table', $html);
} else {
$this->assertStringContainsString('aria-label="' . $definition['title'] . '分页"', $html);
}
$this->assertStringContainsString('action="' . e($url) . '"', $html);
$this->assertStringContainsString('href="' . e($backUrl) . '"', $html);
}
}
public function test_fund_ledger_contains_bank_balance_and_transaction_panels(): void
{
$this->loginAs();
$content = $this->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'fund-ledger',
]))
->assertOk()
->assertSeeText('资金台账')
->assertSee('data-ledger-page-mode="fund-ledger"', false)
->getContent();
$this->assertSame(1, preg_match('/<nav class="ledger-tabbar"[^>]*>(.*?)<\/nav>/s', $content, $tabBar));
$this->assertSame(
['bank_balance', 'transactions'],
preg_match_all('/data-ledger-tab="([^"]+)"/', $tabBar[1], $tabKeys) ? $tabKeys[1] : []
);
$this->assertLessThan(
strpos($tabBar[1], 'data-ledger-tab="transactions"'),
strpos($tabBar[1], 'data-ledger-tab="bank_balance"'),
);
$bankBalanceStart = strpos($content, 'id="ledger-panel-bank_balance"');
$transactionsStart = strpos($content, 'id="ledger-panel-transactions"');
$transactionsEnd = strpos($content, '</section>', $transactionsStart ?: 0);
$this->assertIsInt($bankBalanceStart);
$this->assertIsInt($transactionsStart);
$this->assertIsInt($transactionsEnd);
$this->assertLessThan($transactionsStart, $bankBalanceStart);
$bankBalancePanel = substr($content, $bankBalanceStart, $transactionsStart - $bankBalanceStart);
$this->assertStringContainsString('tab=bank_balance', $bankBalancePanel);
$this->assertStringContainsString('data-loaded="0"', $bankBalancePanel);
$this->assertStringContainsString('data-ledger-bank-balance-loading', $bankBalancePanel);
$this->assertStringContainsString('ledger_bank_balance_partial=1', $bankBalancePanel);
$transactionPanel = substr($content, $transactionsStart, $transactionsEnd - $transactionsStart);
$this->assertStringNotContainsString('aria-label="账户页面导航"', $transactionPanel);
$this->assertStringContainsString('aria-label="动账明细分页"', $transactionPanel);
$this->assertStringContainsString('全部明细', $transactionPanel);
}
public function test_fund_ledger_bank_balance_partial_returns_panel_content_only(): void
{
$this->loginAs();
$this->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'fund-ledger',
]) . '?tab=bank_balance&ledger_bank_balance_partial=1')
->assertOk()
->assertSee('data-bank-balance-inline-summary', false)
->assertSee('data-bank-balance-column-picker', false)
->assertSee('data-bank-balance-date-form', false)
->assertSee('name="period_from"', false)
->assertSee('name="period_to"', false)
->assertSee('aria-label="银行余额明细"', false)
->assertDontSee('data-ledger-tab=', false)
->assertDontSee('data-ledger-bank-balance-loading', false);
}
public function test_fund_ledger_bank_balance_tab_lists_only_bank_accounts(): void
{
$this->loginAs();
$connection = DB::connection('business_mirror');
$connection->table('fin_accounts')->insert([
[
'company_name' => '银行余额测试公司',
'account_short' => '余额测试工行',
'account_type' => '公户',
'bank_name' => '工商银行',
'account_no' => '6222000012345678',
'account_last4' => '5678',
'account_should_keep' => '是',
'current_balance' => 12345.67,
'daily_available' => 12000,
'blocked_amount' => 345.67,
],
[
'company_name' => '银行余额测试公司',
'account_short' => '余额测试支付宝',
'account_type' => '支付宝',
'bank_name' => null,
'account_no' => null,
'account_last4' => null,
'account_should_keep' => '是',
'current_balance' => 900,
'daily_available' => 900,
'blocked_amount' => 0,
],
[
'company_name' => '银行余额测试公司',
'account_short' => '余额测试微信',
'account_type' => '私人微信',
'bank_name' => null,
'account_no' => null,
'account_last4' => null,
'account_should_keep' => '是',
'current_balance' => 500,
'daily_available' => 500,
'blocked_amount' => 0,
],
[
'company_name' => '银行余额测试公司',
'account_short' => '余额测试招行',
'account_type' => '公户',
'bank_name' => '招商银行常州分行',
'account_no' => '5199000012345678',
'account_last4' => '5678',
'account_should_keep' => '是',
'current_balance' => 8300,
'daily_available' => 8300,
'blocked_amount' => 0,
],
[
'company_name' => '银行余额测试公司',
'account_short' => '余额测试个人卡工行',
'account_type' => '个人卡',
'bank_name' => '工商银行',
'account_no' => '6228000012349999',
'account_last4' => '9999',
'account_should_keep' => '是',
'current_balance' => 5000,
'daily_available' => 5000,
'blocked_amount' => 0,
],
]);
$accountIds = $connection->table('fin_accounts')
->whereIn('account_short', ['余额测试工行', '余额测试招行'])
->pluck('id', 'account_short');
$connection->table('fin_flow_summary_account_sources')->insert([
'account_short' => '余额测试工行',
'data_source' => '银企直连',
]);
$connection->table('fin_account_opening')->insert([
[
'account_short' => '余额测试工行',
'opening_date' => '2026-10-17',
'opening_balance' => 12345.67,
],
[
'account_short' => '余额测试招行',
'opening_date' => '2026-10-17',
'opening_balance' => 8300,
],
[
'account_short' => '余额测试个人卡工行',
'opening_date' => '2026-10-17',
'opening_balance' => 5000,
],
]);
$connection->table('fin_bank_direct_balance_snapshots')->insert([
[
'finance_account_id' => (int) $accountIds['余额测试工行'],
'bank_name' => '工商银行',
'account_no' => '6222000012345678',
'account_name' => '银行余额测试公司',
'account_short' => '余额测试工行',
'company_name' => '银行余额测试公司',
'currency' => '人民币',
'account_balance' => 12000,
'available_balance' => 12000,
'balance_date' => '2026-11-25',
'balance_at' => '2026-11-25 09:00:00',
'source' => 'bank-direct',
'source_file_name' => '银行余额.xlsx',
'source_sha256' => str_repeat('a', 64),
'imported_at' => '2026-11-25 09:00:00',
],
[
'finance_account_id' => (int) $accountIds['余额测试招行'],
'bank_name' => '招商银行',
'account_no' => '5199000012345678',
'account_name' => '银行余额测试公司',
'account_short' => '余额测试招行',
'company_name' => '银行余额测试公司',
'currency' => '人民币',
'account_balance' => 8000,
'available_balance' => 8000,
'balance_date' => '2026-11-25',
'balance_at' => '2026-11-25 09:05:00',
'source' => 'bank-direct',
'source_file_name' => '银行余额.xlsx',
'source_sha256' => str_repeat('b', 64),
'imported_at' => '2026-11-25 09:05:00',
],
]);
$connection->table('fin_bank_direct_bills')->insert([
'bank_name' => '招商银行',
'finance_account_id' => (int) $accountIds['余额测试招行'],
'company_name' => '银行余额测试公司',
'account_short' => '余额测试招行',
'account_no' => '5199000012345678',
'txn_date' => '2026-11-25',
'txn_at' => '2026-11-25 09:05:00',
'record_code' => 'BANK-BALANCE-OPENING-TEST',
'income' => 0,
'expense' => 100,
'balance' => 8000,
'row_key' => hash('sha256', 'bank-balance-opening-test'),
]);
$connection->table('fin_daily_flows')->insert([
'flow_date' => '2026-11-01',
'account_short' => '余额测试个人卡工行',
'opening_balance' => 5000,
'inflow' => 0,
'outflow' => 0,
'closing_balance' => 5000,
]);
$content = $this->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'fund-ledger',
]) . '?tab=bank_balance')
->assertOk()
->assertSee('data-bank-balance-inline-summary', false)
->assertSee('aria-label="银行余额明细"', false)
->assertSee('data-bank-balance-row="余额测试工行"', false)
->assertSee('data-bank-balance-row="余额测试招行"', false)
->assertSee('data-bank-balance-row="余额测试个人卡工行"', false)
->assertSeeText('12,000.00')
->assertSeeText('银行账户数')
->getContent();
$bankPanelStart = strpos($content, 'id="ledger-panel-bank_balance"');
$transactionPanelStart = strpos($content, 'id="ledger-panel-transactions"', $bankPanelStart ?: 0);
$this->assertIsInt($bankPanelStart);
$this->assertIsInt($transactionPanelStart);
$bankPanel = substr($content, $bankPanelStart, $transactionPanelStart - $bankPanelStart);
$this->assertSame(
['账户简称', '所属银行', '账户类型', '是否银企直连', '银企直连余额', '期初余额', '当前余额', '与银企直连余额差异', '公司名称', '账号', '开户行'],
preg_match_all('/<th[^>]*>(.*?)<\/th>/s', $bankPanel, $headers)
? array_map(static fn (string $header): string => trim(strip_tags($header)), $headers[1])
: [],
);
$this->assertStringContainsString('余额测试工行', $bankPanel);
$this->assertStringContainsString('银行余额测试公司', $bankPanel);
$this->assertStringContainsString('6222000012345678', $bankPanel);
$this->assertStringContainsString('工商银行', $bankPanel);
$this->assertSame(
1,
preg_match(
'/<tr\b[^>]*data-bank-balance-row="余额测试招行"[^>]*>(.*?)<\/tr>/s',
$bankPanel,
$cmbRow,
),
);
$this->assertMatchesRegularExpression(
'/data-bank-balance-column-key="bank_direct_connection"[^>]*>\s*是\s*<\/td>/',
$cmbRow[1],
);
$this->assertStringContainsString('公户', $cmbRow[1]);
$this->assertStringContainsString('8,000.00', $cmbRow[1]);
$this->assertStringContainsString('8,100.00', $cmbRow[1]);
$this->assertStringContainsString('0.00', $cmbRow[1]);
$this->assertSame(
1,
preg_match(
'/<tr\b[^>]*data-bank-balance-row="余额测试个人卡工行"[^>]*>(.*?)<\/tr>/s',
$bankPanel,
$personalCardRow,
),
);
$this->assertMatchesRegularExpression(
'/data-bank-balance-column-key="bank_direct_connection"[^>]*>\s*否\s*<\/td>/',
$personalCardRow[1],
);
$this->assertStringContainsString('个人卡', $personalCardRow[1]);
$this->assertStringContainsString('5,000.00', $personalCardRow[1]);
$this->assertStringContainsString('银企直连余额日期:2026-11-25', $bankPanel);
$this->assertStringNotContainsString('余额测试支付宝', $bankPanel);
$this->assertStringNotContainsString('余额测试微信', $bankPanel);
}
public function test_bank_balance_edit_is_page_local_and_column_filters_apply(): void
{
$connection = DB::connection('business_mirror');
$today = now()->toDateString();
$directId = $connection->table('fin_accounts')->insertGetId([
'company_name' => '页面校正测试公司',
'account_short' => '页面校正测试招行',
'account_type' => '公户',
'bank_name' => '招商银行常州分行',
'account_no' => '5199000099990001',
'account_should_keep' => '是',
'current_balance' => 120,
'daily_available' => 120,
'blocked_amount' => 0,
]);
$connection->table('fin_accounts')->insert([
'company_name' => '页面筛选测试公司',
'account_short' => '页面筛选测试工行',
'account_type' => '公户',
'bank_name' => '工商银行',
'account_no' => '6222000099990002',
'account_should_keep' => '是',
'current_balance' => 77,
'daily_available' => 77,
'blocked_amount' => 0,
]);
$connection->table('fin_flow_summary_account_sources')->insert([
'account_short' => '页面校正测试招行',
'data_source' => '银企直连',
'updated_by' => '测试',
]);
$connection->table('fin_account_opening')->insert([
[
'account_short' => '页面校正测试招行',
'opening_date' => '2026-10-17',
'opening_balance' => 100,
],
[
'account_short' => '页面筛选测试工行',
'opening_date' => '2026-10-17',
'opening_balance' => 77,
],
]);
$connection->table('fin_transactions')->insert([
'txn_date' => '2026-11-18',
'account_short' => '页面校正测试招行',
'detail' => '页面校正测试收入',
'income' => 20,
'expense' => 0,
'source' => 'manual',
'source_value' => null,
'row_key' => hash('sha256', 'bank-balance-edit-income'),
'synced_at' => '2026-11-18 10:00:00',
'created_at' => '2026-11-18 10:00:00',
'updated_at' => '2026-11-18 10:00:00',
]);
$connection->table('fin_transactions')->insert([
'txn_date' => $today,
'account_short' => '页面校正测试招行',
'detail' => '银企直连余额次日的今日收入',
'income' => 5,
'expense' => 0,
'source' => 'manual',
'source_value' => null,
'row_key' => hash('sha256', 'bank-balance-edit-same-day-income'),
'synced_at' => $today . ' 10:00:00',
'created_at' => $today . ' 10:00:00',
'updated_at' => $today . ' 10:00:00',
]);
$connection->table('fin_transactions')->insert([
'txn_date' => '2026-11-21',
'account_short' => '页面校正测试招行',
'detail' => '银企直连余额更新次日后收入',
'income' => 10,
'expense' => 0,
'source' => 'manual',
'source_value' => null,
'row_key' => hash('sha256', 'bank-balance-edit-after-direct-balance'),
'synced_at' => '2026-11-21 10:00:00',
'created_at' => '2026-11-21 10:00:00',
'updated_at' => '2026-11-21 10:00:00',
]);
$connection->table('fin_bank_direct_balance_snapshots')->insert([
'finance_account_id' => $directId,
'bank_name' => '招商银行',
'account_no' => '5199000099990001',
'account_name' => '页面校正测试公司',
'account_short' => '页面校正测试招行',
'company_name' => '页面校正测试公司',
'currency' => '人民币',
'account_balance' => 130,
'available_balance' => 130,
'balance_date' => '2026-11-20',
'balance_at' => '2026-11-20 09:00:00',
'source' => 'bank-direct',
'source_file_name' => '银行余额.xlsx',
'source_sha256' => str_repeat('d', 64),
'imported_at' => '2026-11-20 09:10:00',
]);
$this->loginAs()->postJson(route('business.financial-ledger.bank-balances.current.update'), [
'account_short' => '页面校正测试招行',
'current_balance' => 150,
])
->assertOk()
->assertJsonPath('current_balance', 150)
->assertJsonPath('is_direct', true)
->assertJsonPath('adjustment_amount', 15);
$this->assertSame(
120.0,
(float) $connection->table('fin_accounts')
->where('id', $directId)
->value('current_balance'),
);
$this->assertSame(1, $connection->table('fin_bank_balance_current_adjustments')
->where('account_short', '页面校正测试招行')
->where('adjustment_amount', 15)
->count());
$this->assertSame(1, $connection->table('fin_ledger_edit_events')
->where('entity_type', 'bank_balance_update')
->where('entity_key', 'account|页面校正测试招行')
->count());
$this->loginAs()->postJson(route('business.financial-ledger.bank-balances.current.update'), [
'account_short' => '页面筛选测试工行',
'current_balance' => 99,
])
->assertOk()
->assertJsonPath('current_balance', 99)
->assertJsonPath('is_direct', false);
$this->assertSame(
77.0,
(float) $connection->table('fin_accounts')
->where('account_short', '页面筛选测试工行')
->value('current_balance'),
);
$filterUrl = route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'fund-ledger',
]) . '?' . http_build_query([
'tab' => 'bank_balance',
'bank_balance_filters' => json_encode([
'account_display_short' => ['页面校正测试招行'],
], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR),
], '', '&', PHP_QUERY_RFC3986);
$html = $this->get($filterUrl)->assertOk()->getContent();
$this->assertStringContainsString('data-bank-balance-row="页面校正测试招行"', $html);
$this->assertStringNotContainsString('data-bank-balance-row="页面筛选测试工行"', $html);
$this->assertStringContainsString('data-bank-balance-filter-key="account_display_short"', $html);
$this->assertStringContainsString('const serverFilterValues =', $html);
$this->assertStringContainsString('150.00', $html);
$this->assertStringContainsString('130.00', $html);
$this->assertStringContainsString('20.00', $html);
$historicalUrl = route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'fund-ledger',
]) . '?' . http_build_query([
'tab' => 'bank_balance',
'period_from' => '2026-11-01',
'period_to' => '2026-11-19',
'bank_balance_filters' => json_encode([
'account_display_short' => ['页面校正测试招行'],
], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR),
], '', '&', PHP_QUERY_RFC3986);
$historicalHtml = $this->get($historicalUrl)->assertOk()->getContent();
$this->assertStringContainsString('135.00', $historicalHtml);
$this->assertStringNotContainsString('data-bank-balance-row="页面筛选测试工行"', $historicalHtml);
}
public function test_regular_account_cannot_edit_bank_balance_current(): void
{
$viewer = $this->regularAccount();
$this->withExceptionHandling()
->loginAs($viewer)
->postJson(route('business.financial-ledger.bank-balances.current.update'), [
'account_short' => '余额测试工行',
'current_balance' => 1,
])
->assertForbidden();
}
public function test_legacy_transaction_url_redirects_to_fund_ledger(): void
{
$this->loginAs();
$this->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'ledger',
]) . '?tab=transactions&txns_from=2026-11-01&txns_to=2026-11-30')
->assertRedirect(
route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'fund-ledger',
]) . '?txns_from=2026-11-01&txns_to=2026-11-30'
);
}
public function test_legacy_wallet_page_uses_empty_custom_headers(): void
{
$this->loginAs();
$content = $this->get(route('business.financial-ledger.account-basic', ['view' => 'wallet']))
->assertOk()
->getContent();
$this->assertSame(
1,
preg_match('/<table\b[^>]*data-ledger-wallet-account-table[^>]*>(.*?)<\/table>/s', $content, $table),
);
preg_match_all('/<th>(.*?)<\/th>/s', $table[1], $headers);
$this->assertSame(
['店铺名称', '店铺ID', '钱包号', '主体公司', '提现账户', '提现账号', '是否保留'],
array_map('trim', $headers[1] ?? []),
);
$this->assertStringContainsString('暂无数据', $table[1]);
$this->assertStringNotContainsString('data-ledger-account-row=', $table[1]);
}
public function test_legacy_independent_company_reconciliation_permission_follows_the_renamed_page(): void
{
$regular = $this->regularAccount();
$subject = 'user_' . $regular->id;
setting()->set('system.sidebar_permissions', [
'configured' => [$subject],
'subjects' => [$subject => ['financial-operations/independent-company-reconciliation']],
]);
$this->assertSame(
['financial-operations/service-company-reconciliation'],
SidebarPermissions::allowedKeys($regular)
);
$navigation = SidebarPermissions::navigationFor($regular);
$this->assertSame(['financial-operations'], array_column($navigation, 'slug'));
$this->assertSame(['service-company-reconciliation'], array_column($navigation[0]['pages'], 'slug'));
}
public function test_ledger_actions_use_financial_operations_permission(): void
{
foreach ([
'business.financial-operations.ledger.mapping.update',
'business.financial-ledger.mapping.update',
'business.financial-ledger.accounts.status',
'business.financial-ledger.accounts.type',
'business.financial-ledger.accounts.template',
'business.financial-ledger.transactions.account.update',
'business.financial-ledger.transactions.local.update',
'business.financial-ledger.transactions.local.delete',
'business.financial-ledger.transactions.import.template',
'business.financial-ledger.transactions.import.preview',
'business.financial-ledger.transactions.import.commit',
'business.financial-ledger.mapping.shop.preview',
'business.financial-ledger.mapping.shop.apply',
'business.financial-ledger.mapping.payable.preview',
'business.financial-ledger.mapping.payable.apply',
] as $routeName) {
$route = app('router')->getRoutes()->getByName($routeName);
$this->assertNotNull($route, $routeName);
$this->assertContains(
'business.page:financial-operations,ledger',
$route->gatherMiddleware(),
$routeName
);
}
}
public function test_legacy_ledger_permissions_follow_the_page(): void
{
$regular = $this->regularAccount();
$subject = 'user_' . $regular->id;
foreach (['financial-ledger', 'financial-ledger/ledger'] as $legacyKey) {
setting()->set('system.sidebar_permissions', [
'configured' => [$subject],
'subjects' => [$subject => [$legacyKey]],
]);
$this->assertSame(
[
'financial-operations/ledger',
'financial-operations/fund-ledger',
'financial-operations/shop-flows',
'financial-operations/service-company-reconciliation',
],
SidebarPermissions::allowedKeys($regular)
);
$navigation = SidebarPermissions::navigationFor($regular);
$this->assertSame(
['fund-management', 'financial-operations'],
array_column($navigation, 'slug'),
);
$this->assertSame(
['ledger', 'fund-ledger'],
array_column($navigation[0]['pages'], 'slug'),
);
$this->assertSame(
['service-company-reconciliation', 'ledger', 'fund-ledger', 'shop-flows'],
array_column($navigation[1]['pages'], 'slug')
);
}
$this->loginAs($regular)
->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'ledger',
]))
->assertOk()
->assertSee('data-ledger-page', false);
}
private function regularAccount(): User
{
$name = 'fixture-finance-ledger-' . User::count();
$user = User::create([
'name' => $name,
'email' => $name . '@example.test',
'password' => 'fixture-unused-password',
'enabled' => true,
'locale' => 'zh-CN',
'landing_page' => 'dashboard',
]);
$user->roles()->attach(Role::where('name', 'user')->firstOrFail()->id);
$user->permissions()->attach(Permission::where('name', 'read-admin-panel')->firstOrFail()->id);
$user->companies()->attach($this->company->id);
return $user;
}
}