<?php
	class Damage_model extends CI_model
	{
		public function __construct()
		{
			parent::__construct();
			$this->load->database();
			//$this->db2 = $this->load->database('otherdb', TRUE);
	
		}
	
	public function getDamage($damage_id) {
		$query = $this->db->query("SELECT *,DATE_FORMAT(damage_date, '%d-%m-%Y') as damage_date FROM damage_order_creation where damage_id='$damage_id'");
		return $query->result();
	}
	
	
	public function get_damage_item($damage_id) {
		$query = $this->db->query("SELECT * FROM  damage_order_creation D inner join damage_order_item T on D.damage_id=T.damage_id where D.damage_id='$damage_id'");
		return $query->result();
	}

	public function get_damage_list($branch_id) {
		$query = $this->db->query("SELECT *,damage_id as mid, DATE_FORMAT(damage_date, '%d-%m-%Y') as damage_date FROM damage_order_creation where branch_id='$branch_id' ORDER BY damage_id desc");
		return $query->result();
	}
	
	public function get_Cdamage_list(){
	    $branch_name = $_SESSION['branch_name'];
	    $cw_ceo = $_SESSION['cw_ceo'];
		if($cw_ceo=='CW')
        {
            $query = $this->db->query("SELECT *,damage_id as mid, DATE_FORMAT(damage_date, '%d-%m-%Y') as damage_date FROM damage_order_creation ORDER BY damage_id desc");
        }
        else{
            $query = $this->db->query("SELECT *,damage_id as mid, DATE_FORMAT(damage_date, '%d-%m-%Y') as damage_date FROM damage_order_creation where branchname LIKE '$cw_ceo%' ORDER BY damage_id desc");
        }
        /*if($branch_name=='CW4_CEO')
        {
            $query = $this->db->query("SELECT *,damage_id as mid, DATE_FORMAT(damage_date, '%d-%m-%Y') as damage_date FROM damage_order_creation where branchname LIKE 'CW4%' ORDER BY damage_id desc");
        }
        else if($branch_name=='CW5_CEO')
        {
            $query = $this->db->query("SELECT *,damage_id as mid, DATE_FORMAT(damage_date, '%d-%m-%Y') as damage_date FROM damage_order_creation where branchname LIKE 'CW5%' ORDER BY damage_id desc");
        }
        else if($branch_name=='CW6_CEO')
        {
            $query = $this->db->query("SELECT *,damage_id as mid, DATE_FORMAT(damage_date, '%d-%m-%Y') as damage_date FROM damage_order_creation where branchname LIKE 'CW6%' ORDER BY damage_id desc");
        }
        else
        {
		    $query = $this->db->query("SELECT *,damage_id as mid, DATE_FORMAT(damage_date, '%d-%m-%Y') as damage_date FROM damage_order_creation ORDER BY damage_id desc");
        }*/
		return $query->result();
	}
	
	public function get_rwCategory() {
		$query = $this->db->query("SELECT category_id,category_name from category order by category_name");
		return $query->result();
	}
    
    public function get_fpCategory() {
		$query = $this->db->query("SELECT pr_cat_id,pr_cat_name from product_category order by pr_cat_name");
		return $query->result();
	}
}

?>