update numberformat in pdf
This commit is contained in:
@@ -70,6 +70,6 @@ class PrintSettingsController < ApplicationController
|
|||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def print_setting_params
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
class ReceiptBillPdf < Prawn::Document
|
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
|
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)
|
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
|
self.page_width = 210
|
||||||
@@ -16,7 +17,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
# @double = @qty_width * 1.3
|
# @double = @qty_width * 1.3
|
||||||
# @half_qty = @qty_width / 2
|
# @half_qty = @qty_width / 2
|
||||||
#setting page margin and width
|
#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/#{font_name}".to_s + ".ttf".to_s
|
||||||
# font "public/fonts/Zawgyi-One.ttf"
|
# font "public/fonts/Zawgyi-One.ttf"
|
||||||
@@ -24,22 +25,32 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
self.header_font_size = 10
|
self.header_font_size = 10
|
||||||
self.item_font_size = 8
|
self.item_font_size = 8
|
||||||
|
|
||||||
|
if printer_settings.delimiter
|
||||||
|
delimiter = ","
|
||||||
|
else
|
||||||
|
delimiter = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "hhhhhhhhhhh"
|
||||||
|
puts delimiter
|
||||||
|
puts printer_settings.precision
|
||||||
|
|
||||||
header( shop_details)
|
header( shop_details)
|
||||||
|
|
||||||
stroke_horizontal_rule
|
stroke_horizontal_rule
|
||||||
|
|
||||||
cashier_info(sale_data, customer_name)
|
cashier_info(sale_data, customer_name)
|
||||||
line_items(sale_items)
|
line_items(sale_items,printer_settings.precision,delimiter)
|
||||||
all_total(sale_data)
|
all_total(sale_data,printer_settings.precision,delimiter)
|
||||||
|
|
||||||
|
|
||||||
if member_info != nil
|
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
|
end
|
||||||
|
|
||||||
customer(customer_name)
|
customer(customer_name)
|
||||||
|
|
||||||
items_account(item_price_by_accounts)
|
items_account(item_price_by_accounts,printer_settings.precision,delimiter)
|
||||||
|
|
||||||
footer
|
footer
|
||||||
end
|
end
|
||||||
@@ -97,7 +108,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
stroke_horizontal_rule
|
stroke_horizontal_rule
|
||||||
end
|
end
|
||||||
|
|
||||||
def line_items(sale_items)
|
def line_items(sale_items,precision,delimiter)
|
||||||
move_down 5
|
move_down 5
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
move_down 5
|
move_down 5
|
||||||
@@ -110,10 +121,10 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
}
|
}
|
||||||
move_down -5
|
move_down -5
|
||||||
stroke_horizontal_rule
|
stroke_horizontal_rule
|
||||||
add_line_item_row(sale_items)
|
add_line_item_row(sale_items,precision,delimiter)
|
||||||
end
|
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)
|
item_name_width = (self.item_width+self.price_width)
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
move_down 5
|
move_down 5
|
||||||
@@ -132,9 +143,9 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
|
|
||||||
pad_top(15) {
|
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 "#{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 "#{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
|
move_down 1
|
||||||
end
|
end
|
||||||
@@ -148,12 +159,12 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
text "Sub Total", :size => self.item_font_size,:align => :left
|
text "Sub Total", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
||||||
text "#{ sub_total }" , :size => self.item_font_size,:align => :right
|
text "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}" ,:delimiter => ',', :size => self.item_font_size,:align => :right
|
||||||
end
|
end
|
||||||
move_down 5
|
move_down 5
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_total(sale_data)
|
def all_total(sale_data,precision,delimiter)
|
||||||
item_name_width = self.item_width
|
item_name_width = self.item_width
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
|
|
||||||
@@ -161,7 +172,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
text "Discount", :size => self.item_font_size,:align => :left
|
text "Discount", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
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
|
end
|
||||||
|
|
||||||
if sale_data.sale_taxes.length > 0
|
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
|
text "#{ st.tax_name }", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
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
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -197,15 +208,15 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left
|
text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left
|
||||||
end
|
end
|
||||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
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
|
end
|
||||||
move_down 5
|
move_down 5
|
||||||
|
|
||||||
sale_payment(sale_data)
|
sale_payment(sale_data,precision,delimiter)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def sale_payment(sale_data)
|
def sale_payment(sale_data,precision,delimiter)
|
||||||
|
|
||||||
stroke_horizontal_rule
|
stroke_horizontal_rule
|
||||||
move_down 5
|
move_down 5
|
||||||
@@ -216,7 +227,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left
|
text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
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
|
end
|
||||||
move_down 5
|
move_down 5
|
||||||
end
|
end
|
||||||
@@ -227,7 +238,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
text "Change Amount", :size => self.item_font_size,:align => :left
|
text "Change Amount", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
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
|
end
|
||||||
move_down 5
|
move_down 5
|
||||||
end
|
end
|
||||||
@@ -235,7 +246,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
end
|
end
|
||||||
|
|
||||||
# show member information
|
# 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
|
if rebate_amount != nil
|
||||||
|
|
||||||
@@ -251,7 +262,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
text "Current Rebate Amount", :size => self.item_font_size,:align => :left
|
text "Current Rebate Amount", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
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
|
||||||
end
|
end
|
||||||
if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Redeem"
|
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
|
text "Current Redeem Amount", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -270,7 +281,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if member_info["status"] == true
|
if member_info["status"] == true
|
||||||
balance = 0.0
|
balance = 0
|
||||||
member_info["data"].each do |res|
|
member_info["data"].each do |res|
|
||||||
|
|
||||||
if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
|
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
|
text "Current Balance", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -302,7 +313,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def items_account(item_price_by_accounts)
|
def items_account(item_price_by_accounts,precision,delimiter)
|
||||||
move_down 5
|
move_down 5
|
||||||
stroke_horizontal_rule
|
stroke_horizontal_rule
|
||||||
move_down 5
|
move_down 5
|
||||||
@@ -313,7 +324,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left
|
text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,6 +14,9 @@
|
|||||||
<%= f.input :page_width %>
|
<%= f.input :page_width %>
|
||||||
<%= f.input :page_height %>
|
<%= f.input :page_height %>
|
||||||
<%= f.input :print_copies %>
|
<%= f.input :print_copies %>
|
||||||
|
<%= f.input :precision %>
|
||||||
|
<%= f.input :delimiter %>
|
||||||
|
<%= f.input :heading_space %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
|
|||||||
@@ -26,6 +26,9 @@
|
|||||||
<th>Page width</th>
|
<th>Page width</th>
|
||||||
<th>Page height</th>
|
<th>Page height</th>
|
||||||
<th>Print copies</th>
|
<th>Print copies</th>
|
||||||
|
<th>Precision</th>
|
||||||
|
<th>Delimiter</th>
|
||||||
|
<th>Heading_space</th>
|
||||||
<th colspan="3"></th>
|
<th colspan="3"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -45,6 +48,9 @@
|
|||||||
<td><%= print_setting.page_width %></td>
|
<td><%= print_setting.page_width %></td>
|
||||||
<td><%= print_setting.page_height %></td>
|
<td><%= print_setting.page_height %></td>
|
||||||
<td><%= print_setting.print_copies %></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 'Show', print_setting %></td>
|
||||||
<td><%= link_to 'Edit', edit_print_setting_path(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>
|
<td><%= link_to 'Destroy', print_setting, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||||
|
|||||||
10
db/seeds.rb
10
db/seeds.rb
@@ -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: "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"})
|
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_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"})
|
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"})
|
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"})
|
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"})
|
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"})
|
member_setting = MembershipSetting.create({membership_type:"paypar_url",gateway_url: "http://192.168.1.47:3006",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user