From 323dd43dd25b622a609e6ba7da3181aabda10e98 Mon Sep 17 00:00:00 2001 From: nandar Date: Mon, 20 Aug 2018 13:03:11 +0630 Subject: [PATCH] check duplicate record --- .../api/batch_line_items_controller.rb | 53 +++++++++++++------ .../update_barcode_and_account_no.jbuilder | 7 +++ .../batches/get_ticket_settings.json.jbuilder | 3 ++ config/routes.rb | 1 + db/migrate/20180810041316_create_setting.rb | 9 ++++ 5 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 app/views/api/batch_line_items/update_barcode_and_account_no.jbuilder create mode 100644 app/views/api/batches/get_ticket_settings.json.jbuilder create mode 100644 db/migrate/20180810041316_create_setting.rb diff --git a/app/controllers/api/batch_line_items_controller.rb b/app/controllers/api/batch_line_items_controller.rb index 9cd3a1d..fa98721 100644 --- a/app/controllers/api/batch_line_items_controller.rb +++ b/app/controllers/api/batch_line_items_controller.rb @@ -143,24 +143,29 @@ class Api::BatchLineItemsController < ApplicationController 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 - success_qty=batch.qty_success + if !batch_line_item.nil? + if batch_line_item.manufacture_uid.nil? + batch_line_item.manufacture_uid = manufacture_uid + batch_line_item.barcode = barcode + batch_line_item.save - batch.qty_processing=card_qty+1 - batch.qty_success=success_qty+1 - batch.save + # update batch + batch = Batch.find_by_id(batch_line_item.batch_id) + card_qty=batch.qty_processing.to_i + success_qty=batch.qty_success - @out = true,"success" - else - @out = false,"error" - end + batch.qty_processing=card_qty+1 + batch.qty_success=success_qty+1 + batch.save + + @out = true,"success" + else + @out = false,"Duplicate Record" + end + else + @out = false,"error" + end end def get_item_by_batch @@ -203,6 +208,24 @@ class Api::BatchLineItemsController < ApplicationController end end + + def update_barcode_and_account_no + session_token = params[:session_token] + barcode =params[:barcode] + user = Member.find_by_session_token(session_token) + if !user.nil? + user_id = user.user_id + find_barcode = BatchLineItem.find_by_barcode(barcode) + if !find_barcode.nil? + @out = true,find_barcode + else + @out = false,"Invalid" + end + else + @out = false, "Not Authorized" + end + end + # def check_ticket # session_token = params[:session_token] # barcode =params[:barcode] diff --git a/app/views/api/batch_line_items/update_barcode_and_account_no.jbuilder b/app/views/api/batch_line_items/update_barcode_and_account_no.jbuilder new file mode 100644 index 0000000..e22ddfc --- /dev/null +++ b/app/views/api/batch_line_items/update_barcode_and_account_no.jbuilder @@ -0,0 +1,7 @@ +if @out[0] == true + json.set! :status, @out[0] + json.set! :message, @out[1] +else + json.set! :status, @out[0] + json.set! :message, @out[1] +end diff --git a/app/views/api/batches/get_ticket_settings.json.jbuilder b/app/views/api/batches/get_ticket_settings.json.jbuilder new file mode 100644 index 0000000..89ac4de --- /dev/null +++ b/app/views/api/batches/get_ticket_settings.json.jbuilder @@ -0,0 +1,3 @@ + + json.set! :status, @out[0] + json.set! :message, @out[1] diff --git a/config/routes.rb b/config/routes.rb index 19aa96f..d10cc0b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,6 +53,7 @@ Rails.application.routes.draw do #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" + post "update_barcode_and_account_no" => "batch_line_items#update_barcode_and_account_no" post "code_activate" => "batch_line_items#code_activate" get "activated_list" => "batch_line_items#activated_list" get "seller_info" => "batch_line_items#seller_info" diff --git a/db/migrate/20180810041316_create_setting.rb b/db/migrate/20180810041316_create_setting.rb new file mode 100644 index 0000000..9304da0 --- /dev/null +++ b/db/migrate/20180810041316_create_setting.rb @@ -0,0 +1,9 @@ +class CreateSetting < ActiveRecord::Migration[5.0] + def change + create_table :settings do |t| + t.string :key + t.string :value + t.string :name + end + end +end