Merge branch 'master' into license
This commit is contained in:
@@ -45,14 +45,14 @@ class Booking < ApplicationRecord
|
||||
if filter.blank?
|
||||
keyword = ''
|
||||
else
|
||||
keyword = "booking_id LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%"
|
||||
keyword = "booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%"
|
||||
end
|
||||
|
||||
if from.present? && to.present?
|
||||
sale = Sale.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and NOT sale_status = 'void' ", from,to)
|
||||
query = sale.where(keyword)
|
||||
booking = Booking.where("DATE_FORMAT(created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(created_at,'%d-%m-%Y') <= ? and NOT booking_status = 'void' ", from,to)
|
||||
query = booking.where(keyword)
|
||||
else
|
||||
where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%",)
|
||||
where("booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ class DiningFacility < ApplicationRecord
|
||||
end
|
||||
|
||||
def get_current_booking
|
||||
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
|
||||
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_by is null").limit(1) #and checkout_at is null
|
||||
if booking.count > 0 then
|
||||
return booking[0]
|
||||
else
|
||||
@@ -65,4 +65,32 @@ class DiningFacility < ApplicationRecord
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def get_current_checkout_booking
|
||||
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is not null and checkout_by is null").limit(1)
|
||||
if booking.count > 0 then
|
||||
return booking[0]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
def get_checkout_booking
|
||||
booking = self.get_current_checkout_booking
|
||||
if booking
|
||||
now = Time.now.utc
|
||||
hr = (now.strftime("%H").to_i).to_int
|
||||
min = (now.strftime("%M").to_i).to_int
|
||||
|
||||
checkout_at = booking.checkout_at.utc
|
||||
|
||||
checkout_at = checkout_at - hr.hour
|
||||
checkout_at = checkout_at - min.minutes
|
||||
checkout_at = checkout_at.utc.strftime("%M").to_i
|
||||
|
||||
if checkout_at <= 15
|
||||
return booking
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -907,7 +907,17 @@ end
|
||||
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
|
||||
"and payment_status='paid' and sale_status= 'completed'")
|
||||
.group('mi.name')
|
||||
.order("SUM(i.qty) DESC").limit(5)
|
||||
.order("SUM(i.qty) DESC").limit(10)
|
||||
end
|
||||
|
||||
def self.bottom_products(today)
|
||||
query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," +
|
||||
" i.price as unit_price,mi.name as product_name")
|
||||
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code")
|
||||
.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+
|
||||
"and payment_status='paid' and sale_status= 'completed'")
|
||||
.group('mi.name')
|
||||
.order("SUM(i.qty) ASC").limit(10)
|
||||
end
|
||||
|
||||
def self.hourly_sales(today)
|
||||
@@ -941,9 +951,9 @@ end
|
||||
# .joins("join sale_payments on sale_id = sales.sale_id")
|
||||
# .group("sales.sale_id")
|
||||
|
||||
query = SalePayment.where('s.sale_status = "completed" and payment_method = "mpu" or payment_method = "visa" or payment_method = "master" or payment_method = "jcb" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
||||
.sum("payment_amount")
|
||||
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb"',today)
|
||||
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||
.sum("sp.payment_amount")
|
||||
|
||||
end
|
||||
|
||||
@@ -953,6 +963,99 @@ end
|
||||
.sum("payment_amount")
|
||||
end
|
||||
|
||||
def self.summary_sale_receipt(today)
|
||||
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
|
||||
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_payment_methods(today)
|
||||
query = Sale.select("sp.payment_method")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||
end
|
||||
|
||||
def self.payment_sale(payment_method, today)
|
||||
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
|
||||
if payment_method == 'card'
|
||||
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb"',today)
|
||||
else
|
||||
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||
end
|
||||
query.sum("sp.payment_amount")
|
||||
end
|
||||
|
||||
def self.total_customer(today)
|
||||
query = Sale.select("count(distinct sales.customer_id) as total_cus")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_dinein(today)
|
||||
query = Sale.select("count(distinct sales.customer_id) as total_dinein_cus")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today)
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_takeaway(today)
|
||||
query = Sale.select("count(distinct sales.customer_id) as total_take_cus")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_membership(today)
|
||||
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is not null',today)
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_other_customer(today)
|
||||
query = Sale.select("count(distinct sales.customer_id) as total_cus")
|
||||
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today)
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_order(today)
|
||||
query = Sale.select("count(distinct a.order_id) as total_order")
|
||||
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
|
||||
.joins("JOIN orders as b ON b.order_id = a.order_id")
|
||||
.where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_account(today)
|
||||
query = Sale.select("distinct b.id as account_id, b.title as title")
|
||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||
.joins("JOIN accounts as b ON b.id = a.account_id")
|
||||
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
|
||||
end
|
||||
|
||||
def self.account_data(account_id, today)
|
||||
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
|
||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.top_items(today)
|
||||
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
|
||||
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||
.where("sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||
.group("a.product_code")
|
||||
.order("SUM(a.price) DESC")
|
||||
.first()
|
||||
end
|
||||
|
||||
def self.total_foc_items(today)
|
||||
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
|
||||
.where("sales.sale_status = 'completed' and a.remark='foc' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
|
||||
.count()
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_custom_id
|
||||
|
||||
@@ -264,8 +264,6 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
def sale_update_payment_status(paid_amount)
|
||||
puts paid_amount
|
||||
puts "parid Masssssssssssssssssssssssssssssssssssssssss"
|
||||
#update amount_outstanding
|
||||
self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f
|
||||
self.sale.save!
|
||||
@@ -316,8 +314,6 @@ class SalePayment < ApplicationRecord
|
||||
self.sale.rebate_status = nil
|
||||
end
|
||||
end
|
||||
puts "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
|
||||
puts response.to_json
|
||||
end
|
||||
|
||||
self.sale.save!
|
||||
@@ -375,7 +371,8 @@ class SalePayment < ApplicationRecord
|
||||
paypar.each do |pp|
|
||||
if pp.payment_method == "paypar"
|
||||
payparcost = payparcost + pp.payment_amount
|
||||
elsif pp.payment_method == "creditnote"
|
||||
end
|
||||
if pp.payment_method == "creditnote"
|
||||
credit = 1
|
||||
end
|
||||
end
|
||||
@@ -410,7 +407,9 @@ class SalePayment < ApplicationRecord
|
||||
rescue SocketError
|
||||
response = { "status": false, "message": "Can't connect server"}
|
||||
end
|
||||
|
||||
puts response.to_json
|
||||
puts payparcost
|
||||
puts overall_dis
|
||||
redeem_amount = payparcost + overall_dis
|
||||
|
||||
total_percentage = 0
|
||||
@@ -431,15 +430,19 @@ class SalePayment < ApplicationRecord
|
||||
data = {:type => a[:type], :amount => a[:amount]}
|
||||
type_arr.each do |si|
|
||||
if si[:type] == a[:type]
|
||||
amount = (redeem_amount / total_percentage)*si[:percentage]
|
||||
actual = a[:amount] - amount
|
||||
data[:amount] = actual
|
||||
if credit == 1
|
||||
data[:amount] = 0
|
||||
else
|
||||
amount = (redeem_amount / total_percentage)*si[:percentage]
|
||||
actual = a[:amount] - amount
|
||||
data[:amount] = actual
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
rebate_arr.push(data)
|
||||
end
|
||||
|
||||
|
||||
total_amount = rebate_prices - payparcost - overall_dis
|
||||
|
||||
if credit == 1
|
||||
@@ -485,6 +488,7 @@ class SalePayment < ApplicationRecord
|
||||
response = { "status": "no_member", "message": "Not membership"}
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -135,4 +135,20 @@ class ShiftSale < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
def self.search(filter,from,to)
|
||||
if filter.blank?
|
||||
keyword = ''
|
||||
else
|
||||
keyword = "booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%"
|
||||
end
|
||||
|
||||
if from.present? && to.present?
|
||||
booking = ShiftSale.where("DATE_FORMAT(created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(created_at,'%d-%m-%Y') <= ? and NOT booking_status = 'void' ", from,to)
|
||||
query = booking.where(keyword)
|
||||
else
|
||||
where("booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user