diff --git a/.gitignore b/.gitignore index ba7590c9..b33a0ee8 100755 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ pickle-email-*.html /config/initializers/* config/deploy/config/* #config/puma.rb +config/license.yml config/shops.json config/license.yml diff --git a/README.md b/README.md index 7d64f2eb..67460830 100755 --- a/README.md +++ b/README.md @@ -262,10 +262,6 @@ Strip insignificant zeros => settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros, value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] } -For Booking checkin time limit -settings/lookups => -{ lookup_type: checkin_time_limit, name: CheckinTimeLimit, value: total hours before checkout (e.g., '48')) } - /_ Customer Types in lookups _/ 1. settings/lookups => { type:customer_type, name: Dinein, value:Dinein } diff --git a/app/assets/javascripts/api/menu_item_groups.coffee b/app/assets/javascripts/api/menu_item_groups.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/api/menu_item_groups.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/dashboard.coffee b/app/assets/javascripts/dashboard.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/dashboard.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 650c81ef..8e3bf9fa 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -373,25 +373,10 @@ function setCommPorts(comPortLists) { } /** pay with CB bank **/ -function pay_withBank( - cmd_type, - payment_type, - bnk_bill_amount, - sale_id, - receipt_no, - cashier_type -) { - $("#loading_wrapper").show(); +function pay_withBank(cmd_type, payment_type, bnk_bill_amount,sale_id,receipt_no,cashier_type) { + $("#loading_wrapper").show(); var com_port = $("#com_port_name").val(); - reqCardSaleTrans( - cmd_type, - payment_type, - bnk_bill_amount, - sale_id, - receipt_no, - com_port, - cashier_type - ); + reqCardSaleTrans(cmd_type, payment_type, bnk_bill_amount, sale_id, receipt_no, com_port,cashier_type); } //add req data to card_sale_trans table diff --git a/app/assets/javascripts/sessions.coffee b/app/assets/javascripts/sessions.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/sessions.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/settings/menu_item_groups.coffee b/app/assets/javascripts/settings/menu_item_groups.coffee new file mode 100644 index 00000000..fad9c6c6 --- /dev/null +++ b/app/assets/javascripts/settings/menu_item_groups.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ \ No newline at end of file diff --git a/app/assets/stylesheets/api/menu_item_groups.scss b/app/assets/stylesheets/api/menu_item_groups.scss new file mode 100644 index 00000000..90b85063 --- /dev/null +++ b/app/assets/stylesheets/api/menu_item_groups.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the api/menu_item_groups controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss new file mode 100644 index 00000000..3a51a8cf --- /dev/null +++ b/app/assets/stylesheets/dashboard.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the dashboard controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sessions.scss b/app/assets/stylesheets/sessions.scss new file mode 100644 index 00000000..7bef9cf8 --- /dev/null +++ b/app/assets/stylesheets/sessions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sessions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/settings/menu_item_groups.scss b/app/assets/stylesheets/settings/menu_item_groups.scss new file mode 100644 index 00000000..297b27f5 --- /dev/null +++ b/app/assets/stylesheets/settings/menu_item_groups.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the settings/menu_item_groups controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index ac9642f6..c728a168 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -6,7 +6,7 @@ class Api::BillController < Api::ApiController def create @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 shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0]) if !ShiftSale.current_shift.nil? #create Bill by Booking ID table = 0 diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index cb00ea1d..8585da17 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -1,8 +1,8 @@ module LoginVerification extend ActiveSupport::Concern included do - before_action :authenticate_session_token - helper_method :current_company, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :current_shop + before_action :authenticate + helper_method :current_company, :current_shop, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :shop_detail end #this is base api base controller to need to inherit. @@ -74,9 +74,10 @@ module LoginVerification def authenticate_session_token token = session[:session_token] + puts "token #{token}" if (token) #@current_user = User.find_by(api_key: token) - #Rails.logger.debug "token - " + token.to_s + # Rails.logger.debug "token - " + token.to_s @user = Employee.authenticate_by_token(token) if @user return true @@ -86,6 +87,6 @@ module LoginVerification end def render_unauthorized - redirect_to root_path + redirect_to login_path end end diff --git a/app/controllers/concerns/multi_tenancy.rb b/app/controllers/concerns/multi_tenancy.rb index 0891f925..b9e74556 100644 --- a/app/controllers/concerns/multi_tenancy.rb +++ b/app/controllers/concerns/multi_tenancy.rb @@ -15,14 +15,8 @@ module MultiTenancy def find_tenant_by_subdomain_or_name if request.subdomains.last && request.subdomains.last != "www" set_current_tenant(Shop.find_by(subdomain: request.subdomains.last)) - elsif ENV["SERVER_MODE"] == "application" - license = License.new(ENV["SX_PROVISION_URL"], request.host) - shop_name = license.read_license_no_decrypt("shop_name") - if Rails.env.production? || shop_name - set_current_tenant(Shop.find_by(name: shop_name)) - else - set_current_tenant(Shop.first) - end + elsif Shop.count == 1 + set_current_tenant(Shop.first) end end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb new file mode 100644 index 00000000..9bcd3442 --- /dev/null +++ b/app/controllers/dashboard_controller.rb @@ -0,0 +1,94 @@ +class DashboardController < ApplicationController + + def index + @from, @to = get_date_range_from_params + + @shop = Shop.current_shop + + @orders = Sale.receipt_date_between(@from, @to).where("payment_status = 'new' and sale_status = 'bill'") + @sales = Sale.receipt_date_between(@from, @to).completed + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user) + @orders = @orders.where(shift_sale_id: shift.id) + @sales = @sales.where(shift_sale_id: shift.id) + end + end + + @top_products = Sale.top_bottom_products(current_user,@from,@to,"top") + @bottom_products = Sale.top_bottom_products(current_user,@from,@to,"bottom") + @hourly_sales = Sale.hourly_sales(current_user,@from,@to) + # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') + # .sum(:grand_total) + employee_sales = Sale.employee_sales(current_user,@from,@to) + # .sum("(CASE WHEN sp.payment_method='cash' THEN ((sp.payment_amount) - (sales.amount_changed)) ELSE (sp.payment_amount) END)") + @employee_sales = [] + if !employee_sales.nil? + employee_sales.each do |emp| + emp_data = [] + if emp.payment_amount > 0 + emp_data.push([emp.e_name, emp.payment_amount]) + + @employee_sales.push({'name' => emp.payment_method, 'data' => emp_data}) + end + end + end + @inventories = StockJournal.inventory_balances(@from,@to).sum(:balance) + + @total_trans = Sale.total_trans(current_user,@from,@to) + @total_card = Sale.total_card_sale(current_user,@from,@to) + @total_credit = Sale.credit_payment(current_user,@from,@to) + + @sale_data = Array.new + @total_payment_methods = Sale.total_payment_methods(current_user,@from,@to) + + if !@total_payment_methods.nil? + @total_payment_methods.each do |payment| + pay = Sale.payment_sale(payment.payment_method, current_user,@from,@to) + @sale_data.push({payment.payment_method => pay.payment_amount}) + end + end + + @summ_sale = Sale.summary_sale_receipt(current_user,@from,@to) + @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(current_user,@from,@to) + # @total_other_customer = Sale.total_other_customer(today,current_user) + + @total_order = Sale.total_order(current_user,@from,@to) + @total_accounts = Account.select("accounts.id as account_id, accounts.title as title") + @account_data = Array.new + if !@total_accounts.nil? + @total_accounts.each do |account| + acc = Sale.account_data(account.account_id,current_user,@from,@to) + if !acc.nil? && acc.cnt_acc > 0 + @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) + end + end + @total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? } + end + + @top_items = Sale.top_items(current_user,@from,@to) + @total_foc_items = Sale.total_foc_items(current_user,@from,@to) + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + end + +private + + def get_date_range_from_params + if params[:from].present? && params[:to].present? + if params[:from_time].present? && params[:to_time].present? + from = Time.parse("#{params[:from]} #{params[:from_time]}") + to = Time.parse("#{params[:to]} #{params[:to_time]}") + else + from = Time.parse(params[:from]) + to = Time.parse(params[:to]).end_of_day + end + else + from = Time.now.beginning_of_day + to = Time.now.end_of_day + end + return from, to + end + +end diff --git a/app/controllers/foodcourt/orders_controller.rb b/app/controllers/foodcourt/orders_controller.rb index 0343c9e2..b9fe6b77 100755 --- a/app/controllers/foodcourt/orders_controller.rb +++ b/app/controllers/foodcourt/orders_controller.rb @@ -87,6 +87,7 @@ class Foodcourt::OrdersController < BaseFoodcourtController def current_shift_order_count @current_shift = ShiftSale.current_shift + status = ['completed', 'void'] @pending_sales = Sale.where('shift_sale_id = ? AND sale_status NOT IN (?)', @current_shift.id, status) @pending_orders = Sale.pending_order('food_court') @occupied_table = @pending_sales.length + @pending_orders.length @@ -97,10 +98,10 @@ class Foodcourt::OrdersController < BaseFoodcourtController @cashier_type = "food_court" today = DateTime.now day = Date.today.wday - + @menus = [] @menu = [] - + if params[:id].include? "BKI" @table_id = nil @table = nil @@ -266,7 +267,7 @@ class Foodcourt::OrdersController < BaseFoodcourtController if ["quick_service", "food_court"].include? order.source redirect_to "/foodcourt/sale/#{sale_data.sale_id}/food_court/payment#" end - # + # end def completed diff --git a/app/controllers/foodcourt/shifts_controller.rb b/app/controllers/foodcourt/shifts_controller.rb index 6866217b..792cf344 100755 --- a/app/controllers/foodcourt/shifts_controller.rb +++ b/app/controllers/foodcourt/shifts_controller.rb @@ -69,8 +69,6 @@ class Foodcourt::ShiftsController < BaseFoodcourtController if ENV["SERVER_MODE"] != "cloud" #no print in cloud server - - # if !close_cashier_print[0].nil? # @close_cashier_print = close_cashier_print[0][1] # end @@ -112,6 +110,7 @@ class Foodcourt::ShiftsController < BaseFoodcourtController @total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount @total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount @total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments + @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) @@ -125,7 +124,7 @@ class Foodcourt::ShiftsController < BaseFoodcourtController end find_close_cashier_print = Lookup.collection_of('close_cashier_print') if find_close_cashier_print[0][1].to_i > 0 - printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments,"foocourt") + printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments,@payment_methods,"foodcourt") end end end diff --git a/app/controllers/foodcourt/void_controller.rb b/app/controllers/foodcourt/void_controller.rb index 9317d163..29d65868 100755 --- a/app/controllers/foodcourt/void_controller.rb +++ b/app/controllers/foodcourt/void_controller.rb @@ -8,11 +8,6 @@ class Foodcourt::VoidController < BaseFoodcourtController access_code = params[:access_code] if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) - if sale.discount_type == "member_discount" - sale.update_attributes(total_discount: 0) - sale.compute_by_sale_items(0, nil, order_source) - end - # update count for shift sale if(sale.sale_status == "completed") if sale.shift_sale_id != nil @@ -28,6 +23,11 @@ class Foodcourt::VoidController < BaseFoodcourtController end end + if sale.discount_type == "member_discount" + sale.update_attributes(total_discount: 0) + sale.compute_by_sale_items(0, nil, order_source) + end + sale.rounding_adjustment = 0.0 sale.payment_status = 'void' sale.sale_status = 'void' diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 72b319cc..a5eb11b3 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,256 +1,54 @@ class HomeController < ApplicationController - # layout "application", except: [:index, :show] - # 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? - redirect_to root_path - end - 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) - - # byebug - # @roles = Lookup.collection_of("employee_roles") - @login_form = LoginForm.new() - render "layouts/login_dashboard", layout: false + redirect_to route_by_role end - def show - @login_form = LoginForm.new() - @login_form.emp_id = params[:emp_id] - render "layouts/login", layout: false - end +private - def update - @login_form = LoginForm.new() - @login_form.emp_id = params[:emp_id] - @login_form.password = params[:login_form][:password] - @employee = Employee.login(current_shop,@login_form.emp_id, @login_form.password) - - if @employee != nil - session[:session_token] = @employee.token_session - route_by_role(@employee) - else - flash[:notice] ="Invalid PIN for Employee. Please try again!" - render :show - end - end - - def create - @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) - - if @employee != nil - if @employee.is_active - if @employee.role == "administrator" - session[:session_token] = @employee.token_session - redirect_to dashboard_path - elsif @employee.role == "cashier" - session[:session_token] = @employee.token_session - route_by_role(@employee) - elsif @employee.role == "manager" - session[:session_token] = @employee.token_session - redirect_to dashboard_path - elsif @employee.role == "supervisor" - session[:session_token] = @employee.token_session - route_by_role(@employee) - # redirect_to origami_root_path - elsif @employee.role == "waiter" - session[:session_token] = @employee.token_session - route_by_role(@employee) - elsif @employee.role == "account" - session[:session_token] = @employee.token_session - redirect_to reports_dailysale_index_path - elsif @employee.role == "kitchen" - session[:session_token] = @employee.token_session - redirect_to oqs_root_path - elsif @employee.role == "foodcourt_cashier" - session[:session_token] = @employee.token_session - route_by_role(@employee) - else - render :index - end - else - redirect_to root_path, :notice => "This Employee is not active" - end - else - redirect_to root_path, :notice => "Username and Password doesn't match!" - end - - end - - def dashboard - @from, @to = get_date_range_from_params - - @shop = Shop.current_shop - - @orders = Sale.receipt_date_between(@from, @to).where("payment_status = 'new' and sale_status = 'bill'") - @sales = Sale.receipt_date_between(@from, @to).completed - - if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user.id) - @orders = @orders.where(shift_sale_id: shift.id) - @sales = @sales.where(shift_sale_id: shift.id) - end - end - - @top_products = Sale.top_bottom_products(current_user,@from,@to,"top") - @bottom_products = Sale.top_bottom_products(current_user,@from,@to,"bottom") - @hourly_sales = Sale.hourly_sales(current_user,@from,@to) - # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') - # .sum(:grand_total) - employee_sales = Sale.employee_sales(current_user,@from,@to) - # .sum("(CASE WHEN sp.payment_method='cash' THEN ((sp.payment_amount) - (sales.amount_changed)) ELSE (sp.payment_amount) END)") - @employee_sales = [] - if !employee_sales.nil? - employee_sales.each do |emp| - emp_data = [] - if emp.payment_amount > 0 - emp_data.push([emp.e_name, emp.payment_amount]) - - @employee_sales.push({'name' => emp.payment_method, 'data' => emp_data}) - end - end - end - @inventories = StockJournal.inventory_balances(@from,@to).sum(:balance) - - @total_trans = Sale.total_trans(current_user,@from,@to) - @total_card = Sale.total_card_sale(current_user,@from,@to) - @total_credit = Sale.credit_payment(current_user,@from,@to) - - @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(current_user,@from,@to) - - if !@total_payment_methods.nil? - @total_payment_methods.each do |payment| - pay = Sale.payment_sale(payment.payment_method, current_user,@from,@to) - @sale_data.push({payment.payment_method => pay.payment_amount}) - end - end - - @summ_sale = Sale.summary_sale_receipt(current_user,@from,@to) - @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(current_user,@from,@to) - # @total_other_customer = Sale.total_other_customer(today,current_user) - - @total_order = Sale.total_order(current_user,@from,@to) - @total_accounts = Account.select("accounts.id as account_id, accounts.title as title") - @account_data = Array.new - if !@total_accounts.nil? - @total_accounts.each do |account| - acc = Sale.account_data(account.account_id,current_user,@from,@to) - if !acc.nil? && acc.cnt_acc > 0 - @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) - end - end - @total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? } - end - - @top_items = Sale.top_items(current_user,@from,@to) - @total_foc_items = Sale.total_foc_items(current_user,@from,@to) - - # get printer info - @print_settings = PrintSetting.get_precision_delimiter() - end - - def destroy - # clear in employee session - Employee.logout(session[:session_token]) - session[:session_token] = nil - # redirect_to root_path - render :json => {:status=> "Success", :url => root_path }.to_json - end - - def run_teamviewer - if File.directory?("/opt/teamviewer") - output = IO.popen('/opt/teamviewer/tv_bin/script/teamviewer') - render :json => {:status=> true} - else - render :json => {:status=> false} - end - end - - private - - # Never trust parameters from the scary internet, only allow the white list through. - def settings_home_params - params.require(:login_form).permit(:emp_id, :password) - end - - def route_by_role(employee) - if employee.role == "administrator" - # redirect_to dashboard_path - shift = ShiftSale.current_open_shift(employee) - if !shift.nil? - redirect_to origami_root_path - else - redirect_to dashboard_path - end - elsif employee.role == "cashier" + def route_by_role + if current_user.role == "administrator" + dashboard_path + elsif current_user.role == "cashier" food_court = Lookup.find_by_lookup_type_and_value("food_court", "1") #check if cashier has existing open cashier - shift = ShiftSale.current_open_shift(employee) + shift = ShiftSale.current_open_shift(current_user) if food_court if !shift.nil? - redirect_to foodcourt_food_court_path(:anchor => "") + foodcourt_food_court_path(:anchor => "") else - redirect_to new_foodcourt_shift_path + new_foodcourt_shift_path end else if !shift.nil? - redirect_to origami_dashboard_path - # redirect_to origami_root_path + origami_dashboard_path else - redirect_to new_origami_shift_path + new_origami_shift_path end end - elsif employee.role == "manager" - redirect_to dashboard_path - elsif employee.role == "waiter" - redirect_to origami_dashboard_path - elsif employee.role == "crm" - redirect_to crm_root_path - elsif employee.role == "supervisor" - redirect_to origami_dashboard_path - elsif employee.role == "account" - redirect_to reports_dailysale_index_path + elsif current_user.role == "manager" + dashboard_path + elsif current_user.role == "supervisor" + origami_dashboard_path + elsif current_user.role == "waiter" + origami_dashboard_path + elsif current_user.role == "crm" + crm_root_path + elsif current_user.role == "account" + reports_dailysale_index_path + elsif @current_user.role == "kitchen" + oqs_root_path elsif employee.role == "foodcourt_cashier" #check if cashier has existing open cashier shift = ShiftSale.current_open_shift(employee) if !shift.nil? - redirect_to foodcourt_food_court_path + foodcourt_food_court_path else - redirect_to new_foodcourt_shift_path + new_foodcourt_shift_path end + else + login_path end end - def get_date_range_from_params - if params[:from].present? && params[:to].present? - if params[:from_time].present? && params[:to_time].present? - from = Time.parse("#{params[:from]} #{params[:from_time]}") - to = Time.parse("#{params[:to]} #{params[:to_time]}") - else - from = Time.parse(params[:from]) - to = Time.parse(params[:to]).end_of_day - end - else - from = Time.now.beginning_of_day - to = Time.now.end_of_day - end - return from, to - end end diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index 7585e080..3e9ed314 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,6 +1,6 @@ class InstallController < BaseController skip_before_action :set_current_tenant_by_subdomain_or_name - skip_before_action :verify_authenticity_token + before_action :lookup_domain def index end @@ -19,55 +19,31 @@ class InstallController < BaseController db_password = params[:db_password] phrase = license_key - # Check Exists IV - # if flag == "<%= ENV['AES_IV'] %>" - # # Export for Key - # aes = MyAesCrypt.new - # aes_key, aes_iv = aes.export_key(phrase) - # else - # aes_key = ENV["AES_KEY"] - # aes_iv = ENV["AES_IV"] - # end - @license = License.new(ENV["SX_PROVISION_URL"], request.host) response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password) if response[:status] - redirect_to root_url, notice: response["message"] + redirect_to root_path, notice: response["message"] else redirect_to activate_path, notice: response["message"] end end +private + def lookup_domain if ENV["SERVER_MODE"] == "cloud" not_found - elsif ENV["SERVER_MODE"] == "application" - if check_license(request.host) - redirect_to root_url - end - elsif request.subdomains.last && request.subdomains.last != "www" - if check_license(request.host) - redirect_to root_url - elsif !check_subdomain(request.host) - not_found + elsif ENV["SERVER_MODE"] == "application" || request.subdomains.last && request.subdomains.last != "www" + if current_license.exists? #(request.host) + if current_license.expired? + redirect_to review_license_path + else + redirect_to root_path + end end else not_found end end - # def current_license(url, key) - # @license = License.new(url, key) - - # ##creating md5 hash - # md5_hostname = Digest::MD5.new - # md5key = md5_hostname.update(request.host) - # if (@license.detail_with_local_cache(key, md5key.to_s) == true) - # #if (@license.detail == true) - - # return @license - # else - # return nil - # end - # end end diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index ef855bbf..5df7a7f0 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -14,7 +14,7 @@ class Origami::DashboardController < BaseOrigamiController @sale_data.push({payment.payment_method => pay.payment_amount}) end else - @sale_data = nil + @sale_data = nil end @summ_sale = Sale.summary_sale_receipt(current_user) @@ -35,7 +35,7 @@ class Origami::DashboardController < BaseOrigamiController end @total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? } else - @account_data = nil + @account_data = nil end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 8f19d713..35a6e464 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -390,7 +390,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 @@ -506,7 +506,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 diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index bbe2cf57..f4dec719 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -111,7 +111,7 @@ class Origami::ShiftsController < BaseOrigamiController @total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount @total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount @total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments - + @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::CashierStationPrinter.new(print_settings) @@ -124,9 +124,7 @@ class Origami::ShiftsController < BaseOrigamiController end find_close_cashier_print = Lookup.collection_of('close_cashier_print') if find_close_cashier_print[0][1].to_i > 0 - - - printer.print_close_cashier(print_settings,cashier_terminal, @shift, @sale_items, @total_other_charges_info, current_shop,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) + printer.print_close_cashier(print_settings,cashier_terminal, @shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments,@payment_methods) end end end diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 4ec5b084..cea64868 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -9,11 +9,6 @@ class Origami::VoidController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) - if sale.discount_type == "member_discount" - sale.update_attributes(total_discount: 0) - sale.compute_by_sale_items(0, nil, order_source) - end - # update count for shift sale if(sale.sale_status == "completed") if sale.shift_sale_id != nil @@ -29,6 +24,11 @@ class Origami::VoidController < BaseOrigamiController end end + if sale.discount_type == "member_discount" + sale.update_attributes(total_discount: 0) + sale.compute_by_sale_items(0, nil, order_source) + end + sale.rounding_adjustment = 0.0 sale.payment_status = 'void' sale.sale_status = 'void' @@ -94,47 +94,47 @@ class Origami::VoidController < BaseOrigamiController customer= Customer.find(sale.customer_id) - #shop detail - shop_details = Shop.current_shop - # get member information - rebate = MembershipSetting.find_by_rebate(1) - if customer.membership_id != nil && rebate - member_info = Customer.get_member_account(customer) - rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) - # current_balance = SaleAudit.paymal_search(sale_id) - current_balance = 0 - end + #shop detail + shop_details = Shop.current_shop + # get member information + rebate = MembershipSetting.find_by_rebate(1) + if customer.membership_id != nil && rebate + member_info = Customer.get_member_account(customer) + rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) + # current_balance = SaleAudit.paymal_search(sale_id) + current_balance = 0 + end - printer = PrintSetting.all + printer = PrintSetting.all - unique_code="ReceiptBillPdf" - if !printer.empty? - printer.each do |printer_setting| - if printer_setting.unique_code == 'ReceiptBillPdf' - unique_code="ReceiptBillPdf" - elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' - unique_code="ReceiptBillA5Pdf" - elsif printer_setting.unique_code == 'ReceiptBillStarPdf' - unique_code="ReceiptBillStarPdf" - end - end - end - # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_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) - result = { - :filepath => filename, - :printer_model => print_settings.brand_name, - :printer_url => print_settings.api_settings - } + unique_code="ReceiptBillPdf" + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'ReceiptBillPdf' + unique_code="ReceiptBillPdf" + elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' + unique_code="ReceiptBillA5Pdf" + elsif printer_setting.unique_code == 'ReceiptBillStarPdf' + unique_code="ReceiptBillStarPdf" + end + end + end + # get printer info + print_settings=PrintSetting.find_by_unique_code(unique_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) + result = { + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } - # Mobile Print - render :json => result.to_json + # Mobile Print + render :json => result.to_json # end #end print diff --git a/app/controllers/origami/waste_spoile_controller.rb b/app/controllers/origami/waste_spoile_controller.rb index 46b6f843..c44cbcee 100755 --- a/app/controllers/origami/waste_spoile_controller.rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -9,10 +9,7 @@ class Origami::WasteSpoileController < BaseOrigamiController SaleTax.where("sale_id='#{sale_id}'").find_each do |existing_tax| existing_tax.delete end - sale.update_attributes(total_discount: 0,total_tax: 0,grand_total: sale.total_amount,rounding_adjustment:0) - sale.payment_status = remark - sale.sale_status = remark - sale.save + sale.update_attributes(total_discount: 0, total_tax: 0, grand_total: sale.total_amount, rounding_adjustment:0, payment_status: remark, sale_status: remark) # add to sale item with foc # sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null") diff --git a/app/controllers/reports/dailysale_controller.rb b/app/controllers/reports/dailysale_controller.rb index 159232db..479bcfe8 100755 --- a/app/controllers/reports/dailysale_controller.rb +++ b/app/controllers/reports/dailysale_controller.rb @@ -19,5 +19,4 @@ class Reports::DailysaleController < BaseReportController def show end - end diff --git a/app/controllers/reports/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb index b75a6b34..9ca18ee6 100644 --- a/app/controllers/reports/payment_method_controller.rb +++ b/app/controllers/reports/payment_method_controller.rb @@ -1,69 +1,65 @@ class Reports::PaymentMethodController < BaseReportController - # authorize_resource :class => false - def index +# authorize_resource :class => false + def index + @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") - @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") + @payments = [["All",''], ["Cash","cash"], ["Credit","creditnote"], ["FOC","foc"]] + @payments += PaymentMethodSetting.pluck(:payment_method).map { |payment_method| [payment_method.parameterize == 'paymal' ? 'Card' : payment_method, payment_method.parameterize] } - @payments = [["All",''], ["Cash","cash"], ["Card", "card"], ["Credit","creditnote"], - ["FOC","foc"]] + PaymentMethodSetting.pluck(:payment_method).map { |payment_method| [payment_method, payment_method.parameterize] } + # @payment_methods.each do |m| + # @payments.push(["#{m} Payment", m.parameterize]) + # end + from, to = get_date_range_from_params - # @payment_methods.each do |m| - # @payments.push(["#{m} Payment", m.parameterize]) - # end + @shift = '' + if params[:shift_name].to_i != 0 + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + @payment_type = params[:payment_type] + @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift,from,to,@payment_type) + @from = from + @to = to + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + if @shift.present? + @shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end - from, to = get_date_range_from_params - - - @shift = '' - if params[:shift_name].to_i != 0 - shift_sale = ShiftSale.find(params[:shift_name]) - if to.blank? - @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) - else - @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) - end - end - @payment_type = params[:payment_type] - @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift,from,to,@payment_type) - @from = from - @to = to - # get printer info - @print_settings = PrintSetting.get_precision_delimiter() - if @shift.present? - @shift.each do |sh| - @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") - @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") - @shift_data = sh - end - end - - respond_to do |format| - format.html - format.xls - end + respond_to do |format| + format.html + format.xls end - - def show - from, to = get_date_range_from_params - - @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) - - date_arr = Array.new - @sale_data.each do |sale| - local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") - local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") - opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc - closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc - shift_id = sale.id.nil? ? '-' : sale.id - str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} - date_arr.push(str) - end - - out = {:status => 'ok', :message => date_arr} - - respond_to do |format| - format.json { render json: out } - end - end - end + + def show + from, to = get_date_range_from_params + + @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) + + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + end + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end +end diff --git a/app/controllers/reports/receipt_no_detail_controller.rb b/app/controllers/reports/receipt_no_detail_controller.rb index b119b7f9..be9c599c 100755 --- a/app/controllers/reports/receipt_no_detail_controller.rb +++ b/app/controllers/reports/receipt_no_detail_controller.rb @@ -1,69 +1,67 @@ class Reports::ReceiptNoDetailController < BaseReportController authorize_resource :class => false - def index - @payment_methods = [["All", ''], ["Cash", "cash"], ["Card", "card"], ["Credit", "creditnote"], ["FOC", "foc"]] + PaymentMethodSetting.pluck(:payment_method).map { |payment_method| [payment_method, payment_method.parameterize] } - from, to = get_date_range_from_params + def index + @payment_methods = [["All", ''], ["Cash", "cash"], ["Credit", "creditnote"], ["FOC", "foc"]] + @payment_methods += PaymentMethodSetting.pluck(:payment_method).map { |payment_method| [payment_method.parameterize == 'paymal' ? 'Card' : payment_method, payment_method.parameterize] } - @shift_sale_range = '' + from, to = get_date_range_from_params + @shift = '' + if params[:shift_name].to_i != 0 + @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) - @shift = '' - if params[:shift_name].to_i != 0 - @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + @shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) + else + if @shift_sale.shift_closed_at.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',@shift_sale.shift_started_at) + else + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',@shift_sale.shift_started_at, @shift_sale.shift_closed_at) + end + end + end - @shift_sale = ShiftSale.find(params[:shift_name]) - if to.blank? - @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) - else - if @shift_sale.shift_closed_at.blank? - @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',@shift_sale.shift_started_at) - else - @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',@shift_sale.shift_started_at, @shift_sale.shift_closed_at) - end - end - end - - payment_type = params[:payment_type] - @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) - - @from = from - @to = to - # get printer info - @print_settings = PrintSetting.get_precision_delimiter() - if @shift.present? - @shift.each do |sh| - @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") - @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") - @shift_data = sh - end - end - respond_to do |format| - format.html - format.xls - end - end - - def show - from, to = get_date_range_from_params - - @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) - - date_arr = Array.new - @sale_data.each do |sale| - local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") - local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") - opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc - closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc - shift_id = sale.id.nil? ? '-' : sale.id - str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} - date_arr.push(str) - end - - out = {:status => 'ok', :message => date_arr} - - respond_to do |format| - format.json { render json: out } - end - end + payment_type = params[:payment_type] + @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) + @from = from + @to = to + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + if @shift.present? + @shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + respond_to do |format| + format.html + format.xls + end end + + def show + from, to = get_date_range_from_params + + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + end + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end +end diff --git a/app/controllers/review_license_controller.rb b/app/controllers/review_license_controller.rb new file mode 100644 index 00000000..e1739aac --- /dev/null +++ b/app/controllers/review_license_controller.rb @@ -0,0 +1,34 @@ +class ReviewLicenseController < BaseController + before_action :lookup_domain + + def index + @license = current_license + @plan = @license.read_license("plan_name") + @bis_name = @license.read_license_no_decrypt("shop_name") + @expired_at = @license.read_license("renewable_date") + @license_status = @license.detail_with_local_file + end + + def create + if current_license.verify_license + redirect_to root_path + else + redirect_to review_license_path, flash: { message: '*** License can not be verified ***' } + end + end + +private + + def lookup_domain + if ENV["SERVER_MODE"] == "cloud" + not_found + elsif ENV["SERVER_MODE"] == "application" || request.subdomains.last && request.subdomains.last != "www" + if !current_license.exists? #(request.host) + redirect_to activate_path + end + else + not_found + end + end + +end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb new file mode 100644 index 00000000..0f6d26d4 --- /dev/null +++ b/app/controllers/sessions_controller.rb @@ -0,0 +1,76 @@ +class SessionsController < ApplicationController + skip_before_action :authenticate, only: [:index, :show, :update, :create, :destroy] + # Special check for only dashboard + + 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) + # byebug + # @roles = Lookup.collection_of("employee_roles") + @login_form = LoginForm.new() + render "layouts/login_dashboard", layout: false + end + + def show + @login_form = LoginForm.new() + @login_form.emp_id = params[:emp_id] + render "layouts/login", layout: false + end + + def update + @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) + + if @employee != nil + session[:session_token] = @employee.token_session + redirect_to root_path + else + flash[:notice] = "Invalid PIN for Employee. Please try again!" + render :show + end + end + + def create + @login_form = LoginForm.new(settings_home_params) + @employee = Employee.login(@login_form.emp_id, @login_form.password) + + if @employee != nil + if @employee.is_active + session[:session_token] = @employee.token_session + redirect_to root_path + else + redirect_to login_path, :notice => "This Employee is not active" + end + else + redirect_to login_path, :notice => "Username and Password doesn't match!" + end + end + + def destroy + # clear in employee session + Employee.logout(session[:session_token]) + session[:session_token] = nil + # redirect_to root_path + render :json => {:status=> "Success", :url => root_path }.to_json + end + + def run_teamviewer + if File.directory?("/opt/teamviewer") + output = IO.popen('/opt/teamviewer/tv_bin/script/teamviewer') + render :json => {:status=> true} + else + render :json => {:status=> false} + end + end + + private + + # Never trust parameters from the scary internet, only allow the white list through. + def settings_home_params + params.require(:login_form).permit(:emp_id, :password) + end + +end diff --git a/app/controllers/settings/menu_item_groups_controller.rb b/app/controllers/settings/menu_item_groups_controller.rb new file mode 100644 index 00000000..538d8d94 --- /dev/null +++ b/app/controllers/settings/menu_item_groups_controller.rb @@ -0,0 +1,59 @@ +class Settings::MenuItemGroupsController < ApplicationController + def index + @menu_item_group = Lookup.where(lookup_type:'menu_item_groups') + end + def new + @settings_menu_item_group = Lookup.new + @menu_category = MenuCategory.order(:name) + end + def create + @settings_menu_item_group = Lookup.new(settings_lookup_params) + menu_item = settings_lookup_params[:value].reject(&:empty?) + menu_category = "{\"#{settings_lookup_params[:lookup_type]}\" : #{menu_item} }" + @settings_menu_item_group.lookup_type = "menu_item_groups" + @settings_menu_item_group.value = menu_category + respond_to do |format| + if @settings_menu_item_group.save + format.html { redirect_to settings_menu_item_groups_path, notice: 'Menu item group was successfully created.' } + format.json { render :show, status: :created, location: @settings_menu_item_group } + else + format.html { render :new } + format.json { render json: settings_menu_item_groups_path.errors, status: :unprocessable_entity } + end + end + end + def edit + @settings_menu_item_group = Lookup.find(params[:id]) + @menu_category = MenuCategory.order(:name) + end + def update + @settings_menu_item_group = Lookup.find(params[:id]) + menu_item = settings_lookup_params[:value].reject(&:empty?) + menu_category = "{\"#{settings_lookup_params[:lookup_type]}\" : #{menu_item} }" + @settings_menu_item_group.lookup_type = "menu_item_groups" + @settings_menu_item_group.value = menu_category + @settings_menu_item_group.name = settings_lookup_params[:name] + respond_to do |format| + if @settings_menu_item_group.save + format.html { redirect_to settings_menu_item_groups_path, notice: 'Menu item group was successfully updated.' } + format.json { render :show, status: :ok, location: @settings_menu_item_group } + else + format.html { render :edit } + format.json { render json: settings_menu_item_groups_path.errors, status: :unprocessable_entity } + end + end + end + def destroy + @settings_menu_item_group = Lookup.find(params[:id]) + if @settings_menu_item_group.destroy + flash[:notice] = 'Menu item group was successfully deleted.' + redirect_to settings_menu_item_groups_path + end + end + private + + # Never trust parameters from the scary internet, only allow the white list through. + def settings_lookup_params + params.require(:lookup).permit(:lookup_type, :name, :value=>[]) + end +end diff --git a/app/helpers/api/menu_item_groups_helper.rb b/app/helpers/api/menu_item_groups_helper.rb new file mode 100644 index 00000000..5c7ab225 --- /dev/null +++ b/app/helpers/api/menu_item_groups_helper.rb @@ -0,0 +1,2 @@ +module Api::MenuItemGroupsHelper +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 16e44953..93664fef 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,8 +5,8 @@ module ApplicationHelper case level when :notice then "alert alert-info fade-in" when :success then "alert alert-success fade-in" - when :error then "alert alert-error fade-in" - when :alert then "alert alert-error fade-in" + when :error then "alert alert-warning fade-in" + when :alert then "alert alert-danger fade-in" end end diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb new file mode 100644 index 00000000..a94ddfc2 --- /dev/null +++ b/app/helpers/dashboard_helper.rb @@ -0,0 +1,2 @@ +module DashboardHelper +end diff --git a/app/helpers/sessions_helper.rb b/app/helpers/sessions_helper.rb new file mode 100644 index 00000000..309f8b2e --- /dev/null +++ b/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/app/helpers/settings/menu_item_groups_helper.rb b/app/helpers/settings/menu_item_groups_helper.rb new file mode 100644 index 00000000..6b689f13 --- /dev/null +++ b/app/helpers/settings/menu_item_groups_helper.rb @@ -0,0 +1,2 @@ +module Settings::MenuItemGroupsHelper +end diff --git a/app/models/booking.rb b/app/models/booking.rb index 5a65cd01..ac5551ee 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -62,7 +62,6 @@ class Booking < ApplicationRecord scope :active, -> {where("booking_status != 'moved'")} scope :today, -> {where("created_at >= #{Time.now.utc}")} scope :assign, -> { where(booking_status: 'assign')} - scope :within_time_limit, -> { where(checkin_at: Lookup.get_checkin_time_limit.hours.ago..DateTime::Infinity.new) } def self.sync_booking_records(bookings) if !bookings.nil? diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index a93f4742..f42545ec 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -9,12 +9,12 @@ class DiningFacility < ApplicationRecord has_many :order_queue_stations, -> { where(is_active: true) }, through: :order_queue_process_by_zones has_many :bookings - has_many :current_bookings, -> { left_joins(:sale).assign.within_time_limit.merge(Booking.where(checkout_at: nil).or(Booking.merge(Sale.where(sale_status: ['new', nil])))) }, class_name: "Booking" - has_one :current_checkin_booking, -> { left_joins(:sale).assign.within_time_limit.merge(Sale.where(sale_status: nil)) }, class_name: "Booking" - has_one :current_checkout_booking, -> { left_joins(:sale).assign.within_time_limit.where.not(checkout_at: nil).merge(Sale.where(sale_status: 'new')) }, class_name: "Booking" - has_one :current_reserved_booking, -> { left_joins(:sale).assign.within_time_limit.where.not(reserved_at: nil).merge(Sale.where(sale_status: nil)) }, class_name: "Booking" + has_many :current_bookings, -> { left_joins(:sale).assign.merge(Booking.where(checkout_at: nil).or(Booking.merge(Sale.where(sale_status: ['new', nil])))) }, class_name: "Booking" + has_one :current_checkin_booking, -> { left_joins(:sale).assign.merge(Sale.where(sale_status: nil)) }, class_name: "Booking" + has_one :current_checkout_booking, -> { left_joins(:sale).assign.where.not(checkout_at: nil).merge(Sale.where(sale_status: 'new')) }, class_name: "Booking" + has_one :current_reserved_booking, -> { left_joins(:sale).assign.where.not(reserved_at: nil).merge(Sale.where(sale_status: nil)) }, class_name: "Booking" - has_many :current_sales, -> { where(sale_status: 'new').merge(Booking.assign.within_time_limit) }, through: :bookings, class_name: "Sale", source: "sale" + has_many :current_sales, -> { where(sale_status: 'new').merge(Booking.assign) }, through: :bookings, class_name: "Sale", source: "sale" TABLE_TYPE = "Table" ROOM_TYPE = "Room" @@ -45,9 +45,7 @@ class DiningFacility < ApplicationRecord end def get_current_booking - - checkin_time_lookup = Lookup.get_checkin_time_limit - Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first #and checkout_at is null + Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).first #and checkout_at is null end def get_checkout_booking @@ -89,8 +87,6 @@ class DiningFacility < ApplicationRecord end def self.get_checkin_booking - - checkin_time_lookup = Lookup.get_checkin_time_limit bookings = self.current_checkin_booking arr_booking = Array.new if bookings diff --git a/app/models/employee.rb b/app/models/employee.rb index c2ec8042..3213ca33 100755 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,6 +1,5 @@ class Employee < ApplicationRecord has_secure_password - # has_secure_token :auth_token has_many :commissioners has_many :shit_sales has_one :current_shift, -> { where.not(shift_started_at: nil).where(shift_closed_at: nil) },class_name: "ShiftSale" @@ -34,6 +33,7 @@ class Employee < ApplicationRecord if (user) #user.authenticate(password) if (user.authenticate(password)) + puts user user.generate_token user.session_expiry = DateTime.now.utc + expiry_time.minutes user.session_last_login = DateTime.now.utc @@ -44,20 +44,21 @@ class Employee < ApplicationRecord return nil end - def self.authenticate_by_token(token) - if token - if user = Employee.find_by_token_session(token) - expiry_time = login_expiry_time - if user.session_expiry && user.session_expiry.utc > DateTime.now.utc - #Extend the login time each time authenticatation take place - user.session_expiry = user.session_expiry.utc + expiry_time.minutes - user.save - return user - end - elsif user = Employee.find_by_app_token(token) - return user + def self.authenticate_by_token(session_token) + if (session_token) + user = Employee.find_by_token_session(session_token) + expiry_time = login_expiry_time + puts expiry_time + if user && user.session_expiry.utc > DateTime.now.utc + #Extend the login time each time authenticatation take place + user.session_expiry = user.session_expiry.utc + expiry_time.minutes + user.save + return true + else + return false end end + return false end diff --git a/app/models/license.rb b/app/models/license.rb index 26a5ea99..79b47ed4 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -27,7 +27,7 @@ class License end # For Cloud - def detail_with_local_cache(lookup) + def detail_with_local_cache aes = MyAesCrypt.new aes_key, aes_iv = aes.export_to_file(lookup) @@ -75,21 +75,14 @@ class License end # For Local System - def detail_with_local_file() - renewal_date_str = read_license("renewable_date") - if check_expiring(renewal_date_str) - # return for all ok - return 1 + def detail_with_local_file + if expired? + return 0 + elsif expire_in?(10) + return 2 else - has_license = verify_license() - if has_license - # return for expiring - return 2 - else - return 0 - end + return 1 end - # end end # License Activation @@ -99,42 +92,58 @@ class License aes_key, aes_iv = aes.export_key(license_key) @params = { query: { lookup_type: self.server_mode, iv_key: aes_iv, license_key: license_key } } - response = self.class.get("/activate", @params) - @activate = response.parsed_response - if (@activate["status"]) + begin + response = self.class.get("/activate", @params) + @activate = response.parsed_response - ##Check from local redis - if available load local otherwise get from remote - cache_key = "shop:#{@activate["shop_name"]}" + if (@activate["status"]) - ##Get redis connection from connection pool - # redis = Redis.new - # cache_license = redis.get(cache_key) + ##Check from local redis - if available load local otherwise get from remote + cache_key = "shop:#{@activate["shop_name"]}" - Rails.logger.info "Cache key - " + cache_key.to_s + ##Get redis connection from connection pool + # redis = Redis.new + # cache_license = redis.get(cache_key) - # if cache_license.nil? - cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] } - redis = Redis.new - redis.set(cache_key, Marshal.dump(cache)) - # end + Rails.logger.info "Cache key - " + cache_key.to_s - Rails.logger.info "License - " + response.parsed_response.to_s + # if cache_license.nil? + cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] } + redis = Redis.new + redis.set(cache_key, Marshal.dump(cache)) + # end - response = create_license_file(@activate) + Rails.logger.info "License - " + response.parsed_response.to_s - if(response[:status]) - #sym_path = "/home/user/symmetric/" - sym_path = File.expand_path("~/symmetric/") - - response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password) + response = create_license_file(@activate) if(response[:status]) - response = run_symmetric(sym_path) + #sym_path = "/home/user/symmetric/" + sym_path = File.expand_path("~/symmetric/") + + response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password) + + if(response[:status]) + response = run_symmetric(sym_path) + end end + else + response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"} end - else - response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"} + + rescue SocketError => e + Rails.logger.debug "In SocketError No Internet connection !" + response = { "status": false, "message": "In SocketError No Internet connection !"} + rescue HTTParty::Error + Rails.logger.debug "Server Error HTTParty" + response = { "status": false, "message": "Server Error HTTParty"} + rescue Net::OpenTimeout + Rails.logger.debug "connection Timeout" + response = { "status": false, "message": "Connection Timeout"} + rescue OpenURI::HTTPError + Rails.logger.debug "Can't connect server" + response = { "status": false, "message": "Can't connect server"} end return response end @@ -144,39 +153,50 @@ class License @params = { query: {lookup_type: "application", api_token: api_token} } begin - response = self.class.get("/verify", @params) - @varified = response.parsed_response - Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s - if (@varified["status"]) - if (!check_expired(@varified["renewable_date"])) - return true - end - else - delete_license_file + response = self.class.get("/verify", @params) + @varified = response.parsed_response + Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s + if (@varified["status"]) + old_renewable_date = read_license("renewable_date") + if old_renewable_date.to_date < @varified['renewable_date'].to_date + update_license("renewable_date", @varified['renewable_date']) + return true end + end rescue SocketError => e Rails.logger.debug "In SocketError No Internet connection ! " - return true rescue HTTParty::Error Rails.logger.debug "Server Error HTTParty" - return true rescue Net::OpenTimeout Rails.logger.debug "connection Timeout" - return true rescue OpenURI::HTTPError Rails.logger.debug "Can't connect server" - return true end return false end + def exists? + License.check_license_file(lookup) + end - # Check Expired before 30 days - def check_expiring(renewal_date_str) - if !renewal_date_str.empty? + def expired? + if renewal_date_str = read_license("renewable_date") renewal_date = DateTime.parse(renewal_date_str) - renewal_date > Date.today.advance(:days => 30) + renewal_date < Date.today + end + end + + def expire_in?(days) + if renewal_date_str = read_license("renewable_date") + renewal_date = DateTime.parse(renewal_date_str) + renewal_date < days.days.from_now + end + end + + def days_to_expire + if renewal_date_str = read_license("renewable_date") + Date.today - DateTime.parse(renewal_date_str).to_date end end @@ -195,13 +215,14 @@ class License end end - def check_license_subdomain(lookup) + def check_license_subdomain aes = MyAesCrypt.new aes_key, aes_iv = aes.export_key(lookup) params = { query: { lookup_type: "cloud", lookup: lookup, iv_key: aes_iv} } response = self.class.get("/subdomain", params) response.parsed_response["status"] + rescue end # Check License File exists @@ -209,15 +230,21 @@ class License return unless File.exist?("config/license.yml") if license = YAML.load_file("config/license.yml") if license[lookup].nil? - if ENV["SERVER_MODE"] == "application" - license[lookup] = license.values.first + + if license['iv_key'] + license = { lookup => license } else tld_length = Rails.application.config.action_dispatch.tld_length subdomains = URL.extract_subdomains(lookup, tld_length) - if key = license.keys.find { |k| URL.extract_subdomains(k, tld_length).last == subdomains.last} - license[lookup] = license[key] + if subdomains.last && subdomains.last != 'www' + if key = license.keys.find { |k| URL.extract_subdomains(k, tld_length).last == subdomains.last} + license[lookup] = license[key] + end + else + license[lookup] = license.values.first end end + if license[lookup] File.open("config/license.yml", "w") { |file| file.write license.to_yaml } end @@ -228,9 +255,8 @@ class License # read line by key for license file def read_license(key_name) - key, iv = get_redis_key() - if File.exist?("config/license.yml") + key, iv = get_redis_key() if license = YAML.load(File.read("config/license.yml")) if license[lookup] AESCrypt.decrypt_data(decode_str(license[lookup][key_name]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) @@ -252,13 +278,12 @@ class License # Update license file for line def update_license(content, new_content) - key, iv = get_redis_key() - - if !new_content.include? "==" - crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) - end - if File.exist?("config/license.yml") + key, iv = get_redis_key() + + if !new_content.include? "==" + crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) + end if license = YAML.load_file("config/license.yml") license[lookup][content] = encode_str(crypted_str) diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index 97695fde..c3b1bd39 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -38,7 +38,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # self.print(filename, cashier_terminal.printer_name) # end - def print_close_cashier(printer_settings,cashier_terminal,shift_sale, sale_items, total_other_charges_info,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,foodcourt=nil) + def print_close_cashier(printer_settings,cashier_terminal,shift_sale, sale_items, total_other_charges_info,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods,foodcourt=nil) if !sale_items.blank? or !sale_items.nil? @account_cate_count = Hash.new {|hash, key| hash[key] = 0} @@ -59,7 +59,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker cashier = shift_sale.employee.name shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" - pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,foodcourt) + pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods,foodcourt) close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf if !close_cashier_pdf.empty? @@ -68,7 +68,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker if close_cashier[1] == '1' pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,foodcourt) else - pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,foodcourt) + pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods,foodcourt) end end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 1651524a..74b1bf04 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -684,7 +684,7 @@ class Sale < ApplicationRecord .joins("JOIN orders ON orders.order_id=booking_orders.order_id") .joins("JOIN order_items ON orders.order_id=order_items.order_id") .joins("JOIN customers ON orders.customer_id=customers.customer_id") - .where("sales.sale_status =? and sales.payment_status =? and orders.source='app' and sales.shift_sale_id = ?", + .where("sales.sale_status =? and sales.payment_status =? and orders.source='app' and sales.shift_sale_id = ?", 'completed','paid', @current_shift.id ).order("bookings.created_at desc").uniq @@ -791,20 +791,20 @@ class Sale < ApplicationRecord return num end -def self.daily_sales_list(from,to) - payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) + def self.daily_sales_list(from,to) + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) - sales = select(Sale.column_names) - .select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method == 'paypar' ? 'redeem' : method}"}.push('').join(', ')} - SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, - SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) - - SUM(case when (sale_payments.payment_method not in('creditnote') and sale_audits.sale_audit_id IS NOT NULL) then sale_payments.payment_amount else 0 end) as credit_amount, - SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") - .sale_payments_with_audit_except_void_between(from, to) - .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) - .group("sale_id").to_sql + sales = select(Sale.column_names) + .select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method == 'paypar' ? 'redeem' : method}"}.push('').join(', ')} + SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) - + SUM(case when (sale_payments.payment_method not in('creditnote') and sale_audits.sale_audit_id IS NOT NULL) then sale_payments.payment_amount else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") + .sale_payments_with_audit_except_void_between(from, to) + .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) + .group("sale_id").to_sql - daily_total = connection.select_all("SELECT + daily_total = connection.select_all("SELECT IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total, IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as total_sale, IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total, @@ -1238,11 +1238,21 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay .includes(:bookings => :dining_facility) .select("sales.*, SUM(sale_payments.payment_amount) AS payments_for_credits_amount") .joins(:bookings) + .joins("INNER JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .left_joins(:payments_for_credits) .completed .where.not(total_amount: 0) .group(:sale_id) .order(:receipt_date) + + if payment_type.present? + if payment_type == 'card' + query = query.where(sanitize_sql_array(["sp.payment_method IN (?)", SalePayment::CARD])) + else + query = query.where("sp.payment_method = (?)", payment_type) + end + end + if shift.present? query = query.where("sales.shift_sale_id in (?)", shift.to_a) elsif shift_sale_range.present? @@ -1528,7 +1538,7 @@ end def self.employee_sales(current_user,from,to) 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 @@ -1575,7 +1585,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 @@ -1631,10 +1641,10 @@ end def self.total_payment_methods(current_user=nil,from=nil,to=nil) - query = Sale.select("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END as payment_method") + query = Sale.select(sanitize_sql_array(["CASE WHEN sp.payment_method IN (?) THEN 'card' ELSE sp.payment_method END as payment_method", SalePayment::CARD])) .where("sales.sale_status = 'completed'") .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") - .group("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END") + .group(sanitize_sql_array(["CASE WHEN sp.payment_method IN (?) THEN 'card' ELSE sp.payment_method END", SalePayment::CARD])) if (!from.nil? && !to.nil?) query = query.receipt_date_between(from, to) @@ -1777,7 +1787,7 @@ end # query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) # end # else - # shift = ShiftSale.current_open_shift(current_user.id) + # shift = ShiftSale.current_open_shift(current_user) # if !shift.nil? # if !from_time.nil? && !to_time.nil? # query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) @@ -1794,7 +1804,7 @@ end # if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' # query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) # else - # shift = ShiftSale.current_open_shift(current_user.id) + # shift = ShiftSale.current_open_shift(current_user) # if !shift.nil? # query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) # end @@ -2311,7 +2321,7 @@ def self.get_daily_sale_data(transaction_date) CASE WHEN sale_payments.payment_method = 'giftvoucher' THEN SUM(sale_payments.payment_amount) ELSE SUM(0) END as voucher_sales FROM sale_payments GROUP BY sale_payments.sale_id, sale_payments.payment_method" - + query = Sale.select(" sales.receipt_no as check_num, sales.receipt_date as business_date, @@ -2348,49 +2358,50 @@ def self.get_daily_sale_data(transaction_date) .where("DATE(sales.receipt_date) = ? AND sales.sale_status != ?", transaction_date, :void) .group("sales.receipt_no,sales.sale_status") end -def paymal_payment_void - membership_setting = MembershipSetting.find_by_membership_type("paypar_url") - membership_actions_data = MembershipAction.find_by_membership_type("void") - if !membership_actions_data.nil? - sale_payments =self.sale_payments.where("payment_reference is not null") - if !sale_payments.empty? - account_no =sale_payments[0].payment_reference - url = membership_setting.gateway_url.to_s + membership_actions_data.gateway_url.to_s - merchant_uid = membership_actions_data.merchant_account_id - auth_token = membership_actions_data.auth_token - params = { receipt_no:self.receipt_no, - account_no:account_no, - merchant_uid:merchant_uid, - auth_token:auth_token}.to_json - # Control for Paypar Cloud - begin - response = HTTParty.post(url, - :body => params, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json; version=3' - }, - :timeout => 10 - ) - rescue Errno::ECONNREFUSED - response = { "status" => false, "message" => "Can't open membership server"} - rescue Net::OpenTimeout - response = { "status" => false, "message" => "No internet connection " } - rescue OpenURI::HTTPError - response = { "status" => false, "message" => "No internet connection "} - rescue SocketError - response = { "status" => false, "message" => "No internet connection "} - end + def paymal_payment_void + membership_setting = MembershipSetting.find_by_membership_type("paypar_url") + membership_actions_data = MembershipAction.find_by_membership_type("void") + if !membership_actions_data.nil? + sale_payments =self.sale_payments.where("payment_reference is not null") + if !sale_payments.empty? + account_no =sale_payments[0].payment_reference + url = membership_setting.gateway_url.to_s + membership_actions_data.gateway_url.to_s + merchant_uid = membership_actions_data.merchant_account_id + auth_token = membership_actions_data.auth_token + params = { receipt_no:self.receipt_no, + account_no:account_no, + merchant_uid:merchant_uid, + auth_token:auth_token}.to_json + + # Control for Paypar Cloud + begin + response = HTTParty.post(url, + :body => params, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json; version=3' + }, + :timeout => 10 + ) + rescue Errno::ECONNREFUSED + response = { "status" => false, "message" => "Can't open membership server"} + rescue Net::OpenTimeout + response = { "status" => false, "message" => "No internet connection " } + rescue OpenURI::HTTPError + response = { "status" => false, "message" => "No internet connection "} + rescue SocketError + response = { "status" => false, "message" => "No internet connection "} + end + end + else + response = { "status" => false} end - else - response = { "status" => false} - end - Rails.logger.debug "Void Payment response" - Rails.logger.debug response.to_json - return response; -end + Rails.logger.debug "Void Payment response" + Rails.logger.debug response.to_json + return response; + end # Loader Service SFTP End private @@ -2408,7 +2419,9 @@ private self.total_tax = self.total_tax.round(precision) end self.grand_total = (self.total_amount - self.total_discount) + self.total_tax - adjust_rounding + if (!['foc', 'waste', 'spoile', 'void'].include? self.payment_status) + adjust_rounding + end end def update_stock_journal diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index 35045763..74e8a397 100755 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -142,8 +142,9 @@ class SaleAudit < ApplicationRecord if paymal[0] remark = paymal[0].remark.split("}") response = "["+remark[0]+'}]' - response = JSON.parse(response) # puts response + # response = JSON.parse(response) + if response[0]["status"] == true if response[0]["current_rebate_amount"].present? amount = response[0]["current_rebate_amount"] diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 9db6f78d..ec615bb1 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -1,4 +1,7 @@ class SalePayment < ApplicationRecord + + CARD = ['mpu', 'visa', 'master', 'jcb', 'unionpay'] + self.primary_key = "sale_payment_id" #primary key - need to be unique generated for multiple shops @@ -11,7 +14,7 @@ class SalePayment < ApplicationRecord attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by scope :credits, -> { where(payment_method: 'creditnote') } - scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher']) } + scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay']) } def self.sync_sale_payment_records(sale_payments) if !sale_payments.nil? @@ -36,7 +39,8 @@ class SalePayment < ApplicationRecord def self.get_kbz_pay_amount(sale_id, current_user) amount = 0 - kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last + kbz_pay_method = PaymentMethodSetting.where(payment_method: KbzPay::KBZ_PAY, gateway_communication_type: ['api', 'Api'], is_active: true) + .where.not(gateway_url: [nil, ''], auth_token: [nil, ''], merchant_account_id: [nil, '']).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' @@ -120,10 +124,8 @@ class SalePayment < ApplicationRecord payment_status,membership_data = dinga_payment when "GiftVoucher" payment_status = giftvoucher_payment - when KbzPay::KBZ_PAY - payment_status = kbz_payment - else - puts "it was something else" + else + payment_status = external_terminal_card_payment(payment_method, payment_for) end if payment_status @@ -361,10 +363,16 @@ class SalePayment < ApplicationRecord # Check for Card Payment def self.get_sale_payments_by_card(sale_payments) # Check for Card Payment + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) sale_payments.each do |sp| - if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" || sp.payment_method == "unionpay" || sp.payment_method == "alipay" - return true; + payment_methods.each do |m| + if sp.payment_method == m + return true; + end end + # if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" || sp.payment_method == "unionpay" || sp.payment_method == "alipay" + # return true; + # end end end @@ -616,22 +624,12 @@ class SalePayment < ApplicationRecord return payment_status end - def kbz_payment - payment_status = false - self.payment_amount = self.received_amount - self.payment_reference = self.payment_reference - self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f - self.payment_status = "paid" - payment_status = self.save! - # sale_update_payment_status(self.received_amount) - return payment_status - end - def sale_update_payment_status(paid_amount, check_foc = false) #update amount_outstanding - if ['completed'].include? sale.sale_status + if !self.sale || ['completed'].include?(self.sale.sale_status) return end + sale = self.sale sale_payments = sale.sale_payments.reload @@ -639,18 +637,14 @@ class SalePayment < ApplicationRecord is_foc = sale_payments.any? { |x| x.payment_method == "foc" } || check_foc if is_foc - total_payment_amount = 0.0 - else - total_payment_amount = sale_payments.sum(&:payment_amount) - end - - sale.amount_received = sale.amount_received.to_f + paid_amount.to_f - sale.amount_changed = total_payment_amount - sale.grand_total.to_f - - if is_foc + sale.amount_received = 0.0 + sale.amount_changed = 0.0 sale.payment_status = 'foc' sale.sale_status = 'completed' - elsif sale.grand_total <= total_payment_amount && sale.sale_status == "new" + elsif sale.grand_total <= sale_payments.sum(&:payment_amount) && sale.sale_status == "new" + sale.amount_received = sale.amount_received + paid_amount.to_d + sale.amount_changed = sale_payments.sum(&:payment_amount) - sale.grand_total + sale.payment_status = "paid" if is_credit sale.payment_status = "outstanding" @@ -682,19 +676,9 @@ class SalePayment < ApplicationRecord end end end - sale.save! - - if check_foc - table_update_status(sale) - update_shift - elsif paid_amount.to_f > 0 #|| paid_amount != "0.0" - table_update_status(sale) - update_shift - elsif paid_amount.to_f == 0 && !is_credit - table_update_status(sale) - update_shift - end + table_update_status(sale) + update_shift end # update for cashier shift diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 6214005a..dc96a425 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -28,7 +28,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.id}").take + shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and employee_id = ?", current_user).take return shift #end end @@ -150,23 +150,15 @@ class ShiftSale < ApplicationRecord end def self.get_by_shift_other_payment(shift) + payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) - other_payment = Sale.select("sale_payments.payment_method as name, - SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount, - SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount, - SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount, - SUM(case when (sale_payments.payment_method='jcb') then (sale_payments.payment_amount) else 0 end) as jcb_amount, - SUM(case when (sale_payments.payment_method='unionpay') then (sale_payments.payment_amount) else 0 end) as unionpay_amount, - SUM(case when (sale_payments.payment_method='alipay') then (sale_payments.payment_amount) else 0 end) as alipay_amount, - SUM(case when (sale_payments.payment_method='KBZPay') then (sale_payments.payment_amount) else 0 end) as kbzpay_amount, - SUM(case when (sale_payments.payment_method='dinga') then (sale_payments.payment_amount) else 0 end) as dinga_amount, - SUM(case when (sale_payments.payment_method='giftvoucher') then (sale_payments.payment_amount) else 0 end) as giftvoucher_amount, - SUM(case when (sale_payments.payment_method='JunctionPay') then (sale_payments.payment_amount) else 0 end) as junctionpay_amount, - SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount, - SUM(case when (sale_payments.payment_method='paymal') then (sale_payments.payment_amount) else 0 end) as paymal_amount, - SUM(case when (sale_payments.payment_method='paypar') then (sale_payments.payment_amount) else 0 end) as paypar_amount") - .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id) + shift_other_payments = Sale.select("sales.sale_id,sale_payments.payment_method as name") + if payment_methods.present? + shift_other_payments = shift_other_payments.select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method == 'paypar' ? 'redeem' : method}"}.join(', ')}") + end + shift_other_payments.select("SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id) end def self.calculate_total_price_by_accounts(shift,type) diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 31f1e1a7..ba1374f2 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -2,7 +2,7 @@ class CloseCashierPdf < Prawn::Document include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width - def initialize(printer_settings, shift_sale, sale_items, total_other_charges_info, acc_cate_count, menu_cate_count, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,foodcourt) + def initialize(printer_settings, shift_sale, sale_items, total_other_charges_info, acc_cate_count, menu_cate_count, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods,foodcourt) self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -43,7 +43,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments,foodcourt) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments,payment_methods,foodcourt) if !sale_items.nil? or !sale_items.blank? sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges_info) @@ -63,7 +63,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule end - def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments,foodcourt) + def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments,payment_methods,foodcourt) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -131,10 +131,12 @@ class CloseCashierPdf < Prawn::Document text "#{number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - if foodcourt.nil? - y_position = cursor + + y_position = cursor + + unless foodcourt bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Cash In:", :size => self.item_font_size, :align => :right + text "Cash In :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right @@ -142,18 +144,19 @@ class CloseCashierPdf < Prawn::Document y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Cash Out:", :size => self.item_font_size, :align => :right + text "Cash Out :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end + move_down -5 stroke_horizontal_rule move_down 7 @total_foc = 0 - if foodcourt.nil? + unless foodcourt y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Cash Payment :", :size => self.item_font_size, :align => :right @@ -174,125 +177,19 @@ class CloseCashierPdf < Prawn::Document if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) - if other.mpu_amount && other.mpu_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "MPU Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + + if !payment_methods.nil? + payment_methods.each do |method| + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "#{method.parameterize == 'paymal' ? 'Card' : method} Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_format(other[method.parameterize.to_sym], :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end end end - if other.visa_amount && other.visa_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "VISA Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.master_amount && other.master_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Master Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.jcb_amount && other.jcb_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "JCB Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.unionpay_amount && other.unionpay_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.alipay_amount && other.alipay_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Alipay Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.kbzpay_amount && other.kbzpay_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "KBZ Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.junctionpay_amount && other.junctionpay_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "JunctionPay Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.dinga_amount && other.dinga_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Dinga Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.paypar_amount && other.paypar_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Redeem Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.paymal_amount && other.paymal_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Card Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end - - if other.giftvoucher_amount && other.giftvoucher_amount.to_f > 0 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end - end end else y_position = cursor @@ -362,7 +259,7 @@ class CloseCashierPdf < Prawn::Document end end #end for service charges and commercial tax -#COMMENTED FOR NO NEED AND NOT CORRECT WHEN OTHER CHARGES + #COMMENTED FOR NO NEED AND NOT CORRECT WHEN OTHER CHARGES # y_position = cursor # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do # text "Total Sale :", :size => self.item_font_size, :align => :right diff --git a/app/views/home/dashboard.html.erb b/app/views/dashboard/index.html.erb similarity index 99% rename from app/views/home/dashboard.html.erb rename to app/views/dashboard/index.html.erb index 46e5f81e..bc3332ca 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/dashboard/index.html.erb @@ -214,13 +214,15 @@ <% if payment.payment_method == 'paypar' %> Redeem Sale : + <% elsif payment.payment_method == 'paymal' %> + Card Sales : <% else %> <%= payment.payment_method.to_s.capitalize %> Sale : <% end %> <% @sale_data.each do |data| %> <% pay_mth = payment.payment_method %> - <%= data[""+pay_mth+""] %> + <%= data[pay_mth] %> <% end %> diff --git a/app/views/home/dashboard_backup.html.erb b/app/views/dashboard/index_backup.html.erb similarity index 100% rename from app/views/home/dashboard_backup.html.erb rename to app/views/dashboard/index_backup.html.erb diff --git a/app/views/foodcourt/discounts/index.html.erb b/app/views/foodcourt/discounts/index.html.erb index 5ca020a3..09cbb9d9 100755 --- a/app/views/foodcourt/discounts/index.html.erb +++ b/app/views/foodcourt/discounts/index.html.erb @@ -1,130 +1,116 @@ -
- - <% if !@print_settings.nil? %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - <% end %> -
- -
- -
- -
-
-
- <%if !@table.nil?%> - - - <%else%> - - - <%end%> +
+ +
+ +
+ +
+ +
+
+
+ <%if !@table.nil?%> + + + <%else%> + + + <%end%> - -

Receipt No: <%=@sale_data.receipt_no rescue ' '%>

- -
-
-

Date: <%=@sale_data.receipt_date.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>

-
-
-
-
- - - - - - - - - - - <% sub_total = 0 %> - <% @sale_data.sale_items.each do |sale_item| %> - <% sub_total += sale_item.qty * sale_item.unit_price %> - <% if sale_item.price > 0 && sale_item.status.blank? %> - > - - - - - <% elsif sale_item.price < 0 && sale_item.status == "Discount" %> - > - - - - - <% end %> - <% end %> - -
ItemsQTYPrice
- - - <%=sale_item.product_name%>@<%=sale_item.unit_price%> - - <%=sale_item.qty%> - - <%=(sale_item.qty*sale_item.unit_price)%> -
- - - <%=sale_item.product_name%>@<%=sale_item.unit_price%> - - <%=sale_item.qty.abs%> - - <%=(sale_item.qty*sale_item.unit_price)%> -
-
-
- +
+ + (<%= number_format(@sale_data.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>) + + + Tax: + <%= number_format(@sale_data.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %> + + + Grand Total: + <%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %> + + +
@@ -132,149 +118,149 @@
- -
-
-
Discount Control
-
-
-
-
-
-
- - -
-
-
- <% @accounts.each do |acc| %> - - <% end %> -
-
-
-
+ +
+
+
Discount Control
+
+
+
+
+
+
+ + +
+
+
+ <% @accounts.each do |acc| %> + + <% end %> +
+
+
+
-
-
-
-
-
-
-
5%
-
-
-
-
1
-
2
-
3
-
-
-
+
+
+
+
+
+
+
5%
+
+
+
+
1
+
2
+
3
+
+
+
-
-
-
10%
-
-
-
-
4
-
5
-
6
-
-
-
+
+
+
10%
+
+
+
+
4
+
5
+
6
+
+
+
-
-
-
15%
-
-
-
-
7
-
8
-
9
-
-
-
+
+
+
15%
+
+
+
+
7
+
8
+
9
+
+
+
-
-
-
20%
-
-
-
-
0
-
.
-
00
-
-
-
+
+
+
20%
+
+
+
+
0
+
.
+
00
+
+
+
-
-
-
30%
-
-
-
-
-
DEL
-
CLR
-
-
-
-
-
-
- - - -
-
-
-
-
-
+
+
+
30%
+
+
+
+
+
DEL
+
CLR
+
+
+
+
+
+
+ + + +
+
+
+
+
+
- +
- -
- -
- - - - - <% if @member_discount%> - - <%end %> -
-
+ +
+ +
+ + + + + <% if @member_discount%> + + <%end %> +
+
@@ -283,637 +269,565 @@ var cashier_type = "<%= @cashier_type %>"; var totalAmount = <%= sub_total %>; var totalDiscount = <%= @sale_data.total_discount %> var precision = <%= precision %>; - $(document).ready(function(){ - setHeaderBreadCrumb(_DISCOUNTS_); - /* check webview loaded*/ - var webview = <%= @webview %>; - showHideNavbar(webview); +var originalAmount = totalAmount; +var originalDiscount = totalDiscount; + $(document).ready(function(){ + setHeaderBreadCrumb(_DISCOUNTS_); + /* check webview loaded*/ + var webview = <%= @webview %>; + showHideNavbar(webview); - $('#back').on('click',function(){ - var id = $("#table_id").text(); - var type = $("#table_type").text(); - var sale_id = $('#sale-id').text(); - if (cashier_type=="quick_service" || cashier_type=="food_court") { - window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/'; - }else{ - if (type=="Table") { - window.location.href = '/foodcourt/table/'+id - }else{ - window.location.href = '/foodcourt/room/'+id - } - } - }) + $('#back').on('click',function(){ + var id = $("#table_id").text(); + var type = $("#table_type").text(); + var sale_id = $('#sale-id').text(); + if (cashier_type=="quick_service" || cashier_type=="food_court") { + window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/'; + }else{ + if (type=="Table") { + window.location.href = '/foodcourt/table/'+id + }else{ + window.location.href = '/foodcourt/room/'+id + } + } + }) - $(".cashier_number").on('click', function(event){ - if(event.handled !== true) { - var original_value=0; - original_value = $('#discount-amount').val(); - var input_type = $(this).attr("data-type"); - switch (input_type) { - case 'num': - var input_value = $(this).attr("data-value"); - if (original_value == "0.0"){ - $('#discount-amount').val(input_value); - } - else{ - $('#discount-amount').val(original_value + '' + input_value); - } - break; - case 'add': - var input_value = $(this).attr("data-value"); - amount = parseInt(input_value); - $('#discount-amount').val(amount); - break; - case 'del' : - var discount_text=$('#discount-amount').val(); - $('#discount-amount').val(discount_text.substr(0,discount_text.length-1)); - break; - case 'clr': - $('#discount-amount').val("0.0"); - break; - } - event.handled = true; - } else { - return false; - } - }); + $(".cashier_number").on('click', function(event){ + if(event.handled !== true) { + var original_value = 0; + original_value = $('#discount-amount').val(); + var input_type = $(this).attr("data-type"); + switch (input_type) { + case 'num': + var input_value = $(this).attr("data-value"); + if (input_value == "." && original_value.includes(".")) { + break; + } + if (parseFloat(input_value) >= 0 && !original_value.includes(".") && (parseFloat(original_value) == 0)) { + $('#discount-amount').val(parseFloat(input_value)); + } else { + $('#discount-amount').val(original_value + input_value); + } + break; + case 'add': + var input_value = $(this).attr("data-value"); + amount = parseInt(input_value); + $('#discount-amount').val(amount); + break; + case 'del' : + var discount_text=$('#discount-amount').val(); + $('#discount-amount').val(discount_text.substr(0,discount_text.length-1)); + break; + case 'clr': + $('#discount-amount').val("0"); + break; + } + event.handled = true; + } else { + return false; + } + }); - // Select Sale Item - $('#order-items-table').on('click', '.item-row', function(){ - if($(this).hasClass('selected-item') == true){ - $(this).removeClass('selected-item'); - } - else { - $(this).addClass('selected-item'); - } - }); + // Select Sale Item + $('#order-items-table').on('click', '.item-row', function(){ + if($(this).hasClass('selected-item') == true){ + $(this).removeClass('selected-item'); + } + else { + $(this).addClass('selected-item'); + } + }); - // Select for account types - $(".accounts-type").on('click', function(e){ - var account_id = $(this).attr('id').substr(8); - if($(this).hasClass('selected-account') == true){ - $(this).removeClass('selected-account'); - $(".item-row").each(function(i){ - if($(this).children().find("#item-account-type").text() == account_id){ - $(this).removeClass("selected-item"); - } - }); - } - else { - $(this).addClass('selected-account'); - $(".item-row").each(function(i){ - if($(this).children().find("#item-account-type").text() == account_id){ - if(parseInt($(this).children().find("#item-account-qty").text()) >0 && parseInt($(this).children().find("#item-total-price").text()) >0){ - $(this).addClass("selected-item"); - } - else{ - console.log("discount item"); - } - } - }); - } - }); + // Select for account types + $(".accounts-type").on('click', function(e){ + var account_id = $(this).attr('id').substr(8); + if($(this).hasClass('selected-account') == true){ + $(this).removeClass('selected-account'); + $(".item-row").each(function(i){ + if($(this).children().find("#item-account-type").text() == account_id){ + $(this).removeClass("selected-item"); + } + }); + } + else { + $(this).addClass('selected-account'); + $(".item-row").each(function(i){ + if($(this).children().find("#item-account-type").text() == account_id){ + if(parseInt($(this).children().find("#item-account-qty").text()) >0 && parseInt($(this).children().find("#item-total-price").text()) >0){ + $(this).addClass("selected-item"); + } + else{ + console.log("discount item"); + } + } + }); + } + }); - // Calculate Net Discount for Payment - $("#net").on('click', function(e){ - e.preventDefault(); - var sale_id = $('#sale-id').text(); - var discount_value = $('#discount-amount').val(); - var sub_total = parseFloat($('#order-sub-total').text()); - var ajax_url = "/foodcourt/" + sale_id + "/discount"; + // Calculate Net Discount for Payment + $("#net").on('click', function(e){ + e.preventDefault(); + var sale_id = $('#sale-id').text(); + var discount_value = $('#discount-amount').val(); + var sub_total = totalAmount; + var ajax_url = "/foodcourt/" + sale_id + "/discount"; - if(discount_value!=""){ - if(discount_value > 0){ - if(parseFloat(discount_value) > sub_total){ - $("#discount-amount").val(""); - $("#discount-amountErr").html("Discount is greater than sub total!"); - }else{ - $("#discount-amountErr").html(""); - // Selected Items - var sale_items = get_selected_sale_items(); + if(discount_value!=""){ + if(discount_value > 0){ + if(parseFloat(discount_value) > sub_total){ + $("#discount-amount").val(""); + $("#discount-amountErr").html("Discount is greater than sub total!"); + }else{ + $("#discount-amountErr").html(""); + // Selected Items + var sale_items = get_selected_sale_items(); - // Selected Account - var account_types = get_selected_account_types(); + // Selected Account + var account_types = get_selected_account_types(); - if(sale_items.length == 0 && account_types.length == 0){ - calculate_overall_discount(0, discount_value); - } - else if(sale_items.length > 0){ - calculate_item_discount(0, discount_value, sale_items, account_types); - } + if(sale_items.length == 0 && account_types.length == 0){ + calculate_overall_discount(0, discount_value); + } + else if(sale_items.length > 0){ + calculate_item_discount(0, discount_value, sale_items, account_types); + } - // Remove Selection - selection_remove(); - } - }else{ - $("#discount-amountErr").html("Discount must be greater than 0!"); - } - }else{ - $("#discount-amountErr").html("can't be blank"); - } + // Remove Selection + selection_remove(); + } + }else{ + $("#discount-amountErr").html("Discount must be greater than 0!"); + } + }else{ + $("#discount-amountErr").html("can't be blank"); + } - }); + }); - // Calculate Percentage Discount for Payment - $("#percentage").on('click', function(e){ - e.preventDefault(); - var sale_id = $('#sale-id').text(); - var discount_value = $('#discount-amount').val(); - var ajax_url = "/foodcourt/" + sale_id + "/discount"; + // Calculate Percentage Discount for Payment + $("#percentage").on('click', function(e){ + e.preventDefault(); + var sale_id = $('#sale-id').text(); + var discount_value = $('#discount-amount').val(); + var ajax_url = "/foodcourt/" + sale_id + "/discount"; - if(discount_value!=""){ - if(discount_value > 0){ - $("#discount-amountErr").val(""); + if(discount_value!=""){ + if(discount_value > 0){ + $("#discount-amountErr").val(""); - // Selected Items - var sale_items = get_selected_sale_items(); - // Selected Account - var account_types = get_selected_account_types(); + // Selected Items + var sale_items = get_selected_sale_items(); + // Selected Account + var account_types = get_selected_account_types(); - if(sale_items.length == 0 && account_types.length == 0){ - calculate_overall_discount(1, discount_value); - } else if(sale_items.length > 0){ - calculate_item_discount(1, discount_value, sale_items, account_types); - } - }else{ - $("#discount-amountErr").html("Discount must be greater than 0!"); - } - }else{ - $("#discount-amountErr").html("can't be blank"); - } + if(sale_items.length == 0 && account_types.length == 0){ + calculate_overall_discount(1, discount_value); + } else if(sale_items.length > 0){ + calculate_item_discount(1, discount_value, sale_items, account_types); + } + }else{ + $("#discount-amountErr").html("Discount must be greater than 0!"); + } + }else{ + $("#discount-amountErr").html("can't be blank"); + } - // Remove Selection - selection_remove(); - }); + // Remove Selection + selection_remove(); + }); - // Remove selected discount items - $("#remove-item").on('click', function(e){ - e.preventDefault(); - var origin_sub_total = parseFloat($("#order-sub-total").text()); - // var total = 0; + // Remove selected discount items + $("#remove-item").on('click', function(e){ + e.preventDefault(); + // var total = 0; - $('.item-row.new-discount').each(function(i){ - var amount = parseFloat($(this).find('#item-total-price').text()); - totalAmount += Math.abs(amount) - // total = total + Math.abs(amount); - $(this).remove(); - }); + $('.item-row.new-discount').each(function(i){ + // total = total + Math.abs(amount); + $(this).remove(); + }); - $("#order-sub-total").text(totalAmount); - $("#order-discount").text(totalDiscount.toFixed(<%= precision.to_i %>)); - }); + $("#order-sub-total").text(originalAmount.toFixed(<%= precision.to_i %>)); + $("#order-discount").text(originalDiscount.toFixed(<%= precision.to_i %>)); + }); - // Pay Discount for Payment - $("#pay-discount").on('click', function(e){ - e.preventDefault(); - if($('#pay-discount').is(":visible")) { - $('#pay-discount').prop("disabled",true); - } - $("#loading_wrapper").show(); - var sale_id = $('#sale-id').text(); - var discount_items = JSON.stringify(get_new_discount_item_rows()); - var overall_discount = $("#order-discount").text(); - var sub_total = $('#order-sub-total').text(); - var ajax_url = "/foodcourt/" + sale_id + "/discount"; + // Pay Discount for Payment + $("#pay-discount").on('click', function(e){ + e.preventDefault(); + if($('#pay-discount').is(":visible")) { + $('#pay-discount').prop("disabled",true); + } + $("#loading_wrapper").show(); + var sale_id = $('#sale-id').text(); + var discount_items = JSON.stringify(get_new_discount_item_rows()); + var overall_discount = totalDiscount; + var sub_total = totalAmount; + var ajax_url = "/foodcourt/" + sale_id + "/discount"; - var params = { 'cashier_type' : cashier_type,'sale_id': sale_id, 'sub_total': sub_total, 'discount_items': discount_items, 'overall_discount': overall_discount }; + var params = { 'cashier_type' : cashier_type,'sale_id': sale_id, 'sub_total': sub_total, 'discount_items': discount_items, 'overall_discount': overall_discount }; - $.ajax({ - type: "POST", - url: ajax_url, - data: params, - success:function(result){ - $("#loading_wrapper").hide(); + $.ajax({ + type: "POST", + url: ajax_url, + data: params, + success:function(result){ + $("#loading_wrapper").hide(); + swal({ + title: "Information!", + text: result.status, + }, function () { + if (cashier_type=="quick_service" || cashier_type=="food_court") { + window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/'; + }else{ + if(result.table_type == "Table"){ + window.location.href = "/foodcourt/table/" + result.table_id + } + else { + window.location.href = "/foodcourt/room/" + result.table_id + } + } + }); + } + }); + }); - swal({ - title: "Information!", - text: result.status, - type: "success" - }, function () { - if (cashier_type=="quick_service" || cashier_type=="food_court") { - window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/'; - }else{ - if(result.table_type == "Table"){ - window.location.href = "/foodcourt/table/" + result.table_id - } - else { - window.location.href = "/foodcourt/room/" + result.table_id - } - } - }); - } - }); - }); + // Remove selected given discount item + $("#remove-item-discount").on('click', function(e){ + e.preventDefault(); + var sale_id = $('#sale-id').text(); + var discount_items = []; - // Remove selected given discount item - $("#remove-item-discount").on('click', function(e){ - e.preventDefault(); - var sale_id = $('#sale-id').text(); - var discount_items = []; + var sale_items = get_selected_discount_items(); - var sale_items = get_selected_discount_items(); + for(var i=0;i < sale_items.length;i++){ + if(sale_items[i].price < 0){ + discount_items.push(sale_items[i]); + } + else { + swal ("Oops" , "You have no selected item!" , "error" ); + return; + } + } - for(var i=0;i < sale_items.length;i++){ - if(sale_items[i].price < 0){ - discount_items.push(sale_items[i]); - } - else { - swal ("Oops" , "You have no selected item!" , "error" ); - return; - } - } + var params = { 'cashier_type': cashier_type,'sale_id': sale_id, 'discount_items': JSON.stringify(discount_items) }; + $.ajax({ + type: "POST", + url: "/foodcourt/" + sale_id + "/remove_discount_items", + data: params, + success: function(result){ + swal({ + title: "Information!", + text: result.status, + type: "success", + }, function () { + if (cashier_type=="quick_service" || cashier_type=="food_court") { + window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/'; + }else{ + if(result.table_type == "Table"){ + window.location.href = "/foodcourt/table/" + result.table_id + } + else { + window.location.href = "/foodcourt/room/" + result.table_id + } + } + }); + } + }); + }); - var params = { 'cashier_type': cashier_type,'sale_id': sale_id, 'discount_items': JSON.stringify(discount_items) }; - $.ajax({ - type: "POST", - url: "/foodcourt/" + sale_id + "/remove_discount_items", - data: params, - success: function(result){ - swal({ - title: "Information!", - text: result.status, - type: "success", - }, function () { - if (cashier_type=="quick_service" || cashier_type=="food_court") { - window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/'; - }else{ - if(result.table_type == "Table"){ - window.location.href = "/foodcourt/table/" + result.table_id - } - else { - window.location.href = "/foodcourt/room/" + result.table_id - } - } - }); - } - }); - }); + $("#remove-all").on('click', function(e){ + e.preventDefault(); + var sale_id = $('#sale-id').text(); + $.ajax({ + type: "GET", + url: "/foodcourt/" + sale_id + "/" + cashier_type + "/remove_all_discount", + success: function(result){ + swal({ + title: "Information!", + text: result.status, + type: "success", + }, function () { + if (cashier_type=="quick_service" || cashier_type=="food_court") { + window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/'; + }else{ + if(result.table_type == "Table"){ + window.location.href = "/foodcourt/table/" + result.table_id + } + else { + window.location.href = "/foodcourt/room/" + result.table_id + } + } + }); + } + }); + }); - $("#remove-all").on('click', function(e){ - e.preventDefault(); - var sale_id = $('#sale-id').text(); - $.ajax({ - type: "GET", - url: "/foodcourt/" + sale_id + "/" + cashier_type + "/remove_all_discount", - success: function(result){ - swal({ - title: "Information!", - text: result.status, - type: "success", - }, function () { - if (cashier_type=="quick_service" || cashier_type=="food_court") { - window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/'; - }else{ - if(result.table_type == "Table"){ - window.location.href = "/foodcourt/table/" + result.table_id - } - else { - window.location.href = "/foodcourt/room/" + result.table_id - } - } - }); - } - }); - }); + // Pay Discount for membership + $("#member-discount").on('click', function(e){ + e.preventDefault(); + var sale_id = $('#sale-id').text(); + var sub_total = totalAmount; + var ajax_url = "/foodcourt/" + sale_id + "/member_discount"; - // Pay Discount for membership - $("#member-discount").on('click', function(e){ - e.preventDefault(); - var sale_id = $('#sale-id').text(); - var sub_total = $('#order-sub-total').text(); - var ajax_url = "/foodcourt/" + sale_id + "/member_discount"; + // Selected Account + //var account_types = JSON.stringify(get_selected_account_types()); - // Selected Account - //var account_types = JSON.stringify(get_selected_account_types()); + // if($('.accounts-type').hasClass('selected-account') == true){ - // if($('.accounts-type').hasClass('selected-account') == true){ + // var params = {'sale_id':sale_id, 'sub_total':sub_total, 'account_types':account_types }; - // var params = {'sale_id':sale_id, 'sub_total':sub_total, 'account_types':account_types }; + var params = {'cashier_type': cashier_type,'sale_id':sale_id, 'sub_total':sub_total }; - var params = {'cashier_type': cashier_type,'sale_id':sale_id, 'sub_total':sub_total }; + $.ajax({ + type: "POST", + url: ajax_url, + data: params, + success:function(result){ + if (result.status == "Success") { + type = 'success' + btn_color = 'green' + }else{ + type = 'error' + btn_color = 'red' + } + swal({ + title: "Information!", + text: result.status, + confirmButtonText: 'OK', + confirmButtonColor: btn_color, + }, function () { + if (cashier_type=="quick_service" || cashier_type=="food_court") { + window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/'; + }else{ + if(result.table_type == "Table"){ + window.location.href = "/foodcourt/table/" + result.table_id + } + else { + window.location.href = "/foodcourt/room/" + result.table_id + } + } + }); + } + }); - $.ajax({ - type: "POST", - url: ajax_url, - data: params, - success:function(result){ - if (result.status == "Success") { - type = 'success' - btn_color = 'green' - }else{ - type = 'error' - btn_color = 'red' - } - swal({ - title: "Information!", - text: result.status, - confirmButtonText: 'OK', - confirmButtonColor: btn_color, - }, function () { - if (cashier_type=="quick_service" || cashier_type=="food_court") { - window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/'; - }else{ - if(result.table_type == "Table"){ - window.location.href = "/foodcourt/table/" + result.table_id - } - else { - window.location.href = "/foodcourt/room/" + result.table_id - } - } - }); - } - }); - - });//end member discount + });//end member discount }); - /* Remove Selection */ - function selection_remove(){ - $(".item-row").removeClass("selected-item"); - $(".accounts-type").removeClass("selected-account"); - } +/* Remove Selection */ +function selection_remove(){ + $(".item-row").removeClass("selected-item"); + $(".accounts-type").removeClass("selected-account"); +} - /* Get Item rows but not discount*/ - function get_item_rows(){ - var sale_items = []; - $('.item-row.item').not('.discount').each(function(i){ - var sale_item = {}; - sale_item.id = $(this).attr('id').substr(0,16); - sale_item.name = $(this).find('#item-name-price').text().split('@')[0]; - sale_item.account_id = $(this).find('#item-account-type').text(); - sale_item.price = $(this).find('#item-total-price').text(); - sale_items.push(sale_item); - }); - return sale_items; - } +/* Get Item rows but not discount*/ +function get_item_rows(){ + var sale_items = []; + $('.item-row.item').not('.discount').each(function(i){ + var sale_item = {}; + sale_item.id = $(this).attr('id').substr(0,16); + sale_item.name = $(this).find('#item-name-price').text().split('@')[0]; + sale_item.account_id = $(this).find('#item-account-type').text(); + sale_item.price = $(this).find('#item-total-price').text(); + sale_items.push(sale_item); + }); + return sale_items; +} - /* Get discount Item rows */ - function get_new_discount_item_rows(){ - var sale_items = []; - $('.item-row.new-discount').each(function(i){ - var sale_item = {}; - sale_item.id = $(this).attr('id'); - sale_item.name = $(this).find('#item-name-price').text(); - sale_item.account_id = $(this).find('#item_account_type').text(); - sale_item.price = $(this).find('#item-total-price').text(); - sale_items.push(sale_item); - }); - return sale_items; - } +/* Get discount Item rows */ +function get_new_discount_item_rows(){ + var sale_items = []; + $('.item-row.new-discount').each(function(i){ + var sale_item = {}; + sale_item.id = $(this).attr('id'); + sale_item.name = $(this).find('#item-name-price').text(); + sale_item.account_id = $(this).find('#item_account_type').text(); + sale_item.price = $(this).find('#item-total-price').text(); + sale_items.push(sale_item); + }); + return sale_items; +} - /* Get discount Item rows */ +/* Get discount Item rows */ function get_selected_discount_items(){ - var sale_items = []; - $('.item-row.discount.selected-item').each(function(i){ - var sale_item = {}; - sale_item.id = $(this).attr('id'); - sale_item.name = $(this).find('#item-name-price').text(); - sale_item.account_id = $(this).find('#item_account_type').text(); - sale_item.price = $(this).find('#item-total-price').text(); - sale_items.push(sale_item); - }); - return sale_items; + var sale_items = []; + $('.item-row.discount.selected-item').each(function(i){ + var sale_item = {}; + sale_item.id = $(this).attr('id'); + sale_item.name = $(this).find('#item-name-price').text(); + sale_item.account_id = $(this).find('#item_account_type').text(); + sale_item.price = $(this).find('#item-total-price').text(); + sale_items.push(sale_item); + }); + return sale_items; } /* Get Selected Sale Item's ID and Price */ function get_selected_sale_items(){ - var sale_items = []; - $('.item-row.item.selected-item').each(function(i){ - var sale_item = {}; - sale_item.id = $(this).attr('id').substr(0,16); - sale_item.name = $(this).find('#item-name-price').text().split('@')[0]; - sale_item.account_id = $(this).find('#item-account-type').text(); - sale_item.price = $(this).find('#item-total-price').text(); - sale_items.push(sale_item); - }); - return sale_items; + var sale_items = []; + $('.item-row.item.selected-item').each(function(i){ + var sale_item = {}; + sale_item.id = $(this).attr('id').substr(0,16); + sale_item.name = $(this).find('#item-name-price').text().split('@')[0]; + sale_item.account_id = $(this).find('#item-account-type').text(); + sale_item.price = $(this).find('#item-total-price').text(); + sale_items.push(sale_item); + }); + return sale_items; } /* Get Selected Accounts ID and Price */ function get_selected_account_types(){ - var account_types = []; + var account_types = []; - $('.selected-account').each(function(i){ - var account= {}; - account.id = $(this).attr('id').substr(8); - account.name = $(this).text(); - account_types.push(account); - }); - return account_types; + $('.selected-account').each(function(i){ + var account= {}; + account.id = $(this).attr('id').substr(8); + account.name = $(this).text(); + account_types.push(account); + }); + return account_types; } /* Calculate Overall Discount*/ function calculate_overall_discount(type, amount){ - var origin_sub_total = parseFloat($("#order-sub-total").text()) + parseFloat($("#order-discount").text()); - var dis_amount = 0; - var sub_total = 0; - var total_discount = 0; + var sub_total = totalAmount; + var total_discount = 0; - // For Net Pay - if(type == 0){ - total_discount = Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision); - } + // For Net Pay + if(type == 0){ + total_discount = Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision); + } - // For Percentage Pay - if(type == 1){ - if(amount > 100 ){ - swal({ - title:"Oops!", - text:'Percentage Value over 100!', - type: "error", - confirmButtonText: 'OK', - confirmButtonColor:"red" - }); - } - else{ - total_discount = Math.round(totalAmount * amount / 100 * Math.pow(10, precision)) / Math.pow(10, precision); - } - } - - sub_total = parseFloat(totalAmount) - parseFloat(total_discount) - - $("#order-discount").text(parseFloat(total_discount).toFixed(<%= precision.to_i %>)); + // For Percentage Pay + if(type == 1){ + if(amount > 100 ){ + swal({ + title:"Oops!", + text:'Percentage Value over 100!', + type: "error", + confirmButtonText: 'OK', + confirmButtonColor:"red" + }); + } + else{ + total_discount = Math.round(sub_total * amount / 100 * Math.pow(10, precision)) / Math.pow(10, precision); + } + } + totalDiscount = total_discount + $("#order-discount").text(parseFloat(total_discount).toFixed(<%= precision.to_i %>)); } /* Calculate Items Discount*/ function calculate_item_discount(type, amount, sale_items, account_types){ - var origin_sub_total = parseFloat($("#order-sub-total").text()); - var dis_amount = 0; - var sub_total = 0; - var total_discount = 0; - var arrItemName = ""; + var origin_sub_total = totalAmount; + var dis_amount = 0; + var sub_total = 0; + var total_discount = 0; + var arrItemName = ""; - $("#discount_itemsErr").html(""); - $("#discount-amountErr").html(""); - // For Net Pay - if(origin_sub_total > 0){ - if(type == 0){ - dis_amount = -Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision); - if(sale_items.length > 0){ - for(var i=0;i < sale_items.length;i++){ - // if(account_types.length > 0){ - // for(var j=0; j < account_types.length; j++){ - // if(sale_items[i].account_id == account_types[j].id){ - // // Discount Items - // var discount_item_row = item_row_template(type, sale_items[i], dis_amount, amount); - // $("#order-items-table tbody").append(discount_item_row); - // total_discount = total_discount + amount; - // } - // } - // } - // else { - if(parseFloat(amount) > parseFloat(sale_items[i].price)){ - arrItemName += ", " + sale_items[i].name; - }else{ - var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); - total_discount = parseFloat(total_discount) + parseFloat(amount); + $("#discount_itemsErr").html(""); + $("#discount-amountErr").html(""); + // For Net Pay + if(origin_sub_total > 0){ + if(type == 0){ + dis_amount = -Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision); + if(sale_items.length > 0){ + for(var i=0;i < sale_items.length;i++){ + if(parseFloat(amount) > parseFloat(sale_items[i].price)){ + arrItemName += ", " + sale_items[i].name; + }else{ + var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); + total_discount = parseFloat(total_discount) + parseFloat(amount); - if(parseFloat(origin_sub_total) >= parseFloat(total_discount)){ - $("#order-items-table tbody").append(discount_item_row); - }else{ - total_discount = parseFloat(total_discount) - parseFloat(amount); - $("#discount-amountErr").html("Discount is greater than sub total!"); - } - } - // } - } - } + if(parseFloat(origin_sub_total) >= parseFloat(total_discount)){ + $("#order-items-table tbody").append(discount_item_row); + }else{ + total_discount = parseFloat(total_discount) - parseFloat(amount); + $("#discount-amountErr").html("Discount is greater than sub total!"); + } + } + } + } - if(arrItemName!=""){ - arrItemName = arrItemName.substr(2); - if(arrItemName.match(/,/g || []) != null){ - if(arrItemName.match(/,/g || []).length >= 1){ - $("#discount_itemsErr").html("Discount is greater than "+arrItemName+" prices"); - } - }else{ - $("#discount_itemsErr").html("Discount is greater than "+arrItemName+" price"); - } + if(arrItemName!=""){ + arrItemName = arrItemName.substr(2); + if(arrItemName.match(/,/g || []) != null){ + if(arrItemName.match(/,/g || []).length >= 1){ + $("#discount_itemsErr").html("Discount is greater than "+arrItemName+" prices"); + } + }else{ + $("#discount_itemsErr").html("Discount is greater than "+arrItemName+" price"); + } - } + } - // No Needs For Auto Selected - // if(account_types.length > 0){ - // var item_rows=get_item_rows(); - // if(item_rows.length > 0){ - // for(var k=0; k < item_rows.length; k++){ - // for(var j=0; j < account_types.length; j++){ - // if(item_rows[k].account_id == account_types[j].id){ - // // Discount Items - // var discount_item_row = item_row_template(type, item_rows[k], dis_amount, amount); - // $("#order-items-table tbody").append(discount_item_row); - // total_discount = total_discount + amount; - // } - // } - // } - // } - // else { - // alert("No Items!"); - // } - // } + sub_total = parseFloat(origin_sub_total) - parseFloat(total_discount); + totalAmount = sub_total + $("#order-sub-total").text(parseFloat(sub_total).toFixed(<%= precision.to_i %>)); + } - sub_total = parseFloat(origin_sub_total) - parseFloat(total_discount); - totalAmount = sub_total - $("#order-sub-total").text(parseFloat(sub_total).toFixed(<%= precision.to_i %>)); - } + // For Percentage Pay + if(type == 1){ + if(amount > 100 ){ + swal({ + title:"Oops!", + text:'Percentage Value over 100!', + type: "error", + confirmButtonText: 'OK', + confirmButtonColor:"red" + }); + } + else{ + // Check sale items exists + if(sale_items.length > 0){ + for(var i=0;i < sale_items.length;i++){ + dis_amount = -Math.round(sale_items[i].price * amount / 100 * Math.pow(10, precision)) / Math.pow(10, precision); + var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); - // For Percentage Pay - if(type == 1){ - if(amount > 100 ){ - swal({ - title:"Oops!", - text:'Percentage Value over 100!', - type: "error", - confirmButtonText: 'OK', - confirmButtonColor:"red" - }); - } - else{ - // Check sale items exists - if(sale_items.length > 0){ - for(var i=0;i < sale_items.length;i++){ - // if(account_types.length > 0){ - // for(var j=0; j < account_types.length; j++){ - // if(sale_items[i].account_id == account_types[j].id){ - // // Discount Items - // dis_amount = 0 - ((sale_items[i].price * amount)/100); - // var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); - // $("#order-items-table tbody").append(discount_item_row); - // total_discount = total_discount + dis_amount; - // } - // } - // } - // else { - dis_amount = -Math.round(sale_items[i].price * amount / 100 * Math.pow(10, precision)) / Math.pow(10, precision); - var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); + total_discount = total_discount + dis_amount; + if(parseFloat(origin_sub_total) >= parseFloat(total_discount)){ + $("#order-items-table tbody").append(discount_item_row); + }else{ + total_discount = total_discount - dis_amount; + $("#discount-amountErr").html("Discount is greater than sub total!"); + } + } + sub_total = parseFloat(origin_sub_total) + parseFloat(total_discount); + totalAmount = sub_total + $("#order-sub-total").text(parseFloat(sub_total).toFixed(<%= precision.to_i %>)); + } + } + } - total_discount = total_discount + dis_amount; - if(parseFloat(origin_sub_total) >= parseFloat(total_discount)){ - $("#order-items-table tbody").append(discount_item_row); - }else{ - total_discount = total_discount - dis_amount; - $("#discount-amountErr").html("Discount is greater than sub total!"); - } - // } - } - sub_total = parseFloat(origin_sub_total) + parseFloat(total_discount); - totalAmount = sub_total - $("#order-sub-total").text(parseFloat(sub_total).toFixed(<%= precision.to_i %>)); - } - } - // No Needs For Auto Selected - // Check account types exists - // if(account_types.length > 0){ - // var item_rows=get_item_rows(); - // console.log(account_types); - // if(item_rows.length > 0){ - // for(var k=0; k < item_rows.length; k++){ - // for(var j=0; j < account_types.length; j++){ - // if(item_rows[k].account_id == account_types[j].id){ - // // Discount Items - // dis_amount = 0 - ((item_rows[k].price * amount)/100); - // var discount_item_row = item_row_template(type, item_rows[k], dis_amount, amount); - // $("#order-items-table tbody").append(discount_item_row); - // total_discount = total_discount + dis_amount; - // } - // } - // } - // } - // else { - // alert("No Items!"); - // } - // } - } - - }else{ - $("#discount-amountErr").html("Discount is greater than sub total!"); - } + }else{ + $("#discount-amountErr").html("Discount is greater than sub total!"); + } } function item_row_template(type, item, discount_amount, amount){ - var dis_str = "-discount"; - if(type == 1){ - dis_str = dis_str + "(" + amount + "%)" - } - var discount_item_row = "" + - "" + - "" + - "" + - item.name + dis_str + - "" + - "" + - "" + - "1" + - "" + - "" + - "" + - discount_amount + - "" + - "" + - ""; - return discount_item_row; + var dis_str = "-discount"; + if(type == 1){ + dis_str = dis_str + "(" + amount + "%)" + } + var discount_item_row = "" + + "" + + "" + + "" + + item.name + dis_str + + "" + + "" + + "" + + "1" + + "" + + "" + + "" + + discount_amount + + "" + + "" + + ""; + return discount_item_row; } diff --git a/app/views/install/_form.html.erb b/app/views/install/_form.html.erb index c4520cd6..682143c8 100755 --- a/app/views/install/_form.html.erb +++ b/app/views/install/_form.html.erb @@ -1,4 +1,4 @@ -
+<%= form_tag activate_path, class: "row" do %>
@@ -27,11 +27,11 @@
- +
- +
@@ -41,4 +41,4 @@
- +<% end %> diff --git a/app/views/layouts/CRM.html.erb b/app/views/layouts/CRM.html.erb index 7d45f0ba..4a994768 100755 --- a/app/views/layouts/CRM.html.erb +++ b/app/views/layouts/CRM.html.erb @@ -31,6 +31,7 @@

Please wait...

+ <%= render 'shared/license_expire_warning' if Rails.env.production? %>
diff --git a/app/views/layouts/OQS.html.erb b/app/views/layouts/OQS.html.erb index de7c2d14..4c02c0db 100755 --- a/app/views/layouts/OQS.html.erb +++ b/app/views/layouts/OQS.html.erb @@ -35,24 +35,25 @@

Please wait...

+ <%= render 'shared/license_expire_warning' if Rails.env.production? %>
<%= render 'layouts/header' %> -
- <%= render 'layouts/left_sidebar' %> - <%= render 'layouts/right_sidebar' %> +
+ <%= render 'layouts/left_sidebar' %> + <%= render 'layouts/right_sidebar' %>
-
+
<% flash.each do |type, message| %>
<%= message %>
- <% end %> - <%= yield %> + <% end %> + <%= yield %>
- \ No newline at end of file + diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index 56c72052..6c6bbd14 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -51,8 +51,18 @@ <% end %> <% if can? :index, :home %> <% if current_login_employee.role != "kitchen" %> + <% if current_user.role == "cashier" + shift = ShiftSale.current_open_shift(current_user) + if !shift.nil? + path = origami_dashboard_path + else + path = new_origami_shift_path + end + else current_user.role == "administrator" + path = origami_dashboard_path + end %>
+ + <%= render 'shared/license_expire_warning' if Rails.env.production? %>
@@ -39,7 +41,6 @@ <%= render 'layouts/header' %>
<%= render 'layouts/left_sidebar' %> - <%= render 'layouts/right_sidebar' %>
diff --git a/app/views/layouts/installation.html.erb b/app/views/layouts/installation.html.erb index 542b7d5a..c41b2532 100755 --- a/app/views/layouts/installation.html.erb +++ b/app/views/layouts/installation.html.erb @@ -10,34 +10,34 @@ <%= csrf_meta_tags %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - + <% flash.each do |type, message| %> - <% if type == "notice" + <% if type == "notice" color = "alert-success" elsif type == "error" color = "alert-danger" else color = "bg-black" end %> - + diff --git a/app/views/layouts/inventory.html.erb b/app/views/layouts/inventory.html.erb index 28dc00f6..bde57dbb 100755 --- a/app/views/layouts/inventory.html.erb +++ b/app/views/layouts/inventory.html.erb @@ -31,14 +31,15 @@

Please wait...

+ <%= render 'shared/license_expire_warning' if Rails.env.production? %>
<%= render 'layouts/header' %> -
- <%= render 'layouts/left_sidebar' %> - <%= render 'layouts/right_sidebar' %> +
+ <%= render 'layouts/left_sidebar' %> + <%= render 'layouts/right_sidebar' %>
@@ -54,8 +55,8 @@ <% end %> <%= render_breadcrumb %> - <%= yield %> + <%= yield %>
- \ No newline at end of file + diff --git a/app/views/layouts/origami.html.erb b/app/views/layouts/origami.html.erb index 83081cbf..656898d3 100755 --- a/app/views/layouts/origami.html.erb +++ b/app/views/layouts/origami.html.erb @@ -31,14 +31,15 @@

Please wait...

+ <%= render 'shared/license_expire_warning' if Rails.env.production? %>
<%= render 'layouts/header' %> -
- <%= render 'layouts/left_sidebar' %> - <%= render 'layouts/right_sidebar' %> +
+ <%= render 'layouts/left_sidebar' %> + <%= render 'layouts/right_sidebar' %>
@@ -46,21 +47,20 @@ -
+
<% flash.each do |type, message| %> - <% if type == "notice" + <% if type == "notice" color = "alert-success" elsif type == "error" color = "alert-danger" else color = "bg-black" end %> - + - <% end %> - <%= yield %> + <% end %> + <%= yield %>
- \ No newline at end of file diff --git a/app/views/layouts/waiter.html.erb b/app/views/layouts/waiter.html.erb index c6cc4d99..885f9594 100755 --- a/app/views/layouts/waiter.html.erb +++ b/app/views/layouts/waiter.html.erb @@ -14,6 +14,7 @@ + <%= render 'shared/license_expire_warning' %> <%= render 'layouts/header' %>
<% flash.each do |type, message| %> diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 1df79ef9..487eeeb2 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -1,5 +1,5 @@ -
+
diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index d5d3e7e5..fa2135c9 100644 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -4,7 +4,7 @@ <% type = request.path_info.include?('quick_service') || request.path_info.include?('food_court')%> <% modify_order = request.path_info.include?('modify_order')%> -
+
diff --git a/app/views/origami/cash_ins/new.html.erb b/app/views/origami/cash_ins/new.html.erb index 5b23656e..675a82c4 100755 --- a/app/views/origami/cash_ins/new.html.erb +++ b/app/views/origami/cash_ins/new.html.erb @@ -1,4 +1,4 @@ -
+

<%= t :cash_in %>

diff --git a/app/views/origami/cash_outs/new.html.erb b/app/views/origami/cash_outs/new.html.erb index ea83b2e0..f31feb62 100755 --- a/app/views/origami/cash_outs/new.html.erb +++ b/app/views/origami/cash_outs/new.html.erb @@ -1,4 +1,4 @@ -
+

<%= t :cash_out %>

diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index bb72b2ed..3640c211 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -176,25 +176,40 @@
<%= t("views.right_panel.detail.order") %>
- <% if !@total_order.nil? %> - - - - - <% end %> - - <% if !@total_accounts.nil? %> - <% @total_accounts.each do |account| %> - - - + <% if payment.payment_method == 'paypar' %> + + <% elsif payment.payment_method == 'paymal' %> + + <% else %> + + <% end %> + + + <% end %> <% end %> - - - <% end %> + <% end %> + + <% total_card = @sale_data.select { |hash| hash["card"]!=nil } %> + <% if !total_card.nil? %> + + + + + <% end %> <% end %> <% if !@top_items.nil? %> diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 5d24c9d1..09aa7f84 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -1,4 +1,4 @@ -
+
@@ -300,12 +300,14 @@ var originalDiscount = totalDiscount; switch (input_type) { case 'num': var input_value = $(this).attr("data-value"); - if (parseFloat(original_value) == 0){ - $('#discount-amount').val(input_value); - } - else{ - $('#discount-amount').val(original_value + '' + input_value); - } + if (input_value == "." && original_value.includes(".")) { + break; + } + if (parseFloat(input_value) >= 0 && !original_value.includes(".") && (parseFloat(original_value) == 0)) { + $('#discount-amount').val(parseFloat(input_value)); + } else { + $('#discount-amount').val(original_value + input_value); + } break; case 'add': var input_value = $(this).attr("data-value"); diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 39c33749..a583e659 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index b71f616a..f66127f2 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/order_reservation/index.html.erb b/app/views/origami/order_reservation/index.html.erb index 4355c06a..dcc6af33 100644 --- a/app/views/origami/order_reservation/index.html.erb +++ b/app/views/origami/order_reservation/index.html.erb @@ -1,6 +1,6 @@ <%= stylesheet_link_tag 'order_reservation', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'order_reservation', 'data-turbolinks-track': 'reload' %> -
+
<% pending_count = 0 diff --git a/app/views/origami/other_charges/index.html.erb b/app/views/origami/other_charges/index.html.erb index 886eda51..06208b2f 100755 --- a/app/views/origami/other_charges/index.html.erb +++ b/app/views/origami/other_charges/index.html.erb @@ -1,4 +1,4 @@ -
+
@@ -202,7 +202,7 @@ <%else%> <%end%> - +
diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 2ead90c7..e5c12572 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -680,8 +680,10 @@ $(document).ready(function(){ $('#pay').click(function() { sub_total = $('#sub-total').text(); member = $('#membership_id').text(); - if (payment_type && payment_type.length > 0 && !other_payments.some(x => payment_type.indexOf(x[0]) >= 0 && x[1] > 0) && sub_total != 0.0 && member) { + if (payment_type && payment_type.length > 0 && parseInt(jQuery.inArray("Credit", payment_type)) == -1 && !other_payments.some(x => payment_type.indexOf(x[0]) >= 0 && x[1] > 0) && sub_total != 0.0 && member) { swal("Oops","Please Pay with " + payment_methods.find(x => payment_type.indexOf(x) >= 0) + " Payment","warning"); + } else if (payment_type && payment_type.length > 0 && parseInt(jQuery.inArray("Credit", payment_type)) != -1 && $('#credit').text() == 0 && sub_total != 0.0 && member) { + swal("Oops","Please Pay with Credit Payment","warning"); } else { $( "#loading_wrapper").show(); if($('#balance').text() > 0){ diff --git a/app/views/origami/pending_order/index.html.erb b/app/views/origami/pending_order/index.html.erb index 903c13a5..fe8ba72f 100644 --- a/app/views/origami/pending_order/index.html.erb +++ b/app/views/origami/pending_order/index.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/pending_order/show.html.erb b/app/views/origami/pending_order/show.html.erb index df120aae..993d6e8a 100644 --- a/app/views/origami/pending_order/show.html.erb +++ b/app/views/origami/pending_order/show.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/shifts/show.html.erb b/app/views/origami/shifts/show.html.erb index a752e5b5..ec529e8c 100755 --- a/app/views/origami/shifts/show.html.erb +++ b/app/views/origami/shifts/show.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index b7ec4ca1..f76c6c01 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/reports/dailysale/index.html.erb b/app/views/reports/dailysale/index.html.erb index 0b9cfc25..374835cf 100755 --- a/app/views/reports/dailysale/index.html.erb +++ b/app/views/reports/dailysale/index.html.erb @@ -83,7 +83,7 @@
<% @payment_methods.each do |method| %> - + <% end %> diff --git a/app/views/reports/dailysale/index.xls.erb b/app/views/reports/dailysale/index.xls.erb index cc0eced9..0d04d6ec 100755 --- a/app/views/reports/dailysale/index.xls.erb +++ b/app/views/reports/dailysale/index.xls.erb @@ -28,7 +28,7 @@ <% @payment_methods.each do |method| %> - + <% end %> diff --git a/app/views/reports/payment_method/index.html.erb b/app/views/reports/payment_method/index.html.erb index 93f7be28..6d6456bc 100755 --- a/app/views/reports/payment_method/index.html.erb +++ b/app/views/reports/payment_method/index.html.erb @@ -41,7 +41,7 @@ <% end %> <% @payment_methods.each do |method| %> - + <% end %> diff --git a/app/views/reports/payment_method/index.xls.erb b/app/views/reports/payment_method/index.xls.erb index ec4dfbee..ca543e0d 100755 --- a/app/views/reports/payment_method/index.xls.erb +++ b/app/views/reports/payment_method/index.xls.erb @@ -28,7 +28,7 @@ <% end %> <% @payment_methods.each do |method| %> - + <% end %> diff --git a/app/views/review_license/index.html.erb b/app/views/review_license/index.html.erb new file mode 100644 index 00000000..e722eaf1 --- /dev/null +++ b/app/views/review_license/index.html.erb @@ -0,0 +1,78 @@ +<% renewable_date = current_license.read_license("renewable_date") %> +<% date_count = (renewable_date.to_date - Date.today).to_i %> +<% day = pluralize( date_count, 'day' )%> + +<% if @license_status == 0 %> + <% text = 'Your license has been expired.' %> +<% else %> + <% text = "Your license will expire in #{day}." %> +<% end %> + +
+
+
+
+
+ <%= link_to origami_dashboard_url do %> + + <% end %> +

Review Your License

+ <% if flash[:message].present? %> +

<%= flash[:message] %>

+ <% end %> +
+ <% if text %> +
<%= text %>

+ <% end %> +
Call Center Phone No: +959 445 665 311
+
+
License Info:
+
+
+
+ + +
+ +
+ + +
+
+ +
+ + +
+
+
+
+ <%= form_with url: review_license_url, local: true do %> + <%= submit_tag 'Review Licese', class: 'btn btn-primary btn-lg float-right m-l-10 m-r-5' %> + <%= link_to 'Go To Home', root_url, class: 'btn btn-default btn-lg float-right' %> + <% end %> +
+
+
+
+
+ + diff --git a/app/views/home/create.html.erb b/app/views/sessions/create.html.erb similarity index 100% rename from app/views/home/create.html.erb rename to app/views/sessions/create.html.erb diff --git a/app/views/home/destroy.html.erb b/app/views/sessions/destroy.html.erb similarity index 100% rename from app/views/home/destroy.html.erb rename to app/views/sessions/destroy.html.erb diff --git a/app/views/home/index-old.html.erb b/app/views/sessions/index-old.html.erb similarity index 100% rename from app/views/home/index-old.html.erb rename to app/views/sessions/index-old.html.erb diff --git a/app/views/home/index.html.erb b/app/views/sessions/index.html.erb similarity index 100% rename from app/views/home/index.html.erb rename to app/views/sessions/index.html.erb diff --git a/app/views/home/index_backup.html.erb b/app/views/sessions/index_backup.html.erb similarity index 100% rename from app/views/home/index_backup.html.erb rename to app/views/sessions/index_backup.html.erb diff --git a/app/views/home/show.html.erb b/app/views/sessions/show.html.erb similarity index 100% rename from app/views/home/show.html.erb rename to app/views/sessions/show.html.erb diff --git a/app/views/settings/menu_item_groups/edit.html.erb b/app/views/settings/menu_item_groups/edit.html.erb new file mode 100755 index 00000000..8d285d49 --- /dev/null +++ b/app/views/settings/menu_item_groups/edit.html.erb @@ -0,0 +1,70 @@ + + +
+
+ <%= simple_form_for ([:settings,@settings_menu_item_group]), :url => settings_menu_item_group_path do |f| %> + <%= f.error_notification %> +
+ <%= f.input :name, :label => "Group Name" ,input_html: {required: true }%> + <%= f.label :lookup_type, label: 'Menu Category', :class => "control-label string optional bmd-label-static" %> + <%= f.collection_select :lookup_type, @menu_category, :id, :name, {}, {:class =>"form-control"} %> + <%= f.label :value, label: 'Menu Items', :class => "control-label string optional bmd-label-static" %> + <%= f.grouped_collection_select :value, @menu_category, :menu_items, :name, :item_code, :name, {}, {:class =>"form-control", :multiple=> true} %> +
+ +
+ <%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %> +
+ <% end %> +
+
+
+
+
view_headline <%= t("views.right_panel.header.page_detail") %>
+

+ 1) <%= t("views.right_panel.detail.lookup") + " " + t("views.right_panel.detail.type_txt") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.lookup_txt") %>
+ 2) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.name_txt2") %>
+ 3) <%= t("views.right_panel.detail.value") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.value_txt") %>
+

+
list <%= t("views.right_panel.header.button_lists") %>
+

+ 1) <%= t("views.right_panel.button.submit") %> - <%= t("views.right_panel.detail.submit_btn_txt") %> <%= t("views.right_panel.detail.lookup_txt") %>
+

+
list <%= t("views.right_panel.header.link_lists") %>
+

+ 1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
+ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.lookup_txt") %>
+

+
+
+
+
+ + + diff --git a/app/views/settings/menu_item_groups/index.html.erb b/app/views/settings/menu_item_groups/index.html.erb new file mode 100644 index 00000000..89ec57e7 --- /dev/null +++ b/app/views/settings/menu_item_groups/index.html.erb @@ -0,0 +1,69 @@ + + + +
+
+
+ <%= link_to t("views.btn.new"),new_settings_menu_item_group_path,:class => 'btn btn-primary btn-lg float-right waves-effect"' %> +
+
+
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.order") %> : <%= @total_order.total_order %>
<%= account.title %> (Account) : - <% @account_data.each do |data| %> - <% acc = account.title %> - <%= data[""+acc+""] %> <% if !data[''+acc+''].nil? %> ( <%= data[''+acc+'_amount'] %> ) <% end %> + <% if !(@total_payment_methods.nil?) %> + <% @total_payment_methods.each do |payment| %> + <% if !@sale_data[0].empty? %> + <% if payment.payment_method != 'mpu' && payment.payment_method != 'visa' && payment.payment_method != 'master' && payment.payment_method != 'jcb' %> +
Redeem Sales : Card Sales : <%= payment.payment_method.to_s.capitalize %> Sales : + <% @sale_data.each do |data| %> + <% pay_mth = payment.payment_method %> + <%= data[pay_mth] %> + <% end %> +
<%= t("views.right_panel.detail.other_payment") %> : + <% total_other_amt = 0 %> + <% @sale_data.map { |k,v| k.map{|meth,amt| meth != 'cash' && meth != 'foc' && meth != 'creditnote' ? total_other_amt += amt : meth }} %> + <%= total_other_amt %> +
<%= t("views.right_panel.detail.sr") %> <%= t("views.righ_panel.detail.date") %><%= t("views.right_panel.detail.#{method}") %><%= t("views.right_panel.detail.#{method.parameterize == 'paymal' ? 'card_sales' : method.parameterize}") %><%= t("views.right_panel.detail.cash_sales") %><%= t("views.right_panel.detail.date") %><%= t("views.right_panel.detail.#{method}") %><%= t("views.right_panel.detail.#{method.parameterize == 'paymal' ? 'card_sales' : method.parameterize}") %><%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %>
<%= t("views.right_panel.detail.#{method} Sales") %><%= t("views.right_panel.detail.#{method.parameterize == 'paymal' ? 'card_sales' : method.parameterize}") %><%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %>
<%= t("views.right_panel.detail.#{method} Sales") %><%= t("views.right_panel.detail.#{method.parameterize == 'paymal' ? 'card_sales' : method.parameterize}") %><%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %>
+ + + + + + + + + + + <% @menu_item_group.each do |menu_item_group| %> + + + + + + + <% end %> + +
<%= t("views.right_panel.detail.menu_item_groups") %><%= t("views.right_panel.detail.group_names") %><%= t("views.right_panel.detail.menu_items") %><%= t("views.right_panel.detail.actions") %>
<%= menu_item_group.lookup_type %><%= menu_item_group.name %><%= menu_item_group.value %> + <%= link_to t("views.btn.edit"), edit_settings_menu_item_group_path(menu_item_group),:class => 'btn btn-primary btn-sm waves-effect' %> + <%= link_to t("views.btn.delete"), settings_menu_item_group_path(menu_item_group),:class => 'btn btn-danger btn-sm waves-effect', method: :delete, data: {confirm: 'Are you sure you want to delete this row ?'} %> + +
+
+
+
+
+
+
view_headline <%= t("views.right_panel.header.page_detail") %>
+

+ 1) <%= t("views.right_panel.detail.lookup") + " " + t("views.right_panel.detail.type_txt") %> - <%= t("views.right_panel.detail.type_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.lookup_txt") %>
+ 2) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.name_txt2") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.lookup_txt") %>
+ 3) <%= t("views.right_panel.detail.value") %> - <%= t("views.right_panel.detail.value_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.lookup_txt") %>
+ 4) <%= t("views.right_panel.detail.actions") %> - <%= t("views.right_panel.detail.actions_txt") %> <%= t("views.right_panel.detail.lookup_txt") %>
+

+
list <%= t("views.right_panel.header.button_lists") %>
+

+ 1) <%= t("views.right_panel.button.new") %> - <%= t("views.right_panel.detail.new_btn_txt") %> <%= t("views.right_panel.detail.lookup_txt") %>
+ 2) <%= t("views.right_panel.button.edit") %> - <%= t("views.right_panel.detail.edit_btn_txt") %> <%= t("views.right_panel.detail.lookup_txt") %>
+

+
list <%= t("views.right_panel.header.link_lists") %>
+

+ 1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
+ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.dashboard_txt") %>
+

+
+
+
+
+ diff --git a/app/views/settings/menu_item_groups/new.html.erb b/app/views/settings/menu_item_groups/new.html.erb new file mode 100644 index 00000000..70b137a7 --- /dev/null +++ b/app/views/settings/menu_item_groups/new.html.erb @@ -0,0 +1,70 @@ + + +
+
+ <%= simple_form_for ([:settings,@settings_menu_item_group]), :url => settings_menu_item_groups_path do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :name, :label => "Group Name" ,input_html: {required: true }%> + <%= f.label :lookup_type, label: 'Menu Category', :class => "control-label string optional bmd-label-static" %> + <%= f.collection_select :lookup_type, @menu_category, :id, :name, {}, {:class =>"form-control"} %> + <%= f.label :value, label: 'Menu Items', :class => "control-label string optional bmd-label-static" %> + <%= f.grouped_collection_select :value, @menu_category, :menu_items, :name, :item_code, :name, {}, {:class =>"form-control", :multiple=> true} %> +
+ +
+ <%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %> +
+ <% end %> +
+
+
+
+
view_headline <%= t("views.right_panel.header.page_detail") %>
+

+ 1) <%= t("views.right_panel.detail.lookup") + " " + t("views.right_panel.detail.type_txt") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.lookup_txt") %>
+ 2) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.name_txt2") %>
+ 3) <%= t("views.right_panel.detail.value") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.value_txt") %>
+

+
list <%= t("views.right_panel.header.button_lists") %>
+

+ 1) <%= t("views.right_panel.button.submit") %> - <%= t("views.right_panel.detail.submit_btn_txt") %> <%= t("views.right_panel.detail.lookup_txt") %>
+

+
list <%= t("views.right_panel.header.link_lists") %>
+

+ 1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %>
+ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.lookup_txt") %>
+

+
+
+
+
+ + \ No newline at end of file diff --git a/app/views/shared/_license_expire_warning.html.erb b/app/views/shared/_license_expire_warning.html.erb new file mode 100644 index 00000000..4a9ea8ef --- /dev/null +++ b/app/views/shared/_license_expire_warning.html.erb @@ -0,0 +1,56 @@ +<% license_status = current_license.detail_with_local_file %> +<% renewable_date = current_license.read_license("renewable_date") %> +<% date_count = (renewable_date.to_date - Date.today).to_i %> +<% day = pluralize( date_count, 'day' )%> + +<% if license_status == 0 + text = 'Your license has expired.' + elsif license_status == 2 + if date_count == 0 + text = "Your license will expire in tomorrow." + else + text = "Your license will expire in #{day}." + end + end +%> +<% if license_status == 0 || license_status == 2 %> + + +<% end %> + + diff --git a/app/views/transactions/shift_sales/show.html.erb b/app/views/transactions/shift_sales/show.html.erb index a1fd7edc..daab9f1a 100755 --- a/app/views/transactions/shift_sales/show.html.erb +++ b/app/views/transactions/shift_sales/show.html.erb @@ -135,7 +135,7 @@ <% @payment_methods.each do |method| %> - <%= method %> Payment + <%= method.parameterize == 'paymal' ? 'Card' : method.parameterize %> Payment <%= @other_payment[method.parameterize.to_sym] || 0.0 %> <% total_other_amount = total_other_amount + (@other_payment[method.parameterize.to_sym] || 0.0) %> @@ -154,7 +154,7 @@ Total Payment - <%= total_other_amount + @other_payment.foc_amount + @shift.cash_sales + @shift.credit_sales %> + <%= total_other_amount + @other_payment.foc_amount.to_d + @shift.cash_sales.to_d + @shift.credit_sales.to_d %> diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 40fe7287..3de08ef0 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -2,6 +2,8 @@ class ActionController::Base before_action :lookup_domain if Rails.env.production? before_action :set_locale + helper_method :current_license, + def not_found respond_to do |format| format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found } @@ -13,10 +15,9 @@ class ActionController::Base def lookup_domain if ENV["SERVER_MODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www" - @license = cache_license(ENV["SX_PROVISION_URL"], request.host) # request.subdomain.downcase - if !@license.nil? - logger.info "Location - " + @license.dbschema - ActiveRecord::Base.establish_connection(website_connection(@license)) + if license = cache_license # request.subdomain.downcase + logger.info "Location - " + license.dbschema + ActiveRecord::Base.establish_connection(website_connection(license)) else # reconnect_default_db logger.info 'License is nil' @@ -24,47 +25,30 @@ class ActionController::Base end elsif ENV["SERVER_MODE"] == "application" || request.subdomains.last && request.subdomains.last != "www" # check for license file - if check_license(request.host) - current_license(ENV["SX_PROVISION_URL"], request.host) - elsif ENV["SERVER_MODE"] == "application" || check_subdomain(request.host) + if !current_license.exists? redirect_to activate_path - else - not_found + elsif current_license.expired? + redirect_to review_license_path end else not_found end end - def current_license(url, lookup) - @license = License.new(url, lookup) - flag = @license.detail_with_local_file() - if (flag == 0) - flash[:notice] = 'Expired or No License!' - elsif (flag == 2) - flash[:notice] = 'Expiring! Please, License extend...' - else - Rails.logger.info "Run License" - end + def current_license + @license ||= License.new(ENV["SX_PROVISION_URL"], request.host) end - def cache_license(url, lookup) - @license = License.new(url, lookup) - - if (@license.detail_with_local_cache(lookup) == true) - return @license + def cache_license + if (current_license.detail_with_local_cache == true) + return current_license else return nil end end - def check_subdomain(lookup) - license = License.new(ENV["SX_PROVISION_URL"], lookup) - license.check_license_subdomain(lookup) - end - - def check_license(lookup) - License.check_license_file(lookup) + def check_subdomain + current_license.check_license_subdomain end def check_installation @@ -76,7 +60,6 @@ class ActionController::Base def website_connection(license) default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, :username => license.dbusername, :password => license.dbpassword) - end def reconnect_default_db @@ -114,27 +97,28 @@ class ActionController::API def lookup_domain if ENV["SERVER_CODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www" - @license = cache_license(ENV["SX_PROVISION_URL"], request.host) # request.subdomain.downcase - if (!@license.nil?) - logger.info "Location - " + @license.dbschema - ActiveRecord::Base.establish_connection(website_connection(@license)) + if license = cache_license # request.subdomain.downcase + logger.info "Location - " + license.dbschema + ActiveRecord::Base.establish_connection(website_connection(license)) else # reconnect_default_db logger.info 'License is nil' not_found end elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.last && request.subdomains.last != "www") - not_found unless check_license(request.host) + not_found unless current_license.exists? && !current_license.expired? else not_found end end - def cache_license(url, lookup) - @license = License.new(url, lookup) + def current_license + @license ||= License.new(ENV["SX_PROVISION_URL"], request.host) + end - if (@license.detail_with_local_cache(lookup) == true) - return @license + def cache_license + if (current_license.detail_with_local_cache == true) + return current_license else return nil end @@ -147,7 +131,6 @@ class ActionController::API def website_connection(license) default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, :username => license.dbusername, :password => license.dbpassword) - end def reconnect_default_db diff --git a/config/routes.rb b/config/routes.rb index b16641e5..49f04813 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,12 +21,17 @@ scope "(:locale)", locale: /en|mm/ do get 'get_key' => 'sym_control#get_key' #--------- Login/Authentication ------------# - get 'auth/:emp_id' => 'home#show', as: :emp_login - patch "auth/:emp_id" => 'home#update', as: :emp_login_update + get 'login' => 'sessions#index' + get 'auth/:emp_id' => 'sessions#show', as: :emp_login + patch "auth/:emp_id" => 'sessions#update', as: :emp_login_update - post 'login' => 'home#create' - delete 'logout' => 'home#destroy' - get 'dashboard' => 'home#dashboard' + post 'login' => 'sessions#create' + delete 'logout' => 'sessions#destroy' + + get 'review_license' => 'review_license#index' + post 'review_license' => 'review_license#create' + + get 'dashboard' => 'dashboard#index' namespace :induties do # resources :assign_in_duties @@ -280,7 +285,6 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/payment/others_payment/giftvoucher' => "gift_voucher#index" get 'sale/:sale_id/:type/payment/others_payment/:method' => 'others_payments#new' - #---------Void --------------# post 'sale/:sale_id/:type/void' => 'void#overall_void' @@ -370,6 +374,7 @@ scope "(:locale)", locale: /en|mm/ do # post 'credit_payment/junctionpay' => 'junction_pay#create' # post 'credit_payment/dinga' => 'dinga#create' # post 'credit_payment/gift_voucher' => 'gift_voucher#create' + post 'credit_payment/:method' => 'others_payments#create', :as => 'credit_payment' get 'sale/:sale_id/:type/credit_payment/others_payment' => "others_payments#index" get 'sale/:sale_id/:type/credit_payment/others_payment/mpu' => "mpu#index" @@ -386,7 +391,6 @@ scope "(:locale)", locale: /en|mm/ do # get 'sale/:sale_id/:type/credit_payment/others_payment/giftvoucher' => "gift_voucher#index" get 'sale/:sale_id/:type/credit_payment/others_payment/:method' => 'others_payments#new' - #------------- Start Reservation -------------------# resources :reservation #------------- End Reservation -------------------# @@ -484,6 +488,8 @@ scope "(:locale)", locale: /en|mm/ do resources :products #lookups resources :lookups + #menu_item_groups + resources :menu_item_groups #cashier_terminals resources :cashier_terminals #order_job_stations diff --git a/spec/controllers/api/menu_item_groups_controller_spec.rb b/spec/controllers/api/menu_item_groups_controller_spec.rb new file mode 100644 index 00000000..cb965035 --- /dev/null +++ b/spec/controllers/api/menu_item_groups_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::MenuItemGroupsController, type: :controller do + +end diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb new file mode 100644 index 00000000..7d2125d7 --- /dev/null +++ b/spec/controllers/dashboard_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe DashboardController, type: :controller do + +end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb new file mode 100644 index 00000000..003beded --- /dev/null +++ b/spec/controllers/sessions_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SessionsController, type: :controller do + +end diff --git a/spec/controllers/settings/menu_item_groups_controller_spec.rb b/spec/controllers/settings/menu_item_groups_controller_spec.rb new file mode 100644 index 00000000..34ae5c89 --- /dev/null +++ b/spec/controllers/settings/menu_item_groups_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Settings::MenuItemGroupsController, type: :controller do + +end diff --git a/spec/helpers/api/menu_item_groups_helper_spec.rb b/spec/helpers/api/menu_item_groups_helper_spec.rb new file mode 100644 index 00000000..0f29393f --- /dev/null +++ b/spec/helpers/api/menu_item_groups_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::MenuItemGroupsHelper. For example: +# +# describe Api::MenuItemGroupsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Api::MenuItemGroupsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/dashboard_helper_spec.rb b/spec/helpers/dashboard_helper_spec.rb new file mode 100644 index 00000000..12cff9a8 --- /dev/null +++ b/spec/helpers/dashboard_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the DashboardHelper. For example: +# +# describe DashboardHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe DashboardHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/sessions_helper_spec.rb b/spec/helpers/sessions_helper_spec.rb new file mode 100644 index 00000000..94841983 --- /dev/null +++ b/spec/helpers/sessions_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the SessionsHelper. For example: +# +# describe SessionsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe SessionsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/settings/menu_item_groups_helper_spec.rb b/spec/helpers/settings/menu_item_groups_helper_spec.rb new file mode 100644 index 00000000..8fa377e7 --- /dev/null +++ b/spec/helpers/settings/menu_item_groups_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Settings::MenuItemGroupsHelper. For example: +# +# describe Settings::MenuItemGroupsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Settings::MenuItemGroupsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end