diff --git a/config/ding_invoice_data.php b/config/ding_invoice_data.php index 8144caf2f..29a5a36c8 100644 --- a/config/ding_invoice_data.php +++ b/config/ding_invoice_data.php @@ -2,6 +2,7 @@ return [ 'dataset_key' => 'operations_replica.rpt.ding_invoices', + 'first_supported_month' => '2026-10', 'document_types' => [ '公摊日常报销', '店铺日常报销', diff --git a/modules/EcommerceFinance/Repositories/DingInvoiceDataMirrorRepository.php b/modules/EcommerceFinance/Repositories/DingInvoiceDataMirrorRepository.php index 36c924ab6..c173a34a0 100644 --- a/modules/EcommerceFinance/Repositories/DingInvoiceDataMirrorRepository.php +++ b/modules/EcommerceFinance/Repositories/DingInvoiceDataMirrorRepository.php @@ -23,10 +23,10 @@ class DingInvoiceDataMirrorRepository public const VIEW_ATTACHMENTS = 'attachments'; public const INVOICE_STATES = [ - 'all' => '全部状态', - 'has_invoice' => '有发票', - 'no_invoice' => '无票', - 'needs_review' => '待复核', + 'all' => '全部流程', + 'has_invoice' => '有票流程', + 'no_invoice' => '无票流程', + 'needs_review' => '待复核流程', ]; private ConnectionInterface $connection; @@ -381,13 +381,14 @@ class DingInvoiceDataMirrorRepository 'has_invoice' => $query->where("{$alias}.invoice_count", '>', 0), 'no_invoice' => $query ->where("{$alias}.invoice_count", '=', 0) + ->whereIn("{$alias}.scan_status", ['no_invoice', 'recognized', 'imported']) ->where(function (Builder $nested) use ($alias): void { $nested->whereNull("{$alias}.last_error") ->orWhere("{$alias}.last_error", '=', ''); }), 'needs_review' => $query ->where(function (Builder $nested) use ($alias): void { - $nested->whereIn("{$alias}.scan_status", ['partial', 'failed']) + $nested->whereIn("{$alias}.scan_status", ['pending', 'partial', 'failed']) ->orWhere(function (Builder $failed) use ($alias): void { $failed->whereNotNull("{$alias}.last_error") ->where("{$alias}.last_error", '!=', ''); @@ -457,12 +458,13 @@ class DingInvoiceDataMirrorRepository $query->where('invoice_count', '>', 0); } elseif (($filters['invoice_state'] ?? 'all') === 'no_invoice') { $query->where('invoice_count', 0) + ->whereIn('scan_status', ['no_invoice', 'recognized', 'imported']) ->where(function (Builder $nested): void { $nested->whereNull('last_error')->orWhere('last_error', ''); }); } elseif (($filters['invoice_state'] ?? 'all') === 'needs_review') { $query->where(function (Builder $nested): void { - $nested->whereIn('scan_status', ['partial', 'failed']) + $nested->whereIn('scan_status', ['pending', 'partial', 'failed']) ->orWhere(function (Builder $failed): void { $failed->whereNotNull('last_error')->where('last_error', '!=', ''); }); @@ -546,10 +548,15 @@ class DingInvoiceDataMirrorRepository 'invoice_total' => $invoice, 'no_invoice_flows' => $rows->filter( static fn (object $row): bool => (int) $row->invoice_count === 0 + && in_array((string) $row->scan_status, ['no_invoice', 'recognized', 'imported'], true) && ($row->last_error === null || $row->last_error === ''), )->count(), 'needs_review_flows' => $rows->filter( - static fn (object $row): bool => in_array((string) $row->scan_status, ['partial', 'failed'], true) + static fn (object $row): bool => in_array( + (string) $row->scan_status, + ['pending', 'partial', 'failed'], + true, + ) || ($row->last_error !== null && $row->last_error !== ''), )->count(), 'invoice_rate' => $payment > 0 ? $invoice / $payment : 0, diff --git a/modules/EcommerceFinance/Services/DingInvoiceSyncService.php b/modules/EcommerceFinance/Services/DingInvoiceSyncService.php index 46a065d0d..7d670732b 100644 --- a/modules/EcommerceFinance/Services/DingInvoiceSyncService.php +++ b/modules/EcommerceFinance/Services/DingInvoiceSyncService.php @@ -157,6 +157,8 @@ class DingInvoiceSyncService public function latestPendingMonth(): ?string { + $this->ensureMissingAvailableMonths(); + $monthQuery = $this->connection->table('ding_invoice_flow_mirror') ->where('source_scope', $this->scope()) ->whereNotNull('process_instance_id') @@ -168,6 +170,52 @@ class DingInvoiceSyncService return trim((string) $month) ?: null; } + private function ensureMissingAvailableMonths(): void + { + $schema = Schema::connection($this->connection->getName()); + if (! $schema->hasTable('ding_process_payment_line_mirror') + || ! $schema->hasTable('ding_process_detail_mirror')) { + return; + } + + $scope = $this->scope(); + $query = $this->connection->table('ding_process_payment_line_mirror as payment') + ->join('ding_process_detail_mirror as detail', function ($join): void { + $join->on('detail.source_scope', '=', 'payment.source_scope') + ->on('detail.business_id', '=', 'payment.business_id'); + }) + ->where('payment.source_scope', $scope) + ->whereNotNull('payment.paid_month') + ->where('payment.paid_month', '!=', '') + ->where( + 'payment.paid_month', + '>=', + (string) config('ding_invoice_data.first_supported_month', '2026-10'), + ) + ->where('payment.paid_month', '<=', now()->format('Y-m')); + DingInvoiceProcessScope::apply($query, 'detail'); + + $months = $query + ->distinct() + ->orderBy('payment.paid_month') + ->pluck('payment.paid_month') + ->map(static fn (mixed $month): string => trim((string) $month)) + ->filter() + ->values(); + + foreach ($months as $month) { + $hasFlows = $this->connection->table('ding_invoice_flow_mirror') + ->where('source_scope', $scope) + ->where('paid_month', $month); + DingInvoiceProcessScope::apply($hasFlows); + if ($hasFlows->exists()) { + continue; + } + + $this->ensureFlowsForMonth($month, $scope); + } + } + private function applyScanCandidates(Builder $query): void { $now = now(); diff --git a/resources/views/business/pages/financial-operations/invoice-data.blade.php b/resources/views/business/pages/financial-operations/invoice-data.blade.php index 65e3e1ffe..452dbb8af 100644 --- a/resources/views/business/pages/financial-operations/invoice-data.blade.php +++ b/resources/views/business/pages/financial-operations/invoice-data.blade.php @@ -9,11 +9,12 @@ $activeView = $invoiceActiveView ?? 'detail'; $startMonth = $invoiceStartMonth ?? '2026-10'; $statusLabels = [ - 'imported' => '已扫描', + 'imported' => '已导入', 'recognized' => '已识别', - 'no_invoice' => '无票', + 'no_invoice' => '已扫描', 'partial' => '部分识别', 'failed' => '识别失败', + 'pending' => '待扫描', ]; $mirrorStatusLabels = [ 'succeeded' => '已同步', @@ -36,6 +37,21 @@ 'invoice_view' => 'attachments', 'per_page' => $invoicePerPage, ])); + $hasInvoiceFlowUrl = $invoicePageUrl . '?' . http_build_query(array_merge($filterQuery, [ + 'invoice_state' => 'has_invoice', + 'invoice_view' => 'flows', + 'per_page' => $invoicePerPage, + ])); + $noInvoiceFlowUrl = $invoicePageUrl . '?' . http_build_query(array_merge($filterQuery, [ + 'invoice_state' => 'no_invoice', + 'invoice_view' => 'flows', + 'per_page' => $invoicePerPage, + ])); + $needsReviewFlowUrl = $invoicePageUrl . '?' . http_build_query(array_merge($filterQuery, [ + 'invoice_state' => 'needs_review', + 'invoice_view' => 'flows', + 'per_page' => $invoicePerPage, + ])); @endphp
@@ -187,6 +203,15 @@ font-weight: 600; } + .invoice-data-status a { + color: var(--invoice-accent-dark); + text-decoration: none; + } + + .invoice-data-status a:hover { + text-decoration: underline; + } + .invoice-data-kpis { display: grid; margin-top: 0.75rem; @@ -203,6 +228,24 @@ border-right: 1px solid var(--invoice-border); } + .invoice-data-kpi.is-link { + display: block; + color: inherit; + text-decoration: none; + transition: background 0.15s ease; + } + + .invoice-data-kpi.is-link:hover { + background: var(--invoice-soft); + } + + .invoice-data-kpi.is-link:focus-visible { + position: relative; + z-index: 2; + outline: 2px solid var(--invoice-accent-dark); + outline-offset: -2px; + } + .invoice-data-kpi:last-child { border-right: 0; } @@ -231,6 +274,15 @@ color: var(--invoice-accent-dark); } + .invoice-data-kpi-action { + display: block; + margin-top: 0.25rem; + color: var(--invoice-accent-dark); + font-size: 0.625rem; + font-style: normal; + line-height: 1.4; + } + .invoice-data-tabs { display: flex; align-items: center; @@ -291,7 +343,7 @@ } .invoice-data-table.is-flow { - min-width: 104rem; + min-width: 110rem; } .invoice-data-table.is-attachments { @@ -786,18 +838,21 @@ @endif · OCR {{ $invoiceOcrConfigured ? '已配置' : '未配置' }} · {{ $invoiceScope }} + · 待复核 {{ number_format((int) ($summary['needs_review_flows'] ?? 0)) }}
-
+ 付款流程 {{ number_format((int) ($summary['flows'] ?? 0)) }} -
-
- 含票流程 + 查看全部流程 + + + 有票流程 {{ number_format((int) ($summary['invoice_flows'] ?? 0)) }} -
+ 查看有票流程 +
发票张数 {{ number_format((int) ($summary['invoice_count'] ?? 0)) }} @@ -815,10 +870,11 @@ title="¥{{ number_format((float) ($summary['payment_amount'] ?? 0), 2) }}" >¥{{ $wan($summary['payment_amount'] ?? 0) }}
-
+ 无票流程 {{ number_format((int) ($summary['no_invoice_flows'] ?? 0)) }} -
+ 查看无票流程 +
开票金额覆盖率 {{ number_format((float) ($summary['invoice_rate'] ?? 0) * 100, 1) }}% @@ -848,7 +904,7 @@ data-invoice-tab="flows" > - 按流程汇总 + 按流程汇总 ({{ number_format($flowRows->total()) }})