fixed conflict
This commit is contained in:
@@ -14,7 +14,7 @@ class Customer < ApplicationRecord
|
||||
|
||||
def self.get_member_group
|
||||
|
||||
membership = MembershipSetting.find_by_membership_type("smartpay_url")
|
||||
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
app_token = membership.auth_token.to_s
|
||||
|
||||
url = membership.gateway_url.to_s + "/api/get_all_member_group".to_s
|
||||
|
||||
@@ -48,7 +48,7 @@ class Order < ApplicationRecord
|
||||
process_order_queue
|
||||
|
||||
#send order to broadcast job
|
||||
send_order_broadcast
|
||||
#send_order_broadcast
|
||||
|
||||
return true, booking
|
||||
|
||||
|
||||
@@ -55,8 +55,8 @@ class Sale < ApplicationRecord
|
||||
generate_receipt_no
|
||||
order = Order.find(order_id)
|
||||
|
||||
#Default - Values
|
||||
self.tax_type = "execlusive"
|
||||
#Default Tax - Values
|
||||
self.tax_type = "exclusive"
|
||||
|
||||
self.requested_by = requested_by
|
||||
self.requested_at = DateTime.now.utc
|
||||
|
||||
@@ -12,7 +12,7 @@ class SaleItem < ApplicationRecord
|
||||
|
||||
|
||||
def self.get_order_items_details(sale_id)
|
||||
order_details = SaleItem.select("sales.total_discount as discount_amount,DATE_FORMAT(sales.receipt_date,'%Y-%m-%d %h:%m') as receipt_date,
|
||||
order_details = SaleItem.select("sales.total_tax as tax_amount, sales.grand_total as grand_total_amount , sales.total_discount as discount_amount,DATE_FORMAT(sales.receipt_date,'%Y-%m-%d %h:%m') as receipt_date,
|
||||
sales.cashier_name,sales.receipt_no,sale_items.product_name as item_name,sale_items.qty,sale_items.price,sale_items.unit_price as total_price")
|
||||
.joins("left join sales on sales.sale_id = sale_items.sale_id")
|
||||
.where("sale_items.sale_id=?",sale_id)
|
||||
|
||||
@@ -8,12 +8,10 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status
|
||||
|
||||
def process_payment(invoice, action_by, cash_amount)
|
||||
def process_payment(invoice, action_by, cash_amount, payment_method)
|
||||
|
||||
self.sale = invoice
|
||||
self.received_amount = cash_amount
|
||||
|
||||
payment_method = "cash"
|
||||
amount_due = invoice.grand_total
|
||||
|
||||
#get all payment for this invoices
|
||||
@@ -54,7 +52,7 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
#record an payment in sale-audit
|
||||
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{amount} | Payment Status ->#{payment_status}"
|
||||
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}"
|
||||
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
|
||||
|
||||
return true, self.sale
|
||||
@@ -66,6 +64,38 @@ class SalePayment < ApplicationRecord
|
||||
return false, "No outstanding Amount"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def self.get_paypar_account(url,token,membership_id,campaign_type_id)
|
||||
response = HTTParty.get(url,
|
||||
:body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
}
|
||||
)
|
||||
return response;
|
||||
|
||||
end
|
||||
|
||||
def self.redeem(paypar_url,token,membership_id,received_amount,sale_id,campaign_type_id)
|
||||
membership_actions_data = Settings::MembershipAction.find_by_membership_type("redeem_url");
|
||||
if !membership_actions_data.nil?
|
||||
url = paypar_url.to_s + membership_actions_data.gateway_url.to_s
|
||||
campaign_type_id = 1
|
||||
response = HTTParty.post(url,
|
||||
:body => { generic_customer_id:membership_id,total_amount:received_amount,receipet_no:sale_id,campaign_type_id:campaign_type_id,account_no:""}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
}
|
||||
)
|
||||
else
|
||||
response =false;
|
||||
end
|
||||
|
||||
return response;
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
@@ -73,7 +103,7 @@ class SalePayment < ApplicationRecord
|
||||
payment_status = false
|
||||
self.payment_method = "cash"
|
||||
self.payment_amount = self.received_amount
|
||||
self.outstanding_amount = self.sale.grand_total - self.received_amount
|
||||
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
|
||||
self.payment_status = "paid"
|
||||
payment_method = self.save!
|
||||
|
||||
@@ -148,16 +178,37 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
def paypar_payment
|
||||
##TODO - Integration with Paypar (SmartPay)
|
||||
payment_status = false
|
||||
|
||||
#Next time - validate if the vochure number is valid - within
|
||||
self.payment_method = "paypar"
|
||||
self.payment_amount = self.received_amount
|
||||
self.payment_reference = self.voucher_no
|
||||
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
|
||||
self.payment_status = "pending"
|
||||
payment_method = self.save!
|
||||
|
||||
campaign_type_id =1;
|
||||
customer_data = Customer.find_by_customer_id(self.sale.customer_id)
|
||||
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id,campaign_type_id)
|
||||
if membership_data["status"]==true
|
||||
SalePayment.where(:sale_payment_id => self.sale_payment_id).update_all(:payment_status => 'paid')
|
||||
sale_update_payment_status(self.received_amount.to_f)
|
||||
|
||||
else
|
||||
sale_update_payment_status(0)
|
||||
end
|
||||
|
||||
return payment_status
|
||||
|
||||
end
|
||||
|
||||
def sale_update_payment_status(paid_amount)
|
||||
puts "paid_amount"
|
||||
puts paid_amount
|
||||
#update amount_outstanding
|
||||
self.sale.amount_received = self.sale.amount_received + paid_amount
|
||||
self.sale.amount_changed = amount - self.sale.amount_received
|
||||
if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0)
|
||||
self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f
|
||||
self.sale.amount_changed = paid_amount.to_f - self.sale.amount_received
|
||||
if (self.sale.grand_total <= self.sale.amount_received.to_f && self.sale.amount_changed.to_f > 0)
|
||||
self.sale.payment_status = "paid"
|
||||
self.sale.sale_status = "completed"
|
||||
self.sale.save!
|
||||
|
||||
2
app/models/settings/membership_action.rb
Normal file
2
app/models/settings/membership_action.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class Settings::MembershipAction < ApplicationRecord
|
||||
end
|
||||
Reference in New Issue
Block a user