@extends('layouts.app') @section('title', $deal->deal_no) @section('heading', 'Deal '.$deal->deal_no) @section('content') @php $st = $deal->status; $kes = fn ($v) => 'KSh '.number_format((float) $v, 2); $isFinance = $deal->payment_type === 'finance'; $balance = $deal->balance_due; $docs = $deal->documents->where('status', 'issued')->keyBy('type'); @endphp

{{ $st->label() }} {{ $isFinance ? 'Finance' : 'Cash' }} deal· {{ $deal->salesperson?->name }} · started {{ $deal->created_at->format('d M Y') }}

{{ $deal->customer->name }} · {{ $deal->vehicle->display_name }}

{{ $deal->vehicle->stock_id }} · {{ $deal->vehicle->vin }} @can('customers.view')· Customer profile@endcan @if ($deal->lead_id) · Lead@endif

@if (in_array($st, [\App\Enums\DealStatus::Draft, \App\Enums\DealStatus::Approved])) @can('deals.edit')Edit terms@endcan @endif @if ($st === \App\Enums\DealStatus::Draft) @can('deals.edit')
@csrf
@endcan @endif
{{-- What needs doing next --}} @if ($st === \App\Enums\DealStatus::Draft && $policy['level'])

The discount of {{ $policy['percent'] }}% needs {{ $policy['level'] }} approval ({{ $policy['below_minimum'] ? 'it takes the price below the vehicle\'s minimum' : 'over the '.$policy['manager_limit'].'% limit' }}{{ $policy['level'] === 'director' ? '; above '.$policy['director_limit'].'% or below cost needs a director' : '' }}). Add a reason, then submit.

@endif @if ($currentApproval)

Waiting for {{ $currentApproval->level }} approval

{{ $currentApproval->discount_percent }}% off ({{ $kes($currentApproval->discount_amount) }}), requested by {{ $currentApproval->requester?->name }}. @if ($currentApproval->below_minimum) Below the vehicle's minimum price. @endif Reason: {{ $currentApproval->reason }}

@can('deals.approve_discount') @if (auth()->user()->can(\App\Services\DiscountPolicy::permissionFor($currentApproval->level)))
Approve
@csrf
Decline
@csrf
@endif @endcan @can('deals.edit')
@csrf
@endcan
@endif
{{-- Money --}}

Price

Vehicle price
{{ $kes($deal->list_price) }}
@if (bccomp((string) $deal->discount_amount, '0', 2) > 0)
Discount ({{ $policy['percent'] }}%){{ $deal->discount_reason ? ' · '.$deal->discount_reason : '' }}
− {{ $kes($deal->discount_amount) }}
@endif @foreach ($deal->items as $i)
{{ $i->description }}{{ $i->quantity > 1 ? ' × '.$i->quantity : '' }}
{{ $kes($i->line_total) }}
@endforeach @if (bccomp((string) $deal->tax_amount, '0', 2) > 0)
{{ $deal->taxRate?->name ?? 'Tax' }} {{ $deal->tax_inclusive ? '(included)' : '(added)' }}
{{ $kes($deal->tax_amount) }}
@endif
Total price
{{ $kes($deal->grand_total) }}
@if ($deal->tradeIn)
Trade-in: {{ $deal->tradeIn->display_name }}
− {{ $kes($deal->trade_in_credit) }}
@endif
Deposit required
{{ $kes($deal->deposit_required) }}
Received so far
{{ $kes($deal->paid) }}
Balance due
{{ bccomp($balance, '0', 2) <= 0 ? 'Paid in full' : $kes($balance) }}
@can('deals.view_margin')

Margin on the vehicle (price after discount less landed cost): {{ $kes(bcsub((string) $deal->net_price, (string) $deal->vehicle->landed_cost, 2)) }}

@endcan
@if ($isFinance && $quote['finance'])

Financing

Amount financed
{{ $kes($quote['finance']['principal']) }}
Monthly instalment
{{ $kes($quote['finance']['installment']) }}
Rate and term
{{ rtrim(rtrim($deal->interest_rate, '0'), '.') }}% {{ $deal->interest_method === 'flat' ? 'flat' : 'reducing' }} · {{ $deal->term_months }} mo
True yearly cost
{{ $deal->effective_rate }}%
Total interest
{{ $kes($quote['finance']['total_interest']) }}
Total to repay
{{ $kes($quote['finance']['total_repayable']) }}
Lender
{{ $deal->financier_name ?: 'Not set' }}{{ $deal->financier_reference ? ' · '.$deal->financier_reference : '' }}
Payment schedule
@foreach ($quote['finance']['schedule'] as $row)@endforeach
Schedule
#DueInstalmentInterestBalance
{{ $row['n'] }}{{ $row['due_date'] }}{{ number_format((float) $row['installment'], 2) }}{{ number_format((float) $row['interest'], 2) }}{{ number_format((float) $row['closing'], 2) }}
@endif {{-- Payments --}}

Payments

@forelse ($deal->payments as $p) @empty @endforelse
Payments
DateMethodReferenceAmountActions
{{ $p->received_on->format('d M Y') }}{{ $p->method->name }}{{ $p->payer === 'financier' ? ' (lender)' : '' }}{{ $p->reference }} {{ number_format((float) $p->amount, 2) }} @if ($p->receipt)Receipt@endif @if ($p->status === 'confirmed' && $st !== \App\Enums\DealStatus::Completed) @can('payments.refund')
Reverse
@csrf
@endcan @endif
Nothing received yet.
@can('payments.record') @if (in_array($st, [\App\Enums\DealStatus::Approved, \App\Enums\DealStatus::Confirmed]) && bccomp($balance, '0', 2) > 0)
@csrf
@if ($isFinance)
@endif
@endif @endcan
@includeIf('deals._mpesa', ['deal' => $deal]) @includeIf('staff._deal_links', ['deal' => $deal]) @if ($deal->approvals->count())

Approval history

    @foreach ($deal->approvals as $a)
  • {{ ucfirst($a->status) }} {{ $a->discount_percent }}% ({{ $a->level }}) requested by {{ $a->requester?->name }} on {{ $a->created_at->format('d M, H:i') }} @if ($a->decider) · decided by {{ $a->decider->name }}{{ $a->self_approved ? ' (own request)' : '' }}{{ $a->decision_note ? ': '.$a->decision_note : '' }}@endif
  • @endforeach
@endif
{{-- Documents and next steps --}}
@endsection