diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss index 4ce4266..7ecca32 100644 --- a/app/assets/stylesheets/scaffolds.scss +++ b/app/assets/stylesheets/scaffolds.scss @@ -29,7 +29,7 @@ a { &:hover { color: #fff; - background-color: #000; + // background-color: #000; } } diff --git a/app/controllers/batch_line_items_controller.rb b/app/controllers/batch_line_items_controller.rb index 16bbd4d..a8253d2 100644 --- a/app/controllers/batch_line_items_controller.rb +++ b/app/controllers/batch_line_items_controller.rb @@ -2,7 +2,7 @@ class BatchLineItemsController < ApplicationController require "csv" skip_before_filter :verify_authenticity_token before_action :authenticate_member! - + require 'digest/md5' def index # user_id=current_member.user_id @@ -21,13 +21,16 @@ class BatchLineItemsController < ApplicationController 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 search - # user_id=current_member.user_id + # user_id=current_member.user_id + batch_list=params[:batch] client_id=params[:client] product_category_id=params[:product_category] @@ -39,12 +42,12 @@ class BatchLineItemsController < ApplicationController @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 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 end # if @batchLineItems.nil? @@ -96,13 +99,13 @@ class BatchLineItemsController < ApplicationController @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") + .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+"'") 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") + .select("*,product.product_type_id ,product.name,'' as secret_token,'' as location_name") end datestr= Time.now.strftime("%Y/%m/%d %H:%M:%S") @@ -112,4 +115,71 @@ class BatchLineItemsController < ApplicationController format.csv { send_data @batchLineItems.to_csv(client_id,location_code), filename: "#{filename}.csv" } end end + + def generate_cards + end + + def generate_card_account_items + # Generate Code + batch_id=params[:id] + client_id="" + qty = params[:qty] + total_count=0 + + # check_member= Member.authenticate_session_token(session_token) + # if !check_member.nil? + encrypt_key="" + asset_identity="" + + find_batch = Batch.find_by_id(batch_id) + if !find_batch.nil? + puts 'hkjfklasj' + card_type=find_batch.adult_or_child.upcase + product_category_id=find_batch.product_category_id + find_product_category=ProductCategory.find_by_id(product_category_id) + + if !find_product_category.nil? + product_type=find_product_category.product_type_id + + find_user=Client.find_by_id(find_batch.client_id) + if !find_user.nil? + encrypt_key=find_user.secrect_key + location_code=find_user.location_code + + client_id=find_user.id + if !encrypt_key.nil? + # Generate with qty + qty.to_i.times do |i| + serial_no=BatchLineItem.generate_serial_no(client_id.to_s) + + asset_identity=BatchLineItem.generate_account_no(location_code) + security_code=BatchLineItem.generate_security_code + out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,"","",security_code) + total_count+=1 + end + respond_to do |format| + format.html { redirect_to batch_url(batch_id), notice: 'Successfully generated.' } + format.json { head :no_content } + end + # Generate with qty + + else + @out=false,'Invalid User!' + end + else + @out=false,"Client doesn't exist!" + end + else + @out=false,"Product Category doesn't exist!" + end + else + @out=false,"Batch doesn't exist!" + end + # else + # @out=false,'Sorry!Unauthorized user!' + # end + # Generate Code + + + end end \ No newline at end of file diff --git a/app/controllers/batches_controller.rb b/app/controllers/batches_controller.rb index 198bd66..4ea6a0f 100644 --- a/app/controllers/batches_controller.rb +++ b/app/controllers/batches_controller.rb @@ -1,17 +1,75 @@ class BatchesController < ApplicationController skip_before_filter :verify_authenticity_token - before_action :authenticate_member! + # before_action :authenticate_member! + before_action :set_batch,:authenticate_member!, only: [:show, :edit, :update, :destroy] def index @product_category_id="" @clients=Client.all.order('id desc') @product_categories=ProductCategory.all.order('id desc') @batches=Batch.joins('inner join users on users.id=batches.user_id') .select('batches.*,users.name as user_name').order('batches.id desc').page(params[:page]) - @count = Batch.joins('inner join users on users.id=batches.user_id') + @count = Batch.joins('inner join users on users.id=batches.user_id') .select('batches.*').count end + def show + @batchLineItems=BatchLineItem.where("batch_id=?",params[:id]).page(params[:page]).per(10) + @result_count= @batchLineItems.total_count + end + + + def new + @batch = Batch.new + end + + def edit + end + + + def create + date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d") + order_ref = params[:batch][:order_ref] + puts order_ref + adult_or_child=params[:adult_or_child] + client_id=params[:client_id] + product_category_id=params[:product_category_id] + @batch = Batch.create_batch(date,order_ref,2,"adult_or_child",6,3) + puts @batch.order_ref + + respond_to do |format| + if @batch.save + format.html { redirect_to @batch, notice: 'Batch was successfully created.' } + format.json { render :show, status: :created, location: @batch } + else + format.html { render :new } + format.json { render json: @batch.errors, status: :unprocessable_entity } + end + end + end + + + def update + + respond_to do |format| + if @batch.update(batch_params) + format.html { redirect_to @batch, notice: 'Batch was successfully updated.' } + format.json { render :show, status: :ok, location: @batch } + else + format.html { render :edit } + format.json { render json: @batch.errors, status: :unprocessable_entity } + end + end + end + + def destroy + @batch.destroy + respond_to do |format| + format.html { redirect_to batches_url, notice: 'Batch was successfully destroyed.' } + format.json { head :no_content } + end + end + def search client_id=params[:client_id] product_category_id=params[:product_category_id] @@ -51,4 +109,14 @@ class BatchesController < ApplicationController end end + private + # Use callbacks to share common setup or constraints between actions. + def set_batch + @batch = Batch.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def batch_params + params.require(:batch).permit(:date,:user_id, :client_id, :order_ref,:batch_start,:batch_end,:exported_by,:qty_processing,:qty_success,:qty_fail,:batch_start_time,:batch_end_time,:export_count,:remark,:adult_or_child,:product_category_id) + end end \ No newline at end of file diff --git a/app/models/batch.rb b/app/models/batch.rb index 61da858..3123db7 100644 --- a/app/models/batch.rb +++ b/app/models/batch.rb @@ -1,5 +1,8 @@ class Batch < ApplicationRecord has_many :batch_line_item + belongs_to :client + belongs_to :product_category + belongs_to :user def self.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id) batch = Batch.new diff --git a/app/models/batch_line_item.rb b/app/models/batch_line_item.rb index d3bd64a..dac29e5 100644 --- a/app/models/batch_line_item.rb +++ b/app/models/batch_line_item.rb @@ -3,6 +3,7 @@ class BatchLineItem < ApplicationRecord attr_accessor :secret_token attr_accessor :location attr_accessor :product_type + require 'digest/md5' def self.generate_account_no(location_code) super_merchant = "101" @@ -21,6 +22,18 @@ class BatchLineItem < ApplicationRecord end return account_no end + def self.generate_security_code + + o = [('0'..'8')].map { |i| i.to_a }.flatten + security_code = (0...8).map { o[rand(o.length)] }.join + + find_account_no = BatchLineItem.find_by_security_code(security_code) + if !find_account_no.nil? + o = [('0'..'8')].map { |i| i.to_a }.flatten + security_code = (0...8).map { o[rand(o.length)] }.join + end + return security_code + end def self.generate_serial_no(client_id) find_lookup=Lookup.find_by_name('generate_serial_no') if !find_lookup.nil? @@ -54,16 +67,22 @@ class BatchLineItem < ApplicationRecord if !find_client.nil? encrypt_key=find_client.secrect_key end - attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location} + attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location security_code} CSV.generate(headers: true) do |csv| csv << attributes all.each do |encoder| - if encoder.product_type_id ==1 + if encoder.product_type_id ==1 + str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s else str="manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s end + security_code = encoder.security_code + digest = Digest::MD5.hexdigest(security_code) + puts 'digest............' + puts digest + encryptd_data=BatchLineItem.encrypted(str,encrypt_key) encoder.secret_token=encryptd_data encoder.location=location_code @@ -89,7 +108,7 @@ class BatchLineItem < ApplicationRecord return encrypted end - def self.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type) + def self.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type,security_code=nil) batchLineItem=BatchLineItem.new batchLineItem.asset_identity=asset_identity batchLineItem.serial_no=serial_no @@ -98,7 +117,10 @@ class BatchLineItem < ApplicationRecord batchLineItem.asset_type = card_type batchLineItem.encoded_at = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d") batchLineItem.verified_at =DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d") - + if !security_code.nil? + batchLineItem.security_code = security_code + puts 'security_code;fksdfklsdjfklsdfklsdjfklsdjfklsdjflskd' + end batch=Batch.find_by_id(batch_id) if batchLineItem.save diff --git a/app/views/.DS_Store b/app/views/.DS_Store index b617d82..cc360ab 100644 Binary files a/app/views/.DS_Store and b/app/views/.DS_Store differ diff --git a/app/views/batch_line_items/.DS_Store b/app/views/batch_line_items/.DS_Store new file mode 100644 index 0000000..ddfccdf Binary files /dev/null and b/app/views/batch_line_items/.DS_Store differ diff --git a/app/views/batch_line_items/_search.html.erb b/app/views/batch_line_items/_search.html.erb index 296b471..65fb91a 100644 --- a/app/views/batch_line_items/_search.html.erb +++ b/app/views/batch_line_items/_search.html.erb @@ -1,17 +1,19 @@ - + +
+ Batch Line Items ( <%= @result_count %> ) - + - - + - + + <% @batchLineItems.each do |item| %> diff --git a/app/views/batch_line_items/generate_cards.html.erb b/app/views/batch_line_items/generate_cards.html.erb new file mode 100644 index 0000000..fe68e9a --- /dev/null +++ b/app/views/batch_line_items/generate_cards.html.erb @@ -0,0 +1,22 @@ +
+ +
+
+
+ <%= form_tag generate_card_account_items_path,:method => :post do %> + <%= hidden_field_tag 'id', params[:id] %> + <%= label_tag(:qty, "Qty:") %> + <%= text_field_tag(:qty) %> + <%= submit_tag("Generate") %> + <% end %> +
+
+
+
+
+
+
\ 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 de30f4c..976d5df 100644 --- a/app/views/batch_line_items/index.html.erb +++ b/app/views/batch_line_items/index.html.erb @@ -28,49 +28,50 @@
-
-
- Batch Line Item List -
-
- <% flash.each do |key, value| %> - <% if key =='message' %> -
- × - <%= value %> - <% end %> -
- <% end %> -
-
Serail NoSerial No Asset Identity Manufacture UID Batch No Asset Type Created At Update At Updated At
<%= item.serial_no rescue '' %>
- - - - - - - - - - - - - <% @batchLineItems.each do |item| %> - - - - - - - - - - <% end %> - -
Serial NoAsset IdentityManufacture UIDBatch NoAsset TypeCreated At Update At
<%= item.serial_no rescue '' %><%= item.asset_identity rescue '' %><%= item.manufacture_uid rescue '' %><%= item.batch_name rescue '' %><%= item.asset_type 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 %> -
-
+
+
+ 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 NoAsset TypeCreated At Updated At
<%= item.serial_no rescue '' %><%= item.asset_identity rescue '' %><%= item.manufacture_uid rescue '' %><%= item.batch_name rescue '' %><%= item.asset_type 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 %> +
+