class Api::BatchesController < ApplicationController skip_before_filter :verify_authenticity_token def create session_token=params[:session_token] check_member= Member.authenticate_session_token(session_token) if !check_member.nil? date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d") created_by = params[:created_by] order_ref = params[:order_ref] card_qty = params[:card_qty] user_id=check_member.user_id batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id) if !batch.nil? @out=true,batch.id else @out=false,'Error occurs in creating batch!' end else @out = false, "Sorry!Unauthorized user!" end end def batch_end session_token=params[:session_token] batch_id=params[:batch_id] is_authorize= Member.authenticate_session_token(session_token) if is_authorize batch=Batch.find_by_id(batch_id) if !batch.nil? batch.batch_end_time = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d") batch.batch_end = true if batch.save @out=true,"Batch end process is successfully finished." else @out=false,'Error occurs in batch end process!' end else @out=false,'Invalid batch no!' end else @out = false, "Sorry!Unauthorized user!" end end def resume_batch session_token=params[:session_token] batch_id=params[:batch_id] is_authorize= Member.authenticate_session_token(session_token) if is_authorize batch=Batch.find_by_id(batch_id) tickets=batch.tickets.count @out=true,tickets else @out = false, "Sorry!Unauthorized user!" end end def batch_progress_list created_by=params[:created_by] if !created_by.nil? batches = Batch.where('batch_end is null and created_by=?', created_by) puts batches if !batches.blank? @out=true,batches else @out = false, "No Batch" end else @out = false, "Sorry!Unauthorized user!" end end end