diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 08caf1b8..4d0b23f2 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -186,57 +186,31 @@ class ReceiptBillA5Pdf < Prawn::Document end def add_line_item_row(sale_items,precision,delimiter) - if precision.to_i > 0 - item_name_width = (self.item_width+self.price_width) - item_qty_front_width = (self.item_width+self.price_width) + 5 - item_qty_end_width = self.qty_width + 4 - item_total_front_width = item_name_width + 10 - item_total_end_width = self.total_width + 9 - else - item_name_width = (self.item_width+self.price_width) - item_qty_front_width = item_name_width + 8 - item_qty_end_width = self.qty_width + 7 - item_total_front_width = item_name_width + 5 - item_total_end_width = self.total_width + 4 - end + y_position = cursor move_down line_move sub_total = 0.0 total_qty = 0.0 sale_items.each do |item| # check for item not to show - if item.price != 0 - sub_total += item.price #(item.qty*item.unit_price) - comment for room charges - if item.status != 'Discount' && item.qty > 0 - total_qty += item.qty - end - qty = item.qty - total_price = item.price #item.qty*item.unit_price - comment for room charges - price = item.unit_price - product_name = item.product_name + show_price = Lookup.find_by_lookup_type("show_price").value - y_position = cursor + sub_total += item.price #(item.qty*item.unit_price) - comment for room charges + if item.status != 'Discount' && item.qty > 0 + total_qty += item.qty + end + qty = item.qty + total_price = item.price #item.qty*item.unit_price - comment for room charges + price = item.unit_price + product_name = item.product_name - pad_top(15) { - bounding_box([0,y_position], :width =>self.item_width) do - text "#{product_name}", :size => self.item_font_size,:align => :left - end - # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - - if show_alt_name - if !(item.product_alt_name).empty? - move_down 2 - font("public/fonts/NotoSansCJKtc-Regular.ttf") do - text "(#{item.product_alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true - end - end - end - move_down line_move - } + if show_price.to_i>0 + item_row(item,precision,delimiter,product_name,price,qty ,total_price) + else + if item.price != 0 + item_row(item,precision,delimiter,product_name,price,qty ,total_price) + end end end @@ -255,6 +229,45 @@ class ReceiptBillA5Pdf < Prawn::Document end end + def item_row(item,precision,delimiter,product_name,price,qty ,total_price) + + if precision.to_i > 0 + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = (self.item_width+self.price_width) + 5 + item_qty_end_width = self.qty_width + 4 + item_total_front_width = item_name_width + 10 + item_total_end_width = self.total_width + 9 + else + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = item_name_width + 8 + item_qty_end_width = self.qty_width + 7 + item_total_front_width = item_name_width + 5 + item_total_end_width = self.total_width + 4 + end + + y_position = cursor + + pad_top(15) { + bounding_box([0,y_position], :width =>self.item_width) do + text "#{product_name}", :size => self.item_font_size,:align => :left + end + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + + if show_alt_name + if !(item.product_alt_name).empty? + move_down 2 + font("public/fonts/NotoSansCJKtc-Regular.ttf") do + text "(#{item.product_alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + end + end + end + move_down line_move + } + end + def all_total(sale_data,precision,delimiter) move_down line_move item_name_width = self.item_width diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 7dc29463..458e1780 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -180,58 +180,32 @@ class ReceiptBillPdf < Prawn::Document end def add_line_item_row(sale_items,precision,delimiter) - if precision.to_i > 0 - item_name_width = (self.item_width+self.price_width) - item_qty_front_width = (self.item_width+self.price_width) + 5 - item_qty_end_width = self.qty_width + 4 - item_total_front_width = item_name_width + 10 - item_total_end_width = self.total_width + 9 - else - item_name_width = (self.item_width+self.price_width) - item_qty_front_width = item_name_width + 8 - item_qty_end_width = self.qty_width + 7 - item_total_front_width = item_name_width + 5 - item_total_end_width = self.total_width + 4 - end + y_position = cursor move_down line_move sub_total = 0.0 total_qty = 0.0 sale_items.each do |item| # check for item not to show - if item.price != 0 - sub_total += item.price #(item.qty*item.unit_price) - comment for room charges - if item.status != 'Discount' && item.qty > 0 - total_qty += item.qty - end - qty = item.qty - total_price = item.price #item.qty*item.unit_price - comment for room charges - price = item.unit_price - product_name = item.product_name + show_price = Lookup.find_by_lookup_type("show_price").value + + sub_total += item.price #(item.qty*item.unit_price) - comment for room charges + if item.status != 'Discount' && item.qty > 0 + total_qty += item.qty + end + qty = item.qty + total_price = item.price #item.qty*item.unit_price - comment for room charges + price = item.unit_price + product_name = item.product_name - y_position = cursor - - pad_top(15) { - bounding_box([0,y_position], :width =>self.item_width) do - text "#{product_name}", :size => self.item_font_size,:align => :left - end - # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - - if show_alt_name - if !(item.product_alt_name).empty? - move_down 2 - font("public/fonts/NotoSansCJKtc-Regular.ttf") do - text "(#{item.product_alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true - end - end - end - move_down line_move - } - + if show_price.to_i>0 + item_row(item,precision,delimiter,product_name,price,qty ,total_price) + else + if item.price != 0 + item_row(item,precision,delimiter,product_name,price,qty ,total_price) + end end + end stroke_horizontal_rule @@ -249,6 +223,45 @@ class ReceiptBillPdf < Prawn::Document end end + def item_row(item,precision,delimiter,product_name,price,qty ,total_price) + if precision.to_i > 0 + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = (self.item_width+self.price_width) + 5 + item_qty_end_width = self.qty_width + 4 + item_total_front_width = item_name_width + 10 + item_total_end_width = self.total_width + 9 + else + item_name_width = (self.item_width+self.price_width) + item_qty_front_width = item_name_width + 8 + item_qty_end_width = self.qty_width + 7 + item_total_front_width = item_name_width + 5 + item_total_end_width = self.total_width + 4 + end + y_position = cursor + + pad_top(15) { + bounding_box([0,y_position], :width =>self.item_width) do + text "#{product_name}", :size => self.item_font_size,:align => :left + end + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + + if show_alt_name + if !(item.product_alt_name).empty? + move_down 2 + font("public/fonts/NotoSansCJKtc-Regular.ttf") do + text "(#{item.product_alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + end + end + end + move_down line_move + } + + + end + def all_total(sale_data,precision,delimiter) move_down line_move item_name_width = self.item_width