<?php

class SalesCustomer extends CI_Model
{
    public $recordID;
    public $customerid;

    public function __construct()
	{
		parent::__construct();

        $this->load->database();
    }

    public function getSalesCustomerByRecordIDCustomerID()
    {
        return $this->db->get_where("salescustomer", array("recordID"=>$this->recordID, "customerid"=>$this->customerid));
    }

    public function getSalesJoinedSalesCustomerByCustomerID($customerid)
    {
        $this->db->select('*');
        $this->db->from('salescustomer');
        $this->db->join('sales', 'salescustomer.recordID=sales.recordID');
        $this->db->where('salescustomer.customerid', $customerid);
        return $this->db->get();
    }


    public function addSalesCustomer()
    {
        $data = array(
            "recordID" => $this->recordID,
            "customerid" => $this->customerid
        );

        $success = $this->db->insert("salescustomer", $data);

        if($success)
            return array("success"=>$success, "data" => $data);
        else
            return array("success"=>$success, "data" => $this->db->error());
    }
}