From a97b6bff3f84e217726a3117f7c13bd1e1a4c9ba Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Thu, 24 Aug 2023 10:40:31 +0630 Subject: [PATCH] fix foodcourt sales transaction --- Gemfile | 6 +- app/assets/javascripts/addorder.js | 16 ++- app/assets/javascripts/foodcourt/addorder.js | 29 +++-- .../foodcourt/addorders_controller.rb | 112 +++++++--------- .../foodcourt/food_court_controller.rb | 60 +++++---- .../foodcourt/orders_controller.rb | 53 ++++---- .../foodcourt/paymal_controller.rb | 30 ++++- .../foodcourt/second_display_controller.rb | 27 ++-- app/controllers/foodcourt/void_controller.rb | 78 ++--------- app/jobs/order_queue_processor_job.rb | 12 +- app/jobs/print_order_queue_job.rb | 14 ++ app/jobs/print_receipt_job.rb | 49 +++++++ app/models/booking.rb | 7 +- app/models/dining_facility.rb | 7 +- app/models/order_queue_station.rb | 103 +++------------ app/models/printer/receipt_printer.rb | 1 - .../foodcourt/addorders/create.json.jbuilder | 5 +- app/views/foodcourt/addorders/detail.html.erb | 121 +++++++----------- .../foodcourt/orders/app_orders.html.erb | 15 ++- app/views/foodcourt/payments/show.html.erb | 63 +++------ config/sidekiq.yml | 1 - ...822085103_add_index_sale_id_on_bookings.rb | 5 + 22 files changed, 361 insertions(+), 453 deletions(-) create mode 100644 app/jobs/print_order_queue_job.rb create mode 100644 app/jobs/print_receipt_job.rb create mode 100644 db/migrate/20230822085103_add_index_sale_id_on_bookings.rb diff --git a/Gemfile b/Gemfile index fb35e5aa..9a1b2f0f 100644 --- a/Gemfile +++ b/Gemfile @@ -42,6 +42,8 @@ gem 'material_icons' gem 'font-awesome-rails', '~> 4.7', '>= 4.7.0.2' gem 'rack-cors' +gem 'sidekiq' + # Multi-tenancy for shops gem 'acts_as_tenant' @@ -51,7 +53,6 @@ gem 'mini_magick' gem 'jquery-fileupload-rails', '~> 0.4.7' #Report and Printing gems - gem 'cups', '~> 0.0.7' gem 'prawn' @@ -82,7 +83,6 @@ gem 'jbuilder', '~> 2.5' gem 'bcrypt', '~> 3.1.7' gem 'aescrypt' -gem 'sidekiq' gem 'whenever', :require => false # XML parser @@ -145,4 +145,4 @@ gem 'momentjs-rails' # for date-range selector # gem 'select2-rails' # for multi-select and auto-complete select box gem "chartkick" #chart lib gem 'myanmar-tools' -gem 'rabbit-mm' \ No newline at end of file +gem 'rabbit-mm' diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 36b5026f..6be6fb7c 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -563,7 +563,7 @@ $(function() { $(document).on('click', '.add_icon', function(event){ if (window.location.pathname.includes('out_of_stock') == false) { - + if($(this).hasClass('product_item')) { $('.sx_item_detailModal').modal('hide'); @@ -1168,10 +1168,12 @@ $(function() { data: params, dataType: "json", success: function(result){ - if (type == "quick_service" || type=="food_court") { - module_name = window.location.href.includes('foodcourt') ? 'foodcourt' : 'origami' - window.location.href = "/"+module_name+"/"+type; - }else{ + booking_id = result.booking_id; + if (type == "quick_service") { + window.location.href = "/origami/quick_service"; + } else if (type=="food_court") { + window.location.href = "/foodcourt/app_orders?pending_id=" + booking_id; + } else { if(table_type == "Table"){ window.location.href = "/origami/table/" + table_id; } @@ -1195,7 +1197,7 @@ $(function() { // Pay Discount for Payment // $("#create_pay_order").on('click', function(e){ - + // $(this).prop("disabled", true); // $("#create_order").prop("disabled", true); // $("#read_modal").attr('data-for', 'member'); @@ -1716,7 +1718,7 @@ $(function() { menu_insta = ''; $(instances).each(function(i){ - if (!instances[i].out_of_stock) { //instances[i].is_default === true && + if (!instances[i].out_of_stock) { //instances[i].is_default === true && code = instances[i].code; name = instances[i].name; price = parseFloat(instances[i].price).toFixed(2); diff --git a/app/assets/javascripts/foodcourt/addorder.js b/app/assets/javascripts/foodcourt/addorder.js index 02f4b6ca..28e8e6b2 100644 --- a/app/assets/javascripts/foodcourt/addorder.js +++ b/app/assets/javascripts/foodcourt/addorder.js @@ -63,7 +63,8 @@ function member_card(cardNo) { var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "", 'table_id': table_id, - 'order_items': order_items,'sale_id': sale_id,'create_type': "create_pay" }; + 'order_items': order_items, 'sale_id': sale_id, 'create_type': "create_pay" }; + if (booking_id.length > 0) { params.booking_id = booking_id; } @@ -72,20 +73,17 @@ function member_card(cardNo) { url: ajax_url, data: params, dataType: "json", - success:function(result){ - if (result.data == 'OK'){ - request_bill(g_membership_id, g_customer_id, g_customer_name); - }else{ - if (result.data["sale_id"]){ - update_sale(g_membership_id, g_customer_id, g_customer_name,result.data["sale_id"]); - } + success:function(result) { + if (result.sale_id) { + sale_id = result.sale_id; + window.location.href = '/foodcourt/sale/'+sale_id+'/food_court/payment/'; } } }); - }else if($('.btn').is('#pay')){ - update_sale(g_membership_id, g_customer_id, g_customer_name,$('#sale_id').text()); - } - else{ + } else if($('.btn').is('#pay')){ + sale_id = $('#sale_id').text(); + window.location.href = '/foodcourt/sale/'+sale_id+'/food_court/payment/'; + } else { request_bill(g_membership_id, g_customer_id, g_customer_name); } } @@ -93,18 +91,20 @@ function member_card(cardNo) { }); } } + function request_bill(membership_id,customer_id,customer_name){ if (window.location.pathname.includes('foodcourt')) { order_id = $('#order_id').val() || $('#save_order_id').val() + data = { 'customer_id': customer_id } $.ajax({ type: "GET", url: "/foodcourt/food_court/"+order_id+"/request_bill" , - data: {}, + data: data, dataType: "json", success: function(data) { if(data.status == true) { - update_sale(membership_id, customer_id, customer_name, data.sale_id); + window.location.href = '/foodcourt/sale/'+data.sale_id+'/food_court/payment/'; }else{ swal("Alert!", "Error!", "error"); location.reload(); @@ -113,6 +113,7 @@ function request_bill(membership_id,customer_id,customer_name){ }); } } + function update_sale(membership_id, customer_id, customer_name, sale_id) { $("#oqs_loading_wrapper").css("display", "none"); var customer=""; diff --git a/app/controllers/foodcourt/addorders_controller.rb b/app/controllers/foodcourt/addorders_controller.rb index 1349d310..60deb1a8 100755 --- a/app/controllers/foodcourt/addorders_controller.rb +++ b/app/controllers/foodcourt/addorders_controller.rb @@ -87,8 +87,6 @@ class Foodcourt::AddordersController < BaseFoodcourtController end def create - new_booking =true - booking_id =nil if params[:booking_id].present? booking = Booking.find(params[:booking_id]) end @@ -105,82 +103,64 @@ class Foodcourt::AddordersController < BaseFoodcourtController items_arr = [] JSON.parse(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["order_item_id"],"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 + if i["parent_order_item_id"]; + items = {"order_item_id": i["order_item_id"],"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["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])} - end - items_arr.push(items) + end + items_arr.push(items) } - if params[:order_source] == "quick_service" && params[:table_id].to_i == 0 - customer_id = takeaway.customer_id # for no customer id from mobile - else - customer_id = params[:customer_id].present? ? params[:customer_id] : Customer.walkin.customer_id # for no customer id from mobile - end - if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved' - new_booking = true - else - new_booking = false - booking_id = booking.booking_id - end - @order =Order.create(source: params[:order_source], - order_type: params[:order_type], - customer_id: customer_id, - items: items_arr, - guest: params[:guest_info], - table_id: params[:table_id], - new_booking: new_booking, - waiters: current_login_employee.name, - employee_name: current_login_employee.name, - is_extra_time: is_extra_time, - extra_time: extra_time, - booking_id: booking_id - ) - @status, @booking = @order.generate + customer_id = params[:customer_id].present? ? params[:customer_id] : Customer.walkin.customer_id - if @status && @booking - #send order broadcast to order_channel - if @order.table_id.to_i > 0 - table = DiningFacility.find(@booking.dining_facility_id) - type = 'order' - from = getCloudDomain #get sub domain in cloud mode - ActionCable.server.broadcast "order_channel",table: table,type:type,from:from + Order.transaction do + @order = Order.new + @order.source = params[:order_source] + @order.order_type = params[:order_type] + @order.customer_id = customer_id + @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.is_extra_time = is_extra_time + @order.extra_time = extra_time + + if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved' + @order.new_booking = true + else + @order.new_booking = false + @order.booking_id = booking.booking_id end - if params[:order_source] != "quick_service" && params[:order_source] != "food_court" - process_order_queue(@order.order_id,@order.table_id,@order.source) - end - end + @status, @booking = @order.generate - if current_user.role != "waiter" && params[:create_type] == "create_pay" - if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court') - - @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) - - # for second display - if @order.source == 'quick_service' + if @status && @booking + #send order broadcast to order_channel + if @order.table_id.to_i > 0 + table = DiningFacility.find(@booking.dining_facility_id) + type = 'order' from = getCloudDomain #get sub domain in cloud mode - ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from + ActionCable.server.broadcast "order_channel",table: table,type:type,from:from end - #end - result = {:status=> @status, :data => @sale ,:current_user_role =>current_user.role} - render :json => result.to_json end - else - result = {:status=> @status, :data => 0 } - render :json => result.to_json - end + if current_user.role != "waiter" && params[:create_type] == "create_pay" + if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court') + + @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) + + # for second display + if @order.source == 'quick_service' + from = getCloudDomain #get sub domain in cloud mode + ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from + end + #end + end + end + end end # render json for http status code diff --git a/app/controllers/foodcourt/food_court_controller.rb b/app/controllers/foodcourt/food_court_controller.rb index 109bb9bc..96ca57d4 100644 --- a/app/controllers/foodcourt/food_court_controller.rb +++ b/app/controllers/foodcourt/food_court_controller.rb @@ -9,51 +9,49 @@ class Foodcourt::FoodCourtController < ApplicationController def index if !ShiftSale.current_shift.nil? - if params[:sale_id].present? - sale =Sale.find(params[:sale_id]) - if sale - @sale_id =sale.sale_id - @booking_id =sale.bookings[0].booking_id + if params[:sale_id].present? + sale =Sale.find(params[:sale_id]) + if sale + @sale_id =sale.sale_id + @booking_id =sale.bookings[0].booking_id + end end - end - @zone = Zone.all - @tables = Table.active.order('status desc') - @rooms = Room.active.order('status desc') + @zone = Zone.all.includes(:tables, :rooms).where("is_active= true") - today = Time.current - day = Date.today.wday - @menus = [] - @menu = [] - @cashier_type = "food_court" - #checked quick_service only + today = Time.current + day = Date.today.wday + @menus = [] + @menu = [] + @cashier_type = "food_court" + #checked quick_service only - display_type = Lookup.find_by_lookup_type("display_type") - if !display_type.nil? && display_type.value.to_i ==2 - @display_type = display_type.value - else - @display_type = nil - end + display_type = Lookup.find_by_lookup_type("display_type") + if !display_type.nil? && display_type.value.to_i ==2 + @display_type = display_type.value + else + @display_type = nil + end - @quick_service_only = true - lookup_dine_in = Lookup.collection_of('dinein_cashier') - if !lookup_dine_in.empty? - lookup_dine_in.each do |dine_in| - if dine_in[0].downcase == "dineincashier" - if dine_in[1] == '1' - @quick_service_only = false + @quick_service_only = true + lookup_dine_in = Lookup.collection_of('dinein_cashier') + if !lookup_dine_in.empty? + lookup_dine_in.each do |dine_in| + if dine_in[0].downcase == "dineincashier" + if dine_in[1] == '1' + @quick_service_only = false + end end end end - end - @app_order_new_count = Booking.select("bookings.*,customers.*") + @app_order_new_count = Booking.select("bookings.*,customers.*") .joins(" JOIN sales ON bookings.sale_id=sales.sale_id") .joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id") .joins("JOIN orders ON orders.order_id=booking_orders.order_id") .joins("JOIN order_items ON orders.order_id=order_items.order_id") .joins("JOIN customers ON orders.customer_id=customers.customer_id") .where("bookings.booking_status !=? and sales.sale_status =? and sales.payment_status =? and orders.source='app' and DATE(bookings.created_at)=?",'completed','completed','paid',Date.today).order("bookings.created_at desc").uniq.length - render "foodcourt/addorders/detail" + render "foodcourt/addorders/detail" else if current_user.role == 'administrator' || current_user.role == 'manager' redirect_to origami_dashboard_path diff --git a/app/controllers/foodcourt/orders_controller.rb b/app/controllers/foodcourt/orders_controller.rb index 59fea916..42d3288e 100755 --- a/app/controllers/foodcourt/orders_controller.rb +++ b/app/controllers/foodcourt/orders_controller.rb @@ -64,7 +64,6 @@ class Foodcourt::OrdersController < BaseFoodcourtController @booking_id =@booking.booking_id @order_id =@booking.order_id @sale_data = Sale.find_by_sale_id(@booking.sale_id) - elsif params[:pending_id] id = params[:pending_id] if id.include? "SAL" @@ -166,40 +165,46 @@ class Foodcourt::OrdersController < BaseFoodcourtController } # begin - order = Order.new - 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 = items_arr - order.guest = params[:guest_info] - order.table_id = params[:table_id] # this is dining facilities's id - order.waiters = current_login_employee.name - order.employee_name = current_login_employee.name + Order.transaction do + order = Order.new + 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 = items_arr + order.guest = params[:guest_info] + order.table_id = params[:table_id] # this is dining facilities's id + order.waiters = current_login_employee.name + order.employee_name = current_login_employee.name - order.is_extra_time = is_extra_time - order.extra_time = extra_time + order.is_extra_time = is_extra_time + order.extra_time = extra_time - order.new_booking = false - order.booking_id = booking.booking_id + order.new_booking = false + order.booking_id = booking.booking_id - if order.generate - if sale - Sale.add_to_existing_pending_invoice(nil, sale.sale_id, booking) - render :json => { :status => true, :data => sale } + if order.generate + if sale + Sale.add_to_existing_pending_invoice(nil, sale.sale_id, booking) + render :json => { :status => true, :data => sale } + else + render :json => { :status => true, :data => 'OK' } + end else - render :json => { :status => true, :data => 'OK' } + render :json => { :status => false } end - else - render :json => { :status => false } end end def request_bill sale_data =[] + customer_id = params[:customer_id] if !ShiftSale.current_shift.nil? - order_id = params[:order_id] # order_id + order_id = params[:order_id] order = Order.find(order_id) booking = order.booking + if Customer.exists?(customer_id: customer_id) + booking.orders.update_all(customer_id: customer_id) + end if booking.checkin_at.utc > Time.now.utc && booking.checkout_at.nil? @status = false @error_message = "Operation failed, Could not request bill!" @@ -295,7 +300,7 @@ class Foodcourt::OrdersController < BaseFoodcourtController def cancel_order order_id = params[:order_id] - + if order_id.present? order = Order.find(order_id) booking = order.booking @@ -321,5 +326,5 @@ class Foodcourt::OrdersController < BaseFoodcourtController end end end - + end diff --git a/app/controllers/foodcourt/paymal_controller.rb b/app/controllers/foodcourt/paymal_controller.rb index 08be1cb4..6f8d138e 100644 --- a/app/controllers/foodcourt/paymal_controller.rb +++ b/app/controllers/foodcourt/paymal_controller.rb @@ -1,19 +1,37 @@ class Foodcourt::PaymalController < BaseFoodcourtController def create - cash = params[:payment_amount] - sale_id = params[:sale_id] - transaction_ref = params[:transaction_ref] - account_no = params[:account_no] - if(Sale.exists?(sale_id)) + cash = params[:payment_amount] + sale_id = params[:sale_id] + transaction_ref = params[:transaction_ref] + account_no = params[:account_no] + if(Sale.exists?(sale_id)) + Sale.transaction do saleObj = Sale.find(sale_id) + booking = saleObj.booking + sale_payment = SalePayment.new - status, @sale, @membership_data = sale_payment.process_payment(saleObj, current_user, cash, "paymal",account_no) + status, @sale, @membership_data = sale_payment.process_payment(saleObj, current_user, cash, "paymal", account_no) + if status == true && @membership_data["status"] == true + PrintOrderQueueJob.perform_later(current_shop.shop_code, booking.booking_id) + PrintReceiptJob.perform_later(current_shop.shop_code, sale_id) + @out = true, "Success!" else @out = false, @membership_data["message"] end end end + end + + private + def getCloudDomain + from = "" + if ENV["SERVER_MODE"] == 'cloud' + from = request.subdomain.to_s + "." + request.domain.to_s + end + + return from + end end diff --git a/app/controllers/foodcourt/second_display_controller.rb b/app/controllers/foodcourt/second_display_controller.rb index c28ce0ec..da2ac742 100644 --- a/app/controllers/foodcourt/second_display_controller.rb +++ b/app/controllers/foodcourt/second_display_controller.rb @@ -9,19 +9,20 @@ class Foodcourt::SecondDisplayController < BaseFoodcourtController def customer_view display_type = Lookup.find_by_lookup_type("display_type") - if !display_type.nil? && display_type.value.to_i == 2 - if params[:status]!= "billed" - tax_profiles = TaxProfile.all.order("order_by asc") - else - tax_profiles = nil - end - if ENV["SERVER_MODE"] == 'cloud' - from = request.host - else - from = "" - end - ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status],from:from - end + if !display_type.nil? && display_type.value.to_i == 2 + if params[:status]!= "billed" + tax_profiles = TaxProfile.all.order("order_by asc") + else + tax_profiles = nil + end + if ENV["SERVER_MODE"] == 'cloud' + from = request.host + else + from = "" + end + ActionCable.server.broadcast "second_display_view_channel",data: params[:data],tax_profiles: tax_profiles,status:params[:status],from:from + end + head :no_content # end end #Shop Name in Navbor diff --git a/app/controllers/foodcourt/void_controller.rb b/app/controllers/foodcourt/void_controller.rb index 553512f8..0c6f5d7f 100755 --- a/app/controllers/foodcourt/void_controller.rb +++ b/app/controllers/foodcourt/void_controller.rb @@ -34,6 +34,15 @@ class Foodcourt::VoidController < BaseFoodcourtController sale.sale_status = 'void' sale.save + #call paymal to void + if !sale.sale_payments.nil? + membership_response = sale.paymal_payment_void + Rails.logger.debug "---------Paymal Payment Void response in VoidController" + Rails.logger.debug membership_response.to_json + end + + PrintReceiptJob.perform_later(current_shop.shop_code, sale.sale_id) + if table = sale.booking.dining_facility unless table.current_bookings.exists? table.update_attributes(status: 'available') @@ -49,73 +58,6 @@ class Foodcourt::VoidController < BaseFoodcourtController # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,"SALEVOID" ) - #call paymal to void - if !sale.sale_payments.nil? - membership_response =sale.paymal_payment_void - Rails.logger.debug "---------Paymal Payment Void response in VoidController" - Rails.logger.debug membership_response.to_json - end - - # For Print - member_info = nil - rebate_amount = nil - current_balance = nil - - if sale.booking.dining_facility_id.to_i > 0 - cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) - else - shift = ShiftSale.find(sale.shift_sale_id) - cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) - end - - customer= Customer.find(sale.customer_id) - - #shop detail - shop_details = Shop.current_shop - # get member information - rebate = MembershipSetting.find_by_rebate(1) - if customer.membership_id != nil && rebate - member_info = Customer.get_member_account(customer) - rebate_amount = Customer.get_membership_transactions(customer,sale.receipt_no) - # current_balance = SaleAudit.paymal_search(sale_id) - current_balance = 0 - end - - printer = PrintSetting.all - - unique_code="ReceiptBillPdf" - if !printer.empty? - printer.each do |printer_setting| - if printer_setting.unique_code == 'ReceiptBillPdf' - unique_code="ReceiptBillPdf" - elsif printer_setting.unique_code == 'ReceiptBillA5Pdf' - unique_code="ReceiptBillA5Pdf" - elsif printer_setting.unique_code == 'ReceiptBillStarPdf' - unique_code="ReceiptBillStarPdf" - end - end - end - # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) - # Calculate Food and Beverage Total - item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) - discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) - other_amount = SaleItem.calculate_other_charges(sale.sale_items) - printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,other_amount,nil,nil,nil) - result = { - :filepath => filename, - :printer_model => print_settings.brand_name, - :printer_url => print_settings.api_settings - } - - # Mobile Print - render :json => result.to_json - # end - - #end print - # update complete order items in oqs SaleOrder.where("sale_id = '#{ sale_id }'").find_each do |sodr| AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| @@ -124,6 +66,6 @@ class Foodcourt::VoidController < BaseFoodcourtController end end end + head :no_content end - end diff --git a/app/jobs/order_queue_processor_job.rb b/app/jobs/order_queue_processor_job.rb index 18fdc2dd..e60dd034 100755 --- a/app/jobs/order_queue_processor_job.rb +++ b/app/jobs/order_queue_processor_job.rb @@ -3,8 +3,8 @@ class OrderQueueProcessorJob < ApplicationJob def perform(order_id, table_id) # Do something later - #Order ID - order = Order.find(order_id) + #Order ID + order = Order.find(order_id) #Execute orders and send to order stations if order @@ -16,11 +16,11 @@ class OrderQueueProcessorJob < ApplicationJob ActionCable.server.broadcast "order_queue_station_channel",order: assign_order end - # private + # private - # def render_order(assign_order) - # ApplicationController.renderer.render(partial: 'oqs/oqs_test', - # locals: { order: assign_order}) + # def render_order(assign_order) + # ApplicationController.renderer.render(partial: 'oqs/oqs_test', + # locals: { order: assign_order}) # end # Read more at https://www.pluralsight.com/guides/ruby-ruby-on-rails/creating-a-chat-using-rails-action-cable#TehYiuqlHDOXaQQk.99 diff --git a/app/jobs/print_order_queue_job.rb b/app/jobs/print_order_queue_job.rb new file mode 100644 index 00000000..eaf27c4c --- /dev/null +++ b/app/jobs/print_order_queue_job.rb @@ -0,0 +1,14 @@ +class PrintOrderQueueJob < ApplicationJob + queue_as :default + + def perform(shop_code, booking_id) + current_shop = Shop.find_by(shop_code: shop_code) + ActsAsTenant.with_tenant(current_shop) do + booking = Booking.find(booking_id) + booking.orders.each do |order| + oqs = OrderQueueStation.new + oqs.process_order(order, booking.dining_facility_id) + end + end + end +end diff --git a/app/jobs/print_receipt_job.rb b/app/jobs/print_receipt_job.rb new file mode 100644 index 00000000..c0b4f18d --- /dev/null +++ b/app/jobs/print_receipt_job.rb @@ -0,0 +1,49 @@ +class PrintReceiptJob < ApplicationJob + queue_as :high_priority + + def perform(shop_code, sale_id) + current_shop = Shop.find_by(shop_code: shop_code) + ActsAsTenant.with_tenant(current_shop) do + saleObj = saleObj = Sale.find(sale_id) + sale_items = SaleItem.get_all_sale_items(sale_id) + + booking = saleObj.booking + latest_order_no = booking.booking_orders.last.order_id + + cashier_terminal = booking.cashier_terminal_by_dining_facility || saleObj.cashier_terminal_by_shift_sale + + customer = saleObj.customer + + # get member information + rebate = MembershipSetting.find_by_rebate(1) + credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id, 'creditnote') + + if customer.membership_id != nil && rebate && credit_data.nil? + member_info = Customer.get_member_account(customer) + + if member_info["status"] == true + rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) + current_balance = SaleAudit.paymal_search(sale_id) + end + end + + card_data = Array.new + #card_balance amount for Paymal payment + card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) + + print_settings = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first + + item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) + discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) + other_amount = SaleItem.calculate_other_charges(sale_items) + + printer = Printer::ReceiptPrinter.new(print_settings) + + if saleObj.sale_status = 'completed' + printer.print_receipt_bill(print_settings, false, nil, cashier_terminal, sale_items, saleObj, customer.paypar_account_no, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, current_shop, 'paid', current_balance, card_data, other_amount, latest_order_no, card_balance_amount, nil, transaction_ref) + elsif saleObj.sale_status = 'void' + printer.print_receipt_bill(print_settings, false, nil,cashier_terminal, sale_items, saleObj, customer.paypar_account_no, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, current_shop, "VOID", current_balance, card_data, other_amount,nil,nil,nil) + end + end + end +end diff --git a/app/models/booking.rb b/app/models/booking.rb index 06a1730e..4562a8aa 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -173,12 +173,7 @@ class Booking < ApplicationRecord end def self.get_booking_id(order_no) - booking = Booking.joins(" JOIN booking_orders bo ON bo.booking_id = bookings.booking_id") - .joins(" JOIN orders o ON o.order_id=bo.order_id") - .where("o.order_id='#{order_no}'") - .first() - - return booking.booking_id + return BookingOrder.where(order_id: order_no).first.booking_id end private diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index cb0e42ce..a6e3bec0 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -10,11 +10,14 @@ class DiningFacility < ApplicationRecord has_many :bookings has_many :current_bookings, -> { left_joins(:sale).assign.merge(Booking.unscoped.where(checkout_at: nil).or(Booking.merge(Sale.unscoped.where(sale_status: ['new', nil])))) }, class_name: "Booking" - has_one :current_checkin_booking, -> { left_joins(:sale).assign.merge(Sale.unscoped.where(sale_status: nil)) }, class_name: "Booking" + has_one :current_checkin_booking, -> { left_joins(:sale).assign.where(sale_id: nil) }, class_name: "Booking" has_one :current_checkout_booking, -> { left_joins(:sale).assign.where.not(checkout_at: nil).merge(Sale.unscoped.where(sale_status: 'new')) }, class_name: "Booking" has_one :current_reserved_booking, -> { left_joins(:sale).assign.where.not(reserved_at: nil).merge(Sale.unscoped.where(sale_status: nil)) }, class_name: "Booking" - has_many :current_sales, -> { where(sale_status: 'new').merge(Booking.assign) }, through: :bookings, class_name: "Sale", source: "sale" + has_many :current_bookings, -> { left_joins(:sale).assign.merge(Booking.unscoped.where(checkout_at: nil).or(Booking.merge(Sale.unscoped.where(sale_status: ['new', nil])))) }, class_name: "Booking" + has_one :current_checkin_booking, -> { left_joins(:sale).assign.where(sale_id: nil) }, class_name: "Booking" + has_one :current_checkout_booking, -> { left_joins(:sale).assign.where.not(checkout_at: nil).merge(Sale.unscoped.where(sale_status: 'new')) }, class_name: "Booking" + has_one :current_reserved_booking, -> { left_joins(:sale).assign.where.not(reserved_at: nil).merge(Sale.unscoped.where(sale_status: nil)) }, class_name: "Booking" TABLE_TYPE = "Table" ROOM_TYPE = "Room" diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index c7f70872..4e88acfb 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -49,99 +49,36 @@ class OrderQueueStation < ApplicationRecord end end - def pay_process_order_queue (order_id, table_id) - - oqs_stations = OrderQueueStation.active - - order = Order.find(order_id) - order_items = order.order_items - - # Order.pay_process_order_queue(order_id,table_id) - # if order - # oqs = OrderQueueStation.new - # oqs.process_order(order, table_id) - # end - # assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) - # if ENV["SERVER_MODE"] == 'cloud' - # from = request.subdomain + "." + request.domain - # else - # from = "" - # end - # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from + def pay_process_order_queue (order_id, table_id = nil) if table_id.to_i > 0 # get dining dining = DiningFacility.find(table_id) - oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}") - booking = Booking.find_by_dining_facility_id(dining.id) - - # ToDo per item per printer - - oqs_by_zones.each do |oqpbz| - oqs = OrderQueueStation.find(oqpbz.order_queue_station_id) - is_auto_printed = false - oqs_order_items = [] - - if oqs.is_active - #Get List of items - - pq_items = JSON.parse(oqs.processing_items) - #Loop through the processing items - pq_items.each do |pq_item| - #Processing through the looping items - order_items.each do |order_item| - if (pq_item == order_item.item_code) - if (order_item.qty > 0) - oqs_order_items.push(order_item) - end - end - end - end - - if oqs.auto_print - if oqs_order_items.length > 0 - if oqs.cut_per_item - print_slip_item(oqs, order, oqs_order_items) - else - print_slip(oqs, order, oqs_order_items) - end - is_auto_printed = true - end - end - end - end + oqs_stations = dining.order_queue_stations else - oqs_stations.each do |oqs| - is_auto_printed = false - oqs_order_items = [] + oqs_stations = OrderQueueStation.active + end - if oqs.is_active - #Get List of items - - pq_items = JSON.parse(oqs.processing_items) - #Loop through the processing items - pq_items.each do |pq_item| - #Processing through the looping items - order_items.each do |order_item| - if (pq_item == order_item.item_code) - if (order_item.qty > 0) - oqs_order_items.push(order_item) - end - end - end - end + order = Order.find(order_id) + order_items = order.order_items - if oqs.auto_print - if oqs_order_items.length > 0 - if oqs.cut_per_item - print_slip_item(oqs, order, oqs_order_items) - else - print_slip(oqs, order, oqs_order_items) - end - is_auto_printed = true - end + assigned_order_items = [] + oqs_order_items_by_zones = [] + + oqs_stations.each do |oqs| + oqs_order_items = order_items.select { |i| JSON.parse(oqs.processing_items).include? i.item_code } + oqs_order_items_by_zones << { oqs: oqs, oqs_order_items: oqs_order_items } + + if oqs.auto_print + if oqs_order_items.length > 0 + if oqs.cut_per_item + print_slip_item(oqs, order, oqs_order_items) + else + print_slip(oqs, order, oqs_order_items) end end end - end #end else + end end private diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index c2c60370..6c4fff23 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -118,7 +118,6 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker if printed_status != 'Paid' || !Lookup.where(lookup_type: "ReceiptPdfView").pluck(:value).include?('1') #no print in cloud server - puts "SERVER_MODE #{ENV["SERVER_MODE"]}" if ENV["SERVER_MODE"] != "cloud" self.print(filename, cashier_terminal.printer_name) end diff --git a/app/views/foodcourt/addorders/create.json.jbuilder b/app/views/foodcourt/addorders/create.json.jbuilder index 175e6e94..e727324d 100755 --- a/app/views/foodcourt/addorders/create.json.jbuilder +++ b/app/views/foodcourt/addorders/create.json.jbuilder @@ -1,10 +1,13 @@ if @status == true json.status :success - json.id @order.id json.booking_id @booking.id + json.order_id @order.id json.order_items do json.array! @order.order_items, :item_code, :item_name, :qty, :options, :remark end + if @sale + json.sale_id @sale.sale_id + end else json.status :error if @error_messages diff --git a/app/views/foodcourt/addorders/detail.html.erb b/app/views/foodcourt/addorders/detail.html.erb index d31f2d1b..41968f24 100644 --- a/app/views/foodcourt/addorders/detail.html.erb +++ b/app/views/foodcourt/addorders/detail.html.erb @@ -167,7 +167,7 @@ Orders - +
ORDER DETAILS @@ -432,80 +432,53 @@
- + <% end %> @@ -440,7 +445,7 @@ <% end %> <% end %> - +