diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 2c7ff816b..1a693064c 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -6002,6 +6002,7 @@ class Pages extends Controller 'planting-reimbursement-workbench' => app(\Modules\EcommerceFinance\View\PlantingReimbursementWorkbenchPageData::class)->page(), 'planting-loss' => app(\Modules\EcommerceFinance\View\PlantingLossPageData::class)->page(), 'finance-data' => app(\Modules\EcommerceFinance\View\SupplierReconciliationPageData::class)->financeData(), + 'raw-statements' => app(\Modules\EcommerceFinance\View\SupplierReconciliationPageData::class)->rawStatementsData(), 'supplier-data' => app(\Modules\EcommerceFinance\View\SupplierReconciliationPageData::class)->supplierData(), 'supplier-negative-alert', 'courier-negative-alert' => $this->negativeAlertContent($page, $tab), 'store-report-data-logic' => $this->prepareStoreReportLogic(), diff --git a/app/Utilities/SidebarPermissions.php b/app/Utilities/SidebarPermissions.php index de5d9e850..b0e6db179 100644 --- a/app/Utilities/SidebarPermissions.php +++ b/app/Utilities/SidebarPermissions.php @@ -131,6 +131,10 @@ class SidebarPermissions $allowed[] = 'courier-payables/returned-parcels'; } + if (in_array('supplier-reconciliation/finance-data', $allowed, true)) { + $allowed[] = 'supplier-reconciliation/raw-statements'; + } + return array_values(array_unique($allowed)); } diff --git a/config/business_navigation.php b/config/business_navigation.php index f67cc7f74..dd855f87d 100644 --- a/config/business_navigation.php +++ b/config/business_navigation.php @@ -813,6 +813,7 @@ $navigation = [ 'icon' => 'fact_check', 'pages' => [ ['slug' => 'finance-data', 'title' => '财务端数据'], + ['slug' => 'raw-statements', 'title' => '原始账单'], ['slug' => 'supplier-data', 'title' => '厂家端数据'], ], ], diff --git a/modules/EcommerceFinance/View/SupplierReconciliationPageData.php b/modules/EcommerceFinance/View/SupplierReconciliationPageData.php index bda0fb4e9..c8c6d0b09 100644 --- a/modules/EcommerceFinance/View/SupplierReconciliationPageData.php +++ b/modules/EcommerceFinance/View/SupplierReconciliationPageData.php @@ -15,6 +15,7 @@ use Modules\EcommerceFinance\Services\SupplierSummaryConfirmation; /** * 「供应商对账」页面数据: * - 财务端数据:按供应商与商品编码汇总,区分一致、未定价、厂家多、厂家少和数量/金额差异 + * - 原始账单:只读查看厂家最新一版上传对账单原始行 * - 厂家端数据:厂家上传的对账单(实时)与只读的退货明细 */ class SupplierReconciliationPageData @@ -32,6 +33,9 @@ class SupplierReconciliationPageData /** 厂家上传的对账数据表:每页行数(短表 + 翻页)。 */ private const PER_PAGE = 15; + /** 财务端查看厂家原始账单:每页行数。 */ + private const RAW_STATEMENT_PER_PAGE = 50; + /** 退货明细行较高:每页 10 行,并在页面内固定表头滚动查看。 */ private const RETURN_PER_PAGE = 10; @@ -444,6 +448,79 @@ class SupplierReconciliationPageData ] + $this->vendorPeriodContext(); } + /** + * 财务端只读查看厂家最新一版上传对账单的原始行。 + * + * @return array + */ + public function rawStatementsData(): array + { + $companyId = $this->companyId(); + $mineDataset = PayablesFinalActions::DATASET_PREFIX . 'supplier:payment-reconciliation'; + $returnDataset = PayablesFinalActions::DATASET_PREFIX . 'supplier:return-reconciliation'; + $supplierNames = $this->financeSupplierNames($mineDataset, $returnDataset, $companyId); + $uploadedSuppliers = $this->statements->uploadedSuppliers($companyId); + sort($uploadedSuppliers, SORT_NATURAL | SORT_FLAG_CASE); + + $supplierQuery = trim((string) request()->query('supplier', '')); + $selected = in_array($supplierQuery, $supplierNames, true) ? $supplierQuery : ''; + if ($supplierQuery === '' && $uploadedSuppliers !== []) { + $selected = $uploadedSuppliers[0]; + } + $supplierNotFound = $supplierQuery !== '' && $selected === ''; + + $month = trim((string) request()->query('month', '')); + if (preg_match('/^\d{4}-(0[1-9]|1[0-2])$/', $month) !== 1) { + $month = $this->latestAccountingMonth(); + } + + $statementRows = []; + $statementTotal = 0; + $rowsPage = 1; + $statementPages = 1; + $uploads = []; + if ($selected !== '') { + $rowsPage = max((int) request()->query('rows_page', 1), 1); + $statementPage = $this->statements->paginate( + $selected, + $companyId, + self::RAW_STATEMENT_PER_PAGE, + $rowsPage, + ); + $statementTotal = (int) ($statementPage['total'] ?? 0); + $statementPages = max((int) ceil($statementTotal / self::RAW_STATEMENT_PER_PAGE), 1); + if ($rowsPage > $statementPages) { + $rowsPage = $statementPages; + $statementPage = $this->statements->paginate( + $selected, + $companyId, + self::RAW_STATEMENT_PER_PAGE, + $rowsPage, + ); + } + $statementRows = (array) ($statementPage['rows'] ?? []); + $uploads = $this->statements->uploads($selected, $companyId, 10); + } + + return [ + 'view' => 'business.pages.supplier-reconciliation.raw-statements', + 'sectionSlug' => 'supplier-reconciliation', + 'pageSlug' => 'raw-statements', + 'supplierNames' => $supplierNames, + 'supplierQuery' => $supplierQuery, + 'supplierNotFound' => $supplierNotFound, + 'selectedSupplier' => $selected, + 'statementRows' => $statementRows, + 'statementTotal' => $statementTotal, + 'rowsPage' => $rowsPage, + 'statementPages' => $statementPages, + 'perPage' => self::RAW_STATEMENT_PER_PAGE, + 'uploads' => $uploads, + 'latestUpload' => $uploads[0] ?? null, + 'month' => $month, + ]; + } + private function isSupplier(string $name): bool { try { diff --git a/resources/views/business/pages/show.blade.php b/resources/views/business/pages/show.blade.php index 0ae6fe3c2..702e25714 100644 --- a/resources/views/business/pages/show.blade.php +++ b/resources/views/business/pages/show.blade.php @@ -999,7 +999,7 @@ {{-- 钉钉单页入口(菜单隐藏时)才需要目录内页签;网页端有左侧菜单和已打开页面标签栏,不再重复。 --}} @include('business.pages.partials.section-page-tabs', ['section' => $section]) @elseif (($section['slug'] ?? '') === 'supplier-reconciliation') - {{-- 供应商对账:财务端数据 / 厂家端数据两个页签。 --}} + {{-- 供应商对账:财务端数据 / 原始账单 / 厂家端数据。 --}} @include('business.pages.partials.section-page-tabs', ['section' => $section]) @elseif (($section['slug'] ?? '') === 'negative-alerts') {{-- 负数预警:供应商负数预警 / 快递负数预警两个页签。 --}} diff --git a/resources/views/business/pages/supplier-reconciliation/finance-data.blade.php b/resources/views/business/pages/supplier-reconciliation/finance-data.blade.php index ead1ea38b..ba0f44435 100644 --- a/resources/views/business/pages/supplier-reconciliation/finance-data.blade.php +++ b/resources/views/business/pages/supplier-reconciliation/finance-data.blade.php @@ -274,6 +274,12 @@ 'comparison_filter' => $comparisonFilter, ], static fn (mixed $value): bool => $value !== '' && $value !== null)) }}" class="sr-button">导出当前筛选 + 查看原始账单
@@ -515,6 +521,12 @@ 'supplier' => $supplier, 'supplier_page' => $supplierPage > 1 ? $supplierPage : null, ], static fn (mixed $value): bool => $value !== '' && $value !== null)); + $rawStatementUrl = route('business.pages.show', [ + 'section' => $section['slug'], + 'page' => 'raw-statements', + 'supplier' => $supplier, + 'month' => $month, + ]); @endphp @@ -538,6 +550,7 @@
查看比对 + 原始账单 @if ($returnCount > 0) @if ($robotConfigured) + + +
+

厂家上传原始账单

+

+ 这里只读查看厂家当前最新一版上传对账单的原始行,不参与比对结果修改。 + 当前表格展示整份上传账单,不按月份拆行;上方上传记录可查看最近版本的上传时间和文件名。 +

+ + + + + + + + @if ($supplierNotFound) + + @endif +
+ + @if ($selectedSupplier !== '') +
+
+
+

{{ $selectedSupplier }} · 原始账单

+

当前显示最新一版上传数据,共 {{ number_format($statementTotal) }} 行。

+
+ +
+ + @if ($latestUpload) +
+
+ 最近上传时间 + {{ $latestUpload['uploaded_at'] ?? '—' }} +
+
+ 文件名 + {{ $latestUpload['filename'] ?? '—' }} +
+
+ 上传行数 + {{ number_format((int) ($latestUpload['rows'] ?? 0)) }} +
+
+ 当前比对账期 + {{ $month }} +
+
+ + @if (count($uploads) > 1) +
    + @foreach ($uploads as $upload) +
  • + {{ $upload['uploaded_at'] ?? '—' }} + {{ $upload['filename'] ?? '—' }} + {{ number_format((int) ($upload['rows'] ?? 0)) }} 行 +
  • + @endforeach +
+ @endif + @endif + + @if ($statementTotal > 0) +
+ + + + + + + + + + + + + + + + + + @foreach ($statementRows as $index => $row) + + + + + + + + + + + + + + @endforeach + +
序号快递名称快递单号单据编号(采购单号)创建时间供应商条码规格名称数量单价金额
{{ number_format(($rowsPage - 1) * $perPage + $index + 1) }}{{ $row['expressName'] ?? '—' }}{{ $row['expressNo'] ?? '—' }}{{ $row['purchaseNo'] ?? '—' }}{{ $row['createdAt'] ?? '—' }}{{ $row['supplier'] ?? '—' }}{{ $row['barcode'] ?? '—' }}{{ $row['skuName'] ?? '—' }}{{ $row['qty'] ?? '—' }}{{ $row['unitPrice'] ?? '—' }}{{ $row['amount'] ?? '—' }}
+
+ + @if ($statementPages > 1) + @php + $pageStart = max(1, min($rowsPage - 4, $statementPages - 8)); + $pageEnd = min($statementPages, $pageStart + 8); + $pageUrl = fn (int $number): string => route('business.pages.show', [ + 'section' => $sectionSlug, + 'page' => $pageSlug, + 'supplier' => $selectedSupplier, + 'month' => $month, + 'rows_page' => $number, + ]); + @endphp +
+ 第 {{ $rowsPage }} / {{ $statementPages }} 页,每页 {{ $perPage }} 行 + @if ($rowsPage > 1) + 上一页 + @endif + @for ($number = $pageStart; $number <= $pageEnd; $number++) + {{ $number }} + @endfor + @if ($rowsPage < $statementPages) + 下一页 + @endif +
+ @endif + @else +
+ 该厂家还没有上传对账单。厂家上传后,这里会显示最新一版原始账单和上传记录。 +
+ @endif +
+ @elseif (! $supplierNotFound) +
+
+ 还没有厂家上传过对账单。厂家上传后,可在上方选择厂家并查看原始账单。 +
+
+ @endif +
diff --git a/tests/Feature/Business/SupplierReconciliationTest.php b/tests/Feature/Business/SupplierReconciliationTest.php index 3dee98531..ca31e52d0 100644 --- a/tests/Feature/Business/SupplierReconciliationTest.php +++ b/tests/Feature/Business/SupplierReconciliationTest.php @@ -218,6 +218,114 @@ class SupplierReconciliationTest extends FeatureTestCase } } + public function test_finance_can_view_latest_uploaded_raw_statement_with_pagination(): void + { + $companyId = (int) $this->company->id; + $statementRows = []; + for ($index = 1; $index <= 52; $index++) { + $statementRows[] = array_merge( + $this->statementRow( + sprintf('RAW-%02d', $index), + '10.00', + '1', + '10.00', + ), + [ + 'purchaseNo' => sprintf('RAW-PO-%02d', $index), + 'createdAt' => '2026-11-30', + 'supplier' => '原始账单厂家', + ], + ); + } + $this->seedStatement('原始账单厂家', $statementRows); + app(SupplierPayableOverrideStore::class)->save( + 'final:supplier:payment-reconciliation', + 'raw:mine', + [ + 'summary_month' => '2026-11', + 'purchaseNo' => 'RAW-PO-01', + 'date' => '2026-11-30', + 'supplier' => '原始账单厂家', + 'skuCode' => 'RAW-01', + 'productCode' => 'RAW-01', + 'qty' => '1', + 'unitPrice' => '10', + 'amount' => '10', + ], + $companyId, + null, + ); + + $pageUrl = fn (int $page): string => route('business.pages.show', [ + 'section' => 'supplier-reconciliation', + 'page' => 'raw-statements', + 'supplier' => '原始账单厂家', + 'month' => '2026-11', + 'rows_page' => $page, + ]); + + $firstPage = $this->loginAs()->get($pageUrl(1))->assertOk(); + $firstPage->assertSeeText('厂家上传原始账单') + ->assertSeeText('原始账单厂家 · 原始账单') + ->assertSeeText('statement.csv') + ->assertSeeText('第 1 / 2 页,每页 50 行') + ->assertSeeText('RAW-01') + ->assertSeeText('RAW-50') + ->assertDontSeeText('RAW-51'); + + $this->loginAs()->get($pageUrl(2)) + ->assertOk() + ->assertSeeText('第 2 / 2 页,每页 50 行') + ->assertSeeText('RAW-51') + ->assertSeeText('RAW-52') + ->assertDontSeeText('RAW-01'); + + $this->loginAs()->get(route('business.pages.show', [ + 'section' => 'supplier-reconciliation', + 'page' => 'finance-data', + 'month' => '2026-11', + ])) + ->assertOk() + ->assertSeeText('原始账单') + ->assertSee('raw-statements', false); + } + + public function test_supplier_portal_cannot_view_the_finance_raw_statement_page(): void + { + $supplierUser = $this->createSupplierPortalUser('晨丰'); + + $this->withExceptionHandling(); + $this->actingAsSupplierPortal($supplierUser) + ->get(route('business.pages.show', [ + 'section' => 'supplier-reconciliation', + 'page' => 'raw-statements', + 'supplier' => '晨丰', + ])) + ->assertForbidden(); + } + + public function test_raw_statement_page_inherits_finance_data_page_permission(): void + { + $this->user->roles()->sync([Role::where('name', 'user')->firstOrFail()->id]); + $subject = 'user_' . $this->user->id; + setting()->set('system.sidebar_permissions', [ + 'configured' => [$subject], + 'subjects' => [$subject => ['supplier-reconciliation/finance-data']], + ]); + setting()->save(); + + $this->assertContains( + 'supplier-reconciliation/raw-statements', + \App\Utilities\SidebarPermissions::effectiveAllowedKeys($this->user), + ); + $section = collect(\App\Utilities\SidebarMenu::sections($this->user)) + ->firstWhere('slug', 'supplier-reconciliation'); + $this->assertContains( + 'raw-statements', + array_column($section['pages'] ?? [], 'slug'), + ); + } + public function test_comparison_prefers_express_before_barcode_quantity(): void { $companyId = (int) $this->company->id;