feat(供应商货款预估): 接入采购入库与变价价格 (#1347)
接入聚水潭采购入库明细、固定剔除规则和工作平台最新变价后采购价。 Co-authored-by: 苏木 <594326199@qq.com> Co-committed-by: 苏木 <594326199@qq.com>
This commit is contained in:
parent
d664680aec
commit
205cdfe50e
@ -105,6 +105,7 @@ use Modules\EcommerceFinance\Services\SupplierFreeShippingStore;
|
||||
use Modules\EcommerceFinance\View\PlatformPromotionAccountPageData;
|
||||
use Modules\EcommerceFinance\View\OrderDataPageData;
|
||||
use Modules\EcommerceFinance\View\SupplierNegativeAlertPageData;
|
||||
use Modules\EcommerceFinance\View\SupplierPayableForecastPageData;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
@ -5469,6 +5470,7 @@ class Pages extends Controller
|
||||
if ($page === 'supplier-negative-alert') {
|
||||
return $tab === 'payable-forecast'
|
||||
? ['view' => 'business.pages.negative-alerts.supplier-payable-forecast']
|
||||
+ app(SupplierPayableForecastPageData::class)->page(request())
|
||||
: app(SupplierNegativeAlertPageData::class)->page();
|
||||
}
|
||||
|
||||
|
||||
@ -159,6 +159,9 @@ return [
|
||||
'jiansun.dbo.fys_supplierGoods_sttlement_purchase' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '货款采购对账'],
|
||||
'jiansun.dbo.fys_supplierGoods_sttlement_sale' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '货款销售对账'],
|
||||
'jiansun.dbo.pm_purchaseIn' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '采购入库'],
|
||||
'jiansun.dbo.jst_purchaseReceiving' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '供应商货款预估/货款明细'],
|
||||
'jiansun.dbo.jst_purchaseReceivingItem' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '供应商货款预估/货款明细'],
|
||||
'jiansun.dbo.pm_priceAdjustment_log' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '供应商货款预估/变价后采购价'],
|
||||
'jiansun.dbo.js_supplier_View' => ['role' => 'dimension', 'target_store' => 'mariadb', 'consumer' => '供应商管理'],
|
||||
'jiansun.dbo.js_supplier_contract_View' => ['role' => 'operational', 'target_store' => 'mariadb', 'consumer' => '供应商管理/合同信息'],
|
||||
'jiansun.dbo.js_supplier_linkers' => ['role' => 'dimension', 'target_store' => 'mariadb', 'consumer' => '供应商管理/联系信息'],
|
||||
|
||||
@ -906,6 +906,54 @@ return [
|
||||
'jiansun.dbo.fys_supplierGoods_sttlement_purchase' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'fys_supplierGoods_sttlement_purchase', 'target' => 'js_supplier_goods_purchase', 'keys' => ['Id'], 'watermark' => 'createTime'],
|
||||
'jiansun.dbo.fys_supplierGoods_sttlement_sale' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'fys_supplierGoods_sttlement_sale', 'target' => 'js_supplier_goods_sale', 'keys' => ['Id'], 'watermark' => 'createTime'],
|
||||
'jiansun.dbo.pm_purchaseIn' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'pm_purchaseIn', 'target' => 'js_pm_purchase_in', 'keys' => ['id'], 'watermark' => 'updateTime'],
|
||||
// 供应商货款预估:聚水潭采购入库头表与明细,按入库日期从 2026-10-01 起接入。
|
||||
'jiansun.dbo.jst_purchaseReceiving' => [
|
||||
'source_key' => 'jiansun',
|
||||
'schema' => 'dbo',
|
||||
'object' => 'jst_purchaseReceiving',
|
||||
'target' => 'js_jst_purchase_receiving',
|
||||
'keys' => ['Id'],
|
||||
'watermark' => 'updateTime',
|
||||
'minimum_datetime' => ['column' => 'io_date', 'value' => '2026-10-01 00:00:00'],
|
||||
'full_reconcile_hours' => 168,
|
||||
'columns' => [
|
||||
'Id', 'io_id', 'po_id', 'io_date', 'remark', 'warehouse', 'type',
|
||||
'supplier_name', 'supplier_id', 'logistics_company', 'status',
|
||||
'wms_co_name', 'created', 'updateTime',
|
||||
],
|
||||
'indexes' => [
|
||||
['io_date', 'Id'],
|
||||
['po_id', 'Id'],
|
||||
['warehouse', 'io_date', 'Id'],
|
||||
['supplier_name', 'io_date', 'Id'],
|
||||
['updateTime', 'Id'],
|
||||
],
|
||||
],
|
||||
'jiansun.dbo.jst_purchaseReceivingItem' => [
|
||||
'source_key' => 'jiansun',
|
||||
'schema' => 'dbo',
|
||||
'object' => 'jst_purchaseReceivingItem',
|
||||
'target' => 'js_jst_purchase_receiving_item',
|
||||
'keys' => ['Id'],
|
||||
'watermark' => null,
|
||||
'parent_minimum_datetime' => [
|
||||
'column' => 'io_date',
|
||||
'value' => '2026-10-01 00:00:00',
|
||||
'parent_dataset' => 'jiansun.dbo.jst_purchaseReceiving',
|
||||
'child_key' => 'io_id',
|
||||
'parent_key' => 'io_id',
|
||||
],
|
||||
'full_reconcile_hours' => 168,
|
||||
'columns' => [
|
||||
'Id', 'io_id', 'ioi_id', 'sku_id', 'i_id', 'name', 'qty',
|
||||
'cost_price', 'cost_amount', 'remark', 'tax_rate', 'unit',
|
||||
],
|
||||
'indexes' => [
|
||||
['io_id', 'Id'],
|
||||
['sku_id', 'Id'],
|
||||
['i_id', 'Id'],
|
||||
],
|
||||
],
|
||||
// 工作平台采购价格:skuCode 对应 ops_jst_sku.sku_id。源表没有可靠更新时间,
|
||||
// 以 Id 稳定追加,页面按 effectTime 取当前已生效的最新价格。
|
||||
'jiansun.dbo.pm_priceAdjustment' => [
|
||||
|
||||
@ -112,6 +112,7 @@
|
||||
| 板材 | `dbo.finance_boardDeduction`、`dbo.pm_plainPlateData`、`dbo.pm_boardPurchasePrice`、`dbo.pm_boardPriceChangeImport`、`dbo.pm_boardApplyDetail` |
|
||||
| 封边条 | `dbo.pm_edgeBandData`、`dbo.pm_edgeBandApplyDetail`、`dbo.pm_edgeBandProfitInfo`、`dbo.finance_edgeBandDeductio`、`dbo.pm_averageUnitPrice` |
|
||||
| 库存与货款对账 | `dbo.pm_boardInventoryDetail_snapshot`、`dbo.fys_supplierGoods_sttlement_purchase`、`dbo.fys_supplierGoods_sttlement_sale`、`dbo.pm_purchaseIn` |
|
||||
| 供应商货款预估 | `dbo.jst_purchaseReceiving`(`io_date >= 2026-10-01`,`Id` 稳定键、`updateTime` 增量)与 `dbo.jst_purchaseReceivingItem`(按 `io_id` 关联父表,`Id` 稳定键,按父表日期下限断点同步);页面固定剔除仓库“配件单仓”、采购单号为空、供应商“虚拟/简尚送货”及商品编码 `DF-` 前缀。单价取 `dbo.pm_priceAdjustment_log` 同 SKU 最新 `priceType=1` 的 `afterPrice`,未匹配按 0 展示。 |
|
||||
| 采购单价 | `dbo.jst_purchase`、`dbo.jst_purchaseItem`(受控字段联表镜像,不复制其他采购业务字段) |
|
||||
| 工作平台采购价格 | `dbo.pm_priceAdjustment`(`Id` 稳定键;按 `skuCode` 匹配 `jst_sku.sku_id`,页面取当前已生效的最新 `purchasePrice` / `effectTime`) |
|
||||
| 快递资料 | `dbo.wp_express`、`dbo.wp_express_expNet`、`dbo.wp_express_account`、`dbo.wp_express_extension`。`wp_express.tradebody` 为合作合同乙方(合同主体),`signcom` 为甲方(签订公司),主资料列表与导出读取这两个原始镜像字段。协议签署选择快递后按确切名称带入唯一乙方主体,缺失或同名主体冲突时保留空值并提示核对,不以快递简称替代,也不改写已签归档合同。 |
|
||||
|
||||
@ -0,0 +1,274 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\EcommerceFinance\Repositories;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class SupplierPayableForecastRepository
|
||||
{
|
||||
public const HEAD_DATASET = 'jiansun.dbo.jst_purchaseReceiving';
|
||||
|
||||
public const ITEM_DATASET = 'jiansun.dbo.jst_purchaseReceivingItem';
|
||||
|
||||
public const PRICE_DATASET = 'jiansun.dbo.pm_priceAdjustment_log';
|
||||
|
||||
public const HEAD_TABLE = 'js_jst_purchase_receiving';
|
||||
|
||||
public const ITEM_TABLE = 'js_jst_purchase_receiving_item';
|
||||
|
||||
public const PRICE_TABLE = 'js_pm_price_adjustment_log';
|
||||
|
||||
public const DEFAULT_FROM = '2026-10-01';
|
||||
|
||||
private readonly ConnectionInterface $connection;
|
||||
|
||||
private readonly string $connectionName;
|
||||
|
||||
public function __construct(DatabaseManager $database)
|
||||
{
|
||||
$this->connectionName = (string) config('upstream_mirrors.connection', 'business_mirror');
|
||||
$this->connection = $database->connection($this->connectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{
|
||||
* ready:bool,
|
||||
* code:string,
|
||||
* initialized_at:?string,
|
||||
* last_succeeded_at:?string,
|
||||
* states:array<string,string>
|
||||
* }
|
||||
*/
|
||||
public function syncStatus(): array
|
||||
{
|
||||
$schema = Schema::connection($this->connectionName);
|
||||
foreach ([self::HEAD_TABLE, self::ITEM_TABLE, self::PRICE_TABLE, 'business_mirror_table_states'] as $table) {
|
||||
if (! $schema->hasTable($table)) {
|
||||
return [
|
||||
'ready' => false,
|
||||
'code' => 'unavailable',
|
||||
'initialized_at' => null,
|
||||
'last_succeeded_at' => null,
|
||||
'states' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$keys = [self::HEAD_DATASET, self::ITEM_DATASET, self::PRICE_DATASET];
|
||||
$rows = $this->connection->table('business_mirror_table_states')
|
||||
->whereIn('dataset_key', $keys)
|
||||
->get(['dataset_key', 'status', 'initial_completed_at', 'last_succeeded_at'])
|
||||
->keyBy('dataset_key');
|
||||
|
||||
$states = [];
|
||||
$ready = $rows->count() === count($keys);
|
||||
$initializedAt = null;
|
||||
$lastSucceededAt = null;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$row = $rows->get($key);
|
||||
$initialized = $row !== null && ($row->initial_completed_at ?? null) !== null;
|
||||
$ready = $ready && $initialized;
|
||||
$states[$key] = $initialized ? (string) ($row->status ?? 'ready') : (string) ($row->status ?? 'pending');
|
||||
if ($initialized) {
|
||||
$completedAt = (string) $row->initial_completed_at;
|
||||
if ($initializedAt === null || $completedAt > $initializedAt) {
|
||||
$initializedAt = $completedAt;
|
||||
}
|
||||
}
|
||||
if (($row->last_succeeded_at ?? null) !== null) {
|
||||
$succeededAt = (string) $row->last_succeeded_at;
|
||||
if ($lastSucceededAt === null || $succeededAt > $lastSucceededAt) {
|
||||
$lastSucceededAt = $succeededAt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'ready' => $ready,
|
||||
'code' => $ready ? 'ready' : ($rows->contains(static fn (object $row): bool => $row->status === 'running')
|
||||
? 'initializing'
|
||||
: 'pending'),
|
||||
'initialized_at' => $initializedAt,
|
||||
'last_succeeded_at' => $lastSucceededAt,
|
||||
'states' => $states,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{date_from:string,date_to:string,keyword:string} $filters
|
||||
* @return array{
|
||||
* total:int,
|
||||
* quantity:float,
|
||||
* supplier_count:int,
|
||||
* rows:list<array<string,mixed>>,
|
||||
* page:int,
|
||||
* per_page:int
|
||||
* }
|
||||
*/
|
||||
public function goodsDetails(array $filters, int $page, int $perPage = 20): array
|
||||
{
|
||||
$query = $this->filteredGoodsQuery($filters);
|
||||
$total = (clone $query)->count();
|
||||
$aggregate = (clone $query)
|
||||
->selectRaw('COALESCE(SUM(qty), 0) AS quantity, COUNT(DISTINCT supplier_name) AS supplier_count')
|
||||
->first();
|
||||
|
||||
$perPage = min(max($perPage, 1), 100);
|
||||
$page = max($page, 1);
|
||||
$sourceRows = (clone $query)
|
||||
->orderByDesc('h.io_date')
|
||||
->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',
|
||||
'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',
|
||||
]);
|
||||
|
||||
$priceMap = $this->latestChangePrices(
|
||||
$sourceRows->pluck('sku_id')->filter()->map(static fn (mixed $value): string => trim((string) $value))->unique()->values()->all()
|
||||
);
|
||||
|
||||
$rows = $sourceRows->map(
|
||||
fn (object $row): array => $this->formatGoodsRow($row, $priceMap->get($this->normalizeSku($row->sku_id)))
|
||||
)->values()->all();
|
||||
|
||||
return [
|
||||
'total' => $total,
|
||||
'quantity' => (float) ($aggregate->quantity ?? 0),
|
||||
'supplier_count' => (int) ($aggregate->supplier_count ?? 0),
|
||||
'rows' => $rows,
|
||||
'page' => $page,
|
||||
'per_page' => $perPage,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @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();
|
||||
$to = trim((string) ($filters['date_to'] ?? ''));
|
||||
$keyword = trim((string) ($filters['keyword'] ?? ''));
|
||||
|
||||
$query = $this->connection->table(self::HEAD_TABLE . ' as h')
|
||||
->join(self::ITEM_TABLE . ' as i', 'i.io_id', '=', 'h.io_id')
|
||||
->where('h.io_date', '>=', $from->format('Y-m-d H:i:s'))
|
||||
->whereRaw("TRIM(COALESCE(warehouse, '')) <> ?", ['配件单仓'])
|
||||
->whereRaw("NULLIF(TRIM(CAST(po_id AS CHAR)), '') IS NOT NULL")
|
||||
->whereRaw("TRIM(COALESCE(supplier_name, '')) NOT IN (?, ?)", ['虚拟', '简尚送货'])
|
||||
->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'));
|
||||
}
|
||||
|
||||
if ($keyword !== '') {
|
||||
$like = '%' . $keyword . '%';
|
||||
$query->where(static function ($nested) use ($like): void {
|
||||
foreach ([
|
||||
'h.io_id',
|
||||
'h.po_id',
|
||||
'h.supplier_name',
|
||||
'h.warehouse',
|
||||
'i.sku_id',
|
||||
'i.i_id',
|
||||
'i.name',
|
||||
] as $column) {
|
||||
$nested->orWhere($column, 'like', $like);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/** @param list<string> $skuIds */
|
||||
private function latestChangePrices(array $skuIds): Collection
|
||||
{
|
||||
if ($skuIds === []) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
return $this->connection->table(self::PRICE_TABLE)
|
||||
->whereIn('skucode', $skuIds)
|
||||
->whereRaw("TRIM(COALESCE(priceType, '')) = ?", ['1'])
|
||||
->whereNotNull('afterPrice')
|
||||
->orderByDesc('effectStartTime')
|
||||
->orderByDesc('Id')
|
||||
->get(['skucode', 'afterPrice', 'effectStartTime', 'Id'])
|
||||
->unique(fn (object $price): string => $this->normalizeSku($price->skucode))
|
||||
->keyBy(fn (object $price): string => $this->normalizeSku($price->skucode));
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
private function formatGoodsRow(object $row, ?object $price): array
|
||||
{
|
||||
$occurredAt = Carbon::parse((string) $row->io_date);
|
||||
$quantity = (float) ($row->qty ?? 0);
|
||||
$afterPrice = $price?->afterPrice;
|
||||
$unitPrice = $afterPrice === null ? 0.0 : (float) $afterPrice;
|
||||
$amount = round($quantity * $unitPrice, 2);
|
||||
$costPrice = $row->cost_price === null ? null : (float) $row->cost_price;
|
||||
$costAmount = $row->cost_amount === null
|
||||
? ($costPrice === null ? null : round($quantity * $costPrice, 2))
|
||||
: (float) $row->cost_amount;
|
||||
$remark = trim(implode(' ', array_filter([
|
||||
trim((string) ($row->head_remark ?? '')),
|
||||
trim((string) ($row->item_remark ?? '')),
|
||||
])));
|
||||
|
||||
return [
|
||||
'receivingId' => (int) $row->receiving_id,
|
||||
'itemId' => (int) $row->item_id,
|
||||
'month' => $occurredAt->format('Y-m'),
|
||||
'stockNo' => (string) ($row->io_id ?? ''),
|
||||
'purchaseNo' => (string) ($row->po_id ?? ''),
|
||||
'date' => $occurredAt->format('Y-m-d'),
|
||||
'supplier' => (string) ($row->supplier_name ?? ''),
|
||||
'skuCode' => (string) ($row->i_id ?? ''),
|
||||
'productCode' => (string) ($row->sku_id ?? ''),
|
||||
'skuName' => (string) ($row->name ?? ''),
|
||||
'qty' => $quantity,
|
||||
'unitPrice' => $unitPrice,
|
||||
'amount' => $amount,
|
||||
'guessUnitPrice' => $costPrice,
|
||||
'guessAmount' => $costAmount,
|
||||
'supplierGoodsCode' => '',
|
||||
'remark' => $remark,
|
||||
'warehouse' => (string) ($row->warehouse ?? ''),
|
||||
'expressName' => (string) ($row->logistics_company ?? ''),
|
||||
'expressNo' => '',
|
||||
'unsent' => '',
|
||||
'reconciler' => '',
|
||||
'priceMatched' => $afterPrice !== null,
|
||||
'priceEffectTime' => $price?->effectStartTime,
|
||||
'sourceStatus' => $row->status,
|
||||
];
|
||||
}
|
||||
|
||||
private function normalizeSku(mixed $value): string
|
||||
{
|
||||
return mb_strtolower(trim((string) $value), 'UTF-8');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\EcommerceFinance\View;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Modules\EcommerceFinance\Repositories\SupplierPayableForecastRepository;
|
||||
use Modules\EcommerceFinance\Services\PayablesFinalRegistry;
|
||||
|
||||
class SupplierPayableForecastPageData
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SupplierPayableForecastRepository $repository,
|
||||
private readonly PayablesFinalRegistry $registry,
|
||||
) {
|
||||
}
|
||||
|
||||
/** @return array<string,mixed> */
|
||||
public function page(Request $request): array
|
||||
{
|
||||
$activeView = in_array($request->query('forecast_view'), ['goods', 'returns', 'summary'], true)
|
||||
? (string) $request->query('forecast_view')
|
||||
: 'goods';
|
||||
$filters = $this->goodsFilters($request);
|
||||
$syncStatus = $this->repository->syncStatus();
|
||||
$result = [
|
||||
'total' => 0,
|
||||
'quantity' => 0.0,
|
||||
'supplier_count' => 0,
|
||||
'rows' => [],
|
||||
'page' => max((int) $request->query('goods_page', 1), 1),
|
||||
'per_page' => 20,
|
||||
];
|
||||
|
||||
if ($syncStatus['ready']) {
|
||||
$result = $this->repository->goodsDetails(
|
||||
$filters,
|
||||
max((int) $request->query('goods_page', 1), 1),
|
||||
20,
|
||||
);
|
||||
}
|
||||
|
||||
$paginationQuery = array_filter([
|
||||
'goods_date_from' => $filters['date_from'] === SupplierPayableForecastRepository::DEFAULT_FROM
|
||||
? null
|
||||
: $filters['date_from'],
|
||||
'goods_date_to' => $filters['date_to'] !== '' ? $filters['date_to'] : null,
|
||||
'goods_keyword' => $filters['keyword'] !== '' ? $filters['keyword'] : null,
|
||||
], static fn (mixed $value): bool => $value !== null && $value !== '');
|
||||
|
||||
$rows = new LengthAwarePaginator(
|
||||
$result['rows'],
|
||||
$result['total'],
|
||||
$result['per_page'],
|
||||
$result['page'],
|
||||
[
|
||||
'path' => $request->url(),
|
||||
'query' => $paginationQuery,
|
||||
],
|
||||
);
|
||||
|
||||
return [
|
||||
'activeForecastView' => $activeView,
|
||||
'goodsForecastFields' => $this->registry->fields(
|
||||
PayablesFinalRegistry::SECTION_SUPPLIER,
|
||||
'payment-reconciliation',
|
||||
),
|
||||
'goodsForecastFilters' => $filters,
|
||||
'goodsForecastRows' => $rows,
|
||||
'goodsForecastSummary' => [
|
||||
'quantity' => $result['quantity'],
|
||||
'supplier_count' => $result['supplier_count'],
|
||||
'matched_price_rows' => collect($result['rows'])->where('priceMatched', true)->count(),
|
||||
'missing_price_rows' => collect($result['rows'])->where('priceMatched', false)->count(),
|
||||
],
|
||||
'goodsForecastSyncStatus' => $syncStatus,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array{date_from:string,date_to:string,keyword:string} */
|
||||
private function goodsFilters(Request $request): array
|
||||
{
|
||||
$minimum = Carbon::createFromFormat('!Y-m-d', SupplierPayableForecastRepository::DEFAULT_FROM);
|
||||
$from = $this->validDate($request->query('goods_date_from'));
|
||||
if ($from === null || $from->lt($minimum)) {
|
||||
$from = $minimum;
|
||||
}
|
||||
|
||||
$to = $this->validDate($request->query('goods_date_to'));
|
||||
if ($to !== null && $to->lt($from)) {
|
||||
$to = $from->copy();
|
||||
}
|
||||
|
||||
return [
|
||||
'date_from' => $from->format('Y-m-d'),
|
||||
'date_to' => $to?->format('Y-m-d') ?? '',
|
||||
'keyword' => mb_substr(trim((string) $request->query('goods_keyword', '')), 0, 120),
|
||||
];
|
||||
}
|
||||
|
||||
private function validDate(mixed $value): ?Carbon
|
||||
{
|
||||
if (! is_string($value) || preg_match('/^\d{4}-\d{2}-\d{2}$/D', $value) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$date = Carbon::createFromFormat('!Y-m-d', $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;
|
||||
}
|
||||
}
|
||||
@ -212,12 +212,142 @@
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-data-overview {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 9px;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-data-metric {
|
||||
display: grid;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #EEE8DC;
|
||||
border-radius: 8px;
|
||||
background: #FCFBF8;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-data-metric span {
|
||||
color: var(--npf-muted);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-data-metric strong {
|
||||
overflow-wrap: anywhere;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-filter {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(140px, .8fr) minmax(140px, .8fr) minmax(240px, 1.8fr) auto;
|
||||
align-items: end;
|
||||
gap: 10px;
|
||||
padding: 12px;
|
||||
border: 1px solid #EEE8DC;
|
||||
border-radius: 9px;
|
||||
background: #FCFBF8;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-field { display: grid; gap: 4px; min-width: 0; }
|
||||
.supplier-payable-forecast .npf-field span { color: var(--npf-muted); font-size: 11px; font-weight: 600; }
|
||||
.supplier-payable-forecast .npf-field input {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
height: 34px;
|
||||
padding: 0 9px;
|
||||
border: 1px solid var(--npf-border);
|
||||
border-radius: 8px;
|
||||
background: #FFFFFF;
|
||||
color: var(--npf-ink);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-field input:focus {
|
||||
border-color: var(--npf-gold);
|
||||
outline: 0;
|
||||
box-shadow: 0 0 0 3px rgba(133, 102, 50, 0.20);
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-filter-actions { display: flex; flex-wrap: wrap; gap: 7px; }
|
||||
.supplier-payable-forecast .npf-button {
|
||||
display: inline-flex;
|
||||
min-height: 34px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 12px;
|
||||
border: 1px solid var(--npf-border);
|
||||
border-radius: 8px;
|
||||
background: #FFFFFF;
|
||||
color: var(--npf-ink);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.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.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-table-shell {
|
||||
max-width: 100%;
|
||||
overflow: auto;
|
||||
border: 1px solid var(--npf-border);
|
||||
border-radius: 9px;
|
||||
scrollbar-gutter: stable;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-table {
|
||||
width: max-content;
|
||||
min-width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: #FFFFFF;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-table th {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
padding: 9px 10px;
|
||||
border-bottom: 1px solid var(--npf-border);
|
||||
background: var(--npf-gold-soft);
|
||||
color: #5B5343;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-table td {
|
||||
padding: 9px 10px;
|
||||
border-bottom: 1px solid #F0EBE2;
|
||||
vertical-align: top;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.supplier-payable-forecast .npf-table tr:last-child td { border-bottom: 0; }
|
||||
.supplier-payable-forecast .npf-table tbody tr:hover td { background: #FCFAF5; }
|
||||
.supplier-payable-forecast .npf-table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
|
||||
.supplier-payable-forecast .npf-price-note { display: block; margin-top: 2px; color: var(--npf-warning); font-size: 10px; }
|
||||
.supplier-payable-forecast .npf-data-note { color: var(--npf-muted); font-size: 11px; line-height: 1.7; }
|
||||
.supplier-payable-forecast .npf-pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; color: var(--npf-muted); font-size: 11px; }
|
||||
.supplier-payable-forecast .npf-pagination-links { display: flex; gap: 7px; }
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.supplier-payable-forecast .npf-notice { margin-inline: 12px; }
|
||||
.supplier-payable-forecast .npf-tabs { padding-inline: 12px; }
|
||||
.supplier-payable-forecast .npf-panel { padding: 16px 14px; }
|
||||
.supplier-payable-forecast .npf-panel-head { display: grid; }
|
||||
.supplier-payable-forecast .npf-scope { grid-template-columns: minmax(0, 1fr); }
|
||||
.supplier-payable-forecast .npf-data-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
||||
.supplier-payable-forecast .npf-filter { grid-template-columns: minmax(0, 1fr); }
|
||||
.supplier-payable-forecast .npf-filter-actions { grid-column: 1; }
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
@ -232,10 +362,18 @@
|
||||
</span>
|
||||
<div class="npf-notice-copy">
|
||||
<p class="npf-notice-title">
|
||||
供应商货款预估口径待接入
|
||||
<span class="npf-badge">待接入</span>
|
||||
{{ $goodsForecastSyncStatus['ready'] ? '供应商货款明细已接入' : '供应商货款明细镜像初始化中' }}
|
||||
<span class="npf-badge">
|
||||
{{ $goodsForecastSyncStatus['ready'] ? '共享镜像' : ($goodsForecastSyncStatus['code'] === 'initializing' ? '同步中' : '待同步') }}
|
||||
</span>
|
||||
</p>
|
||||
<p class="npf-copy">
|
||||
@if ($goodsForecastSyncStatus['ready'])
|
||||
采购入库数据与工作平台变价后价格已接入共享镜像;退货明细和汇总仍待接入。
|
||||
@else
|
||||
采购入库与工作平台价格数据源已确定,共享镜像完成首次同步后自动展示明细。
|
||||
@endif
|
||||
</p>
|
||||
<p class="npf-copy">页面结构已建立,待确认预估月份、供应商范围、货款统计口径及数据来源后接入真实数据。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -295,20 +433,122 @@
|
||||
<span class="material-icons-outlined" aria-hidden="true">receipt_long</span>
|
||||
货款明细
|
||||
</h3>
|
||||
<p class="npf-panel-desc">按供应商查看当月入库与代发明细;接入后支持明细查询、分页和导出。</p>
|
||||
<p class="npf-panel-desc">采购入库数据从 2026-10-01 起展示,按供应商应付(终版)货款对账表头输出,并匹配工作平台最新变价后采购价。</p>
|
||||
</div>
|
||||
<span class="npf-badge">数据待接入</span>
|
||||
<span class="npf-badge">{{ $goodsForecastSyncStatus['ready'] ? '数据已接入' : '数据待同步' }}</span>
|
||||
</div>
|
||||
<div class="npf-scope" aria-label="货款明细范围">
|
||||
<div class="npf-scope-item"><span>业务范围</span><strong>当月入库 / 当月代发</strong></div>
|
||||
<div class="npf-scope-item"><span>核对字段</span><strong>单号、商品、数量、单价、金额</strong></div>
|
||||
<div class="npf-scope-item"><span>页面状态</span><strong>待接入</strong></div>
|
||||
</div>
|
||||
<div class="npf-empty">
|
||||
<span class="material-icons-outlined" aria-hidden="true">inventory_2</span>
|
||||
<strong>货款明细待接入</strong>
|
||||
<span>接入后将在这里展示入库厂家的采购单号、代发厂家的快递单号,以及未定价商品的明细。</span>
|
||||
|
||||
<div class="npf-data-overview" aria-label="当前筛选汇总">
|
||||
<div class="npf-data-metric">
|
||||
<span>筛选结果</span>
|
||||
<strong>{{ number_format($goodsForecastRows->total()) }} 行</strong>
|
||||
</div>
|
||||
<div class="npf-data-metric">
|
||||
<span>数量合计</span>
|
||||
<strong>{{ number_format($goodsForecastSummary['quantity'], 2) }}</strong>
|
||||
</div>
|
||||
<div class="npf-data-metric">
|
||||
<span>供应商数</span>
|
||||
<strong>{{ number_format($goodsForecastSummary['supplier_count']) }}</strong>
|
||||
</div>
|
||||
<div class="npf-data-metric">
|
||||
<span>本页匹配变价</span>
|
||||
<strong>{{ number_format($goodsForecastSummary['matched_price_rows']) }} / {{ $goodsForecastRows->count() }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form method="GET" action="{{ request()->url() }}" class="npf-filter" aria-label="查询货款明细">
|
||||
<input type="hidden" name="forecast_view" value="goods">
|
||||
<label class="npf-field">
|
||||
<span>入库日期起</span>
|
||||
<input type="date" name="goods_date_from" min="{{ \Modules\EcommerceFinance\Repositories\SupplierPayableForecastRepository::DEFAULT_FROM }}" value="{{ $goodsForecastFilters['date_from'] }}">
|
||||
</label>
|
||||
<label class="npf-field">
|
||||
<span>入库日期止</span>
|
||||
<input type="date" name="goods_date_to" min="{{ $goodsForecastFilters['date_from'] }}" value="{{ $goodsForecastFilters['date_to'] }}">
|
||||
</label>
|
||||
<label class="npf-field">
|
||||
<span>关键字</span>
|
||||
<input type="search" name="goods_keyword" maxlength="120" value="{{ $goodsForecastFilters['keyword'] }}" placeholder="入库单号 / 采购单号 / 供应商 / 商品编码">
|
||||
</label>
|
||||
<div class="npf-filter-actions">
|
||||
<button type="submit" class="npf-button is-primary">查询</button>
|
||||
<a class="npf-button" href="{{ request()->url() }}">重置</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@if (! $goodsForecastSyncStatus['ready'])
|
||||
<div class="npf-empty" role="status">
|
||||
<span class="material-icons-outlined" aria-hidden="true">sync</span>
|
||||
<strong>采购入库共享镜像尚未就绪</strong>
|
||||
<span>首次同步完成前不会展示第一页或局部数据,避免把不完整结果误认为全量。</span>
|
||||
</div>
|
||||
@elseif ($goodsForecastRows->isEmpty())
|
||||
<div class="npf-empty">
|
||||
<span class="material-icons-outlined" aria-hidden="true">inventory_2</span>
|
||||
<strong>没有符合当前条件的货款明细</strong>
|
||||
<span>可调整入库日期或关键字后重新查询。</span>
|
||||
</div>
|
||||
@else
|
||||
<div class="npf-table-shell">
|
||||
<table class="npf-table" aria-label="供应商货款明细">
|
||||
<thead>
|
||||
<tr>
|
||||
@foreach ($goodsForecastFields as $field)
|
||||
<th scope="col" @class(['is-num' => $field['type'] === 'number'])>{{ $field['label'] }}</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($goodsForecastRows as $row)
|
||||
<tr>
|
||||
@foreach ($goodsForecastFields as $key => $field)
|
||||
@php($value = $row[$key] ?? null)
|
||||
<td @class(['is-num' => $field['type'] === 'number'])>
|
||||
@if ($field['type'] === 'number')
|
||||
@if ($key === 'qty')
|
||||
{{ number_format((float) $value, 2) }}
|
||||
@else
|
||||
{{ number_format((float) ($value ?? 0), 2) }}
|
||||
@endif
|
||||
@if ($key === 'unitPrice' && ! ($row['priceMatched'] ?? false))
|
||||
<span class="npf-price-note">未匹配变价,按 0 计</span>
|
||||
@endif
|
||||
@else
|
||||
{{ $value !== null && $value !== '' ? $value : '—' }}
|
||||
@endif
|
||||
</td>
|
||||
@endforeach
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="npf-pagination">
|
||||
<span>
|
||||
第 {{ $goodsForecastRows->currentPage() }} / {{ $goodsForecastRows->lastPage() }} 页,
|
||||
每页 {{ $goodsForecastRows->perPage() }} 行;最近同步
|
||||
{{ $goodsForecastSyncStatus['last_succeeded_at'] ?? '—' }}
|
||||
</span>
|
||||
@if ($goodsForecastRows->lastPage() > 1)
|
||||
<div class="npf-pagination-links">
|
||||
@if ($goodsForecastRows->previousPageUrl())
|
||||
<a class="npf-button" href="{{ $goodsForecastRows->previousPageUrl() }}">上一页</a>
|
||||
@endif
|
||||
@if ($goodsForecastRows->nextPageUrl())
|
||||
<a class="npf-button" href="{{ $goodsForecastRows->nextPageUrl() }}">下一页</a>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="npf-data-note">
|
||||
固定剔除:仓库“配件单仓”、采购单号为空、供应商“虚拟/简尚送货”、商品编码以“DF-”开头。
|
||||
单价取工作平台 <code>pm_priceAdjustment_log</code> 中该商品最新一条 <code>priceType=1</code> 的变价后价格;
|
||||
预估单价和预估金额取聚水潭采购入库明细的成本价与成本金额。
|
||||
</div>
|
||||
@endif
|
||||
</section>
|
||||
|
||||
<section
|
||||
|
||||
@ -6,6 +6,10 @@ use App\Http\Controllers\Business\PayablesFinalActions;
|
||||
use App\Listeners\Menu\ShowInAdmin;
|
||||
use App\Models\Auth\Permission;
|
||||
use App\Utilities\BusinessNavigation;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Modules\EcommerceFinance\Repositories\SupplierPayableForecastRepository;
|
||||
use Modules\EcommerceFinance\Repositories\SupplierManagementMirrorRepository;
|
||||
use Modules\EcommerceFinance\Repositories\SupplierPayableReportRepository;
|
||||
use Modules\EcommerceFinance\Services\PayablesFinalRegistry;
|
||||
@ -241,7 +245,8 @@ class NegativeAlertPagesTest extends FeatureTestCase
|
||||
->assertOk()
|
||||
->assertSeeText('供应商负数预警')
|
||||
->assertSeeText('供应商货款预估')
|
||||
->assertSeeText('供应商货款预估口径待接入')
|
||||
->assertSeeText('供应商货款明细镜像初始化中')
|
||||
->assertSeeText('采购入库共享镜像尚未就绪')
|
||||
->assertSeeText('供应商货款预估数据待接入')
|
||||
->assertSeeText('货款明细')
|
||||
->assertSeeText('退货明细')
|
||||
@ -275,7 +280,7 @@ class NegativeAlertPagesTest extends FeatureTestCase
|
||||
'forecast_view' => 'returns',
|
||||
]))
|
||||
->assertOk()
|
||||
->assertSeeText('入库与代发明细')
|
||||
->assertSeeText('采购入库数据')
|
||||
->assertSeeText('关联维度')
|
||||
->assertSeeText('余额口径');
|
||||
|
||||
@ -364,6 +369,113 @@ class NegativeAlertPagesTest extends FeatureTestCase
|
||||
->assertRedirect();
|
||||
}
|
||||
|
||||
public function test_goods_details_render_payment_reconciliation_headers_from_shared_mirror(): 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],
|
||||
]);
|
||||
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::HEAD_TABLE)->insert([
|
||||
'Id' => 1,
|
||||
'io_id' => 'IN-20261001',
|
||||
'po_id' => 20261001,
|
||||
'io_date' => '2026-10-01 10:00:00',
|
||||
'warehouse' => '简尚-崔桥工厂仓进货仓',
|
||||
'supplier_name' => '测试供应商',
|
||||
]);
|
||||
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::ITEM_TABLE)->insert([
|
||||
'Id' => 1,
|
||||
'io_id' => 'IN-20261001',
|
||||
'ioi_id' => 'ITEM-1',
|
||||
'sku_id' => 'SKU-20261001',
|
||||
'i_id' => 'STYLE-20261001',
|
||||
'name' => '测试商品',
|
||||
'qty' => 2,
|
||||
'cost_price' => 10,
|
||||
'cost_amount' => 20,
|
||||
]);
|
||||
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRICE_TABLE)->insert([
|
||||
'Id' => 1,
|
||||
'skucode' => 'SKU-20261001',
|
||||
'priceType' => '1',
|
||||
'afterPrice' => 12,
|
||||
'effectStartTime' => '2026-10-01 08:00:00',
|
||||
]);
|
||||
|
||||
$response = $this->loginAs()->get(route('business.pages.show', [
|
||||
'section' => 'negative-alerts',
|
||||
'page' => 'supplier-negative-alert',
|
||||
'tab' => 'payable-forecast',
|
||||
]))->assertOk()
|
||||
->assertSeeText('供应商货款明细已接入')
|
||||
->assertSeeText('IN-20261001')
|
||||
->assertSeeText('20261001')
|
||||
->assertSeeText('STYLE-20261001')
|
||||
->assertSeeText('SKU-20261001')
|
||||
->assertSeeText('24.00');
|
||||
|
||||
$html = (string) $response->getContent();
|
||||
$tableStart = strpos($html, '<table class="npf-table"');
|
||||
$tableEnd = $tableStart === false ? false : strpos($html, '</table>', $tableStart);
|
||||
$this->assertNotFalse($tableStart);
|
||||
$this->assertNotFalse($tableEnd);
|
||||
preg_match_all('/<th[^>]*>(.*?)<\/th>/s', substr($html, $tableStart, $tableEnd - $tableStart), $headers);
|
||||
$labels = array_map(
|
||||
static fn (string $label): string => trim(html_entity_decode(strip_tags($label), ENT_QUOTES | ENT_HTML5, 'UTF-8')),
|
||||
$headers[1],
|
||||
);
|
||||
$this->assertSame([
|
||||
'月份', '入库单号', '采购单号', '日期', '供应商', '货号', '商品编码', '规格名称',
|
||||
'数量', '单价', '金额', '预估单价', '预估金额', '供应商商品编码', '备注',
|
||||
'仓库名称', '快递名称', '快递单号', '未发出', '对账人',
|
||||
], $labels);
|
||||
}
|
||||
|
||||
private function createSupplierPayableForecastTables(): void
|
||||
{
|
||||
$schema = Schema::connection('business_mirror');
|
||||
$schema->create('business_mirror_table_states', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('dataset_key')->unique();
|
||||
$table->string('status', 32);
|
||||
$table->dateTime('initial_completed_at')->nullable();
|
||||
$table->dateTime('last_succeeded_at')->nullable();
|
||||
});
|
||||
$schema->create(SupplierPayableForecastRepository::HEAD_TABLE, function (Blueprint $table): void {
|
||||
$table->bigIncrements('Id');
|
||||
$table->string('io_id', 100);
|
||||
$table->unsignedBigInteger('po_id')->nullable();
|
||||
$table->dateTime('io_date');
|
||||
$table->text('remark')->nullable();
|
||||
$table->string('warehouse', 255)->nullable();
|
||||
$table->string('logistics_company', 255)->nullable();
|
||||
$table->string('status', 50)->nullable();
|
||||
$table->string('supplier_name', 255)->nullable();
|
||||
});
|
||||
$schema->create(SupplierPayableForecastRepository::ITEM_TABLE, function (Blueprint $table): void {
|
||||
$table->bigIncrements('Id');
|
||||
$table->string('io_id', 100);
|
||||
$table->string('ioi_id', 100)->nullable();
|
||||
$table->string('sku_id', 100)->nullable();
|
||||
$table->string('i_id', 100)->nullable();
|
||||
$table->string('name', 255)->nullable();
|
||||
$table->integer('qty')->nullable();
|
||||
$table->decimal('cost_price', 18, 2)->nullable();
|
||||
$table->decimal('cost_amount', 18, 2)->nullable();
|
||||
$table->text('remark')->nullable();
|
||||
});
|
||||
$schema->create(SupplierPayableForecastRepository::PRICE_TABLE, function (Blueprint $table): void {
|
||||
$table->bigIncrements('Id');
|
||||
$table->string('skucode', 100)->nullable();
|
||||
$table->string('priceType', 20)->nullable();
|
||||
$table->decimal('afterPrice', 18, 2)->nullable();
|
||||
$table->dateTime('effectStartTime')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
private function saveSupplierPayable(
|
||||
string $key,
|
||||
string $supplier,
|
||||
|
||||
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\EcommerceFinance;
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Modules\EcommerceFinance\Repositories\SupplierPayableForecastRepository;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SupplierPayableForecastRepositoryTest extends TestCase
|
||||
{
|
||||
public function test_goods_details_apply_fixed_exclusions_and_latest_change_price(): void
|
||||
{
|
||||
$this->createTables();
|
||||
$this->seedRows();
|
||||
|
||||
$result = app(SupplierPayableForecastRepository::class)->goodsDetails([
|
||||
'date_from' => '2026-10-01',
|
||||
'date_to' => '',
|
||||
'keyword' => '',
|
||||
], 1);
|
||||
|
||||
$this->assertSame(2, $result['total']);
|
||||
$this->assertSame(3.0, $result['quantity']);
|
||||
$this->assertSame(2, $result['supplier_count']);
|
||||
$this->assertSame(['SKU-B', 'SKU-A'], array_column($result['rows'], 'productCode'));
|
||||
|
||||
$priced = collect($result['rows'])->firstWhere('productCode', 'SKU-A');
|
||||
$this->assertSame('STYLE-A', $priced['skuCode']);
|
||||
$this->assertSame(2.0, $priced['qty']);
|
||||
$this->assertSame(12.0, $priced['unitPrice']);
|
||||
$this->assertSame(24.0, $priced['amount']);
|
||||
$this->assertSame(10.0, $priced['guessUnitPrice']);
|
||||
$this->assertSame(20.0, $priced['guessAmount']);
|
||||
$this->assertTrue($priced['priceMatched']);
|
||||
|
||||
$unpriced = collect($result['rows'])->firstWhere('productCode', 'SKU-B');
|
||||
$this->assertSame(0.0, $unpriced['unitPrice']);
|
||||
$this->assertSame(0.0, $unpriced['amount']);
|
||||
$this->assertSame(6.0, $unpriced['guessAmount']);
|
||||
$this->assertFalse($unpriced['priceMatched']);
|
||||
|
||||
$keyword = app(SupplierPayableForecastRepository::class)->goodsDetails([
|
||||
'date_from' => '2026-10-01',
|
||||
'date_to' => '',
|
||||
'keyword' => 'SKU-A',
|
||||
], 1);
|
||||
$this->assertSame(1, $keyword['total']);
|
||||
$this->assertSame('SKU-A', $keyword['rows'][0]['productCode']);
|
||||
}
|
||||
|
||||
private function createTables(): void
|
||||
{
|
||||
$schema = Schema::connection('business_mirror');
|
||||
$schema->create('business_mirror_table_states', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('dataset_key')->unique();
|
||||
$table->string('status', 32);
|
||||
$table->dateTime('initial_completed_at')->nullable();
|
||||
$table->dateTime('last_succeeded_at')->nullable();
|
||||
});
|
||||
$schema->create(SupplierPayableForecastRepository::HEAD_TABLE, function (Blueprint $table): void {
|
||||
$table->bigIncrements('Id');
|
||||
$table->string('io_id', 100);
|
||||
$table->unsignedBigInteger('po_id')->nullable();
|
||||
$table->dateTime('io_date');
|
||||
$table->text('remark')->nullable();
|
||||
$table->string('warehouse', 255)->nullable();
|
||||
$table->string('logistics_company', 255)->nullable();
|
||||
$table->string('status', 50)->nullable();
|
||||
$table->string('supplier_name', 255)->nullable();
|
||||
$table->dateTime('created')->nullable();
|
||||
$table->dateTime('updateTime')->nullable();
|
||||
});
|
||||
$schema->create(SupplierPayableForecastRepository::ITEM_TABLE, function (Blueprint $table): void {
|
||||
$table->bigIncrements('Id');
|
||||
$table->string('io_id', 100);
|
||||
$table->string('ioi_id', 100)->nullable();
|
||||
$table->string('sku_id', 100)->nullable();
|
||||
$table->string('i_id', 100)->nullable();
|
||||
$table->string('name', 255)->nullable();
|
||||
$table->integer('qty')->nullable();
|
||||
$table->decimal('cost_price', 18, 2)->nullable();
|
||||
$table->decimal('cost_amount', 18, 2)->nullable();
|
||||
$table->text('remark')->nullable();
|
||||
$table->decimal('tax_rate', 8, 2)->nullable();
|
||||
$table->string('unit', 50)->nullable();
|
||||
});
|
||||
$schema->create(SupplierPayableForecastRepository::PRICE_TABLE, function (Blueprint $table): void {
|
||||
$table->bigIncrements('Id');
|
||||
$table->string('skucode', 100)->nullable();
|
||||
$table->string('priceType', 20)->nullable();
|
||||
$table->decimal('afterPrice', 18, 2)->nullable();
|
||||
$table->dateTime('effectStartTime')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
private function seedRows(): void
|
||||
{
|
||||
$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],
|
||||
]);
|
||||
|
||||
$heads = [
|
||||
[1, 'IN-1', 101, '2026-10-02 09:00:00', '正常仓', '供应商甲'],
|
||||
[2, 'IN-2', 102, '2026-10-03 09:00:00', '正常仓', '供应商乙'],
|
||||
[3, 'IN-OLD', 103, '2026-09-30 09:00:00', '正常仓', '供应商甲'],
|
||||
[4, 'IN-ACCESSORY', 104, '2026-10-04 09:00:00', '配件单仓', '供应商甲'],
|
||||
[5, 'IN-BLANK-PO', null, '2026-10-05 09:00:00', '正常仓', '供应商甲'],
|
||||
[6, 'IN-VIRTUAL', 106, '2026-10-06 09:00:00', '正常仓', '虚拟'],
|
||||
[7, 'IN-DELIVERY', 107, '2026-10-07 09:00:00', '正常仓', '简尚送货'],
|
||||
[8, 'IN-DF', 108, '2026-10-08 09:00:00', '正常仓', '供应商甲'],
|
||||
];
|
||||
foreach ($heads as [$id, $ioId, $poId, $date, $warehouse, $supplier]) {
|
||||
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::HEAD_TABLE)->insert([
|
||||
'Id' => $id,
|
||||
'io_id' => $ioId,
|
||||
'po_id' => $poId,
|
||||
'io_date' => $date,
|
||||
'warehouse' => $warehouse,
|
||||
'supplier_name' => $supplier,
|
||||
]);
|
||||
}
|
||||
|
||||
$items = [
|
||||
[1, 'IN-1', 'SKU-A', 'STYLE-A', 2, 10],
|
||||
[2, 'IN-2', 'SKU-B', 'STYLE-B', 1, 6],
|
||||
[3, 'IN-OLD', 'SKU-A', 'STYLE-A', 9, 10],
|
||||
[4, 'IN-ACCESSORY', 'SKU-C', 'STYLE-C', 1, 10],
|
||||
[5, 'IN-BLANK-PO', 'SKU-D', 'STYLE-D', 1, 10],
|
||||
[6, 'IN-VIRTUAL', 'SKU-E', 'STYLE-E', 1, 10],
|
||||
[7, 'IN-DELIVERY', 'SKU-F', 'STYLE-F', 1, 10],
|
||||
[8, 'IN-DF', 'DF-SKU', 'DF-STYLE', 1, 10],
|
||||
];
|
||||
foreach ($items as [$id, $ioId, $skuId, $styleId, $qty, $costPrice]) {
|
||||
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::ITEM_TABLE)->insert([
|
||||
'Id' => $id,
|
||||
'io_id' => $ioId,
|
||||
'ioi_id' => 'ITEM-' . $id,
|
||||
'sku_id' => $skuId,
|
||||
'i_id' => $styleId,
|
||||
'name' => $styleId . ' 商品',
|
||||
'qty' => $qty,
|
||||
'cost_price' => $costPrice,
|
||||
'cost_amount' => $qty * $costPrice,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRICE_TABLE)->insert([
|
||||
['Id' => 1, 'skucode' => 'SKU-A', 'priceType' => '1', 'afterPrice' => 8, 'effectStartTime' => '2026-09-01 00:00:00'],
|
||||
['Id' => 2, 'skucode' => 'SKU-A', 'priceType' => '1', 'afterPrice' => 12, 'effectStartTime' => '2026-10-10 00:00:00'],
|
||||
['Id' => 3, 'skucode' => 'SKU-A', 'priceType' => '0', 'afterPrice' => 99, 'effectStartTime' => '2026-10-12 00:00:00'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user