<?php $__env->startSection('filter'); ?>
    <div id="datatable-filter" class="fixed new_filter" data-current-user="Art Ramadani" data-order-by-status="1" data-max-chat-history="25">
        <div class="filter-inner">
            <h2 class="filter-header">
                <a href="#" class="filter-close" data-animate="1"><i class="entypo-cancel"></i></a>
                <i class="fa fa-filter"></i>
                Filter
            </h2>
            <form id="service_filter" method="get"    class="form-horizontal form-groups-bordered validate" novalidate>
                <div class="form-group">
                    <label for="field-1" class="control-label">Name</label>
                    <?php echo Form::text('Name', '', array("class"=>"form-control")); ?>

                </div>
                <div class="form-group">
                    <label for="field-1" class="control-label">Type</label>
                    <?php echo Form::select('Type',['' => 'Select' , 'Fixed' => 'Fixed' , 'Percentage' => 'Percentage'],'', array("class"=>"select2 small")); ?>

                </div>
                <div class="form-group">
                    <label for="field-1" class="control-label">Late Fee Apply</label>
                    <?php echo Form::select('LateFeeApply',['' => 'Select' , 'Daily' => 'Daily' , 'Weekly' => 'Weekly' ,'Once' => 'Once' , 'Monthly' => 'Monthly' , '15 Days' => '15 Days'],'', array("class"=>"select2")); ?>

                </div>
                <div class="form-group">
                    <label for="field-1" class="control-label">Status</label><br/>
                    <p class="make-switch switch-small">
                        <input id="Status" name="Status" type="checkbox" checked>
                    </p>
                </div>
                <div class="form-group">
                    <br/>
                    <button type="submit" class="btn btn-primary btn-md btn-icon icon-left">
                        <i class="entypo-search"></i>
                        Search
                    </button>
                </div>
            </form>
        </div>
    </div>
<?php $__env->stopSection(); ?>


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

<ol class="breadcrumb bc-3">
    <li>
        <a href="<?php echo action('dashboard'); ?>"><i class="entypo-home"></i>Home</a>
    </li>
    <li class="active">
        <strong>Late Fee</strong>
    </li>
</ol>
<h3>Late Fee</h3>
<p class="text-right">
<?php if(User::checkCategoryPermission('Service','Add')): ?>
    <a href="#" data-action="showAddModal" data-type="Late Fee" data-modal="add-new-modal-service" class="btn btn-primary">
        <i class="entypo-plus"></i>
        Add New
    </a>
<?php endif; ?>
</p>

<table class="table table-bordered datatable" id="table-4">
    <thead>
    <tr>
        <th>Name</th>
        <th>Type</th>
        <th>Value</th>   
        <th>Late Fee Apply</th>
        <th>Status</th>
        <th>Actions</th>
    </tr>
    </thead>
    <tbody>
 

    </tbody>
</table>

<script type="text/javascript">
    var $searchFilter = {};
    jQuery(document).ready(function ($) {

        $('#filter-button-toggle').show();

        $searchFilter.Name = $("#service_filter [name='Name']").val();
        $searchFilter.LateFeeApply = $("#service_filter [name='LateFeeApply']").val();
        $searchFilter.Type = $("#service_filter [name='Type']").val();
        $searchFilter.Status = $("#service_filter [name='Status']").prop("checked");

        data_table = $("#table-4").dataTable({

            "bProcessing":true,
            "bServerSide":true,
            "sDom": "<'row'<'col-xs-6 col-left'l><'col-xs-6 col-right'<'export-data'T>f>r>t<'row'<'col-xs-6 col-left'i><'col-xs-6 col-right'p>>",
            "sAjaxSource": baseurl + "/latefee/ajax_datagrid",
            "iDisplayLength": parseInt('<?php echo CompanyConfiguration::get('PAGE_SIZE'); ?>'),
            "sPaginationType": "bootstrap",
            "aaSorting"   : [[0, 'desc']],
            "fnServerParams": function(aoData) {
                aoData.push({"name":"Name","value":$searchFilter.Name},{"name":"LateFeeApply","value":$searchFilter.LateFeeApply},{"name":"Status","value":$searchFilter.Status},{"name":"Type","value":$searchFilter.Type});
                data_table_extra_params.length = 0;
                data_table_extra_params.push({"name":"Name","value":$searchFilter.Name},{"name":"LateFeeApply","value":$searchFilter.LateFeeApply},{"name":"Status","value":$searchFilter.Status},{"name":"Type","value":$searchFilter.Type},{ "name": "Export", "value": 1});
            },
            "aoColumns": 
             [
                { "bSortable": true  }, //Status
                { "bSortable": true }, //Name
                { "bSortable": true }, //Type
                { "bSortable": true }, //Gateway
                { "bSortable": true ,
                    mRender: function ( id, type, full ) {
                        if(id == 1){
                            var output = 'Active';
                        }else{
                            var output = 'Inactive';
                        }
                        return output;
                    }
                }, //Gateway
                {
                   "bSortable": true,
                    mRender: function ( id, type, full ) {
                        var action , edit_ , show_, delete_ ;
                        action = '<div class = "hiddenRowData" >';
                        action += '<input type = "hidden"  name = "LateFeeName" value = "' + (full[0] != null ? full[0] : '') + '" / >';
                        action += '<input type = "hidden"  name = "Type" value = "' + (full[1] != null ? full[1] : '') + '" / >';
                        action += '<input type = "hidden"  name = "Value" value = "' + (full[2] != null ? full[2] : '') + '" / >';
                        action += '<input type = "hidden"  name = "Apply" value = "' + (full[3] != null ? full[3] : '') + '" / >';
                        action += '<input type = "hidden"  name = "Status" value = "' + (full[4] != null ? full[4] : 0) + '" / ></div>';
                        <?php if(User::checkCategoryPermission('Service','Edit')){ ?>
                                action += ' <a data-name = "'+full[1]+'" data-id="'+ full[5] +'" title="Edit" class="edit-service btn btn-default btn-sm"><i class="entypo-pencil"></i>&nbsp;</a>';
                        <?php } ?>
                        <?php if(User::checkCategoryPermission('Service','Delete')){ ?>
                                action += ' <a data-id="'+ full[5] +'" title="Delete" class="delete-service btn btn-danger btn-sm"><i class="entypo-trash"></i></a>';
                        <?php } ?>
                        return action;
                      }
                  }
            ],
            "oTableTools":
            {
                "aButtons": [
                {
                    "sExtends": "download",
                    "sButtonText": "EXCEL",
                    "sUrl": baseurl + "/latefee/exports/xlsx",
                    sButtonClass: "save-collection btn-sm"
                },
                {
                    "sExtends": "download",
                    "sButtonText": "CSV",
                    "sUrl": baseurl + "/latefee/exports/csv",
                    sButtonClass: "save-collection btn-sm"
                }
                ]
            },
            "fnDrawCallback": function() {
                $(".delete-service.btn").click(function(ev) {
                    response = confirm('Are you sure?');
                    if (response) {
                        var clear_url;
                        var id  = $(this).attr("data-id");
                        clear_url = baseurl + "/latefee/delete/"+id;
                        $(this).button('loading');
                        //get
                        $.get(clear_url, function (response) {
                            if (response.status == 'success') {
                                $(this).button('reset');
                                data_table.fnFilter('',0);
                                toastr.success(response.message, "Success", toastr_opts);
                            } else {
                                data_table.fnFilter('',0);
                                toastr.error(response.message, "Error", toastr_opts);
                            }
                        });
                    }
                    return false;


                });
            }
        });
        /*
        $('#ServiceStatus').change(function() {
             if ($(this).is(":checked")) {
                data_table.fnFilter(1,0);  // 1st value 2nd column index
            } else {
                data_table.fnFilter(0,0);
            } 
        });*/

        $("#service_filter").submit(function(e) {
            e.preventDefault();
            $searchFilter.Name = $("#service_filter [name='Name']").val();
            $searchFilter.LateFeeApply = $("#service_filter [name='LateFeeApply']").val();
            $searchFilter.Type = $("#service_filter [name='Type']").val();
            $searchFilter.Status = $("#service_filter [name='Status']").prop("checked");

            data_table.fnFilter('', 0);
            return false;
        });

        $(".dataTables_wrapper select").select2({
            minimumResultsForSearch: -1
        });

        // Highlighted rows
        $("#table-2 tbody input[type=checkbox]").each(function (i, el) {
            var $this = $(el),
                $p = $this.closest('tr');

            $(el).on('change', function () {
                var is_checked = $this.is(':checked');

                $p[is_checked ? 'addClass' : 'removeClass']('highlight');
            });
        });

        // Replace Checboxes
        $(".pagination a").click(function (ev) {
            replaceCheckboxes();
        });

        $('table tbody').on('click','.edit-service',function(ev){
            ev.preventDefault();
            ev.stopPropagation();
            $('#add-new-service-form').trigger("reset");

            LateFeeName = $(this).prev("div.hiddenRowData").find("input[name='LateFeeName']").val();
            Type = $(this).prev("div.hiddenRowData").find("input[name='Type']").val();
            Value = $(this).prev("div.hiddenRowData").find("input[name='Value']").val();
            Apply = $(this).prev("div.hiddenRowData").find("input[name='Apply']").val();
            Status = $(this).prev("div.hiddenRowData").find("input[name='Status']").val();
            if(Status == 1 ){
                $('#add-new-service-form [name="Status"]').prop('checked',true);
            }else{
                $('#add-new-service-form [name="Status"]').prop('checked',false);
            }

            $("#add-new-service-form [name='Name']").val(LateFeeName);
            $("#add-new-service-form [name='Type']").select2().select2('val',Type);
            $("#add-new-service-form [name='Value']").val(Value);
            $("#add-new-service-form [name='LateFeeApply']").select2().select2('val',Apply);
            $("#add-new-service-form [name='LateFeeID']").val($(this).attr('data-id'));
            $('#add-new-modal-service h4').html('Edit Late Fee');
            $('#add-new-modal-service').modal('show');
        })

    });

</script>
<?php echo $__env->make('latefee.latefeemodal', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout.main', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>