$(document).ready(function () {
    $("a").removeClass("active");
    $(".Report3,.Report_class").addClass("active");
    setTimeout(function () {
        $(".Report_class").click();
    }, 500);

    $('#tbl1').DataTable({
		dom: 'Bfrtip',
		buttons: [
			'copy', 'csv', 'excel', 'pdf', 'print'
		]
	});
    $('#tbl2').DataTable({
		dom: 'Bfrtip',
		buttons: [
			'copy', 'csv', 'excel', 'pdf', 'print'
		]
	});

    var table1 = $('#empTable').DataTable({
		dom: 'Bfrtip',
		buttons: [
			'copy', 'csv', 'excel', 'pdf', 'print'
		]
	});
    var table2 = $('#activity_tbl').DataTable({
		dom: 'Bfrtip',
		buttons: [
			'copy', 'csv', 'excel', 'pdf', 'print'
		]
	});
});

function getEmpDeatailOfDep(dep) {
    HoldOn.open({
        theme: "sk-bounce",
        message: "Please wait...."
    });
    $("#emp_info_body").empty();
    $("#act_body").empty();
    $.ajax({
        url: base_urlJs+"Report_Controller/organizationReportEmpList",
        type: "get",
        data: {dep: dep},
        success: function (data) {
            var arr = JSON.parse(data);
            var empList = arr['empList'];

            var tbody1 = "";
            for (i = 0; empList.length > i; i++) {
                tbody1 += "<tr onclick='openActivityReport(\"" + empList[i]['empId'] + "\")' style='cursor: pointer;'>" +
                        "<td>" + empList[i]['empName'] + "</td>" +
                        "<td>" + empList[i]['empId'] + "</td>" +
                        "<td>" + empList[i]['designation'] + "</td>" +
                        "<td>" + empList[i]['Supervisor'] + "</td>" +
                        "<td>" + empList[i]['satisfaction'] + "</td>" +
                        "<td>" + empList[i]['activitycout'] + "</td>" +
                        "<td>" + empList[i]['duration'] + "</td>" +
                        "</tr>";
            }

            $('#empTable').DataTable().destroy();
            $("#emp_info_body").html(tbody1);
            var table1 = $('#empTable').DataTable({
				dom: 'Bfrtip',
				buttons: [
					'copy', 'csv', 'excel', 'pdf', 'print'
				]
			});

            var activityList = arr['activityList'];
            var tbody2 = "";
            for (i = 0; activityList.length > i; i++) {
                tbody2 += "<tr>" +
                        "<td>" + activityList[i]['activity'] + "</td>" +
                        "</tr>";
            }

            $('#activity_tbl').DataTable().destroy();
            $("#act_body").html(tbody2);
            var table2 = $('#activity_tbl').DataTable({
				dom: 'Bfrtip',
				buttons: [
					'copy', 'csv', 'excel', 'pdf', 'print'
				]
			});
        },
        error: function (jqXhr) {
            if (jqXhr.status == 400) { //Validation error or other reason for Bad Request 400
                var json = $.parseJSON(jqXhr.responseText);
                console.log(json);
                toastsCall('bg-danger', 'Error', 'Internal Server Error!');
            }
        }
    });

    HoldOn.close();
}

function openActivityReport(empId) {
    $("#empId").val(empId);
    $("#report1").submit();

}


