shop code
This commit is contained in:
@@ -85,7 +85,7 @@ class SalePayment < ApplicationRecord
|
||||
amount_due = amount_due - payment.payment_amount
|
||||
end
|
||||
end
|
||||
if (amount_due >= 0)
|
||||
if (amount_due > 0)
|
||||
payment_status = false
|
||||
membership_data = nil
|
||||
#route to payment type
|
||||
@@ -777,27 +777,14 @@ class SalePayment < ApplicationRecord
|
||||
def table_update_status(sale_obj)
|
||||
status = true
|
||||
sale_count = 0
|
||||
booking = Booking.find_by_sale_id(sale_obj.id)
|
||||
if booking
|
||||
if booking = sale_obj.bookings[0]
|
||||
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' && tablebooking.sale.sale_status != 'spoile' && tablebooking.sale.sale_status != 'waste'
|
||||
status = false
|
||||
sale_count += 1
|
||||
else
|
||||
status = true
|
||||
end
|
||||
else
|
||||
status = false
|
||||
sale_count += 1
|
||||
end
|
||||
end
|
||||
table = booking.dining_facility
|
||||
if Booking.left_joins(:sale).where(dining_facility_id: booking.dining_facility_id).where.not(booking_status: 'moved').where("sales.sale_status NOT IN ('completed', 'void', 'spoile', 'waste') OR sales.sale_status IS NULL").exists?
|
||||
status = false
|
||||
end
|
||||
if status && sale_count == 0
|
||||
|
||||
if status
|
||||
table.update_attributes(status: "available")
|
||||
# table.status = "available"
|
||||
# table.save
|
||||
@@ -969,38 +956,34 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
#credit payment query
|
||||
def self.get_credit_sales(params,shop_code)
|
||||
receipt_no = ""
|
||||
customer = ""
|
||||
if !params["receipt_no"].blank?
|
||||
receipt_no = " and s.receipt_no LIKE '%#{params["receipt_no"]}%'"
|
||||
|
||||
def self.get_credit_sales(params)
|
||||
payments = SalePayment.select("sale_payments.sale_id, sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount")
|
||||
.select("SUM(sale_payments.payment_amount) OVER (PARTITION BY sale_payments.sale_id) total_payment_amount")
|
||||
|
||||
credit_sales = Sale.select("sales.sale_id, sales.receipt_no, sales.receipt_date as sale_date, sales.cashier_name")
|
||||
.select("sale_payments.sale_payment_id, sale_payments.payment_amount").select("customers.name as customer_name")
|
||||
.joins("JOIN (#{payments.to_sql}) AS sale_payments ON sale_payments.sale_id = sales.sale_id").joins(:customer).joins(:orders)
|
||||
.completed.paid.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount")
|
||||
.group(:receipt_no)
|
||||
.order(:receipt_date).order(:receipt_no)
|
||||
|
||||
if params["receipt_no"].present?
|
||||
credit_sales = credit_sales.where("sales.receipt_no LIKE ?", "%#{params["receipt_no"]}%")
|
||||
|
||||
end
|
||||
|
||||
if !params["customer_id"].blank?
|
||||
customer = " and s.customer_id = '#{params["customer_id"]}'"
|
||||
if params["customer_id"].present?
|
||||
credit_sales = credit_sales.where("sales.customer_id = ?", params["customer_id"])
|
||||
end
|
||||
|
||||
order_source_query = "(select orders.source FROM orders JOIN sale_orders so ON so.order_id=orders.order_id WHERE so.sale_id=s.sale_id GROUP BY so.sale_id)"
|
||||
|
||||
query = SalePayment.select("s.receipt_no, sale_payments.sale_payment_id,
|
||||
sale_payments.payment_method,
|
||||
SUM(sale_payments.payment_amount) as payment_amount,
|
||||
s.receipt_date as sale_date,
|
||||
s.sale_id,
|
||||
s.cashier_name as cashier_name, c.name as customer_name")
|
||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||
.joins("INNER JOIN customers c ON c.customer_id = s.customer_id")
|
||||
|
||||
if params[:type].nil?
|
||||
query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
|
||||
elsif params[:type] == "cashier"
|
||||
query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND #{order_source_query}='#{params[:type]}' OR #{order_source_query}='emenu' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
|
||||
else
|
||||
query = query.where("(CASE WHEN (s.grand_total + s.amount_changed)=(select SUM(payment_amount) FROM sale_payments WHERE sale_id=s.sale_id AND payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' AND #{order_source_query}='#{params[:type]}' END) and s.sale_status = 'completed' and s.payment_status='paid' #{receipt_no} #{customer}")
|
||||
if params[:type].present?
|
||||
sources = []
|
||||
sources << params[:type]
|
||||
sources << 'emenu' if params[:type] == 'cashier'
|
||||
credit_sales = credit_sales.where("orders.source IN (?)", sources)
|
||||
end
|
||||
query = query.where("s.shop_code='#{shop_code}'").group("s.receipt_no")
|
||||
.order("s.receipt_date ASC, s.receipt_no ASC")
|
||||
return query
|
||||
|
||||
end
|
||||
|
||||
def self.get_credit_amount_due_left(sale_id)
|
||||
|
||||
Reference in New Issue
Block a user