diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 3c9feae9..018f24d0 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -86,6 +86,7 @@ use Modules\EcommerceFinance\Services\SupplierPayableOverrideStore; use Modules\EcommerceFinance\Services\SupplierFreeShippingStore; use Modules\EcommerceFinance\View\PlatformPromotionAccountPageData; use Modules\EcommerceFinance\View\OrderDataPageData; +use Modules\EcommerceFinance\View\SupplierNegativeAlertPageData; use RuntimeException; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -4717,6 +4718,7 @@ class Pages extends Controller 'planting-loss' => app(\Modules\EcommerceFinance\View\PlantingLossPageData::class)->page(), 'finance-data' => app(\Modules\EcommerceFinance\View\SupplierReconciliationPageData::class)->financeData(), 'supplier-data' => app(\Modules\EcommerceFinance\View\SupplierReconciliationPageData::class)->supplierData(), + 'supplier-negative-alert' => app(SupplierNegativeAlertPageData::class)->page(), 'store-report-data-logic' => $this->prepareStoreReportLogic(), 'tax-forecast-data-logic' => $this->contentForTaxForecastLogic(), default => null, diff --git a/modules/EcommerceFinance/View/SupplierNegativeAlertPageData.php b/modules/EcommerceFinance/View/SupplierNegativeAlertPageData.php new file mode 100644 index 00000000..7b451e02 --- /dev/null +++ b/modules/EcommerceFinance/View/SupplierNegativeAlertPageData.php @@ -0,0 +1,147 @@ + */ + public function page(): array + { + $rows = $this->store->listRows( + PayablesFinalActions::DATASET_PREFIX . self::DATASET, + (int) (company_id() ?: 1), + ); + + $negativeRows = []; + foreach ($rows as $row) { + $balance = $this->number($row['supplier_balance'] ?? null); + if ($balance === null || $balance >= 0) { + continue; + } + + $row['supplier_balance'] = $balance; + $negativeRows[] = $row; + } + + usort($negativeRows, static function (array $left, array $right): int { + return strcmp( + (string) ($right['summary_month'] ?? ''), + (string) ($left['summary_month'] ?? ''), + ) ?: strnatcasecmp( + (string) ($left['supplier'] ?? ''), + (string) ($right['supplier'] ?? ''), + ); + }); + + $months = []; + foreach ($negativeRows as $row) { + $month = trim((string) ($row['summary_month'] ?? '')); + if (preg_match('/^\d{4}-\d{2}$/', $month) === 1) { + $months[$month] = true; + } + } + $months = array_keys($months); + rsort($months); + + $requestedMonth = trim((string) request()->query('month', '')); + $month = in_array($requestedMonth, $months, true) ? $requestedMonth : ''; + if ($month !== '') { + $negativeRows = array_values(array_filter( + $negativeRows, + static fn (array $row): bool => (string) ($row['summary_month'] ?? '') === $month, + )); + } + + $supplierNames = []; + foreach ($negativeRows as $row) { + $supplier = trim((string) ($row['supplier'] ?? '')); + if ($supplier !== '') { + $supplierNames[$supplier] = true; + } + } + $supplierNames = array_keys($supplierNames); + sort($supplierNames, SORT_NATURAL | SORT_FLAG_CASE); + + $supplierQuery = mb_substr(trim((string) request()->query('supplier', '')), 0, 191); + if ($supplierQuery !== '') { + $needle = mb_strtolower($supplierQuery); + $negativeRows = array_values(array_filter( + $negativeRows, + static function (array $row) use ($needle): bool { + $haystack = mb_strtolower(implode("\n", [ + (string) ($row['supplier'] ?? ''), + (string) ($row['company'] ?? ''), + ])); + + return str_contains($haystack, $needle); + }, + )); + } + + $supplierCounts = []; + foreach ($negativeRows as $row) { + $key = trim((string) ($row['company'] ?? '')) . "\0" . trim((string) ($row['supplier'] ?? '')); + $supplierCounts[$key] = true; + } + + $total = count($negativeRows); + $pages = max((int) ceil($total / self::PER_PAGE), 1); + $page = min(max((int) request()->query('page', 1), 1), $pages); + $items = array_map( + static fn (array $row): object => (object) $row, + array_slice($negativeRows, ($page - 1) * self::PER_PAGE, self::PER_PAGE), + ); + + return [ + 'view' => 'business.pages.negative-alerts.supplier-negative-alert', + 'negativeAlertRows' => new LengthAwarePaginator( + $items, + $total, + self::PER_PAGE, + $page, + [ + 'path' => request()->url(), + 'query' => request()->except('page'), + ], + ), + 'negativeAlertMonths' => $months, + 'negativeAlertMonth' => $month, + 'negativeAlertSupplier' => $supplierQuery, + 'negativeAlertSupplierNames' => $supplierNames, + 'negativeAlertSupplierCount' => count($supplierCounts), + 'negativeAlertTotal' => $total, + 'negativeAlertSourceUrl' => route('business.pages.show', [ + 'section' => 'supplier-payables-final', + 'page' => 'supplier-payables-report', + ]), + ]; + } + + private function number(mixed $value): ?float + { + if ($value === null || trim((string) $value) === '') { + return null; + } + + $normalized = str_replace([',', ',', ' '], '', trim((string) $value)); + + return is_numeric($normalized) ? (float) $normalized : null; + } +} diff --git a/resources/views/business/pages/negative-alerts/supplier-negative-alert.blade.php b/resources/views/business/pages/negative-alerts/supplier-negative-alert.blade.php index 5bde3569..c5fa23a3 100644 --- a/resources/views/business/pages/negative-alerts/supplier-negative-alert.blade.php +++ b/resources/views/business/pages/negative-alerts/supplier-negative-alert.blade.php @@ -1,13 +1,411 @@ -@include('business.pages.negative-alerts._placeholder', [ - 'icon' => 'factory', - 'scopeLabel' => '供应商', - 'statusTitle' => '供应商负数判定口径待确认', - 'description' => '待确认按“供应商余额”还是“应付余额”判定负数,并接入真实数据后,这里将展示需要关注的供应商、负数金额及异常原因。', - 'scopeItems' => [ - ['label' => '判定字段', 'value' => '待确认'], - ['label' => '数据来源', 'value' => '待接入'], - ['label' => '数据日期', 'value' => '待接入'], - ], - 'emptyTitle' => '供应商预警数据将在口径确认后接入', - 'emptyDescription' => '接入后将按供应商汇总负数余额,并保留可追溯的负数原因和数据日期。', -]) +@php + $rows = $negativeAlertRows ?? null; + $months = $negativeAlertMonths ?? []; + $month = $negativeAlertMonth ?? ''; + $supplierQuery = $negativeAlertSupplier ?? ''; + $supplierNames = $negativeAlertSupplierNames ?? []; + $supplierCount = (int) ($negativeAlertSupplierCount ?? 0); + $total = (int) ($negativeAlertTotal ?? 0); + $sourceUrl = $negativeAlertSourceUrl ?? '#'; + $money = static fn (mixed $value): string => $value === null ? '-' : number_format((float) $value, 2); +@endphp + +
供应商余额小于 0 的终版数据
+数据实时读取自“供应商应付(终版)→ 供应商应付表”,仅显示供应商余额 < 0 的记录。
+| 月份 | +供应商公司主体名称 | +供应商简称 | +供应商余额 | +应付余额 | +对账人 | +结算方式 | +负数原因 | +备注 | +
|---|---|---|---|---|---|---|---|---|
| {{ $row->summary_month ?? '-' }} | +{{ ($row->company ?? null) ?: '-' }} | +{{ ($row->supplier ?? null) ?: '-' }} | +{{ $money($row->supplier_balance ?? null) }} | +(float) ($row->should_pay ?? 0) < 0])> + {{ $money($row->should_pay ?? null) }} + | +{{ ($row->checker ?? null) ?: '-' }} | +{{ ($row->settlement_method ?? null) ?: '-' }} | +{{ ($row->negative_reason ?? null) ?: '-' }} | +{{ ($row->remarks ?? null) ?: '-' }} | +