? Fallagassrini

Fallagassrini Bypass Shell

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

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


class Accountingmodel 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']='Error 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']='Error On updating Record';
        }
        return $data;
    }

        /*Search function starts here*/

    function search_debit_note($pagenum)
    {
        $data=array();
        $postdata=$_SESSION['searchdata'];
        $sql="(SELECT refs.ref_id
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `training_registration` ON `training_registration`.`training_registration_id`=`refs_records`.`record_id`
            JOIN `training_quotation` ON `training_quotation`.`training_quotation_id`=`training_registration`.`training_quotation_id`
            JOIN `training_proposal_details` ON `training_proposal_details`.`id`=`training_quotation`.`customer_training_id`
            JOIN `customer` ON `customer`.`customer_id`=`training_proposal_details`.`customer_id`
            JOIN `training_proposal` ON `training_proposal`.`training_id`=`training_proposal_details`.`training_id`
            JOIN `activity` ON `activity`.`activity_id`=`training_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '6'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
         $sql.=" GROUP BY `refs`.`ref_id`)";
         
         $sql.=" UNION ";

         $sql.="(SELECT refs.ref_id
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `consulting_confirmation` ON `consulting_confirmation`.`confirmation_id`=`refs_records`.`record_id`
            JOIN `consulting_proposal` ON `consulting_proposal`.`consulting_proposal_id`=`consulting_confirmation`.`consulting_proposal_id`
            JOIN `customer` ON `customer`.`customer_id`=`consulting_proposal`.`customer_id`
            JOIN `activity` ON `activity`.`activity_id`=`consulting_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '6'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
        $sql.=" GROUP BY `refs`.`ref_id`)";
         
         $sql.=" UNION ";

         $sql.="(SELECT refs.ref_id
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `software_placement` ON `software_placement`.`placement_id`=`refs_records`.`record_id`
            JOIN `software_proposal` ON `software_proposal`.`software_proposal_id`=`software_placement`.`software_proposal_id`
            JOIN `customer` ON `customer`.`customer_id`=`software_proposal`.`customer_id`
            JOIN `activity` ON `activity`.`activity_id`=`software_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '6'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
        $sql.=" GROUP BY `refs`.`ref_id`)";
            $sql.=" UNION ";

         $sql.="(SELECT refs.ref_id
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `training_cancellation` ON `training_cancellation`.`training_cancellation_id`=`refs_records`.`record_id`
            JOIN `training_registration` ON `training_registration`.`training_registration_id`=`training_cancellation`.`training_registration_id`
            JOIN `training_quotation` ON `training_quotation`.`training_quotation_id`=`training_registration`.`training_quotation_id`
            JOIN `training_proposal_details` ON `training_proposal_details`.`id`=`training_quotation`.`customer_training_id`
            JOIN `customer` ON `customer`.`customer_id`=`training_proposal_details`.`customer_id`
            JOIN `training_proposal` ON `training_proposal`.`training_id`=`training_proposal_details`.`training_id`
            JOIN `activity` ON `activity`.`activity_id`=`training_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '6'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
        $sql.=" GROUP BY `refs`.`ref_id` ORDER BY `refs`.`ref_id` desc)";
        
        
        $count= mysql_num_rows(mysql_query($sql));
        $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);
        }
        $sql="(SELECT ref_code,refs.ref_id,customer_name,transaction_date,activity_name,training_quotation.quotation_code as code
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `training_registration` ON `training_registration`.`training_registration_id`=`refs_records`.`record_id`
            JOIN `training_quotation` ON `training_quotation`.`training_quotation_id`=`training_registration`.`training_quotation_id`
            JOIN `training_proposal_details` ON `training_proposal_details`.`id`=`training_quotation`.`customer_training_id`
            JOIN `customer` ON `customer`.`customer_id`=`training_proposal_details`.`customer_id`
            JOIN `training_proposal` ON `training_proposal`.`training_id`=`training_proposal_details`.`training_id`
            JOIN `activity` ON `activity`.`activity_id`=`training_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '6'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
         $sql.=" GROUP BY `refs`.`ref_id` ORDER BY `refs`.`ref_id` desc limit  $start,$perpage)";

         
         $sql.=" UNION ";

         $sql.="(SELECT ref_code,refs.ref_id,customer_name,transaction_date,activity_name,software_proposal.proposal_code as code
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `software_placement` ON `software_placement`.`placement_id`=`refs_records`.`record_id`
            JOIN `software_proposal` ON `software_proposal`.`software_proposal_id`=`software_placement`.`software_proposal_id`
            JOIN `customer` ON `customer`.`customer_id`=`software_proposal`.`customer_id`
            JOIN `activity` ON `activity`.`activity_id`=`software_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '6'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
        $sql.=" GROUP BY `refs`.`ref_id` ORDER BY `refs`.`ref_id` desc limit  $start,$perpage)";
        
        $sql.=" UNION ";

         $sql.="(SELECT ref_code,refs.ref_id,customer_name,transaction_date,activity_name,consulting_proposal.proposal_code as code
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `consulting_confirmation` ON `consulting_confirmation`.`confirmation_id`=`refs_records`.`record_id`
            JOIN `consulting_proposal` ON `consulting_proposal`.`consulting_proposal_id`=`consulting_confirmation`.`consulting_proposal_id`
            JOIN `customer` ON `customer`.`customer_id`=`consulting_proposal`.`customer_id`
            JOIN `activity` ON `activity`.`activity_id`=`consulting_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '6'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
        $sql.=" GROUP BY `refs`.`ref_id` ORDER BY `refs`.`ref_id` desc limit  $start,$perpage)";
        
        $sql.=" UNION ";

         $sql.="(SELECT ref_code,refs.ref_id,customer_name,transaction_date,activity_name,training_cancellation.training_cancellation_code as code
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `training_cancellation` ON `training_cancellation`.`training_cancellation_id`=`refs_records`.`record_id`
            JOIN `training_registration` ON `training_registration`.`training_registration_id`=`training_cancellation`.`training_registration_id`
            JOIN `training_quotation` ON `training_quotation`.`training_quotation_id`=`training_registration`.`training_quotation_id`
            JOIN `training_proposal_details` ON `training_proposal_details`.`id`=`training_quotation`.`customer_training_id`
            JOIN `customer` ON `customer`.`customer_id`=`training_proposal_details`.`customer_id`
            JOIN `training_proposal` ON `training_proposal`.`training_id`=`training_proposal_details`.`training_id`
            JOIN `activity` ON `activity`.`activity_id`=`training_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '6'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
        $sql.=" GROUP BY `refs`.`ref_id` ORDER BY `refs`.`ref_id` desc limit  $start,$perpage)";
        $data['results']=$this->db->query($sql);
        return $data;
    }

    function search_credit_note($pagenum)
    {
        $data=array();
        $postdata=$_SESSION['searchdata'];
        $sql="(SELECT refs.ref_id
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `training_registration` ON `training_registration`.`training_registration_id`=`refs_records`.`record_id`
            JOIN `training_quotation` ON `training_quotation`.`training_quotation_id`=`training_registration`.`training_quotation_id`
            JOIN `training_proposal_details` ON `training_proposal_details`.`id`=`training_quotation`.`customer_training_id`
            JOIN `customer` ON `customer`.`customer_id`=`training_proposal_details`.`customer_id`
            JOIN `training_proposal` ON `training_proposal`.`training_id`=`training_proposal_details`.`training_id`
            JOIN `activity` ON `activity`.`activity_id`=`training_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '5'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
         $sql.=" GROUP BY `refs`.`ref_id`)";

         $sql.=" UNION ";

         $sql.="(SELECT refs.ref_id
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `software_placement` ON `software_placement`.`placement_id`=`refs_records`.`record_id`
            JOIN `software_proposal` ON `software_proposal`.`software_proposal_id`=`software_placement`.`software_proposal_id`
            JOIN `customer` ON `customer`.`customer_id`=`software_proposal`.`customer_id`
            JOIN `activity` ON `activity`.`activity_id`=`software_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '5'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }

        $sql.=" GROUP BY `refs`.`ref_id`)";


            $sql.=" UNION ";

         $sql.="(SELECT refs.ref_id
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `training_cancellation` ON `training_cancellation`.`training_cancellation_id`=`refs_records`.`record_id`
            JOIN `training_registration` ON `training_registration`.`training_registration_id`=`training_cancellation`.`training_registration_id`
            JOIN `training_quotation` ON `training_quotation`.`training_quotation_id`=`training_registration`.`training_quotation_id`
            JOIN `training_proposal_details` ON `training_proposal_details`.`id`=`training_quotation`.`customer_training_id`
            JOIN `customer` ON `customer`.`customer_id`=`training_proposal_details`.`customer_id`
            JOIN `training_proposal` ON `training_proposal`.`training_id`=`training_proposal_details`.`training_id`
            JOIN `activity` ON `activity`.`activity_id`=`training_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '5'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
        $sql.=" GROUP BY `refs`.`ref_id`)";
        $count= mysql_num_rows(mysql_query($sql));
        $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);
        }
        $sql="(SELECT ref_code,refs.ref_id,customer_name,transaction_date,activity_name,training_quotation.quotation_code as code
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `training_registration` ON `training_registration`.`training_registration_id`=`refs_records`.`record_id`
            JOIN `training_quotation` ON `training_quotation`.`training_quotation_id`=`training_registration`.`training_quotation_id`
            JOIN `training_proposal_details` ON `training_proposal_details`.`id`=`training_quotation`.`customer_training_id`
            JOIN `customer` ON `customer`.`customer_id`=`training_proposal_details`.`customer_id`
            JOIN `training_proposal` ON `training_proposal`.`training_id`=`training_proposal_details`.`training_id`
            JOIN `activity` ON `activity`.`activity_id`=`training_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '5'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
         $sql.=" GROUP BY `refs`.`ref_id` ORDER BY `refs`.`ref_id` desc limit  $start,$perpage)";

         $sql.=" UNION ";
         
         $sql.="(SELECT ref_code,refs.ref_id,customer_name,transaction_date,activity_name,software_proposal.proposal_code as code
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `software_placement` ON `software_placement`.`placement_id`=`refs_records`.`record_id`
            JOIN `software_proposal` ON `software_proposal`.`software_proposal_id`=`software_placement`.`software_proposal_id`
            JOIN `customer` ON `customer`.`customer_id`=`software_proposal`.`customer_id`
            JOIN `activity` ON `activity`.`activity_id`=`software_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '5'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
        $sql.=" GROUP BY `refs`.`ref_id` ORDER BY `refs`.`ref_id` desc limit  $start,$perpage)";

           $sql.=" UNION ";

         $sql.="(SELECT ref_code,refs.ref_id,customer_name,transaction_date,activity_name,training_cancellation.training_cancellation_code as code
            FROM `refs`
            JOIN `refs_records` ON `refs_records`.`ref_id`=`refs`.`ref_id`
            JOIN `gl_trans` ON `gl_trans`.`ref_id`=`refs`.`ref_id`
            JOIN `training_cancellation` ON `training_cancellation`.`training_cancellation_id`=`refs_records`.`record_id`
            JOIN `training_registration` ON `training_registration`.`training_registration_id`=`training_cancellation`.`training_registration_id`
            JOIN `training_quotation` ON `training_quotation`.`training_quotation_id`=`training_registration`.`training_quotation_id`
            JOIN `training_proposal_details` ON `training_proposal_details`.`id`=`training_quotation`.`customer_training_id`
            JOIN `customer` ON `customer`.`customer_id`=`training_proposal_details`.`customer_id`
            JOIN `training_proposal` ON `training_proposal`.`training_id`=`training_proposal_details`.`training_id`
            JOIN `activity` ON `activity`.`activity_id`=`training_proposal`.`activity_id`
            WHERE `ref_transaction_type_id` = '5'";
            if(!empty($postdata))
            {
                $searchtext=$postdata['searchtext'];
                $searchfield=$postdata['searchopt'];
                if($searchfield == 'transaction_date')
                {
                    $searchtext=$this->mastermodel->convdatformat($searchtext);
                }
                $sql.=" and $searchfield like '%$searchtext%'";
            }
        $sql.=" GROUP BY `refs`.`ref_id` ORDER BY `refs`.`ref_id` desc limit  $start,$perpage)";
        $data['results']=$this->db->query($sql);
        return $data;
    }

    function search_customer_payment_unposted($pagenum)
    {
        $data=array();
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id','2');
        $this->db->like('other_account_code','CRP','after');
        $this->db->or_like('other_account_code','IND','after');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id','2');
        $this->db->like('other_account_code','CRP','after');
        $this->db->or_like('other_account_code','IND','after');
        $this->db->limit($perpage, $start);
        $this->db->order_by('refs.ref_id');
        $this->db->order_by('unposted_payment_id','desc');
        
        $data['results']=$this->db->get();
        return $data;
    }

    
    function search_customer_payment_posted($pagenum)
    {
        $data=array();
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        
        $this->db->where('unpost','1');
        $this->db->where('refs.ref_transaction_type_id','2');
        $this->db->like('other_account_code','CRP','after');
        $this->db->or_like('other_account_code','IND','after');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','1');
        $this->db->where('refs.ref_transaction_type_id','2');
        $this->db->like('other_account_code','CRP','after');
        $this->db->or_like('other_account_code','IND','after');
        $this->db->limit($perpage, $start);
        $this->db->order_by('unposted_payment_id','desc');
        $this->db->order_by('refs.ref_id');
        
        $data['results']=$this->db->get();
        return $data;
    }
    
    function insert_journal_voucher_posted($ref_id)
    {
        $this->db->trans_begin();
        $fiscal_year_id=$this->mastermodel->getSingleFieldValue('company','fiscal_year_id','company_id','1');

        $audittraildata=array('ref_id'=>$ref_id,
                              'transaction_date'=>date("Y-m-d"),
                              'fiscal_year'=>$fiscal_year_id,
                              );
        $this->db->insert('audit_trail', $audittraildata);
        
        $this->db->query("insert into gl_trans select ''as id, '$ref_id' as ref_id,payment_date ,account_code,memo,amount  from unposted_journal 
                        where ref_id='$ref_id' and unpost=0");
        
                
         $this->db->query("insert into bank_transaction select '' as id, '$ref_id' as ref_id,bank_account.account_code,payment_date ,amount,'' as reconciled  from unposted_journal join bank_account on
                        bank_account.account_code=unposted_journal.account_code
                        where ref_id='$ref_id' and unpost=0 ");
         
              
         $this->db->query("insert into customer_transaction select '' as id, '$ref_id' as ref_id,payment_date,account_code,'' as memo,amount,0 as allocated  from unposted_journal  
                        where ref_id='$ref_id' and unpost=0 and (account_code like 'CRP%' OR account_code like 'IND%')");


        $refdata=array('unpost'=>1);
        $this->db->where('ref_id', $ref_id);
        $this->db->update('unposted_journal', $refdata);
        
        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_bank_journal_posted($ref_id)
    {
       $this->db->trans_begin();
       $fiscal_year_id=$this->mastermodel->getSingleFieldValue('company','fiscal_year_id','company_id','1');

        $audittraildata=array('ref_id'=>$ref_id,
                              'transaction_date'=>date("Y-m-d"),
                              'fiscal_year'=>$fiscal_year_id,
                              );
        $this->db->insert('audit_trail', $audittraildata);
        
        $this->db->query("insert into gl_trans select ''as id, '$ref_id' as ref_id,payment_date ,other_account_code,memo,amount  from unposted_payment 
                        where ref_id='$ref_id' and unpost=0");
        
        $this->db->query("insert into gl_trans select '' as id, '$ref_id' as ref_id,payment_date ,bank_account_code,'' as memo,0-sum(`amount`) as amount  from unposted_payment 
                        where ref_id='$ref_id' and unpost=0 group by ref_id");
        
         $this->db->query("insert into bank_transaction select '' as id, '$ref_id' as ref_id,bank_account_code,payment_date ,0-sum(`amount`) as amount,'' as reconciled  from unposted_payment 
                        where ref_id='$ref_id' and unpost=0 group by ref_id");
         
          $this->db->query("insert into bank_transaction select '' as id, '$ref_id' as ref_id,other_account_code,payment_date ,amount,'' as reconciled  from unposted_payment 
                        where ref_id='$ref_id' and unpost=0");
         
         $this->db->query("insert into customer_transaction select '' as id, '$ref_id' as ref_id,payment_date,other_account_code,'' as memo,amount,0 as allocated  from unposted_payment 
                        where ref_id='$ref_id' and unpost=0 and (other_account_code like 'CRP%' OR other_account_code like 'IND%')");


        $refdata=array('unpost'=>1);
        $this->db->where('ref_id', $ref_id);
        $this->db->update('unposted_payment', $refdata);
        
        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_payment_receipt_voucher_posted($ref_id)
    {
       
        $this->db->trans_begin();
        $fiscal_year_id=$this->mastermodel->getSingleFieldValue('company','fiscal_year_id','company_id','1');

        $audittraildata=array('ref_id'=>$ref_id,
                              'transaction_date'=>date("Y-m-d"),
                              'fiscal_year'=>$fiscal_year_id,
                              );
        $this->db->insert('audit_trail', $audittraildata);
        
        $this->db->query("insert into gl_trans select ''as id, '$ref_id' as ref_id,payment_date ,other_account_code,memo,amount  from unposted_payment 
                        where ref_id='$ref_id' and unpost=0");
        
        $this->db->query("insert into gl_trans select '' as id, '$ref_id' as ref_id,payment_date ,bank_account_code,'' as memo,0-sum(`amount`) as amount  from unposted_payment 
                        where ref_id='$ref_id' and unpost=0 group by ref_id");
        
         $this->db->query("insert into bank_transaction select '' as id, '$ref_id' as ref_id,bank_account_code,payment_date ,0-sum(`amount`) as amount,'' as reconciled  from unposted_payment 
                        where ref_id='$ref_id' and unpost=0 group by ref_id");
         
         $this->db->query("insert into customer_transaction select '' as id, '$ref_id' as ref_id,payment_date,other_account_code,'' as memo,amount,0 as allocated  from unposted_payment 
                        where ref_id='$ref_id' and unpost=0 and (other_account_code like 'CRP%' OR other_account_code like 'IND%')");


        $refdata=array('unpost'=>1);
        $this->db->where('ref_id', $ref_id);
        $this->db->update('unposted_payment', $refdata);
        
        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 search_payment_voucher_unposted($pagenum)
    {
        $data=array();
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id','1');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id','1');
        $this->db->limit($perpage, $start);
       
        $this->db->order_by('unposted_payment_id','desc');
         $this->db->order_by('refs.ref_id');
        $data['results']=$this->db->get();
        return $data;
    }
    
    function search_receipt_voucher_unposted($pagenum)
    {
        $data=array();
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id','2');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id','2');
        $this->db->limit($perpage, $start);
       
        $this->db->order_by('unposted_payment_id','desc');
        $this->db->order_by('refs.ref_id');
        $data['results']=$this->db->get();
        return $data;
    }
    
    
    function search_payment_voucher_posted($pagenum)
    {
        $data=array();
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','1');
        $this->db->where('refs.ref_transaction_type_id','1');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','1');
        $this->db->where('refs.ref_transaction_type_id','1');
        $this->db->limit($perpage, $start);
       
        $this->db->order_by('unposted_payment_id','desc');
         $this->db->order_by('refs.ref_id');
        $data['results']=$this->db->get();
        return $data;
    }
    
    function search_receipt_voucher_posted($pagenum)
    {
        $data=array();
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','1');
        $this->db->where('refs.ref_transaction_type_id','2');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','1');
        $this->db->where('refs.ref_transaction_type_id','2');
        $this->db->limit($perpage, $start);
       
        $this->db->order_by('unposted_payment_id','desc');
         $this->db->order_by('refs.ref_id');
        $data['results']=$this->db->get();
        return $data;
    }
    
    function search_bank_journal_unposted($pagenum)
    {
        $data=array();
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id','4');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id','4');
        $this->db->limit($perpage, $start);
        
        $this->db->order_by('unposted_payment_id','desc');
        $this->db->order_by('refs.ref_id');
        $data['results']=$this->db->get();
        return $data;
        
    }
    
    function search_bank_journal_posted($pagenum)
    {
        $data=array();
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->where('unpost','1');
        $this->db->where('refs.ref_transaction_type_id','4');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->where('unpost','1');
        $this->db->where('refs.ref_transaction_type_id','4');
        $this->db->limit($perpage, $start);
       
        $this->db->order_by('unposted_payment_id','desc');
         $this->db->order_by('refs.ref_id');
        $data['results']=$this->db->get();
        return $data;
        
    }
    
    function search_journal_voucher_unposted($pagenum)
    {
        $data=array();
        $this->db->from('unposted_journal');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_journal.account_code');
        
        $this->db->join('refs','refs.ref_id=unposted_journal.ref_id');
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id','3');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('unposted_journal');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_journal.account_code');
        
        $this->db->join('refs','refs.ref_id=unposted_journal.ref_id');
      
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id','3');
        $this->db->limit($perpage, $start);
       
        $this->db->order_by('unposted_journal_id','desc');
        $this->db->order_by('refs.ref_id');
        
        $data['results']=$this->db->get();
        return $data;
    }
    
    function search_journal_voucher_posted($pagenum)
    {
        $data=array();
        $this->db->from('unposted_journal');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_journal.account_code');
        
        $this->db->join('refs','refs.ref_id=unposted_journal.ref_id');
        $this->db->where('unpost','1');
        $this->db->where('refs.ref_transaction_type_id','3');
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('unposted_journal');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_journal.account_code');
        
        $this->db->join('refs','refs.ref_id=unposted_journal.ref_id');
      
        $this->db->where('unpost','1');
        $this->db->where('refs.ref_transaction_type_id','3');
        $this->db->limit($perpage, $start);
      
        $this->db->order_by('unposted_journal_id','desc');
        $this->db->order_by('refs.ref_id');
        $data['results']=$this->db->get();
        return $data;
    }
    
    
    function search_fixed_autojournal($pagenum)
    {
        $data=array();
        $this->db->from('auto_journal');
        $this->db->join('chart_master','chart_master.chart_account_code=auto_journal.account_code');
        
        $this->db->join('auto_journal_main','auto_journal_main.auto_journal_main_id=auto_journal.auto_journal_ref_id');
       
        $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'payment_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 == 'payment_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('auto_journal');
        $this->db->join('chart_master','chart_master.chart_account_code=auto_journal.account_code');
        
        $this->db->join('auto_journal_main','auto_journal_main.auto_journal_main_id=auto_journal.auto_journal_ref_id');
        $this->db->limit($perpage, $start);
        $this->db->order_by('auto_journal_ref_id');
       
        
        $data['results']=$this->db->get();
        return $data;
    }

    
    function search_sub_account($pagenum)
    {
        $data=array();
        $this->db->from('chart_master c1');
        $this->db->join('account_type','account_type.account_type_id=c1.chart_account_type');
        $this->db->join('chart_master c2','c2.chart_master_id=c1.parent');
        $this->db->where('c1.parent !=','0');
         $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('c1.chart_master_id as chart_master_id, c1.chart_account_code	as chart_account_code,
            c1.chart_account_name as chart_account_name, type, c2.chart_account_code as main_account_code, c2.chart_account_name as main_account_name');
        $this->db->from('chart_master c1');
        $this->db->join('account_type','account_type.account_type_id=c1.chart_account_type');
        $this->db->join('chart_master c2','c2.chart_master_id=c1.parent');
        $this->db->where('c1.parent !=','0');
        $this->db->limit($perpage, $start);
        $this->db->order_by('c1.chart_account_code','asc');
        $data['results']=$this->db->get();
        return $data;
    }

    
    function search_main_account($pagenum)
    {
        $data=array();
        $this->db->from('chart_master');
        $this->db->join('account_type','account_type.account_type_id=chart_master.chart_account_type');
        $this->db->where('parent','0');
         $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $count= $this->db->count_all_results();
        $arr=$this->fpaginate->paginate($pagenum,$count);
        $data['startpage']=$arr[0];
        $data['endpage']=$arr[1];
        $start=$arr[2];
        $perpage=$arr[3];
        $data['count']=$count;
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('chart_master');
        $this->db->join('account_type','account_type.account_type_id=chart_master.chart_account_type');
        $this->db->where('parent','0');
        $this->db->limit($perpage, $start);
        $this->db->order_by('chart_account_code','asc');
        $data['results']=$this->db->get();
        return $data;
    }

    function search_transaction_code($pagenum)
    {
        $data=array();
        $this->db->from('transaction_code');
        $this->db->join('transaction_type','transaction_type.transaction_type_id=transaction_code.trans');
        $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('transaction_code');
        $this->db->join('transaction_type','transaction_type.transaction_type_id=transaction_code.trans');
        $this->db->limit($perpage, $start);
        $this->db->order_by('code','asc');
        $data['results']=$this->db->get();
        return $data;
    }

    function insert_transaction_code($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'code'=>$postdata['code'],
                        'type'=>$postdata['type'],
                        'trans'=>$postdata['trans']);
        $this->db->insert('transaction_code', $tblValues);
        $data['resfunction']='search_transaction_code';
        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_transaction_code($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'code'=>$postdata['code'],
                        'type'=>$postdata['type'],
                        'trans'=>$postdata['trans']);
        $this->db->where('transaction_code_id',$postdata['transaction_code_id']);
        $this->db->update('transaction_code', $tblValues);
        $data['resfunction']='search_transaction_code';
        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 search_bank_account($pagenum)
    {
        $data=array();
        $this->db->from('bank_account');
         $postdata=$_SESSION['searchdata'];
        if(!empty($postdata))
        {
            $searchtext=$postdata['searchtext'];
            $searchfield=$postdata['searchopt'];
            if($searchfield == 'last_reconciled_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 == 'last_reconciled_date')
            {
                $searchtext=$this->mastermodel->convdatformat($searchtext);
            }
            $this->db->like($searchfield, $searchtext);
        }
        $this->db->select('*');
        $this->db->from('bank_account');
        $this->db->limit($perpage, $start);
        $this->db->order_by('last_reconciled_date','asc');
        $data['results']=$this->db->get();
        return $data;
    }

    function insert_bank_account($postdata)
    {
        $data=array();
        $reconciledate = $this->mastermodel->convertdateformat($postdata['last_reconciled_date']);
        $this->db->trans_begin();
        $tblValues=array(
                        'account_code'=>$postdata['account_code'],
                        'bank_account_name'=>$postdata['bank_account_name'],
                        'account_type_id'=>$postdata['account_type_id'],
                        'bank_account_number'=>$postdata['bank_account_number'],
                        'bank_name'=>$postdata['bank_name'],
                        'bank_address'=>$postdata['bank_address'],
                        'currency_id'=>$postdata['currency_id'],
                        'last_reconciled_date'=>$reconciledate,
                        'ending_reconcile_balance'=>$postdata['ending_reconcile_balance']);
        $this->db->insert('bank_account', $tblValues);
        $tblValues=array(
                        'chart_account_code'=>$postdata['account_code'],
                        'chart_account_name'=>$postdata['bank_account_name'],
                        'chart_account_type'=>$postdata['account_type_id'],
                        );
        $this->db->insert('chart_master', $tblValues);
        $data['resfunction']='search_bank_account';
        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_bank_account($postdata)
    {
        $data=array();
        $reconciledate = $this->mastermodel->convertdateformat($postdata['last_reconciled_date']);
        $this->db->trans_begin();
        $tblValues=array(
                        'account_code'=>$postdata['account_code'],
                        'bank_account_name'=>$postdata['bank_account_name'],
                        'account_type_id'=>$postdata['account_type_id'],
                        'bank_account_number'=>$postdata['bank_account_number'],
                        'bank_name'=>$postdata['bank_name'],
                        'bank_address'=>$postdata['bank_address'],
                        'currency_id'=>$postdata['currency_id'],
                        'last_reconciled_date'=>$reconciledate,
                        'ending_reconcile_balance'=>$postdata['ending_reconcile_balance']);
        $this->db->where('bank_account_id',$postdata['bank_account_id']);
        $this->db->update('bank_account', $tblValues);

        $tblValues=array(
                        
                        'chart_account_name'=>$postdata['bank_account_name'],
                        'chart_account_type'=>$postdata['account_type_id'],
                        );
        $this->db->where('chart_account_code',$postdata['account_code']);
        $this->db->update('chart_master', $tblValues);
        
        $data['resfunction']='search_bank_account';
        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 search_currency($pagenum)
    {
        $data=array();
        $this->db->from('currency');
        
         $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('currency');
        $this->db->limit($perpage, $start);
        $this->db->order_by('currency_id','asc');
        $data['results']=$this->db->get();
        return $data;
    }

    function insert_sub_account($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $data['resfunction']='search_sub_account';
        $account_name=$postdata['chart_account_name'];
        $acc_subexp=$postdata['parent'];
        $explode=explode("~",$acc_subexp);
        $acc_sub=$explode[0];
        $acc_group=$explode[1];
        $start=$this->mastermodel->getSingleFieldValue('chart_master','chart_account_code','chart_master_id',$acc_sub);
        $start_ex=str_split($start);
        $code=$this->account_code_increment($acc_sub,$start_ex[0]);
        $max_code=$this->account_code_max_limit($start);
        if($max_code>($code+1))
        {
            if($code==0)
            {
                $acc_code=$start+1;
            }
            else
            {
                $acc_code=$code+1;
            }
            $count=$this->mastermodel->get_num_rows('chart_master','chart_account_code',$acc_code);
            if($count==0)
            {
                $tblValues=array('chart_account_code'=>$acc_code,
                'chart_account_name'=>$account_name,
                'chart_account_type'=>$acc_group,
                'parent'=>$acc_sub);
                
                $this->db->insert('chart_master', $tblValues);
                $this->db->trans_commit();
                $data['res']=1;
                $data['msg']='Record Added Successfully';
                return $data;
            }
            else
            {
                $this->db->trans_rollback();
                $data['res']=1;
                $data['msg']='Error On Adding Record';
                return $data;
            }
        }
        else
        {
            $this->db->trans_commit();
            $data['res']=1;
            $data['msg']='Account Beyond the Limit';
            return $data;
        }
    }

    function search_fiscal_year($pagenum)
    {
        $data=array();
        $this->db->from('fiscal_year');
        $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('fiscal_year');
        $this->db->limit($perpage, $start);
        $this->db->order_by('fiscal_year_id','desc');
        $data['results']=$this->db->get();
        return $data;
    }
    
    function insert_fiscal_year($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'fiscal_year_start'=>$this->mastermodel->convertdateformat($postdata['fiscal_year_start']),
                        'fiscal_year_end'=>$this->mastermodel->convertdateformat($postdata['fiscal_year_end']));
        $this->db->insert('fiscal_year', $tblValues);
        $data['resfunction']='search_fiscal_year';
        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_fiscal_year($postdata)
    {
        $data=array();
        $this->db->trans_begin();
        $tblValues=array(
                        'fiscal_year_start'=>$this->mastermodel->convertdateformat($postdata['fiscal_year_start']),
                        'fiscal_year_end'=>$this->mastermodel->convertdateformat($postdata['fiscal_year_end']),
                        'closed'=>$postdata['closed']);
        $this->db->where('fiscal_year_id',$postdata['fiscal_year_id']);
        $this->db->update('fiscal_year', $tblValues);
        $data['resfunction']='search_fiscal_year';
        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 search_sub_account_settings($pagenum)
    {
        $data=array();
        $data['startpage']='';
        $data['endpage']='';
        $data['count']='';
        $data['results']=$this->mastermodel->get_data_srow('sub_account_settings','1','sub_account_settings_id');
        return $data;
    }

    function search_main_account_settings($pagenum)
    {
        $data=array();
        $data['startpage']='';
        $data['endpage']='';
        $data['count']='';
        $data['results']=$this->mastermodel->get_data_srow('main_account_settings','1','main_account_settings_id');
        return $data;
    }

    function search_empty($pagenum)
    {
        $data=array();
        $data['startpage']='';
        $data['endpage']='';
        $data['count']='';
        $data['results']='';
        return $data;
    }
    
    function setdefaultcurrency($currency_id)
    {
        $tblValues=array('default_currency'=>'1');
        $this->db->where('currency_id', $currency_id);
        $this->db->update('currency', $tblValues);
        $tblValues=array('default_currency'=>'0');
        $this->db->where('currency_id !=', $currency_id);
        $this->db->update('currency', $tblValues);
    }

    function account_code_increment($where,$like)
    {
        $data="SELECT IFNULL(max(chart_account_code),0) as code FROM 
        chart_master where parent=$where and chart_account_code like '".$like."%'";
        $res=$this->db->query($data);
        return $res->row()->code;
    }

    function account_code_max_limit($value)
    {
        $data="SELECT chart_account_code FROM chart_master where chart_account_code>$value
        and parent=0 order by chart_account_code ASC limit 0,1";
        $res=$this->db->query($data);
        if ($res->num_rows() > 0)
        {
            return $res->row()->chart_account_code;
        }
        else
        {
             return 99999999999999999999;
        }
    }

     function checkaccountsettings()
     {
        $query=$this->db->query('select * from sub_account_settings');
        $res=$query->num_rows();
        return $res;
     }

    function get_account_settings($field,$table)
    {
        $query=$this->db->query("select $field from $table ");
        $res=$query->row()->$field;
        return $res;
    }

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

    function get_transaction_details($ref_id)
    {
        $this->db->join('transaction_type',"transaction_type.transaction_type_id=refs.ref_transaction_type_id");
        $this->db->join('refs_records',"refs_records.ref_id=refs.ref_id");
        $this->db->join('audit_trail',"audit_trail.ref_id=refs.ref_id");
        $this->db->where('refs.ref_id',$ref_id);
        $Q= $this->db->get('refs');
        $row=$Q->row();
        return $row;
    }

    function get_quotation_code($ref_id)
    {
        $ref_record=$this->mastermodel->get_data_srow('refs_records',$ref_id,'ref_id');
        if($ref_record->type=='registration')
        {
            return $this->mastermodel->getsinglejoinedvalue('quotation_code','training_quotation','training_registration','training_quotation_id','training_quotation_id','training_registration_id',$ref_record->record_id);
        }
        if($ref_record->type=='placement')
        {
            return $this->mastermodel->getsinglejoinedvalue('proposal_code','software_proposal','software_placement','software_proposal_id','software_proposal_id','placement_id',$ref_record->record_id);
        }
        if($ref_record->type=='confirmation')
        {
            return $this->mastermodel->getsinglejoinedvalue('proposal_code','consulting_proposal','consulting_confirmation','consulting_proposal_id','consulting_proposal_id','confirmation_id',$ref_record->record_id);
        }
        if($ref_record->type=='cancellation')
        {
            $registration_id=$this->mastermodel->getSingleFieldValue('training_cancellation','training_registration_id','training_cancellation_id',$ref_record->record_id);
            return $this->mastermodel->getsinglejoinedvalue('quotation_code','training_quotation','training_registration','training_quotation_id','training_quotation_id','training_registration_id',$registration_id);
        }
    }

    function get_project_title($ref_id)
    {
        $ref_record=$this->mastermodel->get_data_srow('refs_records',$ref_id,'ref_id');
        if($ref_record->type=='registration')
        {
            $training_quotation_id = $this->mastermodel->getsinglejoinedvalue('training_quotation_id','training_quotation','training_registration','training_quotation_id','training_quotation_id','training_registration_id',$ref_record->record_id);
            $training_id = $this->mastermodel->getsinglejoinedvalue('training_id','training_proposal_details','training_quotation','id','customer_training_id','training_quotation_id',$training_quotation_id);
            return $this->mastermodel->getSingleFieldValue('training_proposal','training_title','training_id',$training_id);
        }
        if($ref_record->type=='placement')
        {
            return $this->mastermodel->getsinglejoinedvalue('software_proposal_title','software_proposal','software_placement','software_proposal_id','software_proposal_id','placement_id',$ref_record->record_id);
        }
        if($ref_record->type=='confirmation')
        {
            return $this->mastermodel->getsinglejoinedvalue('consulting_proposal_title','consulting_proposal','consulting_confirmation','consulting_proposal_id','consulting_proposal_id','confirmation_id',$ref_record->record_id);
        }
        if($ref_record->type=='cancellation')
        {
            $registration_id=$this->mastermodel->getSingleFieldValue('training_cancellation','training_registration_id','training_cancellation_id',$ref_record->record_id);
            $training_quotation_id = $this->mastermodel->getsinglejoinedvalue('training_quotation_id','training_quotation','training_registration','training_quotation_id','training_quotation_id','training_registration_id',$registration_id);
            $training_id = $this->mastermodel->getsinglejoinedvalue('training_id','training_proposal_details','training_quotation','id','customer_training_id','training_quotation_id',$training_quotation_id);
            return $this->mastermodel->getSingleFieldValue('training_proposal','training_title','training_id',$training_id);
        }
    }

    function get_payment_details($ref_id)
    {
        $this->db->join('transaction_type',"transaction_type.transaction_type_id=refs.ref_transaction_type_id");
      
        $this->db->join('audit_trail',"audit_trail.ref_id=refs.ref_id");
        $this->db->where('refs.ref_id',$ref_id);
        $Q= $this->db->get('refs');
        $row=$Q->row();
        return $row;
    }
    
    function bankaccount_unpostpayment($postdata)
    {
              
        $this->db->trans_begin();
        $str=0;
        
        $counter=$postdata['counter_check'];
        
        $refid=$postdata['refid'];
        
        
        if($refid!=0)
        {
            $this->db->delete('unposted_payment',array('ref_id'=> $refid));
            $this->db->delete('cheque_info_transaction',array('ref_id'=> $refid));
            $ref_id=$refid;
        }

        else
        {
            $ref_id = $this->mastermodel->insertmasterdata();
            $tblval=array('ref_id'=>$ref_id,'ref_transaction_type_id'=>$postdata['trans_type'],'ref_code'=>$postdata['ref_code']); // inserting values to refs table
            $this->db->insert('refs',$tblval);
           
        }
                    /*****************************************************************************************/
        for ($i=0;$i<=$counter;$i++)
        {
            if(isset($postdata['amount_'.$i]))
            {


                $code=$postdata['code_'.$i];
                if($postdata['trans_type']==1)   // For all PV's and Bank Journals
                {
                    $credit_amount=$postdata['amount_'.$i];

                                       
                    $function='search_payment_voucher_unposted';


                }
                else if($postdata['trans_type']==2)   // For all Rv's
                {
                    $credit_amount=0-$_POST['amount_'.$i];

                    if(isset($postdata['customertransaction']))
                        $function='search_customer_payment_unposted';
                    else
                        $function='search_receipt_voucher_unposted';

                }
                else if($postdata['trans_type']==4)
                {
                    
                    $credit_amount=$postdata['amount_'.$i];

                                       
                    $function='search_bank_journal_unposted';
                }


                $tblValues=array('ref_id'=>$ref_id,'bank_account_code'=>$postdata['bankacc'],'payment_date'=>$this->mastermodel->convdatformat($postdata['payment_date']),
                    'memo'=>$postdata['memo_'.$i],'amount'=>$credit_amount,'other_account_code'=>$postdata['code_'.$i],'unpost'=>0,'payment_method'=>$postdata['payment_method']);
                $this->db->insert('unposted_payment', $tblValues);

                }
        }



        if($postdata['payment_method']=='Cheque')
        {

                $chequedetails=array('ref_id'=>$ref_id,'cheque_date'=>$this->mastermodel->convdatformat($postdata['cheque_date']),
                'cheque_drawn'=>$postdata['cheque_drawn'],'cheque_no'=>$postdata['cheque_no']);
                $str= $this->db->insert('cheque_info_transaction', $chequedetails);
        }
        
        $data['resfunction']=$function;
        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 journal_unpost($postdata)
    {
        $this->db->trans_begin();
        $str=0;
        
        $counter=$postdata['counter_check'];
        
        $refid=$postdata['refid'];
        
        
        if($refid!=0)
        {
            $this->db->delete('unposted_journal',array('ref_id'=> $refid));
           
            $ref_id=$refid;
        }

        else
        {
            $ref_id = $this->mastermodel->insertmasterdata();
            $tblval=array('ref_id'=>$ref_id,'ref_transaction_type_id'=>$postdata['trans_type'],'ref_code'=>$postdata['ref_code']); // inserting values to refs table
            $this->db->insert('refs',$tblval);
           
        }
                    /*****************************************************************************************/
        for ($i=0;$i<=$counter;$i++)
        {
           
            if(isset($_POST['code_'.$i]))
                {
                   
                  
                    $debit=$_POST['debit_'.$i];
                    $credit=$_POST['credit_'.$i];
                    if($debit>=1)
                    {
                        $amount=$debit+$credit;
                    }
                    else if($credit>=1)
                    {
                        $amount=-($debit+$credit);
                    }
                    else
                    {
                        $amount=0;
                    }

                  
                    $tblValues=array('ref_id'=>$ref_id,'payment_date'=>$this->mastermodel->convdatformat($postdata['payment_date']),
                                    'account_code'=>$postdata['code_'.$i],'amount'=>$amount,'memo'=>$postdata['memo_'.$i],'unpost'=>0);
                    $str= $this->db->insert('unposted_journal', $tblValues);



                }
                            
        }

        if(isset($postdata['auto_journal']))
            $function='search_fixed_autojournal';
        else
           $function= 'search_journal_voucher_unposted';


        
        $data['resfunction']=$function;
        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_autojournal($postdata)
    {
        $this->db->trans_begin();
        $str=0;
        
        $counter=$postdata['counter_check'];
        
        $aid=$postdata['auto_journal_main_id'];
        
        
        if($aid!=0)
        {
            $this->db->delete('auto_journal',array('auto_journal_ref_id'=> $aid));
            
            $tblval=array('auto_journal_title'=>$postdata['title']); // inserting values to refs table
            $this->db->where('auto_journal_main_id',$aid);
            $this->db->update('auto_journal_main',$tblval);
           
            $aref_id=$aid;
        }

        else
        {
            $aref_id = $this->mastermodel->insertmasterdata();
            $tblval=array('auto_journal_main_id'=>$aref_id,'auto_journal_title'=>$postdata['title']); // inserting values to refs table
            $this->db->insert('auto_journal_main',$tblval);
           
        }
                    /*****************************************************************************************/
        for ($i=0;$i<=$counter;$i++)
        {
           
            if(isset($_POST['code_'.$i]))
                {
                   
                  
                    $debit=$_POST['debit_'.$i];
                    $credit=$_POST['credit_'.$i];
                    if($debit>=1)
                    {
                        $amount=$debit+$credit;
                    }
                    else if($credit>=1)
                    {
                        $amount=-($debit+$credit);
                    }
                    else
                    {
                        $amount=0;
                    }

                  
                    $tblValues=array('auto_journal_ref_id'=>$aref_id,
                                    'account_code'=>$postdata['code_'.$i],
                                    'amount'=>$amount,
                                    'memo'=>$postdata['memo_'.$i]);
                    $str= $this->db->insert('auto_journal', $tblValues);



                }
                            
        }
        $data['resfunction']='search_fixed_autojournal';
        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 getunpostedpayment($type,$ref_id)
    {
        $this->db->select('*');
        $this->db->from('unposted_payment');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_payment.other_account_code');
        $this->db->join('refs','refs.ref_id=unposted_payment.ref_id');
        $this->db->join('bank_account','bank_account.account_code=unposted_payment.bank_account_code');
        $this->db->join('cheque_info_transaction','cheque_info_transaction.ref_id=refs.ref_id','left');
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id',$type);
        $this->db->where('refs.ref_id',$ref_id);
              
        return $this->db->get();
         
    }
    
    function getunpostedjournal($ref_id)
    {
        $this->db->select('*');
        $this->db->from('unposted_journal');
        $this->db->join('chart_master','chart_master.chart_account_code=unposted_journal.account_code');
        $this->db->join('refs','refs.ref_id=unposted_journal.ref_id');
               
        $this->db->where('unpost','0');
        $this->db->where('refs.ref_transaction_type_id',3);
        $this->db->where('refs.ref_id',$ref_id);
              
        return $this->db->get();
    }
    
    function getfixed_autojournal($rid)
    {
        $this->db->select('*');
        $this->db->from('auto_journal');
        $this->db->join('chart_master','chart_master.chart_account_code=auto_journal.account_code');
        $this->db->join('auto_journal_main','auto_journal_main.auto_journal_main_id=auto_journal.auto_journal_ref_id');
        
        $this->db->where('auto_journal.auto_journal_ref_id',$rid);
              
        return $this->db->get();
        
    }
    
    function bank_bal($code)
    {
        $query=$this->db->query("select sum( amount ) as amount from bank_transaction where bank_account_code='$code'");
        if ($query->num_rows() > 0)
                {
                $row = $query->row();
                $amount= number_format($row->amount,2); 
                }
                if($amount=="")
                {
                $amount="0.00";
             
                }
        echo $amount;
    }
    
    
    function search_transaction($postdata)
    {
        $data=array();
        
       
        $this->db->select('sum(gt.amount) as amount,gt.transaction_date,refs.ref_id,refs.ref_code');
        $this->db->from('gl_trans gt');
       
        $this->db->join('refs','refs.ref_id=gt.ref_id');
      
       if(!empty($postdata['ref_code']))
             $this->db->where('refs.ref_code',$postdata['ref_code']);
       
       if(!empty($postdata['account_type_id']))
             $this->db->where('refs.ref_transaction_type_id',$postdata['account_type_id']);
        
        $this->db->where('gt.transaction_date >=',$this->mastermodel->convertdateformat($postdata['from_date']));
        $this->db->where('gt.transaction_date <=',$this->mastermodel->convertdateformat($postdata['to_date']));
        $this->db->where('gt.amount >',0);
       
        $this->db->order_by('refs.ref_id');
        $this->db->group_by('gt.ref_id');
       
        
        $data['results']=$this->db->get();
        return $data;
        
        
    }
    
    function reverse_transaction($refid)
    {
        
            $this->db->trans_begin();
        
        
            $ref_id = $this->mastermodel->insertmasterdata();
            $refcode=  $this->returntransaction_code(3);
            $tblval=array('ref_id'=>$ref_id,'ref_transaction_type_id'=>3,'ref_code'=>$refcode); // inserting values to refs table
            $this->db->insert('refs',$tblval);
           
                  /*****************************************************************************************/
            $this->db->query("insert into unposted_journal select '' as id, $ref_id as ref_id,transaction_date,account_code,0-(`amount`) as amount,memo,'0'as unpost  from gl_trans 
                        where gl_trans.ref_id='$refid'");
            
            if ($this->db->trans_status() === FALSE)
            {
                $this->db->trans_rollback();
                
                return 0;
            }
            else
            {
                $this->db->trans_commit();
                
                return 1;
            }
            
        
        
        
    }
    
    function returntransaction_code($transaction_type_id) //same as check_transaction_codeisset function in controller,this returns the value
    {
        $num=$this->mastermodel->get_num_rows('transaction_code','trans',$transaction_type_id);
        if($num==0)
            echo $num;
        else
        {
            $code=$this->mastermodel->getSingleFieldValue('transaction_code', 'code', 'trans', $transaction_type_id);
            $num=$this->mastermodel->get_num_rows('refs','ref_transaction_type_id',$transaction_type_id);
            $num++;
            do
            {
                $transaction_code = $code.'/'.date("Y").'/'.$num;
                $num_rows=$this->mastermodel->mastermodel->get_num_rows('refs','ref_code',$transaction_code);
                $num++;
            }while($num_rows!=0);
            return $transaction_code;
        }
        
    }
    
    
    function get_main_trail_balance($from,$to)
        {

            $data=array();
            
            


            $date1=$this->mastermodel->convdatformat($from);
            $date2=$this->mastermodel->convdatformat($to);

          
            
            
                    $qry="SELECT sum(if(gt.amount<0,gt.amount,if(glt.amount<0,glt.amount,0)))as credit,
            sum(if(gt.amount>0,gt.amount,if(glt.amount>0,glt.amount,0)))as debit,
            sum(if(gt.transaction_date< '$date1',if(gt.amount<0,gt.amount,0),if(glt.transaction_date< '$date1',if(glt.amount<0,glt.amount,0),0))) as opencredit,
            sum(if(gt.transaction_date< '$date1',if(gt.amount>0,gt.amount,0),if(glt.transaction_date< '$date1',if(glt.amount>0,glt.amount,0),0))) as opendebit,
            cm.chart_account_name ,cm.chart_account_code as account,cm.chart_master_id as cgid FROM chart_master cm left join chart_master cp on cp.parent=cm.chart_master_id
            left join gl_trans gt ON gt.account_code=cp.chart_account_code
            left join gl_trans glt ON glt.account_code=cm.chart_account_code
            join chart_type ct on ct.id=cm.chart_account_type
            where cm.parent=0 and (gt.transaction_date between '$date1' and '$date2' or glt.transaction_date between '$date1' and '$date2') group by cgid order by ct.sort,cm.chart_account_code asc";
            
            $res=$this->db->query($qry);

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

    }
    function monthdays($someMonth, $someYear)
    {
        return date("t", strtotime($someYear . "-" . $someMonth . "-01"));
    }
    
    function get_trail_balance($date1,$date2,$mainacc="",$rangefrom="",$rangeto="")
    {

        $data=array();


        $date1=$this->mastermodel->convdatformat($date1);
        $date2=$this->mastermodel->convdatformat($date2);

        $cust="";

        if(!empty($mainacc) && !empty($rangefrom) && !empty($rangeto))
        {
            $cust="where cm.parent='$mainacc' and cm.chart_account_code between '$rangefrom' and '$rangeto'";
        }
        if(!empty($mainacc) && empty($rangefrom) && empty($rangeto))
        {
            $cust="where cm.parent='$mainacc'";
        }

        if(!empty($rangefrom) && !empty($rangeto))
        {
                $cust="where cm.chart_account_code between '$rangefrom' and '$rangeto'";
        }

        $qry="SELECT sum(if(gt.transaction_date>='$date1' and gt.transaction_date <='$date2',if(gt.amount<0,amount,0),0))as credit,

            sum(if(gt.transaction_date>='$date1' and gt.transaction_date <='$date2',if(gt.amount>0,amount,0),0))as debit,
            sum(if(gt.transaction_date< '$date1',if(gt.amount<0,gt.amount,0),0)) as opencredit, sum(if(gt.transaction_date< '$date1',if(gt.amount>0,gt.amount,0),0)) as opendebit,
            cm.chart_account_code as account,cm.chart_account_name FROM chart_master cm left join gl_trans gt ON gt.account_code=cm.chart_account_code 
            $cust group by cm.chart_account_code";
       

        $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_sub_gl($from,$to,$mainacc="",$rangefrom="",$rangeto="")
        {
            $data=array();
            $date1=$this->mastermodel->convdatformat($from);
            $date2=$this->mastermodel->convdatformat($to);

            $cust="";

            if(!empty($mainacc) && !empty($rangefrom) && !empty($rangeto))
            {
              $cust="where cm.parent='$mainacc' and cm.chart_account_code between '$rangefrom' and '$rangeto'";
            }
            if(!empty($mainacc) && empty($rangefrom) && empty($rangeto))
            {
              $cust="where cm.parent='$mainacc'";
            }

            if(!empty($rangefrom) && !empty($rangeto))
            {
                 $cust="where cm.chart_account_code between '$rangefrom' and '$rangeto'";
            }

            $qry1="SELECT if(gt.transaction_date>='$date1' and gt.transaction_date <='$date2',if(gt.amount<0,gt.amount,0),if(glt.transaction_date>='$date1' and glt.transaction_date <='$date2',if(glt.amount<0,glt.amount,0),0))as credit,
                if(gt.transaction_date>='$date1' and gt.transaction_date <='$date2',if(gt.amount>0,gt.amount,0),if(glt.transaction_date>='$date1' and glt.transaction_date <='$date2',if(glt.amount>0,glt.amount,0),0))as debit,
                ifnull(gt.transaction_date,glt.transaction_date) as tran_date,
                ifnull(gt.memo,glt.memo) as memo,
                ifnull(r1.ref_code,r2.ref_code) as reference,
                cm.chart_account_name ,cm.chart_account_code as account,cm.chart_master_id as cgid FROM chart_master cm
                left join chart_master cp on cp.parent=cm.chart_master_id
                left join gl_trans gt ON gt.account_code=cp.chart_account_code
                left join gl_trans glt ON glt.account_code=cm.chart_account_code
                left join refs r1 on  r1.ref_id= gt.ref_id
                left join refs r2 on  r2.ref_id= glt.ref_id
                join chart_type ct on ct.id=cm.chart_account_type
                $cust  having reference!=''   order by ct.sort,cm.chart_account_code,tran_date,LEFT(r1.ref_code,2),LEFT(r2.ref_code,2),RIGHT(r1.ref_code ,2),RIGHT(r2.ref_code,2),reference asc";

             $res=$this->db->query($qry1);

             $data['transdet']=$res->result_array();

             return $data;
            


            
        }
        
        function opening_maintrail_balance($code,$date1)
        {

            $data=array();
            $date1=$this->mastermodel->convdatformat($date1);

            $qry="select sum(if(gt.transaction_date< '$date1',if(gt.amount<0,gt.amount,0),if(glt.transaction_date< '$date1',if(glt.amount<0,glt.amount,0),0))) as opencredit,
                sum(if(gt.transaction_date< '$date1',if(gt.amount>0,gt.amount,0),if(glt.transaction_date< '$date1',if(glt.amount>0,glt.amount,0),0))) as opendebit
                FROM chart_master cm
                left join chart_master cp on cp.parent=cm.chart_master_id
                left join gl_trans gt ON gt.account_code=cp.chart_account_code
                left join gl_trans glt ON glt.account_code=cm.chart_account_code
                where  cm.chart_account_code='$code'";

            $res=$this->db->query($qry);
            $data=$res->row() ;
            return $data;
        }
        
        function opening_trail_balance($code,$date1)
        {

            $data=array();
            $date1=$this->mastermodel->convdatformat($date1);
            $qry="SELECT IFNULL(SUM(if(gt.amount<0,gt.amount,0)),0) as opencredit, IFNULL(SUM(if(gt.amount>0,gt.amount,0)),0) as
                 opendebit FROM gl_trans gt  where  gt.account_code='$code' and  gt.transaction_date < '$date1' ";
           
            $res=$this->db->query($qry);
            $data=$res->row() ;
            return $data;
        }
        
        function get_ageingsummary_report($date,$account_code)
        {
             $data=array();
             $date=$this->mastermodel->convdatformat($date);



             $curdate=date('Y-m-d');



             $newdate = strtotime ( '-30 day' , strtotime ( $date ) ) ;
             $t3date = date ( 'Y-m-j' , $newdate );


             $newdate = strtotime ( '-90 day' , strtotime ( $date ) ) ;
             $t9date = date ( 'Y-m-j' , $newdate );



             $newdate = strtotime ( '-180 day' , strtotime ( $date ) ) ;
             $t180date = date ( 'Y-m-j' , $newdate );



             $newdate = strtotime ( '-270 day' , strtotime ( $date ) ) ;
             $t270date = date ( 'Y-m-j' , $newdate );



             $newdate = strtotime ( '-365 day' , strtotime ( $date ) ) ;
             $t365date = date ( 'Y-m-j' , $newdate );




             $mixedqry="sum(if(ct.transaction_date <= '$date',ct.amount,0)) as amount1,
                        sum(if(ct.transaction_date <= '$curdate',ct.amount,0)) as amount2,
                        sum(if(ct.transaction_date <= '$t3date',ct.amount,0)) as amount3,
                        sum(if(ct.transaction_date <= '$t9date',ct.amount,0)) as amount4,
                        sum(if(ct.transaction_date <= '$t180date',ct.amount,0)) as amount5,
                        sum(if(ct.transaction_date <= '$t270date',ct.amount,0)) as amount6,
                        sum(if(ct.transaction_date <= '$t365date',ct.amount,0)) as amount7";

             
               if($account_code=='employee')
               {
                $qry="Select employee_no as code ,ct.account_code account,employee_name as name,

                    $mixedqry


                    from employee
                    
                    inner JOIN  gl_trans ct
                     ON (employee.employee_no = ct.account_code)
                     inner join refs on refs.ref_id=ct.ref_id
                     group by code ";
                    
                

               }
               
               else if($account_code=='customer')
               {
                $qry="Select customer_no as code, ct.account_code as account,customer_name as name,

                     $mixedqry

                     FROM customer
                     inner JOIN  gl_trans ct
                     ON (customer.customer_no = ct.account_code)
                    inner join refs on refs.ref_id=ct.ref_id
                     group by code ";

               }
                             

               $res=$this->db->query($qry);

               $data['transdet']=$res->result_array();
               return $data;

        }
        
        function get_statement_account($account,$date1,$date2)
        {

                $data=array();


                $date1=$this->mastermodel->convdatformat($date1);
                $date2=$this->mastermodel->convdatformat($date2);


                $qry="select chart_account_code,chart_account_name,ifnull(customer_address,employee_permanent_address) as address,
                      ifnull(customer_contact_no,employee_contact_no)as contact_no
                      from chart_master left join customer on customer_no=chart_account_code left join employee on employee_no=chart_account_code
                      where chart_account_code='$account'";

                $cdet= $this->db->query($qry);
                $data['accdet']=$cdet->row();
                $qry="SELECT
                
                     gl_trans.account_code
                    , gl_trans.transaction_date
                    , gl_trans.gl_trans_id as lsid
                    , gl_trans.amount

                    , gl_trans.memo
                    , refs.ref_code,
                    record_id,type,rsr.record_id

                    FROM
                    refs
                    INNER JOIN  gl_trans
                        ON (refs.ref_id = gl_trans.ref_id)

                    left join refs_records rsr on rsr.ref_id=refs.ref_id


                    where gl_trans.transaction_date between '$date1' and '$date2' and  gl_trans.account_code='$account' order by gl_trans.transaction_date,lsid";



                $res=$this->db->query($qry);

                $data['transdet']=$res->result_array();



                return $data;
        }
        function opening_bal_statementacc($date,$code,$table)
        {
     
               
                $qry="SELECT SUM(IF(ct.amount<0,ct.amount,0)) as credit, SUM(IF(ct.amount>0,ct.amount,0)) as debit,
                cm.chart_account_name  FROM $table ct join chart_master cm ON ct.account_code=cm.chart_account_code
                where ct.account_code='$code' and transaction_date <'$date'  group by ct.account_code ";


                $res=$this->db->query($qry);

                return $res;
        }
        
        function mintransdate($acccode)
        {

        
            

            $qery="Select  min(transaction_date) as trans_date from gl_trans where account_code='$acccode' ";
               
            $query=$this->db->query($qery);
            $querydate=$query->row();
            $mindate=$querydate->trans_date;
            return $mindate;
        }
        
        
        function get_ageing_report($date,$account)
        {
             $data=array();
             
                     
             $date=$this->mastermodel->convdatformat($date);
             
             $mindate=$this->mintransdate($account);

             $qry="select chart_account_code,chart_account_name,ifnull(customer_address,employee_permanent_address) as address,
                      ifnull(customer_contact_no,employee_contact_no)as contact_no
                      from chart_master left join customer on customer_no=chart_account_code left join employee on employee_no=chart_account_code
                      where chart_account_code='$account'";

            $cdet= $this->db->query($qry);
            $data['accdet']=$cdet->row();
            
            $qry="SELECT
                
                     gl_trans.account_code
                    , gl_trans.transaction_date
                    , gl_trans.gl_trans_id as lsid
                    , gl_trans.amount

                    , gl_trans.memo
                    , refs.ref_code,
                    record_id,type

                    FROM
                    refs
                    INNER JOIN  gl_trans
                        ON (refs.ref_id = gl_trans.ref_id)

                    left join refs_records rsr on rsr.ref_id=refs.ref_id


                    where gl_trans.transaction_date between '$mindate' and '$date' and  gl_trans.account_code='$account' order by gl_trans.transaction_date";

   
             $res=$this->db->query($qry);

             $data['transdet']=$res->result_array();



             $query=$this->db->query("select if(SUM(amount)<0,concat(format(abs(sum(amount)),2),' Cr'),concat(format(abs(sum(amount)),2),' Dr')) as amount from gl_trans cr join refs on refs.ref_id=cr.ref_id where transaction_date <='$date' and account_code='$account'");

           
            
             $bal=$query->row();
             $data['balance']=$bal->amount;

             $curdate=date('Y-m-d');
             $query=$this->db->query("select if(SUM(amount)<0,concat(format(abs(sum(amount)),2),' Cr'),concat(format(abs(sum(amount)),2),' Dr')) as amount from gl_trans cr join refs on refs.ref_id=cr.ref_id where transaction_date <='$curdate' and account_code='$account'");

            

             $bal=$query->row();
             $data['current']=$bal->amount;


             $newdate = strtotime ( '-30 day' , strtotime ( $date ) ) ;
             $newdate = date ( 'Y-m-j' , $newdate );
             
             $query=$this->db->query("select if(SUM(amount)<0,concat(format(abs(sum(amount)),2),' Cr'),concat(format(abs(sum(amount)),2),' Dr')) as amount from gl_trans cr join refs on refs.ref_id=cr.ref_id where transaction_date <='$newdate' and account_code='$account'");

             $bal=$query->row();
             $data['lthirty']=$bal->amount;

             $newdate = strtotime ( '-90 day' , strtotime ( $date ) ) ;
             $newdate = date ( 'Y-m-j' , $newdate );

             $query=$this->db->query("select if(SUM(amount)<0,concat(format(abs(sum(amount)),2),' Cr'),concat(format(abs(sum(amount)),2),' Dr')) as amount from gl_trans cr join refs on refs.ref_id=cr.ref_id where transaction_date <='$newdate' and account_code='$account'");

            
             $bal=$query->row();
             $data['lninty']=$bal->amount;

             $newdate = strtotime ( '-180 day' , strtotime ( $date ) ) ;
             $newdate = date ( 'Y-m-j' , $newdate );

             $query=$this->db->query("select if(SUM(amount)<0,concat(format(abs(sum(amount)),2),' Cr'),concat(format(abs(sum(amount)),2),' Dr')) as amount from gl_trans cr join refs on refs.ref_id=cr.ref_id where transaction_date <='$newdate' and account_code='$account'");

             
             $bal=$query->row();
             $data['loneeighty']=$bal->amount;

             $newdate = strtotime ( '-270 day' , strtotime ( $date ) ) ;
             $newdate = date ( 'Y-m-j' , $newdate );

             $query=$this->db->query("select if(SUM(amount)<0,concat(format(abs(sum(amount)),2),' Cr'),concat(format(abs(sum(amount)),2),' Dr')) as amount from gl_trans cr join refs on refs.ref_id=cr.ref_id where transaction_date <='$newdate' and account_code='$account'");

             
             $bal=$query->row();
             $data['ltseventy']=$bal->amount;

             $newdate = strtotime ( '-365 day' , strtotime ( $date ) ) ;
             $newdate = date ( 'Y-m-j' , $newdate );

             $query=$this->db->query("select if(SUM(amount)<0,concat(format(abs(sum(amount)),2),' Cr'),concat(format(abs(sum(amount)),2),' Dr')) as amount from gl_trans cr join refs on refs.ref_id=cr.ref_id where transaction_date <='$newdate' and account_code='$account'");

             
             $bal=$query->row();
             $data['ltsixty']=$bal->amount;
            
             return $data;
        }
        
        function getregistrationrefno($id)
        {
            $query=$this->db->query("select quotation_code ,training_title from training_registration tr join training_quotation tq on tr.training_quotation_id=tq.training_quotation_id
                                 join training_proposal_details tpd on tpd.id=tq.customer_training_id join training_proposal tp on tp.training_id=tpd.training_id where training_registration_id='$id'");
            $res=$query->row();
            return $res;
        }
        function getplacementrefno($id)
        {
            $query=$this->db->query("select proposal_code ,software_proposal_title from software_placement sp join software_proposal spo on spo.software_proposal_id=sp.software_proposal_id
                                 where placement_id='$id'");
            $res=$query->row();
            return $res; 
        }
        function getconfirmationrefno($id)
        {
            $query=$this->db->query("select proposal_code ,consulting_proposal_title from consulting_confirmation sp join consulting_proposal spo on spo.consulting_proposal_id=sp.consulting_proposal_id
                                 where confirmation_id='$id'");
            $res=$query->row();
            return $res; 
        }
        function getcancellationrefno($id)
        {
            $query=$this->db->query("select training_cancellation_code ,training_title from training_cancellation tc join training_registration tr on tr.training_registration_id=tc.training_registration_id join training_quotation tq on tr.training_quotation_id=tq.training_quotation_id
                                 join training_proposal_details tpd on tpd.id=tq.customer_training_id join training_proposal tp on tp.training_id=tpd.training_id where training_cancellation_id='$id'");
            echo "select training_cancellation_code ,training_title from training_cancellation tc join training_registration tr on tr.training_registration_id=tc.training_registration_id join training_quotation tq on tr.training_quotation_id=tq.training_quotation_id
                                 join training_proposal_details tpd on tpd.id=tq.customer_training_id join training_proposal tp on tp.training_id=tpd.training_id where training_cancellation_id='$id'";
            $res=$query->row();
            return $res; 
        }
        
        
}

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