From 6b49e045896388068728a3e23d3861c3a7339fbf Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 13 Dec 2017 15:37:05 +0630 Subject: [PATCH 1/3] clean seed --- db/seeds.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 8e0240be..79aab88f 100755 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -131,7 +131,7 @@ 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"}) +# person = Account.create({title: "Person", account_type: "3"}) # END #Default Menu Options @@ -140,7 +140,7 @@ menu_options = MenuItemOption.create([{option_type: "Oil", name: "Less Oil", val 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: "Person", alt_name: "Person", 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"}) @@ -159,14 +159,14 @@ menu_pkg_options = MenuItemOption.create([{option_type: "Package", name: "Bottle # 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_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_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']" }) + # 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"}) @@ -193,7 +193,7 @@ close_cashier_printer=PrintSetting.create({name: "Close Cashier", unique_code: " crm_order_printer=PrintSetting.create({name: "CRM Order", unique_code: "CrmOrderPdf", printer_name: "Cashier", precision: "0", delimiter: 0, heading_space: 5, page_width: 210, page_height: 1450}) queue_no_printer=PrintSetting.create({name: "Queue No", unique_code: "QueueNoPdf", printer_name: "Cashier", precision: "0", delimiter: 0, heading_space: 5, page_width: 210, page_height: 1450}) -cashier_terminal = CashierTerminal.create({name:"Terminal 1", printer_name: "Cashier"}) +# cashier_terminal = CashierTerminal.create({name:"Terminal 1", printer_name: "Cashier"}) zone = Zone.create({id:1, name: "H1", is_active:true, created_by: "SYSTEM DEFAULT"}) @@ -219,13 +219,13 @@ payment_methods = PaymentMethodSetting.create({payment_method:"Master",gateway_u payment_methods = PaymentMethodSetting.create({payment_method:"Redeem",gateway_url: "http://membership.paypar.ws",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv"}) #Default Order Queue stations -order_queue_station1 = OrderQueueStation.create({station_name: "K1", is_active: true,printer_name: "Cashier", processing_items: JSON.generate(['01001','01002','01003','01004']), print_copy:true, cut_per_item: false, use_alternate_name: false, created_by: "SYSTEM DEFAULT"}) -order_queue_station2 = OrderQueueStation.create({station_name: "K2", is_active: false,printer_name: "Cashier", processing_items: JSON.generate(['02005','02006','02007','02008']), print_copy:true, cut_per_item: true, use_alternate_name: true, created_by: "SYSTEM DEFAULT"}) -zone_order_queue_station = OrderQueueStation.create({station_name: "K3", is_active: false, printer_name: "Cashier", processing_items: JSON.generate(['01001','01002','01003','01004','02005','02006','02007','02008']), print_copy: true, cut_per_item: true, use_alternate_name: false, created_by: "SYSTEM DEFAULT"}) +# order_queue_station1 = OrderQueueStation.create({station_name: "K1", is_active: true,printer_name: "Cashier", processing_items: JSON.generate(['01001','01002','01003','01004']), print_copy:true, cut_per_item: false, use_alternate_name: false, created_by: "SYSTEM DEFAULT"}) +# order_queue_station2 = OrderQueueStation.create({station_name: "K2", is_active: false,printer_name: "Cashier", processing_items: JSON.generate(['02005','02006','02007','02008']), print_copy:true, cut_per_item: true, use_alternate_name: true, created_by: "SYSTEM DEFAULT"}) +# zone_order_queue_station = OrderQueueStation.create({station_name: "K3", is_active: false, printer_name: "Cashier", processing_items: JSON.generate(['01001','01002','01003','01004','02005','02006','02007','02008']), print_copy: true, cut_per_item: true, use_alternate_name: false, created_by: "SYSTEM DEFAULT"}) # QueueStationZone -zone_queue_station1 = OrderQueueProcessByZone.create({order_queue_station: order_queue_station1, zone: zone}) -zone_queue_station2 = OrderQueueProcessByZone.create({order_queue_station: order_queue_station2, zone: zone}) -zone_queue_station3 = OrderQueueProcessByZone.create({order_queue_station: zone_order_queue_station, zone: zone}) +# zone_queue_station1 = OrderQueueProcessByZone.create({order_queue_station: order_queue_station1, zone: zone}) +# zone_queue_station2 = OrderQueueProcessByZone.create({order_queue_station: order_queue_station2, zone: zone}) +# zone_queue_station3 = OrderQueueProcessByZone.create({order_queue_station: zone_order_queue_station, zone: zone}) puts " Finished System Default Set Up Data" From 211db16311b376966311addb862afacf5912479b Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 13 Dec 2017 15:58:44 +0630 Subject: [PATCH 2/3] add channel for checkin process --- app/assets/javascripts/channels/checkin.js | 25 ++++++++++++++++++++++ app/channels/checkin_channel.rb | 10 +++++++++ app/controllers/base_origami_controller.rb | 5 +++++ app/controllers/home_controller.rb | 2 +- app/jobs/checkin_job.rb | 10 +++++++++ app/models/dining_facility.rb | 22 +++++++++++++++++++ app/models/sale.rb | 6 +++--- spec/jobs/checkin_job_spec.rb | 5 +++++ 8 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/channels/checkin.js create mode 100644 app/channels/checkin_channel.rb create mode 100644 app/jobs/checkin_job.rb create mode 100644 spec/jobs/checkin_job_spec.rb diff --git a/app/assets/javascripts/channels/checkin.js b/app/assets/javascripts/channels/checkin.js new file mode 100644 index 00000000..859cb733 --- /dev/null +++ b/app/assets/javascripts/channels/checkin.js @@ -0,0 +1,25 @@ +App.order = App.cable.subscriptions.create('CheckinChannel', { +// App.messages = App.cable.subscriptions.create('MessagesChannel', { + + connected: function() {}, + + disconnected: function() {}, + + received: function(data) { + if((data.table != undefined) && (data.table.length > 0)){ + $.each(data.table,function(key,value){ + if($('.table_'+value.table_id).hasClass('blue')){ + $('.table_'+value.table_id).removeClass('blue'); + $('.table_'+value.table_id).addClass('orange'); + } + else if($('.table_'+value.table_id).hasClass('red')){ + $('.table_'+value.table_id).removeClass('red'); + $('.table_'+value.table_id).addClass('orange'); + } + $('.new_text_'+value.table_id).removeClass('hide'); + }); + + } + } +}); + diff --git a/app/channels/checkin_channel.rb b/app/channels/checkin_channel.rb new file mode 100644 index 00000000..c2e78132 --- /dev/null +++ b/app/channels/checkin_channel.rb @@ -0,0 +1,10 @@ +class CheckinChannel < ApplicationCable::Channel + def subscribed + stream_from "checkin_channel" + end + + def unsubscribed + stop_all_streams + # Any cleanup needed when channel is unsubscribed + end +end diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index 979fdf02..f9688235 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -2,6 +2,8 @@ class BaseOrigamiController < ActionController::Base include LoginVerification layout "origami" + before_action :checkin_process + #before_action :check_installation protect_from_forgery with: :exception rescue_from CanCan::AccessDenied do |exception| @@ -13,4 +15,7 @@ class BaseOrigamiController < ActionController::Base @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] end + def checkin_process + CheckinJob.set(wait: 30.seconds).perform_later() + end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 35308c5f..64a6c587 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -72,7 +72,7 @@ class HomeController < ApplicationController @hourly_sales = Sale.hourly_sales(today).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) - @employee_sales = Sale.employee_sales(today).sum(:grand_total) + @employee_sales = Sale.employee_sales(today).sum('total_amount') @inventories = StockJournal.inventory_balances(today).sum(:balance) @total_sale = Sale.total_sale(today) diff --git a/app/jobs/checkin_job.rb b/app/jobs/checkin_job.rb new file mode 100644 index 00000000..3a0d329f --- /dev/null +++ b/app/jobs/checkin_job.rb @@ -0,0 +1,10 @@ +class CheckinJob < ApplicationJob + queue_as :default + + def perform() + table = DiningFacility.get_checkin_booking + ActionCable.server.broadcast "checkin_channel",table: table + end + + +end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 9948ec48..d3e05582 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -96,4 +96,26 @@ class DiningFacility < ApplicationRecord end end end + + def self.get_checkin_booking + bookings = Booking.where("booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and reserved_by is not null and checkout_by is null") + arr_booking = Array.new + if bookings + bookings.each do |booking| + now = Time.now.utc.getlocal + hr = (now.strftime("%H").to_i).to_int + min = (now.strftime("%M").to_i).to_int + if !booking.checkout_at.nil? + checkout_at = booking.checkout_at.utc.getlocal + checkout_at_hr = (checkout_at.strftime("%H").to_i).to_int + checkout_at_min = (checkout_at.strftime("%M").to_i).to_int + checkout_at_min -= min + if (checkout_at_hr <= hr) && (checkout_at_min <= 15) + arr_booking.push({'table_id' => booking.dining_facility_id}) + end + end + end + end + return arr_booking + end end diff --git a/app/models/sale.rb b/app/models/sale.rb index fbd63076..ecebfe67 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -979,11 +979,11 @@ end def self.hourly_sales(today) query= Sale.select("grand_total") .where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) - .group("date_format(receipt_date, '%I %p')") + .group("date_format(convert_tz(receipt_date,'+00:00','+06:30'), '%I:%p')") end def self.employee_sales(today) - query = Sale.select("e.name as employee_name,grand_total") + query = Sale.select("e.name as employee_name,(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE sp.payment_amount END) as total_amount") .where('sales.payment_status="paid" and sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) .joins("join employees e on e.id=sales.cashier_id") .joins("join sale_payments sp on sp.sale_id=sales.sale_id") @@ -1102,7 +1102,7 @@ end .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) .group("a.product_code") - .order("SUM(a.price) DESC") + .order("SUM(a.qty) DESC") .first() end diff --git a/spec/jobs/checkin_job_spec.rb b/spec/jobs/checkin_job_spec.rb new file mode 100644 index 00000000..80f4ac0e --- /dev/null +++ b/spec/jobs/checkin_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CheckinJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From 974c5df83094ed62933ce631c76a98fd80a08964 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 13 Dec 2017 18:29:07 +0630 Subject: [PATCH 3/3] is taxable for other charges --- .../origami/other_charges_controller.rb | 2 +- .../origami/other_charges/index.html.erb | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index ae3d1073..51a1f7db 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -37,7 +37,7 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.qty = 1 sale_item.unit_price = di["price"] sale_item.taxable_price = di["price"] * 1 - sale_item.is_taxable = 1 + sale_item.is_taxable = di["is_taxable"] sale_item.account_id = 0 sale_item.price = di["price"] * 1 diff --git a/app/views/origami/other_charges/index.html.erb b/app/views/origami/other_charges/index.html.erb index 5b677d3e..0317d120 100755 --- a/app/views/origami/other_charges/index.html.erb +++ b/app/views/origami/other_charges/index.html.erb @@ -8,7 +8,7 @@
ORDER DETAILS
-->
-
+

Receipt No: <%=@sale_data.receipt_no rescue ' '%>

@@ -95,12 +95,16 @@
-
+
-
+
-
+
+
+ + Is Taxable +
@@ -199,7 +203,7 @@