From 58e95e573ec224189c979a75576fd0c4d4769816 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 28 Jun 2017 23:13:20 +0630 Subject: [PATCH] update numberformat in pdf --- app/controllers/print_settings_controller.rb | 2 +- app/pdf/receipt_bill_pdf.rb | 65 ++++++++++++-------- app/views/print_settings/_form.html.erb | 3 + app/views/print_settings/index.html.erb | 6 ++ db/seeds.rb | 10 +-- 5 files changed, 53 insertions(+), 33 deletions(-) diff --git a/app/controllers/print_settings_controller.rb b/app/controllers/print_settings_controller.rb index bdd3061a..8efb9dd5 100644 --- a/app/controllers/print_settings_controller.rb +++ b/app/controllers/print_settings_controller.rb @@ -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 diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 9a0a4d21..22fe7240 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -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 diff --git a/app/views/print_settings/_form.html.erb b/app/views/print_settings/_form.html.erb index c5166103..ba703aae 100644 --- a/app/views/print_settings/_form.html.erb +++ b/app/views/print_settings/_form.html.erb @@ -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 %>
diff --git a/app/views/print_settings/index.html.erb b/app/views/print_settings/index.html.erb index 0db16892..d872f7ae 100644 --- a/app/views/print_settings/index.html.erb +++ b/app/views/print_settings/index.html.erb @@ -26,6 +26,9 @@ Page width Page height Print copies + Precision + Delimiter + Heading_space @@ -45,6 +48,9 @@ <%= print_setting.page_width %> <%= print_setting.page_height %> <%= print_setting.print_copies %> + <%= print_setting.precision %> + <%= print_setting.delimiter %> + <%= print_setting.heading_space %> <%= link_to 'Show', print_setting %> <%= link_to 'Edit', edit_print_setting_path(print_setting) %> <%= link_to 'Destroy', print_setting, method: :delete, data: { confirm: 'Are you sure?' } %> diff --git a/db/seeds.rb b/db/seeds.rb index 2063fb7a..d56bad57 100644 --- a/db/seeds.rb +++ b/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: "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"})