user->attachPermission( Permission::where('name', 'read-admin-panel')->firstOrFail(), ); $connection = DB::connection('business_mirror'); foreach ([ [ 'company_name' => '保留直连公司', 'account_short' => '保留直连工行', 'account_type' => '公户', 'bank_name' => '中国工商银行上海分行', 'account_no' => '100200300400', 'single_limit' => '50000', 'daily_limit' => '100000', 'monthly_limit' => '500000', 'yearly_limit' => '5000000', 'company_plan' => '保留', 'account_should_keep' => '是', 'current_balance' => 100000, 'daily_available' => 80000, 'blocked_amount' => 20000, 'owner' => '张三', 'remark' => '保留账户备注', ], [ 'company_name' => '保留手动公司', 'account_short' => '保留手动支付宝', 'account_type' => '支付宝', 'account_no' => 'alipay@example.com', 'alipay_merchant_no' => '20880001', 'alipay_account_kind' => '企业支付宝', 'company_plan' => '保留', 'account_should_keep' => '是', 'current_balance' => 50000, 'daily_available' => 50000, 'blocked_amount' => 0, ], [ 'company_name' => '不保留银行公司', 'account_short' => '不保留华夏', 'account_type' => '公户', 'bank_name' => '华夏银行常州分行', 'account_no' => '131500000001', 'company_plan' => '不保留', 'account_should_keep' => '否', 'current_balance' => 30000, 'daily_available' => 30000, 'blocked_amount' => 0, ], [ 'company_name' => '不保留网商公司', 'account_short' => '不保留网商', 'account_type' => '网商银行', 'account_no' => 'wangshang@example.com', 'company_plan' => '不保留', 'account_should_keep' => '否', 'current_balance' => 12000, 'daily_available' => 10000, 'blocked_amount' => 2000, ], ] as $account) { $connection->table('fin_accounts')->insert($account); } $connection->table('fin_flow_summary_account_sources')->insert([ ['account_short' => '保留直连工行', 'data_source' => '银企直连', 'updated_by' => '测试'], ['account_short' => '保留手动支付宝', 'data_source' => '手动', 'updated_by' => '测试'], ['account_short' => '不保留华夏', 'data_source' => '手动', 'updated_by' => '测试'], ['account_short' => '不保留网商', 'data_source' => '手动', 'updated_by' => '测试'], ]); foreach ([ [ 'account_short' => '不保留华夏', 'owner_name' => '财务甲乙', 'started_at' => '2026-11-16', 'completed_at' => '2026-11-17', 'current_progress' => 'completed', 'updated_by' => '测试', ], [ 'account_short' => '不保留网商', 'owner_name' => '财务丙', 'started_at' => '2026-11-17', 'current_progress' => 'in_progress', 'updated_by' => '测试', ], ] as $task) { $connection->table('fin_account_keep_todos')->insert($task); } $connection->table('fin_daily_flows')->insert([ [ 'flow_date' => '2026-10-31', 'account_short' => '保留直连工行', 'opening_balance' => 80000, 'inflow' => 10000, 'outflow' => 0, 'closing_balance' => 90000, ], [ 'flow_date' => '2026-11-01', 'account_short' => '保留直连工行', 'opening_balance' => 90000, 'inflow' => 20000, 'outflow' => 10000, 'closing_balance' => 100000, ], ]); } protected function tearDown(): void { Carbon::setTestNow(); parent::tearDown(); } public function test_overview_separates_retained_and_unretained_accounts(): void { $html = $this->loginAs()->get($this->pageUrl())->assertOk()->getContent(); $this->assertStringContainsString('

账户总览

', $html); $this->assertStringContainsString('保留账户资金总览', $html); $this->assertStringContainsString('data-retained-open', $html); $this->assertStringContainsString('data-unretained-open', $html); $this->assertStringContainsString('data-unretained-dialog', $html); $this->assertStringContainsString('data-unretained-distribution', $html); $this->assertStringContainsString('保留账户', $html); $this->assertStringContainsString('不保留账户', $html); $this->assertStringContainsString('旧网银钱包', $html); $this->assertStringContainsString('nsm-column-filter-panel', $html); $this->assertStringContainsString('width: min(13rem, calc(100vw - 1rem))', $html); $this->assertStringContainsString('width: min(17rem, calc(100vw - 1rem))', $html); $this->assertStringContainsString('filterPanel.style.maxHeight', $html); $this->assertStringContainsString('nsm-column-filter-panel.is-options-open', $html); $this->assertStringContainsString('.nsm-dialog.is-column-filter-open', $html); $this->assertStringContainsString( "mount.classList.add('is-column-filter-open');", $html, ); $this->assertStringContainsString('const availableAbove = Math.max(0, rect.top - gap - margin);', $html); $this->assertStringContainsString('const placeAbove = availableBelow < Math.min(preferredHeight, 220)', $html); $this->assertStringContainsString('搜索全部账户的筛选项', $html); $this->assertStringContainsString('data-nsm-filter-apply', $html); $this->assertStringContainsString('data-nsm-filter-sort="asc"', $html); $this->assertStringContainsString('data-nsm-filter-sort="desc"', $html); $this->assertGreaterThanOrEqual(8, substr_count($html, 'data-detail-column-picker-toggle')); $this->assertStringContainsString('data-detail-column-table', $html); $this->assertStringContainsString( 'caiwu.non-store-accounts.detail.bank-inline.columns.v2', $html, ); $this->assertStringContainsString( 'caiwu.non-store-accounts.detail.nsm-alipay-drilldown.columns.v2', $html, ); $this->assertStringContainsString('data-detail-column="current_balance"', $html); $this->assertStringContainsString('data-detail-column="balance_updated_at">余额更新时间', $html); $this->assertStringContainsString('const initializeDetailColumnPickers', $html); $this->assertStringContainsString( "const rows = bankInlineDetail.querySelectorAll('[data-bank-detail-row]');", $html, ); $this->assertStringNotContainsString( "const bankInlineRows = root.querySelectorAll('[data-bank-detail-row]');", $html, ); $this->assertStringContainsString( "row.dataset.bankVisible = matchesBankFilter ? '1' : '0';", $html, ); $this->assertStringContainsString( "const matchesBankFilter = row.dataset.bankVisible !== '0';", $html, ); $this->assertStringContainsString( "table?.dispatchEvent(new CustomEvent('nsm-bank-filter-change'));", $html, ); $this->assertStringContainsString('const hasServerColumns = headers.some(', $html); $this->assertStringContainsString('if (!hasServerColumns) {', $html); $this->assertStringContainsString( '弹窗内明细已经包含全部行,筛选和排序后继续留在当前弹窗。', $html, ); $this->assertStringContainsString('查看处理进度清单', $html); $this->assertStringContainsString('银企直连', $html); $this->assertStringContainsString('非银企直连', $html); $this->assertStringContainsString('15.00 万元', $html); $this->assertStringContainsString('4.20 万元', $html); $this->assertStringContainsString('期末总余额', $html); $this->assertStringContainsString('15.00', $html); $this->assertStringContainsString('可用金额', $html); $this->assertStringContainsString('13.00', $html); $this->assertStringContainsString('不可用金额', $html); $this->assertStringContainsString('2.00', $html); $this->assertStringContainsString('保留账户数', $html); } public function test_retained_dialog_amounts_follow_the_selected_period(): void { DB::connection('business_mirror')->table('fin_flow_summary_account_sources') ->where('account_short', '保留直连工行') ->update(['data_source' => '手动']); $connection = DB::connection('business_mirror'); $connection->table('fin_account_opening')->insert([ 'account_short' => '保留直连工行', 'opening_date' => '2026-10-17', 'opening_balance' => 80000, ]); $connection->table('fin_transactions')->insert([ [ 'txn_date' => '2026-10-31', 'account_short' => '保留直连工行', 'detail' => '保留账户十月收入', 'income' => 10000, 'expense' => 0, 'source' => 'manual', 'source_value' => null, 'row_key' => hash('sha256', 'retained-period-october-income'), 'synced_at' => '2026-10-31 10:00:00', 'created_at' => '2026-10-31 10:00:00', 'updated_at' => '2026-10-31 10:00:00', ], [ 'txn_date' => '2026-11-01', 'account_short' => '保留直连工行', 'detail' => '保留账户十一月收入', 'income' => 20000, 'expense' => 0, 'source' => 'manual', 'source_value' => null, 'row_key' => hash('sha256', 'retained-period-november-income'), 'synced_at' => '2026-11-01 10:00:00', 'created_at' => '2026-11-01 10:00:00', 'updated_at' => '2026-11-01 10:00:00', ], [ 'txn_date' => '2026-11-01', 'account_short' => '保留直连工行', 'detail' => '保留账户十一月支出', 'income' => 0, 'expense' => 10000, 'source' => 'manual', 'source_value' => null, 'row_key' => hash('sha256', 'retained-period-november-expense'), 'synced_at' => '2026-11-01 10:00:00', 'created_at' => '2026-11-01 10:00:00', 'updated_at' => '2026-11-01 10:00:00', ], ]); $response = $this->loginAs()->get($this->pageUrl([ 'period_from' => '2026-10-01', 'period_to' => '2026-10-31', 'retained' => 1, ]))->assertOk(); $response->assertSee('data-retained-period-form', false); $response->assertSee('data-retained-period-submit', false); $response->assertSee('data-retained-period-status', false); $response->assertSeeText('正在重新计算...'); $response->assertSeeText('查询时间段'); $response->assertSee('name="period_from" value="2026-10-01"', false); $response->assertSee('name="period_to" value="2026-10-31"', false); $response->assertSee('data-retained-period-from="2026-10-01"', false); $response->assertSee('data-retained-period-to="2026-10-31"', false); $response->assertSee('data-retained-period-total="140000"', false); $response->assertSee('data-retained-period-available="120000"', false); $response->assertSee('data-retained-period-blocked="20000"', false); $this->loginAs()->get($this->pageUrl([ 'period_from' => '2026-11-01', 'period_to' => '2026-11-30', 'retained' => 1, ])) ->assertOk() ->assertSee('data-retained-period-total="150000"', false) ->assertSee('data-retained-period-available="130000"', false) ->assertSee('data-retained-period-blocked="20000"', false); } public function test_direct_account_income_expense_and_balance_follow_bank_bills(): void { $connection = DB::connection('business_mirror'); $connection->table('fin_accounts')->insert([ 'company_name' => '招行账单测试公司', 'account_short' => '招行账单测试', 'account_type' => '公户', 'bank_name' => '招商银行常州分行', 'account_no' => '5199050000000099', 'account_should_keep' => '是', 'current_balance' => 999, 'daily_available' => 999, 'blocked_amount' => 0, ]); $connection->table('fin_bank_direct_bills')->insert([ [ 'bank_name' => '招商银行', 'company_name' => '招行账单测试公司', 'account_short' => '招行账单测试', 'account_no' => '5199050000000099', 'txn_date' => '2026-10-31', 'txn_at' => '2026-10-31 18:00:00', 'record_code' => 'BILL-OPEN', 'income' => 0, 'expense' => 0, 'balance' => 100000, 'imported_at' => null, 'row_key' => hash('sha256', 'bill-open'), ], [ 'bank_name' => '招商银行', 'company_name' => '招行账单测试公司', 'account_short' => '招行账单测试', 'account_no' => '5199050000000099', 'txn_date' => '2026-11-02', 'txn_at' => '2026-11-02 09:00:00', 'record_code' => 'BILL-IN', 'income' => 50000, 'expense' => 0, 'balance' => 150000, 'imported_at' => null, 'row_key' => hash('sha256', 'bill-in'), ], [ 'bank_name' => '招商银行', 'company_name' => '招行账单测试公司', 'account_short' => '招行账单测试', 'account_no' => '5199050000000099', 'txn_date' => '2026-11-03', 'txn_at' => '2026-11-03 10:00:00', 'record_code' => 'BILL-OUT', 'income' => 0, 'expense' => 20000, 'balance' => 130000, 'imported_at' => '2026-11-03 11:45:00', 'row_key' => hash('sha256', 'bill-out'), ], ]); $connection->table('fin_daily_flows')->insert([ 'flow_date' => '2026-11-02', 'account_short' => '招行账单测试', 'opening_balance' => 1, 'inflow' => 999999, 'outflow' => 0, 'closing_balance' => 1000999, ]); $connection->table('fin_transactions')->insert([ 'row_key' => hash('sha256', 'direct-account-ignored-transaction'), 'txn_date' => '2026-11-03', 'account_short' => '招行账单测试', 'source' => 'manual', 'source_value' => null, 'income' => 888888, 'expense' => 0, ]); $response = $this->loginAs()->get($this->pageUrl([ 'period_from' => '2026-11-01', 'period_to' => '2026-11-30', 'retained' => 1, ]))->assertOk(); $response->assertSee('data-retained-period-total="280000"', false); $response->assertSee('data-retained-period-available="260000"', false); $response->assertSeeText('招行账单测试'); $response->assertSeeText('130,000.00'); $response->assertSeeText('余额更新时间'); $response->assertSeeText('2026-11-03 11:45'); $accountHtml = $this->loginAs()->get($this->pageUrl([ 'view' => 'accounts', 'account_category' => 'bank', 'account_search' => '招行账单测试', 'period_from' => '2026-11-01', 'period_to' => '2026-11-30', ]))->assertOk()->getContent(); $this->assertStringContainsString('招行账单测试', $accountHtml); $this->assertStringContainsString('余额更新时间', $accountHtml); $this->assertStringContainsString('2026-11-03 11:45', $accountHtml); $this->assertMatchesRegularExpression( '/招行账单测试.*?20,000\.00.*?50,000\.00.*?130,000\.00/s', $accountHtml, ); } public function test_locked_monthly_opening_does_not_follow_previous_daily_flow(): void { $connection = DB::connection('business_mirror'); $connection->table('fin_accounts')->insert([ 'company_name' => '期初锁定公司', 'account_short' => '期初锁定账户', 'account_type' => '公户', 'bank_name' => '中国银行常州分行', 'account_no' => '6200000000000001', 'account_should_keep' => '是', 'current_balance' => 312.44, 'daily_available' => 312.44, 'blocked_amount' => 0, ]); $connection->table('fin_account_opening')->insert([ 'account_short' => '期初锁定账户', 'opening_date' => '2026-11-01', 'opening_balance' => 412.44, 'remark' => '系统锁定:2026-10-31 最后一笔实际余额', ]); $connection->table('fin_daily_flows')->insert([ [ 'flow_date' => '2026-10-31', 'company_name' => '期初锁定公司', 'account_short' => '期初锁定账户', 'opening_balance' => -99999, 'inflow' => 0, 'outflow' => 0, 'closing_balance' => -99999, ], [ 'flow_date' => '2026-11-02', 'company_name' => '期初锁定公司', 'account_short' => '期初锁定账户', 'opening_balance' => 412.44, 'inflow' => 0, 'outflow' => 100, 'closing_balance' => 312.44, ], ]); $html = $this->loginAs()->get($this->pageUrl([ 'view' => 'accounts', 'account_category' => 'bank', 'account_search' => '期初锁定账户', 'period_from' => '2026-11-01', 'period_to' => '2026-11-30', ]))->assertOk()->getContent(); $this->assertStringContainsString('期初锁定账户', $html); $this->assertStringContainsString('412.44', $html); $this->assertStringNotContainsString('-99,999.00', $html); } public function test_direct_account_without_period_bills_uses_locked_opening_as_closing(): void { $connection = DB::connection('business_mirror'); $connection->table('fin_accounts')->insert([ 'company_name' => '直连无流水公司', 'account_short' => '直连无流水招行', 'account_type' => '公户', 'bank_name' => '招商银行常州分行', 'account_no' => '519900000000001', 'company_plan' => '保留', 'account_should_keep' => '是', 'current_balance' => 999, 'daily_available' => 999, '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-11-01', 'opening_balance' => 1234.56, 'remark' => '系统锁定:2026-10-31 最后一笔实际余额', ]); $this->loginAs()->get($this->pageUrl([ 'view' => 'accounts', 'keep' => 'retained', 'account_category' => 'bank', 'account_search' => '直连无流水招行', 'period_from' => '2026-11-01', 'period_to' => '2026-11-30', ]))->assertOk(); request()->merge([ 'view' => 'accounts', 'keep' => 'retained', 'account_category' => 'bank', 'account_search' => '直连无流水招行', 'period_from' => '2026-11-01', 'period_to' => '2026-11-30', ]); $page = app(\Modules\EcommerceFinance\View\NonStoreAccountMonitorPageData::class)->page(); $row = collect($page['fundOverview']['bank_accounts']) ->firstWhere('account_short', '直连无流水招行'); $this->assertNotNull($row); $this->assertSame(1234.56, $row['opening_balance']); $this->assertSame(1234.56, $row['closing_balance']); $this->assertSame(1234.56, $row['current_balance']); $this->assertSame('monthly_opening_fallback', $row['balance_source']); $this->assertTrue($row['monthly_opening_locked']); } public function test_missing_monthly_opening_is_not_calculated_from_zero(): void { $connection = DB::connection('business_mirror'); $connection->table('fin_accounts')->insert([ 'company_name' => '缺失期初公司', 'account_short' => '缺失期初工行', 'account_type' => '公户', 'bank_name' => '工商银行', 'account_no' => '6222000099990001', 'company_plan' => '保留', 'account_should_keep' => '是', 'current_balance' => 0, 'daily_available' => 0, 'blocked_amount' => 0, ]); $connection->table('fin_flow_summary_account_sources')->insert([ 'account_short' => '缺失期初工行', 'data_source' => '手动', 'updated_by' => '测试', ]); $connection->table('fin_daily_flows')->insert([ 'flow_date' => '2026-11-10', 'company_name' => '缺失期初公司', 'account_short' => '缺失期初工行', 'opening_balance' => 0, 'inflow' => 98765.43, 'outflow' => 0, 'closing_balance' => 98765.43, ]); $connection->table('fin_transactions')->insert([ 'txn_date' => '2026-11-10', 'account_short' => '缺失期初工行', 'detail' => '无期初收入', 'income' => 98765.43, 'expense' => 0, 'source' => 'manual', 'source_value' => null, 'row_key' => hash('sha256', 'missing-monthly-opening-income'), 'synced_at' => '2026-11-10 10:00:00', 'created_at' => '2026-11-10 10:00:00', 'updated_at' => '2026-11-10 10:00:00', ]); $this->loginAs()->get($this->pageUrl([ 'view' => 'accounts', 'keep' => 'retained', 'account_category' => 'bank', 'account_search' => '缺失期初工行', 'period_from' => '2026-11-01', 'period_to' => '2026-11-30', ]))->assertOk(); request()->merge([ 'view' => 'accounts', 'keep' => 'retained', 'account_category' => 'bank', 'account_search' => '缺失期初工行', 'period_from' => '2026-11-01', 'period_to' => '2026-11-30', ]); $page = app(\Modules\EcommerceFinance\View\NonStoreAccountMonitorPageData::class)->page(); $row = collect($page['fundOverview']['bank_accounts']) ->firstWhere('account_short', '缺失期初工行'); $this->assertNotNull($row); $this->assertNull($row['opening_balance']); $this->assertNull($row['closing_balance']); $this->assertNull($row['current_balance']); $this->assertSame('missing_opening', $row['balance_source']); $this->assertFalse($row['monthly_opening_locked']); } public function test_wangshang_account_balance_uses_bank_bills_instead_of_transaction_flows(): void { $connection = DB::connection('business_mirror'); $connection->table('fin_accounts')->insert([ 'company_name' => '网商余额同步公司', 'account_short' => '网商余额同步测试', 'account_type' => '网商银行', 'bank_name' => '浙江网商银行', 'account_no' => '8888888000000999', 'account_should_keep' => '是', 'current_balance' => 1234, 'daily_available' => 1234, 'blocked_amount' => 0, ]); $connection->table('fin_bank_direct_bills')->insert([ [ 'bank_name' => '网商银行', 'company_name' => '网商余额同步公司', 'account_short' => '网商余额同步测试', 'account_no' => '8888888000000999', 'txn_date' => '2026-11-02', 'txn_at' => '2026-11-02 09:00:00', 'record_code' => 'WS-BALANCE-1', 'income' => 200, 'expense' => 0, 'balance' => 200, 'imported_at' => null, 'row_key' => hash('sha256', 'ws-balance-1'), ], [ 'bank_name' => '网商银行', 'company_name' => '网商余额同步公司', 'account_short' => '网商余额同步测试', 'account_no' => '8888888000000999', 'txn_date' => '2026-11-03', 'txn_at' => '2026-11-03 09:00:00', 'record_code' => 'WS-BALANCE-2', 'income' => 100, 'expense' => 0, 'balance' => 300, 'imported_at' => '2026-11-03 10:28:00', 'row_key' => hash('sha256', 'ws-balance-2'), ], ]); $connection->table('fin_daily_flows')->insert([ 'flow_date' => '2026-11-03', 'account_short' => '网商余额同步测试', 'opening_balance' => 999000, 'inflow' => 999, 'outflow' => 0, 'closing_balance' => 999999, ]); $html = $this->loginAs()->get($this->pageUrl([ 'view' => 'accounts', 'keep' => 'retained', 'account_category' => 'wangshang', 'account_search' => '网商余额同步测试', 'period_from' => '2026-11-01', 'period_to' => '2026-11-30', ]))->assertOk()->getContent(); $this->assertStringContainsString('网商余额同步测试', $html); $this->assertStringContainsString('300.00', $html); $this->assertStringContainsString('余额更新时间', $html); $this->assertStringContainsString('2026-11-03 10:28', $html); $this->assertStringNotContainsString('999,999.00', $html); } public function test_fund_overview_is_inside_retained_dialog_and_groups_by_platform(): void { DB::connection('business_mirror')->table('fin_accounts')->insert([ 'company_name' => '保留网商公司', 'account_short' => '保留网商账户', 'account_type' => '网商银行', 'account_should_keep' => '是', 'current_balance' => 8000, 'daily_available' => 8000, 'blocked_amount' => 0, ]); $html = $this->loginAs()->get($this->pageUrl())->assertOk()->getContent(); $this->assertStringNotContainsString('data-fund-overview-open', $html); $this->assertStringNotContainsString('data-fund-distribution-dialog', $html); $this->assertStringContainsString('data-retained-fund-overview', $html); $this->assertStringContainsString('data-retained-fund-distribution', $html); $this->assertStringContainsString('账户平台资金分布', $html); $this->assertStringContainsString('余额占比', $html); $this->assertStringContainsString('银行账户', $html); $this->assertStringContainsString('支付宝', $html); $this->assertStringContainsString('data-bank-drilldown-open', $html); $this->assertStringContainsString('data-bank-drilldown', $html); $this->assertStringNotContainsString('data-bank-count-menu', $html); $this->assertStringContainsString('data-bank-mode="matrix"', $html); $this->assertStringContainsString('data-bank-panel="matrix"', $html); $this->assertStringContainsString('aria-controls="nsm-bank-drilldown"', $html); $this->assertStringContainsString('aria-expanded="false"', $html); $this->assertStringContainsString('data-connection-toggle="bank_matrix"', $html); $this->assertStringContainsString('data-connection-panel="bank_matrix"', $html); $this->assertStringContainsString('aria-controls="nsm-connection-panel-bank-matrix"', $html); $this->assertStringContainsString('data-bank-connection-matrix', $html); $this->assertStringContainsString('data-bank-inline-detail', $html); $this->assertStringContainsString('data-bank-inline-close', $html); $this->assertStringContainsString('data-bank-detail-open', $html); $this->assertStringContainsString('data-bank-detail-row', $html); $this->assertStringContainsString('银行类型', $html); $this->assertStringContainsString('银企直连', $html); $this->assertStringContainsString('非银企直连', $html); $this->assertStringContainsString('账户合计', $html); $this->assertStringContainsString('当前余额', $html); $this->assertStringContainsString('个人卡不计入银企直连', $html); $this->assertStringContainsString('direct=direct', $html); $this->assertStringContainsString('direct=non_direct', $html); $this->assertStringContainsString('showBankInlineDetail', $html); $this->assertStringContainsString('bankMatrixSummary.hidden = true', $html); $this->assertStringContainsString('bankInlineDetail.hidden = false', $html); $this->assertStringContainsString("row.dataset.accountType !== '个人卡'", $html); $this->assertStringContainsString('收起明细', $html); $this->assertStringContainsString('data-platform-account-open="alipay"', $html); $this->assertStringContainsString('data-platform-account-detail="alipay"', $html); $this->assertStringContainsString('data-platform-account-open="wangshang"', $html); $this->assertStringContainsString('data-platform-account-detail="wangshang"', $html); $retainedDialog = $this->dialogHtml($html, 'data-retained-dialog'); $unretainedDialog = $this->dialogHtml($html, 'data-unretained-dialog'); $this->assertStringNotContainsString('旧网银钱包', $retainedDialog); $this->assertStringNotContainsString('data-platform-account-open="legacy_wallet"', $retainedDialog); $this->assertStringNotContainsString('data-platform-account-detail="legacy_wallet"', $retainedDialog); $this->assertStringContainsString('旧网银钱包', $unretainedDialog); $this->assertStringContainsString('data-platform-account-open="legacy_wallet"', $unretainedDialog); $this->assertStringContainsString('data-platform-account-detail="legacy_wallet"', $unretainedDialog); $this->assertStringContainsString('data-account-archive-open', $html); $this->assertStringContainsString('account_category=all', $html); $this->assertStringContainsString('data-bank-plan-bank="工商银行"', $html); $this->assertStringNotContainsString('bank_group=%E5%8D%8E%E5%A4%8F%E9%93%B6%E8%A1%8C', $html); } public function test_bank_matrix_uses_requested_summary_columns_and_keeps_personal_cards_non_direct(): void { $connection = DB::connection('business_mirror'); $connection->table('fin_accounts')->insert([ [ 'company_name' => '招商直连公司', 'account_short' => '保留招商直连公户', 'account_type' => '公户', 'bank_name' => '招商银行上海分行', 'account_no' => '310000000101', 'account_should_keep' => '是', 'current_balance' => 20000, 'daily_available' => 20000, 'blocked_amount' => 0, ], [ 'company_name' => '华夏个人卡公司', 'account_short' => '保留华夏个人卡', 'account_type' => '个人卡', 'bank_name' => '华夏银行常州分行', 'account_no' => '310000000102', 'account_should_keep' => '是', 'current_balance' => 3000, 'daily_available' => 3000, 'blocked_amount' => 0, ], [ 'company_name' => '华夏非直连公司', 'account_short' => '保留华夏非直连公户', 'account_type' => '公户', 'bank_name' => '华夏银行上海分行', 'account_no' => '310000000104', 'account_should_keep' => '是', 'current_balance' => 4000, 'daily_available' => 4000, 'blocked_amount' => 0, ], [ 'company_name' => '农业非直连公司', 'account_short' => '保留农业非直连', 'account_type' => '公户', 'bank_name' => '农业银行上海分行', 'account_no' => '310000000103', 'account_should_keep' => '是', 'current_balance' => 5000, 'daily_available' => 5000, 'blocked_amount' => 0, ], ]); $connection->table('fin_flow_summary_account_sources')->insert([ ['account_short' => '保留华夏个人卡', 'data_source' => '银企直连', 'updated_by' => '测试'], ['account_short' => '保留华夏非直连公户', 'data_source' => '手动', 'updated_by' => '测试'], ['account_short' => '保留农业非直连', 'data_source' => '手动', 'updated_by' => '测试'], ]); $html = $this->loginAs()->get($this->pageUrl())->assertOk()->getContent(); $this->assertSame(1, preg_match( '/]*\bdata-bank-connection-matrix\b[^>]*>(.*?)<\/table>/s', $html, $matrixMatch, )); $matrix = $matrixMatch[1]; $this->assertStringNotContainsString('data-bank-group="direct"', $matrix); $this->assertStringNotContainsString('data-bank-group="non_direct"', $matrix); $this->assertStringNotContainsString('银企直连银行', $matrix); $this->assertStringNotContainsString('非银企直连银行', $matrix); $this->assertStringContainsString('data-bank-name="华夏银行"', $html); $this->assertStringContainsString('data-bank-connection="non_direct"', $html); $this->assertStringContainsString('data-bank-detail-scope="personal_card"', $html); $this->assertStringContainsString('data-account-type="个人卡"', $html); $this->assertLessThan(strpos($matrix, '华夏银行'), strpos($matrix, '工商银行')); $this->assertLessThan(strpos($matrix, '农业银行'), strpos($matrix, '招商银行')); $this->assertLessThan(strpos($matrix, '个人卡'), strpos($matrix, '农业银行')); $this->assertMatchesRegularExpression( '/\s*\s*]*>\s*华夏银行\s*<\/button>.*?' . '\s*]*>\s*0\s*<\/a>\s*<\/td>.*?' . '\s*]*>\s*1\s*<\/a>\s*<\/td>.*?' . '\s*]*>\s*1\s*<\/a>/s', $matrix, ); $this->assertMatchesRegularExpression( '/\s*\s*]*>\s*个人卡\s*<\/button>.*?' . '\s*]*>\s*0\s*<\/a>\s*<\/td>.*?' . '\s*]*>\s*1\s*<\/a>\s*<\/td>.*?' . '\s*]*>\s*1\s*<\/a>/s', $matrix, ); $this->assertMatchesRegularExpression( '/\s*\s*]*>\s*招商银行\s*<\/button>\s*' . '已直连<\/span>/s', $matrix, ); } public function test_bank_name_inline_summary_splits_retained_accounts_by_company_plan(): void { DB::connection('business_mirror')->table('fin_accounts')->insert([ [ 'company_name' => '招商规划保留公司', 'account_short' => '招商规划保留', 'account_type' => '公户', 'bank_name' => '招商银行上海分行', 'account_no' => '310000000201', 'company_plan' => '保留', 'account_should_keep' => '是', 'current_balance' => 11000, 'daily_available' => 11000, 'blocked_amount' => 0, ], [ 'company_name' => '招商规划不保留公司', 'account_short' => '招商规划不保留', 'account_type' => '公户', 'bank_name' => '招商银行上海分行', 'account_no' => '310000000202', 'company_plan' => '不保留', 'account_should_keep' => '暂时保留', 'current_balance' => 22000, 'daily_available' => 22000, 'blocked_amount' => 0, ], [ 'company_name' => '招商规划未填写公司', 'account_short' => '招商规划未填写', 'account_type' => '公户', 'bank_name' => '招商银行上海分行', 'account_no' => '310000000203', 'company_plan' => null, 'account_should_keep' => '暂时保留', 'current_balance' => 33000, 'daily_available' => 33000, 'blocked_amount' => 0, ], ]); $html = $this->loginAs()->get($this->pageUrl())->assertOk()->getContent(); $this->assertStringContainsString('data-bank-plan-open', $html); $this->assertStringContainsString('data-bank-plan-bank="招商银行"', $html); $this->assertStringContainsString('data-bank-plan-retained-count="1"', $html); $this->assertStringContainsString('data-bank-plan-retained-amount="11000.00"', $html); $this->assertStringContainsString('data-bank-plan-unretained-count="1"', $html); $this->assertStringContainsString('data-bank-plan-unretained-amount="22000.00"', $html); $this->assertStringContainsString('data-bank-plan-unspecified-count="1"', $html); $this->assertStringContainsString('data-bank-plan-unspecified-amount="33000.00"', $html); $this->assertStringContainsString('data-bank-plan-total-count="3"', $html); $this->assertStringContainsString('data-bank-plan-total-amount="66000.00"', $html); $this->assertStringContainsString('data-bank-plan-detail', $html); $this->assertStringContainsString('class="nsm-bank-plan-inline-row"', $html); $this->assertStringContainsString('aria-controls="nsm-bank-plan-', $html); $this->assertStringContainsString('公司规划保留', $html); $this->assertStringContainsString('公司规划不保留', $html); $this->assertStringContainsString('data-bank-plan-unspecified', $html); $this->assertStringContainsString('toggleBankPlanDetail', $html); $this->assertStringContainsString('hideBankPlanDetails', $html); $this->assertStringNotContainsString('data-bank-plan-dialog', $html); } public function test_independent_monthly_accounts_are_included_as_other_accounts(): void { $connection = DB::connection('business_mirror'); $connection->table('fin_accounts')->insert([ [ 'company_name' => '朱俊祥', 'account_short' => '朱俊祥支付宝', 'account_type' => '支付宝', 'account_should_keep' => '是', 'current_balance' => 10000, 'daily_available' => 10000, 'blocked_amount' => 0, ], [ 'company_name' => '朱俊祥', 'account_short' => '朱俊祥微信', 'account_type' => null, 'account_should_keep' => '是', 'current_balance' => 20000, 'daily_available' => 20000, 'blocked_amount' => 0, ], ]); $overviewHtml = $this->loginAs()->get($this->pageUrl())->assertOk()->getContent(); $this->assertStringContainsString('其他账户', $overviewHtml); $this->assertStringContainsString('data-platform-account-open="other"', $overviewHtml); $this->assertStringContainsString('data-platform-account-detail="other"', $overviewHtml); $this->assertStringContainsString('aria-controls="nsm-other-drilldown"', $overviewHtml); $this->assertStringContainsString('data-independent-account-open', $overviewHtml); $this->assertStringContainsString('data-independent-account-view="zhu-junxiang-alipay"', $overviewHtml); $this->assertStringContainsString('data-independent-account-view="zhu-junxiang-wechat"', $overviewHtml); $this->assertStringContainsString('data-independent-account-frame', $overviewHtml); $this->assertStringContainsString('ledger_embed=1', $overviewHtml); $this->assertStringContainsString('朱俊祥支付宝', $overviewHtml); $this->assertStringContainsString('朱俊祥微信', $overviewHtml); $otherAccountsHtml = $this->loginAs()->get($this->pageUrl([ 'view' => 'accounts', 'keep' => 'retained', 'account_category' => 'other', ]))->assertOk()->getContent(); $this->assertStringContainsString('朱俊祥支付宝', $otherAccountsHtml); $this->assertStringContainsString('朱俊祥微信', $otherAccountsHtml); $this->assertStringNotContainsString('保留手动支付宝', $otherAccountsHtml); $embeddedHtml = $this->loginAs()->get(route('business.pages.show', [ 'section' => 'financial-operations', 'page' => 'fund-ledger', ]) . '?tab=transactions&txns_view=zhu-junxiang-alipay&ledger_embed=1') ->assertOk() ->getContent(); $this->assertStringContainsString('data-ledger-embed="1"', $embeddedHtml); $this->assertStringContainsString('html[data-ledger-embed]', $embeddedHtml); $this->assertStringContainsString('', $embeddedHtml); $this->assertStringContainsString('txns_view=zhu-junxiang-alipay&ledger_embed=1', $embeddedHtml); $this->assertStringContainsString('当前为“朱俊祥支付宝”独立账单页', $embeddedHtml); } public function test_legacy_wallet_accounts_are_always_unretained(): void { DB::connection('business_mirror')->table('fin_accounts')->insert([ 'company_name' => '旧钱包公司', 'account_short' => '测试旧网银钱包', 'account_type' => '旧网银钱包', 'company_plan' => '保留', 'account_should_keep' => '是', 'current_balance' => 1234.56, 'daily_available' => 1234.56, 'blocked_amount' => 0, ]); $overviewHtml = $this->loginAs()->get($this->pageUrl())->assertOk()->getContent(); $retainedDialog = $this->dialogHtml($overviewHtml, 'data-retained-dialog'); $unretainedDialog = $this->dialogHtml($overviewHtml, 'data-unretained-dialog'); $this->assertStringNotContainsString('旧网银钱包', $retainedDialog); $this->assertStringNotContainsString('测试旧网银钱包', $retainedDialog); $this->assertStringContainsString('data-platform-account-open="legacy_wallet"', $unretainedDialog); $this->assertStringContainsString('测试旧网银钱包', $unretainedDialog); $retainedHtml = $this->loginAs()->get($this->pageUrl([ 'view' => 'accounts', 'account_category' => 'all', ]))->assertOk()->getContent(); $this->assertStringNotContainsString('测试旧网银钱包', $retainedHtml); $this->assertStringNotContainsString('value="legacy_wallet"', $retainedHtml); $this->assertStringNotContainsString('account_category=legacy_wallet', $retainedHtml); $unretainedHtml = $this->loginAs()->get($this->pageUrl([ 'view' => 'unretained_tasks', 'task_category' => 'legacy_wallet', ]))->assertOk()->getContent(); $this->assertStringContainsString('测试旧网银钱包', $unretainedHtml); } public function test_account_view_switches_columns_with_account_type(): void { $alipayHtml = $this->loginAs()->get($this->pageUrl([ 'view' => 'accounts', 'account_category' => 'alipay', ]))->assertOk()->getContent(); $this->assertStringContainsString('账户档案', $alipayHtml); $this->assertStringContainsString('>支付宝账号', $alipayHtml); $this->assertStringContainsString('>商户号', $alipayHtml); $this->assertStringContainsString('保留手动支付宝', $alipayHtml); $this->assertStringNotContainsString('不保留华夏', $alipayHtml); $this->assertStringNotContainsString('>开户城市/网点', $alipayHtml); $bankHtml = $this->loginAs()->get($this->pageUrl([ 'view' => 'accounts', 'keep' => 'retained', 'direct' => 'direct', 'account_category' => 'bank', 'bank_group' => '工商银行', ]))->assertOk()->getContent(); $this->assertStringContainsString('>账号', $bankHtml); $this->assertStringContainsString('>开户行', $bankHtml); $this->assertStringContainsString('>开户城市/网点', $bankHtml); $this->assertStringContainsString('>公司规划', $bankHtml); $this->assertStringContainsString('>单笔限额', $bankHtml); $this->assertStringContainsString('>日限额', $bankHtml); $this->assertStringContainsString('>月限额', $bankHtml); $this->assertStringContainsString('>年限额', $bankHtml); $this->assertStringContainsString('>期初余额', $bankHtml); $this->assertStringContainsString('>当期支出', $bankHtml); $this->assertStringContainsString('>当期收入', $bankHtml); $this->assertStringContainsString('>期末余额', $bankHtml); $this->assertStringContainsString('>操作', $bankHtml); $this->assertStringContainsString('展示全部', $bankHtml); $this->assertStringContainsString('50,000.00', $bankHtml); $this->assertStringContainsString('100,000.00', $bankHtml); $this->assertStringContainsString('data-ledger-account-edit', $bankHtml); $this->assertStringContainsString('保留直连工行', $bankHtml); $this->assertStringContainsString('name="bank_group"', $bankHtml); $this->assertStringContainsString('