$(document).ready(function () {
    debugger;
    
    datatable('DPrevillages');
    LoadDoctorUserlist();

});

function LoadDoctorUserlist() {
    debugger;
    $('#shade_slot').show();
    debugger;
    var DML = "S";
    var DoctorID = $('#HiddenDoctorID').val();
    var DoctorDetailData = {
        doctor_id: DoctorID,
        Dml_Indicator: DML,
        doctor_user_role_id: $('#hiddenRole_id').val(),
        hospital_id: $('#HospitalId').val(),
        doctor_user_id: $('#hiddenUser_id').val(),
        branch_id: $('#HospitalBranchID').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Previllages/DoctorUserSelect',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(DoctorDetailData),
        success: function (data) {
            debugger;
            var data1 = JSON.parse(data);
            console.log(data1);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                $('#shade_slot').hide();
                $('#tblDoctorUser').empty();
                if (jQuery.isEmptyObject((data1)) || data1=='Records Not Found') {
                    debugger;
                    //tr = $('<table id="DPrevillages" class="table-responsive table table-bordered table-striped dataTable"/>');
                    tr = $('<table id="DPrevillages" class="table table-bordered mt10 table-striped table-hover dt-responsive"/>');
                    var urcheck = $('#URight').val();
                    if (urcheck == "1") {
                        tr.append("<thead><tr><th>S No</th><th>Name</th><th>Email ID</th><th>Mobile Number</th><th>User ID</th><th>Designation</th><th>Designation</th><th>Department</th><th>Sub Department</th><th>Branch</th><th>Role</th><th>Doctor Type</th><th class='col-sm-2'>Actions</th></tr></thead><tbody>");
                    }
                    else if ($('#hiddenRole_id').val()==6)
                    {
                        tr.append("<thead><tr><th>S No</th><th>Name</th><th>Email ID</th><th>Mobile Number</th><th>User ID</th><th>Designation</th><th>Display Designation</th><th>Department</th><th>Sub Department</th><th>Branch</th><th>Role</th><th>Doctor Type</th><th class='col-sm-2'>Actions</th></tr></thead><tbody>");
                    }
                    if (urcheck == "2") {
                        tr.append("<thead><tr><th>S No</th><th>Name</th><th>Email ID</th><th>Mobile Number</th><th>User ID</th><th>Designation</th><th>Department</th><th>Sub Department</th><th>Branch</th><th>Role</th><th>Doctor Type</th></tr></thead><tbody>");
                    }
                    tr.append("</tbody>");
                    $('#tblDoctorUser').append(tr)
                    $.when($('#tblDoctorUser').append(tr));
                    datatable('DPrevillages');
                    //$.when($('#tblDoctorUser').append(tr)).then($('#DPrevillages').DataTable({
                    //    "columnDefs": [{
                    //        //"targets":[1,6],
                    //        "orderable": true,
                    //    }]
                    //}));
                }
                else {

                    user_table_binding(data1);
                    //check_priviliges();
                }
            }
            else {
                console.log(data1);
            }
            //$('#shade_slot').hide();
        },
    });
}
//Load Discount Authorisation
function LoadDiscount(user_id) {
    debugger;
    $('#user_id').val(user_id);
    var DoctorDetailData = {
        hospital_id: $('#HospitalId').val(),
        Dml_Indicator: 'LD',
        //for onemaster
      //  branch_id: branch_id
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Previllages/DoctorUserSelect',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(DoctorDetailData),
        success: function (data) {
            var data1 = JSON.parse(data);
            console.log(data1);
            if (data1.msg == "Success") {
                $('#dis_name').empty();
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    var Discount;
                    var default_opt = '<option value="0">--Select--</option>';
                    if (data1 != "Records Not Found") {
                        $.each(data1, function (i, emp) {
                            Discount = Discount + '<option value="' + emp.master_discount_authorization_id + '">' + emp.discount_authorization_description + '</option>';
                        });
                    }
                    $('#dis_name').append(default_opt + Discount);
                    //for onemaster
                    LoadDiscountTable(user_id);
                }
            }
            else {
                console.log(data1);
            }

        }
    });
}
//for onemaster remove branch_id
function LoadDiscountTable(user_id) {
    debugger
    var DoctorDetailData = {
        hospital_id: $('#HospitalId').val(),
        Dml_Indicator: 'LDT',
        doctor_user_id: user_id
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Previllages/DoctorUserSelect',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(DoctorDetailData),
        success: function (data) {
            var data = JSON.parse(data);
            console.log(data);
            debugger;
            if (data.msg == "Success") {
                $('#disc_auth_table').empty();
                var data1 = data.data;
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    if (data1 != 'Records Not Found') {
                        var status = '';
                        if (data1[0].Expired_status == 'Expired') {
                            status = '<span class="label label-danger">Expired</span>'
                        }                       
                        else {
                            status = '<span class="label label-success">Active</span>'
                        }
                        if (data1[0].status == 2){
                            status = '<span class="label label-warning">In-Active</span>'
                        }
                        var thead = '<thead><tr><th>Discount Name</th><th>Discount Amount</th><th>Discount Type</th><th>Status</th></thead>'
                        var tbody = '<tbody><tr><td>' + data1[0].discount_authorization_description + '</td><td>' + data1[0].maximum_Discount_authorization + '</td><td>' + data1[0].maximum_discount_authorization_Type + '</td><td>' + status + '</td></tr></tbody>'
                        $('#disc_auth_table').append(thead + tbody);
                    }

                }
            }
            else {
                console.log(data1);
            }

        }
    });
}
//Discount Authorisation Name Onchange
$('#dis_name').change(function () {
    var DoctorDetailData = {
        discount_authorization_id: $('#dis_name').val(),
        Dml_Indicator: 'DC'
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Previllages/DoctorUserSelect',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(DoctorDetailData),
        success: function (data) {
            var data1 = JSON.parse(data);
            console.log(data1);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    $('#dis_max').val(data1[0].maximum_Discount_authorization);
                    $('#dis_type').val(data1[0].discount_type);
                }
            }
            else {
                console.log(data1);
            }

        }
    });
})
//User-Discount Authorization Mapping
$('#dis_save').click(function () {
    if ($('#dis_name').val() == "" || $('#dis_name').val() == "0" || $('#dis_name').val() == null) {
        $('#Pdis_name').show();
        $('#Pdis_name').fadeOut(8000);
        $('#Pdis_name').html('Select Discount');
        $('#dis_name').val('');
        $('#dis_name').focus();
        return false;
    }
    else {
        var DoctorDetailData = {
            doctor_user_id: $('#user_id').val(),
            Dml_Indicator: 'DUM',
            discount_authorization_id: $('#dis_name').val()
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/Previllages/DoctorUserSelect',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(DoctorDetailData),
            success: function (data) {
                var data1 = JSON.parse(data);
                console.log(data1);
                if (data1.msg == "Success") {
                    var data1 = data1.data;
                    if (jQuery.isEmptyObject((data1))) {
                    }
                    else {
                        $('#dis_name').val('');
                        $('#dis_max').val('');
                        $('#dis_type').val('');
                        toastr.success('Discount Added Successfully',
                             {
                                 closeButton: true,
                                 progressBar: true,
                                 allowHtml: true,
                                 timeOut: 0,
                             })
                        setTimeout(function () {
                            $('#DisAuth').modal('toggle');
                        }, 3000);

                    }
                }
                else {
                    console.log(data1);
                }

            }
        });
    }
})

function DeleteDoctorUser(val) {
    toastr.warning("<button type='button' id='confirmationRevertYes' class='btn btn-warning btn-xs mt20'>Yes</button><button type='button' id='confirmationRevertNo' class='btn btn-warning btn-xs mt20'>No</button>", 'Are you sure, you want to delete the user?',
                  {
                      closeButton: true,
                      progressBar: true,
                      allowHtml: true,
                      timeOut: 20000000,

                      onShown: function (toast) {
                          $("#confirmationRevertYes").click(function () {
                              var DML = "DEDU";
                              var DoctorDetailData = {
                                  doctor_user_id: val,
                                  Dml_Indicator: DML
                              }
                              $.ajax({
                                  async: true,
                                  type: 'POST',
                                  url: '/Previllages/DoctorUserSelect',
                                  contentType: 'application/json; charset=UTF-8',
                                  data: JSON.stringify(DoctorDetailData),
                                  success: function (data) {
                                      var data1 = JSON.parse(data);
                                      console.log(data1);
                                      if (data1.msg == "Success") {
                                          if (data1.data[0].msg == 'usermapped') {
                                              toastr.warning("The User assigned for a service currently. Unable to Delete the User");
                                          }
                                          else {
                                              toastr.success("Deleted Successfully");
                                              LoadDoctorUserlist();
                                          }
                                      }
                                      else {
                                          console.log(data1);
                                      }
                                  },
                              });
                          })
                          $("#confirmationRevertNo").click(function () {
                              //roleDel();
                          })
                      }
                  })


}
//Load Branch
function LoadBranch() {
    document.getElementById("pkg_branch_id").innerHTML = null;
    var subdepartment = {
        Dml_Indicator: "LBRAN"
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(subdepartment),
        success: function (data) {
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                console.log(data1);
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    debugger;
                    var SubDepartment;
                    var default_opt = '<option value="0">All</option>';
                    $.each(data1.Table, function (i, emp) {
                        SubDepartment = SubDepartment + '<option value="' + emp.hospital_branch_id + '">' + emp.branch_name + '</option>';
                    });
                    $('#pkg_branch_id').append(default_opt + SubDepartment);

                    if ($('#hiddenRole_id').val() != 2) {

                        $('#pkg_branch_id').val($('#HospitalBranchID').val());
                        $('#pkg_branch_id').attr('disabled', true);

                        $('#pkg_branch_id').change();
                    }
                    LoadRole()
                }
            }
            else {
                console.log(data1);
            }
        }
    });
}

$('#user_filter_section').click(function () {
    LoadBranch();
})
//filter
$('#req_filter').click(function () {
    debugger;
    //if ($('#pkg_branch_id').val() == '' || $('#pkg_branch_id').val() == 0) {
    //    $('#Ppkg_branch_id').show();
    //    $('#Ppkg_branch_id').fadeOut(8000);
    //    $('#Ppkg_branch_id').html('Select Branch');
    //    $('#pkg_branch_id').focus();
    //    $('#pkg_branch_id').val('');
    //    return false;
    //}
   // else {
        var DML = "SB";
        var DoctorID = $('#HiddenDoctorID').val();
        var DoctorDetailData = {
            doctor_id: DoctorID,
            Dml_Indicator: DML,
            branch_id: $('#pkg_branch_id').val(),
            doctor_user_role_id: $('#hiddenRole_id').val(),
            doctor_user_id: $('#hiddenUser_id').val(),
            department_id: $('#filter_department').val() == '' ? 0 : $('#filter_department').val(),
            subdepartment_id: $('#filter_subdepartment').val() == '' ? 0 : $('#filter_subdepartment').val(),
            discount_authorization_id: $('#filter_role').val() == '' ? 0 : $('#filter_role').val()
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/Previllages/DoctorUserSelect',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(DoctorDetailData),
            success: function (data) {
                debugger;
                var data1 = JSON.parse(data);
                console.log(data1);
                if (data1.msg == "Success") {
                    var data1 = data1.data;
                    $('#tblDoctorUser').empty();
                    if (jQuery.isEmptyObject((data1))) {
                        debugger;
                        //tr = $('<table id="DPrevillages" class="table-responsive table table-bordered table-striped dataTable"/>');
                        tr = $('<table id="DPrevillages" class="table table-bordered mt10 table-striped table-hover dt-responsive" data-title="user_data" data-size="Legal"" />');

                        var urcheck = $('#URight').val();
                        if (urcheck == "1") {
                            tr.append("<thead><tr><th>S No</th><th>Name</th><th>Email ID</th><th>Mobile Number</th><th>User ID</th><th>Designation</th><th>Display Designation</th><th>Department</th><th>Sub Department</th><th>Branch</th><th>Role</th><th>Doctor Type</th><th class='col-sm-2'>Actions</th></tr></thead><tbody>");
                        }
                        if (urcheck == "2") {
                            tr.append("<thead><tr><th>S No</th><th>Name</th><th>Email ID</th><th>Mobile Number</th><th>User ID</th><th>Designation</th><th>Display Designation</th><th>Department</th><th>Sub Department</th><th>Branch</th><th>Role</th><th>Doctor Type</th></tr></thead><tbody>");
                        }
                        tr.append("</tbody>");
                        $('#tblDoctorUser').append(tr)
                        //$.when($('#tblDoctorUser').append(tr));
                        //datatable('DPrevillages');
                        //$.when($('#tblDoctorUser').append(tr)).then($('#DPrevillages').DataTable({
                        //    "columnDefs": [{
                        //        //"targets":[1,6],
                        //        "orderable": false,
                        //    }]
                        //}));
                    }
                    else {
                        user_table_binding(data1);
                    }
                }
            }
        })
   // }
})

function user_table_binding(data1) {
    debugger;
    //$('#DPrevillages').DataTable().destroy();

    var j = 0;
    //tr = $('<table id="DPrevillages" class="table-responsive table table-bordered table-striped dataTable"/>');
   // tr = $('<table id="DPrevillages" class="table table-bordered mt10 table-striped table-hover dt-responsive"/>');
    tr = $('<table id="DPrevillages" class="table table-bordered mt10 table-striped table-hover dt-responsive" data-title="user_data" data-size="Legal"" />');

    
    var urcheck = $('#URight').val();
    if (urcheck == "1") {
        tr.append("<thead><tr><th>S No</th><th >Name</th><th>Email ID</th><th>Mobile Number</th><th>User ID</th><th>Designation</th><th>Display Designation</th><th>Department</th><th>Sub Department</th><th>Branch</th><th>Role</th><th>Doctor Type</th><th class='tbl-action'>Actions</th></tr></thead><tbody>");
    }
    else if ($('#hiddenRole_id').val() == 6) {
        tr.append("<thead><tr><th>S No</th><th >Name</th><th>Email ID</th><th>Mobile Number</th><th>User ID</th><th>Designation</th><th>Display Designation</th><th>Department</th><th>Sub Department</th><th>Branch</th><th>Role</th><th>Doctor Type</th><th class='tbl-action'>Actions</th></tr></thead><tbody>");
    }

    if (urcheck == "2") {
        tr.append("<thead><tr><th>S No</th><th>Name</th><th>Email ID</th><th>Mobile Number</th><th>User ID</th><th>Designation</th><th>Display Designation</th><th>Department</th><th>Sub Department</th><th>Branch</th><th>Role</th><th>Doctor Type</th></tr></thead><tbody>");
    }
    $.each(data1, function (i, emp) {
        j++;

        var edit = '', edit1 = '', del = '', discount = '', ActiveInAct = '',doctype='';

        edit = "<a href='/UserCreate?DoctorId=" + emp.doctor_user_id + "&Name=1&LDesignation=LDDSG' class='edit_icon UM_32' title='Edit'><i class='fa fa-pencil' aria-hidden='true'></i></a>";
        edit1 = "<a href='/UserCreate?Doctor_Id=" + emp.doctor_id + "&doctor_type=" + emp.doctor_type + "'class='edit_icon UM_32' title='Edit'><i class='fa fa-pencil' aria-hidden='true'></i></a>";
        del = "<a class='delete_icon' title='Delete' onclick='DeleteDoctorUser(" + emp.doctor_user_id + ")'><i class='fa fa-trash-o' aria-hidden='true'></i></a>";
        doctype = '<a class="" data-toggle="modal" data-target="#doctorpayout" title="Doctor Type">Doctor Type</a>';
        if (emp.doctor_type != 2)
        {
            discount = "<a class='' data-toggle='modal' data-target='#DisAuth' data-show='true' title='Discount' onclick='LoadDiscount(" + emp.doctor_user_id + ")'>Discount</a>";
        }
        view = "<a  href='/UserCreateView?DoctorId=" + emp.doctor_user_id + "' class='' data-toggle='popover' title='View'>View</a>";

        if (emp.doctor_user_status == 1) {
            ActiveInAct = '<a title="Make In Active!" class="inactive_icon" href="javascript:void(0);"  onclick="ActiveDoctorUser(' + emp.doctor_user_id + ',3)"><i class="fa fa-minus-square-o" aria-hidden="true"></i></a> ';
        }
        else {
            edit = '', edit1 = '';
            ActiveInAct = '<a title="Make Active!" class="active_icon" href="javascript:void(0);"  onclick="ActiveDoctorUser(' + emp.doctor_user_id + ',1)"><i class="fa fa-check-square-o" aria-hidden="true"></i></a> ';
        }
        other_info2 = '<div class="dropdown"><i class="fa fa-ellipsis-h dropdown-toggle pull-right" data-toggle="dropdown" aria-expanded="true"></i> <ul class="dropdown-menu info-dropdown-new"><div class="disp_if mb-10"><li>' + edit + '</li><li>' + del + '</li><li>' + ActiveInAct + '</li></div><li>' + view + '</li><li>' + discount + '</li><li>' + doctype + '</li></ul></div>';
        other_info1 = '<div class="dropdown"><i class="fa fa-ellipsis-h dropdown-toggle pull-right" data-toggle="dropdown" aria-expanded="true"></i> <ul class="dropdown-menu info-dropdown-new"><div class="disp_if mb-10"><li>' + edit1 + '</li><li>' + del + '</li><li>' + ActiveInAct + '</li></div><li>' + view + '</li><li>' + discount + '</li></ul></div>';


        if (emp.doctor_user_role_id == "1" || emp.doctor_user_role_id == "0" || emp.doctor_user_role_id == "2") {
            row_data = "<tr><td>" + j + "</td><td class='tbl-name table_name_space'>" + emp.doctor_user_name + "</td><td>" + emp.doctor_user_email_id + "</td><td>" + emp.doctor_user_mobile_no + "</td><td>" + emp.user_code + "</td><td>" + emp.doctor_user_designation + "</td><td>" + emp.display_designation + "</td><td>" + emp.department_name + "</td><td>" + emp.subdepartment_name + "</td><td>" + emp.multibranch + "</td><td>" + emp.doctor_user_role_name + "</td><td>" + emp.doctor_typename + "</td><td>" + other_info1 + "</td></tr>";
        }
        else {
            row_data = "<tr><td>" + j + "</td><td class='tbl-name table_name_space'>" + emp.doctor_user_name + "</td><td>" + emp.doctor_user_email_id + "</td><td>" + emp.doctor_user_mobile_no + "</td><td>" + emp.user_code + "</td><td>" + emp.doctor_user_designation + "</td><td>" + emp.display_designation + "</td><td>" + emp.department_name + "</td><td>" + emp.subdepartment_name + "</td><td>" + emp.multibranch + "</td><td>" + emp.doctor_user_role_name + "</td><td>" + emp.doctor_typename + "</td><td>" + other_info2 + "</td></tr>";
        }

        tr.append(row_data);
    });
    tr.append("</tbody>");
    $.when($('#tblDoctorUser').append(tr));
    datatable('DPrevillages', 'user_data', 'Legal');
    //datatable('DPrevillages');
    //$.when($('#tblDoctorUser').append(tr)).then($('#DPrevillages').DataTable({
    //    "columnDefs": [{
    //        //"targets":[1,6],
    //        "orderable": false,
    //    }]
    //}));
}
//clear
$('#req_clear').click(function () {

    if ($('#hiddenRole_id').val() == 2) {
        $("#pkg_branch_id").val(0);
    }

    
    $('#filter_role').val('0');
    $('#filter_department').val('0');
    $('#filter_subdepartment').val('0');
    LoadDoctorUserlist();
})
//Branch change function
$('#pkg_branch_id').change(function () {
    LoadRole();
    LoadDepartment();
    //$("#pkg_branch_id").val(0);
    $('#filter_role').empty();
    $('#filter_department').empty();
    $('#filter_subdepartment').empty();
})
//Loading Role  based on branch
function LoadRole() {
    var RoleData = {
        Dml_Indicator: "SS",
        created_by: $('#HiddenDoctorID').val(),
        branch_id: $('#pkg_branch_id').val()
    }

    $.ajax({
        async: true,
        type: 'POST',
        url: '/CreateRole/DoctorRole',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(RoleData),
        success: function (data) {
            var data = JSON.parse(data);
            if (data.msg == "Success") {
                var data = data.data;
                debugger;
                if (jQuery.isEmptyObject((data))) {

                }
                else {
                    var tr = '';
                    var SelRole = '';
                    $('#filter_role').empty();
                    var default_opt = '<option value="0">--Select--</option>';
                    var j = 0;
                    if (data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            j++;
                            SelRole = SelRole + '<option value="' + data[i].doctor_user_role_id + '">' + data[i].doctor_user_role_name + '</option>';
                        }

                        $('#filter_role').append(default_opt + SelRole);


                    }


                }

            }
            else {
                console.log(data);
            }

        }

    });

}
//Department filter load function
//Used for Loading the Departments in Hospital for both in Doctorcreation and in EditProfile
function LoadDepartment() {
    debugger;
    var department = {
        Dml_Indicator: "DP",
        branch_id: $('#pkg_branch_id').val()
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(department),
        success: function (data) {
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                console.log(data1)
                $('#filter_department').empty();
                if (jQuery.isEmptyObject((data1))) {
                }
                else {

                    var Department;
                    var default_opt = '<option value="0">--Select--</option>';
                    $.each(data1.Table, function (i, emp) {
                        Department = Department + '<option value="' + emp.master_category_department_id + '">' + emp.name + '</option>';
                    });
                    if (data1.Table.length == 1) {
                        $('#filter_department').append(Department);
                        $('#filter_department').change();
                    }
                    else {
                        $('#filter_department').append(default_opt + Department);
                    }

                }
            }
            else {
                console.log(data1);
            }
        }
    });
}
//Used for Loading the Sub Department DropDown
$("#filter_department").change(function () {
    debugger;
    LoadSubDepartment($('#filter_department').val(), 0);
    // $('#filter_department').prop('disabled', false);
})
function LoadSubDepartment(id) {
    debugger;
    var val = val;
    document.getElementById("filter_subdepartment").innerHTML = null;
    var subdepartment = {
        Dml_Indicator: "SDP",
        Master_cd_id: id
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Hospitalsetup/Category_Department_Ins_Upd_sel',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(subdepartment),
        success: function (data) {
            var data1 = JSON.parse(data);
            if (data1.msg == "Success") {
                var data1 = data1.data;
                console.log(data1);
                if (jQuery.isEmptyObject((data1))) {
                }
                else {
                    var SubDepartment;
                    $('#filter_subdepartment').empty();
                    var default_opt = '<option value="0">--Select--</option>';
                    $.each(data1.Table, function (i, emp) {
                        SubDepartment = SubDepartment + '<option value="' + emp.sub_category_department_id + '">' + emp.sub_cd_name + '</option>';
                    });
                    if (data1.Table.length == 1) {
                        $('#filter_subdepartment').append(SubDepartment);

                    }
                    else {
                        $('#filter_subdepartment').append(default_opt + SubDepartment);
                    }

                }
            }
            else {
                console.log(data1);
            }
        }
    });
}

function ActiveDoctorUser(val, Actid) {
    var message = '', dml = '';

    if (Actid == 1) {
        message = 'Active';
        //dml = 'DUACT';
    }
    else {
        message = 'In Active';
        //dml = 'DUINACT';
    }

    toastr.warning("<button type='button' id='confirmationRevertYes' class='btn btn-warning btn-xs mt20'>Yes</button><button type='button' id='confirmationRevertNo' class='btn btn-warning btn-xs mt20'>No</button>", 'Are you sure, you want to ' + message + ' the user?',
                  {
                      closeButton: true,
                      progressBar: true,
                      allowHtml: true,
                      timeOut: 20000000,

                      onShown: function (toast) {
                          $("#confirmationRevertYes").click(function () {
                              //var DML = dml;
                              var DoctorDetailData = {
                                  doctor_user_id: val,
                                  Dml_Indicator: "DUACT",
                                  discount_authorization_id: Actid
                              }
                              $.ajax({
                                  async: true,
                                  type: 'POST',
                                  url: '/Previllages/DoctorUserSelect',
                                  contentType: 'application/json; charset=UTF-8',
                                  data: JSON.stringify(DoctorDetailData),
                                  success: function (data) {
                                      var data1 = JSON.parse(data);
                                      console.log(data1);
                                      if (data1.msg == "Success") {
                                          if (data1.data[0].msg == 'usermapped') {
                                              toastr.warning("The User assigned for a service currently. Unable to In Active the User");
                                          }
                                          else if (Actid == 1) {
                                              toastr.success("User Active  Successfully");
                                              LoadDoctorUserlist();
                                          }
                                          else {
                                              toastr.success("User In Active  Successfully");
                                              LoadDoctorUserlist();
                                          }
                                      }
                                      else {
                                          console.log(data1);
                                      }
                                  },
                              });
                          })
                          $("#confirmationRevertNo").click(function () {
                              //roleDel();
                          })
                      }
                  })
}