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

class Klcab_m extends CI_Model
{

    public function get($id = null)
    {

        if ($id != null) {
            $this->db->from('tb_invkm');
            $this->db->order_by('id_invkm', 'desc');
            $this->db->where('id_invkm', $id);
        } elseif (isset($_GET['Cab'])) {
            $cab = $_GET['Cab'];
            $this->db->from('tb_invkm');
            $this->db->where('id_cabang', $cab);
            $this->db->order_by('id_invkm', 'DESC');
        } else {
            $this->db->from('tb_invkm');
            $this->db->order_by('id_invkm', 'desc');
            $this->db->where('aktif_invkm', 0);
        }
        $query = $this->db->get();
        return $query;
    }

    public function addinv($post)
    {
        $params['invkm_ktp'] = $post['invkm_ktp'];
        $params['invkm_nama'] = $post['invkm_nama'];
        $params['invkm_alamat'] = $post['invkm_alamat'];
        $params['invkm_nohp'] = $post['invkm_nohp'];
        $params['invkm_email'] = $post['invkm_email'];
        $params['invkm_sosmed'] = $post['invkm_sosmed'];
        $params['invkm_foto'] = $post['invkm_foto'];
        $params['invkm_noreg'] = $post['invkm_noreg'];
        $params['invkm_bank'] = $post['invkm_bank'];
        $params['invkm_tipe'] = $post['invkm_tipe'];
        $params['id_cabang'] = $post['id_cabang'];
        $params['invkm_tgl'] = $post['invkm_tgl'];
        $params['aktif_invkm'] = 1;

        $this->db->insert('tb_invkm', $params);
    }

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