From bad13f90c5fa273104f914d62161df5efb2e3720 Mon Sep 17 00:00:00 2001 From: shanshi <3316401569@qq.com> Date: Wed, 11 Nov 2026 14:30:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B4=A6=E6=88=B7=E6=80=BB=E8=A1=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=93=B6=E8=A1=8C=E8=B4=A6=E6=88=B7=E4=B8=8E?= =?UTF-8?q?=E9=9D=9E=E5=BA=97=E9=93=BA=E8=B4=A6=E6=88=B7=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=20(#1076)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/FinanceLedgerPageData.php | 51 +++++++++++------ .../pages/financial-ledger/ledger.blade.php | 32 ++++++++++- .../FinanceLedgerHeaderControlsTest.php | 56 +++++++++++++++++++ 3 files changed, 118 insertions(+), 21 deletions(-) diff --git a/modules/EcommerceFinance/View/FinanceLedgerPageData.php b/modules/EcommerceFinance/View/FinanceLedgerPageData.php index 5d81d798..bc78a76a 100644 --- a/modules/EcommerceFinance/View/FinanceLedgerPageData.php +++ b/modules/EcommerceFinance/View/FinanceLedgerPageData.php @@ -91,12 +91,16 @@ class FinanceLedgerPageData $flowView = in_array($requestedFlowView, ['summary', 'bank', 'non_store', 'daily'], true) ? $requestedFlowView : 'summary'; + $requestedAccountView = trim((string) request('accounts_view', 'all')); + $accountView = in_array($requestedAccountView, ['all', 'bank', 'non_store'], true) + ? $requestedAccountView + : 'all'; $flowPeriod = $this->dateRange('flows'); $transactionPeriod = $this->dateRange('txns'); $mappingPeriod = $this->dateRange('mapping'); $sourcePeriod = $this->dateRange('sources'); - $accounts = $this->accounts(); + $accounts = $this->accounts($accountView); $shops = $this->shops(); $availableBreakdown = $this->availableBreakdown($shops); $flows = $this->flows($flowPeriod, $flowView); @@ -113,6 +117,7 @@ class FinanceLedgerPageData 'ledgerTab' => $tab, 'ledgerTabs' => self::TABS, 'ledgerOpeningDate' => $openingDate, + 'ledgerAccountView' => $accountView, 'ledgerAccounts' => $accounts['rows'], 'ledgerAccountSummary' => $accounts['summary'], 'ledgerShops' => $shops['rows'], @@ -155,12 +160,13 @@ class FinanceLedgerPageData ]; } - private function accounts(): array + private function accounts(string $view = 'all'): array { $query = FinanceLedgerIndependentAccounts::exclude( $this->db()->table('fin_accounts as a'), 'a.account_short', ); + $this->applyAccountCategoryScope($query, $view, 'a.account_short', 'a.account_type'); $keyword = trim((string) request('accounts_q', '')); if ($keyword !== '') { $query->where(function (Builder $builder) use ($keyword): void { @@ -632,6 +638,30 @@ class FinanceLedgerPageData ]; } + private function applyAccountCategoryScope( + Builder $query, + string $view, + string $accountShortColumn, + string $accountTypeColumn, + ): void { + if ($view === 'bank') { + $query->where(function (Builder $scope) use ($accountShortColumn, $accountTypeColumn): void { + $scope->where(function (Builder $account) use ($accountShortColumn): void { + $account->whereNull($accountShortColumn) + ->orWhere($accountShortColumn, 'not like', '%支付宝%'); + })->where(function (Builder $accountType) use ($accountTypeColumn): void { + $accountType->whereNull($accountTypeColumn) + ->orWhere($accountTypeColumn, 'not like', '%支付宝%'); + }); + }); + } elseif ($view === 'non_store') { + $query->where(function (Builder $scope) use ($accountShortColumn, $accountTypeColumn): void { + $scope->where($accountShortColumn, 'like', '%支付宝%') + ->orWhere($accountTypeColumn, 'like', '%支付宝%'); + }); + } + } + private function accountFlowSummary(array $period, string $view = 'summary'): array { $customFields = $this->flowSummaryCustomFields(); @@ -639,22 +669,7 @@ class FinanceLedgerPageData $this->db()->table('fin_accounts as a'), 'a.account_short', ); - if ($view === 'bank') { - $accountQuery->where(function ($scope): void { - $scope->where(function ($account): void { - $account->whereNull('a.account_short') - ->orWhere('a.account_short', 'not like', '%支付宝%'); - })->where(function ($accountType): void { - $accountType->whereNull('a.account_type') - ->orWhere('a.account_type', 'not like', '%支付宝%'); - }); - }); - } elseif ($view === 'non_store') { - $accountQuery->where(function ($scope): void { - $scope->where('a.account_short', 'like', '%支付宝%') - ->orWhere('a.account_type', 'like', '%支付宝%'); - }); - } + $this->applyAccountCategoryScope($accountQuery, $view, 'a.account_short', 'a.account_type'); foreach (['flows_company' => 'a.company_name', 'flows_account' => 'a.account_short'] as $param => $column) { $value = trim((string) request($param, '')); if ($value !== '') { diff --git a/resources/views/business/pages/financial-ledger/ledger.blade.php b/resources/views/business/pages/financial-ledger/ledger.blade.php index 490451f8..5776d11b 100644 --- a/resources/views/business/pages/financial-ledger/ledger.blade.php +++ b/resources/views/business/pages/financial-ledger/ledger.blade.php @@ -62,6 +62,26 @@ $date = static fn ($value): string => $value ? \Illuminate\Support\Carbon::parse($value)->format('Y-m-d') : ''; $ledgerPageUrl = route('business.pages.show', ['section' => 'financial-operations', 'page' => 'ledger']); $tabUrl = static fn (string $tab): string => $ledgerPageUrl . '?' . http_build_query(['tab' => $tab]); + $accountView = $ledgerAccountView ?? 'all'; + $accountViewQuery = collect(request()->query()) + ->except([ + 'tab', + 'accounts_page', + 'accounts_filter_column', + 'accounts_filter_value', + 'accounts_sort', + 'accounts_direction', + ]) + ->filter(static fn ($value): bool => is_scalar($value) || $value === null) + ->all(); + $accountViewUrl = static fn (string $view): string => $ledgerPageUrl . '?' . http_build_query(array_merge( + $accountViewQuery, + ['tab' => 'accounts', 'accounts_view' => $view], + )); + $accountViewResetUrl = $ledgerPageUrl . '?' . http_build_query([ + 'tab' => 'accounts', + 'accounts_view' => $accountView, + ]); $transactionView = $ledgerTransactionView ?? 'all'; $transactionViews = $ledgerTransactionViews ?? []; $transactionViewAccount = $ledgerTransactionViewAccount ?? null; @@ -660,6 +680,7 @@