Adding Redeem at payment

This commit is contained in:
Moe Su
2017-06-08 15:17:26 +06:30
50 changed files with 144 additions and 65 deletions

View File

@@ -4,6 +4,6 @@ class Account < ApplicationRecord
has_many :menu_items
# belongs_to :lookup , :class_name => "Lookup"
def self.collection
Account.select("id, title").map { |e| [e.title, e.id] }
end
Account.select("id, title").map { |e| [e.title, e.id] }
end
end

View File

@@ -4,7 +4,7 @@ class MenuItem < ApplicationRecord
has_many :menu_item_instances
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
belongs_to :account, :optional => true
belongs_to :account
validates_presence_of :item_code, :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item

View File

@@ -208,8 +208,7 @@ class Order < ApplicationRecord
OrderBroadcastJob.perform_later(self.id)
end
#Origami: Cashier : to view order type Table
#Origami: Cashier : to view order Table
def self.get_order_table
order_table = Order.select("orders.order_id as order_id,sum(order_items.qty*order_items.price) as total_price,
order_items.order_items_id as order_items_id,dining_facilities.name as table_name")
@@ -220,6 +219,8 @@ class Order < ApplicationRecord
.where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,"dine_in",true)
.group("orders.order_id, order_items.order_items_id,dining_facilities.name")
end
#Origami: Cashier : to view booking order Table
def self.get_booking_order_table
booking_orders = Booking.select("sales.receipt_no,orders.status as order_status,
bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name")

View File

@@ -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
@@ -81,6 +79,21 @@ class SalePayment < ApplicationRecord
end
def self.redeem(paypar_url,token,membership_id,received_amount,sale_id,campaign_type_id)
url = paypar_url.to_s + "/api/redeem".to_s
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'
}
)
puts "RRRRRRRR"
puts response.to_json
return response;
end
private
def cash_payment
payment_status = false
@@ -161,15 +174,38 @@ class SalePayment < ApplicationRecord
end
def paypar_payment
##TODO - Integration with Paypar (SmartPay)
puts "Paypar Payment"
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("smartpay_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
self.sale.amount_changed = paid_amount - self.sale.amount_received
if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0)
self.sale.payment_status = "paid"
self.sale.sale_status = "completed"