<?php echo $__env->make('dashboard.include.header', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

  
  <div class="content-wrapper">
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0">Colombo Orders Packing</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/home">Home</a></li>
              <li class="breadcrumb-item active">Colombo Orders Packing</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
    
    <section class="content">
      <div class="container-fluid">
      <div class="card">
        <div class="card-body">

    <form method="post" id="searchcmbo10" class="searchcmbo10" action="/searchinventorycolombo2">
        <?php echo e(csrf_field()); ?>

        <div class="row">
                <div class="col-md-1"></div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label>Filter orders by rider name</label>
                        <select class="form-control" name="delivery_name" id="delivery_name" style="width: 100%;" required>
                            <option value="" selected="selected" disabled>Select</option>
                            <option value="all" <?php if($deli=="all"): ?>selected <?php endif; ?>>All</option>
                                <?php $__currentLoopData = $delise; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php if($data->type=="Delivery_Guy"): ?>
                                <option value="<?php echo e($data->id); ?>"  <?php if($deli==$data->id ): ?>selected <?php endif; ?>><?php echo e($data->name); ?></option>
                                <?php endif; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                </div>

                <div class="col-md-4">
                <div class="form-group row">
                    <label for="">Delivery Date :</label>
                        <div class="input-group date" id="reservationdate"  data-target-input="nearest">
                            <input type="text" class="form-control datetimepicker-input" value="<?php echo e($ldate); ?>" id="delivery_date" name="delivery_date" data-target="#reservationdate"/  required>
                            <div class="input-group-append" data-target="#reservationdate" data-toggle="datetimepicker">
                                <div class="input-group-text"><i class="fa fa-calendar"></i></div>
                            </div>
                        </div>
                </div>
            </div>
            <div class="col-md-2" style="padding-top:32px;"><button type="submit" class="btn btn-primary btn-block">Search</button></div>

  </div>
  
  </form>
        </div>
        </div>
        <form method="post" id="formFilter">
                    <?php echo e(csrf_field()); ?>

                        <input type="hidden" value="<?php echo e($ldate); ?>" name="date">
                        <input type="hidden" value="<?php echo e($deli); ?>" name="rider">
                    </form>
      <div class="card">
        <div class="card-body">
        <div class="row">
          <div class="col-md-4">
                    <form method="post" id="formsubmittest">
                        <?php echo e(csrf_field()); ?>

                        <input type="hidden" class="form-control" name="riderid" id="riderid" value="<?php echo e($deli); ?>" required>
                        <input type="hidden" class="form-control" name="date" id="date" value="<?php echo e($ldate); ?>" required>
                        <input type="text" class="form-control barcodetxt" name="barcode" id="barcode" placeholder="Barcode" required autofocus>
                    </form>
                </div>
          </div><br>
          <div class="row">
            <div class="col-md-12">
                <table id="example12" data-page-length='50' class="table table-bordered" style="width:100%;">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Product Name</th>
                            <th>Barcode</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                </table>
            </div>
          </div>  


          <!-- <div class="row">
            <div class="col-md-12">
                <table id="example1" class="table table-bordered" style="width:100%;">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Product Name</th>
                            <th>Barcode</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $dataor; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $datapro): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($datapro->id); ?></td>
                                <td><?php echo e($datapro->productgetn->name); ?></td>
                                <td><?php echo e($datapro->barcode); ?></td>
                                <td class="text-center">
                                <?php if($datapro->status=='0'): ?>
                                <span class="badge badge-warning">Not Added Barcode</span>
                                <?php elseif($datapro->status=='1'): ?>
                                <span class="badge badge-success">Barcode Add successfully</span>
                                <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
                        </tbody>
                </table>
            </div>
          </div>       -->


        </div>
        </div>
        <div class="card">
            <div class="card-body">
            <div class="row">
                    <div class="col-md-12">
                        <table id="customerdata" class="table table-bordered" style="width:100%;">
                            <thead>
                                <tr>
                                <th>Name</th>
                                <th>Address</th>
                                <th>Phone</th>
                                <th>Products</th>
                                <th>COD</th>
                                <th>Action</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>

      </div>
    </section>
  </div><br><br><br><br><br><br><br><br>




  <?php echo $__env->make('dashboard.include.footer', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>;



<script>
$(document).ready(function() {
  var table = $('#example12').DataTable({
        "ajax": {   "url": '/getdatatempbarcoderider',
                    "type": 'POST',
                    "data": function ( d ) {
                    return $('#formFilter').serialize();
                    }
        },
        columns: [
            { data: 'id', name: 'id' },
            {  data: 'productname', name: 'productname' },
            { data: 'barcode', name: 'barcode'},
            { data: 'status', 
              render: function(data) { 
                if(data==1) {
                  return '<span class="badge badge-success">Barcode Add successfully</span>' 
                }
                else if(data==2) {
                  return '<span class="badge badge-danger">Return Barcode</span>'
                }
                else{
                    return '<span class="badge badge-warning">Not Added Barcode</span>'
                }},
              defaultContent: '<span class="badge badge-warning">Not Added Barcode</span>'
            },
            { data: 'action', name: 'action', orderable: false, searchable: false}
        ]
    });
} );

$(document).ready(function() {
  var table = $('#customerdata').DataTable({
        "ajax": {   "url": '/colombocustomerdataget',
                    "type": 'POST',
                    "data": function ( d ) {
                    return $('.searchcmbo10').serialize();
                    }
        },
        columns: [
            { data: 'name', name: 'name' },
            { data: 'address', name: 'address'},
            { data: 'phone', name: 'phone'},
            { data: 'productname', name: 'productname' },
            { data: 'cod', name: 'cod'},
            { data: 'action', name: 'action', orderable: false, searchable: false}
        ]
    });
} );


// $('input[name=barcode]').change(function() { 
//     $("#formsubmittest").submit();
//  });

$('.barcodetxt').bind("enterKey",function(e){
    $("#formsubmittest").submit();
});



    $('#formsubmittest').on('submit', function(event){
    let ele = this;
        event.preventDefault();
        var form_data = $(this).serialize();
        $.ajax({
            url:"/colombopackingupdate",
            method:"POST",
            data:form_data,
            dataType:"json",      
            success: function (data) {
                jQuery.each(data, function(key,value){
                    if(value=="1"){
                        $('#barcode').val("");
                        $("#barcode").focus();
                        swal({
                            title: "Error!",
                            text: "This Barcode is not in the database",
                            icon: "error",
                            button: "OK",
                        });

  
                    }
                    else if(value=="2"){
                        $('#barcode').val("");
                        $("#barcode").focus();
                        swal({
                            title: "Error!",
                            text: "Product Not Matching",
                            icon: "error",
                            button: "OK",
                        });


                    }
                    else if(value=="3"){
                        $('#barcode').val("");
                        $("#barcode").focus();
                        swal({
                            title: "Error!",
                            text: "All Barcode Added successfully",
                            icon: "error",
                            button: "OK",
                        });

                    }
                    else if(value=="4"){
                        window.location.href = '/inventorycolombo';

                    }
                    else{
                        toastr.success('Barcode add successfully!')
                        // location.reload();
                        $('#example12').DataTable().ajax.reload();
                        $('#barcode').val("");
                        $("#barcode").focus();
                    }
                
        });
                
            },
            error: function (jqXHR, textStatus, errorThrown) {
                swal("Warning", "Unable to Process your request", "error");
            },
        })
    });



    $('#searchcmbo1').on('submit', function(event){
    let ele = this;
        event.preventDefault();
        var form_data = $(this).serialize();
        $.ajax({
            url:"/searchinventorycolombo",
            method:"POST",
            data:form_data,
            dataType:"json",      
            success: function (data) {
                // toastr.success('Delivery Charges Added successfully!')
                $('.att-group2').remove()
            jQuery.each(data, function(key,value){
                console.log(value);

                $('.applenddata2').append('<form method="post" id="deliveryupdateform3" action="/checklistbarcode"><div class="row att-group2"><div class="col-md-1"> <div class="form-group"><label for="">ID &nbsp;&nbsp;: &nbsp;&nbsp;</label>'+ value.id +'</div></div><div class="col-md-6"> <div class="form-group"><label for="">Product Name &nbsp;&nbsp;: &nbsp;&nbsp;</label>'+ value.id+'</div></div><div class="col-md-3"><input type="hidden" name="id" value="'+ value.id +'"><input type="hidden" name="pro_id"  value="'+ value.productid +'"><input type="text" class="form-control" name="barcode" id="barcode" value="'+ value.barcode +'" required><button type="submit" style="display:none" class="btn btn-primary">Save</button></div></div></form>')



                
        });
                

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


$('#reservationdate').datetimepicker({
    format: 'YYYY/MM/DD'
    });

$('#reservationdate2').datetimepicker({
    format: 'YYYY/MM/DD'
    });

$(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": true, "autoWidth": false,
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
  });
</script>
<script type="text/javascript">
jQuery(function($) {
    $('body').on('click', '#selectall', function() {
        $('.singlechkbox').prop('checked', this.checked);
    });
 
    $('body').on('click', '.singlechkbox', function() {
        if($('.singlechkbox').length == $('.singlechkbox:checked').length) {
            $('#selectall').prop('checked', true);
        } else {
            $("#selectall").prop('checked', false);
        }
 
    });
});

</script>

<script>
<?php if(session('success')): ?>
        // swal("Success!","<?php echo e(session('success')); ?>","success");
        toastr.success('Your work has been successfully!')
// Swal.fire({
  
//   type: 'success',
//   title: 'Your work has been saved',
//   text: "<?php echo e(session('success')); ?>",
//   showConfirmButton: false,
//   timer: 1500
// });


<?php endif; ?>
<?php if(session('error')): ?>
    swal({
            title: "Error!",
            text: "<?php echo e(session('error')); ?>",
            icon: "error",
            button: "OK",
        });
<?php endif; ?>

$(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('/deletetempbarcode')); ?>/"+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();
                                $('#example12').DataTable().ajax.reload();
                                // $("#here").load(location.href + " #here");
                                $('#barcode').val("");
                                $("#barcode").focus();
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

                } else {
                    swal("Cancelled", "No Removed", "error");
                }
            })
});

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

                        $.ajax({
                            url: "<?php echo e(url('/returncustomertembar')); ?>/"+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");
                                toastr.success('It was successfully!')
                                $('#customerdata').DataTable().ajax.reload();
                                // $("#here").load(location.href + " #here");
                                $('#barcode').val("");
                                $("#barcode").focus();
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                swal("Warning", "Unable to Process your request", "error");
                            },
                        });

                } else {
                    swal("Cancelled", "No Return", "error");
                }
            })
});

</script>

