fixed receipt bill print view

This commit is contained in:
Aung Myo
2017-06-04 16:13:15 +06:30
parent a2c9996b76
commit 9b334a20fa
5 changed files with 81 additions and 18 deletions

View File

@@ -10,12 +10,13 @@ class Origami::RequestBillsController < BaseOrigamiController
@sale_data = Sale.find_by_id(@sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_id)
end
unique_code="ReceiptBillPdf"
print_settings=PrintSetting.find_by_unique_code(unique_code)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,@sale_items,@sale)
printer.print_receipt_bill(print_settings,@sale_items,@sale,@sale_data)
end

View File

@@ -1,5 +1,5 @@
class OrderQueueProcessorJob < ApplicationJob
queue_as :default
queue_as :oqs
def perform(order_id)
# Do something later

View File

@@ -64,12 +64,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
self.print(filename)
end
#Bill Receipt Print
def print_receipt_bill(printer_settings,sale_items,sale)
def print_receipt_bill(printer_settings,sale_items,sale,sale_data)
#Use CUPS service
#Generate PDF
#Print
pdf = ReceiptBillPdf.new(printer_settings,sale_items,sale)
pdf.render_file "tmp/receipt_bill_#{sale.id}.pdf"
self.print("tmp/receipt_bill_#{sale.id}.pdf")
pdf = ReceiptBillPdf.new(printer_settings,sale_items,sale,sale_data)
pdf.render_file "tmp/receipt_bill.pdf"
self.print("tmp/receipt_bill.pdf")
end
end

View File

@@ -1,11 +1,11 @@
class ReceiptBillPdf < Prawn::Document
attr_accessor :receipt_width,:price_column_width,:p_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_column_width,:item_description_width
def initialize(printer_settings, sale_items,sale)
def initialize(printer_settings, sale_items,sale, sale_data)
self.p_width = 200
self.page_height = 1450
self.margin = 10
# self.price_width = self.p_width / 2
self.price_width=90
self.price_width=80
self.item_width = self.p_width - self.price_width
self.item_height = self.item_height
self.qty_column_width = self.p_width / 2
@@ -14,7 +14,7 @@ class ReceiptBillPdf < Prawn::Document
@item_width = self.p_width.to_i / 2
@qty_width = @item_width.to_i / 3
@double = @qty_width * 2
@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.p_width, self.page_height])
@@ -25,6 +25,7 @@ class ReceiptBillPdf < Prawn::Document
stroke_horizontal_rule
cashier_info(sale.receipt_no,sale.customer.name, sale.receipt_date)
line_items(sale_items)
all_total(sale_data)
end
@@ -89,7 +90,6 @@ class ReceiptBillPdf < Prawn::Document
text_box "Items", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size
text_box "Price", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "Qty", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "Discount", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "Total", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
}
@@ -98,13 +98,80 @@ class ReceiptBillPdf < Prawn::Document
stroke_horizontal_rule
add_line_item_row(sale_items)
stroke_horizontal_rule
end
def add_line_item_row(sale_items)
y_position = cursor
move_down 5
y_position = cursor
move_down 5
sub_total = 0.0
sale_items.each do |item|
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) {
# @item_width.to_i + @half_qty.to_i
text_box "#{product_name}", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size
text_box "#{price}", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "#{qty.to_i}", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
text_box "#{total_price}", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right
}
move_down 3
end
stroke_horizontal_rule
move_down 5
y_position = cursor
bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do
text "Sub Total", :size => self.item_font_size,:align => :left
end
bounding_box([self.price_width,y_position], :width =>self.price_width) do
text "#{sub_total}" , :size => self.item_font_size,:align => :right
end
end
def all_total(sale_data)
move_down 5
y_position =cursor
bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do
text "Discount", :size => self.item_font_size,:align => :left
end
bounding_box([self.price_width,y_position], :width =>self.price_width) do
text "( " +"#{sale_data.total_discount}" +" )" , :size => self.item_font_size,:align => :right
end
move_down 5
y_position =cursor
bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do
text "Total Tax", :size => self.item_font_size,:align => :left
end
bounding_box([self.price_width,y_position], :width =>self.price_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.price_width, :height => self.item_height) do
text "Grand Total", :size => self.item_font_size,:align => :left
end
bounding_box([self.price_width,y_position], :width =>self.price_width) do
text "#{sale_data.grand_total}" , :size => self.item_font_size,:align => :right
end
move_down 5
# stroke_horizontal_rule
end
end

View File

@@ -29,9 +29,4 @@
</div>
<% end %>
<% end %>
</div>