@extends('Admin.layout.app')

@section('title','Order Details')
@section('page-title','Order Details')

@section('content')

<div class="container-fluid">

    <div class="card shadow">

        <div class="card-header bg-primary text-white d-flex justify-content-between">

            <h4 class="mb-0">
                <i class="fas fa-file-invoice"></i>
                Order #{{ $order->id }}
            </h4>

            <a href="{{ route('admin.new-sale') }}"
               class="btn btn-light btn-sm">

                <i class="fas fa-arrow-left"></i>

                Back

            </a>

        </div>

        <div class="card-body">

            <div class="row">

                <!-- Customer -->

                <div class="col-md-6">

                    <h5 class="border-bottom pb-2">

                        Customer Information

                    </h5>

                    <table class="table table-borderless">

                        <tr>
                            <th width="35%">Name</th>
                            <td>
                                <strong>{{ $order->customer->name }}</strong><br>
                                <small class="text-muted"> {{ $order->customer->urdu_name ?? ''}}
                           </td>
                            
                        </tr>

                        <tr>
                            <th>Phone</th>
                            <td>{{ $order->customer->phone }}</td>
                        </tr>

                        <tr>
                            <th>Address</th>
                            <td>
                                <strong>{{ $order->customer->address }}</strong><br>
                                <small class="text-muted"> {{ $order->customer->urdu_address ?? ''}}
                            </td>
                        </tr>

                    </table>

                </div>

                <!-- Order -->

                <div class="col-md-6">

                    <h5 class="border-bottom pb-2">

                        Order Information

                    </h5>

                    <table class="table table-borderless">

                        <tr>
                            <th width="40%">Order Date</th>
                            <td>{{ $order->order_date->format('d M Y h:i A') }}</td>
                        </tr>

                        <tr>
                            <th>Payment Status</th>
                            <td>

                                <span class="badge bg-success">

                                    {{ $order->payment_status }}

                                </span>

                            </td>
                        </tr>

                        

                        <tr>
                            <th>Paid Amount</th>
                            <td>Rs. {{ number_format($order->paid_amount,2) }}</td>
                        </tr>

                    </table>

                </div>

            </div>

            <hr>

            <h5>

                Products

            </h5>

            <div class="table-responsive">

                <table class="table table-bordered">

                    <thead class="table-dark">

                    <tr>

                        <th>#</th>

                        <th>Product</th>

                        <th>Description</th>

                        <th>Price</th>

                        <th>Qty</th>

                        <th>Discount</th>

                        <th>Total</th>

                    </tr>

                    </thead>

                    <tbody>

                    @foreach($order->details as $item)

                        <tr>

                            <td>{{ $loop->iteration }}</td>

                            <td>
                                <strong>{{ $item->product->name }}</strong>
                                  @if($item->product->category==2)
                                     <strong>
                                         ({{$item->days}}days)
                                     </strong>
                                  @endif
                                
                                <br>
                               <small class="text-muted"> {{ $item->product->name_urdu ?? ''}}</small>
                            </td>

                            <td>{{ $item->description }}</td>

                            <td>Rs. {{ number_format($item->price,2) }}</td>

                            <td>{{ $item->qty }}</td>

                            <td>Rs. {{ number_format($item->discount,2) }}</td>

                            <td>
                                <strong>
                                    Rs. {{ number_format($item->total,2) }}
                                </strong>
                            </td>

                        </tr>

                    @endforeach

                    </tbody>

                </table>

            </div>

            <div class="row mt-4">

                <div class="col-md-4 ms-auto">

                    <table class="table">

                        <tr>

                            <th>Subtotal</th>

                            <td class="text-end">

                                Rs. {{ number_format($order->subtotal,2) }}

                            </td>

                        </tr>

                       
                        <tr>

                            <th>Cariage</th>

                            <td class="text-end">

                                Rs. {{ number_format($order->carriage,2) }}

                            </td>

                        </tr>

                        

                        <tr class="table-success">

                            <th>Grand Total</th>

                            <td class="text-end">

                                <strong>

                                    Rs. {{ number_format($order->grand_total,2) }}

                                </strong>

                            </td>

                        </tr>

                        <tr>

                            <th>Advance</th>

                            <td class="text-end">

                                Rs. {{ number_format($order->paid_amount,2) }}

                            </td>

                        </tr>

                        <tr class="table-warning">

                            <th>Remaining</th>

                            <td class="text-end">

                                <strong>

                                    Rs. {{ number_format($order->balance,2) }}

                                </strong>

                            </td>

                        </tr>

                    </table>

                </div>

            </div>

             <a href="{{ route('admin.order.invoice', $order->id) }}"
                 class="btn btn-sm btn-outline-success"
                 target="_blank">
                  <i class="las la-print"></i> Print Bill
              </a>

        </div>

    </div>

</div>

@endsection