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

                             <strong class="text-danger">There is <a class="error_link" rel="showcardnumbererrors" data-toggle="modal" data-target="#showCardNumberErrors"><?php echo e(count($card_number_error)); ?></a> Error in Card Number</strong>
                         <?php endif; ?>
                         <?php if(count($customer_name_error)>0): ?>
                         <br>
                             <strong class="text-danger">There is <a class="error_link" rel="showcustomeraddresserrors" data-toggle="modal" data-target="#showCustomerAddressErrors"><?php echo e(count($customer_name_error)); ?></a> Error in Customer Name</strong>
                         <?php endif; ?>
                         <?php if(count($customer_address_error)>0): ?>
                         <br>
                         <strong class="text-danger">There is <a class="error_link" rel="showcustomeraddresserrors" data-toggle="modal" data-target="#showCustomerAddressErrors"><?php echo e(count($customer_address_error)); ?></a> Error in Customer Address</strong>
                         <?php endif; ?>
                         <?php if(count($customer_contact_error)>0): ?>
                         <br>
                             <strong class="text-danger">There is <a class="error_link" rel="showcustomercontacterrors" data-toggle="modal" data-target="#showCustomerContactErrors"><?php echo e(count($customer_contact_error)); ?></a> Error in Customer Contact</strong>
                         <?php endif; ?>
                         <?php if(count($city_error)>0): ?>
                         <br>
                             <strong class="text-danger">There is <a class="error_link" rel="showcityerrors" data-toggle="modal" data-target="#showCityErrors"><?php echo e(count($city_error)); ?></a> Error in City</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/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/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.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.excel_card);
                                row.push(values.customer_name);
                                row.push(values.customer_address);
                                row.push(values.excel_contact);
                                row.push(values.card_category);
                                row.push(values.excel_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: [{
                           text: '<i class="la la-plus"></i> Upload Raw Data',
                           className: 'btn btn-dark',
                           enabled: true,
                           action: function (e, dt, node, config) {
                                $('#addSourceData').modal('show');
                               var $invoker = $(e.relatedTarget);
                               var action = 'addsourcedata';
    
                               if(action === 'addsourcedata'){
                                    $.get( "source_data/form", function( data ) {
                                       $("#addSourceDataDiv").html(data);
                                   });
                               }
                           }
    
                        },{
                        extend: 'excel',
                        title: 'Source Data',
                        className: 'btn btn-dark',
                        text: '<i class="la la-file-excel-o"></i> Excel',
                        },
                        {
                           text: '<i class="la la-plus"></i> Upload ATM File',
                           className: 'btn btn-dark',
                           enabled: true,
                           action: function (e, dt, node, config) {
                                $('#addATMFile').modal('show');
                               var $invoker = $(e.relatedTarget);
                               var action = 'addatmfile';
    
                               if(action === 'addatmfile'){
                                    $.get( "source_data/add_atm_file", function( data ) {
                                       $("#addATMFileDiv").html(data);
                                   });
                               }
                           }
    
                        }
                        ],
                   
                    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.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: 'source_data.card_number', class: 'align-middle card_number'},
                        {data: 'customer_name', name: 'source_data.customer_name', class: 'align-middle customer_name'},
                        {data: 'customer_address', name: 'source_data.customer_address', class: 'align-middle customer_address'},
                        {data: 'customer_contact', name: 'source_data.customer_contact', class: 'align-middle customer_contact'},
                        {data: 'card_category', name: 'source_data.card_category', class: 'align-middle card_category'},
                        {data: 'city', name: 'source_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'
            });
        });
  
        $("#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);
                });
            }

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

            if(action == 'editsourcedata'){
                $.get( "/source_data/"+id+"/edit/form", function( data ) {
                    $("#editSourceDataDiv").html(data);
                });
            }
        });

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

            if(action == 'showcardnumbererrors'){
                $.get( "/source_data/show_card_number_errors", function( data ) {
                    console.log(data);
                    $("#showCardNumberErrorsDiv").html(data);
                });
            }
        });

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

            if(action == 'showcustomeraddresserrors'){
                $.get( "/source_data/show_customer_address_errors", function( data ) {
                    console.log(data);
                    $("#showCustomerAddressErrorsDiv").html(data);
                });
            }
        });

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

            if(action == 'showcustomercontacterrors'){
                $.get( "/source_data/show_customer_contact_errors", function( data ) {
                    console.log(data);
                    $("#showCustomerContactErrorsDiv").html(data);
                });
            }
        });
        $("#showCityErrors").on("show.bs.modal", function(e) {
            var $invoker = $(e.relatedTarget);
            var action = $invoker.attr('rel');
            

            if(action == 'showcityerrors'){
                $.get( "/source_data/show_city_errors", function( data ) {
                    console.log(data);
                    $("#showCityErrorsDiv").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/index.blade.php ENDPATH**/ ?>