Rebate balance in receipt
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
class ReceiptBillPdf < Prawn::Document
|
||||
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width
|
||||
def initialize(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total, member_info = nil)
|
||||
def initialize(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total, member_info = nil,rebate_amount = nil)
|
||||
self.page_width = 210
|
||||
self.page_height = 2500
|
||||
self.margin = 5
|
||||
self.price_width = 35
|
||||
self.price_width = 40
|
||||
self.qty_width = 20
|
||||
self.total_width = 35
|
||||
self.total_width = 40
|
||||
self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width))
|
||||
self.item_height = 15
|
||||
self.item_description_width = (self.page_width-20) / 2
|
||||
@@ -32,9 +32,13 @@ class ReceiptBillPdf < Prawn::Document
|
||||
line_items(sale_items, food_total, beverage_total)
|
||||
all_total(sale_data)
|
||||
|
||||
|
||||
if member_info != nil
|
||||
member_info(member_info,customer_name)
|
||||
member_info(member_info,customer_name,rebate_amount,sale_data)
|
||||
end
|
||||
|
||||
customer(customer_name)
|
||||
|
||||
footer
|
||||
end
|
||||
|
||||
@@ -53,11 +57,10 @@ class ReceiptBillPdf < Prawn::Document
|
||||
# move_down 2
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do
|
||||
text "Receipt No:", :size => self.item_font_size,:align => :left
|
||||
text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
|
||||
bounding_box([self.label_width, y_position], :width =>self.item_width) do
|
||||
text "#{sale_data.receipt_no}" , :size => self.item_font_size, :align => :left
|
||||
bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do
|
||||
text "#{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right
|
||||
end
|
||||
move_down 5
|
||||
|
||||
@@ -71,11 +74,28 @@ class ReceiptBillPdf < Prawn::Document
|
||||
# move_down 5
|
||||
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do
|
||||
text "Date:", :size => self.item_font_size,:align => :left
|
||||
bounding_box([0, y_position], :width =>self.item_width) do
|
||||
text "Waiter: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left
|
||||
end
|
||||
bounding_box([self.label_width,y_position], :width => self.item_width) do
|
||||
text "#{sale_data.receipt_date.strftime('%Y-%m-%d %I:%M %p')}" , :size => self.item_font_size,:align => :left
|
||||
move_down 5
|
||||
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width =>self.item_width, :height => self.item_height) do
|
||||
text "Cashier: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
move_down 5
|
||||
|
||||
# bounding_box([self.label_width,y_position], :width =>self.item_width) do
|
||||
# text "#{customer_name}" , :size => self.item_font_size,:align => :left
|
||||
# end
|
||||
# move_down 5
|
||||
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do
|
||||
text "Time In: #{ sale_data.bookings[0].checkin_at.strftime('%I:%M %p') }", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do
|
||||
text "Time Out: #{ sale_data.bookings[0].checkout_at.strftime('%I:%M %p') }" , :size => self.item_font_size,:align => :right
|
||||
end
|
||||
|
||||
move_down 5
|
||||
@@ -91,7 +111,7 @@ class ReceiptBillPdf < Prawn::Document
|
||||
text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
|
||||
text_box "Price", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
||||
text_box "Qty", :at =>[(self.item_width+self.price_width),y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
|
||||
text_box "Total", :at =>[(self.item_width+self.price_width),y_position], :width => self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
||||
text_box "Total", :at =>[(self.item_width+self.price_width+4),y_position], :width => self.total_width+3, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
||||
|
||||
}
|
||||
|
||||
@@ -118,10 +138,10 @@ class ReceiptBillPdf < Prawn::Document
|
||||
y_position = cursor
|
||||
|
||||
pad_top(15) {
|
||||
text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :overflow => :shrink_to_fix, :size => self.item_font_size, :overflow => :shrink_to_fix
|
||||
text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
|
||||
text_box "#{price}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
||||
text_box "#{qty}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
|
||||
text_box "#{total_price}", :at =>[(item_name_width),y_position], :width =>self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
||||
text_box "#{total_price}", :at =>[(item_name_width+4),y_position], :width =>self.total_width+3, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
|
||||
}
|
||||
move_down 3
|
||||
end
|
||||
@@ -163,7 +183,7 @@ class ReceiptBillPdf < Prawn::Document
|
||||
text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right
|
||||
end
|
||||
|
||||
if sale_data.sale_taxes.length > 1
|
||||
if sale_data.sale_taxes.length > 0
|
||||
sale_data.sale_taxes.each do |st|
|
||||
move_down 5
|
||||
y_position = cursor
|
||||
@@ -193,28 +213,82 @@ class ReceiptBillPdf < Prawn::Document
|
||||
y_position = cursor
|
||||
move_down 5
|
||||
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
||||
text "Grand Total", :size => self.item_font_size,:align => :left
|
||||
text "Grand Total", :size => self.header_font_size,:align => :left
|
||||
end
|
||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
||||
text "#{sale_data.grand_total}" , :size => self.item_font_size,:align => :right
|
||||
text "#{sale_data.grand_total}" , :size => self.header_font_size,:align => :right
|
||||
end
|
||||
move_down 5
|
||||
# stroke_horizontal_rule
|
||||
|
||||
sale_payment(sale_data)
|
||||
|
||||
end
|
||||
|
||||
def sale_payment(sale_data)
|
||||
|
||||
stroke_horizontal_rule
|
||||
move_down 5
|
||||
SalePayment.where('sale_id = ?', sale_data.sale_id).each do |payment|
|
||||
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
||||
text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
||||
text "#{ payment.payment_amount }" , :size => self.item_font_size,:align => :right
|
||||
end
|
||||
move_down 5
|
||||
end
|
||||
if sale_data.amount_received > 0
|
||||
y_position = cursor
|
||||
move_down 5
|
||||
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
||||
text "Change Amount", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
||||
text "#{sale_data.amount_changed}" , :size => self.item_font_size,:align => :right
|
||||
end
|
||||
move_down 5
|
||||
end
|
||||
end
|
||||
|
||||
# show member information
|
||||
def member_info(member_info,customer_name)
|
||||
def member_info(member_info,customer_name,rebate_amount,sale_data)
|
||||
|
||||
move_down 7
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
||||
text "Customer", :size => self.item_font_size,:align => :left
|
||||
if rebate_amount != nil
|
||||
stroke_horizontal_rule
|
||||
if rebate_amount[1]["status"] == true
|
||||
total_redeem = 0.0
|
||||
amount = 0.0
|
||||
earm_amount = 0.0
|
||||
SalePayment.where('sale_id = ?', sale_data.sale_id).each do |payment|
|
||||
if payment.payment_method == "paypar"
|
||||
total_redeem = total_redeem + payment.payment_amount
|
||||
end
|
||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
||||
text "#{ customer_name }" , :size => self.item_font_size,:align => :right
|
||||
end
|
||||
move_down 5
|
||||
end
|
||||
earm_amount = earm_amount + rebate_amount[1]["rebate_earned"].to_f
|
||||
amount = amount + total_redeem
|
||||
amount = amount + earm_amount
|
||||
old = rebate_amount[1]["total_rebate_amount"].to_f - amount
|
||||
move_down 5
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
||||
text "Old Balance", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
||||
text "#{old}" , :size => self.item_font_size,:align => :right
|
||||
end
|
||||
move_down 5
|
||||
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
||||
text "Earned Balance", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
||||
text "#{ rebate_amount[1]["rebate_earned"] }" , :size => self.item_font_size,:align => :right
|
||||
end
|
||||
end
|
||||
end
|
||||
if member_info["status"] == true
|
||||
member_info["data"].each do |res|
|
||||
|
||||
@@ -233,6 +307,18 @@ class ReceiptBillPdf < Prawn::Document
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def customer(customer_name)
|
||||
move_down 5
|
||||
y_position = cursor
|
||||
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
||||
text "Customer", :size => self.item_font_size,:align => :left
|
||||
end
|
||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
||||
text "#{ customer_name }" , :size => self.item_font_size,:align => :right
|
||||
end
|
||||
end
|
||||
|
||||
def footer
|
||||
|
||||
Reference in New Issue
Block a user