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 @@
<%=@sale_data.sale_id %>
-Receipt No: <%=@sale_data.receipt_no rescue ' '%>
- -Date: <%=@sale_data.receipt_date.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>
-| Items | -QTY | -Price | -
|---|---|---|
| - <%=sale_item.account_id%> - <%=sale_item.qty%> - <%=sale_item.product_name%>@<%=sale_item.unit_price%> - | -- <%=sale_item.qty%> - | -- <%=(sale_item.qty*sale_item.unit_price)%> - | -
| - <%=sale_item.account_id%> - <%=sale_item.qty%> - <%=sale_item.product_name%>@<%=sale_item.unit_price%> - | -- <%=sale_item.qty.abs%> - | -- <%=(sale_item.qty*sale_item.unit_price)%> - | -