<?php echo View::make('/../include/header'); ?>

<header>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/css/select2.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/js/select2.min.js"></script>

</header>
<body>
<div id="here">
<section id="main-content">
    <section id="container">
        <section class="wrapper">
            <div class="row mt">
                <div class="col-lg-12">
                <h4>Dashboard <i class="fa fa-angle-right"></i> View Details</h4>
                <button type="button" class="btn btn-info btn-xs" data-toggle="modal" data-target="#myModal3"  style="float:right" data-whatever="@getbootstrap">Edit Customer Details</button>
                </div>
            </div>

            <div class="row" >
            @foreach($item as $data)
             <div class="col-sm-4"><h5><b> Customer Name :</b> {{ $data->name}}</h5></div>
             <div class="col-sm-4"><h5><b>Phone #1 :</b> {{ $data->phone}}</h5></div>
             <div class="col-sm-3"><h5><b>Date :</b> {{ $data->created_at}}</h5></div>
             <div class="col-sm-1"><h5><b></b>
            @if($data->status =='0')   
               <span class="label label-warning label-mini">Pending</span>
            @elseif($data->status =='1')   
               <span class="label label-primary label-mini">To Delivery</span>
            @elseif($data->status =='2')               
               <span  class="label label-success label-mini">Complete</span>
            @elseif($data->status =='3')                
               <span  class="label label-info label-mini">Return Order</span>
            @elseif($data->status =='4')               
               <span class="label label-danger label-mini">Cansel</span>
            @elseif($data->status =='5')            
               <span  class="label label-danger label-mini">Not Answer</span>                  
            @elseif($data->status =='6')                
               <span  class="label label-danger label-mini">After Delivery</span>
            @elseif($data->status =='7')                
               <span  class="label label-danger label-mini">Self Delivery</span>
            @endif
             </h5></div>
             <div class="col-sm-8"><h5><b>Address :</b> {{ $data->address}}</h5></div>
             <div class="col-sm-4" ><h5><b>Tracking Code :</b> {{ $data->tracking}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
             @if($data->print =='1')   
               <span class="label label-success label-mini">Print</span>
            @elseif($data->print =='0')
               <span class="label label-danger label-mini">Not Print</span>
            @endif
             </div>
             <div class="col-sm-10"><h5><b>Note :</b> <b style="color:red;">{{ $data->note}}</b></h5></div>
             <div class="col-sm-2"><h5><b>Page :</b> @foreach($pages as $data3) {{ $data3->pagename}}   @endforeach</h5></div>
             @endforeach
         </div><br>

          <table class="table" id="book-table" name="book-table">
                    <thead>
                          <tr>
                            <th style="width:60px" class="text-center">QTY</th>
                            <th class="text-left">DESCRIPTION</th>
                            <th style="width:140px" class="text-right">UNIT PRICE</th>
                            <th style="width:90px" class="text-right">TOTAL</th>
                            <th style="width:90px" class="text-right"></th>

                          </tr>
                    </thead>
                    <tbody>
                            
                    @foreach($item3 as $data) 
                            <tr>
                                <td class="text-center">{{ $data->qty}}</td>
                                <td>{{ $data->orders->name}}
                                @if($data->attribute=="null" or $data->attribute=="")
                                @else
                                    @foreach (json_decode($data->attribute) as $key => $val)
                                        ({{$key }}:{{$val}})
                                    @endforeach
                                @endif
                                </td>
                                <td class="text-right">{{ $data->orders->sell_price}}</td>
                                <td class="text-right"> {{$data->qty * $data->orders->sell_price}}
                                </td>
                                <input type="hidden" value="">
                            </tr>
                    @endforeach
                            <tr>
                                    <td colspan="2" rowspan="4">
                                     
                                      <td class="text-right"><strong>Delivery Charge</strong></td>
                                      <td class="text-right">{{ $deli }}</td>
                                  </tr>

                                  <tr>
                                    <td class="text-right no-border">
                                      <strong>Total</strong>
                                    </td>
                                    <td class="text-right"><strong>{{ $tot + $deli }}</strong></td>
                                  </tr>
                    </tbody>
                </table>  
                <br>
                <br>
                <br>
              <div class="row">
                  <div class="col-sm-7">
                  </div>
                 
                <form action="/updatestatus" method="post" enctype="multipart/form-data">
                  {{csrf_field()}}
                <div class="col-sm-3">
                    <div class="form-group">
                        <div class="col-lg-12">
                        @foreach($item as $data)
                            <input type="hidden" value="{{$data->id}}" name="cus_id">
                        @endforeach
                            <input type="hidden" value="{{ $tot + $deli }}" name="total">
                            <select class="form-control" name="statusValu">
                                <option selected="true" disabled="disabled">Change Status</option>
                                <option value="0">Pending Order</option>
                                <option value="1">To Deliver</option>
                                <option value="7">Self Delivery</option>
                                <option value="5">Not Answer</option>
                                <option value="3">Return Order</option>
                                <option value="4">Cansel Order</option>
                                <option value="6">After Deliver</option>
                                <option value="2">Complete Order</option>

                              </select>
                        </div>
                    </div>
                    

                </div>
                <div class="col-sm-2">
                  <input type="submit" name="btnform1" class="btn btn-primary right" value="Submit"/>
                </div>
                </form>
                
              </div>
<br><br>


                <div class="row">
                    <div class="col-sm-2"></div>
                    <div class="col-sm-1">
                        <button type="button" class="btn btn-info btn-xs" data-toggle="modal" data-target="#myModal" data-whatever="@getbootstrap">Tracking Code</button>
                    </div>
                    <div class="col-sm-1">
                        <button type="button" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#myModal2" data-whatever="@getbootstrap">Add Note</button>
                    </div>
                    <div class="col-sm-1"> <a class="btn btn-success btn-xs" onclick="printDiv('printableArea2')" >Self Print</a> </div>
                    <div class="col-sm-1"> <a class="btn btn-warning btn-xs" onclick="printDiv('printableArea')" >Print invoice</a> </div>
                    <div class="col-sm-1"> <a class="btn btn-info btn-xs" onclick="printDiv('printableArea3')" >Koobiyo print</a> </div>
                    <div class="col-sm-1"> <a class="btn btn-primary btn-xs" href="/statuschange/{{$cus_id}}">Edit Order</a> </div>
                    <div class="col-sm-1"> <a class="btn btn-info btn-xs printstatus" data-id="{{$cus_id}}" href="">Done print</a> </div>
   
                 <div class="col-sm-1"> <a class="btn btn-danger btn-xs deletecusorder" data-id="{{$cus_id}}" onclick="" href="">Delete Order</a> </div>
                </div>




<!-- test -->
<!-- /test --> <br><br>
            <div style="text-align:right;">
                @foreach($item as $data)
                    <h5>Created By - {{ $data->user }}</h5>
                    <h5>Last Updated Date  - {{ $data->updated_at }}</h5>
                @endforeach
            </div>
            
        </section>
    </section> 
</section>
</div><br><br>
   
<div class="modal fade" id="myModal" role="dialog">
        <div class="modal-dialog">
        
          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
                    <h4 class="modal-title">Add Tacking Code</h4>
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              
            </div>
            
            <form action="/updatetracking" method="post" enctype="multipart/form-data">
            {{csrf_field()}}
                <div class="modal-body">
                <input type="hidden" value="{{$cus_id}}" name="cus_id">
                <div class="form-group">
                        <label for="recipient-name" class="col-form-label">Tracking Code :</label>
                        <input type="text" class="form-control" id="code" name="code" required>
                      </div>
                    
                </div>
                
            
                  
            <div class="modal-footer">
            <input type="submit" name="btnform1" class="btn btn-primary right" value="Add Tracking Code"/>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            </form>
          </div>
          
        </div>

</div>


<div class="modal fade" id="myModal2" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
                <h4 class="modal-title">Add Note</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          
        </div>
       
        <form action="/updatenote" method="post" enctype="multipart/form-data">
        {{csrf_field()}}
            <div class="modal-body">
            
            <input type="hidden" value="{{$cus_id}}" name="cus_id">
            <div class="form-group">
                <label for="message-text" class="col-form-label">Message :</label>
                <textarea class="form-control" id="note" name="note"></textarea>
              </div>
                
            </div>
            
       
              
        <div class="modal-footer">
        <input type="submit" name="btnform1" class="btn btn-primary right" value="Update Note"/>
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
        </form>
      </div>
      
    </div>

</div>

<div class="modal fade" id="myModal3" role="dialog">
  <div class="modal-dialog">
  
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
              <h4 class="modal-title">Update Customer Details</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        
      </div>
      
          <form role="form" class="form-horizontal style-form" action="/updatecusdetails" method="post" enctype="multipart/form-data">
          {{csrf_field()}}
            <div class="modal-body">
            @foreach($item as $data)
            <input type="hidden" value="{{ $cus_id }}" name="cus_id">
              <div class="form-group">
                  <label class="col-lg-3 control-label">Customer Name</label>
                  <div class="col-lg-9">
                  <input type="text" placeholder="" value="{{ $data->name }}" id="name" name="name" class="form-control">
                  </div>
              </div>
              <div class="form-group">
                  <label class="col-lg-3 control-label">Address</label>
                  <div class="col-lg-9">
                  <textarea type="text" placeholder="" value="{{ $data->address }}" id="address" rows="6" name="address" class="form-control">{{ $data->address }}</textarea>
                  </div>
              </div>
              <div class="form-group">
                  <label class="col-lg-3 control-label">Phone numbers</label>
                  <div class="col-lg-9">
                  <input type="text" placeholder=""  value="{{ $data->phone }}" id="phone" name="phone" class="form-control">
                  </div>
              </div>
              @endforeach
            </div>
       
      
            
      <div class="modal-footer">
      <button class="btn btn-theme" type="submit">Update Customer Deatils</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
      </form>
    </div>
    
  </div>

</div>
 

<footer class="site-footer">
      <div class="text-center">
        <p>
          &copy; Copyrights <strong>Dashio</strong>. All Rights Reserved
        </p>
        <div class="credits">
          <!--
            You are NOT allowed to delete the credit link to TemplateMag with free version.
            You can delete the credit link only if you bought the pro version.
            Buy the pro version with working PHP/AJAX contact form: https://templatemag.com/dashio-bootstrap-admin-template/
            Licensing information: https://templatemag.com/license/
          -->
          Created with Dashio template by <a href="https://templatemag.com/">TemplateMag</a>
        </div>
        <a href="index.html#" class="go-top">
          <i class="fa fa-angle-up"></i>
          </a>
      </div>
    </footer>

<style>
    .site-footer {

    /* position: fixed; */
   left: 0;
   z-index: -1;
   bottom: 0;
   width: 100%;
}
</style>
    <!--footer end-->
  </section>



  <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
  <script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
  <script src="{{ asset('dash/lib/bootstrap/js/bootstrap.min.js') }}"></script>
  <script class="include" type="text/javascript" src="{{ asset('dash/lib/jquery.dcjqaccordion.2.7.js') }}"></script>
  <script src="{{ asset('dash/lib/jquery.scrollTo.min.js') }}"></script>
  <script src="{{ asset('dash/lib/jquery.nicescroll.js') }}" type="text/javascript"></script>
  <script src="{{ asset('dash/lib/jquery.sparkline.js') }}"></script>

<!--sweet alert-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.29.2/sweetalert2.all.js"></script>

  <!--common script for all pages-->
  <script src="{{ asset('dash/lib/common-scripts.js') }}"></script>
  <script type="text/javascript" src="{{ asset('dash/lib/gritter/js/jquery.gritter.js') }}"></script>
  <script type="{{ asset('dash/text/javascript" src="lib/gritter-conf.js') }}"></script>
  <!--script for this page-->
  <script src="{{ asset('dash/lib/sparkline-chart.js') }}"></script>
  <script src="{{ asset('dash/lib/zabuto_calendar.js') }}"></script>

</body>

</html>





<script>
function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}
</script>

 

<div id="printableArea" style="display: none;">
@foreach($pages as $data)
  <img src="{{url('uploads/'.$data->image)}}" style=" display: block; margin: 0 auto; height:111px"  alt="logo">
@endforeach
    <div class="row">
    @foreach($item as $data)
        <div class="col-xs-1 col-md-1"></div>
        <div class="col-xs-7 col-md-7"><h5>Customer Name : {{$data->name}}</h5></div>
        <div class="col-xs-4 col-md-4"><h5>Date : <a id="date"></a></h5></div>
    @endforeach   
    </div>
<br>

    <table class="table" id="book-table" name="book-table">
            <thead>
                  <tr>
                    <th style="width:60px" class="text-center">QTY</th>
                    <th class="text-left">DESCRIPTION</th>
                    <th style="width:140px" class="text-right">UNIT PRICE</th>
                    <th style="width:90px" class="text-right">TOTAL</th>
   
                  </tr>
            </thead>
            <tbody>
                    
            @foreach($item3 as $data) 
                    <tr>
                        <td class="text-center">{{ $data->qty }}</td>
                        <td>{{ $data->orders->name }}
                        @if($data->attribute=="null" or $data->attribute=="")
                        @else
                            @foreach (json_decode($data->attribute) as $key => $val)
                                ({{$key }}:{{$val}})
                            @endforeach
                        @endif
                        </td>
                        <td class="text-right">{{ $data->orders->sell_price }}</td>
                        <td class="text-right"> {{ $data->qty * $data->orders->sell_price }}
                        </td>
                        <input type="hidden" value="">
                    </tr>
                    
            
                @endforeach
                    <tr>
                            <td colspan="2" rowspan="4">
                             
                              <td class="text-right"><strong>Delivery Charge</strong></td>
                              <td class="text-right">{{$deli}}</td>
                          </tr>

                          <tr>
                            <td class="text-right no-border">
                              <strong>Total</strong>
                            </td>
                            <td class="text-right"><strong>{{ $deli + $tot }}</strong></td>
                          </tr>
            </tbody>
        </table>  
        <br>
        <br>
        <br>
      </div>
      

<div id="printableArea2" style="display: none;">
    <div class="row">
    @foreach($item as $data)
        <div class="col-sm-6"><h5 style="font-size:20px;"> <b> Customer Name :</b> {{$data->name}}</h5></div>
        <div class="col-sm-8"><h5 style="font-size:20px;"><b>Address :</b> {{$data->address}}</h5></div>
        <div class="col-sm-4"><h5 style="font-size:20px;"><b>Phone # :</b>{{$data->phone}} </h5></div>
    @endforeach    
      
        <div class="col-sm-4"><h5 style="font-size:20px;"><b>Total : </b>{{ $deli + $tot }}</h5></div>
        
    </div>
      </div>
      <style>
          hr{
          padding: 0px;
          margin: 0px;    
        }
    </style>

      <div id="printableArea3" style="display: none;   ">
      @foreach($item as $datas)
            <div class="row" style="margin: -6mm 0mm 0mm -4mm;">
                <div class="col-xs-6 col-md-6">
                    <h2 style="text-align:center">PROOF OF DELIVERY</h2>
                    @foreach($pages as $data)
                    <img src="{{url('uploads/'.$data->image)}}" style="width: 200px;"  alt="logo">
                    @endforeach
                    <img src="{{ asset('dash/img/logo250.png') }}" style="width: 110px;"  alt="logo">
                    @foreach($pages as $data)
                    <h5>Contact Number : {{$data->number}}</h5>
                    @endforeach
                    
                    <h5>Issued Date : <a id="date2"></a> </h5>
                    <hr style='margin-top:0em;margin-bottom:0em'>
                    <h5>To : {{$datas->name}}</h5>
                    <h5>Address : {{$datas->address}}</h5>
                    <h5>Phone No : {{$datas->phone}}</h5>
                   
                </div>
                <div class="col-xs-4 col-md-4">
                  
                    <br><br><br><br>
                    
                  <h4>COD AMOUNT :  {{ $deli + $tot }}</h4>
                  <h6>Order No : {{$datas->id}}</h6>
                  <h6>Weight : </h6>
                  <hr style='margin-top:0em;margin-bottom:0em'>
                  <h6>Name ; </h6>
                  <h6>Address : </h6>
                  <h6>NIC Number : </h6>
                  <h6>Date : </h6>
                  <h6>Signature : </h6>
                  <h6>Deliverd : Yes :  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;     No :</h6>
                </div>
                <div class="col-xs-2 col-md-2"></div>
            @endforeach    
            </div>
            <div class="row" style="margin: -0mm 0mm 0mm -4mm;">
                <div class="col-xs-10 col-md-10">
                    <hr style='margin-top:0em;margin-bottom:0em'>
                </div>
                <div class="col-xs-2 col-md-2">

                </div>  
            </div>
          
          
        </div>
<script>
n =  new Date();
y = n.getFullYear();
m = n.getMonth() + 1;
d = n.getDate();
document.getElementById("date").innerHTML = m + "/" + d + "/" + y;
document.getElementById("date2").innerHTML = m + "/" + d + "/" + y;
</script>
<script>
$(document).ready(function() {
    $('#example').DataTable();
} );
</script>

<script>
$(document).on('click', '.printstatus', function (e) {
    e.preventDefault();
    var id = $(this).data('id');
    let ele = this;
    console.log(id);

                swal({
                title: "Are you sure?",
                text: "Are you Sure to Change Print Status",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, Done Print!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

                        $.ajax({
                            url: "{{url('/updateprintstatus')}}/"+id ,
                            method: "POST",
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'JSON',
                            data:{
                                "id":id
                            },
                            success: function (result, code, ex) {
                                swal("Done!", "It was successfully!", "success");
                               // $(ele).closest('tr').hide();
                                $("#here").load(location.href + " #here");
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

                } else {
                    swal("Cancelled", "No Change Print Status", "error");
                }
            })
});




$(document).on('click', '.deletecusorder', function (e) {
    e.preventDefault();
    var id = $(this).data('id');
    let ele = this;
    console.log(id);

                swal({
                title: "Are you sure?",
                text: "Are you Sure to Remove This Customer",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

                        $.ajax({
                            url: "{{url('/deletecusorder')}}/"+id ,
                            method: "POST",
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'JSON',
                            data:{
                                "id":id
                            },
                            success: function (result, code, ex) {
                                swal("Done!", "It was successfully deleted!", "success");
                               // $(ele).closest('tr').hide();
                                // $("#here").load(location.href + " #here");
                                window.location.replace("/viewpending");
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

                } else {
                    swal("Cancelled", "No Customer Removed", "error");
                }
            })
});
</script>