<?php
class M_siplabs extends CI_Model
{
	public function get_data($table)
	{
		return $this->db->get($table);
	}

	public function get_datawithadd($table, $additional)
	{
		return $this->db->query("SELECT * FROM " . $table . ' ' . $additional);
	}

	public function get_join($table, $join, $where)
	{
		$query = "SELECT * FROM " . $table . " INNER JOIN " . $join . " WHERE " . $where;
		return $this->db->query($query);
	}

	public function getwhere($table, $where)
	{
		return $this->db->get_where($table, $where);
	}
	public function add_data($table, $array)
	{
		return $this->db->insert($table, $array);
	}

	public function updatedata($table, $array, $where)
	{
		$this->db->where($where);
		return $this->db->update($table, $array);
	}

	public function deletedata($table, $where)
	{
		return $this->db->delete($table, $where);
	}

	public function deleteinv($q)
	{
		$this->db->where("id_inv", $q);
   		$this->db->delete("inventaris");
   		return true;
	}

	public function proses_tambahdata($array)
	{ 
		$this->db->insert('inventaris',$array);
	}

	public function editdata($where,$table)
	{
		return $this->db->get_where($table,$where);
	}

	public function update_data($where,$data,$table)
	{
		$this->db->where($where);
		$this->db->update($table,$data);
	}

	public function join3($cek)
	{
		$this->db->select('*');    
		$this->db->from('pinjam_inv');
		$this->db->join('inventaris', 'pinjam_inv.id_inv = inventaris.id_inv');
		$this->db->join('user', 'pinjam_inv.id_user = user.id_user');
		$query = $this->db->get();
	}

	public function deletepem($id_pinjam)
	{
		$this->db->where("id_pinjam", $id_pinjam);
   		$this->db->delete("pinjam_inv");
   		return true;
	}
	public function deletepinjam($p)
	{
		$this->db->where("id_pinjam", $p);
   		$this->db->delete("pinjam_inv");
   		return true;
	}
	public function deletepengembalian($p)
	{
		$this->db->where("id_pengembalian", $p);
   		$this->db->delete("pengembalian_inv");
   		return true;
	}

	public function joininv()
	{
		$this->db->query('SELECT * FROM `pengembalian_inv` INNER JOIN user ON pengembalian_inv.id_user=user.id_user INNER JOIN pinjam_inv ON user.id_user=pinjam_inv.id_user INNER JOIN inventaris ON pinjam_inv.id_inv=inventaris.id_inv')->result();
	}

	public function get_data_by_kondisi($kondisi)
    {
        $this->db->select('*');
        $this->db->from('inventaris');
        $this->db->where('inventaris.kondisi', $kondisi);
        $query = $this->db->get();
        return $query->result();
    }
}