diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index dcf31a36..0da2bbf5 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -100,7 +100,7 @@ class HomeController < ApplicationController @sales = Sale.receipt_date_between(@from, @to).completed if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user.id) + if shift = ShiftSale.current_open_shift(current_user) @orders = @orders.where(shift_sale_id: shift.id) @sales = @sales.where(shift_sale_id: shift.id) end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 6f1e0826..a5b38db2 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -192,7 +192,7 @@ class Origami::PaymentsController < BaseOrigamiController end #card_balance amount for Paymal payment - card_balance_amount, transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) + card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 8b7bdf91..bbe2cf57 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -126,7 +126,7 @@ class Origami::ShiftsController < BaseOrigamiController if find_close_cashier_print[0][1].to_i > 0 - printer.print_close_cashier(print_settings,cashier_terminal,current_shop, @sale_items, @total_other_charges_info, current_shop,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) + printer.print_close_cashier(print_settings,cashier_terminal, @shift, @sale_items, @total_other_charges_info, current_shop,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) end end end diff --git a/app/controllers/settings/employees_controller.rb b/app/controllers/settings/employees_controller.rb index 448816f5..bcbec6ff 100755 --- a/app/controllers/settings/employees_controller.rb +++ b/app/controllers/settings/employees_controller.rb @@ -1,6 +1,6 @@ class Settings::EmployeesController < ApplicationController load_and_authorize_resource - before_action :set_employee, only: [:show, :edit, :update, :destroy] + before_action :set_employee, only: [:show, :edit, :update, :destroy, :change_auth_token] # GET /employees @@ -38,6 +38,13 @@ class Settings::EmployeesController < ApplicationController format.html { render :new } end end + end + + def change_app_token + @employee.app_token = @employee.generate_app_token #SecureRandom.hex(10) + @employee.save + flash[:notice] = 'Auth Token was successfully updated.' + redirect_to settings_employee_url(@employee) end # PATCH/PUT /employees/1 @@ -71,6 +78,6 @@ class Settings::EmployeesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def employee_params - params.require(:employee).permit(:name, :role, :is_active, :emp_id, :password,:order_queue_station_id, :image_path) + params.require(:employee).permit(:name, :role, :is_active, :emp_id, :password,:order_queue_station_id, :image_path, :app_id, :app_token) end end diff --git a/app/models/employee.rb b/app/models/employee.rb index 420491af..9d18c6c6 100755 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,5 +1,6 @@ class Employee < ApplicationRecord has_secure_password + # has_secure_token :auth_token has_many :commissioners has_many :shit_sales has_one :current_shift, -> { where.not(shift_started_at: nil).where(shift_closed_at: nil) },class_name: "ShiftSale" @@ -11,6 +12,7 @@ class Employee < ApplicationRecord validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true validates :password, numericality: true, length: {in: 3..9}, allow_blank: true + before_create :generate_app_id, :generate_app_token , if: Proc.new { self.role == "application" } # Employee Image Uploader mount_uploader :image_path, EmployeeImageUploader @@ -89,4 +91,18 @@ class Employee < ApplicationRecord return expiry_time end + + def generate_app_id + # return if self.role != 'application' + self.app_id = SecureRandom.urlsafe_base64(nil, false) + rescue ActiveRecord::RecordNotUnique + retry + end + + def generate_app_token + # return if self.role != 'application' + self.app_token = SecureRandom.hex(10) + rescue ActiveRecord::RecordNotUnique + retry + end end diff --git a/app/models/sale.rb b/app/models/sale.rb index da8db1a6..bf9fa2bd 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1498,7 +1498,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user.id) + if shift = ShiftSale.current_open_shift(current_user) query = query.where("shift_sale_id='#{shift.id}'") end @@ -1525,7 +1525,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user.id) + if shift = ShiftSale.current_open_shift(current_user) query = query.where("shift_sale_id='#{shift.id}'") end end diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 71f7398a..4cb3bde2 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -347,7 +347,7 @@ <% end %> <% end %> - <% if isMobile.include? "Mobile" %> + <% if isMobile.to_s.include? "Mobile" %>