feat(供应商对账): 同页查看厂家原始账单 #1759

Open
renshen wants to merge 1 commits from feature/sumu-raw-statement-drawer into main
6 changed files with 871 additions and 30 deletions

View File

@ -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([

View File

@ -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<string,string|null> $exactFilters
* @return array{rows:list<array<string,mixed>>,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<array<string,mixed>> 最近的上传记录(新到旧) */
public function uploads(string $supplier, int $companyId, int $limit = 10): array
{

View File

@ -0,0 +1,630 @@
<style>
.supplier-reconciliation-page .sr-raw-drawer {
width: min(1120px, calc(100vw - 28px));
max-width: none;
height: calc(100vh - 28px);
max-height: none;
margin: 14px 14px 14px auto;
padding: 0;
overflow: hidden;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 12px;
background: var(--vip-surface, #FFFFFF);
color: var(--vip-content-ink, #171717);
box-shadow: 0 12px 36px rgba(5, 5, 6, .24);
}
.supplier-reconciliation-page .sr-raw-drawer::backdrop {
background: rgba(5, 5, 6, .42);
backdrop-filter: blur(2px);
}
.supplier-reconciliation-page .sr-raw-shell {
display: grid;
grid-template-rows: auto auto auto minmax(0, 1fr) auto;
height: 100%;
min-height: 0;
}
.supplier-reconciliation-page .sr-raw-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
padding: 16px 18px 13px;
border-bottom: 1px solid var(--vip-border, #D8D2C7);
}
.supplier-reconciliation-page .sr-raw-kicker {
display: block;
color: var(--vip-content-accent-dark, #856632);
font-size: .6875rem;
font-weight: 600;
letter-spacing: .06em;
text-transform: uppercase;
}
.supplier-reconciliation-page .sr-raw-title {
margin: 3px 0 0;
font-size: .9375rem;
font-weight: 600;
}
.supplier-reconciliation-page .sr-raw-subtitle {
margin: 5px 0 0;
color: var(--vip-content-muted, #595959);
font-size: .75rem;
line-height: 1.55;
}
.supplier-reconciliation-page .sr-raw-close {
display: grid;
width: 34px;
height: 34px;
flex: 0 0 auto;
place-items: center;
padding: 0;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 8px;
background: #fff;
color: var(--vip-content-muted, #595959);
cursor: pointer;
}
.supplier-reconciliation-page .sr-raw-close .material-icons-outlined {
font-size: 18px;
}
.supplier-reconciliation-page .sr-raw-meta {
display: flex;
flex-wrap: wrap;
gap: 7px 18px;
padding: 9px 18px;
border-bottom: 1px solid #ECE6DA;
background: #FCFAF5;
color: var(--vip-content-muted, #595959);
font-size: .75rem;
}
.supplier-reconciliation-page .sr-raw-meta strong {
color: var(--vip-content-ink, #171717);
font-weight: 500;
}
.supplier-reconciliation-page .sr-raw-version {
display: inline-flex;
min-height: 22px;
align-items: center;
padding: 0 8px;
border: 1px solid #DCC99B;
border-radius: 999px;
background: var(--vip-content-accent-soft, #F7F0DE);
color: var(--vip-content-accent-dark, #856632);
font-size: .6875rem;
font-weight: 600;
}
.supplier-reconciliation-page .sr-raw-tools {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
padding: 10px 18px;
border-bottom: 1px solid var(--vip-border, #D8D2C7);
}
.supplier-reconciliation-page .sr-raw-search {
display: flex;
flex: 1 1 280px;
align-items: center;
gap: 6px;
min-width: 0;
height: 34px;
padding: 0 10px;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: 8px;
background: #fff;
}
.supplier-reconciliation-page .sr-raw-search .material-icons-outlined {
color: var(--vip-content-muted, #595959);
font-size: 17px;
}
.supplier-reconciliation-page .sr-raw-search input {
flex: 1 1 auto;
min-width: 0;
border: 0;
outline: 0;
background: transparent;
color: var(--vip-content-ink, #171717);
font: inherit;
font-size: .8125rem;
}
.supplier-reconciliation-page .sr-raw-search:focus-within {
border-color: var(--vip-content-accent-dark, #856632);
box-shadow: 0 0 0 3px rgba(133, 102, 50, .20);
}
.supplier-reconciliation-page .sr-raw-context {
display: none;
align-items: center;
gap: 6px;
min-height: 30px;
padding: 0 8px;
border: 1px solid #DCC99B;
border-radius: 7px;
background: var(--vip-content-accent-soft, #F7F0DE);
color: var(--vip-content-accent-dark, #856632);
font-size: .75rem;
font-weight: 500;
}
.supplier-reconciliation-page .sr-raw-context.is-visible {
display: inline-flex;
}
.supplier-reconciliation-page .sr-raw-context button {
display: grid;
width: 22px;
height: 22px;
place-items: center;
padding: 0;
border: 0;
border-radius: 50%;
background: transparent;
color: inherit;
cursor: pointer;
}
.supplier-reconciliation-page .sr-raw-context .material-icons-outlined {
font-size: 15px;
}
.supplier-reconciliation-page .sr-raw-error {
margin: 10px 18px 0;
padding: 9px 11px;
border: 1px solid #E2B7B2;
border-radius: 8px;
background: #FFF2F0;
color: #8C2F26;
font-size: .75rem;
line-height: 1.55;
}
.supplier-reconciliation-page .sr-raw-error button {
margin-left: 8px;
}
.supplier-reconciliation-page .sr-raw-table-wrap {
min-height: 0;
overflow: auto;
scrollbar-gutter: stable;
}
.supplier-reconciliation-page .sr-raw-table {
width: 100%;
min-width: 1320px;
border-collapse: collapse;
font-size: .75rem;
}
.supplier-reconciliation-page .sr-raw-table th {
position: sticky;
top: 0;
z-index: 2;
padding: 8px 9px;
border-bottom: 1px solid var(--vip-border, #D8D2C7);
background: var(--vip-content-accent-soft, #F7F0DE);
color: #5B5343;
font-size: .75rem;
font-weight: 600;
text-align: left;
white-space: nowrap;
}
.supplier-reconciliation-page .sr-raw-table td {
max-width: 280px;
padding: 7px 9px;
border-bottom: 1px solid #EFEAE0;
color: var(--vip-content-ink, #171717);
line-height: 1.45;
overflow-wrap: anywhere;
vertical-align: top;
}
.supplier-reconciliation-page .sr-raw-table td.is-number {
text-align: right;
white-space: nowrap;
font-variant-numeric: tabular-nums;
}
.supplier-reconciliation-page .sr-raw-table td.is-code {
font-family: "JetBrains Mono", "Cascadia Mono", monospace;
white-space: nowrap;
}
.supplier-reconciliation-page .sr-raw-table td.is-muted {
color: var(--vip-content-muted, #595959);
}
.supplier-reconciliation-page .sr-raw-table-loading,
.supplier-reconciliation-page .sr-raw-table-empty {
padding: 34px 16px !important;
color: var(--vip-content-muted, #595959) !important;
text-align: center;
}
.supplier-reconciliation-page .sr-raw-footer {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 10px 18px;
border-top: 1px solid var(--vip-border, #D8D2C7);
background: #fff;
}
.supplier-reconciliation-page .sr-raw-footer-status {
color: var(--vip-content-muted, #595959);
font-size: .75rem;
}
.supplier-reconciliation-page .sr-raw-footer-actions {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.supplier-reconciliation-page .sr-raw-footer .sr-button[disabled] {
opacity: .5;
cursor: not-allowed;
}
@media (max-width: 760px) {
.supplier-reconciliation-page .sr-raw-drawer {
width: 100vw;
height: 100dvh;
margin: 0;
border: 0;
border-radius: 0;
}
.supplier-reconciliation-page .sr-raw-head,
.supplier-reconciliation-page .sr-raw-meta,
.supplier-reconciliation-page .sr-raw-tools,
.supplier-reconciliation-page .sr-raw-footer {
padding-inline: 12px;
}
.supplier-reconciliation-page .sr-raw-error {
margin-inline: 12px;
}
.supplier-reconciliation-page .sr-raw-tools .sr-button {
width: 100%;
}
}
</style>
<dialog id="sr-raw-statement-dialog"
class="sr-raw-drawer"
aria-labelledby="sr-raw-statement-title"
data-raw-statement-dialog
data-supplier="{{ $rawStatementSupplier }}"
data-rows-url="{{ $rawStatementRowsUrl }}"
data-page-url="{{ $rawStatementPageUrl }}">
<div class="sr-raw-shell">
<header class="sr-raw-head">
<div>
<span class="sr-raw-kicker">Supplier statement</span>
<h2 class="sr-raw-title" id="sr-raw-statement-title">{{ $rawStatementSupplier }} · 厂家原始账单</h2>
<p class="sr-raw-subtitle">同页查看厂家最新一版上传数据,关闭后保留当前月份、厂家和比对筛选。</p>
</div>
<button type="button" class="sr-raw-close" aria-label="关闭原始账单" data-raw-statement-close>
<span class="material-icons-outlined" aria-hidden="true">close</span>
</button>
</header>
<div class="sr-raw-meta">
<span>最近上传:<strong data-raw-upload-time>{{ $rawStatementUpload['uploaded_at'] ?? '—' }}</strong></span>
<span>文件:<strong title="{{ $rawStatementUpload['filename'] ?? '' }}" data-raw-upload-file>{{ $rawStatementUpload['filename'] ?? '—' }}</strong></span>
<span>总行数:<strong data-raw-upload-rows>{{ number_format((int) ($rawStatementUpload['rows'] ?? 0)) }}</strong></span>
<span>当前账期:<strong>{{ $rawStatementMonth !== '' ? $rawStatementMonth : '全部' }}</strong></span>
@if ($rawStatementUpload)
<span class="sr-raw-version">最新版本</span>
@endif
</div>
<div class="sr-raw-tools">
<label class="sr-raw-search">
<span class="material-icons-outlined" aria-hidden="true">search</span>
<span class="sr-only">搜索原始账单</span>
<input type="search"
placeholder="搜索快递单号、采购单号、条码或规格"
autocomplete="off"
data-raw-statement-search>
</label>
<span class="sr-raw-context" data-raw-statement-context>
<span data-raw-statement-context-label></span>
<button type="button" aria-label="清除原始账单定位" data-raw-statement-clear-context>
<span class="material-icons-outlined" aria-hidden="true">close</span>
</button>
</span>
@if ($rawStatementUpload)
<a href="{{ $rawStatementExportUrl }}" class="sr-button">导出 Excel</a>
@endif
<a href="{{ $rawStatementPageUrl }}" class="sr-button">完整页面</a>
</div>
<div class="sr-raw-error" role="alert" data-raw-statement-error hidden>
<span data-raw-statement-error-message>原始账单读取失败。</span>
<button type="button" class="sr-button is-small" data-raw-statement-retry>重新加载</button>
</div>
<div class="sr-raw-table-wrap" data-raw-statement-table-wrap>
<table class="sr-raw-table" aria-label="{{ $rawStatementSupplier }} 最新上传原始账单">
<thead>
<tr>
<th scope="col">序号</th>
<th scope="col">快递名称</th>
<th scope="col">快递单号</th>
<th scope="col">单据编号(采购单号)</th>
<th scope="col">创建时间</th>
<th scope="col">供应商</th>
<th scope="col">条码</th>
<th scope="col">规格名称</th>
<th scope="col">数量</th>
<th scope="col">单价</th>
<th scope="col">金额</th>
</tr>
</thead>
<tbody data-raw-statement-rows>
<tr><td colspan="11" class="sr-raw-table-loading">正在读取原始账单…</td></tr>
</tbody>
</table>
</div>
<footer class="sr-raw-footer">
<span class="sr-raw-footer-status" aria-live="polite" data-raw-statement-page-label>
第 1 / 1 页 · 共 {{ number_format((int) ($rawStatementUpload['rows'] ?? 0)) }} 行
</span>
<div class="sr-raw-footer-actions">
<button type="button" class="sr-button is-small" data-raw-statement-prev disabled>上一页</button>
<button type="button" class="sr-button is-small" data-raw-statement-next disabled>下一页</button>
</div>
</footer>
</div>
</dialog>
<script>
(() => {
const dialog = document.querySelector('[data-raw-statement-dialog]');
if (!dialog) {
return;
}
const pageRoot = dialog.closest('.supplier-reconciliation-page');
if (!pageRoot) {
return;
}
const rowsBody = dialog.querySelector('[data-raw-statement-rows]');
const tableWrap = dialog.querySelector('[data-raw-statement-table-wrap]');
const searchInput = dialog.querySelector('[data-raw-statement-search]');
const context = dialog.querySelector('[data-raw-statement-context]');
const contextLabel = dialog.querySelector('[data-raw-statement-context-label]');
const pageLabel = dialog.querySelector('[data-raw-statement-page-label]');
const previousButton = dialog.querySelector('[data-raw-statement-prev]');
const nextButton = dialog.querySelector('[data-raw-statement-next]');
const errorBox = dialog.querySelector('[data-raw-statement-error]');
const errorMessage = dialog.querySelector('[data-raw-statement-error-message]');
const retryButton = dialog.querySelector('[data-raw-statement-retry]');
const supplier = dialog.dataset.supplier || '';
const rowsUrl = dialog.dataset.rowsUrl || '';
let opener = null;
let controller = null;
let searchTimer = null;
let page = 1;
let pages = 1;
let barcode = '';
let purchaseNo = '';
const createCell = (value, className = '') => {
const cell = document.createElement('td');
cell.textContent = value === null || value === undefined || value === '' ? '—' : String(value);
if (className !== '') {
cell.className = className;
}
return cell;
};
const setLoading = () => {
rowsBody.replaceChildren();
const row = document.createElement('tr');
const cell = document.createElement('td');
cell.colSpan = 11;
cell.className = 'sr-raw-table-loading';
cell.textContent = '正在读取原始账单…';
row.appendChild(cell);
rowsBody.appendChild(row);
tableWrap.setAttribute('aria-busy', 'true');
errorBox.hidden = true;
};
const setError = (message) => {
rowsBody.replaceChildren();
const row = document.createElement('tr');
const cell = document.createElement('td');
cell.colSpan = 11;
cell.className = 'sr-raw-table-empty';
cell.textContent = '原始账单暂时无法读取。';
row.appendChild(cell);
rowsBody.appendChild(row);
tableWrap.setAttribute('aria-busy', 'false');
errorMessage.textContent = message;
errorBox.hidden = false;
};
const renderContext = () => {
const labels = [];
if (purchaseNo !== '') {
labels.push(`采购单 ${purchaseNo}`);
}
if (barcode !== '') {
labels.push(`条码 ${barcode}`);
}
contextLabel.textContent = labels.length > 0 ? `当前定位:${labels.join(' · ')}` : '';
context.classList.toggle('is-visible', labels.length > 0);
};
const renderRows = (payload) => {
const rows = Array.isArray(payload.rows) ? payload.rows : [];
page = Math.max(Number(payload.page || 1), 1);
pages = Math.max(Number(payload.pages || 1), 1);
const perPage = Math.max(Number(payload.per_page || 50), 1);
const total = Math.max(Number(payload.total || 0), 0);
const upload = payload.upload || null;
if (upload) {
dialog.querySelector('[data-raw-upload-time]').textContent = upload.uploaded_at || '—';
dialog.querySelector('[data-raw-upload-file]').textContent = upload.filename || '—';
dialog.querySelector('[data-raw-upload-file]').title = upload.filename || '';
dialog.querySelector('[data-raw-upload-rows]').textContent = new Intl.NumberFormat('zh-CN')
.format(Number(upload.rows || 0));
}
rowsBody.replaceChildren();
if (rows.length === 0) {
const row = document.createElement('tr');
const cell = document.createElement('td');
cell.colSpan = 11;
cell.className = 'sr-raw-table-empty';
cell.textContent = barcode !== '' || purchaseNo !== '' || searchInput.value.trim() !== ''
? '没有匹配的原始账单行,可清除定位或更换搜索条件。'
: '该厂家还没有上传对账单。';
row.appendChild(cell);
rowsBody.appendChild(row);
} else {
rows.forEach((rawRow, index) => {
const row = document.createElement('tr');
row.appendChild(createCell((page - 1) * perPage + index + 1, 'is-muted'));
row.appendChild(createCell(rawRow.expressName, 'is-muted'));
row.appendChild(createCell(rawRow.expressNo, 'is-code'));
row.appendChild(createCell(rawRow.purchaseNo, 'is-code'));
row.appendChild(createCell(rawRow.createdAt));
row.appendChild(createCell(rawRow.supplier));
row.appendChild(createCell(rawRow.barcode, 'is-code'));
row.appendChild(createCell(rawRow.skuName));
row.appendChild(createCell(rawRow.qty, 'is-number'));
row.appendChild(createCell(rawRow.unitPrice, 'is-number'));
row.appendChild(createCell(rawRow.amount, 'is-number'));
rowsBody.appendChild(row);
});
}
pageLabel.textContent = `第 ${page} / ${pages} 页 · 当前 ${new Intl.NumberFormat('zh-CN').format(total)} 行 · 每页 ${perPage} 行`;
previousButton.disabled = page <= 1;
nextButton.disabled = page >= pages;
tableWrap.setAttribute('aria-busy', 'false');
errorBox.hidden = true;
};
const loadRows = async (targetPage = 1) => {
if (!rowsUrl || supplier === '') {
return;
}
if (controller) {
controller.abort();
}
controller = new AbortController();
setLoading();
renderContext();
const url = new URL(rowsUrl, window.location.origin);
url.searchParams.set('supplier', supplier);
url.searchParams.set('page', String(Math.max(Number(targetPage || 1), 1)));
if (searchInput.value.trim() !== '') {
url.searchParams.set('keyword', searchInput.value.trim());
}
if (barcode !== '') {
url.searchParams.set('barcode', barcode);
}
if (purchaseNo !== '') {
url.searchParams.set('purchase_no', purchaseNo);
}
try {
const response = await fetch(url, {
credentials: 'same-origin',
headers: { Accept: 'application/json' },
signal: controller.signal,
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
renderRows(await response.json());
} catch (error) {
if (error.name !== 'AbortError') {
setError('请检查网络连接后重试,当前页面筛选不会丢失。');
}
}
};
const openDrawer = (trigger, locator = {}) => {
opener = trigger || null;
barcode = String(locator.barcode || '').trim();
purchaseNo = String(locator.purchaseNo || '').trim();
searchInput.value = '';
if (typeof dialog.showModal === 'function' && !dialog.open) {
dialog.showModal();
} else if (!dialog.open) {
dialog.setAttribute('open', '');
}
loadRows(1);
window.setTimeout(() => searchInput.focus(), 0);
};
pageRoot.querySelectorAll('[data-raw-statement-open]').forEach((trigger) => {
trigger.addEventListener('click', (event) => {
event.preventDefault();
openDrawer(trigger);
});
});
pageRoot.querySelectorAll('[data-raw-statement-locate]').forEach((trigger) => {
trigger.addEventListener('click', (event) => {
event.preventDefault();
openDrawer(trigger, {
barcode: trigger.dataset.barcode || '',
purchaseNo: trigger.dataset.purchaseNo || '',
});
});
});
dialog.querySelector('[data-raw-statement-close]').addEventListener('click', () => {
dialog.close();
});
dialog.addEventListener('close', () => {
if (controller) {
controller.abort();
}
if (opener && typeof opener.focus === 'function') {
opener.focus();
}
});
searchInput.addEventListener('input', () => {
window.clearTimeout(searchTimer);
searchTimer = window.setTimeout(() => loadRows(1), 300);
});
dialog.querySelector('[data-raw-statement-clear-context]').addEventListener('click', () => {
barcode = '';
purchaseNo = '';
loadRows(1);
});
previousButton.addEventListener('click', () => loadRows(page - 1));
nextButton.addEventListener('click', () => loadRows(page + 1));
retryButton.addEventListener('click', () => loadRows(page));
})();
</script>

View File

@ -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">导出当前筛选</a>
<a href="{{ route('business.pages.show', [
'section' => $section['slug'],
'page' => 'raw-statements',
'supplier' => $selectedSupplier,
'month' => $month,
]) }}" class="sr-button">查看原始账单</a>
<a href="{{ $rawStatementPageUrl }}"
class="sr-button"
data-raw-statement-open
aria-haspopup="dialog"
aria-controls="sr-raw-statement-dialog">查看原始账单</a>
<form id="summary-push-form"
method="POST"
action="{{ route('business.supplier-reconciliation.push-summary') }}">
@ -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
<tr class="{{ $tagClass }}">
<td class="sr-select-cell">
@ -901,30 +915,40 @@
</td>
<td class="is-num">{{ $row['type'] === '未定价' ? '待定价' : number_format($row['settleAmount'], 2) }}</td>
<td>
@if ($row['type'] !== '一致')
<form method="POST"
action="{{ route('business.supplier-reconciliation.push-differences') }}"
onsubmit="return confirm('确认将这条差异推送到该厂家钉钉群?')">
@csrf
<input type="hidden" name="supplier" value="{{ $selectedSupplier }}">
<input type="hidden" name="month" value="{{ $month }}">
<input type="hidden" name="reconciler" value="{{ $reconciler }}">
<input type="hidden" name="comparison_filter" value="{{ $comparisonFilter }}">
<input type="hidden" name="scope" value="row">
<input type="hidden" name="purchase_no" value="{{ $row['purchaseNo'] }}">
<input type="hidden" name="date" value="{{ $row['date'] }}">
<input type="hidden" name="barcode" value="{{ $row['barcode'] }}">
<input type="hidden" name="difference_type" value="{{ $row['type'] }}">
<button type="submit"
class="sr-button is-small {{ $robot['configured'] ? 'is-primary' : 'is-disabled' }}"
@disabled(! $robot['configured'])
title="{{ $robot['configured'] ? '只推送这条差异' : '请先配置厂家钉钉群机器人' }}">
推送本条
</button>
</form>
@else
<span class="sr-muted">—</span>
@endif
<div class="sr-row-actions">
@if (($uploads[$selectedSupplier]['rows'] ?? 0) > 0)
<a href="{{ $rawStatementPageUrl }}"
class="sr-button is-small"
data-raw-statement-locate
data-barcode="{{ $rawStatementBarcode }}"
data-purchase-no="{{ $rawStatementPurchaseNo }}">查看原始</a>
@endif
@if ($row['type'] !== '一致')
<form method="POST"
action="{{ route('business.supplier-reconciliation.push-differences') }}"
onsubmit="return confirm('确认将这条差异推送到该厂家钉钉群?')">
@csrf
<input type="hidden" name="supplier" value="{{ $selectedSupplier }}">
<input type="hidden" name="month" value="{{ $month }}">
<input type="hidden" name="reconciler" value="{{ $reconciler }}">
<input type="hidden" name="comparison_filter" value="{{ $comparisonFilter }}">
<input type="hidden" name="scope" value="row">
<input type="hidden" name="purchase_no" value="{{ $row['purchaseNo'] }}">
<input type="hidden" name="date" value="{{ $row['date'] }}">
<input type="hidden" name="barcode" value="{{ $row['barcode'] }}">
<input type="hidden" name="difference_type" value="{{ $row['type'] }}">
<button type="submit"
class="sr-button is-small {{ $robot['configured'] ? 'is-primary' : 'is-disabled' }}"
@disabled(! $robot['configured'])
title="{{ $robot['configured'] ? '只推送这条差异' : '请先配置厂家钉钉群机器人' }}">
推送本条
</button>
</form>
@endif
@if (($uploads[$selectedSupplier]['rows'] ?? 0) <= 0 && $row['type'] === '一致')
<span class="sr-muted">—</span>
@endif
</div>
</td>
</tr>
@empty
@ -1114,6 +1138,19 @@
@endif
</div>
@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
</div>
@if ($detail)

View File

@ -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')

View File

@ -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