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

@@ -8,7 +8,9 @@ class Employee < ApplicationRecord
validates_presence_of :name, :role
validates_presence_of :password, :on => [:create]
validates :emp_id, uniqueness: { scope: :shop_code }, numericality: true, length: {in: 1..4}, allow_blank: true
validates :emp_id, numericality: true, length: {in: 1..4}, allow_blank: true
validates :emp_id, uniqueness: { scope: :shop_code }, if: -> { Employee.columns.map { |column| column.name }.include?('shop_code') }
validates :emp_id, uniqueness: true, if: -> { !Employee.columns.map { |column| column.name }.include?('shop_code') }
validates :password, numericality: true, length: {in: 3..9}, allow_blank: true
before_create :generate_app_id, :generate_app_token,

View File

@@ -1434,9 +1434,9 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
end
if shift.present?
query = query.where("sales.shift_sale_id in (?) ", shift.to_a)
query = query.where(sales: { shift_sale_id: shift })
elsif shift_sale_range.present?
query = query.where("sales.shift_sale_id in (?) ", shift_sale_range.to_a)
query = query.where(sales: { shift_sale_id: shift_sale_range.to_a })
else
query = query.where("sales.receipt_date between ? and ? ", from,to)
end
@@ -2034,7 +2034,7 @@ end
.where("sales.shift_sale_id=?", sh_id)
.group("acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price")
.order("acc.title desc, i.account_id desc, i.menu_category_code desc, i.unit_price asc")
end
end
def self.pending_sale(type)
query = Sale.all
@@ -2043,6 +2043,7 @@ end
query = query.where("sales.sale_status = 'new' AND orders.status = 'billed' AND orders.source =? ","#{type}")
.group("sales.sale_id")
end
def self.pending_order(type)
query = Booking.all
query = query.joins("join booking_orders as booking_orders on booking_orders.booking_id = bookings.booking_id")
@@ -2050,6 +2051,7 @@ end
query = query.where("bookings.booking_status = 'assign' AND orders.status = 'new' AND orders.source =? ","#{type}")
.group("bookings.booking_id")
end
def self.completed_sale(type)
if type == "cashier"
type = "and orders.source = 'emenu' or orders.source = 'cashier'"

View File

@@ -36,7 +36,7 @@ class SaleTax < ApplicationRecord
end
def display_name
"#{self.tax_name} (#{'Incl. ' if self.tax_type == 'inclusive'}#{self.tax_rate}%"
"#{self.tax_name} (#{'Incl.' if self.inclusive} #{self.tax_rate}%"
end
private

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()