@extends('layouts.app') @section('title', 'Manajemen Invoice - MCU Klinik Mustika') @section('breadcrumb')

Manajemen Invoice

@endsection @section('content') @if (session('success')) @endif @if (session('error')) @endif
@canRoute ('invoices.create') Buat Invoice Baru @endcanRoute @canRoute ('invoices.bulk-delete') @endcanRoute
Filter Perusahaan
Filter Status Invoice
Filter Bulan
Filter Tahun
Total Perusahaan

{{ number_format($stats['total_companies']) }}

Sesuai filter aktif
Total Invoice

{{ number_format($stats['total_invoices']) }}

{{ number_format($stats['total_invoice_breakdown']['mcu'] ?? 0) }} Invoice MCU @if (($stats['total_invoice_breakdown']['health'] ?? 0) > 0) {{ number_format($stats['total_invoice_breakdown']['health']) }} Invoice Surat Keterangan Sehat @endif @if (($stats['total_invoice_breakdown']['drug'] ?? 0) > 0) {{ number_format($stats['total_invoice_breakdown']['drug']) }} Invoice Surat Pemeriksaan Narkoba @endif
Total Nilai

Rp {{ number_format($stats['total_amount'], 0, ',', '.') }}

Nilai semua invoice sesuai filter
Belum Lunas

Rp {{ number_format($stats['pending_amount'], 0, ',', '.') }}

Invoice draft & terkirim sesuai filter
Status Invoice
Draft: {{ $stats['status_counts']['draft'] ?? 0 }} Terkirim: {{ $stats['status_counts']['sent'] ?? 0 }} Lunas: {{ $stats['status_counts']['paid'] ?? 0 }}
Jatuh Tempo

{{ $stats['overdue_count'] }}

Invoice jatuh tempo sesuai filter
@include('partials.tables.filters', [ 'paginator' => $companies, 'tableFilters' => ['month', 'year', 'company_id', 'status', 'sort', 'direction'] ])
@csrf
@forelse ($companies as $index => $company) @php $companyInvoices = $company->invoices; $totalInvoices = $companyInvoices->count(); $baseTotalAmount = $company->deduped_base_total_amount ?? $companyInvoices->sum('total_amount'); $letterTotalAmount = $company->letter_invoice_total_amount ?? 0; $totalAmount = $baseTotalAmount + $letterTotalAmount; $lastInvoice = $companyInvoices->sortByDesc('created_at')->first(); $pendingAmount = ($company->deduped_pending_base_amount ?? $companyInvoices->whereIn('status', ['draft', 'sent'])->sum('total_amount')) + ($company->letter_invoice_pending_amount ?? 0); $overdueCount = $companyInvoices->where('status', '!=', 'paid')->where('due_date', '<', now())->count(); // Hitung status terakhir berdasarkan invoice terbaru $draftCount = $companyInvoices->where('status', 'draft')->count(); $sentCount = $companyInvoices->where('status', 'sent')->count(); $paidCount = $companyInvoices->where('status', 'paid')->count(); $overdueCount = $companyInvoices->where('status', '!=', 'paid')->where('due_date', '<', now())->count(); // Ambil bulan dari invoice terbaru dalam bahasa Indonesia $latestMonth = '-'; if ($lastInvoice) { $months = [ 1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April', 5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Desember', ]; $monthNum = $lastInvoice->invoice_date->month; $year = $lastInvoice->invoice_date->year; $latestMonth = $months[$monthNum] . ' ' . $year; } @endphp @empty @endforelse
No. @include('partials.tables.sort_link', ['column' => 'name', 'label' => 'Nama Perusahaan']) Kontak Total Invoice Total Nilai Bulan Status Terakhir Aksi
{{ $companies->firstItem() + $index }}
{{ $company->name }}
{{ $company->address ?? '-' }}
{{ $company->email ?? '-' }}
{{ $company->phone ?? '-' }}
@php $letterCounts = $company->letter_invoice_counts ?? ['health' => 0, 'drug' => 0]; $totalLetterInvoices = array_sum($letterCounts); $totalAllInvoices = $totalInvoices + $totalLetterInvoices; @endphp
{{ $totalAllInvoices }} invoice {{ $totalInvoices }} Invoice MCU @if (($letterCounts['health'] ?? 0) > 0) {{ $letterCounts['health'] }} Invoice Surat Keterangan Sehat @endif @if (($letterCounts['drug'] ?? 0) > 0) {{ $letterCounts['drug'] }} Invoice Surat Pemeriksaan Narkoba @endif
Rp {{ number_format($totalAmount, 0, ',', '.') }} @if ($pendingAmount > 0)
Rp {{ number_format($pendingAmount, 0, ',', '.') }} belum lunas @endif
{{ $latestMonth }}
@if ($draftCount > 0) {{ $draftCount }} Draft @endif @if ($sentCount > 0) {{ $sentCount }} Terkirim @endif @if ($paidCount > 0) {{ $paidCount }} Lunas @endif @if ($overdueCount > 0) {{ $overdueCount }} Jatuh Tempo @endif
@canRoute ('invoices.company') @endcanRoute
{{ $companies->links('partials.tables.pagination') }}
@endsection @push('styles') @endpush @push('scripts') @endpush