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

class Kmgpusat_m extends CI_Model
{

    public function get($id = null)
    {

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

    public function addkatalog($post)
    {
        $params['nama_katbrg'] = $post['nama_katbrg'];

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

    public function addpart($post)
    {
        $params['img_brg'] = $post['img_brg'];
        $params['stok_brg'] = $post['stok_brg'];
        $params['id_katalogbrg'] = $post['id_katalogbrg'];
        $params['merek_brg'] = $post['merek_brg'];
        $params['name_brg'] = $post['name_brg'];
        $params['barcode_brg'] = $post['barcode_brg'];
        $params['koderak_brg'] = $post['koderak_brg'];
        $params['hargam_brg'] = $post['hargam_brg'];
        $params['persen_brg'] = $post['persen_brg'];
        $params['hargau_brg'] = $post['hargau_brg'];
        $params['hargac_brg'] = $post['hargac_brg'];
        $params['id_user'] = $this->fungsi->user_login()->id_user;

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

    public function editpart($post)
    {
        $params['stok_brg'] = $post['stok_brg'];
        $params['id_katalogbrg'] = $post['id_katalogbrg'];
        $params['merek_brg'] = $post['merek_brg'];
        $params['name_brg'] = $post['name_brg'];
        $params['barcode_brg'] = $post['barcode_brg'];
        $params['koderak_brg'] = $post['koderak_brg'];
        $params['hargam_brg'] = $post['hargam_brg'];
        if ($post['img_brg'] != null) {
            $params['img_brg'] = $post['img_brg'];
        }
        $params['persen_brg'] = $post['persen_brg'];
        $params['hargau_brg'] = $post['hargau_brg'];
        $params['hargac_brg'] = $post['hargac_brg'];
        $params['id_user'] = $this->fungsi->user_login()->id_user;

        $this->db->where('id_katbrgstok', $post['id_katbrgstok']);
        $this->db->update('tb_katbrgstok', $params);
    }

    public function delpart($id)
    {
        $this->db->where('id_katbrgstok', $id);
        $this->db->delete('tb_katbrgstok');
    }
}
