diff --git a/app/Http/Controllers/Business/SupplierReconciliation.php b/app/Http/Controllers/Business/SupplierReconciliation.php index f1846cba4..f5f346706 100644 --- a/app/Http/Controllers/Business/SupplierReconciliation.php +++ b/app/Http/Controllers/Business/SupplierReconciliation.php @@ -28,6 +28,8 @@ use Throwable; */ class SupplierReconciliation extends Controller { + private const RAW_STATEMENT_PER_PAGE = 50; + public function __construct( private readonly SupplierStatementTemplate $template, private readonly SupplierStatementStore $statements, @@ -183,6 +185,49 @@ class SupplierReconciliation extends Controller ); } + public function rawStatementRows(Request $request): JsonResponse + { + $request->validate([ + 'page' => ['nullable', 'integer', 'min:1', 'max:100000'], + 'keyword' => ['nullable', 'string', 'max:100'], + 'barcode' => ['nullable', 'string', 'max:191'], + 'purchase_no' => ['nullable', 'string', 'max:191'], + ]); + [$supplier, $companyId] = $this->returnTarget($request); + $page = max((int) $request->query('page', 1), 1); + $keyword = trim((string) $request->query('keyword', '')); + $exactFilters = array_filter([ + 'barcode' => trim((string) $request->query('barcode', '')), + 'purchaseNo' => trim((string) $request->query('purchase_no', '')), + ], static fn (string $value): bool => $value !== ''); + $result = $this->statements->paginateFiltered( + $supplier, + $companyId, + self::RAW_STATEMENT_PER_PAGE, + $page, + $keyword, + $exactFilters, + ); + $total = (int) ($result['total'] ?? 0); + $pages = max((int) ceil($total / self::RAW_STATEMENT_PER_PAGE), 1); + $page = min($page, $pages); + $latestUpload = $this->statements->uploads($supplier, $companyId, 1)[0] ?? null; + + return response()->json([ + 'supplier' => $supplier, + 'rows' => array_values((array) ($result['rows'] ?? [])), + 'total' => $total, + 'page' => $page, + 'pages' => $pages, + 'per_page' => self::RAW_STATEMENT_PER_PAGE, + 'upload' => $latestUpload === null ? null : [ + 'uploaded_at' => (string) ($latestUpload['uploaded_at'] ?? ''), + 'filename' => (string) ($latestUpload['filename'] ?? ''), + 'rows' => (int) ($latestUpload['rows'] ?? 0), + ], + ])->header('Cache-Control', 'no-store'); + } + public function saveDingTalkRobot(Request $request): RedirectResponse { $request->validate([ diff --git a/modules/EcommerceFinance/Services/SupplierStatementStore.php b/modules/EcommerceFinance/Services/SupplierStatementStore.php index edcffb2db..9bc4f2f7f 100644 --- a/modules/EcommerceFinance/Services/SupplierStatementStore.php +++ b/modules/EcommerceFinance/Services/SupplierStatementStore.php @@ -12,6 +12,8 @@ class SupplierStatementStore public const LOG_PREFIX = 'statement-log:'; + private const FILTERABLE_COLUMNS = ['expressNo', 'purchaseNo', 'barcode']; + public function __construct( private readonly SupplierPayableOverrideStore $store, ) { @@ -58,6 +60,36 @@ class SupplierStatementStore ); } + /** + * 按关键词和原始账单字段分页,供财务端同页抽屉查看。 + * + * @param array $exactFilters + * @return array{rows:list>,total:int} + */ + public function paginateFiltered( + string $supplier, + int $companyId, + int $perPage, + int $page, + string $keyword = '', + array $exactFilters = [], + ): array { + $exactFilters = array_intersect_key( + $exactFilters, + array_flip(self::FILTERABLE_COLUMNS), + ); + + return $this->store->paginateRows( + self::PREFIX . $supplier, + $companyId, + $perPage, + $page, + $keyword, + false, + $exactFilters, + ); + } + /** @return list> 最近的上传记录(新到旧) */ public function uploads(string $supplier, int $companyId, int $limit = 10): array { diff --git a/resources/views/business/pages/supplier-reconciliation/_raw-statement-drawer.blade.php b/resources/views/business/pages/supplier-reconciliation/_raw-statement-drawer.blade.php new file mode 100644 index 000000000..803df3039 --- /dev/null +++ b/resources/views/business/pages/supplier-reconciliation/_raw-statement-drawer.blade.php @@ -0,0 +1,630 @@ + + + +
+
+
+ Supplier statement +

{{ $rawStatementSupplier }} · 厂家原始账单

+

同页查看厂家最新一版上传数据,关闭后保留当前月份、厂家和比对筛选。

+
+ +
+ +
+ 最近上传:{{ $rawStatementUpload['uploaded_at'] ?? '—' }} + 文件:{{ $rawStatementUpload['filename'] ?? '—' }} + 总行数:{{ number_format((int) ($rawStatementUpload['rows'] ?? 0)) }} + 当前账期:{{ $rawStatementMonth !== '' ? $rawStatementMonth : '全部' }} + @if ($rawStatementUpload) + 最新版本 + @endif +
+ +
+ + + + + + @if ($rawStatementUpload) + 导出 Excel + @endif + 完整页面 +
+ + + +
+ + + + + + + + + + + + + + + + + + + +
序号快递名称快递单号单据编号(采购单号)创建时间供应商条码规格名称数量单价金额
正在读取原始账单…
+
+ +
+ + 第 1 / 1 页 · 共 {{ number_format((int) ($rawStatementUpload['rows'] ?? 0)) }} 行 + + +
+
+
+ + 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 9e8730578..ff64c318b 100644 --- a/resources/views/business/pages/supplier-reconciliation/finance-data.blade.php +++ b/resources/views/business/pages/supplier-reconciliation/finance-data.blade.php @@ -57,6 +57,7 @@ .supplier-reconciliation-page .sr-guide-body { padding: 0 12px 12px; color: var(--vip-content-muted, #595959); font-size: .75rem; line-height: 1.7; } .supplier-reconciliation-page .sr-detail-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; } .supplier-reconciliation-page .sr-detail-actions form { margin: 0; } + .supplier-reconciliation-page .sr-row-actions { display: grid; gap: 5px; min-width: 72px; } .supplier-reconciliation-page .sr-detail-meta { color: var(--vip-content-muted, #595959); font-size: .75rem; line-height: 1.5; } .supplier-reconciliation-page .sr-scroll { min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: thin; } .supplier-reconciliation-page table { width: 100%; min-width: 720px; border-collapse: collapse; font-size: .8125rem; } @@ -250,6 +251,12 @@ @if ($detail) @php $differenceCount = (int) ($detail['difference_count'] ?? 0); + $rawStatementPageUrl = route('business.pages.show', [ + 'section' => $section['slug'], + 'page' => 'raw-statements', + 'supplier' => $selectedSupplier, + 'month' => $month, + ]); $formatDifferenceNumber = static function (mixed $value): string { $formatted = rtrim(rtrim(number_format((float) $value, 4, '.', ''), '0'), '.'); @@ -277,12 +284,11 @@ 'comparison_filter' => $comparisonFilter, ], static fn (mixed $value): bool => $value !== '' && $value !== null)) }}" class="sr-button">导出当前筛选 - 查看原始账单 + 查看原始账单
@@ -819,6 +825,14 @@ '未定价' => 'is-unpriced', default => 'is-match', }; + $rawStatementBarcode = trim((string) ($row['supplierBarcode'] ?? '')); + if ($rawStatementBarcode === '') { + $rawStatementBarcode = trim((string) ($row['barcode'] ?? '')); + } + $rawStatementPurchaseNo = trim((string) ($row['theirsPurchaseNo'] ?? '')); + if ($rawStatementPurchaseNo === '') { + $rawStatementPurchaseNo = trim((string) ($row['purchaseNo'] ?? '')); + } @endphp @@ -901,30 +915,40 @@ {{ $row['type'] === '未定价' ? '待定价' : number_format($row['settleAmount'], 2) }} - @if ($row['type'] !== '一致') - - @csrf - - - - - - - - - - -
- @else - — - @endif +
+ @if (($uploads[$selectedSupplier]['rows'] ?? 0) > 0) + 查看原始 + @endif + @if ($row['type'] !== '一致') +
+ @csrf + + + + + + + + + + +
+ @endif + @if (($uploads[$selectedSupplier]['rows'] ?? 0) <= 0 && $row['type'] === '一致') + — + @endif +
@empty @@ -1114,6 +1138,19 @@ @endif @endif + + @if ($detail) + @include('business.pages.supplier-reconciliation._raw-statement-drawer', [ + 'rawStatementSupplier' => $selectedSupplier, + 'rawStatementMonth' => $month, + 'rawStatementUpload' => $uploads[$selectedSupplier] ?? null, + 'rawStatementRowsUrl' => route('business.supplier-reconciliation.raw-statement.rows'), + 'rawStatementExportUrl' => route('business.supplier-reconciliation.raw-statement.export', [ + 'supplier' => $selectedSupplier, + ]), + 'rawStatementPageUrl' => $rawStatementPageUrl, + ]) + @endif @if ($detail) diff --git a/routes/admin.php b/routes/admin.php index 585cb5892..5c8cacdff 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -618,6 +618,10 @@ Route::get('workspace/supplier-reconciliation/raw-statement/export', [SupplierRe ->middleware('business.page:supplier-reconciliation,finance-data') ->name('business.supplier-reconciliation.raw-statement.export'); +Route::get('workspace/supplier-reconciliation/raw-statement/rows', [SupplierReconciliationActions::class, 'rawStatementRows']) + ->middleware(['business.page:supplier-reconciliation,finance-data', 'throttle:120,1']) + ->name('business.supplier-reconciliation.raw-statement.rows'); + // 退货扣减确认:逐行确认/异议 + 一键全部确认 Route::post('workspace/supplier-reconciliation/returns/confirm', [SupplierReconciliationActions::class, 'confirmReturn']) ->middleware('business.page:supplier-reconciliation,supplier-data') diff --git a/tests/Feature/Business/SupplierReconciliationTest.php b/tests/Feature/Business/SupplierReconciliationTest.php index 646526fcf..e2e39d1c3 100644 --- a/tests/Feature/Business/SupplierReconciliationTest.php +++ b/tests/Feature/Business/SupplierReconciliationTest.php @@ -316,6 +316,93 @@ class SupplierReconciliationTest extends FeatureTestCase } } + public function test_finance_raw_statement_drawer_returns_filtered_pages(): void + { + $companyId = (int) $this->company->id; + $statementRows = []; + for ($index = 1; $index <= 105; $index++) { + $statementRows[] = array_merge( + $this->statementRow( + sprintf('DRAWER-%03d', $index), + '12.50', + '2', + '25.00', + ), + [ + 'expressNo' => sprintf('SF-DRAWER-%03d', $index), + 'purchaseNo' => sprintf('DRAWER-PO-%03d', $index), + 'createdAt' => '2026-11-30', + 'supplier' => '抽屉厂家', + ], + ); + } + $this->seedStatement('抽屉厂家', $statementRows); + app(SupplierPayableOverrideStore::class)->save( + 'final:supplier:payment-reconciliation', + 'drawer:mine', + [ + 'summary_month' => '2026-11', + 'purchaseNo' => 'DRAWER-PO-001', + 'date' => '2026-11-30', + 'supplier' => '抽屉厂家', + 'skuCode' => 'DRAWER-001', + 'productCode' => 'DRAWER-001', + 'qty' => '2', + 'unitPrice' => '12.50', + 'amount' => '25.00', + ], + $companyId, + null, + ); + + $this->loginAs()->get(route('business.pages.show', [ + 'section' => 'supplier-reconciliation', + 'page' => 'finance-data', + 'supplier' => '抽屉厂家', + 'month' => '2026-11', + ])) + ->assertOk() + ->assertSeeText('查看原始账单') + ->assertSee('data-raw-statement-open', false) + ->assertSee('data-raw-statement-dialog', false) + ->assertSee('data-raw-statement-locate', false) + ->assertSee('raw-statement/rows', false); + + $rowsRoute = route('business.supplier-reconciliation.raw-statement.rows'); + $this->loginAs()->getJson($rowsRoute . '?' . http_build_query([ + 'supplier' => '抽屉厂家', + 'page' => 2, + ])) + ->assertOk() + ->assertJsonPath('supplier', '抽屉厂家') + ->assertJsonPath('total', 105) + ->assertJsonPath('page', 2) + ->assertJsonPath('pages', 3) + ->assertJsonPath('per_page', 50) + ->assertJsonPath('upload.filename', 'statement.csv') + ->assertJsonCount(50, 'rows') + ->assertJsonPath('rows.0.barcode', 'DRAWER-051') + ->assertJsonPath('rows.49.barcode', 'DRAWER-100'); + + $this->loginAs()->getJson($rowsRoute . '?' . http_build_query([ + 'supplier' => '抽屉厂家', + 'keyword' => 'DRAWER-077', + ])) + ->assertOk() + ->assertJsonPath('total', 1) + ->assertJsonPath('rows.0.barcode', 'DRAWER-077'); + + $this->loginAs()->getJson($rowsRoute . '?' . http_build_query([ + 'supplier' => '抽屉厂家', + 'barcode' => 'DRAWER-088', + 'purchase_no' => 'DRAWER-PO-088', + ])) + ->assertOk() + ->assertJsonPath('total', 1) + ->assertJsonPath('rows.0.barcode', 'DRAWER-088') + ->assertJsonPath('rows.0.purchaseNo', 'DRAWER-PO-088'); + } + public function test_supplier_portal_cannot_view_the_finance_raw_statement_page(): void { $supplierUser = $this->createSupplierPortalUser('晨丰'); @@ -334,6 +421,12 @@ class SupplierReconciliationTest extends FeatureTestCase 'supplier' => '晨丰', ])) ->assertForbidden(); + + $this->actingAsSupplierPortal($supplierUser) + ->getJson(route('business.supplier-reconciliation.raw-statement.rows', [ + 'supplier' => '晨丰', + ])) + ->assertForbidden(); } public function test_raw_statement_page_inherits_finance_data_page_permission(): void