{{-- 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.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]) }} | {{ $money(99 * $company->invoice_month_interval) }} |
| {{ __('order.nh.show.estimate') }} | {{ __('invoice.smsServiceSent', ['start_date' => $lastPaid->toDateString(), 'stop_date' => $newLastPaid->toDateString()]) }} | {{ $money($priceSent) }} |
| {{ __('order.nh.show.estimate') }} | {{ __('invoice.smsServiceReceived', ['start_date' => $lastPaid->toDateString(), 'stop_date' => $newLastPaid->toDateString()]) }} | {{ $money($priceReceived) }} |