<?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()
	{
		
	}
	
		
// created by Eisa
// 20th may 2014

	public function newPayWithoutItem(){
			$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_all();
			
                        
                        $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('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);
	}
	
	public function newPayWithItem(){
			$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_all();
			
			$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']=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/newotherpaymentwithitem', '', $data);
	}
	
	public function editPayWithItem($id){
			$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('item/itemSetup_model');
                        $data['items'] = $this->itemSetup_model->get_all();
		
			$this->load->model('taxmaster');
			$data['taxmaster'] = $this->taxmaster->taxmaster_all();
			
			$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('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_all();
			
			$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'),
			'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 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.'"}';
	}
	
	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 savenewpaywithOutItem(){
		$this->load->model('accountPayable/othersPayment_model');
		$ID = $this->input->post('ID');
		$companyID =  element('role', $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'),
			'paymentDate' => $this->input->post('paymentDate'),
			'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 savenewpaywithItem(){
		$this->load->model('accountPayable/othersPayment_model');
		$ID = $this->input->post('ID');
		$companyID =  element('role', $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'),
			'paymentDate' => $this->input->post('paymentDate'),
			'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'),
			'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->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);
		//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->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)
	{
		//$otherPaymentID = $this->uri->segment(5);
		$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))
											);
             
          //   $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("taxRate"), $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";
//		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','');
		}else{
			//download excell
			$this->load->helper('excel');
			excel($bodyData);
		}
	}
	
    //Other Payment Without Item List - Farhana
	public function otherpaywithoutList()
	{
		$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->otherpayWithoutItem_date($dateFrom, $dateTo);
		
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ap/othersPayment/newotherpaywithoutitemList', '', $data);
	}
	
	public function otherpaywithoutDetail($otherPaymentID,$mode = false)
	{
		//$otherPaymentID = $this->uri->segment(5);
		$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(
												$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))
											);
             
          //   $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("taxRate"), $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";
//		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','');
		}else{
			//download excell
			$this->load->helper('excel');
			excel($bodyData);
		}
	}
	
	public function otherpaywithoutListprint()
	{
		$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('titlelist2');
        $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->otherpayWithoutItem_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','');
	}

	//Other Pay With Item Post
	public function otherpaywithItemPost(){
		$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);
	}
	
	public function otherpaywithItemPosting()
	{}


	//Other Pay Without Item Post
	public function otherpaywithoutItemPost(){
		$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->otherpaywithoutitem_unpost($dateFrom, $dateTo);
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ap/transactions/otherpaywithoutItemPost', array('latest' => 'sidebar/latest'), $data);
	}
	
	public function otherpaywithoutItemPosting()
	{}
}

