From 676251a12cb84a2d924d2e689e5230539b2f61b7 Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Thu, 16 Jan 2020 10:05:45 +0630 Subject: [PATCH] tax profiles --- app/assets/javascripts/addorder.js | 1 - app/controllers/api/orders_controller.rb | 29 ++++++++--- app/controllers/api/payments_controller.rb | 48 +++++++++---------- .../api/restaurant/menu_controller.rb | 2 - .../api/restaurant/menu_items_controller.rb | 2 - app/controllers/api/shops_controller.rb | 5 +- .../api/verifications_controller.rb | 1 - .../origami/quick_service_controller.rb | 18 +------ app/models/booking.rb | 11 +++-- app/models/employee.rb | 4 +- app/models/sale.rb | 1 - app/models/tax_profile.rb | 17 +++++++ .../api/shops/get_tax_profiles.json.jbuilder | 3 ++ config/routes.rb | 3 +- 14 files changed, 79 insertions(+), 66 deletions(-) create mode 100644 app/views/api/shops/get_tax_profiles.json.jbuilder diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index ab5670ac..e21d9c4a 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -1121,7 +1121,6 @@ $(function() { exclusive_total = total_price * exclusive_tax; total_price = total_price + exclusive_total; } - var fixed_total_price = parseFloat(total_price).toFixed(2); var fixed_taxable_amount = parseFloat(taxable_amount).toFixed(2); $('#total_tax').empty(); diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 91798778..49a5c524 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -1,5 +1,5 @@ class Api::OrdersController < Api::ApiController - skip_before_action :authenticate + # skip_before_action :authenticate #Description # This API show current order details # Input Params - order_id @@ -72,7 +72,6 @@ class Api::OrdersController < Api::ApiController @status = false @message = "No Current Open Shift for This Employee" else - current_user = Employee.find(current_shift.employee_id) if checkin_checkout_time(params[:booking_id]) table = DiningFacility.find(params[:table_id]) if params[:table_id].present? @@ -95,6 +94,24 @@ class Api::OrdersController < Api::ApiController end end } + items_arr = [] + params[:order_items].each { |i| + i["item_instance_code"] = i["item_instance_code"].downcase.to_s + if i["item_instance_code"].include? "ext" + is_extra_time = true + arr_exts = i["item_instance_code"].split("_") + if arr_exts[1].match(/^(\d)+$/) + time = arr_exts[1].to_i*60*i["quantity"].to_i + extra_time = Time.at(time) + end + end + if i["parent_order_item_id"] + items = {"order_item_id": i,"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])} + else + items = {"order_item_id": i,"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]} + end + items_arr.push(items) + } #end extra time Order.transaction do # begin @@ -102,12 +119,12 @@ class Api::OrdersController < Api::ApiController @order.source = params[:order_source] @order.order_type = params[:order_type] @order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile - @order.items = params[:order_items] + @order.items = items_arr @order.guest = params[:guest_info] @order.table_id = params[:table_id] # this is dining facilities's id @order.new_booking = true - @order.waiters = current_login_employee.name - @order.employee_name = current_login_employee.name + @order.waiters = @user.name + @order.employee_name = @user.name @order.is_extra_time = is_extra_time @order.extra_time = extra_time @@ -125,7 +142,7 @@ class Api::OrdersController < Api::ApiController if @status && @booking Order.process_order_queue(@order.order_id,@order.table_id,@order.source) if @order.source == 'app' - @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) + @status, @sale = Sale.request_bill(@order,@user,@user) end end if @order.table_id.to_i > 0 diff --git a/app/controllers/api/payments_controller.rb b/app/controllers/api/payments_controller.rb index 4cb93784..444e7074 100755 --- a/app/controllers/api/payments_controller.rb +++ b/app/controllers/api/payments_controller.rb @@ -1,5 +1,4 @@ class Api::PaymentsController < Api::ApiController - skip_before_action :authenticate #Payment by Invoice ID # Payment Method - [Cash | CreditNote | VISA | MASTER | etc..] @@ -28,23 +27,22 @@ class Api::PaymentsController < Api::ApiController if !sale.nil? @paid_amount = sale.grand_total current_shift = ShiftSale.current_shift - current_login_employee =Employee.find(current_shift.employee_id) - @shop =Shop.find_by_shop_code(sale.shop_code) + @shop =Shop.current_shop @status,@message,@balance =check_security_code(sale,params) sale_items = SaleItem.get_all_sale_items(sale_id) if @status sale_payment = SalePayment.new - @status, @sale, @membership_data = sale_payment.process_payment(sale, current_login_employee, sale.grand_total, "paymal",params[:account_no]) + @status, @sale, @membership_data = sale_payment.process_payment(sale, @user, sale.grand_total, "paymal",params[:account_no]) if @status && @membership_data["status"] == true sale_payment = SalePayment.new - status = sale_payment.process_payment(sale, current_login_employee, 0, "cash") + status = sale_payment.process_payment(sale, @user, 0, "cash") #card_balance amount for Paymal payment card_balance_amount, transaction_ref = SaleAudit.getCardBalanceAmount(params[:sale_id]) rebate_amount = nil # For Cashier by Zone bookings = Booking.find_by_sale_id(sale_id) - shift = ShiftSale.current_open_shift(current_login_employee) + shift = ShiftSale.current_open_shift(@user) if !shift.nil? cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) else @@ -165,10 +163,10 @@ class Api::PaymentsController < Api::ApiController end end - def send_account_paymal(amount, account_no, receipt_no,current_login_employee) + def send_account_paymal(amount, account_no, receipt_no) sale = Sale.find_by_receipt_no(receipt_no) @out = [] - action_by = current_login_employee.name + action_by = @user.name @status = true @message = "" membership_setting = MembershipSetting.find_by_membership_type("paypar_url") @@ -182,10 +180,10 @@ class Api::PaymentsController < Api::ApiController membership_data = SalePayment.get_paypar_account_data(url,membership_setting.auth_token,merchant_uid,auth_token,account_no,amount,receipt_no) if membership_data["status"]==true remark = "Payment by account no Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Transaction ref: #{membership_data[:transaction_ref]} | Reload amount #{membership_data[:reload_amount]} | Old Balance Amount #{membership_data[:old_balance_amount]} | DateTime : #{membership_data[:date]}" - sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,current_login_employee.name, current_login_employee.name,remark,"PAYBYACCOUNT" ) + sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,@user.name, @user.name,remark,"PAYBYACCOUNT" ) else remark = "Payment by account no Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Remark : #{membership_data[:message]}" - sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,current_login_employee.name, current_login_employee.name,remark,"PAYBYACCOUNT" ) + sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,@user.name, @user.name,remark,"PAYBYACCOUNT" ) end @out = membership_data @@ -237,11 +235,9 @@ class Api::PaymentsController < Api::ApiController end def check_security_code(sale,params) current_shift = ShiftSale.current_shift - current_login_employee =Employee.find(current_shift.employee_id) - @shop =Shop.find_by_shop_code(sale.shop_code) - membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",sale.shop_code) + membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",Shop.current_shop.shop_code) if membership_setting.gateway_url - member_actions =MembershipAction.find_by_membership_type_and_shop_code("search_paypar_security_code",sale.shop_code) + member_actions =MembershipAction.find_by_membership_type_and_shop_code("search_paypar_security_code",Shop.current_shop.shop_code) if member_actions.gateway_url url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s merchant_uid= member_actions.merchant_account_id @@ -292,68 +288,68 @@ class Api::PaymentsController < Api::ApiController when "cash" sale_payment.payment_method = "cash" sale_payment.received_amount = params[:amount] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "creditnote" sale_payment.payment_method = "creditnote" sale_payment.received_amount = params[:amount] sale_payment.customer_id = params[:customer_id] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "visa" sale_payment.payment_method = "visa" sale_payment.received_amount = params[:amount] sale_payment.payment_reference = params[:payment_reference] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "master" sale_payment.payment_method = "master" sale_payment.received_amount = params[:amount] sale_payment.payment_reference = params[:payment_reference] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "jcb" sale_payment.payment_method = "jcb" sale_payment.received_amount = params[:amount] sale_payment.payment_reference = params[:payment_reference] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "mpu" sale_payment.payment_method = "mpu" sale_payment.received_amount = params[:amount] sale_payment.payment_reference = params[:payment_reference] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "unionpay" sale_payment.payment_method = "unionpay" sale_payment.received_amount = params[:amount] sale_payment.payment_reference = params[:payment_reference] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "vochure" sale_payment.payment_method = "vochure" sale_payment.received_amount = params[:amount] sale_payment.customer_id = params[:customer_id] sale_payment.payment_reference = params[:vochure_no] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "giftcard" sale_payment.payment_method = "giftcard" sale_payment.received_amount = params[:amount] sale_payment.customer_id = params[:customer_id] sale_payment.payment_reference = params[:giftcard_no] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "paypar" sale_payment.payment_method = "paypar" sale_payment.received_amount = params[:amount] sale_payment.payment_reference = params[:payment_reference] #TODO: implement paypar implementation - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "JunctionPay" sale_payment.payment_method = "JunctionPay" sale_payment.received_amount = params[:amount] sale_payment.customer_id = params[:customer_id] sale_payment.payment_reference = params[:vochure_no] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) when "alipay" sale_payment.payment_method = "alipay" sale_payment.received_amount = params[:amount] sale_payment.payment_reference = params[:payment_reference] - @status, @invoice = sale_payment.process_payment(sale_payment, current_login_employee) + @status, @invoice = sale_payment.process_payment(sale_payment, @user) end end #get cloud domain diff --git a/app/controllers/api/restaurant/menu_controller.rb b/app/controllers/api/restaurant/menu_controller.rb index 1aa6d1d2..ae9f7b12 100755 --- a/app/controllers/api/restaurant/menu_controller.rb +++ b/app/controllers/api/restaurant/menu_controller.rb @@ -1,6 +1,4 @@ class Api::Restaurant::MenuController < Api::ApiController - - skip_before_action :authenticate #Description # Pull the default menu details and also other available (active) menus # Input Params - order_id diff --git a/app/controllers/api/restaurant/menu_items_controller.rb b/app/controllers/api/restaurant/menu_items_controller.rb index 3dc6b394..307ab313 100644 --- a/app/controllers/api/restaurant/menu_items_controller.rb +++ b/app/controllers/api/restaurant/menu_items_controller.rb @@ -1,6 +1,4 @@ class Api::Restaurant::MenuItemsController < Api::ApiController - - skip_before_action :authenticate def index end diff --git a/app/controllers/api/shops_controller.rb b/app/controllers/api/shops_controller.rb index 486f86fa..b455784f 100644 --- a/app/controllers/api/shops_controller.rb +++ b/app/controllers/api/shops_controller.rb @@ -1,7 +1,5 @@ class Api::ShopsController < Api::ApiController - skip_before_action :authenticate - def index @shops = Shop.select('id,logo,name,shop_code,address,phone_no').all end @@ -9,4 +7,7 @@ class Api::ShopsController < Api::ApiController def show @shop = Shop.find_by_shop_code(params[:id]) end + def get_tax_profiles + @inclusive_tax,@exclusive_tax =TaxProfile.calculate_tax("online_order") + end end diff --git a/app/controllers/api/verifications_controller.rb b/app/controllers/api/verifications_controller.rb index 845c7bc4..1a1c1241 100644 --- a/app/controllers/api/verifications_controller.rb +++ b/app/controllers/api/verifications_controller.rb @@ -1,5 +1,4 @@ class Api::VerificationsController < Api::ApiController - skip_before_action :authenticate def new phone_number = params[:phone_number] diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index 8d176912..f9639865 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -40,23 +40,7 @@ class Origami::QuickServiceController < ApplicationController end end end - divided_value =0 - exclusive =0 - tax_profiles = TaxProfile.where(group_type: "quick_service") - if !tax_profiles.empty? - tax_profiles.each do |tax| - #include or execulive - if tax.inclusive - tax_incl_exec = "inclusive" - rate = tax.rate - divided_value += (100 + rate)/rate - else - exclusive +=tax.rate / 100 - end - end - end - @inclusive_tax =divided_value - @exclusive_tax =exclusive + @inclusive_tax,@exclusive_tax =TaxProfile.calculate_tax("quick_service") render "origami/addorders/detail" end diff --git a/app/models/booking.rb b/app/models/booking.rb index e3a8f6e3..5a65cd01 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -15,13 +15,13 @@ class Booking < ApplicationRecord sale_items = [] proxy_association.load_target.select(&:order_items_id).each do |order_item| menu_category = order_item.menu_category || OpenStruct.new(name: 'Product', code: '') #get menu category for menu items - + alt_name = order_item.alt_name.present? ? order_item.alt_name : '-' sale_items << SaleItem.new({ menu_category_name: menu_category.name, menu_category_code: menu_category.code, product_name: order_item.item_name, product_code: order_item.item_code, - product_alt_name: order_item.alt_name, + product_alt_name: alt_name, account_id: order_item.account_id, is_taxable: order_item.taxable, item_instance_code: order_item.item_instance_code, @@ -31,18 +31,19 @@ class Booking < ApplicationRecord taxable_price: order_item.qty * order_item.price, status: order_item.remark }) - if order_item.set_menu_items JSON.parse(order_item.set_menu_items).each do |item| instance = MenuItemInstance.find_by_item_instance_code(item["item_instance_code"]) menu_item = instance.menu_item menu_category = menu_item.menu_category #get menu category for menu items + alt_name = menu_item.alt_name.present? ? menu_item.alt_name : '-' + puts alt_name sale_items << SaleItem.new({ menu_category_name: menu_category.name, menu_category_code: menu_category.code, product_name: instance.item_instance_name, product_code: menu_item.item_code, - product_alt_name: menu_item.alt_name, + product_alt_name: alt_name, account_id: menu_item.account_id, is_taxable: menu_item.taxable, item_instance_code: item["item_instance_code"], @@ -52,8 +53,8 @@ class Booking < ApplicationRecord taxable_price: item["quantity"].to_f * item["price"].to_f }) end - end end + end sale_items end end diff --git a/app/models/employee.rb b/app/models/employee.rb index 3081b036..5532b11d 100755 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -48,10 +48,10 @@ class Employee < ApplicationRecord #Extend the login time each time authenticatation take place user.session_expiry = user.session_expiry.utc + expiry_time.minutes user.save - return true + return user end elsif user = Employee.find_by_app_token(token) - return true + return user end end return false diff --git a/app/models/sale.rb b/app/models/sale.rb index ab929296..a5ba30ac 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -159,7 +159,6 @@ class Sale < ApplicationRecord }) end end - puts sale.sale_items.to_json sale.orders << booking.orders sale.customer_id = booking.orders[0].customer_id diff --git a/app/models/tax_profile.rb b/app/models/tax_profile.rb index 5ae936ba..e561b4e5 100755 --- a/app/models/tax_profile.rb +++ b/app/models/tax_profile.rb @@ -4,4 +4,21 @@ class TaxProfile < ApplicationRecord default_scope { order('order_by asc') } # validations validates_presence_of :name, :rate, :group_type + def self.calculate_tax(group_type) + divided_value =0.0 + exclusive =0.0 + tax_profiles = TaxProfile.where(group_type: group_type) + if !tax_profiles.empty? + tax_profiles.each do |tax| + #include or execulive + if tax.inclusive + rate = tax.rate + divided_value += (100 + rate)/rate + else + exclusive +=tax.rate / 100 + end + end + end + return divided_value,exclusive + end end diff --git a/app/views/api/shops/get_tax_profiles.json.jbuilder b/app/views/api/shops/get_tax_profiles.json.jbuilder new file mode 100644 index 00000000..89da4ab0 --- /dev/null +++ b/app/views/api/shops/get_tax_profiles.json.jbuilder @@ -0,0 +1,3 @@ +json.status true +json.inclusive_tax @inclusive_tax +json.exclusive_tax @exclusive_tax diff --git a/config/routes.rb b/config/routes.rb index b9f592d8..79de27da 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,6 +46,7 @@ scope "(:locale)", locale: /en|mm/ do resources :shops, only: [:index, :show] resources :verifications, only: [:new] + get 'get_tax_profiles' => "shops#get_tax_profiles" post 'verifications/update' => "verifications#update" namespace :restaurant do @@ -432,7 +433,7 @@ scope "(:locale)", locale: /en|mm/ do resources :display_images end #employees - resources :employees + resources :employees get '/:id/change_app_token' => 'employees#change_app_token', as: 'change_app_token' #menu