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

class SalesPrice extends CI_Model{
	
	public function SalesPrice_all(){
		$this->db->select('a.*');
		$this->db->select('b.customerName');
		$this->db->select('c.*');
		$this->db->select('d.itemCode');
		$this->db->select('d.name');
		$this->db->select('e.*');
		$this->db->where('a.companyID', element('compID', $this->session->userdata('logged_in')));
		$this->db->order_by('a.companyID');
		$this->db->from('comp_sales_price a');
		$this->db->join('customer b', 'b.ID = a.customerID');	
		$this->db->join('_sys_um c', 'c.fldid = a.umID');	
		$this->db->join('item d', 'd.ID = a.itemID');	
		$this->db->join('_ref_currency e', 'e.fldid = a.currencyID');	
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
	
	public function SalesPrice_Insert(){
		$newData = array(
			'companyID' => element('compID', $this->session->userdata('logged_in')),
			'customerID' => $this->input->post('customerID'),
			'itemID' => $this->input->post('itemID'),
			'currencyID' => $this->input->post('currencyID'),
			'umID' => $this->input->post('umID'),
			'startDate' => date("Y-m-d", strtotime($this->input->post('startDate'))),
			'endDate' => date("Y-m-d", strtotime($this->input->post('endDate'))),
			'price' => $this->input->post('price'),
			'createdBy' => element('role', $this->session->userdata('logged_in'))
		);
		$query = $this->db->insert('comp_sales_price', $newData);
		if($query){
			return $this->db->insert_id();
		}else{
			return FALSE;
		}
	}
	public function SalesPrice_Update($ID, $data){
		$this->db->where('ID', $ID);
		$query = $this->db->update('comp_sales_price', $data); 
		if($query === TRUE){
			return $this->db->last_query();
		} else {
			return FALSE;
		}
	}
	public function SalesPrice_Delete($ID){
		$this->db->where('ID', $ID);
		$query = $this->db->delete('comp_sales_price'); 
		if($query === TRUE){
			return $this->db->last_query();
		} else {
			return FALSE;
		}
	}
	public function SalesPrice_ID($ID){
		$this->db->where('ID', $ID);
		$this->db->from('comp_sales_price');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}
	
	public function SalesPrice_search($where){
		$this->db->where($where);
		$this->db->from('comp_sales_price');
		$query = $this->db->get();
		if($query->num_rows() >= 1){
			return $query->result();
		}else{
			return FALSE;
		}
	}

}

/* End of file SalesOrder.php */
/* Location: ./application/models/SalesOrder.php */
/* Created By : Yahaya Abdollah */
