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

class Mkurir extends CI_Model{

  /**

  * @author Fendrik Nurul Jadid <fendrik1311@gmail.com>

  * @since v.1.0

  **/


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

  public function get_list($idmitra, $status = null)
  {
    $this->db->select("kurir.*, mitra.*");
    $this->db->join("mitra","mitra.idmitra = kurir.mitra_idmitra");
    if ($status == "2") {
      $this->db->join("user","user.idkurir = kurir.idkurir");
    }
    $this->db->where("mitra.idmitra", $idmitra);
    return $this->db->get("kurir")->result();
  }

  public function get_kurir_mitra($idmitra, $idkurir)
  {
    $this->db->select("kurir.*, mitra.*");
    $this->db->join("mitra","mitra.idmitra = kurir.mitra_idmitra");
    $this->db->join("user","user.idkurir = kurir.idkurir");
    $this->db->where("mitra.idmitra", $idmitra);
    $this->db->where("kurir.idkurir", $idkurir);
    return $this->db->get("kurir");
  }

  public function get_list_mitra($cari_kurir=null, $idkabupaten=null, $idkecamatan=null)
  {
    $this->db->select("kurir.*, mitra.*");
    $this->db->join("mitra","mitra.idmitra = kurir.mitra_idmitra");
    // $this->db->join("user","user.idkurir = kurir.idkurir");
    if ($idkabupaten!=null || $idkabupaten!='') {
      $this->db->where("mitra.idkabupaten", $idkabupaten);
    }
    if ($idkecamatan!=null || $idkecamatan!='') {
      $this->db->where("mitra.idkecamatan", $idkecamatan);
    }
    if ($cari_kurir!=null || $cari_kurir!='') {
      $this->db->where("kurir.nama_kurir", $cari_kurir);
    }
    return $this->db->get("kurir");
  }

  public function get_data($id_kurir){
    return $this->db
    ->where("kurir_idkurir",$id_kurir)
    ->get("pemesanan")->result();
  }
  public function get_kurir($id_kurir){
    return $this->db
    ->where("idkurir",$id_kurir)
    ->get("kurir");
  }

  function get_statusKirim($id_kurir, $status, $tgl = null)
  {
    $this->db->join('data_user', 'data_user.iddata_user = pemesanan.data_user_iddata_user');
    if ($tgl != null || $tgl != "") {
      $this->db->where("pemesanan.tanggal",date("Y-m-d", strtotime($tgl)));
    }
    $this->db->where("status_pemesanan", $status);
    $this->db->where("kurir_idkurir",$id_kurir);
    return $this->db->get("pemesanan");
  }

  function ongkir_kurir($idmitra, $iddesa)
  {
    $this->db->where("mitra_idmitra", $idmitra);
    $this->db->where("villages_id",$iddesa);
    return $this->db->get("ongkir");
  }

  function detail_pemesanan_kurir($id_pemesanan)
  {
    $this->db->join('pemesanan', 'pemesanan.idpemesanan=detail_pemesanan.pemesanan_idpemesanan');
    $this->db->join('data_user', 'data_user.iddata_user=pemesanan.data_user_iddata_user');
    $this->db->join('barang', 'barang.idbarang=detail_pemesanan.barang_idbarang');
    $this->db->where('pemesanan.idpemesanan',$id_pemesanan);

    return $this->db->get('detail_pemesanan');
  }

}
