107 lines
3.0 KiB
Ruby
107 lines
3.0 KiB
Ruby
class Origami::PaymentsController < BaseOrigamiController
|
|
|
|
|
|
def index
|
|
end
|
|
|
|
def create
|
|
cash = params[:cash]
|
|
sale_id = params[:sale_id]
|
|
if(Sale.exists?(sale_id))
|
|
saleObj = Sale.find(sale_id)
|
|
sale_payment = SalePayment.new
|
|
rebate_amount = sale_payment.process_payment(saleObj, @user, cash, "cash")
|
|
|
|
puts "resssssssssssssssssss"
|
|
puts rebate_amount.to_json
|
|
|
|
unique_code = "ReceiptBillPdf"
|
|
customer= Customer.find(saleObj.customer_id)
|
|
|
|
# get member information
|
|
member_info = Customer.get_member_account(customer)
|
|
|
|
# get printer info
|
|
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
# Calculate Food and Beverage Total
|
|
food_total, beverage_total = SaleItem.calculate_food_beverage(saleObj.sale_items)
|
|
|
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
|
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, food_total, beverage_total, member_info,rebate_amount)
|
|
end
|
|
end
|
|
|
|
def show
|
|
sale_id = params[:sale_id]
|
|
if Sale.exists?(sale_id)
|
|
@cash = 0.0
|
|
@other = 0.0
|
|
@ppamount = 0.0
|
|
@visacount= 0.0
|
|
@jcbcount= 0.0
|
|
@mastercount = 0.0
|
|
@sale_data = Sale.find_by_sale_id(sale_id)
|
|
|
|
#get customer amount
|
|
@customer = Customer.find(@sale_data.customer_id)
|
|
|
|
# get member information
|
|
response = Customer.get_member_account(@customer)
|
|
|
|
@balance = 0.00
|
|
@accountable_type = ''
|
|
if response["status"]==true
|
|
response["data"].each do |res|
|
|
if res["accountable_type"] == "RebateAccount"
|
|
@balance = res["balance"]
|
|
@accountable_type = res["accountable_type"]
|
|
end
|
|
end
|
|
end
|
|
|
|
#end customer amount
|
|
|
|
@sale_data.sale_payments.each do |spay|
|
|
if spay.payment_method == "cash"
|
|
@cash = spay.payment_amount
|
|
end
|
|
if spay.payment_method == "mpu"
|
|
@other += spay.payment_amount
|
|
elsif spay.payment_method == "paypar"
|
|
@ppamount += spay.payment_amount
|
|
elsif spay.payment_method == "visa"
|
|
@visacount += spay.payment_amount
|
|
elsif spay.payment_method == "jcb"
|
|
@jcbcount += spay.payment_amount
|
|
elsif spay.payment_method == "master"
|
|
@mastercount += spay.payment_amount
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
def reprint
|
|
|
|
sale_id = params[:sale_id]
|
|
|
|
saleObj = Sale.find(sale_id)
|
|
|
|
unique_code = "ReceiptBillPdf"
|
|
customer= Customer.find(saleObj.customer_id)
|
|
|
|
# get member information
|
|
member_info = Customer.get_member_account(customer)
|
|
|
|
# get printer info
|
|
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
|
|
# Calculate Food and Beverage Total
|
|
food_total, beverage_total = SaleItem.calculate_food_beverage(saleObj.sale_items)
|
|
|
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
|
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, food_total, beverage_total, member_info)
|
|
end
|
|
|
|
|
|
end
|