<?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">Import Orders</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">Import Orders</li>
            </ol>
          </div>
        </div>
      </div>
    </div>
   
    <section class="content">
      <div class="container-fluid">
      <div class="card">
        <div class="card-body">
        <div class="row">
            <div class="col-md-12">
                <?php if($message = Session::get('success')): ?>
					<div class="alert alert-success" role="alert">
						<?php echo e(Session::get('success')); ?>

					</div>
				<?php endif; ?>


				<?php if($message = Session::get('error')): ?>
					<div class="alert alert-danger" role="alert">
						<?php echo e(Session::get('error')); ?>

					</div>
				<?php endif; ?>
            </div>
        </div>
        <div class="row">
            <div class="col-md-10"></div>
            <div class="col-md-2"><a href="uploads/order_template.xlsx" class="btn btn-block btn-warning" download>Download Template</a>
            </div>
        </div> <br><hr><br>
        <form action="<?php echo e(URL::to('importExcelOrders')); ?>" class="form-horizontal" method="post" enctype="multipart/form-data">
        <?php echo e(csrf_field()); ?>

        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    <label>Product Name</label>
                    <select class="form-control select2" name="product_d" id="product_d" style="width: 100%;" required>
                        <option value="" selected="selected" disabled>Select</option>
                        <?php $__currentLoopData = $product; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $productdata): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($productdata->id); ?>"><?php echo e($productdata->pro_name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label for="">Product Price</label><input type="number" class="form-control" name="product_price" id="product_price" value="0" required>
                </div>
            </div>
            <div class="col-md-2">
                <div class="form-group">
                    <label for="">Quantity</label><input type="number" class="form-control" name="qty" id="qty" value="1" required>
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label for="">Select Excel sheet</label> <br>
                    <input type="file" name="import_file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"/>
                </div>
            </div>




            <div class="col-md-3" style="padding-top:30px;"><button type="submit" id="submitbutton" class="btn btn-block btn-primary">Import Orders</button></div>
        </div>

        <div class="row">
            <div class="col-md-1"></div>

        </div>   <br><br>
        <div class="row">
            <div class="col-md-4"></div>
            
            <div class="col-md-4"></div>
        </div> 
        </form>       
      </div>
    </div>
      <div class="card">
        <div class="card-body">
          <div class="row">
            <div class="col-md-12">
                <table id="example12" data-page-length='50' class="table table-bordered" style="width:100%; font-size:13px;">
                    <thead>
                        <tr>
                            <th>Id</th>
                            <!-- <th>Page Name</th> -->
                            <th>Name</th>
                            <th>Address</th>
                            <th>Phone</th>
                            <th>City</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                </table>
            </div>
          </div>
          </div>
        </div>

    <div class="card">
        <div class="card-body">

          <div class="row">
          <div class="col-md-4"></div>
          <div class="col-md-2"><a type="submit" style="float: right;" class="btn btn-block btn-danger delallorders">Delete All</a></div>
            <div class="col-md-2"><a type="submit"  class="btn btn-block btn-primary sentocallcenter">Send Call Center</a></div>
            <!-- <div class="col-md-2"><a type="submit"  class="btn btn-block btn-dark sendtosellercenter">Send to Seller Center</a></div> -->
            <div class="col-md-2"></div>
          </div>
          <br>



        </div>
      </div>


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


<div class="modal fade" id="editordermodelphone" role="dialog">
        <div class="modal-dialog">
        
          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header">
                    <h4 class="modal-title">City Update</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>City :</label>
                    <select class="form-control select2" name="cituselect" id="cituselect">
                        <option value="empty" selected="selected" disabled>Select</option>
                        <?php $__currentLoopData = $city; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cityd): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($cityd->id); ?>"><?php echo e($cityd->city); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div> 
                    
                </div>
                  
            <div class="modal-footer">
            <input type="submit" name="btnform1" id="action" class="btn btn-primary right" value="Submit"/>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
            </form>
          </div>
          
        </div>

</div>







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

<script>
$('#editordermodelphone').on('show.bs.modal', function (event) {

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

var id = button.data('id') 
var city = button.data('city') 

var modal = $(this)
//   modal.find('.modal-title').text('New message to ' + recipient)
modal.find('.modal-body #id').val(id)
$("#cituselect").val(city).change();

})


$('#myform').on('submit', function(event){
    let ele = this;
        event.preventDefault();
        var form_data = $(this).serialize();
        $.ajax({
            url:"/importcityupdate",
            method:"POST",
            data:form_data,
            dataType:"json",      
            success: function (result, code, ex) {
                // swal("Done!", "It was successfully!", "success");
                toastr.success('City Update successfully!')
                $("#editordermodelphone").modal('hide');  
                $('#example12').DataTable().ajax.reload();
            },
            error: function (jqXHR, textStatus, errorThrown) {
                swal("Warning", "Unable to Process your request", "error");
            },
            
        })
    });





$(function () {
    $('.select2').select2()
})


$(document).ready(function() {
    $('#example12').DataTable({
        processing: false,
        serverSide: true,
        responsive: true,
        ajax: '/getpendingdata',
        columns: [
            { data: 'id', name: 'id' },
            // {  data: 'pagename', name: 'pagename' },
            {  data: 'name', name: 'name' },
            { data: 'address', name: 'address'},
            { data: 'phone', name: 'phone'},
            { data: 'citydata', name: 'citydata'},
            { data: 'action', name: 'action', orderable: false, searchable: false}
        ]
    });


} );
</script>
<script>
 $(document).on('click', '.sendtosellercenter', 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!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

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


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

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

















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

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

$('#product_d').on('change', function(){
    var id = $(this).val();
    $.ajax({
            url: "<?php echo e(url('/getproductprice')); ?>/"+id ,
            method: "get",
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'JSON',
            data:{
                "id":id
            },
            success: function (data) {
                // swal("Done!", "It was successfully deleted!", "success");
                    console.log(data.id);
                    jQuery.each(data, function(key,value){
                        for(i=0; i<value.length; i++){
                            var rid = value[i].id;
                            $('#product_price').val(value[i].sell_price);

                        }

                    });

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

$('#page_name').on('change', function(){
    var id = $(this).val();
    $.ajax({
            url: "<?php echo e(url('/getpagebranch')); ?>/"+id ,
            method: "get",
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            cache: false,
            contentType: false,
            processData: false,
            dataType: 'JSON',
            data:{
                "id":id
            },
            success: function (data) {
                // swal("Done!", "It was successfully deleted!", "success");

                    jQuery.each(data, function(key,value){
                        for(i=0; i<value.length; i++){
                            var rid = value[i].id;
                            // $('#product_price').val(value[i].sell_price);
                            $("#branch").val(value[i].branch).change();
                        }

                    });

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


 $(document).on('click', '.sentocallcenter', 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!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

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

                            //     jQuery.each(data, function(key,value){
                            //         if(value==2){
                            //             toastr.success('No stock, all orders hold')
        
                            //         $('#example12').DataTable().ajax.reload();
                            //         }else{
                            //             toastr.success('All Orders Send successfully')
                            //         $('#example12').DataTable().ajax.reload();
                            //         }

                            // });

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

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


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

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

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

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



 $(document).on('click', '.delallorders', function (e) {
    e.preventDefault();
    let ele = this;
                swal({
                title: "Are you sure?",
                text: "Are you Sure to Remove All Orders",
                icon: "warning",
                showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, Delete!',
                dangerMode: true,
            }).then(function(isConfirm) {
                
                if (isConfirm.value===true) {

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

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

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

</script>
