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

class Mtoko extends CI_Model{

  public function __construct()
  {
    parent::__construct();
    //Codeigniter : Write Less Do More
  }

  public function get_data(){
    return $this->db
    ->join("data_user","data_user.iddata_user=mitra.data_user_iddata_user")
    ->get("mitra")->result();
  }

  public function get_data_edit($id){
    return $this->db
    ->where("idmitra",$id)
    ->join("data_user","data_user.iddata_user=mitra.data_user_iddata_user")
    ->get("mitra")->result();
  }

  public function detail_mitra($idmitra)
  {
    return $this->db
    ->where("idmitra",$idmitra)
    ->join("data_user","data_user.iddata_user=mitra.data_user_iddata_user")
    ->get("mitra");
  }

  public function get_mitra($cari_mitra=null, $idprovinsi=null, $idkabupaten=null)
  {
    $this->db->select("mitra.*, barang.*");
    $this->db->join("mitra","mitra.idmitra = barang.mitra_idmitra");
    $this->db->join("kategori","kategori.idkategori = barang.kategori_idkategori");
    if ($idprovinsi!=null || $idprovinsi!="") {
      $this->db->where("mitra.idprovinsi", $idprovinsi);
    }
    if ($idkabupaten!=null || $idkabupaten!="") {
      $this->db->where("mitra.idkabupaten", $idkabupaten);
    }
    if ($cari_mitra!=null || $cari_mitra!="") {
      $this->db->like("mitra.nama_mitra", $cari_mitra);
    }
    $this->db->group_by("mitra.idmitra");
    return $this->db->get("barang");
  }


}
