353 lines
15 KiB
Ruby
353 lines
15 KiB
Ruby
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, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details)
|
|
self.page_width = 210
|
|
self.page_height = 7000
|
|
self.margin = 5
|
|
self.price_width = 40
|
|
self.qty_width = 20
|
|
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
|
|
self.label_width = 100
|
|
# @item_width = self.page_width.to_i / 2
|
|
# @qty_width = @item_width.to_i / 3
|
|
# @double = @qty_width * 1.3
|
|
# @half_qty = @qty_width / 2
|
|
#setting page margin and width
|
|
super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
|
|
|
|
# font "public/fonts/#{font_name}".to_s + ".ttf".to_s
|
|
# font "public/fonts/Zawgyi-One.ttf"
|
|
# font "public/fonts/padauk.ttf"
|
|
self.header_font_size = 10
|
|
self.item_font_size = 8
|
|
|
|
header( shop_details)
|
|
|
|
stroke_horizontal_rule
|
|
|
|
cashier_info(sale_data, customer_name)
|
|
line_items(sale_items)
|
|
all_total(sale_data)
|
|
|
|
|
|
if member_info != nil
|
|
member_info(member_info,customer_name,rebate_amount,sale_data)
|
|
end
|
|
|
|
customer(customer_name)
|
|
|
|
if discount_price_by_accounts.length > 0
|
|
discount_account(discount_price_by_accounts)
|
|
end
|
|
|
|
items_account(item_price_by_accounts)
|
|
|
|
footer
|
|
end
|
|
|
|
def header (shop_details)
|
|
move_down 7
|
|
text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center
|
|
move_down 5
|
|
text "#{shop_details.address}", :size => self.item_font_size,:align => :center
|
|
# move_down self.item_height
|
|
move_down 5
|
|
text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center
|
|
move_down 5
|
|
|
|
stroke_horizontal_rule
|
|
end
|
|
|
|
def cashier_info(sale_data, customer_name)
|
|
move_down 7
|
|
# move_down 2
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do
|
|
text "Receipt No: #{sale_data.receipt_no}", :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 "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right
|
|
end
|
|
move_down 5
|
|
|
|
y_position = cursor
|
|
bounding_box([0, y_position], :width =>self.item_width) do
|
|
text "Waiter: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left
|
|
end
|
|
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
|
|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do
|
|
text "Receipt Date : #{ sale_data.receipt_date.strftime('%d-%m-%Y') } ( #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } )",:size => self.item_font_size,:align => :left
|
|
end
|
|
|
|
|
|
# bounding_box([self.item_description_width,y_position], :width =>self.label_width+5) do
|
|
# text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') }
|
|
# - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') })" ,
|
|
# :size => self.item_font_size,:align => :right
|
|
# end
|
|
|
|
move_down 5
|
|
stroke_horizontal_rule
|
|
end
|
|
|
|
def line_items(sale_items)
|
|
move_down 5
|
|
y_position = cursor
|
|
move_down 5
|
|
pad_top(15) {
|
|
# @item_width.to_i + @half_qty.to_i
|
|
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+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 -5
|
|
stroke_horizontal_rule
|
|
add_line_item_row(sale_items)
|
|
end
|
|
|
|
def add_line_item_row(sale_items)
|
|
item_name_width = (self.item_width+self.price_width)
|
|
y_position = cursor
|
|
move_down 5
|
|
sub_total = 0.0
|
|
sale_items.each do |item|
|
|
# check for item not to show
|
|
if item.price != 0
|
|
sub_total += (item.qty*item.unit_price)
|
|
qty = item.qty
|
|
total_price = item.qty*item.unit_price
|
|
price = item.unit_price
|
|
product_name = item.product_name
|
|
|
|
|
|
y_position = cursor
|
|
|
|
pad_top(15) {
|
|
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+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 1
|
|
end
|
|
end
|
|
|
|
stroke_horizontal_rule
|
|
|
|
move_down 5
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
|
text "Sub Total", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
|
text "#{ sub_total }" , :size => self.item_font_size,:align => :right
|
|
end
|
|
move_down 5
|
|
end
|
|
|
|
def all_total(sale_data)
|
|
item_name_width = self.item_width
|
|
y_position = cursor
|
|
|
|
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
|
text "Overall Discount", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
|
text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right
|
|
end
|
|
|
|
if sale_data.sale_taxes.length > 0
|
|
sale_data.sale_taxes.each do |st|
|
|
move_down 5
|
|
y_position = cursor
|
|
|
|
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
|
text "#{ st.tax_name }", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
|
text "#{ st.tax_payable_amount }" , :size => self.item_font_size,:align => :right
|
|
end
|
|
end
|
|
else
|
|
|
|
end
|
|
|
|
# move_down 5
|
|
# y_position = cursor
|
|
|
|
# bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
|
# text "Total Tax", :size => self.item_font_size,:align => :left
|
|
# end
|
|
# bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
|
# text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right
|
|
# end
|
|
|
|
move_down 5
|
|
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.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.header_font_size,:align => :right
|
|
end
|
|
move_down 5
|
|
|
|
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,rebate_amount,sale_data)
|
|
|
|
if rebate_amount != nil
|
|
|
|
if rebate_amount["status"] == true
|
|
stroke_horizontal_rule
|
|
rebate_amount["data"].each do |res|
|
|
|
|
if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Rebate"
|
|
|
|
move_down 5
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
|
text "Current Rebate Amount", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
|
text "#{ res["rebate"] }" , :size => self.item_font_size,:align => :right
|
|
end
|
|
end
|
|
if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Redeem"
|
|
|
|
move_down 5
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
|
text "Current Redeem Amount", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
|
text "(#{ res["redeem"] })" , :size => self.item_font_size,:align => :right
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|
|
if member_info["status"] == true
|
|
balance = 0.0
|
|
member_info["data"].each do |res|
|
|
|
|
if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
|
|
balance = balance + res["balance"]
|
|
|
|
end
|
|
|
|
end
|
|
move_down 5
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
|
text "Current Balance", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
|
text "#{ balance }" , :size => self.item_font_size,:align => :right
|
|
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 Name", :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 discount_account(discount_price_by_accounts)
|
|
move_down 5
|
|
stroke_horizontal_rule
|
|
move_down 5
|
|
y_position = cursor
|
|
discount_price_by_accounts.each do |ipa|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
|
text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
|
text "(" + "#{ ipa[:price] }" + ")" , :size => self.item_font_size,:align => :right
|
|
end
|
|
end
|
|
end
|
|
|
|
def items_account(item_price_by_accounts)
|
|
move_down 5
|
|
stroke_horizontal_rule
|
|
move_down 5
|
|
y_position = cursor
|
|
item_price_by_accounts.each do |ipa|
|
|
y_position = cursor
|
|
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
|
text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left
|
|
end
|
|
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
|
text "#{ ipa[:price] }" , :size => self.item_font_size,:align => :right
|
|
end
|
|
end
|
|
end
|
|
|
|
def footer
|
|
move_down 5
|
|
stroke_horizontal_rule
|
|
move_down 5
|
|
|
|
text "Thank You! See you Again", :left_margin => -10, :size => self.header_font_size,:align => :center
|
|
|
|
move_down 5
|
|
end
|
|
|
|
end
|
|
|