From 4e61eba843158b6cf49ddf713a9ba6c4383e877b Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 20 Jul 2020 00:26:47 +0630 Subject: [PATCH 1/3] remove get_tax_profiles from api_controller and create tax_profiles api --- app/controllers/api/api_controller.rb | 4 ---- app/controllers/api/tax_profiles_controller.rb | 8 ++++++++ app/models/tax_profile.rb | 2 ++ app/views/api/api/get_tax_profiles.json.jbuilder | 3 --- app/views/api/tax_profiles/index.json.jbuilder | 4 ++++ config/routes.rb | 7 +++++-- 6 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 app/controllers/api/tax_profiles_controller.rb delete mode 100644 app/views/api/api/get_tax_profiles.json.jbuilder create mode 100644 app/views/api/tax_profiles/index.json.jbuilder diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 8cdd684f..8c6aaf65 100755 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -8,10 +8,6 @@ class Api::ApiController < ActionController::API # before_action :lookup_domain helper_method :current_token, :current_login_employee, :get_cashier - def get_tax_profiles - @inclusive_tax, @exclusive_tax = TaxProfile.calculate_tax("online_order") - end - private # ActionView::Rendering override render_to_body breaks render :json, # resulting in an ActionView::MissingTemplate error. diff --git a/app/controllers/api/tax_profiles_controller.rb b/app/controllers/api/tax_profiles_controller.rb new file mode 100644 index 00000000..e1e13de0 --- /dev/null +++ b/app/controllers/api/tax_profiles_controller.rb @@ -0,0 +1,8 @@ +class Api::TaxProfilesController < Api::ApiController + + def index + @tax_profiles = TaxProfile.where(nil) + @tax_profiles = @tax_profiles.filter_by_group_type(params[:group_type]) if params[:group_type].present? + end + +end diff --git a/app/models/tax_profile.rb b/app/models/tax_profile.rb index b531cd5c..e2e25220 100755 --- a/app/models/tax_profile.rb +++ b/app/models/tax_profile.rb @@ -5,6 +5,8 @@ class TaxProfile < ApplicationRecord # validations validates_presence_of :name, :rate, :group_type + scope :filter_by_group_type, -> (group_type) { where group_type: group_type } + def self.calculate_tax(group_type) divided_value =0.0 exclusive =0.0 diff --git a/app/views/api/api/get_tax_profiles.json.jbuilder b/app/views/api/api/get_tax_profiles.json.jbuilder deleted file mode 100644 index 89da4ab0..00000000 --- a/app/views/api/api/get_tax_profiles.json.jbuilder +++ /dev/null @@ -1,3 +0,0 @@ -json.status true -json.inclusive_tax @inclusive_tax -json.exclusive_tax @exclusive_tax diff --git a/app/views/api/tax_profiles/index.json.jbuilder b/app/views/api/tax_profiles/index.json.jbuilder new file mode 100644 index 00000000..e8edb04b --- /dev/null +++ b/app/views/api/tax_profiles/index.json.jbuilder @@ -0,0 +1,4 @@ +json.status true +json.data do + json.tax_profiles @tax_profiles, :name, :group_type, :rate, :inclusive, :order_by +end diff --git a/config/routes.rb b/config/routes.rb index 4ac63e0a..69c4e0ff 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -50,7 +50,11 @@ scope "(:locale)", locale: /en|mm/ do post 'authenticate' => "authenticate#create" delete 'authenticate' => "authenticate#destroy" get "menu_item_groups" => "menu_item_groups#index" - get 'get_tax_profiles' => 'api#get_tax_profiles' + + scope '/(:group_type)', defaults: { group_type: nil } do + resources :tax_profiles, only: [:index] + end + namespace :restaurant do get 'zones' => "zones#index" resources :menu, only: [:index, :show] @@ -69,7 +73,6 @@ scope "(:locale)", locale: /en|mm/ do post "bill/:booking_id" => "bill#create" post "move" => "move#create" - #Order Controller resources :orders, only: [:create, :show, :update] do post "bill" => "bill#create" From 567a716fe3dab5a5596acbad7b10b2443094a85b Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Tue, 21 Jul 2020 11:38:54 +0630 Subject: [PATCH 2/3] remove member_discount method from sale --- app/models/sale.rb | 46 +--------------------------------------- app/models/shift_sale.rb | 1 - 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 4076b4fe..2a747067 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -26,7 +26,7 @@ class Sale < ApplicationRecord has_one :booking has_many :product_commissions - before_save :member_discount, :round_to_precision + before_save :round_to_precision after_update :update_stock_journal scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } @@ -2321,50 +2321,6 @@ private end end - def member_discount - return unless will_save_change_to_customer_id? || will_save_change_to_total_amount? - - if self.customer && self.customer.membership_id.present? - membership = MembershipSetting.find_by_membership_type("paypar_url") - memberaction = MembershipAction.find_by_membership_type("get_member_campaign") - merchant_uid = memberaction.merchant_account_id.to_s - campaign_type_id = memberaction.additional_parameter["campaign_type_id"] - auth_token = memberaction.auth_token - url = "#{membership.gateway_url}#{memberaction.gateway_url}" - - begin - response = HTTParty.get(url, - :body => { - member_group_id: sObj.customer.membership_type, - merchant_uid: merchant_uid, - campaign_type_id: campaign_type_id, - auth_token: auth_token - }.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json; version=3' - }, :timeout => 10) - rescue Net::OpenTimeout - response = { "status": false , "message": " Connection timeout" } - rescue OpenURI::HTTPError - response = { "status": false, "message": "Can't connect server"} - rescue SocketError - response = { "status": false, "message": "Can't connect server"} - end - - return unless response['status'] && response['membership_campaign_data'].present? - - Account.where(discount: true).inject(0) do |dis, acc| - rule = response['membership_campaign_data'].find { |c| c['rules_type'].downcase.strip == acc.title.downcase.strip } - dis += acc.sale_items.inject(0) { |i| i.account_id == acc.id ? i.price : 0 } * rule["change_unit"].to_i / rule["base_unit"].to_i - end - - - else - - end - end - def round_to_precision if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0) self.total_amount = self.total_amount.round(precision) diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index dc96a425..daffd8cf 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -180,7 +180,6 @@ class ShiftSale < ApplicationRecord def self.get_total_member_discount(shift) query = Sale.select("SUM(sales.total_discount) as member_discount") .where("shift_sale_id =? and sale_status = 'completed' and discount_type = 'member_discount'", shift.id) - end def self.get_total_dinein(shift) From 8d7bc2996e2a97a40ec9b5012cf5a7441cdb61a5 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Tue, 21 Jul 2020 12:00:42 +0630 Subject: [PATCH 3/3] default value receipt no detail customer filter --- app/models/sale.rb | 2 +- .../_shift_sale_report_filter.html.erb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 2a747067..1b9ae814 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1203,7 +1203,7 @@ end def self.get_shift_sales_by_receipt_no_detail(shift_sale_range, shift, from, to, payment_type, customer_filter) ## => left join -> show all sales although no orders - + puts customer_filter query = Sale.includes([:survey, :sale_payments]) .select("sales.*, SUM(sale_payments.payment_amount) AS payments_for_credits_amount") .select("dining_facilities.type AS table_type, dining_facilities.name AS table_name") 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 f2370451..56daeb30 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,7 +18,12 @@ - + +
+ + +
+ <% if defined? @payment_methods %>
@@ -31,11 +36,6 @@
<% end %> -
- - -
-