diff --git a/app/controllers/api/batch_line_items_controller.rb b/app/controllers/api/batch_line_items_controller.rb index 0fcf4d6..ce2da50 100644 --- a/app/controllers/api/batch_line_items_controller.rb +++ b/app/controllers/api/batch_line_items_controller.rb @@ -73,5 +73,93 @@ class Api::BatchLineItemsController < ApplicationController else @out=false,'Sorry!Unauthorized user!' end - end + 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? + 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? + arr = Array.new + # 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) + item = out[2] + total_count+=1 + arr.push(item) + end + @out =true,'Success',arr + # 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 + def update_manufacture_uid + account_no = params[:account_no] + manufacture_uid = params[:manufacture_uid] + batch_line_item = BatchLineItem.find_by_asset_identity(account_no) + if !batch_line_item.nil? + puts 'he' + batch_line_item.manufacture_uid = manufacture_uid + batch_line_item.save + + @out = true,"success" + else + @out = false,"error" + end + end + + def get_item_by_batch + batch_id = params[:batch_id] + session_token = params[:session_token] + get_batch = BatchLineItem.where("batch_id=?",batch_id) + if !get_batch.nil? + @out = true,get_batch + else + @out = false,"no batch" + end + + end end \ No newline at end of file diff --git a/app/controllers/api/batches_controller.rb b/app/controllers/api/batches_controller.rb index 639436a..4270d3b 100644 --- a/app/controllers/api/batches_controller.rb +++ b/app/controllers/api/batches_controller.rb @@ -98,4 +98,6 @@ class Api::BatchesController < ApplicationController @out = false, "Sorry!Unauthorized user!" 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 a8253d2..06627ba 100644 --- a/app/controllers/batch_line_items_controller.rb +++ b/app/controllers/batch_line_items_controller.rb @@ -179,7 +179,7 @@ class BatchLineItemsController < ApplicationController # @out=false,'Sorry!Unauthorized user!' # end # Generate Code - - end + + end \ No newline at end of file diff --git a/app/views/api/.DS_Store b/app/views/api/.DS_Store index 0f8a739..b9277d7 100644 Binary files a/app/views/api/.DS_Store and b/app/views/api/.DS_Store differ diff --git a/app/views/api/batch_line_items/.DS_Store b/app/views/api/batch_line_items/.DS_Store new file mode 100644 index 0000000..f64e363 Binary files /dev/null and b/app/views/api/batch_line_items/.DS_Store differ diff --git a/app/views/api/batch_line_items/generate_card_account_items.jbuilder b/app/views/api/batch_line_items/generate_card_account_items.jbuilder new file mode 100644 index 0000000..a0f504c --- /dev/null +++ b/app/views/api/batch_line_items/generate_card_account_items.jbuilder @@ -0,0 +1,3 @@ +json.set! :status, @out[0] +json.set! :message, @out[1] +json.set! :line_item, @out[2] diff --git a/app/views/api/batch_line_items/get_item_by_batch.json.jbuilder b/app/views/api/batch_line_items/get_item_by_batch.json.jbuilder new file mode 100644 index 0000000..6f02a87 --- /dev/null +++ b/app/views/api/batch_line_items/get_item_by_batch.json.jbuilder @@ -0,0 +1,7 @@ + if @out[0] == true + json.set! :status, @out[0] + json.set! :data, @out[1] + else + json.set! :status, @out[0] + json.set! :message,@out[1] + end \ No newline at end of file diff --git a/app/views/api/batch_line_items/update_manufacture_uid.jbuilder b/app/views/api/batch_line_items/update_manufacture_uid.jbuilder new file mode 100644 index 0000000..486ae15 --- /dev/null +++ b/app/views/api/batch_line_items/update_manufacture_uid.jbuilder @@ -0,0 +1,2 @@ +json.set! :status, @out[0] +json.set! :message, @out[1] diff --git a/app/views/api/batches/.DS_Store b/app/views/api/batches/.DS_Store new file mode 100644 index 0000000..409bac7 Binary files /dev/null and b/app/views/api/batches/.DS_Store differ diff --git a/config/database.yml b/config/database.yml index ff4241d..4f48b33 100644 --- a/config/database.yml +++ b/config/database.yml @@ -7,7 +7,7 @@ default: &default adapter: postgresql - # host: http://192.168.1.81 + host: localhost pool: 5 timeout: 5000 encoding: utf8 @@ -15,8 +15,9 @@ default: &default development: <<: *default - database: nemo_production - username: mayzin + database: nemo_august + username: nda + password: 123 default: &default adapter: postgresql diff --git a/config/routes.rb b/config/routes.rb index a5b4663..2ce63c4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,11 +39,16 @@ Rails.application.routes.draw do post "batches/end" => "batches#batch_end" get "batches/resume_batch" =>"batches#resume_batch" get "batches/batch_progress_list" =>"batches#batch_progress_list" + get "get_item_by_batch" =>"batch_line_items#get_item_by_batch" #client get "clients" => 'clients#index' #product get "products" => "products#index" + + #batch_line_items + post "generate_card_account_items" =>"batch_line_items#generate_card_account_items" + post "update_manufacture_uid" => "batch_line_items#update_manufacture_uid" end end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 4ddc3a3..f80e7ec 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -14,6 +14,7 @@ ActiveRecord::Schema.define(version: 20180226100816) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + enable_extension "uuid-ossp" create_table "batch_line_items", force: :cascade do |t| t.integer "batch_id"