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

class TaxTrans extends CI_Model{
	public function taxTransPurchase_GAF($dateFrom, $dateTo){
	    //$this->db->where('is_delete', 0);
		$this->db->where('view_supplier_statement.companyID', element('compID', $this->session->userdata('logged_in')));
		$this->db->where('transDate between  "'.$dateFrom.'" and "'.$dateTo.'"');
		$this->db->select('view_supplier_statement.*');
		$this->db->from('view_supplier_statement');
		$this->db->select('supplier.supplierName as supplierName');
		$this->db->select('supplier.supplierCode as supplierCode');
		$this->db->select('supplier.supplierCompanyNo as supplierCompanyNo');
		$this->db->join('supplier', 'supplier.ID = view_supplier_statement.supplierID');
		$this->db->order_by('transDate desc');
	    //$this->db->where('companyID', element('compID', $this->session->userdata('logged_in')));
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
	public function creditnote_posted($dateFrom, $dateTo){
		$this->db->select('a.*');
		$this->db->select('a.creditNoteDate as transDate');
		$this->db->select('a.updateAble as Yes');
		$this->db->select('b.supplierName');
		$this->db->select('d.*');
		$this->db->select('e.*');
		$this->db->select('f.*');
		$this->db->select('b.supplierCompanyNo');
		$this->db->select('c.formNo as supplierInvoiceNo');
		$this->db->where('a.companyID', element('compID',	$this->session->userdata('logged_in')));
		$this->db->where('creditNoteDate >=', $dateFrom);
		$this->db->where('creditNoteDate <=', $dateTo);
		$this->db->where('a.updateAble', 0);
		$this->db->from('comp_supplier_creditnote a');
		$this->db->join('comp_supplier_creditnote_detail d', 'd.creditnoteID = a.ID');
		$this->db->join('supplier b', 'b.ID = a.supplierID');
		$this->db->join('comp_supplier_invoice c','c.ID = a.supplierInvoiceID', 'left outer');
		$this->db->join('tax_master e','e.ID = d.taxID', 'left outer');
		$this->db->join('_ref_currency f','f.fldid = a.currencyID', 'left outer');
		$query = $this->db->get();
		$join = $this->db->last_query();
		$this->db->flush_cache();
		$this->db->select('a.*');
		$this->db->select('a.debitNoteDate as transDate');
		$this->db->select('a.updateAble as Yes');
		$this->db->select('b.supplierName');
		$this->db->select('d.*');
		$this->db->select('e.*');
		$this->db->select('f.*');
		$this->db->select('b.supplierCompanyNo');
		$this->db->select('c.formNo as supplierInvoiceNo');
		$this->db->where('a.companyID', element('compID',	$this->session->userdata('logged_in')));
		$this->db->where('debitNoteDate >=', $dateFrom);
		$this->db->where('debitNoteDate <=', $dateTo);
		$this->db->where('a.updateAble', 0);
		$this->db->from('comp_supplier_debitnote a');
		$this->db->join('comp_supplier_debitnote_detail d', 'd.debitnoteID = a.ID');
		$this->db->join('supplier b', 'b.ID = a.supplierID');
		$this->db->join('comp_supplier_invoice c','c.ID = a.supplierInvoiceID', 'left outer');
		$this->db->join('tax_master e','e.ID = d.taxID', 'left outer');
		$this->db->join('_ref_currency f','f.fldid = a.currencyID', 'left outer');
		$query1 = $this->db->get();
		$join1 = $this->db->last_query();
		$union_query = $this->db->query($join.' UNION '.$join1 . ' ORDER BY transDate');
		if($union_query->num_rows() >= 1){
			return $union_query->result();
		}else{
			return false;
		}
	}
	public function debitnote_posted($dateFrom, $dateTo){
		$this->db->select('a.*');
		$this->db->select('a.debitNoteDate as transDate');
		$this->db->select('a.updateAble as Yes');
		$this->db->select('b.supplierName');
		$this->db->select('d.*');
		$this->db->select('e.*');
		$this->db->select('f.*');
		$this->db->select('b.supplierCompanyNo');
		$this->db->select('c.formNo as supplierInvoiceNo');
		$this->db->where('a.companyID', element('compID',	$this->session->userdata('logged_in')));
		$this->db->where('debitNoteDate >=', $dateFrom);
		$this->db->where('debitNoteDate <=', $dateTo);
		$this->db->where('a.updateAble', 0);
		$this->db->order_by('debitNoteDate', 'desc');
		$this->db->from('comp_supplier_debitnote a');
		$this->db->join('comp_supplier_debitnote_detail d', 'd.debitnoteID = a.ID');
		$this->db->join('supplier b', 'b.ID = a.supplierID');
		$this->db->join('comp_supplier_invoice c','c.ID = a.supplierInvoiceID', 'left outer');
		$this->db->join('tax_master e','e.ID = d.taxID', 'left outer');
		$this->db->join('_ref_currency f','f.fldid = a.currencyID', 'left outer');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return false;
		}
	}
	public function gafFiles($dateFrom, $dateTo){
		$this->db->select('a.*');
		$this->db->order_by('companyID');
		$this->db->order_by('col1');
		$this->db->where('a.companyID', element('compID',	$this->session->userdata('logged_in')));
		$this->db->where('col4 >=', $dateFrom);
		$this->db->where('col4 <=', $dateTo);
		$this->db->from('view_gaf a');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return false;
		}
	}
	public function accountDetails(){
		$this->db->select('a.*');
		$this->db->from('comp_acc_det a');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return false;
		}
	}
}