Fix bugs and improvements
fix payment outstanding with amount <= 0 fix payment outstanding with other payments
This commit is contained in:
@@ -9,6 +9,8 @@ class Sale < ApplicationRecord
|
||||
belongs_to :cashier, foreign_key: "cashier_id", class_name: "Employee"
|
||||
belongs_to :customer, :optional => true
|
||||
belongs_to :shift_sale
|
||||
has_one :current_shift_by_cashier, through: :cashier, source: :current_shift
|
||||
has_one :cashier_terminal_by_shift_sale, through: :shift_sale, source: :cashier_terminal
|
||||
has_one :survey, foreign_key: "receipt_no"
|
||||
has_many :sale_audits
|
||||
has_many :sale_items
|
||||
@@ -16,8 +18,8 @@ class Sale < ApplicationRecord
|
||||
has_many :sale_discounts
|
||||
has_many :sale_taxes
|
||||
has_many :sale_payments
|
||||
has_many :payments_for_credits, through: :sale_audits
|
||||
has_many :sale_orders
|
||||
has_many :sale_payments_for_credits, through: :sale_audits
|
||||
has_many :orders, through: :sale_orders
|
||||
has_many :order_items, through: :sale_orders
|
||||
has_many :bookings
|
||||
@@ -32,7 +34,7 @@ class Sale < ApplicationRecord
|
||||
scope :paid, -> { where(payment_status: 'paid')}
|
||||
scope :completed, -> { where(sale_status: 'completed') }
|
||||
scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) }
|
||||
scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) }
|
||||
scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments ON sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) }
|
||||
|
||||
def qty_of(item_instance_code)
|
||||
order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first
|
||||
@@ -96,12 +98,19 @@ class Sale < ApplicationRecord
|
||||
if cashier.role == 'cashier'
|
||||
sale.cashier = cashier
|
||||
sale.shift_sale = cashier.current_shift
|
||||
elsif booking.dining_facility_id
|
||||
sale.shift_sale = booking.dining_facility.cashier_terminal.current_shift
|
||||
sale.cashier = booking.dining_facility.cashier_terminal.current_shift.employee
|
||||
else
|
||||
sale.cashier = Employee.where(role: 'cashier').where.not(token_session: [nil, '']).first
|
||||
sale.shift_sale = sale.cashier.current_shift
|
||||
elsif booking.dining_facility
|
||||
if sale.shift_sale = booking.current_shift_by_dining_facility
|
||||
sale.cashier = sale.shift_sale.employee
|
||||
end
|
||||
end
|
||||
|
||||
if sale.shift_sale.nil?
|
||||
if sale.cashier = Employee.where(role: 'cashier').where.not(token_session: [nil, '']).first
|
||||
sale.shift_sale = sale.current_shift_by_cashier
|
||||
else
|
||||
sale.shift_sale = ShiftSale.current_shift
|
||||
sale.cashier = sale.shift_sale.employee
|
||||
end
|
||||
end
|
||||
|
||||
sale.cashier_name = sale.cashier.name
|
||||
@@ -110,7 +119,7 @@ class Sale < ApplicationRecord
|
||||
|
||||
sale.sale_items << booking.order_items.to_sale_items
|
||||
|
||||
if dining_charge = booking.dining_facility.dining_charge
|
||||
if booking.dining_facility.present? && dining_charge = booking.dining_facility.dining_charge
|
||||
block_count, dining_price = DiningCharge.amount_calculate(dining_charge, booking.checkin_at, booking.checkout_at)
|
||||
format = "%I:%M %p" if dining_charge.charge_type == "hr"
|
||||
format ||= "%B %d, %I:%M %p"
|
||||
@@ -173,14 +182,12 @@ class Sale < ApplicationRecord
|
||||
order_id = order.order_id # order_id
|
||||
booking = order.booking
|
||||
|
||||
sale_data = Sale.generate_invoice_from_booking(check_booking, current_login_employee, current_user, order.source)
|
||||
if booking.sale.nil?
|
||||
sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source)
|
||||
# Promotion Activation
|
||||
Promotion.promo_activate(sale_data)
|
||||
end
|
||||
|
||||
# Bind shift sale id to sale
|
||||
# @sale_data.shift_sale_id = shift.id
|
||||
# @sale_data.save
|
||||
|
||||
# Promotion Activation
|
||||
Promotion.promo_activate(sale_data)
|
||||
return true, sale_data
|
||||
else
|
||||
return false, "No Current Open Shift for This Employee"
|
||||
@@ -1219,7 +1226,7 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay
|
||||
.includes(:bookings => :dining_facility)
|
||||
.select("sales.*, SUM(sale_payments.payment_amount) AS payments_for_credits_amount")
|
||||
.joins(:bookings)
|
||||
.left_joins(:sale_payments_for_credits)
|
||||
.left_joins(:payments_for_credits)
|
||||
.completed
|
||||
.where.not(total_amount: 0)
|
||||
.group(:sale_id)
|
||||
|
||||
Reference in New Issue
Block a user