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

class Inventory_model extends CI_Model
{
    private $_table = "inventory";


    // function getAll(){
    //     $query = $this->db->query("SELECT * from inventory where inventory_status=1");
    //     return $query->result();
    // }
   
    public function getAll() {
        $this->db->select('inventory.*, inventory_location.inventory_location_nama, inventory_types.inventory_types_nama');
        $this->db->from('inventory');
        $this->db->join('inventory_location', 'inventory.inventory_location_id = inventory_location.inventory_location_id', 'left');
        $this->db->join('inventory_types', 'inventory.inventory_types_id = inventory_types.inventory_types_id', 'left');
        $query = $this->db->get();
        return $query->result();
    }
    

    public function jumlah_inventory()
    {
        $query =  $this->db->query(" SELECT COUNT(inventory_id) AS JumlahInventory FROM inventory where inventory_status = '1'");
        return $query->result();
      
    }
   
  
    public function save()
    {
        date_default_timezone_set("Asia/Jakarta");
        $tanggal = date("Y-m-d H:i:s");

        $post = $this->input->post();
        // $this->crew_id = $post["crew_id"];
        $this->inventory_nama = $post["inventory_nama"];
        $this->inventory_SN = $post["inventory_SN"];
        $this->inventory_location_id = $post["inventory_location_id"];
        $this->inventory_types_id = $post["inventory_types_id"];
        $this->inventory_remarks = $post["inventory_remarks"];
        $this->inventory_price = $post["inventory_price"];
        $this->inventory_material = $post["inventory_material"];
        $this->inventory_qty = $post["inventory_qty"];
        $this->inventory_status = "1";
        $this->created_at =  $tanggal;
        $this->created_by = $post["created_by"];  
        return $this->db->insert($this->_table, $this);
    }
    public function view_update($where, $table){
        return $this->db->get_where($table, $where);
    }

    public function update($where, $data, $table){
        $this->db->where($where);
        $this->db->update($table, $data);
    }

    public function delete($where, $table){
        $this->db->where($where);
        $this->db->delete($table);
    }
}
