@extends('layouts.homeapp')
@section('content')

<section id="hero" class="shadow pb-5">
  <div class="container">

    <h1 class="inner-page-title">My Orders</h1>

    @if($Myorders)
      @foreach($Myorders as $Myorder)
      <div class="card border border-brandcolor mb-3 mt-4" style="width: 100%;">
        <div class="card-body">

          <h5 class="card-title font-weight-bold">Order No. {{$Myorder->id}}</h5>
          <h6 class="card-subtitle mb-2 ">{{$Myorder->status->title}}</h6>
          
          <div class="row p-3">
            <div style="width:48%; float:left; border-right:1px solid #9f9b9b; padding-top:5px;">
              <h6 class="card-subtitle mb-2 text-muted font-weight-bold">Order Date:</h6>
              <h6 class="card-subtitle mb-2 text-muted">{{date_format(date_create($Myorder->created_at),'d-m-Y')}}</h6>
            </div>
            <div style="width:48%; float:left; padding-left:10px; padding-top:5px;">
              <h6 class="card-subtitle mb-2 text-muted font-weight-bold">Delivery Date:</h6>
              <h6 class="card-subtitle mb-2 text-muted">
                @if($Myorder->order_delivery->last())
                  {{date_format(date_create($Myorder->order_delivery->last()->completingperiod),'d-m-Y')}}
                @else
                  {{"Not Completed"}}
                @endif
              </h6>
            </div>
          </div>

          <div class="d-flex">
            <a href="{{route('DetailsView',$Myorder->id)}}"><button type="submit" class="btn btn-brandcolor">View</button></a>
            @if($Myorder->status_id>='6')
              <a class="ml-3" href="{{route('InvoicePrint',$Myorder->id)}}"><button type="button" class="btn btn-secondary">Inovice</i></button></a>
            @endif
            <div class="ml-3">
              @if($Myorder->status_id <= '4' )
                <form method="POST" action="{{route('cancelorder',$Myorder->id)}}" Id="form-delete-{{$Myorder->id}}">
                  @csrf
                          
                  <button type="button" class="btn btn-danger"  onclick="
                  event.preventDefault();
                  if(confirm('Are you sure cancel this Order'))
                  {
                  document.getElementById('form-delete-{{$Myorder->id}}').submit();
                  }">Cancel</button>
                </form>
              @endif
            </div>
          </div>

        </div>
      </div> 
      @endforeach
    @endif
  
  </div>
</section>


@endsection