<?php $__env->startSection('title', 'Reconciled Source 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>Reconciled Source Data</h1>
                             <?php if(count($unreconcile_data)>0): ?>
                             <br>

                             <strong class="text-danger">You have <a class="error_link" rel="showunrecociledcardnumbers" data-toggle="modal" data-target="#showUnrecociledCardNumbers"><?php echo e(count($unreconcile_data)); ?></a> unrecociled card numbers</strong>
                         <?php endif; ?>
                        </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">S No.</th>
                                    <th class="border-dark border-darken-1">Card Number</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">City</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/extensions/toastr.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/select2.min.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/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/extensions/toastr.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() {
            jQuery.fn.DataTable.Api.register( 'buttons.exportData()', function ( options ) {
                if ( this.context.length ) {
                    body = [];
                    var params = table.ajax.params();
                    params.start = 0;
                    params.length = -1;
                    var jsonResult = $.ajax({
                        url: '<?php echo e(route('source_data.reconcile_data_ajax')); ?>',
                        data: params,
                        success: function (result) {
                            head = [];
                            head.push('S.No');
                            head.push('Card Number');
                            head.push('Customer Name');
                            head.push('Customer Address');
                            head.push('Contact');
                            head.push('Card Category');
                            head.push('City');


                            $.each(result.data, function(index, values) {
                                row = [];

                                row.push(index + 1);
                                row.push(values.card_number);
                                row.push(values.customer_name);
                                row.push(values.customer_address);
                                row.push(values.customer_contact);
                                row.push(values.card_category);
                                row.push(values.city);

                                body.push(row);
                            });
                        },
                        async: false
                    });

                    return {body: body, header: head};
                }
            } );





            //table start
               var table =  $('.datatable').DataTable({
                   dom: '<"d-inline-block"l><"pull-right"B>tipr',
    
                        buttons: [{
                        extend: 'excel',
                        title: 'Reconcile Data',
                        className: 'btn btn-dark',
                        text: '<i class="la la-file-excel-o"></i> Excel',
                        },
                        // {
                        //    text: 'Proceed <i class="la la-plus"></i>',
                        //    className: 'btn btn-dark',
                        //    enabled: true,
                        //    action: function (e, dt, node, config) {
                               
                        //        var action = 'createbatch';
    
                        //        if(action === 'createbatch'){
                        //             $.get("/source_data/reconcile_data/create_batch");
                        //        }
                        //    }
    
                        // },
                        {
                            text: 'Proceed <i class="la la-plus"></i>',
                           className: 'btn btn-dark',
                           enabled: true,
                        //    action: function (e, dt, node, config) {
                               
                        //        var action = 'createbatch';
    
                        //        if(action === 'createbatch'){
                        //             $.get("/source_data/reconcile_data/create_batch");
                        //        }
                        //    }
                        action: function (e, dt, node, config) {
                        
                                swal({
                                    title: 'Are You Sure?',
                                    text: 'Select Yes to Create a 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 action = 'createbatch';
    
                                        // if(action === 'createbatch'){
                                        //         $.get("/source_data/reconcile_data/create_batch");
                                        // }
                                        $.ajax({
                                        url: '<?php echo route('source_data.reconcile.create_batch'); ?>',
                                        method: 'GET',
                                    }).done(function(data){
                                        if(data.status){

                                            table.draw(true);
                                            toastr.success(data.success, 'Success! Batch Data Created', {positionClass: 'toast-top-center', containerId: 'toast-top-center'});
                                        }else{
                                            toastr.error(data.error, 'Error! No Cards Found to create Batch', {positionClass: 'toast-top-center', containerId: 'toast-top-center'});

                                        }

                                    });
                                    }
                                });
                           
                        
                    }},
                        ],
                   
                    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('source_data.reconcile_data_ajax')); ?>',
                   rowId: 'id',
                    order: [[0, 'desc']],
                    columns: [
                        {orderable: false, searchable: false, name: 'serial_number', class: 'align-middle serial_number', targets: 1, render: function (data, type, row) {return '';}},
                        {data: 'card_number', name: 'reconcile_data.card_number', class: 'align-middle card_number'},
                        {data: 'customer_name', name: 'reconcile_data.customer_name', class: 'align-middle customer_name'},
                        {data: 'customer_address', name: 'reconcile_data.customer_address', class: 'align-middle customer_address'},
                        {data: 'customer_contact', name: 'reconcile_data.customer_contact', class: 'align-middle customer_contact'},
                        {data: 'card_category', name: 'reconcile_data.card_category', class: 'align-middle card_category'},
                        {data: 'city', name: 'reconcile_data.city', class: 'align-middle city'},
                        {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(0)', row).html(index + 1 + info.page * info.length);
    
                   },
                   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('.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();
                   }
                });

            $('input.icheck').iCheck({
                checkboxClass: 'icheckbox_squaret-red',
                radioClass: 'iradio_square-red'
            });
        });
  
        $("#createBatch").on("show.bs.modal", function(e) {
            var $invoker = $(e.relatedTarget);
            var action = $invoker.attr('rel');

            if(action == 'createbatch'){
                $.get( "/source_data/reconcile_data/create_batch", function( data ) {
                    $("#createBatchDiv").html(data);
                });
            }

        });
       
        $("#editReconcileData").on("show.bs.modal", function(e) {
            var $invoker = $(e.relatedTarget);
            var action = $invoker.attr('rel');
            var id = $(e.relatedTarget).data('target-id');
            

            if(action == 'editreconciledata'){
                $.get( "/source_data/reconcile_data/"+id+"/edit/form", function( data ) {
                    $("#editReconcileDataDiv").html(data);
                });
            }
        });
        $("#showUnrecociledCardNumbers").on("show.bs.modal", function(e) {
            var $invoker = $(e.relatedTarget);
            var action = $invoker.attr('rel');
            

            if(action == 'showunrecociledcardnumbers'){
                $.get( "/source_data/reconcile_data/show_unrecociled_card_numbers", function( data ) {
                    console.log(data);
                    $("#showUnrecociledCardNumbersDiv").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/source_data/reconcile_data/show_reconcile_data.blade.php ENDPATH**/ ?>