From 7a09ed01080b80ab6b726bfc012871a24814bb4f Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Thu, 30 Jan 2020 11:57:28 +0630 Subject: [PATCH 01/25] Menu Item Groups --- .../javascripts/api/menu_item_groups.coffee | 3 + .../settings/menu_item_groups.coffee | 3 + .../stylesheets/api/menu_item_groups.scss | 3 + .../settings/menu_item_groups.scss | 3 + .../api/menu_item_groups_controller.rb | 8 +++ .../settings/menu_item_groups_controller.rb | 59 ++++++++++++++++ app/helpers/api/menu_item_groups_helper.rb | 2 + .../settings/menu_item_groups_helper.rb | 2 + .../api/menu_item_groups/index.json.jbuilder | 2 + .../settings/menu_item_groups/edit.html.erb | 70 +++++++++++++++++++ .../settings/menu_item_groups/index.html.erb | 69 ++++++++++++++++++ .../settings/menu_item_groups/new.html.erb | 70 +++++++++++++++++++ config/routes.rb | 4 +- .../api/menu_item_groups_controller_spec.rb | 5 ++ .../menu_item_groups_controller_spec.rb | 5 ++ .../api/menu_item_groups_helper_spec.rb | 15 ++++ .../settings/menu_item_groups_helper_spec.rb | 15 ++++ 17 files changed, 337 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/api/menu_item_groups.coffee create mode 100644 app/assets/javascripts/settings/menu_item_groups.coffee create mode 100644 app/assets/stylesheets/api/menu_item_groups.scss create mode 100644 app/assets/stylesheets/settings/menu_item_groups.scss create mode 100644 app/controllers/api/menu_item_groups_controller.rb create mode 100644 app/controllers/settings/menu_item_groups_controller.rb create mode 100644 app/helpers/api/menu_item_groups_helper.rb create mode 100644 app/helpers/settings/menu_item_groups_helper.rb create mode 100644 app/views/api/menu_item_groups/index.json.jbuilder create mode 100755 app/views/settings/menu_item_groups/edit.html.erb create mode 100644 app/views/settings/menu_item_groups/index.html.erb create mode 100644 app/views/settings/menu_item_groups/new.html.erb create mode 100644 spec/controllers/api/menu_item_groups_controller_spec.rb create mode 100644 spec/controllers/settings/menu_item_groups_controller_spec.rb create mode 100644 spec/helpers/api/menu_item_groups_helper_spec.rb create mode 100644 spec/helpers/settings/menu_item_groups_helper_spec.rb 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/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/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/menu_item_groups_controller.rb b/app/controllers/api/menu_item_groups_controller.rb new file mode 100644 index 00000000..6041ec14 --- /dev/null +++ b/app/controllers/api/menu_item_groups_controller.rb @@ -0,0 +1,8 @@ +class Api::MenuItemGroupsController < ApplicationController + def index + # @groups = Lookup.where(lookup_type:'menu_item_groups') + # @group = @groups.group_by(&:name).map { |k, v| { k => v.map { |l| m = eval(l.value); { m[:menu_category] => m[:menu_items] } }.inject({}) { |h, v| p h; h.merge!(v) } } } + @group = Lookup.where(lookup_type:'menu_item_groups') + @group = @group.group_by(&:name).map{|k ,v| { k => v.map{|k, v| JSON.parse(k.value)}.inject({}) { |h, v| p h; h.merge!(v) }}}.inject({}) { |h, v| p h; h.merge!(v) } + 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/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/views/api/menu_item_groups/index.json.jbuilder b/app/views/api/menu_item_groups/index.json.jbuilder new file mode 100644 index 00000000..20b29060 --- /dev/null +++ b/app/views/api/menu_item_groups/index.json.jbuilder @@ -0,0 +1,2 @@ +json.status true +json.data @group \ No newline at end of file diff --git a/app/views/settings/menu_item_groups/edit.html.erb b/app/views/settings/menu_item_groups/edit.html.erb new file mode 100755 index 00000000..8d285d49 --- /dev/null +++ b/app/views/settings/menu_item_groups/edit.html.erb @@ -0,0 +1,70 @@ + + +
+
+ <%= simple_form_for ([:settings,@settings_menu_item_group]), :url => settings_menu_item_group_path do |f| %> + <%= f.error_notification %> +
+ <%= f.input :name, :label => "Group Name" ,input_html: {required: true }%> + <%= f.label :lookup_type, label: 'Menu Category', :class => "control-label string optional bmd-label-static" %> + <%= f.collection_select :lookup_type, @menu_category, :id, :name, {}, {:class =>"form-control"} %> + <%= f.label :value, label: 'Menu Items', :class => "control-label string optional bmd-label-static" %> + <%= f.grouped_collection_select :value, @menu_category, :menu_items, :name, :item_code, :name, {}, {:class =>"form-control", :multiple=> true} %> +
+ +
+ <%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %> +
+ <% end %> +
+
+
+
+
view_headline <%= t("views.right_panel.header.page_detail") %>
+

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

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

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

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

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

+
+
+
+
+ + + diff --git a/app/views/settings/menu_item_groups/index.html.erb b/app/views/settings/menu_item_groups/index.html.erb new file mode 100644 index 00000000..89ec57e7 --- /dev/null +++ b/app/views/settings/menu_item_groups/index.html.erb @@ -0,0 +1,69 @@ + + + +
+
+
+ <%= link_to t("views.btn.new"),new_settings_menu_item_group_path,:class => 'btn btn-primary btn-lg float-right waves-effect"' %> +
+
+ + + + + + + + + + + + <% @menu_item_group.each do |menu_item_group| %> + + + + + + + <% end %> + +
<%= t("views.right_panel.detail.menu_item_groups") %><%= t("views.right_panel.detail.group_names") %><%= t("views.right_panel.detail.menu_items") %><%= t("views.right_panel.detail.actions") %>
<%= menu_item_group.lookup_type %><%= menu_item_group.name %><%= menu_item_group.value %> + <%= link_to t("views.btn.edit"), edit_settings_menu_item_group_path(menu_item_group),:class => 'btn btn-primary btn-sm waves-effect' %> + <%= link_to t("views.btn.delete"), settings_menu_item_group_path(menu_item_group),:class => 'btn btn-danger btn-sm waves-effect', method: :delete, data: {confirm: 'Are you sure you want to delete this row ?'} %> + +
+
+
+
+
+
+
view_headline <%= t("views.right_panel.header.page_detail") %>
+

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

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

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

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

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

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

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

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

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

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

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

+
+
+
+
+ + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 933002d9..2d335b80 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,7 +44,7 @@ scope "(:locale)", locale: /en|mm/ do #Session Login and Logout post 'authenticate' => "authenticate#create" delete 'authenticate' => "authenticate#destroy" - + get "menu_item_groups" => "menu_item_groups#index" namespace :restaurant do get 'zones' => "zones#index" resources :menu, only: [:index, :show] @@ -461,6 +461,8 @@ scope "(:locale)", locale: /en|mm/ do resources :products #lookups resources :lookups + #menu_item_groups + resources :menu_item_groups #cashier_terminals resources :cashier_terminals #order_job_stations diff --git a/spec/controllers/api/menu_item_groups_controller_spec.rb b/spec/controllers/api/menu_item_groups_controller_spec.rb new file mode 100644 index 00000000..cb965035 --- /dev/null +++ b/spec/controllers/api/menu_item_groups_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::MenuItemGroupsController, type: :controller do + +end diff --git a/spec/controllers/settings/menu_item_groups_controller_spec.rb b/spec/controllers/settings/menu_item_groups_controller_spec.rb new file mode 100644 index 00000000..34ae5c89 --- /dev/null +++ b/spec/controllers/settings/menu_item_groups_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Settings::MenuItemGroupsController, type: :controller do + +end diff --git a/spec/helpers/api/menu_item_groups_helper_spec.rb b/spec/helpers/api/menu_item_groups_helper_spec.rb new file mode 100644 index 00000000..0f29393f --- /dev/null +++ b/spec/helpers/api/menu_item_groups_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::MenuItemGroupsHelper. For example: +# +# describe Api::MenuItemGroupsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Api::MenuItemGroupsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/settings/menu_item_groups_helper_spec.rb b/spec/helpers/settings/menu_item_groups_helper_spec.rb new file mode 100644 index 00000000..8fa377e7 --- /dev/null +++ b/spec/helpers/settings/menu_item_groups_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Settings::MenuItemGroupsHelper. For example: +# +# describe Settings::MenuItemGroupsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Settings::MenuItemGroupsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From 4a3d429a532a6e995af0350c20140433594115da Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Thu, 28 May 2020 12:05:42 +0630 Subject: [PATCH 02/25] dashboard sale revenue --- app/views/home/dashboard.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 6cd52f4e..b7bd5c44 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -189,7 +189,7 @@ <%= @summ_sale.total_receipt %> - <% revenue = @summ_sale.total_amount - @summ_sale.total_discount%> + <% revenue = @summ_sale.grand_total - @summ_sale.total_discount - @summ_sale.total_tax %> <%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : <%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %> From 51932b8a86ca5084a303a9e772463b0d8548d951 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 1 Jun 2020 15:46:27 +0630 Subject: [PATCH 03/25] other payments --- app/assets/javascripts/origami.js | 4 +- .../origami/others_payments_controller.rb | 85 +++ .../origami/payments_controller.rb | 279 ++++------ app/models/sale_payment.rb | 22 +- .../others_payments/create.json.jbuilder | 5 + .../origami/others_payments/index.html.erb | 4 +- .../origami/others_payments/new.html.erb | 279 ++++++++++ app/views/origami/payments/show.html.erb | 498 ++++++------------ config/initializers/action_controller.rb | 10 +- config/routes.rb | 52 +- 10 files changed, 665 insertions(+), 573 deletions(-) create mode 100644 app/views/origami/others_payments/create.json.jbuilder create mode 100644 app/views/origami/others_payments/new.html.erb diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 8c910119..d282b611 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -326,8 +326,8 @@ 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(); - var com_port = $("#com_port_name").val(); - reqCardSaleTrans(cmd_type, payment_type, bnk_bill_amount, sale_id, receipt_no, com_port,cashier_type); + var com_port = $("#com_port_name").val(); + 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/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb index 3d95bbb0..964af260 100755 --- a/app/controllers/origami/others_payments_controller.rb +++ b/app/controllers/origami/others_payments_controller.rb @@ -39,7 +39,92 @@ class Origami::OthersPaymentsController < BaseOrigamiController # end end + def new + @sale_id = params[:sale_id] + @cashier_type = params[:type] + payment_methods = PaymentMethodSetting.pluck(:payment_method) + if @payment_method = payment_methods.find { |m| m.parameterize == params[:method] } + path = request.fullpath + # limit master_amount + if path.include? ("credit_payment") + sale_data = Sale.get_sale_data_for_other_payment_credit(@sale_id) + else + sale_data = Sale.find_by_sale_id(@sale_id) + end + total = 0 + @shop = Shop.current_shop + @paid_amount = 0 + @can_paid = 0 + @rounding_adj = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + + @rounding_adj = new_total-sale_data.grand_total + + if path.include? ("credit_payment") + sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data) + else + sale_payment_data = sale_data.sale_payments + end + + sale_payment_data.each do |sale_payment| + if sale_payment.payment_method == @payment_method.parameterize + @paid_amount = @paid_amount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_paid = total - @paid_amount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no + end + bank_integration = Lookup.collection_of('bank_integration') + @bank_integration = 0 + if !bank_integration[0].nil? + @bank_integration = bank_integration[0][1] + end + else + if path.include? ("credit_payment") + redirect_to "sale/#{@sale_id}/#{@cashier_type}/payment/others_payment" + else + redirect_to "sale/#{@sale_id}/#{@cashier_type}/credit_payment/others_payment" + end + end + end + def create + cash = params[:amount] + sale_id = params[:sale_id] + ref_no = params[:ref_no] + payment_method = params[:method] + if PaymentMethodSetting.pluck(:payment_method).map(&:parameterize).include? payment_method + if saleObj = Sale.find(sale_id) + shop_details = Shop.current_shop + + path = request.fullpath + payment_for = false + if path.include? ("credit_payment") + payment_for = true + end + sale_payment = SalePayment.new + @status, @sale = sale_payment.process_payment(saleObj, current_user, cash, payment_method, ref_no, payment_for) + end + end end end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 8693e6be..e86449ac 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -51,7 +51,8 @@ class Origami::PaymentsController < BaseOrigamiController #TODO :: KBZPAY ( QR ) # On/Off setting ( show or not qr ) # qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD" - kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last + kbz_pay_method = PaymentMethodSetting.where(payment_method: KbzPay::KBZ_PAY, gateway_communication_type: ['api', 'Api'], is_active: true) + .where.not(gateway_url: [nil, ''], auth_token: [nil, ''], merchant_account_id: [nil, '']).last status = false qr = nil @@ -232,15 +233,29 @@ class Origami::PaymentsController < BaseOrigamiController # end def show + @sale = Sale.find(params[:sale_id]) + @shop = Shop.current_shop + @customer = @sale.customer + @customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"]) + @member_discount = MembershipSetting.find_by_discount(1) + + if dining_facility = @sale.booking.dining_facility + @table_no = dining_facility.type + ' ' + dining_facility.name + @checkin_time = @sale.booking.checkin_at + @dining = dining_facility + end + display_type = Lookup.find_by_lookup_type("display_type") - if !display_type.nil? && display_type.value.to_i ==2 + if !display_type.nil? && display_type.value.to_i ==2 @display_type = display_type.value else @display_type = nil - end + end + path = request.fullpath - sale_id = params[:sale_id] + @trans_flag = true + if params[:type] == "transaction" @trans_flag = false @cashier_type = "cashier" @@ -248,201 +263,111 @@ class Origami::PaymentsController < BaseOrigamiController @cashier_type = params[:type] end - if path.include? ("credit_payment") - @sale_payment = SalePayment.where(sale_id: sale_id, payment_method: 'creditnote').select("SUM(payment_amount) as payment_amount") + if path.include? 'credit_payment' + @sale_payment = false + @amount_due = @sale.sale_payments.where(payment_method: 'creditnote').pluck('SUM(payment_amount)').first + payments = @sale.sale_payments.joins(:sale_audit).group_by(&:payment_method).map { |method, payments| [method, payments.sum { |payment| payment.payment_amount }] } + else + @sale_payment = true + @amount_due = @sale.grand_total + payments = @sale.sale_payments.left_joins(:sale_audit).where(sale_audits: {sale_audit_id: nil}).group_by(&:payment_method).map { |method, payments| [method, payments.sum { |payment| payment.payment_amount }] } end - @member_discount = MembershipSetting.find_by_discount(1) - @membership_rebate_balance=0 + @payment_methods = PaymentMethodSetting.where(is_active: true).pluck(:payment_method) + @cash = payments.inject(0) { |sum, payment| sum + payment[1] if payment[0] == 'cash' } + @credit = payments.inject(0) { |sum, payment| sum + payment[1] if payment[0] == 'creditnote' } + @other_payments = payments.select { |payment| !['cash', 'creditnote'].include? payment[0] }.map { |method, amount| [ @payment_methods.find { |payment_method| payment_method.parameterize == method }, amount ] } + @other_payment = @other_payments.sum { |payment| payment[1] } - if Sale.exists?(sale_id) - @cash = 0.0 - @kbz_pay_amount = 0.0 - @other = 0.0 - @ppamount = 0.0 - @visacount= 0.0 - @jcbcount= 0.0 - @mastercount = 0.0 - @unionpaycount = 0.0 - @alipaycount = 0.0 - @junctionpaycount = 0.0 - @credit = 0.0 - @paymalcount = 0.0 - @dingacount = 0.0 - @giftvouchercount = 0.0 - @sale_data = Sale.find_by_sale_id(sale_id) - @balance = 0 - @accountable_type = '' - @table_no = '' - @dining = '' - @other_payment = 0.0 - @pdf_view = nil - @lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView") - if !@lookup_pdf.nil? - @pdf_view = @lookup_pdf.value - end + #total customer with individual total amount + @individual_total = Array.new + if !@sale.equal_persons.nil? + per_person_amount = @sale.grand_total / @sale.equal_persons.to_i + @individual_total.push({'total_customer' => @sale.equal_persons.to_i, 'per_person_amount' => per_person_amount }) + end - amount = SalePayment.get_kbz_pay_amount(sale_id, current_user) - @kbz_pay_amount += amount.to_f - - #for changable on/off - @changable_tax = true - lookup_changable_tax = Lookup.collection_of('changable_tax') - if !lookup_changable_tax.empty? - lookup_changable_tax.each do |changable_tax| - if changable_tax[0].downcase == "change" - if changable_tax[1] == '0' - @changable_tax = false - end + #for changable on/off + @changable_tax = true + lookup_changable_tax = Lookup.collection_of('changable_tax') + if !lookup_changable_tax.empty? + lookup_changable_tax.each do |changable_tax| + if changable_tax[0].downcase == "change" + if changable_tax[1] == '0' + @changable_tax = false end end end + end - @shop = shop_detail #show shop info + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() - @customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"]) + @pdf_view = nil + @lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView") + if !@lookup_pdf.nil? + @pdf_view = @lookup_pdf.value + end - saleObj = Sale.find(sale_id) + # amount = SalePayment.get_kbz_pay_amount(sale_id, current_user) + # @kbz_pay_amount += amount.to_f - #total customer with individual total amount - @individual_total = Array.new - if !saleObj.equal_persons.nil? - per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i - @individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f }) + # rounding adjustment + # if @shop.is_rounding_adj + # a = saleObj.grand_total % 25 # Modulus + # b = saleObj.grand_total / 25 # Division + # #not calculate rounding if modulus is 0 and division is even + # #calculate rounding if modulus is zero or not zero and division are not even + # if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + # @rounding_adj = new_total-saleObj.grand_total + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj) + # @sale_data.grand_total = new_total + # @sale_data.old_grand_total = saleObj.grand_total + # @sale_data.rounding_adjustment = @rounding_adj + # else + # @rounding_adj = @sale_data.rounding_adjustment + # end + # else + # @rounding_adj = @sale_data.rounding_adjustment + # end + #end rounding adjustment + + # accounts = @customer.tax_profiles + accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") + @account_arr =[] + @tax_arr =[] + + accounts.each do |acc| + account = TaxProfile.find(acc.id) + # @account_arr.push(account) + @tax_arr.push(account.name) + end + + sale_taxes = @sale.sale_taxes + if !sale_taxes.empty? + sale_taxes.each do |sale_tax| + @account_arr.push(sale_tax) end + end - # rounding adjustment - # if @shop.is_rounding_adj - # a = saleObj.grand_total % 25 # Modulus - # b = saleObj.grand_total / 25 # Division - # #not calculate rounding if modulus is 0 and division is even - # #calculate rounding if modulus is zero or not zero and division are not even - # if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) - # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) - # @rounding_adj = new_total-saleObj.grand_total - # else - # @rounding_adj = @sale_data.rounding_adjustment - # end - # else - # @rounding_adj = @sale_data.rounding_adjustment - # end - #end rounding adjustment + rebate = MembershipSetting.find_by_rebate(1) - # rounding adjustment - if @shop.is_rounding_adj - a = saleObj.grand_total % 25 # Modulus - b = saleObj.grand_total / 25 # Division - #not calculate rounding if modulus is 0 and division is even - #calculate rounding if modulus is zero or not zero and division are not even - if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) - new_total = Sale.get_rounding_adjustment(saleObj.grand_total) - @rounding_adj = new_total-saleObj.grand_total - saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj) - @sale_data.grand_total = new_total - @sale_data.old_grand_total = saleObj.grand_total - @sale_data.rounding_adjustment = @rounding_adj - else - @rounding_adj = @sale_data.rounding_adjustment - end - else - @rounding_adj = @sale_data.rounding_adjustment - end - #end rounding adjustment - - # get printer info - @print_settings = PrintSetting.get_precision_delimiter() - - #get customer amount - @customer = Customer.find(@sale_data.customer_id) - # accounts = @customer.tax_profiles - accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") - @account_arr =[] - @tax_arr =[] - accounts.each do |acc| - account = TaxProfile.find(acc.id) - # @account_arr.push(account) - @tax_arr.push(account.name) - end - sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id) - if !sale_taxes.empty? - sale_taxes.each do |sale_tax| - @account_arr.push(sale_tax) - end - end - rebate = MembershipSetting.find_by_rebate(1) - # get member information - if @customer.membership_id != nil && rebate - response = Customer.get_member_account(@customer) - if response["status"]==true - response["account_data"].each do |res| + # get member information + @balance = 0 + @accountable_type = '' + if @customer.membership_id != nil && rebate + response = Customer.get_member_account(@customer) + if response["status"]==true + response["account_data"].each do |res| if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" @balance = @balance.to_f + res["balance"].to_f # @accountable_type = res["accountable_type"] @accountable_type = "Rebate Balance" end end - end - end - - #end customer amount - - #paymal payment - - @sale_data.bookings.each do |sbk| - if sbk.dining_facility_id.to_i >0 - df = DiningFacility.find(sbk.dining_facility_id) - @table_no = df.type + ' ' + df.name - @checkin_time = sbk.checkin_at - @dining = df - break - else - @table_no = nil - @checkin_time = nil - @dining = nil - end - end - - if path.include? ("credit_payment") - @sale_payment_data = SalePayment.get_sale_payment_for_credit(@sale_data) - else - @sale_payment_data = SalePayment.get_sale_payments(@sale_data) - end - @sale_payment_data.each do |spay| - if spay.payment_method == "cash" - @cash += spay.payment_amount - end - if spay.payment_method !="creditnote" - @other_payment += spay.payment_amount - end - - if spay.payment_method == "mpu" - @other += spay.payment_amount - elsif spay.payment_method == "paypar" - @ppamount += spay.payment_amount - elsif spay.payment_method == "visa" - @visacount += spay.payment_amount - elsif spay.payment_method == "jcb" - @jcbcount += spay.payment_amount - elsif spay.payment_method == "master" - @mastercount += spay.payment_amount - elsif spay.payment_method == "unionpay" - @unionpaycount += spay.payment_amount - elsif spay.payment_method == "JunctionPay" - @junctionpaycount += spay.payment_amount - elsif spay.payment_method == "creditnote" - @credit += spay.payment_amount - elsif spay.payment_method == "paymal" - @paymalcount += spay.payment_amount - elsif spay.payment_method == "alipay" - @alipaycount += spay.payment_amount - elsif spay.payment_method == "dinga" - @dingacount += spay.payment_amount - elsif spay.payment_method == "giftvoucher" - @giftvouchercount += spay.payment_amount - end - end end + #end customer amount end def reprint diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index ee89704a..70812e11 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -36,7 +36,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' @@ -81,7 +82,7 @@ class SalePayment < ApplicationRecord amount_due = invoice.sale_payments .map(&:payment_amount).reduce(invoice.grand_total, :-) end - + if amount_due > 0 payment_status = false membership_data = nil @@ -121,10 +122,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 @@ -623,17 +622,6 @@ 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 diff --git a/app/views/origami/others_payments/create.json.jbuilder b/app/views/origami/others_payments/create.json.jbuilder new file mode 100644 index 00000000..9767a7d8 --- /dev/null +++ b/app/views/origami/others_payments/create.json.jbuilder @@ -0,0 +1,5 @@ +if(@status) + json.status @status +else + json.status false +end diff --git a/app/views/origami/others_payments/index.html.erb b/app/views/origami/others_payments/index.html.erb index 8bbc9747..d9ea86bc 100755 --- a/app/views/origami/others_payments/index.html.erb +++ b/app/views/origami/others_payments/index.html.erb @@ -19,7 +19,7 @@
<% end %>
-
<%= payment_method.payment_method %>
+
<%= payment_method.payment_method %>
<% end %> @@ -45,7 +45,7 @@ payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment"); if(payment_type) { $(".others-payment").hide(); - $(payment_type).each(function(i){ + $(payment_type).each(function(i){ $("."+payment_type[i]).show(); }); } diff --git a/app/views/origami/others_payments/new.html.erb b/app/views/origami/others_payments/new.html.erb new file mode 100644 index 00000000..8962ceb6 --- /dev/null +++ b/app/views/origami/others_payments/new.html.erb @@ -0,0 +1,279 @@ +
+ + +
+
+ + + +
+
+
+ <% if @bank_integration == '1' %> +
+
+ + +
+
+
+ <% end %> +
+
+ + <%@can_paid = @can_paid + @rounding_adj%> + +
+
+
+ <% if @paid_amount != 0 %> +
+
+ + +
+
+
+ <% end %> +
+
+ + +
+
+
+
+
+
+ +
0.0
+
+
+
+
+
+
+
+ +
+
+
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
+
1000
+
3000
+
+
+
5000
+
10000
+
+
+
Pay
+
+
+
+
+
+ +
+ + +
+ + +
+
+ diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 4f5d387a..6ed4044e 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -9,24 +9,24 @@
-
Receipt No : <%=@sale_data.receipt_no rescue ' '%>
-
Receipt Date : <%=@sale_data.receipt_date.utc.getlocal.strftime("%d/%m/%Y-%I:%M %p") rescue '-' %>
+
Receipt No : <%=@sale.receipt_no rescue ' '%>
+
Receipt Date : <%=@sale.receipt_date.utc.getlocal.strftime("%d/%m/%Y-%I:%M %p") rescue '-' %>
Table No : <%=@table_no%>
-
Sale ID : <% if @sale_data %><%=@sale_data.sale_id %><% end %>
+
Sale ID : <% if @sale %><%=@sale.sale_id %><% end %>
Customer : <% if @cashier_type == 'quick_service' || @cashier_type == 'food_court' %> - + <% else %> - <%= @sale_data.customer.name%> + <%= @sale.customer.name%> <% end %> - +
Checkin Time : <%if !@checkin_time.nil?%><%= @checkin_time.utc.getlocal.strftime("%I:%M %p") %> <%end%>
@@ -57,7 +57,7 @@ <% sub_total = 0 count = 0 %> - <% @sale_data.sale_items.each do |sale_item| + <% @sale.sale_items.each do |sale_item| count += 1 %> @@ -82,12 +82,12 @@ <%=number_format(sub_total, precision: precision.to_i)%> - <%if @sale_data.discount_type == 'member_discount'%> + <%if @sale.discount_type == 'member_discount'%> Member Discount: <%else%> (Discount) <%end%> - (<%= number_format(@sale_data.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>) + (<%= number_format(@sale.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>) @@ -104,23 +104,23 @@ <% else %> No Tax <% end %>
- <%if @sale_payment.nil? && @changable_tax %> + <%if @sale_payment && @changable_tax %> <% if @current_user.role == 'cashier' %> - + <% else %> <% end %> <% end %> - <%= number_format(@sale_data.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> + <%= number_format(@sale.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> Rounding Adj: - <%= number_format(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> + <%= number_format(@sale.rounding_adjustment, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> Grand Total - <%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> + <%= number_format(@sale.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> <%if @balance > 0%> @@ -156,22 +156,14 @@
-
Amount Due <% if !@sale_payment.nil? %>( Credit )<% end %>
+
Amount Due <% if !@sale_payment %>( Credit )<% end %>
- <% if @sale_payment.nil? %> - <%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %> - <% else %> - <%= number_format(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i)%> - <% end %> + <%= number_format(@amount_due, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i)%>
@@ -183,7 +175,7 @@ <%= number_format(@cash, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% if @sale_payment.nil? && @cashier_type != "food_court" %> + <% if @sale_payment && @cashier_type != "food_court" %>
Credit
<%= number_format(@credit, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
@@ -191,155 +183,25 @@ <% else %> <% end %> - <% if @kbz_pay_amount > 0.0 %> -
-
Other Payments (KBZ Pay)
-
- <%= number_format(@kbz_pay_amount, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %> +
+
Other Payments
+
+ <%= number_format(@other_payment, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
- <% elsif @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0 && @unionpaycount == 0.0 && @alipaycount == 0.0 && @paymalcount == 0.0 && @junctionpaycount == 0.0 && @dingacount == 0.0 && @giftvouchercount == 0.0 %> -
-
Other Payments
-
- <%= number_format(@other, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %> -
-
- <% else %> -
-
Other Payments
-
- <%= number_format(@other_payment, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %> -
-
- <% end %>
-
- -
-
-
MPU
- <% if @other != 0.0 %> -
<%= number_format(@other, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
Redeem
- <% if @ppamount != 0.0 %> -
<%= number_format(@ppamount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
VISA
- <% if @visacount != 0.0 %> -
<%= number_format(@visacount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
JCB
- <% if @jcbcount != 0.0 %> -
<%= number_format(@jcbcount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
MASTER
- <% if @mastercount != 0.0 %> -
<%= number_format(@mastercount, precision: precision.to_i) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - - -
-
-
UNIONPAY
- <% if @unionpaycount != 0.0 %> -
<%= number_format(@unionpaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
Alipay
- <% if @alipaycount != 0.0 %> -
<%= number_format(@alipaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
PAYMAL
- <% if @paymalcount != 0.0 %> -
<%= number_format(@paymalcount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- -
-
-
DINGA
- <% if @dingacount != 0.0 %> -
<%= number_format(@dingacount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
JUNCTION PAY
- <% if @junctionpaycount != 0.0 %> -
<%= number_format(@junctionpaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> -
- - -
-
-
GIFT VOUCHER
- <% if @giftvouchercount != 0.0 %> -
<%= number_format(@giftvouchercount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
- <% else %> -
<%= number_format(0, precision: precision.to_i ) %>
- <% end %> +
+ <% @other_payments.each do |payment| %> +
+
<%= payment[0] %>
+
<%= number_format(payment[1], precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
+ <% end %>
Balance
-
<%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
+
<%= number_format(@sale.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
@@ -404,30 +266,30 @@ <% if current_login_employee.role == "cashier" %> - <% if @other_payment <= 0 && @sale_payment.nil? %> - <%if @sale_data.total_discount == 0 %> + <% if @other_payment <= 0 && @sale_payment %> + <%if @sale.total_discount == 0 %> FOC <% end %> <%end %> - <% if @sale_payment.nil? %> + <% if @sale_payment %> Void <% if @other_payment <= 0 %> - <%if @sale_data.total_discount == 0 %> + <%if @sale.total_discount == 0 %> Waste Spoile <% end %> <% end %> <% end %> <% else %> - <% if @other_payment <= 0 && @sale_payment.nil?%> - <%if @sale_data.total_discount == 0 %> + <% if @other_payment <= 0 && @sale_payment%> + <%if @sale.total_discount == 0 %> <% end %> @@ -435,7 +297,7 @@ <% end %> <% end %> -<% if (@cashier_type=="quick_service" || @cashier_type=="food_court") && @sale_payment.nil? %> +<% if (@cashier_type=="quick_service" || @cashier_type=="food_court") && @sale_payment %>
@@ -709,10 +571,14 @@ var customer_id = "<%= @customer.id %>"; var customer_name = "<%= @customer.name %>"; var pdf_view = '<%=@pdf_view%>'; var trans_flag = <%= @trans_flag %>; -var paymalcount = <%= @paymalcount %>; +var other_payments = <%= raw @other_payments %>; +var payment_methods = <%= raw @payment_methods %>; + // console.log(pdf_view) $(document).ready(function(){ $("#sxModal").hide(); + + var paymalcount = other_payments.some(x => x[0] == 'paymal') ? other_payments.find(x => x[0] == 'paymal')[1] : 0.0; if(cashier_type == "food_court" && paymalcount == 0.0){ $("#is_paymemberModal").modal({show : true, backdrop : false, keyboard : false}); } @@ -726,45 +592,35 @@ $(document).ready(function(){ } /* replace url type*/ /* start check first bill or not*/ - var member_id = $('#membership_id').text(); - var member_discount = $('#member_discount').text(); - var receipt_no = ""; - if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ - receipt_no = ($("#receipt_no").html()).trim(); - } + var member_id = $('#membership_id').text(); + var member_discount = $('#member_discount').text(); + var receipt_no = ""; + if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ + receipt_no = ($("#receipt_no").html()).trim(); + } - payment_type = ''; + // if ($("#server_mode").val() != "cloud") { // first bill not used in cloud + payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment"); + other_payment = payment_methods.find(x => payment_type.indexOf(x) >= 0) + // console.log(payment_type) + // console.log(parseInt(jQuery.inArray("MPU", payment_type))) + if (member_id && member_discount) { + if(parseInt(jQuery.inArray("Credit", payment_type)) == -1){ + $("#credit_payment").hide(); + } else{ + $("#credit_payment").show(); + } - // if ($("#server_mode").val() != "cloud") { // first bill not used in cloud - payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment"); - // console.log(payment_type) - // console.log(parseInt(jQuery.inArray("MPU", payment_type))) - if (member_id && member_discount) { - if(parseInt(jQuery.inArray("Credit", payment_type)) == -1){ - $("#credit_payment").hide(); - } else{ - $("#credit_payment").show(); - } - if(parseInt(jQuery.inArray("MPU", payment_type)) != -1 || - parseInt(jQuery.inArray("VISA", payment_type)) != -1 || - parseInt(jQuery.inArray("JCB", payment_type)) != -1 || - parseInt(jQuery.inArray("Master", payment_type)) != -1 || - parseInt(jQuery.inArray("UNIONPAY", payment_type)) != -1 || - parseInt(jQuery.inArray("Redeem", payment_type)) != -1 || - parseInt(jQuery.inArray("PAYMAL", payment_type)) != -1 || - parseInt(jQuery.inArray("JUNCTIONPAY", payment_type)) != -1 || - parseInt(jQuery.inArray("Alipay", payment_type)) != -1 || - parseInt(jQuery.inArray("DINGA", payment_type)) != -1 || - parseInt(jQuery.inArray("GiftVoucher", payment_type)) != -1){ - $("#card_payment").show(); - } else{ - $("#card_payment").hide(); - } - } - // } - /* end check first bill or not*/ + if(other_payment){ + $("#card_payment").show(); + } else{ + $("#card_payment").hide(); + } + } + // } + /* end check first bill or not*/ - var dining_id = "<%= @sale_data.bookings[0].dining_facility_id %>"; + var dining_id = "<%= @sale.bookings[0].dining_facility_id %>"; $("#back").on('click', function() { localStorage.removeItem('cash'); @@ -787,12 +643,10 @@ $(document).ready(function(){ window.location.reload(); }) - if(localStorage.getItem("cash") == null || localStorage.getItem("cash") == 'null'){ - - } - else { + if (localStorage.getItem("cash") && localStorage.getItem("cash") != 'null') { $('#cash').text(localStorage.getItem("cash")); } + update_balance(); //checkChangableTax checkChangableTax(); @@ -827,125 +681,96 @@ $(document).ready(function(){ sub_total = $('#sub-total').text(); member = $('#membership_id').text(); // console.log(member) - if (parseInt(jQuery.inArray("MPU", payment_type)) != -1 && $('.mpu').text() == 0 && sub_total != 0.0 && member) { - swal("Oops","Please Pay with MPU Payment","warning"); - }else if(parseInt(jQuery.inArray("Redeem", payment_type)) != -1 && $('#ppamount').text()==0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Redeem Payment","warning"); - }else if(parseInt(jQuery.inArray("VISA", payment_type)) != -1 && $('#visacount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Visa Payment","warning"); - - }else if(parseInt(jQuery.inArray("JCB", payment_type)) != -1 && $('#jcbcount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with jcb Payment","warning"); - } - else if(parseInt(jQuery.inArray("Master", payment_type)) != -1 && $('#mastercount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Master Payment","warning"); - } - else if(payment_type == "UNIONPAY" && $('#unionpaycount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with UNIONPAY Payment","warning"); - } - else if(parseInt(jQuery.inArray("Alipay", payment_type)) != -1 && $('#alipaycount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Alipay Payment","warning"); - } - else if(parseInt(jQuery.inArray("JUNCTIONPAY", payment_type)) != -1 && $('#junctionpaycount').text()==0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with JUNCTIONPAY Payment","warning"); - } - else if(payment_type == "Credit" && $('#credit').text()==0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Credit Payment","warning"); - }else if(parseInt(jQuery.inArray("PAYMAL", payment_type)) != -1 && $('#paymalcount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Paymal Payment","warning"); - }else if(parseInt(jQuery.inArray("DINGA", payment_type)) != -1 && $('#dingacount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Dinga Payment","warning"); - }else if(parseInt(jQuery.inArray("GiftVoucher", payment_type)) != -1 && $('#giftvouchercount').text()== 0 && sub_total != 0.0 && member){ - swal("Oops","Please Pay with Gift Voucher","warning"); + if (other_payment && !other_payments.some(x => x[0] == other_payment && x[1] > 0 ) && sub_total != 0.0 && member) { + swal("Oops","Please Pay with " + other_payment + " Payment","warning"); + } else { + $( "#loading_wrapper").show(); + if($('#balance').text() > 0){ + swal ( "Oops", "Insufficient Amount!" , "error" ); + $("#loading_wrapper").hide(); }else{ + $(this).off("click"); + var sale_id = $('#sale_id').text(); + // var item_row = $('.is_card'); - $( "#loading_wrapper").show(); - if($('#balance').text() > 0){ - swal ( "Oops", "Insufficient Amount!" , "error" ); - $("#loading_wrapper").hide(); - }else{ - $(this).off("click"); - var sale_id = $('#sale_id').text(); - // var item_row = $('.is_card'); + // payment + var cash = $('#cash').text(); + var credit = $('#credit').text(); + var card = $('#card').text(); + var kbz_amt = "<%= @kbz_pay_amount %>"; + var is_kbz = false; + if (kbz_amt > 0) { + is_kbz = true + } - // payment - var cash = $('#cash').text(); - var credit = $('#credit').text(); - var card = $('#card').text(); - var kbz_amt = "<%= @kbz_pay_amount %>"; - var is_kbz = false; - if (kbz_amt > 0) { - is_kbz = true - } + var tax_type = localStorage.getItem("tax_type") ? localStorage.getItem("tax_type") : 'all'; + if (credit <= 0 && (!location.pathname.includes("credit_payment"))) { + calculate_member_discount(sale_id,tax_type); + } - var tax_type = localStorage.getItem("tax_type") ? localStorage.getItem("tax_type") : 'all'; - if (credit <= 0 && (!location.pathname.includes("credit_payment"))) { - calculate_member_discount(sale_id,tax_type); - } + // $("#pdfModal").on('shown.bs.modal', function () { + // $('#pdfModal').focus() }).modal({show : true, backdrop : false, keyboard : false}); + /* check credit payment or not*/ + if(location.pathname.includes("credit_payment")){ + var url = "<%= origami_credit_payment_cash_path %>"; + }else{ + var url = "<%= origami_payment_cash_path %>"; + } - // $("#pdfModal").on('shown.bs.modal', function () { - // $('#pdfModal').focus() }).modal({show : true, backdrop : false, keyboard : false}); - /* check credit payment or not*/ - if(location.pathname.includes("credit_payment")){ - var url = "<%= origami_credit_payment_cash_path %>"; - }else{ - var url = "<%= origami_payment_cash_path %>"; - } + $.ajax({type: "POST", + url: url, + data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type + "&tax_type=" + tax_type + "&is_kbz=" + is_kbz, + success:function(result){ + /* start delete receipt no in first bill*/ + if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ + var receipt_no = ($("#receipt_no").html()).trim(); + deleteReceiptNoInFirstBillData(receipt_no); + } + /* end delete receipt no in first bill*/ - $.ajax({type: "POST", - url: url, - data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type + "&tax_type=" + tax_type + "&is_kbz=" + is_kbz, - success:function(result){ - /* start delete receipt no in first bill*/ - if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ - var receipt_no = ($("#receipt_no").html()).trim(); - deleteReceiptNoInFirstBillData(receipt_no); - } - /* end delete receipt no in first bill*/ + localStorage.removeItem("cash"); + if (result.status) { + var msg = result.message; + } + else{ + var msg = ''; + } - localStorage.removeItem("cash"); - if (result.status) { - var msg = result.message; - } - else{ - var msg = ''; + $("#loading_wrapper" ).hide(); + if(location.pathname.includes("credit_payment")){ + payment_success_alert(); + }else{ + //PDF lightbox data + var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6); + $("#sale_receipt_no").val(result.receipt_no); + $("#filename").val(result.filename); + $("#printer_name").val(result.printer_name); + $("#receipt_pdf").attr("src", pdfPath); + $("#changed_amount").text(""); + if($('#balance').text() < 0){ + <% if precision.to_i > 0 %> + $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>)); + <% else %> + $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1))); + <% end %> } - $("#loading_wrapper" ).hide(); - if(location.pathname.includes("credit_payment")){ - payment_success_alert(); + if (pdf_view == 1) { + $("#pdfModal").modal({show : true, backdrop : false, keyboard : false}); + $("#pdfModalLabel").text("Sale Completed"); }else{ //PDF lightbox data - var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6); - $("#sale_receipt_no").val(result.receipt_no); - $("#filename").val(result.filename); - $("#printer_name").val(result.printer_name); - $("#receipt_pdf").attr("src", pdfPath); - $("#changed_amount").text(""); - if($('#balance').text() < 0){ - <% if precision.to_i > 0 %> - $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>)); - <% else %> - $("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1))); - <% end %> - } - - if (pdf_view == 1) { - $("#pdfModal").modal({show : true, backdrop : false, keyboard : false}); - $("#pdfModalLabel").text("Sale Completed"); - }else{ - //PDF lightbox data - print_receipt(); - } + print_receipt(); } } - }); - } - } - var second_display_lookup = $("#display_type").val(); - if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){ - customer_display_view(null,"reload"); + } + }); } + } + var second_display_lookup = $("#display_type").val(); + if ($('#server_mode').val() != "cloud" && second_display_lookup == 2){ + customer_display_view(null,"reload"); + } }); function customer_display_view(data,status) { @@ -1098,18 +923,8 @@ $(document).ready(function(){ break; case 'nett': var credit1 = $('#credit').text(); - var card1 = $('#others').text(); - var paypar1 = $('#ppamount').text(); - var visa1 = $('#visacount').text(); - var jcb1 = $('#jcbcount').text(); - var master1 = $('#mastercount').text(); - var unionpay1 = $('#unionpaycount').text(); - var paymal1 = $('#paymalcount').text(); - var alipay1 = $('#alipaycount').text(); - var junctionpay1 = $('#junctionpaycount').text(); - var dingapay1 = $('#dingacount').text(); - var giftvoucherpay1 = $('#giftvouchercount').text(); - var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1) + parseFloat(alipay1) + parseFloat(junctionpay1) + parseFloat(paymal1) + parseFloat(dingapay1) + parseFloat(giftvoucherpay1); + var others = other_payments.map(x => x[1]).reduce((acc, v) => acc + v, 0); + var othertotal = parseFloat(credit1) + parseFloat(others); var total = $('#amount_due').text(); var amt = 0; <% if precision.to_i > 0 %>; @@ -1131,19 +946,10 @@ $(document).ready(function(){ function update_balance(){ var cash = $('#cash').text(); var credit = $('#credit').text(); - var card = $('#others').text(); - var paypar = $('#ppamount').text(); - var visa = $('#visacount').text(); - var jcb = $('#jcbcount').text(); - var master = $('#mastercount').text(); - var unionpay = $('#unionpaycount').text(); - var paymal = $('#paymalcount').text(); - var alipay = $('#alipaycount').text(); - var junctionpay = $('#junctionpaycount').text(); - var dinga = $('#dingacount').text(); - var giftvoucher = $('#giftvouchercount').text(); + var others = other_payments.map(x => x[1]).reduce((acc, v) => acc + v, 0); + var amount_due = $('#amount_due').text(); - var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay) + parseFloat(alipay) + parseFloat(junctionpay) + parseFloat(paymal) + parseFloat(dinga) + parseFloat(giftvoucher); + var total = parseFloat(cash) + parseFloat(credit) + parseFloat(others); var result = parseFloat(amount_due) - parseFloat(total); diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index eb7ba401..2cf70a1b 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -20,11 +20,11 @@ class ActionController::Base end else # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end diff --git a/config/routes.rb b/config/routes.rb index 933002d9..974a00d4 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -244,23 +244,25 @@ scope "(:locale)", locale: /en|mm/ do post 'payment/dinga' => 'dinga#create' post 'payment/gift_voucher' => 'gift_voucher#create' post 'payment/credit_payment' => 'credit_payments#create_credit_payment' + post 'payment/:method' => 'others_payments#create', :as => 'payment' post 'payment/:type/change_tax' => 'payments#change_tax', :defaults => {:format => 'json'} get 'sale/:sale_id/:type/payment/credit_payment' => "credit_payments#index" get 'sale/:sale_id/:type/payment/others_payment' => "others_payments#index" - get 'sale/:sale_id/:type/payment/others_payment/MPU' => "mpu#index" - get 'sale/:sale_id/:type/payment/others_payment/VISA' => "visa#index" - get 'sale/:sale_id/:type/payment/others_payment/Master' => "master#index" - get 'sale/:sale_id/:type/payment/others_payment/JCB' => "jcb#index" - get 'sale/:sale_id/:type/payment/others_payment/PAYMAL' => "paymal#index" - get 'sale/:sale_id/:type/payment/others_payment/UNIONPAY' => "unionpay#index" - get 'sale/:sale_id/:type/payment/others_payment/Redeem' => "redeem_payments#index" - get 'sale/:sale_id/:type/payment/others_payment/Voucher' => "voucher#index" - get 'sale/:sale_id/:type/payment/others_payment/JunctionPay' => "junction_pay#index" - get 'sale/:sale_id/:type/payment/others_payment/Alipay' => "alipay#index" - get 'sale/:sale_id/:type/payment/others_payment/DINGA' => "dinga#index" - get 'sale/:sale_id/:type/payment/others_payment/GiftVoucher' => "gift_voucher#index" + get 'sale/:sale_id/:type/payment/others_payment/mpu' => "mpu#index" + get 'sale/:sale_id/:type/payment/others_payment/visa' => "visa#index" + get 'sale/:sale_id/:type/payment/others_payment/master' => "master#index" + get 'sale/:sale_id/:type/payment/others_payment/jcb' => "jcb#index" + get 'sale/:sale_id/:type/payment/others_payment/paymal' => "paymal#index" + get 'sale/:sale_id/:type/payment/others_payment/unionpay' => "unionpay#index" + get 'sale/:sale_id/:type/payment/others_payment/redeem' => "redeem_payments#index" + get 'sale/:sale_id/:type/payment/others_payment/voucher' => "voucher#index" + get 'sale/:sale_id/:type/payment/others_payment/junctionpay' => "junction_pay#index" + get 'sale/:sale_id/:type/payment/others_payment/alipay' => "alipay#index" + get 'sale/:sale_id/:type/payment/others_payment/dinga' => "dinga#index" + get 'sale/:sale_id/:type/payment/others_payment/giftvoucher' => "gift_voucher#index" + get 'sale/:sale_id/:type/payment/others_payment/:method' => 'others_payments#new' #---------Void --------------# post 'sale/:sale_id/:type/void' => 'void#overall_void' @@ -351,20 +353,22 @@ scope "(:locale)", locale: /en|mm/ do # post 'credit_payment/junctionpay' => 'junction_pay#create' # post 'credit_payment/dinga' => 'dinga#create' # post 'credit_payment/gift_voucher' => 'gift_voucher#create' + post 'credit_payment/:method' => 'others_payments#create', :as => 'credit_payment' get 'sale/:sale_id/:type/credit_payment/others_payment' => "others_payments#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/MPU' => "mpu#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/VISA' => "visa#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/Master' => "master#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/JCB' => "jcb#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/PAYMAL' => "paymal#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/UNIONPAY' => "unionpay#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/Redeem' => "redeem_payments#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/Voucher' => "voucher#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/JunctionPay' => "junction_pay#index" - get 'sale/:sale_id/:type/credit_payment/others_payment/Alipay' => "alipay#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/DINGA' => "dinga#index" - # get 'sale/:sale_id/:type/credit_payment/others_payment/GiftVoucher' => "gift_voucher#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/mpu' => "mpu#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/visa' => "visa#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/master' => "master#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/jcb' => "jcb#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/paymal' => "paymal#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/unionpay' => "unionpay#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/redeem' => "redeem_payments#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/voucher' => "voucher#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/junctionpay' => "junction_pay#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/alipay' => "alipay#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/dinga' => "dinga#index" + # get 'sale/:sale_id/:type/credit_payment/others_payment/giftvoucher' => "gift_voucher#index" + get 'sale/:sale_id/:type/credit_payment/others_payment/:method' => 'others_payments#new' #------------- Start Reservation -------------------# resources :reservation From da754034379636e1dd0f6784490370e62f5eea49 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Tue, 2 Jun 2020 14:23:08 +0630 Subject: [PATCH 04/25] update license control --- app/models/license.rb | 252 ++++++++++++++--------- config/initializers/action_controller.rb | 126 +++++++----- config/license.yml | 19 ++ 3 files changed, 244 insertions(+), 153 deletions(-) create mode 100644 config/license.yml diff --git a/app/models/license.rb b/app/models/license.rb index 2c550a1e..e1129405 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,12 +1,15 @@ +require 'yaml' + class License include HTTParty + include ActionDispatch::Http - base_uri "connect.smartsales.asia/api" + base_uri "https://l.doemal.app//api" attr_accessor :name, :address_1, :address_2, :township, :city, :country, :email, :phone, :fax, :logo, :subdomain, :plan_activation_date, :plan_next_renewal_date, :plan_max_products,:plan_max_customers, :plan_active_connections, :dbhost, :dbschema, :dbusername, :dbpassword, :exchange_unqiue_id, :localqueue_host,:server_mode,:localhost_address, - :localqueue_user, :localqueue_password, :remotequeue_host, :remotequeue_user, :remotequeue_password, :api_token, :app_token + :localqueue_user, :localqueue_password, :remotequeue_host, :remotequeue_user, :remotequeue_password, :api_token, :app_token, :lookup @license = nil @secret = nil @@ -14,14 +17,17 @@ class License def initialize(server = "", lookup = "") #this code is hard-code to reflect server mode - Very important. self.server_mode = ENV["SERVER_MODE"] - + unless ENV["SERVER_MODE"] == "cloud" + self.server_mode = "application" + end + self.lookup = lookup if (server != "") self.class.base_uri server end 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) @@ -69,65 +75,75 @@ 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(30)? + 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 def license_activate (shop, license_key, db_host, db_schema, db_user, db_password) + aes = MyAesCrypt.new 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"]) - ##Check from local redis - if available load local otherwise get from remote - cache_key = "shop:#{@activate["shop_name"]}" + begin + response = self.class.get("/activate", @params) + @activate = response.parsed_response - cache_license = nil + 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? + Rails.logger.info "Cache key - " + cache_key.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 + # end - Rails.logger.info "License - " + response.parsed_response.to_s + Rails.logger.info "License - " + response.parsed_response.to_s - response = create_license_file(@activate) - 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 @@ -137,16 +153,16 @@ 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"]) + if (!check_expired(@varified["renewable_date"])) + return true end + else + delete_license_file + end rescue SocketError => e Rails.logger.debug "In SocketError No Internet connection ! " @@ -164,12 +180,23 @@ class License return false 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 @@ -188,39 +215,59 @@ class License end end + 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"] + end + # Check License File exists - def self.check_license_file - return File.exist?("config/license.yml") + def self.check_license_file(lookup) + 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 + 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] + end + end + if license[lookup] + File.open("config/license.yml", "w") { |file| file.write license.to_yaml } + end + end + return license[lookup] + end end # read line by key for license file def read_license(key_name) - decrypted_line = "" key, iv = get_redis_key() if File.exist?("config/license.yml") - File.open("config/license.yml").each do |line| - if line.include? (key_name) - decrypted_line_array = line.split(": ") - decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) + 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']) end end end - return decrypted_line end # read line by key for license file without decrypt def read_license_no_decrypt(key) - decrypted_line = "" if File.exist?("config/license.yml") - File.open("config/license.yml").each do |line| - if line.include? (key) - decrypted_line_array = line.split(": ") - decrypted_line = decrypted_line_array[1] + if license = YAML.load_file("config/license.yml") + if license[lookup] + decrypted_line = license[lookup][key] end end end - return decrypted_line end # Update license file for line @@ -231,18 +278,13 @@ class License crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) end - content_str = read_license_no_decrypt(content) if File.exist?("config/license.yml") - file_str = File.read("config/license.yml") - new_file_str = file_str.gsub(content_str, encode_str(crypted_str)) + if license = YAML.load_file("config/license.yml") + license[lookup][content] = encode_str(crypted_str) - # To write changes to the file, use: - File.open("config/license.yml", "w") {|file| file.puts new_file_str } - - # File.open("config/license.yml").each do |line| - # new_file_str = line.gsub(content, crypted_str) - # f.put - # end + # To write changes to the file, use: + File.open("config/license.yml", "w") {|file| file.write(license.to_yaml) } + end end end @@ -284,12 +326,11 @@ class License ##Check from local redis - if available load local otherwise get from remote cache_key = "shop:#{shop.chomp}" - cache_shop = nil - ##Get redis connection from connection pool redis = Redis.new cache_shop = redis.get(cache_key) + puts Marshal.load(cache_shop) if !cache_shop.nil? @shop = Marshal.load(cache_shop) key = @shop["key"] @@ -308,29 +349,38 @@ class License # License File Creation def create_license_file(response_data) - if File.exist?("config/license.yml") - delete_license_file - end - begin # Licese File Creation - File.open("config/license.yml", "w") do |f| - f.puts("iv_key: #{response_data['iv_key']}") - f.puts("shop_name: #{response_data['shop_name']}") - f.puts("email: #{response_data['email']}") - f.puts("telephone: #{response_data['telephone']}") - f.puts("fax: #{response_data['fax']}") - f.puts("address: #{response_data['address']}") - f.puts("dbhost: #{response_data['dbhost']}") - f.puts("dbschema: #{response_data['dbschema']}") - f.puts("dbusername: #{response_data['dbusername']}") - f.puts("dbpassword: #{response_data['dbpassword']}") - f.puts("api_token: #{response_data['api_token']}") - f.puts("app_token: #{response_data['app_token']}") - f.puts("plan_sku: #{response_data['plan_sku']}") - f.puts("renewable_date: #{response_data['renewable_date']}") - f.puts("plan_name: #{response_data['plan_name']}") + config = { "iv_key" => response_data['iv_key'], + "shop_name" => response_data['shop_name'], + "email" => response_data['email'], + "telephone" => response_data['telephone'], + "fax" => response_data['fax'], + "address" => response_data['address'], + "dbhost" => response_data['dbhost'], + "dbschema" => response_data['dbschema'], + "dbusername" => response_data['dbusername'], + "dbpassword" => response_data['dbpassword'], + "api_token" => response_data['api_token'], + "app_token" => response_data['app_token'], + "plan_sku" => response_data['plan_sku'], + "renewable_date" => response_data['renewable_date'], + "plan_name" => response_data['plan_name'] } + + if File.exist?("config/license.yml") + license = YAML.load_file("config/license.yml") end + + if license + license.each do |k,v| + license[k] = config if v["shop_name"] == config["shop_name"] + end + license[lookup] = config + end + + license ||= {lookup => config} + + File.open("config/license.yml", "w"){ |file| file.write(license.to_yaml) } rescue IOError response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} end @@ -387,10 +437,10 @@ class License # f.write("initial.load.use.extract.job.enabled=true\n") f.close rescue IOError - response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} + return { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} end - response = { "status": true, "message": "Success Activation. License also created."} end + { "status": true, "message": "Success Activation. License also created." } end # Run Symmetric diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 2cf70a1b..a9c835b0 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -1,58 +1,65 @@ class ActionController::Base - before_action :lookup_domain, :set_locale + before_action :lookup_domain if Rails.env.production? + before_action :set_locale + + helper_method :current_license, + + def not_found + respond_to do |format| + format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found } + format.json { head :not_found } + end + end private def lookup_domain - if request.subdomain.present? && request.subdomain != "www" - from = request.subdomain.downcase + "." + request.domain.downcase - @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase - if (!@license.nil?) - logger.info "Location - " + @license.dbschema - ActiveRecord::Base.establish_connection(website_connection(@license)) - # authenticate_session_token - # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema + if ENV["SERVER_MODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www" + if license = cache_license # request.subdomain.downcase + logger.info "Location - " + license.dbschema + ActiveRecord::Base.establish_connection(website_connection(license)) else # reconnect_default_db logger.info 'License is nil' - # redirect_to root_url(:host => request.domain) + "store_error" - render :json => [{ status: false, message: 'Invalid Access!'}] + not_found + end + elsif ENV["SERVER_MODE"] == "application" || request.subdomains.last && request.subdomains.last != "www" + # check for license file + if !check_license + if ENV["SERVER_MODE"] == "application" || check_subdomain + redirect_to activate_path + else + not_found + end end else - # check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end - end - - end - - def current_license(url) - @license = License.new(url) - flag = @license.detail_with_local_file() - if (flag == 0) - flash[:notice] = 'Expired or No License!' - elsif (flag == 2) - flash[:notice] = 'Expiring! Please, License extend...' - else - puts "RUN SAY BYAR" + not_found end end - def cache_license(url, lookup) - @license = License.new(url, lookup) + def current_license + @license ||= License.new(ENV["SX_PROVISION_URL"], request.host) + end - if (@license.detail_with_local_cache(lookup) == true) - return @license + def cache_license + if (current_license.detail_with_local_cache == true) + return current_license else return nil end end + def check_subdomain + current_license.check_license_subdomain + end + def check_license - License.check_license_file + if License.check_license_file(request.host) + if current_license.expired? + return false + end + return true + end end def check_installation @@ -64,7 +71,6 @@ class ActionController::Base def website_connection(license) default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, :username => license.dbusername, :password => license.dbpassword) - end def reconnect_default_db @@ -89,42 +95,58 @@ class ActionController::Base end class ActionController::API - before_action :lookup_domain + before_action :lookup_domain if Rails.env.production? + + def not_found + respond_to do |format| + format.html { render :file => "#{Rails.root}/public/404", :layout => false, :status => :not_found } + format.json { head :not_found } + end + end private def lookup_domain - if request.subdomain.present? && request.subdomain != "www" - from = request.subdomain.downcase + "." + request.domain.downcase - @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase - if (!@license.nil?) - logger.info "Location - " + @license.dbschema - ActiveRecord::Base.establish_connection(website_connection(@license)) - # authenticate_session_token - # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema + if ENV["SERVER_CODE"] == "cloud" && request.subdomains.last && request.subdomains.last != "www" + if license = cache_license # request.subdomain.downcase + logger.info "Location - " + license.dbschema + ActiveRecord::Base.establish_connection(website_connection(license)) else # reconnect_default_db logger.info 'License is nil' - # redirect_to root_url(:host => request.domain) + "store_error" - render :json => [{ status: false, message: 'Invalid Access!'}] + not_found end + elsif ENV["SERVER_MODE"] == "application" || (request.subdomains.last && request.subdomains.last != "www") + not_found unless check_license + else + not_found end end - def cache_license(url, lookup) - @license = License.new(url, lookup) + def current_license + @license ||= License.new(ENV["SX_PROVISION_URL"], request.host) + end - if (@license.detail_with_local_cache(lookup) == true) - return @license + def cache_license + if (current_license.detail_with_local_cache == true) + return current_license else return nil end end + def check_license + if License.check_license_file(request.host) + if current_license.expired? + return false + end + return true + end + end + def website_connection(license) default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, :username => license.dbusername, :password => license.dbpassword) - end def reconnect_default_db diff --git a/config/license.yml b/config/license.yml new file mode 100644 index 00000000..f1861562 --- /dev/null +++ b/config/license.yml @@ -0,0 +1,19 @@ +--- +'': &1 + iv_key: cHmsbixLckobLPvChZxYog== + shop_name: inyahappy + email: support@code2lab.com + telephone: '' + fax: '' + address: '' + dbhost: T78U5MC1QxdtmrveA3dT5znI93KRZgEDv1YEAJLOBuYhF9Okg6IFGds7o0P2Jw0qRCVBAo2mL9zvqCmZ9sIYCQ== + dbschema: QwNWv33nV+/PI7mQ5vUwYpu7oLDVwCFv6E3xLchwDLM= + dbusername: xObcAQiPi19xCQbc0z5buQ== + dbpassword: UIscqcoVMXn4A/OfHnSU6A== + api_token: oHYLdtqtAAacxqAhTMfdVxCRyEkyxLzKcYY + app_token: qVYAxcvsklHlTMEBzgznEqdBZBPI + plan_sku: j3tTAFpFkYP3DNCHSinzqA== + renewable_date: fjyqVnVXXEoyvOVf1Ksa1Q== + plan_name: a3TIsOfLtnkDpqP/FCTjyk/viicooUnN4DJasj4jSF4= +192.168.1.125: *1 +192.168.43.132: *1 From bd18958b96e0d9e55bee95c382b911037076635c Mon Sep 17 00:00:00 2001 From: Zin Moe Date: Thu, 4 Jun 2020 10:10:04 +0630 Subject: [PATCH 05/25] license renew page --- Gemfile.lock | 2 - app/controllers/install_controller.rb | 53 +++++++------- app/controllers/renew_license_controller.rb | 17 +++++ app/helpers/application_helper.rb | 4 +- app/models/license.rb | 15 ++-- app/views/layouts/CRM.html.erb | 3 +- app/views/layouts/OQS.html.erb | 1 + app/views/layouts/application.html.erb | 3 +- app/views/layouts/inventory.html.erb | 3 +- app/views/layouts/origami.html.erb | 1 + app/views/layouts/waiter.html.erb | 1 + app/views/renew_license/expire.html.erb | 72 +++++++++++++++++++ .../shared/_license_expire_warning.html.erb | 21 ++++++ config/license.yml | 30 ++++---- config/routes.rb | 3 + config/shops.json | 7 ++ 16 files changed, 181 insertions(+), 55 deletions(-) create mode 100644 app/controllers/renew_license_controller.rb create mode 100644 app/views/renew_license/expire.html.erb create mode 100644 app/views/shared/_license_expire_warning.html.erb diff --git a/Gemfile.lock b/Gemfile.lock index f56a2d36..4cdc2ded 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,7 +96,6 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) - cups (0.0.7) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -335,7 +334,6 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) - cups (~> 0.0.7) database_cleaner factory_girl_rails (~> 4.0) faker diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index 1ff003db..594c99ea 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,7 +1,6 @@ class InstallController < BaseController - skip_before_action :lookup_domain + # skip_before_action :set_current_tenant_by_subdomain_or_name skip_before_action :verify_authenticity_token - # before_action :check_license def index end @@ -9,7 +8,7 @@ class InstallController < BaseController def activate flag = "<%= ENV['AES_IV'] %>" key_base = "<%= ENV['secret_key_base'] %>" - + restaurant = params[:restaurant_name] license_key = params[:license_key] # admin_user = params[:admin_user] @@ -18,20 +17,20 @@ class InstallController < BaseController db_schema = params[:db_schema] db_user = params[:db_user] db_password = params[:db_password] - phrase = license_key - + phrase = license_key + # Check Exists IV # if flag == "<%= ENV['AES_IV'] %>" - # # Export for Key - # aes = MyAesCrypt.new + # # Export for Key + # aes = MyAesCrypt.new # aes_key, aes_iv = aes.export_key(phrase) - # else + # else # aes_key = ENV["AES_KEY"] # aes_iv = ENV["AES_IV"] # end - @license = License.new(ENV["SX_PROVISION_URL"]) - response = @license.license_activate(restaurant, license_key, db_host, db_schema, db_user, db_password) + @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"] else @@ -39,28 +38,24 @@ class InstallController < BaseController end end - def check_license - if License.check_license_file - redirect_to root_url + 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 + end + else + not_found end end - # def lookup_domain - # if request.subdomain.present? && request.subdomain != "www" - # @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) - # if (!@license.nil?) - # # logger.info "Location - " + @license.name - # ActiveRecord::Base.establish_connection(website_connection(@license)) - # # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema - # else - # # reconnect_default_db - # logger.info 'License is nil' - # # redirect_to root_url(:host => request.domain) + "store_error" - # render :json => [{ status: false, message: 'Invalid Access!'}] - # end - # end - # end - # def current_license(url, key) # @license = License.new(url, key) diff --git a/app/controllers/renew_license_controller.rb b/app/controllers/renew_license_controller.rb new file mode 100644 index 00000000..7ef245fe --- /dev/null +++ b/app/controllers/renew_license_controller.rb @@ -0,0 +1,17 @@ +class RenewLicenseController < ApplicationController + + def expire + @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 renew + status, message = current_license.verify_license + + redirect_to expire_url(message: message, status: status) + end + +end \ No newline at end of file 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/models/license.rb b/app/models/license.rb index e1129405..5335d6c4 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -78,7 +78,7 @@ class License def detail_with_local_file if expired? return 0 - elsif expire_in(30)? + elsif expire_in?(10) return 2 else return 1 @@ -151,15 +151,23 @@ class License def verify_license api_token = read_license_no_decrypt("api_token") @params = { query: {lookup_type: "application", api_token: api_token} } + old_renewable_date = read_license("renewable_date") 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 + if old_renewable_date.to_date == @varified['renewable_date'].to_date + message = "*** License couldn't be verified. ***" + status = 2 + elsif old_renewable_date.to_date < @varified['renewable_date'].to_date + update_license("renewable_date", @varified['renewable_date']) + status = 1 + message = "*** License could be verified. ***" end + return status, message + else delete_license_file end @@ -330,7 +338,6 @@ class License redis = Redis.new cache_shop = redis.get(cache_key) - puts Marshal.load(cache_shop) if !cache_shop.nil? @shop = Marshal.load(cache_shop) key = @shop["key"] diff --git a/app/views/layouts/CRM.html.erb b/app/views/layouts/CRM.html.erb index 955abc98..063080d5 100755 --- a/app/views/layouts/CRM.html.erb +++ b/app/views/layouts/CRM.html.erb @@ -59,7 +59,8 @@

<% end %> <% end %> - <% end %> + <% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/layouts/OQS.html.erb b/app/views/layouts/OQS.html.erb index de7c2d14..b8a3058d 100755 --- a/app/views/layouts/OQS.html.erb +++ b/app/views/layouts/OQS.html.erb @@ -53,6 +53,7 @@ <%= message %>
<% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d03889f7..4b30ef25 100755 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -56,7 +56,8 @@ - <% end %> + <% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/layouts/inventory.html.erb b/app/views/layouts/inventory.html.erb index fe49647e..4a117634 100755 --- a/app/views/layouts/inventory.html.erb +++ b/app/views/layouts/inventory.html.erb @@ -51,7 +51,8 @@
<% end %> - <% end %> + <% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/layouts/origami.html.erb b/app/views/layouts/origami.html.erb index 83081cbf..c3ada661 100755 --- a/app/views/layouts/origami.html.erb +++ b/app/views/layouts/origami.html.erb @@ -60,6 +60,7 @@ data-animate-enter="" data-animate-exit="" data-color-name="<%=color%>" >

<% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/layouts/waiter.html.erb b/app/views/layouts/waiter.html.erb index c6cc4d99..6ecfda70 100755 --- a/app/views/layouts/waiter.html.erb +++ b/app/views/layouts/waiter.html.erb @@ -22,6 +22,7 @@ <%= message %>
<% end %> + <%= render 'shared/license_expire_warning' %> <%= yield %>
diff --git a/app/views/renew_license/expire.html.erb b/app/views/renew_license/expire.html.erb new file mode 100644 index 00000000..67e9fe1a --- /dev/null +++ b/app/views/renew_license/expire.html.erb @@ -0,0 +1,72 @@ +<% renewable_date = current_license.read_license("renewable_date") %> +<% date_count = (renewable_date.to_date - Date.today).to_i %> +<% day = pluralize( date_count, 'day' )%> + +<% if @license_status == 0 + text = 'Your license has been expired.' + elsif @license_status == 2 + text = "Your license will expire in #{day}." + end +%> +
+
+
+ +
+
+

Renew Your License

+ <%= link_to origami_dashboard_url do %> + + <% end %> + <% if params[:message].present? + if params[:status].to_i == 1 + color = 'text-success' + else + color = 'text-danger' + end + %> +

<%= params[:message] %>


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

+ <% end %> +
Call Center Phone No: +959 445 665 311
+
+
License Info:
+
+
+
+ + +
+ +
+ + +
+
+ +
+ + +
+
+ +
+ <%= link_to 'Home', origami_dashboard_url, class: 'btn btn-primary btn-lg' %> + <%= link_to 'Renew License', renew_url, class: 'btn btn-primary btn-lg float-right m-l-5 m-r-5' %> + +
+
+
+
+
+ + diff --git a/app/views/shared/_license_expire_warning.html.erb b/app/views/shared/_license_expire_warning.html.erb new file mode 100644 index 00000000..0949aff7 --- /dev/null +++ b/app/views/shared/_license_expire_warning.html.erb @@ -0,0 +1,21 @@ +<% license_status = current_license.detail_with_local_file %> +<% renewable_date = current_license.read_license("renewable_date") %> +<% date_count = (renewable_date.to_date - Date.today).to_i %> +<% day = pluralize( date_count, 'day' )%> + +<% if license_status == 0 + text = 'Your license has expired.' + elsif license_status == 2 + text = "Your license will expire in #{day}." + end +%> +<% if license_status == 0 || license_status == 2 %> + + +<% end %> \ No newline at end of file diff --git a/config/license.yml b/config/license.yml index f1861562..6148ed67 100644 --- a/config/license.yml +++ b/config/license.yml @@ -1,19 +1,19 @@ --- -'': &1 - iv_key: cHmsbixLckobLPvChZxYog== - shop_name: inyahappy - email: support@code2lab.com +localhost: + iv_key: c5bODYtxFPckKXr3bLPdnQ== + shop_name: scdemo3 + email: hanwintun@code2lab.com telephone: '' fax: '' address: '' - dbhost: T78U5MC1QxdtmrveA3dT5znI93KRZgEDv1YEAJLOBuYhF9Okg6IFGds7o0P2Jw0qRCVBAo2mL9zvqCmZ9sIYCQ== - dbschema: QwNWv33nV+/PI7mQ5vUwYpu7oLDVwCFv6E3xLchwDLM= - dbusername: xObcAQiPi19xCQbc0z5buQ== - dbpassword: UIscqcoVMXn4A/OfHnSU6A== - api_token: oHYLdtqtAAacxqAhTMfdVxCRyEkyxLzKcYY - app_token: qVYAxcvsklHlTMEBzgznEqdBZBPI - plan_sku: j3tTAFpFkYP3DNCHSinzqA== - renewable_date: fjyqVnVXXEoyvOVf1Ksa1Q== - plan_name: a3TIsOfLtnkDpqP/FCTjyk/viicooUnN4DJasj4jSF4= -192.168.1.125: *1 -192.168.43.132: *1 + dbhost: eFiEpFewQVPPylY1pefN2ZIVmxg9v7G1YrnHtNIPIbQQg7WtffKz35uCcOwgwzEvCTPUhPQama4B80FHyTpn3Q== + dbschema: PRMtXnRsDZQjF319ItO7Lw== + dbusername: QYngtMBsTBV/B17XiH5zhQ== + dbpassword: vXsZqV2sJQ+tjIiGBb7N8A== + api_token: UQFLAbMvJxUCnDVCOhIdqYZEGRqVQMvI + app_token: DvRXGlomaBFpGVLYsidekVVZyqosntouTA + plan_sku: AqCfY9X2C03i+XBLnvRz5w== + renewable_date: 'MXf+rRgjWFxIRgpf+Aa4JA== + +' + plan_name: bDYhVmEo9MNZmfIxwxE30BFHUKWTDVkVDnUiE6htM5Y= diff --git a/config/routes.rb b/config/routes.rb index 974a00d4..0507f976 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -29,6 +29,9 @@ scope "(:locale)", locale: /en|mm/ do delete 'logout' => 'home#destroy' get 'dashboard' => 'home#dashboard' + get 'expire' => 'renew_license#expire' + get 'renew' => 'renew_license#renew' + namespace :induties do # resources :assign_in_duties get ':booking_id/assign' => 'assign_in_duties#index', as: :assign_in_duties diff --git a/config/shops.json b/config/shops.json index 0c2cc02d..761a41af 100644 --- a/config/shops.json +++ b/config/shops.json @@ -1049,6 +1049,13 @@ "key": "MdrjwSyyNPqIU+HO3rwsHHSlG6xCKC5y3pQ1ywGbX2k=\n", "iv": "8+fEFUROBPpGp23jrRnb3Q==\n" } + }, + { + "lookup": "localhost", + "value": { + "key": "wyo9gq9KYY0FS1r1+cMmmAGEVGxQ2aTpVjfVYCoC9z4=\n", + "iv": "T2UNnKc4EFLiDiALvjybdg==\n" + } } ] } From 67b4cf870ea68f9688240de206bfab46f3b138f8 Mon Sep 17 00:00:00 2001 From: Zin Moe Date: Mon, 8 Jun 2020 09:53:48 +0630 Subject: [PATCH 06/25] place expire warning in top --- app/assets/stylesheets/BSBMaterial/style.css | 4 +-- app/models/license.rb | 4 +-- app/views/layouts/CRM.html.erb | 4 +-- app/views/layouts/OQS.html.erb | 2 +- app/views/layouts/application.html.erb | 2 +- app/views/layouts/inventory.html.erb | 2 +- app/views/layouts/origami.html.erb | 4 +-- app/views/layouts/waiter.html.erb | 2 +- app/views/oqs/home/index.html.erb | 2 +- app/views/origami/addorders/detail.html.erb | 2 +- app/views/origami/cash_ins/new.html.erb | 2 +- app/views/origami/cash_outs/new.html.erb | 2 +- app/views/origami/discounts/index.html.erb | 2 +- app/views/origami/home/index.html.erb | 2 +- app/views/origami/home/show.html.erb | 2 +- .../origami/order_reservation/index.html.erb | 2 +- .../origami/other_charges/index.html.erb | 4 +-- app/views/origami/payments/show.html.erb | 2 +- .../origami/pending_order/index.html.erb | 2 +- app/views/origami/pending_order/show.html.erb | 2 +- app/views/origami/shifts/show.html.erb | 2 +- app/views/origami/surveys/_form.html.erb | 2 +- app/views/renew_license/expire.html.erb | 28 ++++++++++----- .../shared/_license_expire_warning.html.erb | 34 ++++++++++++++++--- config/license.yml | 18 +++++----- 25 files changed, 84 insertions(+), 50 deletions(-) diff --git a/app/assets/stylesheets/BSBMaterial/style.css b/app/assets/stylesheets/BSBMaterial/style.css index a4620cf5..004439e9 100755 --- a/app/assets/stylesheets/BSBMaterial/style.css +++ b/app/assets/stylesheets/BSBMaterial/style.css @@ -11,7 +11,7 @@ box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3); border: none; position: fixed; - top: 0; + /*top: 0;*/ left: 0; z-index: 12; width: 100%; } @@ -6649,7 +6649,7 @@ fieldset[disabled] .form-control { box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3); border: none; position: fixed; - top: 0; + /*top: 0;*/ left: 0; z-index: 12; width: 100%; } diff --git a/app/models/license.rb b/app/models/license.rb index 5335d6c4..92781a22 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -159,12 +159,12 @@ class License Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s if (@varified["status"]) if old_renewable_date.to_date == @varified['renewable_date'].to_date - message = "*** License couldn't be verified. ***" + message = "*** License can't be verified. ***" status = 2 elsif old_renewable_date.to_date < @varified['renewable_date'].to_date update_license("renewable_date", @varified['renewable_date']) status = 1 - message = "*** License could be verified. ***" + message = "*** License con be verified. ***" end return status, message diff --git a/app/views/layouts/CRM.html.erb b/app/views/layouts/CRM.html.erb index 063080d5..5c2fc4b7 100755 --- a/app/views/layouts/CRM.html.erb +++ b/app/views/layouts/CRM.html.erb @@ -31,6 +31,7 @@

Please wait...

+ <%= render 'shared/license_expire_warning' %>
@@ -59,8 +60,7 @@

<% end %> <% end %> - <% end %> - <%= render 'shared/license_expire_warning' %> + <% end %> <%= yield %> diff --git a/app/views/layouts/OQS.html.erb b/app/views/layouts/OQS.html.erb index b8a3058d..c4d18cab 100755 --- a/app/views/layouts/OQS.html.erb +++ b/app/views/layouts/OQS.html.erb @@ -35,6 +35,7 @@

Please wait...

+ <%= render 'shared/license_expire_warning' %>
@@ -53,7 +54,6 @@ <%= message %>
<% end %> - <%= render 'shared/license_expire_warning' %> <%= yield %> \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4b30ef25..44d3c36a 100755 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -32,6 +32,7 @@

Please wait...

+ <%= render 'shared/license_expire_warning' %>
@@ -57,7 +58,6 @@ data-animate-enter="" data-animate-exit="" data-color-name="<%=color%>" >

<% end %> - <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/layouts/inventory.html.erb b/app/views/layouts/inventory.html.erb index 4a117634..9d52575f 100755 --- a/app/views/layouts/inventory.html.erb +++ b/app/views/layouts/inventory.html.erb @@ -31,6 +31,7 @@

Please wait...

+ <%= render 'shared/license_expire_warning' %>
@@ -52,7 +53,6 @@ <% end %> <% end %> - <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/layouts/origami.html.erb b/app/views/layouts/origami.html.erb index c3ada661..398fc691 100755 --- a/app/views/layouts/origami.html.erb +++ b/app/views/layouts/origami.html.erb @@ -31,6 +31,7 @@

Please wait...

+ <%= render 'shared/license_expire_warning' %>
@@ -60,8 +61,7 @@ data-animate-enter="" data-animate-exit="" data-color-name="<%=color%>" >

<% end %> - <%= render 'shared/license_expire_warning' %> - <%= yield %> + <%= yield %> \ No newline at end of file diff --git a/app/views/layouts/waiter.html.erb b/app/views/layouts/waiter.html.erb index 6ecfda70..885f9594 100755 --- a/app/views/layouts/waiter.html.erb +++ b/app/views/layouts/waiter.html.erb @@ -14,6 +14,7 @@ + <%= render 'shared/license_expire_warning' %> <%= render 'layouts/header' %>
<% flash.each do |type, message| %> @@ -22,7 +23,6 @@ <%= message %>
<% end %> - <%= render 'shared/license_expire_warning' %> <%= yield %> diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index e767bafe..c7b52bb8 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -1,5 +1,5 @@ -
+
diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 27d13860..c0e3a61d 100644 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -4,7 +4,7 @@ <% type = request.path_info.include?('quick_service') || request.path_info.include?('food_court')%> <% modify_order = request.path_info.include?('modify_order')%> -
+
diff --git a/app/views/origami/cash_ins/new.html.erb b/app/views/origami/cash_ins/new.html.erb index 5b23656e..675a82c4 100755 --- a/app/views/origami/cash_ins/new.html.erb +++ b/app/views/origami/cash_ins/new.html.erb @@ -1,4 +1,4 @@ -
+

<%= t :cash_in %>

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

<%= t :cash_out %>

diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 5d24c9d1..2fa34e8c 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 39c33749..a583e659 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 8e3c3b18..c6bdfca3 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/order_reservation/index.html.erb b/app/views/origami/order_reservation/index.html.erb index 4355c06a..dcc6af33 100644 --- a/app/views/origami/order_reservation/index.html.erb +++ b/app/views/origami/order_reservation/index.html.erb @@ -1,6 +1,6 @@ <%= stylesheet_link_tag 'order_reservation', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'order_reservation', 'data-turbolinks-track': 'reload' %> -
+
<% pending_count = 0 diff --git a/app/views/origami/other_charges/index.html.erb b/app/views/origami/other_charges/index.html.erb index 886eda51..06208b2f 100755 --- a/app/views/origami/other_charges/index.html.erb +++ b/app/views/origami/other_charges/index.html.erb @@ -1,4 +1,4 @@ -
+
@@ -202,7 +202,7 @@ <%else%> <%end%> - +
diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 6ed4044e..c9795298 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/pending_order/index.html.erb b/app/views/origami/pending_order/index.html.erb index 903c13a5..fe8ba72f 100644 --- a/app/views/origami/pending_order/index.html.erb +++ b/app/views/origami/pending_order/index.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/pending_order/show.html.erb b/app/views/origami/pending_order/show.html.erb index 73ee0040..9ad89797 100644 --- a/app/views/origami/pending_order/show.html.erb +++ b/app/views/origami/pending_order/show.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/shifts/show.html.erb b/app/views/origami/shifts/show.html.erb index a752e5b5..ec529e8c 100755 --- a/app/views/origami/shifts/show.html.erb +++ b/app/views/origami/shifts/show.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index 8bc99b8b..40e52db6 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -1,4 +1,4 @@ -
+
diff --git a/app/views/renew_license/expire.html.erb b/app/views/renew_license/expire.html.erb index 67e9fe1a..d29c5923 100644 --- a/app/views/renew_license/expire.html.erb +++ b/app/views/renew_license/expire.html.erb @@ -8,13 +8,24 @@ text = "Your license will expire in #{day}." end %> +
- -
+
-

Renew Your License

+

Review Your License

<%= link_to origami_dashboard_url do %> <% end %> @@ -51,11 +62,10 @@
- +
- <%= link_to 'Home', origami_dashboard_url, class: 'btn btn-primary btn-lg' %> - <%= link_to 'Renew License', renew_url, class: 'btn btn-primary btn-lg float-right m-l-5 m-r-5' %> - + <%= link_to 'Review License', renew_url, class: 'btn btn-primary btn-lg float-right m-l-10 m-r-5' %> + <%= link_to 'Go To Home', origami_dashboard_url, class: 'btn btn-default btn-lg float-right' %>
@@ -64,9 +74,9 @@ diff --git a/app/views/shared/_license_expire_warning.html.erb b/app/views/shared/_license_expire_warning.html.erb index 0949aff7..a1292d4c 100644 --- a/app/views/shared/_license_expire_warning.html.erb +++ b/app/views/shared/_license_expire_warning.html.erb @@ -10,12 +10,38 @@ end %> <% if license_status == 0 || license_status == 2 %> - diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 6ed4044e..482a2402 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -600,9 +600,9 @@ $(document).ready(function(){ } // if ($("#server_mode").val() != "cloud") { // first bill not used in cloud - payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment"); - other_payment = payment_methods.find(x => payment_type.indexOf(x) >= 0) - // console.log(payment_type) + payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment") + + console.log(payment_type) // console.log(parseInt(jQuery.inArray("MPU", payment_type))) if (member_id && member_discount) { if(parseInt(jQuery.inArray("Credit", payment_type)) == -1){ @@ -611,7 +611,7 @@ $(document).ready(function(){ $("#credit_payment").show(); } - if(other_payment){ + if(payment_type && payment_methods.some(x => payment_type.indexOf(x) >= 0)){ $("#card_payment").show(); } else{ $("#card_payment").hide(); @@ -680,9 +680,8 @@ $(document).ready(function(){ $('#pay').click(function() { sub_total = $('#sub-total').text(); member = $('#membership_id').text(); - // console.log(member) - if (other_payment && !other_payments.some(x => x[0] == other_payment && x[1] > 0 ) && sub_total != 0.0 && member) { - swal("Oops","Please Pay with " + other_payment + " Payment","warning"); + if (payment_type && !other_payments.some(x => payment_type.indexOf(x[0]) >= 0 && x[1] > 0 ) && sub_total != 0.0 && member) { + swal("Oops","Please Pay with " + payment_methods.find(x => payment_type.indexOf(x) >= 0) + " Payment","warning"); } else { $( "#loading_wrapper").show(); if($('#balance').text() > 0){ diff --git a/app/views/reports/dailysale/index.html.erb b/app/views/reports/dailysale/index.html.erb index 13b315de..db25ce0c 100755 --- a/app/views/reports/dailysale/index.html.erb +++ b/app/views/reports/dailysale/index.html.erb @@ -82,44 +82,11 @@ <%= t("views.right_panel.detail.sr") %> - <%= t("views.right_panel.detail.date") %> + <%= t("views.righ_panel.detail.date") %> + <% @payment_methods.each do |method| %> + <%= t("views.right_panel.detail.#{method}") %> + <% end %> - <% if @payment_methods.include? ("MPU") %> - <%= t("views.right_panel.detail.mpu_sales") %> - <% end %> - <% if @payment_methods.include? ("Master") %> - <%= t("views.right_panel.detail.master_sales") %> - <% end %> - <% if @payment_methods.include? ("VISA") %> - <%= t("views.right_panel.detail.visa_sales") %> - <% end %> - <% if @payment_methods.include? ("JCB") %> - <%= t("views.right_panel.detail.jcb_sales") %> - <% end %> - <% if @payment_methods.include? ("UNIONPAY") %> - <%= t("views.right_panel.detail.unionpay_sales") %> - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - <%= t("views.right_panel.detail.kbzpay_sales") %> - <% end %> - <% if @payment_methods.include? ("Alipay") %> - <%= t("views.right_panel.detail.alipay_sales") %> - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - <%= t("views.right_panel.detail.paymal_sales") %> - <% end %> - <% if @payment_methods.include? ("DINGA") %> - <%= t("views.right_panel.detail.dinga_sales") %> - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - <%= t("views.right_panel.detail.junctionpay_sales") %> - <% end %> - <% if @payment_methods.include? ("Redeem") %> - <%= t("views.right_panel.detail.redeem_sales") %> - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - <%= t("views.right_panel.detail.giftvoucher_sales") %> - <% end %> <%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.void_amount") %> @@ -140,22 +107,10 @@ <% unless @sale_data.blank? %> <% void = 0 %> - <% mpu = 0 %> - <% master = 0 %> - <% visa = 0 %> - <% jcb = 0 %> - <% unionpay = 0 %> - <% alipay = 0 %> - <% paymal = 0 %> - <% dinga = 0 %> - <% junctionpay = 0 %> - <% giftvoucher = 0 %> - <% paypar = 0 %> <% cash = 0 %> <% credit = 0 %> <% foc = 0 %> <% discount = 0 %> - <% kbzpay = 0 %> <% total = 0 %> <% grand_total = 0 %> <% old_grand_total = 0 %> @@ -164,24 +119,13 @@ <% tax = 0 %> <% net_sale = 0 %> <% count = 1 %> <% rounding_adj = 0 %> + <% @sale_data.each do |sale| %> <% void += sale[:void_amount] %> - <% mpu += sale[:mpu_amount] %> - <% master += sale[:master_amount] %> - <% visa += sale[:visa_amount] %> - <% jcb += sale[:jcb_amount] %> - <% unionpay += sale[:unionpay_amount] %> - <% alipay += sale[:alipay_amount] %> - <% paymal += sale[:paymal_amount] %> - <% dinga += sale[:dinga_amount] %> - <% junctionpay += sale[:junctionpay_amount] %> - <% giftvoucher += sale[:giftvoucher_amount] %> - <% paypar += sale[:paypar_amount] %> <% cash += sale[:cash_amount]-sale[:total_change_amount] %> <% credit += sale[:credit_amount] %> <% foc += sale[:foc_amount] %> <% discount += sale[:total_discount] %> - <% kbzpay += sale[:kbzpay_amount] %> <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> <% grand_total += sale[:grand_total].to_f %> <% old_grand_total += sale[:old_grand_total].to_f %> @@ -193,41 +137,8 @@ <%= count %> <%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %> - <% if @payment_methods.include? ("MPU") %> - <%= number_format(sale[:mpu_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("Master") %> - <%= number_format(sale[:master_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("VISA") %> - <%= number_format(sale[:visa_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("JCB") %> - <%= number_format(sale[:jcb_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("UNIONPAY") %> - <%= number_format(sale[:unionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("Alipay") %> - <%= number_format(sale[:alipay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - <%= number_format(sale[:kbzpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - <%= number_format(sale[:paymal_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("DINGA") %> - <%= number_format(sale[:dinga_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - <%= number_format(sale[:junctionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("Redeem") %> - <%= number_format(sale[:paypar_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - <%= number_format(sale[:giftvoucher_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <% @payment_methods.each do |method| %> + <%= number_format(sale[method.parameterize.to_sym], precision:precision.to_i, delimiter: delimiter) rescue 0 %> <% end %> <%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision:precision.to_i, delimiter: delimiter) rescue '-'%> <%= number_format(sale[:credit_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -236,7 +147,7 @@ (<%= number_format(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>) - <%= number_format(sale[:rounding_adj].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(sale[:rounding_adj], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(sale[:gross_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(sale[:total_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <% if @tax.blank? %> @@ -250,75 +161,9 @@ <% colspan = 7 %> Total - <% if @payment_methods.include? ("MPU") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(mpu , precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end%> - <% if @payment_methods.include? ("Master") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(master, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end%> - <% if @payment_methods.include? ("VISA") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(visa, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end%> - <% if @payment_methods.include? ("JCB") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(jcb, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end%> - <% if @payment_methods.include? ("UNIONPAY") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(unionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("Alipay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(alipay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(kbzpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(paymal, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("DINGA") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(dinga, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(junctionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("Redeem") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(paypar, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - <% colspan += 1 %> - <%= number_format(giftvoucher, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <% @payment_methods.each do |method| %> + <% colspan += 1 %> + <%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[method.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue 0 %> <% end %> <%= number_format(cash, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%> diff --git a/app/views/reports/dailysale/index.xls.erb b/app/views/reports/dailysale/index.xls.erb index f3d0aa2b..cc0eced9 100755 --- a/app/views/reports/dailysale/index.xls.erb +++ b/app/views/reports/dailysale/index.xls.erb @@ -27,41 +27,8 @@ <%= t("views.right_panel.detail.sr") %> <%= t("views.right_panel.detail.date") %> - <% if @payment_methods.include? ("MPU") %> - <%= t("views.right_panel.detail.mpu_sales") %> - <% end %> - <% if @payment_methods.include? ("Master") %> - <%= t("views.right_panel.detail.master_sales") %> - <% end %> - <% if @payment_methods.include? ("VISA") %> - <%= t("views.right_panel.detail.visa_sales") %> - <% end %> - <% if @payment_methods.include? ("JCB") %> - <%= t("views.right_panel.detail.jcb_sales") %> - <% end %> - <% if @payment_methods.include? ("UNIONPAY") %> - <%= t("views.right_panel.detail.unionpay_sales") %> - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - <%= t("views.right_panel.detail.kbzpay_sales") %> - <% end %> - <% if @payment_methods.include? ("Alipay") %> - <%= t("views.right_panel.detail.alipay_sales") %> - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - <%= t("views.right_panel.detail.paymal_sales") %> - <% end %> - <% if @payment_methods.include? ("DINGA") %> - <%= t("views.right_panel.detail.dinga_sales") %> - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - <%= t("views.right_panel.detail.junctionpay_sales") %> - <% end %> - <% if @payment_methods.include? ("Redeem") %> - <%= t("views.right_panel.detail.redeem_sales") %> - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - <%= t("views.right_panel.detail.giftvoucher_sales") %> + <% @payment_methods.each do |method| %> + <%= t("views.right_panel.detail.#{method}") %> <% end %> <%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> @@ -108,22 +75,10 @@ <% count = 1 %> <% rounding_adj = 0 %> <% @sale_data.each do |sale| %> <% void += sale[:void_amount] %> - <% mpu += sale[:mpu_amount] %> - <% master += sale[:master_amount] %> - <% visa += sale[:visa_amount] %> - <% jcb += sale[:jcb_amount] %> - <% unionpay += sale[:unionpay_amount] %> - <% alipay += sale[:alipay_amount] %> - <% paymal += sale[:paymal_amount] %> - <% dinga += sale[:dinga_amount] %> - <% junctionpay += sale[:junctionpay_amount] %> - <% giftvoucher += sale[:giftvoucher_amount] %> - <% paypar += sale[:paypar_amount] %> <% cash += sale[:cash_amount]-sale[:total_change_amount] %> <% credit += sale[:credit_amount] %> <% foc += sale[:foc_amount] %> <% discount += sale[:total_discount] %> - <% kbzpay += sale[:kbzpay_amount] %> <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> <% grand_total += sale[:grand_total].to_f %> <% old_grand_total += sale[:old_grand_total].to_f %> @@ -135,41 +90,8 @@ <%= count %> <%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %> - <% if @payment_methods.include? ("MPU") %> - <%= number_format(sale[:mpu_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("Master") %> - <%= number_format(sale[:master_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("VISA") %> - <%= number_format(sale[:visa_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("JCB") %> - <%= number_format(sale[:jcb_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("UNIONPAY") %> - <%= number_format(sale[:unionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("Alipay") %> - <%= number_format(sale[:alipay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - <%= number_format(sale[:kbzpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - <%= number_format(sale[:paymal_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("DINGA") %> - <%= number_format(sale[:dinga_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - <%= number_format(sale[:junctionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("Redeem") %> - <%= number_format(sale[:paypar_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - <%= number_format(sale[:giftvoucher_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <% @payment_methods.each do |method| %> + <%= number_format(sale[method.parameterize.to_sym], precision:precision.to_i, delimiter: delimiter) rescue 0 %> <% end %> <%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision:precision.to_i, delimiter: delimiter) rescue '-'%> <%= number_format(sale[:credit_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -192,75 +114,9 @@ <% colspan = 7 %> Total - <% if @payment_methods.include? ("MPU") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(mpu , precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end%> - <% if @payment_methods.include? ("Master") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(master, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end%> - <% if @payment_methods.include? ("VISA") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(visa, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end%> - <% if @payment_methods.include? ("JCB") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(jcb, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end%> - <% if @payment_methods.include? ("UNIONPAY") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(unionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("Alipay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(alipay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("KBZPay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(kbzpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("PAYMAL") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(paymal, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("DINGA") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(dinga, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("JunctionPay") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(junctionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("Redeem") %> - <% if !request.user_agent.include? "Mobile" %> - <% colspan += 1 %> - <% end %> - <%= number_format(paypar, precision:precision.to_i,delimiter:delimiter) rescue '-'%> - <% end %> - <% if @payment_methods.include? ("GiftVoucher") %> - <% colspan += 1 %> - <%= number_format(giftvoucher, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <% @payment_methods.each do |method| %> + <% colspan += 1 %> + <%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[method.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue 0 %> <% end %> <%= number_format(cash, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%> @@ -293,12 +149,12 @@ <% net = net - total_tax %> <%= t("views.right_panel.detail.net_amount") %> - <%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <% else %> <%= t("views.right_panel.detail.net_amount") %> - <%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%> + <%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <% end %> diff --git a/app/views/reports/payment_method/index.html.erb b/app/views/reports/payment_method/index.html.erb index ed0ffec3..93f7be28 100755 --- a/app/views/reports/payment_method/index.html.erb +++ b/app/views/reports/payment_method/index.html.erb @@ -40,42 +40,25 @@ <% end %> - <%= t("views.right_panel.detail.mpu_sales") %> - <%= t("views.right_panel.detail.master_sales") %> - <%= t("views.right_panel.detail.visa_sales") %> - <%= t("views.right_panel.detail.jcb_sales") %> - <%= t("views.right_panel.detail.unionpay_sales") %> - <%= t("views.right_panel.detail.alipay_sales") %> - <%= t("views.right_panel.detail.kbzpay_sales") %> - - <%= t("views.right_panel.detail.dinga_sales") %> - <%= t("views.right_panel.detail.junctionpay_sales") %> - <%= t("views.right_panel.detail.redeem_sales") %> + <% @payment_methods.each do |method| %> + <%= t("views.right_panel.detail.#{method} Sales") %> + <% end %> <%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.foc_sales") %> - <%= t("views.right_panel.detail.giftvoucher_sales") %> <% unless @sale_data.empty? %> <% @sale_data.each do |sale| %> - <%= number_format(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:kbzpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - - <%= number_format(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <% @payment_methods.each do |method| %> + <%= number_format(sale[method.parameterize.to_sym] , precision: precision.to_i ,delimiter: delimiter) rescue 0 %> + <% end %> <%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_format(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_format(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <% end %> diff --git a/app/views/reports/payment_method/index.xls.erb b/app/views/reports/payment_method/index.xls.erb index a6fcf35d..ec4dfbee 100755 --- a/app/views/reports/payment_method/index.xls.erb +++ b/app/views/reports/payment_method/index.xls.erb @@ -27,42 +27,24 @@ <% end %> - <%= t("views.right_panel.detail.mpu_sales") %> - <%= t("views.right_panel.detail.master_sales") %> - <%= t("views.right_panel.detail.visa_sales") %> - <%= t("views.right_panel.detail.jcb_sales") %> - <%= t("views.right_panel.detail.unionpay_sales") %> - <%= t("views.right_panel.detail.alipay_sales") %> - <%= t("views.right_panel.detail.kbzpay_sales") %> - - <%= t("views.right_panel.detail.dinga_sales") %> - <%= t("views.right_panel.detail.junctionpay_sales") %> - <%= t("views.right_panel.detail.redeem_sales") %> + <% @payment_methods.each do |method| %> + <%= t("views.right_panel.detail.#{method} Sales") %> + <% end %> <%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.foc_sales") %> - <%= t("views.right_panel.detail.giftvoucher_sales") %> <% unless @sale_data.empty? %> <% @sale_data.each do |sale| %> - <%= number_format(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:kbzpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - - <%= number_format(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> + <% @payment_methods.each do |method| %> + <%= number_format(sale[method.parameterize.to_sym] , precision: precision.to_i ,delimiter: delimiter) rescue 0 %> + <% end %> <%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_format(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <%= number_format(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%= number_format(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> <% end %> From f6a35d214fe20e9227136df34f3ef9cb8b3f2296 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Wed, 10 Jun 2020 18:12:15 +0630 Subject: [PATCH 08/25] fixed payment methods & license --- .gitignore | 1 + Gemfile.lock | 4 +- app/assets/stylesheets/BSBMaterial/style.css | 4 +- app/controllers/home_controller.rb | 2 - .../origami/waste_spoile_controller.rb | 5 +- .../reports/payment_method_controller.rb | 10 +-- .../reports/receipt_no_detail_controller.rb | 64 +++++++++---------- .../transactions/shift_sales_controller.rb | 14 ++-- app/models/license.rb | 6 +- app/models/sale.rb | 23 +++++-- app/models/sale_payment.rb | 5 +- app/views/home/dashboard.html.erb | 36 ++++++----- app/views/layouts/CRM.html.erb | 20 +++--- app/views/layouts/OQS.html.erb | 16 ++--- app/views/layouts/application.html.erb | 27 ++++---- app/views/layouts/inventory.html.erb | 14 ++-- app/views/layouts/origami.html.erb | 19 +++--- app/views/origami/dashboard/index.html.erb | 6 +- .../_shift_sale_report_filter.html.erb | 9 +-- .../reports/waste_and_spoilage/index.html.erb | 2 +- .../shared/_license_expire_warning.html.erb | 25 +++++--- .../transactions/shift_sales/show.html.erb | 60 ++++++----------- config/license.yml | 17 ----- 23 files changed, 187 insertions(+), 202 deletions(-) delete mode 100644 config/license.yml diff --git a/.gitignore b/.gitignore index 3560a44c..42dc0371 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 !/log/.keep diff --git a/Gemfile.lock b/Gemfile.lock index 4cdc2ded..578d79d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,6 +96,7 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) + cups (0.0.7) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -334,6 +335,7 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) + cups (~> 0.0.7) database_cleaner factory_girl_rails (~> 4.0) faker @@ -382,4 +384,4 @@ RUBY VERSION ruby 2.6.5p114 BUNDLED WITH - 2.0.2 + 2.1.4 diff --git a/app/assets/stylesheets/BSBMaterial/style.css b/app/assets/stylesheets/BSBMaterial/style.css index 004439e9..a4620cf5 100755 --- a/app/assets/stylesheets/BSBMaterial/style.css +++ b/app/assets/stylesheets/BSBMaterial/style.css @@ -11,7 +11,7 @@ box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3); border: none; position: fixed; - /*top: 0;*/ + top: 0; left: 0; z-index: 12; width: 100%; } @@ -6649,7 +6649,7 @@ fieldset[disabled] .form-control { box-shadow: 0 1px 5px rgba(0, 0, 0, 0.3); border: none; position: fixed; - /*top: 0;*/ + top: 0; left: 0; z-index: 12; width: 100%; } diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 18928fc3..2665a330 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -108,8 +108,6 @@ class HomeController < ApplicationController @hourly_sales = Sale.hourly_sales(current_user,@from,@to) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) - logger.debug 'hourly_sales<>><><><<<<<<>><<<><><><><><><><><><<>><' - logger.debug @hourly_sales.to_json 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 = [] diff --git a/app/controllers/origami/waste_spoile_controller.rb b/app/controllers/origami/waste_spoile_controller.rb index ba0846ee..e1055323 100755 --- a/app/controllers/origami/waste_spoile_controller.rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -10,10 +10,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/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb index 752a2f4e..baad3350 100644 --- a/app/controllers/reports/payment_method_controller.rb +++ b/app/controllers/reports/payment_method_controller.rb @@ -4,12 +4,12 @@ class Reports::PaymentMethodController < BaseReportController @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") - @payments = [["All Payment",''],["Cash Payment","cash"], ["Credit Payment","creditnote"], - ["FOC Payment","foc"]] + @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 + # @payment_methods.each do |m| + # @payments.push(["#{m} Payment", m.parameterize]) + # end from, to = get_date_range_from_params diff --git a/app/controllers/reports/receipt_no_detail_controller.rb b/app/controllers/reports/receipt_no_detail_controller.rb index 775b2651..eba6c3e6 100755 --- a/app/controllers/reports/receipt_no_detail_controller.rb +++ b/app/controllers/reports/receipt_no_detail_controller.rb @@ -1,46 +1,46 @@ class Reports::ReceiptNoDetailController < BaseReportController authorize_resource :class => false def index - @payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"]] - @payment_method = PaymentMethodSetting.all + @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 @shift_sale_range = '' - @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) + 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 + @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 + format.html + format.xls + end end def show diff --git a/app/controllers/transactions/shift_sales_controller.rb b/app/controllers/transactions/shift_sales_controller.rb index f3a9fc05..562d45e4 100644 --- a/app/controllers/transactions/shift_sales_controller.rb +++ b/app/controllers/transactions/shift_sales_controller.rb @@ -10,16 +10,16 @@ class Transactions::ShiftSalesController < ApplicationController to = params[:to] if filter.nil? && from.nil? && to.nil? - @shift_sales = ShiftSale.all.order("id desc") + @shift_sales = ShiftSale.all.order("id desc") @shift_sales = Kaminari.paginate_array(@shift_sales).page(params[:page]).per(20) else shift_sale = ShiftSale.search(filter,from,to) if shift_sale.count > 0 - @shift_sales = shift_sale + @shift_sales = shift_sale @shift_sales = Kaminari.paginate_array(@shift_sales).page(params[:page]).per(20) else @shift_sales = 0 - end + end end respond_to do |format| @@ -32,7 +32,7 @@ class Transactions::ShiftSalesController < ApplicationController # GET /transactions/shift_sales/1 # GET /transactions/shift_sales/1.json def show - + @shift = ShiftSale.find(params[:id]) #get tax @@ -40,13 +40,13 @@ class Transactions::ShiftSalesController < ApplicationController @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') #other payment details for mpu or visa like card @other_payment = ShiftSale.get_by_shift_other_payment(@shift) - + @payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') @total_member_discount = ShiftSale.get_total_member_discount(@shift) - + respond_to do |format| format.html # show.html.erb @@ -59,7 +59,7 @@ class Transactions::ShiftSalesController < ApplicationController redirect_to root_path end end - + private # Use callbacks to share common setup or constraints between actions. def set_transactions_shift_sale diff --git a/app/models/license.rb b/app/models/license.rb index 92781a22..edbe5947 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -164,10 +164,10 @@ class License elsif old_renewable_date.to_date < @varified['renewable_date'].to_date update_license("renewable_date", @varified['renewable_date']) status = 1 - message = "*** License con be verified. ***" + message = "*** License con be verified. ***" end return status, message - + else delete_license_file end @@ -204,7 +204,7 @@ class License def days_to_expire if renewal_date_str = read_license("renewable_date") - Date.today - DateTime.parse(renewal_date_str).to_date + Date.today - DateTime.parse(renewal_date_str).to_date end end diff --git a/app/models/sale.rb b/app/models/sale.rb index aa2b6992..7018f0ff 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1200,11 +1200,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? @@ -1363,7 +1373,11 @@ def self.get_payment_method_by_shift(shift,from,to,payment_type) end if payment_type.present? - sale_payment = sale_payment.where(payment_method: payment_type) + if payment_type == 'card' + sale_payment = sale_payment.where(sanitize_sql_array(["payment_method IN (?)", SalePayment::CARD])) + else + sale_payment = sale_payment.where("payment_method = (?)", payment_type) + end end return payments_total, sale_payment @@ -1577,11 +1591,10 @@ end end def self.total_payment_methods(current_user=nil,from=nil,to=nil) - payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) - query = Sale.select("CASE WHEN sp.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }) 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 (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }) 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) @@ -2293,7 +2306,7 @@ private self.total_tax = self.total_tax.round(precision) end self.grand_total = (self.total_amount - self.total_discount) + self.total_tax - if (!['foc'].include? self.payment_status) + if (!['foc','waste','spoile'].include? self.payment_status) adjust_rounding end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 9ade9920..95162fb2 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: PaymentMethodSetting.where("is_active='1'").pluck("payment_method")) } + scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay']) } def self.sync_sale_payment_records(sale_payments) if !sale_payments.nil? diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index b7bd5c44..e77cee9d 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -209,30 +209,36 @@ <% if !(@total_payment_methods.nil?) %> <% @total_payment_methods.each do |payment| %> - <% if payment.payment_method != 'card' %> - + <% if !@sale_data[0].empty? %> + <% if payment.payment_method != 'mpu' && payment.payment_method != 'visa' && payment.payment_method != 'master' && payment.payment_method != 'jcb' %> + <% if payment.payment_method == 'paypar' %> <% else %> <% end %> - - + + + <% end %> <% end %> <% end %> - <% total_card = @sale_data.find {|x| x.key?("card") } %> - <% if !total_card.nil? %> - - - - + <% total_card = @sale_data.select { |hash| hash["card"]!=nil } %> + <% if !total_card.nil? %> + + + + <% end %> - <% end %>
Redeem Sale : <%= payment.payment_method.to_s.capitalize %> Sale : - <%= number_format(@sale_data.find {|x| x.key?(payment.payment_method) }[payment.payment_method], precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> -
+ <% @sale_data.each do |data| %> + <% pay_mth = payment.payment_method %> + <%= data[""+pay_mth+""] %> + <% end %> +
<%= t("views.right_panel.detail.other_payment") %> : - <%= number_format(total_card["card"], precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> -
<%= t("views.right_panel.detail.other_payment") %> : + <% total_other_amt = 0 %> + <% @sale_data.map { |k,v| k.map{|meth,amt| meth != 'cash' && meth != 'foc' && meth != 'creditnote' ? total_other_amt += amt : meth }} %> + <%= total_other_amt %> +
diff --git a/app/views/layouts/CRM.html.erb b/app/views/layouts/CRM.html.erb index 5c2fc4b7..3fca697d 100755 --- a/app/views/layouts/CRM.html.erb +++ b/app/views/layouts/CRM.html.erb @@ -31,38 +31,38 @@

Please wait...

- <%= render 'shared/license_expire_warning' %> + <%= render 'shared/license_expire_warning' if Rails.env.production? %>
<%= render 'layouts/header' %> -
- <%= render 'layouts/left_sidebar' %> - <%= render 'layouts/right_sidebar' %> +
+ <%= render 'layouts/left_sidebar' %> + <%= render 'layouts/right_sidebar' %>
-
+
<% flash.each do |type, message| %> <% if !flash["errors"]%> - <% + <% if type == "notice" color = "alert-success" end if type == "error" color = "alert-danger" - end + end %> <% if flash["error"] || flash["notice"]%> <% end %> - <% end %> + <% end %> <% end %> - <%= yield %> + <%= yield %>
- \ No newline at end of file + diff --git a/app/views/layouts/OQS.html.erb b/app/views/layouts/OQS.html.erb index c4d18cab..4c02c0db 100755 --- a/app/views/layouts/OQS.html.erb +++ b/app/views/layouts/OQS.html.erb @@ -35,25 +35,25 @@

Please wait...

- <%= render 'shared/license_expire_warning' %> + <%= render 'shared/license_expire_warning' if Rails.env.production? %>
<%= render 'layouts/header' %> -
- <%= render 'layouts/left_sidebar' %> - <%= render 'layouts/right_sidebar' %> +
+ <%= render 'layouts/left_sidebar' %> + <%= render 'layouts/right_sidebar' %>
-
+
<% flash.each do |type, message| %>
<%= message %>
- <% end %> - <%= yield %> + <% end %> + <%= yield %>
- \ No newline at end of file + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 44d3c36a..5f78554c 100755 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -4,7 +4,7 @@ - + SmartSales : Restaurant <%= csrf_meta_tags %> @@ -12,7 +12,7 @@ <%= stylesheet_link_tag 'application', media: 'all' %> - <%= javascript_include_tag 'application' %> + <%= javascript_include_tag 'application' %> @@ -32,33 +32,34 @@

Please wait...

- <%= render 'shared/license_expire_warning' %> + + <%= render 'shared/license_expire_warning' if Rails.env.production? %>
<%= render 'layouts/header' %> -
- <%= render 'layouts/left_sidebar' %> - <%= render 'layouts/right_sidebar' %> +
+ <%= render 'layouts/left_sidebar' %> + <%= render 'layouts/right_sidebar' %>
-
+
<% flash.each do |type, message| %> - <% if type == "notice" + <% if type == "notice" color = "alert-success" elsif type == "error" color = "alert-danger" else color = "bg-black" end %> - + - <% end %> - <%= yield %> -
+ <% end %> + <%= yield %> +
- \ No newline at end of file + diff --git a/app/views/layouts/inventory.html.erb b/app/views/layouts/inventory.html.erb index 9d52575f..283dd311 100755 --- a/app/views/layouts/inventory.html.erb +++ b/app/views/layouts/inventory.html.erb @@ -31,15 +31,15 @@

Please wait...

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

Please wait...

- <%= render 'shared/license_expire_warning' %> + <%= render 'shared/license_expire_warning' if Rails.env.production? %>
<%= render 'layouts/header' %> -
- <%= render 'layouts/left_sidebar' %> - <%= render 'layouts/right_sidebar' %> +
+ <%= render 'layouts/left_sidebar' %> + <%= render 'layouts/right_sidebar' %>
@@ -47,21 +47,20 @@ -
+
<% flash.each do |type, message| %> - <% if type == "notice" + <% if type == "notice" color = "alert-success" elsif type == "error" color = "alert-danger" else color = "bg-black" end %> - + - <% end %> - <%= yield %> + <% end %> + <%= yield %>
- \ No newline at end of file diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index 38df56b3..8fec5deb 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -116,12 +116,14 @@ <% end %> <% end %> - <% total_card = @sale_data.select { |hash| hash["card"]!=nil }.first %> + <% total_card = @sale_data.select { |hash| hash["card"]!=nil } %> <% if !total_card.nil? %> <%= t("views.right_panel.detail.other_payment") %> : - <%= total_card["card"].to_f %> + <% total_other_amt = 0 %> + <% @sale_data.map { |k,v| k.map{|meth,amt| meth != 'cash' && meth != 'foc' && meth != 'creditnote' ? total_other_amt += amt : meth }} %> + <%= total_other_amt %> <% end %> diff --git a/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb b/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb index 89264e82..ad834e00 100755 --- a/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb +++ b/app/views/reports/receipt_no_detail/_shift_sale_report_filter.html.erb @@ -18,17 +18,14 @@
- <% if defined? payments %> + <% if defined? @payment_methods %>
diff --git a/app/views/reports/waste_and_spoilage/index.html.erb b/app/views/reports/waste_and_spoilage/index.html.erb index afd292f9..714f2e69 100755 --- a/app/views/reports/waste_and_spoilage/index.html.erb +++ b/app/views/reports/waste_and_spoilage/index.html.erb @@ -55,7 +55,7 @@ <% @sale_data.each do |sale| %> <% if !sale.item_instance_code.nil?%> <% waste_and_spoil_item_count += sale.qty.to_i %> - <% grand_total += sale.grand_total.to_i %> + <% grand_total += sale.price.to_i %> <% end %> <% if !menu_cat_arr.include?(sale.name) %> diff --git a/app/views/shared/_license_expire_warning.html.erb b/app/views/shared/_license_expire_warning.html.erb index a1292d4c..eb19cd49 100644 --- a/app/views/shared/_license_expire_warning.html.erb +++ b/app/views/shared/_license_expire_warning.html.erb @@ -3,15 +3,15 @@ <% date_count = (renewable_date.to_date - Date.today).to_i %> <% day = pluralize( date_count, 'day' )%> -<% if license_status == 0 +<% if license_status == 0 text = 'Your license has expired.' elsif license_status == 2 text = "Your license will expire in #{day}." end %> <% if license_status == 0 || license_status == 2 %> -