? Fallagassrini

Fallagassrini Bypass Shell

echo"
Fallagassrini
";
Current Path : /home1/savoy/public_html/savoyglobal.net/sec_old/application/models/

Linux gator3171.hostgator.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
Upload File :
Current File : /home1/savoy/public_html/savoyglobal.net/sec_old/application/models/hrmodel.php

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Hrmodel extends CI_Model {

    function __construct() {
        // Call the Model constructor
        parent::__construct();
        // $this->load->model('hrmodel');
    }

    function search_designation($pagenum) {
        $data = array();
        $this->db->select('*');
        $this->db->from('designation');
        $this->db->order_by('designation_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_designation($postdata) {

        $data = array();

        $this->db->trans_begin();

        $tblValues = array(
            'designation_name' => $postdata['designation_name'],
        );

        $this->db->insert('designation', $tblValues);
        $data['resfunction'] = 'search_designation';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_designation($postdata) {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array('designation_name' => $postdata['designation_name']);
        $this->db->where('designation_id', $postdata['designation_id']);
        $this->db->update('designation', $tblValues);
        $data['resfunction'] = 'search_designation';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_department($pagenum) {
        $data = array();

        $this->db->select('*');
        $this->db->from('department');

        $this->db->order_by('department_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_department($postdata) {
        $data = array();
        $this->db->trans_begin();

        $tblValues = array(
            'department_name' => $postdata['department_name'],
        );
        $this->db->insert('department', $tblValues);
        $data['resfunction'] = 'search_department';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_department($postdata) {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'department_name' => $postdata['department_name']
        );
        $this->db->where('department_id', $postdata['department_id']);
        $this->db->update('department', $tblValues);
        $data['resfunction'] = 'search_department';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_grade($pagenum) {
        $data = array();

        $this->db->select('*');
        $this->db->from('grade');

        $this->db->order_by('grade_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_grade($postdata) {

        $data = array();
        $this->db->trans_begin();

        $tblValues = array(
            'grade_name' => $postdata['grade_name'],
        );
        $this->db->insert('grade', $tblValues);
        $data['resfunction'] = 'search_grade';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_grade($postdata) {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'grade_name' => $postdata['grade_name']
        );
        $this->db->where('grade_id', $postdata['grade_id']);
        $this->db->update('grade', $tblValues);
        $data['resfunction'] = 'search_grade';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_status($pagenum) {
        $data = array();

        $this->db->select('*');
        $this->db->from('status');
        $this->db->order_by('status_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_status($postdata) {
        $data = array();
        $this->db->trans_begin();

        $tblValues = array(
            'status_name' => $postdata['status_name'],
        );
        $this->db->insert('status', $tblValues);
        $data['resfunction'] = 'search_status';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_status($postdata) {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'status_name' => $postdata['status_name']
        );
        $this->db->where('status_id', $postdata['status_id']);
        $this->db->update('status', $tblValues);
        $data['resfunction'] = 'search_status';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_employee($pagenum) {
        $data = array();
        $this->db->select('*');
        $this->db->from('employee');
        $this->db->join('master', 'master_id=employee_id');
        $this->db->join('designation', 'designation_id=employee_designation_id');
        $this->db->join('department', 'department_id=employee_department_id');
        $this->db->join('grade', 'grade_id=employee_grade_id');
        $this->db->order_by('employee_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_employee($postdata) {

        $data = array();
        $this->db->trans_begin();
        $masterid = $this->mastermodel->insertmasterdata();
        $expiry_date = $this->mastermodel->convertdateformat($postdata['employee_visa_expiry_date']);
        $dob = $this->mastermodel->convertdateformat($postdata['employee_dob']);
        $labour_date = $this->mastermodel->convertdateformat($postdata['employee_labour_card_expiry_date']);
        if (isset($postdata['employee_teacher']))
            $employee_teacher = 1;
        else
            $employee_teacher = 0;
        $tblValues = array('employee_id' => $masterid,
            'employee_no' => $postdata['employee_no'],
            'employee_name' => $postdata['employee_name'],
            'employee_gender' => $postdata['employee_gender'],
            'employee_dob' => $dob,
            'employee_nationality' => $postdata['employee_nationality'],
            'employee_branch_id' => $postdata['employee_branch_id'],
            'employee_designation_id' => $postdata['employee_designation_id'],
            'employee_department_id' => $postdata['employee_department_id'],
            'employee_grade_id' => $postdata['employee_grade_id'],
            'employee_status_id' => $postdata['employee_status_id'],
            'employee_local_address' => $postdata['employee_local_address'],
            'employee_permanent_address' => $postdata['employee_permanent_address'],
            'employee_contact_no' => $postdata['employee_contact_no'],
            'employee_mobile_no' => $postdata['employee_mobile_no'],
            'employee_email' => $postdata['employee_email'],
            'employee_passport_no' => $postdata['employee_passport_no'],
            'employee_visa_type' => $postdata['employee_visa_type'],
            'employee_visa_expiry_date' => $expiry_date,
            'employee_labour_card_no' => $postdata['employee_labour_card_no'],
            'device_no' => $postdata['device_no'],
            'employee_labour_card_expiry_date' => $labour_date,
            'employee_reporting_to' => $postdata['employee_reporting_to'],
            'employee_qatar_id_no' => $postdata['employee_qatar_id_no'],
            'employee_teacher' => $employee_teacher,
        );
        $this->db->insert('employee', $tblValues);

        $parent = $this->mastermodel->get_account_settings('employee', 'finance_sub_account_settings');
        if ($parent) {
            $chart_type_id = $this->mastermodel->get_single_field_value('finance_chart_master', 'chart_type_id', 'chart_master_id', $parent);
            if ($this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $postdata['employee_no']) == 0) {
                $tblValues = array('chart_account_code' => $postdata['employee_no'],
                    'chart_account_name' => $postdata['employee_name'],
                    'chart_type_id' => $chart_type_id,
                    'parent' => $parent,
                    'inactive' => 0);
                $this->db->insert('finance_chart_master', $tblValues);
            } else {
                $tblValues = array(
                    'chart_account_name' => $postdata['employee_name'],
                    'chart_type_id' => $chart_type_id,
                    'parent' => $parent,
                    'inactive' => 0);
                $this->db->where('chart_account_code', $postdata['employee_no']);
                $this->db->update('finance_chart_master', $tblValues);
            }
        }


        $i = 1;
        while (isset($postdata['course' . $i])) {
            if ($postdata['course' . $i] != '') {
                $tblValues = array(
                    'employee_id' => $masterid,
                    'course' => $postdata['course' . $i],
                    'university' => $postdata['university' . $i],
                    'yearofpassing' => $postdata['yearofpassing' . $i]);
                $this->db->insert('employee_educational_qualification', $tblValues);
            }
            $i++;
        }
        $i = 1;
        while (isset($postdata['employer' . $i])) {
            if ($postdata['employer' . $i] != '') {
                $tblValues = array(
                    'employee_id' => $masterid,
                    'employer' => $postdata['employer' . $i],
                    'designation' => $postdata['designation' . $i],
                    'period' => $postdata['period' . $i]);
                $this->db->insert('employee_professional_experience', $tblValues);
            }
            $i++;
        }
        $i = 1;
        while (isset($postdata['additional_course' . $i])) {
            if ($postdata['additional_course' . $i] != '') {
                $tblValues = array(
                    'employee_id' => $masterid,
                    'course' => $postdata['additional_course' . $i],
                    'institute' => $postdata['additional_institute' . $i],
                    'yearofpassing' => $postdata['additional_yearofpassing' . $i]);
                $this->db->insert('employee_additional_certification', $tblValues);
            }
            $i++;
        }

        $data['resfunction'] = 'search_employee';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_employee($postdata) {
        $data = array();
        $this->db->trans_begin();
        if (isset($postdata['employee_teacher']))
            $employee_teacher = 1;
        else
            $employee_teacher = 0;
        $tblValues = array(
            'employee_name' => $postdata['employee_name'],
            'employee_gender' => $postdata['employee_gender'],
            'employee_dob' => $this->mastermodel->convertdateformat($postdata['employee_dob']),
            'device_no' => $postdata['device_no'],
            'employee_nationality' => $postdata['employee_nationality'],
            'employee_branch_id' => $postdata['employee_branch_id'],
            'employee_passport_no' => $postdata['employee_passport_no'],
            'employee_visa_type' => $postdata['employee_visa_type'],
            'employee_visa_expiry_date' => $this->mastermodel->convertdateformat($postdata['employee_visa_expiry_date']),
            'employee_contact_no' => $postdata['employee_contact_no'],
            'employee_mobile_no' => $postdata['employee_mobile_no'],
            'employee_local_address' => $postdata['employee_local_address'],
            'employee_permanent_address' => $postdata['employee_permanent_address'],
            'employee_designation_id' => $postdata['employee_designation_id'],
            'employee_department_id' => $postdata['employee_department_id'],
            'employee_grade_id' => $postdata['employee_grade_id'],
            'employee_status_id' => $postdata['employee_status'],
            'employee_labour_card_no' => $postdata['employee_labour_card_no'],
            'employee_labour_card_expiry_date' => $this->mastermodel->convertdateformat($postdata['employee_labour_card_expiry_date']),
            'employee_email' => $postdata['employee_email'],
            'employee_reporting_to' => $postdata['employee_reporting_to'],
            'employee_qatar_id_no' => $postdata['employee_qatar_id_no'],
            'employee_teacher' => $employee_teacher,
        );
        $this->db->where('employee_id', $postdata['employee_id']);
        $this->db->update('employee', $tblValues);


        $this->db->where('employee_id', $postdata['employee_id']);
        $this->db->delete('employee_educational_qualification');

        $i = 1;
        while (isset($postdata['course' . $i])) {
            if ($postdata['course' . $i] != '') {
                $tblValues1 = array(
                    'employee_id' => $postdata['employee_id'],
                    'course' => $postdata['course' . $i],
                    'university' => $postdata['university' . $i],
                    'yearofpassing' => $postdata['yearofpassing' . $i]
                );
                $this->db->insert('employee_educational_qualification', $tblValues1);
            }
            $i++;
        }

        $this->db->where('employee_id', $postdata['employee_id']);
        $this->db->delete('employee_professional_experience');

        $i = 1;
        while (isset($postdata['employer' . $i])) {
            if ($postdata['employer' . $i] != '') {
                $tblValues1 = array(
                    'employee_id' => $postdata['employee_id'],
                    'employer' => $postdata['employer' . $i],
                    'designation' => $postdata['designation' . $i],
                    'period' => $postdata['period' . $i]);
                $this->db->insert('employee_professional_experience', $tblValues1);
            }
            $i++;
        }
        $this->db->where('employee_id', $postdata['employee_id']);
        $this->db->delete('employee_additional_certification');
        $i = 1;
        while (isset($postdata['additional_course' . $i]) != '') {
            if ($postdata['additional_course' . $i] != '') {
                $tblValues1 = array(
                    'employee_id' => $postdata['employee_id'],
                    'course' => $postdata['additional_course' . $i],
                    'institute' => $postdata['additional_institute' . $i],
                    'yearofpassing' => $postdata['additional_yearofpassing' . $i]);
                $this->db->insert('employee_additional_certification', $tblValues1);
            }
            $i++;
        }


        $this->db->where('employee_id', $postdata['employee_id']);
        $this->db->update('employee', $tblValues);

        $parent = $this->mastermodel->get_account_settings('employee', 'finance_sub_account_settings');
        if ($parent) {
            $chart_type_id = $this->mastermodel->get_single_field_value('finance_chart_master', 'chart_type_id', 'chart_master_id', $parent);
            if ($this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $postdata['employee_no']) == 0) {
                $tblValues = array('chart_account_code' => $postdata['employee_no'],
                    'chart_account_name' => $postdata['employee_name'],
                    'chart_type_id' => $chart_type_id,
                    'parent' => $parent,
                    'inactive' => 0);
                $this->db->insert('finance_chart_master', $tblValues);
            } else {
                $tblValues = array(
                    'chart_account_name' => $postdata['employee_name'],
                    'chart_type_id' => $chart_type_id,
                    'parent' => $parent,
                    'inactive' => 0);
                $this->db->where('chart_account_code', $postdata['employee_no']);
                $this->db->update('finance_chart_master', $tblValues);
            }
        }


        $data['resfunction'] = 'search_employee';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_leave_allocation($pagenum) {
        $data = array();

        $this->db->select('*');
        $this->db->from('leave_allocation');
        $this->db->join('employee', 'employee.employee_id=leave_allocation.employee_id');

        $this->db->order_by('leave_allocation_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_leave_allocation($postdata) {


        $data = array();
        $this->db->trans_begin();
        $masterid = $this->mastermodel->insertmasterdata();
        $tblValues = array('leave_allocation_id' => $masterid,
            'employee_id' => $postdata['employee_id'],
            'leave_allocation_year' => $postdata['leave_allocation_year']);
        $this->db->insert('leave_allocation', $tblValues);
        $i = 1;
        while (isset($postdata['leave_type_id' . $i])) {
            $tblValues = array('leave_allocation_id' => $masterid,
                'leave_type_id' => $postdata['leave_type_id' . $i],
                'leave_allocation_days' => $postdata['leave_allocation_days' . $i]);
            $this->db->insert('leave_allocation_detail', $tblValues);
            $i++;
        }
        $data['resfunction'] = 'search_leave_allocation';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_leave_allocation($postdata) {
        $data = array();
        $this->db->trans_begin();
        $this->mastermodel->updatemasterdata($postdata['leave_allocation_id']);
        $tblValues = array(
            'leave_allocation_year' => $postdata['leave_allocation_year']);

        $this->db->where('leave_allocation_id', $postdata['leave_allocation_id']);
        $this->db->update('leave_allocation', $tblValues);

        $this->db->where('leave_allocation_id', $postdata['leave_allocation_id']);
        $this->db->delete('leave_allocation_detail');
        $i = 1;
        while (isset($postdata['leave_type_id' . $i])) {
            $tblValues = array('leave_allocation_id' => $postdata['leave_allocation_id'],
                'leave_type_id' => $postdata['leave_type_id' . $i],
                'leave_allocation_days' => $postdata['leave_allocation_days' . $i]);
            $this->db->insert('leave_allocation_detail', $tblValues);
            $i++;
        }
        $data['resfunction'] = 'search_leave_allocation';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_leave_application($pagenum) {
        $data = array();
        $emp = $this->mastermodel->get_single_field_value('user', 'employee_id', 'user_id', $_SESSION['user_id']);

        $this->db->select('*');
        $this->db->from('leave_application');
        $this->db->join('employee', 'employee.employee_id=leave_application.employee_id');
        if ($_SESSION['user_id'] != 1)
            $this->db->where('employee.employee_reporting_to', $emp);
        $this->db->order_by('leave_application_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_leave_application($postdata) {

        $data = array();
        $this->db->trans_begin();
        $masterid = $this->mastermodel->insertmasterdata();
        $fromdate = $this->mastermodel->convertdateformat($postdata['from_date']);
        $todate = $this->mastermodel->convertdateformat($postdata['to_date']);
        $tblValues = array('leave_application_id' => $masterid,
            'employee_id' => $postdata['employee_id'],
            'leave_type_id' => $postdata['leave_type_id'],
            'from_date' => $fromdate,
            'to_date' => $todate,
            'remarks' => $postdata['remarks']);
        $this->db->insert('leave_application', $tblValues);
        $data['resfunction'] = 'search_leave_application';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_leave_application($postdata) {

        $data = array();
        $this->db->trans_begin();
        $this->mastermodel->updatemasterdata($postdata['leave_application_id']);
        $fromdate = $this->mastermodel->convertdateformat($postdata['from_date']);
        $todate = $this->mastermodel->convertdateformat($postdata['to_date']);
        $tblValues = array(
            'leave_type_id' => $postdata['leave_type_id'],
            'from_date' => $fromdate,
            'to_date' => $todate,
            'remarks' => $postdata['remarks']);
        $this->db->where('leave_application_id', $postdata['leave_application_id']);
        $this->db->update('leave_application', $tblValues);
        $data['resfunction'] = 'search_leave_application';

        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function leave_approval($id, $status) {
        $tblvalue = array(
            'leave_status' => $status
        );
        $this->db->where('leave_application_id', $id);
        $this->db->update('leave_application', $tblvalue);
    }

    function search_leave_type($pagenum) {
        $data = array();
        $this->db->select('*');
        $this->db->from('leave_type');
        $this->db->order_by('leave_type_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_leave_type($postdata) {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'leave_code' => $postdata['leave_code'],
            'leave_type_name' => $postdata['leave_type_name']
        );
        $this->db->insert('leave_type', $tblValues);
        $data['resfunction'] = 'search_leave_type';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_leave_type($postdata) {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'leave_code' => $postdata['leave_code'],
            'leave_type_name' => $postdata['leave_type_name']
        );
        $this->db->where('leave_type_id', $postdata['leave_type_id']);
        $this->db->update('leave_type', $tblValues);
        $data['resfunction'] = 'search_leave_type';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_holiday($pagenum) {
        $data = array();

        $this->db->select('*');
        $this->db->from('holiday');

        $this->db->order_by('holiday_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_holiday($postdata) {

        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'holiday_name' => $postdata['holiday_name'],
            'holiday_start_date' => $this->mastermodel->convertdateformat($postdata['holiday_start_date']),
            'holiday_end_date' => $this->mastermodel->convertdateformat($postdata['holiday_end_date']),
        );

        $this->db->insert('holiday', $tblValues);
        $data['resfunction'] = 'search_holiday';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_holiday($postdata) {
        $data = array();
        $this->db->trans_begin();
        $tblValues = array(
            'holiday_name' => $postdata['holiday_name'],
            'holiday_start_date' => $this->mastermodel->convertdateformat($postdata['holiday_start_date']),
            'holiday_end_date' => $this->mastermodel->convertdateformat($postdata['holiday_end_date']),
        );
        $this->db->where('holiday_id', $postdata['holiday_id']);
        $this->db->update('holiday', $tblValues);
        $data['resfunction'] = 'search_holiday';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_teachers($pagenum) {
        $data = array();
        $this->db->select('*');
        $this->db->from('employee');
        $this->db->join('master', 'master_id=employee_id');
        $this->db->where('employee_teacher', 1);
        $this->db->order_by('employee_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_teacher($postdata) {
        $data = array();
        $this->db->trans_begin();
        $masterid = $this->mastermodel->insertmasterdata();
        $reliev_date = $this->mastermodel->convertdateformat($postdata['relieving_date']);
        $dob = $this->mastermodel->convertdateformat($postdata['dob']);
        $join_date = $this->mastermodel->convertdateformat($postdata['date_of_join']);
        $tblValues = array(
            'employee_id' => $masterid,
            'employee_no' => $postdata['teacher_no'],
            'employee_name' => $postdata['employee_name'],
            'employee_gender' => $postdata['gender'],
            'employee_dob' => $dob,
            'employee_email' => $postdata['email'],
            'employee_contact_no' => $postdata['contact_no'],
            'employee_mobile_no' => $postdata['mobile_no'],
            'employee_passport_no' => $postdata['passport_no'],
            'device_no' => $postdata['device_no'],
            'date_of_join' => $join_date,
            'relieving_date' => $reliev_date,
            'teacher' => '1',
            'employee_branch_id' => $postdata['employee_branch_id'],
            'employee_designation_id' => $postdata['employee_designation_id'],
            'employee_department_id' => $postdata['employee_department_id'],
            'employee_grade_id' => $postdata['employee_grade_id'],
            'employee_status_id' => $postdata['employee_status_id'],
            'employee_reporting_to' => $postdata['employee_reporting_to'],
            'employee_qatar_id_no' => $postdata['employee_qatar_id_no'],
        );


        $this->db->insert('employee', $tblValues);
        $i = 1;
        while (isset($postdata['course' . $i])) {
            if ($postdata['course' . $i] != '') {
                $tblValues = array(
                    'employee_id' => $masterid,
                    'course' => $postdata['course' . $i],
                    'university' => $postdata['university' . $i],
                    'yearofpassing' => $postdata['passing_year' . $i]);
                $this->db->insert('employee_educational_qualification', $tblValues);
            }
            $i++;
        }

        $i = 1;
        while (isset($postdata['employer' . $i])) {
            if ($postdata['employer' . $i] != '') {
                $tblValues = array(
                    'employee_id' => $masterid,
                    'employer' => $postdata['employer' . $i],
                    'designation' => $postdata['designation' . $i],
                    'period' => $postdata['period' . $i]);
                $this->db->insert('employee_professional_experience', $tblValues);
            }
            $i++;
        }
        $i = 1;
        while (isset($postdata['subject_id' . $i])) {
            $id = $this->mastermodel->get_single_field_value_two('course_subject', 'id', 'course_id', $postdata['course_id' . $i], 'subject_id', $postdata['subject_id' . $i]);
            $tblValues = array(
                'teacher_id' => $masterid,
                'course_subject_id' => $id,
            );
            $this->db->insert('teacher_subject', $tblValues);
            $i++;
        }

        $parent = $this->mastermodel->get_account_settings('employee', 'finance_sub_account_settings');
        if ($parent) {
            $chart_type_id = $this->mastermodel->get_single_field_value('finance_chart_master', 'chart_type_id', 'chart_master_id', $parent);
            if ($this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $postdata['teacher_no']) == 0) {
                $tblValues = array('chart_account_code' => $postdata['teacher_no'],
                    'chart_account_name' => $postdata['employee_name'],
                    'chart_type_id' => $chart_type_id,
                    'parent' => $parent,
                    'inactive' => 0);
                $this->db->insert('finance_chart_master', $tblValues);
            } else {
                $tblValues = array(
                    'chart_account_name' => $postdata['employee_name'],
                    'chart_type_id' => $chart_type_id,
                    'parent' => $parent,
                    'inactive' => 0);
                $this->db->where('chart_account_code', $postdata['teacher_no']);
                $this->db->update('finance_chart_master', $tblValues);
            }
        }


        $data['resfunction'] = 'search_teachers';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_teacher($postdata) {
        $data = array();
        $this->db->trans_begin();
        $reliev_date = $this->mastermodel->convertdateformat($postdata['relieving_date']);
        $dob = $this->mastermodel->convertdateformat($postdata['dob']);
        $join_date = $this->mastermodel->convertdateformat($postdata['date_of_join']);
        $tblValues = array(
            'employee_name' => $postdata['employee_name'],
            'employee_gender' => $postdata['gender'],
            'employee_dob' => $dob,
            'employee_email' => $postdata['email'],
            'employee_contact_no' => $postdata['contact_no'],
            'employee_mobile_no' => $postdata['mobile_no'],
            'employee_passport_no' => $postdata['passport_no'],
            'device_no' => $postdata['device_no'],
            'date_of_join' => $join_date,
            'relieving_date' => $reliev_date,
            'teacher' => '1',
            'employee_branch_id' => $postdata['employee_branch_id'],
            'employee_designation_id' => $postdata['employee_designation_id'],
            'employee_department_id' => $postdata['employee_department_id'],
            'employee_grade_id' => $postdata['employee_grade_id'],
            'employee_status_id' => $postdata['employee_status_id'],
            'employee_reporting_to' => $postdata['employee_reporting_to'],
            'employee_qatar_id_no' => $postdata['employee_qatar_id_no'],
        );
        $this->db->where('employee_id', $postdata['employee_id']);
        $this->db->update('employee', $tblValues);

        $this->db->where('employee_id', $postdata['employee_id']);
        $this->db->delete('employee_educational_qualification');

        $i = 1;
        while (isset($postdata['course' . $i])) {
            if ($postdata['course' . $i] != '') {
                $tblValues = array(
                    'employee_id' => $postdata['employee_id'],
                    'course' => $postdata['course' . $i],
                    'university' => $postdata['university' . $i],
                    'yearofpassing' => $postdata['passing_year' . $i]);
                $this->db->insert('employee_educational_qualification', $tblValues);
            }
            $i++;
        }
        $this->db->where('employee_id', $postdata['employee_id']);
        $this->db->delete('employee_professional_experience');

        $i = 1;
        while (isset($postdata['employer' . $i])) {
            if ($postdata['employer' . $i] != '') {
                $tblValues1 = array(
                    'employee_id' => $postdata['employee_id'],
                    'employer' => $postdata['employer' . $i],
                    'designation' => $postdata['designation' . $i],
                    'period' => $postdata['period' . $i]);
                $this->db->insert('employee_professional_experience', $tblValues1);
            }
            $i++;
        }

        $this->db->where('teacher_id', $postdata['employee_id']);
        $this->db->delete('teacher_subject');
        $i = 1;
        while (isset($postdata['course_id' . $i])) {
            $id = $this->mastermodel->get_single_field_value_two('course_subject', 'id', 'course_id', $postdata['course_id' . $i], 'subject_id', $postdata['subject_id' . $i]);
            $tblValues = array(
                'teacher_id' => $postdata['employee_id'],
                'course_subject_id' => $id,
            );
            $this->db->insert('teacher_subject', $tblValues);
            $i++;
        }


        $parent = $this->mastermodel->get_account_settings('employee', 'finance_sub_account_settings');
        if ($parent) {
            $chart_type_id = $this->mastermodel->get_single_field_value('finance_chart_master', 'chart_type_id', 'chart_master_id', $parent);

            if ($this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $postdata['employee_no']) == 0) {
                $tblValues = array('chart_account_code' => $postdata['employee_no'],
                    'chart_account_name' => $postdata['employee_name'],
                    'chart_type_id' => $chart_type_id,
                    'parent' => $parent,
                    'inactive' => 0);
                $this->db->insert('finance_chart_master', $tblValues);
            } else {
                $tblValues = array(
                    'chart_account_name' => $postdata['employee_name'],
                    'chart_type_id' => $chart_type_id,
                    'parent' => $parent,
                    'inactive' => 0);
                $this->db->where('chart_account_code', $postdata['employee_no']);
                $this->db->update('finance_chart_master', $tblValues);
            }
        }

        $data['resfunction'] = 'search_teachers';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_tool_kit($postdata) {
        $data = array();
        $this->db->trans_begin();
        $this->mastermodel->updatemasterdata($postdata['tool_id']);

        $i = 1;

        $this->db->where('tool_id', $postdata['tool_id']);
        $this->db->delete('tool_kit_details');


        while (isset($postdata['tool_id' . $i])) {
            $tblValues = array('tool_id' => $postdata['tool_id'],
                'tool_name' => $postdata['tool_id' . $i]);
            $this->db->insert('tool_kit_details', $tblValues);
            $i++;
        }
        $data['resfunction'] = 'search_tool_kit';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_timetable($pagenum) {
        $data = array();
        $this->db->select('*');
        $this->db->from('timetable');
        $this->db->join('master', 'master_id=timetable_id');
        $this->db->join('teacher', 'teacher_id=staff_id');
        $this->db->join('batch', 'batch.batch_id=timetable.batch_id');
        $this->db->join('course', 'course.course_id=batch.course_id');
        $this->db->join('course_subject', 'course_subject.course_id=course.course_id');
        $this->db->join('subject', 'subject.subject_id=course_subject.subject_id');
        $this->db->order_by('timetable_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function search_allowdeduc($pagenum) {
        $data = array();
        $this->db->select('*');
        $this->db->from('allowdeduc');
        $this->db->order_by('allowdeduc_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_allowdeduc($postdata) {
        $data = array();
        $this->db->trans_begin();
        $data['resfunction'] = 'search_allowdeduc';
        $chart_account_type = 3;
        $chart_type_sort = $this->mastermodel->get_single_field_value('finance_chart_type', 'sort', 'chart_type_id ', $chart_account_type);
        $start = $chart_type_sort * 100000;
        $max_code = $start + 50000;
        $code = $this->accountingmodel->account_code_generated($start, $max_code);

        if ($max_code > ($code)) {
            $acc_code = $code;
            $count = $this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $acc_code);
            if ($count == 0) {

                $tblValues = array(
                    'allowdeduc_name' => $postdata['allowdeduc_name'],
                    'allowdeduc_type' => $postdata['allowdeduc_type'],
                    'allowdeduc_mode' => $postdata['allowdeduc_mode'],
                    'chart_account_code' => $acc_code
                );
                $this->db->insert('allowdeduc', $tblValues);

                $tblValues = array(
                    'chart_account_code' => $acc_code,
                    'chart_account_name' => $postdata['allowdeduc_name'],
                    'chart_type_id' => 3,
                    'parent' => 0,
                    'inactive' => 0
                );
                $this->db->insert('finance_chart_master', $tblValues);


                $this->db->trans_commit();
                $data['res'] = 1;
                $data['msg'] = 'Record Added Successfully';
                return $data;
            } else {
                $this->db->trans_rollback();
                $data['res'] = 1;
                $data['msg'] = 'Error On Adding Record';
                return $data;
            }
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Account Beyond the Limit';
            return $data;
        }
    }

    function getmaxexpense() {
        $parent = $this->mastermodel->get_account_settings('salary', 'finance_sub_account_settings');

        if ($parent) {
            $chart_type_id = $this->mastermodel->get_single_field_value('finance_chart_master', 'chart_type_id', 'chart_master_id', $parent);
            $res = $this->db->query("SELECT max(`chart_account_code`) as max FROM `finance_chart_master` WHERE `chart_type_id`=$chart_type_id and parent=$parent");
            $row = $res->row();
            return $row->max;
        }
    }

    function update_allowdeduc($postdata) {

        $data = array();
        $this->db->trans_begin();
        $tblValues = array('allowdeduc_name' => $postdata['allowdeduc_name']
        );
        $this->db->where('allowdeduc_id', $postdata['allowdeduc_id']);
        $this->db->update('allowdeduc', $tblValues);

        $tblValues = array('chart_account_name' => $postdata['allowdeduc_name']
        );
        $this->db->where('chart_account_code', $postdata['chart_account_code']);
        $this->db->update('finance_chart_master', $tblValues);

        $data['resfunction'] = 'search_allowdeduc';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_salary_setting($pagenum) {
        $data = array();
        $this->db->select('*');
        $this->db->from('employee_salary');
        $this->db->join('master', 'master_id=employee_salary_id');
        $this->db->join('employee', 'employee.employee_id=employee_salary.employee_id');
        $this->db->order_by('employee_salary_id', 'desc');
        $data['results'] = $this->db->get();
        return $data;
    }

    function insert_salary_setting($postdata) {

        $data = array();
        $this->db->trans_begin();
        $masterid = $this->mastermodel->insertmasterdata();
        $wef_date = $this->mastermodel->convertdateformat($postdata['wef_date']);
        if (isset($postdata['return_ticket'])) {
            $return_ticket = 1;
        } else {
            $return_ticket = 0;
        }
        $tblValues = array('employee_salary_id' => $masterid,
            'employee_id' => $postdata['employee_id'],
            'wef_date' => $wef_date,
            'basic_salary' => $postdata['basic_salary'],
            'from_ticket' => $postdata['from_ticket'],
            'to_ticket' => $postdata['to_ticket'],
            'return_ticket' => $return_ticket,
            'no_tickets' => $postdata['no_tickets'],
            'payment_method' => $postdata['payment_method']);

        $this->db->insert('employee_salary', $tblValues);
        $i = 1;
        while (isset($postdata['amount_' . $i])) {
            $tblValues = array(
                'employee_salary_id' => $masterid,
                'allowdeduc_id' => $postdata['allowdeduc_id_' . $i],
                'amount' => $postdata['amount_' . $i]);
            $this->db->insert('employee_salary_allowdeduc', $tblValues);
            $i++;
        }
        $i = 1;
        while (isset($postdata['type' . $i])) {
            if ($postdata['type' . $i] != "") {
                $tblValues = array(
                    'employee_salary_id' => $masterid,
                    'type' => $postdata['type' . $i],
                    'company' => $postdata['company' . $i],
                    'policy' => $postdata['policy' . $i],
                    'plan' => $postdata['plan' . $i],
                    'sum' => $postdata['sum' . $i]);
                $this->db->insert('employee_salary_medical', $tblValues);
            }
            $i++;
        }

        $data['resfunction'] = 'search_salary_setting';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Added Successfully';
            return $data;
        }
    }

    function update_salary_setting($postdata) {

        $data = array();
        $this->db->trans_begin();
        $this->mastermodel->updatemasterdata($postdata['employee_salary_id']);
        $wef_date = $this->mastermodel->convertdateformat($postdata['wef_date']);
        if (isset($postdata['return_ticket'])) {
            $return_ticket = 1;
        } else {
            $return_ticket = 0;
        }
        $tblValues = array(
            'employee_id' => $postdata['employee_id'],
            'wef_date' => $wef_date,
            'basic_salary' => $postdata['basic_salary'],
            'from_ticket' => $postdata['from_ticket'],
            'to_ticket' => $postdata['to_ticket'],
            'return_ticket' => $return_ticket,
            'no_tickets' => $postdata['no_tickets'],
            'payment_method' => $postdata['payment_method']
        );

        $this->db->where('employee_salary_id', $postdata['employee_salary_id']);
        $this->db->update('employee_salary', $tblValues);

        $this->db->where('employee_salary_id', $postdata['employee_salary_id']);
        $this->db->delete('employee_salary_medical');
        $i = 1;
        while (isset($postdata['type' . $i])) {
            if ($postdata['type' . $i] != "") {
                $tblValues = array(
                    'employee_salary_id' => $postdata['employee_salary_id'],
                    'type' => $postdata['type' . $i],
                    'company' => $postdata['company' . $i],
                    'policy' => $postdata['policy' . $i],
                    'plan' => $postdata['plan' . $i],
                    'sum' => $postdata['sum' . $i]);
                $this->db->insert('employee_salary_medical', $tblValues);
            }
            $i++;
        }


        $i = 1;

        $this->db->where('employee_salary_id', $postdata['employee_salary_id']);
        $this->db->delete('employee_salary_allowdeduc');
        while (isset($postdata['amount_' . $i])) {
            $tblValues = array(
                'employee_salary_id' => $postdata['employee_salary_id'],
                'allowdeduc_id' => $postdata['allowdeduc_id_' . $i],
                'amount' => $postdata['amount_' . $i]);
            $this->db->insert('employee_salary_allowdeduc', $tblValues);
            $i++;
        }
        $data['resfunction'] = 'search_salary_setting';
        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Updating Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Record Updated Successfully';
            return $data;
        }
    }

    function search_salary_payment($pagenum) {
        $data = array();
        $data['results'] = '';
        return $data;
    }

    function getemployeelist() {
        $data = array();
        $this->db->select('*');
        $this->db->from('employee');
        $this->db->join('master', 'master_id=employee_id');
        $this->db->join('department', 'department.department_id=employee.employee_department_id');
        $this->db->join('designation', 'designation.designation_id=employee.employee_designation_id');
        $this->db->order_by('employee_visa_expiry_date', 'asc');
        $Q = $this->db->get();
        if ($Q->num_rows() > 0) {
            foreach ($Q->result_array() as $row) {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function count_data_salary($table, $id, $date) {
        $date = $this->mastermodel->convdatformat($date);
        $query = "select employee_salary_id from $table where employee_id = '$id' and wef_date <= '$date' order by wef_date DESC limit 1";
        $res = mysql_query($query);
        $num = mysql_num_rows($res);
        $data['num'] = $num;
        return $num;
    }

    function check_salary_month($id, $date) {
        $date = $this->mastermodel->convdatformat($date);
        $this->db->select('employee_salary_slip_id');
        $this->db->from('employee_salary_slip');
        $this->db->where('employee_id', $id);
        $where = "month(salary_date)=month('$date') and year(salary_date)=year('$date')";
        $this->db->where($where, NULL, FALSE);
        return $this->db->count_all_results();
    }

    function get_employee_salary_id($employee_id, $date) {
        $data = array();

        $date = $this->mastermodel->convertdateformat($date);
        $sql = "SELECT tt.*
                FROM employee_salary tt
                INNER JOIN
                (SELECT employee_id, MAX(wef_date) AS wefdate
                FROM employee_salary
                GROUP BY employee_id) groupedtt ON tt.employee_id = groupedtt.employee_id AND tt.wef_date = groupedtt.wefdate
                where tt.employee_id = '$employee_id' AND wefdate <= '$date'";
        $Q = $this->db->query($sql);
        $result = $Q->row();

        if (!empty($result))
            return $result->employee_salary_id;
        else
            return '';
    }

    function insert_single_salary_payment($postdata) {
        $data = array();
        $this->db->trans_begin();
        $data['resfunction'] = 'search_salary_payment';
        $masterid = $this->mastermodel->insertmasterdata();
        $salary_date = $this->mastermodel->convertdateformat($postdata['salary_date']);
        $pay_date = date('Y-m-d');
        $netpayment = $postdata['basic_salary'] + $postdata['allowance'] - $postdata['deduction'];
        $tblValues = array(
            'employee_salary_slip_id' => $masterid,
            'employee_id' => $postdata['employee_id'],
            'salary_date' => $salary_date,
            'pay_date' => $pay_date,
            'basic_salary' => $postdata['basic_salary'],
            'allowance_amount' => $postdata['allowance'],
            'deduction_amount' => $postdata['deduction'],
            'net_payment' => $netpayment,
            'commission_amount' => $postdata['commission'],
            'payment_method' => $postdata['employee_sal_payment_mode'],
            'paid_amount' => $postdata['payamount']
        );
        $this->db->insert('employee_salary_slip', $tblValues);


        $i = 1;
        while (isset($postdata['amount_' . $i])) {
            $tblValues = array(
                'employee_salary_slip_id' => $masterid,
                'allowdeduc_id' => $postdata['allowdeduc_id_' . $i],
                'amount' => $postdata['amount_' . $i]);
            $this->db->insert('employee_salary_slip_allowdeduc', $tblValues);
            $i++;
        }


        if ($this->db->trans_status() === FALSE) {
            $this->db->trans_rollback();
            $data['res'] = 0;
            $data['msg'] = 'Error On Adding Record';
            return $data;
        } else {
            $this->db->trans_commit();
            $data['res'] = 1;
            $data['msg'] = 'Employee Salary Processed successfully';
            return $data;
        }
    }

    function insert_multiple_salary_payment($postdata) {
        $data = array();
        $this->db->trans_begin();
        $salary_date = $this->mastermodel->convertdateformat($postdata['salary_date']);
        $pay_date = date('Y-m-d');
        if (isset($postdata['salempdet'])) {
//echo sizeof($postdata['salempdet']);die();
            for ($k = 0; $k < sizeof($postdata['salempdet']); $k++) {
                if (isset($postdata['salempdet'][$k])) {
                    $masterid = $this->mastermodel->insertmasterdata();
                    $employee_id = $postdata['salempdet'][$k];
                    $salary_payment = $this->get_employee_salary_data('employee_salary', $employee_id, $postdata['salary_date']);
                    $pay_date = date('Y-m-d');
                    $basic_salary = $salary_payment->basic_salary;
                    $employee_salary_id = $salary_payment->employee_salary_id;
                    $tblValues = array(
                        'employee_salary_slip_id' => $masterid,
                        'employee_id' => $employee_id,
                        'salary_date' => $salary_date,
                        'pay_date' => $pay_date,
                        'basic_salary' => $basic_salary
                    );
                    $this->db->insert('employee_salary_slip', $tblValues);

                    $allowance = 0;
                    $deduction = 0;
                    $commission = 0;
                    if (isset($postdata['employee_id_' . $employee_id])) {

                        $allowance = $postdata['allowance_' . $employee_id];
                        $deduction = $postdata['deduction_' . $employee_id];
                        $commission = $postdata['commission_' . $employee_id];
                        $netpayment = $basic_salary + $allowance - $deduction;

                        $i = 1;
                        while (isset($postdata['amount_' . $employee_id . '_' . $i])) {
                            $tblValues = array(
                                'employee_salary_slip_id' => $masterid,
                                'allowdeduc_id' => $postdata['allowdeduc_id_' . $employee_id . '_' . $i],
                                'amount' => $postdata['amount_' . $employee_id . '_' . $i]);
                            $this->db->insert('employee_salary_slip_allowdeduc', $tblValues);
                            $i++;
                        }
                        $tblValues = array(                          
                            'allowance_amount' => $allowance,
                            'deduction_amount' => $deduction,
                            'net_payment' => $netpayment,
                            'commission_amount' => $commission,
                            'paid_amount' => $postdata['payamount_' . $employee_id]
                        );
                    } else {
                        $allowdeduc_details = $this->mastermodel->get_data('employee_salary_allowdeduc', $employee_salary_id, 'employee_salary_id');
                        foreach ($allowdeduc_details as $list) {
                            $tblValues = array(
                                'employee_salary_slip_id' => $masterid,
                                'allowdeduc_id' => $list['allowdeduc_id'],
                                'amount' => $list['amount']);
                            $res = $this->db->insert('employee_salary_slip_allowdeduc', $tblValues);
                            $allowdeductype = $this->mastermodel->get_data_srow('allowdeduc', $list['allowdeduc_id'], 'allowdeduc_id');
                            if ($allowdeductype->allowdeduc_type == 1) {  //allowance
                                if ($allowdeductype->allowdeduc_mode == 1) {
                                    $sf = 1;
                                    $amount = $list['amount'] * $sf;
                                    $asubtotal = $amount;
                                } else {
                                    $sf = 0.01;
                                    $amount = $list['amount'] * $sf;
                                    $asubtotal = $basic_salary * $amount;
                                }
                                $allowance+=$asubtotal;
                            } else {
                                if ($allowdeductype->allowdeduc_mode == 1) {
                                    $sf = 1;
                                    $amount = $list['amount'] * $sf;
                                    $dsubtotal = $amount;
                                } else {

                                    $sf = 0.01;
                                    $amount = $list['amount'] * $sf;
                                    $dsubtotal = $basic_salary * $amount;
                                }
                                $deduction+=$dsubtotal;
                            }
                        }
                        $netpayment = $basic_salary + $allowance - $deduction;
                        $tblValues = array(
                            'allowance_amount' => $allowance, 
                            'deduction_amount' => $deduction,
                            'commission_amount' => 0,
                            'net_payment' => $netpayment, 'paid_amount' => $netpayment);
                    }
                    $this->db->where('employee_salary_slip_id', $masterid);
                    $res = $this->db->update('employee_salary_slip', $tblValues);
                }
            }
            $data['resfunction'] = 'search_salary_payment';

            if ($this->db->trans_status() === FALSE) {
                $this->db->trans_rollback();
                $data['res'] = 0;
                $data['msg'] = 'Error On Adding Record';
                return $data;
            } else {
                $this->db->trans_commit();
                $data['res'] = 1;
                $data['msg'] = 'Salary processed succesfully';
                return $data;
            }
        } else {
            $data['resfunction'] = 'search_salary_payment';
            $this->db->trans_rollback();
            $data['res'] = 1;
            $data['msg'] = 'No employee selected';
            return $data;
        }
    }

    function get_employee_salary_data($table, $id, $date) {
        $date = $this->mastermodel->convdatformat($date);
        $data = array();
        $sql = "select * from $table where employee_id = '$id' and wef_date <= '$date' order by wef_date DESC limit 1";
        $Q = $this->db->query($sql);
        $row = $Q->row();
        return $row;
    }

    function load_employee_details($id) {
        $employee_id = $this->mastermodel->get_single_field_value('employee', 'employee_id', 'employee_id', $id);
        $data['emp'] = $this->mastermodel->get_data_srow('employee', $employee_id, 'employee_id');
        $data['designation'] = $this->mastermodel->get_single_field_value('designation', 'designation_name', 'designation_id', $data['emp']->employee_designation_id);
        $data['department'] = $this->mastermodel->get_single_field_value('department', 'department_name', 'department_id', $data['emp']->employee_department_id);
        $this->load->view('hr/employee_details', $data);
    }

    function search_payslip($pagenum) {
        $data = array();
        $data['startpage'] = '';
        $data['endpage'] = '';
        $data['count'] = '';
        $data['results'] = '';
        return $data;
    }

    function search_final_settlement($pagenum) {
        $data = array();
        $data['startpage'] = '';
        $data['endpage'] = '';
        $data['count'] = '';
        $data['results'] = '';
        return $data;
    }

    function loademployeesalary($post, $date) {
        $data = array();
        $salary_date = $this->mastermodel->convdatformat($date);
        $this->db->select('employee_salary_slip.employee_salary_slip_id,employee_salary_slip.salary_date,employee_salary_slip.employee_id,employee.employee_no,employee.employee_name');
        $this->db->from('employee_salary_slip');
        $this->db->join('master', 'master_id=employee_id');
        $this->db->join('employee', 'employee.employee_id=employee_salary_slip.employee_id');
        $this->db->where("month(salary_date)=month('$salary_date')and year(salary_date)=year('$salary_date') and unpost='$post'");

        $this->db->order_by('employee_salary_slip.employee_id', 'desc');
        $res = $this->db->get();


        foreach ($res->result_array() as $row) {
            $data[] = $row;
        }
        return $data;
    }

    function loadunpostedsalary($sal_id) {
        $this->db->select('*');
        $this->db->from('employee_salary_slip');
        $this->db->join('employee', 'employee.employee_id=employee_salary_slip.employee_id');
        $this->db->join('department', 'department.department_id=employee.employee_department_id');
        $this->db->join('designation', 'designation.designation_id=employee.employee_designation_id');
        $this->db->where('employee_salary_slip_id', $sal_id);
        $this->db->where('unpost', 1);
        $Q = $this->db->get();

        return $Q->row();
    }

    function loadpostedsalary($sal_id) {
        $this->db->select('*');
        $this->db->from('employee_salary_slip');
        $this->db->join('employee', 'employee.employee_id=employee_salary_slip.employee_id');
        $this->db->join('department', 'department.department_id=employee.employee_department_id');
        $this->db->join('designation', 'designation.designation_id=employee.employee_designation_id');
        $this->db->where('employee_salary_slip_id', $sal_id);
        $this->db->where('unpost', 0);
        $Q = $this->db->get();

        return $Q->row();
    }

    function insert_multiple_posted_salary_payment($postdata) {
        $data = array();
        $data['resfunction'] = 'search_payslip';
        $fisc_year_id = $this->accountingmodel->getfiscalyearid();
        $default_currency = $this->accountingmodel->getcurrency();
        $sub_accounts = $this->mastermodel->get_srow('finance_sub_account_settings', 'sub_account_settings_id!=');
        if ($fisc_year_id != 0 && $default_currency != 0) {
            $this->db->trans_begin();
            $memo = $postdata['memo'];
            $bankaccount = $postdata['bank_account_code'];
            $sal_date = $this->mastermodel->convertdateformat($postdata['wef_date']);
            $monthName = date("F", strtotime($sal_date));
            $year = date("Y", strtotime($sal_date));

            if (isset($postdata['salempdet'])) {

                for ($i = 0; $i < sizeof($postdata['salempdet']); $i++) {
                    if (isset($postdata['salempdet'][$i])) {
                        $salid = $postdata['salempdet'][$i];

                        $employee_sal = $this->mastermodel->get_data_srow('employee_salary_slip', $salid, 'employee_salary_slip_id');
                        $basic_salary = $employee_sal->basic_salary;
                        $emp_id = $employee_sal->employee_id;
                        $employee_details = $this->mastermodel->get_data_srow('employee', $emp_id, 'employee_id');
                        $employee_name = $employee_details->employee_name;
                        $paydate = $employee_sal->pay_date;
                        $salary_date = $employee_sal->salary_date;
                        $monthName = '';

                        $transaction_id = 3; /* jv */
                        $payment_type = 0;
                        $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type);

                        $journalid_jv = $this->mastermodel->insertmasterdata();
                        $journal_date = $employee_sal->pay_date;

                        /* Basic Salary is debited */
                        $sal_acc_id = $sub_accounts->salary;
                        $sal_acc = $this->mastermodel->get_data_srow('finance_chart_master', $sal_acc_id, 'chart_master_id');
                        $sal_acc_code = $sal_acc->chart_account_code;
                        $description = "Salary slip of $employee_name ( $employee_details->employee_no ) For the month $monthName  $year    from Account : $sal_acc->chart_account_name ( $sal_acc_code )";

                        $tblValues = array(
                            'journal_id' => $journalid_jv,
                            'journal_date' => $journal_date,
                            'description' => $description,
                            'reference' => $reference,
                            'currency_id' => $default_currency,
                            'payment_type_id' => $payment_type,
                            'transaction_id' => $transaction_id,
                        );
                        $this->db->insert('finance_journal_refs', $tblValues);

                        $tblValues = array(
                            'journal_id' => $journalid_jv,
                            'chart_account_code' => $sal_acc_code,
                            'debit' => $basic_salary,
                            'credit' => 0,
                            'description' => "Basic salary of $employee_name ( $employee_details->employee_no ) For the month $monthName  $year    from Account : $sal_acc->chart_account_name ( $sal_acc_code )",
                            'fiscal_year_id' => $fisc_year_id
                        );
                        $this->db->insert('finance_journal', $tblValues);


                        $tblValues = array(
                            'journal_id' => $journalid_jv,
                            'param_id' => $salid,
                            'refs_type' => "Salary slip of $employee_name ( $employee_details->employee_no ) ",
                            'param_table' => 'employee_salary_slip'
                        );
                        $this->db->insert('finance_refs', $tblValues);

                        /* Allowence and deduction */
                        $allowdeduc_details = $this->mastermodel->get_data('employee_salary_slip_allowdeduc', $salid, 'employee_salary_slip_id');
                        $allowance = 0;
                        $deduction = 0;
                        foreach ($allowdeduc_details as $list) {
                            $allowdeductype = $this->mastermodel->get_data_srow('allowdeduc', $list['allowdeduc_id'], 'allowdeduc_id');

                            if ($allowdeductype->allowdeduc_mode == 1) {
                                $sf = 1;
                                $amount = $list['amount'] * $sf;
                                $asubtotal = $amount;
                            } else {
                                $sf = 0.01;
                                $amount = $list['amount'] * $sf;
                                $asubtotal = $basic_salary * $amount;
                            }

                            if ($allowdeductype->allowdeduc_type == 1) {  //allowance                                
                                $allowance+=$asubtotal;
                                $debit = $asubtotal;
                                $credit = 0;
                                $description = "Allowance ( $allowdeductype->allowdeduc_name) for  $employee_name ( $employee_details->employee_no )  For the month $monthName  $year   From  Account $allowdeductype->chart_account_code ";
                            } else { //deduction
                                $deduction+=$asubtotal;
                                $debit = 0;
                                $credit = $asubtotal;
                                $description = "Deduction ( $allowdeductype->allowdeduc_name) for  $employee_name ( $employee_details->employee_no )  For the month $monthName  $year   From  Account $allowdeductype->chart_account_code ";
                            }

                            /* transaction here */
                            if ($list['amount'] > 0) {
                                $tblValues = array(
                                    'journal_id' => $journalid_jv,
                                    'chart_account_code' => $allowdeductype->chart_account_code,
                                    'debit' => $debit,
                                    'credit' => $credit,
                                    'description' => $description,
                                    'fiscal_year_id' => $fisc_year_id
                                );
                                $this->db->insert('finance_journal', $tblValues);
                            }
                        }
//                        $net_deduction = $deduction ;
//                        $lop = 0;

                        $net_amount = $basic_salary + $allowance - $deduction;
                        $paid_amount = $net_amount;


                        $tblValues = array(
                            'unpost' => 0,
                            'paid_amount' => $paid_amount,
                            'deduction_amount' => $deduction
                        );
                        $this->db->where('employee_salary_slip_id', $salid);
                        $this->db->update('employee_salary_slip', $tblValues);


                        /* Employeee Account */
                        $emp = $this->mastermodel->get_data_srow('employee', $emp_id, 'employee_id');
                        $emp_acc = $emp->employee_no;
                        $parent = $this->accountingmodel->get_account_settings('employee', 'finance_sub_account_settings');
                        if ($this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $emp_acc) == 0) {
                            $tblValues = array(
                                'chart_account_code' => $emp->employee_no,
                                'chart_account_name' => $emp->employee_name,
                                'chart_type_id' => 3,
                                'parent' => $parent,
                                'inactive' => 0);
                            $this->db->insert('finance_chart_master', $tblValues);
                        }

                        $tblValues = array(
                            'journal_id' => $journalid_jv,
                            'chart_account_code' => $emp_acc,
                            'debit' => 0,
                            'credit' => $paid_amount,
                            'description' => "Salary payable for $employee_name ( $employee_details->employee_no ) For the month $monthName  $year  ",
                            'fiscal_year_id' => $fisc_year_id
                        );
                        $this->db->insert('finance_journal', $tblValues);


                        /* Salary payment */
                        $transaction_id = 1; /* pv */
                        $payment_type = 1;
                        $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type);
                        $journalid_pv = $this->mastermodel->insertmasterdata();

                        $description = "Salary received by $employee_name ( $employee_details->employee_no ) For the month $monthName  $year   ";
                        $tblValues = array(
                            'journal_id' => $journalid_pv,
                            'journal_date' => $journal_date,
                            'description' => $description,
                            'reference' => $reference,
                            'currency_id' => $default_currency,
                            'payment_type_id' => $payment_type,
                            'transaction_id' => $transaction_id,
                        );
                        $this->db->insert('finance_journal_refs', $tblValues);

                        $tblValues = array(
                            'journal_id' => $journalid_pv,
                            'chart_account_code' => $emp_acc,
                            'debit' => $paid_amount,
                            'credit' => 0,
                            'description' => "Salary received by $employee_name ( $employee_details->employee_no ) For the month $monthName  $year    From the Account $emp_acc",
                            'fiscal_year_id' => $fisc_year_id
                        );
                        $this->db->insert('finance_journal', $tblValues);


                        $tblValues = array(
                            'journal_id' => $journalid_pv,
                            'chart_account_code' => $postdata['bank_account_code'],
                            'debit' => 0,
                            'credit' => $paid_amount,
                            'description' => "Salary Paid to $employee_name ( $employee_details->employee_no ) For the month $monthName  $year    From the Account " . $postdata['bank_account_code'],
                            'fiscal_year_id' => $fisc_year_id
                        );
                        $this->db->insert('finance_journal', $tblValues);

                        $tblValues = array(
                            'journal_id' => $journalid_pv,
                            'param_id' => $salid,
                            'refs_type' => "Salary Payment of $employee_name ( $employee_details->employee_no ) ",
                            'param_table' => 'employee_salary_slip'
                        );
                        $this->db->insert('finance_refs', $tblValues);
                    }
                }
            }

            if ($this->db->trans_status() === FALSE) {
                $this->db->trans_rollback();
                $data['res'] = 0;
                $data['msg'] = 'Error On Adding Record';
                return $data;
            } else {
                $this->db->trans_commit();
                $data['res'] = 1;
                $data['msg'] = 'Employee Salary Processed successfully';
                return $data;
            }
        } else {
            $data['res'] = 0;
            if ($fisc_year_id == 0)
                $data['msg'] = 'Fiscal Year Not Set.';
            else if ($default_currency == 0)
                $data['msg'] = 'Default Currency Not Set.';
            else
                $data['msg'] = 'Fiscal Year and Default Currency Not Set.';

            return $data;
        }
    }

    function insert_single_posted_salary_payment($postdata) {
        $data = array();
        $data['resfunction'] = 'search_payslip';
        $fisc_year_id = $this->accountingmodel->getfiscalyearid();
        $default_currency = $this->accountingmodel->getcurrency();
        $sub_accounts = $this->mastermodel->get_data_srow('finance_sub_account_settings', '1', 'sub_account_settings_id');
        $payment = $postdata['payamount'];
        $sal_date = $this->mastermodel->convertdateformat($postdata['wef_date']);
        $monthName = date("F", strtotime($sal_date));
        $year = date("Y", strtotime($sal_date));

        if ($fisc_year_id != 0 && $default_currency != 0) {

            $this->db->trans_begin();
            $this->db->where('employee_salary_slip_id', $postdata['employee_salary_slip_id']);
            $this->db->delete('employee_salary_slip');
            $this->db->where('employee_salary_slip_id', $postdata['employee_salary_slip_id']);
            $this->db->delete('employee_salary_slip_allowdeduc');

            $transaction_id = 3; /* jv */
            $payment_type = 0;
            $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type);

            $salary_slip_id = $this->mastermodel->insertmasterdata();
            $salary_date = $this->mastermodel->convertdateformat($postdata['salary_date']);
            $pay_date = date('Y-m-d');
            $monthName = '';

            $netpayment = $postdata['basic_salary'] + $postdata['allowance'] - $postdata['deduction'];
            $paid_amount = $postdata['payamount'];

            $employee_id = $postdata['employee_id'];
            $employee_details = $this->mastermodel->get_data_srow('employee', $employee_id, 'employee_id');
            $employee_name = $employee_details->employee_name;

            $tblValues = array(
                'employee_salary_slip_id' => $salary_slip_id,
                'employee_id' => $postdata['employee_id'],
                'salary_date' => $salary_date,
                'pay_date' => $pay_date,
                'basic_salary' => $postdata['basic_salary'],
                'allowance_amount' => $postdata['allowance'],
                'deduction_amount' => $postdata['deduction'],
                'net_payment' => $netpayment,
                'commission_amount' => $postdata['commission'],
                'paid_amount' => $paid_amount,
                'unpost' => 0
            );
            $this->db->insert('employee_salary_slip', $tblValues);

            $journalid_jv = $this->mastermodel->insertmasterdata();
            $journal_date = $pay_date;


            /* Basic Salary is debited */
            $sal_acc_id = $sub_accounts->salary;
            $sal_acc = $this->mastermodel->get_data_srow('finance_chart_master', $sal_acc_id, 'chart_master_id');
            $sal_acc_code = $sal_acc->chart_account_code;
            $description = "Salary slip of $employee_name ( $employee_details->employee_no ) For the month $monthName  $year  from Account :$sal_acc->chart_account_name  ( $sal_acc_code )";

            $tblValues = array(
                'journal_id' => $journalid_jv,
                'journal_date' => $journal_date,
                'description' => $description,
                'reference' => $reference,
                'currency_id' => $default_currency,
                'payment_type_id' => $payment_type,
                'transaction_id' => $transaction_id,
            );
            $this->db->insert('finance_journal_refs', $tblValues);

            $tblValues = array(
                'journal_id' => $journalid_jv,
                'chart_account_code' => $sal_acc_code,
                'debit' => $postdata['basic_salary'],
                'credit' => 0,
                'description' => "Basic salary of $employee_name ( $employee_details->employee_no )  For the month $monthName  $year   from Account :$sal_acc->chart_account_name  ( $sal_acc_code )",
                'fiscal_year_id' => $fisc_year_id
            );
            $this->db->insert('finance_journal', $tblValues);

            $tblValues = array(
                'journal_id' => $journalid_jv,
                'param_id' => $salary_slip_id,
                'refs_type' => "Salary slip of $employee_name ( $employee_details->employee_no ) ",
                'param_table' => 'employee_salary_slip'
            );
            $this->db->insert('finance_refs', $tblValues);

            /* Allowence and deduction */
            $i = 1;
            while (isset($postdata['amount_' . $i])) {
                $allowaccount = $this->mastermodel->get_data_srow('allowdeduc', $postdata['allowdeduc_id_' . $i], 'allowdeduc_id');
                $tblValues = array(
                    'employee_salary_slip_id' => $salary_slip_id,
                    'allowdeduc_id' => $postdata['allowdeduc_id_' . $i],
                    'amount' => $postdata['amount_' . $i]);
                $this->db->insert('employee_salary_slip_allowdeduc', $tblValues);

                $allowded_id = mysql_insert_id();

                if ($allowaccount->allowdeduc_type == 1) {

                    $debit = $postdata['alltotal_' . $i];
                    $credit = 0;
                    $description = "Allowance ($allowaccount->allowdeduc_name) for  $employee_name ( $employee_details->employee_no )  For the month $monthName  $year   From  Account $allowaccount->chart_account_code ";
                } else {
                    $debit = 0;
                    $credit = $postdata['alltotal_' . $i];
                    $description = "Deduction ($allowaccount->allowdeduc_name) for  $employee_name ( $employee_details->employee_no )  For the month $monthName  $year   from Account $allowaccount->chart_account_code ";
                }

                if ($postdata['alltotal_' . $i] > 0) {
                    $tblValues = array(
                        'journal_id' => $journalid_jv,
                        'chart_account_code' => $allowaccount->chart_account_code,
                        'debit' => $debit,
                        'credit' => $credit,
                        'description' => $description,
                        'fiscal_year_id' => $fisc_year_id
                    );
                    $this->db->insert('finance_journal', $tblValues);
                }
                $i++;
            }

            /* Employeee Account */
            $emp = $this->mastermodel->get_data_srow('employee', $postdata['employee_id'], 'employee_id');
            $emp_acc = $emp->employee_no;
            $parent = $this->accountingmodel->get_account_settings('employee', 'finance_sub_account_settings');
            if ($this->mastermodel->get_num_rows('finance_chart_master', 'chart_account_code', $emp_acc) == 0) {
                $tblValues = array(
                    'chart_account_code' => $emp->employee_no,
                    'chart_account_name' => $emp->employee_name,
                    'chart_account_type' => 3,
                    'parent' => $parent,
                    'inactive' => 0);
                $this->db->insert('chart_master', $tblValues);
            }


            $tblValues = array(
                'journal_id' => $journalid_jv,
                'chart_account_code' => $emp_acc,
                'debit' => 0,
                'credit' => $paid_amount,
                'description' => "Salary payable of $employee_name ( $employee_details->employee_no )  For the month $monthName  $year    From the Account : $emp_acc",
                'fiscal_year_id' => $fisc_year_id
            );
            $this->db->insert('finance_journal', $tblValues);


            /* Salary payment */
            $transaction_id = 1; /* PV */
            $payment_type = $postdata['payment_type_id'];
            $reference = $this->accountingmodel->get_transaction_code($transaction_id, $payment_type);
            $journalid_pv = $this->mastermodel->insertmasterdata();

            $description = "Salary received by $employee_name ( $employee_details->employee_no ) For the month $monthName  $year   ";
            $tblValues = array(
                'journal_id' => $journalid_pv,
                'journal_date' => $journal_date,
                'description' => $description,
                'reference' => $reference,
                'currency_id' => $default_currency,
                'payment_type_id' => $payment_type,
                'transaction_id' => $transaction_id,
            );
            $this->db->insert('finance_journal_refs', $tblValues);


            if ($postdata['payment_type_id'] == 2) {
                $tblValues = array(
                    'journal_id' => $journalid_pv,
                    'cheque_date' => $this->mastermodel->convertdateformat($postdata['cheque_date']),
                    'cheque_no ' => $postdata['cheque_no'],
                    'chart_account_code' => $postdata['bank_account_code'],
                    'cheque_info' => $postdata['cheque_info']
                );
                $this->db->insert('finance_cheque_info', $tblValues);
            } else if ($postdata['payment_type_id'] == 3) {
                $tblValues = array(
                    'journal_id' => $journalid_pv,
                    'wire_info' => $postdata['wire_info'],
                );
                $this->db->insert('finance_wire_info', $tblValues);
            }
            $tblValues = array(
                'journal_id' => $journalid_pv,
                'chart_account_code' => $emp_acc,
                'debit' => $paid_amount,
                'credit' => 0,
                'description' => "Salary received by $employee_name ( $employee_details->employee_no ) For the month $monthName  $year    From the Account $emp_acc",
                'fiscal_year_id' => $fisc_year_id
            );
            $this->db->insert('finance_journal', $tblValues);


            $tblValues = array(
                'journal_id' => $journalid_pv,
                'chart_account_code' => $postdata['bank_account_code'],
                'debit' => 0,
                'credit' => $paid_amount,
                'description' => "Salary Paid to $employee_name ( $employee_details->employee_no ) For the month $monthName  $year    From the Account  " . $postdata['bank_account_code'],
                'fiscal_year_id' => $fisc_year_id
            );
            $this->db->insert('finance_journal', $tblValues);

            $tblValues = array(
                'journal_id' => $journalid_pv,
                'param_id' => $salary_slip_id,
                'refs_type' => "Salary Payment of $employee_name ( $employee_details->employee_no ) For the month $monthName  $year ",
                'param_table' => 'employee_salary_slip'
            );
            $this->db->insert('finance_refs', $tblValues);

            if ($this->db->trans_status() === FALSE) {
                $this->db->trans_rollback();
                $data['res'] = 0;
                $data['msg'] = 'Error On Adding Record';
                return $data;
            } else {
                $this->db->trans_commit();
                $data['res'] = 1;
                $data['msg'] = 'Employee Salary Processed successfully';
                return $data;
            }
        } else {
            $data['res'] = 0;
            if ($fisc_year_id == 0)
                $data['msg'] = 'Fiscal Year Not Set.';
            else if ($default_currency == 0)
                $data['msg'] = 'Default Currency Not Set.';
            else
                $data['msg'] = 'Fiscal Year and Default Currency Not Set.';

            return $data;
        }
    }

    function getreferencecode($trans) {
        $code = $this->mastermodel->getSingleFieldValue('finance_transaction_code', 'transaction_code', 'transaction_id', $trans);
        if ($code == '')
            return 0;
        else {
            $num = $this->mastermodel->get_num_rows('refs', 'ref_transaction_type_id', $trans);
            $num++;
            return $code . '/' . date("Y") . '/' . $num;
        }
    }

    function getunpaidemployees($month, $year) {
        $data = array();
        $this->db->where("employee.employee_id NOT IN (SELECT `employee_id` FROM `employee_salary_slip` where month(salary_date)='$month' and year(salary_date)='$year')", NULL, FALSE);
        $Q = $this->db->get('employee');
        if ($Q->num_rows() > 0) {
            foreach ($Q->result_array() as $row) {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function getstfleavapply($id) {

        $data = array();
        $year = date("Y");
        $sql = "select * from leave_application 
        join leave_type on leave_type.leave_type_id =leave_application.leave_type_id where employee_id = '$id' and (from_date like '" . $year . "%')";
        $Q = $this->db->query($sql);

        if ($Q->num_rows() > 0) {
            foreach ($Q->result_array() as $row) {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_leave_balance($staffid, $type, $year) {
        $balleav = 0;
        $sql = "select datediff(to_date,from_date) as leavbal from leave_application
        where  leave_type_id = $type and leave_status = 'Approved' and employee_id = '$staffid' and (from_date like '" . $year . "%')";
        $Q = $this->db->query($sql);
        $rows = $Q->result_array();
        foreach ($rows as $rw) {
            $balleav+=$rw['leavbal'];
        }
        return $balleav;
    }

}

?>

bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped)
Email: contact@elmoujehidin.net