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

class SalesInvoice extends CI_Controller {
	
	public function __construct(){
		parent::__construct();
		$this->load->model('Useraccess');
		$query = $this->Useraccess->useraccess_id_module2('5', '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()
	{
		
	}
	
	//Sales Invoice List - Farhana
	public function salesInvoiceList(){
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		$this->load->model('salesInvoice_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->salesInvoice_model->salesInvoice_Date($dateFrom, $dateTo);
		//echo var_dump($data['datatbls']);
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ar/reports/salesinvoiceList', array('latest' => 'sidebar/latest'), $data);
	}
	
	public function salesInvoiceDetail($ID,$mode = false){
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
		
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->salesInvoice_model->salesInvoiceDetails_ID($ID); //detail
		$data['datatbls2'] = $this->salesInvoice_model->salesInvoiceCharges_ID($ID); //charges
		$data['transInfo'] = $this->salesInvoice_model->salesInvoice_id($ID);
		//$supplierInfo = $this->Supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
		//echo $this->db->last_query();
		//var_dump($data['datatbls2'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle");
             $headerData['leftContentHeader'] = $data['transInfo'][0]->customerName;
             $headerData['leftContent'] = array(
												$data['transInfo'][0]->customerCompanyNo,
												$data['transInfo'][0]->line1,
												$data['transInfo'][0]->line2,
												$data['transInfo'][0]->line3,
												$data['transInfo'][0]->customerPostCode.' '.$data['transInfo'][0]->city
											);
             $headerData['rightContentHeader'] = $this->lang->line("formNo").":".$data['transInfo'][0]->salesInvoiceNo;
			 $headerData['rightContent'] = array(
												$this->lang->line("date").":".date('d-m-Y', strtotime($data['transInfo'][0]->salesInvoiceDate)),
												$this->lang->line("currency").":".$data['transInfo'][0]->fldcurr_code,
												$this->lang->line("terms").":".$data['transInfo'][0]->termName
											);
             
          //   $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("itemDesc"), $this->lang->line("unitPrice"), $this->lang->line("quantity"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData['selectFields'] = array("name","description","unitPrice","quantity","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			$bodyData ['tdAmount'] = array("unitPrice","quantity","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['excelTitle'] = "Location Transfer Detail";
			
			$bodyData2['rptDataDetail'] = $data['datatbls2'];
			$bodyData2['tableHeader'] = array($this->lang->line("account"), $this->lang->line("description"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData2['selectFields'] = array("acctNameCode","chargeDescription","amountExcludedTax","taxRate","taxAmount","amountIncludedTax");
			//var_dump($bodyData2['selectFields']);
			$bodyData2 ['tdAmount'] = array("amountExcludedTax","taxRate","taxAmount","amountIncludedTax");
			$bodyData2['tableFooter'] = array ("footer : value");
			$bodyData2['excelTitle'] = "Location Transfer Detail";
				
		if(!$mode){
			//print
			$this->load->view('layouts/report/header', $headerData);
			$this->load->view('layouts/report/body', $bodyData);
			//var_dump($bodyData2['selectFields']);

			$this->load->view('layouts/report/body', $bodyData2);
			$this->load->view('layouts/report/footer','');
		}else{
			//download excell
			$this->load->helper('excel');
			excel($bodyData);
		}
	}
	
	/*public function salesinvList_print() 
	{
		$mode=$this->uri->segment(3);
		$this->load->library('layouts');
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		
		$data['mode'] = $mode;
		$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));
		}
		
		$ID = $this->input->post('ID');
		$query = $this->salesInvoice_model->updatePosting($ID);
		
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		$data['datatbls'] = $this->salesInvoice_model->salesInvoice_Date($dateFrom, $dateTo);
		
		//		echo $this->db->last_query();
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->load->view('ar/reports/salesinvlist_print', $data);
	}*/
	
	public function salesinvList_print($mode = false) 
	{
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
		
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		
		$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));
		}
		
		$ID = $this->input->post('ID');
		$query = $this->salesInvoice_model->updatePosting($ID);
		
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		$data['datatbls'] = $this->salesInvoice_model->salesInvoice_Date($dateFrom, $dateTo);
		//$supplierInfo = $this->Supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
		//echo $this->db->last_query();
		//var_dump($data['datatbls2'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle2");
             /*$headerData['leftContent'] = array(
												"<b>".$data['transInfo'][0]->customerName."</b>",
												$data['transInfo'][0]->customerCompanyNo,
												$data['transInfo'][0]->line1,
												$data['transInfo'][0]->line2,
												$data['transInfo'][0]->line3,
												$data['transInfo'][0]->customerPostCode.' '.$data['transInfo'][0]->city
											);*/
			 $headerData['rightContent'] = array(
												//"<b>".$this->lang->line("formNo").":".$data['transInfo'][0]->salesInvoiceNo."</b>",
												$this->lang->line("from")." ".date('d-m-Y', strtotime($dateFrom))." ".$this->lang->line("to")." ".date('d-m-Y', strtotime($dateTo)),
												//$this->lang->line("currency").":".$data['transInfo'][0]->fldcurr_code,
												//$this->lang->line("terms").":".$data['transInfo'][0]->termName
											);
             
          //   $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
			$bodyData['rptDataDetail'] = $data['datatbls'];
			$bodyData['tableHeader'] = array($this->lang->line("formNo"), $this->lang->line("customerName"), $this->lang->line("salesInvoiceDate"), $this->lang->line("posting"), $this->lang->line("totalReceivable")); 
			$bodyData['selectFields'] = array("formNo","customerName","invoiceDate","confirm","totalReceivable");
			$bodyData ['tdAmount'] = array("totalReceivable");
			$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);
		}
	}
	
	//Sales Invoice List Excel
	public function salesinvlist_excel()
	{
		$this->load->library('parser');
		$mode=$this->uri->segment(3);
		$this->load->library('layouts');
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		
		$data['mode'] = $mode; 
		
		$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));
		}
		
		$ID = $this->input->post('ID');
		$query = $this->salesInvoice_model->updatePosting($ID);
		
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		$data['datatbls'] = $this->salesInvoice_model->salesInvoice_Date($dateFrom, $dateTo);
		
		$myFile = "Sales_Invoice_List.xls";
 
        //pass retrieved data into template and return as a string
        $stringData = $this->parser->parse('ar/report/salesinvlist_excel', $data, true);
 
        //open excel and write string into excel
        $fh = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, $stringData);
 
        fclose($fh);
        //download excel file
        $this->downloadExcel($myFile);
		
	}
	//Sales Debit Note List - Farhana
	public function salesdebitnoteList(){
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		$this->load->model('salesInvoice_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->salesInvoice_model->salesdebitnote_Date($dateFrom, $dateTo);
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ar/reports/salesdebitnoteList', array('latest' => 'sidebar/latest'), $data);
	}
	
	public function salesdebitnoteDetail($ID,$mode = false){
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
		
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->salesInvoice_model->salesdebitnoteDetails_id($ID); //detail
		$data['datatbls2'] = $this->salesInvoice_model->salesdebitnoteCharges_id($ID); //charges
		$data['transInfo'] = $this->salesInvoice_model->salesdebitnote_id($ID);
		//$supplierInfo = $this->Supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
		//echo $this->db->last_query();
		//var_dump($data['datatbls2'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle3");
             $headerData['leftContentHeader'] = $data['transInfo'][0]->customerName;
             $headerData['leftContent'] = array(
												$data['transInfo'][0]->customerCompanyNo,
												$data['transInfo'][0]->line1,
												$data['transInfo'][0]->line2,
												$data['transInfo'][0]->line3,
												$data['transInfo'][0]->customerPostCode.' '.$data['transInfo'][0]->city
											);
             $headerData['rightContentHeader'] = $this->lang->line("formNo").":".$data['transInfo'][0]->debitNoteNo;
			 $headerData['rightContent'] = array(
												$this->lang->line("date").":".date('d-m-Y', strtotime($data['transInfo'][0]->debitNoteDate)),
												$this->lang->line("currency").":".$data['transInfo'][0]->fldcurr_code,
												$this->lang->line("terms").":".$data['transInfo'][0]->termName
											);
             
          //   $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("itemDesc"), $this->lang->line("unitPrice"), $this->lang->line("quantity"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData['selectFields'] = array("itemNameCode","description","unitPrice","quantity","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			$bodyData ['tdAmount'] = array("unitPrice","quantity","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['tableFooter'] = array ("");
			$bodyData['excelTitle'] = "Location Transfer Detail";
			
			$bodyData2['rptDataDetail'] = $data['datatbls2'];
			$bodyData2['tableHeader'] = array($this->lang->line("account"), $this->lang->line("description"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData2['selectFields'] = array("acctNameCode","chargeDescription","amountExcludedTax","taxRate","taxAmount","amountIncludedTax");
			//var_dump($bodyData2['selectFields']);
			$bodyData2 ['tdAmount'] = array("amountExcludedTax","taxRate","taxAmount","amountIncludedTax");
			//$bodyData2['tableFooter'] = array ("footer : value");
			$bodyData2['tableFooter'] = array ("");
			$bodyData2['excelTitle'] = "Location Transfer Detail";
				
		if(!$mode){
			//print
			$this->load->view('layouts/report/header', $headerData);
			$this->load->view('layouts/report/body', $bodyData);
			//var_dump($bodyData2['selectFields']);

			$this->load->view('layouts/report/body', $bodyData2);
			$this->load->view('layouts/report/footer','');
		}else{
			//download excell
			$this->load->helper('excel');
			excel($bodyData);
		}
		
	}
	
	public function salescreditnoteDetail($ID,$mode = false){
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
		
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->salesInvoice_model->salescreditnoteDetails_id($ID); //detail
		$data['datatbls2'] = $this->salesInvoice_model->salescreditnoteCharges_id($ID); //charges
		$data['transInfo'] = $this->salesInvoice_model->salescreditnote_id($ID);
		//$supplierInfo = $this->Supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
		//echo $this->db->last_query();
		//var_dump($data['datatbls2'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle4");
             $headerData['leftContentHeader'] = $data['transInfo'][0]->customerName;
             $headerData['leftContent'] = array(
												$data['transInfo'][0]->customerCompanyNo,
												$data['transInfo'][0]->line1,
												$data['transInfo'][0]->line2,
												$data['transInfo'][0]->line3,
												$data['transInfo'][0]->customerPostCode.' '.$data['transInfo'][0]->city
											);
             $headerData['rightContentHeader'] = $this->lang->line("formNo").":".$data['transInfo'][0]->creditNoteNo;
			 $headerData['rightContent'] = array(
												$this->lang->line("date").":".date('d-m-Y', strtotime($data['transInfo'][0]->creditNoteDate)),
												$this->lang->line("currency").":".$data['transInfo'][0]->fldcurr_code,
												$this->lang->line("terms").":".$data['transInfo'][0]->termName
											);
             
          //   $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("itemDesc"), $this->lang->line("unitPrice"), $this->lang->line("quantity"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData['selectFields'] = array("itemNameCode","description","unitPrice","quantity","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			$bodyData ['tdAmount'] = array("unitPrice","quantity","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['tableFooter'] = array ("");
			$bodyData['excelTitle'] = "Location Transfer Detail";
			
			$bodyData2['rptDataDetail'] = $data['datatbls2'];
			$bodyData2['tableHeader'] = array($this->lang->line("account"), $this->lang->line("description"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData2['selectFields'] = array("acctNameCode","chargeDescription","amountExcludedTax","taxRate","taxAmount","amountIncludedTax");
			//var_dump($bodyData2['selectFields']);
			$bodyData2 ['tdAmount'] = array("amountExcludedTax","taxRate","taxAmount","amountIncludedTax");
			//$bodyData2['tableFooter'] = array ("footer : value");
			$bodyData2['tableFooter'] = array ("");
			$bodyData2['excelTitle'] = "Location Transfer Detail";
				
		if(!$mode){
			//print
			$this->load->view('layouts/report/header', $headerData);
			$this->load->view('layouts/report/body', $bodyData);
			//var_dump($bodyData2['selectFields']);

			$this->load->view('layouts/report/body', $bodyData2);
			$this->load->view('layouts/report/footer','');
		}else{
			//download excell
			$this->load->helper('excel');
			excel($bodyData);
		}
		
	}
	
	//Sales Debit Note List Print
	/*public function salesdebitnoteList_print() 
	{
		$mode=$this->uri->segment(3);
		$this->load->library('layouts');
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		
		$data['mode'] = $mode;
		$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));
		}
		
		$ID = $this->input->post('ID');
		$query = $this->salesInvoice_model->updatePosting($ID);
		
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		$data['datatbls'] = $this->salesInvoice_model->salesdebitnote_Date($dateFrom, $dateTo);
		
		//		echo $this->db->last_query();
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->load->view('ar/reports/salesdbtnote_print', $data);
	}*/
	
	public function salesdebitnoteList_print($mode = false) 
	{
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
		
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		
		$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->salesInvoice_model->salesdebitnote_Date($dateFrom, $dateTo);
		//$supplierInfo = $this->Supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
		//echo $this->db->last_query();
		//var_dump($data['datatbls2'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle3");
             /*$headerData['leftContent'] = array(
												"<b>".$data['transInfo'][0]->customerName."</b>",
												$data['transInfo'][0]->customerCompanyNo,
												$data['transInfo'][0]->line1,
												$data['transInfo'][0]->line2,
												$data['transInfo'][0]->line3,
												$data['transInfo'][0]->customerPostCode.' '.$data['transInfo'][0]->city
											);*/
			 $headerData['rightContent'] = array(
												//"<b>".$this->lang->line("formNo").":".$data['transInfo'][0]->creditNoteNo."</b>",
												$this->lang->line("from")." ".date('d-m-Y', strtotime($dateFrom))." ".$this->lang->line("to")." ".date('d-m-Y', strtotime($dateTo)),
												//$this->lang->line("currency").":".$data['transInfo'][0]->fldcurr_code,
												//$this->lang->line("terms").":".$data['transInfo'][0]->termName
											);
             
          //   $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
			$bodyData['rptDataDetail'] = $data['datatbls'];
			$bodyData['tableHeader'] = array($this->lang->line("formNo"), $this->lang->line("invoiceNo"), $this->lang->line("customerName"), $this->lang->line("date"), $this->lang->line("posting"), $this->lang->line("totalPayable"), $this->lang->line("totaltaxAmount")); 
			$bodyData['selectFields'] = array("debitNoteNo","invoiceNo","customerName","debitDate","confirm","totalPayable","totalTaxAmount");
			$bodyData ['tdAmount'] = array("totalPayable","totalTaxAmount");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['tableFooter'] = array ("");
			$bodyData['excelTitle'] = "Location Transfer Detail";
			
				
		if($mode){
			//print
			$this->load->view('layouts/report/header', $headerData);
			$this->load->view('layouts/report/body', $bodyData);
			//var_dump($bodyData2['selectFields']);
			$this->load->view('layouts/report/footer','');
		}else{
			//download excell
			$this->load->helper('excel');
			excel($bodyData);
		}
	}
	
	//Sales DebitNote List Excel
	public function salesdebitnoteList_excel()
	{
		$this->load->library('parser');
		$mode=$this->uri->segment(3);
		$this->load->library('layouts');
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		
		$data['mode'] = $mode; 
		
		$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));
		}
		
		$ID = $this->input->post('ID');
		$query = $this->salesInvoice_model->updatePosting($ID);
		
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		$data['datatbls'] = $this->salesInvoice_model->salesdebitnote_Date($dateFrom, $dateTo);
		
		$myFile = "Sales_DebitNote_List.xls";
 
        //pass retrieved data into template and return as a string
        $stringData = $this->parser->parse('ar/report/salesdbtnotelist_excel', $data, true);
 
        //open excel and write string into excel
        $fh = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, $stringData);
 
        fclose($fh);
        //download excel file
        $this->downloadExcel($myFile);
		
	}

//Sales Credit Note List-Farhana
	public function salescreditnoteList(){
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		$this->load->model('salesInvoice_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->salesInvoice_model->salescreditnote_Date($dateFrom, $dateTo);
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ar/reports/salescreditnoteList', array('latest' => 'sidebar/latest'), $data);
	}
	
	//SalesCreditNoteListPrint
	/*public function salescreditnoteList_print() 
	{
		$mode=$this->uri->segment(3);
		$this->load->library('layouts');
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		
		$data['mode'] = $mode;
		$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));
		}
		
		$ID = $this->input->post('ID');
		$query = $this->salesInvoice_model->updatePosting($ID);
		
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		$data['datatbls'] = $this->salesInvoice_model->salescreditnote_Date($dateFrom, $dateTo);
		
		//		echo $this->db->last_query();
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->load->view('ar/reports/salescdtnote_print', $data);
	}*/
	
	public function salescreditnoteList_print($mode = false) 
	{
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
		
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		
		$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->salesInvoice_model->salescreditnote_Date($dateFrom, $dateTo);
		//$supplierInfo = $this->Supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
		//echo $this->db->last_query();
		//var_dump($data['datatbls2'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle4");
             /*$headerData['leftContent'] = array(
												"<b>".$data['transInfo'][0]->customerName."</b>",
												$data['transInfo'][0]->customerCompanyNo,
												$data['transInfo'][0]->line1,
												$data['transInfo'][0]->line2,
												$data['transInfo'][0]->line3,
												$data['transInfo'][0]->customerPostCode.' '.$data['transInfo'][0]->city
											);*/
			 $headerData['rightContent'] = array(
												//"<b>".$this->lang->line("formNo").":".$data['transInfo'][0]->creditNoteNo."</b>",
												$this->lang->line("from")." ".date('d-m-Y', strtotime($dateFrom))." ".$this->lang->line("to")." ".date('d-m-Y', strtotime($dateTo)),
												//$this->lang->line("currency").":".$data['transInfo'][0]->fldcurr_code,
												//$this->lang->line("terms").":".$data['transInfo'][0]->termName
											);
             
          //   $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
			$bodyData['rptDataDetail'] = $data['datatbls'];
			$bodyData['tableHeader'] = array($this->lang->line("formNo"), $this->lang->line("invoiceNo"), $this->lang->line("customerName"), $this->lang->line("date"), $this->lang->line("posting"), $this->lang->line("totalPayable"), $this->lang->line("totaltaxAmount")); 
			$bodyData['selectFields'] = array("creditNoteNo","invoiceNo","customerName","creditDate","confirm","totalPayable","totalTaxAmount");
			$bodyData ['tdAmount'] = array("totalPayable","totalTaxAmount");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['tableFooter'] = array ("");
			$bodyData['excelTitle'] = "Location Transfer Detail";
			
				
		if($mode){
			//print
			$this->load->view('layouts/report/header', $headerData);
			$this->load->view('layouts/report/body', $bodyData);
			//var_dump($bodyData2['selectFields']);
			$this->load->view('layouts/report/footer','');
		}else{
			//download excell
			$this->load->helper('excel');
			excel($bodyData);
		}
	}
	
	//Sales Credit Note List Excel
	public function salescreditnoteList_excel()
	{
		$this->load->library('parser');
		$mode=$this->uri->segment(3);
		$this->load->library('layouts');
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		
		$data['mode'] = $mode; 
		
		$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));
		}
		
		$ID = $this->input->post('ID');
		$query = $this->salesInvoice_model->updatePosting($ID);
		
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		$data['datatbls'] = $this->salesInvoice_model->salescreditnote_Date($dateFrom, $dateTo);
		
		$myFile = "Sales_CreditNote_List.xls";
 
        //pass retrieved data into template and return as a string
        $stringData = $this->parser->parse('ar/report/salescdtnotelist_excel', $data, true);
 
        //open excel and write string into excel
        $fh = fopen($myFile, 'w') or die("can't open file");
        fwrite($fh, $stringData);
 
        fclose($fh);
        //download excel file
        $this->downloadExcel($myFile);
		
	}
	//Receive Payment List-Farhana
	public function receivepayList(){
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		$this->load->model('salesInvoice_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->salesInvoice_model->rcvpayment_Date($dateFrom, $dateTo);
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('ar/reports/receivepayList', array('latest' => 'sidebar/latest'), $data);
	}
	 
	 
	/* 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);
    }
	
}
 //big end


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

