<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of HRMAjax
 *
 * @author Ola
 */
class HRMAjax extends mainController {
    private $permission;

    public function __construct() {
        parent::__construct();
        $this->db = DBConnectorFactory::loadDriver();
        $this->load->model('HRM');
        $this->permission = Session::getPermissionsObject();
    }

    public function landing() {
        self::HRMAjax();
    }

    //    public function ViewDepartmentRequest() {
    //        if (isset($_POST["Branch_Name"])) {
    //            if (isset($_POST['Branch_ID'])) {
    //                $RET = $this->_registry->employee->setData($_POST)->updateDepartment($_POST['Branch_ID']);
    //            } else {
    //                $RET = $this->_registry->branch->setData($_POST)->create();
    //            }
    //            die(empty($RET) ? 'ok' : $RET[0]);
    //        }
    //        if (isset($_POST["GetID"])) { // to update Status of Department and delete 
    //            $Department_ID = $_POST["GetID"];
    //            $delete_department = $this->_registry->employee->deleteDepartment($Department_ID);
    //            die(empty($delete_department) ? "ok" : "error");
    //        }
    //        $columns = array(
    //            array('db' => 'Branch_Name', 'dt' => 0),
    //            array(
    //                'db' => 'Branch_ID',
    //                'dt' => 1,
    //                'formatter' => function( $d ) {
    //                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
    //                                                   "ActionOption" => [
    //                                                       ["title" => CommonLanguage::getMessage("delete"),
    //                                                        "class" => "Delete",
    //                                                        "icon" => "fa-trash"
    //                                                       ],
    //                                                       ["title" => CommonLanguage::getMessage("Edit"),
    //                                                        "class" => "Edit",
    //                                                        "icon" => "fa-pencil"
    //                                                       ]
    //                                                   ]]);
    //                    return $html;
    //                }
    //            )
    //        );
    //        $key = 'Branch_ID';
    //        $table = 'tbl_hrm_branch';
    //        $data = DataTable::complex($_GET, $table, $key, $columns, 'Status_ID = 1');
    //        echo json_encode($data);
    //    }
    //    public function viewJobsRequest() {
    //
    //        if (isset($_GET['code_id'])) {
    //
    //            $id = $_GET['code_id'];
    //            $JobDetails = $this->_registry->job->getJobsDetails($id);
    //            die(json_encode($JobDetails));
    //        }
    //        if (isset($_POST["GetID"])) { // to update Status of Department and delete 
    //            $logged_id = Session::getUserID();
    //            $job_ID = $_POST["GetID"];
    //            $delete_job = $this->_registry->job->deleteJobs($job_ID, $logged_id);
    //            die(json_encode(empty($delete_job) ? 'OK' : $delete_job));
    //        }
    //
    //
    //
    //        $columns = array(
    //            array('db' => 'Job_Name', 'dt' => 0),
    //            array('db' => 'Job_Description', 'dt' => 1),
    //            array(
    //                'db' => 'Job_ID',
    //                'dt' => 2,
    //                'formatter' => function( $d ) {
    //                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => false, "data_id" => $d,
    //                                                   "ActionOption" => [
    //                                                       ["title" => CommonLanguage::getMessage("delete"),
    //                                                        "class" => "btn-success Delete",
    //                                                        "icon" => "fa-trash"
    //                                                       ]
    //                                                   ]]);
    //                    return $html;
    //                }
    //            )
    //        );
    //        $key = 'Job_ID';
    //        $table = 'tbl_hrm_jobs';
    //        $data = DataTable::complex($_GET, $table, $key, $columns, 'Status_ID = 1');
    //        echo json_encode($data);
    //    }
    //    public function addJobRequest() {
    //        if (isset($_POST["Job_Name"])) {
    //            $logged_id = Session::getUserID();
    //            array_push($_POST, $logged_id);
    //            $validate = $this->_registry->job->viewExistingJob($_POST["Job_Name"]);
    //            if ($validate) {
    //                $Ret = $this->_registry->job->setData($_POST)->create();
    //                die(empty($Ret) ? "success" : "error");
    //            } else
    //                die("exists");
    //        }
    //    }
    //    public function ManagePaygradeRequest() {
    //        if (isset($_GET["Job_Id"])) {
    //            $Content = $this->_registry->job->getJobsDetails($_GET["Job_Id"]);
    //            die(json_encode($Content));
    //        }
    //        if (isset($_POST["Job_ID"])) {
    //            $logged_id = Session::getUserID();
    //            array_push($_POST, $logged_id);
    //
    //            $Ret = $this->_registry->job->setData($_POST)->updateJob();
    //            die(empty($Ret) ? "success" : "error");
    //        }
    //    }
    public function PayrollForEmployeeRequest() {
        if (isset($_GET['Payslip_Date'])) {
            $today = $this->_registry->datetoday->getToday();
            $branch = $_GET['Branch'];
            $Year = intval($_GET['Payslip_Date'][0]);
            $Month = intval($_GET['Payslip_Date'][1]);
            $Day = substr($today, 8, 2);
            $Date = $Year . '-' . $Month . '-' . $Day;
            $flag = $_GET['is_actual'] == 1 ? true : false;
            //            $payroll = $this->_registry->employee->viewPayroll(null, $Year, false, $Month, null, $Day, null, null, null, $branch, 84, true);

            $payroll = $this->_registry->employee->viewPayroll(null, $Year, false, $Month, null, $Day, null, null, null, $branch, 84, $flag);
            die(json_encode($payroll));
        }
    }

    public function PayrollForEmployeeActual() {
        if (isset($_GET['Payslip_Date'])) {
            $branch = $_GET['Branch'];
            $Year = intval($_GET['Payslip_Date'][0]);
            $Month = intval($_GET['Payslip_Date'][1]);
            $Day = intval($_GET['Payslip_Date'][2]);
            $Date = $Year . '-' . $Month . '-' . $Day;
            $payroll = $this->_registry->employee->viewPayroll(null, $Year, false, $Month, null, $Day, null, null, null, $branch, 84, true);
            die(json_encode($payroll));
        }
    }

    public function viewEmployeesRequest() {
        if (isset($_POST["GetID"])) { // to update Status of employee and delete 
            $logged_id = Session::getUserID();
            $Employee_ID = $_POST["GetID"];
            $delete_employee = $this->_registry->employee->deleteEmployee($Employee_ID, $logged_id);
            die(empty($delete_employee) ? "OK" : "error");
        }
        $cond = ' Status_ID = 1 ';
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and Is_Hidden = 0 ';
        }
        if(!empty($_GET['dep_id']))
            $cond.=' and Branch_ID = "'.$_GET['dep_id'].'" ';
        if($_GET['emp_type'] !='')
            $cond.=' and IS_Employee = "'.$_GET['emp_type'].'" ';
        $columns = array(
            array('db' => 'Employee_Work_ID', 'dt' => 0),
            array('db' => 'Employee_Name', 'dt' => 1, 'full_search' => true),
            array('db' => 'Employee_MobilePhone', 'dt' => 2),
            array('db' => 'Employee_Email', 'dt' => 3),
            array('db' => 'Employee_StartDate', 'dt' => 4),
            array('db' => 'Branch_Name', 'dt' => 5),
            array('db' => 'Job_Name', 'dt' => 6),
            array(
                'db' => 'Employee_ID',
                'dt' => 7,
                'formatter' => function( $d ) {
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("view"),
                                                        "class" => "View",
                                                        "icon" => "fa-eye",
                                                        "href" => "HRM/viewEmployeesDetails/" . $d,
                                                        "permission" => "viewEmployeesDetails"
                                                       ],
                                                       ["title" => CommonLanguage::getMessage("copy"),
                                                        "class" => "copy_row",
                                                        "icon" => "fa-copy",
                                                        "data-target"=>"#Add_Employee",
                                                        "attr" => "data-id='{$d}'",
                                                        "permission" => "copy_employee"
                                                       ],["title" => CommonLanguage::getMessage("Edit"),
                                                        "class" => "openFrame",
                                                        "icon" => "fa-pencil",
                                                         "attr" => "data-src='HRM/viewEmployeesDetails/{$d}?is_pop=1&modal=1'",
                                                        "permission" => "edit_employee"
                                                       ],
                                                       ["title" => CommonLanguage::getMessage("delete"),
                                                        "class" => "Delete",
                                                        "icon" => "fa-trash",
                                                        "permission" => "DeleteEmployee"
                                                       ],
                                                       ["title" => CommonLanguage::getMessage("print"),
                                                        "class" => "print_emp",
                                                        "icon" => "fa-print",
                                                        "permission" => "print_employee_profile"
                                                       ],
                                                   ]]);
                    return $html;
                }
            )
        );
        $key = 'Employee_ID';
        $table = 'view_employees';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function viewVolunteersRequest() {
        if (isset($_POST["GetID"])) { // to update Status of employee and delete 
            $Volunteers_ID = $_POST["GetID"];
            $result = $this->_registry->employee->deleteVolunteer($Volunteers_ID);
            die(json_encode(empty($result) ? ["OK", ""] : ["error", $result[0]]));
        }
        $columns = array(
            array('db' => 'Volunteer_Work_ID', 'dt' => 0),
            array('db' => 'Volunteer_Name', 'dt' => 1),
            array('db' => 'Volunteer_MobilePhone', 'dt' => 2),
            array('db' => 'Volunteer_Email', 'dt' => 3),
            array('db' => 'Volunteer_StartDate', 'dt' => 4),
            array(
                'db' => 'volunteer_id',
                'dt' => 5,
                'formatter' => function( $d ) {
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("view"),
                                                        "class" => "View",
                                                        "icon" => "fa-eye",
                                                        "href" => "HRM/viewVolunteersDetails/" . $d,
                                                        "permission" => "viewVolunteersDetails"
                                                       ],
                                                       ["title" => CommonLanguage::getMessage("delete"),
                                                        "class" => "Delete",
                                                        "icon" => "fa-trash",
                                                        "permission" => "DeleteVolunteer"
                                                       ],
                                                   ]]);
                    return $html;
                }
            )
        );
        $key = 'volunteer_id';
        $table = 'view_volunteers';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function viewProListRequest() {
        if (isset($_POST["GetID"])) { // to update Status of employee and delete 
            $pro_id = $_POST["GetID"];
            $delete_pro = $this->_registry->employee->deleteproList($pro_id);
            die(empty($delete_pro) ? "OK" : "error");
        }
        $columns = array(
            array('db' => 'pro_name', 'dt' => 0),
            array('db' => 'pro_date', 'dt' => 1),
            array('db' => 'pro_desc', 'dt' => 2),
            array('db' => 'pro_loc', 'dt' => 3),
            array(
                'db' => 'pro_id',
                'dt' => 4,
                'formatter' => function( $d ) {
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("Edit"),
                                                        "class" => "Edit",
                                                        "icon" => "fa-pencil",
                                                        "permission" => "edit_pro_list"
                                                       ],
                                                       //                                    ["title" => CommonLanguage::getMessage("view"),
                                                       //                                        "class" => "View",
                                                       //                                        "icon" => "fa-eye",
                                                       //                                        "href" => "HRM/viewProDetails/" . $d,
                                                       //                                        "permission" => "viewVolunteersDetails"
                                                       //                                    ],
                                                       ["title" => CommonLanguage::getMessage("delete"),
                                                        "class" => "Delete",
                                                        "icon" => "fa-trash",
                                                        "permission" => "delete_pro_list"
                                                       ],
                                                   ]]);
                    return $html;
                }
            )
        );
        $key = 'pro_id';
        $table = 'tbl_pro_vlnt';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function EditEmployees() {
        if (isset($_POST["Employee_FirstName"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->employee->setData($_POST)->update();
            die(empty($RET) ? "ok" : $RET[0]);
            //                if ($RET) {
            //                    die("ok");
            //                } else {
            //                    die("error");
            //                }
        }
        if (isset($_GET["GetEmployeeID"])) {
            $employee_country = $this->_registry->countries->viewCountries();
            $Content = $this->_registry->employee->viewEmployee($_GET["GetEmployeeID"], true);
            die($Content ? json_encode($Content) : "");
        }
    }

    public function EditVolunteers() {
        if (isset($_POST["Volunteer_FirstName"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->employee->setData($_POST)->updateVolunteer();
            die(empty($RET) ? "ok" : $RET[0]);
        }
        if (isset($_GET["GetVolunteerID"])) {
            $employee_country = $this->_registry->countries->viewCountries();
            $Content = $this->_registry->employee->viewVolunteerDetails($_GET["GetVolunteerID"]);
            die($Content ? json_encode($Content) : "");
        }
    }

    public function addDocumentType() {
        if (isset($_POST["Document_Type_Name"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->employee->setData($_POST)->addDocumentType();
            $Type = $this->_registry->material->getLastOfType('tbl_hrm_document_types', 'Document_ID');
            die(empty($RET) ? json_encode($Type) : $RET[0]);
        }
    }

    public function addEmployeeLocation() {
        if (isset($_POST["Location_Name"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->employee->setData($_POST)->addEmployeeLocation();
            $Type = $this->_registry->material->getLastOfType('tbl_employee_location', 'Location_ID');
            die(empty($RET) ? json_encode($Type) : $RET[0]);
        }
    }

    public function addEmployeeNationality() {
        if (isset($_POST["Nationality_Name"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->employee->setData($_POST)->addEmployeeNationality();
            $Type = $this->_registry->material->getLastOfType('tbl_hrm_nationalities', 'Nationality_ID');
            die(empty($RET) ? json_encode($Type) : $RET[0]);
        }
    }

    public function UploadDocument() {
        if (isset($_POST['Document_Name'])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $Insert = $this->_registry->employee->setData($_POST)->insertEmployeeDocument();
            if ($Insert)
                die("success");
            die("error");
        }
    }

    public function addEmployee() {
        if (isset($_POST["Employee_FirstName"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);


            $RET = $this->_registry->employee->setData($_POST)->create();
            die(empty($RET) ? "ok" : $RET[0]);
        }
    }

    public function addVolunteerRequest() {
        $logged_id = Session::getUserID();
        array_push($_POST, $logged_id);
        $RET = $this->_registry->employee->setData($_POST)->createVolunteer();
        die(empty($RET) ? "ok" : $RET[0]);
    }

    public function addEmergencyContact() {
        if (isset($_POST["Employee_ID"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            if ($_POST['IsEdit'] == 0) {
                $RET = $this->_registry->employee->setData($_POST)->addEmergencyContact();
            } else {
                $id = $_POST['EmergencyContact_ID'];
                $RET = $this->_registry->employee->setData($_POST)->updateEmergencyContact($id);
            }
            if (empty($RET))
                die("success");
            else
                die("error");
        }
    }

    public function addEmployeeExpense() {
        if (isset($_POST["Expense_Date"])) {
            $result = $this->_registry->employee->setData($_POST)->addEmployeeExpense();
            if (empty($result))
                die("success");
            else
                die("error");
        }
    }

    public function viewEmployeeExpenseRequest() {
        $cond = '';
        if (isset($_GET['employee_ID'])) {
            $cond = 'Employee_ID= "' . smc_escape($_GET['employee_ID']) . '"';
        }
        $columns = array(
            array('db' => 'Employee_Name', 'dt' => 0, 'full_search' => true),
            array('db' => 'Expense_Date', 'dt' => 1),
            array('db' => 'Expense_Description', 'dt' => 2),
            array('db' => 'Amount', 'dt' => 3)
        );
        $key = 'Expense_ID';
        $table = 'employee_expenses';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function viewEmployeeDependantRequest() {
        $cond = '';
        $columns = array(
            array('db' => 'Employee_Name', 'dt' => 0, 'full_search' => true),
            array('db' => 'Number_Of_Children', 'dt' => 1),
            array('db' => 'child_name', 'dt' => 2),
            array('db' => 'child_dob', 'dt' => 3),
            array('db' => 'child_school', 'dt' => 4),
            array('db' => 'school_type_name', 'dt' => 5),
            array('db' => 'child_class', 'dt' => 6),
            array('db' => 'child_problem', 'dt' => 7),
            array('db' => 'Employee_ID', 'dt' => 8, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => false, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "edit_employee_dependent",
                                                    "icon" => "fa-pencil",
                                                    "permission" => "edit_employee_dependent",
                                                    "data-target"=>"#add_EmployeeDependent"
                                                   ]
                                               ]]);
                return $html;
            }
                 )
        );
        $key = 'Dependant_ID';
        $table = 'dependant_employee';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function viewEmployeeEmergencyContactRequest() {
        if (isset($_POST['GetID'])) {
            $id = $_POST['GetID'];
            $result = $this->_registry->employee->setData($_POST)->deleteEmergencyContact($id);
            die(empty($result) ? "ok" : "error");
        }
        $cond = '';
        if (isset($_GET['employee_ID'])) {
            $cond = 'Employee_ID= "' . smc_escape($_GET['employee_ID']) . '"';
        }
        $columns = array(
            //            array('db' => 'Contact_Name', 'dt' => 0),
            array('db' => 'Relation_Name', 'dt' => 0),
            array('db' => 'EmergencyContact_HomePhone', 'dt' => 1),
            array('db' => 'EmergencyContact_MobilePhone', 'dt' => 2),
            array('db' => 'EmergencyContact_WorkPhone', 'dt' => 3),
            array('db' => 'EmergencyContact_ID', 'dt' => 4, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash",
                                                    "permission" => "deleteEmergencyContact",
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "permission" => "editEmergencyContact",
                                                    "href" => "HRM/addEmergencyContact/{$d}"
                                                   ]
                                               ]]);
                return $html;
            }
                 ),
        );
        $key = 'EmergencyContact_ID';
        $table = 'employee_emergency_contact';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function addEmployeeDependentRequest() {
        if (isset($_POST["Employee_ID"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->employee->setData($_POST)->createEmployeeDependent();
            //            echo"<pre>";die(print_r($RET));
            if (empty($RET))
                die("success");
            else
                die("error");
        }
    }

    public function viewEmployeeChildRequest() {
        if (isset($_POST["Employee_ID"])) {
            $RET = $this->_registry->employee->setData($_POST)->CheckEmployeeChild();
            if ($RET == false) {
                die('error_exist');
            }

            if (!empty($_POST['Entry_ID'])) {
                $RET = $this->_registry->employee->setData($_POST)->updateEmployeeChild($_POST['Entry_ID']);
            } else {
                $RET = $this->_registry->employee->setData($_POST)->createEmployeeChild();
            }
            die(empty($RET) ? 'success' : $RET[0]);
        }


        if (isset($_POST['GetID'])) {
            $id = $_POST['GetID'];
            $result = $this->_registry->employee->setData($_POST)->deleteEmployeeChild($id);
            die(empty($result) ? "ok" : "error");
        }
        $cond = ' 1=1 ';
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and Is_Hidden = 0 ';
        }
        $columns = array(
            array('db' => 'Employee_Name', 'dt' => 0, 'full_search' => true),
            array('db' => 'Amount_Date', 'dt' => 1),
            array('db' => 'Employee_Amount', 'dt' => 2, "formatter" => function($d, $row) {
                return Forms::DecimalNumber($d) . ' ' . $row[5];
            }),
            array('db' => 'note', 'dt' => 3),
            array('db' => 'Entry_id', 'dt' => 4, 'formatter' => function( $d, $row) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d, "attr" => " employee_id='{$row[6]}' currency_id='{$row[7]}' currency_name='{$row[8]}' ",
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash",
                                                    "permission" => "deleteEmployeeChild",
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "permission" => "editEmployeeChild"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("excel"),
                                                    "class" => "excel",
                                                    "icon" => "fa-file-excel-o",
                                                    "href" => "HRM/downloadexcel/" . $row[6] . "/" . $d
                                                   ]
                                               ]]);
                return $html;
            }
                 ),
            array('db' => 'Currency_Symbol', 'dt' => 5),
            array('db' => 'Employee_ID', 'dt' => 6),
            array('db' => 'currency_id', 'dt' => 7),
            array('db' => 'Currency_Name', 'dt' => 8),
        );
        $key = 'Entry_id';
        $table = 'viewemployeechild';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function AddEvaluationQuestionRequest() {
        if (isset($_POST['Question_Name'])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $ret = $this->_registry->employee->setData($_POST)->createEvaluationQuestion();
            die(empty($ret) ? "success" : "error");
        }
    }

    public function EvaluationPerformanceRequest() {
        if (isset($_POST['Employee_ID'])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $result = $this->_registry->employee->setData($_POST)->createEvaluationPerformanceForEmployee();
            die(empty($result) ? "success" : "error");
        }
    }

    public function EvaluationGraphRequest() {
        if (isset($_POST['Year']) && isset($_POST['CheckedValue'])) {
            $Employee_ID = $_POST['Employee_ID'];
            $CheckValue = $_POST['CheckedValue'];
            $year = $_POST['Year'];
            if ($CheckValue == 1) {
                $EvaluationPerEmployee = $this->_registry->employee->getEvalutionPerformance($Employee_ID, $year);
                $EvaluationEmployee = $this->_registry->employee->performanceGraph($Employee_ID, $year);
                die(json_encode([$EvaluationEmployee, $EvaluationPerEmployee]));
            } else if ($CheckValue == 2) {
                $EvaluationPerEmployee = $this->_registry->employee->getEvalutionPerformance($Employee_ID, $year);
                $EvaluationEmployee = $this->_registry->employee->performanceGraph($Employee_ID, $year, true);
                die(json_encode([$EvaluationEmployee, $EvaluationPerEmployee]));
            } else if ($CheckValue == 3) {
                $EvaluationPerEmployee = $this->_registry->employee->getEvalutionPerformance($Employee_ID, $year);
                $EvaluationEmployee = $this->_registry->employee->performanceGraph($Employee_ID, $year, false, true);
                die(json_encode([$EvaluationEmployee, $EvaluationPerEmployee]));
            } else
                die("error");
        }
    }

    public function TotalPayslipRequest() {
        if (isset($_POST['Current_Date']) && isset($_POST['Report_Hrm'])) {
            $year = $_POST['Current_Date'];
            $type = $_POST['Report_Hrm'];
            if ($type == 1) {
                $Total = $this->_registry->employee->TotalPaidPayslip($year);
                die(json_encode($Total));
            } else if ($type == 2) {
                $Total = $this->_registry->employee->TotalPaidOverTime($year);
                die(json_encode($Total));
            } else if ($type == 3) {
                $Total = $this->_registry->employee->TotalPaidAdvance($year);
                die(json_encode($Total));
            } else if ($type == 4) {
                $Total = $this->_registry->employee->TotalPaidLoan($year);
                die(json_encode($Total));
            } else if ($type == 5) {
                $Total = $this->_registry->employee->TotalPaidBonus($year);
                die(json_encode($Total));
            } else if ($type == 6) {
                $Total = $this->_registry->employee->TotalPaidDeduction($year);
                die(json_encode($Total));
            } else if ($type == 7) {
                $Total = $this->_registry->employee->TotalPaidAbsence($year);
                die(json_encode($Total));
            }
        }
    }

    public function TotalOverTimeDeatilsRequest() {
        $cond = '';
        if (isset($_GET['OverTime_Date'])) {
            $date1 = $_GET['OverTime_Date'];
            $year = substr($date1, 0, 4);
            $month = substr($date1, 5, 2);
            $cond = ' YEAR(OverTime_Date)= "' . smc_escape($year) . '" and MONTH(OverTime_Date)="' . smc_escape($month) . '"';
        }
        $columns = array(
            array('db' => 'OverTime_Date', 'dt' => 0),
            array('db' => 'Employee_Name', 'dt' => 1, 'full_search' => true),
            array('db' => 'Branch_Name', 'dt' => 2),
            array('db' => 'Job_Name', 'dt' => 3),
            array('db' => 'Overtime_Amount', 'dt' => 4, "formatter" => function($d, $row) {
                return Forms::DecimalNumber($d) . ' ' . $row[5];
            }),
            array('db' => 'Currency_Symbol', 'dt' => 5
                 )
        );
        $key = 'Overtime_ID';
        $table = 'overtime_paid_details';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function addAbsenceRequest() {
        if (isset($_POST["Employee_ID"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->absence->setData($_POST)->create();
            die(json_encode(empty($RET) ? ["success", ""] : ["error", $RET[0]]));
        }
    }

    public function checkAbsenceRequest() {

        $RET = $this->_registry->absence->checkAbsenceDay($_GET['Employee_ID'], $_GET['Absence_Reason']);
        die(json_encode(empty($RET) ? ["success", ""] : ["error", $RET[0]]));
    }
    public function addDeductionrequest() {
        if (isset($_POST["Deduction_Date"]) && isset($_POST["url"])) {
            if ($_POST["url"] == "true") {
                $Result = $this->_registry->finance->setData($_POST)->createBonusOrDeduction("tbl_hrm_bonuses", "Bonus");
            } else {
                $Result = $this->_registry->finance->setData($_POST)->createBonusOrDeduction("tbl_hrm_deductions", "Deduction");
            }
            die(empty($Result) ? "success" : $Result[0]);
        }
    }

    public function addLoanRequest() {
        if (isset($_POST["Loan_Date"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            if (isset($_POST['Loan_ID'])) {
                $Result = $this->_registry->finance->setData($_POST)->updateLoan();
            } else {
                $Result = $this->_registry->finance->setData($_POST)->addLoan();
            }
            die(empty($Result) ? "OK" : $Result[0]);
        }
    }

    public function addAdvancePaymentRequest() {
        if (isset($_POST["Advance_Payment_Date"])) {
            $_POST['Logged_ID'] = Session::getUserID();
            if (isset($_POST['Advance_Payment_ID'])) {

                $result = $this->_registry->finance->setData($_POST)->updateAdvancePayment();
            } else {


                $result = $this->_registry->finance->setData($_POST)->addAdvancePayment();
            }
            die(empty($result) ? "OK" : $result[0]);
        }
    }

    public function addOverTimeRequest() {

        if (isset($_POST["Employee_ID"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $result = $this->_registry->finance->setData($_POST)->addOverTime();
            die(empty($result) ? "Ok" : $result[0]);
        }
    }

    public function dailyOvertimeRequest() {
        if (isset($_POST['OverTime'])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $result = $this->_registry->finance->setData($_POST)->connectOvertimeToAccountingSystem();
            die(empty($result) ? "ok" : "error");
        }
        $cond = ' 1=1 ';
        //        if (isset($_GET['OverTimeDate'])) {
        //            $date1 = $_GET['OverTimeDate'];
        //            $year = substr($date1, 0, 4);
        //            $month = substr($date1, 5, 2);
        //            $cond .= ' and YEAR(OverTime_Date)= "' . smc_escape($year) . '" and MONTH(OverTime_Date)="' . smc_escape($month) . '"';
        //        }
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and is_actual = 0 ';
        }
         if (isset($_GET['status']) && $_GET['status'] != '') {
            $cond.=' and is_approved = "'.$_GET['status'].'" ';
        }
        if (!empty($_GET['from_date'])  && !empty($_GET['to_date'])) {
            $cond.=' and OverTime_Date between "'.$_GET['from_date'].'" and "'.$_GET['to_date'].'"';

        }
        if (isset($_GET['is_deduction']) ) {
            $cond.=' and is_deduction = "'.$_GET['is_deduction'].'" ';
        }
        if (!empty($_GET['emp_id']) ) {
            $cond.=' and Employee_ID = "'.$_GET['emp_id'].'" ';
        }
        if (!empty($_GET['overtime_id_filter']) ) {
            $cond.=' and Overtime_ID = "'.$_GET['overtime_id_filter'].'" ';
        }
        $columns = array(
            array('db' => 'OverTime_Date', 'dt' => 0),
            array('db' => 'Employee_Name', 'dt' => 1, 'full_search' => true),
            array('db' => 'note', 'dt' => 2),
            array('db' => 'Overtime_Amount', 'dt' => 3, "formatter" => function($d, $row) {
                return Forms::DecimalNumber($d) . ' ' . $row[7];
            }),
            array('db' => 'Overtime_Duration', 'dt' => 4),
            array('db' => 'is_approved', 'dt' => 5, 'formatter' => function( $d ,$row) {
                $Statuses = [$this->_registry->expenses->getStatusName(1) . "#label-info", $this->_registry->expenses->getStatusName(2) . "#label-warning", $this->_registry->expenses->getStatusName(3) . "#label-danger"];
                return '<span class="label ' . explode("#", $Statuses[$d])[1] . '" data-status="' . $d . '">' . explode("#", $Statuses[$d])[0] . '</span>';
            }),
            array('db' => 'Overtime_ID', 'dt' => 6, 'formatter' => function( $d ,$row) {
                $option_array = [["title" => CommonLanguage::getMessage("Edit"),
                                  "class" => "edit",
                                  "href" => "HRM/addOvertime" . ($row[8] ? '/ded/' : '/').($row[9] ? 'act/' : '').  $d,
                                  "icon" => "fa-pencil",
                                  "permission" => ($row[8] ? "editdeduction" : "edit_overtime")
                                 ],["title" => CommonLanguage::getMessage("Delete"),
                                  "class" => "delete_entry",
                                  "icon" => "fa-trash",
                                  "permission" => ($row[8] ? "delete_deduction" : "delete_overtime")
                                 ]];
                if($row[5] == 0){
                    $option_array[]= ["title" => CommonLanguage::getMessage("approve"),
                                      "class" => "Approve",
                                      "icon" => "fa-check",
                                      "permission" => ($row[8] ? "approve_deduction": "approve_overtime"),
                                      "attr"=>"data-status ='1' data-id='" . $d . "' ".($row[5] == 1 || $row[5] == 2 ? 'disabled' : ''),
                                     ];
                    $option_array[]=  ["title" => CommonLanguage::getMessage("Reject"),
                                       "class" => "Reject",
                                       "permission" => ($row[8] ? "approve_deduction": "approve_overtime"),
                                       "icon" => "fa-times",
                                       "attr"=>"data-status ='2' data-id='" . $d . "' ".($row[5] == 1 || $row[5] == 2 ? 'disabled' : ''),
                                      ];
                }
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => $option_array
                                              ]);
                return $html;
            }),
            //            array('db' => 'Is_Paid', 'dt' => 4, "formatter" => function($d, $row) {
            //                return "<div class='overData' data-id='{$row[7]}' data-currency='{$row[8]}' data-overtime ='{$row[6]}' data-amount='{$row[2]}' data-actual='{$row[9]}'>" . Forms::datatable_chekcbox($d) . "</div>";
            //            }),
            array('db' => 'Currency_Symbol', 'dt' => 7),
            array('db' => 'is_deduction', 'dt' => 8),
            array('db' => 'is_actual', 'dt' => 9)
        );
        $key = 'Overtime_ID';
        $table = 'view_daily_overtime';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function addWorkingDayRequest() {
        if (isset($_POST['MyData'])) {
            $RET = $this->_registry->worktimes->setData($_POST)->addWorkingDays();
            die(empty($RET) ? 'ok' : $RET[0]);
        }
        if (isset($_GET['cmd'])) {
            $days = $this->_registry->worktimes->viewUnOrWorkingDays(1);
            die(json_encode($days));
        }
    }

    public function addHolidayRequest() {
        if (isset($_POST['Holiday_ID'])) {
            $holiday_id = $_POST['Holiday_ID'];
            $RET = $this->_registry->worktimes->setData($_POST)->updateHoliday($holiday_id);
        } else {
            $RET = $this->_registry->worktimes->setData($_POST)->addHoliday();
        }
        die(empty($RET) ? "success" : $RET[0]);
    }

    public function viewHolidayRequest() {
        if (isset($_POST["GetID"])) { // to update Status of Shift and delete 
            $delete_holiday = $this->_registry->worktimes->deleteHoliday($_POST["GetID"]);
            die(empty($delete_holiday) ? "OK" : $delete_holiday[0]);
        }
        $columns = array(
            array('db' => 'Holiday_Name', 'dt' => 0),
            array('db' => 'Holiday_Reason', 'dt' => 1),
            array('db' => 'Holiday_From_Date', 'dt' => 2),
            array('db' => 'Holiday_To_Date', 'dt' => 3, 'formatter' => function( $d, $row ) {

                $html = '<span class="holiday" data-name="'.$row[0].'" data-reason="'.$row[1].'" data-from="'.$row[2].'" data-from="'.$row[3].'">'.($row[2] == $d ? '-- -- --' : $d).'</span>';

                return $html;
            }),
            array('db' => 'Holiday_ID', 'dt' => 4, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash",
                                                    "permission" => "editHoliday"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "permission" => "deleteHoliday"
                                                   ]
                                               ]]);
                return $html;
            }
                 ),
        );
        $key = 'Holiday_ID';
        $table = 'tbl_hrm_holidays';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function addUserRequest() {
        if (isset($_POST["User_Name"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->user->setData($_POST)->create();
            die(json_encode(empty($RET) ? "OK" : $RET));
        }
    }

    public function viewUsersRequest() {
        if (isset($_POST["GetID"]) && isset($_POST["Role_ID"])) { // to change role of user
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $USER_ID = $_POST["GetID"];
            $UpdateRole = $this->_registry->role->setData($_POST)->updateRole($USER_ID);
            die(empty($UpdateRole) ? "OK" : "error");
        }
        if (isset($_POST["GetID"])) { // to delete user
            $logged_id = Session::getUserID();
            $USER_ID = $_POST["GetID"];
            $delete_user = $this->_registry->user->delete($USER_ID, $logged_id);
            die(empty($delete_user) ? "OK" : "error");
        }
        if (isset($_POST["ChangePassword"])) { // to delete user
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $change_password = $this->_registry->user->setData($_POST)->updatePassword();
            die(empty($change_password) ? "OK" : "error");
        }

        if (isset($_POST['is_admin'])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $is_admin = $this->_registry->user->setData($_POST)->updateUserIsAdmin();
            die(empty($is_admin) ? "OK" : "error");
        }
        $cond = ' 1=1 ';
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond = ' Is_Hidden = 0 ';
        }
        $columns = array(
            array('db' => 'User_Name', 'dt' => 0),
            array('db' => 'Role_Name', 'dt' => 1),
            array('db' => 'Employee_Name', 'dt' => 2, 'full_search' => true),
            array('db' => 'is_admin', 'dt' => 3, 'formatter' => function($d) {
                return ($d == 0 ? CommonLanguage::getMessage('no') : CommonLanguage::getMessage('yes'));
            }),
            array('db' => 'User_ID', 'dt' => 4, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "permission" => "deleteUser",
                                                    "icon" => "fa-trash"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "EditRole",
                                                    "permission" => "EditUser",
                                                    "icon" => "fa-pencil"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("is_admin"),
                                                    "class" => "Edit_is_admin",
                                                    "permission" => "EditUser",
                                                    "icon" => "fa-pencil"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("EditPassword"),
                                                    "class" => "ChangePassword",
                                                    "permission" => "EditPasswordUser",
                                                    "icon" => "fa-lock"
                                                   ]
                                               ]]);
                return $html;
            }
                 ),
            array('db' => 'Role_ID', 'dt' => 5),
        );
        $key = 'User_ID';
        $table = 'view_users';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function createRoleModalRequest() {
        if (isset($_POST['Role_Name'])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $name = $_POST['Role_Name'];
            $validate = $this->_registry->role->viewAccessLevel($name);
            if ($validate) {
                $RET = $this->_registry->role->setData($_POST)->create();
                die(empty($RET) ? "success" : "error");
            } else
                die("Exists");
        }
    }

    public function viewRolesModalRequest() {
        if (isset($_POST["GetID"]) && isset($_POST["Role_Name"])) { // to update Status
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $Role_ID = $_POST["GetID"];
            $Name = $_POST["Role_Name"];
            $delete_role = $this->_registry->role->setData($_POST)->delete($Role_ID, $Name);
            die(json_encode(empty($delete_role) ? "OK" : $delete_role));
        }
        $columns = array(
            array('db' => 'Role_Name', 'dt' => 0),
            array('db' => 'Role_ID', 'dt' => 1, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => false, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash"
                                                   ],
                                               ]]);
                return $html;
            }
                 ),
        );
        $key = 'Role_ID';
        $cond = 'Status_ID = 1';
        $table = 'tbl_common_roles';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function viewRolesPermissionModalRequest() {
        $cond = 'Role_ID= 1';
        if (isset($_GET['Role_ID'])) {
            $cond = 'Role_ID= "' . smc_escape($_GET['Role_ID']) . '"';
        }
        $columns = array(
            array('db' => 'Permission_Name', 'dt' => 0),
        );
        $key = 'Role_ID';
        $table = 'view_roles_permissions';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function NewAnnouncementRequest() {
        $pubObj = $this->_registry->announcement;
        $pubObj->setData($_POST);

        $Query = isset($_POST['Announcement_ID']) ? $pubObj->update($_POST['Announcement_ID']) : $pubObj->create();
        die(empty($Query) ? 'OK' : $Query[0]);
    }

    public function ViewAnnouncmentRequest() {
        if (isset($_GET["Announcement_ID"]) && isset($_GET["Announcement_Status"])) {
            $logged_id = Session::getUserID();
            array_push($_GET, $logged_id);
            $changeStatus = $this->_registry->announcement->setData($_GET)->updateAnnouncementStatus($_GET["Announcement_ID"], $_GET["Announcement_Status"]);
            $Email = $this->_registry->announcement->sendmail_ToAllEmployee($_GET['Announcement_ID'], $logged_id);
            die(empty($changeStatus) ? "OK" : "error");
        } else if (isset($_GET["Announcement_ID"]) && isset($_GET["RemoveAnnouncement"])) {
            $logged_id = Session::getUserID();
            array_push($_GET, $logged_id);
            $RemoveID = $this->_registry->announcement->setData($_GET)->deleteAnnouncement($_GET["Announcement_ID"]);
            die(empty($RemoveID) ? "OK" : "error");
        }
        $columns = array(
            array('db' => 'Announcement_Title', 'dt' => 0),
            array('db' => 'Announcement_Subtitle', 'dt' => 1),
            array('db' => 'Announcement_DateCreated', 'dt' => 2),
            array('db' => 'Announcement_Status', 'dt' => 3, 'formatter' => function( $d ) {
                $x = 1;
                if ($this->_registry->per->hasPermission('EditAnnouncement')) {
                    $x = 0;
                }
                return Forms::datatable_chekcbox($d, $x);
            }),
            array('db' => 'Announcement_ID', 'dt' => 4, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash",
                                                    "permission" => "DeleteAnnouncement"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "href" => "HRM/NewAnnouncement/" . $d,
                                                    "permission" => "EditAnnouncement"
                                                   ],
                                               ]]);
                return $html;
            }
                 ),
        );
        $key = 'Announcement_ID';
        $cond = 'Status_ID = 1';
        $table = 'tbl_hrm_announcements';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function AssignAcruedLeaveRequest() {
        if (isset($_POST['Employee_ID'])) {
            $result = $this->_registry->worktimes->setData($_POST)->addTakenAccruedDays();
            die(json_encode(empty($result) ? ["success", ""] : ["error", $result[0]]));
        }
    }

    public function AbsenceSettingRequest() {
        if (isset($_POST["GetID"])) {
            $Absence_ID = $_POST["GetID"];
            $delete_Absence = $this->_registry->absence->deleteAbsenceReason($Absence_ID);
            die(empty($delete_Absence) ? "OK" : "error");
        }
        if (isset($_POST["EditID"])) {
            $Absence_ID = $_POST["EditID"];
            $delete_Absence = $this->_registry->absence->viewAbsenceReasons($Absence_ID);
            die($delete_Absence ? json_encode($delete_Absence) : "error");
        }
        $columns = array(
            array('db' => 'Absence_Reason_Name', 'dt' => 0),
            array('db' => 'Absence_Reason_Days', 'dt' => 1),
            array('db' => 'Absence_Reason_ID', 'dt' => 2, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil"
                                                   ],
                                               ]]);
                return $html;
            }
                 ),
        );
        $key = 'Absence_Reason_ID';
        $table = 'tbl_hrm_absence_reasons';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function paidAccruedLeaveRequest() {
        if (isset($_POST['Employee_ID'])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $Result = $this->_registry->worktimes->setData($_POST)->payAccruedDays();
            die(empty($Result) ? "success" : $Result[0] );
        }
    }
    

    public function addUserActualRequest() {
        if (isset($_POST["User_Name"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->user->setData($_POST)->create();
            if ($RET)
                die("success");
            else
                die("error");
        }
    }

    public function viewUsersActualRequest() {
        if (isset($_POST["GetID"]) && isset($_POST["Role_ID"])) { // to change role of user
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $USER_ID = $_POST["GetID"];
            $UpdateRole = $this->_registry->role->setData($_POST)->updateRole($USER_ID);
            die(empty($UpdateRole) ? "OK" : "error");
        }
        if (isset($_POST["GetID"])) { // to delete user
            $logged_id = Session::getUserID();
            $USER_ID = $_POST["GetID"];
            $delete_user = $this->_registry->user->delete($USER_ID, $logged_id);
            die(empty($delete_user) ? "OK" : "error");
        }
        $columns = array(
            array('db' => 'User_Name', 'dt' => 0),
            array('db' => 'Role_Name', 'dt' => 1),
            array('db' => 'Employee_Name', 'dt' => 2, 'full_search' => true),
            array('db' => 'User_ID', 'dt' => 3, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil"
                                                   ]
                                               ]]);
                return $html;
            }
                 ),
            array('db' => 'Role_ID', 'dt' => 4),
        );
        $key = 'User_ID';
        $table = 'view_users';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    //    public function viewEmployeesActualRequest() {
    //        if (isset($_POST["GetID"])) { // to update Status of employee and delete 
    //            $logged_id = Session::getUserID();
    //            $Employee_ID = $_POST["GetID"];
    //            $delete_employee = $this->_registry->employee->deleteEmployee($Employee_ID, $logged_id);
    //            die(empty($delete_employee) ? "OK" : "error");
    //        }
    //        $columns = array(
    //            array('db' => 'Employee_Name', 'dt' => 0),
    //            array('db' => 'Employee_MobilePhone', 'dt' => 1),
    //            array('db' => 'Employee_Email', 'dt' => 2),
    //            array('db' => 'Employee_StartDate', 'dt' => 3),
    //            array('db' => 'Branch_Name', 'dt' => 4),
    //            array('db' => 'Job_Name', 'dt' => 5),
    //            array(
    //                'db' => 'Employee_ID',
    //                'dt' => 6,
    //                'formatter' => function( $d ) {
    //                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
    //                                                   "ActionOption" => [
    //                                                       ["title" => CommonLanguage::getMessage("view"),
    //                                                        "class" => "View",
    //                                                        "icon" => "fa-eye",
    //                                                        "href" => "HRM/viewEmployeesDetails/" . $d
    //                                                       ],
    //                                                       //                                                       ["title" => CommonLanguage::getMessage("expenses"),
    //                                                       //                                                        "class" => "View",
    //                                                       //                                                        "icon" => "fa-usd",
    //                                                       //                                                        "href" => "HRM/viewEmployeeExpenses/" . $d
    //                                                       //                                                       ],
    //                                                       ["title" => CommonLanguage::getMessage("dependant"),
    //                                                        "class" => "View",
    //                                                        "icon" => "fa-child",
    //                                                        "href" => "HRM/viewEmployeeDependent/" . $d
    //                                                       ],
    //                                                       ["title" => CommonLanguage::getMessage("emergency"),
    //                                                        "class" => "View",
    //                                                        "icon" => "fa-phone",
    //                                                        "href" => "HRM/viewEmployeeEmergencyContact/" . $d
    //                                                       ],
    //                                                       ["title" => CommonLanguage::getMessage("delete"),
    //                                                        "class" => "Delete",
    //                                                        "icon" => "fa-trash"
    //                                                       ],
    //                                                   ]]);
    //                    return $html;
    //                }
    //            )
    //        );
    //        $key = 'Employee_ID';
    //        $table = 'view_employeesactual';
    //        $data = DataTable::complex($_GET, $table, $key, $columns, 'Status_ID = 1');
    //        echo json_encode($data);
    //    }

    public function addEmergencyContactActualrequest() {
        if (isset($_POST["Employee_ID"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->employee->setData($_POST)->addEmergencyContact();
            if (empty($RET))
                die("success");
            else
                die("error");
        }
    }

    public function addEmployeeExpenseActualRequest() {
        if (isset($_POST["Expense_Date"])) {
            $result = $this->_registry->employee->setData($_POST)->addEmployeeExpense(1);
            die(empty($result) ? "success" : "error");
        }
    }

    public function addEmployeeDependentActualRequest() {
        if (isset($_POST["Employee_ID"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $RET = $this->_registry->employee->setData($_POST)->createEmployeeDependent();
            if ($RET)
                die("success");
            else
                die("error");
        }
    }

    public function EvaluationPerformanceActualrequest() {
        if (isset($_POST['Employee_ID'])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $result = $this->_registry->employee->setData($_POST)->createEvaluationPerformanceForEmployee();
            die(empty($result) ? "success" : "error");
        }
    }

    public function EvaluationGraphActualRequest() {
        if (isset($_POST['Year']) && isset($_POST['CheckedValue'])) {
            $Employee_ID = $_POST['Employee_ID'];
            $CheckValue = $_POST['CheckedValue'];
            $year = $_POST['Year'];
            if ($CheckValue == 1) {
                $EvaluationPerEmployee = $this->_registry->employee->getEvalutionPerformance($Employee_ID, $year);
                $EvaluationEmployee = $this->_registry->employee->performanceGraph($Employee_ID, $year);
                die(json_encode([$EvaluationEmployee, $EvaluationPerEmployee]));
            } else if ($CheckValue == 2) {
                $EvaluationPerEmployee = $this->_registry->employee->getEvalutionPerformance($Employee_ID, $year);
                $EvaluationEmployee = $this->_registry->employee->performanceGraph($Employee_ID, $year, true);
                die(json_encode([$EvaluationEmployee, $EvaluationPerEmployee]));
            } else if ($CheckValue == 3) {
                $EvaluationPerEmployee = $this->_registry->employee->getEvalutionPerformance($Employee_ID, $year);
                $EvaluationEmployee = $this->_registry->employee->performanceGraph($Employee_ID, $year, false, true);
                die(json_encode([$EvaluationEmployee, $EvaluationPerEmployee]));
            } else
                die("error");
        }
    }

    public function viewEmployeeDeductionRequest() {
        $cond = ' 1=1 ';
        $IsBonus = ($_GET['url'] == 'true') ? true : false;

        if (isset($_POST["GetID"])) {
            $bonus = $_POST['IsBonus'];
            $delete_dedcution = $bonus != 0 ? $this->_registry->finance->setData($_POST)->deletebonus() : $this->_registry->finance->setData($_POST)->deletededcution();


            die(empty($delete_dedcution) ? "OK" : "error");
        }
        if (isset($_GET['IsBonus'])) {
            $IsBonus = $_GET['IsBonus'];
        }
        if (isset($_GET['is_actual']) && $_GET['is_actual'] = 0) {
            $cond.= 'and  is_actual = 0 ';
        }
        if(!empty($_GET['from_date']) && !empty($_GET['to_date'])){
            $cond.=' and Deduction_Date between "'.$_GET['from_date'].'" and "'.$_GET['to_date'].'" ';
        }
        if(!empty($_GET['employee_id'])){
            $cond.=' and Employee_ID="'.$_GET['employee_id'].'" ';
        }
        $columns = array(
            array('db' => 'Employee_Name', 'dt' => 0, 'full_search' => true),
            array('db' => 'Deduction_Description', 'dt' => 1),
            array('db' => 'Deduction_Amount', 'dt' => 2, 'formatter' => function($d, $row) {

                return Forms::DecimalNumber($d) . ' ' . $row[5];
            }),
            array('db' => 'Deduction_Date', 'dt' => 3),
            array(
                'db' => 'Deduction_ID',
                'dt' => 4,
                'formatter' => function( $d, $row ) {
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("Edit"),
                                                        "permission" => $_GET['IsBonus'] == 1 ? "editbonus" : "editdeduction",
                                                        "class" => "Edit",
                                                        "icon" => "fa-pencil",
//                                                                                                "href" => $_GET['IsBonus'] ==1 ? "HRM/addDeduction/".($_GET['is_actual']==1 ? 'act/' : '') . $d . "/0/bonus" : "HRM/addDeduction/" . $d . "/0"
                                                        "href" => "HRM/addDeduction/" . ($row[7] == 1 ? 'act/' : '') . $d .'/0'. ($_GET['IsBonus'] == 1 ? "/bonus" : "")
                                                       ],
                                                       ["title" => CommonLanguage::getMessage("delete"),
                                                        "permission" => $_GET['IsBonus'] === 'true' ? "deletebonus" : "deletededuction",
                                                        "class" => "Delete",
                                                        "icon" => "fa-trash"
                                                       ],
                                                   ]]);
                    return $row['6'] == 0 ? $html : CommonLanguage::getMessage('noauthactions');
                }
            ),
            array('db' => 'Currency_Symbol', 'dt' => 5),
            array('db' => 'is_paid', 'dt' => 6),
            array('db' => 'is_actual', 'dt' => 7)
        );
        $key = 'Deduction_ID';
        $table = $IsBonus ? 'view_bonus' : 'view_dedcutions';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    //    public function addDeductionActualRequest() {
    //        if (isset($_POST["Deduction_Date"]) && isset($_POST["url"])) {
    //            if ($_POST["url"] == "true") {
    //                $Result = $this->_registry->finance->setData($_POST)->createBonusOrDeduction("tbl_hrm_bonuses", "Bonus");
    //            } else {
    //                $Result = $this->_registry->finance->setData($_POST)->createBonusOrDeduction("tbl_hrm_deductions", "Deduction");
    //            }
    //            die(empty($Result) ? "success" : "error");
    //        }
    //    }
    //
    //    public function addLoanActualRequest() {
    //        if (isset($_POST["Loan_Date"])) {
    //            $logged_id = Session::getUserID();
    //            array_push($_POST, $logged_id);
    //            $Result = $this->_registry->finance->setData($_POST)->addLoan(1);
    //            die(empty($Result) ? "success" : "error");
    //        }
    //    }
    //
    //    public function addAdvancePaymentActualRequest() {
    //        if (isset($_POST["Advance_Payment_Date"])) {
    //            $logged_id = Session::getUserID();
    //            array_push($_POST, $logged_id);
    //            $Result = $this->_registry->finance->setData($_POST)->addAdvancePayment(1);
    //            die(empty($Result) ? "success" : "error");
    //        }
    //    }
    //
    //    public function addOverTimeActualRequest() {
    //        if (isset($_GET["Employee_ID"])) {
    //            $EmployeeID = $_GET["Employee_ID"];
    //            $result = $this->_registry->finance->returnBasicSalaryAndShiftDuration($EmployeeID);
    //            die(json_encode($result));
    //        }
    //        if (isset($_POST["Employee_ID"])) {
    //            $logged_id = Session::getUserID();
    //            array_push($_POST, $logged_id);
    //            $result = $this->_registry->finance->setData($_POST)->addOverTime(1);
    //            die(empty($result) ? "success" : "error");
    //        }
    //    }
    //
    //    public function dailyOvertimeActualRequest() {
    //        if (isset($_POST['OverTime'])) {
    //            $logged_id = Session::getUserID();
    //            array_push($_POST, $logged_id);
    //            $result = $this->_registry->finance->setData($_POST)->connectOvertimeToAccountingSystem(1);
    //            die(empty($result) ? "ok" : "error");
    //        }
    //        $cond = '';
    //        if (isset($_GET['OverTimeDate'])) {
    //            $date1 = $_GET['OverTimeDate'];
    //            $year = substr($date1, 0, 4);
    //            $month = substr($date1, 5, 2);
    //            $cond = 'YEAR(OverTime_Date)= "' . smc_escape($year) . '" and MONTH(OverTime_Date)="' . smc_escape($month) . '"';
    //        }
    //        $columns = array(
    //            array('db' => 'OverTime_Date', 'dt' => 0),
    //            array('db' => 'Employee_Name', 'dt' => 1),
    //            array('db' => 'Overtime_Amount', 'dt' => 2, "formatter" => function($d, $row) {
    //                    return Forms::DecimalNumber($d) . ' ' . $row[5];
    //                }),
    //            array('db' => 'Overtime_Duration', 'dt' => 3),
    //            array('db' => 'Is_Paid', 'dt' => 4, "formatter" => function($d, $row) {
    //                    return "<div class='overData' data-id='{$row[7]}' data-currency='{$row[8]}' data-overtime ='{$row[6]}' data-amount='{$row[2]}'>" . Forms::datatable_chekcbox($d) . "</div>";
    //                }),
    //            array('db' => 'Currency_Symbol', 'dt' => 5),
    //            array('db' => 'Overtime_ID', 'dt' => 6),
    //            array('db' => 'Employee_ID', 'dt' => 7),
    //            array('db' => 'Currency_ID', 'dt' => 8),
    //        );
    //        $key = 'Overtime_ID';
    //        $table = 'view_daily_overtime';
    //        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
    //        echo json_encode($data);
    //    }

    public function addShiftRequest() {
        if (isset($_POST['Shift_ID'])) {
            $RET = $this->_registry->worktimes->setData($_POST)->updateShift($_POST['Shift_ID']);
        } else {
            $RET = $this->_registry->worktimes->setData($_POST)->addShifts();
        }
        die(empty($RET) ? "ok" : $RET[0]);
    }

    public function viewShiftsrequest() {
        if (isset($_GET['GetShiftID'])) {
            $id = $_GET['GetShiftID'];
            $result = $this->_registry->worktimes->viewShifts($id);
            $days = $this->_registry->worktimes->viewUnOrWorkingDays(1);
            die(json_encode([$result, $days]));
        }
        if (isset($_POST["GetID"])) { // to update Status of Shift and delete 
            $delete_shift = $this->_registry->worktimes->deleteShift($_POST["GetID"]);
            die(empty($delete_shift) ? "OK" : $delete_shift[0]);
        }
        $columns = array(
            array('db' => 'Shift_Name', 'dt' => 0),
            //            array('db' => 'Working_Day_ID', 'dt' => 1,"formatter" => function($d,$row) {
            //
            //                return $row[5];
            //
            //            }),
            array('db' => 'Working_Day_ID', 'dt' => 1, "formatter" => function($d,$row) {
                if($row[3]=='fx'){
                    $days = json_decode($d, true);
                    $string_arrays = '';
                    for ($i = 0; $i < count($days); $i++) {
                        $val = $days[$i];
                        $string_arrays .= CommonLanguage::getMessage($val['day_id'] == 1 ? 'Monday' : ($val['day_id'] == 2 ? 'Tuesday' : ($val['day_id'] == 3 ? 'Wednesday' : ($val['day_id'] == 4 ? 'Thursday' : ($val['day_id'] == 5 ? 'Friday' : ($val['day_id'] == 6 ? 'Saturday' : 'Sunday'))))));
                        $string_arrays .= ": " . str_replace(array('AM', 'PM'), array('ص', 'م'), $val['Shift_From'] . " &#8703; " . $val['Shift_To']);
                        if ($i < count($days) - 1) {
                            $string_arrays .= '<br/>';
                        }
                    };
                    return $string_arrays;
                }
            }
                 ),
            array('db' => 'Shift_ID', 'dt' => 2, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash",
                                                    "permission" => "DeleteShift"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "permission" => "EditShift",
                                                    "href" => "HRM/addShift/{$d}"
                                                   ]
                                               ]]);
                return $html;
            }
                 ),array('db' => 'shift_type', 'dt' => 3)
        );
        $key = 'Shift_ID';
        $table = 'view_shifts';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    //    public function addEmployeeActual() {
    //        $logged_id = Session::getUserID();
    //        array_push($_POST, $logged_id);
    //        $RET = $this->_registry->employee->setData($_POST)->create(true);
    //        die(empty($RET) ? "ok" : "error");
    //    }

    public function addAbsenceSetting() {
        if (isset($_POST["Absence_Reason"])) {
            if ($_POST['IsEdit'] == 0) {
                $RET = $this->_registry->absence->setData($_POST)->addAbsenceReasons();
            } else {
                $RET = $this->_registry->absence->setData($_POST)->updateAbsenceReason();
            }
            if (empty($RET))
                die("success");
            else
                die("error");
        }
    }

    public function ChangePassword() {
        if (md5(sha1(md5($_POST['User_Old_Password']))) == $_POST['Old_Password']) {
            $result = $this->_registry->user->setData($_POST)->changePassword();
            die(json_encode(empty($result) ? 'OK' : 'error'));
        }
    }

    public function PaidPayrollForEmployee() {
        if (isset($_POST['main']['Employee_ID'])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $Actual = $_POST['main']['Actual'];
            $Ret = $Actual == 1 ? $this->_registry->employee->setData($_POST)->submitUdetailedPayRoll(1) : $this->_registry->employee->setData($_POST)->submitUdetailedPayRoll();
            die(empty($Ret) ? "OK" : $Ret[0]);
        }

    }


    public function EmployeeAbsenceList() {
        $cond = ' 1=1 ';
        if (!$this->_registry->per->hasPermission('ApproveLeave')) {
            $cond .= ' and Employee_ID = "' . smc_session()['user_details']['Employee_ID'] . '"';
        }
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and Is_Hidden = 0 ';
        }
        if (isset($_GET['status']) && $_GET['status'] != '') {
            $cond.=' and is_approved = "'.$_GET['status'].'" ';
        }
        if(!empty($_GET['absence_id_filter'])){
            $cond.= ' and Absence_ID = "'.$_GET['absence_id_filter'].'"';
        }
        if(!empty($_GET['employee_id'])){
            $cond.= ' and Employee_ID = "'.$_GET['employee_id'].'"';
        }
        if(!empty($_GET['absence_reason_id'])){
            $cond.= ' and Absence_Reason_ID = "'.$_GET['absence_reason_id'].'"';
        }
        if(!empty($_GET['start_date']) && !empty($_GET['end_date'])){
            $cond.=' and (Absence_From_Date between "'.$_GET['start_date'].'" and "'.$_GET['end_date'].'"
                or Absence_To_Date between "'.$_GET['start_date'].'" and "'.$_GET['end_date'].'"
                or "'.$_GET['start_date'].'" between Absence_From_Date and Absence_To_Date
                or "'.$_GET['end_date'].'" between Absence_From_Date and Absence_To_Date )';
        }
        
        $columns = array(
            array('db' => 'Absence_ID', 'dt' => 0,
                  "formatter" => function($d,$row) {
                      return ($row[6] == 0 && $this->permission->hasPermission('ApproveLeave')) ? '<input type="checkbox" data-id="' . $d . '" class="employee_absence_check"/>' :'--- ---';
                  }),
            array('db' => 'Name', 'dt' => 1),
            array('db' => 'Absence_From_Date', 'dt' => 2),
            array('db' => 'Absence_To_Date', 'dt' => 3),
            array('db' => 'Absence_To_Date', 'dt' => 4, "formatter" => function($d, $row) {
                     return (CommonFunctions::calc_date_diff($row[2],$d)+1);
//                    $date_diff =    round((strtotime($d) - strtotime($row[2])) / (60 * 60 * 24))+1;
//                $date_diff = date_diff(date_create($d), date_create($row[2]));
//                $html = ($date_diff = intval($date_diff->format("%d"))+1).' '.(CommonLanguage::getMessage('days'));
//                return $date_diff;
            }),
            array('db' => 'Absence_Reason_Name', 'dt' => 5),
            array('db' => 'is_approved', 'dt' => 6,
                  "formatter" => function($d) {
                      $Statuses = [$this->_registry->expenses->getStatusName(1) . "#label-info", $this->_registry->expenses->getStatusName(2) . "#label-warning", $this->_registry->expenses->getStatusName(3) . "#label-danger"];
                      return '<span class="label ' . explode("#", $Statuses[$d])[1] . '" data-status="' . $d . '">' . explode("#", $Statuses[$d])[0] . '</span>';
                  }),
            array(
                'db' => 'Absence_ID',
                'dt' => 7,
                'formatter' => function( $d, $row ) {
                    $option_arr = [["title" => CommonLanguage::getMessage("delete"),
                                    "class" => "deleteAccrued",
                                    "permission" => "delete_absence",
                                    "icon" => "fa-trash"
                                   ]];
                    if($row[7] != ''){
                        $option_arr[]= ["title" => CommonLanguage::getMessage("view"),
                                        "class" => "Viewfile",
                                        "href"=> "uploads/Documents/" . $row[8],
                                        "icon" => "fa-eye",
                                        "attr"=>'target="_blank" style = "' . ($row[8] == '' ? 'cursor: not-allowed;' : '') . '"',
                                       ];
                    }
                    if($row[6] != 1 && $row[6] != 2){
                        $option_arr[]= ["title" => CommonLanguage::getMessage("Edit"),
                                    "class" => "edit_absence",
                                    "permission" => "edit_absence",
                                    "icon" => "fa-pencil"
                                   ];
                        $option_arr[]= ["title" => CommonLanguage::getMessage("approve"),
                                        "class" => "Approve",
                                        "permission" => "ApproveLeave",
                                        "icon" => "fa-check",
                                        "attr"=>"data-status ='1' data-id='" . $d . "' ".($row[6] == 1 || $row[6] == 2 ? 'disabled' : ''),
                                       ];
                        $option_arr[]=  ["title" => CommonLanguage::getMessage("Reject"),
                                         "class" => "Reject",
                                         "permission" => "reject_absence_leave",
                                         "icon" => "fa-times",
                                         "attr"=>"data-status ='2' data-id='" . $d . "' ".($row[6] == 1 || $row[6] == 2 ? 'disabled' : ''),
                                        ];
                    }


                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                                   "ActionOption" => $option_arr]);

                    return $html;
                }
            ),
            array('db' => 'Document_File_Name', 'dt' => 8)
        );
        $key = 'Absence_ID';
        $table = 'employee_absence';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function EmployeeAccruedList() {
        $cond = ' 1=1 ';
        if (!$this->_registry->per->hasPermission('ApproveLeave')) {
            $cond .= ' and Employee_ID = "' . smc_session()['user_details']['Employee_ID'] . '"';
        }
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and Is_Hidden = 0 ';
        }
        if (isset($_GET['status']) && $_GET['status'] != '') {
            $cond.=' and is_approved = "'.$_GET['status'].'" ';
        }
        if(!empty($_GET['leave_id_filter'])){
            $cond.=' and Entry_ID="'.$_GET['leave_id_filter'].'"';
        }
        if(isset($_GET['is_holiday'])){
            $cond.=' and is_holiday="'.$_GET['is_holiday'].'" ';
        }
        if(!empty($_GET['employee_id'])){
            $cond.= ' and Employee_ID = "'.$_GET['employee_id'].'"';
        }
        if(!empty($_GET['start_date']) && !empty($_GET['end_date'])){
            $cond.=' and (Date_From between "'.$_GET['start_date'].'" and "'.$_GET['end_date'].'"
                or Date_To between "'.$_GET['start_date'].'" and "'.$_GET['end_date'].'"
                or "'.$_GET['start_date'].'" between Date_From and Date_To
                or "'.$_GET['end_date'].'" between Date_From and Date_To )';
        }
      
        $columns = array(
            array('db' => 'Entry_ID', 'dt' => 0,
                  "formatter" => function($d,$row) {
                      return ($row[5] == 0 && $this->permission->hasPermission('ApproveLeave') ) ? '<input type="checkbox" data-id="' . $d . '" class="employee_accrued_check"/>' :'--- ---';
                  }),
            array('db' => 'Name', 'dt' => 1),
            array('db' => 'Date_From', 'dt' => 2),
            array('db' => 'Date_To', 'dt' => 3),
            array('db' => 'Days_Number', 'dt' => 4),
            array('db' => 'is_approved', 'dt' => 5,
                  "formatter" => function($d) {
                      $Statuses = [$this->_registry->expenses->getStatusName(1) . "#label-info", $this->_registry->expenses->getStatusName(2) . "#label-warning", $this->_registry->expenses->getStatusName(3) . "#label-danger"];
                      return '<span class="label ' . explode("#", $Statuses[$d])[1] . '" data-status="' . $d . '">' . explode("#", $Statuses[$d])[0] . '</span>';
                  }),
            array(
                'db' => 'Entry_ID',
                'dt' => 6,
                'formatter' => function( $d, $row ) {

                    $option_arr = [["title" => CommonLanguage::getMessage("delete"),
                                    "class" => "deleteAccrued",
                                    "permission" => ($_GET['is_holiday']==1 ? ($_GET['is_actual']==1 ? 'delete_employee_holiday_act' : 'delete_employee_holiday'):"delete_accrued_leave"),
                                    "icon" => "fa-trash"
                                   ]];
                    $option_arr[]= ["title" => CommonLanguage::getMessage("view"),
                                    "class" => "Viewfile",
                                    "href"=> ($row[7] == '' ? 'javascript:void(0)' : SITE_LINK . 'uploads/Documents/' . $row[7]),
                                    "icon" => "fa-eye",
                                    "attr"=>'target="_blank" style = "' . ($row[7] == '' ? 'cursor: not-allowed;' : '') . '"',
                                   ];
                    if($row[5] != 1 && $row[5] != 2){
                        $option_arr[]= ["title" => CommonLanguage::getMessage("Edit"),
                                    "class" => "edit_leave",
                                    "permission" => ($_GET['is_holiday']==1 ? ($_GET['is_actual']==1 ? 'edit_employee_holiday_act' : 'edit_employee_holiday'):"edit_leave"),
                                    "icon" => "fa-pencil"
                                   ];
                        $option_arr[]= ["title" => CommonLanguage::getMessage("approve"),
                                        "class" => "Approve",
                                        "permission" => ($_GET['is_holiday']==1 ? ($_GET['is_actual']==1 ? 'approve_employee_holiday_act' : 'approve_employee_holiday'):"ApproveLeave"),
                                        "icon" => "fa-check",
                                        "attr"=>"data-status ='1' data-id='" . $d . "' ".($row[5] == 1 || $row[5] == 2 ? 'disabled' : ''),
                                       ];
                        $option_arr[]=  ["title" => CommonLanguage::getMessage("Reject"),
                                         "class" => "Reject",
                                         "permission" => ($_GET['is_holiday']==1 ? ($_GET['is_actual']==1 ? 'approve_employee_holiday_act' : 'approve_employee_holiday'):"ApproveLeave"),
                                         "icon" => "fa-times",
                                         "attr"=>"data-status ='2' data-id='" . $d . "' ".($row[5] == 1 || $row[5] == 2 ? 'disabled' : ''),
                                        ];
                    }


                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                                   "ActionOption" => $option_arr]);

                    return $html;
                }
            ),
            array('db' => 'Document_File_Name', 'dt' => 7)
        );
        //        echo $cond;
        //        die('ok');
        $key = 'Entry_ID';
        $table = 'employee_accrued_leave';
        
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function approveAbsenceRequest() {
        $update = $this->_registry->absence->setData($_POST)->approveAbsenceRequest();
        die(empty($update) ? 'OK' : 'error');
    }
    public function submitMultiApproveAbsence() {
        $update = $this->_registry->absence->setData($_POST)->submitMultiApproveAbsence();
        die(empty($update) ? 'OK' : 'error');
    }
    public function approveRejectOvertime() {
        $update = $this->_registry->absence->setData($_POST)->approveRejectOvertime();
        die(empty($update) ? 'OK' : 'error');
    }

    public function approveAccruedRequest() {
        $update = $this->_registry->worktimes->setData($_POST)->approveAccruedRequest();
        die(json_encode(empty($update) ? ['OK', ""] : ['error', $update[0]]));
    }
    public function submitMultiApproveAccrued() {
        $update = $this->_registry->worktimes->setData($_POST)->submitMultiApproveAccrued();
        die(json_encode(empty($update) ? ['OK', ""] : ['error', $update[0]]));
    }

    public function EmployeeDocumentList() {

        $type = $_GET['Is_Vlnt'] == true ? "vlnt" : "emp";
        $cond = ' Employee_ID = "' . $_GET['emp_id'] . '" and Document_Type <> 0 and main_type = "' . $type . '"';
        $columns = array(
            array('db' => 'Document_Name', 'dt' => 0),
            array('db' => 'Document_Comments', 'dt' => 1),
            array('db' => 'Document_Date', 'dt' => 2),
            array('db' => 'Document_Type_Name', 'dt' => 3),
            array(
                'db' => 'Entry_ID',
                'dt' => 4,
                'formatter' => function( $d, $row ) {
                    $html = '<a href="' . ($row[5] == '' ? 'javascript:void(0)' : SITE_LINK . 'uploads/Documents/' . $row[5]) . '" data-id="' . $d . '"  target="_blank" ><button class="btn Viewfile" style = "' . ($row[5] == '' ? 'cursor: not-allowed;' : '') . '">
<i class="fa fa-eye"></i>  </button></a>';
                    if($this->_registry->per->hasPermission('delete_emp_doc')){
                        $html.='<button data-id="' . $d . '"  class="btn deletefile" >
<i class="fa fa-trash"></i>  </button>';
                    }
                    return $html;
                }
            ),
            array('db' => 'Document_File_Name', 'dt' => 5)
        );
        $key = 'Entry_ID';
        $table = 'employee_documents';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function leaveCalenderRequest() {
        $absence = $this->_registry->absence->viewAbsence('', $_GET['is_actual']);
        $holiday = $this->_registry->worktimes->viewHoliday();
        $accrued_leave = $this->_registry->worktimes->viewAccruedLeave('', $_GET['is_actual']);
        $array = array_merge($absence, $holiday, $accrued_leave);
        die(json_encode($array));
    }

    public function add_employee_deduction_note() {
        $logged_id = Session::getUserID();
        array_push($_POST, $logged_id);
        $RET = $this->_registry->employee->setData($_POST)->addEmployeeDeductionNote();
        die(empty($RET) ? "ok" : "error");
    }

    public function viewEmployeeDeductionNote() {
        $cond = '';
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' is_actual = 0 ';
        }
        $columns = array(
            array('db' => 'Employee_Name', 'dt' => 0, 'full_search' => true),
            array('db' => 'date_time', 'dt' => 1),
            array('db' => 'Employee_IS_Deduction', 'dt' => 2, 'formatter' => function( $d, $row ) {
                $html = CommonLanguage::getMessage($d == 0 ? "bonus" : "deduction_nb");
                return $html;
            }),
            array('db' => 'Employee_Note', 'dt' => 3),
            array('db' => 'status_id', 'dt' => 4,
                  "formatter" => function($d) {
                      $Statuses = [$this->_registry->expenses->getStatusName(1) . "#label-info", $this->_registry->expenses->getStatusName(2) . "#label-warning", $this->_registry->expenses->getStatusName(3) . "#label-danger"];
                      return '<span class="label ' . explode("#", $Statuses[$d])[1] . '" data-status="' . $d . '">' . explode("#", $Statuses[$d])[0] . '</span>';
                  }),
            array(
                'db' => 'Entry_ID',
                'dt' => 5,
                'formatter' => function( $d, $row ) {
                    $html = '';
                    if ($this->_registry->per->hasPermission('deleteEmployeeDedcutionNote')) {
                        $html .= '<a><button ' . ($row[4] == 1 ? 'disabled' : '') . ' class="btn Delete"  data-id="' . $d . '" data-toggle="modal" data-target="">
                                                <i class="fa fa-trash"></i>  </button></a>';
                    }
                    if ($this->_registry->per->hasPermission('rejectEmployeeDedcutionNote')) {
                        $html .= '<a><button  ' . ($row[4] == 1 || $row[4] == 2 ? 'disabled' : '') . '  class="btn Reject" data-status ="2" data-id="' . $d . '" data-toggle="modal" data-target="">
                                                <i class="fa fa-times"></i>  </button></a>';
                    }

                    if ($this->_registry->per->hasPermission('EditEmployeeDeductionNote')) {
                        $html .= '<a href=   "' . ($row[4] == 1 || $row[4] == 2 ? 'javascript:void(0)' : 'HRM/addDeduction/' . ($row[6] == 1 ? "act/" : "") . $d . ($row[2] == 0 ? "/bonus" : '')) . '"   data-id="' . $d . '"  ><button class="btn Viewfile" ' . ($row[4] == 1 || $row[4] == 2 ? 'disabled' : '') . ' style = "' . ($row[4] == 1 || $row[4] == 2 ? 'cursor: not-allowed;' : '') . '">
<i class="fa fa-pencil"></i>  </button></a>';
                    }
                    return $html;
                }
            ),
            array('db' => 'is_actual', 'dt' => 6)
        );
        $key = 'Entry_ID';
        $table = 'tbl_employee_dedcution_note';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function rejectEmployeeDeductionNote() {
        $logged_id = Session::getUserID();
        array_push($_POST, $logged_id);
        $update = $this->_registry->employee->setData($_POST)->rejectEmployeeDeductionNote();
        die(empty($update) ? 'OK' : 'error');
    }

    public function deleteEmployeeDeductionNote() {
        $update = $this->_registry->employee->setData($_POST)->deleteEmployeeDeductionNote();
        die(empty($update) ? 'OK' : 'error');
    }

    public function viewAdvancePaymentRequest() {
        $cond = ' 1=1 ';
        if (isset($_POST["GetID"])) {
            $delete_advance = $this->_registry->finance->setData($_POST)->deleteAdvancePayment();
            die(empty($delete_advance) ? "OK" : $delete_advance[0]);
        }
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and is_actual=0 ';
        }
          if (isset($_GET['status']) && $_GET['status'] != '') {
            $cond.=' and is_approved = "'.$_GET['status'].'" ';
        }
        if (!empty($_GET['from_date'])  && !empty($_GET['to_date'])) {
            $cond.=' and Advance_Payment_Date between "'.$_GET['from_date'].'" and "'.$_GET['to_date'].'"';

        }
        
        if (!empty($_GET['emp_id']) ) {
            $cond.=' and Employee_ID = "'.$_GET['emp_id'].'" ';
        }
        if (!empty($_GET['advance_id_filter']) ) {
            $cond.=' and Advance_Payment_ID = "'.$_GET['advance_id_filter'].'" ';
        }
        $columns = array(
            array('db' => 'employee_name', 'dt' => 0, 'full_search' => true),
            array('db' => 'Advance_Payment_Description', 'dt' => 1),
            array('db' => 'Advance_Payment_Amount', 'dt' => 2, 'formatter' => function( $d, $row ) {
                return Forms::DecimalNumber($d) . ' ' . $row[6];
            }),
            array('db' => 'Advance_Payment_Date', 'dt' => 3),
            array('db' => 'is_approved', 'dt' => 4,
                  "formatter" => function($d) {
                      $Statuses = [$this->_registry->expenses->getStatusName(1) . "#label-info", $this->_registry->expenses->getStatusName(2) . "#label-warning", $this->_registry->expenses->getStatusName(3) . "#label-danger"];
                      return '<span class="label ' . explode("#", $Statuses[$d])[1] . '" data-status="' . $d . '">' . explode("#", $Statuses[$d])[0] . '</span>';
                  }),
            array('db' => 'Advance_Payment_ID', 'dt' => 5, 'formatter' => function( $d, $row ) {

                $option_arr = [["title" => CommonLanguage::getMessage("View"),
                                "class" => "View openFrame",
                                "icon" => "fa-eye",
                                "attr" => "data-src='HRM/view_advance_payment/" . "{$d}?is_pop=1'"

                               ],
                               ["title" => CommonLanguage::getMessage("delete"),
                                "class" => "Delete",
                                "icon" => "fa-trash",
                                "permission" => $row[8] == 1 ? "DeleteActAdvancePayment" : "DeleteAdvancePayment"
                               ],
                               ["title" => CommonLanguage::getMessage("Edit"),
                                "class" => "Edit",
                                "icon" => "fa-pencil",
                                "permission" => $row['is_actual'] == 1 ? "EditActAdvancePayment" : "EditAdvancePayment",
                                "href" => "HRM/addAdvancePayment/" . ($row[8] == 1 ? 'act/' : '') . $d
                               ]
                              ];


                if($row[4] != 1 && $row[4] != 2){
                    $option_arr[]= ["title" => CommonLanguage::getMessage("approve"),
                                    "class" => "Approve",
                                    "permission" => "approve_advance_payment",
                                    "icon" => "fa-check",
                                    "attr"=>"data-status ='1' data-id='" . $d . "' ".($row[4] == 1 || $row[4] == 2 ? 'disabled' : ''),
                                   ];
                    $option_arr[]=  ["title" => CommonLanguage::getMessage("Reject"),
                                     "class" => "Reject",
                                     "permission" => "approve_advance_payment",
                                     "icon" => "fa-times",
                                     "attr"=>"data-status ='2' data-id='" . $d . "' ".($row[4] == 1 || $row[4] == 2 ? 'disabled' : ''),
                                    ];
                }
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => $option_arr]);
                return $html;
            }),
            array('db' => 'Currency_Symbol', 'dt' => 6),
            array('db' => 'is_paid', 'dt' => 7),
            array('db' => 'is_actual', 'dt' => 8)
        );
        $key = 'Advance_Payment_ID';
        $table = 'advance_payment_list';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function viewLoanPaymentRequest() {
        $cond = ' 1=1 ';


        if (isset($_POST["GetID"])) {

            $delete_loan = $this->_registry->finance->setData($_POST)->deleteloan();


            die(empty($delete_loan) ? "OK" : "error");
        }
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and is_actual = 0 ';
        }
         if (isset($_GET['status']) && $_GET['status'] != '') {
            $cond.=' and is_approved = "'.$_GET['status'].'" ';
        }
        if (!empty($_GET['from_date'])  && !empty($_GET['to_date'])) {
            $cond.=' and Loan_Repayment_Start between "'.$_GET['from_date'].'" and "'.$_GET['to_date'].'"';

        }
        
        if (!empty($_GET['emp_id']) ) {
            $cond.=' and Employee_ID = "'.$_GET['emp_id'].'" ';
        }
         if (!empty($_GET['loan_id_filter']) ) {
            $cond.=' and Loan_ID = "'.$_GET['loan_id_filter'].'" ';
        }
        $columns = array(
            array('db' => 'Employee_Name', 'dt' => 0, 'full_search' => true),
            array('db' => 'Loan_Description', 'dt' => 1),
            array('db' => 'Loan_Amount', 'dt' => 2, 'formatter' => function($d, $row) {

                return Forms::DecimalNumber($d) . ' ' . $row[7];
            }),
            array('db' => 'Loan_Date', 'dt' => 3),
            array('db' => 'Loan_Repayment_Start', 'dt' => 4),
            array('db' => 'is_approved', 'dt' => 5,
                  "formatter" => function($d) {
                      $Statuses = [$this->_registry->expenses->getStatusName(1) . "#label-info", $this->_registry->expenses->getStatusName(2) . "#label-warning", $this->_registry->expenses->getStatusName(3) . "#label-danger"];
                      return '<span class="label ' . explode("#", $Statuses[$d])[1] . '" data-status="' . $d . '">' . explode("#", $Statuses[$d])[0] . '</span>';
                  }),
            array(
                'db' => 'Loan_ID',
                'dt' => 6,
                'formatter' => function( $d, $row ) {
                    $loan_main_action = Forms::action_snippet(["color" => "success", "isDropDown" => false,
                                                               "ActionOption" => [
                                                                   ["title" => CommonLanguage::getMessage("View"),
                                                                    "class" => "btn-success View openFrame",
                                                                    "icon" => "fa-eye",
                                                                    "attr" => "data-src='HRM/view_loan_payment/" . "{$d}?is_pop=1'",
                                                                    "permission"=>"view_loan_payment"

                                                                   ]
                                                               ]]);



                    $option_arr = [["title" => CommonLanguage::getMessage("View"),
                                    "class" => "View openFrame",
                                    "icon" => "fa-eye",
                                    "attr" => "data-src='HRM/view_loan_payment/" . "{$d}?is_pop=1'",
                                    "permission"=>"view_loan_payment"

                                   ],
                                   ["title" => CommonLanguage::getMessage("Edit"),
                                    "permission" => "editloan",
                                    "class" => "Edit",
                                    "icon" => "fa-pencil",
                                    "href" => "HRM/addLoan/" . ($row[9] == 1 ? 'act/' : '') . $d
                                   ],
                                   ["title" => CommonLanguage::getMessage("delete"),
                                    "permission" => "deleteloan",
                                    "class" => "Delete",
                                    "icon" => "fa-trash"
                                   ],
                                  ];

                    if($row[5] != 1 && $row[5] != 2){
                        $option_arr[]= ["title" => CommonLanguage::getMessage("approve"),
                                        "class" => "Approve",
                                        "permission" => "approve_loan",
                                        "icon" => "fa-check",
                                        "attr"=>"data-status ='1' data-id='" . $d . "' ".($row[5] == 1 || $row[5] == 2 ? 'disabled' : ''),
                                       ];
                        $option_arr[]=  ["title" => CommonLanguage::getMessage("Reject"),
                                         "class" => "Reject",
                                         "permission" => "approve_loan",
                                         "icon" => "fa-times",
                                         "attr"=>"data-status ='2' data-id='" . $d . "' ".($row[5] == 1 || $row[5] == 2 ? 'disabled' : ''),
                                        ];
                    }


                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d, "attr" => " loan_amount='{$row[3]}' payment_amount='{$row[8]}'",
                                                   "ActionOption" => $option_arr]);


                    return $row[8] == $row[3] ? $loan_main_action : $html;
                }
            ),
            array('db' => 'Currency_Symbol', 'dt' => 7),
            array('db' => 'Payment_Amount', 'dt' => 8),
            array('db' => 'is_actual', 'dt' => 9)
        );
        $key = 'Loan_ID';
        $table = 'view_loans';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function viewEmployeeDependantChild() {
        if (isset($_GET['id'])) {

            $id = $_GET['id'];
            $Data = $this->_registry->employee->viewEmployeeDependantChild($id);
            die(json_encode($Data));
        }
    }

    public function importAttendanceSheet() {
        $Ret = $this->_registry->attendance->setData($_POST)->uploadExcelSheet();
        die(json_encode(is_array($Ret) ? ["OK", $Ret] : $Ret));
    }

    public function GetEmployeeChildSchoolTotal() {
        $emp_id = !empty($_GET['emp_id']) ? $_GET['emp_id'] : '';
        $entry_id = !empty($_GET['entry_id']) ? $_GET['entry_id'] : '';
        $result = $this->_registry->employee->getEmployeeChildSchoolTotal($emp_id, $entry_id);
        die(json_encode($result));
    }

    public function insertAttendanceSheet() {
        $Ret = $this->_registry->attendance->setData($_POST)->insertAttendanceSheet();
//        print_r($Ret);
        die(json_encode(empty($Ret) ? "ok" : $Ret ));
    }

    public function MedicalSettingRequest() {
        if (isset($_POST["GetID"])) {
            $Medical_ID = $_POST["GetID"];
            $delete_medical = $this->_registry->employee->deleteMedicalType($Medical_ID);
            die(empty($delete_medical) ? "OK" : "error");
        }
        if (isset($_POST["EditID"])) {
            $Medical_Type_ID = $_POST["EditID"];
            $Edit_Medical = $this->_registry->employee->viewMedicalType($Medical_Type_ID);
            die($Edit_Medical ? json_encode($Edit_Medical) : "error");
        }
        $columns = array(
            array('db' => 'mdcl_type_name', 'dt' => 0),
            array('db' => 'mdcl_type_percent', 'dt' => 1),
            array('db' => 'mdcl_type_id', 'dt' => 2, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil"
                                                   ],
                                               ]]);
                return $html;
            }
                 ),
        );
        $key = 'mdcl_type_id';
        $table = 'tbl_mdcl_type';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function addMedicalTypeSetting() {
        if (isset($_POST["Medical_Type"])) {
            if ($_POST['IsEdit'] == 0) {
                $RET = $this->_registry->employee->setData($_POST)->addMedicalType();
            } else {
                $RET = $this->_registry->employee->setData($_POST)->updateMedicalType();
            }
            if (empty($RET))
                die("success");
            else
                die("error");
        }
    }

    public function MedicalPlaceRequest() {
        if ($_POST['Is_Edit'] == 0) {

            $Ret = $this->_registry->employee->setData($_POST)->addMedicalPlace();
        } else {


            $Ret = $this->_registry->employee->setData($_POST)->updateMedicalPlace();
        }

        die(empty($Ret) ? "ok" : "error" );
    }

    public function medicalLocationRequest() {

        if (isset($_POST["GetID"])) {
            $Medical_Location = $_POST["GetID"];
            $delete_medical = $this->_registry->employee->deleteMedicalLocation($Medical_Location);
            die(empty($delete_medical) ? "OK" : "error");
        }



        $columns = array(
            array('db' => 'mdcl_place_name', 'dt' => 0),
            array('db' => 'mdcl_place_id', 'dt' => 1, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "href" => 'HRM/MedicalLocation/' . $d
                                                   ],
                                               ]]);
                return $html;
            }
                 ),
        );
        $key = 'mdcl_place_id';
        $table = 'tbl_mdcl_place';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function medicalEmployeeRequest() {

        $Ret = $this->_registry->employee->setData($_POST)->medicalEmployee();

        die(empty($Ret) ? "ok" : "error" );
    }

    public function EmployeeMedicalList() {
        $columns = array(
            array('db' => 'mdcl_employee_date', 'dt' => 0),
            array('db' => 'mdcl_employee_note', 'dt' => 1),
            array('db' => 'mdcl_total_iswa', 'dt' => 2, 'formatter' => function($d) {

                return Forms::DecimalNumber($d) . ' L.L';
            }),
            array('db' => 'mdcl_total_employee', 'dt' => 3, 'formatter' => function($d) {

                return Forms::DecimalNumber($d) . ' L.L';
            }),
            array('db' => 'mdcl_total_final', 'dt' => 4, 'formatter' => function($d) {

                return Forms::DecimalNumber($d) . ' L.L';
            }),
            array('db' => 'mdcl_employee_id', 'dt' => 5, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "href" => 'HRM/medicalEmployee/' . $d
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash"
                                                   ]
                                               ]]);
                return $html;
            }
                 ),
        );
        $cond = ' Employee_ID = "' . smc_escape($_GET['emp_id']) . '"';
        $key = 'mdcl_employee_id';
        $table = 'mdcl_employee';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function medicalEmployeeListRequest() {
        $cond = ' 1=1 ';
        if (isset($_POST["GetID"])) {
            $Medical_Employee = $_POST["GetID"];
            $delete_medical_employee = $this->_registry->employee->deleteMedicalEmployee($Medical_Employee);
            die(empty($delete_medical_employee) ? "OK" : "error");
        }
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and Is_Hidden = 0 ';
        }
        $columns = array(
            array('db' => 'Employee_Name', 'dt' => 0, 'full_search' => true),
            array('db' => 'mdcl_employee_date', 'dt' => 1),
            array('db' => 'mdcl_employee_note', 'dt' => 2),
            array('db' => 'mdcl_total_final', 'dt' => 3, 'formatter' => function($d) {

                return Forms::DecimalNumber($d) . ' L.L';
            }),
            array('db' => 'mdcl_employee_id', 'dt' => 4, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "href" => 'HRM/medicalEmployee/' . $d
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash"
                                                   ]
                                               ]]);
                return $html;
            }
                 ),
        );
        $key = 'mdcl_employee_id';
        $table = 'mdcl_employee';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    function returnAttForEmp() {
        $from_date = smc_escape($_GET['from_date']);
        $to_date = smc_escape($_GET['to_date']);
        $emp_id = smc_escape($_GET['emp_id']);
        $dep_id = smc_escape($_GET['dep_id']);
        $posted = smc_escape($_GET['posted']);
        $emp_location_filter = smc_escape($_GET['emp_location_filter']);
        $att_location_filter = smc_escape($_GET['att_location_filter']);
        $check_type_empty = smc_escape($_GET['check_type_empty']);
        $result = $this->_registry->attendance->returnAttForEmp($from_date, $to_date, $emp_id, $dep_id,$posted,$emp_location_filter,$att_location_filter,$check_type_empty);
        die($result ? json_encode($result) : 'error');
    }
    function exportAttForEmp() {
        $from_date = smc_escape($_GET['from_date']);
        $to_date = smc_escape($_GET['to_date']);
        $emp_id = smc_escape($_GET['emp_id']);
        $dep_id = smc_escape($_GET['dep_id']);
        $posted = smc_escape($_GET['posted']);
        $emp_location_filter = smc_escape($_GET['emp_location_filter']);
        $att_location_filter = smc_escape($_GET['att_location_filter']);
        $check_type_empty = smc_escape($_GET['check_type_empty']);
        $this->_registry->attendance->exportAttForEmp($from_date, $to_date, $emp_id, $dep_id,$posted,$emp_location_filter,$att_location_filter,$check_type_empty);
    }

    //    function returnComapreData() {
    //
    //        $from_date = smc_escape($_GET['from_date']);
    //        $to_date = smc_escape($_GET['to_date']);
    //        $emp_id = smc_escape($_GET['emp_id']);
    //        $dep_id = smc_escape($_GET['dep_id']);
    //        $result = $this->_registry->attendance->returnComapreData($from_date, $to_date, $emp_id, $dep_id);
    //        die($result ? json_encode($result) : 'error');
    //    }

    function attendanceReport() {
        $from_date = smc_escape($_GET['from_date']);
        $to_date = smc_escape($_GET['to_date']);
        $emp_id = smc_escape($_GET['emp_id']);
        $dep_id = smc_escape($_GET['dep_id']);
        $shift_type = smc_escape($_GET['shift_type']);
        $is_actual = smc_escape($_GET['is_actual']);
        $result = $this->_registry->attendance->attendanceReport($from_date, $to_date, $emp_id, $dep_id,$shift_type,$is_actual);
        die($result ? json_encode($result) : 'error');
    }

    function insertAttForEmp() {
        $from_date = smc_escape($_POST['from_date']);
        $to_date = smc_escape($_POST['to_date']);
        $emp_id = smc_escape($_POST['emp_id']);
        $dep_id = smc_escape($_POST['dep_id']);
        $emp_location_filter = smc_escape($_POST['emp_location_filter']);
        $att_location_filter = smc_escape($_POST['att_location_filter']);
        $result = null;
        if (!empty($from_date) && !empty($to_date))
            $result = $this->_registry->attendance->setData($_POST)->insertAttendanceManual($from_date, $to_date, $emp_id, $dep_id,$emp_location_filter,$att_location_filter);
        die(json_encode(empty($result) ? "ok" : $result));
    }

    public function viewEmployeeAlert() {

        $cond = ' 1=1 ';
        if (isset($_GET['emp_id'])) {
            $cond = ' employee_id = "' . smc_escape($_GET['emp_id']) . '"';
        }
        if (isset($_POST["id"])) {
            $entry_id = $_POST["id"];
            $doc_id = $_POST["doc_id"];
            $result = $this->_registry->employee->setData($_POST)->deleteEmpAlert($entry_id, $doc_id);

            die(empty($result) ? "OK" : "error");
        }
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and Is_Hidden=0 ';
        }


        $columns = array(
            array('db' => 'employee_name', 'dt' => 0, 'full_search' => true),
            array('db' => 'employee_alert_date', 'dt' => 1),
            array('db' => 'employee_alert_type', 'dt' => 2, 'formatter' => function($d) {

                return ($d == 1 ? CommonLanguage::getMessage('emp_allusion') : CommonLanguage::getMessage('emp_warning') );
            }),
            array('db' => 'employee_alert_note', 'dt' => 3),
            array(
                'db' => 'entry_id',
                'dt' => 4,
                'formatter' => function( $d, $row ) {
                        
                        $options = [
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "attr"=>'doc_id="' . $row[7] . '" data-id="' . $d . '"',
                                                    "icon" => "fa-pencil",
                                                    "permission"=>($_GET['is_actual']==1 ? "edit_act_employee_alert": "edit_employee_alert")
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "attr"=>'doc_id="' . $row[7] . '" data-id="' . $d . '"',
                                                    "icon" => "fa-trash",
                                                    "permission"=>($_GET['is_actual']==1 ? "delete_act_employee_alert": "delete_employee_alert")

                                                   ],
                                                   ["title" => CommonLanguage::getMessage("print"),
                                                    "class" => "print openFrame",
                                                    "icon" => "fa-print",
                                                    "attr" => "data-src='HRM/view_employee_alert/{$d}?is_pop=1'",
                                                    "permission"=>($_GET['is_actual']==1 ? "print_act_employee_alert": "print_employee_alert")


                                                   ],
                                                   
                                               ];
                        if($row[6] != ''){
                            $options[] = ["title" => CommonLanguage::getMessage("View"),
                                                    "class" => "Viewfile",
                                                    "attr"=>'target="_blank" doc_id="' . $row[7] . '" data-id="' . $d . '" href = "'.($row[6] == '' ? 'javascript:void(0)' : SITE_LINK . 'uploads/Documents/' . $row[6]).'"',
                                                    "icon" => "fa-eye",
//                                                    "href" => ($row[6] == '' ? 'javascript:void(0)' : SITE_LINK . 'uploads/Documents/' . $row[6]),
                                                   ];
                        }
                        $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => $options]);
                return $html;
//                    $html = '';
//
//                    $html .= '<a><button class="btn Edit" doc_id="' . $row[7] . '" data-id="' . $d . '" data-toggle="modal" data-target=""> <i class="fa fa-pencil"></i>  </button></a>'
//                        . '<a><button class="btn Delete" doc_id="' . $row[7] . '" data-id="' . $d . '" ><i class="fa fa-trash"></i>  </button></a>';
//
//                    $html .= '<a href="' . ($row[6] == '' ? 'javascript:void(0)' : SITE_LINK . 'uploads/Documents/' . $row[6]) . '" data-id="' . $d . '"  target="_blank" ><button class="btn Viewfile" style = "' . ($row[6] == '' ? 'cursor: not-allowed;' : '') . '">
//<i class="fa fa-eye"></i>  </button></a>';
//                    return $html;
                }
            ),
            array('db' => 'employee_id', 'dt' => 5),
            array('db' => 'employee_alert_document', 'dt' => 6),
            array('db' => 'doc_id', 'dt' => 7),
        );
        $key = 'entry_id';
        $table = 'employee_alerts';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function add_employee_alert() {

        if (isset($_POST['entry_id'])) {
            $result = $this->_registry->employee->setData($_POST)->addEmployeeAlert($_POST['entry_id'], $_POST['doc_id']);
        } else {
            $result = $this->_registry->employee->setData($_POST)->addEmployeeAlert();
        }
        die(json_encode(empty($result) ? ["success", ""] : ["error", $result[0]]));
    }

    public function getEmpAlert() {
        $result = $this->_registry->employee->getEmpAlert($_GET['id']);
        die(json_encode($result));
    }

    public function viewEmployeeAlertDetails() {
        $cond = '';
        if (isset($_GET['emp_id'])) {
            $cond = ' employee_id = "' . smc_escape($_GET['emp_id']) . '"';
        }
        $columns = array(
            array('db' => 'employee_alert_date', 'dt' => 0),
            array('db' => 'employee_alert_type', 'dt' => 1, 'formatter' => function($d) {

                return ($d == 1 ? CommonLanguage::getMessage('emp_alert_allusion') : CommonLanguage::getMessage('emp_alert_warning') );
            }),
            array('db' => 'employee_alert_note', 'dt' => 2),
            array(
                'db' => 'entry_id',
                'dt' => 3,
                'formatter' => function( $d, $row ) {

                    $html = '<a href="' . ($row[5] == '' ? 'javascript:void(0)' : SITE_LINK . 'uploads/Documents/' . $row[5]) . '" data-id="' . $d . '"  target="_blank" ><button class="btn Viewfile" style = "' . ($row[5] == '' ? 'cursor: not-allowed;' : '') . '">
<i class="fa fa-eye"></i>  </button></a>';
                    return $html;
                }
            ),
            array('db' => 'employee_id', 'dt' => 4),
            array('db' => 'employee_alert_document', 'dt' => 5)
        );
        $key = 'entry_id';
        $table = 'tbl_employee_alert';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function deleteJobFile() {
        $result = $this->_registry->employee->deleteJobFilePerEmp($_GET['entry_id']);
        die(empty($result) ? 'ok' : 'error');
    }

    public function viewEmpTransferDay() {
        $cond = ' 1=1 ';

        if (isset($_POST["Getid"])) {

            $entry_id = $_POST["Getid"];
            $result = $this->_registry->employee->setData($_POST)->deleteEmployeeTrnsfDay($entry_id);
            die(json_encode(empty($result) ? ["OK", ""] : ["error", $result[0]]));
        }
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and Is_Hidden = 0 ';
        }
        $columns = array(
            array('db' => 'employee_name', 'dt' => 0, 'full_search' => true),
            array('db' => 'transfer_date', 'dt' => 1),
            array('db' => 'transfer_day_number', 'dt' => 2),
            array('db' => 'transfer_day_note', 'dt' => 3),
            array('db' => 'entry_id', 'dt' => 4, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "permission" => "editEmpTransferDay"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash",
                                                    "permission" => "deleteEmpTransferDay"
                                                   ]
                                               ]]);
                return $html;
            }
                 )
        );
        $key = 'entry_id';
        $table = 'employee_transfer_days';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function add_employee_transfer_date() {
        if (isset($_POST['entry_id'])) {
            $result = $this->_registry->employee->setData($_POST)->updateEmployeeTrnsfDay($_POST['entry_id']);
        } else {
            $result = $this->_registry->employee->setData($_POST)->addEmployeeTrnsfDay();
        }
        die(json_encode(empty($result) ? ["success", ""] : ["error", $result[0]]));
    }

    public function getEmpTransferDay() {
        $result = $this->_registry->employee->getEmpTransferDay($_GET['id']);
        die(json_encode($result));
    }

    public function viewEmpTransferDayPerEmp() {
        $cond = '';
        if (isset($_GET['emp_id'])) {
            $cond = ' employee_id = "' . smc_escape($_GET['emp_id']) . '"';
        }
        $columns = array(
            array('db' => 'transfer_date', 'dt' => 0),
            array('db' => 'transfer_day_number', 'dt' => 1),
            array('db' => 'transfer_day_note', 'dt' => 2),
        );
        $key = 'entry_id';
        $table = 'tbl_employee_transfer_day';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function CreateUserGroupRequest() {
        $logged_id = Session::getUserID();
        array_push($_POST, $logged_id);
        if (isset($_POST['group_id'])) {

            $result = $this->_registry->user->setData($_POST)->updateUserGroup();
        } else {

            $result = $this->_registry->user->setData($_POST)->CreateUserGroup();
        }
        die(json_encode(empty($result) ? ["ok", ""] : ["error", $result[0]]));
    }

    public function viewUserGroupRequest() {

        if (isset($_POST["Getid"])) {

            $group_id = $_POST["Getid"];
            $result = $this->_registry->user->setData($_POST)->deleteUserGroup($group_id);
            die(json_encode(empty($result) ? ["OK", ""] : ["error", $result[0]]));
        }
        $columns = array(
            array('db' => 'group_name', 'dt' => 0),
            array('db' => 'group_id', 'dt' => 1, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "permission" => "editEmpTransferDay"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash",
                                                    "permission" => "deleteEmpTransferDay"
                                                   ]
                                               ]]);
                return $html;
            }
                 )
        );
        $key = 'group_id';
        $table = 'tbl_group_user';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function getUserGroupInfoRequest() {
        $group_id = $_GET['grp_id'];
        $result = $this->_registry->user->getUserGroupInfo($group_id);
        die(json_encode($result));
    }

    public function ViewVolunteerTeamRequest() {
        if (isset($_POST["GetID"])) {
            $team_id = $_POST["GetID"];
            $result = $this->_registry->employee->setData($_POST)->deleteVolunteerTeam($team_id);
            die(json_encode(empty($result) ? ["OK", ""] : ["error", $result[0]]));
        }
        $columns = array(
            array('db' => 'volunteer_team_name', 'dt' => 0),
            array('db' => 'volunteer_team_id', 'dt' => 1, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "permission" => "edit_volunteer_team"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash",
                                                    "permission" => "delete_volunteer_team"
                                                   ]
                                               ]]);
                return $html;
            }
                 )
        );
        $key = 'volunteer_team_id';
        $table = 'tbl_volunteer';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function ViewVolunteerSkillsRequest() {
        if (isset($_POST["GetID"])) {
            $team_id = $_POST["GetID"];
            $result = $this->_registry->employee->setData($_POST)->deleteVolunteerSkills($team_id);
            die(json_encode(empty($result) ? ["OK", ""] : ["error", $result[0]]));
        }
        $columns = array(
            array('db' => 'skills_name', 'dt' => 0),
            array('db' => 'skills_id', 'dt' => 1, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "permission" => "edit_volunteer_skills"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash",
                                                    "permission" => "delete_volunteer_skills"
                                                   ]
                                               ]]);
                return $html;
            }
                 )
        );
        $key = 'skills_id';
        $table = 'tbl_hrm_skills';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function ViewVolunteerNoticeRequest() {
        if (isset($_POST["GetID"])) {
            $team_id = $_POST["GetID"];
            $result = $this->_registry->employee->setData($_POST)->deleteVolunteerNotice($team_id);
            die(json_encode(empty($result) ? ["OK", ""] : ["error", $result[0]]));
        }
        $columns = array(
            array('db' => 'notice_name', 'dt' => 0),
            array('db' => 'notice_id', 'dt' => 1, 'formatter' => function( $d ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("Edit"),
                                                    "class" => "Edit",
                                                    "icon" => "fa-pencil",
                                                    "permission" => "edit_volunteer_notice"
                                                   ],
                                                   ["title" => CommonLanguage::getMessage("delete"),
                                                    "class" => "Delete",
                                                    "icon" => "fa-trash",
                                                    "permission" => "delete_volunteer_notice"
                                                   ]
                                               ]]);
                return $html;
            }
                 )
        );
        $key = 'notice_id';
        $table = 'tbl_volunteer_notice';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function addVolunteerTeamRequest() {
        $logged_id = Session::getUserID();
        array_push($_POST, $logged_id);
        $result = $this->_registry->employee->setData($_POST)->addVolunteerTeam();
        die(json_encode(empty($result) ? ["ok", ""] : ["error", $result[0]]));
    }

    public function addVolunteerSkillsRequest() {
        $logged_id = Session::getUserID();
        array_push($_POST, $logged_id);
        $result = $this->_registry->employee->setData($_POST)->addVolunteerSkills();
        die(json_encode(empty($result) ? ["ok", ""] : ["error", $result[0]]));
    }

    public function addVolunteerNoticeRequest() {
        $logged_id = Session::getUserID();
        array_push($_POST, $logged_id);
        $result = $this->_registry->employee->setData($_POST)->addVolunteerNotice();
        die(json_encode(empty($result) ? ["ok", ""] : ["error", $result[0]]));
    }

    public function addProSetting() {
        $logged_id = Session::getUserID();
        array_push($_POST, $logged_id);

        $result = $this->_registry->employee->setData($_POST)->addProVlnt();

        die(json_encode(empty($result) ? ["ok", ""] : ["error", $result[0]]));
    }

    public function ProSettingRequest() {
        $pro_id = $_POST['EditID'];
        $result = $this->_registry->employee->setData($_POST)->viewProVlnt($pro_id);
        die(json_encode($result));
    }

    public function returnWrkIDEmployee() {

        $result = $this->_registry->employee->getMaxEmpWrkID();
        echo($result);
        die();
    }

    public function ViewDepartmentRequestList() {

        if (isset($_POST["Department_Name"])) {
            if (!empty($_POST['Department_ID'])) {
                $RET = $this->_registry->branch->setData($_POST)->updateDepartment($_POST['Department_ID']);
                die(json_encode($RET) ? 'ok' : $RET[0]);
            } else {
                $RET = $this->_registry->branch->setData($_POST)->createDepartment();
                die(json_encode(is_numeric($RET) ? ['ok', $RET] : $RET[0] ));
            }

            die(json_encode(is_numeric($RET) ? ['ok', $RET] : $RET[0] ));
            //            die(json_encode($RET) ? 'ok'.$RET : $RET[0]);
        }
        if (isset($_GET["GetID"])) { // to update Status of Department and delete 
            $Department_ID = $_GET["GetID"];
            $delete_department = $this->_registry->branch->deleteDepartment($Department_ID);
            die(empty($delete_department) ? "ok" : "error");
        }
        $columns = array(
            array('db' => 'department_name', 'dt' => 0),
            array(
                'db' => 'department_id',
                'dt' => 1,
                'formatter' => function( $d ) {
                    $html = Forms::action_snippet(["color" => "info", "isDropDown" => true, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("delete"),
                                                        "class" => "Delete",
                                                        "icon" => "fa-trash",
                                                        "permission" => "DeleteDepartment",
                                                       ],
                                                       ["title" => CommonLanguage::getMessage("Edit"),
                                                        "class" => "Edit",
                                                        "icon" => "fa-pencil",
                                                        "permission" => "EditDepartment",
                                                       ]
                                                   ]]);
                    return $html;
                }
            )
        );
        $key = 'department_id';
        $table = 'tbl_department';
        $data = DataTable::complex($_GET, $table, $key, $columns, 'status_id = 1');
        echo json_encode($data);
    }

    public function searchDepartment() {
        $term = isset($_GET['term']) ? $_GET['term'] : null;
        $page = isset($_GET['page']) ? $_GET['page'] - 1 : 0;
        $ALL = $this->_registry->branch->searchDepartment($term, $page, $_GET['limit']);
        echo json_encode(array('data' => $ALL['data'], 'is_more' => $ALL['is_more']));
    }
    public function searchBanks() {
        $term = isset($_GET['term']) ? $_GET['term'] : null;
        $page = isset($_GET['page']) ? $_GET['page'] - 1 : 0;
        $add_no_bank = isset($_GET['add_no_bank']) ? true : false;
        $ALL = $this->_registry->employee->searchBanks($term, $page, $_GET['limit'],$add_no_bank);
        echo json_encode(array('data' => $ALL['data'], 'is_more' => $ALL['is_more']));
    }

    public function BuildImageTree() {
        $id = (isset($_GET['dep_id']) ? $_GET['dep_id'] : null);
        $Content = $this->_registry->branch->viewAllDepartmentByTree($id);
        $result = array("id" => 1, "root" => $Content);
        die(json_encode($result));
    }

    public function fetchBranch() {
        $cmd = isset($_GET["cmd"]) ? $_GET["cmd"] : "";
        $id = isset($_GET["id"]) ? intval($_GET["id"]) : 0;
        $this->status = isset($_GET["status"]) ? intval($_GET["status"]) : -1;
        if ($cmd == "fetch") {
            $RET = $id == 0 ? $this->_registry->branch->viewDepartment() : $this->_registry->branch->viewDepartment($id);
            for ($x = 0; $x < count($RET); $x++) {
                $RET2 = $this->_registry->branch->viewDepartment(intval($RET[$x]["department_id"]));
                if (count($RET2) > 0)
                    $RET[$x]["isLazy"] = true;
                $RET[$x]["key"] = $RET[$x]["department_id"];
            }
            echo json_encode($RET);
        }
        else if ($cmd == "addnewitem") {
            $remove = $this->_registry->branch->setdata($_POST)->createDepartment();
            die(empty($remove) ? "OK" : "error");
        } else if ($cmd == "removeaddeditem") {
            $RET2 = $this->_registry->branch->deleteDepartment($_POST["MyID"]);
            if ($RET2 == 0)
                die("OK");
            if ($RET2 == 1)
                die(CommonLanguage::getMessage('check_department_employee'));
            if ($RET2 == 2)
                die(CommonLanguage::getMessage('check_department_not_empty'));
            die($RET2);
        } else if ($cmd == "edititem") {
            $RET3 = $this->_registry->branch->setdata($_POST)->updateDepartment($_POST["Department_ID"]);
            die(empty($RET3) ? "OK" : "error");
        } else if ($cmd == 'update') {

            $RET4 = $this->_registry->branch->setdata($_POST)->updateParentForDepartment($_POST["department_id"], $_POST['parent_id']);
            die(empty($RET4) ? "OK" : "error");
        } else {
            $RET = $this->_registry->branch->viewDepartment();
        }
    }

    public function viewJobsRequest() {

        if (isset($_GET['code_id'])) {

            $id = $_GET['code_id'];
            $JobDetails = $this->_registry->job->getJobsDetails($id);
            die(json_encode($JobDetails));
        }
        if (isset($_POST["GetID"])) { // to update Status of Department and delete 
            $logged_id = Session::getUserID();
            $job_ID = $_POST["GetID"];
            $delete_job = $this->_registry->job->deleteJobs($job_ID, $logged_id);
            die(json_encode(empty($delete_job) ? 'OK' : $delete_job));
        }



        $columns = array(
            array('db' => 'Job_Name', 'dt' => 0),
            array('db' => 'Job_Description', 'dt' => 1),
            array(
                'db' => 'Job_ID',
                'dt' => 2,
                'formatter' => function( $d ) {
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("Edit"),
                                                        "class" => " edit_job",
                                                        "icon" => "fa-pencil"
                                                       ],["title" => CommonLanguage::getMessage("delete"),
                                                          "class" => " Delete",
                                                          "icon" => "fa-trash"
                                                         ]
                                                   ]]);
                    return $html;
                }
            )
        );
        $key = 'Job_ID';
        $table = 'tbl_hrm_jobs';
        $data = DataTable::complex($_GET, $table, $key, $columns, 'Status_ID = 1');
        echo json_encode($data);
    }


    public function addJobRequest() {
        if (isset($_POST["Job_Name"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);
            $validate = $this->_registry->job->viewExistingJob($_POST["Job_Name"]);
            if ($validate) {
                $Ret = $this->_registry->job->setData($_POST)->create();
                die(empty($Ret) ? "success" : "error");
            } else
                die("exists");
        }
    }

    public function ManagePaygradeRequest() {
        if (isset($_GET["Job_Id"])) {
            $Content = $this->_registry->job->getJobsByID($_GET["Job_Id"]);
            die(json_encode($Content));
        }
        if (isset($_POST["Job_ID"])) {
            $logged_id = Session::getUserID();
            array_push($_POST, $logged_id);

            $Ret = $this->_registry->job->setData($_POST)->updateJob();
            die(empty($Ret) ? "success" : "error");
        }
    }
    public function salary_unit_formulas_ajax() {




        $columns = array(
            array('db' => 'formula_name', 'dt' => 0),
            array('db' => 'hr_price_formula', 'dt' => 1),
            array('db' => 'deduction_rate', 'dt' => 2),
            array('db' => 'overtime_rate', 'dt' => 3),
            array(
                'db' => 'formula_id',
                'dt' => 4,
                'formatter' => function( $d ) {
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => false, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("Edit"),
                                                        "class" => "btn-success Edit",
                                                        "icon" => "fa-pencil"
                                                       ]
                                                   ]]);
                    return $html;
                }
            )
        );
        $key = 'formula_id';
        $table = 'tbl_hrm_salary_unit_formulas';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function add_edit_salary_formula(){
        $insert = $this->_registry->worktimes->setData($_POST)->add_edit_salary_formula();
        die(json_encode(empty($insert) ? 'OK' : $insert[0]));
    }
    public function salary_periods_ajax() {

        $columns = array(
            array('db' => 'period_name', 'dt' => 0),
            array('db' => 'basic_salary', 'dt' => 1,"formatter"=>function($d,$row){
                return $d.' '.$row[6];
            }),
            array('db' => 'unit_time', 'dt' => 2,"formatter"=>function($d){
                return WorkingTimes::get_payperiod_by_id($d);
            }),
            array('db' => 'pay_period', 'dt' => 3,"formatter"=>function($d){
                return WorkingTimes::get_unittime_by_id($d);
            }),
            array('db' => 'formula_name', 'dt' => 4),
            array(
                'db' => 'period_id',
                'dt' => 5,
                'formatter' => function( $d ) {
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => false, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("Edit"),
                                                        "class" => "btn-success Edit",
                                                        "icon" => "fa-pencil"
                                                       ]
                                                   ]]);
                    return $html;
                }
            ),
            array('db' => 'Currency_Symbol', 'dt' => 6)
        );
        $key = 'period_id';
        $table = 'salary_periods';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function add_edit_salary_periods(){
        $insert = $this->_registry->worktimes->setData($_POST)->add_edit_salary_periods();
        die(json_encode(empty($insert) ? 'OK' : $insert[0]));
    }

    public function get_salary_periods_by_id(){
        $insert = $this->_registry->worktimes->get_salary_periods_by_id($_GET['id']);
        die(json_encode($insert));
    }

    public function submitEmployeePiecePrice(){
        $insert = $this->_registry->employee->setData($_POST)->submitEmployeePiecePrice();
        die(json_encode(empty($insert) ? 'OK' : $insert[0]));
    }
    public function submitPieceService(){
        $submit = $this->_registry->employee->setData($_POST)->submitPieceService();
        die(json_encode(empty($submit) ? [CommonLanguage::getMessage($_POST['piece_service_id'] == 0 ? 'piece_service_added' : 'piece_service_updated'), 'success' ] : [$submit[0], 'danger']));
    } 
    public function submitPaymentEmployeePiece(){
        $submit = $this->_registry->employee->setData($_POST)->submitPaymentEmployeePiece();
        die(json_encode(empty($submit) ? [CommonLanguage::getMessage('Submitted_Successfully'), 'success' ] : [$submit[0], 'danger']));
    } 
    public function getEmployeePieceQuantity(){
        $data = $this->_registry->employee->setData($_GET)->getEmployeePieceQuantity();
        $html = Forms::build_table_html($data);
        die($html);
    }
    public function getEmployeeDuePayments(){
        $data = $this->_registry->employee->setData($_GET)->getEmployeeDuePayments();
        $html = Forms::build_table_html($data);
        die($html);
    }
    public function getEmployeePieceData(){
        $data = $this->_registry->employee->setData($_GET)->getEmployeePieceData();
        die(json_encode($data));
    }
    public function viewPieceService() {
        $columns = array('piece_service_name','piece_service_price','currency',
                         array(
                             'db' => 'piece_service_id',
                             'dt' => 3,
                             'formatter' => function( $d ) {
                                 $html = Forms::action_snippet(["color" => "success",
                                                                "isDropDown" => true,
                                                                "data_id" => $d,
                                                                "ActionOption" => [
                                                                    ["title" => CommonLanguage::getMessage("Edit"),
                                                                     "class" => "edit_piece_service",
                                                                     "data-target" => "#add-edit-piece-modal",
                                                                     "icon" => "fa-pencil"
                                                                    ],
                                                                    ["title" => CommonLanguage::getMessage("delete"),
                                                                     "class" => "delete_piece_service",
                                                                     "icon" => "fa-trash"
                                                                    ]
                                                                ]]);
                                 return $html;
                             }
                         ));
        $key = 'piece_service_id';
        $table = 'view_piece_service';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }
    public function piecePaymentReport() {
        $condition = '';
        $_GET['local_sym'] = CurrencyFactory::getLocalCurrencySymbol();
        if($_GET['is_actual'] == 0){
            $condition .=' and is_actual = "'.$_GET['is_actual'].'"';
        }
        $condition .= ' and ( from_date >= "'.$_GET['start_date'].'"
                            and  from_date <= "'.$_GET['end_date'].'" )
                        or (to_date >=  "'.$_GET['start_date'].'"
                            and to_date <=  "'.$_GET['end_date'].'" )';

        $condition .= !empty($_GET['employee_id']) ? ' and employee_id = "'.$_GET['employee_id'].'"' : '';
        $columns = array('from_to_date','employee_full_name',
                         array('db' => 'amount', 'dt' => 2, "formatter" => function($d, $row) {
                             return CommonFunctions::formatNumber($d) . $_GET['local_sym'];
                         }),
                         array('db' => 'paid_amount', 'dt' => 3, "formatter" => function($d, $row) {
                             return CommonFunctions::formatNumber($d) . $_GET['local_sym'];
                         }));
        $key = 'entery_id';
        $table = 'view_piece_payment';
        $data = DataTable::complex($_GET, $table, $key, $columns,' 1=1 '.$condition);
        echo json_encode($data);
    }

    public function payroll_list() {
        $cond=' Is_Hidden = "'.$_GET['is_actual'].'" ';
        if(!empty($_GET['branch_id'])){
            $cond.=' and Branch_ID = "'.$_GET['branch_id'].'"';
        }
        if(isset($_GET['is_nssf']) && $_GET['is_nssf'] !='' ){
            $cond.=' and is_nssf = "'.$_GET['is_nssf'].'"';
        }
        if($_GET['emp_type'] !='' ){
            $cond.=' and IS_Employee = "'.$_GET['emp_type'].'"';
        }
        if(isset($_GET['is_working']) && $_GET['is_working'] !='' ){
            if($_GET['is_working']==1)
                $cond.=' and  (leave_date is null or leave_date ="" or leave_date="0000-00-00")';
            else
                $cond.=' and  (leave_date is not null && leave_date <> "" && leave_date <> "0000-00-00")'; 
        }
        $columns = array(
            array('db' => 'Employee_Work_ID', 'dt' => 0),
            array('db' => 'Employee_Name', 'dt' => 1, 'full_search' => true),
            array('db' => 'Job_Name', 'dt' => 2),
            array('db' => 'basic_salary', 'dt' => 3,"formatter"=>function($d,$row){
                return $d.' '.$row[7];
            }),
            array('db' => 'unit_time', 'dt' => 4,"formatter"=>function($d){
                return WorkingTimes::get_unittime_by_id($d);
            }),
            array('db' => 'pay_period', 'dt' => 5,"formatter"=>function($d){
                return WorkingTimes::get_payperiod_by_id($d);
            }),
            array(
                'db' => 'Employee_ID',
                'dt' => 6,
                'formatter' => function( $d ) {
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => false, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("view"),
                                                        "class" => "btn-success View",
                                                        "href"=>"HRM/PaidPayrollForEmployee/".($_GET['is_actual'] ? 'act/':'').$d,
                                                        "icon" => "fa-eye"
                                                       ]
                                                   ]]);
                    return $html;
                }
            ),
            array('db' => 'basic_currency_symbol', 'dt' => 7)
        );
        $key = 'Employee_ID';
        $table = 'view_employees';
        $data = DataTable::complex($_GET, $table, $key, $columns,$cond);
        echo json_encode($data);
    }
    public function EmployeeProcess_list() {
        $cond=' 1=1';
       if(!empty($_GET['myBarcode'])){
            $cond.=' and barcode_nb = "'.$_GET['myBarcode'].'"';
        }
        if(!empty($_GET['Employee_ID'])){
            $cond.=' and Employee_ID = "'.$_GET['Employee_ID'].'"';
        }
        
        if(!empty($_GET['template_id'])){
            $cond.=' and template_id = "'.$_GET['template_id'].'"';
        }
        if(!empty($_GET['from_date'])&&!empty($_GET['to_date'])){
            $cond.=' and date BETWEEN   "'.$_GET['from_date'].'" and   "'.$_GET['to_date'].'"';
        }
         $columns = array(
            array('db' => 'full_name', 'dt' => 0),
            array('db' => 'type_name', 'dt' => 1),
            array('db' => 'template_name', 'dt' => 2),
            array('db' => 'cost', 'dt' => 3),
            array('db' => 'barcode_nb', 'dt' => 4),

        );
        $key = 'process_id';
        $table = 'process_employee';
        $data = DataTable::complex($_GET, $table, $key, $columns,$cond);
        echo json_encode($data);
    }

    public function get_payroll_per_emp(){
        $data = $this->_registry->employee->viewPayroll($_GET['emp_id'], $_GET['from_date'], $_GET['to_date']);
        $html ='';
        if(empty($data['error'])){
           $html = empty($data['main']) ? '' :Forms::build_payroll_table($data); 
        }
        die(json_encode(['data'=>$data,'html'=>$html]));
    }
    public function delete_payrool_employee() {
        if (isset($_POST["GetID"])) { // to update Status of employee and delete 
            $Payroll_ID = $_POST["GetID"];
            $delete_payroll = $this->_registry->employee->delete_payrool_employee_action($Payroll_ID);
            die(empty($delete_payroll) ? "OK" : "error");
        }
    }

    public function absence_leave_list() {

        $data = $this->_registry->attendance->employee_absence_leave($_GET['emp_id'], $_GET['from_date'], $_GET['to_date']);
        //        echo"<pre>";die(print_r($data));
        $html = Forms::build_table_html($data);
        die($html);
    }   
    public function add_edit_attendance_setting(){
        $insert = $this->_registry->attendance->setData($_POST)->add_edit_attendance_setting();
        die(json_encode(empty($insert) ? 'OK' : $insert[0]));
    }    
    public function get_att_setting_by_id(){
        $data = $this->_registry->attendance->get_att_setting_by_id($_GET['id']);
        die(json_encode($data));
    }
    public function employee_locations() {
        $columns = array('location_code','Location_Name',
                         array(
                             'db' => 'Location_ID',
                             'dt' => 2,
                             'formatter' => function( $d ) {
                                 $html = Forms::action_snippet(["color" => "success",
                                                                "isDropDown" => true,
                                                                "data_id" => $d,
                                                                "ActionOption" => [
                                                                    ["title" => CommonLanguage::getMessage("Edit"),
                                                                     "class" => "Edit",
                                                                     "permission"=>"edit_employee_location",
                                                                     "icon" => "fa-pencil"
                                                                    ],
                                                                    ["title" => CommonLanguage::getMessage("Delete"),
                                                                     "class" => "Delete",
                                                                     "permission"=>"delete_employee_location",
                                                                     "icon" => "fa-trash"
                                                                    ]
                                                                ]]);
                                 return $html;
                             }
                         ));
        $key = 'Location_ID';
        $table = 'tbl_employee_location';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }
    public function add_edit_emp_location(){
        $insert = $this->_registry->employee->setData($_POST)->add_edit_emp_location();
        die(json_encode(empty($insert) ? 'OK' : $insert[0]));
    }    

    public function employee_banks_ajax() {

        $columns = array(
            array('db' => 'bank_name', 'dt' => 0),
            array('db' => 'bank_branch', 'dt' => 1),
            array('db' => 'bank_code', 'dt' => 2),
            array(
                'db' => 'bank_id',
                'dt' => 3,
                'formatter' => function( $d ) {
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => false, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("Edit"),
                                                        "class" => "btn-success Edit",
                                                        "icon" => "fa-pencil"
                                                       ]
                                                   ]]);
                    return $html;
                }
            )
        );
        $key = 'bank_id';
        $table = 'tbl_employee_banks';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }
    public function add_edit_employee_banks(){
        $insert = $this->_registry->employee->setData($_POST)->add_edit_employee_banks();
        die(json_encode(empty($insert) ? 'OK' : $insert[0]));
    }

    public function get_emp_banks_by_id(){
        $insert = $this->_registry->employee->get_emp_banks_by_id($_GET['id']);
        die(json_encode($insert));
    }

    public function employee_bank_info_ajax(){
        $data = $this->_registry->employee->setData($_GET)->get_emp_bank_info();
        $html = Forms::build_table_html($data);
        die($html);
    }

    public function editOverTimeRequest(){
        $edit = $this->_registry->finance->setData($_POST)->edit_overtime();
        die(empty($insert) ? 'Ok' : $insert[0]);
    }
    public function add_edit_att_template(){
        $insert = $this->_registry->attendance->setData($_POST)->add_edit_att_template();
        die(json_encode(empty($insert) ? 'OK' : 'error' ));
    }

    public function get_att_template_by_id(){
        $data = $this->_registry->attendance->get_att_template_by_id($_GET['id']);
        die(json_encode($data));
    }
    public function att_template_ajax() {

        $columns = array('template_name','max_hrs_shift' ,
            array(
                'db' => 'template_id',
                'dt' => 2,
                'formatter' => function( $d ) {
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => true, "data_id" => $d,
                                                   "ActionOption" => [
                                                       ["title" => CommonLanguage::getMessage("Edit"),
                                                        "class" => " Edit",
                                                        "icon" => "fa-pencil"
                                                       ],
                                                       ["title" => CommonLanguage::getMessage("Delete"),
                                                        "class" => " delete",
                                                        "icon" => "fa-trash",
                                                           "permission"=>"delete_att_template"
                                                       ]
                                                   ]]);
                    return $html;
                }
            )
        );
        $key = 'template_id';
        $table = 'tbl_employee_attendance_template';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }

    public function build_att_template_html(){
        $data = $_GET['template'];
        $html = Forms::build_att_template_html($data);
        die($html);
    }

    public function deleteEmpFile(){
        $delete = $this->_registry->employee->deleteEmpFile($_GET['id']);
        die(empty($delete) ? 'OK' : 'error');
    }

    public function delete_accrued_leave(){
        $delete = $this->_registry->worktimes->delete_accrued_leave($_POST['id']);
        die(empty($delete) ? 'OK' : $delete[0]);
    }
    public function delete_absence(){
        $delete = $this->_registry->worktimes->delete_absence($_POST['id']);
        die(empty($delete) ? 'OK' : $delete[0]);
    }
    public function payroll_report(){
        $from_date = smc_escape($_GET['from_date']);
        $to_date = smc_escape($_GET['to_date']);
        $dep_id = smc_escape($_GET['dep_id']);
        $shift_type = smc_escape($_GET['shift_type']);
        $is_nssf = smc_escape($_GET['is_nssf']);
        $is_paid = smc_escape($_GET['is_paid']);
        $bank_filter = smc_escape($_GET['bank_filter']);
        $is_working = smc_escape($_GET['is_working']);
        $emp_type= smc_escape($_GET['emp_type']);
        $is_actual= smc_escape($_GET['is_actual']);
        $actual_only= smc_escape($_GET['actual_only']);
        $early_payroll= smc_escape($_GET['early_payroll']);
        $data = $this->_registry->employee->payroll_report($from_date,$to_date,$dep_id,$shift_type,$is_nssf,$is_paid,$bank_filter,$is_working,$emp_type,$is_actual,$actual_only,$early_payroll);
        die(json_encode([$data]));
    }
    public function attendance_location_report(){
        $data = $this->_registry->attendance->attendance_location_report( $_GET['from_date'], $_GET['to_date'],$_GET['dep_id']);
        $html = Forms::build_table_html($data['html']);
        die(json_encode([$html,$data['total_hours']]));
    }
    public function att_location_details_ajax() {
        $cond=' 1=1 ';
        if(!empty($_GET['location']))
            $cond.=' and location_id = "'.$_GET['location'].'" ';
        if(!empty($_GET['employee']))
            $cond.=' and employee_id = "'.$_GET['employee'].'" ';
        if(!empty($_GET['from_date']) && !empty($_GET['to_date']))
            $cond.=' and date(date_time_in) between "'.$_GET['from_date'].'" and "'.$_GET['to_date'].'"';
        if(!empty($_GET['dep_id']))
            $cond.=' and Branch_ID = "'.$_GET['dep_id'].'"';
        $columns = array(
            array('db' => 'Employee_Name', 'dt' => 0, 'full_search' => true),
            array('db' => 'Location_Name', 'dt' => 1),
            array('db' => 'date_time_in', 'dt' => 2),
            array('db' => 'date_time_out', 'dt' => 3),
            array('db' => 'time_diff', 'dt' => 4)
        );
        $key = 'attendance_id';
        $table = 'detail_attendance_locations';
        $data = DataTable::complex($_GET, $table, $key, $columns,$cond);
        echo json_encode($data);
    }
    public function att_location_details_total_hours(){
        $totals = $this->_registry->attendance->setData($_GET)->att_location_details_total_hours();
        die($totals);
    }

    public function interior_ministry_report_ajax() {
//        die('here');
         $data = $this->_registry->employee->get_interior_ministry_report($_GET);
        $html = Forms::build_table_html($data);
        die(json_encode(['html'=>$html,'data'=>$data]));
    }
    public function interior_ministry_saved_report_ajax() {
//        die('here');
         $data = $this->_registry->employee->get_interior_ministry_saved_report($_GET['id']);
        $html = Forms::build_table_html($data);
        die(json_encode(['html'=>$html,'data'=>$data]));
    }
    
//    public function interior_ministry_report_ajax() {
//        $cond=' 1=1 ';
//        if(isset($_GET['type'])){
//            if($_GET['type'] ==0)
//                $cond.=' and isnull(leave_date) and Employee_StartDate < "'.$_GET['from_date'].'"';
//            if($_GET['type']==1)
//                $cond.=' and Employee_StartDate between "'.$_GET['from_date'].'" and "'.$_GET['to_date'].'"';
//            if($_GET['type'] ==2)
//                $cond.=' and leave_date between "'.$_GET['from_date'].'" and "'.$_GET['to_date'].'"';
//        }
//        if(!empty($_GET['dep_id']))
//            $cond.=' and Branch_ID = "'.$_GET['dep_id'].'"';
//        if(isset($_GET['is_nssf']) && $_GET['is_nssf'] !='')
//            $cond.=' and is_nssf = "'.$_GET['is_nssf'].'"';
//
//
//        $columns = array(
//            array('db' => 'second_lang_name', 'dt' => 0),
//            array('db' => 'location_address', 'dt' => 1),
//            array('db' => 'Employee_StartDate', 'dt' => 2),
//            array('db' => 'Job_Name', 'dt' => 3),
//            array('db' => 'shift_note', 'dt' => 4),
//            array('db' => 'Employee_StreetAddress1', 'dt' => 5),
//            array('db' => 'Employee_MobilePhone', 'dt' => 6)
//        );
//        $key = 'Employee_ID';
//        $table = 'view_employees';
//        $data = DataTable::complex($_GET, $table, $key, $columns,$cond);
//        echo json_encode($data);
//    }

    public function submit_multi_payroll() {
        if (!empty($_POST['data'])) {

            $db = DBConnectorFactory::loadDriver();
            $db->query('START TRANSACTION');
            $this->_registry->employee->stop_transaction_start_end = true;
            foreach($_POST['data'] as $emp){
                if(!empty($emp)){
                    $logged_id = Session::getUserID();
                    array_push($emp, $logged_id);
                    $Actual = $emp['main']['Actual'];
                    $Ret = $Actual == 1 ? $this->_registry->employee->setData($emp)->submitUdetailedPayRoll(1) : $this->_registry->employee->setData($emp)->submitUdetailedPayRoll();
                   }

            }
            $error = $db->error();
            if(empty($error))
                $db->query('COMMIT');
            else
                $db->query('ROLLBACK');

            die(empty($error) ? "OK" : 'error');
        }
    }
    public function multi_advance_payment() {
        $data = $this->_registry->employee->setData($_GET)->multi_advance_payment_emp();
        $html=Forms::build_table_html($data);
        die($html);
    }
    
   
    public function addMultiAdvancePayment() {
        $_POST['Logged_ID'] = Session::getUserID();
        $submit = $this->_registry->finance->setData($_POST)->submit_multi_advance_payment();
        die(empty($submit) ? 'OK' : 'error');
    }
    public function AdvancePaymentList() {
        $cond = $_GET['is_actual'] == 0 ? ' and is_actual = 0' : '';
        if(!empty($_GET['from_date']) && !empty($_GET['to_date']))
            $cond.=' and Advance_Payment_Date between "'.$_GET['from_date'].'" and "'.$_GET['to_date'].'"';
        if (!empty($_GET['emp_id']))
            $cond.=' and Employee_ID = "' .$_GET['emp_id'] . '"  ';
        if (!empty($_GET['dep_id']))
            $cond.=' and Branch_ID = "' . $_GET['dep_id'] . '"  ';
        if (isset($_GET['bank_id']) && $_GET['bank_id']!='')
            $cond.=' and bank_id = "' . $_GET['bank_id'] . '"  ';
        if (isset($_GET['is_nssf']) && $_GET['is_nssf'] !='')
            $cond.=' and is_nssf = "' . $_GET['is_nssf'] . '"  ';
        $columns = array(array('db'=>'employee_name','dt'=>0, 'full_search' => true),'bank_name_code','bank_branch','bank_account',
                         array(
                             'db' => 'Sum(Advance_Payment_Amount*current_rate)',
                             'dt' => 4,
                             'formatter' => function( $d ) {
                                 return $d.' '.smc_session()['local_currency_symbol'];
                             }
                         )
                        );
        $key = 'Advance_Payment_ID';
        $table = 'advance_payment_list';
        $data = DataTable::complex($_GET, $table, $key, $columns,' 1=1 '.$cond,null,' group by Employee_ID');
        echo json_encode($data);
    }
    public function getEmployeeOpening() {
        $columns = array('emp','to_date',array(
                             'db' => 'total_salary',
                             'dt' => 2,
                             'formatter' => function( $d,$row ) {
                                 return CommonFunctions::formatNumber($d).' '.$row[6];
                             }
                         ),array(
                             'db' => 'total_allowance',
                             'dt' => 3,
                             'formatter' => function( $d ,$row) {
                                 return CommonFunctions::formatNumber($d).' '.$row[6];
                             }
                         ),array(
                             'db' => 'total_tax',
                             'dt' => 4,
                             'formatter' => function( $d,$row ) {
                                 return CommonFunctions::formatNumber($d).' '.$row[6];
                             }
                         ),
                         array(
                             'db' => 'entry_id',
                             'dt' => 5,
                             'formatter' => function( $d ) {
                                 $html = Forms::action_snippet(["color" => "success",
                                                                  "isDropDown" => true,
                                                                  "data_id" => "{$d}",
                                                                  "ActionOption" => [
                                                                      ['title' =>CommonLanguage::getMessage('Edit'),
                                                                       'class' => 'edit_emp_opening',
                                                                       'data-target' => '#add-edit-emp-opening-modal',
                                                                       'attr'=>"data-id={$d}",
                                                                       'icon' => 'fa-pencil',
                                                                       'permission'=>'edit_emp_opening'
                                                                      ],
                                                                      ['title' => CommonLanguage::getMessage('delete'),
                                                                       'class' => 'delete_emp_opening',
                                                                        'attr'=>"data-id={$d}",
                                                                       'icon' => 'fa-trash',
                                                                       'permission'=>'delete_emp_opening'
                                                                      ]]]);
                                   return $html;
                             }
                         ),'Currency_Symbol'
                        );
        $key = 'entry_id';
        $table = 'employee_opening_list';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }
    public function viewNtfsrequest() {
        $user_id = smc_session()['user_logged_id'];
        //        $cond = ' 1=1 ';
        $cond = ' employee_id = "' . smc_escape($user_id) . '" ';

        if (!empty($_GET['Data']['filter_type']))
            $cond .= ' and main_type = "' . smc_escape($_GET['Data']['filter_type']) . '"';
        if (!empty($_GET['Data']['filter_date'])) {
            $date = explode(" - ", $_GET['Data']['filter_date']);
            smc_session()['from_date_ntf'] = $date[0];
            smc_session()['to_date_ntf'] = $date[1];
            $cond .= ' and date(date_time) between "' . smc_escape($date[0]) . '" and  "' . smc_escape($date[1]) . '" ';
        }
        if (($_GET['Data']['read_ntf'] != 3))
            $cond .= ' and task_status = "' . smc_escape($_GET['Data']['read_ntf']) . '"';

        $columns = array(
            array('db' => 'task_desc', 'dt' => 0),
            array('db' => 'main_type', 'dt' => 1, 'formatter' => function($d) {
                return CommonLanguage::getMessage($d);
            }),
            array('db' => 'date_time', 'dt' => 2),
            array('db' => 'task_id', 'dt' => 3, 'formatter' => function( $d, $row ) {
                $html = Forms::action_snippet(["color" => "success", "isDropDown" => false, "data_id" => $d, "attr" => " task_status='{$row[5]}'  main_type='{$row[1]}' main_id='{$row[4]}'   ",
                                               "ActionOption" => [
                                                   ["title" => CommonLanguage::getMessage("view"),
                                                    "class" => "view",
                                                    "icon" => "fa-eye",
                                                    //                                        "attr"=>" task_status='".$row[5]."' ",
                                                    "permission" => "view_ntf_details",
                                                    "href" =>
                                                    $row[1] == "annoucement" ? "HRM/ViewAnnouncmentDetails/{$row[4]}" :
                                                        ($row[1] == "absence" ? "HRM/AbsenceList?main_id={$row[4]}" :
                                                            ($row[1] == "leave" ? "HRM/AccruedList?main_id={$row[4]}" : 
                                                            ($row[1] == "overtime" || $row[1] == "deduction" ?  "HRM/dailyOvertime".($row[1] =='deduction' ? '/ded' : '')."?main_id={$row[4]}":
                                                        ($row[1] == "advance" ? "HRM/viewAdvancePayment?main_id={$row[4]}" :
                                                            ($row[1] == "loan" ?"HRM/viewLoans?main_id={$row[4]}" : '')))))
                                                   ]
                                               ]]);
                //                    if ($row[6] == 'task' && $row[5] != 2) {
                //                        $html .= '<a><button class="btn finish" data-id="' . $d . '" task_status="'.$row[5].'" main_type="'.$row[1].'" main_id="'.$row[4].'" >
                //                                                <i class="fa fa-check"></i> ' . CommonLanguage::getMessage('finish') . ' </button></a>';
                //                    }
                return $html;
            }
                 ),
            array('db' => 'main_id', 'dt' => 4),
            array('db' => 'task_status', 'dt' => 5),
            array('db' => 'task_type', 'dt' => 6),
        );
        //    echo $cond;exit;
        $key = 'task_id';
        $table = 'tbl_emp_tasks';
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }

    public function updateStatusTaskRequest() {
        $task_id = $_GET['task_id'];
        $task_status = $_GET['task_status'];
        $result = $this->_registry->announcement->updateStatusTask($task_status, $task_id);
    }
    public function doneStatusTaskRequest() {
        $task_id = $_GET['task_id'];
        $result = $this->_registry->announcement->doneStatusTask($task_id);
    }

    public function getNtfDetailsRequest() {
        $main_id = $_GET['main_id'];
        $main_type = $_GET['main_type'];
        $result = $this->_registry->announcement->getNtfDetails($main_id, $main_type);

        die(json_encode($result));
    }
    public function submit_multi_deduction(){

        $_POST['Logged_ID'] = Session::getUserID();
        $submit = $this->_registry->finance->setData($_POST)->submit_multi_deduction();
        die(empty($submit) ? 'OK' : 'error');
    }
    function returnNonAttForEmp() {
        $from_date = smc_escape($_GET['from_date']);
        $to_date = smc_escape($_GET['to_date']);
        $emp_id = smc_escape($_GET['emp_id']);
        $dep_id = smc_escape($_GET['dep_id']);
        $day_count = smc_escape($_GET['day_count']);
        $result = $this->_registry->attendance->get_non_working_days($from_date, $to_date, $emp_id, $dep_id,$day_count);
        die(json_encode($result));
        die($result ? json_encode($result) : 'error');
    }

    public function insertNonAttForEmp(){
        $db=  DBConnectorFactory::loadDriver();
        $db->query('START TRANSACTION;');
        foreach($_POST['emp_arr'] as $emp){
            if($emp['type']=='leave'){
                $emp['trs_dys'] = 0;
                $emp['is_half_day'] = 0;
                $this->_registry->worktimes->stop_transaction_start_end = true;
                $this->_registry->worktimes->setData($emp)->addTakenAccruedDays();
            }else{
                $emp['Absence_From_Date']=$emp['Date_From'];
                $emp['Absence_To_Date']=$emp['Date_To'];
                $emp['Absence_Reason']=$emp['type_id'];
                $emp[0]=smc_session()['user_logged_id'];
                $this->_registry->absence->stop_transaction_start_end = true;
                $this->_registry->absence->setData($emp)->create();
            }
        }
        $error = $db->error();
        if(empty($error))
            $db->query('COMMIT');
        else
            $db->query('ROLLBACK');
        die(empty($error) ? 'OK' : 'error');
    }
    public function approve_advance_payment() {
        $update = $this->_registry->finance->setData($_POST)->approve_advance_payment();
        die(empty($update) ? 'OK' : 'error');
    }
    public function approve_loan() {
        $update = $this->_registry->finance->setData($_POST)->approve_loan();
        die(empty($update) ? 'OK' : 'error');
    }

    public function submitEmpOpening(){
        $submit = $this->_registry->employee->setData($_POST)->submitEmpOpening();
        die(json_encode(empty($submit) ? [CommonLanguage::getMessage('Submitted_Successfully'), 'success' ] : [$submit[0], 'danger']));
    }
    public function deleteEmpOpening(){
        $delete_emp_opening = $this->_registry->employee->setData($_GET)->deleteEmpOpening();
        die(empty($delete_emp_opening) ? "ok" : "error");
    }
    public function edit_absence(){
        $edit = $this->_registry->absence->setData($_POST)->edit_absence();
         die(json_encode(empty($edit) ? ["success", ""] : ["error", $edit[0]]));
    }
    public function view_absence_by_id(){
        $data = $this->_registry->absence->view_absence_by_id($_GET['id']);
        die(json_encode($data));
    }
    public function view_leave_by_id(){
        $data = $this->_registry->worktimes->view_leave_by_id($_GET['id']);
        die(json_encode($data));
    }
    public function getEmployeeInfo(){
        $data = $this->_registry->employee->viewEmployee($_GET['employee_id']);
        die(json_encode($data));
    }
     public function edit_leave() {
            $result = $this->_registry->worktimes->setData($_POST)->edit_leave();
            die(json_encode(empty($result) ? ["success", ""] : ["error", $result[0]]));
    }
     public function employee_leave_absence_report() {
         $reason_ids = empty($_GET['reason_ids']) ? array() : $_GET['reason_ids'];
        $data = $this->_registry->absence->setData($_GET)->employee_leave_absence_report($_GET['start_date'],$_GET['end_date'],$reason_ids);
        $html=Forms::build_table_html($data);
        die($html);
    }
    
    public function delete_overtime(){
        $delete = $this->_registry->finance->delete_overtime($_POST['id']);
        die(empty($delete) ? 'OK' : $delete[0]);
    }
    public function manage_emp_leaves() {
        $data = $this->_registry->worktimes->setData($_GET)->manage_emp_leaves();
        $html=Forms::build_table_html($data);
        die($html);
    }
    
    public function update_multi_emp_leave_setting(){
        $update = $this->_registry->employee->setData($_POST)->update_multi_emp_leave_setting();
        die(empty($update) ? 'OK' : 'error');
    }
     public function paid_accrued_list_ajax() {
        $cond = ' 1=1 ';
        
        if (isset($_GET['is_actual']) && $_GET['is_actual'] == 0) {
            $cond.=' and is_actual = 0 ';
        }
        
        if(!empty($_GET['employee_id'])){
            $cond.= ' and Employee_ID = "'.$_GET['employee_id'].'"';
        }
        if(!empty($_GET['start_date']) && !empty($_GET['end_date'])){
            $cond.=' and (Paid_Date between "'.$_GET['start_date'].'" and "'.$_GET['end_date'].'")';
        }
        $columns = array(
            array('db' => 'Employee_Name', 'dt' => 0),
            array('db' => 'Paid_Date', 'dt' => 1),
            array('db' => 'Days_Number', 'dt' => 2),
            array('db' => 'Paid_Amount', 'dt' => 3,"formatter"=>function($d,$row){
                return $d.' '.$row[5];
            }),
            array(
                'db' => 'Paid_Accrued_ID',
                'dt' => 4,
                'formatter' => function( $d, $row ) {
                        $option_arr[]= ["title" => CommonLanguage::getMessage("Edit"),
                                    "class" => "edit_leave",
                                    "permission" => $row[6]==0 ? "edit_paid_accrued_leave" : "edit_act_paid_accrued_leave",
                                    "href"=>"HRM/paidAccruedLeave/".($row[6]==1 ? 'act/' : '').$d,
                                    "icon" => "fa-pencil"
                                   ];
                    
                    $html = Forms::action_snippet(["color" => "success", "isDropDown" => false, "data_id" => $d,
                                                   "ActionOption" => $option_arr]);

                    return $html;
                }
            ),
            array('db' => 'Currency_Symbol', 'dt' => 5),
            array('db' => 'is_actual', 'dt' => 6)
        );
        //        echo $cond;
        //        die('ok');
        $key = 'Paid_Accrued_ID';
        $table = 'paid_accrued_leave';
        
        $data = DataTable::complex($_GET, $table, $key, $columns, $cond);
        echo json_encode($data);
    }
    public function edit_paid_accrued() {
            $Result = $this->_registry->worktimes->setData($_POST)->edit_paid_accrued();
            die(empty($Result) ? "success" : $Result[0] );
    }
    
    public function delete_emp_location(){
        $delete = $this->_registry->employee->delete_emp_location($_GET['id']);
        die(empty($delete) ? 'ok' : $delete[0]);
    }
    public function save_interior_ministry_report(){
        $insert = $this->_registry->employee->setData($_POST)->save_interior_ministry_report();
        die(empty($insert) ? 'OK' : $insert[0]);
    }
     public function submitCommissionSetting(){
        $submit = $this->_registry->employee->setData($_POST)->submitCommissionSetting();
        die(json_encode(empty($submit) ? [CommonLanguage::getMessage('Submitted_Successfully'), 'success' ] : [$submit[0], 'danger']));
    }
    public function deleteCommissionSetting(){
        $delete = $this->_registry->employee->setData($_GET)->deleteCommissionSetting();
        die(empty($delete) ? "ok" : "error");
    }
    public function getCommissionSettingData(){
        $data['main'] =CommonFunctions::CommonView('tbl_commission_type',['commission_id'],[$_GET['commission_id']]);
        $data['details'] =CommonFunctions::CommonView('tbl_commission_type_details',['commission_id'],[$_GET['commission_id']]);
        die(json_encode($data));
    }
    public function commissionSettingAjax() {
        $columns = array('commission_name',
                         array(
                             'db' => 'commission_id',
                             'dt' => 1,
                             'formatter' => function( $d ) {
                                 $html = Forms::action_snippet(["color" => "success",
                                                                  "isDropDown" => true,
                                                                  "data_id" => "{$d}",
                                                                  "ActionOption" => [
                                                                      ['title' =>CommonLanguage::getMessage('Edit'),
                                                                       'class' => 'edit',
                                                                       'data-target' => '#commission_setting_modal',
                                                                       'attr'=>"data-id={$d}",
                                                                       'icon' => 'fa-pencil',
                                                                       'permission'=>'edit_commission_setting'
                                                                      ],
                                                                      ['title' => CommonLanguage::getMessage('delete'),
                                                                       'class' => 'delete',
                                                                        'attr'=>"data-id={$d}",
                                                                       'icon' => 'fa-trash',
                                                                       'permission'=>'delete_commission_setting'
                                                                      ]]]);
                                   return $html;
                             }
                         )
                        );
        $key = 'commission_id';
        $table = 'tbl_commission_type';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }
    
    public function salesCommissionAjax(){
        $data = $this->_registry->finance->setData($_GET)->salesman_commission_report($_GET['commission_id'],$_GET['from_date'],$_GET['to_date'],$_GET['sales_id'],$_GET['type']);
        $html = Forms::build_table_html($data['data']);
        die(json_encode(['row_arr'=>$data['row_arr'],'data'=>$data,'html'=>$html,'total'=>$data['total']]));
    }
    
    public function add_commission_bonus(){
        $db=  DBConnectorFactory::loadDriver();
        $db->query('START TRANSACTION');
        foreach($_POST['bonuses'] as $row){
          $submit = $this->_registry->finance->setData($row)->createBonusOrDeduction("tbl_hrm_bonuses", "Bonus");
          if(!empty($submit)){
              die($submit[0]);
          }
        }
        $error = $db->error();
        if(empty($error)){
            $db->query('COMMIT');
        }else{
            $db->query('ROLLBACK'); 
        }
        die(empty($error) ? 'OK' : $error[0]);
        
    }
    public function fetch_dep_emp() {
//        $this->_registry->branch->view_department_emp(1);
        
        $cmd = isset($_GET["cmd"]) ? $_GET["cmd"] : "";
        $id = isset($_GET["id"]) ? intval($_GET["id"]) : 0;
        $this->status = isset($_GET["status"]) ? intval($_GET["status"]) : -1;
        if ($cmd == "fetch") {
            $RET = $id == 0 ? $this->_registry->branch->view_department_emp() : $this->_registry->branch->view_department_emp($id);
            for ($x = 0; $x < count($RET); $x++) {
                if($RET[$x]["is_emp"]==0){
                    $RET2 = $this->_registry->branch->view_department_emp(intval($RET[$x]["myid"]));
                if (count($RET2) > 0)
                    $RET[$x]["isLazy"] = true;
                }else{
                    $RET[$x]["isLazy"] = false;
                }
                $RET[$x]["key"] = $RET[$x]["id"];
            }
            echo json_encode($RET);
        }
       else {
            $RET = $this->_registry->branch->view_department_emp();
        }
    }
    public function get_absence_by_job(){
        $job_id = !empty($_GET['job_id']) ? $_GET['job_id'] : null;
        $data = $this->_registry->absence->get_absence_by_job($job_id);
        die(json_encode($data));
    }
    public function get_absence_by_type(){
        $type_id = !empty($_GET['type_id']) ? $_GET['type_id'] : null;
        $data = $this->_registry->absence->get_absence_by_type($_GET['type'],$type_id);
        die(json_encode($data));
    }
    
    public function emp_absence_setting_ajax(){
        
       $_GET['reasons_arr'] = $this->_registry->absence->viewAbsenceReasons();
        //
        $_GET['emp_types']=array();
        $cond=' ';
        $cond_reason='';
         if(!empty($_GET['dep_id']))
            $cond.= ' and Branch_ID = "'.$_GET['dep_id'].'" ';
        if(!empty($_GET['job_id']))
            $cond.=' and Job_ID = "'.$_GET['job_id'].'" ';
        if(!empty($_GET['shift_id']))
            $cond.=' and Shift_ID = "'.$_GET['shift_id'].'" ';
        if(!empty($_GET['reason_arr'])){
//            echo"<pre>";die(print_r($_GET['reason_arr']));
            $cond_reason.=' and Absence_Reason_ID in ('.implode(',',$_GET['reason_ids']).') ';
        }
        $query = $this->db->query('select * from tbl_hrm_emp_absence_setting s 
            join tbl_hrm_employee e on e.employee_id = s.Employee_ID where absence_type = 2 '.$cond.' '.$cond_reason);
        while($row = $this->db->assoc($query)){
            $_GET['emp_types'][$row['employee_id']][$row['absence_reason_id']] =$row['nb_days'];  
            
        }
// echo"<pre>";die(print_r($_GET['reasons_arr']));
        $columns = array('Employee_Name');
        if(!empty($_GET['reasons_arr'])){
            foreach($_GET['reasons_arr'] as $type){
                if(in_array($type['Absence_Reason_ID'], $_GET['reason_ids'])){
                   
                    $columns[] =  array('db' => 'absence_type',  "formatter" => function($d,$row) use($type){
                        $nb_days=!empty($_GET['emp_types'][$row['Employee_ID']][$type['Absence_Reason_ID']]) ? $_GET['emp_types'][$row['Employee_ID']][$type['Absence_Reason_ID']] : '';
                         return '<input data-type="'.$type['Absence_Reason_ID'].'" data-emp="'.$row['Employee_ID'].'" class="nb_days form-control text-center" type="number" min="0" max="100" step="any" value="'.$nb_days.'"/>';
                     });
                }
            }
        }
        $columns[] =  'Employee_ID';
        $key = 'Employee_ID';
        $table = '( select CONCAT(Employee_FirstName, " ", Employee_MiddleName, " ", Employee_LastName) AS Employee_Name,
            absence_type,Employee_ID from tbl_hrm_employee where absence_type=2 '.$cond.') as emp';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }
    public function update_emp_absence(){
        $update = $this->_registry->absence->setData($_POST)->update_emp_absence();
        die(empty($update) ? 'OK' : 'error');
    }
    
    public function save_temp_att_data(){
        $insert = $this->_registry->attendance->setData($_POST)->save_temp_att_data();
        die(empty($insert) ? 'OK' : 'error');
    }
     public function get_temp_att_list(){
      $columns = array('temp_title','date_time',
                         array(
                             'db' => 'temp_id',
                             'dt' => 2,
                             'formatter' => function( $d,$row ) {
                                $html='<button class="btn btn-success retreive_temp" data-title="'.$row['temp_title'].'" data-id="'.$d.'">'.CommonLanguage::getMessage('retreive').'</button>'
                                        . '<button class="btn btn-success m-l-10 delete_temp"  data-id="'.$d.'">'.CommonLanguage::getMessage('delete').'</button>';
//                                 $html = Forms::action_snippet(["color" => "success",
//                                                                  "isDropDown" => true,
//                                                                  "data_id" => "{$d}",
//                                                                  "ActionOption" => [
//                                                                      ['title' =>CommonLanguage::getMessage('retreive'),
//                                                                       'class' => 'retreive_temp',
//                                                                       'attr'=>"data-title='".$row['temp_title']."'",
//                                                                       'icon' => 'fa-pencil'
//                                                                      ],
//                                                                      ['title' => CommonLanguage::getMessage('delete'),
//                                                                       'class' => 'delete_temp',
//                                                                       'icon' => 'fa-trash'
//                                                                      ]]]);
                                   return $html;
                             }
                         )
                        );
        $key = 'temp_id';
        $table = 'tbl_hrm_temp_attendance';
        $data = DataTable::complex($_GET, $table, $key, $columns);
        echo json_encode($data);
    }
    
    public function get_temp_att_data(){
        $data =CommonFunctions::CommonView('tbl_hrm_temp_attendance',['temp_id'],[$_GET['temp_id']]);
//        echo"<pre>";die(print_r($data));
        die($data[0]['temp_arr']);

    }
    
    public function delete_temp_att(){
            $delete = $this->_registry->attendance->delete_temp_att($_GET['id']);
        die(empty($delete) ? 'ok' : $delete[0]);
    }
    
      public function delete_att_template() {
        $delete = $this->_registry->attendance->delete_att_template($_GET['id']);
        die(empty($delete) ? 'ok' : $delete[0]);
    }
}
