Guest User

Untitled

a guest
Apr 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. class InvoiceDrawer
  2. def self.draw(invoice)
  3. pdf = PDF::Writer.new(:paper => "A4")
  4. pdf.select_font "Times-Roman"
  5. pdf.text("Page One Technologies Pty. Ltd.", :font_size => 16, :justification => :left)
  6. pdf.text("A.B.N 85 074 597 103", :font_size => 8, :justification => :left)
  7. pdf.text("Suite 4, No. 1 Shaw Road", :font_size => 10, :justification => :left)
  8. pdf.text("Ingleburn NSW 2565", :font_size => 10, :justification => :left)
  9. pdf.text("Ph: (02) 9829 3151 Fax: (02) 9829 2713", :font_size => 10, :justification => :left)
  10. pdf.text("\n")
  11. pdf.text("Job/Invoice ##{"%05.0f" % invoice.id}", :font_size => 10, :justification => :right)
  12. PDF:: SimpleTable.new do |billto|
  13. billto.column_order.push(*%w(billto))
  14.  
  15. billto.columns["billto"] = PDF::SimpleTable::Column.new("billto") { |col|
  16. col.heading = "BILL TO"
  17. }
  18. billto.show_lines = :outer
  19. billto.show_headings = true
  20. billto.position = :left
  21. billto.orientation = 20
  22. billto.shade_rows = :none
  23. billto.width = 170
  24. data = [
  25. { "billto" => "#{invoice.client.name}" },
  26. { "billto" => "#{invoice.client.address}" },
  27. { "billto" => "#{invoice.client.suburb} #{invoice.client.state} #{invoice.client.postcode}" }
  28. ]
  29.  
  30. billto.data.replace data
  31. billto.render_on(pdf)
  32.  
  33. pdf.text("\n")
  34.  
  35. end
  36. PDF:: SimpleTable.new do |invoice|
  37. invoice.column_order.push(*%w(description quantity rate amount))
  38.  
  39. invoice.columns["description"] = PDF::SimpleTable::Column.new("description") { |col|
  40. col.heading = "Description"
  41. }
  42. invoice.columns["quantity"] = PDF::SimpleTable::Column.new("quantity") { |col|
  43. col.heading = "Quantity"
  44. }
  45. invoice.columns["rate"] = PDF::SimpleTable::Column.new("rate") { |col|
  46. col.heading = "Rate"
  47. }
  48. invoice.columns["amount"] = PDF::SimpleTable::Column.new("amount") { |col|
  49. col.heading = "Amount"
  50. }
  51. invoice.show_lines = :outer
  52. invoice.show_headings = true
  53. invoice.position = :left
  54. invoice.orientation = 20
  55. invoice.shade_rows = :none
  56. invoice.width = 792
  57.  
  58.  
  59. @activities = @invoice.activities.find(:all)
  60.  
  61. unless @activities.nil
  62.  
  63. data = @activities.collect do |o|
  64. { "description" => "#{o.comments}", "quantity" => "#{hour_format(o.minutes)}", "rate" => "#{number_to_currency(o.rate)}", "amount" => "#{number_to_currency(o.price)}"}
  65.  
  66. end
  67. invoice.data.replace data
  68. invoice.render_on(pdf)
  69. end
  70. end
  71. pdf.render
  72.  
  73. end
  74. end
Add Comment
Please, Sign In to add comment