File: //home/cafsindia/ntc_cafsinfotech_in_bk/application/controllers/Product_availability.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Base_controller.php");
class Product_availability extends Base_controller{
public function __construct(){
parent::__construct('product_availability');
if(!$this->Appconfig->isAppvalid()){
redirect('config');
}
$this->collect_base_info();
}
// LOAD PAGE WITH TABLE DATA
public function index(){
$data['table_headers']= $this->xss_clean(get_product_availability_headers());
$data['load_customer_info']= $this->get_load_customer_name();
$this->load->view("$this->control_name/manage",$data);
}
//LOAD MODEL PAGE VIEW WITH DATA
public function view($prime_customer_id){
if($this->customer_exists($prime_customer_id, TRUE)){
$rlst = $this->get_product_id($prime_customer_id);
$product_ids = explode(",",$rlst[0]->product_ids);
$quantity = explode(",",$rlst[0]->quantity);
$tr_line = "";
$i = 0;
foreach($product_ids as $product_id){
$receiving_quantity_info = $this->receiving_quantity($product_id);
$dispatch_quantity_info = $this->dispatch_quantity($product_id);
$product_info = $this->product_info($product_id);
$rslt_info = json_encode(array_merge($product_info[0],$receiving_quantity_info[0],$dispatch_quantity_info[0]));
$rslt_info = json_decode($rslt_info);
$dispatch_quantity = $rslt_info->dispatch_quantity;
$receiving_quantity = $rslt_info->receiving_quantity;
$product_name = $rslt_info->product_name;
$brand_name = $rslt_info->brand_name;
$category_name = $rslt_info->category_name;
$product_description = $rslt_info->product_description;
$product_code = $rslt_info->product_code;
$wastage_units = $rslt_info->wastage_units;
$no_of_units = $rslt_info->no_of_units;
$availability_quantity = abs((int)$quantity[$i]);
$i++;
if((int)$availability_quantity <= 10){
$availability_quantity_style = "style='color: red;font-weight: 600 !important;'";
}else{
$availability_quantity_style= "";
}
$tr_line .= "<tr>
<td>$product_name</td>
<td>$brand_name</td>
<td>$category_name</td>
<td>$product_description</td>
<td>$product_code</td>
<td>$receiving_quantity</td>
<td>$no_of_units</td>
<td>$wastage_units</td>
<td>$dispatch_quantity</td>
<td $availability_quantity_style>$availability_quantity</td>
</tr>";
}
$data['product_data'] = $tr_line;
$this->load->view("$this->control_name/form",$data);
}
}
//LOAD PAGE TABLE VIEW WITH DATA BASED ON SEARCH FILTERS
public function search(){
$search = $this->input->get('search');
$limit = $this->input->get('limit');
$offset = $this->input->get('offset');
$sort = $this->input->get('sort');
$order = $this->input->get('order');
$customer_name = $this->input->get('customer_name');
$start_date = str_replace("/","-",$this->input->get('start_date'));
$end_date = str_replace("/","-",$this->input->get('end_date'));
$from_date = date('Y-m-d',strtotime($start_date));
$to_date = date('Y-m-d',strtotime($end_date));
$this->db->select('customer.prime_customer_id,our_vendor_no, bee_level, acc, customer_name, delivery_address, postal_address, telephone, fax, mobile_number, email, customer_type, customer_category, normal_terms, early_terms, currency_code, eu_country, no_of_notes, discount, cr_limit, interest, statement, blocked_status, sales_code, tax_mode, tax_type, tax_reference, cash_sale_acc, accepts_email, contact_person, contact_persons_no');
$this->db->from('customer');
$this->db->where('customer.trans_status', 1);
if($search){
$this->db->group_start();
$this->db->like('our_vendor_no',$search);
$this->db->or_like('customer_name',$search);
$this->db->or_like('telephone',$search);
$this->db->or_like('delivery_address',$search);
$this->db->or_like('mobile_number',$search);
$this->db->or_like('email',$search);
$this->db->group_end();
}
$filter_sts = array();
if(!empty($customer_name)){
foreach($customer_name as $key => $value){
if($value){
$filter_sts[] = $value;
}
}
}
if(count($filter_sts) > 0){
$this->db->where_in('customer.prime_customer_id',$filter_sts);
}
$this->db->order_by($sort,$order);
$receiving_data = $this->db->get();
$receiving_rslt = $receiving_data->result();
$num_rows = $receiving_data->num_rows();
$datarows=array();
foreach($receiving_rslt as $receiving){
$datarows[]=get_product_availability_datarows($receiving,$this);
}
echo json_encode(array('total'=>$num_rows,'rows'=>$datarows));
}
//CHECKING RECEIVING QUANTITY
public function receiving_quantity($product_id){
$this->db->select('IFNULL(sum(cw_product_receiving.quantity ), 0) as receiving_quantity, ,IFNULL(sum(cw_product_receiving.wastage_units),0) as wastage_units,IFNULL(sum(cw_product_receiving.no_of_units),0) as no_of_units');
$this->db->from('product_receiving');
$this->db->where('product_receiving.trans_status', 1);
$this->db->where('product_receiving.product_id', (int)$product_id);
$receiving_quantity_amount_info = $this->db->get()->result_array();
return $receiving_quantity_amount_info;
}
//CHECKING DISPATCH QUANTITY
public function dispatch_quantity($product_id){
$this->db->select('IFNULL(sum(cw_product_dispatch.quantity), 0) as dispatch_quantity');
$this->db->from('product_dispatch');
$this->db->where('product_dispatch.trans_status', 1);
$this->db->where('product_dispatch.product_id', (int)$product_id);
$dispatch_quantity_amount_info = $this->db->get()->result_array();
return $dispatch_quantity_amount_info;
}
public function product_info($product_id){
$this->db->select('warehouse_product.product_name,warehouse_brand.brand_name,warehouse_category.category_name,warehouse_product.product_description,warehouse_product.product_code');
$this->db->from('warehouse_product');
$this->db->join('warehouse_brand', 'warehouse_product.brand_name = warehouse_brand.prime_warehouse_brand_id','inner');
$this->db->join('warehouse_category', 'warehouse_product.category_name = warehouse_category.prime_warehouse_category_id','inner');
$this->db->where('warehouse_product.prime_warehouse_product_id', (int)$product_id);
$product_info = $this->db->get()->result_array();
return $product_info;
}
//CHECKING PRODUCT IS EXISTS
public function customer_exists($prime_customer_id){
$this->db->from('customer');
$this->db->where('prime_customer_id', (int)$prime_customer_id);
$this->db->where('trans_status',1);
$count = $this->db->get()->num_rows();
return ((int)$count === 1);
}
public function get_product_id($prime_customer_id){
$this->db->select('customer_name,GROUP_CONCAT(prime_warehouse_product_id) as product_ids,GROUP_CONCAT(availabale_quantity) as quantity');
$this->db->from('warehouse_product');
$this->db->where('customer_name', (int)$prime_customer_id);
$this->db->where('trans_status',1);
$this->db->group_by('warehouse_product.customer_name');
$rslt = $this->db->get()->result();
return $rslt;
}
//GET CUSTUMER NAME FOR FILTERS
public function get_load_customer_name(){
$this->db->select('prime_customer_id,customer_name');
$this->db->from('customer');
$this->db->where('trans_status',1);
$customer_info = $this->db->get()->result();
foreach($customer_info as $row){
$load_customer_type[$row->prime_customer_id] = $row->customer_name;
}
return $load_customer_type;
}
}
?>