From 8d715c6265ca668c5e52ccd04ffc34ffb8da3a45 Mon Sep 17 00:00:00 2001 From: WuYongJie Date: Tue, 10 Nov 2026 17:00:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=91=E7=A5=A8=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=96=B0=E5=A2=9E=E7=AD=9B=E9=80=89=E4=B8=8E?= =?UTF-8?q?=E5=90=88=E8=AE=A1=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Business/Pages.php | 80 +++++++++++ resources/views/business/pages/show.blade.php | 80 +++++++++++ .../InvoiceBasicFiltersTotalsTest.php | 129 ++++++++++++++++++ 3 files changed, 289 insertions(+) create mode 100644 tests/Feature/Business/InvoiceBasicFiltersTotalsTest.php diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 9c01a07f..407eedee 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -28,6 +28,7 @@ use App\Models\Business\CourierQuoteSignature; use App\Models\Business\CourierQuoteVersion; use App\Models\Business\CourierSigningSubject; use App\Models\Business\InstallationDetail; +use App\Models\Business\InvoiceBasic; use App\Models\Business\InvoiceBasicDetail; use App\Models\Business\InventoryWarehouseNameMapping; use App\Models\Business\Todo; @@ -3938,6 +3939,12 @@ class Pages extends Controller ): array { $descriptor = null; $rows = collect(); + $isInvoiceBasicPage = ($section['slug'] ?? null) === 'invoice-management' + && ($page['slug'] ?? null) === 'basic-information'; + $invoiceBasicFilters = ['seller_entity' => '', 'store_name' => '', 'period' => '']; + $invoiceBasicPeriodOptions = collect(); + $invoiceBasicPageTotals = ['invoice_limit' => 0.0, 'output_amount' => 0.0, 'input_amount' => 0.0]; + $invoiceBasicAllTotals = ['invoice_limit' => 0.0, 'output_amount' => 0.0, 'input_amount' => 0.0]; $invoiceBasicDetails = collect(); $tabValue = null; $tabColumn = null; @@ -4086,6 +4093,66 @@ class Pages extends Controller } else { $query = ($descriptor->model)::query(); + if ($isInvoiceBasicPage) { + $invoiceBasicFilters = [ + 'seller_entity' => mb_substr(trim((string) request()->query('seller_entity', '')), 0, 100), + 'store_name' => mb_substr(trim((string) request()->query('store_name', '')), 0, 100), + 'period' => trim((string) request()->query('period', '')), + ]; + + if ($invoiceBasicFilters['period'] !== '' + && preg_match('/^\d{4}-\d{2}$/', $invoiceBasicFilters['period']) !== 1) { + $invoiceBasicFilters['period'] = ''; + } + + if ($invoiceBasicFilters['seller_entity'] !== '') { + $needle = '%' . addcslashes($invoiceBasicFilters['seller_entity'], '%_\\') . '%'; + $query->where('store_entity', 'like', $needle); + } + + if ($invoiceBasicFilters['store_name'] !== '') { + $needle = '%' . addcslashes($invoiceBasicFilters['store_name'], '%_\\') . '%'; + $pairs = collect(); + try { + $pairs = InvoiceBasicDetail::query() + ->where('shop_name', 'like', $needle) + ->select(['seller_entity', 'period']) + ->distinct() + ->limit(500) + ->get(); + } catch (Throwable $exception) { + report($exception); + } + + $query->where(function ($builder) use ($needle, $pairs): void { + $builder->where('store_name', 'like', $needle); + foreach ($pairs as $pair) { + $builder->orWhere(function ($sub) use ($pair): void { + $sub->where('store_entity', $pair->seller_entity) + ->where('period', $pair->period); + }); + } + }); + } + + if ($invoiceBasicFilters['period'] !== '') { + $query->where('period', $invoiceBasicFilters['period']); + } + + $invoiceBasicPeriodOptions = InvoiceBasic::query() + ->select('period') + ->where('period', '<>', '') + ->distinct() + ->orderByDesc('period') + ->pluck('period'); + + $invoiceBasicAllTotals = [ + 'invoice_limit' => round((float) (clone $query)->sum('invoice_limit'), 2), + 'output_amount' => round((float) (clone $query)->sum('output_amount'), 2), + 'input_amount' => round((float) (clone $query)->sum('input_amount'), 2), + ]; + } + if ($descriptor->tabFilterColumn && $activeTab) { $tabValue = TableRegistry::tabValue($section['slug'], $page['slug'], $activeTab['slug']); @@ -4102,6 +4169,15 @@ class Pages extends Controller $rows = $query->orderByDesc('id')->paginate(50)->withQueryString(); + if ($isInvoiceBasicPage) { + $invoiceBasicPageRows = $rows->getCollection(); + $invoiceBasicPageTotals = [ + 'invoice_limit' => round((float) $invoiceBasicPageRows->sum('invoice_limit'), 2), + 'output_amount' => round((float) $invoiceBasicPageRows->sum('output_amount'), 2), + 'input_amount' => round((float) $invoiceBasicPageRows->sum('input_amount'), 2), + ]; + } + if (($section['slug'] ?? null) === 'invoice-management' && ($page['slug'] ?? null) === 'basic-information') { try { @@ -4153,6 +4229,10 @@ class Pages extends Controller 'inventoryWarehouseMappingView' => $inventoryWarehouseMappingView, 'receiptStats' => $receiptStats, 'invoiceBasicDetails' => $invoiceBasicDetails, + 'invoiceBasicFilters' => $invoiceBasicFilters, + 'invoiceBasicPeriodOptions' => $invoiceBasicPeriodOptions, + 'invoiceBasicPageTotals' => $invoiceBasicPageTotals, + 'invoiceBasicAllTotals' => $invoiceBasicAllTotals, 'payablesFinal' => $this->payablesFinalData($section, $page), ]; } diff --git a/resources/views/business/pages/show.blade.php b/resources/views/business/pages/show.blade.php index be6cc779..5c65acba 100644 --- a/resources/views/business/pages/show.blade.php +++ b/resources/views/business/pages/show.blade.php @@ -1097,6 +1097,10 @@ font-weight: 600; } .invoice-detail-table .num { text-align: right; } + .invoice-total-row td { + background: var(--vip-content-accent-soft, #f7f0de); + font-weight: 600; + } @endif
@@ -1147,6 +1151,58 @@ @endunless
+ @if ($isInvoiceBasicPage) + + @endif + @if ($isStoreReceivingAccountsPage)
+ + @foreach ($descriptor->fields as $field) + + @if ($field['name'] === 'store_name') + {{ $totalLabel }} + @elseif (array_key_exists($field['name'], $totals)) + {{ number_format((float) $totals[$field['name']], 2) }} + @endif + + @endforeach + @unless ($descriptor->readOnly) + + @endunless + + @endforeach + + @endif diff --git a/tests/Feature/Business/InvoiceBasicFiltersTotalsTest.php b/tests/Feature/Business/InvoiceBasicFiltersTotalsTest.php new file mode 100644 index 00000000..21e75124 --- /dev/null +++ b/tests/Feature/Business/InvoiceBasicFiltersTotalsTest.php @@ -0,0 +1,129 @@ +user->attachPermission( + Permission::where('name', 'read-admin-panel')->firstOrFail() + ); + + InvoiceBasic::create([ + 'company_id' => $this->company->id, + 'store_name' => '多店铺(2)', + 'store_entity' => '甲公司', + 'invoice_issuer' => '甲开票员', + 'invoice_limit' => 50, + 'output_amount' => 300, + 'input_amount' => 100, + 'period' => '2026-10', + ]); + InvoiceBasic::create([ + 'company_id' => $this->company->id, + 'store_name' => '乙店铺', + 'store_entity' => '乙公司', + 'invoice_issuer' => '乙开票员', + 'invoice_limit' => 20, + 'output_amount' => 200, + 'input_amount' => 50, + 'period' => '2026-11', + ]); + + InvoiceBasicDetail::create([ + 'company_id' => $this->company->id, + 'period' => '2026-10', + 'seller_entity' => '甲公司', + 'shop_name' => '一号店', + 'invoice_count' => 1, + 'output_amount' => 100, + 'tax_amount' => 10, + 'net_amount' => 90, + ]); + InvoiceBasicDetail::create([ + 'company_id' => $this->company->id, + 'period' => '2026-10', + 'seller_entity' => '甲公司', + 'shop_name' => '二号店', + 'invoice_count' => 2, + 'output_amount' => 200, + 'tax_amount' => 20, + 'net_amount' => 180, + ]); + InvoiceBasicDetail::create([ + 'company_id' => $this->company->id, + 'period' => '2026-11', + 'seller_entity' => '乙公司', + 'shop_name' => '三号店', + 'invoice_count' => 1, + 'output_amount' => 200, + 'tax_amount' => 20, + 'net_amount' => 180, + ]); + } + + public function test_invoice_basic_shows_filters_and_page_and_all_totals(): void + { + $this->loginAs() + ->get($this->pageUrl()) + ->assertOk() + ->assertSeeText('店铺主体') + ->assertSeeText('店铺名称') + ->assertSeeText('期间') + ->assertSeeText('本页合计') + ->assertSeeText('全部合计') + ->assertSeeText('300.00') + ->assertSeeText('200.00') + ->assertSeeText('500.00') + ->assertSeeText('150.00') + ->assertSeeText('70.00') + ->assertSee('