fix(供应商应付): 终版货款对账按数据库分页 (#1489)
This commit is contained in:
parent
1954e10b5e
commit
8df3c3ec36
@ -4699,29 +4699,15 @@ class Pages extends Controller
|
||||
}
|
||||
|
||||
$keyword = trim((string) request('keyword', ''));
|
||||
$rows = $this->supplierPayableOverrides->listRows(
|
||||
PayablesFinalActions::DATASET_PREFIX
|
||||
. ($sectionSlug === PayablesFinalRegistry::SECTION_COURIER ? 'courier:' : 'supplier:')
|
||||
. $dataset,
|
||||
(int) (company_id() ?: 1),
|
||||
);
|
||||
|
||||
if ($keyword !== '') {
|
||||
$needle = mb_strtolower($keyword);
|
||||
$rows = array_values(array_filter($rows, static function (array $row) use ($needle): bool {
|
||||
foreach ($row as $key => $value) {
|
||||
if ($key === '_action_key' || $value === null) {
|
||||
continue;
|
||||
}
|
||||
if (str_contains(mb_strtolower((string) $value), $needle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
|
||||
$storeDataset = PayablesFinalActions::DATASET_PREFIX
|
||||
. ($sectionSlug === PayablesFinalRegistry::SECTION_COURIER ? 'courier:' : 'supplier:')
|
||||
. $dataset;
|
||||
$perPage = in_array($dataset, [
|
||||
'payment-reconciliation',
|
||||
'return-reconciliation',
|
||||
'supplier-payables-report',
|
||||
], true) ? 15 : 50;
|
||||
$currentPage = max((int) request('page', 1), 1);
|
||||
$unpricedSummaryFields = match ($dataset) {
|
||||
'delivery-unpriced' => ['qty', 'guessAmount'],
|
||||
'return-unpriced' => ['qty', 'guess_amount'],
|
||||
@ -4729,6 +4715,25 @@ class Pages extends Controller
|
||||
};
|
||||
$unpricedSummary = null;
|
||||
if ($unpricedSummaryFields !== null) {
|
||||
$rows = $this->supplierPayableOverrides->listRows(
|
||||
$storeDataset,
|
||||
(int) (company_id() ?: 1),
|
||||
);
|
||||
if ($keyword !== '') {
|
||||
$needle = mb_strtolower($keyword);
|
||||
$rows = array_values(array_filter($rows, static function (array $row) use ($needle): bool {
|
||||
foreach ($row as $key => $value) {
|
||||
if ($key === '_action_key' || $value === null) {
|
||||
continue;
|
||||
}
|
||||
if (str_contains(mb_strtolower((string) $value), $needle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
$quantity = 0.0;
|
||||
$estimatedAmount = 0.0;
|
||||
[$quantityField, $amountField] = $unpricedSummaryFields;
|
||||
@ -4744,16 +4749,20 @@ class Pages extends Controller
|
||||
'quantity' => $quantity,
|
||||
'estimated_amount' => $estimatedAmount,
|
||||
];
|
||||
$pagedRows = array_slice($rows, ($currentPage - 1) * $perPage, $perPage);
|
||||
$totalRows = count($rows);
|
||||
} else {
|
||||
$paged = $this->supplierPayableOverrides->paginateRows(
|
||||
$storeDataset,
|
||||
(int) (company_id() ?: 1),
|
||||
$perPage,
|
||||
$currentPage,
|
||||
$keyword,
|
||||
);
|
||||
$pagedRows = $paged['rows'];
|
||||
$totalRows = $paged['total'];
|
||||
}
|
||||
|
||||
// 宽表固定每页 15 行,减少纵向滚动并保持横向核对区稳定。
|
||||
$perPage = in_array($dataset, [
|
||||
'payment-reconciliation',
|
||||
'return-reconciliation',
|
||||
'supplier-payables-report',
|
||||
], true) ? 15 : 50;
|
||||
$currentPage = max((int) request('page', 1), 1);
|
||||
|
||||
return [
|
||||
'dataset' => $dataset,
|
||||
'fields' => collect($registry->fields($sectionSlug, $dataset))
|
||||
@ -4761,8 +4770,8 @@ class Pages extends Controller
|
||||
->values()
|
||||
->all(),
|
||||
'rows' => new LengthAwarePaginator(
|
||||
array_slice($rows, ($currentPage - 1) * $perPage, $perPage),
|
||||
count($rows),
|
||||
$pagedRows,
|
||||
$totalRows,
|
||||
$perPage,
|
||||
$currentPage,
|
||||
['path' => request()->url(), 'query' => request()->query()],
|
||||
|
||||
@ -321,6 +321,45 @@ class SupplierPayableOverrideStore
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按数据库分页读取终版明细,避免宽表在历史数据较多时整表解码。
|
||||
*
|
||||
* @return array{rows:list<array<string,mixed>>,total:int}
|
||||
*/
|
||||
public function paginateRows(
|
||||
string $dataset,
|
||||
int $companyId,
|
||||
int $perPage,
|
||||
int $page,
|
||||
string $keyword = '',
|
||||
): array {
|
||||
$perPage = max(1, min($perPage, 200));
|
||||
$page = max(1, $page);
|
||||
$query = $this->connection()->table('supplier_payable_overrides')
|
||||
->where('company_id', $companyId)
|
||||
->where('dataset', $dataset);
|
||||
|
||||
$keyword = trim($keyword);
|
||||
if ($keyword !== '') {
|
||||
$query->where('values', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
|
||||
$total = (int) (clone $query)->count();
|
||||
$rows = $query
|
||||
->orderBy('id')
|
||||
->forPage($page, $perPage)
|
||||
->get()
|
||||
->map(static function (object $record): array {
|
||||
$values = json_decode((string) $record->values, true) ?: [];
|
||||
$values['_action_key'] = (string) $record->record_key;
|
||||
|
||||
return $values;
|
||||
})
|
||||
->all();
|
||||
|
||||
return ['rows' => $rows, 'total' => $total];
|
||||
}
|
||||
|
||||
/**
|
||||
* 按记录键读取一条本地业务记录,找不到时返回 null。
|
||||
*
|
||||
|
||||
@ -312,6 +312,54 @@ class SupplierPayableFinalPagesTest extends FeatureTestCase
|
||||
$this->assertStringContainsString('快递单号,未发出,对账人', $export->streamedContent());
|
||||
}
|
||||
|
||||
public function test_final_payment_reconciliation_page_reads_one_database_page(): void
|
||||
{
|
||||
$records = [];
|
||||
for ($index = 1; $index <= 31; $index++) {
|
||||
$records[sprintf('payment:%02d', $index)] = [
|
||||
'summary_month' => '2026-09',
|
||||
'stockNo' => sprintf('RK-%02d', $index),
|
||||
'purchaseNo' => sprintf('CG-%02d', $index),
|
||||
'date' => '2026-09-08',
|
||||
'supplier' => sprintf('供应商%02d', $index),
|
||||
'skuCode' => sprintf('SKU-%02d', $index),
|
||||
'productCode' => sprintf('BAR-%02d', $index),
|
||||
'skuName' => sprintf('规格%02d', $index),
|
||||
'qty' => '2',
|
||||
'unitPrice' => '10',
|
||||
'amount' => '20',
|
||||
];
|
||||
}
|
||||
app(SupplierPayableOverrideStore::class)->saveBatch(
|
||||
'final:supplier:payment-reconciliation',
|
||||
$records,
|
||||
(int) $this->company->id,
|
||||
(int) $this->user->id,
|
||||
);
|
||||
|
||||
$baseUrl = route('business.pages.show', [
|
||||
'company_id' => (int) $this->company->id,
|
||||
'section' => 'supplier-payables-final',
|
||||
'page' => 'payment-reconciliation',
|
||||
]);
|
||||
|
||||
$this->loginAs()
|
||||
->get($baseUrl . '?page=2')
|
||||
->assertOk()
|
||||
->assertSeeText('第 2 页 / 共 3 页')
|
||||
->assertSeeText('RK-16')
|
||||
->assertSeeText('RK-30')
|
||||
->assertDontSeeText('RK-01')
|
||||
->assertDontSeeText('RK-31');
|
||||
|
||||
$this->loginAs()
|
||||
->get($baseUrl . '?keyword=' . urlencode('供应商31'))
|
||||
->assertOk()
|
||||
->assertSeeText('共 1 条')
|
||||
->assertSeeText('RK-31')
|
||||
->assertDontSeeText('RK-01');
|
||||
}
|
||||
|
||||
public function test_final_return_reconciliation_template_adds_wms_and_creator_columns(): void
|
||||
{
|
||||
$response = $this->loginAs()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user