Permalink
Browse files

Added a shipping rate and description.

  • Loading branch information...
1 parent 5f9d005 commit fcfc27bffc26472fa99bc88b4a6ad1505203c4e3 @mhoofman mhoofman committed Mar 14, 2011
Showing with 27 additions and 5 deletions.
  1. +9 −2 lib/payday/invoice.rb
  2. +11 −1 lib/payday/invoiceable.rb
  3. +2 −0 lib/payday/pdf_renderer.rb
  4. +5 −2 test/invoice_test.rb
View
@@ -4,15 +4,17 @@ module Payday
class Invoice
include Payday::Invoiceable
- attr_accessor :invoice_number, :bill_to, :ship_to, :notes, :line_items, :tax_rate, :tax_description, :due_at, :paid_at,
- :currency, :invoice_details
+ attr_accessor :invoice_number, :bill_to, :ship_to, :notes, :line_items, :shipping_rate, :shipping_description,
+ :tax_rate, :tax_description, :due_at, :paid_at, :currency, :invoice_details
def initialize(options = {})
self.invoice_number = options[:invoice_number] || nil
self.bill_to = options[:bill_to] || nil
self.ship_to = options[:ship_to] || nil
self.notes = options[:notes] || nil
self.line_items = options[:line_items] || []
+ self.shipping_rate = options[:shipping_rate] || nil
+ self.shipping_description = options[:shipping_description] || nil
self.tax_rate = options[:tax_rate] || nil
self.tax_description = options[:tax_description] || nil
self.due_at = options[:due_at] || nil
@@ -25,5 +27,10 @@ def initialize(options = {})
def tax_rate=(value)
@tax_rate = BigDecimal.new(value.to_s)
end
+
+ # Shipping rate
+ def shipping_rate=(value)
+ @shipping_rate = BigDecimal.new(value.to_s)
+ end
end
end
View
@@ -35,9 +35,19 @@ def tax
end
end
+ # TODO Add a per weight unit shipping cost
+ # Calculates the shipping
+ def shipping
+ if defined?(shipping_rate)
+ shipping_rate
+ else
+ 0
+ end
+ end
+
# Calculates the total for this invoice.
def total
- subtotal + tax
+ subtotal + tax + shipping
end
def overdue?
@@ -173,6 +173,8 @@ def self.totals_lines(invoice, pdf)
cell(pdf, number_to_currency(invoice.subtotal, invoice), :align => :right)]
table_data << [bold_cell(pdf, I18n.t('payday.invoice.tax', :default => "Tax:")),
cell(pdf, number_to_currency(invoice.tax, invoice), :align => :right)]
+ table_data << [bold_cell(pdf, I18n.t('payday.invoice.shipping', :default => "Shipping:")),
+ cell(pdf, number_to_currency(invoice.shipping, invoice), :align => :right)]
table_data << [bold_cell(pdf, I18n.t('payday.invoice.total', :default => "Total:"), :size => 12),
cell(pdf, number_to_currency(invoice.total, invoice), :size => 12, :align => :right)]
table = pdf.make_table(table_data, :cell_style => { :borders => [] })
View
@@ -7,14 +7,17 @@ class InvoiceTest < MiniTest::Unit::TestCase
i = Invoice.new(:invoice_number => 20, :bill_to => "Here", :ship_to => "There",
:notes => "These are some notes.",
:line_items => [LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")],
- :tax_rate => 12.5, :tax_description => "Local Sales Tax, 12.5%")
+ :shipping_rate => 15.00, :shipping_description => "USPS Priority Mail:",
+ :tax_rate => 0.125, :tax_description => "Local Sales Tax, 12.5%")
assert_equal 20, i.invoice_number
assert_equal "Here", i.bill_to
assert_equal "There", i.ship_to
assert_equal "These are some notes.", i.notes
assert_equal "Shirts", i.line_items[0].description
- assert_equal BigDecimal.new("12.5"), i.tax_rate
+ assert_equal BigDecimal.new("15.00"), i.shipping_rate
+ assert_equal "USPS Priority Mail:", i.shipping_description
+ assert_equal BigDecimal.new("0.125"), i.tax_rate
assert_equal "Local Sales Tax, 12.5%", i.tax_description
end

0 comments on commit fcfc27b

Please sign in to comment.