update numberformat in pdf

This commit is contained in:
Aung Myo
2017-06-28 23:13:20 +06:30
parent 342b654f81
commit 58e95e573e
5 changed files with 53 additions and 33 deletions

View File

@@ -70,6 +70,6 @@ class PrintSettingsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def print_setting_params
params.require(:print_setting).permit(:name, :unique_code, :template, :db_name, :db_type, :db_username, :db_password, :printer_name, :api_settings, :page_width, :page_height, :print_copies)
params.require(:print_setting).permit(:name, :unique_code, :template, :db_name, :db_type, :db_username, :db_password, :printer_name, :api_settings, :page_width, :page_height, :print_copies,:precision,:delimiter,:heading_space)
end
end

View File

@@ -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

View File

@@ -14,6 +14,9 @@
<%= f.input :page_width %>
<%= f.input :page_height %>
<%= f.input :print_copies %>
<%= f.input :precision %>
<%= f.input :delimiter %>
<%= f.input :heading_space %>
</div>
<div class="form-actions">

View File

@@ -26,6 +26,9 @@
<th>Page width</th>
<th>Page height</th>
<th>Print copies</th>
<th>Precision</th>
<th>Delimiter</th>
<th>Heading_space</th>
<th colspan="3"></th>
</tr>
</thead>
@@ -45,6 +48,9 @@
<td><%= print_setting.page_width %></td>
<td><%= print_setting.page_height %></td>
<td><%= print_setting.print_copies %></td>
<td><%= print_setting.precision %></td>
<td><%= print_setting.delimiter %></td>
<td><%= print_setting.heading_space %></td>
<td><%= link_to 'Show', print_setting %></td>
<td><%= link_to 'Edit', edit_print_setting_path(print_setting) %></td>
<td><%= link_to 'Destroy', print_setting, method: :delete, data: { confirm: 'Are you sure?' } %></td>

View File

@@ -150,11 +150,11 @@ admin_employee = Employee.create({name: "Waiter", role: "waiter", password: "111
admin_employee = Employee.create({name: "Waiter 2", role: "waiter", password: "22222", emp_id:"222", created_by: "SYSTEM DEFAULT"})
admin_employee = Employee.create({name: "Cashier", role: "cashier", password: "33333", emp_id:"333", created_by: "SYSTEM DEFAULT"})
order_station1=PrintSetting.create({name: "OrderItemPdf", unique_code: "OrderItemPdf", printer_name: "EPSON-TM-T82-S-A"})
order_station2=PrintSetting.create({name: "Order Summary", unique_code: "OrderSummaryPdf", printer_name: "EPSON-TM-T82-S-A"})
request_bill_printer=PrintSetting.create({name: "Receipt Bill", unique_code: "ReceiptBillPdf", printer_name: "EPSON-TM-T82-S-A"})
crm_order_printer=PrintSetting.create({name: "CRM Order", unique_code: "CrmOrderPdf", printer_name: "EPSON-TM-T82-S-A"})
queue_no_printer=PrintSetting.create({name: "Queue No", unique_code: "QueueNoPdf", printer_name: "EPSON-TM-T82-S-A"})
order_station1=PrintSetting.create({name: "OrderItemPdf", unique_code: "OrderItemPdf", printer_name: "EPSON-TM-T82-S-A", precision: "0", delimiter: "0", heading_space: "5"})
order_station2=PrintSetting.create({name: "Order Summary", unique_code: "OrderSummaryPdf", printer_name: "EPSON-TM-T82-S-A", precision: "0", delimiter: "0", heading_space: "5"})
request_bill_printer=PrintSetting.create({name: "Receipt Bill", unique_code: "ReceiptBillPdf", printer_name: "EPSON-TM-T82-S-A", precision: "0", delimiter: "0", heading_space: "5"})
crm_order_printer=PrintSetting.create({name: "CRM Order", unique_code: "CrmOrderPdf", printer_name: "EPSON-TM-T82-S-A", precision: "0", delimiter: "0", heading_space: "5"})
queue_no_printer=PrintSetting.create({name: "Queue No", unique_code: "QueueNoPdf", printer_name: "EPSON-TM-T82-S-A", precision: "0", delimiter: "0", heading_space: "5"})
member_setting = MembershipSetting.create({membership_type:"paypar_url",gateway_url: "http://192.168.1.47:3006",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"})