@extends('layouts.master') @section('css') @endsection @section('title') تقرير العملاء والاشتراكات الشامل @stop @section('page-header') @endsection @section('content') @if(isset($stats))
العملاء بالتقرير

{{ number_format($stats['filtered_count'] ?? 0) }} / {{ $stats['total_customers'] ?? 0 }}

الفواتير المسددة

{{ number_format($stats['paid_invoices'] ?? 0) }}

فواتير غير مسددة

{{ number_format($stats['unpaid_invoices'] ?? 0) }}

إجمالي التحصيلات

{{ number_format($stats['total_revenue'] ?? 0, 2) }} ريال

@endif
@php $renewalYears = [2024, 2025, 2026, 2027]; @endphp
{{-- أعمدة سنين التجديد --}} @foreach($renewalYears as $year) @endforeach @forelse ($reports as $customer) @php $invoice = $customer->invoices->first(); $saleDetail = $invoice ? $invoice->sales->first() : null; $totalWithTax = $invoice ? ($invoice->cashamount + $invoice->bankamount + $invoice->creaditamount + $invoice->Bank_transfer) : 0; $rawPhone = preg_replace('/[^0-9]/', '', $customer->phone ?? ''); $waPhone = str_starts_with($rawPhone, '05') ? '966' . substr($rawPhone, 1) : $rawPhone; $msgReport = urlencode("السلام عليكم ورحمة الله، أهلاً بك عميلنا العزيز " . ($customer->name ?? '')); @endphp {{-- كود العميل --}} {{-- اسم العميل ورقم الجوال + الرابط وبيانات الدخول كاملة --}} {{-- تاريخ التفعيل (مع الفحص الذكي لتاريخ أقدم فاتورة إن لم يوجد subscription_date) --}} {{-- نوع السيرفر --}} {{-- الفروع والمستخدمين --}} {{-- حالة الاشتراك --}} {{-- حالة الدفع --}} {{-- إجمالي الفاتورة --}} {{-- أعمدة مصفوفة سنين التجديد --}} @foreach($renewalYears as $year) @php $isLocal = ($customer->server_type == 'local') || ($saleDetail && ($saleDetail->software_type ?? '') == 'local'); $firstInvoice = $customer->invoices->sortBy('id')->first(); $firstSale = $firstInvoice ? $firstInvoice->sales->first() : null; $firstYear = null; if ($firstSale && $firstSale->subscription_start_date) { $firstYear = \Carbon\Carbon::parse($firstSale->subscription_start_date)->year; } elseif ($firstInvoice && $firstInvoice->created_at) { $firstYear = \Carbon\Carbon::parse($firstInvoice->created_at)->year; } $currentYearVal = \Carbon\Carbon::now()->year; $yearInvoice = $customer->invoices->first(function($inv) use ($year) { $sale = $inv->sales->first(); $startYear = ($sale && $sale->subscription_start_date) ? \Carbon\Carbon::parse($sale->subscription_start_date)->year : null; $createdYear = $inv->created_at ? \Carbon\Carbon::parse($inv->created_at)->year : null; return $startYear == $year || $createdYear == $year; }); @endphp @endforeach @empty @endforelse
كود العميل العميل / المؤسسة تاريخ التفعيل نوع السيرفر الفروع / المستخدمين حالة الاشتراك حالة الدفع إجمالي الفاتورة تجديد {{ $year }}
#{{ $customer->id }}
@php $isLocalCustomer = ($customer->server_type == 'local') || ($saleDetail && ($saleDetail->software_type ?? '') == 'local'); $hasValidPhone = !empty($customer->phone) && $customer->phone != '0'; @endphp {{-- 1. اسم العميل وبجانبه مباشرة زر فتح النظام أو محلي --}}
{{ $customer->name ?? '---' }} @if($isLocalCustomer) محلي @elseif($customer->website_link) فتح النظام @endif
{{-- 2. رقم الجوال والواتساب (يظهر فقط إذا كان هناك رقم سليم ولا يظهر 0) --}} @if($hasValidPhone)
{{ $customer->phone }}
@endif {{-- 3. بيانات الدخول (الإيميل وكلمة السر) كاملة دون اقتطاع --}} @if(!$isLocalCustomer && $customer->admin_credentials)
{{ $customer->admin_credentials }}
@endif
@php $activationDate = $customer->subscription_date; if (!$activationDate && $customer->invoices && $customer->invoices->isNotEmpty()) { $oldestInvoice = $customer->invoices->last(); $activationDate = $oldestInvoice->created_at ?? $oldestInvoice->invoice_date ?? $oldestInvoice->date; } @endphp {{ $activationDate ? \Carbon\Carbon::parse($activationDate)->format('Y-m-d') : '---' }} @if($customer->server_type == 'new') جديد @elseif($customer->server_type == 'old') قديم @elseif($customer->server_type == 'local') محلي @else --- @endif
{{ $saleDetail->branches_count ?? '1' }} فرع | {{ $saleDetail->users_count ?? '1' }} مستخدم
@if($customer->is_suspended == 1) موقوف @else @if($saleDetail) @if(($saleDetail->software_type ?? 'cloud') == 'local')
مدى الحياة {{ $saleDetail->subscription_start_date ?? '---' }}
@else @if($saleDetail->subscription_end_date) @if(\Carbon\Carbon::parse($saleDetail->subscription_end_date)->isPast()) منتهي @else نشط @endif @else --- @endif @endif @else --- @endif @endif
@if($invoice) {{ $invoice->payment_status == 1 ? 'تم الدفع' : 'معلقة' }} @else --- @endif {{ number_format($totalWithTax, 2) }} ريال @if(!$firstYear || $year < $firstYear) لا يوجد @elseif($isLocal && $year > $firstYear) مدى الحياة @elseif($year > $currentYearVal) @if($yearInvoice && $yearInvoice->payment_status == 1) تم الدفع @else قيد الانتظار @endif @else @if($yearInvoice) @if($yearInvoice->payment_status == 1) تم الدفع @else لم يدفع @endif @else لم يجدد @endif @endif

لا توجد سجلات عملاء تطابق الفلاتر المحددة حالياً.

{{ $reports->links() }}
@endsection