check duplicate batch no

This commit is contained in:
Sunandar
2017-02-24 14:19:25 +06:30
parent 93085271a9
commit c784057d1b
2 changed files with 23 additions and 15 deletions

View File

@@ -6,27 +6,33 @@ class Api::BatchesController < ApplicationController
if !check_member.nil? if !check_member.nil?
date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d") date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
order_ref = params[:order_ref] order_ref = params[:order_ref]
order_ref=order_ref.delete(' ')
adult_or_child=params[:adult_or_child] adult_or_child=params[:adult_or_child]
client_id=params[:client_id] client_id=params[:client_id]
product_category_id=params[:product_category_id] product_category_id=params[:product_category_id]
find_client=Client.find_by_id(client_id) find_batch=Batch.find_by_order_ref(order_ref)
if !find_client.nil? if find_batch.nil?
find_product_category=ProductCategory.find_by_id(product_category_id) find_client=Client.find_by_id(client_id)
if !find_product_category.nil? if !find_client.nil?
user_id=check_member.user_id find_product_category=ProductCategory.find_by_id(product_category_id)
if !find_product_category.nil?
user_id=check_member.user_id
batch = Batch.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id) batch = Batch.create_batch(date,order_ref,user_id,adult_or_child,client_id,product_category_id)
if !batch.nil? if !batch.nil?
@out=true,batch.id @out=true,batch.id
else else
@out=false,'Error occurs in creating batch!' @out=false,'Error occurs in creating batch!'
end end
else
@out=false,'Product Category does not exists!'
end
else else
@out=false,'Product Category does not exists!' @out = false, "Client does not exist!"
end end
else else
@out = false, "Client does not exist!" @out=false,order_ref.to_s+ " is already taken!"
end end
else else
@out = false, "Sorry!Unauthorized user!" @out = false, "Sorry!Unauthorized user!"

View File

@@ -26,9 +26,11 @@ namespace :setup do
task :set_product_category, [:name,:product_type] => :environment do |t, args| task :set_product_category, [:name,:product_type] => :environment do |t, args|
find_product_type=ProductType.find_by_id(args.product_type) find_product_type=ProductType.find_by_id(args.product_type)
if !find_product_type.nil? if !find_product_type.nil?
find_product_category=ProductCategory.find_by_name(args.name) find_product_category=ProductCategory.find_by_name(args.name)
if find_product_category.nil? if find_product_category.nil?
product_category=ProductCategory.new product_category=ProductCategory.new
product_category.name=args.name product_category.name=args.name
product_category.product_type_id=args.product_type product_category.product_type_id=args.product_type