From b885b658f60e1209d06fd8d82ad54e06152bcbae Mon Sep 17 00:00:00 2001 From: nandar Date: Wed, 1 Aug 2018 17:04:00 +0630 Subject: [PATCH] commit by nda --- .../batch_line_items_controller.rb | 85 ++++++++- .../batch_line_items/export_to_seller.csv.erb | 0 .../export_to_seller.html.erb | 173 ++++++++++++++++++ app/views/batch_line_items/index.html.erb | 4 - app/views/layouts/_navigation.html.erb | 13 +- config/routes.rb | 2 + 6 files changed, 265 insertions(+), 12 deletions(-) create mode 100644 app/views/batch_line_items/export_to_seller.csv.erb create mode 100644 app/views/batch_line_items/export_to_seller.html.erb diff --git a/app/controllers/batch_line_items_controller.rb b/app/controllers/batch_line_items_controller.rb index 5d2e3f4..63ac3a7 100644 --- a/app/controllers/batch_line_items_controller.rb +++ b/app/controllers/batch_line_items_controller.rb @@ -14,6 +14,32 @@ class BatchLineItemsController < ApplicationController @product_category_id="" @clients=Client.all.order('id desc') @product_categories=ProductCategory.all.order('id desc') + + find_client=Client.select(:id).order('id desc').last + if !find_client.nil? + client_id=find_client.id + + find_batch=Batch.where('client_id=?',client_id).order('id desc').first + + if !find_batch.nil? + @product_category_id=find_batch.product_category_id + end + sub_query="(select * from batches where client_id="+client_id.to_s+" and product_category_id ="+@product_category_id.to_s+" )" + + @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) + @result_count= @batchLineItems.total_count + else + @batchLineItems=BatchLineItem.joins('inner join 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) + @result_count= @batchLineItems.total_count + end + end + + def export_to_seller + @product_category_id="" + @clients=Client.all.order('id desc') + @product_categories=ProductCategory.all.order('id desc') @sellers=User.where("user_type=?","Seller") find_client=Client.select(:id).order('id desc').last @@ -35,7 +61,7 @@ class BatchLineItemsController < ApplicationController .select('batch_line_items.*,batches.order_ref as batch_name').order('batch_line_items.id desc').page(params[:page]).per(10) @result_count= @batchLineItems.total_count end - end + end def search # user_id=current_member.user_id @@ -84,7 +110,6 @@ class BatchLineItemsController < ApplicationController @batches=Batch.where('user_id=?',user_id) client_id=params[:client] product_category_id=params[:product_category] - seller_id = params[:seller] find_client=Client.find_by_id(client_id) location_code=find_client.location_code client_name=find_client.name.downcase @@ -100,7 +125,7 @@ class BatchLineItemsController < ApplicationController end if !batch_list.empty? - res=Batch.where("client_id=? and product_category_id=? and id in (?)",client_id,product_category_id,batch_list).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"'") + res=Batch.where("client_id=? and product_category_id=? and id in (?)",client_id,product_category_id,batch_list).update_all("export_count = export_count + 1,exported_by='"+exported_by+"'") sub_query= "(select * from batches where client_id="+client_id.to_s+" and product_category_id="+ product_category_id.to_s+")" @@ -110,7 +135,59 @@ class BatchLineItemsController < ApplicationController .where('batch_id in (?)',batch_list) .select("*,product.product_type_id ,product.name,'' as secret_token,'' as location_name") else - Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"'") + 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 product_category_id="+ product_category_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') + .select("*,product.product_type_id ,product.name,'' as secret_token,'' as location_name") + end + + datestr= Time.now.strftime("%Y/%m/%d %H:%M:%S") + filename=client_name.to_s+"_"+product_name.to_s+"_"+datestr + respond_to do |format| + format.html + format.csv { send_data @batchLineItems.to_csv(client_id,location_code), filename: "#{filename}.csv" } + end + end + + + def export_seller + batch_list="" + @batchLineItems=nil + user_id=current_member.user_id + + @clients=Client.all + @batches=Batch.where('user_id=?',user_id) + client_id=params[:client] + product_category_id=params[:product_category] + seller_id = params[:seller] + find_client=Client.find_by_id(client_id) + location_code=find_client.location_code + client_name=find_client.name.downcase + find_product=ProductCategory.find_by_id(product_category_id) + product_name=find_product.name.downcase + + find_user=User.find_by_id(user_id) + if !find_user.nil? + exported_by=find_user.name + end + if params[:batch].present? + batch_list=params[:batch] + end + today_date = Time.now.to_s + if !batch_list.empty? + res=Batch.where("client_id=? and product_category_id=? and id in (?)",client_id,product_category_id,batch_list).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"',export_to_seller_date='"+today_date+"'") + + + sub_query= "(select * from batches where client_id="+client_id.to_s+" and product_category_id="+ product_category_id.to_s+")" + + @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') + .where('batch_id in (?)',batch_list) + .select("*,product.product_type_id ,product.name,'' as secret_token,'' as location_name") + else + # Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"',export_to_seller_date='"+today_date+"'") + Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"',export_to_seller_date='"+today_date+"'") sub_query="(select * from batches where client_id ="+client_id+" and product_category_id="+ product_category_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') diff --git a/app/views/batch_line_items/export_to_seller.csv.erb b/app/views/batch_line_items/export_to_seller.csv.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/batch_line_items/export_to_seller.html.erb b/app/views/batch_line_items/export_to_seller.html.erb new file mode 100644 index 0000000..0b1dd34 --- /dev/null +++ b/app/views/batch_line_items/export_to_seller.html.erb @@ -0,0 +1,173 @@ +
+ +
+
+ <%= form_tag export_seller_path(:format => :csv),:method => :post do%> +
+ + <%= select_tag "client", options_from_collection_for_select(@clients, "id", "name"), :class => 'form-control'%> +
+
+ + <%= select_tag "product_category", options_from_collection_for_select(@product_categories, "id", "name"), :class => 'form-control'%> +
+ + +
+
+ + <%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %> +
+
+
+ + <%= select_tag "seller", options_from_collection_for_select(@sellers, "id", "name"), :class => 'form-control'%> +
+ + + <% end %> +
+
+
+
+ +
+
+
+
+
+ Batch Line Item List +
+
+ <% flash.each do |key, value| %> + <% if key =='message' %> +
+ × + <%= value %> + <% end %> +
+ <% end %> +
+ + + Batch Line Items ( <%= @result_count %> ) + + + + + + + + + + + + <% @batchLineItems.each do |item| %> + + + + + + + + + + <% end %> + +
Serial NoAsset IdentityManufacture UIDBatch NoBarcodeCreated At Updated At
<%= item.serial_no rescue '' %><%= item.asset_identity rescue '' %><%= item.manufacture_uid rescue '' %><%= item.batch_name rescue '' %><%= item.barcode rescue '' %><%= item.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %>
+ <%=paginate @batchLineItems %> +
+ +
+
+ + \ No newline at end of file diff --git a/app/views/batch_line_items/index.html.erb b/app/views/batch_line_items/index.html.erb index 8631744..5c69fdf 100644 --- a/app/views/batch_line_items/index.html.erb +++ b/app/views/batch_line_items/index.html.erb @@ -22,10 +22,6 @@ <%= button_tag "Export csv?",:class =>'btn btn-primary btn-sm',:id =>"btnexport" %>

-
- - <%= select_tag "seller", options_from_collection_for_select(@sellers, "id", "name"), :class => 'form-control'%> -
<% end %> diff --git a/app/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb index 4c9bc46..0cda2b0 100644 --- a/app/views/layouts/_navigation.html.erb +++ b/app/views/layouts/_navigation.html.erb @@ -11,15 +11,20 @@ - + + +