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

class arReports extends CI_Controller {
	
	public function __construct(){
		parent::__construct();
		$this->load->model('Useraccess');
		$query = $this->Useraccess->useraccess_id_module2('2', 'transaction');
		if(!$query){
			echo '<script>alert("Not authorised..");
				window.location.replace("'.base_url().'Error");
				</script>';
		}
		$this->load->library('layouts');
		$this->load->model('menu');
		$this->load->model('ar/saleInvoice_model');
	}
        
        public function customerAging(){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARCUSTAG');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
                $this->lang->load("customerAging", $this->session->userdata('language'));
		//$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
                $this->load->model('ar/arReport_model');
                $data["agingList"] = $this->arReport_model->getCustomerAgingAll();
		$this->layouts->view('arReports/customerAging', array('latest' => 'sidebar/latest'),$data);
	}
        
        public function printCustomerAgingByID(){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARCUSTAG');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
            $this->lang->load("customerAging", $this->session->userdata('language'));
            $id = $this->uri->segment(3);
            $month = $this->uri->segment(4);
            
           if ($month =='current'){
                    $year = date('Y');
                    $month = date('m')-1;
                    if($month<0)
                        $year = 12;
                     redirect("customerStatement/get_byCustomerID2/".$month.'-01-'.$year.'/'.($month + 1).'-01-'.$year.'/'.$id);
                   
            }else
                 redirect("customerStatement/get_byCustomerID2/".$month.'-01-'.$year.'/'.($month + 1).'-01-'.$year.'/'.$id);
        }
	//Sales Invoice List - Farhana
	public function salesInvoiceList(){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARINVLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$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('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARINVLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
    	$company = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->salesInvoice_model->salesInvoiceDetails_ID($ID); //detail
		$netTotal1 = '';
		$taxPayable1 = ''; 
		$totalTbl1 = '';
		
		if(!empty($data['datatbls'])){
			foreach($data['datatbls'] as $row){
				$netTotal1 += $row->amountExcludedTax;
				$taxPayable1 += $row->taxAmount;
				$totalTbl1 += $row->amountIncludedTax;
			}
		}
		$data['datatbls2'] = $this->salesInvoice_model->salesInvoiceCharges_ID($ID); //charges
		$netTotal2 = '';
		$taxPayable2 = ''; 
		$totalTbl2 = '';
		
		if(!empty($data['datatbls2'])){
			foreach($data['datatbls2'] as $row){
				$netTotal2 += $row->amountExcludedTax;
				$taxPayable2 += $row->taxAmount;
				$totalTbl2 += $row->amountIncludedTax;
			}
		}
		$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'] = $company[0]->gstRegisteredNo == ''?$this->lang->line("rptTitle"):$this->lang->line("rptTaxTitle");
             
			 $headerData['leftContentHeader'] = $data['transInfo'][0]->customerName .' ('. $data['transInfo'][0]->customerCompanyNo .')';
             $headerData['leftContent'] = array(
												!empty($data['transInfo'][0]->gstRegNo)?'GST Registration No : '.$data['transInfo'][0]->gstRegNo:'',
												$data['transInfo'][0]->line1,
												$data['transInfo'][0]->line2,
												$data['transInfo'][0]->line3,
												$data['transInfo'][0]->customerPostCode.' '.$data['transInfo'][0]->city,
												$data['transInfo'][0]->tstate.' '.$data['transInfo'][0]->ucountry
											);
             $headerData['rightContentHeader'] = $company[0]->gstRegisteredNo == ''?$this->lang->line("rptTitle6"):$this->lang->line("rptTitle4").":".$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,
                             "<strong>".$this->lang->line("shipto").":"."</strong>",
                             "<span style='line-height:1.4;'>".$data['transInfo'][0]->sline1."<br>".
												$data['transInfo'][0]->sline2."<br>".
												$data['transInfo'][0]->sline3."<br>".
												$data['transInfo'][0]->scustomerPostCode.' '.$data['transInfo'][0]->scity."</span>"
											);
                       //  $shipto = $this->salesInvoice_model->saleInvoiceShipTo($ID);
			//print_r($data['transInfo'][0]);
			 $footerData['ftrLeftContentHeader'] = $this->lang->line("terms").":".$data['transInfo'][0]->termName;
             $footerData['ftrLeftContent'] = array(
			 									$this->lang->line("termsdesc").":".$data['transInfo'][0]->termDescription,
												$this->lang->line("memo").":".$data['transInfo'][0]->memo,
                 
												);
              if ($data['transInfo']){
                  if($data['transInfo'][0]->showSaleAgent){
                      $footerData['ftrLeftContent'][] = $this->lang->line("agent")." : ".$data['transInfo'][0]->agentName;
                  }
                  
              }
          //   $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("um"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData['selectFields'] = array("name","description","unitPrice","qty","code","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			$bodyData ['tdAmount'] = array("unitPrice","qty","amountExcludedTax", "taxAmount", "amountIncludedTax");
			$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","taxAmount","amountIncludedTax");
			$bodyData2['tableFooter'] = array ("");
			$bodyData2['excelTitle'] = "Location Transfer Detail";
			
			//Total of invoice
			$footerData['amountCount'] = array (
												$this->lang->line('totalExcTax').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($netTotal1+$netTotal2),2, '.', ','),
												$this->lang->line('totalTax').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($taxPayable1+$taxPayable2),2, '.', ','),
												$this->lang->line('totalIncTax').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($totalTbl1+$totalTbl2),2, '.', ','),
											);
				
		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',$footerData);
		}else{
			//download excell
			$this->load->helper('excel');
			excel($headerData,array($bodyData,$bodyData2),$footerData);
		}
	}
	public function salesinvList_print($dateFrom = '',$dateTo = '',$mode = false) 
	{
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARINVLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$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("title4");
             /*$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",*/"totalamount");
			$bodyData ['tdAmount'] = array("totalamount");
			$bodyData['tableFooter'] = array ("");
			$bodyData['excelTitle'] = "Sales_Invoice_List";
				
		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($headerData,array($bodyData),$footerData);
		}
	}
	
	//Sales Invoice List Excel
	public function salesinvlist_excel()
	{
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARINVLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$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->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARDBNLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$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('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARDBNLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
		$company = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->salesInvoice_model->salesdebitnoteDetails_id($ID); //detail
		$netTotal1 = '';
		$taxPayable1 = ''; 
		$totalTbl1 = '';
		
		if(!empty($data['datatbls'])){
			foreach($data['datatbls'] as $row){
				$netTotal1 += $row->amountExcludedTax;
				$taxPayable1 += $row->taxAmount;
				$totalTbl1 += $row->amountIncludedTax;
			}
		}
		$data['datatbls2'] = $this->salesInvoice_model->salesdebitnoteCharges_id($ID); //charges
		$totalTbl2 = '';
		$netTotal2 = '';
		$taxPayable2 = ''; 
		$totalTbl2 = '';
		if(!empty($data['datatbls2'])){
			foreach($data['datatbls2'] as $row){
				$netTotal2 += $row->amountExcludedTax;
				$taxPayable2 += $row->taxAmount;
				$totalTbl2 += $row->amountIncludedTax;
			}
		}
		$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 ." (".$data['transInfo'][0]->customerCompanyNo.")";
             $headerData['leftContent'] = array(
												!empty($data['transInfo'][0]->gstRegNo)?'GST Registration No : '.$data['transInfo'][0]->gstRegNo:'',
												$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("debitFormNo").":".$data['transInfo'][0]->debitNoteNo;
			 $headerData['rightContent'] = array(
												$this->lang->line("debitNoteDate").":".date('d-m-Y', strtotime($data['transInfo'][0]->debitNoteDate)),
			 									$company[0]->gstRegisteredNo == ''?$this->lang->line("salesInvoiceNo"):$this->lang->line('rptTitle4').":".$data['transInfo'][0]->salesInvoiceNo,
												$this->lang->line('salesInvoiceDate').":".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("um"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData['selectFields'] = array("itemNameCode","description","unitPrice","itmQty","code","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			$bodyData ['tdAmount'] = array("unitPrice","itmQty","amountExcludedTax", "taxAmount", "amountIncludedTax");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['tableFooter'] = array ($this->lang->line('total').": ".number_format((double)$totalTbl1,2, '.', ','));
			
			$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","taxAmount","amountIncludedTax");
			//$bodyData2['tableFooter'] = array ("footer : value");
			$bodyData2['tableFooter'] = array ($this->lang->line('total').": ".number_format((double)$totalTbl1,2, '.', ','));
			$bodyData2['excelTitle'] = $this->lang->line("rptTitle3");
			
			$footerData['amountCount'] = array (
												$this->lang->line('totalExcTax').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($netTotal1+$netTotal2),2, '.', ','),
												$this->lang->line('totalTax').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($taxPayable1+$taxPayable2),2, '.', ','),
												$this->lang->line('totalIncTax').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($totalTbl1+$totalTbl2),2, '.', ','),
											);
			
			$footerData['ftrLeftContentHeader'] = $this->lang->line("terms").":".$data['transInfo'][0]->termName;
			$footerData['ftrLeftContent'] = array(
											$this->lang->line("termsdesc").":".$data['transInfo'][0]->termDescription,
											$this->lang->line("memo").":".$data['transInfo'][0]->memo,
											);	
			
		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',$footerData);
		}else{
			//download excell
			$this->load->helper('excel');
			excel($headerData,array($bodyData),array($bodyData2),$footerData);
		}
		
	}
	public function salesdebitnoteList_print($dateFrom = '',$dateTo = '',$mode = false) 
	{
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARDBNLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$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("title1");
             /*$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("totalAmount")/*, $this->lang->line("totaltaxAmount")*/); 
			$bodyData['selectFields'] = array("formNo","invoiceNo","customerName","debitDate",/*"confirm",*/"totalAmount"/*,"totalTaxAmount"*/);
			$bodyData ['tdAmount'] = array("totalAmount"/*,"totalTaxAmount"*/);
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['tableFooter'] = array ("");
			$bodyData['excelTitle'] = "Sales_Debit_Note_List";
			
				
		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($headerData,array($bodyData),$footerData);
		}
	}
	
	//Sales DebitNote List Excel
	public function salesdebitnoteList_excel()
	{
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARDBNLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$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->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARCDNLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$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);
	}
	
	public function salescreditnoteList_print($dateFrom = '',$dateTo = '',$mode = false) 
	{
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARCDNLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$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($dateFrom));
		$dateTo = date("Y-m-d",strtotime($dateTo));
		if ($dateFrom == ""){
			$dateFrom = date("Y-m-01");
		}
		if($dateTo == ""){
			$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')));
			//print_r($data['datatbls']);
			$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("totalAmount"), /*$this->lang->line("totaltaxAmount")*/); 
			$bodyData['selectFields'] = array("formNo","invoiceNo","customerName","creditDate",/*"confirm",*/"totalAmount"/*,"totalTaxAmount"*/);
			$bodyData ['tdAmount'] = array("totalAmount"/*,"totalTaxAmount"*/);
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['tableFooter'] = array ("");
			$bodyData['excelTitle'] = "Sales_Credit_Note_List";
			
		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($headerData,array($bodyData),$footerData);
		}
	}
	
	//Sales Credit Note List Excel
	public function salescreditnoteList_excel()
	{
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARCDNLST');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$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);
		
	}
	public function salescreditnoteDetail($ID,$mode = false){
		$this->load->model('salesInvoice_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
		$company = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
		$this->lang->load("saleInvoice",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->salesInvoice_model->salescreditnoteDetails_id($ID); //detail
		$netTotal1 = '';
		$taxPayable1 = ''; 
		$totalTbl1 = '';
		
		if(!empty($data['datatbls'])){
			foreach($data['datatbls'] as $row){
				$netTotal1 += $row->amountExcludedTax;
				$taxPayable1 += $row->taxAmount;
				$totalTbl1 += $row->amountIncludedTax;
			}
		}
		$data['datatbls2'] = $this->salesInvoice_model->salescreditnoteCharges_id($ID); //charges
		$totalTbl2 = '';
		$netTotal2 = '';
		$taxPayable2 = ''; 
		$totalTbl2 = '';
		if(!empty($data['datatbls2'])){
			foreach($data['datatbls2'] as $row){
				$netTotal2 += $row->amountExcludedTax;
				$taxPayable2 += $row->taxAmount;
				$totalTbl2 += $row->amountIncludedTax;
			}
		}
		$data['transInfo'] = $this->salesInvoice_model->salescreditnote_id($ID);
		/*print_r($data);
		exit();*/
		//$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("rptTitle5");
             $headerData['leftContentHeader'] = $data['transInfo'][0]->customerName." (".$data['transInfo'][0]->customerCompanyNo.")";
             $headerData['leftContent'] = array(
												!empty($data['transInfo'][0]->gstRegNo)?'GST Registration No : '.$data['transInfo'][0]->gstRegNo:'',
												$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("formNoPrint").":".$data['transInfo'][0]->creditNoteNo;
			 $headerData['rightContent'] = array(			 									
												$this->lang->line('creditNoteDate').":".date('d-m-Y', strtotime($data['transInfo'][0]->creditNoteDate)),
			 									$company[0]->gstRegisteredNo == ''?$this->lang->line("salesInvoiceNo"):$this->lang->line('rptTitle4').":".$data['transInfo'][0]->salesInvoiceNo,
												$this->lang->line('salesInvoiceDate').":".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
											);
             $footerData['ftrLeftContentHeader'] = $this->lang->line("terms").":".$data['transInfo'][0]->termName;
			 $footerData['ftrLeftContent'] = array(
			 									$this->lang->line("termsdesc").":".$data['transInfo'][0]->termDescription,
												$this->lang->line("memo").":".$data['transInfo'][0]->memo,
												);
          //   $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("um"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData['selectFields'] = array("itemNameCode","description","unitPrice","itmQty","code","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			$bodyData ['tdAmount'] = array("unitPrice","itmQty","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			$bodyData['tableFooter'] = array ($this->lang->line('total').": ".number_format((double)$totalTbl1,2, '.', ','));
			$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 ($this->lang->line('total').": ".number_format((double)$totalTbl2,2, '.', ','));
			$bodyData2['excelTitle'] = "Location Transfer Detail";
			
			$footerData['amountCount'] = array (
												$this->lang->line('totalExcTax').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($netTotal1+$netTotal2),2, '.', ','),
												$this->lang->line('totalTax').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($taxPayable1+$taxPayable2),2, '.', ','),
												$this->lang->line('totalIncTax').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($totalTbl1+$totalTbl2),2, '.', ','),
											);
				
		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',$footerData);
		}else{
			//download excell
			$this->load->helper('excel');
			excel($bodyData);
		}
		
	}
	//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);
	}
	public function compRecPaymentList() {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARRCVPLS');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		//$ID = isset($_REQUEST['ID'])?$_REQUEST['ID']:"";
		$mode = $this->uri->segment(3);
		$this->load->library('layouts');
		$this->lang->load("compRecPaymentList1",$this->session->userdata('language'));
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
		
		
//		$dateFrom = $this->input->post('selDateFrom');
//		$dateTo = $this->input->post('selDateTo');

		$data['mode'] = 'rpt'; 
		
		$dateFrom = date("Y-m-d",strtotime($this->uri->segment(4)));
		$dateTo = date("Y-m-d",strtotime($this->uri->segment(5)));
		
		if ($this->uri->segment(4) == ""){
			$dateFrom = date("Y-m-01");
		}
		if($this->uri->segment(5) == ""){
			$dateTo = date("Y-m-t");
		}
		if($dateFrom > $dateTo){
			$dateTo = date("Y-m-t", strtotime($dateFrom));
		}
		
		//$ID = $this->input->post('ID');
		//$query = $this->company_info_model->updatePosting($ID);
		
		
		$data['dateFrom'] = $dateFrom;
		$data['dateTo'] = $dateTo;
		$data['datatbls'] = $this->company_info_model->compRecPaymentDate($dateFrom, $dateTo);
		
//		echo $this->db->last_query();
		$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
		$this->layouts->view('company/compRecPaymentList', array('latest' => 'sidebar/latest'), $data);
	}
	
	public function compRecPaymentListPrint($dateFrom = '',$dateTo = '',$mode = false) {
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARRCVPLS');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		//$ID = isset($_REQUEST['ID'])?$_REQUEST['ID']:"";
		$this->load->library('layouts');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
	
		$this->lang->load("compRecPaymentList1",$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(4) == ""){
			$dateFrom = date("Y-m-01");
		}
		if($this->uri->segment(5) == ""){
			$dateTo = date("Y-m-t");
		}
		if($dateFrom > $dateTo){
			$dateTo = date("Y-m-t", strtotime($dateFrom));
		}
		
		$data['datatbls'] = $this->company_info_model->compRecPaymentDate($dateFrom, $dateTo); //detail
		//$data['transInfo'] = $this->company_info_model->compRecPayment_id($receivePaymentID);
		//$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(
												"<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(
												$this->lang->line("dateFrom")." ".date('d-m-Y', strtotime($dateFrom))." ".$this->lang->line("dateTo")." ".date('d-m-Y', strtotime($dateTo))
											);
             
          //   $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("referenceNo"), $this->lang->line("receivePaymentDate"), $this->lang->line("totalReceived")/*,$this->lang->line("exchangeRate"),$this->lang->line("discount"),$this->lang->line("totalReceived")*/); 
			$bodyData['selectFields'] = array("formNo", "customerName","referenceNo","recpaydate", "totalReceived"/*,"exchangeRate","totalDiscount","totalReceived"*/);
			$bodyData ['tdAmount'] = array("totalReceived"/*"exchangeRate","totalDiscount","totalReceived"*/);
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['excelTitle'] = "Company_Receive_Payment_List";
				
			if(!$mode){
				$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($headerData, array($bodyData));
			}
		/*if($mode = false){
			//download excell
			$this->load->helper('excel');
			excel($bodyData);
		}*/	
	}
	
	public function compRecPaymentDetail($receivePaymentID,$mode = false) {
		//$ID = isset($_REQUEST['ID'])?$_REQUEST['ID']:"";
		$this->load->library('layouts');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
	
		$this->lang->load("compRecPaymentList1",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->company_info_model->compRecPaymentDetail_id($receivePaymentID); //detail
		$data['transInfo'] = $this->company_info_model->compRecPayment_id($receivePaymentID);
		//$supplierInfo = $this->Supplier_model->suppliermaster_id($data['transInfo'][0]->supplierID);
		
         //   var_dump($data['transInfo'][0]);           
             //$headerData['rightContentHeader'] = "Name supplier/ ot";
             $headerData['rptTitle'] = $this->lang->line("rptTitle");
             if ($data['transInfo'][0]){
             $headerData['leftContent'] = array(
												"<b>".$data['transInfo'][0]->customerName." (".$data['transInfo'][0]->customerCompanyNo.")</b>",
												!empty($data['transInfo'][0]->gstRegNo)?'GST Registration No : '.$data['transInfo'][0]->gstRegNo:'',
												$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]->receivePaymentNo."</b>",
												$this->lang->line("date").":".date('d-m-Y', strtotime($data['transInfo'][0]->receivePaymentDate)),
												$this->lang->line("currency").":".$data['transInfo'][0]->fldcurr_code,
												$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("invoiceNo"), $this->lang->line("invoiceDate"), $this->lang->line("totalAmount"), $this->lang->line("ARBalance"), $this->lang->line("discount"), $this->lang->line("amountApplied")); 
			//$bodyData['selectFields'] = array("invoiceNo", "invoiceDate", "totalAmount", "ARBalance","discount","amountApplied",);
			$bodyData['tableHeader'] = array($this->lang->line("invoiceNo"), $this->lang->line("invoiceDate"), $this->lang->line("amountApplied")); 
			$bodyData['selectFields'] = array("invoiceNo", "invoiceDate", "amntApplied");
			$bodyData ['tdAmount'] = array("amntApplied");
			//$bodyData['tdNoFormat'] = array("invoiceNo", "invoiceDate");
			//$bodyData['tableFooter'] = array ("footer : value");
			$bodyData['excelTitle'] = "Location Transfer Detail";
                        
                        
                          $netTotal = 0;
            $discount = 0;
            $totalTbl = 0;
             if(!empty($bodyData['rptDataDetail'])){
			foreach($bodyData['rptDataDetail'] as $row){
				$netTotal += $row->amountApplied;
				$discount += $row->discount;
			}
		}
             
               
            
                
            $footerData['amountCount'] = array (//$this->lang->line('discountTotal').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($discount),2),
            									$this->lang->line('bankCharges').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format($data['transInfo'][0]->bankCharges,2),
												$this->lang->line('totalApplied').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format($data['transInfo'][0]->totalReceived,2)
												
											);    
                        
				
				
		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 cashsalelist(){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARCSHS');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
			$add_year = $this->uri->segment(3);
			$add_period = $this->uri->segment(4);
			if(!$add_year){
				$add_year = date("Y");
			}
			if(!$add_period){
				$add_period = date("m");
			}
			$this->lang->load("cashsale",$this->session->userdata('language'));
			$this->load->model('ar/cashsale_model');
			$this->load->model('company/FormSetup_model');
			$this->load->model('Compfinancialyear');
			//$data['yrs'] = range(date('Y'), 1900);
			//change to get financial year based on select disctint financial year
			$data['yrs'] = $this->Compfinancialyear->get_financialYear();
			$data['selyear'] = $add_year;
			$data['selper'] = $add_period;
			$query = $this->Compfinancialyear->financialYear_year($add_year);
			if($query){
				$data['period'] = $query;
			}else{
				$data['period'] = NULL;
			}
			$queryCal = $this->Compfinancialyear->financialYear_yearperiod($add_year, $add_period);
			
			if($queryCal){
				$data['datatbls'] = $this->cashsale_model->cashsalelist($queryCal[0]->startDate, $queryCal[0]->endDate);
				//echo $this->db->last_query();
				//return;
			}else{
				$data['datatbls'] = NULL;
			}
			$this->load->library('layouts');
			$this->layouts->add_includes('js/datatables/jquery.dataTables.min.js');
			$this->layouts->view('ar/reports/cashsalelist', array('latest' => 'sidebar/latest'), $data);
		}
		
		public function cashsalelistDetail($projectID,$mode = false){
        $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARCSHS');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
		$this->load->model('ar/cashsale_model');
		$this->load->model('company/FormSetup_model');
		$this->load->model('company/company_info_model');
    	$company = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
		$this->lang->load("cashsale",$this->session->userdata('language'));
		
		$data['datatbls'] = $this->cashsale_model->cashsaleDetail_ID($projectID); //detail
		$netTotal1 = '';
		$taxPayable1 = ''; 
		$totalTbl1 = '';
		
		if(!empty($data['datatbls'])){
			foreach($data['datatbls'] as $row){
				$netTotal1 += $row->amountExcludedTax;
				$taxPayable1 += $row->taxAmount;
				$totalTbl1 += $row->amountIncludedTax;
			}
		}
		$data['datatbls2'] = $this->cashsale_model->cashsaleCharges_ID($projectID); //charges
		$netTotal2 = '';
		$taxPayable2 = ''; 
		$totalTbl2 = '';
		
		if(!empty($data['datatbls2'])){
			foreach($data['datatbls2'] as $row){
				$netTotal2 += $row->amountExcludedTax;
				$taxPayable2 += $row->taxAmount;
				$totalTbl2 += $row->amountIncludedTax;
			}
		}
		$data['transInfo'] = $this->cashsale_model->cashsale_ID($projectID);
		//$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'] = $company[0]->gstRegisteredNo == '0'?$this->lang->line("rptTitle"):$this->lang->line("title");
             
			 $headerData['leftContentHeader'] = $data['transInfo'][0]->paymentFrom;
             /*$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]->cashSaleNo;
			 $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,						
											);
			/*//print_r($data['transInfo'][0]);
			 $footerData['ftrLeftContentHeader'] = $this->lang->line("terms").":".$data['transInfo'][0]->termName;
             $footerData['ftrLeftContent'] = array(
			 									$this->lang->line("termsdesc").":".$data['transInfo'][0]->termDescription,
												$this->lang->line("memo").":".$data['transInfo'][0]->memo,
												);*/
          //   $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("um"), $this->lang->line("amountExcludeTax"), $this->lang->line("tax"), $this->lang->line("taxAmount"), $this->lang->line("amountIncludeTax")); 
			$bodyData['selectFields'] = array("name","description","unitPrice","qty","code","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			$bodyData ['tdAmount'] = array("unitPrice","qty","amountExcludedTax", "taxRate", "taxAmount", "amountIncludedTax");
			$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 ("");
			$bodyData2['excelTitle'] = "Location Transfer Detail";*/
			
			//Total of invoice
			$footerData['amountCount'] = array (
												$this->lang->line('netTotal').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($netTotal1+$netTotal2),2, '.', ','),
												$this->lang->line('taxPayable').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($taxPayable1+$taxPayable2),2, '.', ','),
												$this->lang->line('grossTotal').": ".$data['transInfo'][0]->fldcurr_code.' '.number_format((double)($totalTbl1+$totalTbl2),2, '.', ','),
											);
				
		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',$footerData);
		}else{
			//download excell
			$this->load->helper('excel');
			excel($headerData,array($bodyData),$footerData);
		}
	}
        
        public function printcashsalelist($year = '',$period = '', $mode = false){
            {
       $this->load->model('UseraccessDetails');
        $query = $this->UseraccessDetails->UseraccessDetails_id_code('ARCSHS');
        if (!$query) {
            echo '<script>alert("Not authorised..");
				window.location.replace("' . base_url() . 'Error");
				</script>';
        }
			$add_year = $year;
			$add_period = $period;
			if(!$add_year){
				$add_year = date("Y");
			}
			if(!$add_period){
				$add_period = date("m");
			}
			$this->lang->load("cashsale",$this->session->userdata('language'));
			$this->load->model('ar/cashsale_model');
			$this->load->model('company/FormSetup_model');
			$this->load->model('Compfinancialyear');
			$data['yrs'] = range(date('Y'), 1900);
			$data['selyear'] = $add_year;
			$data['selper'] = $add_period;
			$query = $this->Compfinancialyear->financialYear_year($add_year);
			if($query){
				$data['period'] = $query;
			}else{
				$data['period'] = NULL;
			}
			$queryCal = $this->Compfinancialyear->financialYear_yearperiod($add_year, $add_period);
			
			if($queryCal){
				$data['datatbls'] = $this->cashsale_model->cashsalelist($queryCal[0]->startDate, $queryCal[0]->endDate);
				//echo $this->db->last_query();
				//return;
			}else{
				$data['datatbls'] = NULL;
			}
                        
                        
		
             $headerData['rptTitle'] = $this->lang->line("rptTitle4");
			 $headerData['rightContent'] = array(
                             $this->lang->line("from")." ".date('d-m-Y', strtotime($queryCal[0]->startDate))." ".$this->lang->line("to")." ".date('d-m-Y', strtotime($queryCal[0]->endDate))
                         );
             
            //   $headerData['company'] = $this->company_info_model->companyById(element('compID', $this->session->userdata('logged_in')));
			//print_r($data['datatbls']);
			$bodyData['rptDataDetail'] = $data['datatbls'];
			$bodyData['tableHeader'] = array($this->lang->line("date"), $this->lang->line("formno"), $this->lang->line("customer"), $this->lang->line("amount"), $this->lang->line("importDutyPayable")); 
			$bodyData['selectFields'] = array("effDate","formNo","customer","amount","taxAmount");
			$bodyData ['tdAmount'] = array("amount","taxAmount");
			$bodyData['tableFooter'] = array ("");
			$bodyData['excelTitle'] = "Sales_Credit_Note_List";
			
		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($headerData,array($bodyData),$footerData);
		}
        }
        
        }
}