<?php $__env->startSection('title', 'Edit Batch Data'); ?>

<?php $__env->startSection('content'); ?>

    <section>
        <div class="row">
           
            <div class="col-12">

                <div class="card">

                    <div class="card-content">
                        <div class="card-header">
                             <h1>Edit Batch Data</h1>
                           
                        </div>
                        <div class="card-body card-dashboard">
                            <?php echo $__env->make('inc.messages', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                            <table class="table table-bordered datatable" id="datatable" style="z-index: 3;">
                                <thead>
                                <tr class="bg-dark white">
                                    <th class="border-dark border-darken-1"></th>
                                    <th class="border-dark border-darken-1">S No.</th>
                                    <th class="border-dark border-darken-1">CN Number</th>
                                    <th class="border-dark border-darken-1">Batch #</th>
                                    <th class="border-dark border-darken-1">Card Number</th>
                                    <th class="border-dark border-darken-1">Booking Data/Time</th>
                                    <th class="border-dark border-darken-1">Customer Name</th>
                                    <th class="border-dark border-darken-1">Customer Address</th>
                                    <th class="border-dark border-darken-1">Contact</th>
                                    <th class="border-dark border-darken-1">Card Category</th>
                                    
                                    <th class="border-dark border-darken-1">Action</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                    </div>


                </div>
            </div>
        </div>
    </section>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('css'); ?>
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('app-assets/vendors/css/forms/icheck/custom.css')); ?>">
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('app-assets/vendors/css/forms/icheck/icheck.css')); ?>">
    
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('app-assets/vendors/css/forms/selects/selectize.bootstrap4.css')); ?>">
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('app-assets/vendors/css/forms/selects/select2.min.css')); ?>">
    <link rel="stylesheet" type="text/css" href="<?php echo e(asset('app-assets/vendors/css/extensions/toastr.css')); ?>">
   
   <style> 
    .error_link{
        color: #a50303 !important; 
         text-decoration: underline !important;
    }
    </style> 
<?php $__env->stopSection(); ?>
<?php $__env->startSection('js'); ?>
<script src="<?php echo e(asset('app-assets/vendors/js/extensions/toastr.min.js')); ?>" type="text/javascript"></script>
   
<script src="<?php echo e(asset('app-assets/vendors/js/forms/icheck/icheck.min.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('app-assets/js/scripts/forms/checkbox-radio.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('app-assets/vendors/js/forms/select/select2.full.min.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('app-assets/vendors/js/forms/validation/jquery.validate.min.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('app-assets/vendors/js/forms/select/selectize.min.js')); ?>" type="text/javascript"></script>

   <script src="<?php echo e(asset('app-assets/vendors/js/extensions/sweetalert.min.js')); ?>" type="text/javascript"></script>

    <script src="<?php echo e(asset('app-assets/vendors/js/forms/validation/additional-methods.min.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('app-assets/vendors/js/forms/extended/inputmask/jquery.inputmask.bundle.min.js')); ?>" type="text/javascript"></script>
    <script src="<?php echo e(asset('js/datatable_buttons.js')); ?>" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            //table start
       var selected_rows = [];

               var table =  $('.datatable').DataTable({
                   dom: '<"d-inline-block"l><"pull-right"B>tipr',
    
                        buttons: [{
                        extend: 'selectAll',
                        text: 'Select All',
                        className: 'btn btn-dark select_all',
                        action : function(e) {
                            e.preventDefault();
                            table.rows().nodes().each(function(index) {
                                var row = table.row(index);
                                if ($(row.node().firstChild).hasClass('select-checkbox') && !$(row.node()).hasClass('selected')) {
                                    id = parseInt(row.id());
                                        row.select();
                                        var index = $.inArray(id, selected_rows);
                                        if (index === -1) {
                                            selected_rows.push(id);
                                        }
                                        table.button('.proceed_card').enable();
                                        table.button('.unbatch').enable();
                                }
                            });
                        }
                    }, {
                        extend: 'selectNone',
                        text: 'Select None',
                        className: 'btn btn-dark select_none',
                        action : function(e) {
                            e.preventDefault();

                            table.rows().nodes().each(function(index) {
                                var row = table.row(index);

                                if ($(row.node().firstChild).hasClass('select-checkbox')) {
                                    row.deselect();

                                    id = parseInt(row.id());

                                    var index = $.inArray(id, selected_rows);

                                    if (index !== -1) {
                                        selected_rows.splice(index, 1);
                                    }

                                }
                            });
                            
                            $('#submit_selected_status').attr('disabled', true);
                        }
                    },{
                            text: 'Unbatch ',
                           className: 'btn btn-dark unbatch',
                           enabled: false,
                        
                        action: function (e, dt, node, config) {
                        
                                swal({
                                    title: 'Are You Sure?',
                                    text: 'Select Yes to Unbatch Cards!',
                                    icon: 'warning',
                                    buttons: {
                                        cancel: {
                                            text: 'No',
                                            value: null,
                                            visible: true,
                                            closeModal: true,
                                        },
                                        confirm: {
                                            text: 'Yes',
                                            value: true,
                                            visible: true,
                                            closeModal: true
                                        }
                                    },
                                    closeOnClickOutside: false,
                                    closeOnEsc: false,
                                    dangerMode: true
                                }).then(function (confirm) {
                                    if (confirm) {
                                        // var action = 'createbatch';
    
                                        // if(action === 'createbatch'){
                                        //         $.get("/source_data/reconcile_data/create_batch");
                                        // }
                                    }
                                    if (confirm) {
                                                $.ajax({
                                                    url: '<?php echo route('batch_data.unbatch'); ?>',
                                                    method: 'POST',
                                                    data: {
                                                        'batch_cards[]': selected_rows,
                                                        '_token': '<?php echo e(csrf_token()); ?>'
                                                    }
                                                })
                                                    .done(function (data) {
                                                        if (data.status == 1) {
                                                            table.draw();
                                                            toastr.success(data.success, 'Success!', {
                                                                positionClass: 'toast-bottom-center',
                                                                containerId: 'toast-bottom-center'
                                                            });
                                                        } else {
                                                            toastr.error(data.error, 'Error!', {
                                                                positionClass: 'toast-top-center',
                                                                containerId: 'toast-top-center'
                                                            });
                                                        }
                                                        selected_rows = [];

                                                        table.rows().deselect();
                                                        table.button('.unbatch').disable();
                                                        table.button('.proceed_card').disable();
                                                        
                                                    });
                                        }
                                });
                           
                        
                    }},
                        {
                           text: 'Proceed',
                           className: 'btn btn-dark proceed_card',
                           enabled: false,
                        action: function (e, dt, node, config) {
                        if(selected_rows != ''){
                                swal({
                                    title: 'Are You Sure?',
                                    text: 'Select Yes to Proceed Batch!',
                                    icon: 'warning',
                                    buttons: {
                                        cancel: {
                                            text: 'No',
                                            value: null,
                                            visible: true,
                                            closeModal: true,
                                        },
                                        confirm: {
                                            text: 'Yes',
                                            value: true,
                                            visible: true,
                                            closeModal: true
                                        }
                                    },
                                    closeOnClickOutside: false,
                                    closeOnEsc: false,
                                    dangerMode: true
                                }).then(function (confirm) {
                                    if (confirm) {
                                       
                                       var link = '<?php echo e(route('batch_data.proceed_batch', ["ids" => 0])); ?>';
                                     window.location = link.substr(0, link.lastIndexOf('/')) + '/proceed_batch/'+ selected_rows;

                                        // window.location = link.substr(0, link.lastIndexOf('/')) + '/' + selected_rows;
                                       
                                    }
                                });
                            }else{
                                var error = "Something went wrong please refresh page and try again!";
                                toastr.error(error, 'Error!', {positionClass: 'toast-top-center', containerId: 'toast-top-center'});
                                table.button('.proceed_card').disable();
                                table.button('.unbatch').disable();

                            }
                    }},
                        ],
                    select: {
                    info: false,
                    style: 'multi',
                    selector: 'td.select-checkbox',
                    className: 'selected bg-success bg-lighten-5 success'
                },
                    scrollX: true, scrollY: '500px',
                    lengthMenu: [[50, 100, 500, 1000, -1], [50, 100, 500, 1000, 'All']],
                    pageLength: 50,
                    pagingType: 'full_numbers',
                    processing: true,
                    language: {
                        processing: data_table_loader
                    },
                    serverSide: true,
                    ajax : '<?php echo e(route('batch_data.edit_ajax',['id' => $batch_data->id])); ?>',
                   rowId: 'id',
                    order: [[0, 'desc']],
                    columns: [
                        {data: 'batch_card_data.id', orderable: false, searchable: false, class: 'text-center align-middle select p-1', targets: 0, render: function (data, type, row) {return '';}},
                        {orderable: false, searchable: false, name: 'serial_number', class: 'align-middle serial_number', targets: 1, render: function (data, type, row) {return '';}},
                        {data: 'tracking_number', name: 'batch_data_cards.tracking_number', class: 'align-middle tracking_number'},
                        {data: 'batch_data_id', name: 'batch_data_cards.batch_data_id', class: 'align-middle batch_data_id'},
                        {data: 'card_number', name: 'batch_data_cards.card_number', class: 'align-middle card_number'},
                        {data: 'created_at', name: 'batch_data_cards.created_at', class: 'align-middle created_at'},
                        {data: 'customer_name', name: 'batch_data_cards.customer_name', class: 'align-middle customer_name'},
                        {data: 'customer_address', name: 'batch_data_cards.customer_address', class: 'align-middle customer_address'},
                        {data: 'customer_contact', name: 'batch_data_cards.customer_contact', class: 'align-middle customer_contact'},
                        {data: 'card_category', name: 'batch_data_cards.card_category', class: 'align-middle card_category'},
                        {data: 'action', name: 'action', class: 'align-middle text-center action', orderable: false, searchable: false}
                    ],
                   rowCallback: function(row, data, index) {
                       var info = table.page.info();
                       $('td:eq(1)', row).html(index + 1 + info.page * info.length);
                       
                        if ($.inArray(data.id, selected_rows) !== -1) {
                            table.row(row).select();
                        }
                        if(data.status == 0){
                         $('tr', row).addClass('select-checkbox disabled'); 

                         $('td:eq(0)', row).addClass('select-checkbox disabled'); 
                       
                       }
                   },
                   initComplete: function() {
                       var search = $('<tr role="row" class="bg-dark bg-lighten-1 search"></tr>').appendTo(this.api().table().header());
    
                       var td = '<td style="padding:5px;" class="border-dark border-lighten-2"><fieldset class="form-group m-0 position-relative has-icon-right"></fieldset></td>';
                       var input = '<input type="text" class="form-control form-control-sm input-sm primary">';
                       var icon = '<div class="form-control-position primary"><i class="la la-search"></i></div>';
                      this.api().columns().every(function(column_id) {
                           var column = this;
                           var header = column.header();
    
                           if ($(header).is('.select') || $(header).is('.serial_number') || $(header).is('.action') ) {
                               $(td).appendTo($(search));
                           }
                           else {
                               var current = $(input).appendTo($(search)).on('change', function() {
                                   column.search($(this).val(), false, false, true).draw();
                               }).wrap(td).after(icon);
    
                               if (column.search()) {
                                   current.val(column.search());
                               }
                           }
                       });
                       
                       this.api().table().columns.adjust();
                   }
                });
                $('#datatable tbody').on('click', 'tr td.select-checkbox', function() {
                var id = parseInt($(this).parent('tr').attr('id'));
                 console.log(id);
                var index = $.inArray(id, selected_rows);
                if (index === -1) {
                    selected_rows.push(id);
                }
                else {
                    selected_rows.splice(index, 1);
                }

                if (selected_rows.length > 0) {
                    table.button('.unbatch').enable();
                    table.button('.proceed_card').enable();
                    
                }
                else {
                    table.button('.unbatch').disable();
                    table.button('.proceed_card').disable();
                   
                }
                console.log(selected_rows);
        });
            $('input.icheck').iCheck({
                checkboxClass: 'icheckbox_squaret-red',
                radioClass: 'iradio_square-red'
            });
        });
        
        $("#addSourceData").on("show.bs.modal", function(e) {
            var $invoker = $(e.relatedTarget);
            var action = $invoker.attr('rel');

            if(action == 'addsourcedata'){
                $.get( "/source_data/form", function( data ) {
                    $("#addSourceDataDiv").html(data);
                });
            }

        });

        $("#addATMFile").on("show.bs.modal", function(e) {
            var $invoker = $(e.relatedTarget);
            var action = $invoker.attr('rel');

            if(action == 'addatmfile'){
                $.get( "/source_data/add_atm_file", function( data ) {
                    $("#addATMFileDiv").html(data);
                });
            }

        });
        
        $("#editBatchDataCards").on("show.bs.modal", function(e) {
            var $invoker = $(e.relatedTarget);
            var action = $invoker.attr('rel');
            var id = $(e.relatedTarget).data('target-id');
            if(action == 'editbatchdatacards'){
                $.get( "/batch_data/cards/"+id+"/edit/form", function( data ) {
                    $("#editBatchDataCardsDiv").html(data);
                });
            }
        });

    </script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layout.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\laragon\www\catalyst\resources\views/batch_data/show_batch_cards.blade.php ENDPATH**/ ?>