fix bugs and improvement
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -137,16 +137,16 @@
|
||||
<% @payment_methods.each do |method| %>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td style="text-align: right;"><%= method.upcase %> Payment </td>
|
||||
<td style="text-align: right;"><%= method %> Payment</td>
|
||||
<td><%=other[method.parameterize.to_sym].round(2) rescue '-' %></td>
|
||||
<% @total_amount = @total_amount+other[method.parameterize.to_sym] rescue 0.0 %>
|
||||
<% @total_amount = @total_amount + other[method.parameterize.to_sym] rescue 0.0 %>
|
||||
</tr>
|
||||
<% end %>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td style="text-align: right;"><strong>FOC </strong></td>
|
||||
<td><%=other.foc_amount.round(2) rescue 0.0 %></td>
|
||||
<% @total_amount = @total_amount+other.foc_amount rescue 0.0 %>
|
||||
<% @total_amount = @total_amount + other.foc_amount rescue 0.0 %>
|
||||
</tr>
|
||||
<%end%>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user