91 lines
2.8 KiB
Ruby
91 lines
2.8 KiB
Ruby
class Origami::UnionpayController < BaseOrigamiController
|
|
def index
|
|
@sale_id = params[:sale_id]
|
|
@cashier_type = params[:type]
|
|
path = request.fullpath
|
|
# limit unionpay_amount
|
|
if path.include? ("credit_payment")
|
|
sale_data = Sale.get_sale_data_for_other_payment_credit(@sale_id)
|
|
else
|
|
sale_data = Sale.find_by_sale_id(@sale_id)
|
|
end
|
|
total = 0
|
|
@unionpaycount = 0
|
|
@shop = Shop.first
|
|
@rounding_adj = 0
|
|
@can_unionpay = 0
|
|
@member_discount = 0
|
|
@sub_total = 0
|
|
@membership_id = nil
|
|
@receipt_no = nil
|
|
if !sale_data.nil?
|
|
total = sale_data.grand_total
|
|
others = 0
|
|
|
|
if @shop.is_rounding_adj
|
|
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
|
|
else
|
|
new_total = sale_data.grand_total
|
|
end
|
|
@rounding_adj = new_total-sale_data.grand_total
|
|
if path.include? ("credit_payment")
|
|
sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data)
|
|
else
|
|
sale_payment_data = sale_data.sale_payments
|
|
end
|
|
|
|
sale_payment_data.each do |sale_payment|
|
|
if sale_payment.payment_method == "unionpay"
|
|
@unionpaycount = @unionpaycount + sale_payment.payment_amount
|
|
else
|
|
others = others + sale_payment.payment_amount
|
|
end
|
|
end
|
|
@can_unionpay = total - @unionpaycount - others
|
|
@member_discount = MembershipSetting.find_by_discount(1)
|
|
@sub_total = sale_data.total_amount
|
|
@membership_id = sale_data.customer.membership_id
|
|
#for bank integration
|
|
@receipt_no = sale_data.receipt_no
|
|
end
|
|
bank_integration = Lookup.collection_of('bank_integration')
|
|
@bank_integration = 0
|
|
if !bank_integration[0].nil?
|
|
@bank_integration = bank_integration[0][1]
|
|
end
|
|
end
|
|
|
|
def create
|
|
cash = params[:amount]
|
|
sale_id = params[:sale_id]
|
|
ref_no = params[:ref_no]
|
|
if(Sale.exists?(sale_id))
|
|
saleObj = Sale.find(sale_id)
|
|
shop_details = Shop.first
|
|
|
|
# rounding adjustment
|
|
# if shop_details.is_rounding_adj
|
|
# new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
|
# rounding_adj = new_total-saleObj.grand_total
|
|
# saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
|
|
# end
|
|
|
|
# saleObj = Sale.find(sale_id)
|
|
#end rounding adjustment
|
|
path = request.fullpath
|
|
payment_for = false
|
|
if path.include? ("credit_payment")
|
|
payment_for = true
|
|
end
|
|
sale_payment = SalePayment.new
|
|
@status, @sale = sale_payment.process_payment(saleObj, current_user, cash, "unionpay",ref_no,payment_for)
|
|
end
|
|
end
|
|
|
|
#Shop Name in Navbor
|
|
helper_method :shop_detail
|
|
def shop_detail
|
|
@shop = Shop.first
|
|
end
|
|
end
|