Merge branch 'r-1902001-01' into foodcourt

This commit is contained in:
Thein Lin Kyaw
2020-07-11 04:00:55 +06:30
99 changed files with 2085 additions and 1781 deletions

View File

@@ -684,7 +684,7 @@ class Sale < ApplicationRecord
.joins("JOIN orders ON orders.order_id=booking_orders.order_id")
.joins("JOIN order_items ON orders.order_id=order_items.order_id")
.joins("JOIN customers ON orders.customer_id=customers.customer_id")
.where("sales.sale_status =? and sales.payment_status =? and orders.source='app' and sales.shift_sale_id = ?",
.where("sales.sale_status =? and sales.payment_status =? and orders.source='app' and sales.shift_sale_id = ?",
'completed','paid', @current_shift.id
).order("bookings.created_at desc").uniq
@@ -791,20 +791,20 @@ class Sale < ApplicationRecord
return num
end
def self.daily_sales_list(from,to)
payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
def self.daily_sales_list(from,to)
payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
sales = select(Sale.column_names)
.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}"}.push('').join(', ')}
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) -
SUM(case when (sale_payments.payment_method not in('creditnote') and sale_audits.sale_audit_id IS NOT NULL) 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")
.sale_payments_with_audit_except_void_between(from, to)
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
.group("sale_id").to_sql
sales = select(Sale.column_names)
.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}"}.push('').join(', ')}
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) -
SUM(case when (sale_payments.payment_method not in('creditnote') and sale_audits.sale_audit_id IS NOT NULL) 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")
.sale_payments_with_audit_except_void_between(from, to)
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
.group("sale_id").to_sql
daily_total = connection.select_all("SELECT
daily_total = connection.select_all("SELECT
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total,
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as total_sale,
IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total,
@@ -1238,11 +1238,21 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay
.includes(:bookings => :dining_facility)
.select("sales.*, SUM(sale_payments.payment_amount) AS payments_for_credits_amount")
.joins(:bookings)
.joins("INNER JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.left_joins(:payments_for_credits)
.completed
.where.not(total_amount: 0)
.group(:sale_id)
.order(:receipt_date)
if payment_type.present?
if payment_type == 'card'
query = query.where(sanitize_sql_array(["sp.payment_method IN (?)", SalePayment::CARD]))
else
query = query.where("sp.payment_method = (?)", payment_type)
end
end
if shift.present?
query = query.where("sales.shift_sale_id in (?)", shift.to_a)
elsif shift_sale_range.present?
@@ -1528,7 +1538,7 @@ end
def self.employee_sales(current_user,from,to)
shift = if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
ShiftSale.current_open_shift(current_user.id)
ShiftSale.current_open_shift(current_user)
end
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
@@ -1575,7 +1585,7 @@ end
end
if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor')
if shift = ShiftSale.current_open_shift(current_user.id)
if shift = ShiftSale.current_open_shift(current_user)
query = query.where("sales.shift_sale_id = ?", shift.id)
end
end
@@ -1631,10 +1641,10 @@ end
def self.total_payment_methods(current_user=nil,from=nil,to=nil)
query = Sale.select("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END as payment_method")
query = Sale.select(sanitize_sql_array(["CASE WHEN sp.payment_method IN (?) THEN 'card' ELSE sp.payment_method END as payment_method", SalePayment::CARD]))
.where("sales.sale_status = 'completed'")
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
.group("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END")
.group(sanitize_sql_array(["CASE WHEN sp.payment_method IN (?) THEN 'card' ELSE sp.payment_method END", SalePayment::CARD]))
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
@@ -1777,7 +1787,7 @@ end
# query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to)
# end
# else
# shift = ShiftSale.current_open_shift(current_user.id)
# shift = ShiftSale.current_open_shift(current_user)
# 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)
@@ -1794,7 +1804,7 @@ end
# if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor'
# query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today)
# else
# shift = ShiftSale.current_open_shift(current_user.id)
# shift = ShiftSale.current_open_shift(current_user)
# if !shift.nil?
# query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id)
# end
@@ -2311,7 +2321,7 @@ def self.get_daily_sale_data(transaction_date)
CASE WHEN sale_payments.payment_method = 'giftvoucher' THEN SUM(sale_payments.payment_amount) ELSE SUM(0) END as voucher_sales
FROM sale_payments
GROUP BY sale_payments.sale_id, sale_payments.payment_method"
query = Sale.select("
sales.receipt_no as check_num,
sales.receipt_date as business_date,
@@ -2348,49 +2358,50 @@ def self.get_daily_sale_data(transaction_date)
.where("DATE(sales.receipt_date) = ? AND sales.sale_status != ?", transaction_date, :void)
.group("sales.receipt_no,sales.sale_status")
end
def paymal_payment_void
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
membership_actions_data = MembershipAction.find_by_membership_type("void")
if !membership_actions_data.nil?
sale_payments =self.sale_payments.where("payment_reference is not null")
if !sale_payments.empty?
account_no =sale_payments[0].payment_reference
url = membership_setting.gateway_url.to_s + membership_actions_data.gateway_url.to_s
merchant_uid = membership_actions_data.merchant_account_id
auth_token = membership_actions_data.auth_token
params = { receipt_no:self.receipt_no,
account_no:account_no,
merchant_uid:merchant_uid,
auth_token:auth_token}.to_json
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => params,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
},
:timeout => 10
)
rescue Errno::ECONNREFUSED
response = { "status" => false, "message" => "Can't open membership server"}
rescue Net::OpenTimeout
response = { "status" => false, "message" => "No internet connection " }
rescue OpenURI::HTTPError
response = { "status" => false, "message" => "No internet connection "}
rescue SocketError
response = { "status" => false, "message" => "No internet connection "}
end
def paymal_payment_void
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
membership_actions_data = MembershipAction.find_by_membership_type("void")
if !membership_actions_data.nil?
sale_payments =self.sale_payments.where("payment_reference is not null")
if !sale_payments.empty?
account_no =sale_payments[0].payment_reference
url = membership_setting.gateway_url.to_s + membership_actions_data.gateway_url.to_s
merchant_uid = membership_actions_data.merchant_account_id
auth_token = membership_actions_data.auth_token
params = { receipt_no:self.receipt_no,
account_no:account_no,
merchant_uid:merchant_uid,
auth_token:auth_token}.to_json
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => params,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
},
:timeout => 10
)
rescue Errno::ECONNREFUSED
response = { "status" => false, "message" => "Can't open membership server"}
rescue Net::OpenTimeout
response = { "status" => false, "message" => "No internet connection " }
rescue OpenURI::HTTPError
response = { "status" => false, "message" => "No internet connection "}
rescue SocketError
response = { "status" => false, "message" => "No internet connection "}
end
end
else
response = { "status" => false}
end
else
response = { "status" => false}
end
Rails.logger.debug "Void Payment response"
Rails.logger.debug response.to_json
return response;
end
Rails.logger.debug "Void Payment response"
Rails.logger.debug response.to_json
return response;
end
# Loader Service SFTP End
private
@@ -2408,7 +2419,9 @@ private
self.total_tax = self.total_tax.round(precision)
end
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
adjust_rounding
if (!['foc', 'waste', 'spoile', 'void'].include? self.payment_status)
adjust_rounding
end
end
def update_stock_journal