@extends('layouts.dashboard') @section('content') @php use App\Models\Order; /** * Vendor CRM → one customer's relationship with THIS restaurant: profile, * lifetime KPIs, the reviews they left here, and their recent orders. Built * entirely from shared dashboard components (.qm-card / kpi-card / .qm-table) * to match the admin user-detail page. * * @var array $cust the aggregated customer row (scoped to this restaurant) * @var int $points loyalty balance at this restaurant * @var float $aov average paid order value * @var array $reviews reviews this customer left for this restaurant * @var array $orders their most recent orders here * @var array $reviewsPager @var array $ordersPager panel_pager() metadata per table * @var array|null $restaurant */ $loyLabel = (string) ($restaurant['loyalty_points_label'] ?? 'points'); $payPill = ['paid' => 'qm-pill-green', 'unpaid' => 'qm-pill-grey', 'refunded' => 'qm-pill-red']; $pillClass = ['approved' => 'qm-pill-green', 'pending' => 'qm-pill-amber']; // What this customer is worth is a takings figure, so it follows the owner boundary the // list page and the analytics equivalent already draw. $showMoney = $showMoney ?? true; @endphp @php /* .qm-d2: the dashboard density standard (app.css §35) */ @endphp
{{ t_raw('vendor.customerdetail.back') }}
@php /* The guest's identity wears the same hero every profile page wears now: brand-wash band over the facts as one measured stat band. */ @endphp
{!! brandmark_html($cust['avatar'] ?? null, (string) $cust['name'], 'lg', 'qm-brandmark--round') !!}

{{ $cust['name'] }}

@if ($reviews)
{{ t_raw('vendor.customerdetail.reviewer_pill') }}
@endif
{{ t_raw('common.email') }}
{!! or_dash($cust['email'] ?? null) !!}
{{ t_raw('common.phone') }}
{!! or_dash($cust['phone'] ?? null) !!}
{{ t_raw('vendor.customerdetail.member_since') }}
{!! fmt_day($cust['created_at']) !!}
{{ t_raw('vendor.customerdetail.first_order') }}
{!! fmt_day($cust['first_order']) !!}
@partial('kpi-card', ['accent' => 'blue', 'icon' => 'fa-receipt', 'label' => t_raw('common.orders'), 'value' => number_format((int) $cust['orders_c'])]) @if ($showMoney) @partial('kpi-card', ['accent' => 'green', 'icon' => 'fa-wallet', 'label' => t_raw('vendor.customerdetail.kpi_spent'), 'value' => money($cust['spend'])]) @partial('kpi-card', ['accent' => 'violet', 'icon' => 'fa-chart-line', 'label' => t_raw('common.average_order'), 'value' => money($aov)]) @endif @partial('kpi-card', ['accent' => 'amber', 'icon' => 'fa-gift', 'label' => t_raw('vendor.analytics.col_loyalty_balance'), 'value' => number_format($points) . ' ' . $loyLabel])
@if (!empty($showMoney)) @php $credit = (float) ($credit ?? 0); $debt = (float) ($debt ?? 0); $creditLimit = (float) ($creditLimit ?? 0); $walletHistory = $walletHistory ?? []; @endphp

{{ t_raw('vendor.customerdetail.wallet_heading') }}

@partial('kpi-card', ['accent' => 'green', 'icon' => 'fa-hand-holding-usd', 'label' => t_raw('vendor.customerdetail.wallet_credit'), 'value' => money($credit)]) @partial('kpi-card', ['accent' => 'amber', 'icon' => 'fa-file-invoice-dollar', 'label' => t_raw('vendor.customerdetail.wallet_debt'), 'value' => money($debt)]) @partial('kpi-card', ['accent' => 'slate', 'icon' => 'fa-tachometer-alt', 'label' => t_raw('vendor.customerdetail.wallet_limit'), 'value' => $creditLimit > 0 ? money($creditLimit) : t_raw('vendor.customerdetail.wallet_no_limit')])
@if (!empty($canWallet))
@csrf
@endif
@if ($walletHistory) @foreach ($walletHistory as $wt) @php $amt = (float) $wt['amount']; @endphp @endforeach @else @partial('table-empty', ['colspan' => 3, 'icon' => 'fa-wallet', 'msg' => t('vendor.customerdetail.wallet_no_history')]) @endif
{{ t_raw('common.note') }} {{ t_raw('common.amount') }} {{ t_raw('admin.reviews.col_posted') }}
{!! or_dash($wt['note'] ?? null) !!} {{ $amt < 0 ? '−' : '+' }}{{ money(abs($amt)) }} {!! fmt_day($wt['created_at']) !!}
@endif

{{ t_raw('vendor.customerdetail.reviews_heading') }}

@if ($reviews) @foreach ($reviews as $rv) @endforeach @else @partial('table-empty', ['colspan' => 5, 'icon' => 'fa-star', 'msg' => t('vendor.customerdetail.no_reviews')]) @endif
{{ t_raw('common.rating') }}{{ t_raw('vendor.customerdetail.col_comment') }}{{ t_raw('vendor.orders.col_order') }}{{ t_raw('common.status') }}{{ t_raw('admin.reviews.col_posted') }}
{!! rating_stars_html((float) (int) $rv['rating']) !!} {!! or_dash($rv['comment'] ?? null) !!} @if (!empty($rv['order_id'])){{ (string) $rv['order_number'] }}@else{!! or_dash($rv['order_number'] ?? null) !!}@endif {{ status_label('review', (string) $rv['status']) }} {!! fmt_day($rv['created_at']) !!}
@partial('table-toolbar', ['pager' => $reviewsPager])

{{ t_raw('vendor.customerdetail.orders_heading') }}

@if ($orders) @foreach ($orders as $o) @endforeach @else @partial('table-empty', ['colspan' => 5, 'icon' => 'fa-receipt', 'msg' => t('vendor.customerdetail.no_orders')]) @endif
{{ t_raw('vendor.orders.col_order') }}{{ t_raw('common.status') }}{{ t_raw('admin.orders.col_payment') }}{{ t_raw('common.total') }}{{ t_raw('admin.orders.col_placed') }}
{{ $o['order_number'] }} {{ Order::statusLabel((string) $o['status'], (string) ($o['service_mode'] ?? 'delivery')) }} {{ t_raw('status.payment.' . $o['payment_status']) }} {{ money($o['total']) }} {!! fmt_datetime($o['placed_at']) !!}
@partial('table-toolbar', ['pager' => $ordersPager])
@php /* /.qm-d2 */ @endphp @endsection