diff --git a/Gemfile.lock b/Gemfile.lock index 073bf04c..3a70c5bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -375,7 +375,5 @@ DEPENDENCIES web-console (>= 3.3.0) whenever -RUBY VERSION - ruby 2.6.3p62 BUNDLED WITH 2.0.2 diff --git a/app/controllers/api/authenticate_controller.rb b/app/controllers/api/authenticate_controller.rb index aad8607c..f95151e0 100755 --- a/app/controllers/api/authenticate_controller.rb +++ b/app/controllers/api/authenticate_controller.rb @@ -25,7 +25,7 @@ class Api::AuthenticateController < Api::ApiController @employee = Employee.login(emp_id, password) if @employee && @employee.role == "cashier" if @employee.is_active - shift = ShiftSale.current_open_shift(@employee.id) + shift = ShiftSale.current_open_shift(@employee) if !shift.nil? @status = true @shift_id = shift.id diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 7a00666a..4c9d5a79 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -6,7 +6,7 @@ class Api::BillController < Api::ApiController @status = false @error_message = "Order ID or Booking ID is require to request for a bill." # if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id) - if !ShiftSale.current_shift.nil? + if !ShiftSale.current_shift(@shop.shop_code).nil? #create Bill by Booking ID table = 0 if (params[:booking_id]) @@ -161,7 +161,7 @@ class Api::BillController < Api::ApiController @status, @booking = @order.generate if @status && @booking - shift = ShiftSale.current_open_shift(current_login_employee.id) + shift = ShiftSale.current_open_shift(current_login_employee) if !shift.nil? cashier = Employee.find(shift.employee_id) if (@booking.booking_id) diff --git a/app/controllers/api/call_waiters_controller.rb b/app/controllers/api/call_waiters_controller.rb index 066fa30c..08edc944 100644 --- a/app/controllers/api/call_waiters_controller.rb +++ b/app/controllers/api/call_waiters_controller.rb @@ -18,17 +18,17 @@ class Api::CallWaitersController < ActionController::API # CallWaiterJob.perform_later(@table,@time) if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain - else + else from = "" - end - ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time,from: from, shift_ids: shift_ids + end + ActionCable.server.broadcast "call_waiter_channel",table: @table,time:@time,from: from, shift_ids: shift_ids # get printer info - @shop = Shop.first - unique_code = "CallWaiterPdf" + # @shop = Shop.first + unique_code = "CallWaiterPdf" print_settings = PrintSetting.find_by_unique_code(unique_code) - printer = Printer::ReceiptPrinter.new(print_settings) + printer = Printer::ReceiptPrinter.new(print_settings) printer.print_call_waiter(print_settings,@table,@time,@shop) end - + end diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 77e6f3fd..411fca2c 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -46,7 +46,7 @@ class Api::OrdersController < Api::ApiController @tax_profile = TaxProfile.where("lower(group_type)='cashier'") # end - @shop = Shop.first + # @shop = Shop.first puts "Hello world" puts @shop.to_json return @shop.to_json diff --git a/app/controllers/api/payment/mobilepayment_controller.rb b/app/controllers/api/payment/mobilepayment_controller.rb index 220cbbeb..1dd984c4 100644 --- a/app/controllers/api/payment/mobilepayment_controller.rb +++ b/app/controllers/api/payment/mobilepayment_controller.rb @@ -14,11 +14,11 @@ class Api::Payment::MobilepaymentController < Api::ApiController saleObj = Sale.find(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id) - shop_detail = Shop.first + # shop_detail = Shop.first # rounding adjustment if !path.include? ("credit_payment") - if shop_detail.is_rounding_adj + if @shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even diff --git a/app/controllers/api/survey_controller.rb b/app/controllers/api/survey_controller.rb index e4fffbaf..1c5e81a2 100644 --- a/app/controllers/api/survey_controller.rb +++ b/app/controllers/api/survey_controller.rb @@ -19,14 +19,15 @@ class Api::SurveyController < Api::ApiController # shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) # puts params.to_json # set cashier - open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") - current_shift = ShiftSale.current_shift + open_cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''") + current_shift = ShiftSale.current_shift(@shop.shop_code) + current_shift_user =Employee.find_by_id(current_shift.employee_id) if open_cashier.count>0 - shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0].id) + shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0]) else - shift_by_terminal = ShiftSale.current_open_shift(current_shift.employee_id) + shift_by_terminal = ShiftSale.current_open_shift(current_shift_user) end - + if params[:survey][:id]>0 survey = Survey.find(params[:survey][:id]) else @@ -50,8 +51,8 @@ class Api::SurveyController < Api::ApiController # private # def survey_params - # params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, + # params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, # :dining_name,:created_by,:total_customer,:total_amount) # end -end \ No newline at end of file +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f1d5f79a..c4023b49 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,10 +1,10 @@ class ApplicationController < ActionController::Base include LoginVerification - + #before_action :check_installation protect_from_forgery with: :exception - helper_method :shop_detail, :order_reservation, :bank_integration + helper_method :shop_detail,:order_reservation, :bank_integration # lookup domain for db from provision # before_action :set_locale # helper_method :current_company,:current_login_employee,:current_user @@ -17,7 +17,5 @@ class ApplicationController < ActionController::Base flash[:warning] = exception.message redirect_to root_path end + end - - - diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index dc93b2de..3c362207 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -5,7 +5,7 @@ class BaseOrigamiController < ActionController::Base before_action :check_user #before_action :check_installation - protect_from_forgery with: :exception + protect_from_forgery with: :exception helper_method :current_token @@ -15,16 +15,16 @@ class BaseOrigamiController < ActionController::Base redirect_to origami_dashboard_path end - def check_user - if check_mobile + def check_user + if check_mobile if current_user.nil? return render status: 401, json: { - message: "User using other device!" + message: "User using other device!" }.to_json end - else + else if current_user.nil? - redirect_to root_path + redirect_to root_path end end end @@ -33,21 +33,22 @@ class BaseOrigamiController < ActionController::Base # CheckinJob.set(wait: 1.minute).perform_later() # end + ##already in LoginVerification # Get current Cashier - def get_cashier - @cashier = Employee.where("role = 'cashier' AND token_session <> ''") - end + # def get_cashier + # @cashier = Employee.where("role = 'cashier' AND token_session <> ''") + # end #check webview def check_mobile status = false - authenticate_with_http_token do |token, options| + authenticate_with_http_token do |token, options| if token session[:webview] = true session[:session_token] = token - end + end end - + if session[:webview] && request.user_agent =~ /android|blackberry|iphone|ipad|ipod|iemobile|mobile|webos/i status = true end diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index 8eb719cb..5ae86b18 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -1,6 +1,5 @@ module LoginVerification extend ActiveSupport::Concern - included do before_action :authenticate_session_token helper_method :current_company,:current_shop, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :shop_detail @@ -19,34 +18,38 @@ module LoginVerification def current_shop begin - return Shop.first + shop_code ='263' + @shop =Shop.find_by_shop_code(shop_code) + return @shop rescue return nil end end def current_login_employee - @employee = Employee.find_by_token_session(session[:session_token]) + @employee = Employee.find_by_token_session_and_shop_code(session[:session_token],@shop.shop_code) end def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + @current_user ||= Employee.find_by_token_session_and_shop_code(session[:session_token],@shop.shop_code) if session[:session_token] end # Get current Cashiers def get_cashier - @cashier = Employee.where("role = 'cashier' AND token_session <> ''") + @cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''") end #Shop Name in Navbor def shop_detail - @shop = Shop.first + shop_code ='263' + @shop = Shop.find_by_shop_code(shop_code) + return @shop end #check order reservation used def order_reservation - order_reserve = Lookup.collection_of('order_reservation') + order_reserve = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('order_reservation') status = false if !order_reserve.empty? order_reserve.each do |order| @@ -62,7 +65,7 @@ module LoginVerification #check bank integration used def bank_integration - bank_integration = Lookup.collection_of('bank_integration') + bank_integration = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('bank_integration') status = false if !bank_integration.empty? bank_integration.each do |bank| @@ -78,17 +81,17 @@ module LoginVerification protected # Authenticate the user with token based authentication - def authenticate - authenticate_session_token || render_unauthorized + def authenticate + authenticate_session_token || render_unauthorized end - def authenticate_session_token + def authenticate_session_token token = session[:session_token] if (token) #@current_user = User.find_by(api_key: token) #Rails.logger.debug "token - " + token.to_s - @user = Employee.authenticate_by_token(token) + @user =Employee.authenticate_by_token(token,current_shop) if @user return true #Maybe log - login? diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 2f846601..936ef7a2 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -21,7 +21,7 @@ class Crm::CustomersController < BaseCrmController # paymal_customer = Customer.search_paypar_account_no(filter) # search account no from paypar if type == "card" - + response = Customer.search_paypar_account_no(filter) if !@crm_customers.present? if response["status"] == true @@ -38,6 +38,7 @@ class Crm::CustomersController < BaseCrmController @crm_customers.membership_type = response["customer_data"]["member_group_id"] @crm_customers.customer_type = "Dinein" @crm_customers.tax_profiles = ["1", "2"] + @crm_customers.shop_code = @shop.shop_code @crm_customers.save @crm_customers = Customer.search(filter) flash[:member_notice]='Customer was successfully created.' @@ -70,7 +71,7 @@ class Crm::CustomersController < BaseCrmController else flash[:member_error]="Need to press sync button " end - + end end end @@ -95,7 +96,7 @@ class Crm::CustomersController < BaseCrmController lookup_customer = Lookup.collection_of('customer_settings') if !lookup_customer.empty? lookup_customer.each do |create_setting| - if create_setting[0].downcase == "create" + if create_setting[0].downcase == "create" if create_setting[1] == '0' && current_login_employee.role == 'cashier' @create_flag = false end @@ -134,8 +135,8 @@ class Crm::CustomersController < BaseCrmController params[:type] = nil params[:customer_id] = params[:id] - @credit_sales = SalePayment.get_credit_sales(params) - + @credit_sales = SalePayment.get_credit_sales(params,@shop.shop_code) + #get customer amount @customer = Customer.find(params[:id]) @response = Customer.get_membership_transactions(@customer) @@ -159,7 +160,7 @@ class Crm::CustomersController < BaseCrmController @customer = Customer.find(params[:id]) end def sync - @customer = Customer.find(params[:id]) + @customer = Customer.find(params[:id]) respond_to do |format| name = @customer.name phone = @customer.contact_no @@ -170,8 +171,8 @@ class Crm::CustomersController < BaseCrmController card_no = @customer.card_no paypar_account_no = @customer.paypar_account_no id = @crm_customer.membership_id - member_group_id = @customer.membership_type - if !id.present? && !member_group_id.nil? + member_group_id = @customer.membership_type + if !id.present? && !member_group_id.nil? membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("create_membership_customer") merchant_uid = memberaction.merchant_account_id.to_s @@ -179,7 +180,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -221,7 +222,7 @@ class Crm::CustomersController < BaseCrmController Rails.logger.debug "--------Sync Member response -------" Rails.logger.debug response.to_json if response["status"] == true - + status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) format.html { redirect_to crm_customers_path } @@ -252,14 +253,14 @@ class Crm::CustomersController < BaseCrmController end # POST /crm/customers # POST /crm/customers.json - def create - # Remove "" default first - params[:customer][:tax_profiles].delete_at(0) + def create + # Remove "" default first + params[:customer][:tax_profiles].delete_at(0) @checked_contact = Customer.find_by_contact_no(customer_params[:contact_no]) if @checked_contact.nil? respond_to do |format| @crm_customers = Customer.new(customer_params) - + @crm_customers.shop_code = @shop.shop_code if @crm_customers.save # update tax profile customer = Customer.find(@crm_customers.customer_id) @@ -272,7 +273,7 @@ class Crm::CustomersController < BaseCrmController nrc = customer_params[:nrc_no] card_no = customer_params[:card_no] paypar_account_no = customer_params[:paypar_account_no] - member_group_id = params[:member_group_id] + member_group_id = params[:member_group_id] if member_group_id.present? membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -282,7 +283,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -333,7 +334,7 @@ class Crm::CustomersController < BaseCrmController end # format.json { render :index, status: :created, location: @crm_customers } else - customer = Customer.find(@crm_customers.customer_id) + customer = Customer.find(@crm_customers.customer_id) # Check membership id and bind to user if response["membership_id"] != nil @@ -399,7 +400,7 @@ class Crm::CustomersController < BaseCrmController # PATCH/PUT /crm/customers/1 # PATCH/PUT /crm/customers/1.json def update - # Remove "" default first + # Remove "" default first params[:customer][:tax_profiles].delete_at(0) @checked_contact = nil @existed_contact = Customer.find_by_customer_id_and_contact_no(customer_params[:id], customer_params[:contact_no]) @@ -409,7 +410,7 @@ class Crm::CustomersController < BaseCrmController if !@existed_contact.nil? || @checked_contact.nil? respond_to do |format| if @crm_customer.update(customer_params) - # update tax profile + # update tax profile @crm_customer.update_attributes(tax_profiles: params[:customer][:tax_profiles]) name = customer_params[:name] phone = customer_params[:contact_no] @@ -420,7 +421,7 @@ class Crm::CustomersController < BaseCrmController card_no = customer_params[:card_no] paypar_account_no = customer_params[:paypar_account_no] id = @crm_customer.membership_id - member_group_id = params[:member_group_id] + member_group_id = params[:member_group_id] if !id.present? && !member_group_id.nil? membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -430,7 +431,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -471,7 +472,7 @@ class Crm::CustomersController < BaseCrmController Rails.logger.debug "--------Update Member response -------" Rails.logger.debug response.to_json if response["status"] == true - + status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) format.html { redirect_to crm_customers_path } @@ -496,7 +497,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -601,7 +602,7 @@ class Crm::CustomersController < BaseCrmController flash[:member_notice]='Membership was successfully updated' end end - + end @@ -617,6 +618,5 @@ class Crm::CustomersController < BaseCrmController params.require(:customer).permit(:id, :name, :company, :contact_no, :email, :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type, :image_path) end - -end +end diff --git a/app/controllers/crm/dining_queues_controller.rb b/app/controllers/crm/dining_queues_controller.rb index 38b7ea0b..28da784a 100755 --- a/app/controllers/crm/dining_queues_controller.rb +++ b/app/controllers/crm/dining_queues_controller.rb @@ -1,22 +1,22 @@ class Crm::DiningQueuesController < BaseCrmController load_and_authorize_resource before_action :set_dining_queue, only: [:show, :edit, :update, :destroy] - + # GET /crm/dining_queues # GET /crm/dining_queues.json def index today = DateTime.now.strftime('%Y-%m-%d') - @dining_queues = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status is NULL ", today).order("queue_no asc") - @complete_queue = DiningQueue.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status = 'Assign' ", today).order("queue_no asc") - + @dining_queues = DiningQueue.where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status is NULL ", today).order("queue_no asc") + @complete_queue = DiningQueue.where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(created_at,'%Y-%m-%d') = ? and status = 'Assign' ", today).order("queue_no asc") + if params[:term] @customer = Customer.order(:name).where('lower(name) LIKE ?', "%#{params[:term].downcase}%") else @customer = Customer.all end - respond_to do |format| - format.html + respond_to do |format| + format.html format.json { render :json => @customer.to_json } end end @@ -41,16 +41,16 @@ class Crm::DiningQueuesController < BaseCrmController def create puts dining_queue_params @dining_queue = DiningQueue.new(dining_queue_params) - + @dining_queue.shop_code = @shop.shop_code respond_to do |format| if @dining_queue.save - # unique_code = "QueueNoPdf" - + # unique_code = "QueueNoPdf" + # # get printer info # print_settings = PrintSetting.find_by_unique_code(unique_code) - # printer = Printer::ReceiptPrinter.new(print_settings) + # printer = Printer::ReceiptPrinter.new(print_settings) # printer.print_queue_no(print_settings,@dining_queue) format.html { redirect_to crm_dining_queues_path, notice: 'Queue was successfully created.' } @@ -88,7 +88,7 @@ class Crm::DiningQueuesController < BaseCrmController def assign @queue = DiningQueue.find(params[:id]) - @tables = DiningFacility.where("status = 'available' ") + @tables = DiningFacility.where("status = 'available' and shop_code='#{@shop.shop_code}' and type!='HotelRoom'") respond_to do |format| format.html # index.html.erb end @@ -105,42 +105,46 @@ class Crm::DiningQueuesController < BaseCrmController # type = "RoomBooking" # end - booking = Booking.create({:dining_facility_id => params[:table_id],:type => type, - :checkin_at => Time.now.utc,:customer_id => queue.customer_id,:booking_status => "assign" }) + booking = Booking.create({:dining_facility_id => params[:table_id], + :type => type, + :checkin_at => Time.now.utc, + :customer_id => queue.customer_id, + :booking_status => "assign", + :shop_code => @shop.shop_code}) booking.save! status = queue.update_attributes(dining_facility_id: table_id,status:"Assign") # status = DiningFacility.find(table_id).update_attributes(status: "occupied") - + if status == true render json: JSON.generate({:status => true , notice: 'Dining queue was successfully assigned .'}) else render json: JSON.generate({:status => false, :error_message => "Record not found"}) - end + end end def cancel_queue queue = DiningQueue.find(params[:id]) status = queue.update_attributes(id: params[:id],status:"Cancel") - + if status == true render json: JSON.generate({:status => true , notice: 'Dining queue was successfully canceled .'}) else render json: JSON.generate({:status => false, :error_message => "Record not found"}) - end + end end private # Use callbacks to share common setup or constraints between actions. def set_dining_queue - @dining_queue = DiningQueue.find(params[:id]) + @dining_queue = DiningQueue.find_by_id_and_shop_code(params[:id],@shop.shop_code) end # Never trust parameters from the scary internet, only allow the white list through. def dining_queue_params params.require(:dining_queue).permit(:customer_id, :name, :contact_no, :queue_no,:status,:seater,:remark) end - + end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index eaab0511..32d47ce3 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -3,7 +3,7 @@ class HomeController < ApplicationController # skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy] include PrecisionHelper before_action :check_user, only: :dashboard - + # Special check for only dashboard def check_user if current_user.nil? @@ -11,14 +11,16 @@ class HomeController < ApplicationController end end - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] - end + ##already check current_user with helper_method + # def current_user + # @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + # end def index # @employees = Employee.all_emp_except_waiter.order("name asc") - @employees = Employee.all.where("is_active = true").order("name asc") - @roles = Employee.distinct.pluck(:role) + @employees = Employee.all.where("shop_code='#{current_shop.shop_code}' and is_active = true").order("name asc") + @roles = Employee.where("shop_code='#{current_shop.shop_code}'").distinct.pluck(:role) + # byebug # @roles = Lookup.collection_of("employee_roles") @login_form = LoginForm.new() @@ -35,7 +37,7 @@ class HomeController < ApplicationController @login_form = LoginForm.new() @login_form.emp_id = params[:emp_id] @login_form.password = params[:login_form][:password] - @employee = Employee.login(@login_form.emp_id, @login_form.password) + @employee = Employee.login(current_shop,@login_form.emp_id, @login_form.password) if @employee != nil session[:session_token] = @employee.token_session @@ -50,7 +52,7 @@ class HomeController < ApplicationController @login_form = LoginForm.new() @login_form.emp_id = params[:login_form][:emp_id] @login_form.password = params[:login_form][:password] - @employee = Employee.login(@login_form.emp_id, @login_form.password) + @employee = Employee.login(current_shop,@login_form.emp_id, @login_form.password) if @employee != nil if @employee.is_active @@ -90,31 +92,30 @@ class HomeController < ApplicationController def dashboard @from, @to, @from_time, @to_time = get_date_range_from_params - @shop = Shop.first today = DateTime.now.strftime('%Y-%m-%d') if !@from.nil? && !@to.nil? if !@from_time.nil? && @to_time.nil? - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() + @orders = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() else - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + @orders = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() end else - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() + @orders = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() end if !@from.nil? && !@to.nil? if !@from_time.nil? && @to_time.nil? - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() + @sales = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() else - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + @sales = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() end else - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() + @sales = Sale::where("shop_code='#{@shop.shop_code}' and payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() end - @top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top").sum('i.qty') - @bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom").sum('i.qty') - @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total) + @top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top",@shop).sum('i.qty') + @bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom",@shop).sum('i.qty') + @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time,@shop).sum(:grand_total) - employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time) + employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time,@shop) @employee_sales = [] if !employee_sales.nil? employee_sales.each do |emp| @@ -126,43 +127,43 @@ class HomeController < ApplicationController end end end - @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance) + @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time,@shop).sum(:balance) - @total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time) - @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time) - @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time) + @total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time,@shop) + @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time,@shop) + @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time,@shop) @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to,@from_time,@to_time) + @total_payment_methods = Sale.total_payment_methods(@shop,today,current_user,@from,@to,@from_time,@to_time) if !@total_payment_methods.nil? @total_payment_methods.each do |payment| if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" - pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time) + pay = Sale.payment_sale(@shop,'card', today, current_user,@from,@to,@from_time,@to_time) @sale_data.push({'card' => pay.payment_amount}) else - pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to,@from_time,@to_time) + pay = Sale.payment_sale(@shop,payment.payment_method, today, current_user,@from,@to,@from_time,@to_time) @sale_data.push({payment.payment_method => pay.payment_amount}) end end end - @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time) - @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time) + @summ_sale = Sale.summary_sale_receipt(@shop,today,current_user,@from,@to,@from_time,@to_time) + @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time) - @total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time) - @total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time) + @total_order = Sale.total_order(@shop,today,current_user,@from,@to,@from_time,@to_time) + @total_accounts = Sale.total_account(@shop,today,current_user,@from,@to,@from_time,@to_time) @account_data = Array.new if !@total_accounts.nil? @total_accounts.each do |account| - acc = Sale.account_data(account.account_id, today,current_user,@from,@to,@from_time,@to_time) + acc = Sale.account_data(@shop,account.account_id, today,current_user,@from,@to,@from_time,@to_time) if !acc.nil? @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end end end - @top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time) - @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time) + @top_items = Sale.top_items(@shop,today,current_user,@from,@to,@from_time,@to_time) + @total_foc_items = Sale.total_foc_items(@shop,today,current_user,@from,@to,@from_time,@to_time) # get printer info # @print_settings = get_precision_delimiter @@ -170,7 +171,7 @@ class HomeController < ApplicationController def destroy # clear in employee session - Employee.logout(session[:session_token]) + Employee.logout(@shop,session[:session_token]) session[:session_token] = nil # redirect_to root_path render :json => {:status=> "Success", :url => root_path }.to_json @@ -195,7 +196,7 @@ class HomeController < ApplicationController def route_by_role(employee) if employee.role == "administrator" # redirect_to dashboard_path - shift = ShiftSale.current_open_shift(employee.id) + shift = ShiftSale.current_open_shift(employee) if !shift.nil? redirect_to origami_root_path else @@ -203,7 +204,7 @@ class HomeController < ApplicationController end elsif employee.role == "cashier" #check if cashier has existing open cashier - shift = ShiftSale.current_open_shift(employee.id) + shift = ShiftSale.current_open_shift(employee) if !shift.nil? redirect_to origami_dashboard_path # redirect_to origami_root_path diff --git a/app/controllers/inventory/inventory_controller.rb b/app/controllers/inventory/inventory_controller.rb index a0324b15..137b733a 100755 --- a/app/controllers/inventory/inventory_controller.rb +++ b/app/controllers/inventory/inventory_controller.rb @@ -3,16 +3,14 @@ class Inventory::InventoryController < BaseInventoryController def index filter = params[:filter] - - @inventory_definitions = InventoryDefinition.get_by_category(filter) + @inventory_definitions = InventoryDefinition.get_by_category(@shop,filter) end def show inventory_definition_id = params[:inventory_definition_id] - inventory = InventoryDefinition.find(inventory_definition_id) - - @stock_journals = StockJournal.where(item_code: inventory.item_code).order("id DESC") + inventory = InventoryDefinition.find_by_id_and_shop_code(inventory_definition_id,@shop.shop_code) + @stock_journals = StockJournal.where("item_code=? and shop_code='#{@shop.shop_code}'",inventory.item_code).order("id DESC") @stock_journals = Kaminari.paginate_array(@stock_journals).page(params[:page]).per(20) respond_to do |format| @@ -20,12 +18,4 @@ class Inventory::InventoryController < BaseInventoryController format.xls end end - - - - #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end end diff --git a/app/controllers/inventory/inventory_definitions_controller.rb b/app/controllers/inventory/inventory_definitions_controller.rb index 01ca52b3..8497553e 100755 --- a/app/controllers/inventory/inventory_definitions_controller.rb +++ b/app/controllers/inventory/inventory_definitions_controller.rb @@ -4,7 +4,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController # GET /inventory_definitions # GET /inventory_definitions.json def index - @inventory_definitions = InventoryDefinition.all + @inventory_definitions = InventoryDefinition.where("shop_code='#{@shop.shop_code}'") end # GET /inventory_definitions/1 @@ -14,7 +14,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController # GET /inventory_definitions/new def new - @menus = Menu.all + @menus = Menu.where("shop_code='#{@shop.shop_code}'").order('created_at asc') @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') @inventory_definition = InventoryDefinition.new end @@ -26,7 +26,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController # POST /inventory_definitions # POST /inventory_definitions.json def create - inventory = InventoryDefinition.find_by_item_code(params[:item_code]) + inventory = InventoryDefinition.find_by_item_code_and_shop_code(params[:item_code],@shop.shop_code) if inventory.nil? @inventory_definition = InventoryDefinition.new @@ -39,6 +39,7 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController @inventory_definition.min_order_level = params[:min_order_level] @inventory_definition.max_stock_level = inventory.max_stock_level.to_i + params[:max_stock_level].to_i end + @inventory_definition.shop_code = @shop.shop_code @inventory_definition.created_by = current_user.id if @inventory_definition.save result = {:status=> true, :message => "Inventory definition was created successfully",:data=> @inventory_definition} @@ -83,16 +84,16 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController # DELETE /inventory_definitions/1 # DELETE /inventory_definitions/1.json def destroy - inventory = InventoryDefinition.find_by_item_code(params[:item_code]) + inventory = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code) @inventory_definition.destroy - respond_to do |format| - format.html { redirect_to inventory_definitions_url, notice: 'Inventory definition was successfully destroyed.' } - format.json { head :no_content } - end + # respond_to do |format| + # format.html { redirect_to inventory_inventory_definitions_url, notice: 'Inventory definition was successfully destroyed.' } + # format.json { head :no_content } + # end - inventory = InventoryDefinition.find(params[:id]) - StockJournal.delete_stock_journal(inventory.item_code) - StockCheckItem.delete_stock_check_item(inventory.item_code) + # inventory = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code) + StockJournal.delete_stock_journal(inventory.item_code,@shop) + StockCheckItem.delete_stock_check_item(inventory.item_code,@shop) if !inventory.nil? inventory.destroy flash[:message] = 'Inventory was successfully destroyed.' @@ -103,16 +104,10 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController end end - #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end - private # Use callbacks to share common setup or constraints between actions. def set_inventory_definition - @inventory_definition = InventoryDefinition.find(params[:id]) + @inventory_definition = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code) end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/controllers/inventory/stock_check_items_controller.rb b/app/controllers/inventory/stock_check_items_controller.rb index 7a37f789..e4563277 100755 --- a/app/controllers/inventory/stock_check_items_controller.rb +++ b/app/controllers/inventory/stock_check_items_controller.rb @@ -25,7 +25,6 @@ class Inventory::StockCheckItemsController < BaseInventoryController # POST /stock_check_items.json def create @stock_check_item = StockCheckItem.new(stock_check_item_params) - respond_to do |format| if @stock_check_item.save format.html { redirect_to inventory_stock_checks_path, notice: 'Stock check item was successfully created.' } @@ -61,12 +60,6 @@ class Inventory::StockCheckItemsController < BaseInventoryController end end - #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end - private # Use callbacks to share common setup or constraints between actions. def set_stock_check_item diff --git a/app/controllers/inventory/stock_checks_controller.rb b/app/controllers/inventory/stock_checks_controller.rb index b7f7369d..c756c8bb 100755 --- a/app/controllers/inventory/stock_checks_controller.rb +++ b/app/controllers/inventory/stock_checks_controller.rb @@ -8,19 +8,23 @@ class Inventory::StockChecksController < BaseInventoryController .joins("JOIN menu_item_instances mii ON mii.item_instance_code = inventory_definitions.item_code" + " JOIN menu_items mi ON mi.id = mii.menu_item_id" + " JOIN menu_categories mc ON mc.id = mi.menu_category_id ") + .where("inventory_definitions.shop_code='#{@shop.shop_code}'") .group("mi.menu_category_id") .order("mi.menu_category_id desc") + unless !@category.nil? + @category_id =@category[0].id + end end def create item_list = JSON.parse(params[:stock_item]) reason = params[:reason] check = StockCheck.new - @check = check.create(current_user, reason, item_list) + @check = check.create(current_user, reason, item_list,@shop) end def show - @check = StockCheck.find(params[:id]) + @check = StockCheck.find_by_id_and_shop_code(params[:id],@shop.shop_code) @stock_check_items = StockCheckItem.get_items_with_category(params[:id]) @@ -28,31 +32,31 @@ class Inventory::StockChecksController < BaseInventoryController def save_to_journal check = params[:data] - stockCheck = StockCheck.find(check) + stockCheck = StockCheck.find_by_id_and_shop_code(check,@shop.shop_code) stockCheck.stock_check_items.each do |item| - StockJournal.from_stock_check(item) + StockJournal.from_stock_check(item,@shop) end end def print_stock_check stock_id = params[:stock_check_id] # sale_id - stockcheck = StockCheck.find(stock_id) + stockcheck = StockCheck.find_by_id_and_shop_code(stock_id,@shop.shop_code) stockcheck_items = stockcheck.stock_check_items member_info = nil unique_code = 'StockCheckPdf' shop_details = current_shop - checker = Employee.find(stockcheck.check_by) - print_settings = PrintSetting.find_by_unique_code(unique_code) + checker = Employee.find_by_id_and_shop_code(stockcheck.check_by,@shop.shop_code) + print_settings = PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) if !print_settings.nil? printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker.name, shop_details) + printer.print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker.name, @shop) end end def get_menu_category () if (params[:id]) - + #Pull this menu @menu_category = InventoryDefinition.search_by_category(params[:id]) puts @menu_category.to_json diff --git a/app/controllers/inventory/stock_journals_controller.rb b/app/controllers/inventory/stock_journals_controller.rb index 11db2efd..cdba207e 100755 --- a/app/controllers/inventory/stock_journals_controller.rb +++ b/app/controllers/inventory/stock_journals_controller.rb @@ -25,7 +25,7 @@ class StockJournalsController < ApplicationController # POST /stock_journals.json def create @stock_journal = StockJournal.new(stock_journal_params) - + @stock_journal.shop_code = @shop.shop_code respond_to do |format| if @stock_journal.save format.html { redirect_to @stock_journal, notice: 'Stock journal was successfully created.' } @@ -61,12 +61,6 @@ class StockJournalsController < ApplicationController end end - #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end - private # Use callbacks to share common setup or constraints between actions. def set_stock_journal diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index c6e130ec..aeda9b40 100644 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -81,10 +81,4 @@ class Oqs::EditController < BaseOqsController render :json => {:status=> false, :message => "Not allowed over quantity!" } end end - - #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index aa06d103..f63e505e 100755 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -6,13 +6,13 @@ class Oqs::HomeController < BaseOqsController # Query for OQS with delivery status true # @tables = DiningFacility.all.active.order('status desc') - @tables = DiningFacility.where(:type => 'Table').order('status desc') - @rooms = Room.all.active.order('status desc') + @tables = DiningFacility.all.active.where("type = 'Table' and shop_code='#{@shop.shop_code}' ").order('status desc') + @rooms = DiningFacility.all.active.where("type = 'Room' and shop_code='#{@shop.shop_code}' ").order('status desc') @filter = params[:filter] @queue_stations = OrderQueueStation.active - + # @queue_completed_item = completed_order(@filter) @queue_completed_item = all_order(@filter) if !@queue_completed_item.empty? @@ -49,7 +49,7 @@ class Oqs::HomeController < BaseOqsController # zone_id = qid.zone_id # i=i+1 # end - # end + # end # end # @queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i }) # end @@ -157,8 +157,8 @@ puts items.to_json # Query for OQS with delivery status - def queue_items_query(status,oqs_id=nil,filter,table_id,delivery_status) - if oqs_id != "0" + def queue_items_query(status,oqs_id=nil,filter,table_id,delivery_status) + if oqs_id != "0" oqs = "and assigned_order_items.order_queue_station_id = '#{oqs_id}' " else oqs = '' @@ -169,7 +169,7 @@ puts items.to_json elsif delivery_status == "Processed" queue_status = "and assigned_order_items.delivery_status = true " else - queue_status = "and assigned_order_items.delivery_status = false " + queue_status = "and assigned_order_items.delivery_status = false " end if !table_id.empty? tableId = table_id.to_a.map{|h| h}.join(",") @@ -178,12 +178,12 @@ puts items.to_json table = '' end - query = AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, - oqs.id as station_id, oqs.station_name, - oqs.is_active, oqpz.zone_id, - df.name as zone, df.type as table_type, - odt.order_id, odt.item_code, odt.item_name, - odt.price, odt.qty, odt.item_order_by, odt.options, odt.set_menu_items, + query = AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, + oqs.id as station_id, oqs.station_name, + oqs.is_active, oqpz.zone_id, + df.name as zone, df.type as table_type, + odt.order_id, odt.item_code, odt.item_name, + odt.price, odt.qty, odt.item_order_by, odt.options, odt.set_menu_items, cus.name as customer_name, odt.created_at, assigned_order_items.delivery_status") .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id @@ -234,7 +234,7 @@ puts items.to_json left join bookings as bk on bk.booking_id = bo.booking_id left join dining_facilities as df on df.id = bk.dining_facility_id") .where("assigned_order_items.created_at between '#{Time.now.beginning_of_day.utc}' and '#{Time.now.end_of_day.utc}'") - query = query.where("df.name LIKE ? OR odt.order_id LIKE ? OR odt.item_name LIKE ? OR cus.name = '#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",) + query = query.where("df.shop_code='#{@shop.shop_code}' and df.name LIKE ? OR odt.order_id LIKE ? OR odt.item_name LIKE ? OR cus.name = '#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",) .group("odt.order_items_id") .order("assigned_order_items.created_at desc") @@ -242,7 +242,7 @@ puts items.to_json # completed_order = AssignedOrderItem.group(:order_id).where('delivery_status=true'); end - # def queue_items_count_query(status,filter) + # def queue_items_count_query(status,filter) # query = AssignedOrderItem.select("count(odt.item_code) as total,oqs.id as station_id") # .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id # left join orders as od ON od.order_id = assigned_order_items.order_id @@ -257,7 +257,7 @@ puts items.to_json # end - def queue_items_count_query(status,filter) + def queue_items_count_query(status,filter) # query = OrderQueueStation.all query = OrderQueueStation.select("order_queue_stations.id as station_id, (case when (count(odt.item_code)>0) then count(odt.item_code) else 0 end) as total") diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 597b5d28..baa88e4d 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -7,10 +7,10 @@ class Origami::AddordersController < BaseOrigamiController @webview = true end - @tables = Table.all.active.order('zone_id asc').group("zone_id") - @rooms = Room.all.active.order('zone_id asc').group("zone_id") - @all_table = Table.all.active.order('status desc') - @all_room = Room.all.active.order('status desc') + @tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id") + @rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id") + @all_table = Table.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc') + @all_room = Room.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc') end def detail @@ -19,7 +19,7 @@ class Origami::AddordersController < BaseOrigamiController if check_mobile @webview = true end - display_type = Lookup.find_by_lookup_type("display_type") + display_type = Lookup.find_by_lookup_type_and_shop_code("display_type",@shop.shop_code) if !display_type.nil? && display_type.value.to_i ==2 @display_type = display_type.value else @@ -28,10 +28,6 @@ class Origami::AddordersController < BaseOrigamiController # if params[:menu] == "true" @menus = [] @menu = [] - # else - # @menus = Menu.all - # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') - # end @table_id = params[:id] @table = DiningFacility.find(@table_id) @@ -140,7 +136,7 @@ class Origami::AddordersController < BaseOrigamiController @order.new_booking = true @order.waiters = current_login_employee.name @order.employee_name = current_login_employee.name - + @order.shop_code =@shop.shop_code @order.is_extra_time = is_extra_time @order.extra_time = extra_time @@ -237,7 +233,7 @@ class Origami::AddordersController < BaseOrigamiController #Send to background job for processing order = Order.find(order_id) - sidekiq = Lookup.find_by_lookup_type("sidekiq") + sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",@shop.shop_code) if ENV["SERVER_MODE"] != 'cloud' cup_status = `#{"sudo service cups status"}` print_status = check_cup_status(cup_status) @@ -311,10 +307,4 @@ class Origami::AddordersController < BaseOrigamiController return from end - private - - # def set_dining - # @dining = DiningFacility.find(params[:id]) - # end - end diff --git a/app/controllers/origami/alipay_controller.rb b/app/controllers/origami/alipay_controller.rb index 8c5f4884..63ff5a6b 100644 --- a/app/controllers/origami/alipay_controller.rb +++ b/app/controllers/origami/alipay_controller.rb @@ -11,7 +11,7 @@ class Origami::AlipayController < BaseOrigamiController end total = 0 @alipaycount = 0 - @shop = Shop.first + # @shop = Shop.first @rounding_adj = 0 @can_alipay = 0 @member_discount = 0 @@ -20,15 +20,15 @@ class Origami::AlipayController < BaseOrigamiController @receipt_no = nil if !sale_data.nil? total = sale_data.grand_total - + others = 0 - + if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total + @rounding_adj = new_total-sale_data.grand_total if path.include? ("credit_payment") sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) else @@ -64,13 +64,13 @@ class Origami::AlipayController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first - + # shop_details = Shop.first + # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end # saleObj = Sale.find(sale_id) @@ -86,8 +86,8 @@ class Origami::AlipayController < BaseOrigamiController end #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end + # helper_method :shop_detail + # def shop_detail + # @shop = Shop.first + # end end diff --git a/app/controllers/origami/cash_ins_controller.rb b/app/controllers/origami/cash_ins_controller.rb index 8cbbef85..7ebb698a 100755 --- a/app/controllers/origami/cash_ins_controller.rb +++ b/app/controllers/origami/cash_ins_controller.rb @@ -11,35 +11,34 @@ class Origami::CashInsController < BaseOrigamiController type = params[:type] p_jour = PaymentJournal.new - p_jour.cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user.id) - shift = ShiftSale.current_open_shift(current_user.id) - current_shift = ShiftSale.current_shift + p_jour.cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user) + shift = ShiftSale.current_open_shift(current_user) + current_shift = ShiftSale.current_shift(@shop.shop_code) # set cashier if shift != nil shift = shift else - open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") - if open_cashier.count > 0 - - shift = ShiftSale.current_open_shift(open_cashier[0].id) + open_cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''") + if open_cashier.count>0 + shift = ShiftSale.current_open_shift(open_cashier[0]) if shift - shift = ShiftSale.current_open_shift(shift.id) + emp = Employee.find_by_id(shift.employee_id) + shift = ShiftSale.current_open_shift(emp) else - shift = ShiftSale.current_open_shift(current_shift.id) + shift = ShiftSale.current_open_shift(current_shift) end else - - shift = Employee.find(current_shift.employee_id).name - #shift = current_shift + # shift = Employee.find(current_shift.employee_id).name + shift =current_shift end end - + puts shift.to_json shift.cash_in = shift.cash_in + amount.to_f shift.save end - + end diff --git a/app/controllers/origami/cash_outs_controller.rb b/app/controllers/origami/cash_outs_controller.rb index d3716915..e576bfc5 100755 --- a/app/controllers/origami/cash_outs_controller.rb +++ b/app/controllers/origami/cash_outs_controller.rb @@ -7,28 +7,29 @@ class Origami::CashOutsController < BaseOrigamiController remark = params[:remark] amount = params[:amount] p_jour = PaymentJournal.new - p_jour.cash_out(reference, remark, amount, current_user.id) - shift = ShiftSale.current_open_shift(current_user.id) - - current_shift = ShiftSale.current_shift + p_jour.cash_out(reference, remark, amount, current_user) + shift = ShiftSale.current_open_shift(current_user) + + current_shift = ShiftSale.current_shift(@shop.shop_code) # set cashier if shift != nil shift = shift else - open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") + open_cashier = Employee.where("shop_code='#{@shop.shop_code}' and role = 'cashier' AND token_session <> ''") if open_cashier.count>0 - - shift = ShiftSale.current_open_shift(open_cashier[0].id) - + + shift = ShiftSale.current_open_shift(open_cashier[0]) + if shift - shift = ShiftSale.current_open_shift(shift.id) + emp = Employee.find_by_id(shift.employee_id) + shift = ShiftSale.current_open_shift(emp) else - shift = ShiftSale.current_open_shift(current_shift.id) + shift = ShiftSale.current_open_shift(current_shift) end else - shift = Employee.find(current_shift.employee_id).name - + # shift = Employee.find(current_shift.employee_id).name + shift =current_shift end end shift.cash_out = shift.cash_out + amount.to_i diff --git a/app/controllers/origami/credit_payments_controller.rb b/app/controllers/origami/credit_payments_controller.rb index 05faf4f7..f5ac5740 100755 --- a/app/controllers/origami/credit_payments_controller.rb +++ b/app/controllers/origami/credit_payments_controller.rb @@ -9,13 +9,12 @@ class Origami::CreditPaymentsController < BaseOrigamiController @creditcount = 0 others = 0 - @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total + @rounding_adj = new_total-sale_data.grand_total sale_data.sale_payments.each do |sale_payment| if sale_payment.payment_method == "creditnote" @@ -32,13 +31,12 @@ class Origami::CreditPaymentsController < BaseOrigamiController sale_id = params[:sale_id] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first - + # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end saleObj = Sale.find(sale_id) @@ -50,7 +48,7 @@ class Origami::CreditPaymentsController < BaseOrigamiController def create_credit_payment arr_sale = JSON.parse(params[:data]) - if !ShiftSale.current_shift.nil? + if !ShiftSale.current_shift(@shop.shop_code).nil? if !arr_sale.nil? arr_sale.each do |arr_sale| arr_sale.each do |sale| @@ -71,7 +69,7 @@ class Origami::CreditPaymentsController < BaseOrigamiController else render :json => {status: false, message: 'No current shift open for this employee!'} end - + end end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 97f35339..151ff8e8 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -92,12 +92,12 @@ class Origami::CustomersController < BaseOrigamiController # if flash["errors"] # @crm_customer.valid? # end - @membership_types = Lookup.collection_of("member_group_type") + @membership_types = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("member_group_type") #get paypar accountno @paypar_accountno = Customer.where("paypar_account_no IS NOT NULL AND paypar_account_no != ''").pluck("paypar_account_no") #for create customer on/off @create_flag = true - lookup_customer = Lookup.collection_of('customer_settings') + lookup_customer = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('customer_settings') if !lookup_customer.empty? lookup_customer.each do |create_setting| if create_setting[0].downcase == "create" diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index c7dc9423..0a8e5c18 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -1,36 +1,35 @@ class Origami::DashboardController < BaseOrigamiController def index - @shop = Shop.first today = DateTime.now.strftime('%Y-%m-%d') - @display_type = Lookup.find_by_lookup_type("display_type") + @display_type = Lookup.where("shop_code='#{@shop.shop_code}'").find_by_lookup_type("display_type") @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(today,current_user) + @total_payment_methods = Sale.total_payment_methods(@shop,today,current_user) if !@total_payment_methods.nil? @total_payment_methods.each do |payment| if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" - pay = Sale.payment_sale('card', today, current_user) + pay = Sale.payment_sale(@shop,'card', today, current_user) @sale_data.push({'card' => pay.payment_amount}) else - pay = Sale.payment_sale(payment.payment_method, today, current_user) + pay = Sale.payment_sale(@shop,payment.payment_method, today, current_user) @sale_data.push({payment.payment_method => pay.payment_amount}) end end else @sale_data = nil end - @summ_sale = Sale.summary_sale_receipt(today,current_user) - @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time) + @summ_sale = Sale.summary_sale_receipt(@shop,today,current_user) + @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time) # @total_other_customer = Sale.total_other_customer(today,current_user) - @total_order = Sale.total_order(today,current_user) - @total_accounts = Sale.total_account(today,current_user) + @total_order = Sale.total_order(@shop,today,current_user) + @total_accounts = Sale.total_account(@shop,today,current_user) @account_data = Array.new if !@total_accounts.nil? @total_accounts.each do |account| - acc = Sale.account_data(account.account_id, today,current_user) + acc = Sale.account_data(@shop,account.account_id, today,current_user) if !acc.nil? @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end @@ -39,28 +38,28 @@ class Origami::DashboardController < BaseOrigamiController @account_data = nil end - @top_items = Sale.top_items(today,current_user) - @total_foc_items = Sale.total_foc_items(today,current_user) + @top_items = Sale.top_items(@shop,today,current_user) + @total_foc_items = Sale.total_foc_items(@shop,today,current_user) # get printer info @print_settings = PrintSetting.get_precision_delimiter() @current_user = current_user #dine-in cashier - dinein_cashier = Lookup.collection_of('dinein_cashier') + dinein_cashier = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dinein_cashier') @dinein_cashier = 0 if !dinein_cashier[0].nil? @dinein_cashier = dinein_cashier[0][1] end #quick service - quick_service = Lookup.collection_of('quick_service') + quick_service = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quick_service') @quick_service = 0 if !quick_service[0].nil? @quick_service = quick_service[0][1] end #fourt court - food_court = Lookup.collection_of('food_court') + food_court = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('food_court') @food_court = 0 @food_court_name = nil if !food_court[0].nil? @@ -69,7 +68,7 @@ class Origami::DashboardController < BaseOrigamiController end #order reservation - order_reservation = Lookup.collection_of('order_reservation') + order_reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('order_reservation') @order_reservation = 0 if !order_reservation.empty? order_reservation.each do |order_reserve| @@ -80,7 +79,7 @@ class Origami::DashboardController < BaseOrigamiController end #dashboard settings on/off for supervisor and cashier - dashboard_settings = Lookup.collection_of('dashboard_settings') + dashboard_settings = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dashboard_settings') @setting_flag = true if !dashboard_settings.empty? dashboard_settings.each do |setting| @@ -91,7 +90,7 @@ class Origami::DashboardController < BaseOrigamiController end #reservation - reservation = Lookup.collection_of('reservation') + reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('reservation') @reservation = 0 if !reservation.empty? reservation.each do |reserve| @@ -103,13 +102,13 @@ class Origami::DashboardController < BaseOrigamiController end def get_all_menu - @menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.all + @menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.all.where("shop_code='#{@shop.shop_code}'") @item_attributes = MenuItemAttribute.all.load @item_options = MenuItemOption.all.load end def get_credit_sales - credit_sales = SalePayment.get_credit_sales(params) + credit_sales = SalePayment.get_credit_sales(params,@shop.shop_code) if !credit_sales.nil? result = {:status=> true, :data=> credit_sales } else diff --git a/app/controllers/origami/dinga_controller.rb b/app/controllers/origami/dinga_controller.rb index 01e35004..0472728a 100644 --- a/app/controllers/origami/dinga_controller.rb +++ b/app/controllers/origami/dinga_controller.rb @@ -6,14 +6,14 @@ class Origami::DingaController < BaseOrigamiController @membership_rebate_balance=0 @sale_data = Sale.find_by_sale_id(@sale_id) @receipt_no = @sale_data.receipt_no - @shop = Shop.first + # @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(@sale_data.grand_total) else new_total = @sale_data.grand_total end - @rounding_adj = new_total-@sale_data.grand_total - # @rounding_adj = @sale_data.rounding_adjustment + @rounding_adj = new_total-@sale_data.grand_total + # @rounding_adj = @sale_data.rounding_adjustment @payparcount = 0 others = 0 @@ -77,12 +77,12 @@ def create account_no = params[:account_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first + # shop_details = Shop.first # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end # saleObj = Sale.find(sale_id) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 6f4690f0..4d9f26f8 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -21,8 +21,8 @@ class Origami::DiscountsController < BaseOrigamiController end end - @member_discount = MembershipSetting.find_by_discount(1) - @accounts = Account.all + @member_discount = MembershipSetting.find_by_discount_and_shop_code(1,@shop.shop_code) + @accounts = Account.where("shop_code='#{@shop.shop_code}'") end #discount page show from origami index with selected order @@ -87,7 +87,7 @@ class Origami::DiscountsController < BaseOrigamiController remark = "Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} " sale_audit = SaleAudit.record_audit_discount(sale_item.sale_id,sale.cashier_name, action_by,remark,"ITEMDISCOUNT" ) - + end end diff --git a/app/controllers/origami/gift_voucher_controller.rb b/app/controllers/origami/gift_voucher_controller.rb index 572e248e..7bd4cd77 100644 --- a/app/controllers/origami/gift_voucher_controller.rb +++ b/app/controllers/origami/gift_voucher_controller.rb @@ -6,7 +6,7 @@ class Origami::GiftVoucherController < BaseOrigamiController sale_data = Sale.find_by_sale_id(@sale_id) total = 0 @gift_vouchercount = 0 - @shop = Shop.first + # @shop = Shop.first @rounding_adj = 0 @can_gift_voucher = 0 @member_discount = 0 @@ -15,16 +15,16 @@ class Origami::GiftVoucherController < BaseOrigamiController @receipt_no = nil if !sale_data.nil? total = sale_data.grand_total - + others = 0 - + if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total - + @rounding_adj = new_total-sale_data.grand_total + sale_data.sale_payments.each do |sale_payment| if sale_payment.payment_method == "gift_voucher" @gift_vouchercount = @gift_vouchercount + sale_payment.payment_amount @@ -48,13 +48,13 @@ class Origami::GiftVoucherController < BaseOrigamiController ref_no = params[:reference_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first - + # shop_details = Shop.first + # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end # saleObj = Sale.find(sale_id) @@ -64,8 +64,8 @@ class Origami::GiftVoucherController < BaseOrigamiController end #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end + # helper_method :shop_detail + # def shop_detail + # @shop = Shop.first + # end end diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index fe074210..81986afa 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -4,15 +4,14 @@ class Origami::HomeController < BaseOrigamiController def index @webview = check_mobile - @tables = Table.unscoped.all.active.order('status desc') - @rooms = Room.unscoped.all.active.order('status desc') - @complete = Sale.completed_sale("cashier") - @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @tables = Table.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') + @rooms = Room.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') + @complete = Sale.completed_sale("cashier",@shop.shop_code) + @orders = Order.includes("sale_orders").where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @customers = Customer.pluck("customer_id, name") - @shop = shop_detail - @occupied_table = DiningFacility.where("status='occupied'").count - @shift = ShiftSale.current_open_shift(current_user.id) + @occupied_table = DiningFacility.where("shop_code='#{@shop.shop_code}' and status='occupied'").count + @shift = ShiftSale.current_open_shift(current_user) end # origami table detail @@ -21,20 +20,19 @@ class Origami::HomeController < BaseOrigamiController @print_settings = PrintSetting.get_precision_delimiter() @webview = check_mobile - @tables = Table.unscoped.all.active.order('status desc') - @rooms = Room.unscoped.all.active.order('status desc') - @complete = Sale.completed_sale("cashier") - @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') + @tables = Table.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') + @rooms = Room.unscoped.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') + @complete = Sale.completed_sale("cashier",@shop.shop_code) + @orders = Order.includes("sale_orders").where("shop_code='#{@shop.shop_code}' and DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @customers = Customer.pluck("customer_id, name") - @shift = ShiftSale.current_open_shift(current_user.id) + @shift = ShiftSale.current_open_shift(current_user) @status_order = "" @status_sale = "" @sale_array = Array.new - @shop = shop_detail - @membership = MembershipSetting::MembershipSetting - @payment_methods = PaymentMethodSetting.all + @membership = MembershipSetting.find_by_shop_code(@shop.shop_code) + @payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'") @dining_booking = @dining.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ") #@dining_booking = @dining.bookings.active.where("created_at between '#{DateTime.now.utc - 12.hours}' and '#{DateTime.now.utc}'") @order_items = Array.new @@ -106,16 +104,16 @@ class Origami::HomeController < BaseOrigamiController end #for bank integration - @checkout_time = Lookup.collection_of('checkout_time') - @checkout_alert_time = Lookup.collection_of('checkout_alert_time') + @checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time') + @checkout_alert_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_alert_time') - accounts = TaxProfile.where("group_type = ?","cashier").order("order_by ASC") + accounts = TaxProfile.where("shop_code='#{@shop.shop_code}' and group_type = ?","cashier").order("order_by ASC") @tax_arr =[] accounts.each do |acc| @tax_arr.push(acc.name) end - lookup_spit_bill = Lookup.collection_of('split_bill') + lookup_spit_bill = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('split_bill') @split_bill = 0 if !lookup_spit_bill[0].nil? @split_bill = lookup_spit_bill[0][1] @@ -123,10 +121,10 @@ class Origami::HomeController < BaseOrigamiController #for edit order on/off @edit_order_origami = true - lookup_edit_order = Lookup.collection_of('edit_order') + lookup_edit_order = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('edit_order') if !lookup_edit_order.empty? lookup_edit_order.each do |edit_order| - if edit_order[0].downcase == "editorderorigami" + if edit_order[0].downcase == "editorderorigami" if edit_order[1] == '0' && (current_login_employee.role == 'cashier' || current_login_employee.role == 'waiter') @edit_order_origami = false end @@ -136,17 +134,17 @@ class Origami::HomeController < BaseOrigamiController #for changable on/off @changable_tax = true - lookup_changable_tax = Lookup.collection_of('changable_tax') + lookup_changable_tax = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('changable_tax') if !lookup_changable_tax.empty? lookup_changable_tax.each do |changable_tax| - if changable_tax[0].downcase == "change" - if changable_tax[1] == '0' + if changable_tax[0].downcase == "change" + if changable_tax[1] == '0' @changable_tax = false end end end end - + end def check_emp_access_code diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb index 1f979adc..897d8bae 100644 --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -12,7 +12,7 @@ class Origami::JcbController < BaseOrigamiController end total = 0 @jcbcount = 0 - @shop = Shop.first + # @shop = Shop.first @rounding_adj = 0 @can_jcb = 0 @member_discount= 0 @@ -21,15 +21,15 @@ class Origami::JcbController < BaseOrigamiController @receipt_no = nil if !sale_data.nil? total = sale_data.grand_total - + others = 0 - + if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total + @rounding_adj = new_total-sale_data.grand_total if path.include? ("credit_payment") sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) else @@ -66,13 +66,13 @@ class Origami::JcbController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first - + # shop_details = Shop.first + # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end # saleObj = Sale.find(sale_id) @@ -87,8 +87,8 @@ class Origami::JcbController < BaseOrigamiController end #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end + # helper_method :shop_detail + # def shop_detail + # @shop = Shop.first + # end end diff --git a/app/controllers/origami/junction_pay_controller.rb b/app/controllers/origami/junction_pay_controller.rb index c77c2655..67a9c748 100644 --- a/app/controllers/origami/junction_pay_controller.rb +++ b/app/controllers/origami/junction_pay_controller.rb @@ -11,14 +11,14 @@ class Origami::JunctionPayController < BaseOrigamiController @cashier_id = current_user.emp_id @payment_method_setting_nav = PaymentMethodSetting.all - @shop = Shop.first + # @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total - + @rounding_adj = new_total-sale_data.grand_total + sale_data.sale_payments.each do |sale_payment| if sale_payment.payment_method == "JunctionPay" @junction_pay_count = @junction_pay_count + sale_payment.payment_amount @@ -32,7 +32,7 @@ class Origami::JunctionPayController < BaseOrigamiController @sub_total = sale_data.total_amount @membership_id = sale_data.customer.membership_id #for bank integration - @receipt_no = sale_data.receipt_no + @receipt_no = sale_data.receipt_no end def create @@ -52,13 +52,13 @@ class Origami::JunctionPayController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first - + # shop_details = Shop.first + # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end # saleObj = Sale.find(sale_id) diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb index 15edb703..26a31b71 100644 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -12,7 +12,7 @@ class Origami::MasterController < BaseOrigamiController end total = 0 @mastercount = 0 - @shop = Shop.first + # @shop = Shop.first @rounding_adj = 0 @can_master = 0 @member_discount = 0 @@ -21,15 +21,15 @@ class Origami::MasterController < BaseOrigamiController @receipt_no = nil if !sale_data.nil? total = sale_data.grand_total - + others = 0 - + if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total + @rounding_adj = new_total-sale_data.grand_total if path.include? ("credit_payment") sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) else @@ -63,13 +63,13 @@ class Origami::MasterController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first - + # shop_details = Shop.first + # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end # saleObj = Sale.find(sale_id) @@ -85,8 +85,8 @@ class Origami::MasterController < BaseOrigamiController end #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end + # helper_method :shop_detail + # def shop_detail + # @shop = Shop.first + # end end diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb index 220219c3..2c8a1d29 100644 --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -11,7 +11,7 @@ class Origami::MpuController < BaseOrigamiController end total = 0 @mpucount = 0 - @shop = Shop.first + # @shop = Shop.first @rounding_adj = 0 @can_mpu = 0 @member_discount = 0 @@ -20,15 +20,15 @@ class Origami::MpuController < BaseOrigamiController @receipt_no = nil if !sale_data.nil? total = sale_data.grand_total - + others = 0 - + if @shop.is_rounding_adj && (!path.include? ("credit_payment")) new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total + @rounding_adj = new_total-sale_data.grand_total if path.include? ("credit_payment") sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) else @@ -64,13 +64,13 @@ class Origami::MpuController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first - + # shop_details = Shop.first + # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end # saleObj = Sale.find(sale_id) @@ -85,8 +85,8 @@ class Origami::MpuController < BaseOrigamiController end #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end + # helper_method :shop_detail + # def shop_detail + # @shop = Shop.first + # end end diff --git a/app/controllers/origami/order_reservation_controller.rb b/app/controllers/origami/order_reservation_controller.rb index 3fdeee25..3bde49ec 100644 --- a/app/controllers/origami/order_reservation_controller.rb +++ b/app/controllers/origami/order_reservation_controller.rb @@ -4,7 +4,6 @@ class Origami::OrderReservationController < BaseOrigamiController @order = OrderReservation.latest_order #.active @count_on_order = OrderReservation.get_count_on_order @count_on_completed = OrderReservation.get_count_on_completed - @shop = Shop.find_by_id(1) @receipt_bill = check_receipt_bill end @@ -23,7 +22,7 @@ class Origami::OrderReservationController < BaseOrigamiController order_reserve = OrderReservation.find_by_transaction_ref(params[:ref_no]) if !order_reserve.nil? - if !ShiftSale.current_shift.nil? + if !ShiftSale.current_shift(@shop.shop_code).nil? if @status == "processed" if order_reserve.status == "accepted" result = OrderReservation.create_doemal_order(order_reserve,current_user) @@ -87,7 +86,7 @@ class Origami::OrderReservationController < BaseOrigamiController def send_status order_reservation = OrderReservation.find_by_transaction_ref(params[:ref_no]) if !order_reservation.nil? - if !ShiftSale.current_shift.nil? || params[:status] == 'accepted' || (order_reservation.status == 'new' && params[:status] == 'rejected') + if !ShiftSale.current_shift(@shop.shop_code).nil? || params[:status] == 'accepted' || (order_reservation.status == 'new' && params[:status] == 'rejected') response = OrderReservation.send_status_to_ordering(params[:url],params[:ref_no],params[:status],params[:waiting_time],params[:min_type],params[:reason]) else response = { status: false, message: 'No current shift open for this employee!'} @@ -99,12 +98,12 @@ class Origami::OrderReservationController < BaseOrigamiController end def get_order_info - order_reservation = OrderReservation.where("status = 'new'").count() + order_reservation = OrderReservation.where("status = 'new' and shop_code='#{@shop.shop_code}'").count() render :json => order_reservation end def check_receipt_bill - receipt_bill = Lookup.collection_of("order_reservation") + receipt_bill = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("order_reservation") status = 0 if !receipt_bill.nil? diff --git a/app/controllers/origami/paymal_controller.rb b/app/controllers/origami/paymal_controller.rb index 36c19327..4b03d0fb 100644 --- a/app/controllers/origami/paymal_controller.rb +++ b/app/controllers/origami/paymal_controller.rb @@ -6,14 +6,14 @@ class Origami::PaymalController < BaseOrigamiController @membership_rebate_balance=0 sale_data = Sale.find_by_sale_id(@sale_id) @receipt_no = sale_data.receipt_no - @shop = Shop.first + # @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total - # @rounding_adj = sale_data.rounding_adjustment + @rounding_adj = new_total-sale_data.grand_total + # @rounding_adj = sale_data.rounding_adjustment @payparcount = 0 others = 0 @@ -72,16 +72,16 @@ def create sale_id = params[:sale_id] transaction_ref = params[:transaction_ref] account_no = params[:account_no] - puts params.to_json + puts params.to_json if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first + # shop_details = Shop.first # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end # saleObj = Sale.find(sale_id) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index c6c61602..fac5937a 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -17,7 +17,7 @@ class Origami::PaymentsController < BaseOrigamiController # else # table = DiningFacility.find(bookings[0].dining_facility_id) # end - shift = ShiftSale.current_open_shift(current_user.id) + shift = ShiftSale.current_open_shift(current_user) if !shift.nil? cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) else @@ -32,7 +32,7 @@ class Origami::PaymentsController < BaseOrigamiController end # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server - receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf # Print for First Bill to Customer unique_code = "ReceiptBillPdf" print_settings = PrintSetting.all @@ -63,7 +63,7 @@ class Origami::PaymentsController < BaseOrigamiController # customer= Customer.where('customer_id=' +.customer_id) customer = Customer.find(sale_data.customer_id) # rounding adjustment - if shop_detail.is_rounding_adj + if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) rounding_adj = new_total - sale_data.grand_total sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0 @@ -76,14 +76,14 @@ class Origami::PaymentsController < BaseOrigamiController remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}" sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type ) # get member information - rebate = MembershipSetting.find_by_rebate(1) + rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code) if customer.membership_id != nil && rebate # member_info = Customer.get_member_account(customer) # current_balance = SaleAudit.paymal_search(sale_id) current_balance = 0 end # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) # find order id by sale id # sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id) @@ -99,7 +99,7 @@ class Origami::PaymentsController < BaseOrigamiController #TODO :: KBZPAY ( QR ) # On/Off setting ( show or not qr ) # qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD" - kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last + kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY,:shop_code => @shop.shop_code).last status = false qr = nil @@ -113,7 +113,7 @@ class Origami::PaymentsController < BaseOrigamiController end end - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, @shop, "Frt",current_balance,nil,other_amount,nil,nil,nil) result = { :filepath => filename, @@ -144,7 +144,7 @@ class Origami::PaymentsController < BaseOrigamiController #shop_detail = Shop.first # rounding adjustment if !path.include? ("credit_payment") - if shop_detail.is_rounding_adj + if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(saleObj.grand_total) rounding_adj = new_total - saleObj.grand_total saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0 @@ -178,7 +178,7 @@ class Origami::PaymentsController < BaseOrigamiController # bookings = Booking.where("sale_id='#{sale_id}'") bookings = Booking.find_by_sale_id(sale_id) - shift = ShiftSale.current_open_shift(current_user.id) + shift = ShiftSale.current_open_shift(current_user) if !shift.nil? cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) else @@ -198,7 +198,7 @@ class Origami::PaymentsController < BaseOrigamiController # For Print # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server - receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf unique_code = "ReceiptBillPdf" print_settings = PrintSetting.all if !print_settings.nil? @@ -226,7 +226,7 @@ class Origami::PaymentsController < BaseOrigamiController customer= Customer.find(saleObj.customer_id) # get member information - rebate = MembershipSetting.find_by_rebate(1) + rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code) credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote') if customer.membership_id != nil && rebate && credit_data.nil? @@ -281,14 +281,14 @@ class Origami::PaymentsController < BaseOrigamiController card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id) # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) # Calculate Food and Beverage Total item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) other_amount = SaleItem.calculate_other_charges(sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) #end end @@ -313,7 +313,7 @@ class Origami::PaymentsController < BaseOrigamiController # end def show - display_type = Lookup.find_by_lookup_type("display_type") + display_type = Lookup.find_by_lookup_type_and_shop_code("display_type",@shop.shop_code) if !display_type.nil? && display_type.value.to_i ==2 @display_type = display_type.value else @@ -333,7 +333,7 @@ class Origami::PaymentsController < BaseOrigamiController @sale_payment = SalePayment.get_credit_amount_due_left(sale_id) end - @member_discount = MembershipSetting.find_by_discount(1) + @member_discount = MembershipSetting.find_by_discount_and_shop_code(1,@shop.shop_code) @membership_rebate_balance=0 if Sale.exists?(sale_id) @@ -358,17 +358,17 @@ class Origami::PaymentsController < BaseOrigamiController @dining = '' @other_payment = 0.0 @pdf_view = nil - @lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView") + @lookup_pdf = Lookup.find_by_lookup_type_and_shop_code("ReceiptPdfView",@shop.shop_code) if !@lookup_pdf.nil? @pdf_view = @lookup_pdf.value end - amount = SalePayment.get_kbz_pay_amount(sale_id, current_user) + amount = SalePayment.get_kbz_pay_amount(sale_id, current_user,@shop) @kbz_pay_amount += amount.to_f #for changable on/off @changable_tax = true - lookup_changable_tax = Lookup.collection_of('changable_tax') + lookup_changable_tax = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('changable_tax') if !lookup_changable_tax.empty? lookup_changable_tax.each do |changable_tax| if changable_tax[0].downcase == "change" @@ -379,7 +379,7 @@ class Origami::PaymentsController < BaseOrigamiController end end - @shop = shop_detail #show shop info + # @shop = shop_detail #show shop info @customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'") @@ -436,7 +436,7 @@ class Origami::PaymentsController < BaseOrigamiController #get customer amount @customer = Customer.find(@sale_data.customer_id) # accounts = @customer.tax_profiles - accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") + accounts = TaxProfile.where("group_type = ? and shop_code='#{@shop.shop_code}'",@cashier_type).order("order_by ASC") @account_arr =[] @tax_arr =[] accounts.each do |acc| @@ -450,7 +450,7 @@ class Origami::PaymentsController < BaseOrigamiController @account_arr.push(sale_tax) end end - rebate = MembershipSetting.find_by_rebate(1) + rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code) # get member information if @customer.membership_id != nil && rebate response = Customer.get_member_account(@customer) @@ -546,7 +546,7 @@ class Origami::PaymentsController < BaseOrigamiController # else # table = DiningFacility.find(bookings[0].dining_facility_id) # end - shift = ShiftSale.current_open_shift(current_user.id) + shift = ShiftSale.current_open_shift(current_user) if !shift.nil? cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) else @@ -612,7 +612,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) result = { :status => true, @@ -664,7 +664,7 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - shift = ShiftSale.current_open_shift(current_user.id) + shift = ShiftSale.current_open_shift(current_user) if !shift.nil? cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) else @@ -687,7 +687,7 @@ class Origami::PaymentsController < BaseOrigamiController #shop detail #shop_detail = Shop.first - printer = PrintSetting.all + printer = PrintSetting.where("shop_code='#{@shop.shop_code}'") unique_code="ReceiptBillPdf" if !printer.empty? @@ -702,7 +702,7 @@ class Origami::PaymentsController < BaseOrigamiController end end # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) # Calculate Food and Beverage Total item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) @@ -711,7 +711,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "FOC",nil,nil,other_amount,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "FOC",nil,nil,other_amount,nil,nil,nil) result = { :status => true, :filepath => filename, @@ -745,7 +745,6 @@ class Origami::PaymentsController < BaseOrigamiController def rounding_adj saleObj = Sale.find(params[:sale_id]) - @shop = shop_detail if @shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus @@ -770,9 +769,9 @@ class Origami::PaymentsController < BaseOrigamiController if cashier_type.strip.downcase == "doemal_order" unique_code = "ReceiptBillOrderPdf" else - receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf unique_code = "ReceiptBillPdf" - print_settings = PrintSetting.all + print_settings = PrintSetting.where("shop_code='#{@shop.shop_code}'") if !print_settings.nil? print_settings.each do |setting| if setting.unique_code == 'ReceiptBillPdf' @@ -795,7 +794,7 @@ class Origami::PaymentsController < BaseOrigamiController end end # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) printer = Printer::ReceiptPrinter.new(print_settings) printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name) diff --git a/app/controllers/origami/paypar_payments_controller.rb b/app/controllers/origami/paypar_payments_controller.rb index fbcd348c..70a3aef5 100755 --- a/app/controllers/origami/paypar_payments_controller.rb +++ b/app/controllers/origami/paypar_payments_controller.rb @@ -7,15 +7,15 @@ class Origami::PayparPaymentsController < BaseOrigamiController payment_method = "paypar" if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first - + # shop_details = Shop.first + # rounding adjustment - if shop_details.is_rounding_adj + if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(saleObj.grand_total) rounding_adj = new_total-saleObj.grand_total - saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) end - + sale_payment = SalePayment.new status,msg =sale_payment.process_payment(saleObj, current_user, redeem_amount,payment_method) if status == true @@ -28,5 +28,5 @@ class Origami::PayparPaymentsController < BaseOrigamiController end end - + end diff --git a/app/controllers/origami/pending_order_controller.rb b/app/controllers/origami/pending_order_controller.rb index 773a217e..c6bdb2e7 100644 --- a/app/controllers/origami/pending_order_controller.rb +++ b/app/controllers/origami/pending_order_controller.rb @@ -5,7 +5,7 @@ class Origami::PendingOrderController < BaseOrigamiController @cashier_type = params[:type] @sale = Sale.pending_sale(@cashier_type) @order = Sale.pending_order(@cashier_type) - @completed = Sale.completed_sale(@cashier_type) + @completed = Sale.completed_sale(@cashier_type,@shop.shop_code) @customers = Customer.pluck("customer_id, name") @occupied_table = @sale.count.length + @order.count.length @@ -36,7 +36,7 @@ class Origami::PendingOrderController < BaseOrigamiController @cashier_type = params[:type] @sales = Sale.pending_sale(@cashier_type) @orders = Sale.pending_order(@cashier_type) - @completed = Sale.completed_sale(@cashier_type) + @completed = Sale.completed_sale(@cashier_type,@shop.shop_code) @customers = Customer.pluck("customer_id, name") @occupied_table = @sales.count.length + @orders.count.length @@ -46,7 +46,7 @@ class Origami::PendingOrderController < BaseOrigamiController @cashier_type = params[:type] @sales = Sale.pending_sale(@cashier_type) @orders = Sale.pending_order(@cashier_type) - @completed = Sale.completed_sale(@cashier_type) + @completed = Sale.completed_sale(@cashier_type,@shop.shop_code) @customers = Customer.pluck("customer_id, name") @occupied_table = @sales.count.length + @orders.count.length @@ -81,7 +81,7 @@ class Origami::PendingOrderController < BaseOrigamiController @cashier_type = params[:type] @sales = Sale.pending_sale(@cashier_type) @orders = Sale.pending_order(@cashier_type) - @completed = Sale.completed_sale(@cashier_type) + @completed = Sale.completed_sale(@cashier_type,@shop.shop_code) @occupied_table = @sales.count.length + @orders.count.length diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index 3e69485a..f57189d0 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -13,16 +13,12 @@ class Origami::QuickServiceController < ApplicationController # if params[:menu] == "true" @menus = [] @menu = [] - # else - # @menus = Menu.all - # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') - # end - @zone = Zone.all + @zone = Zone.all.where("shop_code='#{@shop.shop_code}'") @customer = Customer.all - @tables = Table.all.active.order('status desc') - @rooms = Room.all.active.order('status desc') + @tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') + @rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') @cashier_type = "quick_service" - display_type = Lookup.find_by_lookup_type("display_type") + display_type = Lookup.find_by_lookup_type_and_shop_code("display_type",@shop.shop_code) if !display_type.nil? && display_type.value.to_i ==2 @display_type = display_type.value else @@ -31,9 +27,7 @@ class Origami::QuickServiceController < ApplicationController #checked quick_service only @quick_service_only = false - lookup_dine_in = Lookup.collection_of('quickservice_add_order') - puts 'lookup_dine_in!!!!' - puts lookup_dine_in + lookup_dine_in = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quickservice_add_order') if !lookup_dine_in.empty? lookup_dine_in.each do |dine_in| if dine_in[0].downcase == "quickserviceaddorder" @@ -121,7 +115,7 @@ class Origami::QuickServiceController < ApplicationController order.table_id = params[:table_id] # this is dining facilities's id order.waiters = current_login_employee.name order.employee_name = current_login_employee.name - + order.is_extra_time = is_extra_time order.extra_time = extra_time diff --git a/app/controllers/origami/redeem_payments_controller.rb b/app/controllers/origami/redeem_payments_controller.rb index c0edf879..4a2d867a 100755 --- a/app/controllers/origami/redeem_payments_controller.rb +++ b/app/controllers/origami/redeem_payments_controller.rb @@ -2,18 +2,18 @@ class Origami::RedeemPaymentsController < BaseOrigamiController def index @sale_id = params[:sale_id] payment_method = params[:payment_method] - @cashier_type = params[:type] + @cashier_type = params[:type] @membership_rebate_balance=0 sale_data = Sale.find_by_sale_id(@sale_id) - @shop = Shop.first + # @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total - # @rounding_adj = sale_data.rounding_adjustment + @rounding_adj = new_total-sale_data.grand_total + # @rounding_adj = sale_data.rounding_adjustment @payparcount = 0 others = 0 @@ -68,5 +68,5 @@ class Origami::RedeemPaymentsController < BaseOrigamiController end @out = false, 0 end - + end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 6d36f319..c23d4964 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -8,7 +8,7 @@ class Origami::RequestBillsController < ApplicationController end # Print Request Bill and add to sale tables def print - if !ShiftSale.current_shift.nil? + if !ShiftSale.current_shift(@shop.shop_code).nil? order_id = params[:id] # order_id order = Order.find(order_id) booking = order.booking @@ -45,7 +45,7 @@ class Origami::RequestBillsController < ApplicationController sale_audit = SaleAudit.record_audit_sale(sale_data.sale_id,remark,action_by,type ) # Promotion Activation - Promotion.promo_activate(sale_data) + Promotion.promo_activate(sale_data,@shop.shop_code) #bill channel if ENV["SERVER_MODE"] == 'cloud' @@ -62,14 +62,14 @@ class Origami::RequestBillsController < ApplicationController render :json => result.to_json else #check checkInOut pdf print - checkout_time = Lookup.collection_of('checkout_time') + checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time') if !booking.dining_facility_id.nil? terminal = DiningFacility.find_by_id(booking.dining_facility_id) cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id) if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server unique_code = "CheckInOutPdf" - printer = PrintSetting.find_by_unique_code(unique_code) + printer = PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) # print when complete click order_queue_printer = Printer::OrderQueuePrinter.new(printer) diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 80eb5641..c7c19930 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -2,37 +2,35 @@ class Origami::RoomsController < BaseOrigamiController def index @tables = Table.unscoped.all.active.order('status desc') @rooms = Room.unscoped.all.active.order('status desc') - @complete = Sale.completed_sale("cashier") + @complete = Sale.completed_sale("cashier",@shop.shop_code) @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') - @shift = ShiftSale.current_open_shift(current_user.id) + @shift = ShiftSale.current_open_shift(current_user) @webview = false if check_mobile - @webview = true + @webview = true end end def show @webview = false if check_mobile - @webview = true + @webview = true end - + @tables = Table.unscoped.all.active.order('status desc') @rooms = Room.unscoped.all.active.order('status desc') - @complete = Sale.completed_sale("cashier") + @complete = Sale.completed_sale("cashier",@shop.shop_code) @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @customers = Customer.pluck("customer_id, name") @room = DiningFacility.find(params[:room_id]) - @shift = ShiftSale.current_open_shift(current_user.id) - + @shift = ShiftSale.current_open_shift(current_user) + @status_order = "" @status_sale = "" @sale_array = Array.new + @membership = MembershipSetting.find_by_shop_code(@shop.shop_code) + @payment_methods = PaymentMethodSetting.find_by_shop_code(@shop.shop_code) - @shop = Shop.first - @membership = MembershipSetting::MembershipSetting - @payment_methods = PaymentMethodSetting.all - @dining_room = @room.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ") @order_items = Array.new @dining_room.each do |booking| @@ -91,7 +89,7 @@ class Origami::RoomsController < BaseOrigamiController @account_arr.push(account) end end - + @sale_taxes = [] sale_taxes = SaleTax.where("sale_id = ?", sale.sale_id) if !sale_taxes.empty? @@ -105,7 +103,7 @@ class Origami::RoomsController < BaseOrigamiController # @room.bookings.each do |booking| # if booking.sale_id.nil? # @order_items = Array.new - + # booking.booking_orders.each do |booking_order| # order = Order.find(booking_order.order_id) # @obj = order @@ -148,7 +146,7 @@ class Origami::RoomsController < BaseOrigamiController lookup_edit_order = Lookup.collection_of('edit_order') if !lookup_edit_order.empty? lookup_edit_order.each do |edit_order| - if edit_order[0].downcase == "editorderorigami" + if edit_order[0].downcase == "editorderorigami" if edit_order[1] == '0' && (current_login_employee.role == 'cashier' || current_login_employee.role == 'waiter') @edit_order_origami = false end @@ -161,8 +159,8 @@ class Origami::RoomsController < BaseOrigamiController lookup_changable_tax = Lookup.collection_of('changable_tax') if !lookup_changable_tax.empty? lookup_changable_tax.each do |changable_tax| - if changable_tax[0].downcase == "change" - if changable_tax[1] == '0' + if changable_tax[0].downcase == "change" + if changable_tax[1] == '0' @changable_tax = false end end diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 7f456f35..7c9ec35e 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -163,9 +163,9 @@ class Origami::SaleEditController < BaseOrigamiController # end # end - sale.compute_by_sale_items(saleObj.total_discount, nil, order_source) + sale.compute_by_sale_items(sale.total_discount, nil, order_source) - ProductCommission.edit_product_commission(saleitemObj) + ProductCommission.edit_product_commission(saleitemObj,sale.shop_code) end # make cancel void item @@ -195,7 +195,7 @@ class Origami::SaleEditController < BaseOrigamiController end remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}" sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"ITEMCANCELVOID" ) - + saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source) ProductCommission.remove_product_commission(saleitemObj) end diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index d2af3258..4e20e293 100755 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -7,7 +7,7 @@ class Origami::SalesController < BaseOrigamiController @tables = Table.unscoped.all.active.order('status desc') @rooms = Room.unscoped.all.active.order('status desc') - @complete = Sale.completed_sale("cashier") + @complete = Sale.completed_sale("cashier",@shop.shop_code) @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @customers = Customer.pluck("customer_id, name") @sale = Sale.find(params[:sale_id]) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index f28c1428..679dbb14 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -4,7 +4,7 @@ class Origami::ShiftsController < BaseOrigamiController def show @cashier_type = params[:type] - @shift = ShiftSale.current_open_shift(current_user.id) + @shift = ShiftSale.current_open_shift(current_user) #for bank integration bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 @@ -56,7 +56,7 @@ class Origami::ShiftsController < BaseOrigamiController cashier_terminal.save #add shift_sale_id to card_settle_trans - bank_integration = Lookup.find_by_lookup_type('bank_integration') + bank_integration = Lookup.find_by_lookup_type_and_shop_code('bank_integration',@shop.shop_code) if !bank_integration.nil? card_settle_trans = CardSettleTran.select('id').where(['shift_sale_id IS NULL and status IS NOT NULL']) @@ -74,7 +74,7 @@ class Origami::ShiftsController < BaseOrigamiController # if !close_cashier_print[0].nil? # @close_cashier_print = close_cashier_print[0][1] # end - close_cashier_pdf = Lookup.collection_of("print_settings") + close_cashier_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") unique_code = "CloseCashierPdf" if !close_cashier_pdf.empty? @@ -92,7 +92,7 @@ class Origami::ShiftsController < BaseOrigamiController #get tax shift_obj = ShiftSale.where('id =?',@shift.id) sale_items = '' - @lookup = Lookup.shift_sale_items_lookup_value + @lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code) if @lookup.to_i == 1 @sale_items = Sale.get_shift_sale_items(@shift.id) other_charges = Sale.get_other_charges() @@ -129,7 +129,7 @@ class Origami::ShiftsController < BaseOrigamiController end end end - Employee.logout(session[:session_token]) + Employee.logout(@shop,session[:session_token]) session[:session_token] = nil end @@ -137,7 +137,7 @@ class Origami::ShiftsController < BaseOrigamiController end def sale_summary - @shift = ShiftSale.current_open_shift(current_user.id) + @shift = ShiftSale.current_open_shift(current_user) # @shift = ShiftSale.find_by_id(shift_id) if @shift diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index fb6db35f..a80a3a4d 100755 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -100,7 +100,7 @@ class Origami::SplitBillController < BaseOrigamiController end status = false - if !ShiftSale.current_shift.nil? + if !ShiftSale.current_shift(@shop.shop_code).nil? #create Bill by Booking ID table = 0 if !params[:booking_id].empty? @@ -133,7 +133,8 @@ class Origami::SplitBillController < BaseOrigamiController booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type, :checkin_at => Time.now.utc, :checkin_by => current_user.name, - :booking_status => "assign" }) + :booking_status => "assign", + :shop_code =>@shop.shop_code}) if !orders.nil? orders.each do |order| @@ -333,7 +334,7 @@ class Origami::SplitBillController < BaseOrigamiController end end - Promotion.promo_activate(sale_data) + Promotion.promo_activate(sale_data,@shop.shop_code) if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain else @@ -358,6 +359,7 @@ class Origami::SplitBillController < BaseOrigamiController order.waiters = current_user.name order.employee_name = current_user.name order.guest_info = nil + order.shop_code = @shop.shop_code order.save! return order @@ -410,10 +412,4 @@ class Origami::SplitBillController < BaseOrigamiController render :json => { status: true } end - #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end - end diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index 700159bb..be8d6b1c 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -2,9 +2,9 @@ class Origami::SurveysController < BaseOrigamiController def new @webview = false if check_mobile - @webview = true + @webview = true end - + @survey = Survey.new @id = params[:id] @cashier_type = params[:type] @@ -18,8 +18,8 @@ class Origami::SurveysController < BaseOrigamiController if @booking.dining_facility_id.to_i>0 @dining_facility = DiningFacility.find(@booking.dining_facility_id) @table_type = @dining_facility.type - @survey_data = Survey.find_by_dining_name(@dining_facility.name) - survey_process = Survey.find_by_receipt_no(@receipt_no) + @survey_data = Survey.find_by_dining_name_and_shop_code(@dining_facility.name,@shop.shop_code) + survey_process = Survey.find_by_receipt_no_and_shop_code(@receipt_no,@shop.shop_code) if !survey_process.nil? @survey_data = survey_process end @@ -27,14 +27,14 @@ class Origami::SurveysController < BaseOrigamiController @dining_facility = nil @table_type = nil end - + else @dining_facility = DiningFacility.find(@id) @table_type = @dining_facility.type @receipt_no = nil @grand_total = nil - @survey_data = Survey.find_by_dining_name_and_receipt_no(@dining_facility.name,nil) - end + @survey_data = Survey.find_by_dining_name_and_receipt_no_and_shop_code(@dining_facility.name,nil,@shop.shop_code) + end end def create @@ -43,38 +43,40 @@ class Origami::SurveysController < BaseOrigamiController if params[:table_id].to_i>0 @dining_facility = DiningFacility.find(params[:table_id]) if params[:sale_id].to_i > 0 - # cashier_zone = CashierTerminalByZone.find_by_zone_id(@dining_facility.zone_id) - # shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) - # set cashier - open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") - current_shift = ShiftSale.current_shift - if open_cashier.count>0 - shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0].id) - else - shift_by_terminal = ShiftSale.current_open_shift(current_shift.employee_id) - end - else - sale = Sale.find(@sale_id) - shift = ShiftSale.find(sale.shift_sale_id) - shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(shift.cashier_terminal_id,nil) - end + # cashier_zone = CashierTerminalByZone.find_by_zone_id(@dining_facility.zone_id) + # shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) + # set cashier + open_cashier = Employee.where("role = 'cashier' AND token_session <> '' and shop_code='#{@shop.shop_code}'") + current_shift = ShiftSale.current_shift(@shop.shop_code) + current_shift_user =Employee.find_by_id(current_user.employee_id) + if open_cashier.count>0 + shift_by_terminal = ShiftSale.current_open_shift(open_cashier[0]) + else + shift_by_terminal = ShiftSale.current_open_shift(current_shift_user) + end + else + sale = Sale.find(@sale_id) + shift = ShiftSale.find(sale.shift_sale_id) + shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(shift.cashier_terminal_id,nil) + end else sale = Sale.find(@sale_id) - shift = ShiftSale.find(sale.shift_sale_id) + shift = ShiftSale.find(sale.shift_sale_id) shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(shift.cashier_terminal_id,nil) end - + if @type == "quick_service" || @type == "food_court" @url = "/origami/sale/"+@sale_id+"/"+@type+"/payment" else @url = "/origami/"+@dining_facility.type.downcase+"/"+params[:table_id] end - + if params[:survey_id].nil? || params[:survey_id] == "" @survey = Survey.new(survey_params) @survey.shift_id = shift_by_terminal.id @survey.foreigner = params["survey"]["foreigner"].to_json + @survey.shop_code = @shop.shop_code # respond_to do |format| if @survey.save redirect_to @url @@ -106,5 +108,5 @@ class Origami::SurveysController < BaseOrigamiController def survey_params params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount,:survey_id) end - + end diff --git a/app/controllers/origami/table_invoices_controller.rb b/app/controllers/origami/table_invoices_controller.rb index 7082e44c..a5d72b1e 100755 --- a/app/controllers/origami/table_invoices_controller.rb +++ b/app/controllers/origami/table_invoices_controller.rb @@ -1,7 +1,7 @@ class Origami::TableInvoicesController < BaseOrigamiController def index @table = DiningFacility.find(params[:table_id]) - shop = Shop.first + # shop = Shop.first puts "table bookig lenght" @sale_array = Array.new @table.bookings.each do |booking| @@ -11,7 +11,7 @@ class Origami::TableInvoicesController < BaseOrigamiController else sale = Sale.find(booking.sale_id) # rounding adjustment - if shop.is_rounding_adj + if @shop.is_rounding_adj a = sale.grand_total % 25 # Modulus b = sale.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even @@ -32,16 +32,17 @@ class Origami::TableInvoicesController < BaseOrigamiController def show # puts 'Catch me if you can.......................' @table = DiningFacility.find(params[:table_id]) - @membership = MembershipSetting::MembershipSetting - @payment_methods = PaymentMethodSetting.all - shop = Shop.first + @membership = MembershipSetting.find_by_shop_code(@shop.shop_code) + @payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'") + + # shop = Shop.first @sale_array = Array.new @table.bookings.each do |booking| if booking.sale_id.nil? else sale = Sale.find(booking.sale_id) # rounding adjustment - if shop.is_rounding_adj + if @shop.is_rounding_adj a = sale.grand_total % 25 # Modulus b = sale.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even @@ -49,7 +50,7 @@ class Origami::TableInvoicesController < BaseOrigamiController if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) new_total = Sale.get_rounding_adjustment(sale.grand_total) sale.rounding_adjustment = new_total-sale.grand_total - sale.update_attributes(grand_total: new_total,old_grand_total: sale.grand_total,rounding_adjustment:sale.rounding_adjustment) + sale.update_attributes(grand_total: new_total,old_grand_total: sale.grand_total,rounding_adjustment:sale.rounding_adjustment) end end #end rounding adjustment @@ -64,7 +65,7 @@ class Origami::TableInvoicesController < BaseOrigamiController @status_sale = 'sale' @customer = @sale.customer #for split bill - lookup_spit_bill = Lookup.collection_of('split_bill') + lookup_spit_bill = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('split_bill') @split_bill = 0 if !lookup_spit_bill[0].nil? @split_bill = lookup_spit_bill[0][1] diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb index b351d40a..aaa05922 100644 --- a/app/controllers/origami/unionpay_controller.rb +++ b/app/controllers/origami/unionpay_controller.rb @@ -11,7 +11,7 @@ class Origami::UnionpayController < BaseOrigamiController end total = 0 @unionpaycount = 0 - @shop = Shop.first + # @shop = Shop.first @rounding_adj = 0 @can_unionpay = 0 @member_discount = 0 @@ -21,13 +21,13 @@ class Origami::UnionpayController < BaseOrigamiController if !sale_data.nil? total = sale_data.grand_total others = 0 - + if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total + @rounding_adj = new_total-sale_data.grand_total if path.include? ("credit_payment") sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) else @@ -61,15 +61,15 @@ class Origami::UnionpayController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first - + # shop_details = Shop.first + # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end - + # saleObj = Sale.find(sale_id) #end rounding adjustment path = request.fullpath @@ -83,8 +83,8 @@ class Origami::UnionpayController < BaseOrigamiController end #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end + # helper_method :shop_detail + # def shop_detail + # @shop = Shop.first + # end end diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb index c50339e4..7463e271 100644 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -11,7 +11,7 @@ class Origami::VisaController < BaseOrigamiController end total = 0 @visacount = 0 - @shop = Shop.first + # @shop = Shop.first @rounding_adj = 0 @can_visa = 0 @member_discount = 0 @@ -19,7 +19,7 @@ class Origami::VisaController < BaseOrigamiController @membership_id = nil @receipt_no = nil if !sale_data.nil? - total = sale_data.grand_total + total = sale_data.grand_total others = 0 if @shop.is_rounding_adj @@ -27,7 +27,7 @@ class Origami::VisaController < BaseOrigamiController else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total + @rounding_adj = new_total-sale_data.grand_total if path.include? ("credit_payment") sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) else @@ -61,15 +61,15 @@ class Origami::VisaController < BaseOrigamiController ref_no = params[:ref_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - shop_details = Shop.first - + # shop_details = Shop.first + # rounding adjustment # if shop_details.is_rounding_adj # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) # rounding_adj = new_total-saleObj.grand_total - # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) # end - + # saleObj = Sale.find(sale_id) #end rounding adjustment path = request.fullpath @@ -83,8 +83,8 @@ class Origami::VisaController < BaseOrigamiController end #Shop Name in Navbor - helper_method :shop_detail - def shop_detail - @shop = Shop.first - end + # helper_method :shop_detail + # def shop_detail + # @shop = Shop.first + # end end diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 5352b7c3..5f5b5352 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -73,7 +73,7 @@ class Origami::VoidController < BaseOrigamiController # FOr Sale Audit action_by = current_user.name if access_code != "null" && current_user.role == "cashier" - action_by = Employee.find_by_emp_id(access_code).name + action_by = Employee.find_by_emp_id_and_shop_code(access_code,@shop.shop_code).name end # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" @@ -115,10 +115,8 @@ class Origami::VoidController < BaseOrigamiController customer= Customer.find(sale.customer_id) - #shop detail - shop_details = current_shop # get member information - rebate = MembershipSetting.find_by_rebate(1) + rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code) if customer.membership_id != nil && rebate member_info = Customer.get_member_account(customer) rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) @@ -126,7 +124,7 @@ class Origami::VoidController < BaseOrigamiController current_balance = 0 end - printer = PrintSetting.all + printer = PrintSetting.where("shop_code='#{@shop.shop_code}'") unique_code="ReceiptBillPdf" if !printer.empty? @@ -141,13 +139,13 @@ class Origami::VoidController < BaseOrigamiController end end # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) # Calculate Food and Beverage Total item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) other_amount = SaleItem.calculate_other_charges(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "VOID",current_balance,nil,other_amount,nil,nil,nil) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/origami/voucher_controller.rb b/app/controllers/origami/voucher_controller.rb index e512a48b..671eb9fc 100755 --- a/app/controllers/origami/voucher_controller.rb +++ b/app/controllers/origami/voucher_controller.rb @@ -8,14 +8,14 @@ class Origami::VoucherController < BaseOrigamiController @vouchercount = 0 others = 0 - @shop = Shop.first + # @shop = Shop.first if @shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total end - @rounding_adj = new_total-sale_data.grand_total - + @rounding_adj = new_total-sale_data.grand_total + sale_data.sale_payments.each do |sale_payment| if sale_payment.payment_method == "voucher" @vouchercount = @vouchercount + sale_payment.payment_amount diff --git a/app/controllers/origami/waste_spoile_controller.rb b/app/controllers/origami/waste_spoile_controller.rb index 6a68a2b9..82c63d80 100755 --- a/app/controllers/origami/waste_spoile_controller.rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -55,7 +55,7 @@ class Origami::WasteSpoileController < BaseOrigamiController # FOr Sale Audit action_by = current_user.name if access_code != "null" && current_user.role == "cashier" - action_by = Employee.find_by_emp_id(access_code).name + action_by = Employee.find_by_emp_id_and_shop_code(access_code,@shop.shop_code).name end # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,remark ) @@ -88,10 +88,8 @@ class Origami::WasteSpoileController < BaseOrigamiController # unique_code = "ReceiptBillPdf" customer= Customer.find(sale.customer_id) - #shop detail - shop_details = current_shop # get member information - rebate = MembershipSetting.find_by_rebate(1) + rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code) if customer.membership_id != nil && rebate member_info = Customer.get_member_account(customer) rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) @@ -99,7 +97,7 @@ class Origami::WasteSpoileController < BaseOrigamiController current_balance = 0 end - printer = PrintSetting.all + printer = PrintSetting.where("shop_code='#{@shop.shop_code}'") unique_code="ReceiptBillPdf" if !printer.empty? @@ -115,13 +113,13 @@ class Origami::WasteSpoileController < BaseOrigamiController end # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) # Calculate Food and Beverage Total item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) other_amount = SaleItem.calculate_other_charges(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, remark,current_balance,nil,other_amount,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, remark,current_balance,nil,other_amount,nil,nil,nil) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/print_settings_controller.rb b/app/controllers/print_settings_controller.rb index c1e13727..0d8c5280 100755 --- a/app/controllers/print_settings_controller.rb +++ b/app/controllers/print_settings_controller.rb @@ -11,7 +11,7 @@ class PrintSettingsController < ApplicationController # GET /print_settings/1 # GET /print_settings/1.json def show - @lookup = Lookup.shift_sale_items_lookup_value + @lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code) end # GET /print_settings/new @@ -22,7 +22,7 @@ class PrintSettingsController < ApplicationController # GET /print_settings/1/edit def edit - @lookup = Lookup.shift_sale_items_lookup_value + @lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code) @server_mode = ENV["SERVER_MODE"] end @@ -30,7 +30,7 @@ class PrintSettingsController < ApplicationController # POST /print_settings.json def create @print_setting = PrintSetting.new(print_setting_params) - + @print_setting.shop_code = @shop.shop_code respond_to do |format| if @print_setting.save format.html { redirect_to @print_setting, notice: 'Print setting was successfully created.' } @@ -48,7 +48,7 @@ class PrintSettingsController < ApplicationController respond_to do |format| if @print_setting.update(print_setting_params) if @print_setting.unique_code == 'CloseCashierPdf' - Lookup.save_shift_sale_items_settings(params[:shift_sale_items]) + Lookup.save_shift_sale_items_settings(params[:shift_sale_items],@shop.shop_code) end format.html { redirect_to @print_setting, notice: 'Print setting was successfully updated.' } @@ -68,8 +68,8 @@ class PrintSettingsController < ApplicationController render :json => {:status=> "Success", :url => print_settings_url }.to_json end - def get_printer_options - printer_name = params[:printer_name] + def get_printer_options + printer_name = params[:printer_name] printer_options = Printer::PrinterWorker.printer_options(printer_name) options = { :url => printer_options['device-uri'], diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index eeff4bf0..4aa1b1df 100755 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -24,9 +24,9 @@ authorize_resource :class => false end end - @lookup = Lookup.find_by_lookup_type('reprint_receipt') + @lookup = Lookup.find_by_lookup_type_and_shop_code('reprint_receipt',@shop.shop_code) if @lookup.nil? - @lookup = Lookup.create_reprint_receipt_lookup + @lookup = Lookup.create_reprint_receipt_lookup(@shop.shop_code) end payment_type = params[:payment_type] @@ -152,7 +152,7 @@ authorize_resource :class => false # else # table = DiningFacility.find(bookings[0].dining_facility_id) # end - shift = ShiftSale.current_open_shift(current_user.id) + shift = ShiftSale.current_open_shift(current_user) if !shift.nil? cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) else diff --git a/app/controllers/settings/accounts_controller.rb b/app/controllers/settings/accounts_controller.rb index b192c24d..d46ba093 100755 --- a/app/controllers/settings/accounts_controller.rb +++ b/app/controllers/settings/accounts_controller.rb @@ -5,7 +5,7 @@ class Settings::AccountsController < ApplicationController # GET /settings/accounts # GET /settings/accounts.json def index - @settings_accounts = Account.all + @settings_accounts = Account.all.where("shop_code='#{@shop.shop_code}'") end # GET /settings/accounts/1 @@ -26,6 +26,7 @@ class Settings::AccountsController < ApplicationController # POST /settings/accounts.json def create @settings_account = Account.new(account_params) + @settings_account.shop_code = @shop.shop_code respond_to do |format| if @settings_account.save format.html { redirect_to settings_accounts_url, notice: 'Account was successfully created.' } diff --git a/app/controllers/settings/cashier_terminals_controller.rb b/app/controllers/settings/cashier_terminals_controller.rb index 1d1c5497..29fe202f 100755 --- a/app/controllers/settings/cashier_terminals_controller.rb +++ b/app/controllers/settings/cashier_terminals_controller.rb @@ -28,7 +28,7 @@ class Settings::CashierTerminalsController < ApplicationController # POST /settings/cashier_terminals.json def create @settings_cashier_terminal = CashierTerminal.new(settings_cashier_terminal_params) - + @settings_cashier_terminal.shop_code = @shop.shop_code respond_to do |format| if @settings_cashier_terminal.save format.html { redirect_to settings_cashier_terminals_path, notice: 'Cashier terminal was successfully created.' } diff --git a/app/controllers/settings/commissioners_controller.rb b/app/controllers/settings/commissioners_controller.rb index bbaa1ca8..0f93545d 100755 --- a/app/controllers/settings/commissioners_controller.rb +++ b/app/controllers/settings/commissioners_controller.rb @@ -18,7 +18,7 @@ class Settings::CommissionersController < ApplicationController def new @commissioner = Commissioner.new @employee = Employee.all.order('name asc') - + end # GET /commissioners/1/edit @@ -30,6 +30,7 @@ class Settings::CommissionersController < ApplicationController def create @commissioner = Commissioner.new(commissioner_params) @commissioner.created_by = current_user.id + @commissioner.shop_code = @shop.shop_code unless @commissioner.joined_date.nil? @commissioner.joined_date = @commissioner.joined_date.utc.getlocal.strftime('%Y-%b-%d') end diff --git a/app/controllers/settings/commissions_controller.rb b/app/controllers/settings/commissions_controller.rb index 1ac6b2cc..519074c7 100755 --- a/app/controllers/settings/commissions_controller.rb +++ b/app/controllers/settings/commissions_controller.rb @@ -31,6 +31,7 @@ class Settings::CommissionsController < ApplicationController @commission = Commission.new(commission_params) @commission.product_type = 'menu_item' @commission.product_code = "[]" + @commission.shop_code = @shop.shop_code respond_to do |format| if @commission.save @@ -74,7 +75,7 @@ class Settings::CommissionsController < ApplicationController redirect_to root_path end end - + private # Use callbacks to share common setup or constraints between actions. def set_commission diff --git a/app/controllers/settings/employees_controller.rb b/app/controllers/settings/employees_controller.rb index c416cc87..5c9dae6f 100755 --- a/app/controllers/settings/employees_controller.rb +++ b/app/controllers/settings/employees_controller.rb @@ -31,7 +31,7 @@ class Settings::EmployeesController < ApplicationController # POST /employees.json def create @employee = Employee.new(employee_params) - + @employee.shop_code = @shop.shop_code respond_to do |format| if @employee.save format.html { redirect_to settings_employees_path, notice: 'Employee was successfully created.' } diff --git a/app/controllers/settings/lookups_controller.rb b/app/controllers/settings/lookups_controller.rb index 8eb98aed..87c81842 100755 --- a/app/controllers/settings/lookups_controller.rb +++ b/app/controllers/settings/lookups_controller.rb @@ -25,7 +25,7 @@ class Settings::LookupsController < ApplicationController # POST /settings/lookups.json def create @settings_lookup = Lookup.new(settings_lookup_params) - + @settings_lookup.shop_code = @shop.shop_code respond_to do |format| if @settings_lookup.save format.html { redirect_to settings_lookups_path, notice: 'Lookup was successfully created.' } diff --git a/app/controllers/settings/membership_actions_controller.rb b/app/controllers/settings/membership_actions_controller.rb index ea8d903b..0f1b8c93 100755 --- a/app/controllers/settings/membership_actions_controller.rb +++ b/app/controllers/settings/membership_actions_controller.rb @@ -26,7 +26,7 @@ class Settings::MembershipActionsController < ApplicationController # POST /settings/membership_actions.json def create @settings_membership_action = MembershipAction.new(settings_membership_action_params) - + @settings_membership_action.shop_code = @shop.shop_code respond_to do |format| if @settings_membership_action.save format.html { redirect_to settings_membership_actions_path, notice: 'Membership action was successfully created.' } diff --git a/app/controllers/settings/membership_settings_controller.rb b/app/controllers/settings/membership_settings_controller.rb index 48f601db..698c755c 100755 --- a/app/controllers/settings/membership_settings_controller.rb +++ b/app/controllers/settings/membership_settings_controller.rb @@ -26,7 +26,7 @@ class Settings::MembershipSettingsController < ApplicationController # POST /settings/membership_settings.json def create @settings_membership_setting = MembershipSetting.new(settings_membership_setting_params) - + @settings_membership_setting.shop_code = @shop.shop_code respond_to do |format| if @settings_membership_setting.save format.html { redirect_to settings_membership_settings_path, notice: 'Membership setting was successfully created.' } diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index cccc6dc7..d7cb6b8a 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -5,7 +5,7 @@ class Settings::MenusController < ApplicationController # GET /settings/menus # GET /settings/menus.json def index - @settings_menus = Menu.all.page(params[:page]).per(10) + @settings_menus = Menu.all.where("shop_code='#{@shop.shop_code}'").page(params[:page]).per(10) respond_to do |format| format.html format.xlsx @@ -32,6 +32,7 @@ class Settings::MenusController < ApplicationController def create @settings_menu = Menu.new(settings_menu_params) @settings_menu.created_by = current_login_employee.name + @settings_menu.shop_code = @shop.shop_code respond_to do |format| if @settings_menu.save format.html { redirect_to settings_menus_path, notice: 'Menu was successfully created.' } @@ -73,7 +74,7 @@ class Settings::MenusController < ApplicationController end def export - @settings_menus = Menu.all.page(params[:page]).per(10) + @settings_menus = Menu.all.where("shop_code='#{@shop.shop_code}'").page(params[:page]).per(10) menu = Menu.find(params[:id]) p = Axlsx::Package.new @@ -93,17 +94,17 @@ class Settings::MenusController < ApplicationController :alignment => { :horizontal => :left, :vertical => :center , :header_text => true} - + # Menu Sheet wb.add_worksheet(name: menu.name,is_ordering: menu.is_ordering) do |sheet| - sheet.add_row ["Name",menu.name,"is_ordering",menu.is_ordering], :style=>title + sheet.add_row ["Name",menu.name,"is_ordering",menu.is_ordering], :style=>title sheet.add_row - sheet.add_row ["Category Code", "Category Name", "Item Code", "Item Name", "Account", "Item AltName", "Taxable", "Attributes", "Options", "Instance Code", "Instance Name", "Instance Attribute", "Price", "Is Default", "Image Path"], :style=>header_text + sheet.add_row ["Category Code", "Category Name", "Item Code", "Item Name", "Account", "Item AltName", "Taxable", "Attributes", "Options", "Instance Code", "Instance Name", "Instance Attribute", "Price", "Is Default", "Image Path"], :style=>header_text menu.menu_categories.each do |mc| - mc.menu_items.each do |mi| - attributes = "" - i=0 + mc.menu_items.each do |mi| + attributes = "" + i=0 if mi.item_attributes.length > 0 mi.item_attributes.each do |mia| attribute = MenuItemAttribute.find(mia) @@ -111,8 +112,8 @@ class Settings::MenusController < ApplicationController attributes = attributes + attribute.name else attributes = attributes + attribute.name + "," - end - i = i + 1 + end + i = i + 1 end end image_path = "" @@ -128,8 +129,8 @@ class Settings::MenusController < ApplicationController options = options + option.name else options = options + option.name + "," - end - i = i + 1 + end + i = i + 1 end end @@ -141,8 +142,8 @@ class Settings::MenusController < ApplicationController sheet.add_row [ mc.code, mc.name, mi.item_code, mi.name, mi.account.title, mi.alt_name, mi.taxable, attributes, options, mii.item_instance_code, mii.item_instance_name, attribute, mii.price, mii.is_default, image_path], :style=>wrap_text end end - end - end + end + end end directory_name = "public/menus" @@ -154,9 +155,9 @@ class Settings::MenusController < ApplicationController def import if params[:file] - status = Menu.import(params[:file], current_user.name) + status = Menu.import(params[:file], current_user.name,@shop) redirect_to settings_menus_path, notice: status - end + end end private diff --git a/app/controllers/settings/order_queue_stations_controller.rb b/app/controllers/settings/order_queue_stations_controller.rb index 1c4ceb3b..d28bdd91 100755 --- a/app/controllers/settings/order_queue_stations_controller.rb +++ b/app/controllers/settings/order_queue_stations_controller.rb @@ -32,6 +32,7 @@ class Settings::OrderQueueStationsController < ApplicationController @settings_order_queue_station = OrderQueueStation.new(settings_order_queue_station_params) @settings_order_queue_station.created_by = current_login_employee.name @settings_order_queue_station.processing_items = "[]" + @settings_order_queue_station.shop_code = @shop.shop_code respond_to do |format| if @settings_order_queue_station.save format.html { redirect_to settings_order_queue_stations_path, notice: 'Order queue station was successfully created.' } @@ -77,7 +78,7 @@ class Settings::OrderQueueStationsController < ApplicationController redirect_to root_path end end - + private # Use callbacks to share common setup or constraints between actions. def set_settings_order_queue_station diff --git a/app/controllers/settings/payment_method_settings_controller.rb b/app/controllers/settings/payment_method_settings_controller.rb index 46ad82d4..515bae9d 100755 --- a/app/controllers/settings/payment_method_settings_controller.rb +++ b/app/controllers/settings/payment_method_settings_controller.rb @@ -26,7 +26,7 @@ class Settings::PaymentMethodSettingsController < ApplicationController # POST /settings/payment_method_settings.json def create @settings_payment_method_setting = PaymentMethodSetting.new(settings_payment_method_setting_params) - + @settings_payment_method_settings.shop_code = @shop.shop_code respond_to do |format| if @settings_payment_method_setting.save format.html { redirect_to settings_payment_method_settings_path, notice: 'Payment method setting was successfully created.' } diff --git a/app/controllers/settings/products_controller.rb b/app/controllers/settings/products_controller.rb index 66e8f162..b473a54e 100755 --- a/app/controllers/settings/products_controller.rb +++ b/app/controllers/settings/products_controller.rb @@ -26,9 +26,10 @@ load_and_authorize_resource except: [:create] # POST /settings/products # POST /settings/products.json def create - + @settings_product = Product.new(settings_product_params) @settings_product.created_by = current_user.name + @settings_product.shop_code = @shop.shop_code respond_to do |format| if @settings_product.save format.html { redirect_to settings_products_path, notice: 'Product was successfully created.' } @@ -71,7 +72,7 @@ load_and_authorize_resource except: [:create] redirect_to root_path end end - + private # Use callbacks to share common setup or constraints between actions. def set_settings_product diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index 123f01d8..9f3c8fcf 100755 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -30,6 +30,7 @@ class Settings::PromotionsController < ApplicationController def create @promotion = Promotion.new(promotion_params) @promotion.created_by = current_login_employee.id + @promotion.shop_code = @shop.shop_code if !@promotion.promo_start_hour.nil? @promotion.promo_start_hour = @promotion.promo_start_hour.to_datetime.advance(hours: +6, minutes: +30) end @@ -126,7 +127,7 @@ class Settings::PromotionsController < ApplicationController redirect_to root_path end end - + private # Use callbacks to share common setup or constraints between actions. def set_promotion diff --git a/app/controllers/settings/rooms_controller.rb b/app/controllers/settings/rooms_controller.rb index ef127e2b..35e4fcb5 100755 --- a/app/controllers/settings/rooms_controller.rb +++ b/app/controllers/settings/rooms_controller.rb @@ -29,6 +29,7 @@ class Settings::RoomsController < ApplicationController @settings_room.type = DiningFacility::ROOM_TYPE @settings_room.zone_id = params[:zone_id] @settings_room.created_by = current_login_employee.name + @settings_room.shop_code = @shop.shop_code respond_to do |format| if @settings_room.save format.html { redirect_to settings_zone_path(@zone), notice: 'Room was successfully created.' } diff --git a/app/controllers/settings/shops_controller.rb b/app/controllers/settings/shops_controller.rb index 598e4f9b..ab492bdf 100644 --- a/app/controllers/settings/shops_controller.rb +++ b/app/controllers/settings/shops_controller.rb @@ -56,9 +56,9 @@ class Settings::ShopsController < ApplicationController audio_data = @settings_shop.display_images.find_by_name("order_audio").image delete_path = Rails.root.join("public/#{audio_data}") if File.exists?(delete_path) - File.delete(delete_path) - end - end + File.delete(delete_path) + end + end save_path = Rails.root.join("public/#{current_shop.shop_code}_#{a.original_filename}") File.open(save_path, 'wb') do |f| f.write a.read diff --git a/app/controllers/settings/tables_controller.rb b/app/controllers/settings/tables_controller.rb index f0f5f4ac..91f35eed 100755 --- a/app/controllers/settings/tables_controller.rb +++ b/app/controllers/settings/tables_controller.rb @@ -28,6 +28,7 @@ class Settings::TablesController < ApplicationController @settings_table = Table.new(settings_table_params) @settings_table.type = DiningFacility::TABLE_TYPE @settings_table.zone_id = params[:zone_id] + @settings_table.shop_code = @shop.shop_code @settings_table.created_by = current_login_employee.name respond_to do |format| if @settings_table.save diff --git a/app/controllers/settings/tax_profiles_controller.rb b/app/controllers/settings/tax_profiles_controller.rb index 7357e21d..298d077d 100755 --- a/app/controllers/settings/tax_profiles_controller.rb +++ b/app/controllers/settings/tax_profiles_controller.rb @@ -47,7 +47,7 @@ class Settings::TaxProfilesController < ApplicationController def create @settings_tax_profile = TaxProfile.new(settings_tax_profile_params) @settings_tax_profile.created_by = current_login_employee.name - + @settings_tax_profile.shop_code = @shop.shop_code respond_to do |format| if @settings_tax_profile.save format.html { redirect_to settings_tax_profiles_path, notice: 'Tax profile was successfully created.' } diff --git a/app/controllers/settings/zones_controller.rb b/app/controllers/settings/zones_controller.rb index 63bd3439..22b5165d 100755 --- a/app/controllers/settings/zones_controller.rb +++ b/app/controllers/settings/zones_controller.rb @@ -5,7 +5,7 @@ class Settings::ZonesController < ApplicationController # GET /settings/zones # GET /settings/zones.json def index - @settings_zones = Zone.all + @settings_zones = Zone.all.where("shop_code='#{@shop.shop_code}' and is_active= true") end # GET /settings/zones/1 @@ -28,6 +28,7 @@ class Settings::ZonesController < ApplicationController # POST /settings/zones.json def create @settings_zone = Zone.new(settings_zone_params) + @settings_zone.shop_code =@shop.shop_code @settings_zone.created_by = current_login_employee.name respond_to do |format| if @settings_zone.save diff --git a/app/controllers/transactions/bookings_controller.rb b/app/controllers/transactions/bookings_controller.rb index f8a74a53..8bb56249 100644 --- a/app/controllers/transactions/bookings_controller.rb +++ b/app/controllers/transactions/bookings_controller.rb @@ -9,16 +9,16 @@ class Transactions::BookingsController < ApplicationController to = params[:to] if filter.nil? && from.nil? && to.nil? - @bookings = Booking.all.order("sale_id desc") + @bookings = Booking.where("shop_code='#{@shop.shop_code}'").order("sale_id desc") @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(20) else - booking = Booking.search(filter,from,to) + booking = Booking.search(filter,from,to).where("bookings.shop_code='#{@shop.shop_code}'") if booking.count > 0 - @bookings = booking + @bookings = booking @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(20) else @bookings = 0 - end + end end @receipt_no = filter @from = from @@ -33,7 +33,7 @@ class Transactions::BookingsController < ApplicationController # GET /transactions/bookings/1 # GET /transactions/bookings/1.json def show - + @booking = Booking.find(params[:id]) @order = nil @order_items = [] @@ -45,7 +45,7 @@ class Transactions::BookingsController < ApplicationController end if @booking.sale_id.present? @sale = Sale.find(@booking.sale_id) - end + end respond_to do |format| format.html # show.html.erb diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb index 83efc401..52c029d2 100755 --- a/app/controllers/transactions/sales_controller.rb +++ b/app/controllers/transactions/sales_controller.rb @@ -89,8 +89,8 @@ class Transactions::SalesController < ApplicationController # GET /transactions/sales/1 # GET /transactions/sales/1.json def show - @membership = MembershipSetting::MembershipSetting - @payment_methods = PaymentMethodSetting.where("is_active='1'") + @membership = MembershipSetting.find_by_shop_code(@shop.shop_code) + @payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}' and is_active='1'") @sale = Sale.find(params[:id]) @order_items = [] diff --git a/app/models/assigned_order_item.rb b/app/models/assigned_order_item.rb index c1b0162e..80036850 100755 --- a/app/models/assigned_order_item.rb +++ b/app/models/assigned_order_item.rb @@ -36,17 +36,18 @@ class AssignedOrderItem < ApplicationRecord assigned_order_item.order_queue_station = order_queue_station assigned_order_item.print_status = false assigned_order_item.delivery_status = false + assigned_order_item.shop_code =order.shop_code assigned_order_item.save! end def self.assigned_order_item_by_job(order_id) order_item = AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, - assigned_order_items.order_queue_station_id, - oqs.id as station_id, oqs.station_name, - oqs.is_active, oqpz.zone_id, - df.name as zone, df.type as table_type, - odt.order_id, odt.item_code, odt.item_instance_code, odt.item_name, - odt.price, odt.qty, odt.item_order_by, odt.options, + assigned_order_items.order_queue_station_id, + oqs.id as station_id, oqs.station_name, + oqs.is_active, oqpz.zone_id, + df.name as zone, df.type as table_type, + odt.order_id, odt.item_code, odt.item_instance_code, odt.item_name, + odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id diff --git a/app/models/booking.rb b/app/models/booking.rb index 9ca45ec4..2f85d211 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -127,4 +127,9 @@ class Booking < ApplicationRecord self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI") end end + def generate_custom_id + if self.booking_id.nil? + self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI") + end + end end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index e5f35e03..f947a0e8 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -32,9 +32,8 @@ class DiningFacility < ApplicationRecord end def get_current_booking - checkin_time_lookup = Lookup.get_checkin_time_limit - booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and (CASE WHEN checkin_at > '#{DateTime.now.utc}' THEN checkin_at >= '#{DateTime.now.utc}' ELSE checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' END) and checkout_by is null").limit(1) #and checkout_at is null - # booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_by is null").limit(1) #and checkout_at is null + checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code) + booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='assign' and (CASE WHEN checkin_at > '#{DateTime.now.utc}' THEN checkin_at >= '#{DateTime.now.utc}' ELSE checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' END) and checkout_by is null").limit(1) #and checkout_at is null if booking.count > 0 then return booking[0] else @@ -43,8 +42,8 @@ class DiningFacility < ApplicationRecord end def get_moved_booking - checkin_time_lookup = Lookup.get_checkin_time_limit - booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1) + checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code) + booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1) if booking.count > 0 then return booking[0] @@ -70,8 +69,8 @@ class DiningFacility < ApplicationRecord end def get_current_checkout_booking - checkin_time_lookup = Lookup.get_checkin_time_limit - booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null").limit(1) + checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code) + booking = Booking.where("shop_code='#{self.shop_code}' and dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null").limit(1) if booking.count > 0 then return booking[0] else @@ -82,7 +81,7 @@ class DiningFacility < ApplicationRecord def get_checkout_booking booking = self.get_current_checkout_booking if booking - lookup_checkout_time = Lookup.collection_of("checkout_alert_time") + lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time") free_time_min = 0 if !lookup_checkout_time.empty? now = Time.now.utc @@ -118,11 +117,11 @@ class DiningFacility < ApplicationRecord end def self.get_checkin_booking - checkin_time_lookup = Lookup.get_checkin_time_limit - bookings = Booking.where("booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null") + checkin_time_lookup = Lookup.get_checkin_time_limit(self.shop_code) + bookings = Booking.where("shop_code='#{self.shop_code}' and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - checkin_time_lookup.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null") arr_booking = Array.new if bookings - lookup_checkout_time = Lookup.collection_of("checkout_alert_time") + lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time") free_time_min = 0 if !lookup_checkout_time.empty? now = Time.now.utc diff --git a/app/models/employee.rb b/app/models/employee.rb index f27adf29..67aad0f6 100755 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -3,7 +3,6 @@ class Employee < ApplicationRecord has_many :commissioners has_many :shit_sales belongs_to :order_queue_station - validates_presence_of :name, :role validates_presence_of :password, :on => [:create] validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true @@ -20,9 +19,9 @@ class Employee < ApplicationRecord Employee.select("id, name").map { |e| [e.name, e.id] } end - def self.login(emp_id, password) - user = Employee.find_by_emp_id(emp_id) - expiry_time = login_expiry_time + def self.login(shop,emp_id, password) + user = Employee.find_by_emp_id_and_shop_code(emp_id,shop.shop_code) + expiry_time = login_expiry_time(shop) if (user) #user.authenticate(password) if (user.authenticate(password)) @@ -37,10 +36,10 @@ class Employee < ApplicationRecord end - def self.authenticate_by_token(session_token) + def self.authenticate_by_token(session_token,shop) if (session_token) - user = Employee.find_by_token_session(session_token) - expiry_time = login_expiry_time + user = Employee.find_by_token_session_and_shop_code(session_token,shop.shop_code) + expiry_time = login_expiry_time(shop) if user && user.session_expiry.utc > DateTime.now.utc #Extend the login time each time authenticatation take place @@ -55,9 +54,9 @@ class Employee < ApplicationRecord return false end - def self.logout(session_token) + def self.logout(shop,session_token) if (session_token) - user = Employee.find_by_token_session(session_token) + user = Employee.find_by_token_session_and_shop_code(session_token,shop.shop_code) if user user.token_session = nil @@ -73,9 +72,9 @@ class Employee < ApplicationRecord retry end - def self.login_expiry_time + def self.login_expiry_time(shop) expiry_time = 30 - login_expiry = Lookup.collection_of('expiry_time') + login_expiry = Lookup.where("shop_code='#{shop.shop_code}'").collection_of('expiry_time') if !login_expiry.empty? login_expiry.each do |exp_time| if exp_time[0].downcase == "login" diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index f2ed207d..b7ef3e44 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -8,7 +8,7 @@ class InventoryDefinition < ApplicationRecord logger.debug saleObj.sale_items.to_json if !saleObj.nil? saleObj.sale_items.each do |item| - found, inventory_definition = find_product_in_inventory(item) + found, inventory_definition = find_product_in_inventory(item,saleObj.shop_code) if found check_balance(item,inventory_definition) end @@ -23,7 +23,7 @@ class InventoryDefinition < ApplicationRecord end end - def self.find_product_in_inventory(item,instance_code) + def self.find_product_in_inventory(item,shop_code=nil) # unless instance_code.empty? # instance_code = instance_code.to_s # instance_code[0] = "" @@ -36,16 +36,15 @@ class InventoryDefinition < ApplicationRecord # puts "found prodcut+++++++++++++++++++++++++++++++++++===" # puts prod.to_json # end - - if product = InventoryDefinition.find_by_item_code(item.item_instance_code) - if stock_check_item = StockCheckItem.find_by_item_code(item.item_instance_code) + if product = InventoryDefinition.find_by_item_code_and_shop_code(item.item_instance_code,shop_code) + if stock_check_item = StockCheckItem.find_by_item_code_and_shop_code(item.item_instance_code,shop_code) return true, product end end end def self.check_balance(item, inventory_definition) # item => saleItemOBj - stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first + stock = StockJournal.where("shop_code='#{inventory_definition.shop_code}' and item_code=?", item.item_instance_code).order("id DESC").first unless stock.nil? modify_balance(item, stock, inventory_definition) else @@ -94,7 +93,7 @@ class InventoryDefinition < ApplicationRecord .order("mi.menu_category_id desc") end - def self.get_by_category(filter) + def self.get_by_category(shop,filter) # THEN (SELECT min(balance) FROM stock_journals # least_stock = "SELECT (CASE WHEN stock_journals.remark != 'out of stock' # THEN (SELECT balance FROM stock_journals @@ -123,9 +122,9 @@ class InventoryDefinition < ApplicationRecord " JOIN menu_items mi ON mi.id = mii.menu_item_id" + " JOIN menu_categories mc ON mc.id = mi.menu_category_id ") .joins(" JOIN accounts acc ON acc.id = mi.account_id") - .where("inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ? + .where("inventory_definitions.shop_code='#{shop.shop_code}' and (inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ? OR inventory_definitions.max_stock_level LIKE ? OR sj.balance LIKE ? OR mi.name LIKE ? - OR mii.item_instance_name LIKE ? OR mc.name LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%", + OR mii.item_instance_name LIKE ? OR mc.name LIKE ?)","%#{filter}%","%#{filter}%","%#{filter}%", "%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%") .group("mi.menu_category_id,inventory_definitions.item_code") .order("balance asc, mi.name asc,acc.title desc,mi.menu_category_id desc") diff --git a/app/models/lookup.rb b/app/models/lookup.rb index b446d4e8..5aaf3329 100755 --- a/app/models/lookup.rb +++ b/app/models/lookup.rb @@ -1,6 +1,7 @@ class Lookup < ApplicationRecord has_many :accounts + belongs_to :shop def available_types {'Employee Roles' => 'employee_roles', @@ -21,10 +22,10 @@ class Lookup < ApplicationRecord # Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] } # end - def self.get_checkin_time_limit + def self.get_checkin_time_limit(shop_code) time_limit = 5 - lookup = Lookup.find_by_lookup_type('checkin_time_limit') + lookup = Lookup.find_by_lookup_type_and_shop_code('checkin_time_limit',shop_code) if !lookup.nil? time_limit = lookup.value.to_i end @@ -59,39 +60,41 @@ class Lookup < ApplicationRecord end - def self.create_shift_sale_lookup + def self.create_shift_sale_lookup(shop_code) @lookup = Lookup.new @lookup.lookup_type = 'shift_sale_items' @lookup.name = 'Shift Sale Items' @lookup.value = 0 + @lookup.shop_code = shop_code @lookup.save return @lookup end - def self.create_reprint_receipt_lookup + def self.create_reprint_receipt_lookup(shop_code) @lookup = Lookup.new @lookup.lookup_type = 'reprint_receipt' @lookup.name = 'Reprint Receipt in Report' @lookup.value = 0 + @lookup.shop_code = shop_code @lookup.save return @lookup end - def self.save_shift_sale_items_settings(val) - @lookup = Lookup.where('lookup_type=?', 'shift_sale_items').last + def self.save_shift_sale_items_settings(val,shop_code) + @lookup = Lookup.where("shop_code='#{shop_code}' and lookup_type=?", 'shift_sale_items').last if @lookup.nil? - @lookup = Lookup.create_shift_sale_lookup + @lookup = Lookup.create_shift_sale_lookup(shop_code) end @lookup.value = val @lookup.save end - def self.shift_sale_items_lookup_value - @lookup = Lookup.where('lookup_type=?', 'shift_sale_items').last + def self.shift_sale_items_lookup_value(shop_code) + @lookup = Lookup.where("shop_code='#{shop_code}' and lookup_type=?", 'shift_sale_items').last if @lookup.nil? - @lookup = Lookup.create_shift_sale_lookup + @lookup = Lookup.create_shift_sale_lookup(shop_code) end return @lookup.value end diff --git a/app/models/membership_setting.rb b/app/models/membership_setting.rb index 9ab0ee96..a498526c 100755 --- a/app/models/membership_setting.rb +++ b/app/models/membership_setting.rb @@ -1,5 +1,5 @@ class MembershipSetting < ApplicationRecord scope :active, -> { where(is_active: true) } - MembershipSetting = MembershipSetting.find_by_id(1) + # MembershipSetting = MembershipSetting.find_by_id(1) end diff --git a/app/models/menu.rb b/app/models/menu.rb index a825cc7b..de60ef66 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -30,13 +30,13 @@ class Menu < ApplicationRecord cats = MenuCategory.where("menu_id=?",menu.id) cats.each do |cat| abc = MenuCategory.destroyCategory(cat) - end + end menu.destroy return false end def self.to_csv - m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at} + m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at} CSV.generate(headers: true, row_sep: "\r\n") do |csv| csv << m_attributes menu = Menu.all @@ -46,8 +46,8 @@ class Menu < ApplicationRecord end end - def self.import(file, created_by) - status = "" + def self.import(file, created_by,shop) + status = "" spreadsheet = open_spreadsheet(file) if spreadsheet.sheets.count > 1 sheet_count = spreadsheet.sheets.count-1 @@ -59,15 +59,15 @@ class Menu < ApplicationRecord row = Hash[[header,spreadsheet.sheet(i).row(ii)].transpose] if sheet_name == "Account" # Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) - account = Account.find_by_id(row["id"]) + account = Account.find_by_id(row["id"]) if account - Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) + Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"],shop_code: shop.shop_code) else - Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) + Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"],shop_code: shop.shop_code) end elsif sheet_name == "Item Set" # ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty]) - item_set = ItemSet.find_by_id(row["id"]) + item_set = ItemSet.find_by_id(row["id"]) if item_set ItemSet.create( name: row["name"], alt_name: row["alt_name"], min_selectable_qty: row["min_selectable_qty"], max_selectable_qty: row["max_selectable_qty"]) else @@ -92,9 +92,9 @@ class Menu < ApplicationRecord elsif sheet_name == "Menu" menu = Menu.find_by_id(row["id"]) if menu - Menu.create(name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"]) + Menu.create(name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"],shop_code: shop.shop_code) else - Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"]) + Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"],shop_code: shop.shop_code) end elsif sheet_name == "Menu Category" # MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) @@ -128,7 +128,7 @@ class Menu < ApplicationRecord else MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"]) end - elsif sheet_name == "Menu Item Set" + elsif sheet_name == "Menu Item Set" # MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"]) menu_item_set = MenuItemSet.find_by_id(row["id"]) if menu_item_set @@ -141,32 +141,26 @@ class Menu < ApplicationRecord end else # Menu by Menu Import - @shop = Shop.first - shop_code = "" - if !@shop.nil? - if @shop.shop_code - shop_code = @shop.shop_code + "_" - end - end + shop_code= shop.shop_code + "_" - sheet = spreadsheet.sheet(0) + sheet = spreadsheet.sheet(0) menu = sheet.row(1)[1] is_ordering = sheet.row(1)[3]?sheet.row(1)[3]:0 - imported_menu = Menu.create({name: menu, is_active: true, is_ordering: is_ordering, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by}) + imported_menu = Menu.create({name: menu, is_active: true, is_ordering: is_ordering, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by,shop_code: shop.shop_code}) - (4..sheet.last_row).each do |ii| - row = Hash[[sheet.row(3),sheet.row(ii)].transpose] - menu_cat = MenuCategory.find_by_code(row["Category Code"]) + (4..sheet.last_row).each do |ii| + row = Hash[[sheet.row(3),sheet.row(ii)].transpose] + menu_cat = MenuCategory.find_by_code(row["Category Code"]) if !menu_cat - menu_cat = MenuCategory.create({menu_id: imported_menu.id, code: row["Category Code"], name: row["Category Name"], alt_name: '', order_by: (ii - 3), created_by: created_by, menu_category_id: nil, is_available: 1}) + menu_cat = MenuCategory.create({menu_id: imported_menu.id, code: row["Category Code"], name: row["Category Name"], alt_name: '', order_by: (ii - 3), created_by: created_by, menu_category_id: nil, is_available: 1}) end # Menu Item Attributes item_attrs = [] if !row["Attributes"].nil? attributes = row["Attributes"].split(',') - attributes.each do |attr| + attributes.each do |attr| attribute = MenuItemAttribute.find_by_name(attr) if attribute.nil? attribute = MenuItemAttribute.create({ attribute_type:"any", name: attr.capitalize, value: attr.downcase }) @@ -188,11 +182,11 @@ class Menu < ApplicationRecord end end - menu_itm = MenuItem.find_by_item_code(row["Item Code"]) + menu_itm = MenuItem.find_by_item_code(row["Item Code"]) if !menu_itm account = Account.find_by_title(row["Account"]) if account.nil? - account = Account.create({title: row["Account"], account_type: "0"}) + account = Account.create({title: row["Account"], account_type: "0",shop_code: shop.shop_code}) end image_path = "" @@ -205,22 +199,22 @@ class Menu < ApplicationRecord end instance_attr = [] - menu_inst = MenuItemInstance.find_by_item_instance_code(row["Instance Code"]) + menu_inst = MenuItemInstance.find_by_item_instance_code(row["Instance Code"]) if !menu_inst instance_name = '' - if !row["Instance Name"].nil? + if !row["Instance Name"].nil? instance_name = row["Instance Name"] end if !row["Attributes"].nil? - if !row["Instance Attribute"].nil? + if !row["Instance Attribute"].nil? attributes = row["Attributes"].split(',') instance_attributes = row["Instance Attribute"].split(',') - attributes.each do |attr| + attributes.each do |attr| if attr == instance_attributes[0] ins_attr = MenuItemAttribute.find_by_name(attr) - instance_attr.push(ins_attr.id) - end + instance_attr.push(ins_attr.id) + end end end end @@ -231,7 +225,7 @@ class Menu < ApplicationRecord end imported_instance = MenuItemInstance.create(menu_item_id: menu_itm.id, item_instance_code: row["Instance Code"], item_instance_name: instance_name, item_attributes: instance_attr, price: row["Price"], is_on_promotion: false, promotion_price: 0, is_available: true, is_default: is_default) end - end + end end # if status == '' status="Menu Imported!" @@ -249,4 +243,4 @@ class Menu < ApplicationRecord end end -end \ No newline at end of file +end diff --git a/app/models/order.rb b/app/models/order.rb index cd350e34..b42ef694 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -35,12 +35,14 @@ class Order < ApplicationRecord if self.is_extra_time && self.extra_time booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking", :checkin_at => Time.now.utc,:checkout_at => Time.now.utc + self.extra_time.to_i, - :checkin_by => self.employee_name, - :booking_status => "assign" }) + :checkin_by => self.employee_name, + :booking_status => "assign", + :shop_code=>self.shop_code}) else booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking", :checkin_at => Time.now.utc, :checkin_by => self.employee_name, - :booking_status => "assign" }) + :booking_status => "assign", + :shop_code=>self.shop_code }) end #end extra time @@ -290,11 +292,11 @@ class Order < ApplicationRecord #Process order items and send to order queue def self.pay_process_order_queue(id,table_id) # if ENV["SERVER_MODE"] != 'cloud' - sidekiq = Lookup.find_by_lookup_type("sidekiq") + order = Order.find(id) + sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",order.shop_code) if !sidekiq.nil? OrderQueueProcessorJob.perform_later(id, table_id) else - order = Order.find(id) if order oqs = OrderQueueStation.new oqs.process_order(order, table_id) diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 005bfe67..3461c5ea 100755 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -136,7 +136,7 @@ class OrderItem < ApplicationRecord print instance_code end if self.qty != self.qty_before_last_save - found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,instance_code) + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,self.order.shop_code) if found InventoryDefinition.check_balance(self, inventory_definition) end diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 147ebdc4..f7d8ab36 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -5,7 +5,7 @@ class OrderQueueStation < ApplicationRecord has_many :assigned_order_items has_many :order_items - has_many :order_queue_process_by_zones + has_many :order_queue_process_by_zones has_many :zones, through: :order_queue_process_by_zones belongs_to :employee @@ -16,22 +16,22 @@ class OrderQueueStation < ApplicationRecord def process_order (order, table_id, order_source = nil, pdf_status = nil ,change_to=nil,current_user=nil) - oqs_stations = OrderQueueStation.active - + oqs_stations = OrderQueueStation.active.where("shop_code='#{order.shop_code}'") + order_items = order.order_items if table_id.to_i > 0 - # get dining - dining = DiningFacility.find(table_id) + # get dining + dining = DiningFacility.find(table_id) oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}") booking = Booking.find_by_dining_facility_id(dining.id) - + # ToDo per item per printer oqs_by_zones.each do |oqpbz| oqs = OrderQueueStation.find(oqpbz.order_queue_station_id) - is_auto_printed = false + is_auto_printed = false oqs_order_items = [] if oqs.is_active @@ -44,22 +44,22 @@ class OrderQueueStation < ApplicationRecord if (pq_item == order_item.item_code) # if oqs.id == oqpbz.order_queue_station_id # #Same Order_items can appear in two location. - # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) # else - + if (order_item.qty > 0) if pdf_status.nil? - AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs) + AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs) end oqs_order_items.push(order_item) end - # end + # end end end end - + if oqs.auto_print && order_source != "quick_service" - if oqs_order_items.length > 0 + if oqs_order_items.length > 0 if oqs.cut_per_item print_slip_item(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id) else @@ -67,12 +67,12 @@ class OrderQueueStation < ApplicationRecord end is_auto_printed = true end - end + end end end else oqs_stations.each do |oqs| - is_auto_printed = false + is_auto_printed = false oqs_order_items = [] if oqs.is_active @@ -85,39 +85,39 @@ class OrderQueueStation < ApplicationRecord if (pq_item == order_item.item_code) # if oqs.id == oqpbz.order_queue_station_id # #Same Order_items can appear in two location. - # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) # else - + if (order_item.qty > 0) if pdf_status.nil? - AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs) + AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs) end oqs_order_items.push(order_item) end - # end + # end end end end - + if oqs.auto_print && order_source != "quick_service" - if oqs_order_items.length > 0 + if oqs_order_items.length > 0 if oqs.cut_per_item print_slip_item(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id) - else + else print_slip(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id) end is_auto_printed = true end - end + end end end - end #end else + end #end else end - def pay_process_order_queue (order_id, table_id) + def pay_process_order_queue (order_id, table_id) oqs_stations = OrderQueueStation.active - + order = Order.find(order_id) order_items = order.order_items @@ -129,22 +129,22 @@ class OrderQueueStation < ApplicationRecord # assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) # if ENV["SERVER_MODE"] == 'cloud' # from = request.subdomain + "." + request.domain - # else + # else # from = "" # end # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from if table_id.to_i > 0 - # get dining - dining = DiningFacility.find(table_id) + # get dining + dining = DiningFacility.find(table_id) oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}") - booking = Booking.find_by_dining_facility_id(dining.id) - + booking = Booking.find_by_dining_facility_id(dining.id) + # ToDo per item per printer oqs_by_zones.each do |oqpbz| oqs = OrderQueueStation.find(oqpbz.order_queue_station_id) - is_auto_printed = false + is_auto_printed = false oqs_order_items = [] if oqs.is_active @@ -157,26 +157,26 @@ class OrderQueueStation < ApplicationRecord if (pq_item == order_item.item_code) if (order_item.qty > 0) oqs_order_items.push(order_item) - end + end end end end - + if oqs.auto_print - if oqs_order_items.length > 0 + if oqs_order_items.length > 0 if oqs.cut_per_item print_slip_item(oqs, order, oqs_order_items) - else + else print_slip(oqs, order, oqs_order_items) end is_auto_printed = true end - end + end end end else oqs_stations.each do |oqs| - is_auto_printed = false + is_auto_printed = false oqs_order_items = [] if oqs.is_active @@ -186,39 +186,39 @@ class OrderQueueStation < ApplicationRecord pq_items.each do |pq_item| #Processing through the looping items order_items.each do |order_item| - if (pq_item == order_item.item_code) + if (pq_item == order_item.item_code) if (order_item.qty > 0) oqs_order_items.push(order_item) - end + end end end end - + if oqs.auto_print - if oqs_order_items.length > 0 + if oqs_order_items.length > 0 if oqs.cut_per_item print_slip_item(oqs, order, oqs_order_items) - else + else print_slip(oqs, order, oqs_order_items) end is_auto_printed = true end - end + end end end - end #end else + end #end else end private #Print order_items in 1 slip def print_slip(oqs, order, order_items ,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil) if pdf_status.nil? - printer = PrintSetting.all.order("id ASC") + printer = PrintSetting.where("shop_code='#{oqs.shop_code}'").order("id ASC") unique_code="OrderSummaryPdf" if !printer.empty? - printer.each do |printer_setting| - if printer_setting.unique_code == 'OrderSummaryPdf' + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderSummaryPdf' unique_code="OrderSummaryPdf" elsif printer_setting.unique_code == 'OrderSummarySlimPdf' unique_code="OrderSummarySlimPdf" @@ -227,34 +227,34 @@ class OrderQueueStation < ApplicationRecord elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf' unique_code="OrderSummaryCustomisePdf" elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf' - unique_code="OrderSummarySetCustomisePdf" + unique_code="OrderSummarySetCustomisePdf" elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf' unique_code="OrderSummarySlimCustomisePdf" end - end - end + end + end - print_settings=PrintSetting.find_by_unique_code(unique_code) + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,oqs.shop_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) order_queue_printer.print_order_summary(print_settings, oqs,order.order_id, order_items, print_status="") else move_print_pdf(change_to,current_user,table_id,order_items,oqs) end - + assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id) AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(print_status: true) end #Print order_item in 1 slip per item def print_slip_item(oqs, order, assigned_items,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil) - + if pdf_status.nil? - printer = PrintSetting.all.order("id ASC") + printer = PrintSetting.where("shop_code='#{oqs.shop_code}'").order("id ASC") unique_code="OrderItemPdf" if !printer.empty? printer.each do |printer_setting| - if printer_setting.unique_code == 'OrderItemPdf' + if printer_setting.unique_code == 'OrderItemPdf' unique_code="OrderItemPdf" elsif printer_setting.unique_code == 'OrderItemStarPdf' unique_code="OrderItemStarPdf" @@ -265,16 +265,16 @@ class OrderQueueStation < ApplicationRecord elsif printer_setting.unique_code == 'OrderItemCustomisePdf' unique_code="OrderItemCustomisePdf" elsif printer_setting.unique_code == 'OrderSetItemCustomisePdf' - unique_code="OrderSetItemCustomisePdf" + unique_code="OrderSetItemCustomisePdf" elsif printer_setting.unique_code == 'OrderItemSlimCustomisePdf' unique_code="OrderItemSlimCustomisePdf" - end + end end end # order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first() - # print when complete click - print_settings=PrintSetting.find_by_unique_code(unique_code) + # print when complete click + print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,oqs.shop_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) if !assigned_items.nil? assigned_items.each do |order_item| @@ -284,7 +284,7 @@ class OrderQueueStation < ApplicationRecord else move_print_pdf(change_to,current_user,table_id,assigned_items,oqs) end - + assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id) AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(print_status: true) end @@ -297,8 +297,8 @@ class OrderQueueStation < ApplicationRecord @type = (DiningFacility.find(change_to)).type @moved_by = current_user @date = DateTime.now - @shop = Shop.first - unique_code = "MoveTablePdf" + @shop = Shop.find_by_shop_code(oqs.shop_code) + unique_code = "MoveTablePdf" # pdf_no = PrintSetting.where(:unique_code => unique_code).count print_settings = PrintSetting.find_by_unique_code(unique_code) # printer_array = [] @@ -307,10 +307,10 @@ class OrderQueueStation < ApplicationRecord # for i in 0..pdf_no # if i != pdf_no # print_settings = printer_array[i] - printer = Printer::ReceiptPrinter.new(print_settings) + printer = Printer::ReceiptPrinter.new(print_settings) printer.print_move_table(print_settings,@to,@from ,@shop,@date,@type,@moved_by,order_items,oqs) - # end - # end + # end + # end end end end diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 8de88ee2..457566db 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -40,8 +40,8 @@ class OrderReservation < ApplicationRecord # unless customer.valid? # render json: { # status: 422, - # message: "Validation error", - # errors: customer.errors + # message: "Validation error", + # errors: customer.errors # }.to_json # return # end @@ -53,7 +53,7 @@ class OrderReservation < ApplicationRecord Rails.logger.debug order_reserve.to_s check_order_reservation = OrderReservation.where("transaction_ref = ?",order_reserve[:reference]) if check_order_reservation.empty? - OrderReservation.transaction do + OrderReservation.transaction do begin order_reservation = OrderReservation.new order_reservation.order_reservation_type = order_reserve[:order_type] @@ -84,7 +84,7 @@ class OrderReservation < ApplicationRecord end order_reservation.save! if order_reserve[:order_info][:items] - order_reserve[:order_info][:items].each do |oritem| + order_reserve[:order_info][:items].each do |oritem| OrderReservationItem.process_order_reservation_item(oritem[:product_code],oritem[:item_instance_code],oritem[:product_name],oritem[:product_alt_name], oritem[:account_id],oritem[:qty],oritem[:price],oritem[:unit_price], oritem[:options],nil,order_reservation.id) @@ -93,13 +93,13 @@ class OrderReservation < ApplicationRecord if order_reserve[:delivery_info] Delivery.addDeliveryInfo(order_reserve[:delivery_info],order_reservation.id) end - + return order_reservation.id, true rescue ActiveRecord::StatementInvalid raise ActiveRecord::Rollback return nil, false - end + end end else return check_order_reservation[0].id, false @@ -112,14 +112,14 @@ class OrderReservation < ApplicationRecord items_arr = [] count = 1 - order.order_reservation_items.each { |i| + order.order_reservation_items.each { |i| i.item_instance_code = i.item_instance_code.downcase.to_s items = {"order_item_id": count,"item_instance_code": i.item_instance_code,"quantity": i.qty,"options": i.options} count += 1 items_arr.push(items) } customer_id = order.customer_id - + @order = Order.new @order.source = "doemal_order" @order.order_type = "delivery" @@ -138,7 +138,7 @@ class OrderReservation < ApplicationRecord # Order.send_customer_view(@booking) if @status && @booking - + @status, @sale = Sale.request_bill(@order,current_user,current_user) #order status send to doemal @@ -157,7 +157,7 @@ class OrderReservation < ApplicationRecord def self.update_doemal_payment(order,current_user,receipt_bill) if(Sale.exists?(order.sale_id)) saleObj = Sale.find(order.sale_id) - shop_details = Shop.first + shop_details = Shop.find_by_shop_code(order.shop_code) # rounding adjustment if shop_details.is_rounding_adj a = saleObj.grand_total % 25 # Modulus @@ -167,11 +167,11 @@ class OrderReservation < ApplicationRecord if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) new_total = Sale.get_rounding_adjustment(saleObj.grand_total) rounding_adj = new_total-saleObj.grand_total - saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) end end #end rounding adjustment - + sale_payment = SalePayment.new if(order.payment_type == "cash_on_delivery") sale_payment.process_payment(saleObj, current_user, saleObj.grand_total, "cash") @@ -183,9 +183,9 @@ class OrderReservation < ApplicationRecord callback_response = send_status_to_ordering(order.callback_url,order.transaction_ref,DELIVERED) #order reservation status updated update_order_reservation(order.id, saleObj.sale_id, DELIVERED) - Rails.logger.debug "@@@@ receipt_bill :: " + Rails.logger.debug "@@@@ receipt_bill :: " Rails.logger.debug receipt_bill - + if receipt_bill == 1 #receipt bill pdf setting # get printer info @@ -194,7 +194,7 @@ class OrderReservation < ApplicationRecord shift = ShiftSale.find(saleObj.shift_sale_id) cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) - shop_detail = Shop.first + # shop_detail = Shop.first order_reservation = OrderReservation.get_order_reservation_info(saleObj.sale_id) if !cashier_terminal.nil? # Calculate Food and Beverage Total @@ -203,16 +203,16 @@ class OrderReservation < ApplicationRecord other_amount = SaleItem.calculate_other_charges(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,saleObj.sale_items,saleObj,saleObj.customer.name, item_price_by_accounts, discount_price_by_accounts, nil,nil,shop_detail, "Paid",nil,nil,other_amount,nil,nil, order_reservation) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,saleObj.sale_items,saleObj,saleObj.customer.name, item_price_by_accounts, discount_price_by_accounts, nil,nil,shop_details, "Paid",nil,nil,other_amount,nil,nil, order_reservation) #receipt bill pdf setting - result = {:status=> true, - :filepath => filename, - :sale_id => saleObj.sale_id, - :receipt_no => sale_receipt_no, - :printer_name => printer_name, - :printer_model => print_settings.brand_name, - :printer_url => print_settings.api_settings , + result = {:status=> true, + :filepath => filename, + :sale_id => saleObj.sale_id, + :receipt_no => sale_receipt_no, + :printer_name => printer_name, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings , :message => DELIVERED } else result = {:status=> true, :message => DELIVERED } @@ -223,7 +223,7 @@ class OrderReservation < ApplicationRecord result = {:status=> true, :message => DELIVERED } end return result - end + end end def self.send_status_to_ordering(url,ref_no,status,waiting_time=nil,min_type=nil,reason=nil) @@ -349,12 +349,12 @@ class OrderReservation < ApplicationRecord shift.save end end - + sale.payment_status = 'void' sale.sale_status = 'void' sale.save - # For Sale Audit + # For Sale Audit if !current_user.nil? action_by = current_user.name else @@ -363,7 +363,7 @@ class OrderReservation < ApplicationRecord approved_name = nil approved_by = Employee.find_by_emp_id(access_code) - + if !approved_by.nil? approved_name = approved_by.name end @@ -372,7 +372,7 @@ class OrderReservation < ApplicationRecord sale_audit = SaleAudit.record_audit_for_edit(sale_id,cashier_name, approved_name,remark,"SALEVOID" ) # update complete order items in oqs - SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr| + SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr| AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| aoi.delivery_status = 1 aoi.save @@ -410,7 +410,7 @@ class OrderReservation < ApplicationRecord if order_reservation.length > 0 if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain - else + else from = "" end ActionCable.server.broadcast "check_new_order_channel",data: order_reservation, shop_code: shop_code,from:from @@ -428,7 +428,7 @@ class OrderReservation < ApplicationRecord if order_reservation.length > 0 if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain - else + else from = "" end ActionCable.server.broadcast "check_order_send_to_kitchen_channel",data: order_reservation, shop_code: shop_code,from:from @@ -446,7 +446,7 @@ class OrderReservation < ApplicationRecord if order_reservation.length > 0 if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain - else + else from = "" end ActionCable.server.broadcast "check_order_ready_to_delivery_channel",data: order_reservation, shop_code: shop_code,from:from diff --git a/app/models/payment_journal.rb b/app/models/payment_journal.rb index 0f0c3ce5..51b7fdf3 100755 --- a/app/models/payment_journal.rb +++ b/app/models/payment_journal.rb @@ -7,7 +7,8 @@ class PaymentJournal < ApplicationRecord self.payment_method = payment_method self.payment_status = 'paid' self.payment_method_references = payment_method_reference - self.created_by = current_user + self.created_by = current_user.id + self.shop_code = current_user.shop_code self.save end @@ -16,7 +17,8 @@ class PaymentJournal < ApplicationRecord self.remark = remark self.debit_amount = amount self.payment_status = 'paid' - self.created_by = current_user + self.created_by = current_user.id + self.shop_code = current_user.shop_code self.save end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index ed14d884..cadba8ce 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -38,8 +38,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end # end - shop = Shop.first - directory_name = 'public/orders_'+shop.shop_code + # shop = Shop.first + directory_name = 'public/orders_'+oqs.shop_code Dir.mkdir(directory_name) unless File.exists?(directory_name) filename = directory_name + "/order_item_#{order_id}_#{order_item_id}" + ".pdf" @@ -80,8 +80,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker print_setting = PrintSetting.all.order("id ASC") order=print_query('order_summary', order_id) - shop = Shop.first - directory_name = 'public/orders_'+shop.shop_code + # shop = Shop.first + directory_name = 'public/orders_'+oqs.shop_code Dir.mkdir(directory_name) unless File.exists?(directory_name) # For Print Per Item @@ -192,8 +192,8 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker order=print_query('booking_summary', booking_id) - shop = Shop.first - directory_name = 'public/orders_'+shop.shop_code + # shop = Shop.first + directory_name = 'public/orders_'+oqs.shop_code Dir.mkdir(directory_name) unless File.exists?(directory_name) # For Print Per Item diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index fee19a31..e0d4fc85 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -3,7 +3,7 @@ require 'cups' class Printer::PrinterWorker attr_accessor :print_settings - + def initialize(print_settings) self.print_settings = print_settings end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index f7b35a5a..a935c3b0 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -195,7 +195,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker if !printer_settings.nil? if !printer_settings.unique_code.strip.downcase.include? ("receiptbillorder") pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) - settings = PrintSetting.all + settings = PrintSetting.where("shop_code='#{shop_details.shop_code}'") if !settings.nil? settings.each do |setting| if setting.unique_code == 'ReceiptBillPdf' @@ -206,7 +206,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end end - receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + receipt_bill_a5_pdf = Lookup.where("shop_code='#{shop_details.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| if receipt_bilA5[0] == 'ReceiptBillA5Pdf' diff --git a/app/models/product_commission.rb b/app/models/product_commission.rb index 9f91673a..7ab094af 100755 --- a/app/models/product_commission.rb +++ b/app/models/product_commission.rb @@ -33,9 +33,9 @@ class ProductCommission < ApplicationRecord product_commission.save end - def self.edit_product_commission(saleItemObj) + def self.edit_product_commission(saleItemObj,shop_code) menu_item = MenuItem.find_by_item_code(saleItemObj.product_code) - commission = Commission.where('product_code = ? AND is_active = ?', menu_item.id, true).take + commission = Commission.where("shop_code='#{shop_code}' and product_code = ? AND is_active = ?", menu_item.id, true).take product_commission = ProductCommission.where('sale_item_id = ?', saleItemObj.id).take if !product_commission.nil? diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 6d5a7039..3e657e63 100755 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -15,11 +15,11 @@ class Promotion < ApplicationRecord promo_day.include? Date.today.wday.to_s end - def self.promo_activate(saleObj) + def self.promo_activate(saleObj,shop_code) current_day = Time.now.strftime("%Y-%m-%d") current_time = Time.now.strftime('%H:%M:%S') day = Date.today.wday - promoList = is_between_promo_datetime(current_day,current_time) + promoList = is_between_promo_datetime(current_day,current_time,shop_code) promoList.each do |promo| if promo.is_promo_day @@ -30,8 +30,8 @@ class Promotion < ApplicationRecord end end - def self.is_between_promo_datetime(current_day,current_time) #database is not local time - promoList = Promotion.where("(Date_Format(promo_start_date, '%Y-%m-%d') <=? AND Date_Format(promo_end_date, '%Y-%m-%d') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time) + def self.is_between_promo_datetime(current_day,current_time,shop_code) #database is not local time + promoList = Promotion.where("shop_code='#{shop_code}' and (Date_Format(promo_start_date, '%Y-%m-%d') <=? AND Date_Format(promo_end_date, '%Y-%m-%d') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time) return promoList end @@ -157,7 +157,7 @@ class Promotion < ApplicationRecord sale_item.is_taxable = 1 sale_item.sale = saleObj sale_item.save - + saleObj.sale_items << sale_item saleObj.compute_by_sale_items(saleObj.total_discount, nil, source) end diff --git a/app/models/sale.rb b/app/models/sale.rb index 54b7602b..5192f468 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -29,7 +29,6 @@ class Sale < ApplicationRecord scope :date_between, -> (from, to) { where("DATE(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) } scope :time_between, -> (from, to) { where("TIME(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) } scope :along_with_sale_payments_except_void, -> { joins("LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND DATE(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30')) = DATE(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'))") } - def qty_of(item_instance_code) order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first end @@ -136,8 +135,8 @@ class Sale < ApplicationRecord order = Order.find(order_id) # current cashier login - open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") - current_shift = ShiftSale.current_shift + open_cashier = Employee.where("shop_code='#{order.shop_code}' and role = 'cashier' AND token_session <> ''") + current_shift = ShiftSale.current_shift(order.shop_code) # shift with terminal zone # set cashier @@ -145,12 +144,12 @@ class Sale < ApplicationRecord if !booking.dining_facility_id.nil? table = DiningFacility.find(booking.dining_facility_id) cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first + shift = ShiftSale.where("shop_code='#{order.shop_code}' and shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first #for multiple zone with terminal if shift.nil? multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}") multiple_zone.each do |zone| - shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first + shift = ShiftSale.where("shop_code='#{order.shop_code}' and shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first if !shift.nil? then break end @@ -158,7 +157,7 @@ class Sale < ApplicationRecord end end else - shift = ShiftSale.current_open_shift(cashier.id) + shift = ShiftSale.current_open_shift(cashier) end # set cashier if shift != nil #if current login employee open shift @@ -170,7 +169,7 @@ class Sale < ApplicationRecord # table and terminal in multiple shift self.cashier_id = open_cashier[0].id self.cashier_name = open_cashier[0].name - shift_id = ShiftSale.current_open_shift(open_cashier[0].id) + shift_id = ShiftSale.current_open_shift(open_cashier[0]) if shift_id self.shift_sale_id = shift_id.id else @@ -188,7 +187,7 @@ class Sale < ApplicationRecord self.requested_by = requested_by.name self.requested_at = DateTime.now.utc.getlocal - + self.shop_code = order.shop_code Rails.logger.debug "Order -> #{order.id} | order_status -> #{order.status}" if order self.customer_id = order.customer_id @@ -234,15 +233,13 @@ class Sale < ApplicationRecord #fOR Quick Service pay and create def self.request_bill(order,current_user,current_login_employee) - if !ShiftSale.current_shift.nil? + if !ShiftSale.current_shift(order.shop_code).nil? order_id = order.order_id # order_id bk_order = BookingOrder.find_by_order_id(order_id) check_booking = Booking.find_by_booking_id(bk_order.booking_id) if @sale_data = check_booking.sale # Create Sale if it doesn't exist - # puts "current_login_employee" - # puts current_login_employee.name @sale_items = SaleItem.where("sale_id=?",@sale_id) elsif @sale_data = Sale.generate_invoice_from_booking(check_booking,current_login_employee,current_user,order.source) @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) @@ -253,7 +250,7 @@ class Sale < ApplicationRecord # @sale_data.save # Promotion Activation - Promotion.promo_activate(@sale_data) + Promotion.promo_activate(@sale_data,order.shop_code) @status = true return @status, @sale_data else @@ -438,7 +435,7 @@ class Sale < ApplicationRecord #compute - invoice total def compute_by_sale_items(total_discount, discount_type=nil, order_source=nil, tax_type=nil, type=nil) - shop = Shop.first + # shop = Shop.first #Computation Fields subtotal_price = 0 @@ -505,7 +502,7 @@ class Sale < ApplicationRecord # Tax Re-Calculte def compute_tax(total_taxable, total_discount = 0, order_source = nil, tax_type=nil) - shop = Shop.first + shop = Shop.find_by_shop_code(self.shop_code) #if tax is not apply create new record # SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax| @@ -559,7 +556,7 @@ class Sale < ApplicationRecord # Tax Calculate def apply_tax(total_taxable, order_source = nil, tax_type = nil) - shop = Shop.first + shop = Shop.find_by_shop_code(self.shop_code) #if tax is not apply create new record # SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax| @@ -639,7 +636,7 @@ class Sale < ApplicationRecord end def adjust_rounding - shop_details = Shop.first + shop_details = Shop.find_by_shop_code(self.shop_code) # rounding adjustment if shop_details.is_rounding_adj new_total = Sale.get_rounding_adjustment(self.grand_total) @@ -655,7 +652,7 @@ class Sale < ApplicationRecord #Generate new Receipt No when it is not assigned def generate_receipt_no #shop_code and client_code - shop_details = Shop.first + shop_details = Shop.find_by_shop_code(self.shop_code) #Date-Shift- if self.receipt_no.nil? prefix = DateTime.now().utc @@ -1502,10 +1499,10 @@ end return tax end - def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type) + def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type,shop) if (!from.nil? && !to.nil?) && (from != "" && to!="") if current_user.nil? - query = Sale.top_bottom(today,nil,from,to,from_time,to_time) + query = Sale.top_bottom(shop,today,nil,from,to,from_time,to_time) if type == "top" query = query.group('i.product_name') @@ -1516,7 +1513,7 @@ end end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.top_bottom(today,nil,from,to,from_time,to_time) + query = Sale.top_bottom(shop,today,nil,from,to,from_time,to_time) if type == "top" query = query.group('i.product_name') .order("SUM(i.qty) DESC").limit(20) @@ -1525,9 +1522,9 @@ end .order("SUM(i.qty) ASC").limit(20) end else - shift = ShiftSale.current_open_shift(current_user.id) + shift = ShiftSale.current_open_shift(current_user) if !shift.nil? - query = Sale.top_bottom(today,shift,from,to,from_time,to_time) + query = Sale.top_bottom(shop,today,shift,from,to,from_time,to_time) if type == "top" query = query.group('i.product_name') .order("SUM(i.qty) DESC").limit(20) @@ -1540,7 +1537,7 @@ end end else if current_user.nil? - query = Sale.top_bottom(today).group('i.product_name') + query = Sale.top_bottom(shop,today).group('i.product_name') if type == "top" query = query.order("SUM(i.qty) DESC").limit(20) @@ -1549,16 +1546,16 @@ end end else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.top_bottom(today).group('i.product_name') + query = Sale.top_bottom(shop,today).group('i.product_name') if type == "top" query = query.order("SUM(i.qty) DESC").limit(20) elsif type == "bottom" query = query.order("SUM(i.qty) ASC").limit(20) end else - shift = ShiftSale.current_open_shift(current_user.id) + shift = ShiftSale.current_open_shift(current_user) if !shift.nil? - query = Sale.top_bottom(today,shift).group('i.product_name') + query = Sale.top_bottom(shop,today,shift).group('i.product_name') if type == "top" query = query.order("SUM(i.qty) DESC").limit(20) elsif type == "bottom" @@ -1570,53 +1567,53 @@ end end end - def self.hourly_sales(today,current_user,from,to,from_time,to_time) + def self.hourly_sales(today,current_user,from,to,from_time,to_time,shop) if (!from.nil? && !to.nil?) && (from != "" && to!="") if current_user.nil? - query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time) + query = Sale.hourly_sale_data(shop,today,nil,from,to,from_time,to_time) else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time) + query = Sale.hourly_sale_data(shop,today,nil,from,to,from_time,to_time) else - shift = ShiftSale.current_open_shift(current_user.id) + shift = ShiftSale.current_open_shift(current_user) if !shift.nil? - query = Sale.hourly_sale_data(today,shift,from,to,from_time,to_time) + query = Sale.hourly_sale_data(shop,today,shift,from,to,from_time,to_time) end end end else if current_user.nil? - query = Sale.hourly_sale_data(today) + query = Sale.hourly_sale_data(shop,today) else if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.hourly_sale_data(today) + query = Sale.hourly_sale_data(shop,today) else - shift = ShiftSale.current_open_shift(current_user.id) + shift = ShiftSale.current_open_shift(current_user) if !shift.nil? - query = Sale.hourly_sale_data(today,shift) + query = Sale.hourly_sale_data(shop,today,shift) end end end end end - def self.employee_sales(today,current_user,from,to,from_time,to_time) + def self.employee_sales(today,current_user,from,to,from_time,to_time,shop) shift = if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - ShiftSale.current_open_shift(current_user.id) + ShiftSale.current_open_shift(current_user) end payments_for_credits = SalePayment.joins(:sale_audit).to_sql - query = employee_sale(today, shift, from, to, from_time, to_time) + query = employee_sale(shop,today, shift, from, to, from_time, to_time) .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id") .select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount, CASE WHEN sale_payments.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sale_payments.payment_method END AS payment_method, employees.name AS e_name") end - def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop) query = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count") - .where('sale_status = "completed"') + .where("sale_status = 'completed' AND shop_code='#{shop.shop_code}'") if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) @@ -1627,16 +1624,16 @@ end query = query.date_on(today) 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("sales.shift_sale_id = ?", shift.id) end end return query end - def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop) query = Sale.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .where('sales.sale_status = "completed" and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")') + .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and (sp.payment_method = 'mpu' or sp.payment_method = 'visa' or sp.payment_method = 'master' or sp.payment_method = 'jcb' or sp.payment_method = 'unionpay' or sp.payment_method = 'alipay' or sp.payment_method = 'paymal' or sp.payment_method = 'dinga' or sp.payment_method = 'JunctionPay')") if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) if !from_time.nil? && !to_time.nil? @@ -1646,20 +1643,20 @@ end query = query.date_on(today) 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("sales.shift_sale_id = ?", shift.id) end end query = query.sum("sp.payment_amount") end - def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil,shop) payments_for_credits = SalePayment.joins(:sale_audit).to_sql query = SalePayment.credits .joins(:sale) .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sale_payments.sale_id") - .where("sale_payments.payment_method= ? AND sales.sale_status = ?", 'creditnote', 'completed') + .where("sale_payments.payment_method= ? AND sales.sale_status = ? AND sales.shop_code=?", 'creditnote', 'completed',shop.shop_code) if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.merge(Sale.date_between(from, to)) @@ -1670,7 +1667,7 @@ end query = query.merge(Sale.date_on(today)) 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("sales.shift_sale_id = ?", shift.id) end end @@ -1678,9 +1675,9 @@ end return query.sum("sale_payments.payment_amount - IFNULL(payments_for_credits.payment_amount, 0)") end - def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.summary_sale_receipt(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') - .where('sale_status = "completed"') + .where("shop_code='#{shop.shop_code}' and sale_status = 'completed'") if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) if !from_time.nil? && !to_time.nil? @@ -1690,16 +1687,16 @@ end query = query.date_on(today) 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("sales.shift_sale_id = ?", shift.id) end end query = query.first() end - def self.total_payment_methods(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_payment_methods(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("distinct sp.payment_method") - .where('sales.sale_status = "completed"') + .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed'") .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) @@ -1710,19 +1707,20 @@ end query = query.date_on(today) 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("sales.shift_sale_id = ?", shift.id) end end return query end - def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.payment_sale(shop,payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) payments_for_credits = SalePayment.joins(:sale_audit).to_sql query = Sale.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount") .joins(:sale_payments) .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id") + .where("sales.shop_code='#{shop.shop_code}'") .completed if payment_method == 'card' @@ -1741,15 +1739,15 @@ 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("sales.shift_sale_id = ?", shift.id) end end query.first end - def self.total_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - total_dinein_takeaway = self.total_dinein_takeaway(today,current_user,from,to,from_time,to_time) + def self.total_customer(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + total_dinein_takeaway = self.total_dinein_takeaway(shop,today,current_user,from,to,from_time,to_time) dinein_cnt = 0 takeaway_cnt = 0 if !total_dinein_takeaway.nil? @@ -1758,7 +1756,7 @@ end takeaway_cnt = total_dinein_takeaway[0].total_take_cus end end - membership_cnt = self.total_membership(today,current_user,from,to,from_time,to_time) + membership_cnt = self.total_membership(shop,today,current_user,from,to,from_time,to_time) member_cnt = 0 if !membership_cnt.nil? member_cnt = membership_cnt.total_memb_cus @@ -1771,10 +1769,10 @@ end return total_cus, dinein_cnt, takeaway_cnt, member_cnt end - def self.total_dinein_takeaway(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_dinein_takeaway(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("(CASE WHEN c.customer_type='Dinein' THEN count(sales.customer_id) ELSE 0 END) as total_dinein_cus, (CASE WHEN c.customer_type='Takeaway' THEN count(sales.customer_id) ELSE 0 END) as total_take_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and c.membership_id is null') + .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and c.membership_id is null") if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) if !from_time.nil? && !to_time.nil? @@ -1784,17 +1782,17 @@ end query = query.date_on(today) 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("sales.shift_sale_id = ?", shift.id) end end query = query.first() end - def self.total_membership(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_membership(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))') + .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and ((c.customer_type = 'Dinein' and c.membership_id is not null) or (c.customer_type = 'Takeaway' and c.membership_id is not null))") if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) if !from_time.nil? && !to_time.nil? @@ -1804,7 +1802,7 @@ end query = query.date_on(today) 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("sales.shift_sale_id = ?", shift.id) end end @@ -1857,9 +1855,10 @@ end # query = query.first() # end - def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_order(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("count(distinct sale_orders.order_id) as total_order") .joins(:sale_orders) + .where("shop_code='#{shop.shop_code}'") .completed if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) @@ -1871,7 +1870,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("sales.shift_sale_id = ?", shift.id) end end @@ -1879,11 +1878,11 @@ end query = query.first end - def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_account(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("distinct b.id as account_id, b.title as title") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed"') + .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed'") if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) if !from_time.nil? && !to_time.nil? @@ -1893,17 +1892,17 @@ end query = query.date_on(today) 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("sales.shift_sale_id = ?", shift.id) end end return query end - def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.account_data(shop,account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}'") + .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and a.account_id ='#{account_id}'") if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) if !from_time.nil? && !to_time.nil? @@ -1913,17 +1912,17 @@ end query = query.date_on(today) 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("sales.shift_sale_id = ?", shift.id) end end query = query.first end - def self.top_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.top_items(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed'") + .where("sales.shop_code='#{shop.shop_code}' and (a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed'") if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) if !from_time.nil? && !to_time.nil? @@ -1933,7 +1932,7 @@ end query = query.date_on(today) 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("sales.shift_sale_id = ?", shift.id) end end @@ -1942,9 +1941,9 @@ end .first() end - def self.total_foc_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + def self.total_foc_items(shop,today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'") + .where("sales.shop_code='#{shop.shop_code}' and sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'") if (!from.nil? && !to.nil?) && (from != "" && to!="") query = query.date_between(from, to) if !from_time.nil? && !to_time.nil? @@ -1954,7 +1953,7 @@ end query = query.date_on(today) 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("sales.shift_sale_id = ?", shift.id) end end @@ -2016,13 +2015,13 @@ end query = query.where("bookings.booking_status = 'assign' AND orders.status = 'new' AND orders.source =? ","#{type}") .group("bookings.booking_id") end - def self.completed_sale(type) + def self.completed_sale(type,shop_code) if type == "cashier" type = "and orders.source = 'emenu' or orders.source = 'cashier'" else type = "and orders.source = '#{type}'" end - query = Sale.all + query = Sale.where("sales.shop_code='#{shop_code}'") query = query.joins("join sale_orders as sale_orders on sale_orders.sale_id = sales.sale_id") .joins("join orders as orders on orders.order_id = sale_orders.order_id") query = query.where("sales.sale_status != 'new' AND orders.status = 'billed' #{type}") @@ -2085,8 +2084,7 @@ def self.get_sale_data_for_other_payment_credit(sale_id) end def unique_tax_profiles(order_source, customer_id) - tax_data = TaxProfile - .where(group_type: order_source) + tax_data = TaxProfile.where(group_type: order_source,shop_code: self.shop_code) customer_tax_profiles = Customer.select(:tax_profiles).where(customer_id: customer_id).first if customer_tax_profiles.present? @@ -2096,7 +2094,7 @@ def unique_tax_profiles(order_source, customer_id) return tax_data end -def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) +def self.top_bottom(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,i.product_name") @@ -2105,7 +2103,7 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") else - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + query = query.where("shop_code='#{shop.shop_code}' and (i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ " and sale_status= 'completed'") end if !shift.nil? @@ -2115,7 +2113,7 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,i.product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id") - .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ + .where("shop_code='#{shop.shop_code}' and (i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ " and sale_status= 'completed'") if !shift.nil? query = query.where("shift_sale_id='#{shift.id}'") @@ -2124,7 +2122,7 @@ def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) return query end -def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) +def self.hourly_sale_data(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? query = Sale.select("grand_total") if !from_time.nil? && !to_time.nil? @@ -2135,11 +2133,11 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time= if !shift.nil? query = query.where("shift_sale_id='#{shift.id}'") end - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") + query = query.where("shop_code='#{shop.shop_code}'").group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') else query = Sale.select("grand_total") - .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) + .where("shop_code='#{shop.shop_code}' and sale_status = 'completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = ?",today) if !shift.nil? query = query.where("shift_sale_id='#{shift.id}'") end @@ -2150,10 +2148,10 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time= return query end -def self.employee_sale(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) +def self.employee_sale(shop,today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.joins(:cashier) .joins(:sale_payments) - .paid.completed + .paid.completed.where("sales.shop_code='#{shop.shop_code}'") if !from.nil? && !to.nil? query = query.date_between(from, to) if !from_time.nil? && !to_time.nil? @@ -2474,7 +2472,7 @@ private def update_stock_journal if self.sale_status == "void" && self.sale_status_before_last_save != "void" self.sale_items.each do |item| - found, inventory_definition = InventoryDefinition.find_product_in_inventory(item) + found, inventory_definition = InventoryDefinition.find_product_in_inventory(item,self.shop_code) if found stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first unless stock.nil? @@ -2487,7 +2485,7 @@ private end elsif self.sale_status == "waste" || self.sale_status == "spoile" || (self.payment_status == "foc" && self.payment_status_was != "foc") self.bookings.first.order_items.each do |item| - found, inventory_definition = InventoryDefinition.find_product_in_inventory(item) + found, inventory_definition = InventoryDefinition.find_product_in_inventory(item,self.shop_code) if found if stock_journal = StockJournal.find_by_trans_ref(item.order_items_id) stock_journal.update(remark: self.sale_status) diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 8473da78..c6b19926 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -311,11 +311,11 @@ class SaleItem < ApplicationRecord cancel_foc = self.status_before_last_save == "foc" if is_void or cancel_void or is_edit or is_foc or cancel_foc - found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,self.sale.shop_code) if found - stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first + stock = StockJournal.where("shop_code='#{self.sale.shop_code}' and item_code=?", self.item_instance_code).order("id DESC").first unless stock.nil? - check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first + check_item = StockCheckItem.where("shop_code='#{self.sale.shop_code}' and item_code=?", self.item_instance_code).order("id DESC").first if is_void or cancel_void or is_edit if is_void qty = -self.qty diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index e0ad2383..0e2902ce 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -34,9 +34,9 @@ class SalePayment < ApplicationRecord end end - def self.get_kbz_pay_amount(sale_id, current_user) + def self.get_kbz_pay_amount(sale_id, current_user,shop) amount = 0 - kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last + kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY,:shop_code => shop.shop_code).last sale_payment = SalePayment.where('sale_id=? and payment_method=? and payment_status!=?', sale_id, KbzPay::KBZ_PAY, 'dead').last if !sale_payment.nil? and !kbz_pay_method.nil? if sale_payment.payment_status == 'pending' @@ -136,11 +136,12 @@ class SalePayment < ApplicationRecord #record an payment in sale-audit remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" if payment_for - shift = ShiftSale.current_open_shift(self.sale.cashier_id) + current_shift_user =Employee.find_by_id(self.sale.cashier_id) + shift = ShiftSale.current_open_shift(current_shift_user) if !shift.nil? shift_sale_id = shift.id else - shift = ShiftSale.current_shift + shift = ShiftSale.current_shift(self.sale.shop_code) shift_sale_id = shift.id end @@ -726,11 +727,12 @@ class SalePayment < ApplicationRecord # update for cashier shift def update_shift - - shift = ShiftSale.current_open_shift(self.action_by.id) + current_shift_user = Employee.find_by_id(self.action_by.id) + shift = ShiftSale.current_open_shift(current_shift_user) if shift.nil? - shift = ShiftSale.current_open_shift(self.sale.cashier_id) + current_shift_user = Employee.find_by_id(self.sale.cashier_id) + shift = ShiftSale.current_open_shift(current_shift_user) end if !shift.nil? @@ -740,7 +742,7 @@ class SalePayment < ApplicationRecord self.sale.cashier_name = Employee.find(shift.employee_id).name self.sale.save else - shift = ShiftSale.current_shift + shift = ShiftSale.current_shift(self.sale.shop_code) shift.update(self.sale) self.sale.shift_sale_id = shift.id self.sale.cashier_id = shift.employee_id @@ -972,7 +974,7 @@ class SalePayment < ApplicationRecord end #credit payment query - def self.get_credit_sales(params) + def self.get_credit_sales(params,shop_code) receipt_no = "" customer = "" if !params["receipt_no"].blank? @@ -1001,7 +1003,7 @@ class SalePayment < ApplicationRecord else query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND #{order_source_query}='#{params[:type]}' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}") end - query = query.group("s.receipt_no") + query = query.where("s.shop_code='#{shop_code}'").group("s.receipt_no") .order("s.receipt_date ASC, s.receipt_no ASC") return query end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 07217103..3125ca8d 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -16,10 +16,11 @@ class ShiftSale < ApplicationRecord belongs_to :cashier_terminal belongs_to :employee, :foreign_key => 'employee_id' has_many :sales + belongs_to :shop - def self.current_shift + def self.current_shift(shop_code) # today_date = DateTime.now.strftime("%Y-%m-%d") - shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").first + shift = ShiftSale.where("shop_code='#{shop_code}' and shift_started_at is not null and shift_closed_at is null").first return shift end @@ -28,7 +29,7 @@ class ShiftSale < ApplicationRecord #find open shift where is open today and is not closed and login by current cashier #DATE(shift_started_at)=? and today_date = DateTime.now.strftime("%Y-%m-%d") - shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take + shift = ShiftSale.where("shop_code='#{current_user.shop_code}' and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user.id}").take return shift #end end diff --git a/app/models/shop.rb b/app/models/shop.rb index 75c30dd7..d12986a1 100755 --- a/app/models/shop.rb +++ b/app/models/shop.rb @@ -3,7 +3,6 @@ class Shop < ApplicationRecord # Shop Image Uploader mount_uploader :logo, ShopImageUploader - has_many :display_images accepts_nested_attributes_for :display_images diff --git a/app/models/stock_check.rb b/app/models/stock_check.rb index c2499c29..541a7ea5 100755 --- a/app/models/stock_check.rb +++ b/app/models/stock_check.rb @@ -1,11 +1,12 @@ class StockCheck < ApplicationRecord has_many :stock_check_items - def create(user, reason, item_list) + def create(user, reason, item_list,shop) self.reason = reason self.check_by = user.id self.check_start = Time.now self.check_end = Time.now + self.shop_code = shop.shop_code save item_list.each do |item| stockItem = StockCheckItem.new diff --git a/app/models/stock_check_item.rb b/app/models/stock_check_item.rb index 16699803..18d90156 100755 --- a/app/models/stock_check_item.rb +++ b/app/models/stock_check_item.rb @@ -67,7 +67,7 @@ class StockCheckItem < ApplicationRecord return query end - def self.delete_stock_check_item(item_code) - self.where("item_code=?", item_code).delete_all + def self.delete_stock_check_item(item_code,shop) + self.where("item_code=? and shop_code='#{shop.shop_code}'", item_code).delete_all end end diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index 6e72d94a..d70ca051 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -1,5 +1,5 @@ class StockJournal < ApplicationRecord - + belongs_to :shop SALES_TRANS = "sale" ORDER_TRANS = "order" STOCK_CHECK_TRANS = "stock_check" @@ -24,7 +24,8 @@ class StockJournal < ApplicationRecord inventory_definition_id: inventory_definition.id, remark: stock_message, trans_ref: trans_ref, - trans_type: trans_type + trans_type: trans_type, + shop_code: inventory_definition.shop_code ) end @@ -32,27 +33,30 @@ class StockJournal < ApplicationRecord return balance.to_i - qty.to_i end - def self.from_stock_check(item) - stock_journal = StockJournal.where('item_code=?', item.item_code).order("id DESC").first + def self.from_stock_check(item,shop) + stock_journal = StockJournal.where("shop_code='#{shop.shop_code}' and item_code=?", item.item_code).order("id DESC").first if stock_journal.nil? old_blance = 0 + inventory_definition_id = InventoryDefinition.find_by_item_code_and_shop_code(item.item_code,shop.shop_code).id else old_blance = stock_journal.balance + inventory_definition_id = stock_journal.inventory_definition_id end - definition_id = InventoryDefinition.find_by_item_code(item.item_code) + # definition_id = InventoryDefinition.find_by_item_code(item.item_code) journal = StockJournal.new journal.item_code = item.item_code - journal.inventory_definition_id = definition_id.id + journal.inventory_definition_id = inventory_definition_id journal.debit = 0 journal.credit = item.stock_count journal.balance = item.stock_count + old_blance.to_i journal.remark = StockJournal::STOCK_CHECK_TRANS journal.trans_ref = item.id journal.trans_type = StockJournal::STOCK_CHECK_TRANS + journal.shop_code = shop.shop_code journal.save end - def self.inventory_balances(today,from,to,from_time,to_time) + def self.inventory_balances(today,from,to,from_time,to_time,shop) if !from.nil? && !to.nil? query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") @@ -61,12 +65,12 @@ class StockJournal < ApplicationRecord else query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") end - query = query.group("mii.item_instance_name") + query = query.where("shop_code='#{shop.shop_code}'").group("mii.item_instance_name") .order("mii.item_instance_name ASC") else query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") - .where("DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'") + .where("shop_code='#{shop.shop_code}' and DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'") .group("mii.item_instance_name") .order("mii.item_instance_name ASC") end @@ -81,8 +85,8 @@ class StockJournal < ApplicationRecord end end - def self.delete_stock_journal(item_code) - self.where("item_code=?", item_code).delete_all + def self.delete_stock_journal(item_code,shop) + self.where("item_code=? and shop_code='#{shop.shop_code}'", item_code).delete_all end end diff --git a/app/views/crm/dining_queues/assign.html.erb b/app/views/crm/dining_queues/assign.html.erb index 1e50042e..a6e6c20a 100755 --- a/app/views/crm/dining_queues/assign.html.erb +++ b/app/views/crm/dining_queues/assign.html.erb @@ -19,17 +19,17 @@
- <% @i =0 %> - <% DiningFacility.all.each do |table| %> + <% @i =0 %> + <% @tables.each do |table| %>
" data-id="<%= table.id %>">
- +

<%= table.name %>

Seat : <%= table.seater %>

- + <% end %>
@@ -50,12 +50,12 @@ $(document).on('click',".assign_table",function(){ var table_id = $(this).attr('data-id'); url = '<%= crm_assign_table_path %>'; var status = $(this).find(".queue-status").text() - + if (status == "available") { assign_table(queue_id,table_id,url); } else { swal ( "Alert!" , "You cannot assign this table!" , "warning" ); - } + } }) function assign_table(id,table_id,url) { @@ -63,24 +63,23 @@ function assign_table(id,table_id,url) { title: "Confirm!", text: "Are You Sure to assign this customer!", }, function () { - $.ajax({ - type: "POST", + $.ajax({ + type: "POST", url: url , data: {id:id,table_id:table_id}, dataType: "json", success: function(data) { if(data.status == true) - { + { window.location.href = '<%=crm_dining_queues_path%>' }else{ swal ( "Alert!" , "Record not found!" , "warning" ); location.reload(); } - } + } }); }); } - diff --git a/app/views/inventory/stock_checks/index.html.erb b/app/views/inventory/stock_checks/index.html.erb index b302882e..b66d74c4 100644 --- a/app/views/inventory/stock_checks/index.html.erb +++ b/app/views/inventory/stock_checks/index.html.erb @@ -244,7 +244,7 @@ \ No newline at end of file + diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index e8074fe2..cfa1df70 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -57,14 +57,14 @@
- <% @tables.each do |table| %> + <% @tables.each do |table| %> <% if table.status == 'occupied' %> <% if table.get_booking.nil? %> <% if table.get_checkout_booking.nil? %>
- <% else %> + <% else %>
- <% end %> + <% end %>
<%= table.name %>
<%= table.zone.name %> @@ -72,12 +72,12 @@
- <% else %> + <% else %> <% if table.get_checkout_booking.nil? %>
- <% else %> + <% else %>
- <% end %> + <% end %>
<%= table.name %>
<%= table.zone.name %> @@ -111,7 +111,7 @@ <% end %>
<%= room.name %>
- <%= room.zone.name %> + <%= room.zone.name %> billed
@@ -123,7 +123,7 @@ <% end %>
<%= room.name %>
- <%= room.zone.name %> + <%= room.zone.name %> new
@@ -132,8 +132,8 @@
<%= room.name %>
- <%= room.zone.name %> - + <%= room.zone.name %> +
<% end %> @@ -160,8 +160,8 @@ <% else %> <% order_status = order.status %> <% end %> - <%= order.order_id %> - <% if !order_status.empty? %>| <%= order_status %> + <%= order.order_id %> + <% if !order_status.empty? %>| <%= order_status %> <% end %>
@@ -193,7 +193,7 @@ <%= t :credit %> <%= t :sale %> <%= t("views.right_panel.detail.date") %> <%= t("views.right_panel.detail.receipt_no") %> <%= t :cashier %> <%= t("views.right_panel.detail.name") %> - <%= t :customer %> <%= t("views.right_panel.detail.name") %> + <%= t :customer %> <%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.credit_amount") %> @@ -245,7 +245,7 @@ <% else %> ORDER DETAILS | Table <%= @dining.name rescue "" %> <% end %> -
+
@@ -335,8 +335,8 @@ <% end %> <% if !order_item.set_menu_items.nil? && order_item.set_menu_items != '[]' - JSON.parse(order_item.set_menu_items).each do |item_instance| - set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f %> + JSON.parse(order_item.set_menu_items).each do |item_instance| + set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f %>
<%= item_instance["item_instance_name"] %> @@ -345,17 +345,17 @@
<%= set_item_option %> <% end %> <% end %> -
- <% end + + <% end sub_total += set_item_prices end %> <%= order_item.qty %> <%= (order_item.qty*order_item.price).to_f + set_item_prices %> - + <% end %> <% end %> - <% end %> + <% end %>
@@ -431,10 +431,10 @@ <% end %> <% end %> - <% if !order_item.set_menu_items.nil? - JSON.parse(order_item.set_menu_items).each do |item_instance| + <% if !order_item.set_menu_items.nil? + JSON.parse(order_item.set_menu_items).each do |item_instance| set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f - %> + %>
<%= item_instance["item_instance_name"] %> <% if !item_instance["options"].nil? && item_instance["options"] != "undefined" %> @@ -444,8 +444,8 @@ <% end %> <% end %> - - <% end + + <% end sub_total += set_item_prices end %> @@ -456,7 +456,7 @@ end %> --> - + <% end %> <% if @sale_array.size > 1 %> @@ -496,7 +496,7 @@ - <% if @dining.status != "available" %> + <% if @dining.status != "available" %> <% if @status_order == 'order' && @status_sale != 'sale' %> <%if !@order_items.empty? %> @@ -526,7 +526,7 @@ <% if current_login_employee.role == "cashier" %> - Edit + Edit Void <% else %> @@ -545,19 +545,19 @@ <% end %> <% if current_login_employee.role != "waiter" %> - + <%if @membership.discount && @obj_sale.customer.membership_id %> <%else%> - <%end%> - + <%end%> + <% end %> <% end %> @@ -583,7 +583,7 @@
- + <% @payment_methods.each_with_index do |pay, pay_index| %> <%if (pay_index+1)%3 == 0 %>
@@ -625,7 +625,7 @@
- +
@@ -638,7 +638,7 @@ - @@ -690,7 +690,7 @@ count += 1 %> - <%= count %> + <%= count %> <%= order_item.item_name %> <% if !order_item.options.nil? && !order_item.options.empty? && order_item.options != "undefined" %> @@ -701,10 +701,10 @@ <% end %> <% end %> - <% if !order_item.set_menu_items.nil? - JSON.parse(order_item.set_menu_items).each do |item_instance| + <% if !order_item.set_menu_items.nil? + JSON.parse(order_item.set_menu_items).each do |item_instance| set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f - %> + %>
<%= item_instance["item_instance_name"] %> <% if !item_instance["options"].nil? && item_instance["options"] != "undefined" %> @@ -714,8 +714,8 @@ <% end %> <% end %> - - <% end + + <% end sub_total += set_item_prices end %> @@ -823,7 +823,7 @@ if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ receipt_no = ($("#receipt_no").html()).trim(); } - + discount="<%= @membership.discount%>" if ($("#server_mode").val() != "cloud") { // first bill not used in cloud if (discount) { @@ -887,7 +887,7 @@ } else { var sale_id = "<%= @dining.id %>"; } - //var table_id = $('.tables').attr("data-id"); + //var table_id = $('.tables').attr("data-id"); window.location.href = '/origami/' + sale_id +"/"+cashier_type+ "/surveys" }); @@ -989,22 +989,22 @@ } location.reload(); } - }); + }); } - }); + }); }); - // click select option icon for add - $(document).on('click', '.payment_btn', function(event){ + // click select option icon for add + $(document).on('click', '.payment_btn', function(event){ active = $(this).hasClass('selected-payment'); value = $(this).data('value'); type = $(this).data('type'); group = $(this).data('group'); payments = $(".payment_btn"); - if (active) { + if (active) { $(this).removeClass('selected-payment'); - }else{ + }else{ $(this).addClass('selected-payment'); } }); //End selecct attribute buttom @@ -1026,7 +1026,7 @@ if(!location.pathname.includes("credit_payment")){ calculate_member_discount(sale_id,"Cash",tax_type); } - } + } } var ajax_url = "/origami/sale/" + sale_id + "/first_bill"; $.ajax({ @@ -1045,7 +1045,7 @@ } location.reload(); } - }); + }); }); function calculate_member_discount(sale_id,type,tax_type) { @@ -1060,10 +1060,10 @@ url: "/origami/" + sale_id + "/member_discount", data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':is_card,'cashier_type':'cashier','tax_type':tax_type }, async: false, - success:function(result){ + success:function(result){ } }); - + } $('#pay').on('click', function () { @@ -1137,11 +1137,11 @@ } }); } - else { + else { location.reload(); } } - }); + }); }else{ swal("Opps","There is no orders!","warning"); } @@ -1151,7 +1151,7 @@ $('#split_bills').click(function(){ var dining_id = "<%= @dining.id %>"; window.location.href = '/origami/table/' + dining_id + "/" + cashier_type +"/split_bills"; - }); + }); $('#move').on('click', function () { if($('#move').is(":visible")) { @@ -1236,7 +1236,7 @@ }else{ swal("Opps","You are not authorized for void","warning") } - + }); $('#commissions').on('click', function () { @@ -1285,7 +1285,7 @@ } }); } - }); + }); }else{ swal("Opps","You are not authorized for void","warning") } @@ -1303,7 +1303,7 @@ window.location.href = '/origami/addorders/' + dining_id; }); - /* check in process */ + /* check in process */ $('#check_in').on('click',function(){ var dining_id = "<%= @dining.id %>"; @@ -1394,7 +1394,7 @@ } }); } - }); + }); } function check_emp_access_code(access_code,type) { @@ -1460,11 +1460,11 @@ type: "POST", url: "/origami/payment/"+cashier_type+"/change_tax", data: {sale_id: sale_id, cashier_type: cashier_type, tax_type: tax_type}, - success:function(data){ + success:function(data){ if(data.status){ localStorage.setItem("tax_type", tax_type); window.location.href = '/origami/table/'+dining_id; - } + } } }); }else{ diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index 8bc99b8b..a4d8a666 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -14,14 +14,14 @@
- <%= f.input :adult, input_html: { value: @survey_data.adult, class: 'col-md-10', :onChange => "total_customer();", :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyAdult(this.value);" }%> + <%= f.input :adult, input_html: { value: @survey_data.adult, class: 'col-md-10', :onChange => "total_customer();", :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyAdult(this.value);" }%>
- +
- <%= f.input :male , input_html: { value: @survey_data.male, class: 'col-md-10', :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyMale(this.value);" }%> + <%= f.input :male , input_html: { value: @survey_data.male, class: 'col-md-10', :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyMale(this.value);" }%>
@@ -29,7 +29,7 @@ <%= f.input :female , input_html: { value: @survey_data.female, class: 'col-md-10', :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyFemale(this.value);" }%>
- + <%= f.input :total_customer, input_html: { value:@survey_data.total_customer , :readonly => true, class: 'col-md-11'} %> <%= f.input :local , input_html: { value: @survey_data.local, class: 'col-md-11', :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyLocal(this.value);" }%> @@ -72,19 +72,19 @@
- <%= f.input :adult , input_html: { class: 'col-md-10' ,min:'1', :onChange => "total_customer();", :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyAdult(this.value);" }%> + <%= f.input :adult , input_html: { class: 'col-md-10' ,min:'1', :onChange => "total_customer();", :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyAdult(this.value);" }%>
- +
- <%= f.input :male , input_html: { min:'1',class: 'col-md-10' , :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyMale(this.value);" }%> + <%= f.input :male , input_html: { min:'1',class: 'col-md-10' , :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyMale(this.value);" }%>
- <%= f.input :female , input_html: { min:'1',class: 'col-md-10' , :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyFemale(this.value);" }%> + <%= f.input :female , input_html: { min:'1',class: 'col-md-10' , :onkeypress => "return isNumberKey(event);", :onkeyup => "surveyFemale(this.value);" }%>
@@ -99,7 +99,7 @@ @@ -139,7 +139,7 @@ <% else %> <% end %> - + <%= f.input :created_by, :as => :hidden, :input_html => { :value => current_login_employee.name } %> <%= f.input :receipt_no, :as => :hidden, :input_html => { :value => @receipt_no} %> @@ -204,11 +204,11 @@
CLR
- - + + - - + + +
@@ -250,7 +250,7 @@ return false; } else { return true; - } + } } function surveyChild(val){ var aa = parseInt(val); @@ -273,12 +273,12 @@ if(isNaN(aa)) $("#survey_local").val(""); } -var cashier_type = "<%= @cashier_type %>"; +var cashier_type = "<%= @cashier_type %>"; $(document).ready(function(){ /* check webview loaded*/ var webview = <%= @webview %>; showHideNavbar(webview); - + $('.foreignerDiv').removeClass("hidden"); setHeaderBreadCrumb(_SURVEY_); <% if !@survey_data.nil? %> @@ -293,7 +293,7 @@ var cashier_type = "<%= @cashier_type %>"; +'
' +' ' - +'<% Lookup.where("lookup_type = ?", "country" ).each do |ct| %>' + +'<% Lookup.where("lookup_type = ? and shop_code='#{@shop.shop_code}'", "country" ).each do |ct| %>' +'' +'<%end %>' @@ -340,19 +340,19 @@ var cashier_type = "<%= @cashier_type %>"; $('#newTemplate').append(text_box); }); - //click remove buttom + //click remove buttom $('#newTemplate').on('click','#removeRow', function(){ $(this).parent().parent().remove() }); $( "input" ).focusin(function() { - $('.addfocus').removeClass('addfocus'); + $('.addfocus').removeClass('addfocus'); $( this ).addClass('addfocus'); }); $(".cashier_number").on('click', function(event){ if(event.handled !== true) { - + var original_value=''; original_value = $('.addfocus').val(); @@ -362,50 +362,50 @@ var cashier_type = "<%= @cashier_type %>"; case 'num': var input_value = $(this).attr("data-value"); if (original_value == "0.0"){ - var value = $('.addfocus').val(input_value); + var value = $('.addfocus').val(input_value); if ($("#survey_child").hasClass('addfocus')){ var child = $("#survey_child").val()+value; var adult = $("#survey_adult").val() || 0; var result = parseInt(child) + parseInt(adult); $("#survey_total_customer").val(result); - } + } if ($("#survey_adult").hasClass('addfocus')){ var adult = $("#survey_adult").val()+value; var child = $("#survey_child").val() || 0; var result = parseInt(child) + parseInt(adult); $("#survey_total_customer").val(result); - } + } } else{ - var value = $('.addfocus').val(original_value + '' + input_value); + var value = $('.addfocus').val(original_value + '' + input_value); if ($("#survey_child").hasClass('addfocus')){ var child = $("#survey_child").val()+value; var adult = $("#survey_adult").val() || 0; var result = parseInt(child) + parseInt(adult); $("#survey_total_customer").val(result); - } + } if ($("#survey_adult").hasClass('addfocus')){ var adult = $("#survey_adult").val()+value; var child = $("#survey_child").val() || 0; var result = parseInt(child) + parseInt(adult); $("#survey_total_customer").val(result); - } + } } break; case 'add': var input_value = $(this).attr("data-value"); amount = parseInt(input_value); - $('.addfocus').val(amount); + $('.addfocus').val(amount); break; case 'del' : var discount_text=$('.addfocus').val(); - $('.addfocus').val(discount_text.substr(0,discount_text.length-1)); + $('.addfocus').val(discount_text.substr(0,discount_text.length-1)); break; case 'clr': - $('.addfocus').val(""); + $('.addfocus').val(""); if($("#survey_child").hasClass('addfocus')){ $("#survey_child").val(""); var adult = $("#survey_adult").val() || 0; @@ -416,7 +416,7 @@ var cashier_type = "<%= @cashier_type %>"; var child = $("#survey_child").val() || 0; var result = parseInt(child); $("#survey_total_customer").val(result); - } + } break; } event.handled = true; @@ -470,10 +470,10 @@ var cashier_type = "<%= @cashier_type %>"; +'
' +'