From adc3daaae8325abd9df50d37dccc7b9e0b18be1f Mon Sep 17 00:00:00 2001 From: Sunandar Date: Tue, 7 Mar 2017 15:27:36 +0630 Subject: [PATCH] edit --- .../api/batch_line_items_controller.rb | 31 ++++++++++--------- .../batch_line_items/register.json.jbuilder | 1 + 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/controllers/api/batch_line_items_controller.rb b/app/controllers/api/batch_line_items_controller.rb index c3d4c50..d9a619c 100644 --- a/app/controllers/api/batch_line_items_controller.rb +++ b/app/controllers/api/batch_line_items_controller.rb @@ -3,8 +3,8 @@ class Api::BatchLineItemsController < ApplicationController def register batch_id=params[:batch_id] session_token=params[:session_token] - manufacture_uid = params[:card_manufacture] - + manufacture_uid = params[:card_manufacture] + card_account_no=params[:card_account_no] client_id="" check_member= Member.authenticate_session_token(session_token) @@ -13,12 +13,12 @@ class Api::BatchLineItemsController < ApplicationController asset_identity="" find_batch = Batch.find_by_id(batch_id) - if !find_batch.nil? + 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? + if !find_product_category.nil? product_type=find_product_category.product_type_id find_user=Client.find_by_id(find_batch.client_id) @@ -27,10 +27,9 @@ class Api::BatchLineItemsController < ApplicationController location_code=find_user.location_code client_id=find_user.id - - if !encrypt_key.nil? - check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid) - if check_manufacture.nil? + if !encrypt_key.nil? + check_manufacture = BatchLineItem.find_by_manufacture_uid(manufacture_uid) + if check_manufacture.nil? serial_no=BatchLineItem.generate_serial_no(client_id.to_s) if product_type ==1 #CARD @@ -49,20 +48,24 @@ class Api::BatchLineItemsController < ApplicationController if check_asset.nil? @out=BatchLineItem.create_product(asset_identity,serial_no,batch_id,manufacture_uid,card_type) else - @out=false,'Asset Identity is already registered!' + @out=false,'Asset Identity is already registered!',nil end end else - @out=false,'Manufacture UID is already registered!' + if check_manufacture.asset_identity !=card_account_no + @out=false,"Error",check_manufacture + else + @out=false,'Manufacture UID is already registered!',nil + end end else - @out=false,'Invalid User!' + @out=false,'Invalid User!',nil end else - @out=false,"Client doesn't exist!" + @out=false,"Client doesn't exist!",nil end else - @out=false,"Product Category doesn't exist!" + @out=false,"Product Category doesn't exist!",nil end else @out=false,"Batch doesn't exist!" @@ -70,5 +73,5 @@ class Api::BatchLineItemsController < ApplicationController else @out=false,'Sorry!Unauthorized user!' end - end + end end \ No newline at end of file diff --git a/app/views/api/batch_line_items/register.json.jbuilder b/app/views/api/batch_line_items/register.json.jbuilder index 56c768d..92c3726 100644 --- a/app/views/api/batch_line_items/register.json.jbuilder +++ b/app/views/api/batch_line_items/register.json.jbuilder @@ -5,4 +5,5 @@ else json.set! :status, @out[0] json.set! :message,@out[1] + json.set! :data,@out[2] end \ No newline at end of file