Current File : /home/giriqfky/public_html/Barga/application/modules/report/models//Product_model.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Product_model extends CI_Model
{
var $table_cities = TABLE_CITIES;
var $table_product = TABLE_PRODUCT_LIST;
var $table_product_order = TABLE_PRODUCT_ORDER;
var $table_product_order_details = TABLE_PRODUCT_ORDER_DETAILS;
public function __construct()
{
parent::__construct();
}
/*** Code for Todo start ***/
public function getTodoData($todo_id)
{
$this->db->select('*');
$this->db->where('id', $todo_id);
$this->db->limit(1);
return $this->db->get($this->table_product)->row();
}
public function getSingleProductData($product_id)
{
$this->db->select('*');
$this->db->where('id',$product_id);
return $this->db->get($this->table_product)->result();
}
public function getAllProductData($todo_id)
{
$this->db->select('*');
$this->db->where('status','1');
$this->db->where('qty > ','0');
// $this->db->limit(1);
return $this->db->get($this->table_product)->result();
}
public function OrderDetailsSave($data_array, $id = 0)
{
if($id == 0) {
$this->db->insert($this->table_product_order, $data_array);
$last_id = $this->db->insert_id();
echo $last_id;
} else {
$this->db->where('id', $id);
$this->db->update($this->table_product_order, $data_array);
$last_id = $id;
}
return $last_id;
}
// fly_product_order_details table save | start
public function OrderDetailsTableSave($data_array, $id = 0)
{
if($id == 0) {
$this->db->insert($this->table_product_order_details, $data_array);
$last_id = $this->db->insert_id();
echo $last_id;
} else {
$this->db->where('id', $id);
$this->db->update($this->table_product_order_details, $data_array);
$last_id = $id;
}
return $last_id;
}
// fly_product_order_details table save | end
public function getTodoList($params = array())
{
$this->db->select("product_order.id,product_order.table_no,product_order.order_id,(SUM(product_order.total)+SUM(product_order.tax)) AS Total_Amt_val,product_order.tax,SUM(product_order.total) AS Total_Amt,GROUP_CONCAT(product_order.quantity,'*',product_order.product_name,' ') as product_name,
order_deti.cust_name,order_deti.cust_number,order_deti.cust_address,order_deti.cust_gst,order_deti.doc,order_deti.room_number");
$this->db->from($this->table_product_order . ' as product_order');
$this->db->join($this->table_product_order_details.' order_deti','order_deti.order_id = product_order.order_id', 'left');
if(!empty($params['search']['order_id'])){
$this->db->like('order_id',$params['search']['order_id']);
}
if(!empty($params['search']['date'])){
$this->db->like('order_deti.doc',$params['search']['date']);
}
$this->db->group_by('product_order.order_id');
$this->db->order_by('product_order.doc','DESC');
//set start and limit
if(array_key_exists("start",$params) && array_key_exists("limit",$params)) {
$this->db->limit($params['limit'],$params['start']);
} elseif(!array_key_exists("start",$params) && array_key_exists("limit",$params)) {
$this->db->limit($params['limit']);
}
return $this->db->get()->result();
}
public function deleteProduct($where = array())
{
if(!empty($where)){
$this->db->where($where);
$this->db->delete($this->table_cities);
}
}
/*** Code for City end ***/
public function getProductOrder($order_id)
{
$this->db->select("product_order.*");
$this->db->from($this->table_product_order . ' as product_order');
$this->db->where('product_order.order_id',$order_id);
return $this->db->get()->result();
}
public function getOrderDetails($order_id)
{
$this->db->select("product_order_deti.*");
$this->db->from($this->table_product_order_details . ' as product_order_deti');
$this->db->where('product_order_deti.order_id',$order_id);
return $this->db->get()->result();
}
public function productSave($data_array, $id = 0)
{
if($id == 0) {
$this->db->insert($this->table_product, $data_array);
$last_id = $this->db->insert_id();
echo $last_id;
} else {
$this->db->where('id', $id);
$this->db->update($this->table_product, $data_array);
$last_id = $id;
}
return $last_id;
}
public function currentOrderId()
{
$this->db->select("id");
$this->db->from($this->table_product_order_details);
$this->db->order_by('id','DESC');
$this->db->limit(1);
$result = $this->db->get()->row();
if(!empty($result)){
return $result->id+1;
}else{
return 0;
}
}
//
public function getAllProductDataList($params = array())
{
$this->db->select('*');
$this->db->from($this->table_product);
if(!empty($params['search']['name'])){
$this->db->like('name',$params['search']['name']);
}
$this->db->order_by('dom','DESC');
//set start and limit
if(array_key_exists("start",$params) && array_key_exists("limit",$params)) {
$this->db->limit($params['limit'],$params['start']);
} elseif(!array_key_exists("start",$params) && array_key_exists("limit",$params)) {
$this->db->limit($params['limit']);
}
return $this->db->get()->result();
}
}