tax profiles
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user