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

class Apreports extends CI_Controller {
	
	public function __construct(){
		parent::__construct();
		$this->load->model('Useraccess');
		$query = $this->Useraccess->useraccess_id_module2('3', 'reports');
		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()
	{
		
	}
	
// Account Debit Note List
	public function debitnoteList(){
		$this->lang->load("debitNote",$this->session->userdata('language'));
		$this->load->model('debitnote_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->debitnote_model->debitnote_Date($dateFrom, $dateTo);
//		echo $this->db->last_query();
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ap/reports/debitnoteList', array('latest' => 'sidebar/latest'), $data);
	}
	
	/*public function debitnoteListPrint(){
		$this->lang->load("debitNote",$this->session->userdata('language'));
		$this->load->model('debitnote_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->debitnote_model->debitnote_Date($dateFrom, $dateTo);
//		echo $this->db->last_query();
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->load->view('ap/reports/debitnoteList_print', $data);
	}*/
	
	public function debitnoteListPrint(){
		$this->lang->load("debitNote",$this->session->userdata('language'));
		$this->load->model('debitnote_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_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'] = 
//		echo $this->db->last_query();
		$headerData['rightContentHeader'] = "Name supplier/ ot";
        $headerData['rptTitle'] = "Purchase Debit Note";
        $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->debitnote_model->debitnote_Date($dateFrom, $dateTo);
        $bodyData['tableHeader'] = array($this->lang->line('formNo'), $this->lang->line('invoiceno'), $this->lang->line('supplierName'), $this->lang->line('totalAmount2'));
		
		//$ID = isset($_REQUEST['ID'])?$_REQUEST['ID']:"";
		//$fad = $this->FormSetup_model->getFormSerialNo_zeroLeading($ID);
		//var_dump($fad);
		 
        $bodyData['selectFields'] = array("formNo","supplierInvoiceNo", "supplierName", "totalAmount");
        $bodyData ['tdAmount'] = array("totalAmount");
        //$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 debitnote(){    
		//$id = isset($_REQUEST['id'])?$_REQUEST['id']:"";
		$ID = $this->uri->segment(3);
		$this->lang->load("debitNote",$this->session->userdata('language'));
		$this->load->model('debitnote_model');
		$this->load->model('company/FormSetup_model');
		//$dataum = $this->Company_info_model->company_id($id);
		$dataum = $this->debitnote_model->debitnote_id($ID);
		$data['umaster'] = $dataum[0];
		//if($id >= '0')
		//{
			$this->load->view('ap/reports/debitnote', array('latest' => 'sidebar/latest'), $data);
		//}
		//else
		//{
			//$this->layouts->view('masterfile/company', array('latest' => 'sidebar/latest'), $data);
		//}
	}
	
// Account Credit Note List
        public function creditnoteList(){
		$this->lang->load("creditNote",$this->session->userdata('language'));
		$this->load->model('creditnote_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->creditnote_model->creditnote_Date($dateFrom, $dateTo);
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ap/reports/creditnoteList', array('latest' => 'sidebar/latest'), $data);
	}
		
		/*public function creditnoteListPrint(){
		$this->lang->load("creditNote",$this->session->userdata('language'));
		$this->load->model('creditnote_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->creditnote_model->creditnote_Date($dateFrom, $dateTo);
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->load->view('ap/reports/creditnoteList_print', $data);
	}*/
	
	public function creditnoteListPrint(){
		$this->lang->load("creditNote",$this->session->userdata('language'));
		$this->load->model('creditnote_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_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;
		
		$headerData['rightContentHeader'] = "Name supplier/ ot";
        $headerData['rptTitle'] = "Purchase Debit Note";
        $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->creditnote_model->creditnote_Date($dateFrom, $dateTo);
        $bodyData['tableHeader'] = array($this->lang->line('formNo'), $this->lang->line('invoiceno'), $this->lang->line('supplierName'), $this->lang->line('totalAmount2'));
		
		//$ID = isset($_REQUEST['ID'])?$_REQUEST['ID']:"";
		//$fad = $this->FormSetup_model->getFormSerialNo_zeroLeading($ID);
		//var_dump($fad);
		 
        $bodyData['selectFields'] = array("creditNoteNo","supplierInvoiceNo", "supplierName", "totalAmount");
        $bodyData ['tdAmount'] = array("totalAmount");
        //$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','');
	}
	
	// Account Supplier Payment List
		public function supplierpaymentlist(){
		//$mode = $this->uri->segment(3);
		$this->load->library('layouts');
		$this->lang->load("supplierPaymentList",$this->session->userdata('language'));
		$this->load->model('company/FormSetup_model');
		$this->load->model('supplier/SupplierPayment_model');
		
		$dateFrom = date("Y-m-d",strtotime($this->uri->segment(3)));
		$dateTo = date("Y-m-d",strtotime($this->uri->segment(4)));
		
		//$data['mode'] = $mode;
		
		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->SupplierPayment_model->supplierPaymentDate($dateFrom, $dateTo);
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('supplierpayment/supplierPaymentList', array('latest' => 'sidebar/latest'), $data);
	}
	
	public function supplierpaymentlistprint(){
		$this->load->library('layouts');
		$this->lang->load("supplierPaymentList",$this->session->userdata('language'));
		$this->load->model('company/FormSetup_model');
		$this->load->model('supplier/SupplierPayment_model');
		$this->load->model('company/company_info_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;
		
		$headerData['rightContentHeader'] = "Name supplier/ ot";
        $headerData['rptTitle'] = "Supplier Payment";
        $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->SupplierPayment_model->supplierPaymentDate($dateFrom, $dateTo);
        $bodyData['tableHeader'] = array($this->lang->line('formNo'), $this->lang->line('supplierName'), $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","supplierName", "paymentDate", "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 supplierpaymentDetail($paymentID,$mode = false){
		//$mode = $this->uri->segment(3);
		$this->load->model('company/company_info_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('supplier/SupplierPayment_model');
		$this->load->model('supplier/Supplier_model');
		
		//$data['mode'] = $mode;
		$this->lang->load("supplierPaymentList",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->SupplierPayment_model->supppaymentPrintDetails_ID($paymentID); //detail
		$data['transInfo'] = $this->SupplierPayment_model->supppayment_byID($paymentID);
		$supplierInfo = $this->Supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
		
		//var_dump($data['datatbls'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle");
             $headerData['leftContent'] = array(
												$data['transInfo'][0]->supplierName,
												$data['transInfo'][0]->supplierCompanyNo,
												$data['transInfo'][0]->line1,
												$data['transInfo'][0]->line2,
												$data['transInfo'][0]->line3,
												$data['transInfo'][0]->supplierPostCode.' '.$data['transInfo'][0]->city
											);
			 $headerData['rightContent'] = array(
												$this->lang->line("formNo").":".$data['transInfo'][0]->paymentNo,
												$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("apBalance"), $this->lang->line("amountApplied"), $this->lang->line("discount"), $this->lang->line("totalAmount")); 
			$bodyData['selectFields'] = array("APBalance","amountApplied","discount","totalAmount");
			$bodyData ['tdAmount'] = array("amountApplied","discount","totalAmount");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['excelTitle'] = "Location Transfer Detail";
				
		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);
		}
	}
		
	//Printing report detail
	public function debitNoteDetail($debitNoteID,$mode = false){
           	$this->load->model('company/company_info_model');
			$this->load->model('debitnote_model');
			$this->load->model('supplier/Supplier_model');
		
            $this->lang->load("debitNote",$this->session->userdata('language'));
			//Gather report data

			$data['datatbls'] = $this->debitnote_model->debitNotePrintDetails_ID($debitNoteID); //detail
			$data['transInfo'] = $this->debitnote_model->debitnote_id($debitNoteID);			//master
			$supplierInfo = $this->Supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
			 //var_dump($data['datatbls'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle");
             $headerData['leftContent'] = array(
												$data['transInfo'][0]->supplierName,
												$data['transInfo'][0]->supplierCompanyNo,
												$data['transInfo'][0]->line1,
												$data['transInfo'][0]->line2,
												$data['transInfo'][0]->line3,
												$data['transInfo'][0]->supplierPostCode.' '.$data['transInfo'][0]->city
											);
			 $headerData['rightContent'] = array(
												$this->lang->line("formNo").":".$data['transInfo'][0]->debitNoteNo,
												$this->lang->line("date").":".date('d-m-Y', strtotime($data['transInfo'][0]->debitNoteDate))
											);
             
          //   $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("itemDescription"), $this->lang->line("quantity"), $this->lang->line("unitPrice"), $this->lang->line("amountExcTax"), $this->lang->line("taxRate"), $this->lang->line("amountIncTax"), $this->lang->line("taxAmount")); 
			$bodyData['selectFields'] = array("itemname","itemdescription","quantity","unitPrice","amountExcludedTax","taxRate","amountIncludedTax","taxAmount");
			$bodyData ['tdAmount'] = array("quantity","unitPrice","amountExcludedTax","taxRate","amountIncludedTax","taxAmount");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['excelTitle'] = "Location Transfer Detail";
				
		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);
		}	
	}
	
	//Printing report detail
	public function creditNoteDetail($creditNoteID,$mode = false){
           	$this->load->model('company/company_info_model');
			$this->load->model('creditnote_model');
			$this->load->model('supplier/Supplier_model');
		
            $this->lang->load("creditNote",$this->session->userdata('language'));
			//Gather report data

			$data['datatbls'] = $this->creditnote_model->creditNotePrintDetails_ID($creditNoteID); //detail
			$data['transInfo'] = $this->creditnote_model->creditnote_id($creditNoteID);			//master
			$supplierInfo = $this->Supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
			 //var_dump($data['datatbls'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle");
             $headerData['leftContent'] = array(
												$data['transInfo'][0]->supplierName,
												$data['transInfo'][0]->supplierCompanyNo,
												$data['transInfo'][0]->line1,
												$data['transInfo'][0]->line2,
												$data['transInfo'][0]->line3,
												$data['transInfo'][0]->supplierPostCode.' '.$data['transInfo'][0]->city
											);
			 $headerData['rightContent'] = array(
												$this->lang->line("formNo").":".$data['transInfo'][0]->creditNoteNo,
												$this->lang->line("date").":".date('d-m-Y', strtotime($data['transInfo'][0]->creditNoteDate))
											);
             
          //   $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("itemDescription"), $this->lang->line("quantity"), $this->lang->line("unitPrice"), $this->lang->line("amountExcTax"), $this->lang->line("taxRate"), $this->lang->line("amountIncTax"), $this->lang->line("taxAmount")); 
			$bodyData['selectFields'] = array("itemname","itemdescription","quantity","unitPrice","amountExcludedTax","taxRate","amountIncludedTax","taxAmount");
			$bodyData ['tdAmount'] = array("quantity","unitPrice","amountExcludedTax","taxRate","amountIncludedTax","taxAmount");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['excelTitle'] = "Location Transfer Detail";
				
		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);
		}	
	}
	
}

	
/* End of file gltransaction.php */
/* Location: ./application/controller/gltransaction.php */
/* Farhana : add creditnotelist and supplierpaymentlist */
