From bf8778bfcd3ce8a45d7b353b295d1c43d4565614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E6=9C=A8?= <594326199@qq.com> Date: Mon, 30 Nov 2026 13:56:12 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BE=9B=E5=BA=94=E5=95=86=E8=B4=A7?= =?UTF-8?q?=E6=AC=BE=E9=A2=84=E4=BC=B0):=20=E6=8E=A5=E5=85=A5=E6=9C=AC?= =?UTF-8?q?=E6=9C=88=E6=B1=87=E6=80=BB=E8=A1=A8=20(#1559)=20Co-authored-by?= =?UTF-8?q?:=20=E8=8B=8F=E6=9C=A8=20<594326199@qq.com>=20Co-committed-by:?= =?UTF-8?q?=20=E8=8B=8F=E6=9C=A8=20<594326199@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SupplierPayableForecastRepository.php | 91 +++++ ...pplierPayableForecastSummaryRepository.php | 354 ++++++++++++++++++ .../View/SupplierPayableForecastPageData.php | 44 +++ .../supplier-payable-forecast.blade.php | 169 ++++++++- .../Business/NegativeAlertPagesTest.php | 218 ++++++++++- ...erPayableForecastSummaryRepositoryTest.php | 285 ++++++++++++++ 6 files changed, 1149 insertions(+), 12 deletions(-) create mode 100644 modules/EcommerceFinance/Repositories/SupplierPayableForecastSummaryRepository.php create mode 100644 tests/Unit/EcommerceFinance/SupplierPayableForecastSummaryRepositoryTest.php diff --git a/modules/EcommerceFinance/Repositories/SupplierPayableForecastRepository.php b/modules/EcommerceFinance/Repositories/SupplierPayableForecastRepository.php index 17fb73bb..73b8af09 100644 --- a/modules/EcommerceFinance/Repositories/SupplierPayableForecastRepository.php +++ b/modules/EcommerceFinance/Repositories/SupplierPayableForecastRepository.php @@ -254,6 +254,50 @@ class SupplierPayableForecastRepository ]; } + /** + * 汇总页按供应商复用货款明细的取价规则,只返回明细中实际匹配到价格的货款金额。 + * + * @param array{date_from:string,date_to:string,keyword:string} $filters + * @return array + */ + public function goodsAmountsBySupplier(array $filters): array + { + $groups = $this->goodsSummarySourceRows($filters) + ->select('supplier_name') + ->selectRaw('TRIM(product_code) AS product_code') + ->selectRaw('COALESCE(SUM(qty), 0) AS quantity') + ->groupBy('supplier_name', DB::raw('TRIM(product_code)')) + ->get(); + if ($groups->isEmpty()) { + return []; + } + + $priceMap = $this->latestEffectivePrices( + $groups->pluck('product_code') + ->map(static fn (mixed $value): string => trim((string) $value)) + ->filter() + ->unique() + ->values() + ->all(), + ); + $amounts = []; + foreach ($groups as $group) { + $supplier = trim((string) ($group->supplier_name ?? '')); + if ($supplier === '') { + continue; + } + $price = $priceMap->get($this->normalizeSku($group->product_code)); + $amount = $price === null + ? 0.0 + : round((float) $group->quantity * (float) $price->price, 2); + $amounts[$supplier] = round(($amounts[$supplier] ?? 0.0) + $amount, 2); + } + + ksort($amounts, SORT_NATURAL | SORT_FLAG_CASE); + + return $amounts; + } + /** @param array{date_from:string,date_to:string,keyword:string} $filters */ private function goodsSummary(array $filters): object { @@ -453,6 +497,53 @@ class SupplierPayableForecastRepository ]; } + /** + * 汇总页按商品资料中的供应商归集退货明细金额,金额规则与退货明细完全一致。 + * + * @param array{date_from:string,date_to:string,keyword:string} $filters + * @return array + */ + public function returnAmountsBySupplier(array $filters): array + { + $groups = $this->filteredReturnQuery($filters) + ->select('i.sku_id AS product_code') + ->selectRaw('COALESCE(SUM(qty), 0) AS quantity') + ->groupBy('i.sku_id') + ->get(); + if ($groups->isEmpty()) { + return []; + } + + $productCodes = $groups->pluck('product_code') + ->map(static fn (mixed $value): string => trim((string) $value)) + ->filter() + ->unique() + ->values() + ->all(); + $priceMap = $this->latestEffectivePrices($productCodes); + $productMap = $this->latestCatalogProducts($productCodes); + $amounts = []; + foreach ($groups as $group) { + $productCode = trim((string) ($group->product_code ?? '')); + $price = $priceMap->get($this->normalizeSku($productCode)); + $amount = $price === null + ? 0.0 + : round((float) $group->quantity * (float) $price->price, 2); + if ($amount === 0.0) { + continue; + } + $supplier = trim((string) ($productMap->get($this->normalizeSku($productCode))?->supplier_name ?? '')); + if ($supplier === '') { + $supplier = '未匹配供应商'; + } + $amounts[$supplier] = round(($amounts[$supplier] ?? 0.0) + $amount, 2); + } + + ksort($amounts, SORT_NATURAL | SORT_FLAG_CASE); + + return $amounts; + } + /** * 流式读取当前退货筛选全集,价格与预估规则和货款明细一致。 * diff --git a/modules/EcommerceFinance/Repositories/SupplierPayableForecastSummaryRepository.php b/modules/EcommerceFinance/Repositories/SupplierPayableForecastSummaryRepository.php new file mode 100644 index 00000000..cc661f65 --- /dev/null +++ b/modules/EcommerceFinance/Repositories/SupplierPayableForecastSummaryRepository.php @@ -0,0 +1,354 @@ +connectionName = (string) config('upstream_mirrors.connection', 'business_mirror'); + $this->connection = $database->connection($this->connectionName); + } + + /** + * @param array{month?:string,keyword?:string} $filters + * @return array{ + * ready:bool, + * sync_status:array, + * months:list, + * filters:array{month:string,keyword:string}, + * total:int, + * rows:list>, + * page:int, + * per_page:int, + * totals:array{subtotal:float,supplier_balance:float,goods_amount:float,return_amount:float} + * } + */ + public function paginate(array $filters, int $page, int $perPage = 20): array + { + $syncStatus = $this->syncStatus(); + $months = $this->availableMonths(); + $month = $this->resolveMonth((string) ($filters['month'] ?? ''), $months); + $keyword = mb_substr(trim((string) ($filters['keyword'] ?? '')), 0, 120); + $perPage = min(max($perPage, 1), 100); + $page = max($page, 1); + + $result = [ + 'ready' => $syncStatus['ready'], + 'sync_status' => $syncStatus, + 'months' => $months, + 'filters' => ['month' => $month, 'keyword' => $keyword], + 'total' => 0, + 'rows' => [], + 'page' => 1, + 'per_page' => $perPage, + 'totals' => [ + 'subtotal' => 0.0, + 'supplier_balance' => 0.0, + 'goods_amount' => 0.0, + 'return_amount' => 0.0, + ], + ]; + + if (! $syncStatus['ready'] || $month === '') { + return $result; + } + + [$dateFrom, $dateTo] = $this->monthWindow($month); + if ($dateTo === null || Carbon::parse($dateTo)->lt(Carbon::parse($dateFrom))) { + return $result; + } + + $goodsStatus = $this->details->syncStatus(); + $returnStatus = $this->details->returnSyncStatus(); + $goodsAmounts = $goodsStatus['ready'] + ? $this->details->goodsAmountsBySupplier([ + 'date_from' => $dateFrom, + 'date_to' => $dateTo, + 'keyword' => '', + ]) + : []; + $returnAmounts = $returnStatus['ready'] + ? $this->details->returnAmountsBySupplier([ + 'date_from' => $dateFrom, + 'date_to' => $dateTo, + 'keyword' => '', + ]) + : []; + $suppliers = array_values(array_unique(array_merge( + array_keys($goodsAmounts), + array_keys($returnAmounts), + ))); + if ($suppliers === []) { + return $result; + } + + $currentMetadata = $this->metadataForMonth($month); + $companyMap = $this->latestCompanyMap($suppliers); + $rows = []; + foreach ($suppliers as $supplier) { + $metadata = $currentMetadata[$supplier] ?? []; + $company = trim((string) ($metadata['company'] ?? '')); + if ($company === '') { + $company = $companyMap[$supplier] ?? ''; + } + if ($keyword !== '' + && mb_stripos($supplier, $keyword, 0, 'UTF-8') === false + && mb_stripos($company, $keyword, 0, 'UTF-8') === false) { + continue; + } + + $goodsAmount = $this->money($goodsAmounts[$supplier] ?? 0); + $returnAmount = $this->money($returnAmounts[$supplier] ?? 0); + $subtotal = $this->money($goodsAmount - $returnAmount); + $expressFreight = $this->money($metadata['express_freight'] ?? 0); + $advanceLoan = $this->money($metadata['advance_loan'] ?? 0); + $invoiceDeduction = $this->money($metadata['invoice_deduction'] ?? 0); + $boardDeduction = $this->money($metadata['board_deduction'] ?? 0); + $estimatedBoardDeduction = 0.0; + $sampleDeduction = $this->money($metadata['sample_deduction'] ?? 0); + $unpricedAdjustment = $this->money($metadata['unpriced_adjustment'] ?? 0); + + $rows[] = [ + 'month' => $month, + 'company' => $company, + 'supplier' => $supplier, + 'express_freight' => $expressFreight, + 'goods_amount' => $goodsAmount, + 'return_amount' => $returnAmount, + 'advance_loan' => $advanceLoan, + 'subtotal' => $subtotal, + 'invoice_deduction' => $invoiceDeduction, + 'board_deduction' => $boardDeduction, + 'estimated_board_deduction' => $estimatedBoardDeduction, + 'sample_deduction' => $sampleDeduction, + 'estimated_amount' => null, + 'unpriced_adjustment' => $unpricedAdjustment, + 'supplier_balance' => $this->money( + $expressFreight + - $advanceLoan + + $subtotal + - $invoiceDeduction + - $boardDeduction + - $estimatedBoardDeduction + - $sampleDeduction + + $unpricedAdjustment, + ), + ]; + } + + usort($rows, static function (array $left, array $right): int { + return [$left['company'], $left['supplier']] <=> [$right['company'], $right['supplier']]; + }); + + $total = count($rows); + $lastPage = max((int) ceil($total / $perPage), 1); + $page = min($page, $lastPage); + $totals = [ + 'subtotal' => $this->money(array_sum(array_column($rows, 'subtotal'))), + 'supplier_balance' => $this->money(array_sum(array_column($rows, 'supplier_balance'))), + 'goods_amount' => $this->money(array_sum(array_column($rows, 'goods_amount'))), + 'return_amount' => $this->money(array_sum(array_column($rows, 'return_amount'))), + ]; + + return array_replace($result, [ + 'total' => $total, + 'rows' => array_slice($rows, ($page - 1) * $perPage, $perPage), + 'page' => $page, + 'totals' => $totals, + ]); + } + + /** + * @return array{ + * ready:bool, + * code:string, + * status:string, + * last_succeeded_at:?string + * } + */ + public function syncStatus(): array + { + $goods = $this->details->syncStatus(); + $returns = $this->details->returnSyncStatus(); + $ready = $goods['ready'] || $returns['ready']; + $initializing = $goods['code'] === 'initializing' || $returns['code'] === 'initializing'; + $succeededAt = array_filter([ + $goods['last_succeeded_at'] ?? null, + $returns['last_succeeded_at'] ?? null, + ], static fn (mixed $value): bool => $value !== null && $value !== ''); + + return [ + 'ready' => $ready, + 'code' => $ready ? 'ready' : ($initializing ? 'initializing' : 'pending'), + 'status' => $ready ? 'ready' : ($initializing ? 'running' : 'pending'), + 'last_succeeded_at' => $succeededAt === [] ? null : max($succeededAt), + ]; + } + + /** @return list */ + public function availableMonths(): array + { + $start = Carbon::createFromFormat( + '!Y-m-d', + SupplierPayableForecastRepository::DEFAULT_FROM, + 'Asia/Shanghai', + )->startOfMonth(); + $current = now('Asia/Shanghai')->startOfMonth(); + if ($start->gt($current)) { + return [$current->format('Y-m')]; + } + + $months = []; + while ($start->lte($current)) { + $months[] = $start->format('Y-m'); + $start->addMonthNoOverflow(); + } + + return array_reverse($months); + } + + /** @param list $months */ + private function resolveMonth(string $requested, array $months): string + { + $requested = trim($requested); + if (preg_match('/^\d{4}-(0[1-9]|1[0-2])$/D', $requested) === 1 + && in_array($requested, $months, true)) { + return $requested; + } + + return $months[0] ?? ''; + } + + /** @return array{0:string,1:?string} */ + private function monthWindow(string $month): array + { + $start = Carbon::createFromFormat('!Y-m-d H:i:s', $month . '-01 00:00:00', 'Asia/Shanghai'); + $closedThrough = now('Asia/Shanghai')->subDay()->endOfDay(); + $monthEnd = $start->copy()->endOfMonth()->endOfDay(); + $end = $monthEnd->gt($closedThrough) ? $closedThrough : $monthEnd; + + if ($end->lt($start)) { + return [$start->format('Y-m-d H:i:s'), null]; + } + + return [$start->format('Y-m-d H:i:s'), $end->format('Y-m-d H:i:s')]; + } + + /** + * @return array + */ + private function metadataForMonth(string $month): array + { + if (! Schema::connection($this->connectionName)->hasTable(self::METADATA_TABLE)) { + return []; + } + + $rows = $this->connection->table(self::METADATA_TABLE) + ->where('Month', $month) + ->selectRaw('TRIM(supplier) AS supplier, TRIM(company) AS company') + ->selectRaw('COALESCE(SUM(ExpFieght), 0) AS express_freight') + ->selectRaw('COALESCE(SUM(advloan), 0) AS advance_loan') + ->selectRaw('COALESCE(SUM(invoiceDct), 0) AS invoice_deduction') + ->selectRaw('COALESCE(SUM(boardDct), 0) AS board_deduction') + ->selectRaw('COALESCE(SUM(specimenDct), 0) AS sample_deduction') + ->selectRaw('COALESCE(SUM(unpriced), 0) AS unpriced_adjustment') + ->groupByRaw('TRIM(supplier), TRIM(company)') + ->get(); + + $metadata = []; + foreach ($rows as $row) { + $supplier = trim((string) ($row->supplier ?? '')); + if ($supplier === '') { + continue; + } + $entry = $metadata[$supplier] ?? [ + 'company' => '', + 'express_freight' => 0.0, + 'advance_loan' => 0.0, + 'invoice_deduction' => 0.0, + 'board_deduction' => 0.0, + 'sample_deduction' => 0.0, + 'unpriced_adjustment' => 0.0, + ]; + $company = trim((string) ($row->company ?? '')); + if ($entry['company'] === '' && $company !== '') { + $entry['company'] = $company; + } + foreach ([ + 'express_freight', + 'advance_loan', + 'invoice_deduction', + 'board_deduction', + 'sample_deduction', + 'unpriced_adjustment', + ] as $field) { + $entry[$field] = (float) $entry[$field] + (float) ($row->{$field} ?? 0); + } + $metadata[$supplier] = $entry; + } + + return $metadata; + } + + /** + * @param list $suppliers + * @return array + */ + private function latestCompanyMap(array $suppliers): array + { + if ($suppliers === [] || ! Schema::connection($this->connectionName)->hasTable(self::METADATA_TABLE)) { + return []; + } + + $rows = $this->connection->table(self::METADATA_TABLE) + ->whereIn('supplier', $suppliers) + ->whereNotNull('company') + ->where('company', '!=', '') + ->orderByDesc('Month') + ->orderByDesc('id') + ->get(['supplier', 'company']); + $companies = []; + foreach ($rows as $row) { + $supplier = trim((string) ($row->supplier ?? '')); + if ($supplier !== '' && ! isset($companies[$supplier])) { + $companies[$supplier] = trim((string) ($row->company ?? '')); + } + } + + return $companies; + } + + private function money(mixed $value): float + { + $number = round((float) ($value ?? 0), 2); + + return abs($number) < 0.005 ? 0.0 : $number; + } +} diff --git a/modules/EcommerceFinance/View/SupplierPayableForecastPageData.php b/modules/EcommerceFinance/View/SupplierPayableForecastPageData.php index 22760f13..56ed22ce 100644 --- a/modules/EcommerceFinance/View/SupplierPayableForecastPageData.php +++ b/modules/EcommerceFinance/View/SupplierPayableForecastPageData.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Carbon; use Modules\EcommerceFinance\Repositories\SupplierPayableForecastRepository; +use Modules\EcommerceFinance\Repositories\SupplierPayableForecastSummaryRepository; use Modules\EcommerceFinance\Services\PayablesFinalRegistry; use Modules\EcommerceFinance\Services\SupplierPayableForecastSyncRunStore; @@ -13,6 +14,7 @@ class SupplierPayableForecastPageData { public function __construct( private readonly SupplierPayableForecastRepository $repository, + private readonly SupplierPayableForecastSummaryRepository $summaryRepository, private readonly PayablesFinalRegistry $registry, private readonly SupplierPayableForecastSyncRunStore $syncRuns, ) { @@ -47,6 +49,22 @@ class SupplierPayableForecastPageData 'page' => max((int) $request->query('returns_page', 1), 1), 'per_page' => 20, ]; + $summaryResult = [ + 'ready' => false, + 'sync_status' => [ + 'ready' => false, + 'code' => 'unavailable', + 'status' => 'unavailable', + 'last_succeeded_at' => null, + ], + 'months' => [], + 'filters' => ['month' => '', 'keyword' => ''], + 'total' => 0, + 'rows' => [], + 'page' => max((int) $request->query('summary_page', 1), 1), + 'per_page' => 20, + 'totals' => ['subtotal' => 0.0, 'supplier_balance' => 0.0], + ]; if ($syncStatus['ready']) { $result = $this->repository->goodsDetails( @@ -62,6 +80,10 @@ class SupplierPayableForecastPageData 20, ); } + $summaryResult = $this->summaryRepository->paginate([ + 'month' => (string) $request->query('summary_month', ''), + 'keyword' => (string) $request->query('summary_keyword', ''), + ], max((int) $request->query('summary_page', 1), 1)); $paginationQuery = array_filter([ 'goods_date_from' => $filters['date_from'] === SupplierPayableForecastRepository::DEFAULT_FROM_TIME @@ -99,6 +121,23 @@ class SupplierPayableForecastPageData 'query' => $returnPaginationQuery, ], ); + $summaryPaginationQuery = array_filter([ + 'forecast_view' => 'summary', + 'summary_month' => $summaryResult['filters']['month'], + 'summary_keyword' => $summaryResult['filters']['keyword'] !== '' + ? $summaryResult['filters']['keyword'] + : null, + ], static fn (mixed $value): bool => $value !== null && $value !== ''); + $summaryRows = new LengthAwarePaginator( + $summaryResult['rows'], + $summaryResult['total'], + $summaryResult['per_page'], + $summaryResult['page'], + [ + 'path' => $request->url(), + 'query' => $summaryPaginationQuery, + ], + ); return [ 'activeForecastView' => $activeView, @@ -129,6 +168,11 @@ class SupplierPayableForecastPageData 'estimated_amount_after_discount' => $returnResult['estimated_amount_after_discount'], ], 'returnForecastSyncStatus' => $returnSyncStatus, + 'summaryForecastFilters' => $summaryResult['filters'], + 'summaryForecastMonths' => $summaryResult['months'], + 'summaryForecastRows' => $summaryRows, + 'summaryForecastTotals' => $summaryResult['totals'], + 'summaryForecastSyncStatus' => $summaryResult['sync_status'], 'forecastSyncRuns' => $this->syncRuns->latestSummary(), ]; } diff --git a/resources/views/business/pages/negative-alerts/supplier-payable-forecast.blade.php b/resources/views/business/pages/negative-alerts/supplier-payable-forecast.blade.php index 2fc8e249..45e348c5 100644 --- a/resources/views/business/pages/negative-alerts/supplier-payable-forecast.blade.php +++ b/resources/views/business/pages/negative-alerts/supplier-payable-forecast.blade.php @@ -253,6 +253,10 @@ background: #FCFBF8; } + .supplier-payable-forecast .npf-summary-filter { + grid-template-columns: minmax(180px, .7fr) minmax(260px, 1.8fr) auto; + } + .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 { @@ -360,6 +364,20 @@ .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-summary-table th:nth-child(1), + .supplier-payable-forecast .npf-summary-table td:nth-child(1) { min-width: 92px; } + .supplier-payable-forecast .npf-summary-table th:nth-child(2), + .supplier-payable-forecast .npf-summary-table td:nth-child(2) { min-width: 250px; } + .supplier-payable-forecast .npf-summary-table th:nth-child(3), + .supplier-payable-forecast .npf-summary-table td:nth-child(3) { min-width: 120px; } + .supplier-payable-forecast .npf-summary-table th:nth-child(n+4), + .supplier-payable-forecast .npf-summary-table td:nth-child(n+4) { min-width: 116px; } + .supplier-payable-forecast .npf-summary-table .is-total { color: var(--npf-gold); font-weight: 600; } + .supplier-payable-forecast .npf-summary-table .is-pending { + color: var(--npf-muted); + font-size: 11px; + text-align: center; + } .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; } @@ -379,6 +397,7 @@ .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-summary-filter { grid-template-columns: minmax(0, 1fr); } .supplier-payable-forecast .npf-filter-actions { grid-column: 1; justify-content: flex-start; } .supplier-payable-forecast .npf-table-shell { max-height: 58vh; } } @@ -408,7 +427,7 @@

@if ($goodsForecastSyncStatus['ready']) @if ($goodsForecastSyncStatus['shipping_available'] ?? false) - 采购入库与“代发仓”发货明细已合并展示,并匹配工作平台变价后价格;退货明细读取聚水潭采购退货,汇总仍待接入。 + 采购入库与“代发仓”发货明细已合并展示,并匹配工作平台变价后价格;退货明细读取聚水潭采购退货,汇总读取供应商应付表共享镜像。 @else 采购入库已接入,并匹配工作平台变价后价格;代发仓发货明细共享镜像尚未就绪。 @endif @@ -811,19 +830,147 @@ 汇总 -

按供应商汇总货款、退货扣减、违约金和提前付款,形成待付货款预估。

+

按月份、供应商主体和简称汇总本页货款与退货明细;小计与供应商余额使用固定公式计算,预估金额暂不参与余额。

- 数据待接入 + + {{ $summaryForecastSyncStatus['ready'] ? '共享镜像' : ($summaryForecastSyncStatus['code'] === 'initializing' ? '同步中' : '待同步') }} + -
-
汇总维度按供应商
-
余额口径货款 - 退货扣减 - 违约金 - 提前付款
-
页面状态待接入
+ +
+
+ 本月供应商 + {{ number_format($summaryForecastRows->total()) }} 家 +
+
+ 小计合计(元) + {{ number_format($summaryForecastTotals['subtotal'], 2) }} +
+
+ 供应商余额合计(元) + {{ number_format($summaryForecastTotals['supplier_balance'], 2) }} +
+
+ 镜像最近成功 + {{ $summaryForecastSyncStatus['last_succeeded_at'] ?? '待同步' }} +
-
- - 供应商货款预估数据待接入 - 接入后将按供应商展示待付货款余额、数据日期和核对结果。 + +
+ + + +
+ 重置 + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + @forelse ($summaryForecastRows as $summaryRow) + + + + + + + + + + + + + + + + + + @empty + + + + @endforelse + +
月份供应商主体名称供应商简称运费货款金额退货金额预支借款小计发票扣款板材扣款预估板材扣款样品扣款预估金额未定价-本月定价供应商余额
{{ $summaryRow['month'] }}{{ $summaryRow['company'] }}{{ $summaryRow['supplier'] }}{{ number_format($summaryRow['express_freight'], 2) }}{{ number_format($summaryRow['goods_amount'], 2) }}{{ number_format($summaryRow['return_amount'], 2) }}{{ number_format($summaryRow['advance_loan'], 2) }}{{ number_format($summaryRow['subtotal'], 2) }}{{ number_format($summaryRow['invoice_deduction'], 2) }}{{ number_format($summaryRow['board_deduction'], 2) }}{{ number_format($summaryRow['estimated_board_deduction'], 2) }}{{ number_format($summaryRow['sample_deduction'], 2) }}—{{ number_format($summaryRow['unpriced_adjustment'], 2) }}{{ number_format($summaryRow['supplier_balance'], 2) }}
+
+ + {{ $summaryForecastSyncStatus['ready'] ? '当前条件下没有供应商汇总' : '供应商汇总共享镜像尚未就绪' }} + + {{ $summaryForecastSyncStatus['ready'] + ? '请调整月份或供应商关键字后重新查询。' + : '共享镜像完成首次同步后将自动显示供应商应付汇总。' }} + +
+
+
+ + @if ($summaryForecastRows->total() > 0) +
+ + 第 {{ $summaryForecastRows->currentPage() }} / {{ $summaryForecastRows->lastPage() }} 页, + 共 {{ number_format($summaryForecastRows->total()) }} 家供应商 + + +
+ @endif + +
+ 货款金额取自本页“货款明细”,退货金额取自本页“退货明细”,均沿用明细页的取价、剔除和日期口径。运费、预支借款及各类扣款优先读取当前月份供应商应付表,当月资料尚未接入时暂按 0.00 展示。 + 小计 = 货款金额 - 退货金额;供应商余额 = 运费 - 预支借款 + 小计 - 发票扣款 - 板材扣款 - 预估板材扣款 - 样品扣款 +(未定价-本月定价)。 + 当前源表没有“预估板材扣款”字段,暂按 0.00 展示;“预估金额”仅保留列,暂不参与供应商余额计算。
diff --git a/tests/Feature/Business/NegativeAlertPagesTest.php b/tests/Feature/Business/NegativeAlertPagesTest.php index 052cdc1d..aab216cc 100644 --- a/tests/Feature/Business/NegativeAlertPagesTest.php +++ b/tests/Feature/Business/NegativeAlertPagesTest.php @@ -7,9 +7,11 @@ use App\Listeners\Menu\ShowInAdmin; use App\Models\Auth\Permission; use App\Utilities\BusinessNavigation; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; use Modules\EcommerceFinance\Repositories\SupplierPayableForecastRepository; +use Modules\EcommerceFinance\Repositories\SupplierPayableForecastSummaryRepository; use Modules\EcommerceFinance\Repositories\SupplierManagementMirrorRepository; use Modules\EcommerceFinance\Repositories\SupplierPayableReportRepository; use Modules\EcommerceFinance\Services\PayablesFinalRegistry; @@ -32,6 +34,13 @@ class NegativeAlertPagesTest extends FeatureTestCase $this->app->instance(SupplierPayableReportRepository::class, $payableReport); } + protected function tearDown(): void + { + Carbon::setTestNow(); + + parent::tearDown(); + } + public function test_negative_alert_pages_expose_visible_forecast_subtabs(): void { $navigation = collect(BusinessNavigation::all())->keyBy('slug'); @@ -248,7 +257,7 @@ class NegativeAlertPagesTest extends FeatureTestCase ->assertSeeText('供应商货款预估') ->assertSeeText('供应商货款明细镜像初始化中') ->assertSeeText('采购入库共享镜像尚未就绪') - ->assertSeeText('供应商货款预估数据待接入') + ->assertSeeText('供应商汇总共享镜像尚未就绪') ->assertSeeText('货款明细') ->assertSeeText('退货明细') ->assertSeeText('汇总') @@ -292,6 +301,196 @@ class NegativeAlertPagesTest extends FeatureTestCase $this->assertDoesNotMatchRegularExpression('/id="npf-panel-returns"[^>]*hidden/s', $html); } + public function test_supplier_payable_forecast_summary_uses_screenshot_headers_and_formulas(): void + { + Carbon::setTestNow(Carbon::parse('2026-11-30 12:00:00', 'Asia/Shanghai')); + $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], + ['dataset_key' => SupplierPayableForecastRepository::RETURN_HEAD_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now], + ['dataset_key' => SupplierPayableForecastRepository::RETURN_ITEM_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::HEAD_TABLE)->insert([ + [ + 'Id' => 101, + 'io_id' => 'IN-YZH', + 'po_id' => 1001, + 'io_date' => '2026-11-10 10:00:00', + 'warehouse' => '正常仓', + 'supplier_name' => '亿之航', + ], + [ + 'Id' => 102, + 'io_id' => 'IN-CY', + 'po_id' => 1002, + 'io_date' => '2026-11-11 10:00:00', + 'warehouse' => '正常仓', + 'supplier_name' => '彩艺', + ], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::ITEM_TABLE)->insert([ + [ + 'Id' => 101, + 'io_id' => 'IN-YZH', + 'ioi_id' => 'ITEM-YZH', + 'sku_id' => 'SKU-YZH-GOODS', + 'i_id' => 'STYLE-YZH', + 'name' => '亿之航货款', + 'qty' => 1, + 'cost_price' => 58665, + 'cost_amount' => 58665, + ], + [ + 'Id' => 102, + 'io_id' => 'IN-CY', + 'ioi_id' => 'ITEM-CY', + 'sku_id' => 'SKU-CY-GOODS', + 'i_id' => 'STYLE-CY', + 'name' => '彩艺货款', + 'qty' => 1, + 'cost_price' => 178523, + 'cost_amount' => 178523, + ], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRICE_TABLE)->insert([ + ['Id' => 101, 'skucode' => 'SKU-YZH-GOODS', 'priceType' => '1', 'afterPrice' => 58665, 'effectStartTime' => '2026-11-01 00:00:00'], + ['Id' => 102, 'skucode' => 'SKU-YZH-RETURN', 'priceType' => '1', 'afterPrice' => 4554.50, 'effectStartTime' => '2026-11-01 00:00:00'], + ['Id' => 103, 'skucode' => 'SKU-CY-GOODS', 'priceType' => '1', 'afterPrice' => 178523, 'effectStartTime' => '2026-11-01 00:00:00'], + ['Id' => 104, 'skucode' => 'SKU-CY-RETURN', 'priceType' => '1', 'afterPrice' => 19096, 'effectStartTime' => '2026-11-01 00:00:00'], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRODUCT_TABLE)->insert([ + ['autoid' => 101, 'sku_id' => 'SKU-YZH-RETURN', 'sku_type' => 'normal', 'supplier_name' => '亿之航', 'cost_price' => 4554.50], + ['autoid' => 102, 'sku_id' => 'SKU-CY-RETURN', 'sku_type' => 'normal', 'supplier_name' => '彩艺', 'cost_price' => 19096], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::RETURN_HEAD_TABLE)->insert([ + 'Id' => 201, + 'io_id' => 6201, + 'io_date' => '2026-11-20 10:00:00', + 'status' => 'Confirmed', + 'warehouse' => '正常仓', + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::RETURN_ITEM_TABLE)->insert([ + [ + 'Id' => 201, + 'io_id' => 6201, + 'ioi_id' => 'RETURN-YZH', + 'sku_id' => 'SKU-YZH-RETURN', + 'i_id' => 'STYLE-YZH-RETURN', + 'name' => '亿之航退货', + 'qty' => 1, + 'cost_price' => 4554.50, + 'cost_amount' => 4554.50, + ], + [ + 'Id' => 202, + 'io_id' => 6201, + 'ioi_id' => 'RETURN-CY', + 'sku_id' => 'SKU-CY-RETURN', + 'i_id' => 'STYLE-CY-RETURN', + 'name' => '彩艺退货', + 'qty' => 1, + 'cost_price' => 19096, + 'cost_amount' => 19096, + ], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastSummaryRepository::METADATA_TABLE)->insert([ + [ + 'id' => 101, + 'Month' => '2026-11', + 'company' => '常州市亿之航家具科技有限公司', + 'supplier' => '亿之航', + 'ExpFieght' => 0, + 'loan' => 999999, + 'refund' => 888888, + 'advloan' => 0, + 'invoiceDct' => 0, + 'boardDct' => 49190, + 'specimenDct' => 0, + 'guessPrice' => 12345, + 'unpriced' => 0, + ], + [ + 'id' => 102, + 'Month' => '2026-11', + 'company' => '曹县美莱客木制品有限公司', + 'supplier' => '彩艺', + 'ExpFieght' => 0, + 'loan' => 0, + 'refund' => 0, + 'advloan' => 0, + 'invoiceDct' => 0, + 'boardDct' => 0, + 'specimenDct' => 0, + 'guessPrice' => 0, + 'unpriced' => 0, + ], + ]); + + $response = $this->loginAs()->get(route('business.pages.show', [ + 'section' => 'negative-alerts', + 'page' => 'supplier-negative-alert', + 'tab' => 'payable-forecast', + 'forecast_view' => 'summary', + ])) + ->assertOk() + ->assertSeeText('常州市亿之航家具科技有限公司') + ->assertSeeText('亿之航') + ->assertSeeText('54,110.50') + ->assertSeeText('4,920.50') + ->assertSeeText('159,427.00'); + + $html = (string) $response->getContent(); + $tableStart = strpos($html, 'data-summary-table'); + $tableEnd = $tableStart === false ? false : strpos($html, '', $tableStart); + $this->assertNotFalse($tableStart); + $this->assertNotFalse($tableEnd); + preg_match_all('/]*>(.*?)<\/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); + $this->assertStringContainsString('title="预估金额逻辑待接入"', $html); + $this->assertStringContainsString('data-estimated-amount-pending', $html); + $this->assertStringContainsString('position: sticky', $html); + + $filteredHtml = (string) $this->loginAs()->get(route('business.pages.show', [ + 'section' => 'negative-alerts', + 'page' => 'supplier-negative-alert', + 'tab' => 'payable-forecast', + 'forecast_view' => 'summary', + 'summary_month' => '2026-11', + 'summary_keyword' => '彩艺', + ])) + ->assertOk() + ->getContent(); + $filteredStart = strpos($filteredHtml, 'data-summary-table'); + $filteredEnd = $filteredStart === false ? false : strpos($filteredHtml, '', $filteredStart); + $this->assertNotFalse($filteredEnd); + $filteredSummary = substr($filteredHtml, $filteredStart, $filteredEnd - $filteredStart); + $this->assertStringContainsString('彩艺', $filteredSummary); + $this->assertStringNotContainsString('亿之航', $filteredSummary); + } + public function test_supplier_negative_alert_filters_by_month_and_supplier(): void { $this->saveSupplierPayable('negative:sep', '九月负余额供应商', '-99.00', '2026-09'); @@ -778,6 +977,23 @@ class NegativeAlertPagesTest extends FeatureTestCase $table->decimal('afterPrice', 18, 2)->nullable(); $table->dateTime('effectStartTime')->nullable(); }); + if (! $schema->hasTable(SupplierPayableForecastSummaryRepository::METADATA_TABLE)) { + $schema->create(SupplierPayableForecastSummaryRepository::METADATA_TABLE, function (Blueprint $table): void { + $table->unsignedBigInteger('id')->primary(); + $table->string('company', 255)->nullable(); + $table->string('supplier', 255)->nullable(); + $table->decimal('ExpFieght', 18, 2)->nullable(); + $table->decimal('loan', 18, 2)->nullable(); + $table->decimal('refund', 18, 2)->nullable(); + $table->decimal('advloan', 18, 2)->nullable(); + $table->decimal('invoiceDct', 18, 2)->nullable(); + $table->decimal('boardDct', 18, 2)->nullable(); + $table->decimal('specimenDct', 18, 2)->nullable(); + $table->decimal('guessPrice', 18, 2)->nullable(); + $table->decimal('unpriced', 18, 2)->nullable(); + $table->string('Month', 7)->nullable(); + }); + } if (! $schema->hasTable(SupplierPayableForecastRepository::SHIPPING_TABLE)) { $schema->create(SupplierPayableForecastRepository::SHIPPING_TABLE, function (Blueprint $table): void { $table->bigIncrements('id'); diff --git a/tests/Unit/EcommerceFinance/SupplierPayableForecastSummaryRepositoryTest.php b/tests/Unit/EcommerceFinance/SupplierPayableForecastSummaryRepositoryTest.php new file mode 100644 index 00000000..7ea431c4 --- /dev/null +++ b/tests/Unit/EcommerceFinance/SupplierPayableForecastSummaryRepositoryTest.php @@ -0,0 +1,285 @@ +createTables(); + $this->seedReadyStates(); + + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::HEAD_TABLE)->insert([ + [ + 'Id' => 1, + 'io_id' => 'IN-SUMMARY-A', + 'po_id' => 1001, + 'io_date' => '2026-11-10 10:00:00', + 'warehouse' => '正常仓', + 'supplier_name' => '供应商甲', + ], + [ + 'Id' => 2, + 'io_id' => 'IN-SUMMARY-B', + 'po_id' => 1002, + 'io_date' => '2026-11-11 10:00:00', + 'warehouse' => '正常仓', + 'supplier_name' => '彩艺', + ], + [ + 'Id' => 3, + 'io_id' => 'IN-OCTOBER', + 'po_id' => 1003, + 'io_date' => '2026-10-20 10:00:00', + 'warehouse' => '正常仓', + 'supplier_name' => '历史供应商', + ], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::ITEM_TABLE)->insert([ + [ + 'Id' => 1, + 'io_id' => 'IN-SUMMARY-A', + 'sku_id' => 'SKU-GOODS-A', + 'i_id' => 'STYLE-GOODS-A', + 'name' => '甲货款', + 'qty' => 2, + 'cost_price' => 8, + 'cost_amount' => 16, + ], + [ + 'Id' => 2, + 'io_id' => 'IN-SUMMARY-B', + 'sku_id' => 'SKU-GOODS-B', + 'i_id' => 'STYLE-GOODS-B', + 'name' => '乙货款', + 'qty' => 1, + 'cost_price' => 100, + 'cost_amount' => 100, + ], + [ + 'Id' => 3, + 'io_id' => 'IN-OCTOBER', + 'sku_id' => 'SKU-OCTOBER', + 'i_id' => 'STYLE-OCTOBER', + 'name' => '历史货款', + 'qty' => 1, + 'cost_price' => 9, + 'cost_amount' => 9, + ], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRICE_TABLE)->insert([ + ['Id' => 1, 'skucode' => 'SKU-GOODS-A', 'priceType' => '1', 'afterPrice' => 8, 'effectStartTime' => '2026-10-01 00:00:00'], + ['Id' => 2, 'skucode' => 'SKU-RETURN-A', 'priceType' => '1', 'afterPrice' => 8, 'effectStartTime' => '2026-10-01 00:00:00'], + ['Id' => 3, 'skucode' => 'SKU-GOODS-B', 'priceType' => '1', 'afterPrice' => 100, 'effectStartTime' => '2026-10-01 00:00:00'], + ['Id' => 4, 'skucode' => 'SKU-OCTOBER', 'priceType' => '1', 'afterPrice' => 9, 'effectStartTime' => '2026-10-01 00:00:00'], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRODUCT_TABLE)->insert([ + ['autoid' => 1, 'sku_id' => 'SKU-GOODS-A', 'sku_type' => 'normal', 'supplier_name' => '供应商甲', 'cost_price' => 8], + ['autoid' => 2, 'sku_id' => 'SKU-RETURN-A', 'sku_type' => 'normal', 'supplier_name' => '供应商甲', 'cost_price' => 8], + ['autoid' => 3, 'sku_id' => 'SKU-GOODS-B', 'sku_type' => 'normal', 'supplier_name' => '彩艺', 'cost_price' => 100], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::RETURN_HEAD_TABLE)->insert([ + 'Id' => 1, + 'io_id' => 5001, + 'io_date' => '2026-11-12 10:00:00', + 'status' => 'Confirmed', + 'warehouse' => '正常仓', + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::RETURN_ITEM_TABLE)->insert([ + 'Id' => 1, + 'io_id' => 5001, + 'ioi_id' => 'RETURN-ITEM-1', + 'sku_id' => 'SKU-RETURN-A', + 'i_id' => 'STYLE-RETURN-A', + 'name' => '甲退货', + 'qty' => 1, + 'cost_price' => 8, + 'cost_amount' => 8, + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastSummaryRepository::METADATA_TABLE)->insert([ + [ + 'id' => 1, + 'Month' => '2026-11', + 'company' => '供应商甲公司', + 'supplier' => '供应商甲', + 'ExpFieght' => 1000, + 'loan' => 999999, + 'refund' => 888888, + 'advloan' => 500, + 'invoiceDct' => 300, + 'boardDct' => 700, + 'specimenDct' => 200, + 'guessPrice' => 999999, + 'unpriced' => 400, + ], + [ + 'id' => 2, + 'Month' => '2026-11', + 'company' => '彩艺家具有限公司', + 'supplier' => '彩艺', + 'ExpFieght' => 0, + 'loan' => 0, + 'refund' => 0, + 'advloan' => 0, + 'invoiceDct' => 0, + 'boardDct' => 0, + 'specimenDct' => 0, + 'guessPrice' => 0, + 'unpriced' => 0, + ], + ]); + + $result = app(SupplierPayableForecastSummaryRepository::class)->paginate([], 1); + + $this->assertTrue($result['ready']); + $this->assertSame(['2026-11', '2026-10'], $result['months']); + $this->assertSame('2026-11', $result['filters']['month']); + $this->assertSame(2, $result['total']); + $this->assertSame(116.0, $result['totals']['goods_amount']); + $this->assertSame(8.0, $result['totals']['return_amount']); + $this->assertSame(108.0, $result['totals']['subtotal']); + $this->assertSame(-192.0, $result['totals']['supplier_balance']); + + $supplierA = collect($result['rows'])->firstWhere('supplier', '供应商甲'); + $this->assertSame('供应商甲公司', $supplierA['company']); + $this->assertSame(16.0, $supplierA['goods_amount']); + $this->assertSame(8.0, $supplierA['return_amount']); + $this->assertSame(8.0, $supplierA['subtotal']); + $this->assertSame(-292.0, $supplierA['supplier_balance']); + $this->assertSame(0.0, $supplierA['estimated_board_deduction']); + $this->assertNull($supplierA['estimated_amount']); + + $filtered = app(SupplierPayableForecastSummaryRepository::class)->paginate([ + 'month' => '2026-11', + 'keyword' => '彩艺', + ], 1); + $this->assertSame(1, $filtered['total']); + $this->assertSame('彩艺', $filtered['rows'][0]['supplier']); + $this->assertSame(100.0, $filtered['rows'][0]['goods_amount']); + $this->assertSame(0.0, $filtered['rows'][0]['return_amount']); + $this->assertSame(100.0, $filtered['rows'][0]['supplier_balance']); + } + + public function test_summary_is_empty_until_forecast_details_are_initialized(): void + { + Carbon::setTestNow(Carbon::parse('2026-11-30 12:00:00', 'Asia/Shanghai')); + $this->createTables(); + + $result = app(SupplierPayableForecastSummaryRepository::class)->paginate([], 1); + + $this->assertFalse($result['ready']); + $this->assertSame('pending', $result['sync_status']['code']); + $this->assertSame([], $result['rows']); + $this->assertSame(0, $result['total']); + } + + private function seedReadyStates(): 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], + ['dataset_key' => SupplierPayableForecastRepository::RETURN_HEAD_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now], + ['dataset_key' => SupplierPayableForecastRepository::RETURN_ITEM_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now], + ]); + } + + 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->string('warehouse', 255)->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('sku_id', 100)->nullable(); + $table->string('i_id', 100)->nullable(); + $table->string('name', 255)->nullable(); + $table->decimal('qty', 18, 2)->nullable(); + $table->decimal('cost_price', 18, 2)->nullable(); + $table->decimal('cost_amount', 18, 2)->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(); + }); + $schema->create(SupplierPayableForecastRepository::PRODUCT_TABLE, function (Blueprint $table): void { + $table->unsignedBigInteger('autoid'); + $table->string('sku_id', 100)->nullable(); + $table->string('sku_type', 32)->nullable(); + $table->decimal('cost_price', 18, 2)->nullable(); + $table->string('supplier_name', 255)->nullable(); + }); + $schema->create(SupplierPayableForecastRepository::RETURN_HEAD_TABLE, function (Blueprint $table): void { + $table->bigIncrements('Id'); + $table->unsignedBigInteger('io_id')->nullable(); + $table->dateTime('io_date')->nullable(); + $table->string('status', 50)->nullable(); + $table->string('warehouse', 255)->nullable(); + $table->text('remark')->nullable(); + $table->string('labels', 255)->nullable(); + $table->string('l_id', 100)->nullable(); + $table->string('creator_name', 255)->nullable(); + }); + $schema->create(SupplierPayableForecastRepository::RETURN_ITEM_TABLE, function (Blueprint $table): void { + $table->bigIncrements('Id'); + $table->string('ioi_id', 100)->nullable(); + $table->string('sku_id', 100)->nullable(); + $table->string('i_id', 100)->nullable(); + $table->string('name', 500)->nullable(); + $table->decimal('qty', 18, 2)->nullable(); + $table->decimal('cost_price', 18, 2)->nullable(); + $table->decimal('cost_amount', 18, 2)->nullable(); + $table->text('remark')->nullable(); + $table->unsignedBigInteger('io_id')->nullable(); + }); + $schema->create(SupplierPayableForecastSummaryRepository::METADATA_TABLE, function (Blueprint $table): void { + $table->unsignedBigInteger('id')->primary(); + $table->string('company', 255)->nullable(); + $table->string('supplier', 255)->nullable(); + $table->decimal('ExpFieght', 18, 2)->nullable(); + $table->decimal('loan', 18, 2)->nullable(); + $table->decimal('refund', 18, 2)->nullable(); + $table->decimal('advloan', 18, 2)->nullable(); + $table->decimal('invoiceDct', 18, 2)->nullable(); + $table->decimal('boardDct', 18, 2)->nullable(); + $table->decimal('specimenDct', 18, 2)->nullable(); + $table->decimal('guessPrice', 18, 2)->nullable(); + $table->decimal('unpriced', 18, 2)->nullable(); + $table->string('Month', 7)->nullable(); + }); + } +}