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

class OthersPayment extends CI_Controller {
	
	public function __construct(){
		parent::__construct();
		$this->load->model('Useraccess');
		$query = $this->Useraccess->useraccess_id_module2('3', '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 newPayWithItem(){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('APOPWI');
        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();
			
			$this->load->model('bank/bank_model');
			$data['bankaccount'] = $this->bank_model->bank_all();
			
			$this->load->model('company/formSetup_Model');
			$filter['companyID']=element('compID', $this->session->userdata('logged_in'));
			$filter['formID']=124;
			$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/newotherpaymentwithitem', '', $data);
	}
	
	public function editPayWithItem($id){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('APTRPYIE');
        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->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->lang->load("otherspayment",$this->session->userdata('language'));
			
			$this->load->model('Usermaster');
			$data['records'] = $this->Usermaster->usermaster_all();
                        
                        $this->load->model('Project/project_model');
                        $data['project'] = $this->project_model->project_all();
			
			$this->load->model('item/itemSetup_model');
                        $data['items'] = $this->itemSetup_model->get_all();
		
			$this->load->model('taxmaster');
			$data['taxmaster'] = $this->taxmaster->taxmaster_purchaseInput();
			
			$this->load->model('accountPayable/othersPayment_model');
			$data['pdetails']=$this->othersPayment_model->getOthersPaymentDetail($id,"comp_payment_others_with_item");
			$data['otherPay']=$this->othersPayment_model->getOthersPayment($id);
			
			$this->layouts->view('ap/othersPayment/editotherpaymentwithitem', '', $data);
	}
	
	public function editPayWithoutItem ($id){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('APTRPYOE');
        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'));
			$filter['formID']=41;
			$data['formNo']= $this->formSetup_Model->getFormNo($filter); 
			$this->lang->load("otherspayment",$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_purchaseInput();
			
			$this->load->model('accountPayable/othersPayment_model');
			$data['pdetails']=$this->othersPayment_model->getOthersPaymentDetail($id,"comp_payment_others_without_item");
			$data['otherPay']=$this->othersPayment_model->getOthersPayment($id);
			
			$this->layouts->view('ap/othersPayment/editotherpaymentwithoutitem', '', $data);	
	}
	
	private function getItemCodes(){
		$JsonRecords = '[';
		$i= 0;
		$this->load->model('item/itemSetup_model');
		//$default = $this->itemSetup_model->get_byCode($this->input->post('itemCode'));
		$default = $this->itemSetup_model->get_all();
		$n = sizeof($default);
		if ($default) foreach($default as $row){
			$JsonRecords .= '&quot;'.$row->itemCode.'&quot;';
			if ($i < $n - 1)
				$JsonRecords .= ',';
			$i++;
		}
		 $JsonRecords .= ']';
		 return $JsonRecords;
	}
	
	function refreshPayMethod(){
		$this->load->model('master/masterCode_model');
		$filter['masterID']=7;
		$data = $this->masterCode_model->get_all($filter);
		
		$JsonRecords = '{"records":[';
		
		$i= 0;
		$n = sizeof($data);
		 foreach($data as $row){
			$JsonRecords .= '{';
			$JsonRecords .= '"id":"' . $row->ID.'",'.'"name":"'.$row->name.'"';
			$JsonRecords .= '}';
			if ($i < $n - 1)
				$JsonRecords .= ',';
			$i++;
		}
		$JsonRecords .= ']}';
		 echo $JsonRecords;

	}
	
	function savenewpaywithItemDetailOnly(){
			$this->load->model('accountPayable/othersPayment_model');
			$datinsertDetails = array (
			'otherPaymentID' => $this->input->post('otherPaymentID'),
			'createdBy' => element('role', $this->session->userdata('logged_in')),
			'itemID' => $this->input->post('itemID'),
			'lineNo' => $this->input->post('lineNo'), 
			'itemdescription' => $this->input->post('itemdescription'),
			'quantity' => $this->input->post('quantity'),
                            'umID' => $this->input->post('umid'),
			'unitPrice' => $this->input->post('unitPrice'),
			'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_with_item',$datinsertDetails);
		 $detail=$this->othersPayment_model->getLasIdInsert("comp_payment_others_with_item");
		 echo '{"status":"success","detailID":"'.$detail.'"}';
	}
	
	
	function getItemDetails(){
		$JsonRecords = '{';
		$i= 0;
		$this->load->model('item/itemSetup_model');
		$default = $this->itemSetup_model->get_byCode($this->input->post('code'));
		//$default = $this->itemSetup_model->get_all();
		$n = sizeof($default);
		//print json_encode(array("status"=>"success", "message"=>$query));
		if($default){
		 foreach($default as $row){
			 
			 $tax="0";
			 $taxcode = "...";
			 $this->load->model('taxmaster');
		     $taxObj = $this->taxmaster->taxmaster_id($row->inputTaxID);
			 if($taxObj){
			  foreach($taxObj as $taxrow){
				   $tax=$taxrow->taxPercentage;
				   $taxcode = $taxrow->code;
			  }}
			$JsonRecords .= '"itemID":"'.$row->ID.'","taxcode":"'.$taxcode.'","name":"'.$row->name.'","description":"' .$row->description.'", "tax":"'.$tax.'", "taxID":"' .$row->inputTaxID.'"';
			if ($i < $n - 1)
				$JsonRecords .= ',';
			$i++;
		}
		 $JsonRecords .= '}';
		 echo $JsonRecords;
		}else {
			echo "item Not found";
			}
	}
        
        function updatepayitemwithoutitemMaster(){
            $this->load->model('accountPayable/othersPayment_model');
			$data = array (
			'updatedBy' => element('role', $this->session->userdata('logged_in')),
			'amountPaid' => $this->input->post('amountPaid'), 
			'referenceNo' => $this->input->post('refNo')
		);
		echo $query = $this->othersPayment_model->updateByTname($this->input->post('masterID'), $data,
		 'comp_payment_others');
        }
                
	function savenewpaywithItem(){
		$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' => 0,
			'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){
			
			$datinsertDetails = array (
			'otherPaymentID' =>  $otherPaymentID,
			'createdBy' => element('role', $this->session->userdata('logged_in')),
			'itemID' => $this->input->post('itemID'),
                        'lineNo' => $this->input->post('lineNo'),
			'itemdescription' => $this->input->post('itemdescription'),
			'quantity' => $this->input->post('quantity'),
                             'umID' => $this->input->post('umid'),
			'unitPrice' => $this->input->post('unitPrice'),
			'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_with_item',$datinsertDetails);
		 echo '{"status":"success","paymentID":"'.$otherPaymentID.'","detailID":"'.$query.'"}';
		}else{
			echo "false";
		}
	}
	
	function updatepayitemwithitem(){
	$this->load->model('accountPayable/othersPayment_model');
			$data = array (
			'updatedBy' => element('role', $this->session->userdata('logged_in')),
			'itemID' => $this->input->post('itemID'), 
			'itemdescription' => $this->input->post('itemdescription'),
			'quantity' => $this->input->post('quantity'),
			'unitPrice' => $this->input->post('unitPrice'),
			'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')
		);
		echo $query = $this->othersPayment_model->updateByTname($this->input->post('invDetailsId'), $data,
		 'comp_payment_others_with_item');
	}
	
	function updatepayitemwithoutitem(){
			$data = array (
			'updatedBy' => element('role', $this->session->userdata('logged_in')),
			'itemdescription' => $this->input->post('itemdescription'),
			'accountID' => $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_payment_others_without_item');
	}
	
	function deletePaymentWithItem(){
		$this->load->model('accountPayable/othersPayment_model');
		echo $this->othersPayment_model->deleteByTname($this->input->post('rowID'),"comp_payment_others_with_item");
	}
   
    
	function deletePaymentWithoutItem(){
		$this->load->model('accountPayable/othersPayment_model');
		echo $this->othersPayment_model->deleteByTname($this->input->post('rowID'),"comp_payment_others_without_item");
	}
   
   
	public function otherpay_edit(){
			$this->load->model('accountPayable/othersPayment_model');
		  	$updateuser = array('is_delete' => '1');
			$ID = $this->input->post('ID');
		  	$updateuser = $this->othersPayment_model->otherpay_edit($updateuser,$ID);
			if($updateuser){
				return TRUE;
			}else{
				return FALSE;
			}
	}
	//Other Payment With Item List - Farhana
	public function otherpaywithList()
	{
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('APRPTOPW');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->load->library('layouts');
		$this->load->helper('form');
		$this->load->helper('menu');
		$this->lang->load("otherspayment",$this->session->userdata('language'));
		$this->load->model('accountPayable/othersPayment_model');
		$this->load->model('company/FormSetup_model');
		$filter['companyID']=element('compID', $this->session->userdata('logged_in'));
		$filter['formID']=55;
		$data['formNo']= $this->FormSetup_model->getFormNo($filter); 
		
		$data['headertbl'] = $this->session->userdata('menuactive');
		
		$dateFrom = date("Y-m-d",strtotime($this->uri->segment(3)));
		$dateTo = date("Y-m-d",strtotime($this->uri->segment(4)));
		
		if ($this->uri->segment(3) == ""){
			$dateFrom = date("Y-m-01");
		}
		if($this->uri->segment(4) == ""){
			$dateTo = date("Y-m-t");
		}
		if($dateFrom > $dateTo){
			$dateTo = date("Y-m-t", strtotime($dateFrom));
		}
		
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		
		$data['datatbls'] = $this->othersPayment_model->otherpayWithItem_date($dateFrom, $dateTo,0);  //report will data updateable=0
		//echo $this->db->last_query();
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ap/othersPayment/newotherpaywithitemList', '', $data);
	}
   
   	public function otherpaywithListprint()
	{
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('APRPTOPW');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->load->library('layouts');
		$this->load->helper('form');
		$this->load->helper('menu');
		$this->lang->load("otherspayment",$this->session->userdata('language'));
		$this->load->model('accountPayable/othersPayment_model');
		$this->load->model('company/FormSetup_model');
		$filter['companyID']=element('compID', $this->session->userdata('logged_in'));
		$filter['formID']=55;
		$data['formNo']= $this->FormSetup_model->getFormNo($filter);
		$this->load->model('company/company_info_model'); 
		
		$data['headertbl'] = $this->session->userdata('menuactive');
		
		$dateFrom = date("Y-m-d",strtotime($this->uri->segment(3)));
		$dateTo = date("Y-m-d",strtotime($this->uri->segment(4)));
		
		if ($this->uri->segment(3) == ""){
			$dateFrom = date("Y-m-01");
		}
		if($this->uri->segment(4) == ""){
			$dateTo = date("Y-m-t");
		}
		if($dateFrom > $dateTo){
			$dateTo = date("Y-m-t", strtotime($dateFrom));
		}
		
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		
		//$headerData['rightContentHeader'] = "Name supplier/ ot";
        $headerData['rptTitle'] = $this->lang->line('titlelist1');
        $headerData['rightContent'] = array($this->lang->line('dateFrom')." ".date('d-m-Y',strtotime($dateFrom))." ".$this->lang->line('dateTo')." ".date('d-m-Y',strtotime($dateTo)));
        //$headerData['leftContent'] = array("Left : value", "Left: value");
             
        $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
              
        $bodyData['rptDataDetail'] = $this->othersPayment_model->otherpayWithItem_date($dateFrom, $dateTo);
        $bodyData['tableHeader'] = array($this->lang->line('formno'), $this->lang->line('payto'), $this->lang->line('paymentdate'), $this->lang->line('amountpaid'));
		
		//$ID = isset($_REQUEST['ID'])?$_REQUEST['ID']:"";
		//$fad = $this->FormSetup_model->getFormSerialNo_zeroLeading($ID);
		//var_dump($fad);
		 
        $bodyData['selectFields'] = array("formNo","payTo", "payDate", "amountPaid");
        $bodyData ['tdAmount'] = array("amountPaid");
        //$bodyData['tableFooter'] = array ("footer : value");
            
        $this->load->view('layouts/report/header', $headerData);
        $this->load->view('layouts/report/body', $bodyData);
        $this->load->view('layouts/report/footer','');
	}
   public function otherpaywithDetail($otherPaymentID,$mode = false)
	{
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('APRPTOPW');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->load->library('layouts');
		$this->load->helper('form');
		$this->load->helper('menu');
		$this->load->model('company/company_info_model');
		$this->load->model('accountPayable/othersPayment_model');
		$this->load->model('company/FormSetup_model');
		$filter['companyID']=element('compID', $this->session->userdata('logged_in'));
		$filter['formID']=55;
		$data['formNo']= $this->FormSetup_model->getFormNo($filter);
		
		$this->lang->load("otherspayment",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->othersPayment_model->othersPaymentWithItem_ID($otherPaymentID); //detail
		$data['transInfo'] = $this->othersPayment_model->otherpayWithItem_byID($otherPaymentID);
//		echo $this->db->last_query();
		//$supplierInfo = $this->supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
//		var_dump($data['transInfo'][0]);
		//var_dump($data['datatbls'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle");
             $headerData['leftContent'] = array(
												$data['transInfo'][0]->payTo,
											);
			 $headerData['rightContent'] = array(
												$this->lang->line("formno").":".$data['transInfo'][0]->otherPaymentNo,
												$this->lang->line("date").":".date('d-m-Y', strtotime($data['transInfo'][0]->paymentDate)),
												$this->lang->line("referenceNo").":".$data['transInfo'][0]->referenceNo
											);
             
          //   $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
			$bodyData['rptDataDetail'] = $data['datatbls'];
			$bodyData['tableHeader'] = array($this->lang->line("itemName"), $this->lang->line("description"), $this->lang->line("unitPrice"), $this->lang->line("quantity"), $this->lang->line("um"), $this->lang->line("amountExcludeTax"), $this->lang->line("taxRate"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData['selectFields'] = array("itemname", "itemdescription", "unitPrice", "quantity", "code", "amountExcludedTax","taxRate","taxAmount","amountIncludedTax");
			$bodyData ['tdAmount'] = array("unitPrice", "quantity","amountExcludedTax","taxRate","taxAmount","amountIncludedTax");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['excelTitle'] = "Location Transfer Detail";
			
			$netTotal1 = 0;
            $taxPayable1 = 0;
            $totalTbl1 = 0;
             if(!empty($bodyData['rptDataDetail'])){
			foreach($bodyData['rptDataDetail'] as $row){
				$netTotal1 += $row->amountExcludedTax;
				$taxPayable1 += $row->taxAmount;
				$totalTbl1 += $row->amountIncludedTax;
			}
		}
                
              $netTotal2 = 0;
            $taxPayable2 = 0;
            $totalTbl2 = 0;
             if(!empty($bodyData2['rptDataDetail'])){
			foreach($bodyData2['rptDataDetail'] as $row){
				$netTotal2 += $row->amountExcludedTax;
				$taxPayable2 += $row->taxAmount;
				$totalTbl2 += $row->amountIncludedTax;
			}
		}
             
               
            
                
            $footerData['amountCount'] = array (
												$this->lang->line('totalExcTax').": ".$data['transInfo'][0]->currency.' '.number_format((double)($netTotal1 + $netTotal2),2),
												$this->lang->line('totalTax').": ".$data['transInfo'][0]->currency.' '.number_format((double)($taxPayable1 + $taxPayable2),2),
												$this->lang->line('totalIncTax').": ".$data['transInfo'][0]->currency.' '.number_format((double)($totalTbl1 + $totalTbl2),2),
											);
//		var_dump($mode);		
		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 otherpaywithoutDetail($otherPaymentID,$mode = false)
	{
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('APRPTOPW');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->load->library('layouts');
		$this->load->helper('form');
		$this->load->helper('menu');
		$this->load->model('company/company_info_model');
		$this->load->model('accountPayable/othersPayment_model');
		$this->load->model('company/FormSetup_model');
		$filter['companyID']=element('compID', $this->session->userdata('logged_in'));
		$filter['formID']=55;
		$data['formNo']= $this->FormSetup_model->getFormNo($filter);
		
		$this->lang->load("otherspayment",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->othersPayment_model->othersPaymentWithoutItem_ID($otherPaymentID); //detail
		$data['transInfo'] = $this->othersPayment_model->otherpayWithoutItem_byID($otherPaymentID);
//		echo $this->db->last_query();
		//$supplierInfo = $this->supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
//		var_dump($data['transInfo'][0]);
		//var_dump($data['datatbls'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle2");
             $headerData['leftContent'] = array(
												"<b>".$this->lang->line("payTo")." : ".$data['transInfo'][0]->payTo."</b>",
											);
			 $headerData['rightContent'] = array(
												$this->lang->line("formno").":".$data['transInfo'][0]->otherPaymentNo,
												$this->lang->line("date").":".date('d-m-Y', strtotime($data['transInfo'][0]->paymentDate)),
												$this->lang->line("refno").":".$data['transInfo'][0]->referenceNo
											);
             
          //   $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
			$bodyData['rptDataDetail'] = $data['datatbls'];
			$bodyData['tableHeader'] = array($this->lang->line("description"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData['selectFields'] = array("itemdescription","amountExcludedTax","taxRate","taxAmount","amountIncludedTax");
			$bodyData ['tdAmount'] = array("amountExcludedTax","taxRate","taxAmount","amountIncludedTax");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['excelTitle'] = "Location Transfer Detail";
                        
                         $netTotal2 = 0;
            $taxPayable2 = 0;
            $totalTbl2 = 0;
             if(!empty($bodyData['rptDataDetail'])){
			foreach($bodyData['rptDataDetail'] as $row){
				$netTotal2 += $row->amountExcludedTax;
				$taxPayable2 += $row->taxAmount;
				$totalTbl2 += $row->amountIncludedTax;
			}
		}
             
               
            
                
            $footerData['amountCount'] = array (
												$this->lang->line('totalExcTax').": ".$data['transInfo'][0]->currency.' '.number_format((double)($netTotal2),2),
												$this->lang->line('totalTax').": ".$data['transInfo'][0]->currency.' '.number_format((double)($taxPayable2),2),
												$this->lang->line('totalIncTax').": ".$data['transInfo'][0]->currency.' '.number_format((double)($totalTbl2),2),
											); 
            
//		var_dump($mode);		
		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);
		}
	}
	

	//Other Pay With Item Post
	public function otherpaywithItemPost(){
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('APPAYICM');
        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('accountPayable/othersPayment_model');
		$this->load->model('company/FormSetup_model');
		$dateFrom = date("Y-m-d",strtotime($this->uri->segment(3)));
		$dateTo = date("Y-m-d",strtotime($this->uri->segment(4)));
		if ($this->uri->segment(3) == ""){
			$dateFrom = date("Y-m-01");
		}
		if($this->uri->segment(4) == ""){
			$dateTo = date("Y-m-t");
		}
		if($dateFrom > $dateTo){
			$dateTo = date("Y-m-t", strtotime($dateFrom));
		}
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		$data['datatbls'] = $this->othersPayment_model->otherpaywithitem_unpost($dateFrom, $dateTo);
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ap/transaction/otherpaywithoutItemPost', array('latest' => 'sidebar/latest'), $data);
	}
        
        function updatecashpurchaseMaster(){
           $this->load->model('accountPayable/othersPayment_model');
			$data = array (
			'updatedBy' => element('role', $this->session->userdata('logged_in')),
			'amountPaid' => $this->input->post('amount'), 
			'referenceNo' => $this->input->post('refNo'),
                        'projectID' => $this->input->post('project'),
                        'paymentDate' => date("Y-m-d",  strtotime($this->input->post('createdOn'))),
                        'memo' => $this->input->post('memo')
		);
		echo $query = $this->othersPayment_model->updateByTname($this->input->post('masterID'), $data,
		 'comp_payment_others');
        }
}

