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

class Motor_m extends CI_Model
{

    public function getmerek($id = null)
    {
        $this->db->from('tb_merekkendaraan');
        if ($id != null) {
            $this->db->where('id_merek', $id);
        }
        $query = $this->db->get();
        return $query;
    }

    public function gettipe($id = null)
    {

        $this->db->from('tb_tipekendaraan');
        if (isset($_GET['Seri'])) {
            $cab = $_GET['Seri'];
            $this->db->order_by('id_tipeken', 'desc');
            $this->db->where('id_merek', $cab);
        }
        $query = $this->db->get();
        return $query;
    }

    public function getseri($id = null)
    {

        if ($id != null) {
            $this->db->from('tb_serikendaraan');
            $this->db->order_by('id_seriken', 'asc');
            $this->db->where('id_seriken', $id);
        } elseif (isset($_GET['Seri'])) {
            $cab = $_GET['Seri'];
            $this->db->select('tb_serikendaraan.* , tb_tipekendaraan.tipeken as tipeken');
            $this->db->from('tb_serikendaraan');
            $this->db->join('tb_tipekendaraan', 'tb_tipekendaraan.id_tipeken   = tb_serikendaraan.id_tipeken ');
            $this->db->where('tipeken_pass', $cab);
            $this->db->order_by('id_seriken', 'asc');
        } else {
            $this->db->from('tb_serikendaraan');
            $this->db->order_by('id_seriken', 'asc');
            $this->db->where('id_seriken', 0);
        }
        $query = $this->db->get();
        return $query;
    }

    public function addmerekken($post)
    {
        $params['merek_kendaraan'] = $post['merek_kendaraan'];
        $this->db->insert('tb_merekkendaraan', $params);
    }

    public function addtipeken($post)
    {
        $params['id_merek'] = $post['id_merek'];
        $params['tipeken_pass'] = $post['id_merek'];
        $params['tipeken'] = $post['tipeken'];
        $this->db->insert('tb_tipekendaraan', $params);
    }

    public function addseriken($post)
    {
        $params['id_merek'] = $post['id_merek'];
        $params['id_tipeken'] = $post['id_tipeken'];
        $params['seriken'] = $post['seriken'];
        $this->db->insert('tb_serikendaraan', $params);
    }

    public function delinvkm($id)
    {
        $this->db->where('id_invkm', $id);
        $this->db->delete('tb_invkm');
    }
}
