tax profiles

This commit is contained in:
Myat Zin Wai Maw
2020-01-16 10:05:45 +06:30
parent bad510c6b4
commit 676251a12c
14 changed files with 79 additions and 66 deletions

View File

@@ -1121,7 +1121,6 @@ $(function() {
exclusive_total = total_price * exclusive_tax; exclusive_total = total_price * exclusive_tax;
total_price = total_price + exclusive_total; total_price = total_price + exclusive_total;
} }
var fixed_total_price = parseFloat(total_price).toFixed(2); var fixed_total_price = parseFloat(total_price).toFixed(2);
var fixed_taxable_amount = parseFloat(taxable_amount).toFixed(2); var fixed_taxable_amount = parseFloat(taxable_amount).toFixed(2);
$('#total_tax').empty(); $('#total_tax').empty();

View File

@@ -1,5 +1,5 @@
class Api::OrdersController < Api::ApiController class Api::OrdersController < Api::ApiController
skip_before_action :authenticate # skip_before_action :authenticate
#Description #Description
# This API show current order details # This API show current order details
# Input Params - order_id # Input Params - order_id
@@ -72,7 +72,6 @@ class Api::OrdersController < Api::ApiController
@status = false @status = false
@message = "No Current Open Shift for This Employee" @message = "No Current Open Shift for This Employee"
else else
current_user = Employee.find(current_shift.employee_id)
if checkin_checkout_time(params[:booking_id]) if checkin_checkout_time(params[:booking_id])
table = DiningFacility.find(params[:table_id]) if params[:table_id].present? table = DiningFacility.find(params[:table_id]) if params[:table_id].present?
@@ -95,6 +94,24 @@ class Api::OrdersController < Api::ApiController
end end
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 #end extra time
Order.transaction do Order.transaction do
# begin # begin
@@ -102,12 +119,12 @@ class Api::OrdersController < Api::ApiController
@order.source = params[:order_source] @order.source = params[:order_source]
@order.order_type = params[:order_type] @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.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.guest = params[:guest_info]
@order.table_id = params[:table_id] # this is dining facilities's id @order.table_id = params[:table_id] # this is dining facilities's id
@order.new_booking = true @order.new_booking = true
@order.waiters = current_login_employee.name @order.waiters = @user.name
@order.employee_name = current_login_employee.name @order.employee_name = @user.name
@order.is_extra_time = is_extra_time @order.is_extra_time = is_extra_time
@order.extra_time = extra_time @order.extra_time = extra_time
@@ -125,7 +142,7 @@ class Api::OrdersController < Api::ApiController
if @status && @booking if @status && @booking
Order.process_order_queue(@order.order_id,@order.table_id,@order.source) Order.process_order_queue(@order.order_id,@order.table_id,@order.source)
if @order.source == 'app' 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
end end
if @order.table_id.to_i > 0 if @order.table_id.to_i > 0

View File

@@ -1,5 +1,4 @@
class Api::PaymentsController < Api::ApiController class Api::PaymentsController < Api::ApiController
skip_before_action :authenticate
#Payment by Invoice ID #Payment by Invoice ID
# Payment Method - [Cash | CreditNote | VISA | MASTER | etc..] # Payment Method - [Cash | CreditNote | VISA | MASTER | etc..]
@@ -28,23 +27,22 @@ class Api::PaymentsController < Api::ApiController
if !sale.nil? if !sale.nil?
@paid_amount = sale.grand_total @paid_amount = sale.grand_total
current_shift = ShiftSale.current_shift current_shift = ShiftSale.current_shift
current_login_employee =Employee.find(current_shift.employee_id) @shop =Shop.current_shop
@shop =Shop.find_by_shop_code(sale.shop_code)
@status,@message,@balance =check_security_code(sale,params) @status,@message,@balance =check_security_code(sale,params)
sale_items = SaleItem.get_all_sale_items(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id)
if @status if @status
sale_payment = SalePayment.new 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 if @status && @membership_data["status"] == true
sale_payment = SalePayment.new 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 for Paymal payment
card_balance_amount, transaction_ref = SaleAudit.getCardBalanceAmount(params[:sale_id]) card_balance_amount, transaction_ref = SaleAudit.getCardBalanceAmount(params[:sale_id])
rebate_amount = nil rebate_amount = nil
# For Cashier by Zone # For Cashier by Zone
bookings = Booking.find_by_sale_id(sale_id) 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? if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else else
@@ -165,10 +163,10 @@ class Api::PaymentsController < Api::ApiController
end end
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) sale = Sale.find_by_receipt_no(receipt_no)
@out = [] @out = []
action_by = current_login_employee.name action_by = @user.name
@status = true @status = true
@message = "" @message = ""
membership_setting = MembershipSetting.find_by_membership_type("paypar_url") 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) 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 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]}" 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 else
remark = "Payment by account no Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} | Remark : #{membership_data[:message]}" 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 end
@out = membership_data @out = membership_data
@@ -237,11 +235,9 @@ class Api::PaymentsController < Api::ApiController
end end
def check_security_code(sale,params) def check_security_code(sale,params)
current_shift = ShiftSale.current_shift current_shift = ShiftSale.current_shift
current_login_employee =Employee.find(current_shift.employee_id) membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",Shop.current_shop.shop_code)
@shop =Shop.find_by_shop_code(sale.shop_code)
membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",sale.shop_code)
if membership_setting.gateway_url 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 if member_actions.gateway_url
url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s
merchant_uid= member_actions.merchant_account_id merchant_uid= member_actions.merchant_account_id
@@ -292,68 +288,68 @@ class Api::PaymentsController < Api::ApiController
when "cash" when "cash"
sale_payment.payment_method = "cash" sale_payment.payment_method = "cash"
sale_payment.received_amount = params[:amount] 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" when "creditnote"
sale_payment.payment_method = "creditnote" sale_payment.payment_method = "creditnote"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.customer_id = params[:customer_id] 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" when "visa"
sale_payment.payment_method = "visa" sale_payment.payment_method = "visa"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.payment_reference = params[:payment_reference] 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" when "master"
sale_payment.payment_method = "master" sale_payment.payment_method = "master"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.payment_reference = params[:payment_reference] 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" when "jcb"
sale_payment.payment_method = "jcb" sale_payment.payment_method = "jcb"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.payment_reference = params[:payment_reference] 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" when "mpu"
sale_payment.payment_method = "mpu" sale_payment.payment_method = "mpu"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.payment_reference = params[:payment_reference] 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" when "unionpay"
sale_payment.payment_method = "unionpay" sale_payment.payment_method = "unionpay"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.payment_reference = params[:payment_reference] 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" when "vochure"
sale_payment.payment_method = "vochure" sale_payment.payment_method = "vochure"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.customer_id = params[:customer_id] sale_payment.customer_id = params[:customer_id]
sale_payment.payment_reference = params[:vochure_no] 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" when "giftcard"
sale_payment.payment_method = "giftcard" sale_payment.payment_method = "giftcard"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.customer_id = params[:customer_id] sale_payment.customer_id = params[:customer_id]
sale_payment.payment_reference = params[:giftcard_no] 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" when "paypar"
sale_payment.payment_method = "paypar" sale_payment.payment_method = "paypar"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.payment_reference = params[:payment_reference] sale_payment.payment_reference = params[:payment_reference]
#TODO: implement paypar implementation #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" when "JunctionPay"
sale_payment.payment_method = "JunctionPay" sale_payment.payment_method = "JunctionPay"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.customer_id = params[:customer_id] sale_payment.customer_id = params[:customer_id]
sale_payment.payment_reference = params[:vochure_no] 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" when "alipay"
sale_payment.payment_method = "alipay" sale_payment.payment_method = "alipay"
sale_payment.received_amount = params[:amount] sale_payment.received_amount = params[:amount]
sale_payment.payment_reference = params[:payment_reference] 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
end end
#get cloud domain #get cloud domain

View File

@@ -1,6 +1,4 @@
class Api::Restaurant::MenuController < Api::ApiController class Api::Restaurant::MenuController < Api::ApiController
skip_before_action :authenticate
#Description #Description
# Pull the default menu details and also other available (active) menus # Pull the default menu details and also other available (active) menus
# Input Params - order_id # Input Params - order_id

View File

@@ -1,6 +1,4 @@
class Api::Restaurant::MenuItemsController < Api::ApiController class Api::Restaurant::MenuItemsController < Api::ApiController
skip_before_action :authenticate
def index def index
end end

View File

@@ -1,7 +1,5 @@
class Api::ShopsController < Api::ApiController class Api::ShopsController < Api::ApiController
skip_before_action :authenticate
def index def index
@shops = Shop.select('id,logo,name,shop_code,address,phone_no').all @shops = Shop.select('id,logo,name,shop_code,address,phone_no').all
end end
@@ -9,4 +7,7 @@ class Api::ShopsController < Api::ApiController
def show def show
@shop = Shop.find_by_shop_code(params[:id]) @shop = Shop.find_by_shop_code(params[:id])
end end
def get_tax_profiles
@inclusive_tax,@exclusive_tax =TaxProfile.calculate_tax("online_order")
end
end end

View File

@@ -1,5 +1,4 @@
class Api::VerificationsController < Api::ApiController class Api::VerificationsController < Api::ApiController
skip_before_action :authenticate
def new def new
phone_number = params[:phone_number] phone_number = params[:phone_number]

View File

@@ -40,23 +40,7 @@ class Origami::QuickServiceController < ApplicationController
end end
end end
end end
divided_value =0 @inclusive_tax,@exclusive_tax =TaxProfile.calculate_tax("quick_service")
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
render "origami/addorders/detail" render "origami/addorders/detail"
end end

View File

@@ -15,13 +15,13 @@ class Booking < ApplicationRecord
sale_items = [] sale_items = []
proxy_association.load_target.select(&:order_items_id).each do |order_item| 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 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({ sale_items << SaleItem.new({
menu_category_name: menu_category.name, menu_category_name: menu_category.name,
menu_category_code: menu_category.code, menu_category_code: menu_category.code,
product_name: order_item.item_name, product_name: order_item.item_name,
product_code: order_item.item_code, product_code: order_item.item_code,
product_alt_name: order_item.alt_name, product_alt_name: alt_name,
account_id: order_item.account_id, account_id: order_item.account_id,
is_taxable: order_item.taxable, is_taxable: order_item.taxable,
item_instance_code: order_item.item_instance_code, item_instance_code: order_item.item_instance_code,
@@ -31,18 +31,19 @@ class Booking < ApplicationRecord
taxable_price: order_item.qty * order_item.price, taxable_price: order_item.qty * order_item.price,
status: order_item.remark status: order_item.remark
}) })
if order_item.set_menu_items if order_item.set_menu_items
JSON.parse(order_item.set_menu_items).each do |item| JSON.parse(order_item.set_menu_items).each do |item|
instance = MenuItemInstance.find_by_item_instance_code(item["item_instance_code"]) instance = MenuItemInstance.find_by_item_instance_code(item["item_instance_code"])
menu_item = instance.menu_item menu_item = instance.menu_item
menu_category = menu_item.menu_category #get menu category for menu items 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({ sale_items << SaleItem.new({
menu_category_name: menu_category.name, menu_category_name: menu_category.name,
menu_category_code: menu_category.code, menu_category_code: menu_category.code,
product_name: instance.item_instance_name, product_name: instance.item_instance_name,
product_code: menu_item.item_code, product_code: menu_item.item_code,
product_alt_name: menu_item.alt_name, product_alt_name: alt_name,
account_id: menu_item.account_id, account_id: menu_item.account_id,
is_taxable: menu_item.taxable, is_taxable: menu_item.taxable,
item_instance_code: item["item_instance_code"], item_instance_code: item["item_instance_code"],

View File

@@ -48,10 +48,10 @@ class Employee < ApplicationRecord
#Extend the login time each time authenticatation take place #Extend the login time each time authenticatation take place
user.session_expiry = user.session_expiry.utc + expiry_time.minutes user.session_expiry = user.session_expiry.utc + expiry_time.minutes
user.save user.save
return true return user
end end
elsif user = Employee.find_by_app_token(token) elsif user = Employee.find_by_app_token(token)
return true return user
end end
end end
return false return false

View File

@@ -159,7 +159,6 @@ class Sale < ApplicationRecord
}) })
end end
end end
puts sale.sale_items.to_json
sale.orders << booking.orders sale.orders << booking.orders
sale.customer_id = booking.orders[0].customer_id sale.customer_id = booking.orders[0].customer_id

View File

@@ -4,4 +4,21 @@ class TaxProfile < ApplicationRecord
default_scope { order('order_by asc') } default_scope { order('order_by asc') }
# validations # validations
validates_presence_of :name, :rate, :group_type 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 end

View File

@@ -0,0 +1,3 @@
json.status true
json.inclusive_tax @inclusive_tax
json.exclusive_tax @exclusive_tax

View File

@@ -46,6 +46,7 @@ scope "(:locale)", locale: /en|mm/ do
resources :shops, only: [:index, :show] resources :shops, only: [:index, :show]
resources :verifications, only: [:new] resources :verifications, only: [:new]
get 'get_tax_profiles' => "shops#get_tax_profiles"
post 'verifications/update' => "verifications#update" post 'verifications/update' => "verifications#update"
namespace :restaurant do namespace :restaurant do