<?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');
		  	$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')),
		  					);
		  	$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)){
		  		$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')),
	  					);
			  	$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 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;
		$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 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(true || $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
     
    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 $this->db->last_query(); 

        if ($query) {
			if ($query[0]->exchangeRate==0 || $query[0]->exchangeRate == '') $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 = $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 "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 ,
                '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);
                echo "true";
            } else {
               echo "false";
            }
        } else {
            echo "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')
		);

		 $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'),
			'amountIncludedTax' => $this->input->post('amountIncludedTax')
		);
		 $query = $this->othersPayment_model->insert('comp_payment_others_without_item',$datinsertDetails);
		 $detail=$this->othersPayment_model->getLasIdInsert("comp_payment_others_without_item");
		 echo '{"status":"success","paymentID":"'.$otherPaymentID.'","detailID":"'.$detail.'"}';
		}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'),
			'amountIncludedTax' => $this->input->post('amountIncludedTax')
		);
		 $query = $this->othersPayment_model->insert('comp_payment_others_without_item',$datinsertDetails);
		 $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('taxmaster');
			$data['taxmaster'] = $this->taxmaster->taxmaster_saleOutput();
			
			$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')
		);

		 $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' => '0'
        );
        
        $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 "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 . ' ]',
                '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);
                echo "true";
            } else {
               echo "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')
		);
		echo $query = $this->othersPayment_model->updateByTname($this->input->post('masterID'), $data,
		 'comp_receive_payment_others');
        }
	
}

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