@extends('layouts.enterprise') @section('title', 'Mis facturas') @section('content')

Mis facturas

Seguimiento de facturas cargadas y fechas de pago estimadas.

@if(session('ok'))
{{ session('ok') }}
@endif @if($errors->any())
@endif
{{ $invoices->total() }} facturas + Subir nueva factura
@php $hasActiveFilters = (($filters['status'] ?? 'all') !== 'all') || !empty($filters['rc_number'] ?? null) || !empty($filters['project'] ?? null) || !empty($filters['invoice_date_from'] ?? null) || !empty($filters['invoice_date_to'] ?? null) || !empty($filters['payment_date_from'] ?? null) || !empty($filters['payment_date_to'] ?? null); @endphp
Filtros @if($hasActiveFilters) Activos @endif
Limpiar
@foreach($invoices as $inv) @php $rejectionLog = $inv->logs->first(); $isRejected = $inv->status === \App\Models\Invoice::STATUS_REJECTED; $providerMatch = (array) data_get($inv->pipefy_payload, 'provider_match', []); $providerTrackableTotal = (int) ($providerMatch['provider_trackable_items_total'] ?? 0); $providerCoveredAfter = (int) ($providerMatch['provider_items_covered_after'] ?? 0); $providerPendingAfter = (int) ($providerMatch['provider_items_pending_after'] ?? max($providerTrackableTotal - $providerCoveredAfter, 0)); $providerPendingCodesAfter = array_values(array_filter((array) ($providerMatch['provider_pending_codes_after'] ?? []))); $isPartialForProvider = $providerTrackableTotal > 0 ? (bool) ($providerMatch['is_partial_for_provider'] ?? false) : null; $paymentMethod = strtoupper((string) ($inv->cfdi_payment_method ?? data_get($inv->pipefy_payload, 'cfdi_payment_method'))); $paymentForm = strtoupper((string) ($inv->cfdi_payment_form ?? data_get($inv->pipefy_payload, 'cfdi_payment_form'))); $isPpd99 = $paymentMethod === 'PPD' && $paymentForm === '99'; $paymentProofFile = $inv->files->firstWhere('type', \App\Models\InvoiceFile::TYPE_PAYMENT_PROOF); $complementXmlFile = $inv->files->firstWhere('type', \App\Models\InvoiceFile::TYPE_PAYMENT_COMPLEMENT_XML); $complementPdfFile = $inv->files->firstWhere('type', \App\Models\InvoiceFile::TYPE_PAYMENT_COMPLEMENT_PDF); $legacyComplementFile = $inv->files->firstWhere('type', \App\Models\InvoiceFile::TYPE_PAYMENT_COMPLEMENT); $hasComplement = $complementXmlFile || $complementPdfFile || $legacyComplementFile || !empty($inv->payment_complement_uploaded_at); $complementStatus = strtolower((string) ($inv->payment_complement_status ?? '')); $complementRejected = $complementStatus === 'rejected'; $complementApproved = $complementStatus === 'approved'; $complementPendingReview = $hasComplement && !$complementApproved && !$complementRejected; $canUploadComplement = !$isRejected && $inv->status === \App\Models\Invoice::STATUS_PAID && $isPpd99 && (!$hasComplement || $complementRejected); $statusBadgeClass = match ($inv->status) { \App\Models\Invoice::STATUS_RECEIVED => 'badge--status-received', \App\Models\Invoice::STATUS_VALIDATING => 'badge--status-validating', \App\Models\Invoice::STATUS_APPROVED => 'badge--status-approved', \App\Models\Invoice::STATUS_SCHEDULED => 'badge--status-scheduled', \App\Models\Invoice::STATUS_PAID => 'badge--status-paid', \App\Models\Invoice::STATUS_ON_HOLD => 'badge--status-on-hold', \App\Models\Invoice::STATUS_REJECTED => 'badge--rejected', default => '', }; @endphp @endforeach
ID Empresa RC PROJECT NAME Método / Forma Estatus Motivo de cancelación Fecha pago Comprobante de pago Complemento Total
{{ $inv->id }} {{ $inv->company?->legal_name }} {{ $inv->rc_number }}
{{ $inv->pipefyRequest?->project_name ?: '-' }}
Title: {{ $inv->pipefyRequest?->title ?: ($inv->jn_number ?: '-') }}
{{ ($paymentMethod !== '' ? $paymentMethod : '-') }} / {{ ($paymentForm !== '' ? $paymentForm : '-') }} {{ $inv->status }} @if($isPartialForProvider !== null) @if($isPartialForProvider) Parcial proveedor ({{ $providerCoveredAfter }}/{{ $providerTrackableTotal }}, pendientes {{ $providerPendingAfter }}) @if(!empty($providerPendingCodesAfter)) COD pendientes: {{ implode(', ', $providerPendingCodesAfter) }} @endif @else Completa proveedor ({{ $providerCoveredAfter }}/{{ $providerTrackableTotal }}) @endif @endif @if($isRejected) {{ $rejectionLog?->note ?: 'Sin motivo registrado.' }} @else - @endif {{ $isRejected ? '-' : optional($inv->payment_date)->format('Y-m-d') }} @if($isRejected) - @elseif($paymentProofFile) Ver comprobante @elseif(in_array($inv->status, [\App\Models\Invoice::STATUS_APPROVED, \App\Models\Invoice::STATUS_SCHEDULED, \App\Models\Invoice::STATUS_PAID], true)) Sin comprobante @else No aplica @endif @if($isRejected) - @elseif(!$isPpd99) No aplica @elseif($inv->status !== \App\Models\Invoice::STATUS_PAID) Esperando pago @elseif($complementApproved) Aprobado @include('provider.invoices.partials.complement-links', ['xmlFile' => $complementXmlFile, 'pdfFile' => $complementPdfFile, 'legacyFile' => $legacyComplementFile]) @elseif($complementPendingReview) En revisión @include('provider.invoices.partials.complement-links', ['xmlFile' => $complementXmlFile, 'pdfFile' => $complementPdfFile, 'legacyFile' => $legacyComplementFile]) @elseif($complementRejected) Rechazado @if(!empty($inv->payment_complement_review_note)) {{ $inv->payment_complement_review_note }} @endif @include('provider.invoices.partials.complement-links', ['xmlFile' => $complementXmlFile, 'pdfFile' => $complementPdfFile, 'legacyFile' => $legacyComplementFile, 'legacyLabel' => 'Ver último complemento']) @elseif($hasComplement && ($complementXmlFile || $complementPdfFile || $legacyComplementFile)) @include('provider.invoices.partials.complement-links', ['xmlFile' => $complementXmlFile, 'pdfFile' => $complementPdfFile, 'legacyFile' => $legacyComplementFile]) @elseif($hasComplement) Cargado @elseif($canUploadComplement)
@csrf
@else Pendiente @endif
${{ number_format((float) $inv->total, 2) }}
{{ $invoices->onEachSide(1)->links('vendor.pagination.enterprise') }}
@endsection @push('styles') @endpush