From 47ffc5fa51046173ef9c6a6b5b399ee67ea1b993 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 14 Feb 2018 18:21:10 +0630 Subject: [PATCH] update no table quick srevice --- app/controllers/application_controller.rb | 10 +-- .../origami/customers_controller.rb | 7 +- .../origami/other_charges_controller.rb | 30 +++++-- .../origami/payments_controller.rb | 84 ++++++++++++------- app/controllers/origami/sales_controller.rb | 9 +- app/controllers/origami/surveys_controller.rb | 15 +++- app/models/sale_payment.rb | 42 +++++----- app/pdf/receipt_bill_pdf.rb | 13 ++- app/views/origami/customers/index.html.erb | 22 +++-- .../origami/other_charges/index.html.erb | 6 +- app/views/origami/surveys/_form.html.erb | 16 +++- app/views/origami/surveys/new.html.erb | 9 -- 12 files changed, 173 insertions(+), 90 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4dafef41..3a35a15b 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -38,11 +38,11 @@ class ApplicationController < ActionController::Base end else # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index b0056fb2..db89b1d0 100755 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -53,7 +53,12 @@ class Origami::CustomersController < BaseOrigamiController if(@sale_id[0,3] == "SAL") @booking = Booking.find_by_sale_id(@sale_id) - @dining_facility = DiningFacility.find(@booking.dining_facility_id) + if @booking.dining_facility_id.to_i > 0 + @dining_facility = DiningFacility.find(@booking.dining_facility_id) + else + @dining_facility = nil + end + else @booking_order = BookingOrder.find_by_order_id(@sale_id) @booking = Booking.find(@booking_order.booking_id) diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index 7ed087d4..d15edb5e 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -6,7 +6,12 @@ class Origami::OtherChargesController < BaseOrigamiController @cashier_type = params[:type] if Sale.exists?(sale_id) @sale_data = Sale.find(sale_id) - @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) + if @sale_data.bookings[0].dining_facility_id.to_i > 0 + @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) + else + @table = nil + end + end end @@ -17,8 +22,14 @@ class Origami::OtherChargesController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find(sale_id) - table_id = sale.bookings[0].dining_facility_id - table = DiningFacility.find(table_id) + if sale.bookings[0].dining_facility_id.to_i > 0 + table_id = sale.bookings[0].dining_facility_id + table = DiningFacility.find(table_id) + else + table_id = nil + table = nil + end + # sale.total_amount = sub_total.to_f # sale.grand_total = sub_total.to_f + sale.total_tax; @@ -45,7 +56,12 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.save action_by = current_user.id - remark = "Add Other Charges - Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} |Charges ->#{di["price"]} For ->#{di["name"]}- Table ->#{table.name}" + if table.nil? + remark = "Add Other Charges - Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} |Charges ->#{di["price"]} For ->#{di["name"]}- Table ->" + else + remark = "Add Other Charges - Receipt No #{sale.receipt_no} | Sale ID #{sale.sale_id} |Charges ->#{di["price"]} For ->#{di["name"]}- Table ->#{table.name}" + end + sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"ADDOTHERCHARGES" ) end @@ -54,9 +70,11 @@ class Origami::OtherChargesController < BaseOrigamiController # Re-calc All Amount in Sale sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount) end - - dining = {:table_id => table_id, :table_type => table.type } + if !table.nil? + dining = {:table_id => table_id, :table_type => table.type } render :json => dining.to_json + end + end #Shop Name in Navbor diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 2d3618b5..fe384a89 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -11,15 +11,21 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - if bookings.count > 1 - # for Multiple Booking - table = DiningFacility.find(bookings[0].dining_facility_id) - else - table = DiningFacility.find(bookings[0].dining_facility_id) - end + # if bookings.count > 1 + # # for Multiple Booking + # table = DiningFacility.find(bookings[0].dining_facility_id) + # else + # table = DiningFacility.find(bookings[0].dining_facility_id) + # end - cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + if bookings[0].dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end if ENV["SERVER_MODE"] != "cloud" #no print in cloud server # Print for First Bill to Customer @@ -94,15 +100,21 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - if bookings.count > 1 - # for Multiple Booking - table = DiningFacility.find(bookings[0].dining_facility_id) - else - table = DiningFacility.find(bookings[0].dining_facility_id) - end + # if bookings.count > 1 + # # for Multiple Booking + # table = DiningFacility.find(bookings[0].dining_facility_id) + # else + # table = DiningFacility.find(bookings[0].dining_facility_id) + # end - cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + if bookings[0].dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end # For Print if ENV["SERVER_MODE"] != "cloud" #no print in cloud server @@ -264,15 +276,21 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - if bookings.count > 1 - # for Multiple Booking - table = DiningFacility.find(bookings[0].dining_facility_id) - else - table = DiningFacility.find(bookings[0].dining_facility_id) - end + # if bookings.count > 1 + # # for Multiple Booking + # table = DiningFacility.find(bookings[0].dining_facility_id) + # else + # table = DiningFacility.find(bookings[0].dining_facility_id) + # end - cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + if bookings[0].dining_facility_id.to_i > 0 + table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + else + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) + end if ENV["SERVER_MODE"] != "cloud" #no print in cloud server unique_code = "ReceiptBillPdf" @@ -333,15 +351,21 @@ class Origami::PaymentsController < BaseOrigamiController # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") - if bookings.count > 1 - # for Multiple Booking + # if bookings.count > 1 + # # for Multiple Booking + # table = DiningFacility.find(bookings[0].dining_facility_id) + # else + # table = DiningFacility.find(bookings[0].dining_facility_id) + # end + if bookings[0].dining_facility_id.to_i > 0 table = DiningFacility.find(bookings[0].dining_facility_id) + cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) + cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) else - table = DiningFacility.find(bookings[0].dining_facility_id) + shift = ShiftSale.find(saleObj.shift_sale_id) + cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) end - - cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) - cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) + # Re-call Sale Data saleObj = Sale.find(sale_id) diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index c522f9e7..513bdb2c 100755 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -7,8 +7,13 @@ class Origami::SalesController < BaseOrigamiController @sale = Sale.find(params[:sale_id]) @order = SaleOrder.find_by_sale_id(@sale.sale_id).order_id @booking = BookingOrder.find_by_order_id(@order).booking_id - @table_id = Booking.find(@booking).dining_facility_id - @dining = DiningFacility.find(@table_id) + if Booking.find(@booking).dining_facility_id.to_i>0 + @table_id = Booking.find(@booking).dining_facility_id + @dining = DiningFacility.find(@table_id) + else + @table_id = nil + @dining = nil + end end def add_to_existing_invoice diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index d7f97a6e..4ecdf95f 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -9,8 +9,14 @@ class Origami::SurveysController < BaseOrigamiController @receipt_no = @sale.receipt_no @grand_total = @sale.grand_total @booking = Booking.find_by_sale_id(@id) - @dining_facility = DiningFacility.find(@booking.dining_facility_id) - @table_type = @dining_facility.type + if @booking.dining_facility_id.to_i>0 + @dining_facility = DiningFacility.find(@booking.dining_facility_id) + @table_type = @dining_facility.type + else + @dining_facility = nil + @table_type = nil + end + else @dining_facility = DiningFacility.find(@id) @table_type = @dining_facility.type @@ -20,8 +26,9 @@ class Origami::SurveysController < BaseOrigamiController end def create - @dining_facility = DiningFacility.find(params[:table_id]) - + if params[:table_id].to_i>0 + @dining_facility = DiningFacility.find(params[:table_id]) + end @type = params[:cashier_type] @sale_id = params[:sale_id] if @type == "quick_service" diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 661eb57b..c2fce169 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -385,32 +385,34 @@ class SalePayment < ApplicationRecord sale_count = 0 booking = Booking.find_by_sale_id(sale_obj.id) if booking - table = DiningFacility.find(booking.dining_facility_id) - bookings = table.bookings - bookings.each do |tablebooking| - if tablebooking.booking_status != 'moved' - if tablebooking.sale_id - if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' + if booking.dining_facility_id.to_i > 0 + table = DiningFacility.find(booking.dining_facility_id) + bookings = table.bookings + bookings.each do |tablebooking| + if tablebooking.booking_status != 'moved' + if tablebooking.sale_id + if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void' + status = false + sale_count += 1 + else + status = true + end + else status = false sale_count += 1 - else - status = true end - else - status = false - sale_count += 1 end end - end - if status && sale_count == 0 - table.status = "available" - table.save - end + if status && sale_count == 0 + table.status = "available" + table.save + end - type = 'payment' - #Send to background job for processing - # OrderBroadcastJob.perform_later(table,type) - ActionCable.server.broadcast "order_channel",table: table,type:type + type = 'payment' + #Send to background job for processing + # OrderBroadcastJob.perform_later(table,type) + ActionCable.server.broadcast "order_channel",table: table,type:type + end end end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index d2ad0260..dece55cb 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -104,9 +104,12 @@ class ReceiptBillPdf < Prawn::Document bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left end - bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do + if sale_data.bookings[0].dining_facility_id.to_i > 0 + bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right + end end + move_down 5 y_position = cursor @@ -119,8 +122,14 @@ class ReceiptBillPdf < Prawn::Document move_down 5 y_position = cursor + if sale_data.bookings[0].dining_facility_id.to_i > 0 + time =sale_data.receipt_date.strftime('%d-%m-%Y') +"("+ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') +"-"+ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p')+")" + else + time = time = sale_data.receipt_date.strftime('%d-%m-%Y %H:%M %p') + end + bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do - text "Date : #{ sale_data.receipt_date.strftime('%d-%m-%Y') } ( #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } - #{ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p') } )",:size => self.item_font_size,:align => :left + text "Date : #{ time }",:size => self.item_font_size,:align => :left end diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 88f4646d..eebaabbf 100755 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -32,7 +32,6 @@
-
@@ -115,8 +114,13 @@ + <%if !@dining_facility.nil?%> + <%else%> + + + <%end%> <%= f.error_notification %> <%= f.hidden_field :id, :class => "form-control col-md-6 " %>
@@ -417,6 +421,7 @@ if(customer_name != ""){ customer = '(' + customer_name + ')'; } + swal({ title: "Confirmation !", text: 'Are You Sure to assign this customer' + customer + '!', @@ -437,7 +442,6 @@ var id = $("#table_id").val(); var type = $("#type").val(); if (cashier_type == "quick_service") { - window.location.href = '/origami/table/'+id window.location.href = '/origami/sale/'+sale_id+'/'+cashier_type+'/payment/'; }else{ if (type=="Table") { @@ -458,11 +462,17 @@ $('#back').on('click',function(){ var id = $("#table_id").val() var type = $("#type").val() - if (type=="Table") { - window.location.href = '/origami/table/'+id + var sale_id = $("#sale_id").val() + if (cashier_type == "quick_service") { + window.location.href = '/origami/sale/'+sale_id+'/'+cashier_type+'/payment/'; }else{ - window.location.href = '/origami/room/'+id - } + if (type=="Table") { + window.location.href = '/origami/table/'+id + }else{ + window.location.href = '/origami/room/'+id + } + } + }) diff --git a/app/views/origami/other_charges/index.html.erb b/app/views/origami/other_charges/index.html.erb index 9e3b7c3f..a194e03a 100755 --- a/app/views/origami/other_charges/index.html.erb +++ b/app/views/origami/other_charges/index.html.erb @@ -197,7 +197,11 @@
- + <%if !@table.nil?%> + + <%else%> + + <%end%>
diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb index 9f2b5d06..47cb08d0 100755 --- a/app/views/origami/surveys/_form.html.erb +++ b/app/views/origami/surveys/_form.html.erb @@ -41,10 +41,18 @@
- + <%if !@dining_facility.nil?%> + + + <%= f.input :dining_name, :as => :hidden, :input_html => { :value => @dining_facility.name } %> + <%else%> + + + <%= f.input :dining_name, :as => :hidden, :input_html => { :value => 0 } %> + <%end%> - <%= f.input :dining_name, :as => :hidden, :input_html => { :value => @dining_facility.name } %> + <%= f.input :created_by, :as => :hidden, :input_html => { :value => current_login_employee.name } %> <%= f.input :receipt_no, :as => :hidden, :input_html => { :value => @receipt_no} %> <%= f.input :total_amount, :as => :hidden, :input_html => { :value => @grand_total } %> @@ -228,8 +236,8 @@ var cashier_type = "<%= @cashier_type %>"; }); // click back button for redirect $('#back').on('click',function(){ - table_type = '<%=@table_type%>'; - table_id = '<%=@dining_facility.id%>'; + table_type = $('#table_type').val() + table_id = $('#table_id').val() if (cashier_type == "quick_service") { window.location.href = '/origami/sale/<%= @id %>/<%= @cashier_type %>/payment/'; diff --git a/app/views/origami/surveys/new.html.erb b/app/views/origami/surveys/new.html.erb index bee0f843..ee4d9a57 100755 --- a/app/views/origami/surveys/new.html.erb +++ b/app/views/origami/surveys/new.html.erb @@ -1,12 +1,3 @@ - <%= render 'form', survey: @survey %>