Rebate balance in receipt

This commit is contained in:
Aung Myo
2017-06-20 11:31:02 +06:30
15 changed files with 266 additions and 103 deletions

View File

@@ -231,7 +231,7 @@ class Order < ApplicationRecord
.joins("left join orders on orders.order_id = booking_orders.order_id")
.joins("left join sales on sales.sale_id = bookings.sale_id")
.where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::TABLE_TYPE,true)
.group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id")
.group("bookings.booking_id")
# For PG
# booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true
# sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id
@@ -262,7 +262,7 @@ class Order < ApplicationRecord
.joins("left join orders on orders.order_id = booking_orders.order_id")
.joins("left join sales on sales.sale_id = bookings.sale_id")
.where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::ROOM_TYPE,true)
.group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id")
.group("bookings.booking_id")
# For PG
# booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true
# sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id

View File

@@ -29,7 +29,9 @@ class OrderQueueStation < ApplicationRecord
if oqs.id == oqpbz.order_queue_station_id
#Same Order_items can appear in two location.
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
end
else
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
end
end
end
end

View File

@@ -65,11 +65,11 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
end
#Bill Receipt Print
def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name, food_total, beverage_total, member_info = nil)
def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name, food_total, beverage_total, member_info = nil,rebate_amount=nil)
#Use CUPS service
#Generate PDF
#Print
pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total, member_info)
pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total, member_info,rebate_amount)
pdf.render_file "tmp/receipt_bill.pdf"
self.print("tmp/receipt_bill.pdf")

View File

@@ -31,8 +31,7 @@ class Sale < ApplicationRecord
if (booking)
Rails.logger.debug "Booking -> Booking Order Count -> " + booking.booking_orders.count.to_s
#get all order attached to this booking and combine into 1 invoice
puts booking.booking_orders.length
booking.booking_orders.each do |order|
if booking.sale_id
status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by)
@@ -98,6 +97,8 @@ class Sale < ApplicationRecord
order.save
booking.sale_id = self.id
booking.checkout_at = Time.now.utc
booking.checkout_by = requested_by.name
booking.save
return true, self.id
@@ -198,9 +199,14 @@ class Sale < ApplicationRecord
# Tax Calculate
def apply_tax(total_taxable)
#if tax is not apply create new record
# self.sale_taxes.each do |existing_tax|
# #delete existing and create new
# existing_tax.delete
# end
#if tax is not apply create new record
self.sale_taxes.each do |existing_tax|
SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax|
#delete existing and create new
existing_tax.delete
end

View File

@@ -36,11 +36,13 @@ class SaleItem < ApplicationRecord
beverage_prices=0
sale_items.each do |si|
food_price, beverage_price = self.get_price(si.sale_item_id)
food_price, beverage_price = self.get_price(si.sale_item_id)
food_prices = food_prices + food_price
beverage_prices = beverage_prices + beverage_price
end
puts food_prices
puts beverage_prices
return food_prices, beverage_prices
end
@@ -54,11 +56,22 @@ class SaleItem < ApplicationRecord
.where("sale_items.sale_item_id=?", sale_item_id.to_s)
if item[0].account_id == 1
food_price = item[0].price
else
else
beverage_price = item[0].price
end
return food_price, beverage_price
return food_price, beverage_price
end
def self.get_overall_discount(sale_id)
price = 0.0
item=SaleItem.where("product_code=?", sale_id)
item.each do|i|
price += i.price
end
return price
end
private

View File

@@ -54,8 +54,10 @@ class SalePayment < ApplicationRecord
#record an payment in sale-audit
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
sObj = Sale.find(self.sale_id)
response = rebat(sObj)
return true, response
else
#record an payment in sale-audit
remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]"
@@ -66,37 +68,52 @@ class SalePayment < ApplicationRecord
end
def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token)
def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token)
# Control for Paypar Cloud
begin
response = HTTParty.get(url,
:body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
)
return response;
:body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}, :timeout => 10
)
rescue Net::OpenTimeout
response = { status: false }
end
return response;
end
def self.redeem(paypar_url,token,membership_id,received_amount,sale_id)
membership_actions_data = MembershipAction.find_by_membership_type("redeem");
if !membership_actions_data.nil?
url = paypar_url.to_s + membership_actions_data.gateway_url.to_s
merchant_uid = membership_actions_data.merchant_account_id
auth_token = membership_actions_data.auth_token
campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"]
sale_data = Sale.find_by_sale_id(sale_id)
if sale_data
response = HTTParty.post(url,
:body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
)
else
response = false;
end
if sale_data
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
},
:timeout => 10
)
puts "vvvvvvvvv"
puts response.to_json
rescue Net::OpenTimeout
response = false
end
else
response = false;
end
else
response =false;
@@ -119,7 +136,6 @@ class SalePayment < ApplicationRecord
end
def creditnote_payment(customer_id)
payment_status = false
self.payment_method = "creditnote"
@@ -187,17 +203,20 @@ class SalePayment < ApplicationRecord
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!
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)
puts 'membership_data["status"]'
puts membership_data.to_json
puts "amountttttttttttt"
puts self.received_amount
if membership_data["status"]==true
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!
SalePayment.where(:sale_payment_id => self.sale_payment_id).update_all(:payment_status => 'paid')
sale_update_payment_status(self.received_amount.to_f)
@@ -251,7 +270,12 @@ class SalePayment < ApplicationRecord
payparcost = payparcost + pp.payment_amount
end
end
total_amount = food_prices - payparcost
overall_dis = SaleItem.get_overall_discount(sObj.id)
total_amount = food_prices - payparcost + overall_dis
puts "total_amount"
puts food_prices
puts payparcost
puts total_amount
if total_amount > 0
receipt_no = sObj.receipt_no
membership = MembershipSetting.find_by_membership_type("paypar_url")
@@ -261,6 +285,7 @@ class SalePayment < ApplicationRecord
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
# Control for Paypar Cloud
begin
response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id,
receipt_no: receipt_no,auth_token:auth_token}.to_json,
@@ -271,8 +296,8 @@ class SalePayment < ApplicationRecord
rescue Net::OpenTimeout
response = { status: false }
end
puts response.to_json
return response
# puts response.to_json
end
end
end