This commit is contained in:
Sunandar
2017-02-10 17:25:12 +06:30
parent 9931152796
commit 723ad7462a
8 changed files with 39 additions and 29 deletions

View File

@@ -260,4 +260,10 @@ hr
.show_image{ .show_image{
padding-top: 30px; padding-top: 30px;
} }
.multiselect-container{
width: 250px;
}
.ul.multiselect-container > li> a> label{
padding-left: 10px;
}

View File

@@ -10,15 +10,13 @@ class Api::BatchesController < ApplicationController
client_id=params[:client_id] client_id=params[:client_id]
product_category_id=params[:product_category_id] product_category_id=params[:product_category_id]
find_user=User.find_by_id(check_member.user_id)
created_by=find_user.name
find_client=Client.find_by_id(client_id) find_client=Client.find_by_id(client_id)
if !find_client.nil? if !find_client.nil?
find_product_category=ProductCategory.find_by_id(product_category_id) find_product_category=ProductCategory.find_by_id(product_category_id)
if !find_product_category.nil? if !find_product_category.nil?
user_id=check_member.user_id user_id=check_member.user_id
batch = Batch.create_batch(date,order_ref,user_id,created_by,adult_or_child,client_id,product_category_id) batch = Batch.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id)
if !batch.nil? if !batch.nil?
@out=true,batch.id @out=true,batch.id
else else
@@ -76,16 +74,16 @@ class Api::BatchesController < ApplicationController
end end
def batch_progress_list def batch_progress_list
session_token=params[:session_token] session_token=params[:session_token]
created_by=params[:created_by] user_id=params[:created_by]
check_member= Member.authenticate_session_token(session_token) check_member= Member.authenticate_session_token(session_token)
if !check_member.nil? if !check_member.nil?
if !created_by.nil? if !user_id.nil?
batches = Batch.where('batch_end is null and created_by=?', created_by) batches = Batch.where('batch_end is null and user_id=?', user_id)
if !batches.blank? if !batches.empty?
@out=true,batches @out=true,batches
else else
@out = false, "No Batch" @out = false, batches
end end
else else
@out = false, "Sorry!Unauthorized user!" @out = false, "Sorry!Unauthorized user!"

View File

@@ -5,36 +5,35 @@ class BatchLineItemsController < ApplicationController
def index def index
user_id=current_member.user_id # user_id=current_member.user_id
@clients=Client.all.order('id asc') @clients=Client.all.order('id asc')
find_client=Client.select(:id).order('id asc').first find_client=Client.select(:id).order('id asc').first
if !find_client.nil? if !find_client.nil?
client_id=find_client.id client_id=find_client.id
sub_query="(select * from batches where user_id="+user_id.to_s+" and client_id="+client_id.to_s+")" sub_query="(select * from batches where client_id="+client_id.to_s+")"
@batchLineItems=BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id') @batchLineItems=BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id')
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10) .select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
else else
sub_query="(select * from batches where user_id="+user_id.to_s+")" @batchLineItems=BatchLineItem.joins('inner join batches on batches.id=batch_line_items.batch_id')
@batchLineItems=BatchLineItem.joins('inner join '+ sub_query + ' as batches on batches.id=batch_line_items.batch_id')
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10) .select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
end end
end end
def search def search
user_id=current_member.user_id # user_id=current_member.user_id
batch_list=params[:batch] batch_list=params[:batch]
client_id=params[:client] client_id=params[:client]
@batchLineItems=nil @batchLineItems=nil
if !batch_list.empty? if !batch_list.empty?
sub_query="(select * from batches where id in ("+batch_list+") and user_id="+user_id.to_s+" and client_id="+client_id.to_s+")" sub_query="(select * from batches where id in ("+batch_list+") and client_id="+client_id.to_s+")"
@batchLineItems=BatchLineItem.joins('inner join '+ sub_query +' as batches on batches.id=batch_line_items.batch_id') @batchLineItems=BatchLineItem.joins('inner join '+ sub_query +' as batches on batches.id=batch_line_items.batch_id')
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10) .select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
else else
sub_query="(select * from batches where user_id="+user_id.to_s+" and client_id="+client_id.to_s+")" sub_query="(select * from batches where client_id="+client_id.to_s+")"
@batchLineItems=BatchLineItem.joins('inner join '+ sub_query +'as batches on batches.id=batch_line_items.batch_id') @batchLineItems=BatchLineItem.joins('inner join '+ sub_query +'as batches on batches.id=batch_line_items.batch_id')
.select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10) .select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10)
@@ -65,23 +64,27 @@ class BatchLineItemsController < ApplicationController
find_client=Client.find_by_id(client_id) find_client=Client.find_by_id(client_id)
location_code=find_client.location_code location_code=find_client.location_code
find_user=User.find_by_id(user_id)
if !find_user.nil?
exported_by=find_user.name
end
if params[:batch].present? if params[:batch].present?
batch_list=params[:batch] batch_list=params[:batch]
end end
if !batch_list.empty? if !batch_list.empty?
res=Batch.where("client_id=? and id in (?)",client_id,batch_list).update_all("export_count = export_count + 1") res=Batch.where("client_id=? and id in (?)",client_id,batch_list).update_all("export_count = export_count + 1,exported_by='"+exported_by+"'")
# sub_query=Batch.where('id in (?)',batch_list).select('*').to_sql # sub_query=Batch.where('id in (?)',batch_list).select('*').to_sql
sub_query= "(select * from batches where user_id="+user_id.to_s+" and client_id="+client_id.to_s+")" sub_query= "(select * from batches where client_id="+client_id.to_s+")"
@batchLineItems = BatchLineItem.joins('inner join '+sub_query +" as batches on batches.id=batch_line_items.batch_id") @batchLineItems = BatchLineItem.joins('inner join '+sub_query +" as batches on batches.id=batch_line_items.batch_id")
.joins('inner join product_categories product on product.id=batches.product_category_id') .joins('inner join product_categories product on product.id=batches.product_category_id')
.where('batch_id in (?)',batch_list) .where('batch_id in (?)',batch_list)
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location") .select("*,product.product_type_id ,product.name,'' as secret_token,'' as location")
else else
Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1") Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"'")
sub_query="(select * from batches where client_id ="+client_id+" and user_id="+user_id.to_s+")" sub_query="(select * from batches where client_id ="+client_id+")"
@batchLineItems = BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id') @batchLineItems = BatchLineItem.joins('inner join '+sub_query+' as batches on batches.id=batch_line_items.batch_id')
.joins('inner join product_categories as product on product.id=batches.product_category_id') .joins('inner join product_categories as product on product.id=batches.product_category_id')
.select("*,product.product_type_id ,product.name,'' as secret_token,'' as location") .select("*,product.product_type_id ,product.name,'' as secret_token,'' as location")

View File

@@ -1,9 +1,9 @@
class Batch < ApplicationRecord class Batch < ApplicationRecord
has_many :batch_line_item has_many :batch_line_item
def self.create_batch(date,order_ref,user_id,created_by,adult_or_child,client_id,product_category_id) def self.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id)
batch = Batch.new batch = Batch.new
batch.created_by=created_by batch.exported_by=""
batch.order_ref = order_ref batch.order_ref = order_ref
batch.date = date batch.date = date
batch.batch_start = true batch.batch_start = true

View File

@@ -120,7 +120,7 @@ class BatchLineItem < ApplicationRecord
end end
def self.get_array def self.get_array
arr=Array.new arr=Array.new
(1..1000).each do |i| (1..100).each do |i|
str= SecureRandom.hex str= SecureRandom.hex
uid=str[0..13] uid=str[0..13]
arr.push(uid) arr.push(uid)

View File

@@ -79,7 +79,7 @@ $(document).ready(function(){
client_id=$(this).val() client_id=$(this).val()
get_batch(client_id) get_batch(client_id)
}); });
function get_batch(client_id){ function get_batch(client_id){
$('#batch').multiselect('disable'); $('#batch').multiselect('disable');
$.ajax({ $.ajax({
type: "GET", type: "GET",
@@ -110,7 +110,7 @@ $(document).ready(function(){
filter(client,batch); filter(client,batch);
}); });
function filter(client,batch){ function filter(client,batch){
if (batch==null){ if (batch==null){
batch="" batch=""
} }
@@ -130,6 +130,7 @@ $(document).ready(function(){
} }
}); });
} }
$("ul.multiselect-container > li> a > label").attr("style","padding-left:10px");
}) })
</script> </script>

View File

@@ -18,7 +18,8 @@
<th>Qty Processing</th> <th>Qty Processing</th>
<th>Qty Success</th> <th>Qty Success</th>
<th>Qty Fail</th> <th>Qty Fail</th>
<th>Export Count</th> <th>Export Count</th>
<th>Exported By</th>
<th>Creatd At</th> <th>Creatd At</th>
</tr> </tr>
</thead> </thead>
@@ -30,7 +31,8 @@
<td><%= batch.qty_processing rescue '' %></td> <td><%= batch.qty_processing rescue '' %></td>
<td><%= batch.qty_success rescue '' %></td> <td><%= batch.qty_success rescue '' %></td>
<td><%= batch.qty_fail rescue '' %></td> <td><%= batch.qty_fail rescue '' %></td>
<td><%= batch.export_count %></td> <td><%= batch.export_count %></td>
<td><%= batch.exported_by %></td>
<td><%= batch.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td> <td><%= batch.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %></td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170209102414) do ActiveRecord::Schema.define(version: 20170210103359) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@@ -35,7 +35,7 @@ ActiveRecord::Schema.define(version: 20170209102414) do
t.string "order_ref", null: false t.string "order_ref", null: false
t.boolean "batch_start" t.boolean "batch_start"
t.boolean "batch_end" t.boolean "batch_end"
t.string "created_by", null: false t.string "exported_by", null: false
t.integer "qty_processing", null: false t.integer "qty_processing", null: false
t.integer "qty_success", null: false t.integer "qty_success", null: false
t.integer "qty_fail", null: false t.integer "qty_fail", null: false