diff --git a/app/controllers/api/authenticate_controller.rb b/app/controllers/api/authenticate_controller.rb index 410d4bd0..8fb10040 100755 --- a/app/controllers/api/authenticate_controller.rb +++ b/app/controllers/api/authenticate_controller.rb @@ -28,6 +28,7 @@ class Api::AuthenticateController < Api::ApiController shift = ShiftSale.current_open_shift(@employee.id) if !shift.nil? @status = true + @shift_id = shift.id # render json: JSON.generate({:status => true, :session_token => @employee.token_session, :name => @employee.name, :role => @employee.role}) else @status = true diff --git a/app/controllers/api/shifts_controller.rb b/app/controllers/api/shifts_controller.rb index d8de4e50..06b1e1a5 100644 --- a/app/controllers/api/shifts_controller.rb +++ b/app/controllers/api/shifts_controller.rb @@ -44,7 +44,7 @@ class Api::ShiftsController < Api::ApiController cashier_terminal.is_currently_login = 0 cashier_terminal.save - logout_status = Employee.logout(params[:session_token]) + logout_status = Employee.logout(current_token) if logout_status render json: JSON.generate({:status => true, :message => "Shift successfully close."}) else diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index 97d4081c..01ec45fb 100755 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -8,19 +8,20 @@ class SeedGenerator < ApplicationRecord end padding_len = 15 - prefix.length - generate_id = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0') - return generate_id + last_val = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0') + return last_val end # Generate Receipt No for number order (1,2,3) Don't touch def self.new_receipt_no - seed = SeedGenerator.find_by_model("sale") + seed = SeedGenerator.find_by_model("Sale") new_receipt_no = 0 if (seed.nil?) seed = SeedGenerator.new() - seed.model = "sale" + seed.model = "Sale" new_receipt_no = seed.next seed.save + else current_no = seed.next seed.next = seed.next @@ -63,16 +64,14 @@ class SeedGenerator < ApplicationRecord def self.execute_query(model) current = 0 nex = 0 - + sql = "INSERT INTO seed_generators (model, created_at, updated_at) VALUES('#{ model }', NOW(), NOW()) - ON DUPLICATE KEY UPDATE current = next, next = next + 1;" - - select_sql = "select * from seed_generators where model='#{model}';" + ON DUPLICATE KEY UPDATE current = current + 1, next = next + 1;" + select_sql = "select * from seed_generators where model='#{model}';" ActiveRecord::Base.connection.execute(sql); - select_result = ActiveRecord::Base.connection.execute(select_sql); - + select_result = ActiveRecord::Base.connection.execute(select_sql); select_result.each do |row| current = row [3] @@ -88,8 +87,8 @@ class SeedGenerator < ApplicationRecord update_sql = "UPDATE seed_generators set current = next, next = next + 1 WHERE model='#{model}';" select_sql = "select * from seed_generators where model='#{model}';" - update_result = ActiveRecord::Base.connection.execute(update_sql); + select_result = ActiveRecord::Base.connection.execute(select_sql); select_result.each do |row| diff --git a/app/views/api/authenticate/create_cashier.json.jbuilder b/app/views/api/authenticate/create_cashier.json.jbuilder index 5c47fb5b..3789b4fc 100644 --- a/app/views/api/authenticate/create_cashier.json.jbuilder +++ b/app/views/api/authenticate/create_cashier.json.jbuilder @@ -3,6 +3,9 @@ if @status == true json.session_token @employee.token_session json.name @employee.name json.role @employee.role + if @shift_id + json.shift_id @shift_id + end if @error_message json.error_message @error_message json.terminals do