{{--
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') }}
{{-- 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) }}
{{-- 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. --}}
{{-- 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}) --}}