@extends('layouts.master') @section('css') @endsection @section('title') {{ __('home.home') }} @stop @section('page-header')
@endsection @section('content') @php // لو الصفحة اتفتحت من غير DashboardController (مثلاً /index) نرجّعها للداشبورد $dbDirect = !isset($all); if ($dbDirect) { $all = array_fill_keys(['trx_today_count','trx_today_amount','trx_yest_count','trx_month_count','trx_month_amount','liq_today_count','liq_today_amount','liq_yest_count','liq_month_count','liq_month_amount','liq_today_confirmed','liq_today_unconfirmed','liq_month_confirmed','liq_month_unconfirmed'], 0); $chart = null; $accounts = collect(); $custody = collect(); $recentTrx = collect(); $recentLiq = collect(); $branch = null; $isAdminBranch = false; $fleet = null; $wb = ['enabled' => false, 'today' => 0, 'month' => 0, 'month_fare' => 0, 'recent' => collect()]; } $ar = App::getLocale() == 'ar'; $t = function ($a, $e) use ($ar) { return $ar ? $a : $e; }; $sar = __('home.SAR'); $h = (int) date('G'); $greet = $h < 12 ? $t('صباح الخير', 'Good morning') : ($h < 18 ? $t('مساء الخير', 'Good afternoon') : $t('مساء النور', 'Good evening')); $delta = function ($now, $prev) { if ($prev == 0 && $now == 0) return ['flat', '0%']; if ($prev == 0) return ['up', '+100%']; $p = round((($now - $prev) / $prev) * 100); return [$p > 0 ? 'up' : ($p < 0 ? 'down' : 'flat'), ($p > 0 ? '+' : '') . $p . '%']; }; $palette = ['#3B82F6', '#D6AE62', '#10B981', '#F59E0B', '#14B8A6', '#8B5CF6', '#EF4444']; @endphp @if ($dbDirect)@endif
{{-- ================= HERO ================= --}}
{{ $greet }}

{{ $t('أهلاً', 'Welcome') }}، {{ Auth::user()->name }} 👋

{{ $t('ده ملخص سريع لأداء النشاط النهارده', "Here's a quick overview of today's activity") }} {{ ($isAdminBranch ?? false) ? $t('بيانات كل الفروع', 'All branches') : $t('بيانات فرعك فقط', 'Your branch only') }}

--:--:--
·
{{-- ================= حالة الأسطول (لكل المستخدمين) ================= --}} @if (!empty($fleet))

{{ $t('حالة الشاحنات', 'Fleet status') }}

{{ $t('لوحة الشاحنات', 'Truck board') }}
{{ $t('الشاحنات المتاحة في كل منطقة (ملك المؤسسة)', 'Available own trucks by region') }}
@foreach ($fleet['byRegion'] as $reg => $cnt) @if ($reg !== 'غير محدد' || $cnt > 0)
{{ $cnt }} {{ $reg }}
@endif @endforeach
{{ $t('الشاحنات المحمّلة', 'Loaded trucks') }} {{ $fleet['loaded'] }} {{ $t('شحنة جديدة', 'New shipment') }}
@forelse ($fleet['loadedList']->take(8) as $trip)
{{ optional($trip->truck)->plate_number }}
{{ $trip->from_region }} {{ $trip->to_region }} {{ $trip->load_type }}{{ $trip->driver_name ? ' · ' . $trip->driver_name : '' }}{{ optional($trip->driver)->phone ? ' · ' . $trip->driver->phone : '' }}
@if (optional($trip->driver)->phone) @endif
@if ($trip->is_overdue) {{ $t('متأخرة', 'Overdue') }}@endif {{ optional($trip->expected_unloading_at)->format('m/d h:i A') }}
@empty
{{ $t('مفيش شاحنات محمّلة دلوقتي', 'No loaded trucks right now') }}
@endforelse @if ($fleet['loaded'] > 8) {{ $t('عرض الكل', 'View all') }} ({{ $fleet['loaded'] }}) @endif
@endif @can('Home') {{-- ================= KPIs ================= --}} @php $d1 = $delta($all['trx_today_count'], $all['trx_yest_count']); $d2 = $delta($all['liq_today_count'], $all['liq_yest_count']); @endphp
{{ $d1[1] }}
{{ __('home.salesdoday') }}
0{{ __('home.invoice') }}
{{ __('home.TODAYEARNINGS') }}0 {{ $sar }}
{{ $t('الشهر', 'Month') }}
{{ __('home.TOTAL_EARNINGS_Month') }}
0{{ $sar }}
{{ __('home.PRODUCT_number_SOLD') }}0 {{ __('home.invoice') }}
{{ $d2[1] }}
{{ __('home.liquitiondoday') }}
0{{ __('home.invoice') }}
{{ __('home.TODAYEARNINGS_liquition') }}0 {{ $sar }}
{{ $t('بوليصات الشحن', 'Waybills') }}
{{ $t('بوليصات اليوم', 'Waybills today') }}
0{{ $t('بوليصة', 'waybills') }}
{{ $t('الشهر', 'Month') }}: 00 {{ $sar }}
{{-- ================= Charts ================= --}}
{{ $t('التحويلات مقابل التصفيات', 'Transfers vs Liquidations') }} {{ $t('آخر 7 أيام', 'Last 7 days') }}
{{ $t('عدد العمليات اليومية', 'Daily operations count') }}
@php $tc = $all['liq_today_confirmed']; $tu = $all['liq_today_unconfirmed']; $tt = max(1, $tc + $tu); $mc = $all['liq_month_confirmed']; $mu = $all['liq_month_unconfirmed']; $mt = max(1, $mc + $mu); @endphp
{{ __('home.liquitiondoday_confirm') }} / {{ __('home.liquitiondoday_notconfirm') }}
{{ $t('حالة التصفيات اليوم والشهر', 'Liquidation status today & this month') }}
{{ __('home.liquitiondoday_confirm') }}
0
{{ __('home.liquitiondoday_confirm_month') }}: {{ $mc }}
{{ __('home.liquitiondoday_notconfirm') }}
0
{{ __('home.liquitiondoday_notconfirm_month') }}: {{ $mu }}
{{-- ================= Accounts ================= --}} @if ($accounts->count())

{{ $t('الحسابات المالية', 'Financial accounts') }}

{{ $accounts->count() }}
@foreach ($accounts as $k => $acc)
{{ mb_substr(trim($acc->name), 0, 1) }}
{{ $acc->name }}
@endforeach
{{ $t('العهد', 'Custody') }}
{{ $t('أرصدة حسابات العهدة', 'Custody account balances') }}
@endif {{-- ================= Recent ================= --}}
@if ($wb['enabled'])
{{ $t('أحدث بوليصات الشحن', 'Latest waybills') }} {{ ($isAdminBranch ?? false) ? $t('كل الفروع', 'All branches') : $t('فرعك', 'Your branch') }} {{ $t('عرض الكل', 'View all') }}
@forelse ($wb['recent'] as $w) @empty @endforelse
#{{ $t('العميل', 'Customer') }}{{ $t('السائق', 'Driver') }}{{ $t('المدينة', 'City') }}{{ $t('الأجرة', 'Fare') }}
{{ $w->waybill_no }} {{ \Illuminate\Support\Str::limit($w->customer_name, 22) }} {{ \Illuminate\Support\Str::limit($w->driver_name, 18) }} {{ $w->destination_city }} {{ number_format($w->total_fare, 2) }}
{{ $t('لا توجد بوليصات بعد', 'No waybills yet') }}
@endif
{{ $t('أحدث التحويلات', 'Latest transfers') }} {{ ($isAdminBranch ?? false) ? $t('كل الفروع', 'All branches') : $t('فرعك', 'Your branch') }} {{ $t('عرض الكل', 'View all') }}
@forelse ($recentTrx as $tr) @empty @endforelse
#{{ $t('المحوَّل له', 'Transferred to') }}{{ $t('المبلغ', 'Amount') }}{{ $t('التاريخ', 'Date') }}
{{ $tr->id }}
{{ \Illuminate\Support\Str::limit($tr->to_name ?: '—', 28) }}
@if ($tr->from_name || $tr->by_name)
@if ($tr->from_name){{ $t('من', 'From') }}: {{ \Illuminate\Support\Str::limit($tr->from_name, 24) }}@endif @if ($tr->by_name)· {{ $t('بواسطة', 'by') }} {{ $tr->by_name }}@endif
@endif
{{ number_format((float) $tr->price, 2) }} {{ $tr->date ? \Carbon\Carbon::parse($tr->date)->format('Y/m/d') : optional($tr->created_at)->format('Y/m/d') }}
{{ $t('لا توجد تحويلات', 'No transfers') }}
{{-- ================= Recent liquidations (الإدارة) ================= --}}
{{ $t('أحدث التصفيات', 'Latest liquidations') }} {{ ($isAdminBranch ?? false) ? $t('كل الفروع', 'All branches') : $t('فرعك', 'Your branch') }} {{ $t('عرض الكل', 'View all') }}
@forelse ($recentLiq ?? [] as $lq) @empty @endforelse
#{{ $t('النوع', 'Type') }}{{ $t('الفرع', 'Branch') }}{{ $t('بواسطة', 'By') }} {{ $t('المبلغ', 'Amount') }}{{ $t('الحالة', 'Status') }}{{ $t('التاريخ', 'Date') }}
{{ $lq->id }} @if ($lq->type == 1) {{ __('home.liquidation_shipments') }} @elseif ($lq->type == 2) {{ __('home.liquidation_purchase') }} @else — @endif {{ optional($lq->branch)->name ?? '—' }} {{ optional($lq->user)->name ?? '—' }} {{ number_format((float) $lq->price_filtering, 2) }} @if ($lq->status == 2) {{ __('home.confirm_done') }} @elseif ($lq->status == 3) {{ __('home.pratiail_of_review') }} @else {{ __('home.data_complete') }} @endif {{ optional($lq->created_at)->format('Y/m/d') }} @if ($lq->type == 1) @elseif ($lq->type == 2) @endif
{{ $t('لا توجد تصفيات', 'No liquidations') }}
@endcan {{-- ================= Branch ================= --}} @if ($branch)

{{ $t('أداء فرعي', 'My branch') }}

{{ $t('فرعي', 'Branch') }}
{{ $t('اليوم', 'Today') }}
{{ __('home.salesdoday') }}
0{{ __('home.invoice') }}
{{ __('home.TODAYEARNINGS') }}0 {{ $sar }}
{{ $t('الشهر', 'Month') }}
{{ __('home.TOTAL_EARNINGS_Month') }}
0{{ $sar }}
{{ __('home.PRODUCT_number_SOLD') }}0
{{ $t('اليوم', 'Today') }}
{{ __('home.liquitiondoday') }}
0{{ __('home.invoice') }}
{{ $branch['liq_today_confirmed'] }} {{ $branch['liq_today_unconfirmed'] }}
{{ $t('الشهر', 'Month') }}
{{ __('home.PRODUCT_number_SOLD_liquition') }}
0{{ __('home.invoice') }}
{{ $branch['liq_month_confirmed'] }} {{ $branch['liq_month_unconfirmed'] }}
@endif
@include('trucks._unload_quick') @include('trucks._load_quick') @endsection @section('js') @endsection