|
|
|
|
@@ -1,4 +1,5 @@
|
|
|
|
|
class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
include ActionView::Helpers::NumberHelper
|
|
|
|
|
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, member_info = nil,rebate_amount = nil,shop_details)
|
|
|
|
|
self.page_width = 210
|
|
|
|
|
@@ -16,7 +17,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
# @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])
|
|
|
|
|
super(:margin => [printer_settings.heading_space, 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"
|
|
|
|
|
@@ -24,22 +25,32 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
self.header_font_size = 10
|
|
|
|
|
self.item_font_size = 8
|
|
|
|
|
|
|
|
|
|
if printer_settings.delimiter
|
|
|
|
|
delimiter = ","
|
|
|
|
|
else
|
|
|
|
|
delimiter = ""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
puts "hhhhhhhhhhh"
|
|
|
|
|
puts delimiter
|
|
|
|
|
puts printer_settings.precision
|
|
|
|
|
|
|
|
|
|
header( shop_details)
|
|
|
|
|
|
|
|
|
|
stroke_horizontal_rule
|
|
|
|
|
|
|
|
|
|
cashier_info(sale_data, customer_name)
|
|
|
|
|
line_items(sale_items)
|
|
|
|
|
all_total(sale_data)
|
|
|
|
|
line_items(sale_items,printer_settings.precision,delimiter)
|
|
|
|
|
all_total(sale_data,printer_settings.precision,delimiter)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if member_info != nil
|
|
|
|
|
member_info(member_info,customer_name,rebate_amount,sale_data)
|
|
|
|
|
member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
customer(customer_name)
|
|
|
|
|
|
|
|
|
|
items_account(item_price_by_accounts)
|
|
|
|
|
items_account(item_price_by_accounts,printer_settings.precision,delimiter)
|
|
|
|
|
|
|
|
|
|
footer
|
|
|
|
|
end
|
|
|
|
|
@@ -97,7 +108,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
stroke_horizontal_rule
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def line_items(sale_items)
|
|
|
|
|
def line_items(sale_items,precision,delimiter)
|
|
|
|
|
move_down 5
|
|
|
|
|
y_position = cursor
|
|
|
|
|
move_down 5
|
|
|
|
|
@@ -110,10 +121,10 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
}
|
|
|
|
|
move_down -5
|
|
|
|
|
stroke_horizontal_rule
|
|
|
|
|
add_line_item_row(sale_items)
|
|
|
|
|
add_line_item_row(sale_items,precision,delimiter)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def add_line_item_row(sale_items)
|
|
|
|
|
def add_line_item_row(sale_items,precision,delimiter)
|
|
|
|
|
item_name_width = (self.item_width+self.price_width)
|
|
|
|
|
y_position = cursor
|
|
|
|
|
move_down 5
|
|
|
|
|
@@ -132,9 +143,9 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
|
|
|
|
|
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 "%.#{precision}f" % 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
|
|
|
|
|
text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :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
|
|
|
|
|
@@ -148,12 +159,12 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
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
|
|
|
|
|
text "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}" ,:delimiter => ',', :size => self.item_font_size,:align => :right
|
|
|
|
|
end
|
|
|
|
|
move_down 5
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def all_total(sale_data)
|
|
|
|
|
def all_total(sale_data,precision,delimiter)
|
|
|
|
|
item_name_width = self.item_width
|
|
|
|
|
y_position = cursor
|
|
|
|
|
|
|
|
|
|
@@ -161,7 +172,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
text "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
|
|
|
|
|
text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if sale_data.sale_taxes.length > 0
|
|
|
|
|
@@ -173,7 +184,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
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
|
|
|
|
|
text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
@@ -197,15 +208,15 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
text "Grand Total",:style => :bold, :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}" , :style => :bold, :size => self.header_font_size,:align => :right
|
|
|
|
|
text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right
|
|
|
|
|
end
|
|
|
|
|
move_down 5
|
|
|
|
|
|
|
|
|
|
sale_payment(sale_data)
|
|
|
|
|
sale_payment(sale_data,precision,delimiter)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def sale_payment(sale_data)
|
|
|
|
|
def sale_payment(sale_data,precision,delimiter)
|
|
|
|
|
|
|
|
|
|
stroke_horizontal_rule
|
|
|
|
|
move_down 5
|
|
|
|
|
@@ -216,7 +227,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
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
|
|
|
|
|
text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
|
|
|
|
|
end
|
|
|
|
|
move_down 5
|
|
|
|
|
end
|
|
|
|
|
@@ -227,7 +238,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
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
|
|
|
|
|
text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
|
|
|
|
|
end
|
|
|
|
|
move_down 5
|
|
|
|
|
end
|
|
|
|
|
@@ -235,7 +246,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# show member information
|
|
|
|
|
def member_info(member_info,customer_name,rebate_amount,sale_data)
|
|
|
|
|
def member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter)
|
|
|
|
|
|
|
|
|
|
if rebate_amount != nil
|
|
|
|
|
|
|
|
|
|
@@ -251,7 +262,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
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
|
|
|
|
|
text "#{number_with_precision(res["rebate"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Redeem"
|
|
|
|
|
@@ -262,7 +273,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
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
|
|
|
|
|
text "#{number_with_precision(res["redeem"], :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@@ -270,7 +281,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if member_info["status"] == true
|
|
|
|
|
balance = 0.0
|
|
|
|
|
balance = 0
|
|
|
|
|
member_info["data"].each do |res|
|
|
|
|
|
|
|
|
|
|
if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
|
|
|
|
|
@@ -285,7 +296,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
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
|
|
|
|
|
text "#{number_with_precision(balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@@ -302,7 +313,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def items_account(item_price_by_accounts)
|
|
|
|
|
def items_account(item_price_by_accounts,precision,delimiter)
|
|
|
|
|
move_down 5
|
|
|
|
|
stroke_horizontal_rule
|
|
|
|
|
move_down 5
|
|
|
|
|
@@ -313,7 +324,7 @@ class ReceiptBillPdf < Prawn::Document
|
|
|
|
|
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
|
|
|
|
|
text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|