diff --git a/modules/EcommerceFinance/View/FinanceLedgerPageData.php b/modules/EcommerceFinance/View/FinanceLedgerPageData.php index 2d8099b9..00b4de27 100644 --- a/modules/EcommerceFinance/View/FinanceLedgerPageData.php +++ b/modules/EcommerceFinance/View/FinanceLedgerPageData.php @@ -106,6 +106,7 @@ class FinanceLedgerPageData '中信' => '中信银行', '杭州银行' => '杭州银行', '杭州' => '杭州银行', + '微信' => '微信', ]; public function __construct( @@ -207,11 +208,19 @@ class FinanceLedgerPageData */ private function accounts(string $view = 'all', array $accountDisplayLabels = []): array { - $query = FinanceLedgerIndependentAccounts::exclude( - $this->db()->table('fin_accounts as a'), + $query = $this->db()->table('fin_accounts as a'); + if ($view !== 'other') { + $query = FinanceLedgerIndependentAccounts::exclude($query, 'a.account_short'); + } + $this->applyAccountCategoryScope( + $query, + $view, 'a.account_short', + 'a.account_type', + true, + 'a.bank_name', + $view === 'other', ); - $this->applyAccountCategoryScope($query, $view, 'a.account_short', 'a.account_type', true, 'a.bank_name'); $keyword = trim((string) request('accounts_q', '')); if ($keyword !== '') { $query->where(function (Builder $builder) use ($keyword): void { @@ -352,10 +361,10 @@ class FinanceLedgerPageData $cards = []; foreach (self::ACCOUNT_TYPE_VIEWS as $view => $definition) { - $query = FinanceLedgerIndependentAccounts::exclude( - $this->db()->table('fin_accounts as a'), - 'a.account_short', - ); + $query = $this->db()->table('fin_accounts as a'); + if ($view !== 'other') { + $query = FinanceLedgerIndependentAccounts::exclude($query, 'a.account_short'); + } $this->applyAccountCategoryScope( $query, $view, @@ -363,6 +372,7 @@ class FinanceLedgerPageData 'a.account_type', true, 'a.bank_name', + $view === 'other', ); $summary = $query->selectRaw( 'COUNT(*) AS account_count,' @@ -766,6 +776,7 @@ class FinanceLedgerPageData string $accountTypeColumn, bool $separateWangshangBank = false, ?string $bankNameColumn = null, + bool $includeIndependentAccounts = false, ): void { if ($view === 'bank') { $query->where(function (Builder $scope) use ($accountShortColumn, $accountTypeColumn): void { @@ -831,32 +842,43 @@ class FinanceLedgerPageData } }); } elseif ($view === 'other') { - $query->where(function (Builder $scope) use ($accountShortColumn, $accountTypeColumn, $bankNameColumn): void { - $scope->where(function (Builder $account) use ($accountShortColumn): void { - $account->whereNull($accountShortColumn) - ->orWhere(function (Builder $name) use ($accountShortColumn): void { - $name->where($accountShortColumn, 'not like', '%支付宝%') - ->where($accountShortColumn, 'not like', '%网商%') - ->where($accountShortColumn, 'not like', '%钱包%'); - }); - })->where(function (Builder $accountType) use ($accountTypeColumn): void { - $accountType->whereNull($accountTypeColumn) - ->orWhere(function (Builder $type) use ($accountTypeColumn): void { - $type->where($accountTypeColumn, 'not like', '%支付宝%') - ->where($accountTypeColumn, 'not like', '%网商%') - ->where($accountTypeColumn, 'not like', '%钱包%'); - }); - }); - if ($bankNameColumn !== null) { - $scope->where(function (Builder $bankName) use ($bankNameColumn): void { - $bankName->whereNull($bankNameColumn) - ->orWhere($bankNameColumn, '') - ->orWhere($bankNameColumn, '/'); + $bankAffiliation = $this->bankAffiliationSqlExpression($this->rawQualifiedColumn($accountShortColumn)); + $query->where(function (Builder $scope) use ( + $accountShortColumn, + $accountTypeColumn, + $bankNameColumn, + $includeIndependentAccounts, + $bankAffiliation, + ): void { + $scope->where(function (Builder $regular) use ($accountShortColumn, $accountTypeColumn, $bankNameColumn, $bankAffiliation): void { + $regular->where(function (Builder $account) use ($accountShortColumn): void { + $account->whereNull($accountShortColumn) + ->orWhere(function (Builder $name) use ($accountShortColumn): void { + $name->where($accountShortColumn, 'not like', '%支付宝%') + ->where($accountShortColumn, 'not like', '%网商%') + ->where($accountShortColumn, 'not like', '%钱包%'); + }); + })->where(function (Builder $accountType) use ($accountTypeColumn): void { + $accountType->whereNull($accountTypeColumn) + ->orWhere(function (Builder $type) use ($accountTypeColumn): void { + $type->where($accountTypeColumn, 'not like', '%支付宝%') + ->where($accountTypeColumn, 'not like', '%网商%') + ->where($accountTypeColumn, 'not like', '%钱包%'); + }); }); + if ($bankNameColumn !== null) { + $regular->where(function (Builder $bankName) use ($bankNameColumn): void { + $bankName->whereNull($bankNameColumn) + ->orWhere($bankNameColumn, '') + ->orWhere($bankNameColumn, '/'); + }); + } + $regular->whereRaw($bankAffiliation . " = ''"); + }); + if ($includeIndependentAccounts) { + $scope->orWhereIn($accountShortColumn, FinanceLedgerIndependentAccounts::names()); } }); - $bankAffiliation = $this->bankAffiliationSqlExpression($this->rawQualifiedColumn($accountShortColumn)); - $query->whereRaw($bankAffiliation . " = ''"); } } diff --git a/resources/views/business/pages/financial-ledger/ledger.blade.php b/resources/views/business/pages/financial-ledger/ledger.blade.php index 1537e8f1..626d0a69 100644 --- a/resources/views/business/pages/financial-ledger/ledger.blade.php +++ b/resources/views/business/pages/financial-ledger/ledger.blade.php @@ -307,6 +307,15 @@ ['remark', '备注', 'text'], ]; } + if ($standaloneAccountView === 'other') { + $ledgerTableHeaders['accounts'] = [ + ['company_name', '公司名称', 'text'], + ['account_short', '账户简称', 'text'], + ['bank_affiliation', '所属银行', 'enum', ['options' => $optionMap($accountBankOptions)]], + ['account_status', '账户状态', 'enum', ['options' => $accountStatusOptions, 'headerClass' => 'ledger-status-column']], + ['account_no', '登录账号', 'text'], + ]; + } $accountTableColumnCount = count($ledgerTableHeaders['accounts']); @endphp @@ -1358,6 +1367,28 @@ {{ $row->alipay_store_name }} {{ $row->remark }} + @elseif ($standaloneAccountView === 'other') + {{ $row->company_name }} + + {{ $accountDisplayShort }} + @if ($canEditAccounts) + + @endif + + {{ $row->bank_affiliation ?: '未填写' }} + + @if ($canEditAccountStatus) + {{ $accountStatusOptions[$row->account_status] ?? '正常' }} + + @else + {{ $accountStatusOptions[$row->account_status] ?? '正常' }} + @endif + + {{ $row->account_no }} @else {{ $row->company_name }} diff --git a/tests/Feature/Business/FinanceLedgerHeaderControlsTest.php b/tests/Feature/Business/FinanceLedgerHeaderControlsTest.php index 91b5af48..b9a90d84 100644 --- a/tests/Feature/Business/FinanceLedgerHeaderControlsTest.php +++ b/tests/Feature/Business/FinanceLedgerHeaderControlsTest.php @@ -650,6 +650,71 @@ class FinanceLedgerHeaderControlsTest extends FeatureTestCase $this->assertStringNotContainsString('data-flow-summary-account="账户甲"', $walletFlowHtml); } + public function test_other_account_basic_page_only_uses_five_login_fields(): void + { + DB::connection('business_mirror')->table('fin_accounts')->insert([ + [ + 'company_name' => '其他账户公司', + 'account_short' => '其他账户登录测试', + 'bank_name' => '/', + 'account_type' => '其他', + 'account_no' => 'other-login@example.com', + 'current_balance' => 0, + 'daily_available' => 0, + 'blocked_amount' => 0, + ], + [ + 'company_name' => '朱俊祥', + 'account_short' => '朱俊祥支付宝', + 'bank_name' => '支付宝', + 'account_type' => '其他', + 'account_no' => 'zhujunxiang-alipay', + 'current_balance' => 0, + 'daily_available' => 0, + 'blocked_amount' => 0, + ], + [ + 'company_name' => '朱俊祥', + 'account_short' => '朱俊祥微信', + 'bank_name' => '微信', + 'account_type' => '其他', + 'account_no' => 'zhujunxiang-wechat', + 'current_balance' => 0, + 'daily_available' => 0, + 'blocked_amount' => 0, + ], + ]); + + $html = $this->loginAs()->get(route('business.financial-ledger.account-basic', [ + 'company_id' => $this->company->id, + 'view' => 'other', + ]))->assertOk()->getContent(); + + preg_match( + '/.*?\s*(.*?)<\/tr>\s*<\/thead>/s', + $html, + $headerMatch, + ); + $headerHtml = $headerMatch[1] ?? ''; + + $this->assertSame(5, substr_count($headerHtml, '([^<]+)<\/span>/', $headerHtml, $labelMatches); + $this->assertSame( + ['company_name', 'account_short', 'bank_affiliation', 'account_status', 'account_no'], + $fieldMatches[1] ?? [], + ); + $this->assertSame( + ['公司名称', '账户简称', '所属银行', '账户状态', '登录账号'], + array_map('trim', $labelMatches[1] ?? []), + ); + $this->assertTrue(str_contains($html, 'other-login@example.com')); + $this->assertTrue(str_contains($html, 'data-ledger-account-row="朱俊祥支付宝"')); + $this->assertTrue(str_contains($html, 'data-ledger-account-row="朱俊祥微信"')); + $this->assertTrue(str_contains($html, 'zhujunxiang-alipay')); + $this->assertTrue(str_contains($html, 'zhujunxiang-wechat')); + } + public function test_account_directory_bank_affiliation_filter_uses_account_short_suffix(): void { DB::connection('business_mirror')->table('fin_accounts')->insert([