diff --git a/modules/EcommerceFinance/View/FinanceLedgerPageData.php b/modules/EcommerceFinance/View/FinanceLedgerPageData.php index cb820cdd..472e1188 100644 --- a/modules/EcommerceFinance/View/FinanceLedgerPageData.php +++ b/modules/EcommerceFinance/View/FinanceLedgerPageData.php @@ -34,6 +34,12 @@ class FinanceLedgerPageData 'sources' => ['title' => '数据来源', 'icon' => 'database'], ]; + public const TRANSACTION_VIEWS = [ + 'all' => ['title' => '全部明细', 'account_short' => null], + 'zhu-junxiang-alipay' => ['title' => '朱俊祥支付宝', 'account_short' => '朱俊祥支付宝'], + 'zhu-junxiang-wechat' => ['title' => '朱俊祥微信', 'account_short' => '朱俊祥微信'], + ]; + private const ACCOUNT_FILTER_EMPTY = '__empty__'; public function __construct( @@ -47,12 +53,17 @@ class FinanceLedgerPageData $tab = (string) (request('tab') ?: $tab); $tab = array_key_exists($tab, self::TABS) ? $tab : 'accounts'; $openingDate = (string) config('finance_ledger.opening_date', '2026-10-17'); + $transactionView = $this->transactionView(); $accounts = $this->accounts(); $shops = $this->shops(); $availableBreakdown = $this->availableBreakdown($shops); $flows = $this->flows(); - $transactions = $this->transactions(); + $transactions = $this->transactions($transactionView['account_short']); + $transactionViewAccountExists = $transactionView['account_short'] === null + || $this->db()->table('fin_accounts') + ->where('account_short', $transactionView['account_short']) + ->exists(); return [ 'view' => 'business.pages.financial-ledger.ledger', @@ -70,6 +81,10 @@ class FinanceLedgerPageData 'ledgerFlowSummary' => $flows['summary'], 'ledgerTransactions' => $transactions['rows'], 'ledgerTransactionSummary' => $transactions['summary'], + 'ledgerTransactionView' => $transactionView['key'], + 'ledgerTransactionViews' => self::TRANSACTION_VIEWS, + 'ledgerTransactionViewAccount' => $transactionView['account_short'], + 'ledgerTransactionViewAccountExists' => $transactionViewAccountExists, 'ledgerMapping' => $this->mapping(), 'ledgerSourceSummary' => $this->sourceSummary(), 'ledgerMeta' => $this->meta(), @@ -551,10 +566,10 @@ class FinanceLedgerPageData ]; } - private function transactions(): array + private function transactions(?string $accountShort = null): array { $query = $this->transactionQuery(); - $this->applyTransactionFilters($query); + $this->applyTransactionFilters($query, $accountShort); $headerColumns = $this->transactionHeaderColumns(); $summary = $this->transactionSummaryMetrics($query); @@ -573,12 +588,12 @@ class FinanceLedgerPageData public function transactionSummary(): array { $query = $this->transactionQuery(); - $this->applyTransactionFilters($query); + $this->applyTransactionFilters($query, $this->transactionView()['account_short']); return $this->transactionSummaryMetrics($query); } - private function applyTransactionFilters(Builder $query): void + private function applyTransactionFilters(Builder $query, ?string $forcedAccountShort = null): void { $keyword = trim((string) request('txns_q', '')); if ($keyword !== '') { @@ -589,10 +604,14 @@ class FinanceLedgerPageData ->orWhere('m.account_short', 'like', '%' . $keyword . '%'); }); } - $account = trim((string) request('txns_account', '')); - if ($account !== '') { - $effectiveAccount = $this->transactionHeaderColumns()['effective_account_short']['sort']; - $query->whereRaw($effectiveAccount . ' LIKE ?', ['%' . $account . '%']); + $effectiveAccount = $this->transactionHeaderColumns()['effective_account_short']['sort']; + if ($forcedAccountShort !== null) { + $query->whereRaw($effectiveAccount . ' = ?', [$forcedAccountShort]); + } else { + $account = trim((string) request('txns_account', '')); + if ($account !== '') { + $query->whereRaw($effectiveAccount . ' LIKE ?', ['%' . $account . '%']); + } } $from = trim((string) request('txns_from', '')); if ($from !== '') { @@ -607,7 +626,24 @@ class FinanceLedgerPageData $query->where('t.source', $source); } - $this->applyLedgerHeaderFilter($query, 'transactions', $this->transactionHeaderColumns()); + $headerColumns = $this->transactionHeaderColumns(); + if ($forcedAccountShort !== null) { + unset($headerColumns['effective_account_short']); + } + $this->applyLedgerHeaderFilter($query, 'transactions', $headerColumns); + } + + private function transactionView(): array + { + $key = trim((string) request('txns_view', 'all')); + if (! array_key_exists($key, self::TRANSACTION_VIEWS)) { + $key = 'all'; + } + + return [ + 'key' => $key, + ...self::TRANSACTION_VIEWS[$key], + ]; } private function transactionSummaryMetrics(Builder $query): array diff --git a/resources/views/business/pages/financial-ledger/ledger.blade.php b/resources/views/business/pages/financial-ledger/ledger.blade.php index 0f047b19..b628f644 100644 --- a/resources/views/business/pages/financial-ledger/ledger.blade.php +++ b/resources/views/business/pages/financial-ledger/ledger.blade.php @@ -62,6 +62,14 @@ $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]); + $transactionView = $ledgerTransactionView ?? 'all'; + $transactionViews = $ledgerTransactionViews ?? []; + $transactionViewAccount = $ledgerTransactionViewAccount ?? null; + $transactionViewAccountExists = (bool) ($ledgerTransactionViewAccountExists ?? true); + $transactionViewResetUrl = $ledgerPageUrl . '?' . http_build_query([ + 'tab' => 'transactions', + 'txns_view' => $transactionView, + ]); $sourceLabels = ['dingtalk' => '钉钉审批', 'alipay-company' => '公司支付宝', 'shop' => '店铺提现', 'shop_bill' => '店铺账单提现', 'payable' => '供应商应付', 'store' => '店铺开店', 'workorder' => '聚工单', 'manual' => '手工录入']; $shopBalanceDate = $ledgerShopBalanceDate ?? null; $shopBalanceDates = $ledgerShopBalanceDates ?? []; @@ -181,6 +189,16 @@ .ledger-tab.is-active { color:#fff; background:var(--vip-content-accent-dark, #856632); } .ledger-tab:focus-visible { outline:2px solid var(--vip-content-accent-dark, #856632); outline-offset:2px; } .ledger-tab .material-icons-outlined { font-size:1.05rem; } + .ledger-subtabbar { display:flex; gap:.2rem; margin:-.3rem 0 .75rem; padding:0 .1rem; border-bottom:1px solid var(--vip-border, #D8D2C7); overflow-x:auto; } + .ledger-subtab { position:relative; display:inline-flex; flex:0 0 auto; align-items:center; justify-content:center; min-height:2.25rem; padding:0 .8rem; border:0; background:transparent; color:var(--vip-content-muted, #595959); font:inherit; font-weight:600; white-space:nowrap; cursor:pointer; transition:color 150ms ease, background-color 150ms ease; } + .ledger-subtab::after { position:absolute; right:.35rem; bottom:-1px; left:.35rem; height:3px; background:transparent; content:''; } + .ledger-subtab:hover { color:var(--vip-content-accent-dark, #856632); background:var(--vip-content-accent-soft, #F7F0DE); } + .ledger-subtab.is-active { color:var(--vip-content-accent-dark, #856632); } + .ledger-subtab.is-active::after { background:var(--vip-content-accent, #B9954F); } + .ledger-subtab:focus-visible { outline:2px solid var(--vip-content-accent-dark, #856632); outline-offset:-2px; } + .ledger-transaction-view-note { margin:0 0 .75rem; padding:.55rem .65rem; border:1px solid var(--vip-border, #D8D2C7); border-radius:.45rem; background:#fff; color:var(--vip-content-muted, #595959); font-size:.7rem; line-height:1.6; } + .ledger-transaction-view-note.is-warning { border-color:#E2C88E; background:#fff8eb; color:var(--vip-warning, #935F07); } + @media (prefers-reduced-motion: reduce) { .ledger-subtab { transition:none; } } .ledger-panel[hidden] { display:none !important; } .ledger-toolbar { display:flex; flex-wrap:wrap; align-items:flex-end; gap:.65rem; padding:.85rem 1rem; margin-bottom:.85rem; border:1px solid var(--vip-border, #D8D2C7); border-radius:.65rem; background:#fff; } .ledger-field { display:flex; flex-direction:column; gap:.3rem; min-width:10rem; } @@ -998,15 +1016,30 @@ {{-- 动账明细 --}} -