Sale Item Pdf added
This commit is contained in:
@@ -49,7 +49,7 @@ class Sale < ApplicationRecord
|
||||
|
||||
# dining charges
|
||||
charges = DiningCharge.where('dining_facility_id=?',booking.dining_facility_id).take
|
||||
if !charges.nil?
|
||||
if !charges.nil?
|
||||
block_count, diningprice = DiningCharge.amount_calculate(charges, booking.checkin_at, booking.checkout_at)
|
||||
if charges.charge_type =='hr'
|
||||
dining_time = booking.checkin_at.strftime('%H:%M %p').to_s + " - " + booking.checkout_at.strftime('%H:%M %p').to_s
|
||||
@@ -84,7 +84,7 @@ class Sale < ApplicationRecord
|
||||
# current cashier login
|
||||
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
|
||||
current_shift = ShiftSale.current_shift
|
||||
# shift with terminal zone
|
||||
# shift with terminal zone
|
||||
|
||||
# set cashier
|
||||
if order_source.downcase == "emenu"
|
||||
@@ -112,7 +112,7 @@ class Sale < ApplicationRecord
|
||||
self.cashier_name = cashier.name
|
||||
self.shift_sale_id = shift.id
|
||||
else
|
||||
if open_cashier.count>0 # if we have two open cashier
|
||||
if open_cashier.count>0 # if we have two open cashier
|
||||
# table and terminal in multiple shift
|
||||
self.cashier_id = open_cashier[0].id
|
||||
self.cashier_name = open_cashier[0].name
|
||||
@@ -171,9 +171,9 @@ class Sale < ApplicationRecord
|
||||
else
|
||||
booking.checkout_at = Time.now.utc.getlocal
|
||||
end
|
||||
|
||||
|
||||
booking.checkout_by = requested_by.name
|
||||
booking.save
|
||||
booking.save
|
||||
|
||||
# InventoryJob.perform_now(self.id)
|
||||
saleObj = Sale.find(self.id)
|
||||
@@ -195,7 +195,7 @@ class Sale < ApplicationRecord
|
||||
order_id = order.order_id # order_id
|
||||
bk_order = BookingOrder.find_by_order_id(order_id)
|
||||
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
|
||||
|
||||
|
||||
if check_booking.sale_id.nil?
|
||||
# Create Sale if it doesn't exist
|
||||
# puts "current_login_employee"
|
||||
@@ -234,7 +234,7 @@ class Sale < ApplicationRecord
|
||||
if !item.set_menu_items.nil?
|
||||
add_sub_item(item.set_menu_items)
|
||||
end
|
||||
|
||||
|
||||
#this will result in multiple orders belonging in multiple invoices - because of spilt invoices.
|
||||
link_order_sale(item.order_id, taxable)
|
||||
end
|
||||
@@ -253,7 +253,7 @@ class Sale < ApplicationRecord
|
||||
|
||||
#save sale_audit
|
||||
sale_item = SaleItem.new
|
||||
|
||||
|
||||
#pull
|
||||
if !menu_category.nil?
|
||||
sale_item.menu_category_code = menu_category.code
|
||||
@@ -326,7 +326,7 @@ class Sale < ApplicationRecord
|
||||
sale_item.price = diningprice
|
||||
sale_item.save
|
||||
|
||||
# Re-calc
|
||||
# Re-calc
|
||||
sale = Sale.find(self.id)
|
||||
self.compute_by_sale_items(self.id, sale.sale_items, self.total_discount, nil, order_source)
|
||||
end
|
||||
@@ -481,7 +481,7 @@ class Sale < ApplicationRecord
|
||||
if order_source.to_s == "emenu"
|
||||
order_source = "cashier"
|
||||
end
|
||||
|
||||
|
||||
if sale.payment_status != 'foc'
|
||||
tax_profiles.each do |tax|
|
||||
if tax.group_type.to_s == order_source.to_s
|
||||
@@ -548,7 +548,7 @@ class Sale < ApplicationRecord
|
||||
# Tax Calculate
|
||||
def apply_tax(total_taxable, order_source = nil, tax_type = nil)
|
||||
shop = Shop.first
|
||||
|
||||
|
||||
#if tax is not apply create new record
|
||||
# SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax|
|
||||
# #delete existing and create new
|
||||
@@ -669,7 +669,7 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
|
||||
def adjust_rounding
|
||||
shop_details = Shop.first
|
||||
shop_details = Shop.first
|
||||
# rounding adjustment
|
||||
if shop_details.is_rounding_adj
|
||||
a = self.grand_total % 25 # Modulus
|
||||
@@ -685,11 +685,11 @@ class Sale < ApplicationRecord
|
||||
else
|
||||
self.rounding_adjustment = 0.00
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
def compute_adjust_rounding(grand_total)
|
||||
shop_details = Shop.first
|
||||
shop_details = Shop.first
|
||||
# rounding adjustment
|
||||
if shop_details.is_rounding_adj
|
||||
a = grand_total % 25 # Modulus
|
||||
@@ -786,7 +786,7 @@ class Sale < ApplicationRecord
|
||||
.joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id")
|
||||
.joins(" JOIN orders ON orders.order_id=booking_orders.order_id")
|
||||
.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and (CASE WHEN (sales.grand_total + sales.amount_changed)=(select SUM(sale_payments.payment_amount)
|
||||
FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) #{keyword} #{custo} #{source}", from,to)
|
||||
FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote') THEN NULL ELSE payment_method='creditnote' END) #{keyword} #{custo} #{source}", from,to)
|
||||
else
|
||||
sale = Sale.select("sales.*,#{order_source_query} as source").joins(" JOIN sale_payments sp on sp.sale_id = sales.sale_id")
|
||||
.joins(" JOIN bookings ON bookings.sale_id=sales.sale_id")
|
||||
@@ -922,7 +922,7 @@ def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||
.group('i.product_code')
|
||||
.order("sale_items.menu_category_code")
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
JOIN employees ea ON ea.id = sales.cashier_id")
|
||||
|
||||
|
||||
@@ -944,13 +944,14 @@ def self.get_by_shiftsales(from,to,shift)
|
||||
.joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id")
|
||||
.where("sales.shift_sale_id=? and sp.payment_method='foc'",shift_sale.id)
|
||||
.first()
|
||||
|
||||
|
||||
if !foc_data.foc_sales.nil? && foc_data.foc_sales > 0
|
||||
shift_sale.other_sales -= foc_data.foc_sales
|
||||
foc = foc_data.foc_sales
|
||||
end
|
||||
|
||||
shift_sale_data[shift_sale.id] = {
|
||||
:shift_id => shift_sale.id,
|
||||
:cashier_terminal_name => shift_sale.cashier_terminal.name,
|
||||
:employee_name => shift_sale.employee.name,
|
||||
:shift_started_at => shift_sale.shift_started_at,
|
||||
@@ -1037,7 +1038,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
|
||||
end
|
||||
|
||||
query = self.get_item_query(type)
|
||||
|
||||
|
||||
discount_query = 0
|
||||
total_card_amount = 0
|
||||
total_cash_amount = 0
|
||||
@@ -1098,12 +1099,12 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
|
||||
|
||||
else
|
||||
query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to)
|
||||
|
||||
|
||||
if type.nil? || type == 'all' || type == "other"
|
||||
other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
|
||||
end
|
||||
product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
|
||||
|
||||
|
||||
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
|
||||
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
|
||||
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
@@ -1147,17 +1148,17 @@ end
|
||||
|
||||
#product sale report query
|
||||
def self.get_menu_item_query(order_by)
|
||||
query = MenuItem.unscoped.select("acc.id as account_id,
|
||||
acc.title as account_name,
|
||||
query = MenuItem.unscoped.select("acc.id as account_id,
|
||||
acc.title as account_name,
|
||||
mii.item_instance_code as item_code, " +
|
||||
"(CASE WHEN si.qty IS NOT NULL THEN SUM(si.qty) ELSE 0 END) as total_item," +
|
||||
"(CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END) as unit_price," +
|
||||
"(CASE WHEN si.qty IS NOT NULL THEN (SUM(si.qty) * si.unit_price) ELSE 0 END) as grand_total," +
|
||||
"mii.price as unit_price, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE CONCAT(menu_items.name,' - ',mii.item_instance_name) END) as product_name,
|
||||
"mii.price as unit_price, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE CONCAT(menu_items.name,' - ',mii.item_instance_name) END) as product_name,
|
||||
mc.name as" +
|
||||
" menu_category_name,mc.id as menu_category_id, si.status as status_type,
|
||||
" menu_category_name,mc.id as menu_category_id, si.status as status_type,
|
||||
si.price as price ")
|
||||
.joins(" LEFT JOIN menu_item_instances mii ON menu_items.id = mii.menu_item_id" +
|
||||
.joins(" LEFT JOIN menu_item_instances mii ON menu_items.id = mii.menu_item_id" +
|
||||
" LEFT JOIN menu_categories mc ON mc.id = menu_items.menu_category_id" +
|
||||
" LEFT JOIN accounts acc ON acc.id = menu_items.account_id" +
|
||||
" LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" +
|
||||
@@ -1203,7 +1204,7 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay
|
||||
query = Sale.select("sales.*,bookings.dining_facility_id as table_id")
|
||||
.where("sale_status= 'completed' and sale_payments.payment_amount != 0 #{payment_type}")
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.joins("join bookings on bookings.sale_id = sales.sale_id")
|
||||
.joins("join bookings on bookings.sale_id = sales.sale_id")
|
||||
.group("sales.sale_id")
|
||||
if shift.present?
|
||||
query = query.where("sales.shift_sale_id in (?)", shift.to_a)
|
||||
@@ -1216,13 +1217,13 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay
|
||||
end
|
||||
|
||||
def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,order_source)
|
||||
sub_query = "SELECT (CASE WHEN SUM(payment_amount) > 0
|
||||
sub_query = "SELECT (CASE WHEN SUM(payment_amount) > 0
|
||||
THEN DATE_FORMAT(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30'),'%d %b %y %h:%i%p') ELSE '-' END)
|
||||
FROM `sale_payments`
|
||||
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||
WHERE sale_audits.sale_id = s.sale_id"
|
||||
|
||||
sub_query1 = "SELECT (CASE WHEN SUM(payment_amount) > 0 THEN SUM(payment_amount) -
|
||||
sub_query1 = "SELECT (CASE WHEN SUM(payment_amount) > 0 THEN SUM(payment_amount) -
|
||||
(SUM(payment_amount) - (SELECT SUM(payment_amount) FROM sale_payments WHERE payment_method='creditnote' AND sale_id=s.sale_id)) ELSE 0 END)
|
||||
FROM `sale_payments`
|
||||
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||
@@ -1253,7 +1254,7 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,
|
||||
WHERE sale_audits.sale_id = s.sale_id) = 0"
|
||||
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)"
|
||||
|
||||
|
||||
if order_source.blank?
|
||||
source = ""
|
||||
else
|
||||
@@ -1345,7 +1346,7 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type
|
||||
ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id
|
||||
INNER JOIN sales ON sa.sale_id = sales.sale_id
|
||||
WHERE sales.sale_status='completed' "
|
||||
|
||||
|
||||
if shift.present?
|
||||
shift_ids = shift.map(&:id).join(",")
|
||||
sub_query += " AND sales.shift_sale_id in (#{shift_ids})"
|
||||
@@ -1389,7 +1390,7 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type
|
||||
(CASE WHEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end)) > 0 THEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) - (#{sub_query})) ELSE 0 END) as credit_amount,
|
||||
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
|
||||
.joins("join sales on sales.sale_id = sale_payments.sale_id")
|
||||
.joins("join sales on sales.sale_id = sale_payments.sale_id")
|
||||
|
||||
if shift.present?
|
||||
|
||||
@@ -1397,7 +1398,7 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type
|
||||
# .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')")
|
||||
if payment_type.blank?
|
||||
sale_type = sale_payment.where(" s.sale_status = 'completed' and payment_amount != 0 and s.shift_sale_id in (?)",shift.to_a)
|
||||
.order("payment_method")
|
||||
.order("payment_method")
|
||||
else
|
||||
sale_type = sale_payment.where(" payment_method= '#{payment_type}' and payment_amount != 0 and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift.to_a)
|
||||
end
|
||||
@@ -1408,20 +1409,20 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type
|
||||
# .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')")
|
||||
if payment_type.blank?
|
||||
sale_type = sale_payment.where(" s.sale_status = 'completed' and payment_amount != 0 and s.shift_sale_id in (?)",shift_sale_range.to_a)
|
||||
.order("payment_method")
|
||||
.order("payment_method")
|
||||
else
|
||||
sale_type = sale_payment.where(" payment_method='#{payment_type}' and payment_amount != 0 and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift_sale_range.to_a)
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
|
||||
all_total = payments_total.where("sales.receipt_date between ? and ? and sales.sale_status= 'completed' and sale_payments.payment_amount != 0", from,to)
|
||||
# .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')")
|
||||
if payment_type.blank?
|
||||
sale_type = sale_payment.where(" s.sale_status = 'completed' and payment_amount != 0 and s.receipt_date between ? and ? ",from,to)
|
||||
.order("payment_method")
|
||||
.order("payment_method")
|
||||
else
|
||||
sale_type = sale_payment.where(" payment_method='#{payment_type}' and payment_amount != 0 and s.sale_status = 'completed' and s.receipt_date between ? and ? ",from,to)
|
||||
sale_type = sale_payment.where(" payment_method='#{payment_type}' and payment_amount != 0 and s.sale_status = 'completed' and s.receipt_date between ? and ? ",from,to)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1594,12 +1595,12 @@ end
|
||||
|
||||
def self.employee_sales(today,current_user,from,to,from_time,to_time)
|
||||
#sub query for credit payment
|
||||
outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END
|
||||
outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END
|
||||
FROM sale_payments
|
||||
JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||
JOIN sales ON sale_payments.sale_id = sales.sale_id
|
||||
WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'"
|
||||
|
||||
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
||||
@@ -1765,12 +1766,12 @@ end
|
||||
end
|
||||
|
||||
def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||
outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END
|
||||
outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END
|
||||
FROM sale_payments
|
||||
JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||
JOIN sales ON sale_payments.sale_id = sales.sale_id
|
||||
WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'"
|
||||
|
||||
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
||||
@@ -1972,12 +1973,12 @@ end
|
||||
time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
||||
end
|
||||
|
||||
outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END
|
||||
outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END
|
||||
FROM sale_payments
|
||||
JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
||||
JOIN sales ON sale_payments.sale_id = sales.sale_id
|
||||
WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'"
|
||||
|
||||
|
||||
if (!from.nil? && !to.nil?) && (from != "" && to!="")
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'"
|
||||
@@ -2162,7 +2163,7 @@ end
|
||||
if !shift.nil?
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id).first()
|
||||
else
|
||||
else
|
||||
query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id).first()
|
||||
end
|
||||
end
|
||||
@@ -2378,14 +2379,14 @@ end
|
||||
if current_user.nil?
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time)
|
||||
else
|
||||
else
|
||||
query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to)
|
||||
end
|
||||
else
|
||||
if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
|
||||
if !from_time.nil? && !to_time.nil?
|
||||
query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time)
|
||||
else
|
||||
else
|
||||
query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to)
|
||||
end
|
||||
else
|
||||
@@ -2468,12 +2469,12 @@ end
|
||||
query = Sale.select("cst.res_date,cst.res_time,cst.trace,cst.pan,cst.batch_no,cst.exp_date,cst.app,cst.res_type,cst.ref_no,cst.terminal_id,cst.merchant_id,cst.app_code")
|
||||
.joins("JOIN card_sale_trans as cst on cst.sale_id = sales.sale_id")
|
||||
.where("sales.sale_id=? and status = 'Approved'",sale_id)
|
||||
|
||||
|
||||
return query
|
||||
end
|
||||
|
||||
def self.add_to_existing_pending_invoice(dining,sale_id,booking)
|
||||
|
||||
|
||||
existing_booking = Booking.find_by_sale_id(sale_id)
|
||||
if dining.to_i > 0
|
||||
table = DiningFacility.find(dining)
|
||||
@@ -2483,7 +2484,7 @@ end
|
||||
# end
|
||||
if booking.sale_id.nil?
|
||||
booking.booking_orders.each do |booking_order|
|
||||
|
||||
|
||||
booking.booking_status = 'moved'
|
||||
order = Order.find(booking_order.order_id)
|
||||
order.status = 'billed'
|
||||
@@ -2502,7 +2503,7 @@ end
|
||||
order.save
|
||||
booking.save
|
||||
end
|
||||
|
||||
|
||||
booking_order = BookingOrder.where('booking_id=?',booking)
|
||||
booking_order.each do |bo|
|
||||
bo.booking_id = existing_booking.booking_id
|
||||
@@ -2513,7 +2514,7 @@ end
|
||||
else
|
||||
if booking.sale_id.nil?
|
||||
booking.booking_orders.each do |booking_order|
|
||||
|
||||
|
||||
booking.booking_status = 'moved'
|
||||
order = Order.find(booking_order.order_id)
|
||||
order.status = 'billed'
|
||||
@@ -2532,7 +2533,7 @@ end
|
||||
order.save
|
||||
booking.save
|
||||
end
|
||||
|
||||
|
||||
booking_order = BookingOrder.where('booking_id=?',booking)
|
||||
booking_order.each do |bo|
|
||||
bo.booking_id = existing_booking.booking_id
|
||||
@@ -2577,17 +2578,17 @@ end
|
||||
SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
|
||||
SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount,
|
||||
SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount,
|
||||
SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount,
|
||||
SUM(case when (sale_payments.payment_method='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount,
|
||||
SUM(case when (sale_payments.payment_method='alipay') then sale_payments.payment_amount else 0 end) as alipay_amount,
|
||||
SUM(case when (sale_payments.payment_method='paymal') then sale_payments.payment_amount else 0 end) as paymal_amount,
|
||||
SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount,
|
||||
SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount,
|
||||
SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount,
|
||||
SUM(case when (sale_payments.payment_method='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount,
|
||||
SUM(case when (sale_payments.payment_method='alipay') then sale_payments.payment_amount else 0 end) as alipay_amount,
|
||||
SUM(case when (sale_payments.payment_method='paymal') then sale_payments.payment_amount else 0 end) as paymal_amount,
|
||||
SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount,
|
||||
SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount,
|
||||
SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) as credit_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount,
|
||||
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
|
||||
SUM(case when (sale_items.status='foc') then sale_items.price else 0 end) as item_foc,
|
||||
SUM(case when (sale_items.status='Discount') then sale_items.price else 0 end) as item_discount,
|
||||
SUM(case when (sale_items.status='Discount') then sale_items.price else 0 end) as item_discount,
|
||||
SUM(sale_items.qty) as qty,
|
||||
sales.cashier_name as cashier_name,
|
||||
surveys.child as child,
|
||||
@@ -2597,7 +2598,7 @@ end
|
||||
.joins("join sale_items on sale_items.sale_id = sales.sale_id")
|
||||
.joins("join sale_audits on sale_audits.sale_id = sales.sale_id")
|
||||
.joins("left join surveys on surveys.receipt_no = sales.receipt_no")
|
||||
|
||||
|
||||
query = query.where("sales.sale_status != 'new' && sale_payments.payment_amount > 0")
|
||||
query = query.where("sales.created_at between ? and ?", '2017-11-01 00:00:00 +0630','2018-11-16 13:59:59 +0630')
|
||||
.group("sales.sale_id")
|
||||
|
||||
Reference in New Issue
Block a user