CaiWuXiTong/tests/Feature/Business/FinanceLedgerTransactionBalanceTest.php

149 lines
5.4 KiB
PHP

<?php
namespace Tests\Feature\Business;
use Illuminate\Support\Facades\DB;
use Tests\Feature\FeatureTestCase;
class FinanceLedgerTransactionBalanceTest extends FeatureTestCase
{
public function test_transaction_rows_calculate_non_direct_balances_and_hide_direct_balances(): void
{
$connection = DB::connection('business_mirror');
$connection->table('fin_accounts')->insert([
[
'company_name' => '余额测试公司',
'account_short' => '测试非直连华夏',
'account_type' => '公户',
'bank_name' => '华夏银行测试支行',
'current_balance' => 120,
],
[
'company_name' => '余额测试公司',
'account_short' => '测试直连招行',
'account_type' => '公户',
'bank_name' => '招商银行测试支行',
'current_balance' => 250,
],
[
'company_name' => '余额测试公司',
'account_short' => '测试手动招行',
'account_type' => '公户',
'bank_name' => '招商银行测试支行',
'current_balance' => 290,
],
]);
$connection->table('fin_flow_summary_account_sources')->insert([
[
'account_short' => '测试非直连华夏',
'data_source' => '手动',
],
[
'account_short' => '测试直连招行',
'data_source' => '银企直连',
],
[
'account_short' => '测试手动招行',
'data_source' => '手动',
],
]);
$connection->table('fin_daily_flows')->insert([
[
'flow_date' => '2026-10-18',
'company_name' => '余额测试公司',
'account_short' => '测试非直连华夏',
'opening_balance' => 100,
'inflow' => 30,
'outflow' => 10,
'closing_balance' => 120,
],
[
'flow_date' => '2026-10-18',
'company_name' => '余额测试公司',
'account_short' => '测试直连招行',
'opening_balance' => 200,
'inflow' => 50,
'outflow' => 0,
'closing_balance' => 250,
],
[
'flow_date' => '2026-10-18',
'company_name' => '余额测试公司',
'account_short' => '测试手动招行',
'opening_balance' => 300,
'inflow' => 0,
'outflow' => 10,
'closing_balance' => 290,
],
]);
$connection->table('fin_account_map')->insert([
'source' => 'payable',
'source_value' => 'supplier-balance-test',
'account_short' => '测试非直连华夏',
]);
$connection->table('fin_transactions')->insert([
[
'txn_date' => '2026-10-18',
'account_short' => '测试供应商原始名称',
'detail' => '非直连收入',
'income' => 30,
'expense' => 0,
'approval_no' => 'TEST-NONDIRECT-INCOME',
'source' => 'payable',
'source_value' => 'supplier-balance-test',
'row_key' => hash('sha256', 'test-nondirect-income'),
],
[
'txn_date' => '2026-10-18',
'account_short' => '测试非直连华夏',
'detail' => '非直连支出',
'income' => 0,
'expense' => 10,
'approval_no' => 'TEST-NONDIRECT-EXPENSE',
'source' => 'manual',
'source_value' => null,
'row_key' => hash('sha256', 'test-nondirect-expense'),
],
[
'txn_date' => '2026-10-18',
'account_short' => '测试直连招行',
'detail' => '直连收入',
'income' => 50,
'expense' => 0,
'approval_no' => 'TEST-DIRECT-INCOME',
'source' => 'manual',
'source_value' => null,
'row_key' => hash('sha256', 'test-direct-income'),
],
[
'txn_date' => '2026-10-18',
'account_short' => '测试手动招行',
'detail' => '手动招行支出',
'income' => 0,
'expense' => 10,
'approval_no' => 'TEST-MANUAL-CMB-EXPENSE',
'source' => 'manual',
'source_value' => null,
'row_key' => hash('sha256', 'test-manual-cmb-expense'),
],
]);
$this->loginAs();
$response = $this->get(route('business.pages.show', [
'section' => 'financial-operations',
'page' => 'fund-ledger',
]) . '?tab=transactions&txns_from=2026-10-18&txns_to=2026-10-18')
->assertOk()
->assertSee('测试非直连华夏')
->assertSee('130.00')
->assertSee('120.00')
->assertSee('290.00');
$html = $response->getContent();
$this->assertMatchesRegularExpression(
'/TEST-DIRECT-INCOME.*?<td class="num"[^>]*>—<\/td>/s',
$html,
);
}
}