{{-- Sales Pipeline — server-rendered Kanban board. Columns = pipeline stages, cards = deals. Drag a card to another column → PATCH /deals/{id}/stage (user-deals-board.js). Per-column totals + a weighted forecast (value × stage probability) sit in the header. Contact phone numbers are always masked (mask_phone()). --}}
@php // Currency list + symbols are DYNAMIC from the admin's active currencies // (Admin → Currencies) so e.g. IDR shows up for Indonesian workspaces // instead of a hard-coded INR/USD/EUR/GBP/AED list. Falls back to a sane // set if the table is empty. // 100% dynamic from the admin Currencies table — no hard-coded list. Add a // currency in Admin → Currencies and it appears here (e.g. IDR). $dealCurrencies = \App\Models\Currency::active()->orderBy('code')->pluck('code')->map(fn($c) => strtoupper($c))->all(); // Keep the pipeline's own stored currency selectable even if it was later // deactivated in admin (so existing deals still render). if (!empty($pipeline->currency) && !in_array(strtoupper($pipeline->currency), $dealCurrencies, true)) { array_unshift($dealCurrencies, strtoupper($pipeline->currency)); } $dealSymMap = \App\Models\Currency::pluck('symbol', 'code')->mapWithKeys(fn($s, $c) => [strtoupper($c) => $s])->all(); // Use the dynamic display currency the controller resolved (workspace // setting → platform default), not the pipeline's stored code. $sym = $dealSymMap[$currency] ?? ($currency.' '); // Deterministic avatar palette + source-pill map (decorative). $palette = ['bg-accent-coral','bg-wa-teal','bg-accent-amber','bg-wa-deep','bg-accent-plum','bg-accent-sky']; $srcMap = [ 'order' => ['label'=>'Order', 'pill'=>'bg-wa-bubble text-wa-deep', 'icon'=>'bg-wa-green'], 'inbox' => ['label'=>'WhatsApp', 'pill'=>'bg-wa-bubble text-wa-deep', 'icon'=>'bg-wa-green'], 'shopify' => ['label'=>'Shopify', 'pill'=>'bg-accent-plum/15 text-accent-plum', 'icon'=>'bg-accent-plum'], 'woo' => ['label'=>'WooCommerce','pill'=>'bg-accent-sky/15 text-accent-sky', 'icon'=>'bg-accent-sky'], 'form' => ['label'=>'Form', 'pill'=>'bg-accent-amber/20 text-[#8B5A14]', 'icon'=>'bg-accent-amber'], 'api' => ['label'=>'API', 'pill'=>'bg-paper-100 text-ink-600', 'icon'=>'bg-ink-500'], 'manual' => ['label'=>'Manual', 'pill'=>'bg-paper-100 text-ink-600', 'icon'=>'bg-ink-400'], // Every value in Deal::SOURCES needs a row here — an unmapped source // silently falls back to the 'Manual' pill (line ~135). 'flow' => ['label'=>'Flow', 'pill'=>'bg-wa-mint/40 text-wa-deep', 'icon'=>'bg-wa-teal'], 'facebook' => ['label'=>'Messenger', 'pill'=>'bg-accent-sky/15 text-accent-sky', 'icon'=>'bg-accent-sky'], ]; @endphp {{-- Header --}}
{{ __('Sales') }} {{ __('Pipeline of opportunities') }}

{{ __('Deals') }} {{ __('pipeline') }}

{{-- Always rendered, even with one pipeline: it is also how you reach "New pipeline", which is why extra boards were unreachable before. --}} {{ __('Reports') }}
{{-- KPI strip --}}
{{ __('Open pipeline') }}
{{ $kpis['open_value'] }}
{{ $kpis['open_count'] }} {{ __('deals') }}
{{ __('Weighted forecast') }}
{{ $kpis['forecast'] }}
{{ __('by probability') }}
{{ __('Won · this month') }}
{{ $kpis['won_value'] }}
{{ $kpis['won_this_month'] }} {{ __('deals') }}
{{ __('Win rate') }}
{{ $kpis['win_rate'] }}%
{{ __('won vs lost') }}
{{ __('Open deals') }}
{{ $kpis['open_count'] }}
{{ __('in pipeline') }}
{{-- Filters --}}
@if($filters['q'] || $filters['owner'] || $filters['source']) {{ __('Clear') }} @endif
{{-- Board --}}
@foreach($columns as $col) @php $stage = $col['stage']; $colCls = $stage->is_won ? 'dl-col-won' : ($stage->is_lost ? 'dl-col-lost' : ''); @endphp
{{ $stage->name }} {{ $col['count'] }}
{{ $sym }}{{ number_format($col['value_minor']/100, 0) }}
@forelse($col['deals'] as $deal) @php $c = $deal->contact; $who = $c && $c->id ? ($c->name ?: trim(($c->first_name ?? '').' '.($c->last_name ?? '')) ?: mask_phone((string)($c->country_code.$c->mobile))) : null; $src = $srcMap[$deal->source] ?? $srcMap['manual']; $ownerName = $deal->owner && $deal->owner->id ? $deal->owner->name : ($who ?: 'Deal'); $initials = collect(preg_split('/\s+/', trim($ownerName)))->filter()->take(2)->map(fn($w)=>mb_substr($w,0,1))->implode(''); $avColor = $palette[abs(crc32((string)$ownerName)) % count($palette)]; $prob = (int) $stage->probability; $showProg = !$stage->is_won && !$stage->is_lost && $prob > 0 && $prob < 100; $age = $deal->created_at ? $deal->created_at->diffForHumans(['short'=>true,'parts'=>1,'syntax'=>\Carbon\CarbonInterface::DIFF_ABSOLUTE]) : ''; @endphp
@if($stage->is_won) {{ __('Closed won') }} @elseif($stage->is_lost) {{ __('Lost') }} @else {{ $src['label'] }} @endif {{ $age }}
{{ $deal->title }}
@if($who)
{{ $who }}
@endif @if($showProg)
@endif
{{-- Converted to the workspace display currency so the card matches the column total + KPIs (no $ total over ₹ cards). --}} {{ $sym }}{{ number_format(($deal->display_minor ?? 0) / 100, 2) }}
@if($showProg){{ $prob }}%@endif {{ mb_strtoupper($initials ?: '–') }}
@empty
{{ __('No deals yet') }}
@endforelse
@endforeach
{{-- New-deal modal --}}

{{ __('New deal') }}

{{-- Pipeline settings — tabbed. "Automation" is the original auto-deal-from- orders form; Stages / Lost reasons / Pipeline are the management surfaces the schema always supported but nothing ever exposed. --}}

{{ __('Pipeline settings') }}

{{ $pipeline->name }}

@foreach([ 'stages' => __('Stages'), 'lost' => __('Lost reasons'), 'fields' => __('Custom fields'), 'pipeline' => __('Pipeline'), 'automation'=> __('Automation'), ] as $key => $label) @endforeach
{{-- Stages --}}

{{ __('Drag to reorder. Probability drives the weighted forecast.') }}

@foreach($columns as $col) @php $s = $col['stage']; @endphp
@endforeach
{{-- Lost reasons --}} {{-- Custom fields — definitions only; values are edited on each deal. --}} {{-- Pipeline --}} {{-- Automation (original settings form, unchanged) --}}
{{-- Mark Lost — renders a picklist when the pipeline configures reasons, otherwise a free-text box (the pre-existing behaviour). --}}

{{ __('Mark this deal lost') }}

{{ __('Recording why helps the pipeline report show what is costing you deals.') }}

{{-- Move-deals prompt, shared by stage + pipeline deletion. The server refuses to strand deals; this is where the operator names the destination. --}}

{{ __('Move the deals first') }}

{{-- Deal detail slide-over (body rendered by user-deals-board.js from /deals/{id}) --}}
{{ __('Loading…') }}