<?php

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

class Gltransaction extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model('Useraccess');
        $query = $this->Useraccess->useraccess_id_module2('1', 'transaction');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $this->load->library('layouts');
        $this->load->model('menu');
    }

    public function index() {
        
    }

    public function journal() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRJRNL');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        if ($this->input->post('mysubmit')) {
            
        } else {
            $data = '';
            $this->load->library('table');
            $this->lang->load("journal", $this->session->userdata('language'));
            $this->load->model('Chartofaccount');
            $data['chartAccounts'] = $this->Chartofaccount->chartofaccount_all();
            $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')
                    ->add_includes('js/validationengine/jquery.validationEngine.js')
                    ->add_includes('js/datatables/jquery.dataTables.min.js');
            $data['datatbls'] = NULL;
            $this->layouts->view('gl/transactions/journal_new', array('latest' => 'sidebar/latest'), $data);
        }
    }

    //Add GST Journal
    public function gstjournal() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRJRNL');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        if ($this->input->post('based_amount')) {
            $this->load->model('Glseq');
            $reverse = $this->input->post('reverse');
            $journalHdr = array(
                "companyID" => element('compID', $this->session->userdata('logged_in')),
                "formNo" => $this->input->post('formNo'),
                "vendor_cust_name" => $this->input->post('vendor_cust_name'),
                "type" => $this->input->post('type'),
                "gst_number" => $this->input->post('gst_number'),
                "Description" => $this->input->post('Description'),
                "date" => date('Y-m-d', strtotime($this->input->post('date'))),
                "reference" => $this->input->post('reference'),
                "based_amount" => preg_replace("/([^0-9\\.])/i", "", $this->input->post('based_amount')),
                "reverse" => ($reverse == 'on') ? 1 : 0,
            );
            $gstTransID = $this->Glseq->gstInsert('comp_gst_transaction', $journalHdr);
            if ($gstTransID) {
                for ($i = 0; $i < 2; $i++) {
                    $journalDetail = array(
                        "gstTransID" => $gstTransID,
                        "accountID" => $this->input->post('accountID')[$i],
                        "description" => $this->input->post('description')[$i],
                        "taxID" => $this->input->post('taxID')[$i],
                        "taxRate" => $this->input->post('taxRate')[$i],
                        "taxAmountDr" => preg_replace("/([^0-9\\.])/i", "", $this->input->post('taxAmountDr')[$i]),
                        "taxAmountCr" => preg_replace("/([^0-9\\.])/i", "", $this->input->post('taxAmountCr')[$i]),
                    );
                    $this->Glseq->gstInsert('comp_gst_transaction_detail', $journalDetail);
                }
            }

            header('Location:' . base_url() . 'gltransaction/gstjournalConfirm');
        }
        $data = '';
        $this->load->library('table');
        $this->lang->load("journal", $this->session->userdata('language'));
        $this->load->model('Chartofaccount');
        $data['chartAccounts'] = $this->Chartofaccount->chartofaccount_all();
        $data['type'] = array('Deemed Supply', 'Imported Services', 'Imported Goods', 'Apportionment', 'Others');
        $this->load->model('taxmaster');
        $data['taxmaster'] = $this->taxmaster->taxmaster_saleOutput1();

        $this->load->model('company/formSetup_Model');
        $filter['companyID'] = element('compID', $this->session->userdata('logged_in'));
        $filter['formID'] = 118;
        $data['formNo'] = $this->formSetup_Model->getFormNo($filter);

        $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')
                ->add_includes('js/validationengine/jquery.validationEngine.js')
                ->add_includes('js/accounting.js')
                ->add_includes('js/datatables/jquery.dataTables.min.js');
        $data['datatbls'] = NULL;
        $this->layouts->view('gl/transactions/gstjournal_new', array('latest' => 'sidebar/latest'), $data);
    }

    //Edit GST Journal
    public function editgstjournal($id = null) {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRJRNL');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $this->load->model('Glseq');
        if ($this->input->post('based_amount')) {
            $prevId = $this->input->post('ID');
            if (isset($prevId)) {
                $reverse = $this->input->post('reverse');
                $journalHdr = array(
                    "companyID" => element('compID', $this->session->userdata('logged_in')),
                    "formNo" => $this->input->post('formNo'),
                    "vendor_cust_name" => $this->input->post('vendor_cust_name'),
                    "type" => $this->input->post('type'),
                    "gst_number" => $this->input->post('gst_number'),
                    "Description" => $this->input->post('Description'),
                    "date" => date('Y-m-d', strtotime($this->input->post('date'))),
                    "reference" => $this->input->post('reference'),
                    "based_amount" => preg_replace("/([^0-9\\.])/i", "", $this->input->post('based_amount')),
                    "reverse" => ($reverse == 'on') ? 1 : 0,
                );
                $this->Glseq->gstUpdate('comp_gst_transaction', $journalHdr, $prevId);

                for ($i = 0; $i < 2; $i++) {
                    $journalDetail = array(
                        "accountID" => $this->input->post('accountID')[$i],
                        "description" => $this->input->post('description')[$i],
                        "taxID" => !empty($this->input->post('taxID')[$i]) ? $this->input->post('taxID')[$i] : 0,
                        "taxRate" => !empty($this->input->post('taxRate')[$i]) ? $this->input->post('taxRate')[$i] : 0,
                        "taxAmountDr" => preg_replace("/([^0-9\\.])/i", "", $this->input->post('taxAmountDr')[$i]),
                        "taxAmountCr" => preg_replace("/([^0-9\\.])/i", "", $this->input->post('taxAmountCr')[$i]),
                    );
                    $this->Glseq->gstUpdate('comp_gst_transaction_detail', $journalDetail, $this->input->post('detailID')[$i]);
                }
            }


            //print_r($this->input->post());
        }
        $data = '';
        $this->load->library('table');
        $this->lang->load("journal", $this->session->userdata('language'));
        $this->load->model('Chartofaccount');
        $data['chartAccounts'] = $this->Chartofaccount->chartofaccount_all();
        $data['type'] = array('Deemed Supply', 'Imported Services', 'Imported Goods', 'Apportionment', 'Others');
        $this->load->model('taxmaster');
        $data['taxmaster'] = $this->taxmaster->taxmaster_saleOutput1();

        $this->load->model('company/formSetup_Model');
        $filter['companyID'] = element('compID', $this->session->userdata('logged_in'));
        $filter['formID'] = 118;
        $data['formNo'] = $this->formSetup_Model->getFormNo($filter);

        if (!empty($id)) {
            $data['prevData'] = $this->Glseq->gstTransID($id);
        } else {
            header('Location:' . base_url() . 'gltransaction/gstjournalConfirm');
        }

        $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')
                ->add_includes('js/validationengine/jquery.validationEngine.js')
                ->add_includes('js/accounting.js')
                ->add_includes('js/datatables/jquery.dataTables.min.js');
        $data['datatbls'] = NULL;
        $this->layouts->view('gl/transactions/gstjournal_edit', array('latest' => 'sidebar/latest'), $data);
    }

    //Remove GST Journal
    public function gstjournalremove($id = null) {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRJRNL');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }

        $this->load->model('Glseq');
        $status = $this->Glseq->removeGST($id);
        if ($status) {
            $this->session->set_userdata('success', "GST Transaction successfully removed.");
        } else {
            $this->session->set_userdata('error', "Error occured while tring to remove GST Transaction");
        }

        header('Location:' . base_url() . 'gltransaction/gstjournalConfirm');
    }

    //GST Journal confirm
    public function gstjournalConfirm($add_year = null, $add_period = null) {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRJRNL');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }

        if (!$add_year) {
            $add_year = date("Y");
        }
        if (!$add_period) {
            $add_period = date("m");
        }
        $this->lang->load("journal", $this->session->userdata('language'));
        $this->load->model('Compfinancialyear');
        $this->load->model('Glseq');
        //change to get financial year based on select disctint financial year
        $data['yrs'] = $this->Compfinancialyear->get_financialYear();
        $data['selyear'] = $add_year;
        $data['selper'] = $add_period;
        $query = $this->Compfinancialyear->financialYear_year($add_year);
        if ($query) {
            $data['period'] = $query;
        } else {
            $data['period'] = NULL;
        }
        $queryCal = $this->Compfinancialyear->financialYear_yearperiod($add_year, $add_period);
        if ($queryCal) {
            $data['datatbls'] = $this->Glseq->gstTransactionList($queryCal[0]->startDate, $queryCal[0]->endDate);
        } else {
            $data['datatbls'] = NULL;
        }
        $this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
        $this->layouts->view('gl/transactions/gstjournalconfirm', array('latest' => 'sidebar/latest'), $data);
    }

    //GST Journal posting
    public function gstconfirmposting() {

        $this->load->model('Glseq');
        $this->lang->load("journal", $this->session->userdata('language'));

        $ID = $this->input->post('ID');
        $effdate = date("Y-m-d", strtotime($this->input->post('date')));

        $data = array(
            'updateAble' => '0'
        );
        //2.get detail unpost into queryDetails
        $queryDetails = $this->Glseq->gstTransactionDetails_ID($ID);
        //1. first call to update updateable to 1 and return the recordset.
        $query = $this->Glseq->gstTransactionPosting($ID, $data);


        if ($query) {
            $query[0]->exchangeRate = 1;
            $this->load->model('Compfinancialyear');
            $query1 = $this->Compfinancialyear->compfinancialyear_date1($effdate);
            if ($query1) {
                $year = $query1[0]->financialYear;
                $period = $query1[0]->period;
                $formNo = $this->lang->line('gstTitle') . ' [' . $query[0]->formNo . ']]';
                $total_amount_dr = $query[0]->based_amount * $query[0]->exchangeRate;
                $total_amount_cr = $query[0]->based_amount * $query[0]->exchangeRate;
            } else {
                echo "false";
                return FALSE;
            }

            $this->load->model('Glseq');
            $query2 = $this->Glseq->glSequence_sub('3', 'GT', $year, $period);
            $newData = array(
                'companyID' => element('compID', $this->session->userdata('logged_in')),
                'journalID' => $query2['seqNumber'],
                'formNo' => $formNo,
                'description' => $formNo,
                'module' => '3',
                'effective_date' => $effdate,
                'year' => $year,
                'period' => $period,
                'total_amount_dr' => $total_amount_dr,
                'total_amount_cr' => $total_amount_cr,
                'createdBy' => element('role', $this->session->userdata('logged_in'))
            );
            $data = array(
                'journalNo' => $query2['seqNumber']
            );
            //second call to update journal no.  
            $query5 = $this->Glseq->gstTransactionPosting($ID, $data);
            $this->load->model('Journal');
            //4.update journal no into master other pay
            $query3 = $this->Journal->journal_insert($newData);

            if ($query3) {
                //5.pos data into journal using gstJournalDetail
                $query4 = $this->Glseq->gstJournalDetail($query2['seqNumber'], $query[0], $queryDetails, $year, $period);
                echo "true";
            } else {
                echo "false";
            }
        } else {
            echo "false";
            return FALSE;
        }
    }

// Journal Copy ( Duplicate) **** Start	
    public function journalCopy() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRJlCY');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $add_year = $this->uri->segment(3);
        $add_period = $this->uri->segment(4);
        if (!$add_year) {
            $add_year = date("Y");
        }
        if (!$add_period) {
            $add_period = date("m");
        }
        $this->lang->load("journalcopy", $this->session->userdata('language'));
        $this->load->model('Journal');
        $this->load->model('Compfinancialyear');
        $data['yrs'] = range(date('Y'), 1900);
        $data['selyear'] = $add_year;
        $data['selper'] = $add_period;
        $data['period'] = $this->Compfinancialyear->financialYear_year($add_year);
        $data['datatbls'] = $this->Journal->journal_all_yearperiod($add_year, $add_period);
        $this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
        $this->layouts->view('gl/transactions/journalList', array('latest' => 'sidebar/latest'), $data);
    }

    public function jlCopy() {
        $journalID = $this->uri->segment(3);
        $this->load->model('Journal');
        $query = $this->Journal->journal_ID($journalID);
        $data['orijournal'] = $query[0];
        $this->lang->load("journalcopy", $this->session->userdata('language'));
        $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')
                ->add_includes('js/validationengine/jquery.validationEngine.js');
        $this->layouts->view('gl/transactions/jlcopy', array('latest' => 'sidebar/latest'), $data);
    }

    public function journal_copy_save() {
        $this->load->model('Journal');
        $this->load->model('Glseq');
        $query1 = $this->Glseq->glSequence_jl();
        $newData = array(
            'companyID' => element('compID', $this->session->userdata('logged_in')),
            'journalID' => $query1['seqNumber'],
            'description' => $this->input->post('description'),
            'referrence' => $this->input->post('referrence'),
            'module' => '1',
            'effective_date' => date("Y-m-d", strtotime($this->input->post('effdate'))),
            'year' => $query1['financialYear'],
            'period' => $query1['period'],
            'createdBy' => element('userid', $this->session->userdata('logged_in'))
        );
        $query2 = $this->Journal->journal_insert($newData);
        $query3 = $this->Journal->journaldetails_copy($query1['seqNumber']);
        print json_encode(array("status" => "success", "message" => $query2, "journalID" => $query1['seqNumber']));
    }

// Journal Copy ( Duplicate) **** end
// Journal Copy ( Reverse) **** Start
    public function reverse() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRJlRV');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $add_year = $this->uri->segment(3);
        $add_period = $this->uri->segment(4);
        if (!$add_year) {
            $add_year = date("Y");
        }
        if (!$add_period) {
            $add_period = date("m");
        }
        $this->lang->load("journalreverse", $this->session->userdata('language'));
        $this->load->model('Journal');
        $this->load->model('Compfinancialyear');
        //$data['yrs'] = range(date('Y'), 1900);
        //change to get financial year based on select disctint financial year
        $data['yrs'] = $this->Compfinancialyear->get_financialYear();
        $data['selyear'] = $add_year;
        $data['selper'] = $add_period;
        $query = $this->Compfinancialyear->financialYear_year($add_year);
        if ($query) {
            $data['period'] = $query;
        } else {
            $data['period'] = NULL;
        }
        $data['datatbls'] = $this->Journal->journal_all_yearperiod($add_year, $add_period);
        $this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
        $this->layouts->view('gl/transactions/journalLists', array('latest' => 'sidebar/latest'), $data);
    }

    public function jlReverse() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRJlRV');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $journalID = $this->uri->segment(3);
        $this->load->model('Journal');
        $query = $this->Journal->journal_ID($journalID);
        $data['datatbls'] = $this->Journal->journalDetails_journalno($query[0]->journalID);
        $data['orijournal'] = $query[0];
        $data['parentjournalID'] = $journalID;
        $this->lang->load("journalreverse", $this->session->userdata('language'));
        $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')
                ->add_includes('js/validationengine/jquery.validationEngine.js');
        $this->layouts->view('gl/transactions/jlreverse', array('latest' => 'sidebar/latest'), $data);
    }

    public function journal_reverse_save() {
        $this->load->model('Journal');
        $this->load->model('Glseq');


        $query1 = $this->Glseq->glSequence_rv();

        $parentJ = $this->Journal->journal_ID($this->input->post('parentjournalID'));

        //var_dump($parentJ);
        $newData = array(
            'companyID' => element('compID', $this->session->userdata('logged_in')),
            'journalID' => $query1['seqNumber'],
            'description' => $this->input->post('description'),
            'referrence' => $this->input->post('referrence'),
            'module' => '1',
            'effective_date' => date("Y-m-d", strtotime($this->input->post('effdate'))),
            'total_amount_dr' => $parentJ[0]->total_amount_cr,
            'total_amount_cr' => $parentJ[0]->total_amount_dr,
            'total_amount' => $parentJ[0]->total_amount,
            'year' => $query1['financialYear'],
            'period' => $query1['period'],
            'createdBy' => element('userid', $this->session->userdata('logged_in'))
        );

        $query2 = $this->Journal->journal_insert($newData);
        $query3 = $this->Journal->journaldetails_reverse($query1['seqNumber']);
        print json_encode(array("status" => "success", "message" => $query2, "journalID" => $query1['seqNumber']));
    }

// Journal Copy ( Reverse) **** end	

    public function journal_copy_edit() {
        $journalID = $this->uri->segment(3);
        $this->load->model('Journal');
        $this->load->library('table');
        $this->lang->load("journaledit", $this->session->userdata('language'));
        $this->load->model('Chartofaccount');
        $data['chartAccounts'] = $this->Chartofaccount->chartofaccount_all();
        $query = $this->Journal->journal_journalno($journalID);
        $data['journalHead'] = $query[0];
        $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')
                ->add_includes('js/validationengine/jquery.validationEngine.js')
                ->add_includes('js/datatables/jquery.dataTables.min.js');
        $data['datatbls'] = NULL;
        $this->layouts->view('gl/transactions/journal_edit', array('latest' => 'sidebar/latest'), $data);
    }

    public function journal_head() {
        $this->load->model('Journal');
        $this->lang->load("journal", $this->session->userdata('language'));
        if ($this->input->post('journalNo') == '') {
            $this->load->model('Glseq');
            $query = $this->Glseq->glSequence_jl();
            $newData = array(
                'companyID' => element('compID', $this->session->userdata('logged_in')),
                'journalID' => $query['seqNumber'],
                'description' => $this->input->post('description'),
                'referrence' => $this->input->post('referrence'),
                'module' => '1',
                'effective_date' => date("Y-m-d", strtotime($this->input->post('effdate'))),
                'year' => $query['financialYear'],
                'period' => $query['period'],
                'createdBy' => element('role', $this->session->userdata('logged_in'))
            );
            $query2 = $this->Journal->journal_insert($newData);
            print json_encode(array("status" => "success", "message" => $query));
        } else {
            $query2 = $this->Journal->journal_journalNo($this->input->post('journalNo'));
            if ($query2 and $query2[0]->status == 0) {
                $query3 = $this->Journal->journalDetails_journalno($this->input->post('journalNo'));
                if ($query3) {
                    $i = 0;
                    foreach ($query3 as $row) {
                        $datatbls[$i] = $row;
                        $i++;
                    }
                } else {
                    $datatbls = '';
                }
                $query['description'] = $query2[0]->description;
                $query['referrence'] = $query2[0]->referrence;
                $query['effdate'] = date("d-m-Y", strtotime($query2[0]->effective_date));
                print json_encode(array(
                    "status" => "success1",
                    "message" => $query,
                    "journalID" => $this->input->post('journalNo'),
                    "datatbls" => $datatbls));
            } else {
                print json_encode(array(
                    "status" => "failed",
                    "message" => $this->lang->line('jlnumber') . " : " . $this->input->post('journalNo') . " " . $this->lang->line('message7')));
            }
        }
    }

    public function journal_head_() {
        $this->load->model('Journal');
        $this->lang->load("journal", $this->session->userdata('language'));
//		if($this->input->post('journalNo') != ''){
//		$delete_journalPosting = $this->Journal->journalPostingDelete_journalno($this->input->post('journalNo'));
//        }
        $this->load->model('Glseq');
        $query = $this->Glseq->glSequence_jl();
        $newData = array(
            'companyID' => element('compID', $this->session->userdata('logged_in')),
            'journalID' => $query['seqNumber'],
            'description' => $this->input->post('description'),
            'referrence' => $this->input->post('referrence'),
            'module' => '1',
            'effective_date' => date("Y-m-d", strtotime($this->input->post('effdate'))),
            'year' => $query['financialYear'],
            'period' => $query['period'],
            'createdBy' => element('role', $this->session->userdata('logged_in'))
        );
        $query2 = $this->Journal->journal_insert($newData);
        print json_encode(array("status" => "success", "message" => $query));
    }

    public function getAccount() {
        $this->load->model('Chartofaccount');
        $this->load->model('Compfinancialyear');
        $query = $this->Chartofaccount->chartofaccount_all();
        if ($query) {
            print json_encode(array("status" => "success", "message" => $query));
        } else {
            
        }
    }

    public function journaldetails_insert() {
        $this->load->model('Journal');
        $this->load->model('Compfinancialyear');
        $headdata = array(
            'total_amount_dr' => $this->input->post('amountdebit'),
            'total_amount_cr' => $this->input->post('amountcredit'),
            'total_amount' => $this->input->post('totalamount'),
        );
        $queryhead = $this->Journal->journal_update($this->input->post('journalNo'), $headdata);
        $querycal = $this->Compfinancialyear->compfinancialyear_date($this->input->post('effdate'));
        $datacal = $querycal[0];
        $newdata = array(
            'companyID' => element('compID', $this->session->userdata('logged_in')),
            'journalID' => $this->input->post('journalNo'),
            'sequence' => $this->input->post('sequence'),
            'description' => $this->input->post('description'),
            'acctCode' => $this->input->post('acctCode'),
            'year' => $datacal->financialYear,
            'period' => $datacal->period,
            'exchange_rate' => 1,
            'currencyID' => element('compCurrency', $this->session->userdata('logged_in')),
            'amount_cr' => $this->input->post('amountcr'),
            'amount_dr' => $this->input->post('amountdr'),
            'createdBy' => element('role', $this->session->userdata('logged_in'))
        );
        $query = $this->Journal->journalDetails_insert($newdata);
        if ($query) {
            $query3 = $this->Journal->journalDetails_journalno($this->input->post('journalNo'));
            if ($query3) {
                $i = 0;
                foreach ($query3 as $row) {
                    $datatbls[$i] = $row;
                    $i++;
                }
            } else {
                $datatbls = '';
            }
            print json_encode(array(
                "status" => "success",
                "message" => 'Journal details saved..',
                "datatbls" => $datatbls));
        } else {
            print json_encode(array("status" => "failed", "message" => 'Journal details saved..'));
        }
    }

    public function journaldetails_save() {
        $this->load->model('Journal');
        $fldid = $this->input->post('fldid');
        $fieldname = $this->input->post('fieldname');
        $value = $this->input->post('content');
        $data = array($fieldname => $value);
        $query = $this->Journal->journalDetails_save($fldid, $data);
        if ($query) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    public function journaldetails_delete() {
        $this->load->model('Journal');
        $fldid = $this->input->post('fldid');
        $delete_menu = $this->Journal->journalDetails_delete($fldid);
        if ($delete_menu) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    public function accountSearch() {
        $this->load->model('CompanyChartAcct');
        $query = $this->CompanyChartAcct->chartAcct_all_asc();
        if ($query) {
            print json_encode(array("status" => "success", "message" => $query));
        } else {
            print json_encode(array("status" => "failed", "message" => 'Journal details saved..'));
        }
    }

    public function accountSearch_ID() {
        $this->load->model('CompanyChartAcct');
        $query = $this->CompanyChartAcct->chartAcct_id($this->input->post('ID'));
        if ($query) {
            print json_encode(array("status" => "success", "message" => $query[0]));
        } else {
            print json_encode(array("status" => "failed", "message" => 'Journal details saved..'));
        }
    }

// Posting Journal start
//    public function posting() {
//        $this->load->model('UseraccessDetails');
//        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRPOST');
//        if (!$query) {
//            echo '<script>alert("Not authorised..");
//				window.location.replace("' . base_url() . 'Error");
/*				</script>';*/
//        }
//        $add_year = $this->uri->segment(3);
//        $add_period = $this->uri->segment(4);
//        if (!$add_year) {
//            $add_year = date("Y");
//        }
//        if (!$add_period) {
//            $add_period = date("m");
//        }
//        $this->lang->load("journalpost", $this->session->userdata('language'));
//        $this->load->model('Journal');
//        $this->load->model('Compfinancialyear');
//        //$data['yrs'] = range(date('Y', strtotime('+1 year')), 1900);
//        //change to get financial year based on select disctint financial year
//        $data['yrs'] = $this->Compfinancialyear->get_financialYear();
//        $data['selyear'] = $add_year;
//        $data['selper'] = $add_period;
//        $data['dateFrom'] = "";
//        $data['dateTo'] = "";
//         $data['para_display_option']="1";
//        
//        $query = $this->Compfinancialyear->financialYear_year($add_year);
//        if ($query) {
//            $data['period'] = $query;
//        } else {
//            $data['period'] = NULL;
//        }
//        $data['datatbls'] = $this->Journal->journal_unpost_yearperiod($add_year, $add_period);
//        $this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
//        $this->layouts->view('gl/transactions/journalPost', array('latest' => 'sidebar/latest'), $data);
//    }

    public function posting() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRPOST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $add_year = date("Y");
        $add_period = date("m");


        if ($this->input->post('add_year') != "") {
            $add_year = $this->input->post('add_year');
        }
        if ($this->input->post('add_period') != "") {
            $add_period = $this->input->post('add_period');
        }


        $this->lang->load("journalpost", $this->session->userdata('language'));
        $this->load->model('Journal');
        $this->load->model('Compfinancialyear');
        //$data['yrs'] = range(date('Y', strtotime('+1 year')), 1900);
        //change to get financial year based on select disctint financial year
        $data['yrs'] = $this->Compfinancialyear->get_financialYear();

        $data['selyear'] = $add_year;
        $data['selper'] = $add_period;

        $data['para_display_option'] = ($this->input->post('para_display_option') == "") ? 0 : $this->input->post('para_display_option');

        //var_dump($this->input->post('para_display_option'));


        $query = $this->Compfinancialyear->financialYear_year($add_year);
        if ($query) {
            $data['period'] = $query;
        } else {
            $data['period'] = NULL;
        }
        $data['datatbls'] = $this->Journal->journal_unpost_yearperiod($add_year, $add_period, $data['para_display_option']);
		
        $this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
        $this->layouts->view('gl/transactions/journalPost', array('latest' => 'sidebar/latest'), $data);
    }


	/*public function postJournalPrint() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRPOST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $add_year = date("Y");
        $add_period = date("m");


        if ($this->input->post('add_year') != "") {
            $add_year = $this->input->post('add_year');
        }
        if ($this->input->post('add_period') != "") {
            $add_period = $this->input->post('add_period');
        }


        $this->lang->load("journalpost", $this->session->userdata('language'));
        $this->load->model('Journal');
        $this->load->model('Compfinancialyear');
        //$data['yrs'] = range(date('Y', strtotime('+1 year')), 1900);
        //change to get financial year based on select disctint financial year
        $data['yrs'] = $this->Compfinancialyear->get_financialYear();

        $data['selyear'] = $add_year;
        $data['selper'] = $add_period;

        $data['para_display_option'] = ($this->input->post('para_display_option') == "") ? 0 : $this->input->post('para_display_option');

        //var_dump($this->input->post('para_display_option'));


        $query = $this->Compfinancialyear->financialYear_year($add_year);
        if ($query) {
            $data['period'] = $query;
        } else {
            $data['period'] = NULL;
        }
        $data['datatbls'] = $this->Journal->journal_unpost_yearperiod($add_year, $add_period, $data['para_display_option']);
        
		$headerData['rptTitle'] = $this->lang->line("title");
		
		$headerData['rightContent'] = array(
            $this->lang->line("from") . " " . date('d-m-Y', strtotime($dateFrom)) . " " . $this->lang->line("to") . " " . date('d-m-Y', strtotime($dateTo)),
        );
		
		//   $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
        $bodyData['rptDataDetail'] = $data['datatbls'];
        $bodyData['tableHeader'] = array($this->lang->line("jlnumber"), $this->lang->line("referenceNo"), $this->lang->line("year"), $this->lang->line("period"), $this->lang->line("description"), $this->lang->line("total"));
        $bodyData['selectFields'] = array("journalID", "refNo", "year", "period", "");
        $bodyData ['tdAmount'] = array("totalamount");
        $bodyData['tableFooter'] = array("");
        $bodyData['excelTitle'] = "Sales_Invoice_List";

        if (!$mode) {
            //print
            $this->load->view('layouts/report/header', $headerData);
            $this->load->view('layouts/report/body', $bodyData);
            $this->load->view('layouts/report/footer', $footerData);
        } else {
            //download excell
            $this->load->helper('excel');
            excel($headerData, array($bodyData), $footerData);
        }
		
    }*/


    public function journalPostingDelete() {
        $this->load->model('Journal');
        //$deletePO = array('is_delete' => '1');
        $ID = $this->input->post('ID');
        //var_dump($ID);

        $delete_journalPosting = $this->Journal->journalPostingDelete_id($ID);
        if ($delete_journalPosting) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    public function journalPosting() {
        $ID = $this->input->post('fldid');
        $journalNo = $this->input->post('journalNo');
        $data = array(
            'status' => '1'
        );
        $this->load->model('Journal');
        $query = $this->Journal->journal_save($ID, $journalNo, $data);
        print json_encode(array("status" => "success", "message" => $query));
    }

// Posting Journal end

    public function YearEndClose() {
        $this->load->model('CompAcctDet');
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('GLTRYECL');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $this->load->model('Compfinancialyear');
        if ($this->input->post('mysubmit')) {
            $closing_year = $this->input->post('add_year');
            $lstYrCloseChk = $this->Compfinancialyear->lastYearClosedCheck($closing_year);

            if ($lstYrCloseChk) {
                $balStatus = $this->Compfinancialyear->closeingChkYear($closing_year);
                if ($balStatus) {
                    $query = $this->Compfinancialyear->financialYear_year_all($closing_year);
                    if ($query) {
                        $query = $this->CompAcctDet->AcctDet_allfypnl1($closing_year);
                        echo '<script>alert("Year End Closed....");
							window.location.replace("../glsetting/financialCalendarList");
							</script>';
                    } else {
                        
                    }
                } else {
                    echo '<script>alert("Financial Year already closed....");
							window.location.replace("../Gltransaction/YearEndClose");
							</script>';
                }
            } else {
                echo '<script>alert("Close previous Financial Year in order to close current....");
							window.location.replace("../Gltransaction/YearEndClose");
							</script>';
            }
        }
        $this->lang->load("yearEnd", $this->session->userdata('language'));
        $data['yrs'] = $this->Compfinancialyear->financialCalendar_all_array();
        //$data['yrs'] = range(date('Y'), 1900);
        $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')
                ->add_includes('js/validationengine/jquery.validationEngine.js');
        $this->layouts->view('gl/transactions/yearEndClose', array('latest' => 'sidebar/latest'), $data);
    }

// created by Eisa
// 20th may 2014
//akmal-20141027 - the process. 
//1.update updateable to 1
//2.get detail unpost into queryDetails
//3.generate journal no
//4.update journal no into master other pay
//5.pos data into journal using $this->othersPayment_model->otherpaymentJournalDetail
//6.update updateable to 1 after successfully move data to journal

    public function otherpaymentposting() {
        $this->load->model('accountPayable/othersPayment_model');
        $this->lang->load("otherspayment", $this->session->userdata('language'));

        $ID = $this->input->post('fldid');
        $effdate = date("Y-m-d", strtotime($this->input->post('effdate')));

        $data = array(
//            'updateAble' => '0'
        );
        //2.get detail unpost into queryDetails
        $queryDetails = $this->othersPayment_model->othersPaymentDetails_ID($ID);
        //1. first call to update updateable to 1 and return the recordset.
        $query = $this->othersPayment_model->otherpaymentposting($ID, $data);
        //otherpaymentposting = SELECT `comp_payment_others`.*, concat(comp_payment_others.formNo, "[", lpad(comp_payment_others.serialNo, 8, "0"), "]") as formNo FROM (`comp_payment_others`) WHERE `ID` =  '107'
//	echo '<br>otherpaymentpostingmodel='.$this->db->last_query(); 

        if ($query) {
//print_r ($query); 
            if ($query[0]->exchangeRate == 0 || $query[0]->exchangeRate == '')
                $query[0]->exchangeRate = 1;
            $this->load->model('Compfinancialyear');
            $query1 = $this->Compfinancialyear->compfinancialyear_date1($effdate);
//	echo '<br>compfinancialyear_date1='.$this->db->last_query(); 
            if ($query1) {
                $year = $query1[0]->financialYear;
                $period = $query1[0]->period;
                //$formNo = $query[0]->formNo . '[' . sprintf('%08d', $query[0]->ID) . ']';
                $formNo = $this->lang->line('title') . ' [' . $query[0]->formNo . ']]';
                $total_amount_dr = $query[0]->amountPaid * $query[0]->exchangeRate;
                $total_amount_cr = $query[0]->amountPaid * $query[0]->exchangeRate;
            } else {
                echo "financial year false";
                return FALSE;
            }
            $this->load->model('Glseq');
            $query2 = $this->Glseq->glSequence_sub('3', 'AP', $year, $period);
            $newData = array(
                'companyID' => element('compID', $this->session->userdata('logged_in')),
                'journalID' => $query2['seqNumber'],
                'formNo' => $formNo,
//                'description' => $this->lang->line('message2') . ' [ ' . $formNo . ' ]',
                'description' => $formNo,
				'referrence' => $query[0]->referenceNo,
                'module' => '3',
                'effective_date' => $effdate,
                'year' => $year,
                'period' => $period,
                'total_amount_dr' => $total_amount_dr,
                'total_amount_cr' => $total_amount_cr,
                'createdBy' => element('role', $this->session->userdata('logged_in'))
            );
            $data = array(
                'journalNo' => $query2['seqNumber']
            );
            //second call to update journal no.  
            $query5 = $this->othersPayment_model->otherpaymentposting($ID, $data);
            $this->load->model('Journal');
            //4.update journal no into master other pay
            $query3 = $this->Journal->journal_insert($newData);
            //var_dump($query3);
//var_dump($queryDetails);
            if ($query3) {
                //5.pos data into journal using $this->othersPayment_model->otherpaymentJournalDetail
                //var_dump($queryDetails);
                $query4 = $this->othersPayment_model->otherpaymentJournalDetail($query2['seqNumber'], $query[0], $queryDetails, $year, $period);
				$data = array(
					'updateAble' => '0'        );
				 $this->db->where('ID',$ID)
							->update('comp_payment_others', $data);
//	echo '<br>update otherpaymentpostingmodel='.$this->db->last_query(); 
                echo "true";
            } else {
                echo "journal detail false";
            }
        } else {
            echo "updateable false";
            return FALSE;
        }
    }

    public function otherpaymentConfirm() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('OTRPAY');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $this->lang->load("otherspayment", $this->session->userdata('language'));
        $this->load->model('company/FormSetup_model');
        $this->load->model('Compfinancialyear');
        $add_year = $this->uri->segment(3);
        $add_period = $this->uri->segment(4);
        if (!$add_year) {
            $add_year = date("Y");
            $startDate = date("Y-m-01");
            $endDate = date("Y-m-t");
        } else {
            $query2 = $this->Compfinancialyear->financialYear_yearperiod($add_year, $add_period);
            if ($query2) {
                $startDate = $query2[0]->startDate;
                $endDate = $query2[0]->endDate;
            } else {
                $startDate = date("Y-m-01");
                $endDate = date("Y-m-t");
            }
        }
        if (!$add_period) {
            $add_period = date("m");
        }
        $query = $this->Compfinancialyear->financialYear_year($add_year);
        if ($query) {
            $data['period'] = $query;
        } else {
            $data['period'] = NULL;
        }
        //$data['yrs'] = range(date('Y', strtotime('+2 year')), 1900);
        //change to get financial year based on select disctint financial year
        $data['yrs'] = $this->Compfinancialyear->get_financialYear();
        $data['selyear'] = $add_year;
        $data['selper'] = $add_period;
        $this->load->model('accountPayable/othersPayment_model');
        $data['datatbls'] = $this->othersPayment_model->otherpaywithoutitem_unpost($startDate, $endDate);
//		echo $this->db->last_query(); 
        $this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
        $this->layouts->view('ap/othersPayment/otherpaymentPosting', array('latest' => 'sidebar/latest'), $data);
    }

    public function newPayWithoutItem() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('APOPWOI');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $this->load->model('company/formSetup_Model');
        $filter['companyID'] = element('compID', $this->session->userdata('logged_in'));
        $this->lang->load("otherspayment", $this->session->userdata('language'));
        $this->load->model('companyChartAcct');

        $this->load->model('Usermaster');
        $data['records'] = $this->Usermaster->usermaster_all();

        $this->load->model('master/masterCode_model');
        $filter['masterID'] = 7;
        $data['paymentmethod'] = $this->masterCode_model->get_all($filter);


        $this->load->model('Project/project_model');
        $data['project'] = $this->project_model->project_all();

        $this->load->model('location');
        $data['location'] = $this->location->location_all();


        $this->load->model('taxmaster');
        $data['taxmaster'] = $this->taxmaster->taxmaster_purchaseInput();

        $this->load->model('item/itemSetup_model');
        $data['items'] = $this->itemSetup_model->get_all(true);

        $this->load->model('bank/bank_model');
        $data['bankaccount'] = $this->bank_model->bank_all();

        $this->load->model('companyChartAcct');
        $data['chargeAccount'] = $this->companyChartAcct->chartAcct_all();

        $filter['companyID'] = element('compID', $this->session->userdata('logged_in'));
        $filter['formID'] = 55;
        $data['formNo'] = $this->formSetup_Model->getFormNo($filter);

        $this->load->model('Usermaster');
        $data['records'] = $this->Usermaster->usermaster_all();
        $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')
                ->add_includes('js/accounting.js')
                ->add_includes('js/validationengine/jquery.validationEngine.js');
        $this->layouts->view('ap/othersPayment/newotherpaywithoutitem', '', $data);
    }

    function savenewpaywithOutItem() {

        $this->load->model('accountPayable/othersPayment_model');
        $ID = $this->input->post('ID');
        $companyID = element('compID', $this->session->userdata('logged_in'));
        $datinsert = array(
            'memo' => $this->input->post('memo'),
            //'locationID' => $this->input->post('locationID'), 
            'companyID' => $companyID,
            'createdBy' => element('role', $this->session->userdata('logged_in')),
            'otherPaymentType' => 1,
            'paymentMethodID' => $this->input->post('paymentMethodID'),
            'amountPaid' => $this->input->post('amountPaid'),
            'formNo' => $this->input->post('formNo'),
            'paymentDate' => date('Y-m-d', strtotime($this->input->post('paymentDate'))),
            'referenceNo' => $this->input->post('referenceNo'),
            'payTo' => $this->input->post('payto'),
            'bankId' => $this->input->post('bankID'),
            'projectID' => $this->input->post('projectID'),
            'simplifiedTax' => $this->input->post('simplifiedTax'),
            'exchangeRate' => $this->input->post('exchangeRate')
        );
        
        
        $otherPaymentID = $this->othersPayment_model->insert("comp_payment_others", $datinsert);

        if ($otherPaymentID > 0) {

            //$otherPaymentID=$this->othersPayment_model->getLasIdInsert("comp_payment_others");
            $datinsertDetails = array(
                'otherPaymentID' => $otherPaymentID,
                'createdBy' => element('role', $this->session->userdata('logged_in')),
                'itemdescription' => $this->input->post('itemdescription'),
                'lineNo' => $this->input->post('lineNo'),
                'accountID' => $this->input->post('itemAccountID'),
                'amountIncludedTax' => $this->input->post('amountIncludedTax'),
                'amountExcludedTax' => $this->input->post('amountExcludedTax'),
                'taxID' => $this->input->post('taxID'),
                'taxRate' => $this->input->post('taxRate'),
                'taxAmount' => $this->input->post('taxAmount'),
                'taxBL' => $this->input->post('taxbl'),
                'amountIncludedTax' => $this->input->post('amountIncludedTax')
            );
            $query = $this->othersPayment_model->insert('comp_payment_others_without_item', $datinsertDetails);
            echo '{"status":"success","paymentID":"' . $otherPaymentID . '","detailID":"' . $query . '"}';
        } else {
            echo "false";
        }
    }

    function savenewpaywithoutItemDetailOnly() {
        $this->load->model('accountPayable/othersPayment_model');
        $datinsertDetails = array(
            'otherPaymentID' => $this->input->post('otherPaymentID'),
            'createdBy' => element('role', $this->session->userdata('logged_in')),
            'lineNo' => $this->input->post('lineNo'),
            'itemdescription' => $this->input->post('itemdescription'),
            'accountID' => $this->input->post('itemAccountID'),
            'amountIncludedTax' => $this->input->post('amountIncludedTax'),
            'amountExcludedTax' => $this->input->post('amountExcludedTax'),
            'taxID' => $this->input->post('taxID'),
            'taxRate' => $this->input->post('taxRate'),
            'taxAmount' => $this->input->post('taxAmount'),
            'taxBL' => $this->input->post('taxbl'),
            'amountIncludedTax' => $this->input->post('amountIncludedTax')
        );
        $query = $this->othersPayment_model->insert('comp_payment_others_without_item', $datinsertDetails);
        
        $this->db->query("update comp_payment_others set amountPaid = ? where id = ? ", array($this->input->post('amountPaid'), $this->input->post('otherPaymentID')));
        $detail = $this->othersPayment_model->getLasIdInsert("comp_payment_others_without_item");
        echo '{"status":"success","detailID":"' . $detail . '"}';
    }

    // 9/24/2014

    public function newotherreceive() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('OTHRCV');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $this->load->model('company/formSetup_Model');
        $filter['companyID'] = element('compID', $this->session->userdata('logged_in'));
        $this->lang->load("othersreceive", $this->session->userdata('language'));
        $this->load->model('companyChartAcct');

        $this->load->model('Usermaster');
        $data['records'] = $this->Usermaster->usermaster_all();

        $this->load->model('master/masterCode_model');
        $filter['masterID'] = 7;
        $data['paymentmethod'] = $this->masterCode_model->get_all($filter);


        $this->load->model('Project/project_model');
        $data['project'] = $this->project_model->project_all();

        //$this->load->model('location');
        //$data['location'] = $this->location->location_all();

        $this->load->model('taxmaster');
        $data['taxmaster'] = $this->taxmaster->taxmaster_saleOutput();

        $this->load->model('customer/Customer_model');
        $data['customer'] = $this->Customer_model->customermaster_all();
        /* $this->load->model('taxmaster');
          $data['taxmaster'] = $this->taxmaster->taxmaster_purchaseInput(); */



        $this->load->model('bank/bank_model');
        $data['bankaccount'] = $this->bank_model->bank_all();

        $this->load->model('companyChartAcct');
        $data['chargeAccount'] = $this->companyChartAcct->chartAcct_all();

        $filter['companyID'] = element('compID', $this->session->userdata('logged_in'));
        $filter['formID'] = 56;
        $data['formNo'] = $this->formSetup_Model->getFormNo($filter);

        $this->load->model('Usermaster');
        $data['records'] = $this->Usermaster->usermaster_all();
        $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')
                ->add_includes('js/accounting.js')
                ->add_includes('js/validationengine/jquery.validationEngine.js');
        $this->layouts->view('gl/othersreceive/newotherReceive', '', $data);
    }

    public function editotherreceive($id) {
        $this->load->model('UseraccessDetails');
        /* $query = $this->UseraccessDetails->UseraccessDetails_id_code('OTRCVCON');
          if (!$query) {
          echo '<script>alert("Not authorised..");
          window.location.replace("' . base_url() . 'Error");
          </script>';
          } */

        $this->lang->load("othersreceive", $this->session->userdata('language'));
        $this->load->model('companyChartAcct');

        $this->load->model('Usermaster');
        $data['records'] = $this->Usermaster->usermaster_all();
        $this->load->library('layouts');
        $this->layouts->add_includes('js/validationengine/languages/jquery.validationEngine-' . $this->session->userdata('language') . '.js')
                ->add_includes('js/accounting.js')
                ->add_includes('js/validationengine/jquery.validationEngine.js');

        $this->load->model('Usermaster');
        $data['records'] = $this->Usermaster->usermaster_all();

        $this->load->model('companyChartAcct');
        $data['pmtAccount'] = $this->companyChartAcct->chartAcct_all();

        $this->load->model('Project/project_model');
        $data['project'] = $this->project_model->project_all();

        $this->load->model('taxmaster');
        $data['taxmaster'] = $this->taxmaster->taxmaster_saleOutput();

        $this->load->model('master/masterCode_model');
        $filter['masterID'] = 7;
        $data['paymentmethod'] = $this->masterCode_model->get_all($filter);

        $this->load->model('bank/bank_model');
        $data['bankaccount'] = $this->bank_model->bank_all();


        $this->load->model('accountPayable/othersPayment_model');
        $data['pdetails'] = $this->othersPayment_model->getOthersPaymentDetail($id, "comp_receive_payment_others");
        $data['otherPay'] = $this->othersPayment_model->getOthersPaymentReceive($id);

        $this->layouts->view('gl/othersreceive/editotherReceive', '', $data);
    }

    public function otherreceiveConfirm() {
        $this->load->model('UseraccessDetails');
        $queryOR = $this->UseraccessDetails->UseraccessDetails_id_code('OTRCVCON');
        if (!$queryOR) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
        $this->lang->load("othersreceive", $this->session->userdata('language'));

        $this->load->model('Compfinancialyear');
        $add_year = $this->uri->segment(3);
        $add_period = $this->uri->segment(4);
        if (!$add_year) {
            $add_year = date("Y");
            $startDate = date("Y-m-01");
            $endDate = date("Y-m-t");
        } else {
            $query2 = $this->Compfinancialyear->financialYear_yearperiod($add_year, $add_period);
            if ($query2) {
                $startDate = $query2[0]->startDate;
                $endDate = $query2[0]->endDate;
            } else {
                $startDate = date("Y-m-01");
                $endDate = date("Y-m-t");
            }
        }
        if (!$add_period) {
            $add_period = date("m");
        }
        $query = $this->Compfinancialyear->financialYear_year($add_year);
        if ($query) {
            $data['period'] = $query;
        } else {
            $data['period'] = NULL;
        }
        //$data['yrs'] = range(date('Y', strtotime('+2 year')), 1900);
        //change to get financial year based on select disctint financial year
        $data['yrs'] = $this->Compfinancialyear->get_financialYear();
        $data['selyear'] = $add_year;
        $data['selper'] = $add_period;
        $this->load->model('accountPayable/othersPayment_model');
        $data['datatbls'] = $this->othersPayment_model->otherPaymentReceive_unpost($startDate, $endDate);
        $this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
        $this->layouts->view('gl/othersreceive/otherReceivePosting', array('latest' => 'sidebar/latest'), $data);
    }

    function savenewotherreveive() {

        $this->load->model('accountPayable/othersPayment_model');
        $ID = $this->input->post('ID');
        $companyID = element('compID', $this->session->userdata('logged_in'));
        $datinsert = array(
            'memo' => $this->input->post('memo'),
            //'locationID' => $this->input->post('locationID'), 
            'companyID' => $companyID,
            'createdBy' => element('role', $this->session->userdata('logged_in')),
            'paymentMethodID' => $this->input->post('paymentMethodID'),
            'totalReceived' => $this->input->post('totalReceived'),
            'formNo' => $this->input->post('formNo'),
            'receivePaymentDate' => date('Y-m-d', strtotime($this->input->post('paymentDate'))),
            'referenceNo' => $this->input->post('referenceNo'),
            'receiveFrom' => $this->input->post('receiveFrom'),
            'bankId' => $this->input->post('bankID'),
            'projectID' => $this->input->post('projectID'),
            'exchangeRate' => $this->input->post('exchangeRate')
        );

        $otherPaymentID = $this->othersPayment_model->insert("comp_receive_payment_others", $datinsert);

        if ($otherPaymentID > 0) {

            //$otherPaymentID=$this->othersPayment_model->getLasIdInsert("comp_payment_others");
            $datinsertDetails = array(
                'receivePaymentOthersID' => $otherPaymentID,
                'createdBy' => element('role', $this->session->userdata('logged_in')),
                'description' => $this->input->post('description'),
                'lineNo' => $this->input->post('lineNo'),
                'accountNoID' => $this->input->post('accountID'),
                'amountIncludedTax' => $this->input->post('amountIncludedTax'),
                'amountExcludedTax' => $this->input->post('amountExcludedTax'),
                'taxID' => $this->input->post('taxID'),
                'taxRate' => $this->input->post('taxRate'),
                'taxAmount' => $this->input->post('taxAmount'),
                'amountIncludedTax' => $this->input->post('amountIncludedTax')
            );
            $query = $this->othersPayment_model->insert('comp_receive_payment_others_detail', $datinsertDetails);
            //$detail=$this->othersPayment_model->getLasIdInsert("comp_payment_others_without_item");
            echo '{"status":"success","paymentID":"' . $otherPaymentID . '","detailID":"' . $query . '"}';
        } else {
            echo "false";
        }
    }

    function saveotherReceiveDetailOnly() {
        $this->load->model('accountPayable/othersPayment_model');
        $datinsertDetails = array(
            'receivePaymentOthersID' => $this->input->post('otherPaymentID'),
            'createdBy' => element('role', $this->session->userdata('logged_in')),
            'lineNo' => $this->input->post('lineNo'),
            'description' => $this->input->post('description'),
            'accountNoID' => $this->input->post('accountID'),
            'amountIncludedTax' => $this->input->post('amountIncludedTax'),
            'amountExcludedTax' => $this->input->post('amountExcludedTax'),
            'taxID' => $this->input->post('taxID'),
            'taxRate' => $this->input->post('taxRate'),
            'taxAmount' => $this->input->post('taxAmount'),
            'amountIncludedTax' => $this->input->post('amountIncludedTax')
        );
        $query = $this->othersPayment_model->insert('comp_receive_payment_others_detail', $datinsertDetails);
        // $detail=$this->othersPayment_model->getLasIdInsert("comp_payment_others_without_item");
        echo '{"status":"success","detailID":"' . $query . '"}';
    }

    public function updOtherRecieveRow() {
        $data = array(
            'updatedBy' => element('role', $this->session->userdata('logged_in')),
            'description' => $this->input->post('description'),
            'accountNoID' => $this->input->post('accountID'),
            'amountIncludedTax' => $this->input->post('amountIncludedTax'),
            'amountExcludedTax' => $this->input->post('amountExcludedTax'),
            'taxID' => $this->input->post('taxID'),
            'taxRate' => $this->input->post('taxRate'),
            'taxAmount' => $this->input->post('taxAmount')
        );
        $this->load->model('accountPayable/othersPayment_model');
        echo $query = $this->othersPayment_model->updateByTname($this->input->post('rowID'), $data, 'comp_receive_payment_others_detail');
    }

    function deleteOtherReceiveRow() {
        $this->load->model('accountPayable/othersPayment_model');
        echo $this->othersPayment_model->deleteByTname($this->input->post('rowID'), "comp_receive_payment_others_detail");
    }

    public function otherreceiveposting() {
        $this->load->model('accountPayable/othersPayment_model');

        $ID = $this->input->post('fldid');
        $effdate = date("Y-m-d", strtotime($this->input->post('effdate')));

        $queryDetails = $this->othersPayment_model->othersReceiveDetails_ID($ID);

        $data = array(
            'updateAble' => '1'
        );

        $query = $this->othersPayment_model->otherRecievePosting($ID, $data);
        //var_dump($query);
        if ($query) {
            $this->load->model('Compfinancialyear');
            $query1 = $this->Compfinancialyear->compfinancialyear_date1($effdate);
            if ($query1) {
                $year = $query1[0]->financialYear;
                $period = $query1[0]->period;
                $formNo = $query[0]->formNo;
                $total_amount_dr = $query[0]->totalReceived;
                $total_amount_cr = $query[0]->totalReceived;
            } else {
                echo "financial year false";
                return FALSE;
            }
            $this->load->model('Glseq');
            $query2 = $this->Glseq->glSequence_sub('2', 'AR', $year, $period);
            $newData = array(
                'companyID' => element('compID', $this->session->userdata('logged_in')),
                'journalID' => $query2['seqNumber'],
                'formNo' => $formNo,
                'description' => $this->lang->line('message2') . ' [ ' . $formNo . ' ]',
				'referrence' => $query[0]->referenceNo,
                'module' => '2',
                'effective_date' => $effdate,
                'year' => $year,
                'period' => $period,
                'total_amount_dr' => $total_amount_dr,
                'total_amount_cr' => $total_amount_cr,
                'createdBy' => element('role', $this->session->userdata('logged_in'))
            );
            $data = array(
                'journalNo' => $query2['seqNumber']
            );
            $query5 = $this->othersPayment_model->otherRecievePosting($ID, $data);
            $this->load->model('Journal');
            $query3 = $this->Journal->journal_insert($newData);
            if ($query3) {
                $query4 = $this->othersPayment_model->otherReceiveJournalDetail($query2['seqNumber'], $query[0], $queryDetails, $year, $period);
				$data = array(
					'updateAble' => '0'        );
				 $this->db->where('ID',$ID)
							->update('comp_receive_payment_others', $data);
                echo "true";
            } else {
                echo "journal insert false";
            }
        } else {
            echo "false";
            return FALSE;
        }
    }

    /// 11-5-2014
    function updatepayotherreceiveMaster() {
        $this->load->model('accountPayable/othersPayment_model');
        $data = array(
            'updatedBy' => element('role', $this->session->userdata('logged_in')),
            'totalReceived' => $this->input->post('amountPaid'),
            'referenceNo' => $this->input->post('refNo'),
            'receivePaymentDate' => date('Y-m-d', strtotime($this->input->post('date'))),
            'receiveFrom' => $this->input->post('receiveFrom'),
            'memo' => $this->input->post('memo'),
            'projectID' => $this->input->post('project'),
            'bankID' => $this->input->post('bankId'),
            'paymentMethodID' => $this->input->post('paymentmethood'),
            'formNo' => $this->input->post('formNo')
        );
        echo $query = $this->othersPayment_model->updateByTname($this->input->post('masterID'), $data, 'comp_receive_payment_others');
    }

    public function otherpaymentDelete() {
        $this->load->model('accountPayable/othersPayment_model');
        $res = $this->othersPayment_model->updateByTname($this->input->post('ID'), array("is_delete" => 1), "comp_payment_others");
        if ($res) {
            echo "success";
        } else {
            echo "fail";
        }
    }

    public function otherreceiveDelete() {
        $this->load->model('accountPayable/othersPayment_model');
        $res = $this->othersPayment_model->updateByTname($this->input->post('ID'), array("is_delete" => 1), "comp_receive_payment_others");
        if ($res) {
            echo "success";
        } else {
            echo "fail";
        }
    }

    public function journalUnpost() {
        $this->load->model('Journal');

        $ID = $this->input->post('ID');
        $journalNo = $this->input->post('journalID');
       // $formNo = $this->input->post('formNo');
        $companyID = element('compID', $this->session->userdata('logged_in'));
        $dateJournal = $this->input->post('dateJournal');
        $sql = "Select id,status from comp_financial_year where startDate<= ? and endDate >= ? and companyID = $companyID";
        $query = $this->db->query($sql, array($dateJournal, $dateJournal));
        $res = $query->result();

        if ($query->num_rows() > 0) {
            if ($res[0]->status == 1) {
                print $res[0]->id."Unposting deny: Financial year close";
            } else {
                $data = array(
                    'status' => 0
                );
                $this->load->model('Journal');
                $query = $this->Journal->journal_save($ID, $journalNo, $data);
                if ($query) {
                    print "success";
                } else {
                    print "Unposting Fail: Update issues";
                }
            }
        }else{
            print  "Unposting Deny: Financial year not found";
        }
    }

    public function journalUnconfirm() {
        $this->load->model('Journal');

        $ID = $this->input->post('ID');
        $journalID = $this->input->post('journalID');
        $formNo = $this->input->post('formNo');
        $companyID = element('compID', $this->session->userdata('logged_in'));
        $status = "Fail To unconfirmed this transaction";

        $masterTable = $this->Journal->get_journal_masterTable($companyID, $journalID, $formNo);
//	$status = 'mastertable='.$this->db->last_query(); 
        if ($masterTable) {
            $table_name = $masterTable[0]->tableName;
            $master_table_id = $masterTable[0]->ID;
//                $this->load->model('accountPayable/othersPayment_model');
//                $data = array('updateAble' => 1, 'journalNo'=>"");
//                $res1 = $this->Journal->updateByTname($master_table_id, $data, $table_name);
//
//                $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
//                $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail);
//
//                $status = "success";
//$status .= 'tablename='.table_name; 
            switch ($table_name) {
                case "comp_payment_others":

                    $this->load->model('accountPayable/othersPayment_model');
                    $data = array('updateAble' => 1, 'journalNo' => "");

                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_payment_others");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_receive_payment_others":
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_receive_payment_others");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_sales_invoice":
                    $sql = "Select ID  from comp_sales_debitnote where is_delete = 0 AND salesInvoiceID = $master_table_id"
                            . " UNION "
                            . "Select ID  from comp_sales_creditnote where is_delete = 0 AND salesInvoiceID = $master_table_id"
                            . " UNION "
                            . "Select a.ID  from comp_receive_payment a, comp_receive_payment_detail b  "
							. " where a.ID = b.receivePaymentID and a.is_delete =0 and b.invoiceID = $master_table_id";
                    $query = $this->db->query($sql);
                    if ($query->num_rows() > 0) {
                        $status = "Fail to unconfirm this sale invoice due some Debit/Credit Note/Payment(s) related to this invoice";
                    } else {
                        $data = array('updateAble' => 1, 'journalNo' => "");
                        $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_sales_invoice");

                        $trashID = $this->Journal->trash("comp_journal", $ID);
                        $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                        $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                        $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");
                        $status = "success";
                    }
                    break;

                case "comp_sales_debitnote":
//add new condition to check payment status before delete/cancel. akmal 20151121
					$sql = "Select b.ID  from comp_receive_payment_detail_debitnote a, comp_receive_payment b  "
							. " where a.paymentID = b.ID AND b.is_delete = 0 and debitnoteID = $master_table_id";
                    $query = $this->db->query($sql);
                    if ($query->num_rows() > 0) {
                        $status = "Fail to unconfirm this sale debitnote due some payment(s) related to this debitnote";
                    } else {

						$this->Journal->itemIncrease($master_table_id,3);

						$data = array('updateAble' => 1, 'journalNo' => "");
						$res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_sales_debitnote");

						$trashID = $this->Journal->trash("comp_journal", $ID);
						$resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

						$res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
						$res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");
                    
//                    $sql = "Select inv.locationID, debt.itemID, debt.quantity, type, typeID "
//                            . "from comp_sales_debitnote deb, comp_sales_debitnote_detail debt, "
//                            . "comp_sales_invoice inv, ";
//                    
//                    $data = array(
//                        'locationID'	=> $row->locationID,
//                        'itemID'		=> $row->itemID,
//                        'quantity'		=> $qtyReduce,
//                        'type'			=> $row->typeID,
//                        'typeID'		=> $row->typeDetailID,
//                    );
                    
						$status = "success";
					}
                    break;
                case "comp_sales_creditnote":
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_sales_creditnote");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");
                    
                    
                    $invId = 0;
                    $amt = 0;
                    $resInv = $this->db->query("Select 	salesInvoiceID,totalAmount  from comp_sales_creditnote where ID = ?", $master_table_id);
 
                    if($resInv){
                        $resss = $resInv->result();
                       $invId = $resss[0]->salesInvoiceID;
                       $amt = $resss[0]->totalAmount;
                    }
                    
                   $resUpd = $this->db->query("Update comp_sales_invoice set totalReceivable = 	totalReceivable + ".$amt." Where ID = ".$invId);
                  
                   
                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_receive_payment":
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_receive_payment");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_cash_sales":
                    $this->Journal->itemIncrease($master_table_id,5);
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_cash_sales");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_supplier_invoice":
                    $sql = "Select ID, 'debit' as type  from comp_supplier_debitnote where is_delete = 0 AND supplierInvoiceID = $master_table_id"
                            . " UNION "
                            . "Select ID, 'credit' as type  from comp_supplier_creditnote where is_delete = 0 AND supplierInvoiceID = $master_table_id"
                            . " UNION "
                            . "Select a.ID, 'payment' as type  from comp_payment a, comp_payment_detail b "
							. "	where a.ID = b.paymentID and a.is_delete = 0 AND b.purchaseInvoiceID = $master_table_id";
                    $query = $this->db->query($sql);
                    if ($query->num_rows() > 0) {
                        $status = "Fail to unconfirm this purchase invoice due some Debit/Credit Note/Payment(s) related to this invoice";
                    } else {
                        $data = array('updateAble' => 1, 'journalNo' => "");
                        $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_supplier_invoice");

                        $trashID = $this->Journal->trash("comp_journal", $ID);
                        $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                        $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                        $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");
                        $status = "success";
                    }
                    break;
                case "comp_supplier_creditnote":
//add checking payment before cancel supplier creditnote. akmal 20151121				
                    $sql = "Select a.ID  from comp_payment a, comp_payment_detail_creditnote b where "
                        . " a.ID = b.paymentID and a.is_delete = 0 and creditnoteID = $master_table_id";
                    $query = $this->db->query($sql);
                    if ($query->num_rows() > 0) {
                        $status = "Fail to unconfirm this purchase creditnote due some payment(s) related to this creditnote";
                    } else {
						$data = array('updateAble' => 1, 'journalNo' => "");
						$res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_supplier_creditnote");

						$trashID = $this->Journal->trash("comp_journal", $ID);
						$resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

						$res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
						$res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

						$status = "success";
					}
                    break;
                case "comp_supplier_debitnote":
                   $data = array('updateAble' => 1, 'journalNo' => "");
                   $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_supplier_debitnote");
                    
                    $supplierInvoiceID = 0;
                    $amt = 0;
                    $resInv = $this->db->query("Select supplierInvoiceID,totalAmount  from comp_supplier_debitnote where ID = ?", $master_table_id);
                    if($resInv){
                        $resss = $resInv->result();
                       $supplierInvoiceID = $resss[0]->supplierInvoiceID;
                       $amt = $resss[0]->totalAmount;
                    }
                    
                   $resUpd = $this->db->query("Update  comp_supplier_invoice set totalPayable = totalPayable + ".$amt." Where ID = ".$supplierInvoiceID);
                  
                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_payment":
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_payment");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_payment_others":
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_payment_others");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_delivery_order":
                    $this->Journal->itemIncrease($master_table_id,1);
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_delivery_order");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_receive_item":
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_receive_item");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_sales_bad_debt":
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_sales_bad_debt");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_sales_debt_recover":
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_sales_debt_recover");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_purchase_bad_debt":
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_purchase_bad_debt");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                case "comp_purchase_debt_recover":
                    $data = array('updateAble' => 1, 'journalNo' => "");
                    $res1 = $this->Journal->updateByTname($master_table_id, $data, "comp_purchase_debt_recover");

                    $trashID = $this->Journal->trash("comp_journal", $ID);
                    $resA = $this->Journal->trash_detail("comp_journal_detail", $journalID, $trashID, "journalID");

                    $res2 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal");
                    $res3 = $this->Journal->deleteByTname("journalID", $journalID, "comp_journal_detail");

                    $status = "success";
                    break;
                default:
                    break;
            }
        }
        echo $status;
    }

}

/* End of file gltransaction.php */
/* Location: ./application/controller/gltransaction.php */
