feat(货款预估): 支持秒级筛选和筛选结果导出 (#1468)
支持入库时间精确到秒筛选,并导出当前筛选全集。 Co-authored-by: 苏木 <594326199@qq.com> Co-committed-by: 苏木 <594326199@qq.com>
This commit is contained in:
parent
95f7734845
commit
73679c55e3
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Business;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Modules\EcommerceFinance\Repositories\SupplierPayableForecastRepository;
|
||||
use Modules\EcommerceFinance\Services\PayablesFinalRegistry;
|
||||
use Modules\EcommerceFinance\View\SupplierPayableForecastPageData;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
final class SupplierPayableForecastExport extends Controller
|
||||
{
|
||||
public function goods(
|
||||
Request $request,
|
||||
SupplierPayableForecastPageData $pageData,
|
||||
SupplierPayableForecastRepository $repository,
|
||||
PayablesFinalRegistry $registry,
|
||||
): StreamedResponse {
|
||||
$filters = $pageData->goodsFilters($request);
|
||||
abort_unless(
|
||||
$repository->syncStatus()['ready'],
|
||||
503,
|
||||
'采购入库共享镜像尚未就绪,暂不能导出。',
|
||||
);
|
||||
|
||||
$fields = $registry->fields(
|
||||
PayablesFinalRegistry::SECTION_SUPPLIER,
|
||||
'payment-reconciliation',
|
||||
);
|
||||
|
||||
return response()->streamDownload(function () use ($fields, $filters, $repository): void {
|
||||
$stream = fopen('php://output', 'w');
|
||||
if ($stream === false) {
|
||||
throw new \RuntimeException('无法创建供应商货款明细导出文件。');
|
||||
}
|
||||
|
||||
fwrite($stream, "\xEF\xBB\xBF");
|
||||
fputcsv($stream, array_map(
|
||||
static fn (array $field): string => (string) ($field['label'] ?? ''),
|
||||
$fields,
|
||||
));
|
||||
|
||||
foreach ($repository->goodsRowsForExport($filters) as $row) {
|
||||
$values = [];
|
||||
foreach ($fields as $key => $field) {
|
||||
$value = $row[$key] ?? '';
|
||||
$values[] = ($field['type'] ?? '') === 'number'
|
||||
? number_format((float) $value, 2, '.', '')
|
||||
: $this->textCell($value);
|
||||
}
|
||||
fputcsv($stream, $values);
|
||||
}
|
||||
|
||||
fclose($stream);
|
||||
}, $this->filename($filters), [
|
||||
'Content-Type' => 'text/csv; charset=UTF-8',
|
||||
'Cache-Control' => 'private, no-store',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @param array{date_from:string,date_to:string,keyword:string} $filters */
|
||||
private function filename(array $filters): string
|
||||
{
|
||||
$from = Carbon::parse($filters['date_from'])->format('Ymd_His');
|
||||
$to = $filters['date_to'] !== ''
|
||||
? Carbon::parse($filters['date_to'])->format('Ymd_His')
|
||||
: '不限';
|
||||
|
||||
return '供应商货款明细_' . $from . '_' . $to . '_' . now()->format('Ymd_His') . '.csv';
|
||||
}
|
||||
|
||||
private function textCell(mixed $value): string
|
||||
{
|
||||
$text = trim((string) $value);
|
||||
if ($text === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return preg_match('/^[=+\-@\t\r\n]/u', $text) === 1
|
||||
|| preg_match('/^\d{12,}$/D', $text) === 1
|
||||
? "'" . $text
|
||||
: $text;
|
||||
}
|
||||
}
|
||||
@ -24,6 +24,28 @@ class SupplierPayableForecastRepository
|
||||
|
||||
public const DEFAULT_FROM = '2026-10-01';
|
||||
|
||||
public const DEFAULT_FROM_TIME = self::DEFAULT_FROM . ' 00:00:00';
|
||||
|
||||
private const GOODS_SOURCE_COLUMNS = [
|
||||
'h.Id as receiving_id',
|
||||
'h.io_id',
|
||||
'h.po_id',
|
||||
'h.io_date',
|
||||
'h.remark as head_remark',
|
||||
'h.warehouse',
|
||||
'h.logistics_company',
|
||||
'h.status',
|
||||
'h.supplier_name',
|
||||
'i.Id as item_id',
|
||||
'i.sku_id',
|
||||
'i.i_id',
|
||||
'i.name',
|
||||
'i.qty',
|
||||
'i.cost_price',
|
||||
'i.cost_amount',
|
||||
'i.remark as item_remark',
|
||||
];
|
||||
|
||||
private readonly ConnectionInterface $connection;
|
||||
|
||||
private readonly string $connectionName;
|
||||
@ -125,25 +147,7 @@ class SupplierPayableForecastRepository
|
||||
->orderByDesc('h.Id')
|
||||
->orderByDesc('i.Id')
|
||||
->forPage($page, $perPage)
|
||||
->get([
|
||||
'h.Id as receiving_id',
|
||||
'h.io_id',
|
||||
'h.po_id',
|
||||
'h.io_date',
|
||||
'h.remark as head_remark',
|
||||
'h.warehouse',
|
||||
'h.logistics_company',
|
||||
'h.status',
|
||||
'h.supplier_name',
|
||||
'i.Id as item_id',
|
||||
'i.sku_id',
|
||||
'i.i_id',
|
||||
'i.name',
|
||||
'i.qty',
|
||||
'i.cost_price',
|
||||
'i.cost_amount',
|
||||
'i.remark as item_remark',
|
||||
]);
|
||||
->get(self::GOODS_SOURCE_COLUMNS);
|
||||
|
||||
$priceMap = $this->latestChangePrices(
|
||||
$sourceRows->pluck('sku_id')->filter()->map(static fn (mixed $value): string => trim((string) $value))->unique()->values()->all()
|
||||
@ -163,12 +167,52 @@ class SupplierPayableForecastRepository
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 流式读取当前筛选全集,按小批次匹配变价,避免导出把整表装入内存。
|
||||
*
|
||||
* @param array{date_from:string,date_to:string,keyword:string} $filters
|
||||
* @return \Generator<int,array<string,mixed>>
|
||||
*/
|
||||
public function goodsRowsForExport(array $filters, int $batchSize = 500): \Generator
|
||||
{
|
||||
$batchSize = min(max($batchSize, 1), 1000);
|
||||
$query = $this->filteredGoodsQuery($filters);
|
||||
$page = 1;
|
||||
|
||||
do {
|
||||
$sourceRows = (clone $query)
|
||||
->orderByDesc('h.io_date')
|
||||
->orderByDesc('h.Id')
|
||||
->orderByDesc('i.Id')
|
||||
->forPage($page, $batchSize)
|
||||
->get(self::GOODS_SOURCE_COLUMNS);
|
||||
|
||||
$priceMap = $this->latestChangePrices(
|
||||
$sourceRows->pluck('sku_id')
|
||||
->filter()
|
||||
->map(static fn (mixed $value): string => trim((string) $value))
|
||||
->unique()
|
||||
->values()
|
||||
->all()
|
||||
);
|
||||
|
||||
foreach ($sourceRows as $row) {
|
||||
yield $this->formatGoodsRow(
|
||||
$row,
|
||||
$priceMap->get($this->normalizeSku($row->sku_id)),
|
||||
);
|
||||
}
|
||||
|
||||
$page++;
|
||||
} while ($sourceRows->count() === $batchSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{date_from:string,date_to:string,keyword:string} $filters
|
||||
*/
|
||||
private function filteredGoodsQuery(array $filters): \Illuminate\Database\Query\Builder
|
||||
{
|
||||
$from = Carbon::parse($filters['date_from'] ?: self::DEFAULT_FROM)->startOfDay();
|
||||
$from = Carbon::parse($filters['date_from'] ?: self::DEFAULT_FROM_TIME);
|
||||
$to = trim((string) ($filters['date_to'] ?? ''));
|
||||
$keyword = trim((string) ($filters['keyword'] ?? ''));
|
||||
|
||||
@ -181,7 +225,11 @@ class SupplierPayableForecastRepository
|
||||
->whereRaw("TRIM(COALESCE(sku_id, '')) NOT LIKE ?", ['DF-%']);
|
||||
|
||||
if ($to !== '') {
|
||||
$query->where('h.io_date', '<', Carbon::parse($to)->addDay()->startOfDay()->format('Y-m-d H:i:s'));
|
||||
$toDate = Carbon::parse($to);
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/D', $to) === 1) {
|
||||
$toDate->endOfDay();
|
||||
}
|
||||
$query->where('h.io_date', '<=', $toDate->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
if ($keyword !== '') {
|
||||
@ -245,7 +293,7 @@ class SupplierPayableForecastRepository
|
||||
'month' => $occurredAt->format('Y-m'),
|
||||
'stockNo' => (string) ($row->io_id ?? ''),
|
||||
'purchaseNo' => (string) ($row->po_id ?? ''),
|
||||
'date' => $occurredAt->format('Y-m-d'),
|
||||
'date' => $occurredAt->format('Y-m-d H:i:s'),
|
||||
'supplier' => (string) ($row->supplier_name ?? ''),
|
||||
'skuCode' => (string) ($row->i_id ?? ''),
|
||||
'productCode' => (string) ($row->sku_id ?? ''),
|
||||
|
||||
@ -42,7 +42,7 @@ class SupplierPayableForecastPageData
|
||||
}
|
||||
|
||||
$paginationQuery = array_filter([
|
||||
'goods_date_from' => $filters['date_from'] === SupplierPayableForecastRepository::DEFAULT_FROM
|
||||
'goods_date_from' => $filters['date_from'] === SupplierPayableForecastRepository::DEFAULT_FROM_TIME
|
||||
? null
|
||||
: $filters['date_from'],
|
||||
'goods_date_to' => $filters['date_to'] !== '' ? $filters['date_to'] : null,
|
||||
@ -79,39 +79,53 @@ class SupplierPayableForecastPageData
|
||||
}
|
||||
|
||||
/** @return array{date_from:string,date_to:string,keyword:string} */
|
||||
private function goodsFilters(Request $request): array
|
||||
public function goodsFilters(Request $request): array
|
||||
{
|
||||
$minimum = Carbon::createFromFormat('!Y-m-d', SupplierPayableForecastRepository::DEFAULT_FROM);
|
||||
$from = $this->validDate($request->query('goods_date_from'));
|
||||
$minimum = Carbon::createFromFormat('!Y-m-d H:i:s', SupplierPayableForecastRepository::DEFAULT_FROM_TIME);
|
||||
$from = $this->validDateTime($request->query('goods_date_from'));
|
||||
if ($from === null || $from->lt($minimum)) {
|
||||
$from = $minimum;
|
||||
$from = $minimum->copy();
|
||||
}
|
||||
|
||||
$to = $this->validDate($request->query('goods_date_to'));
|
||||
$to = $this->validDateTime($request->query('goods_date_to'), true);
|
||||
if ($to !== null && $to->lt($from)) {
|
||||
$to = $from->copy();
|
||||
}
|
||||
|
||||
return [
|
||||
'date_from' => $from->format('Y-m-d'),
|
||||
'date_to' => $to?->format('Y-m-d') ?? '',
|
||||
'date_from' => $from->format('Y-m-d H:i:s'),
|
||||
'date_to' => $to?->format('Y-m-d H:i:s') ?? '',
|
||||
'keyword' => mb_substr(trim((string) $request->query('goods_keyword', '')), 0, 120),
|
||||
];
|
||||
}
|
||||
|
||||
private function validDate(mixed $value): ?Carbon
|
||||
private function validDateTime(mixed $value, bool $endOfDay = false): ?Carbon
|
||||
{
|
||||
if (! is_string($value) || preg_match('/^\d{4}-\d{2}-\d{2}$/D', $value) !== 1) {
|
||||
if (! is_string($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$date = Carbon::createFromFormat('!Y-m-d', $value);
|
||||
$value = trim($value);
|
||||
$dateOnly = preg_match('/^\d{4}-\d{2}-\d{2}$/D', $value) === 1;
|
||||
$withTime = preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/D', $value) === 1;
|
||||
if (! $dateOnly && ! $withTime) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$format = $dateOnly ? '!Y-m-d' : '!Y-m-d H:i:s';
|
||||
$date = Carbon::createFromFormat($format, $value);
|
||||
$errors = Carbon::getLastErrors();
|
||||
|
||||
return $date !== false
|
||||
&& ($errors === false || ($errors['warning_count'] === 0 && $errors['error_count'] === 0))
|
||||
&& $date->format('Y-m-d') === $value
|
||||
? $date
|
||||
: null;
|
||||
if (! $date
|
||||
|| ! ($errors === false || ($errors['warning_count'] === 0 && $errors['error_count'] === 0))
|
||||
|| $date->format($dateOnly ? 'Y-m-d' : 'Y-m-d H:i:s') !== $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($dateOnly) {
|
||||
return $endOfDay ? $date->endOfDay() : $date->startOfDay();
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@
|
||||
|
||||
.supplier-payable-forecast .npf-filter {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(140px, .8fr) minmax(140px, .8fr) minmax(240px, 1.8fr) auto;
|
||||
grid-template-columns: minmax(190px, .9fr) minmax(190px, .9fr) minmax(240px, 1.8fr) auto;
|
||||
align-items: end;
|
||||
gap: 10px;
|
||||
padding: 12px;
|
||||
@ -313,8 +313,10 @@
|
||||
|
||||
.supplier-payable-forecast .npf-button:hover { border-color: var(--npf-gold); background: #FCFAF5; }
|
||||
.supplier-payable-forecast .npf-button:focus-visible { outline: 0; box-shadow: 0 0 0 3px rgba(133, 102, 50, 0.20); }
|
||||
.supplier-payable-forecast .npf-button:disabled { opacity: .48; cursor: not-allowed; }
|
||||
.supplier-payable-forecast .npf-button.is-primary { border-color: var(--npf-gold); background: var(--npf-gold); color: #FFFFFF; }
|
||||
.supplier-payable-forecast .npf-button.is-primary:hover { border-color: #6A5129; background: #6A5129; }
|
||||
.supplier-payable-forecast .npf-button .material-icons-outlined { margin-right: 3px; font-size: 16px; }
|
||||
|
||||
.supplier-payable-forecast .npf-table-shell {
|
||||
max-width: 100%;
|
||||
@ -482,26 +484,26 @@
|
||||
<form method="GET" action="{{ request()->url() }}" class="npf-filter" aria-label="查询货款明细">
|
||||
<input type="hidden" name="forecast_view" value="goods">
|
||||
<div class="npf-field">
|
||||
<span>入库日期起</span>
|
||||
<div class="upstream-data-date" data-date-picker>
|
||||
<input type="text" name="goods_date_from" value="{{ $goodsForecastFilters['date_from'] }}" readonly data-date-input aria-label="入库日期起">
|
||||
<button type="button" class="upstream-data-date__clear" data-date-clear hidden aria-label="清空入库日期起">
|
||||
<span>入库时间起</span>
|
||||
<div class="upstream-data-date" data-date-picker data-date-time>
|
||||
<input type="text" name="goods_date_from" value="{{ $goodsForecastFilters['date_from'] }}" readonly data-date-input aria-label="入库时间起,精确到秒">
|
||||
<button type="button" class="upstream-data-date__clear" data-date-clear hidden aria-label="清空入库时间起">
|
||||
<span class="material-icons-outlined" aria-hidden="true">close</span>
|
||||
</button>
|
||||
<button type="button" class="upstream-data-date__pick" data-date-toggle aria-label="选择入库日期起">
|
||||
<button type="button" class="upstream-data-date__pick" data-date-toggle aria-label="选择入库时间起">
|
||||
<span class="material-icons-outlined" aria-hidden="true">calendar_month</span>
|
||||
</button>
|
||||
<div class="upstream-data-calendar" data-date-calendar hidden></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="npf-field npf-field--date-end">
|
||||
<span>入库日期止</span>
|
||||
<div class="upstream-data-date" data-date-picker>
|
||||
<input type="text" name="goods_date_to" value="{{ $goodsForecastFilters['date_to'] }}" readonly data-date-input aria-label="入库日期止">
|
||||
<button type="button" class="upstream-data-date__clear" data-date-clear hidden aria-label="清空入库日期止">
|
||||
<span>入库时间止</span>
|
||||
<div class="upstream-data-date" data-date-picker data-date-time data-date-end-of-day>
|
||||
<input type="text" name="goods_date_to" value="{{ $goodsForecastFilters['date_to'] }}" readonly data-date-input aria-label="入库时间止,精确到秒">
|
||||
<button type="button" class="upstream-data-date__clear" data-date-clear hidden aria-label="清空入库时间止">
|
||||
<span class="material-icons-outlined" aria-hidden="true">close</span>
|
||||
</button>
|
||||
<button type="button" class="upstream-data-date__pick" data-date-toggle aria-label="选择入库日期止">
|
||||
<button type="button" class="upstream-data-date__pick" data-date-toggle aria-label="选择入库时间止">
|
||||
<span class="material-icons-outlined" aria-hidden="true">calendar_month</span>
|
||||
</button>
|
||||
<div class="upstream-data-calendar" data-date-calendar hidden></div>
|
||||
@ -513,6 +515,17 @@
|
||||
</label>
|
||||
<div class="npf-filter-actions">
|
||||
<button type="submit" class="npf-button is-primary">查询</button>
|
||||
<button
|
||||
type="submit"
|
||||
class="npf-button"
|
||||
formaction="{{ route('business.supplier-payable-forecast.goods.export') }}"
|
||||
formmethod="get"
|
||||
title="导出当前筛选的全部货款明细"
|
||||
@disabled(! $goodsForecastSyncStatus['ready'] || $goodsForecastRows->total() === 0)
|
||||
>
|
||||
<span class="material-icons-outlined" aria-hidden="true">download</span>
|
||||
导出当前筛选
|
||||
</button>
|
||||
<a class="npf-button" href="{{ request()->url() }}">重置</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@ -158,6 +158,62 @@
|
||||
background: var(--vip-content-accent-dark, #856632);
|
||||
color: #ffffff;
|
||||
}
|
||||
.upstream-data-calendar.has-time {
|
||||
width: min(18.5rem, calc(100vw - 2rem));
|
||||
}
|
||||
.upstream-data-calendar__time {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 0.375rem;
|
||||
margin-top: 0.5rem;
|
||||
padding-top: 0.5rem;
|
||||
border-top: 1px solid var(--vip-border, #d8d2c7);
|
||||
}
|
||||
.upstream-data-calendar__time label {
|
||||
display: grid;
|
||||
gap: 0.25rem;
|
||||
min-width: 0;
|
||||
color: var(--vip-content-muted, #595959);
|
||||
font-size: 0.6875rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
.upstream-data-calendar__time input {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
height: 2rem;
|
||||
padding: 0 0.375rem;
|
||||
border: 1px solid var(--vip-border, #d8d2c7);
|
||||
border-radius: 0.375rem;
|
||||
background: var(--vip-surface, #ffffff);
|
||||
color: var(--vip-content-ink, #171717);
|
||||
font: inherit;
|
||||
font-size: 0.75rem;
|
||||
font-variant-numeric: tabular-nums;
|
||||
text-align: center;
|
||||
}
|
||||
.upstream-data-calendar__time input:focus {
|
||||
border-color: var(--vip-content-accent-dark, #856632);
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 2px rgba(133, 102, 50, 0.18);
|
||||
}
|
||||
.upstream-data-calendar__actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
.upstream-data-calendar__apply {
|
||||
min-height: 1.875rem;
|
||||
padding: 0 0.75rem;
|
||||
border: 1px solid var(--vip-content-accent-dark, #856632);
|
||||
border-radius: 0.375rem;
|
||||
background: var(--vip-content-accent-dark, #856632);
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.upstream-data-calendar__apply:hover { background: #6a5129; }
|
||||
/* 结束日期的日历向右展开会顶出工具栏,改成向左 */
|
||||
.upstream-data-date:last-of-type .upstream-data-calendar {
|
||||
right: 0;
|
||||
@ -197,6 +253,36 @@
|
||||
&& left.getDate() === right.getDate();
|
||||
}
|
||||
|
||||
function parseTimeParts(text, endOfDay) {
|
||||
var match = /^\d{4}-\d{2}-\d{2}[ T](\d{2}):(\d{2}):(\d{2})$/.exec(String(text || '').trim());
|
||||
if (!match) {
|
||||
return endOfDay ? { hour: 23, minute: 59, second: 59 } : { hour: 0, minute: 0, second: 0 };
|
||||
}
|
||||
|
||||
return {
|
||||
hour: Number(match[1]),
|
||||
minute: Number(match[2]),
|
||||
second: Number(match[3])
|
||||
};
|
||||
}
|
||||
|
||||
function clampPart(value, max) {
|
||||
var number = Number.parseInt(value, 10);
|
||||
if (Number.isNaN(number)) { return 0; }
|
||||
|
||||
return Math.min(Math.max(number, 0), max);
|
||||
}
|
||||
|
||||
function dateTimeText(dateText, timeParts) {
|
||||
return dateText + ' ' + pad2(timeParts.hour) + ':' + pad2(timeParts.minute) + ':' + pad2(timeParts.second);
|
||||
}
|
||||
|
||||
function timeField(part, label, max, value) {
|
||||
return '<label><span>' + label + '</span>'
|
||||
+ '<input type="number" inputmode="numeric" min="0" max="' + max + '" step="1"'
|
||||
+ ' data-time-part="' + part + '" aria-label="' + label + '" value="' + pad2(value) + '"></label>';
|
||||
}
|
||||
|
||||
function setupDatePicker(picker) {
|
||||
if (picker.dataset.datePickerReady === 'true') { return; }
|
||||
picker.dataset.datePickerReady = 'true';
|
||||
@ -206,11 +292,15 @@
|
||||
var clear = picker.querySelector('[data-date-clear]');
|
||||
if (!input || !panel || !toggle) { return; }
|
||||
|
||||
var withTime = picker.hasAttribute('data-date-time') || input.hasAttribute('data-date-time');
|
||||
var endOfDay = picker.hasAttribute('data-date-end-of-day');
|
||||
var today = new Date();
|
||||
var selected = parseIsoDate(input.value);
|
||||
var timeParts = parseTimeParts(input.value, endOfDay);
|
||||
var anchor = selected || today;
|
||||
var viewYear = anchor.getFullYear();
|
||||
var viewMonth = anchor.getMonth();
|
||||
panel.classList.toggle('has-time', withTime);
|
||||
|
||||
function isOpen() { return !panel.hidden; }
|
||||
|
||||
@ -218,6 +308,35 @@
|
||||
if (clear) { clear.hidden = input.value === ''; }
|
||||
}
|
||||
|
||||
function updateInputValue() {
|
||||
if (!selected) {
|
||||
input.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
var dateText = isoDate(selected);
|
||||
input.value = withTime ? dateTimeText(dateText, timeParts) : dateText;
|
||||
}
|
||||
|
||||
function readTimeParts() {
|
||||
if (!withTime) { return; }
|
||||
var next = {};
|
||||
var limits = { hour: 23, minute: 59, second: 59 };
|
||||
panel.querySelectorAll('[data-time-part]').forEach(function (node) {
|
||||
var part = node.getAttribute('data-time-part');
|
||||
if (!(part in limits)) { return; }
|
||||
next[part] = clampPart(node.value, limits[part]);
|
||||
node.value = pad2(next[part]);
|
||||
});
|
||||
if ('hour' in next && 'minute' in next && 'second' in next) {
|
||||
timeParts = next;
|
||||
}
|
||||
}
|
||||
|
||||
function dispatchChange() {
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
|
||||
function render() {
|
||||
var monthStart = new Date(viewYear, viewMonth, 1);
|
||||
var gridStart = new Date(viewYear, viewMonth, 1 - monthStart.getDay());
|
||||
@ -242,12 +361,27 @@
|
||||
html += '<button type="button" class="' + classes + '" data-calendar-day="'
|
||||
+ isoDate(day) + '">' + day.getDate() + '</button>';
|
||||
}
|
||||
html += '</div>';
|
||||
|
||||
panel.innerHTML = html + '</div>';
|
||||
if (withTime) {
|
||||
html += '<div class="upstream-data-calendar__time">'
|
||||
+ timeField('hour', '时', 23, timeParts.hour)
|
||||
+ timeField('minute', '分', 59, timeParts.minute)
|
||||
+ timeField('second', '秒', 59, timeParts.second)
|
||||
+ '</div>'
|
||||
+ '<div class="upstream-data-calendar__actions">'
|
||||
+ '<button type="button" class="upstream-data-calendar__apply" data-calendar-apply>确定</button>'
|
||||
+ '</div>';
|
||||
}
|
||||
|
||||
panel.innerHTML = html;
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (!isOpen()) { return; }
|
||||
readTimeParts();
|
||||
updateInputValue();
|
||||
syncClear();
|
||||
panel.hidden = true;
|
||||
toggle.setAttribute('aria-expanded', 'false');
|
||||
}
|
||||
@ -256,6 +390,7 @@
|
||||
closers.forEach(function (otherClose) { if (otherClose !== close) { otherClose(); } });
|
||||
if (isOpen()) { return; }
|
||||
selected = parseIsoDate(input.value);
|
||||
timeParts = parseTimeParts(input.value, endOfDay);
|
||||
anchor = selected || new Date();
|
||||
viewYear = anchor.getFullYear();
|
||||
viewMonth = anchor.getMonth();
|
||||
@ -285,10 +420,43 @@
|
||||
}
|
||||
var day = event.target.closest('[data-calendar-day]');
|
||||
if (day && panel.contains(day)) {
|
||||
input.value = day.getAttribute('data-calendar-day');
|
||||
selected = parseIsoDate(input.value);
|
||||
selected = parseIsoDate(day.getAttribute('data-calendar-day'));
|
||||
updateInputValue();
|
||||
syncClear();
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
dispatchChange();
|
||||
if (withTime) {
|
||||
render();
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
var apply = event.target.closest('[data-calendar-apply]');
|
||||
if (apply && panel.contains(apply)) {
|
||||
readTimeParts();
|
||||
updateInputValue();
|
||||
syncClear();
|
||||
dispatchChange();
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
panel.addEventListener('change', function (event) {
|
||||
var timeInput = event.target.closest('[data-time-part]');
|
||||
if (!withTime || !timeInput || !panel.contains(timeInput)) { return; }
|
||||
readTimeParts();
|
||||
updateInputValue();
|
||||
syncClear();
|
||||
dispatchChange();
|
||||
});
|
||||
|
||||
panel.addEventListener('keydown', function (event) {
|
||||
if (withTime && event.key === 'Enter' && event.target.closest('[data-time-part]')) {
|
||||
event.preventDefault();
|
||||
readTimeParts();
|
||||
updateInputValue();
|
||||
syncClear();
|
||||
dispatchChange();
|
||||
close();
|
||||
}
|
||||
});
|
||||
@ -311,8 +479,9 @@
|
||||
clear.addEventListener('click', function () {
|
||||
input.value = '';
|
||||
selected = null;
|
||||
timeParts = endOfDay ? { hour: 23, minute: 59, second: 59 } : { hour: 0, minute: 0, second: 0 };
|
||||
syncClear();
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
dispatchChange();
|
||||
close();
|
||||
});
|
||||
}
|
||||
|
||||
@ -263,6 +263,10 @@ Route::get('workspace/supplier-payables/supplier-management/contracts/export', [
|
||||
->middleware('business.page:supplier-payables,supplier-management')
|
||||
->name('business.supplier-contracts.export');
|
||||
|
||||
Route::get('workspace/negative-alerts/supplier-payable-forecast/goods/export', [\App\Http\Controllers\Business\SupplierPayableForecastExport::class, 'goods'])
|
||||
->middleware('business.page:negative-alerts,supplier-negative-alert')
|
||||
->name('business.supplier-payable-forecast.goods.export');
|
||||
|
||||
Route::get('workspace/product-inventory/normal-products/export', 'Business\Pages@exportNormalProducts')
|
||||
->middleware('business.page:product-inventory,normal-products')
|
||||
->name('business.product-inventory.normal-products.export');
|
||||
|
||||
@ -421,6 +421,14 @@ class NegativeAlertPagesTest extends FeatureTestCase
|
||||
$html = (string) $response->getContent();
|
||||
$this->assertStringContainsString('data-date-picker', $html);
|
||||
$this->assertStringContainsString('data-date-input', $html);
|
||||
$this->assertStringContainsString('data-date-time', $html);
|
||||
$this->assertStringContainsString('data-date-end-of-day', $html);
|
||||
$this->assertStringContainsString("timeField('hour', '时', 23", $html);
|
||||
$this->assertStringContainsString("timeField('second', '秒', 59", $html);
|
||||
$this->assertStringContainsString('入库时间起', $html);
|
||||
$this->assertStringContainsString('2026-10-01 00:00:00', $html);
|
||||
$this->assertStringContainsString(route('business.supplier-payable-forecast.goods.export'), $html);
|
||||
$this->assertStringContainsString('导出当前筛选', $html);
|
||||
$this->assertStringContainsString('CaiWuDatePicker.setup(filterForm)', $html);
|
||||
$this->assertStringNotContainsString('name="goods_date_from" min=', $html);
|
||||
$this->assertStringNotContainsString('name="goods_date_to" min=', $html);
|
||||
@ -439,6 +447,94 @@ class NegativeAlertPagesTest extends FeatureTestCase
|
||||
'数量', '单价', '金额', '预估单价', '预估金额', '供应商商品编码', '备注',
|
||||
'仓库名称', '快递名称', '快递单号', '未发出', '对账人',
|
||||
], $labels);
|
||||
|
||||
$this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'negative-alerts',
|
||||
'page' => 'supplier-negative-alert',
|
||||
'tab' => 'payable-forecast',
|
||||
'goods_date_from' => '2026-10-01 10:00:00',
|
||||
'goods_date_to' => '2026-10-01 10:00:00',
|
||||
]))->assertOk()
|
||||
->assertSeeText('IN-20261001')
|
||||
->assertSeeText('2026-10-01 10:00:00');
|
||||
|
||||
$this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'negative-alerts',
|
||||
'page' => 'supplier-negative-alert',
|
||||
'tab' => 'payable-forecast',
|
||||
'goods_date_from' => '2026-10-01 10:00:01',
|
||||
'goods_date_to' => '2026-10-01 10:00:02',
|
||||
]))->assertOk()
|
||||
->assertSeeText('没有符合当前条件的货款明细')
|
||||
->assertDontSeeText('IN-20261001');
|
||||
|
||||
$this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'negative-alerts',
|
||||
'page' => 'supplier-negative-alert',
|
||||
'tab' => 'payable-forecast',
|
||||
'goods_date_from' => '2026-10-01',
|
||||
'goods_date_to' => '2026-10-01',
|
||||
]))->assertOk()
|
||||
->assertSeeText('IN-20261001');
|
||||
}
|
||||
|
||||
public function test_supplier_payable_forecast_export_streams_all_rows_matching_second_precision(): void
|
||||
{
|
||||
$this->createSupplierPayableForecastTables();
|
||||
$now = now();
|
||||
DB::connection('business_mirror')->table('business_mirror_table_states')->insert([
|
||||
['dataset_key' => SupplierPayableForecastRepository::HEAD_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
|
||||
['dataset_key' => SupplierPayableForecastRepository::ITEM_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
|
||||
['dataset_key' => SupplierPayableForecastRepository::PRICE_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now],
|
||||
]);
|
||||
|
||||
for ($index = 1; $index <= 22; $index++) {
|
||||
$ioId = $index === 21 ? '123456789012345678' : 'IN-EXPORT-' . $index;
|
||||
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::HEAD_TABLE)->insert([
|
||||
'Id' => $index,
|
||||
'io_id' => $ioId,
|
||||
'po_id' => 800000 + $index,
|
||||
'io_date' => $index === 22 ? '2026-11-01 10:00:01' : '2026-11-01 10:00:00',
|
||||
'warehouse' => '正常仓',
|
||||
'supplier_name' => '导出供应商',
|
||||
]);
|
||||
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::ITEM_TABLE)->insert([
|
||||
'Id' => $index,
|
||||
'io_id' => $ioId,
|
||||
'ioi_id' => 'ITEM-EXPORT-' . $index,
|
||||
'sku_id' => 'SKU-EXPORT-' . $index,
|
||||
'i_id' => 'STYLE-EXPORT-' . $index,
|
||||
'name' => $index === 21 ? '=危险商品' : '导出商品 ' . $index,
|
||||
'qty' => 1,
|
||||
'cost_price' => 3,
|
||||
'cost_amount' => 3,
|
||||
]);
|
||||
}
|
||||
|
||||
$response = $this->loginAs()->get(route('business.supplier-payable-forecast.goods.export', [
|
||||
'goods_date_from' => '2026-11-01 00:00:00',
|
||||
'goods_date_to' => '2026-11-01 10:00:00',
|
||||
]))->assertOk()
|
||||
->assertHeader('content-type', 'text/csv; charset=UTF-8')
|
||||
->assertDownload();
|
||||
|
||||
$csv = $response->streamedContent();
|
||||
$this->assertStringStartsWith("\xEF\xBB\xBF", $csv);
|
||||
$this->assertSame(22, substr_count($csv, "\n"));
|
||||
$this->assertStringContainsString('IN-EXPORT-1', $csv);
|
||||
$this->assertStringContainsString('IN-EXPORT-20', $csv);
|
||||
$this->assertStringContainsString('STYLE-EXPORT-21', $csv);
|
||||
$this->assertStringNotContainsString('IN-EXPORT-22', $csv);
|
||||
$this->assertStringContainsString("'123456789012345678", $csv);
|
||||
$this->assertStringContainsString("'=危险商品", $csv);
|
||||
|
||||
$lines = preg_split('/\r\n|\n|\r/', trim(substr($csv, 3))) ?: [];
|
||||
$this->assertSame([
|
||||
'月份', '入库单号', '采购单号', '日期', '供应商', '货号', '商品编码', '规格名称',
|
||||
'数量', '单价', '金额', '预估单价', '预估金额', '供应商商品编码', '备注',
|
||||
'仓库名称', '快递名称', '快递单号', '未发出', '对账人',
|
||||
], str_getcsv($lines[0]));
|
||||
$this->assertSame('2026-11-01 10:00:00', str_getcsv($lines[1])[3]);
|
||||
}
|
||||
|
||||
private function createSupplierPayableForecastTables(): void
|
||||
|
||||
@ -49,6 +49,45 @@ class SupplierPayableForecastRepositoryTest extends TestCase
|
||||
], 1);
|
||||
$this->assertSame(1, $keyword['total']);
|
||||
$this->assertSame('SKU-A', $keyword['rows'][0]['productCode']);
|
||||
|
||||
$exportRows = iterator_to_array(app(SupplierPayableForecastRepository::class)->goodsRowsForExport([
|
||||
'date_from' => '2026-10-01 00:00:00',
|
||||
'date_to' => '',
|
||||
'keyword' => '',
|
||||
], 1));
|
||||
$this->assertCount(2, $exportRows);
|
||||
$this->assertSame(['SKU-B', 'SKU-A'], array_column($exportRows, 'productCode'));
|
||||
}
|
||||
|
||||
public function test_goods_date_filters_are_inclusive_to_the_second_and_keep_legacy_date_ranges(): void
|
||||
{
|
||||
$this->createTables();
|
||||
$this->seedRows();
|
||||
$repository = app(SupplierPayableForecastRepository::class);
|
||||
|
||||
$exact = $repository->goodsDetails([
|
||||
'date_from' => '2026-10-02 09:00:00',
|
||||
'date_to' => '2026-10-02 09:00:00',
|
||||
'keyword' => '',
|
||||
], 1);
|
||||
$this->assertSame(1, $exact['total']);
|
||||
$this->assertSame('IN-1', $exact['rows'][0]['stockNo']);
|
||||
$this->assertSame('2026-10-02 09:00:00', $exact['rows'][0]['date']);
|
||||
|
||||
$afterBoundary = $repository->goodsDetails([
|
||||
'date_from' => '2026-10-02 09:00:01',
|
||||
'date_to' => '2026-10-02 09:00:02',
|
||||
'keyword' => '',
|
||||
], 1);
|
||||
$this->assertSame(0, $afterBoundary['total']);
|
||||
|
||||
$legacy = $repository->goodsDetails([
|
||||
'date_from' => '2026-10-02',
|
||||
'date_to' => '2026-10-02',
|
||||
'keyword' => '',
|
||||
], 1);
|
||||
$this->assertSame(1, $legacy['total']);
|
||||
$this->assertSame('IN-1', $legacy['rows'][0]['stockNo']);
|
||||
}
|
||||
|
||||
private function createTables(): void
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user