diff --git a/README.md b/README.md index b8c1cb62..63ba995a 100755 --- a/README.md +++ b/README.md @@ -262,10 +262,6 @@ Strip insignificant zeros => settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros, value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] } -For Booking checkin time limit -settings/lookups => -{ lookup_type: checkin_time_limit, name: CheckinTimeLimit, value: total hours before checkout (e.g., '48')) } - /_ Customer Types in lookups _/ 1. settings/lookups => { type:customer_type, name: Dinein, value:Dinein } diff --git a/app/controllers/transactions/shift_sales_controller.rb b/app/controllers/transactions/shift_sales_controller.rb index 562d45e4..40f64ff4 100644 --- a/app/controllers/transactions/shift_sales_controller.rb +++ b/app/controllers/transactions/shift_sales_controller.rb @@ -40,7 +40,7 @@ class Transactions::ShiftSalesController < ApplicationController @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') #other payment details for mpu or visa like card @other_payment = ShiftSale.get_by_shift_other_payment(@shift) - @payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) + @payment_methods = PaymentMethodSetting.where(is_active: true).pluck(:payment_method) # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') diff --git a/app/models/booking.rb b/app/models/booking.rb index c5e5d6f0..3add744b 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -61,7 +61,6 @@ class Booking < ApplicationRecord scope :active, -> {where("booking_status != 'moved'")} scope :today, -> {where("created_at >= #{Time.now.utc}")} scope :assign, -> { where(booking_status: 'assign')} - scope :within_time_limit, -> { where(checkin_at: Lookup.get_checkin_time_limit.hours.ago..DateTime::Infinity.new) } def self.sync_booking_records(bookings) if !bookings.nil? diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index b3f31fa3..f42545ec 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -9,12 +9,12 @@ class DiningFacility < ApplicationRecord has_many :order_queue_stations, -> { where(is_active: true) }, through: :order_queue_process_by_zones has_many :bookings - has_many :current_bookings, -> { left_joins(:sale).assign.within_time_limit.merge(Booking.where(checkout_at: nil).or(Booking.merge(Sale.where(sale_status: ['new', nil])))) }, class_name: "Booking" - has_one :current_checkin_booking, -> { left_joins(:sale).assign.within_time_limit.merge(Sale.where(sale_status: nil)) }, class_name: "Booking" - has_one :current_checkout_booking, -> { left_joins(:sale).assign.within_time_limit.where.not(checkout_at: nil).merge(Sale.where(sale_status: 'new')) }, class_name: "Booking" - has_one :current_reserved_booking, -> { left_joins(:sale).assign.within_time_limit.where.not(reserved_at: nil).merge(Sale.where(sale_status: nil)) }, class_name: "Booking" + has_many :current_bookings, -> { left_joins(:sale).assign.merge(Booking.where(checkout_at: nil).or(Booking.merge(Sale.where(sale_status: ['new', nil])))) }, class_name: "Booking" + has_one :current_checkin_booking, -> { left_joins(:sale).assign.merge(Sale.where(sale_status: nil)) }, class_name: "Booking" + has_one :current_checkout_booking, -> { left_joins(:sale).assign.where.not(checkout_at: nil).merge(Sale.where(sale_status: 'new')) }, class_name: "Booking" + has_one :current_reserved_booking, -> { left_joins(:sale).assign.where.not(reserved_at: nil).merge(Sale.where(sale_status: nil)) }, class_name: "Booking" - has_many :current_sales, -> { where(sale_status: 'new').merge(Booking.assign.within_time_limit) }, through: :bookings, class_name: "Sale", source: "sale" + has_many :current_sales, -> { where(sale_status: 'new').merge(Booking.assign) }, through: :bookings, class_name: "Sale", source: "sale" TABLE_TYPE = "Table" ROOM_TYPE = "Room" @@ -45,8 +45,7 @@ class DiningFacility < ApplicationRecord end def get_current_booking - checkin_time_lookup = Lookup.get_checkin_time_limit - Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first #and checkout_at is null + Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).first #and checkout_at is null end def get_checkout_booking @@ -88,7 +87,6 @@ class DiningFacility < ApplicationRecord end def self.get_checkin_booking - checkin_time_lookup = Lookup.get_checkin_time_limit bookings = self.current_checkin_booking arr_booking = Array.new if bookings diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 4825d161..db727b38 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -648,7 +648,7 @@ class SalePayment < ApplicationRecord sale.payment_status = 'foc' sale.sale_status = 'completed' elsif sale.grand_total <= sale_payments.sum(&:payment_amount) && sale.sale_status == "new" - sale.amount_received = sale.amount_received + paid_amount + sale.amount_received = sale.amount_received + paid_amount.to_d sale.amount_changed = sale_payments.sum(&:payment_amount) - sale.grand_total sale.payment_status = "paid" diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index afd4ab29..f625cf27 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -152,12 +152,11 @@ class ShiftSale < ApplicationRecord def self.get_by_shift_other_payment(shift) payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) - other_payment = Sale.select("sales.sale_id,sale_payments.payment_method as name, - #{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method}"}.join(', ')}, - SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") - .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id) - return other_payment + Sale.select("sales.sale_id,sale_payments.payment_method as name") + .select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method}"}.join(', ')}") + .select("SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id) end def self.calculate_total_price_by_accounts(shift,type) diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index e6b594bc..11cb139b 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -134,7 +134,7 @@ class CloseCashierPdf < Prawn::Document y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Cash In:", :size => self.item_font_size, :align => :right + text "Cash In :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right @@ -142,7 +142,7 @@ class CloseCashierPdf < Prawn::Document y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Cash Out:", :size => self.item_font_size, :align => :right + text "Cash Out :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right diff --git a/app/views/transactions/shift_sales/show.html.erb b/app/views/transactions/shift_sales/show.html.erb index 9085dd90..587f4490 100755 --- a/app/views/transactions/shift_sales/show.html.erb +++ b/app/views/transactions/shift_sales/show.html.erb @@ -137,16 +137,16 @@ <% @payment_methods.each do |method| %> - <%= method.upcase %> Payment + <%= method %> Payment <%=other[method.parameterize.to_sym].round(2) rescue '-' %> - <% @total_amount = @total_amount+other[method.parameterize.to_sym] rescue 0.0 %> + <% @total_amount = @total_amount + other[method.parameterize.to_sym] rescue 0.0 %> <% end %> FOC <%=other.foc_amount.round(2) rescue 0.0 %> - <% @total_amount = @total_amount+other.foc_amount rescue 0.0 %> + <% @total_amount = @total_amount + other.foc_amount rescue 0.0 %> <%end%>