MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.53
Web Server : LiteSpeed
System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64
User : celkcksm ( 1031)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, popen, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/celkcksm/ecampus.ncriptech.com/application/controllers/admin/hrm/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/ecampus.ncriptech.com/application/controllers/admin/hrm/Settings.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');


/**
 * 
 */
class Settings  extends BaseAdminController
{

    protected $inst_id='';
    protected $inst_parent_id='';
    protected $inst_code='';
    protected $inst_type='';

    protected $payschedule_settings='';
    protected $attendance_settings='';

    protected $hrms_access='';

    function __construct()
    {
        parent::__construct();

        $institute_data=check_institute($this->data['userdata']);
        $this->inst_id=$institute_data['institute_id'];
        $this->inst_parent_id=$institute_data['inst_parent_id'];
        $this->inst_code=$institute_data['inst_code'];
        $this->inst_type=$institute_data['inst_type'];

        $this->hrms_access=$institute_data['hrms_access'];

        //$this->load->model('hrm/employee_model','em');
        //$this->load->model('hrm/roles_model','hrmrm');
        $this->load->model(array('hrm/employee_model'=>'em','hrm/leaves_model'=>'lvm','hrm/roles_model'=>'hrmrm','hrm/payroll_model'=>'hrmpm','hrm/hrmsettings_model'=>'hrmsm'));

        $hrm_settings=$this->hrmsm->get_hrm_settings(array('hrm_settings_inst_id'=>$this->inst_id,'hrm_settings_inst_type'=>$this->inst_type,'hrm_settings_type'=>'pay_schedule_settings'));

        $hrm_att_settings=$this->hrmsm->get_hrm_settings(array('hrm_settings_inst_id'=>$this->inst_id,'hrm_settings_inst_type'=>$this->inst_type,'hrm_settings_type'=>'attendance_settngs'));

        if(!empty($hrm_settings)){
            $this->attendance_settings=unserialize($hrm_att_settings->hrm_settings_value);
            $this->payschedule_settings=unserialize($hrm_settings->hrm_settings_value);


            //print_obj($this->attendance_settings);die;
        }
    }


    public function index(){
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='HRM Settings';

            if($this->hrms_access=='yes'){  

                $this->data['configurations']=$this->config->item('hrmodules_array');



                $view='hrm/vw_hrm_settings';
            }else{
                $view='hrm/vw_permission_denied';
            }

            $this->theme->title($this->data['page_title'])->load($view, $this->data);
                
        }else{

            redirect($this->data['base_url']);
        }
    }


    //Salary Components

    public function indexSalaryComponents(){
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='HRM Salary Components Settings';

            if($this->hrms_access=='yes'){  

                $system_salary_earnings_components=$this->sm->get_salary_components(array('sal_comp_inst_id'=>$this->inst_id,'sal_comp_inst_type'=>$this->inst_type,'sal_comp_types'=>'earnings'),FALSE);

                //print_obj($system_salary_earnings_components);die;

                $system_salary_deductions_components=$this->sm->get_salary_components(array('sal_comp_inst_id'=>$this->inst_id,'sal_comp_inst_type'=>$this->inst_type,'sal_comp_types'=>'deductions'),FALSE);

                $system_salary_reimbursement_components=$this->sm->get_salary_components(array('sal_comp_inst_id'=>$this->inst_id,'sal_comp_inst_type'=>$this->inst_type,'sal_comp_types'=>'reimbursements'),FALSE);

                $this->data['earning_components']=$system_salary_earnings_components;
                $this->data['deduction_components']=$system_salary_deductions_components;
                $this->data['reimbursement_components']=$system_salary_reimbursement_components;


                $view='hrm/settings/vw_hrm_salary_component_settings';
            }else{
                $view='hrm/vw_permission_denied';
            }

            $this->theme->title($this->data['page_title'])->load($view, $this->data);
                
        }else{

            redirect($this->data['base_url']);
        }
    }


    public function indexSalaryComponentsEdit($component_id){
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='HRM Salary Components Settings';

            if($this->hrms_access=='yes'){
                $component_id=decode_data($component_id);
                $_sys_earn_comp_calc_type_json=array();

                $system_earnings_components=$this->sm->get_salary_components(array('sal_comp_types'=>'earnings','sal_comp_id'=>$component_id,'sal_comp_inst_id'=>$this->inst_id,'sal_comp_inst_type'=>$this->inst_type));

                //print_obj($system_earnings_components);die;


                $sys_earn_comp_calc_type_json=json_decode($system_earnings_components->sal_comp_calculation_types);



                foreach ($sys_earn_comp_calc_type_json as $key => $value) {
                    $_sys_earn_comp_calc_type_json[]=array(
                        $key=>$value,
                        'selected'=>($key==$system_earnings_components->sal_comp_calculation_type_v)?'selected':''
                    );
                }

                // foreach ($_sys_earn_comp_calc_type_json as $key => $value) {
                //     echo $value[$key];
                // }

                // die;

                //print_obj($_sys_earn_comp_calc_type_json);die;

                $this->data['sys_earn_comp_calc_type_json']=$sys_earn_comp_calc_type_json;


                $this->data['component_id']=$component_id;

                $this->data['system_earnings_components']=$system_earnings_components;


                $payroll_settings=array(
                    'earning_settings'=>array(
                        ''
                    )
                );


                $a=array(
                    'fixed_flat_amount'=>'Flat Amount',
                    'fixed_percentage_of_basic'=>'Percentage of Basic'
                );

                //echo json_encode($a);die;



                $view='hrm/settings/vw_hrm_salary_earning_component_settings';
            }else{
                $view='hrm/vw_permission_denied';
            }

            $this->theme->title($this->data['page_title'])->load($view, $this->data);  

        }else{
           redirect($this->data['base_url']);
        }
    }


    public function onUpdateSalaryComponents(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $component_id=post_data('sal_comp_id');
                $component_name=post_data('sal_comp_name');
                $component_name_on_payslip=post_data('sal_comp_name_in_payslip');
                $sal_comp_calc_type=post_data('sal_comp_calc_type');
                $sal_comp_calc_value=post_data('sal_comp_calc_value');
                $sal_comp_status=post_data('sal_comp_status');




                json_headers($return);

            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
    }



    public function indexSalaryTemplates(){
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='HRM Salary Templates';

            if($this->hrms_access=='yes'){ 


                $view='hrm/settings/vw_hrm_salary_template';


                $this->data['configurations']=$this->config->item('hrmodules_array');
            }else{
                $view='hrm/vw_permission_denied';
            }

            $this->theme->title($this->data['page_title'])->load($view, $this->data);

        }else{

            redirect($this->data['base_url']);
        }
    }

    public function indexSalaryTemplatesAddEdit($template_id=null){
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='HRM Salary Templates';

            if($this->hrms_access=='yes'){

                $sal_monthly_ctc=0;
                $sal_annual_ctc=0;

                if(!empty($template_id)){
                    $template_id=decode_data($template_id);

                    $_template_data=$this->hrmsm->get_hrm_salary_template(array('template_id'=>$template_id,'template_inst_id'=>$this->inst_id,'template_inst_type'=>$this->inst_type));

                    $this->data['template_data']=array(
                        'template_id='=>$_template_data->template_id,
                        'template_name'=>$_template_data->template_name,
                        'template_desc'=>$_template_data->template_desc,
                        'template_ctc'=>$_template_data->template_ctc
                    );
                }


                $template_components=$this->sm->get_salary_components(array('sal_comp_inst_type'=>$this->inst_id,'sal_comp_inst_type'=>$this->inst_type,'sal_comp_include_in_template'=>'yes','sal_comp_status'=>'active','sal_comp_types'=>'earnings'),FALSE);

                if(!empty($template_components)){
                    $sal_template_data=array();
                    foreach ($template_components as $key => $value) {
                        if(!empty($template_id)){
                            $sal_template_data=$this->hrmsm->get_hrm_salary_template_data(array('template_data_inst_id'=>$this->inst_id,'template_data_inst_type'=>$this->inst_type,'template_cal_type_id'=>$value->sal_comp_id,'template_data_template_id'=>$template_id));
                        }                        

                        //print_obj($sal_template_data);

                        if(!empty($sal_template_data)){
                            $sal_monthly_ctc+=$sal_template_data->template_monthly_value;
                            $sal_annual_ctc+=$sal_template_data->template_annual_value;
                        }

                        $components[]=array(
                            'content_type_id'=>$value->sal_comp_id,
                            'component_type'=>(!empty($value->sal_comp_desc))?$value->sal_comp_desc:$value->sal_comp_name,
                            'component_value'=>$value->sal_comp_calculation_type_value,
                            'component_type_name'=>$value->sal_comp_name_type,
                            'component_calculation_type'=>$value->sal_comp_calculation_type_v,
                            'component_calculation_type_name'=>$value->sal_comp_calculation_type,
                            'component_mandatory'=>$value->sal_comp_mandatory,
                            'component_editable'=>$value->sal_comp_data_editable,
                            'component_monthly_data'=>(!empty($sal_template_data))?$sal_template_data->template_monthly_value:'system calculated',
                            'component_annual_data'=>(!empty($sal_template_data))?$sal_template_data->template_annual_value:'system calculated',
                            'component_applicable'=>(!empty($sal_template_data))?'yes':'no'
                        );
                    }
                }

                //die;


                $this->data['components']=$components;
                $this->data['component_month_ctc']=number_format($sal_monthly_ctc,2);
                $this->data['component_annual_ctc']=number_format($sal_annual_ctc,2);
                $this->data['template_id']=(!empty($template_id))?encode_data($template_id):null;


                $view='hrm/settings/vw_hrm_salary_template_add_edit';

                $this->data['configurations']=$this->config->item('hrmodules_array');
            }else{
                $view='hrm/vw_permission_denied';
            }

            $this->theme->title($this->data['page_title'])->load($view, $this->data);

        }else{

            redirect($this->data['base_url']);
        }
    }


    public function onCalculateSalTructure(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $annual_ctc=post_data('annual_ctc');

                $component_data=$this->input->post('component_data');

                if(!empty($component_data)){

                    $monthly_ctc=$annual_ctc/12;

                    foreach ($component_data as $key => $value) {
                        $component_type=$key;
                        $sal_comp_settings=$this->sm->get_salary_components(array('sal_comp_inst_id'=>$this->inst_id,'sal_comp_inst_type'=>$this->inst_type,'sal_comp_id'=>$component_type));

                        $format=$sal_comp_settings->sal_comp_calculation_type_v;
                        $editable=$sal_comp_settings->sal_comp_data_editable;
                        $calc_val=$sal_comp_settings->sal_comp_calculation_type_value;

                        if($format=='fixed_percentage_of_basic' && $editable=='no'){

                            $format_month_val=($component_data[1]['mamount']*$calc_val)/100;
                            $format_annual_val=$format_month_val*12;
                        }
                    }
                }


            }else{

            }
        }else{

        }
    }

    public function onCreateSalaryTemplate(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $_template_id=post_data('_template_id');
                $template_name=post_data('template_name');
                $template_desc=post_data('template_description');
                $anual_ctc=post_data('template_annual_ctc');
                $template_status=post_data('template_status');

                $component_data=$this->input->post('component_data');

                $c_data=array();

                //print_obj($c_data);die;

                $monthly_ctc=$anual_ctc/12;

                if(!empty($_template_id)){
                    $template_id=decode_data($_template_id);

                    //echo $template_id;die;

                    $template_data=array(
                        'template_inst_id'=>$this->inst_id,
                        'template_inst_type'=>$this->inst_type,
                        'template_name'=>$template_name,
                        'template_desc'=>$template_desc,
                        'template_ctc'=>$anual_ctc,
                        'template_status'=>$template_status
                    );


                    $updated=$this->hrmsm->update_hrm_salary_templates($template_data,array('template_id'=>$template_id,'template_inst_id'=>$this->inst_id,'template_inst_type'=>$this->inst_type));

                    if($updated){

                        foreach ($component_data as $key => $value) {
                            $component_type=$key;
                            $sal_comp_settings=$this->sm->get_salary_components(array('sal_comp_inst_id'=>$this->inst_id,'sal_comp_inst_type'=>$this->inst_type,'sal_comp_id'=>$component_type));

                            $format=$sal_comp_settings->sal_comp_calculation_type_v;
                            $editable=$sal_comp_settings->sal_comp_data_editable;
                            $calc_val=$sal_comp_settings->sal_comp_calculation_type_value;

                            if($format=='fixed_percentage_of_basic' && $editable=='no'){

                                $format_month_val=($component_data[1]['mamount']*$calc_val)/100;
                                $format_annual_val=$format_month_val*12;
                            }else if($format=='fixed_flat_amount' && $editable=='yes'){
                                $format_month_val=$value['mamount'];
                                $format_annual_val=$format_month_val*12;
                            }

                            $c_data[]=array(
                                'template_data_inst_id'=>$this->inst_id,
                                'template_data_inst_type'=>$this->inst_type,
                                'template_data_template_id'=>$template_id,
                                'template_cal_type_id'=>$key,
                                'template_cal_type_value'=>$sal_comp_settings->sal_comp_calculation_type_value,
                                'template_monthly_value'=>$format_month_val,
                                'template_annual_value'=>$format_annual_val
                            );
                        }

                        //print_obj($c_data);die;


                        if(!empty($c_data)){
                            $deleted=$this->hrmsm->delete_hrm_salary_template_data(array('template_data_inst_id'=>$this->inst_id,
                                'template_data_inst_type'=>$this->inst_type,
                                'template_data_template_id'=>$template_id));

                            if($deleted){
                                $this->hrmsm->store_hrm_salary_template_data($c_data,TRUE);
                                $return['success']='Template has been updated';
                                $return['redirect']=$this->data['base_url'].'/hrm/salarytemplates/add/'.encode_data($template_id);
                            }else{
                                $return['error']='Template has not been updated';
                            }
                            
                        }else{
                            $return['error']='Template data not found to update';
                        }                        

                    }else{
                        $return['error']='Template not updated';
                    }

                }else{

                    $template_data=array(
                        'template_inst_id'=>$this->inst_id,
                        'template_inst_type'=>$this->inst_type,
                        'template_name'=>$template_name,
                        'template_desc'=>$template_desc,
                        'template_ctc'=>$anual_ctc,
                        'template_status'=>$template_status
                    );


                    $template_id=$this->hrmsm->store_hrm_salary_template($template_data);

                    if($template_id){

                        foreach ($component_data as $key => $value) {
                            $component_type=$key;
                            $sal_comp_settings=$this->sm->get_salary_components(array('sal_comp_inst_id'=>$this->inst_id,'sal_comp_inst_type'=>$this->inst_type,'sal_comp_id'=>$component_type));

                            $format=$sal_comp_settings->sal_comp_calculation_type_v;
                            $editable=$sal_comp_settings->sal_comp_data_editable;
                            $calc_val=$sal_comp_settings->sal_comp_calculation_type_value;

                            if($format=='fixed_percentage_of_basic' && $editable=='no'){

                                $format_month_val=($component_data[1]['mamount']*$calc_val)/100;
                                $format_annual_val=$format_month_val*12;
                            }else if($format=='fixed_flat_amount' && $editable=='yes'){
                                $format_month_val=$value['mamount'];
                                $format_annual_val=$format_month_val*12;
                            }

                            $c_data[]=array(
                                'template_data_inst_id'=>$this->inst_id,
                                'template_data_inst_type'=>$this->inst_type,
                                'template_data_template_id'=>$template_id,
                                'template_cal_type_id'=>$key,
                                'template_cal_type_value'=>$sal_comp_settings->sal_comp_calculation_type_value,
                                'template_monthly_value'=>$format_month_val,
                                'template_annual_value'=>$format_annual_val
                            );
                        }

                        if(!empty($c_data)){
                            $inserted=$this->hrmsm->store_hrm_salary_template_data($c_data,TRUE);
                            if($inserted){
                                $return['success']='Template has been created';
                                $return['redirect']=$this->data['base_url'].'/hrm/salarytemplates/add/'.encode_data($template_id);
                            }else{
                                $return['error']='Template data not found to add';
                            }
                        }else{
                            $return['error']='Template data not found to add';
                        }

                    }else{
                        $return['error']='Template not created';
                    }
                }


                json_headers($return);



            }else{
                 redirect($this->data['base_url']);
            }
        }else{
             redirect($this->data['base_url']);
        }
    }


    public function onSearchSalarayTemplatesList(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){
                $param['column_order'] = array(
                    null,
                    'department_name'
                );


                $param['inst_id']=$this->inst_id;
                $param['inst_type']=$this->inst_type;

                $param['column_search'] = array('template_name');
                $param['order'] = array('template_id' => 'ASC');
                $posts=$this->input->post();

                $list = $this->hrmsm->_get_hrm_salary_template($posts,$param,FALSE,FALSE);

                //print_obj($list);die;
                
                
                $data = array();
                $no = isset($posts['start'])?$posts['start']:0;

                $action='';

                foreach ($list as $temp){
                    $no++;

                    $row = array();

                    $row[]  =   $no;
                    $row[]  =   $temp->template_name;
                    $row[]  =   (!empty($temp->template_desc))?$temp->template_desc:'-';

                    if($temp->template_status=='active'){
                        $status='<span class="badge badge-sm badge-success">Active</span>';
                    }else if($temp->template_status=='inactive'){
                        $status='<span class="badge badge-sm badge-danger">Inactive</span>';
                    }

                    $row[]  =   $status;
                    
                    $row[]  =   '
                    <a href="'.$this->data['base_url'].'/hrm/salarytemplates/add/'.encode_data($temp->template_id).'" class="btn btn-xs btn-info"><i class="fa fa-pencil"></i></a>
                    <button type="button" class="btn btn-xs btn-danger btn_dep_del" data-template_id="'.encode_data($temp->template_id).'"><i class="fa fa-trash"></i></button>';

                    $data[] = $row; 
                }

                $output = array(
                    "draw" => isset($posts['draw'])?$posts['draw']:'',
                    "recordsTotal" => $this->hrmsm->_get_hrm_salary_template($posts,$param,TRUE),
                    "recordsFiltered" => $this->hrmsm->_get_hrm_salary_template($posts,$param,TRUE),
                    "data" => $data,
                );
                
                echo json_encode($output);

            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
    }


    //Statutory Components

    public function indexStatutoryComponents(){
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='HRM Statutory Components Settings';

            if($this->hrms_access=='yes'){  

                $this->data['configurations']=$this->config->item('hrmodules_array');

                $view='hrm/settings/vw_hrm_statutory_component_settings';
            }else{
                $view='hrm/vw_permission_denied';
            }

            $this->theme->title($this->data['page_title'])->load($view, $this->data);
                
        }else{

            redirect($this->data['base_url']);
        }
    }



    //Payment Schedule

    public function indexPaySchedules(){
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='HRM Pay Schedule Settings';

            if($this->hrms_access=='yes'){  
                $week_days=array('0'=>'Sunday','1'=>'Monday','2'=>'Tuesday','3'=>'Wednesday','4'=>'Thursday','5'=>'Friday','6'=>'Saturday');

                foreach ($week_days as $key => $value) {
                    $_week_days[]=array(
                        'days_no'=>$key,
                        'days_name'=>$value,
                        'default_selection'=>(empty($this->payschedule_settings) && in_array($key, array(1,2,3,4,5)))?'checked':'',
                        'selected'=>(!empty($this->payschedule_settings) && in_array($key,$this->payschedule_settings['workdays']))?'checked':'',
                    );
                }

                //print_obj($this->payschedule_settings['workdays']);die;

                $this->data['week_days']=$_week_days;

                for ($i=20; $i <=30; $i++) { 
                    $month_days[]=$i;
                }


                $this->data['month_days']=$month_days;

                for ($i=1; $i <=28; $i++) { 
                    $pay_days[]=$i;
                }


                $this->data['pay_days']=$pay_days;

                //print_obj($this->payschedule_settings);die;


                $leave_types=$this->lvm->get_leave_types(array('leave_type_inst_id'=>$this->inst_id,'leave_type_inst_type'=>$this->inst_type),FALSE);


                $this->data['leave_types']=$leave_types;

                $this->data['payschedule_settings']=$this->payschedule_settings;
                $this->data['attendance_settings']=$this->attendance_settings;

                $view='hrm/settings/vw_hrm_payschedule_settings';
            }else{
                $view='hrm/vw_permission_denied';
            }

            $this->theme->title($this->data['page_title'])->load($view, $this->data);
                
        }else{

            redirect($this->data['base_url']);
        }
    }


    public function onUpdatePaySchedule(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $week_days=$this->input->post('week_days');
                $pay_day=post_data('pay_day');
                $pay_days_monthly=post_data('pay_days_monthly');


                if(!empty($week_days)){

                    $counted_week_days=count($week_days);

                    if($counted_week_days>=4){

                        foreach ($week_days as $key => $value) {
                            $workdays[]=$value;
                        }


                        if($pay_day=='selected_working_day'){
                            $monthly_salary_cal_days_setting=post_data('pay_day_selected_value');
                        }else{
                            $monthly_salary_cal_days_setting='calculated';
                        }

                        if($pay_days_monthly=='organisation_days_in_month'){
                            $monthly_pay_days=post_data('pay_day_organisational');
                        }else{
                            $monthly_pay_days='calculated';
                        }

                        if($pay_day=='last_day_of_month'){
                            $_pay_day=post_data('pay_day_selected_value');
                        }else{
                            $_pay_day=$pay_day;
                        }

                        $_data_to_save=array(
                            'workdays'=>$workdays,
                            'monthly_salary_cal_days_setting'=>$monthly_salary_cal_days_setting,
                            'monthly_pay_day'=>$_pay_day,
                            'monthly_pay_days'=>$monthly_pay_days,
                            'monthly_pay_day_fails_day'=>'-1 day',
                        );

                        $data_to_save=serialize($_data_to_save);

                        if(!empty($this->payschedule_settings)){
                            $updated=$this->hrmsm->update_hrm_settings(array('hrm_settings_type'=>'pay_schedule_settings','hrm_settings_inst_id'=>$this->inst_id,'hrm_settings_inst_type'=>$this->inst_type,'hrm_settings_value'=>$data_to_save),array('hrm_settings_type'=>'pay_schedule_settings','hrm_settings_inst_id'=>$this->inst_id,'hrm_settings_inst_type'=>$this->inst_type));
                        }else{
                            $updated=$this->hrmsm->store_hrm_settings(array('hrm_settings_type'=>'pay_schedule_settings','hrm_settings_inst_id'=>$this->inst_id,'hrm_settings_inst_type'=>$this->inst_type,'hrm_settings_value'=>$data_to_save));
                        }

                        $absent_on_leave=post_data('absent_on_leave');
                        $absent_on_late=post_data('absent_on_late');
                        $auto_leave_deduction_from=post_data('auto_leave_deduction_from');
                        $check_in_time=post_data('check_in_time');
                        $check_out_time=post_data('check_out_time');
                        $check_in_grace_time=post_data('check_in_grace_time');

                        $weekdays_arr=array(0,1,2,3,4,5,6);

                        $week_off_days = array_diff($weekdays_arr, $workdays);


                        $att_data_to_save=array(
                            'check_in_time'=>$check_in_time,
                            'check_in_grace_time'=>$check_in_grace_time,
                            'check_out_time'=>$check_out_time,
                            'absent_on_late'=>$absent_on_late,
                            'absent_on_leave'=>$absent_on_leave,
                            'auto_leave_deduction_from'=>$auto_leave_deduction_from,
                            'weekdays'=>$week_off_days
                        );

                        if($updated){

                            $att_data_to_save=serialize($att_data_to_save);

                            if(!empty($this->payschedule_settings)){
                                $this->hrmsm->update_hrm_settings(array('hrm_settings_type'=>'attendance_settngs','hrm_settings_inst_id'=>$this->inst_id,'hrm_settings_inst_type'=>$this->inst_type,'hrm_settings_value'=>$att_data_to_save),array('hrm_settings_type'=>'attendance_settngs','hrm_settings_inst_id'=>$this->inst_id,'hrm_settings_inst_type'=>$this->inst_type));
                            }else{
                                $this->hrmsm->store_hrm_settings(array('hrm_settings_type'=>'attendance_settngs','hrm_settings_inst_id'=>$this->inst_id,'hrm_settings_inst_type'=>$this->inst_type,'hrm_settings_value'=>$att_data_to_save));
                            }

                            $return['success']='Settings updated successfully';
                        }else{
                            $return['error']='Settings not updated';
                        }

                    }else{
                        $return['error']='A minimum of 4 working days has to be present in a work week.';
                    }

                }else{
                    $return['error']='A minimum of 4 working days has to be present in a work week.';
                }

                json_headers($return);

            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
    }



    //Payslip Templates

    public function indexPaySlipTemplates(){
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='HRM Pay Slip Settings';


            if($this->hrms_access=='yes'){


                $payslip_templates=$this->hrmsm->get_hrm_payslip_settings(array('payslip_template_inst_id'=>$this->inst_id,'payslip_template_inst_type'=>$this->inst_type),FALSE);

                if(!empty($payslip_templates)){
                    foreach ($payslip_templates as $key => $value) {
                        $_payslip_templates[]=array(
                            'template_id'=>$value->payslip_template_id,
                            'template_name'=>$value->payslip_template_name,
                            'template_image'=>base_url('uploads/app/'.$value->payslip_template_file),
                            'template_is_default'=>$value->payslip_template_default
                        );
                    }
                }


                $this->data['_payslip_templates']=$_payslip_templates;



                $month = 5; // assume February
                $year = 2023; // assume 2023

                $fiscal_year_start_month = 4; // assume fiscal year starts in April
                $fiscal_year_start_year = ($year - 1);
                $fiscal_year_end_month = 3; // assume fiscal year ends in March

                if ($month >= $fiscal_year_start_month) {
                    $fiscal_year = $year;
                } else {
                    $fiscal_year = $fiscal_year_start_year;
                }


                //echo $fiscal_year;


                //die;


                $view='hrm/settings/vw_hrm_payslip_template_settings';

            }else{
                $view='hrm/vw_permission_denied';
            }

            $this->theme->title($this->data['page_title'])->load($view, $this->data);


        }else{

            redirect($this->data['base_url']);
        }
    }

}

MMCT - 2023