diff --git a/Gemfile b/Gemfile index 2a9087d..4f61880 100644 --- a/Gemfile +++ b/Gemfile @@ -20,9 +20,10 @@ gem 'unicorn' gem 'execjs' gem 'rack', '~> 2.0.1' gem 'therubyracer' -platform :ruby do - gem 'pg' -end +gem 'pg', '~> 0.20' +# platform :ruby do +# gem 'pg' +# end # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks diff --git a/Gemfile.lock b/Gemfile.lock index d9c7620..16b8529 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,78 +1,77 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.0.1) - actionpack (= 5.0.1) - nio4r (~> 1.2) + actioncable (5.0.7) + actionpack (= 5.0.7) + nio4r (>= 1.2, < 3.0) websocket-driver (~> 0.6.1) - actionmailer (5.0.1) - actionpack (= 5.0.1) - actionview (= 5.0.1) - activejob (= 5.0.1) + actionmailer (5.0.7) + actionpack (= 5.0.7) + actionview (= 5.0.7) + activejob (= 5.0.7) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.0.1) - actionview (= 5.0.1) - activesupport (= 5.0.1) + actionpack (5.0.7) + actionview (= 5.0.7) + activesupport (= 5.0.7) rack (~> 2.0) rack-test (~> 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.0.1) - activesupport (= 5.0.1) + actionview (5.0.7) + activesupport (= 5.0.7) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (5.0.1) - activesupport (= 5.0.1) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.0.7) + activesupport (= 5.0.7) globalid (>= 0.3.6) - activemodel (5.0.1) - activesupport (= 5.0.1) - activerecord (5.0.1) - activemodel (= 5.0.1) - activesupport (= 5.0.1) + activemodel (5.0.7) + activesupport (= 5.0.7) + activerecord (5.0.7) + activemodel (= 5.0.7) + activesupport (= 5.0.7) arel (~> 7.0) - activesupport (5.0.1) + activesupport (5.0.7) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - airbrussh (1.1.2) + airbrussh (1.3.0) sshkit (>= 1.6.1, != 1.7.0) arel (7.1.4) - bcrypt (3.1.11) + bcrypt (3.1.12) + bindex (0.5.0) builder (3.2.3) - byebug (9.0.6) - capistrano (3.7.2) + byebug (10.0.2) + capistrano (3.11.0) airbrussh (>= 1.0.0) - capistrano-harrow i18n rake (>= 10.0.0) sshkit (>= 1.9.0) - capistrano-bundler (1.2.0) + capistrano-bundler (1.3.0) capistrano (~> 3.1) sshkit (~> 1.2) - capistrano-harrow (0.5.3) - capistrano-rails (1.2.2) + capistrano-rails (1.4.0) capistrano (~> 3.1) capistrano-bundler (~> 1.1) - capistrano-rbenv (2.1.0) + capistrano-rbenv (2.1.3) capistrano (~> 3.1) sshkit (~> 1.3) - coffee-rails (4.2.1) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.2.x) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.4) - debug_inspector (0.0.2) - devise (4.2.0) + concurrent-ruby (1.0.5) + crass (1.0.4) + devise (4.4.3) bcrypt (~> 3.0) orm_adapter (~> 0.1) - railties (>= 4.1.0, < 5.1) + railties (>= 4.1.0, < 6.0) responders warden (~> 1.2.3) devise_uid (0.1.1) @@ -80,140 +79,145 @@ GEM railties (>= 3.0) erubis (2.7.0) execjs (2.7.0) - ffi (1.9.17) - globalid (0.3.7) - activesupport (>= 4.1.0) - i18n (0.8.1) - jbuilder (2.6.2) - activesupport (>= 3.0.0, < 5.1) - multi_json (~> 1.2) - jquery-rails (4.2.2) + ffi (1.9.25) + globalid (0.4.1) + activesupport (>= 4.2.0) + i18n (1.0.1) + concurrent-ruby (~> 1.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) + multi_json (>= 1.2) + jquery-rails (4.3.3) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - kaminari (1.0.1) + kaminari (1.1.1) activesupport (>= 4.1.0) - kaminari-actionview (= 1.0.1) - kaminari-activerecord (= 1.0.1) - kaminari-core (= 1.0.1) - kaminari-actionview (1.0.1) + kaminari-actionview (= 1.1.1) + kaminari-activerecord (= 1.1.1) + kaminari-core (= 1.1.1) + kaminari-actionview (1.1.1) actionview - kaminari-core (= 1.0.1) - kaminari-activerecord (1.0.1) + kaminari-core (= 1.1.1) + kaminari-activerecord (1.1.1) activerecord - kaminari-core (= 1.0.1) - kaminari-core (1.0.1) - kgio (2.11.0) - libv8 (3.16.14.17) + kaminari-core (= 1.1.1) + kaminari-core (1.1.1) + kgio (2.11.2) + libv8 (3.16.14.19) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - loofah (2.0.3) + loofah (2.2.2) + crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.6.4) - mime-types (>= 1.16, < 4) - method_source (0.8.2) - mime-types (3.1) - mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) - minitest (5.10.1) - multi_json (1.12.1) + mail (2.7.0) + mini_mime (>= 0.1.1) + method_source (0.9.0) + mini_mime (1.0.0) + mini_portile2 (2.3.0) + minitest (5.11.3) + multi_json (1.13.1) net-scp (1.2.1) net-ssh (>= 2.6.5) - net-ssh (4.1.0) - nio4r (1.2.1) - nokogiri (1.7.0.1) - mini_portile2 (~> 2.1.0) + net-ssh (5.0.2) + nio4r (2.3.1) + nokogiri (1.8.4) + mini_portile2 (~> 2.3.0) orm_adapter (0.5.0) - pg (0.19.0) - puma (3.7.1) - rack (2.0.1) + pg (0.21.0) + puma (3.12.0) + rack (2.0.5) rack-test (0.6.3) rack (>= 1.0) - rails (5.0.1) - actioncable (= 5.0.1) - actionmailer (= 5.0.1) - actionpack (= 5.0.1) - actionview (= 5.0.1) - activejob (= 5.0.1) - activemodel (= 5.0.1) - activerecord (= 5.0.1) - activesupport (= 5.0.1) - bundler (>= 1.3.0, < 2.0) - railties (= 5.0.1) + rails (5.0.7) + actioncable (= 5.0.7) + actionmailer (= 5.0.7) + actionpack (= 5.0.7) + actionview (= 5.0.7) + activejob (= 5.0.7) + activemodel (= 5.0.7) + activerecord (= 5.0.7) + activesupport (= 5.0.7) + bundler (>= 1.3.0) + railties (= 5.0.7) sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.2) - activesupport (>= 4.2.0, < 6.0) - nokogiri (~> 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.0.1) - actionpack (= 5.0.1) - activesupport (= 5.0.1) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.0.4) + loofah (~> 2.2, >= 2.2.2) + railties (5.0.7) + actionpack (= 5.0.7) + activesupport (= 5.0.7) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - raindrops (0.17.0) - rake (12.0.0) - rb-fsevent (0.9.8) - rb-inotify (0.9.8) - ffi (>= 0.5.0) + raindrops (0.19.0) + rake (12.3.1) + rb-fsevent (0.10.3) + rb-inotify (0.9.10) + ffi (>= 0.5.0, < 2) ref (2.0.0) - responders (2.3.0) - railties (>= 4.2.0, < 5.1) - sass (3.4.23) - sass-rails (5.0.6) + responders (2.4.0) + actionpack (>= 4.2.0, < 5.3) + railties (>= 4.2.0, < 5.3) + sass (3.5.7) + sass-listen (~> 4.0.0) + sass-listen (4.0.0) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + sass-rails (5.0.7) railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - simple_form (3.4.0) - actionpack (> 4, < 5.1) - activemodel (> 4, < 5.1) - spring (2.0.1) + simple_form (4.0.1) + actionpack (>= 5.0) + activemodel (>= 5.0) + spring (2.0.2) activesupport (>= 4.2) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (3.7.1) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) + sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sshkit (1.12.0) + sshkit (1.17.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) therubyracer (0.12.3) libv8 (~> 3.16.14.15) ref - thor (0.19.4) + thor (0.20.0) thread_safe (0.3.6) - tilt (2.0.6) + tilt (2.0.8) to_csv-rails (0.1.5) - turbolinks (5.0.1) - turbolinks-source (~> 5) - turbolinks-source (5.0.0) - tzinfo (1.2.2) + turbolinks (5.1.1) + turbolinks-source (~> 5.1) + turbolinks-source (5.1.0) + tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (3.0.4) + uglifier (4.1.15) execjs (>= 0.3.0, < 3) - unicorn (5.2.0) + unicorn (5.4.0) kgio (~> 2.6) raindrops (~> 0.7) warden (1.2.7) rack (>= 1.0) - web-console (3.4.0) + web-console (3.6.2) actionview (>= 5.0) activemodel (>= 5.0) - debug_inspector + bindex (>= 0.4.0) railties (>= 5.0) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) + websocket-extensions (0.1.3) PLATFORMS ruby @@ -233,7 +237,7 @@ DEPENDENCIES jquery-rails kaminari listen (~> 3.0.5) - pg + pg (~> 0.20) puma (~> 3.0) rack (~> 2.0.1) rails (~> 5.0.0, >= 5.0.0.1) @@ -250,4 +254,4 @@ DEPENDENCIES web-console BUNDLED WITH - 1.14.3 + 1.16.1 diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss index 7ecca32..4ce4266 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/api/batch_line_items_controller.rb b/app/controllers/api/batch_line_items_controller.rb index 947fd35..e321dec 100644 --- a/app/controllers/api/batch_line_items_controller.rb +++ b/app/controllers/api/batch_line_items_controller.rb @@ -140,14 +140,17 @@ class Api::BatchLineItemsController < ApplicationController # end # Generate Code end + def update_manufacture_uid account_no = params[:account_no] + barcode = params[:barcode] manufacture_uid = params[:manufacture_uid] batch_line_item = BatchLineItem.find_by_asset_identity(account_no) if !batch_line_item.nil? batch_line_item.manufacture_uid = manufacture_uid + batch_line_item.barcode = barcode batch_line_item.save - + # update batch batch = Batch.find_by_id(batch_line_item.batch_id) card_qty=batch.qty_processing.to_i @@ -172,6 +175,94 @@ class Api::BatchLineItemsController < ApplicationController else @out = false,"no batch" end + end + + def code_activate + session_token = params[:session_token] + barcode =params[:barcode] + find_seller = Member.find_by_session_token(session_token) + if !find_seller.nil? + seller_id = find_seller.user_id + find_barcode = BatchLineItem.find_by_barcode(barcode) + if !find_barcode.nil? + find_batch = Batch.find_by_id(find_barcode.batch_id) + if find_batch.export_to_seller_id == seller_id + if find_barcode.is_activated == false + find_barcode.is_activated = true + find_barcode.activated_date = DateTime.now + find_barcode.save + @out = true,"Success" + else + @out = false,"This is already activated!" + end + else + @out = false,"Not Authorized Seller" + end + else + @out = false,"Fail" + end + else + @out = false, "Not Authorized" + end + end + + # def check_ticket + # session_token = params[:session_token] + # barcode =params[:barcode] + # find_seller = Member.find_by_session_token(session_token) + # if !find_seller.nil? + # seller_id = find_seller.user_id + # find_barcode = BatchLineItem.find_by_barcode(barcode) + # if !find_barcode.nil? + # @out = true,"valid" + # end + # else + # @out = false, "Not Authorized" + # end + # end + + def activated_list + session_token = params[:session_token] + find_seller = Member.find_by_session_token(session_token) + if !find_seller.nil? + total_page_count= 0 + page_no = params[:page] + if !page_no.nil? && page_no != "" + offset = (page_no.to_i - 1 ) * 10 + else + offset = 0 + end + seller_id = find_seller.user_id + get_list = BatchLineItem.select("batch_line_items.id,batch_line_items.barcode,batch_line_items.activated_date").joins("join batches on batches.id=batch_line_items.batch_id").where("batch_line_items.is_activated=? and batches.export_to_seller_id=?",true,seller_id).limit(10).offset(offset) + + if get_list.count%10 > 0 + total_page_count = get_list.count/10 + 1 + else + total_page_count = get_list.count/10 + end + + if !get_list.nil? + @out = true, get_list, total_page_count + else + @out = false, "No data" + end + else + @out = false, "Not Authorized" + end end + + def seller_info + session_token = params[:session_token] + find_seller = Member.find_by_session_token(session_token) + if !find_seller.nil? + seller_id = find_seller.user_id + total_export_qty = BatchLineItem.select("count(batch_line_items.id)as count").joins("join batches on batches.id=batch_line_items.batch_id").where("batches.export_to_seller_id=?",seller_id) + total_activated_qty = BatchLineItem.select("count(batch_line_items.id)as count").joins("join batches on batches.id=batch_line_items.batch_id").where("batches.export_to_seller_id=? and batch_line_items.is_activated=?",seller_id,true) + @out = true,total_export_qty[0]["count"],total_activated_qty[0]["count"] + else + @out = false,"Not Authorized" + end + end + end \ No newline at end of file diff --git a/app/controllers/batch_line_items_controller.rb b/app/controllers/batch_line_items_controller.rb index 06627ba..575c083 100644 --- a/app/controllers/batch_line_items_controller.rb +++ b/app/controllers/batch_line_items_controller.rb @@ -9,16 +9,19 @@ class BatchLineItemsController < ApplicationController @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 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 @@ -76,6 +79,7 @@ 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 @@ -91,7 +95,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+"'") + 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+"'") sub_query= "(select * from batches where client_id="+client_id.to_s+" and product_category_id="+ product_category_id.to_s+")" @@ -101,7 +105,7 @@ 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+"'") + Batch.where("client_id=? ",client_id).update_all("export_count = export_count + 1,exported_by='"+exported_by+"',export_to_seller_id='"+seller_id+"'") 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/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1f20112..2cdc0f6 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -100,6 +100,6 @@ class UsersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def user_params - params.require(:user).permit(:name, :nrc, :email, :phone, :address,:is_active) + params.require(:user).permit(:name, :nrc, :email, :phone, :address,:is_active,:user_type) end end diff --git a/app/models/batch_line_item.rb b/app/models/batch_line_item.rb index 3a658c6..08c27f4 100644 --- a/app/models/batch_line_item.rb +++ b/app/models/batch_line_item.rb @@ -72,20 +72,21 @@ 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 security_code} + attributes = %w{serial_no asset_identity batch_id manufacture_uid asset_type secret_token location} CSV.generate(headers: true) do |csv| csv << attributes - all.each do |encoder| + all.each do |encoder| 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 + elsif encoder.product_type_id == 3 + + attributes = attributes+ %w{security_code} str="account_no="+encoder.asset_identity.to_s+"&manufacture_uid="+encoder.manufacture_uid.to_s+"&serial_no="+encoder.serial_no.to_s+"&security_code="+encoder.security_code.to_s - else - str="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) encryptd_data=BatchLineItem.encrypted(str,encrypt_key) encoder.secret_token=encryptd_data diff --git a/app/models/member.rb b/app/models/member.rb index b1034a7..2e9adbb 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -6,6 +6,7 @@ class Member < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable,:uid, :confirmable, :lockable + def self.authenticate_session_token(token) if token.nil? || token.blank? || token.to_s == ' ' return false diff --git a/app/views/batch_line_items/index.html.erb b/app/views/batch_line_items/index.html.erb index 976d5df..8631744 100644 --- a/app/views/batch_line_items/index.html.erb +++ b/app/views/batch_line_items/index.html.erb @@ -14,11 +14,20 @@ <%= 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 %>
@@ -50,7 +59,7 @@ Asset Identity Manufacture UID Batch No - Asset Type + Barcode Created At Updated At @@ -62,7 +71,7 @@ <%= item.asset_identity rescue '' %> <%= item.manufacture_uid rescue '' %> <%= item.batch_name rescue '' %> - <%= item.asset_type 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 '' %> diff --git a/app/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb index 28dc7cb..4c9bc46 100644 --- a/app/views/layouts/_navigation.html.erb +++ b/app/views/layouts/_navigation.html.erb @@ -19,7 +19,7 @@ +