<?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>

<section id="main-content">
    <section id="container">
        <section class="wrapper">
        <div id="here">
            <div class="row mt">
                <div class="col-lg-12">
                <h4>Dashboard <i class="fa fa-angle-right"></i> Self Orders</h4>
                </div>
            </div>

            <table id="example12" name="example12" class="table table-striped table-bordered" style="width:100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Address</th>                
                <th>Contact</th>                
                <th>COD</th>
                <th>Action</th>
            </tr>
        </thead>
    </table>
    </div><br><br>
    <a type="submit" style="float: right;" class="btn btn-success completeorders">Complete orders</a>
                <br><br><br><br>
    <a type="button" class="btn btn-info btn-xs" href="/exportselfdelivery">Export Data Self Delivery</a>                  

        </section>
    </section> 
</section>
   
        <!-- <?php $__currentLoopData = $item; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <tr>
                <td><?php echo e($data->id); ?></td>
                <td><?php echo e($data->name); ?></td>
                <td><?php echo e($data->cod); ?></td>
                <td><?php echo e($data->tracking); ?></td>
                <td class="text-center">
                <?php if($data->print =='1'): ?>   
                    <span class="label label-success label-mini">Print</span>
                <?php elseif($data->print =='0'): ?>
                    <span class="label label-danger label-mini">Not Print</span>
                <?php endif; ?>
                </td>
                <td class="text-center">
                    <button type="button" class="btn btn-info btn-xs" data-toggle="modal" data-target="#myModal" data-whatever="@getbootstrap">Tracking Code</button>
                    <a class="btn btn-danger btn-xs" data-id="<?php echo e($data->id); ?>"  href=""><i class="fa fa-trash-o "></i></a>
                    <a data-id="<?php echo e($data->id); ?>" class="btn btn-primary btn-xs" href="viwedetails/<?php echo e($data->id); ?>">View</a>
                </td>
                
            </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>  -->
        <br><br><br><br>
<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>
$(document).ready(function() {
    $('#example').DataTable();
} );
</script>

<script>
$(document).on('click', '.btn-danger', 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 Order Item",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

                        $.ajax({
                            url: "<?php echo e(url('/deletecustomer')); ?>/"+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");
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

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


  <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="<?php echo e(asset('dash/lib/bootstrap/js/bootstrap.min.js')); ?>"></script>
  <script class="include" type="text/javascript" src="<?php echo e(asset('dash/lib/jquery.dcjqaccordion.2.7.js')); ?>"></script>
  <script src="<?php echo e(asset('dash/lib/jquery.scrollTo.min.js')); ?>"></script>
  <script src="<?php echo e(asset('dash/lib/jquery.nicescroll.js')); ?>" type="text/javascript"></script>
  <script src="<?php echo e(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="<?php echo e(asset('dash/lib/common-scripts.js')); ?>"></script>
  <script type="text/javascript" src="<?php echo e(asset('dash/lib/gritter/js/jquery.gritter.js')); ?>"></script>
  <script type="<?php echo e(asset('dash/text/javascript" src="lib/gritter-conf.js')); ?>"></script>
  <!--script for this page-->
  <script src="<?php echo e(asset('dash/lib/sparkline-chart.js')); ?>"></script>
  <script src="<?php echo e(asset('dash/lib/zabuto_calendar.js')); ?>"></script>

</body>

</html>

<div class="modal fade" id="editordermodel" 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 method="post" enctype="multipart/form-data" id="myform">
            <?php echo e(csrf_field()); ?>

                <div class="modal-body">
                <input type="hidden" id="id" name="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" id="action" 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>
<script>
$('#editordermodel').on('show.bs.modal', function (event) {

var button = $(event.relatedTarget) // Button that triggered the modal

var id = button.data('id') 
var tracking = button.data('tracking') 
var modal = $(this)
//   modal.find('.modal-title').text('New message to ' + recipient)
modal.find('.modal-body #id').val(id)
modal.find('.modal-body #code').val(tracking)

})
</script>


<script>
$('#myform').on('submit', function(event){
    let ele = this;
        event.preventDefault();
        var form_data = $(this).serialize();
        $.ajax({
            url:"/todaycode",
            method:"POST",
            data:form_data,
            dataType:"json",      
            success: function (result, code, ex) {
                swal("Done!", "It was successfully!", "success");
                $("#editordermodel").modal('hide');  
                // $('#example').data.reload();
                $('#example12').DataTable().ajax.reload();
                // $('#example12').data.reload();
                // $("#here").load(location.href + " #here");
            },
            error: function (jqXHR, textStatus, errorThrown) {
                swal("Warning", "Unable to Process your request", "error");
            },
            
        })
    });

        $('#example12').DataTable({
        processing: false,
        serverSide: true,
        responsive: true,
        ajax: '/getBasicObjectDataself',
        columns: [
            {  data: 'name', name: 'name' },
            {  data: 'address', name: 'address' },
            {  data: 'phone', name: 'phone' },
            { data: 'cod', name: 'cod'},
            { data: 'action', name: 'action', orderable: false, searchable: false}
        ]
    });
</script>

<script>
 $(document).on('click', '.completeorders', function (e) {
    e.preventDefault();
    let ele = this;
                swal({
                title: "Are you sure?",
                text: "Are you Sure to Change Order Status",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, Change to Complete Order!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

                        $.ajax({
                            url: "<?php echo e(url('/completedUpdateself')); ?>" ,
                            method: "POST",
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            cache: false,
                            contentType: false,
                            processData: false,
                            dataType: 'JSON',
                            success: function (result, code, ex) {
                                swal("Done!", "It was successfully!", "success");
                                // $('#example12').DataTable().ajax.reload();
                                window.location.replace("/viewpending");

                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

                } else {
                    swal("Cancelled", "No Change Order Status", "error");
                }
            })
});
</script>