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

class ApTransactionReport 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 printPaymentAdviceRpt(){
			
			
			$id = $this->uri->segment(3); 
			$data['id'] = $id;
			$this->load->model('company/company_info_model');
			$data['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
			$this->load->model('purchase/purchase_model');
			$data['rptData'] = $this->purchase_model->rptGetPaymentAdvice($id);
			$data['rptDataDetail'] = $this->purchase_model->rptGetPaymentAdviceDetail($id);
			
			$this->lang->load("aptransactionreport",$this->session->userdata('language'));
                        //$this->load->view('layouts/rptheader', $data);
			$this->load->view('ap/reports/paymentAdviceRpt', $data);
			
	}
	public function printPaymentAdviceRptExel(){
	 //place where the excel file is created
        $this->load->library('parser');
 		
		$id = $this->uri->segment(3); 
			$data['id'] = $id;
		$this->load->model('company/company_info_model');
		$data['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
		$this->load->model('purchase/purchase_model');
		$data['rptData'] = $this->purchase_model->rptGetPaymentAdvice($id);
		$data['rptDataDetail'] = $this->purchase_model->rptGetPaymentAdviceDetail($id);
		
		$this->lang->load("aptransactionreport",$this->session->userdata('language'));
       
 
        //pass retrieved data into template and return as a string
        $stringData = $this->parser->parse('ap/reports/paymentAdviceExcel', $data, true);
 
        //open excel and write string into excel
		
		 $myFile = "paymentAdviceExcel.xls";
         $fh = fopen($myFile, 'w') or die("can't open file");
         fwrite($fh, $stringData);
		 fclose($fh);
 		$this->downloadExcel("paymentAdviceExcel.xls");
       
        //download excel file
        
		
	}
	
		
/* download created excel file */
    function downloadExcel($myFile) {
        header("Content-Length: " . filesize($myFile));
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment; filename='.$myFile);
		readfile($myFile);
}
	// edit of debit note
	
	public function printPaymentAdvice ($id){
			$this->load->model('company/formSetup_Model');
			
			$this->lang->load("invoices",$this->session->userdata('language'));
	
			$this->load->library('layouts');
			
			$this->lang->load("aptransactionreport",$this->session->userdata('language'));
			
			$this->load->model('Usermaster');
			$data['records'] = $this->Usermaster->usermaster_all();
			
			$this->load->model('company/company_info_model');
			$data['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
			
			$data['id'] = $id;
			$this->load->model('purchase/purchase_model');
			$data['rptData'] = $this->purchase_model->rptGetPaymentAdvice($id);
			$data['rptDataDetail'] = $this->purchase_model->rptGetPaymentAdviceDetail($id);
		
			$this->layouts->view('ap/reports/paymentAdvice', '', $data);
	
	}
        
        
        //trying rpt
        public function rptExample ($id='',$mode = false){
           
            
            /**
             * header parameter :
              1) company (must)
               $this->load->model('company/company_info_model');
               $data['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in'))); 
               2) rightContent 
                 array 
               3) rightContentHeader
                 string
               4) rightContent
                array
               5) leftContent
                 array 
               6 rptTitle
                 string
              7) id (must)
               integer (id of master table)
             * 
             * 
             *single array of string Example : $dataBody[bodyFooter] = array ("Total : 1,290.00","Total Tax: 0.00"),
             
             * body parameters
               1) rptDataDetail
                query result 
               2) selectFields
                    -array  (Field name in select)
               3)tableHeader
                   -array( label of the table )
               4) tableFooter
                    array 
               5) tdNoFormat
                   array (field name in select)
               6) excelTitle
                   string:title of the excel file.
               7) Compulsary add parameter '$mode = false' to the function
             *
             */
             //$id = $this->uri->segment(3);
            $this->load->model('company/company_info_model');
            $this->load->model('purchase/purchase_model');
            $this->lang->load("aptransactionreport",$this->session->userdata('language'));
            
            
             
             
             
            $headerData['rightContentHeader'] = "Right Content Header";						//Header right side bold content.
            $headerData['leftContentHeader'] = "Left Content Header";						//Header left side bold content.
            $headerData['rptTitle'] = "Payment Voucher";									//Title of the report
            $headerData['rightContent'] = array("Right : value");							//Header right side normal sized content
            $headerData['leftContent'] = array("Left : value", "Left: value");				//Header left side normal sized content
            
            $bodyData['rptDataDetail'] = $this->purchase_model->rptGetPaymentAdviceDetail($id); 	//Gather all data from the table
            $bodyData['tableHeader'] = array("Date", "Supplier Inv No", "Amount"); 					//Table header name
            $bodyData['selectFields'] = array("invoiceDate","supplierInvoiceNo", "amountApplied");	//database select names
            $bodyData ['tdAmount'] = array("amountApplied");										//Right align column names
            $bodyData['tableFooter'] = array ("footer : value");									//Footer value
           
        	$bodyData['excelTitle'] = "Payment Voucher";									//Excel download file name
			
			if(!$mode){
				//print
				$this->load->view('layouts/report/header', $headerData);
				$this->load->view('layouts/report/body', $bodyData);
                                $this->load->view('layouts/report/body', $bodyData);
				$this->load->view('layouts/report/footer','');
			}else{
				//download excell
				$this->load->helper('excel');
				excel($bodyData);
			}	
        }
        
        
        
	
	
}

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