Finished Request Bill print function
This commit is contained in:
@@ -119,6 +119,7 @@ GEM
|
|||||||
nokogiri (1.7.2)
|
nokogiri (1.7.2)
|
||||||
mini_portile2 (~> 2.1.0)
|
mini_portile2 (~> 2.1.0)
|
||||||
pdf-core (0.7.0)
|
pdf-core (0.7.0)
|
||||||
|
pg (0.20.0)
|
||||||
prawn (2.2.2)
|
prawn (2.2.2)
|
||||||
pdf-core (~> 0.7.0)
|
pdf-core (~> 0.7.0)
|
||||||
ttfunk (~> 1.5)
|
ttfunk (~> 1.5)
|
||||||
@@ -252,6 +253,7 @@ DEPENDENCIES
|
|||||||
kaminari!
|
kaminari!
|
||||||
listen (~> 3.0.5)
|
listen (~> 3.0.5)
|
||||||
mysql2 (>= 0.3.18, < 0.5)
|
mysql2 (>= 0.3.18, < 0.5)
|
||||||
|
pg
|
||||||
prawn
|
prawn
|
||||||
prawn-table
|
prawn-table
|
||||||
puma (~> 3.0)
|
puma (~> 3.0)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
class Origami::RequestBillsController < BaseOrigamiController
|
class Origami::RequestBillsController < BaseOrigamiController
|
||||||
def show
|
def show
|
||||||
@sale = Sale.new
|
@sale = Sale.new
|
||||||
|
|
||||||
check_order = Order.find_by_id(params[:id])
|
check_order = Order.find_by_id(params[:id])
|
||||||
if check_order
|
if check_order
|
||||||
@order_details = OrderItem.get_order_items_details(check_order.id)
|
@order_details = OrderItem.get_order_items_details(check_order.id)
|
||||||
@@ -9,5 +10,13 @@ class Origami::RequestBillsController < BaseOrigamiController
|
|||||||
@sale_data = Sale.find_by_id(@sale_id)
|
@sale_data = Sale.find_by_id(@sale_id)
|
||||||
@sale_items = SaleItem.where("sale_id=?",@sale_id)
|
@sale_items = SaleItem.where("sale_id=?",@sale_id)
|
||||||
end
|
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)
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ class Account < ApplicationRecord
|
|||||||
validates_presence_of :title, :account_type
|
validates_presence_of :title, :account_type
|
||||||
|
|
||||||
has_many :menu_items
|
has_many :menu_items
|
||||||
# belongs_to :lookup , :class_name => "Lookup" ,:foreign_key => :tax_type
|
# belongs_to :lookup , :class_name => "Lookup"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -63,4 +63,13 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
|||||||
|
|
||||||
self.print(filename)
|
self.print(filename)
|
||||||
end
|
end
|
||||||
|
#Bill Receipt Print
|
||||||
|
def print_receipt_bill(printer_settings,sale_items,sale)
|
||||||
|
#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")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
110
app/pdf/receipt_bill_pdf.rb
Normal file
110
app/pdf/receipt_bill_pdf.rb
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
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)
|
||||||
|
self.p_width = 200
|
||||||
|
self.page_height = 1450
|
||||||
|
self.margin = 10
|
||||||
|
# self.price_width = self.p_width / 2
|
||||||
|
self.price_width=90
|
||||||
|
self.item_width = self.p_width - self.price_width
|
||||||
|
self.item_height = self.item_height
|
||||||
|
self.qty_column_width = self.p_width / 2
|
||||||
|
self.item_description_width=self.p_width - self.price_width
|
||||||
|
self.receipt_width=130
|
||||||
|
|
||||||
|
@item_width = self.p_width.to_i / 2
|
||||||
|
@qty_width = @item_width.to_i / 3
|
||||||
|
@double = @qty_width * 2
|
||||||
|
@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])
|
||||||
|
self.header_font_size = 10
|
||||||
|
self.item_font_size = 6
|
||||||
|
|
||||||
|
header( printer_settings.printer_name, printer_settings.name)
|
||||||
|
stroke_horizontal_rule
|
||||||
|
cashier_info(sale.receipt_no,sale.customer.name, sale.receipt_date)
|
||||||
|
line_items(sale_items)
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def header (printer_name, name)
|
||||||
|
text "#{printer_name}", :size => self.header_font_size,:align => :center
|
||||||
|
move_down 5
|
||||||
|
text "#{name}", :size => self.header_font_size,:align => :center
|
||||||
|
# move_down self.item_height
|
||||||
|
move_down 5
|
||||||
|
|
||||||
|
stroke_horizontal_rule
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def cashier_info(receipt_no, customer, receipt_date)
|
||||||
|
move_down 5
|
||||||
|
move_down 2
|
||||||
|
y_position = cursor
|
||||||
|
bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do
|
||||||
|
text "Receipt No:", :size => self.item_font_size,:align => :left
|
||||||
|
end
|
||||||
|
|
||||||
|
bounding_box([self.price_width, y_position], :width =>self.receipt_width) do
|
||||||
|
text "#{receipt_no}" , :size => self.item_font_size, :align => :left
|
||||||
|
end
|
||||||
|
move_down 5
|
||||||
|
|
||||||
|
y_position = cursor
|
||||||
|
bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do
|
||||||
|
text "Customer:", :size => self.item_font_size,:align => :left
|
||||||
|
end
|
||||||
|
bounding_box([self.price_width,y_position], :width =>self.price_width) do
|
||||||
|
text "#{customer}" , :size => self.item_font_size,:align => :left
|
||||||
|
end
|
||||||
|
move_down 5
|
||||||
|
|
||||||
|
y_position = cursor
|
||||||
|
bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do
|
||||||
|
text "Date:", :size => self.item_font_size,:align => :left
|
||||||
|
end
|
||||||
|
bounding_box([self.price_width,y_position], :width =>self.price_width) do
|
||||||
|
text "#{receipt_date}" , :size => self.item_font_size,:align => :left
|
||||||
|
end
|
||||||
|
# stroke_horizontal_rule
|
||||||
|
move_down 5
|
||||||
|
end
|
||||||
|
|
||||||
|
def line_items(sale_items)
|
||||||
|
y_position = cursor
|
||||||
|
qty_column_width = self.p_width * 0.2
|
||||||
|
item_description_width = self.p_width * 0.5
|
||||||
|
price_column_width = self.p_width * 0.3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
stroke_horizontal_rule
|
||||||
|
move_down 5
|
||||||
|
y_position = cursor
|
||||||
|
pad_top(15) {
|
||||||
|
# @item_width.to_i + @half_qty.to_i
|
||||||
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
move_down 5
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
<%= link_to 'New Settings Account', new_settings_account_path %>
|
|
||||||
|
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<ul class="breadcrumb">
|
<ul class="breadcrumb">
|
||||||
<li><a href="<%= %>">Home</a></li>
|
<li><a href="<%= %>">Home</a></li>
|
||||||
|
|||||||
@@ -1,18 +1,3 @@
|
|||||||
<p id="notice"><%= notice %></p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<strong>Title:</strong>
|
|
||||||
<%= @settings_account.title %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<strong>Account type:</strong>
|
|
||||||
<%= @settings_account.account_type %>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<%= link_to 'Edit', %> |
|
|
||||||
<%= link_to 'Back', settings_accounts_path %>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<ul class="breadcrumb">
|
<ul class="breadcrumb">
|
||||||
|
|||||||
Reference in New Issue
Block a user