58 lines
1.8 KiB
Ruby
58 lines
1.8 KiB
Ruby
class Api::Payment::MobilepaymentController < Api::ApiController
|
|
|
|
# skip_before_action :authenticate
|
|
|
|
def cash
|
|
|
|
cash = params[:cash]
|
|
sale_id = params[:sale_id]
|
|
cashier_id = params[:cashier_id]
|
|
|
|
current_user = Employee.find(cashier_id)
|
|
|
|
if(Sale.exists?(sale_id))
|
|
|
|
saleObj = Sale.find(sale_id)
|
|
sale_items = SaleItem.get_all_sale_items(sale_id)
|
|
|
|
shop_detail = current_shop
|
|
|
|
# rounding adjustment
|
|
if !path.include? ("credit_payment")
|
|
if shop_detail.is_rounding_adj
|
|
a = saleObj.grand_total % 25 # Modulus
|
|
b = saleObj.grand_total / 25 # Division
|
|
#not calculate rounding if modulus is 0 and division is even
|
|
#calculate rounding if modulus is zero or not zero and division are not even
|
|
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
|
|
|
|
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
|
|
end
|
|
end
|
|
# end rounding adjustment
|
|
|
|
sale_payment = SalePayment.new
|
|
|
|
sale_payment =sale_payment.process_payment(saleObj, current_user, cash, "cash")
|
|
if sale_payment[0]
|
|
@cash ={"change_amount"=>sale_payment[3],"balance_amount"=>sale_payment[4] ,"receipt_url"=>''}
|
|
end
|
|
@out = true,@cash
|
|
|
|
else
|
|
@out =false,"Something wrong!"
|
|
sale_payment = SalePayment.new
|
|
sale_payment = sale_payment.process_payment(saleObj, current_user, cash, "cash")
|
|
if sale_payment[0]
|
|
@cash = {"change_amount"=>sale_payment[3],"balance_amount"=>sale_payment[4] ,"receipt_url"=>''}
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
end
|