{{-- Body of the order page (#2957 slice 6d, card #3020). Included by order/show only. Expects: $order. Same data and estimates as the old view: while the order has no invoice it adds a package renewal estimate (when no package row exists yet) and, for SMS companies, the SMS service, sent and received estimates with the two "Skapa rader" buttons (POST order.createSmsRow, type generate_sms_rows / generate_sms_rows_usage). Totals without and with the estimates, then the "Skapa orderrad" form (POST order.createRow, text and price) while the order has no invoice. --}} @php $money = fn ($value) => formatNumber($value, 2, ','); $company = $order->company; $open = is_null($order->invoice_id); $estimation = 0; $packagePrice = null; if ($open && is_null($order->rows()->withType(\App\Models\OrderRow::$types['package'])->first())) { $packagePrice = $company->package->monthly_cost * $company->invoice_month_interval; $estimation = $packagePrice; } $smsEstimate = $open && $company->sms_enabled == 1; if ($smsEstimate) { $prop = $company->props()->where('name', 'last_sms_paid')->first(); $newLastPaid = \Carbon\Carbon::now(); $lastPaid = is_null($prop) ? $company->created_at : \Carbon\Carbon::now(); $smsTotal = $company->sentSms($lastPaid, $newLastPaid); $priceSent = ceil($smsTotal['sent'] * \App\Models\SMS::$price['sent']); $priceReceived = ceil($smsTotal['received'] * \App\Models\SMS::$price['received']); $estimation += $priceSent + $priceReceived; } // Only an open order needs the company's period; an invoiced order may belong to a deleted company. $periodStart = $open ? $company->expire_date->toDateString() : null; $periodStop = $open ? $company->expire_date->copy()->addMonths($company->invoice_month_interval)->toDateString() : null; $total = $order->calculateTotal(); @endphp
{{ __('order.show.customerName') }}
{{ $order['company_name'] }} ({{ $company->customer_number ?? 'Borttaget' }})
{{ __('order.show.customerStreet') }}
{{ $order['company_address'] }}
{{ __('order.show.customerZip') }}
{{ $order['company_zip'] }}, {{ $order['company_city'] }}
{{ __('order.nh.show.status') }}
@if (! is_null($order->invoice)) {{ __('order.nh.show.invoiced') }}: {{ $order->invoice->number }} @else {{ __('order.nh.show.nextInvoice') }}: {{ \App\Support\DisplayDate::timestamp($company->expire_date) }} @endif
{{ __('order.nh.show.created') }}
{{ $order['created_at']->format('Y-m-d') }}

{{ __('order.nh.show.rowsTitle') }}

@php $orderRows = \App\Support\TablePagination::rows($order->rows()->get()); @endphp @foreach ($orderRows as $key => $row) @endforeach @if (! is_null($packagePrice)) @endif @if ($smsEstimate) @endif
{{ __('order.show.row.line') }} {{ __('order.nh.show.description') }} {{ __('order.show.row.total') }}
{{ ($key + 1) * 10 }} {{ $row['row_text'] }} {{ $money($row['price']) }}
{{ __('order.nh.show.estimate') }} {{ __('invoice.packageName', ['receivers' => $company->package->max_receivers, 'start_time' => $periodStart, 'stop_time' => $periodStop]) }} {{ $money($packagePrice) }}
{{ __('order.nh.show.estimate') }} {{ __('invoice.smsServices', ['start_time' => $periodStart, 'stop_time' => $periodStop]) }}
@csrf {{ __('order.nh.show.generateSms') }}
{{ $money(99 * $company->invoice_month_interval) }}
{{ __('order.nh.show.estimate') }} {{ __('invoice.smsServiceSent', ['start_date' => $lastPaid->toDateString(), 'stop_date' => $newLastPaid->toDateString()]) }}
@csrf {{ __('order.nh.show.generateSmsUsage') }}
{{ $money($priceSent) }}
{{ __('order.nh.show.estimate') }} {{ __('invoice.smsServiceReceived', ['start_date' => $lastPaid->toDateString(), 'stop_date' => $newLastPaid->toDateString()]) }} {{ $money($priceReceived) }}
{{ __('order.show.row.total') }}
{{ $money($total) }}
@if ($open)
{{ __('order.show.row.totalWithEstimate') }}
{{ $money($total + $estimation) }}
@endif
@if ($open)
@csrf {{ __('order.show.createRow') }}
@endif