@extends('admin.app')

@section('page_title','All Orders') 

@section('page_location')
<ol class="breadcrumb">
      <li><a href="javascript:void('0');"><i class="fa fa-dashboard"></i> Home</a></li>
      <li><a href="javascript:void('0');">Order list</a></li>
      <li class="active">all</li>
</ol>
@endsection

@section('main-content')
  <div class="row">
    <div class="col-xs-12">
      <div class="box">
        <!-- /.box-header -->
        @php $i=1; @endphp
        @if(isset($orders))
        <div class="box-body table-responsive no-padding">
          <table class="table table-hover">
            <tbody>
              <tr>
                    <th>Id</th>
                    <th>Order Id</th>
                    <th>Order status</th>                     
                    <th>User</th>
                    <th>Products</th>
                    <th>Shipping</th>
                    <th>Billing</th>
                    <th>subtotal</th>
                    <th>Coupon discount</th>
                    <th>Grand total</th>
                    <th>Order notes</th>
                    <th>Payment status</th>
                    <th>Shipping status</th>
                    <th>Tracking no</th>
                    <th>Courier name</th>
              </tr>
              @foreach($orders as $value)

              <td style="">{{ $i++ }}</td>
              <td style="">{{ $value->order_id }}</td>  
              <td style="">{{ $value->order_status }}</td>  
              <td style="">
                @php
                $users = userdata( $value->user_id );
                @endphp
                <b>Name </b>: {{ $users->name }} <br>
                <b>Email </b>: {{ $users->email }}
              </td>   
              <td style="">
                {{-- {{ $value->products }} --}}
                @php
                $products  = array();
                $products = json_decode($value->products);
                 foreach ($products as $value2) {
                      foreach ($value2 as $key => $value1) {
                          if($key=='product_id')
                          {
                              echo '<b>Product Image </b>: <img src="'.coursesimage($value1).'" width="100px"><br>';
                          }
                          if($key=='name')
                          {
                              echo '<b>Product Name  </b>: '.$value1.'<br>';
                          }
                          if($key=='quantity')
                          {
                              echo '<b>Quantity  </b>: '.$value1.'<br>';
                          }
                          if($key=='price')
                          {
                              echo '<b>Price  </b>: '.$value1.'<br>';
                          }
                          echo "</hr>";
                      }

                  }
            @endphp
              </td>
              <td>
               @php
               $shipping_address = json_decode($value->shipping_address);
                foreach ($shipping_address as $key1 => $value3) {
                 $key1 = str_replace("shipping", "", $key1);
                 $key1 = str_replace("delivery", "", $key1);
                  echo '<b>'.ucwords(str_replace("_"," ",$key1)).'</b> : '.$value3.'<br>';

                }
                @endphp
              </td>
              <td style="">
                 @php
                    $billing_address = json_decode($value->billing_address);
                  foreach ($billing_address as $key2 => $value4) {
                      $key2 = str_replace("billing", "", $key2);
                    echo '<b>'.ucwords(str_replace("_"," ",$key2)).'</b> : '.$value4.'<br>';

                  }
                  @endphp
              </td>
               <td>
               Rs.{{ $value->subtotal }}             
              </td>
               <td>
               Rs.{{ $value->coupon_discount }}             
              </td>
               <td>
               Rs.{{ $value->grand_total }}             
              </td>
               <td>
               {{ $value->order_notes }}             
              </td>
               <td>
               {{ $value->payment_status }}             
              </td>
               <td>
               {{ $value->shipping_status }}             
              </td>
               <td>
               {{ $value->tracking_no }}             
              </td>
               <td>
               {{ $value->courier_name }}             
              </td>              
              
              <td>
              {{ $value->payment_mode }}
              </td>
              <td>                                                    
                  <a href="<?php echo url('/admin/orderedit/'.$value->id);?>" title="Edit" style="color: black;">
                  <span class="pull-right-container">
                    <i class="fa fa-edit"></i>
                  </span>
                  </a>
            </td>
            </tr>
            @endforeach
          </tbody>
        </table>                            
        </div>
        @endif
        @if(isset($message))
        <p style="font-size: 22px;text-align: -webkit-center;color: red;">{{ $message }}</p>
        @endif
            <!-- /.box-body -->
      </div>
          <!-- /.box -->
    </div>
  </div>
@endsection