diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb index 0baa258a..7b60f7cc 100644 --- a/app/controllers/api/check_in_process_controller.rb +++ b/app/controllers/api/check_in_process_controller.rb @@ -1,5 +1,19 @@ class Api::CheckInProcessController < Api::ApiController + def check_in_time + if params[:dining_id] + dining_facility = DiningFacility.find(params[:dining_id]) + booking = dining_facility.get_booking + if !booking.nil? + check_in_time = booking.checkin_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") + check_out_time = booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") + render :json => { :status => true, :check_in_time => check_in_time, :check_out_time => check_out_time } + else + render :json => { :status => false, :error_message => "No current booking!" } + end + end + end + def check_in_process if params[:dining_id] dining_facility = DiningFacility.find(params[:dining_id]) diff --git a/app/controllers/settings/set_menu_items_controller.rb b/app/controllers/settings/set_menu_items_controller.rb index 1fbeb148..c460c362 100755 --- a/app/controllers/settings/set_menu_items_controller.rb +++ b/app/controllers/settings/set_menu_items_controller.rb @@ -141,6 +141,6 @@ class Settings::SetMenuItemsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_menu_item_params - params.require(:set_menu_item).permit(:item_code, :name, :alt_name, :type, :image_path, :menu_category_id,:account_id , :item_attributes, :item_options, :min_qty, :is_sub_item, :is_available, :created_by, :item_sets, :unit) + params.require(:set_menu_item).permit(:item_code, :name, :alt_name, :type, :image_path, :menu_category_id,:account_id , :item_attributes, :item_options, :min_qty, :is_sub_item, :is_available, :created_by, :item_sets, :unit, :taxable) end end diff --git a/app/controllers/settings/simple_menu_items_controller.rb b/app/controllers/settings/simple_menu_items_controller.rb index 35af3b83..9a7c46db 100755 --- a/app/controllers/settings/simple_menu_items_controller.rb +++ b/app/controllers/settings/simple_menu_items_controller.rb @@ -157,6 +157,6 @@ class Settings::SimpleMenuItemsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_menu_item_params - params.require(:simple_menu_item).permit(:item_code, :name, :alt_name, :type, :image_path, :menu_category_id, :account_id, :item_attributes, :item_options, :min_qty, :is_sub_item, :is_available, :created_by, :item_sets, :unit) + params.require(:simple_menu_item).permit(:item_code, :name, :alt_name, :type, :image_path, :menu_category_id, :account_id, :item_attributes, :item_options, :min_qty, :is_sub_item, :is_available, :created_by, :item_sets, :unit, :taxable) end end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 9bfcdb85..67a3c823 100755 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -13,7 +13,7 @@ class MenuItem < ApplicationRecord has_many :menu_item_sets has_many :item_sets, through: :menu_item_sets - validates_presence_of :item_code, :name, :type, :min_qty, :taxable,:account_id + validates_presence_of :item_code, :name, :type, :min_qty,:account_id validates_uniqueness_of :item_code default_scope { order('item_code asc') } diff --git a/app/models/order.rb b/app/models/order.rb index dd6f6d66..ba8adc8f 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -133,7 +133,7 @@ class Order < ApplicationRecord OrderItem.processs_item(menu_item[:item_code], item[:item_instance_code], menu_item[:name], menu_item[:alt_name], menu_item[:account_id], item[:quantity],menu_item[:price], item[:options], set_order_items, self.id, - self.employee_name) + self.employee_name, menu_item[:taxable]) #end end diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 12c8c378..776bb94c 100755 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -20,7 +20,7 @@ class OrderItem < ApplicationRecord # option_values : [], # sub_order_items : [], # } - def self.processs_item (item_code, instance_code, menu_name, alt_name, account_id, qty,price, options, set_menu_items, order_id, item_order_by) + def self.processs_item (item_code, instance_code, menu_name, alt_name, account_id, qty,price, options, set_menu_items, order_id, item_order_by, taxable) orderitem = OrderItem.create do |oitem| oitem.order_id = order_id @@ -31,6 +31,7 @@ class OrderItem < ApplicationRecord oitem.account_id = account_id oitem.qty = qty oitem.price = price + oitem.taxable = taxable oitem.options = options oitem.set_menu_items = set_menu_items oitem.item_order_by = item_order_by #person who order this. * If emenu - it will be login user on the app diff --git a/app/models/sale.rb b/app/models/sale.rb index 9e29e0b8..01cd2a28 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -225,7 +225,11 @@ class Sale < ApplicationRecord puts "item.sales_item_id ddd" puts item.sale_item_id subtotal_price = subtotal_price + item.price - total_taxable = total_taxable + item.taxable_price + + # only calc tax when true + if(item.is_taxable) + total_taxable = total_taxable + item.taxable_price + end # total_taxable = total_taxable + (item.taxable_price * item.qty) end @@ -287,7 +291,11 @@ class Sale < ApplicationRecord if item.remark != 'void' && item.remark != 'foc' #compute each item and added to total subtotal_price = subtotal_price + item.price - total_taxable = total_taxable + item.price + + # only calc tax when true + if(item.is_taxable) + total_taxable = total_taxable + item.taxable_price + end end end diff --git a/app/views/api/orders/view_orders.json.jbuilder b/app/views/api/orders/view_orders.json.jbuilder index b2c960af..0ac1b92f 100755 --- a/app/views/api/orders/view_orders.json.jbuilder +++ b/app/views/api/orders/view_orders.json.jbuilder @@ -19,6 +19,13 @@ if (@booking) @total_amount = 0.00 @total_tax = 0.00 + # For YGN BBQ + adult_count = 0 + child_count = 0 + adult_spent = 0 + child_spent = 0 + # End YGN BBQ + if @booking.booking_orders order_items = [] @booking.booking_orders.each do |bo| @@ -26,21 +33,45 @@ if (@booking) if (order.status == "new") order_items = order_items + order.order_items end - end + end json.order_items order_items do |item| - json.item_instance_code item.item_code - json.item_name item.item_name - json.price item.price - json.qty item.qty - json.options item.options - json.remark item.remark - json.item_status item.order_item_status - @total_amount = @total_amount + (item.price * item.qty) + # For YGN BBQ + if item.item_code == "P00001" + adult_count += item.qty + adult_spent += (item.price * item.qty) + end + if item.item_code == "P00002" + child_count += item.qty + child_spent += (item.price * item.qty) + end + # End YGN BBQ + json.item_code item.item_code + json.item_instance_code item.item_instance_code + json.item_name item.item_name + json.price item.price + json.qty item.qty + json.options item.options + json.remark item.remark + json.item_status item.order_item_status + @total_amount = @total_amount + (item.price * item.qty) end end + # For YGN BBQ + if adult_count > 0 + json.per_adult_spent (adult_spent/adult_count) * 0.05 + else + json.per_adult_spent 0 + end + if child_count > 0 + json.per_child_spent (child_spent/child_count) * 0.05 + else + json.per_child_spent 0 + end + # End YGN BBQ + json.sub_total @total_amount json.commerical_tax @total_amount * 0.05 json.total @total_amount + (@total_amount * 0.05) diff --git a/app/views/settings/set_menu_items/_form.html.erb b/app/views/settings/set_menu_items/_form.html.erb index 31a31c15..0f8eed54 100755 --- a/app/views/settings/set_menu_items/_form.html.erb +++ b/app/views/settings/set_menu_items/_form.html.erb @@ -16,6 +16,8 @@ <%= f.input :is_available,:input_html => {:class => "col-md-9"} %> + <%= f.input :taxable,:input_html => {:class => "col-md-9"} %> + <%= f.input :is_sub_item,:input_html => {:class => "col-md-9"} %> <%= f.input :unit, :collection => Lookup.collection_of("unit") ,:input_html => {:class => "col-md-9"} %> diff --git a/app/views/settings/simple_menu_items/_form.html.erb b/app/views/settings/simple_menu_items/_form.html.erb index ff143e46..39932bdd 100755 --- a/app/views/settings/simple_menu_items/_form.html.erb +++ b/app/views/settings/simple_menu_items/_form.html.erb @@ -16,6 +16,8 @@ <%= f.input :is_available,:input_html => {:class => "col-md-9"} %> + <%= f.input :taxable,:input_html => {:class => "col-md-9"} %> + <%= f.input :is_sub_item,:input_html => {:class => "col-md-9"} %> <%= f.input :unit, :collection => Lookup.collection_of("unit") ,:input_html => {:class => "col-md-9"} %> diff --git a/config/routes.rb b/config/routes.rb index 1bdc2291..93fe22e2 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,7 +68,8 @@ scope "(:locale)", locale: /en|mm/ do end namespace :origami do - post "check_in/:dining_id" => "check_in_process#check_in_process" + get "check_in/:dining_id" => "check_in_process#check_in_time" + post "check_in" => "check_in_process#check_in_process" post "request_time" => "check_in_process#request_time" post "call_waiter" => "call_waiters#index" end diff --git a/db/seeds.rb b/db/seeds.rb index 03c2fb5b..8e0240be 100755 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -130,13 +130,17 @@ food = Account.create({title: "Food", account_type: "0"}) beverage = Account.create({title: "Beverage", account_type: "1"}) product = Account.create({title: "Product", account_type: "2"}) +# YGN BBQ +person = Account.create({title: "Person", account_type: "3"}) +# END + #Default Menu Options menu_options = MenuItemOption.create([{option_type: "Spicy", name: "Less Spicy", value: "less_spicy"},{option_type: "Spicy", name: "Spicy", value: "spicy"},{option_type: "Spicy", name: "Super Spicy", value: "super_spicy"}]) menu_options = MenuItemOption.create([{option_type: "Oil", name: "Less Oil", value: "less_oil"},{name: "No MSG", value: "no_msg"},{option_type: "Sweet", name: "Less Sweet", value: "less_sweet"}]) menu_pkg_options = MenuItemOption.create([{option_type: "Package", name: "Bottle", value: "Bottle"},{option_type: "Package", name: "Can", value: "can"}]) # #Default Menu Category - menu_category1 = MenuCategory.create({menu: menu, code:"C001", name: "Soup Base", alt_name: "Soup_base", order_by: 1, is_available: 1, created_by: "SYSTEM DEFAULT"}) + menu_category1 = MenuCategory.create({menu: menu, code:"C001", name: "Person", alt_name: "Person", order_by: 1, is_available: 1, created_by: "SYSTEM DEFAULT"}) # menu_category2 = MenuCategory.create({menu: menu, code:"C005", name: "Beef & Mutton", alt_name: "Beef_and_mutton", order_by: 2,created_by: "SYSTEM DEFAULT"}) # menu_category3 = MenuCategory.create({menu: menu, code:"C006", name: "Pork", alt_name: "Pork", order_by: 3,created_by: "SYSTEM DEFAULT"}) # menu_category4 = MenuCategory.create({menu: menu, code:"C006", name: "Chicken", alt_name: "Chicken", order_by: 1, menu_category_id: menu_category3.id, created_by: "SYSTEM DEFAULT"}) @@ -154,6 +158,17 @@ menu_pkg_options = MenuItemOption.create([{option_type: "Package", name: "Bottle # menu_category2_menu_item1 = SimpleMenuItem.create({item_code:"I008", name: "Default Menu Item Name 1", alt_name: "Alternate Menu Item Name 1",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 2 , account: food}) # menu_category2_menu_item2 = SimpleMenuItem.create({item_code:"I009", name: "Default Menu Item Name 2", alt_name: "Alternate Menu Item Name 2",menu_category: menu_category2 , min_selectable_item: 1, max_selectable_item:1, min_qty: 3 , account: food}) +# YGN BBQ +menu_item_attribute_adult = MenuItemAttribute.create({attribute_type:"person", name: "Adult", value: "adult"}) +menu_item_attribute_child = MenuItemAttribute.create({attribute_type:"person", name: "Child", value: "child"}) + + menu_category1_menu_item0 = SimpleMenuItem.create({item_code:"P00001", name: "Adult", alt_name: "",menu_category: menu_category1 , min_qty: 1, account: person, :item_attributes => "['1']", created_by: "System" }) + menu_item0_instance = MenuItemInstance.create({item_instance_name:"",item_instance_code:"PI0001", menu_item: menu_category1_menu_item0, price:15000.00, is_on_promotion:false, is_default:true, :item_attributes => "['1']" }) + + menu_category1_menu_item1 = SimpleMenuItem.create({item_code:"P00002", name: "Child", alt_name: "",menu_category: menu_category1 , min_qty: 1, account: person, :item_attributes => "['2']", created_by: "System" }) + menu_item1_instance = MenuItemInstance.create({item_instance_name:"",item_instance_code:"PI0002", menu_item: menu_category1_menu_item1, price:10000.00, is_on_promotion:false, is_default:true, :item_attributes => "['2']" }) +# END + menu_item_attribute_size_small = MenuItemAttribute.create({attribute_type:"size", name: "Small", value: "small"}) menu_item_attribute_size_medium = MenuItemAttribute.create({attribute_type:"size",name: "Medium", value: "medium"}) menu_item_attribute_size_large = MenuItemAttribute.create({attribute_type:"size", name: "Large", value: "large"})