<?php

Class Library_model extends CI_Model {

	function insert($tableName, $post)
    {

        $this->db->insert($tableName, $post);
        return $this->db->insert_id();
    }


    public function itemInfo()
    {
        //$row = $this->db->query("select * from lib_item")->result();
        $row = $this->db->query("select libi.ITEM_ID ,libi.ISBN_NO ,libi.BOOK_CELL_NO , libi.ITEM_NAME  ,libi.ACTIVE_STATUS , b.LKP_NAME as DEPARTMENT ,c.LKP_NAME as BOOK_TYPE_ID from lib_item  libi  left join m00_lkpdata b on b.LKP_ID=libi.DEPARTMENT left join m00_lkpdata c on c.LKP_ID=libi.BOOK_TYPE_ID")->result();

        return $row;
    }


    public function singleItemLiberayInfo($ITEM_ID)
    {

        $row = $this->db->query("select libi.* , b.LKP_NAME as DEPARTMENT ,c.LKP_NAME as BOOK_TYPE_ID ,liba.AUTHOR_NAME , libp.PUBLISHER_NAME ,invs.FULL_ENAME from lib_item  libi  left join m00_lkpdata b on b.LKP_ID=libi.DEPARTMENT left join m00_lkpdata c on c.LKP_ID=libi.BOOK_TYPE_ID left join lib_author liba on liba.AUTHOR_ID=libi.AUTHOR_ID left join lib_publisher libp  on libp.PUBLISHER_ID=libi.PUBLISHER_ID left join inv_supplier invs  on invs.SUPPLIER_ID=libi.SUPPILER_ID ")->row();

        return $row;
    }

    public function stockItemInfo()
    {
       
        $row = $this->db->query("select libir.* , libi.ITEM_NAME ,invs.FULL_ENAME  from lib_item_receive  libir  left join lib_item libi on libi.ITEM_ID=libir.ITEM_NAME_ID left join inv_supplier invs on invs.SUPPLIER_ID=libir.SUPPLIER_ID")->result();

        return $row;
    }


    public function stockItemList(){
                $row = $this->db->query("SELECT  libs.ITEM_ID , libi.ITEM_NAME, COUNT(libs.ITEM_ID) as number_item FROM lib_stock libs left join lib_item libi on libi.ITEM_ID=libs.ITEM_ID GROUP BY ITEM_ID ")->result();
                 return $row;
            }


    public function libraryMember()
    {
      
        $row = $this->db->query("select libm.* , spi.FULL_NAME_EN from lib_members libm left join student_personal_info spi on spi.STUDENT_ID=libm.MEBBER_ID")->result();
        return $row;
    }

    function findAllByAttributeLibrary($tableName, $attribute)
    {
        return $this->db->get_where($tableName, $attribute)->row();
    }


}