foodcourt apis for app

This commit is contained in:
Thein Lin Kyaw
2022-07-08 16:06:12 +06:30
parent 7485486868
commit 063345eae3
37 changed files with 785 additions and 171 deletions

View File

@@ -154,9 +154,9 @@ class ShiftSale < ApplicationRecord
shift_other_payments = Sale.select("sales.sale_id, sale_payments.payment_method as name")
if payment_methods.present?
shift_other_payments = shift_other_payments.select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as `#{method == 'paypar' ? 'redeem' : method}`"}.join(', ')}")
shift_other_payments = shift_other_payments.select("#{payment_methods.map { |method| "IFNULL(SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end), 0) as `#{method == 'paypar' ? 'redeem' : method}`"}.join(', ')}")
end
shift_other_payments.select("SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
shift_other_payments.select("IFNULL(SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end), 0) 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
@@ -204,7 +204,7 @@ class ShiftSale < ApplicationRecord
# end
def self.get_total_other_charges(shift)
query = SaleItem.select("sum(sale_items.qty * sale_items.unit_price) as total_other_charges_amount")
query = SaleItem.select("IFNULL(sum(sale_items.qty * sale_items.unit_price), 0) as total_other_charges_amount")
.joins("JOIN sales as s ON s.sale_id = sale_items.sale_id")
.where('shift_sale_id =? and s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null',shift.id)
.first()