? Fallagassrini

Fallagassrini Bypass Shell

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

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


class Timesheetmodel 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_customer($pagenum)
    {
        
        $data=array();
        $this->db->from('payroll_customer');
        $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_customer');
        $this->db->limit($perpage, $start);
        $this->db->order_by('customer_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_manpower_hiring($pagenum)
    {

        $data=array();
        $this->db->from('payroll_manpower_hiring');
        $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_manpower_hiring');
        $this->db->limit($perpage, $start);
        $this->db->order_by('company_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_purchase_order($pagenum)
    {

        $data=array();
        $this->db->from('payroll_purchase_order');
        $this->db->join('payroll_customer','payroll_customer.customer_id=payroll_purchase_order.customer_id');
        $this->db->join('site','site.site_id=payroll_purchase_order.purchase_order_site_id');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="purchase_order_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=="purchase_order_date")
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('payroll_purchase_order');
        $this->db->join('payroll_customer','payroll_customer.customer_id=payroll_purchase_order.customer_id');
        $this->db->join('site','site.site_id=payroll_purchase_order.purchase_order_site_id');
        $this->db->limit($perpage, $start);
        $this->db->order_by('purchase_order_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }
    
    function search_client_timesheet($pagenum)
    {

        $data=array();
        $this->db->from('payroll_client_timesheet');
        $this->db->join('payroll_purchase_order','payroll_purchase_order.purchase_order_id=payroll_client_timesheet.purchase_order_id');
        $this->db->join('payroll_customer','payroll_customer.customer_id=payroll_purchase_order.customer_id');
        $this->db->join('site','site.site_id=payroll_purchase_order.purchase_order_site_id');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="client_timesheet_received_date" || $searchfield=="client_timesheet_submission_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=="client_timesheet_received_date" || $searchfield=="client_timesheet_submission_date")
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('payroll_client_timesheet');
        $this->db->join('payroll_purchase_order','payroll_purchase_order.purchase_order_id=payroll_client_timesheet.purchase_order_id');
        $this->db->join('payroll_customer','payroll_customer.customer_id=payroll_purchase_order.customer_id');
        $this->db->join('site','site.site_id=payroll_purchase_order.purchase_order_site_id');
        $this->db->limit($perpage, $start);
        $this->db->order_by('client_timesheet_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_manpower_timesheet($pagenum)
    {

        $data=array();
        $this->db->from('payroll_manpower_timesheet');
        $this->db->join('payroll_manpower_hiring','payroll_manpower_hiring.company_id=payroll_manpower_timesheet.manpower_timesheet_company_id');
        $this->db->join('payroll_purchase_order','payroll_purchase_order.purchase_order_id=payroll_manpower_timesheet.purchase_order_id');
        $this->db->join('payroll_customer','payroll_customer.customer_id=payroll_purchase_order.customer_id');
        $this->db->join('site','site.site_id=payroll_purchase_order.purchase_order_site_id');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="manpower_timesheet_issued_date" || $searchfield=="manpower_timesheet_submission_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=="manpower_timesheet_issued_date" || $searchfield=="manpower_timesheet_submission_date")
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('payroll_manpower_timesheet');
        $this->db->join('payroll_manpower_hiring','payroll_manpower_hiring.company_id=payroll_manpower_timesheet.manpower_timesheet_company_id');
        $this->db->join('payroll_purchase_order','payroll_purchase_order.purchase_order_id=payroll_manpower_timesheet.purchase_order_id');
        $this->db->join('payroll_customer','payroll_customer.customer_id=payroll_purchase_order.customer_id');
        $this->db->join('site','site.site_id=payroll_purchase_order.purchase_order_site_id');
        $this->db->limit($perpage, $start);
        $this->db->order_by('manpower_timesheet_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_invoice($pagenum)
    {

        $data=array();
        $this->db->from('payroll_invoice');
        $this->db->join('payroll_purchase_order','payroll_purchase_order.purchase_order_id=payroll_invoice.purchase_order_id');
        $this->db->join('payroll_customer','payroll_customer.customer_id=payroll_purchase_order.customer_id');
        $this->db->join('site','site.site_id=payroll_purchase_order.purchase_order_site_id');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="invoice_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=="invoice_date")
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('payroll_invoice');
        $this->db->join('payroll_purchase_order','payroll_purchase_order.purchase_order_id=payroll_invoice.purchase_order_id');
        $this->db->join('payroll_customer','payroll_customer.customer_id=payroll_purchase_order.customer_id');
        $this->db->join('site','site.site_id=payroll_purchase_order.purchase_order_site_id');
        $this->db->limit($perpage, $start);
        $this->db->order_by('invoice_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_internal_timesheet($pagenum)
    {

        $data=array();
        $this->db->from('payroll_internal_timesheet');
        $this->db->join('payroll_internal_job','payroll_internal_job.internal_job_id=payroll_internal_timesheet.internal_job_id');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield=="internal_timesheet_submission_date" || $searchfield=="internal_timesheet_start_date" || $searchfield=="internal_timesheet_end_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=="internal_timesheet_submission_date" || $searchfield=="internal_timesheet_start_date" || $searchfield=="internal_timesheet_end_date")
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('payroll_internal_timesheet');
        $this->db->join('payroll_internal_job','payroll_internal_job.internal_job_id=payroll_internal_timesheet.internal_job_id');
        $this->db->limit($perpage, $start);
        $this->db->order_by('internal_timesheet_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_internal_job($pagenum)
    {

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

        /*Search function ends here*/


        /*Add function starts here*/



    function insert_manpower_hiring($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'company_name'=>$postdata['company_name'],
                        'company_address'=>$postdata['company_address'],
                        'company_pobox'=>$postdata['company_pobox'],
                        'company_city'=>$postdata['company_city'],
                        'company_country'=>$postdata['company_country'],
                        'company_email'=>$postdata['company_email'],
                        'company_contact_no'=>$postdata['company_contact_no']);
        $this->db->insert('payroll_manpower_hiring', $tblValues);
        $company_id=mysql_insert_id();
        $i=1;
        while (isset($postdata['manpower_hiring_employee_no'.$i]))
        {
            if($postdata['manpower_hiring_employee_no'.$i]!='')
            {
                $tblValues=array('manpower_hiring_employee_company_id'=>$company_id,
                                'manpower_hiring_employee_no'=>$postdata['manpower_hiring_employee_no'.$i],
                                'manpower_hiring_employee_name'=>$postdata['manpower_hiring_employee_name'.$i],
                                'manpower_hiring_employee_trade_id'=>$postdata['manpower_hiring_employee_trade_id'.$i],
                                'manpower_hiring_employee_active'=>$postdata['manpower_hiring_employee_active'.$i],
                                'manpower_hiring_employee_contact_no'=>$postdata['manpower_hiring_employee_contact_no'.$i],);
                $this->db->insert('payroll_manpower_hiring_employee', $tblValues);
            }
            $i++;
        }
        
        $data['resfunction']='search_manpower_hiring';
        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_customer($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'customer_name'=>$postdata['customer_name'],
                        'customer_code'=>$postdata['customer_code'],
                        'customer_address'=>$postdata['customer_address'],
                        'customer_pobox'=>$postdata['customer_pobox'],
                        'customer_city'=>$postdata['customer_city'],
                        'customer_state'=>$postdata['customer_state'],
                        'customer_country'=>$postdata['customer_country'],
                        'customer_email'=>$postdata['customer_email'],
                        'customer_contact_no'=>$postdata['customer_contact_no'],
                        'customer_status'=>$postdata['customer_status']);
        $this->db->insert('payroll_customer', $tblValues);
        $customer_id=mysql_insert_id();
        $i=1;
        while(isset($postdata['contact_name'.$i]))
        {
            if($postdata['contact_name'.$i]!="")
            {
                $tblValues=array('customer_id'=>$customer_id,
                                'contact_name'=>$postdata['contact_name'.$i],
                                'contact_mobile'=>$postdata['contact_mobile'.$i],
                                'contact_email'=>$postdata['contact_email'.$i],
                                'contact_phone'=>$postdata['contact_phone'.$i],
                                'contact_designation'=>$postdata['contact_designation'.$i]);
                $this->db->insert('payroll_customer_contacts', $tblValues);

            }
            $i++;
        }
       

        $data['resfunction']='search_customer';
        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_purchase_order($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $customer=explode('-', $postdata['customer_name']);
        $customer_id=$this->mastermodel->getSingleFieldValue('payroll_customer','customer_id','customer_code',$customer[1]);
        $tblValues=array(
                'job_code'=>$postdata['job_code'],
                'customer_id'=>$customer_id,
                'customer_purchase_order_no'=>$postdata['customer_purchase_order_no'],
                'purchase_order_subject'=>$postdata['purchase_order_subject'],
                'purchase_order_start_date'=>$this->mastermodel->convertdateformat($postdata['purchase_order_start_date']),
                'purchase_order_end_date'=>$this->mastermodel->convertdateformat($postdata['purchase_order_end_date']),
                'purchase_order_site_id'=>$postdata['purchase_order_site_id'],
                'purchase_order_date'=>$this->mastermodel->convertdateformat($postdata['purchase_order_date']),
                'purchase_order_hours_basic'=>$postdata['purchase_order_hours_basic'],
                'purchase_order_transportation'=>$postdata['purchase_order_transportation'],
                'purchase_order_food_allowance'=>$postdata['purchase_order_food_allowance'],
                'purchase_order_accomodation'=>$postdata['purchase_order_accomodation'],
                'purchase_order_status'=>$postdata['purchase_order_status'],
                'purchase_order_payment_terms'=>$postdata['purchase_order_payment_terms'],
                'purchase_order_remarks'=>$postdata['purchase_order_remarks'],
                'purchase_order_document_name'=>$postdata['purchase_order_document_name'],
                'purchase_order_document_doc'=>$postdata['purchase_order_document_doc'],
                        );
        $this->db->insert('payroll_purchase_order', $tblValues);
        $purchase_order_id=mysql_insert_id();
        $i=1;
        while (isset($postdata['purchase_order_trade_id'.$i]))
        {
            if($postdata['purchase_order_trade_id'.$i]!='')
            {
                $tblValues=array('purchase_order_id'=>$purchase_order_id,
                                'purchase_order_trade_id'=>$postdata['purchase_order_trade_id'.$i],
                                'purchase_order_manpower_no'=>$postdata['purchase_order_manpower_no'.$i],
                                'purchase_order_rate'=>$postdata['purchase_order_rate'.$i],
                                'purchase_order_ot_type'=>$postdata['purchase_order_ot_type'.$i],
                                'purchase_order_ot_rate'=>$postdata['purchase_order_ot_rate'.$i],
                                'purchase_order_hot_rate'=>$postdata['purchase_order_hot_rate'.$i]);
                $this->db->insert('payroll_purchase_order_details', $tblValues);
            }
            $i++;
        }

        $data['resfunction']='search_purchase_order';
        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_client_timesheet($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        if(isset($postdata['client_timesheet_reviewed']))
            $client_timesheet_reviewed=1;
        else
            $client_timesheet_reviewed=0;
        $tblValues=array(
                        'purchase_order_id'=>$postdata['purchase_order_id'],
                        'client_timesheet_received_date'=>$this->mastermodel->convertdateformat($postdata['client_timesheet_received_date']),
                        'client_timesheet_reviewed'=>$client_timesheet_reviewed,
                        'client_timesheet_submission_date'=>$this->mastermodel->convertdateformat($postdata['client_timesheet_submission_date']),
                        'client_timesheet_start_date'=>$this->mastermodel->convertdateformat($postdata['client_timesheet_start_date']),
                        'client_timesheet_end_date'=>$this->mastermodel->convertdateformat($postdata['client_timesheet_end_date']),
                        'client_timesheet_remarks'=>$postdata['client_timesheet_remarks'],
                        'client_timesheet_document'=>$postdata['client_timesheet_document']);
        $this->db->insert('payroll_client_timesheet', $tblValues);
       
        $data['resfunction']='search_client_timesheet';
        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_manpower_timesheet($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        if(isset($postdata['manpower_timesheet_reviewed']))
            $manpower_timesheet_reviewed=1;
        else
            $manpower_timesheet_reviewed=0;
        $tblValues=array(
                        'manpower_timesheet_company_id'=>$postdata['manpower_timesheet_company_id'],
                        'purchase_order_id'=>$postdata['purchase_order_id'],
                        'manpower_timesheet_issued_date'=>$this->mastermodel->convertdateformat($postdata['manpower_timesheet_issued_date']),
                        'manpower_timesheet_reviewed'=>$manpower_timesheet_reviewed,
                        'manpower_timesheet_submission_date'=>$this->mastermodel->convertdateformat($postdata['manpower_timesheet_submission_date']),
                        'manpower_timesheet_start_date'=>$this->mastermodel->convertdateformat($postdata['manpower_timesheet_start_date']),
                        'manpower_timesheet_end_date'=>$this->mastermodel->convertdateformat($postdata['manpower_timesheet_end_date']),
                        'manpower_timesheet_remarks'=>$postdata['manpower_timesheet_remarks'],
                        'manpower_timesheet_document'=>$postdata['manpower_timesheet_document']);
        $this->db->insert('payroll_manpower_timesheet', $tblValues);

        $data['resfunction']='search_manpower_timesheet';
        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_invoice($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        
        $tblValues=array(
                        'purchase_order_id'=>$postdata['purchase_order_id'],
                        'invoice_date'=>$this->mastermodel->convertdateformat($postdata['invoice_date']),
                        'invoice_status'=>$postdata['invoice_status'],
                        'invoice_no'=>$postdata['invoice_no'],
                        'invoice_remarks'=>$postdata['invoice_remarks'],
                        'invoice_heading'=>$postdata['invoice_heading'],
                        'invoice_footer'=>$postdata['invoice_footer'],
                        'invoice_start_date'=>$this->mastermodel->convertdateformat($postdata['invoice_start_date']),
                        'invoice_end_date'=>$this->mastermodel->convertdateformat($postdata['invoice_end_date']),
                        'invoice_document'=>$postdata['invoice_document']);
        $this->db->insert('payroll_invoice', $tblValues);
        $i=1;
       $invoice_id=mysql_insert_id();
        while(isset($postdata['label_text'.$i]))
        {
            if($postdata['label_text'.$i]!='')
            {
                            $tbl_Values=array('invoice_id'=>$invoice_id,
                                'label_text'=>$postdata['label_text'.$i],
                                'label_value'=>$postdata['label_value'.$i]);
                $this->db->insert('payroll_invoice_field', $tbl_Values);
            }
            $i++;
        }
        $data['resfunction']='search_invoice';
        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_internal_job($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        
        
        $tblValues=array(
                'internal_job_code'=>$postdata['internal_job_code'],
                'internal_job_subject'=>$postdata['internal_job_subject'],
                'internal_job_remarks'=>$postdata['internal_job_remarks'],
                'internal_job_start_date'=>$this->mastermodel->convertdateformat($postdata['internal_job_start_date']),
                'internal_job_end_date'=>$this->mastermodel->convertdateformat($postdata['internal_job_end_date']),
                'internal_job_document_name'=>$postdata['internal_job_document_name'],
                'internal_job_document_doc'=>$postdata['internal_job_document_doc'],
                'internal_job_status'=>$postdata['internal_job_status']);
        $this->db->insert('payroll_internal_job', $tblValues);
       

        $data['resfunction']='search_internal_job';
        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_internal_timesheet($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'internal_job_id'=>$postdata['internal_job_id'],
                        'internal_timesheet_submission_date'=>$this->mastermodel->convertdateformat($postdata['internal_timesheet_submission_date']),
                        'internal_timesheet_start_date'=>$this->mastermodel->convertdateformat($postdata['internal_timesheet_start_date']),
                        'internal_timesheet_end_date'=>$this->mastermodel->convertdateformat($postdata['internal_timesheet_end_date']),
                        'internal_timesheet_remarks'=>$postdata['internal_timesheet_remarks']);
        $this->db->insert('payroll_internal_timesheet', $tblValues);

        $data['resfunction']='search_internal_timesheet';
        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_manpower_hiring($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'company_name'=>$postdata['company_name'],
                        'company_address'=>$postdata['company_address'],
                        'company_pobox'=>$postdata['company_pobox'],
                        'company_city'=>$postdata['company_city'],
                        'company_country'=>$postdata['company_country'],
                        'company_email'=>$postdata['company_email'],
                        'company_contact_no'=>$postdata['company_contact_no']);
        $this->db->where('company_id', $postdata['company_id']);
        $this->db->update('payroll_manpower_hiring', $tblValues);
        $i=1;
        while(isset ($postdata['manpower_hiring_employee_id_'.$i]))
        {
           if($postdata['manpower_hiring_employee_no_'.$i]!='')
           {
               $tblValues=array(
                        'manpower_hiring_employee_no'=>$postdata['manpower_hiring_employee_no_'.$i],
                        'manpower_hiring_employee_name'=>$postdata['manpower_hiring_employee_name_'.$i],
                        'manpower_hiring_employee_trade_id'=>$postdata['manpower_hiring_employee_trade_id_'.$i],
                        'manpower_hiring_employee_active'=>$postdata['manpower_hiring_employee_active_'.$i],
                        'manpower_hiring_employee_contact_no'=>$postdata['manpower_hiring_employee_contact_no_'.$i]);
                $this->db->where('manpower_hiring_employee_id', $postdata['manpower_hiring_employee_id_'.$i]);
                $this->db->update('payroll_manpower_hiring_employee', $tblValues);
           }
            $i++;
        }
        $i=1;
        while (isset($postdata['manpower_hiring_employee_no'.$i]))
        {
            if($postdata['manpower_hiring_employee_no'.$i]!='')
            {
                $tblValues=array('manpower_hiring_employee_company_id'=>$postdata['company_id'],
                                'manpower_hiring_employee_no'=>$postdata['manpower_hiring_employee_no'.$i],
                                'manpower_hiring_employee_name'=>$postdata['manpower_hiring_employee_name'.$i],
                                'manpower_hiring_employee_trade_id'=>$postdata['manpower_hiring_employee_trade_id'.$i],
                                'manpower_hiring_employee_active'=>$postdata['manpower_hiring_employee_active'.$i],
                                'manpower_hiring_employee_contact_no'=>$postdata['manpower_hiring_employee_contact_no'.$i],);
                $this->db->insert('payroll_manpower_hiring_employee', $tblValues);
            }
            $i++;
        }
        $data['resfunction']='search_manpower_hiring';
        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_purchase_order($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                'job_code'=>$postdata['job_code'],
                'customer_purchase_order_no'=>$postdata['customer_purchase_order_no'],
                'purchase_order_subject'=>$postdata['purchase_order_subject'],
                'purchase_order_start_date'=>$this->mastermodel->convertdateformat($postdata['purchase_order_start_date']),
                'purchase_order_end_date'=>$this->mastermodel->convertdateformat($postdata['purchase_order_end_date']),
                'purchase_order_site_id'=>$postdata['purchase_order_site_id'],
                'purchase_order_date'=>$this->mastermodel->convertdateformat($postdata['purchase_order_date']),
                'purchase_order_hours_basic'=>$postdata['purchase_order_hours_basic'],
                'purchase_order_transportation'=>$postdata['purchase_order_transportation'],
                'purchase_order_food_allowance'=>$postdata['purchase_order_food_allowance'],
                'purchase_order_accomodation'=>$postdata['purchase_order_accomodation'],
                'purchase_order_status'=>$postdata['purchase_order_status'],
                'purchase_order_payment_terms'=>$postdata['purchase_order_payment_terms'],
                'purchase_order_remarks'=>$postdata['purchase_order_remarks'],
                'purchase_order_document_name'=>$postdata['purchase_order_document_name']
                        );
        $this->db->where('purchase_order_id', $postdata['purchase_order_id']);
        $this->db->update('payroll_purchase_order', $tblValues);

        if($postdata['purchase_order_document_doc']!='')
        {
            $tblValues=array(
            'purchase_order_document_doc'=>$postdata['purchase_order_document_doc']);
            $this->db->where('purchase_order_id', $postdata['purchase_order_id']);
        $this->db->update('payroll_purchase_order', $tblValues);
        }
        $this->db->where('purchase_order_id', $postdata['purchase_order_id']);
        $this->db->delete('payroll_purchase_order_details');
        $i=1;
        while (isset($postdata['purchase_order_trade_id'.$i]))
        {
            if($postdata['purchase_order_trade_id'.$i]!='')
            {
                $tblValues=array('purchase_order_id'=>$postdata['purchase_order_id'],
                                'purchase_order_trade_id'=>$postdata['purchase_order_trade_id'.$i],
                                'purchase_order_manpower_no'=>$postdata['purchase_order_manpower_no'.$i],
                                'purchase_order_rate'=>$postdata['purchase_order_rate'.$i],
                                'purchase_order_ot_type'=>$postdata['purchase_order_ot_type'.$i],
                                'purchase_order_ot_rate'=>$postdata['purchase_order_ot_rate'.$i],
                                'purchase_order_hot_rate'=>$postdata['purchase_order_hot_rate'.$i]);
                $this->db->insert('payroll_purchase_order_details', $tblValues);
            }
            $i++;
        }

        $data['resfunction']='search_purchase_order';
        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_customer($postdata)
    {
        $data=array();
        $this->db->trans_begin();
             $tblValues=array(
                        'customer_name'=>$postdata['customer_name'],
                        'customer_code'=>$postdata['customer_code'],
                        'customer_address'=>$postdata['customer_address'],
                        'customer_pobox'=>$postdata['customer_pobox'],
                        'customer_city'=>$postdata['customer_city'],
                        'customer_state'=>$postdata['customer_state'],
                        'customer_country'=>$postdata['customer_country'],
                        'customer_email'=>$postdata['customer_email'],
                        'customer_contact_no'=>$postdata['customer_contact_no'],
                        'customer_status'=>$postdata['customer_status']);
        $this->db->where('customer_id',$postdata['customer_id']);
        $this->db->update('payroll_customer', $tblValues);

            $i=1;
            $this->db->where('customer_id',$postdata['customer_id']);
            $this->db->delete('payroll_customer_contacts');

            while(isset($postdata['contact_name'.$i]))
            {
                if($postdata['contact_name'.$i]!='')
                {
                    $tbl_Values=array('customer_id'=>$postdata['customer_id'],
                                    'contact_name'=>$postdata['contact_name'.$i],
                                    'contact_mobile'=>$postdata['contact_mobile'.$i],
                                    'contact_email'=>$postdata['contact_email'.$i],
                                    'contact_phone'=>$postdata['contact_phone'.$i],
                                    'contact_designation'=>$postdata['contact_designation'.$i]);
                    $this->db->insert('payroll_customer_contacts', $tbl_Values);
                }
                $i++;
            }
        
        $data['resfunction']='search_customer';
        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_internal_job($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                'internal_job_code'=>$postdata['internal_job_code'],
                'internal_job_subject'=>$postdata['internal_job_subject'],
                'internal_job_remarks'=>$postdata['internal_job_remarks'],
                'internal_job_start_date'=>$this->mastermodel->convertdateformat($postdata['internal_job_start_date']),
                'internal_job_end_date'=>$this->mastermodel->convertdateformat($postdata['internal_job_end_date']),
                'internal_job_document_name'=>$postdata['internal_job_document_name'],
                'internal_job_status'=>$postdata['internal_job_status']);
        $this->db->where('internal_job_id', $postdata['internal_job_id']);
        $this->db->update('payroll_internal_job', $tblValues);

        if($postdata['internal_job_document_doc']!='')
        {
            $tblValues=array(
            'internal_job_document_doc'=>$postdata['internal_job_document_doc']);
            $this->db->where('internal_job_id', $postdata['internal_job_id']);
            $this->db->update('payroll_internal_job', $tblValues);
        }
        $data['resfunction']='search_internal_job';
        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_client_timesheet($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        if(isset($postdata['client_timesheet_reviewed']))
            $client_timesheet_reviewed=1;
        else
            $client_timesheet_reviewed=0;
        $tblValues=array(
                        'client_timesheet_received_date'=>$this->mastermodel->convertdateformat($postdata['client_timesheet_received_date']),
                        'client_timesheet_reviewed'=>$client_timesheet_reviewed,
                        'client_timesheet_submission_date'=>$this->mastermodel->convertdateformat($postdata['client_timesheet_submission_date']),
                        'client_timesheet_start_date'=>$this->mastermodel->convertdateformat($postdata['client_timesheet_start_date']),
                        'client_timesheet_end_date'=>$this->mastermodel->convertdateformat($postdata['client_timesheet_end_date']),
                        'client_timesheet_remarks'=>$postdata['client_timesheet_remarks']);
        $this->db->where('client_timesheet_id', $postdata['client_timesheet_id']);
        $this->db->update('payroll_client_timesheet', $tblValues);
        
        if($postdata['client_timesheet_document']!='')
        {
            $tblValues=array('client_timesheet_document'=>$postdata['client_timesheet_document']);
            $this->db->where('client_timesheet_id', $postdata['client_timesheet_id']);
            $this->db->update('payroll_client_timesheet', $tblValues);
        }
       
       
        $data['resfunction']='search_client_timesheet';
        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_manpower_timesheet($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        if(isset($postdata['manpower_timesheet_reviewed']))
            $manpower_timesheet_reviewed=1;
        else
            $manpower_timesheet_reviewed=0;
        $tblValues=array(
                        'manpower_timesheet_issued_date'=>$this->mastermodel->convertdateformat($postdata['manpower_timesheet_issued_date']),
                        'manpower_timesheet_reviewed'=>$manpower_timesheet_reviewed,
                        'manpower_timesheet_submission_date'=>$this->mastermodel->convertdateformat($postdata['manpower_timesheet_submission_date']),
                        'manpower_timesheet_start_date'=>$this->mastermodel->convertdateformat($postdata['manpower_timesheet_start_date']),
                        'manpower_timesheet_end_date'=>$this->mastermodel->convertdateformat($postdata['manpower_timesheet_end_date']),
                        'manpower_timesheet_remarks'=>$postdata['manpower_timesheet_remarks']);
        $this->db->where('manpower_timesheet_id', $postdata['manpower_timesheet_id']);
        $this->db->update('payroll_manpower_timesheet', $tblValues);

        if($postdata['manpower_timesheet_document']!='')
        {
            $tblValues=array('manpower_timesheet_document'=>$postdata['manpower_timesheet_document']);
            $this->db->where('manpower_timesheet_id', $postdata['manpower_timesheet_id']);
            $this->db->update('payroll_manpower_timesheet', $tblValues);
        }


        $data['resfunction']='search_manpower_timesheet';
        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_invoice($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'invoice_date'=>$this->mastermodel->convertdateformat($postdata['invoice_date']),
                        'invoice_status'=>$postdata['invoice_status'],
                        'invoice_no'=>$postdata['invoice_no'],
                        'invoice_remarks'=>$postdata['invoice_remarks'],
                        'invoice_heading'=>$postdata['invoice_heading'],
                        'invoice_footer'=>$postdata['invoice_footer'],
                        );
        $this->db->where('invoice_id', $postdata['invoice_id']);
        $this->db->update('payroll_invoice', $tblValues);
        $i=1;
        $this->db->where('invoice_id',$postdata['invoice_id']);
        $this->db->delete('payroll_invoice_field');

        while(isset($postdata['label_text'.$i]))
        {
            if($postdata['label_text'.$i]!='')
            {
                $tbl_Values=array('invoice_id'=>$postdata['invoice_id'],
                                'label_text'=>$postdata['label_text'.$i],
                                'label_value'=>$postdata['label_value'.$i]);
                $this->db->insert('payroll_invoice_field', $tbl_Values);
            }
            $i++;
        }
        
        if($postdata['invoice_document']!='')
        {
            $tblValues=array(
            'invoice_document'=>$postdata['invoice_document']);
            $this->db->where('invoice_id', $postdata['invoice_id']);
        $this->db->update('payroll_invoice', $tblValues);
        }
        

        $data['resfunction']='search_invoice';
        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_internal_timesheet($postdata)
    {
        $data=array();
        $this->db->trans_begin();
       
        $tblValues=array(
                        'internal_timesheet_submission_date'=>$this->mastermodel->convertdateformat($postdata['internal_timesheet_submission_date']),
                        'internal_timesheet_start_date'=>$this->mastermodel->convertdateformat($postdata['internal_timesheet_start_date']),
                        'internal_timesheet_end_date'=>$this->mastermodel->convertdateformat($postdata['internal_timesheet_end_date']),
                        'internal_timesheet_remarks'=>$postdata['internal_timesheet_remarks']);
        $this->db->where('internal_timesheet_id', $postdata['internal_timesheet_id']);
        $this->db->update('payroll_internal_timesheet', $tblValues);



        $data['resfunction']='search_internal_timesheet';
        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 get_external_job_info()
    {
        $data = array();
        $this->db->join('payroll_customer',"payroll_purchase_order.customer_id=payroll_customer.customer_id");
        $this->db->join('site',"payroll_purchase_order.purchase_order_site_id=site.site_id");
        $this->db->where('purchase_order_status',"Active");
        $this->db->order_by('purchase_order_id','desc');
        $Q= $this->db->get('payroll_purchase_order');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_job_info_single($customer_purchase_order_id)
    {
        $this->db->join('payroll_customer',"payroll_purchase_order.customer_id=payroll_customer.customer_id");
        $this->db->join('site',"payroll_purchase_order.purchase_order_site_id=site.site_id");
        $this->db->where('purchase_order_status',"Active");
        $this->db->where('purchase_order_id',$customer_purchase_order_id);
        $Q = $this->db->get('payroll_purchase_order');
        return $Q->row();
    }

    function enter_client_timesheet_details($postdata)
    {
        $this->db->trans_begin();
       
        $this->db->where('client_timesheet_id',$postdata['client_timesheet_id']);
        $this->db->delete('payroll_client_timesheet_main');
        $j=0;
        $x=0;
        while(isset($postdata['employee_id'][$x]))
        {
            $i=1;
            $tblValues=array(
                        'client_timesheet_id'=>$postdata['client_timesheet_id'],
                        'client_timesheet_employee_id'=>$postdata['employee_id'][$x],
                        'client_timesheet_company_id'=>$postdata['company_id'][$x],
                        'normal_hours'=>$postdata['normal_hours'][$x],
                        'ot_hours'=>$postdata['ot_hours'][$x],
                        'hot_hours'=>$postdata['hot_hours'][$x],
                        'basic_rate'=>$postdata['basic_rate'][$x],
                        'ot_rate'=>$postdata['ot_rate'][$x],
                        'hot_rate'=>$postdata['hot_rate'][$x],
                        );
            $this->db->insert('payroll_client_timesheet_main', $tblValues);
            $main_id=mysql_insert_id();
            while(isset ($postdata['attendance_day'.$i]))
            {
                if(is_numeric($postdata['attendance_day'.$i][$j]))
                {
                    $postdata['attendance_day'.$i][$j]=number_format($postdata['attendance_day'.$i][$j],2);
                }
                 $tblValues=array(
                        'client_timesheet_main_id'=>$main_id,
                        'client_timesheet_day'=>$i,
                        'client_timesheet_date'=>$postdata['attendance_date'.$i][$j],
                        'client_timesheet_no_hours'=>$postdata['attendance_day'.$i][$j]);
                 $this->db->insert('payroll_client_timesheet_details', $tblValues);
                 
                 $i++;
            }
            $j++;
            $x++;
        }
        
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
        }
        else
        {
            $this->db->trans_commit();
        }
    }

    function get_timesheet_employees($client_timesheet_id)
    {
        $data = array();
        $this->db->where('client_timesheet_id',$client_timesheet_id);
        $this->db->group_by('client_timesheet_employee_id');
        $this->db->order_by('client_timesheet_id','asc');
        $Q= $this->db->get('payroll_client_timesheet_details');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    function get_attendance_days($client_timesheet_id,$employee_id)
    {
        $data = array();
        $this->db->where('client_timesheet_id',$client_timesheet_id);
        $this->db->where('client_timesheet_employee_id',$employee_id);
        $this->db->order_by('id','asc');
        $Q= $this->db->get('payroll_client_timesheet_details');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    function get_attendance_days_manpower($client_timesheet_main_id,$start_date,$end_date)
    {
        $data = array();
        $this->db->where('client_timesheet_main_id',$client_timesheet_main_id);
        $this->db->where('client_timesheet_date >=',$start_date);
        $this->db->where('client_timesheet_date <=',$end_date);
        $this->db->order_by('id','asc');
        $Q= $this->db->get('payroll_client_timesheet_details');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    function get_employees_not_marked($client_timesheet_id)
    {
        $data = array();
        $sql = "(select employee_non_main.emp_non_id, emp_non_full_name,   CONCAT(`employee_non_main`.`emp_non_no_old`,','
            ,GROUP_CONCAT(DISTINCT(`visa_processing`.`employee_no`) order by visa_processing_id)) AS emp_non_no,0 from employee_non_main
             JOIN visa_processing ON `visa_processing`.`employee_id` = `employee_non_main`.`emp_non_id`
             
             ";
        $sql.=  " where active =1 and `employee_non_main`.`emp_non_id` not in (select client_timesheet_employee_id from payroll_client_timesheet_main where client_timesheet_id=$client_timesheet_id and client_timesheet_company_id = 0)
        and `employee_non_main`.`emp_non_trade_id` in (select purchase_order_trade_id from payroll_purchase_order_details inner join payroll_client_timesheet on payroll_client_timesheet.purchase_order_id=payroll_purchase_order_details.purchase_order_id
        where payroll_client_timesheet.client_timesheet_id = $client_timesheet_id )
        GROUP BY emp_non_id order by  emp_non_trade_id,emp_non_full_name)";

        $sql .= "UNION (select payroll_manpower_hiring_employee.manpower_hiring_employee_id as emp_non_id, manpower_hiring_employee_name as emp_non_full_name,  manpower_hiring_employee_no AS emp_non_no,company_id from payroll_manpower_hiring_employee
             JOIN payroll_manpower_hiring ON `payroll_manpower_hiring`.`company_id` = `payroll_manpower_hiring_employee`.`manpower_hiring_employee_company_id`
             ";
        $sql.=  " where manpower_hiring_employee_active =1 and `payroll_manpower_hiring_employee`.`manpower_hiring_employee_id` not in (select client_timesheet_employee_id from payroll_client_timesheet_main where client_timesheet_id=$client_timesheet_id  and client_timesheet_company_id != 0)
        and `payroll_manpower_hiring_employee`.`manpower_hiring_employee_trade_id` in (select purchase_order_trade_id from payroll_purchase_order_details inner join payroll_client_timesheet on payroll_client_timesheet.purchase_order_id=payroll_purchase_order_details.purchase_order_id
        where payroll_client_timesheet.client_timesheet_id = $client_timesheet_id)
        GROUP BY manpower_hiring_employee_id order by  manpower_hiring_employee_trade_id,manpower_hiring_employee_name)";
        $Q = $this->db->query($sql);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_timesheet_employees_internal($internal_timesheet_id)
    {
        $data = array();
        $this->db->where('internal_timesheet_id',$internal_timesheet_id);
        $this->db->group_by('internal_timesheet_employee_id');
        $this->db->order_by('internal_timesheet_id','asc');
        $Q= $this->db->get('payroll_internal_timesheet_details');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    function get_attendance_days_internal($internal_timesheet_id,$employee_id)
    {
        $data = array();
        $this->db->where('internal_timesheet_id',$internal_timesheet_id);
        $this->db->where('internal_timesheet_employee_id',$employee_id);
        $this->db->order_by('id','asc');
        $Q= $this->db->get('payroll_internal_timesheet_details');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_employees_not_marked_internal($internal_timesheet_id)
    {
        $data = array();
        $sql = "select employee_non_main.emp_non_id, emp_non_full_name, emp_non_date_joining, batch_code, trade_name, 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 employee_non_main
             JOIN visa_processing ON `visa_processing`.`employee_id` = `employee_non_main`.`emp_non_id`
             inner join emp_non_personal on emp_non_personal.emp_non_id=employee_non_main.emp_non_id  inner join batch on id=batch_id inner join trade on emp_non_trade_id=trade_id
             ";
        $sql.=  " where active =1 and `employee_non_main`.`emp_non_id` not in (select internal_timesheet_employee_id from payroll_internal_timesheet_details where internal_timesheet_id=$internal_timesheet_id) GROUP BY emp_non_id order by batch_code, emp_non_full_name";
        $Q = $this->db->query($sql);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function enter_internal_timesheet_details($postdata)
    {
        $this->db->trans_begin();
        $this->db->where('internal_timesheet_id',$postdata['internal_timesheet_id']);
        $this->db->delete('payroll_internal_timesheet_details');
        $j=0;
        foreach($postdata['employee_id'] as $employee)
        {
            $i=1;
            while(isset ($postdata['attendance_day'.$i]))
            {
                 $number=$this->mastermodel->number_rows('payroll_internal_timesheet_details','internal_timesheet_employee_id',$employee,'internal_timesheet_date',$postdata['attendance_date'.$i][$j]);
                 if($number==0)
                 {
                 $tblValues=array(
                        'internal_timesheet_id'=>$postdata['internal_timesheet_id'],
                        'internal_timesheet_employee_id'=>$employee,
                        'internal_timesheet_day'=>$i,
                        'internal_timesheet_date'=>$postdata['attendance_date'.$i][$j],
                        'internal_timesheet_no_hours'=>$postdata['attendance_day'.$i][$j]);
                 $this->db->insert('payroll_internal_timesheet_details', $tblValues);
                 }
                 $i++;
            }
            $j++;
        }

        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
        }
        else
        {
            $this->db->trans_commit();
        }
    }

    function get_timesheet_employee_details($client_timesheet_id)
    {
        $data = array();
        $sql = "(select payroll_client_timesheet_main.*,emp_non_full_name,emp_non_no,client_timesheet_employee_id,purchase_order_hours_basic,
            trade_name,payroll_purchase_order.purchase_order_id,trade_id,0,client_timesheet_company_id from payroll_client_timesheet_main
            join employee_non_main on employee_non_main.emp_non_id=client_timesheet_employee_id
            join trade on employee_non_main.emp_non_trade_id=trade_id
            join payroll_client_timesheet on payroll_client_timesheet.client_timesheet_id=payroll_client_timesheet_main.client_timesheet_id
            join payroll_purchase_order on payroll_purchase_order.purchase_order_id=payroll_client_timesheet.purchase_order_id
            where payroll_client_timesheet_main.client_timesheet_id = '$client_timesheet_id' and client_timesheet_company_id = '0'
            group by payroll_client_timesheet_main.client_timesheet_employee_id order by trade_id asc)";
        $sql .= " UNION (select payroll_client_timesheet_main.*,manpower_hiring_employee_name as emp_non_full_name,manpower_hiring_employee_no as emp_non_no,client_timesheet_employee_id,purchase_order_hours_basic,
            trade_name,payroll_purchase_order.purchase_order_id,trade_id,company_name,client_timesheet_company_id from payroll_client_timesheet_main
            join payroll_manpower_hiring_employee on payroll_manpower_hiring_employee.manpower_hiring_employee_id=client_timesheet_employee_id
            join payroll_manpower_hiring on payroll_manpower_hiring.company_id=payroll_manpower_hiring_employee.manpower_hiring_employee_company_id
            join trade on payroll_manpower_hiring_employee.manpower_hiring_employee_trade_id=trade_id
            join payroll_client_timesheet on payroll_client_timesheet.client_timesheet_id=payroll_client_timesheet_main.client_timesheet_id
            join payroll_purchase_order on payroll_purchase_order.purchase_order_id=payroll_client_timesheet.purchase_order_id
            where payroll_client_timesheet_main.client_timesheet_id = '$client_timesheet_id' and client_timesheet_company_id != '0'
            group by payroll_client_timesheet_main.client_timesheet_employee_id order by trade_id asc)";
        $Q= $this->db->query($sql);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_po_rates($purchase_order_id,$trade_id)
    {
        $data = array();
        $this->db->where('purchase_order_id',$purchase_order_id);
        $this->db->where('purchase_order_trade_id',$trade_id);
        $Q= $this->db->get('payroll_purchase_order_details');
        $row=$Q->row();
        return $row;
    }
    
    function get_employees_not_marked_manpower($manpower_timesheet_id)
    {
        $data = array();
        $sql = "select * from payroll_manpower_hiring_employee
             ";
        $sql.=  " where `payroll_manpower_hiring_employee`.`manpower_hiring_employee_id`
        not in (select manpower_timesheet_employee_id from payroll_manpower_timesheet_details where manpower_timesheet_id=$manpower_timesheet_id)
        and `payroll_manpower_hiring_employee`.`manpower_hiring_employee_trade_id` in (select purchase_order_trade_id from payroll_purchase_order_details inner join payroll_manpower_timesheet on payroll_manpower_timesheet.purchase_order_id=payroll_purchase_order_details.purchase_order_id
        where payroll_manpower_timesheet.manpower_timesheet_id = $manpower_timesheet_id)";
        $Q = $this->db->query($sql);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function enter_manpower_timesheet_details($postdata)
    {
        $this->db->trans_begin();
        $this->db->where('manpower_timesheet_id',$postdata['manpower_timesheet_id']);
        $this->db->delete('payroll_manpower_timesheet_details');
        $j=0;
        foreach($postdata['employee_id'] as $employee)
        {
            $i=1;
            while(isset ($postdata['attendance_day'.$i]))
            {
                 $number=$this->mastermodel->number_rows('payroll_manpower_timesheet_details','manpower_timesheet_employee_id',$employee,'manpower_timesheet_date',$postdata['attendance_date'.$i][$j]);
                 if($number==0)
                 {
                 $tblValues=array(
                        'manpower_timesheet_id'=>$postdata['manpower_timesheet_id'],
                        'manpower_timesheet_employee_id'=>$employee,
                        'manpower_timesheet_day'=>$i,
                        'manpower_timesheet_date'=>$postdata['attendance_date'.$i][$j],
                        'manpower_timesheet_no_hours'=>$postdata['attendance_day'.$i][$j]);
                 $this->db->insert('payroll_manpower_timesheet_details', $tblValues);
                 }
                 $i++;
            }
            $j++;
        }
        
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
        }
        else
        {
            $this->db->trans_commit();
        }
    }
    
    function get_timesheet_employees_manpower($manpower_timesheet_id)
    {
        $data = array();
        $this->db->where('manpower_timesheet_id',$manpower_timesheet_id);
        $this->db->group_by('manpower_timesheet_employee_id');
        $this->db->order_by('manpower_timesheet_id','asc');
        $Q= $this->db->get('payroll_manpower_timesheet_details');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }
    
   
    
    function get_timesheet_employee_details_manpower($manpower_timesheet_company_id,$purchase_order_id,$manpower_timesheet_start_date,$manpower_timesheet_end_date)
    {
        $data = array();
            $sql = "select * from payroll_client_timesheet_main
            inner join payroll_manpower_hiring_employee on payroll_manpower_hiring_employee.manpower_hiring_employee_id=payroll_client_timesheet_main.client_timesheet_employee_id
            inner join payroll_manpower_hiring on payroll_manpower_hiring.company_id=payroll_manpower_hiring_employee.manpower_hiring_employee_company_id
            inner join trade on trade.trade_id = payroll_manpower_hiring_employee.manpower_hiring_employee_trade_id
            inner join payroll_client_timesheet on payroll_client_timesheet.client_timesheet_id = payroll_client_timesheet_main.client_timesheet_id
            inner join payroll_client_timesheet_details on payroll_client_timesheet_details.client_timesheet_main_id = payroll_client_timesheet_main.client_timesheet_main_id
            where client_timesheet_company_id = '$manpower_timesheet_company_id'
            and payroll_client_timesheet.purchase_order_id = '$purchase_order_id'
            and payroll_client_timesheet_details.client_timesheet_date >= '$manpower_timesheet_start_date'
            and payroll_client_timesheet_details.client_timesheet_date <= '$manpower_timesheet_start_date'
            order by trade_id asc";
        $Q= $this->db->query($sql);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_client_timesheet_invoice_info($po_id,$timesheet_start_date,$timesheet_end_date)
    {
        $data=array();
        $timesheet_start_date=$this->mastermodel->convertdateformat($timesheet_start_date);
        $timesheet_end_date=$this->mastermodel->convertdateformat($timesheet_end_date);
        $sql="SELECT
            `payroll_purchase_order`.`purchase_order_id`, `trade`.`trade_name`, `trade`.`trade_id`,
            `payroll_purchase_order_details`.`purchase_order_rate` AS 'normal_rate',
            `payroll_purchase_order_details`.`purchase_order_ot_rate` AS 'ot_rate',
            `payroll_purchase_order_details`.`purchase_order_hot_rate` AS 'hot_rate',
            @othour := SUM(
                        IF (	(SELECT COUNT(*) FROM `payroll_weekly_holiday` WHERE `payroll_weekly_holiday`.`payroll_weekly_holiday` = DAYNAME(`client_timesheet_date`)) =0
				,IF(	`client_timesheet_no_hours` > `purchase_order_hours_basic`
				, `client_timesheet_no_hours` - `purchase_order_hours_basic`
				,0
			   ),0)
		     ) AS ot_hours
            ,@hothour := SUM(
			IF (	(SELECT COUNT(*) FROM `payroll_weekly_holiday` WHERE `payroll_weekly_holiday`.`payroll_weekly_holiday` = DAYNAME(`client_timesheet_date`)) >0
				, `client_timesheet_no_hours`
				, 0
			   )
		     ) AS hot_hours,
            SUM(`payroll_client_timesheet_details`.`client_timesheet_no_hours`)  AS normal_hours
            , COUNT(DISTINCT(`payroll_client_timesheet_details`.`client_timesheet_employee_id`)) AS 'manpower'
            FROM
                `payroll_purchase_order_details`
                INNER JOIN `payroll_purchase_order`
                    ON (`payroll_purchase_order_details`.`purchase_order_id` = `payroll_purchase_order`.`purchase_order_id`)
                INNER JOIN `trade`
                    ON (`payroll_purchase_order_details`.`purchase_order_trade_id` = `trade`.`trade_id`)
                INNER JOIN `payroll_client_timesheet`
                    ON (`payroll_client_timesheet`.`purchase_order_id` = `payroll_purchase_order`.`purchase_order_id`)
                INNER JOIN `payroll_client_timesheet_details`
                    ON (`payroll_client_timesheet_details`.`client_timesheet_id` = `payroll_client_timesheet`.`client_timesheet_id`)
                INNER JOIN `employee_non_main`
                    ON (`employee_non_main`.`emp_non_trade_id` = `trade`.`trade_id`) AND (`payroll_client_timesheet_details`.`client_timesheet_employee_id` = `employee_non_main`.`emp_non_id`)
            WHERE `payroll_client_timesheet_details`.`client_timesheet_date` BETWEEN '$timesheet_start_date' AND '$timesheet_end_date' and `payroll_purchase_order_details`.`purchase_order_id`='$po_id'
            GROUP BY `trade`.`trade_id`";
      
        
        //echo $sql;
        $Q= $this->db->query($sql);
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_manpower_timesheet_invoice_info($po_id,$timesheet_start_date,$timesheet_end_date)
    {
        $data=array();
        $timesheet_start_date=$this->mastermodel->convertdateformat($timesheet_start_date);
        $timesheet_end_date=$this->mastermodel->convertdateformat($timesheet_end_date);
        $sql="SELECT
            `payroll_purchase_order`.`purchase_order_id`, `trade`.`trade_name`, `trade`.`trade_id`,
            `payroll_purchase_order_details`.`purchase_order_rate` AS 'normal_rate',
            `payroll_purchase_order_details`.`purchase_order_ot_rate` AS 'ot_rate',
            `payroll_purchase_order_details`.`purchase_order_hot_rate` AS 'hot_rate',
            @othour := SUM(
			IF (	(SELECT COUNT(*) FROM `payroll_weekly_holiday` WHERE `payroll_weekly_holiday`.`payroll_weekly_holiday` = DAYNAME(`client_timesheet_date`)) =0
				,IF(	`client_timesheet_no_hours` > `purchase_order_hours_basic`
				, `client_timesheet_no_hours` - `purchase_order_hours_basic`
				,0
			   ),0)
		     ) AS ot_hours
            ,@hothour := SUM(
			IF (	(SELECT COUNT(*) FROM `payroll_weekly_holiday` WHERE `payroll_weekly_holiday`.`payroll_weekly_holiday` = DAYNAME(`client_timesheet_date`)) >0
				, `client_timesheet_no_hours`
				, 0
			   )
		     ) AS hot_hours,
            SUM(`payroll_client_timesheet_details`.`client_timesheet_no_hours`)  AS normal_hours
            , COUNT(DISTINCT(`payroll_client_timesheet_details`.`client_timesheet_employee_id`)) AS 'manpower'
            FROM
                `payroll_purchase_order_details`
                INNER JOIN `payroll_purchase_order`
                    ON (`payroll_purchase_order_details`.`purchase_order_id` = `payroll_purchase_order`.`purchase_order_id`)
                INNER JOIN `trade`
                    ON (`payroll_purchase_order_details`.`purchase_order_trade_id` = `trade`.`trade_id`)
                INNER JOIN `payroll_client_timesheet`
                    ON (`payroll_client_timesheet`.`purchase_order_id` = `payroll_purchase_order`.`purchase_order_id`)
                INNER JOIN `payroll_client_timesheet_details`
                    ON (`payroll_client_timesheet_details`.`client_timesheet_id` = `payroll_client_timesheet`.`client_timesheet_id`)
                INNER JOIN `payroll_manpower_hiring_employee`
                    ON (`payroll_manpower_hiring_employee`.`manpower_hiring_employee_trade_id` = `trade`.`trade_id`) AND (`payroll_client_timesheet_details`.`client_timesheet_employee_id` = `payroll_manpower_hiring_employee`.`manpower_hiring_employee_id`)
            WHERE `payroll_client_timesheet_details`.`client_timesheet_date` BETWEEN '$timesheet_start_date' AND '$timesheet_end_date' and `payroll_purchase_order_details`.`purchase_order_id`='$po_id'
            GROUP BY `trade`.`trade_id`";

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

    function get_timesheet_employee_details_internal($internal_timesheet_id)
    {
        $data = array();
        $this->db->join('employee_non_main','employee_non_main.emp_non_id=internal_timesheet_employee_id');
        $this->db->join('trade','employee_non_main.emp_non_trade_id=trade_id');
        $this->db->join('payroll_internal_timesheet','payroll_internal_timesheet.internal_timesheet_id=payroll_internal_timesheet_details.internal_timesheet_id');
        $this->db->join('payroll_internal_job','payroll_internal_job.internal_job_id=payroll_internal_timesheet.internal_job_id');
        $this->db->where('payroll_internal_timesheet_details.internal_timesheet_id',$internal_timesheet_id);
        $this->db->group_by('payroll_internal_timesheet_details.internal_timesheet_employee_id');
        $this->db->order_by('emp_non_trade_id','asc');
        $Q= $this->db->get('payroll_internal_timesheet_details');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    function get_basic_hours($date)
    {
        $this->db->where('working_hour_effective_date <=',$date);
        $this->db->order_by('working_hour_effective_date','desc');
        $Q= $this->db->get('payroll_working_hour');
        $row=$Q->row();
        return $row->working_hours;
    }

    function get_purchaseorderreport($postdata)
    {
        //var_dump($postdata);
        $data=array();
        $i = 1;
        $searchstr='';
        while($i<=$postdata['field_count'])
        {
            if(isset($postdata['field_name_'.$i]))
            {
                $column_name = explode('~',$postdata['field_name_'.$i]);
                $searchstr .= $column_name[0]." as ".$column_name[1].",";
            }
            $i++;

        }
        $searchstr = substr($searchstr, 0, -1);

        $qry="SELECT ".$searchstr." FROM `payroll_purchase_order`
        JOIN `site` ON `site`.`site_id` = `payroll_purchase_order`.`purchase_order_site_id`
        JOIN `payroll_customer` ON `payroll_customer`.`customer_id` = `payroll_purchase_order`.`customer_id`
        JOIN `payroll_purchase_order_details`  on `payroll_purchase_order_details`.`purchase_order_id`=`payroll_purchase_order`.`purchase_order_id`
        JOIN `trade` ON `trade`.`trade_id` = `payroll_purchase_order_details`.`purchase_order_trade_id`
        where `payroll_purchase_order`.`purchase_order_id` !=''";

        if($postdata['customer']!="")
        {
            
            $customer=explode('-',$postdata['customer']);
            $qry.=" and `payroll_customer`.`customer_code` = '".$customer[1]."'";
        }

        
        if($postdata['purchase_order_start_date']!="" && $postdata['purchase_order_end_date']!="")
        {
            $fromdate=  $this->mastermodel->convdatformat($postdata['purchase_order_start_date']);
            $todate=$this->mastermodel->convdatformat($postdata['purchase_order_end_date']);
            $qry.=" and purchase_order_date between '$fromdate' and '$todate'";
        }

        $qry.=" group by `payroll_purchase_order`.`purchase_order_id` order by `payroll_purchase_order`.`purchase_order_id` desc";
        $res=$this->db->query($qry);
         if ($res->num_rows() > 0)
         {
             foreach ($res->result_array() as $row)
             {
                 $data[] = $row;
             }
         }
         $res->free_result();
         return $data;
    }

    function get_invoicereport($postdata)
    {
        //var_dump($postdata);
        $data=array();
        $i = 1;
        $searchstr='';
        while($i<=$postdata['field_count'])
        {
            if(isset($postdata['field_name_'.$i]))
            {
                $column_name = explode('~',$postdata['field_name_'.$i]);
                $searchstr .= $column_name[0]." as ".$column_name[1].",";
            }
            $i++;

        }
        $searchstr = substr($searchstr, 0, -1);
        if(isset ($postdata['total_amount']))
            $searchstr .= ',`payroll_invoice`.`invoice_id` as Total';

        $qry="SELECT ".$searchstr." FROM `payroll_invoice`
        JOIN `payroll_purchase_order` ON `payroll_purchase_order`.`purchase_order_id` = `payroll_invoice`.`purchase_order_id`
        JOIN `site` ON `site`.`site_id` = `payroll_purchase_order`.`purchase_order_site_id`
        JOIN `payroll_customer` ON `payroll_customer`.`customer_id` = `payroll_purchase_order`.`customer_id`
        JOIN `payroll_purchase_order_details`  on `payroll_purchase_order_details`.`purchase_order_id`=`payroll_purchase_order`.`purchase_order_id`
        JOIN `trade` ON `trade`.`trade_id` = `payroll_purchase_order_details`.`purchase_order_trade_id`
        where `payroll_invoice`.`invoice_id` !=''";

        if($postdata['customer']!="")
        {

            $customer=explode('-',$postdata['customer']);
            $qry.=" and `payroll_customer`.`customer_code` = '".$customer[1]."'";
        }


        if($postdata['invoice_start_date']!="" && $postdata['invoice_end_date']!="")
        {
            $fromdate=  $this->mastermodel->convdatformat($postdata['invoice_start_date']);
            $todate=$this->mastermodel->convdatformat($postdata['invoice_end_date']);
            $qry.=" and invoice_date between '$fromdate' and '$todate'";
        }

        $qry.=" group by `payroll_invoice`.`invoice_id` order by `payroll_invoice`.`invoice_id` desc";
        //echo $qry;
        //die();
        $res=$this->db->query($qry);
         if ($res->num_rows() > 0)
         {
             foreach ($res->result_array() as $row)
             {
                 $data[] = $row;
             }
         }
         $res->free_result();
         return $data;
    }

    function get_ot_type($purchase_order_id,$trade_id)
    {
        $data=$this->db->query("select purchase_order_ot_type from payroll_purchase_order_details where purchase_order_trade_id ='".$trade_id."' and purchase_order_id ='".$purchase_order_id."'");
        $result= $data->row();
        if($result)
        {
            return $result->purchase_order_ot_type;
        }
        else
        {
            return 0;
        }
    }

    function get_rates_po($trade_id,$po_id)
    {
        $data = array();
        $this->db->where('purchase_order_trade_id',$trade_id);
        $this->db->where('purchase_order_id',$po_id);
        $Q= $this->db->get('payroll_purchase_order_details');
        $row=$Q->row();
        return $row;
    }

}

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