This commit is contained in:
Myat Zin Wai Maw
2019-12-13 10:12:08 +06:30
parent 79598c0126
commit f45849de49
39 changed files with 123 additions and 1121 deletions

View File

@@ -32,6 +32,7 @@ class Sale < ApplicationRecord
scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) }
scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) }
scope :shop, -> { where("sales.shop_code=?",Shop.current_shop.shop_code) }
def qty_of(item_instance_code)
@@ -832,7 +833,7 @@ class Sale < ApplicationRecord
return num
end
def self.daily_sales_list(from,to,shop_code)
def self.daily_sales_list(from,to)
sales = select("
sales.*,
SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount,
@@ -853,7 +854,7 @@ def self.daily_sales_list(from,to,shop_code)
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")
.along_with_sale_payments_except_void_between(from, to)
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to).shop
.group("sale_id").to_sql
daily_total = connection.select_all("SELECT
@@ -2431,39 +2432,40 @@ def self.get_check_sale_data(transaction_date)
.group("sales.receipt_no,sales.sale_status")
end
def paymal_payment_void
puts self.sale_payments.to_json
membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",self.shop_code)
membership_actions_data = MembershipAction.find_by_membership_type_and_shop_code("void",self.shop_code)
if !membership_actions_data.nil?
sale_payments =self.sale_payments.where("payment_reference is not null")
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
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
# 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