payday 1.0.0beta5 → 1.0.0beta6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,8 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- group :development do
6
- gem "rake"
7
- gem "yard"
8
- end
9
-
data/README.md CHANGED
@@ -29,9 +29,10 @@ Documentation
29
29
  ===
30
30
  Documentation for the latest version of Payday is available at [rdoc.info](http://rdoc.info/github/commondream/payday/v1.0.0beta5/frames).
31
31
 
32
- Customizing Your Logo and Company Name
32
+ Customizing Your Invoice
33
33
  ===
34
- Check out Payday::Config to customize your company's name, details, and logo.
34
+ Payday::Config includes quite a few options for customizing your invoices, such as options for customizing the logo and
35
+ company details on the invoice.
35
36
 
36
37
  Example:
37
38
 
@@ -98,12 +99,36 @@ In your controller:
98
99
  respond_to do |format|
99
100
  format.html
100
101
  format.pdf do
101
- send_data invoice.render_pdf, :filename => "Invoice #12.pdf", :type => "application/pdf", :disposition => :inline
102
+ send_data invoice.render_pdf, :filename => "Invoice #12.pdf", :type => "application/pdf", :disposition => "inline"
102
103
  end
103
104
  end
104
105
 
105
106
  Be sure to restart your server after you edit the mime_types initializer. The updated setting won't take effect until you do.
106
107
 
108
+ I18n
109
+ ===
110
+ Payday uses the i18n gem to provide support for custom labels and internationalized applications. You can change the default labels by
111
+ adding a YAML file in the `config/locales` directory of your Rails app. Here are the default labels you can customize :
112
+
113
+ payday:
114
+ status:
115
+ paid: PAID
116
+ overdue: OVERDUE
117
+ invoice:
118
+ bill_to: Bill To
119
+ ship_to: Ship To
120
+ invoice_no: "Invoice #:"
121
+ due_date: "Due Date:"
122
+ paid_date: "Paid Date:"
123
+ subtotal: "Subtotal:"
124
+ tax: "Tax:"
125
+ total: "Total:"
126
+ line_item:
127
+ description: Description
128
+ unit_price: Unit Price
129
+ quantity: Quantity
130
+ amount: Amount
131
+
107
132
  Examples
108
133
  ===
109
134
  Here's an [example PDF Invoice](https://github.com/downloads/commondream/payday/example.pdf)
@@ -114,6 +139,12 @@ Contributing
114
139
  ===
115
140
  Payday is pretty young, so there's still a good bit of work to be done. I highly recommend sending me a message on GitHub before making too many changes, just to make sure that two folks aren't doing the same work, but beyond that feel free to fork the project, make some changes, and send a pull request. If you're unsure about what to work on but would like to help, send me a message on GitHub. I'd love the help!
116
141
 
142
+ We've had some awesome contributers:
143
+
144
+ * Sam Pizzey ([pizzeys](http://github.com/pizzeys))
145
+ * Andrew Nordman ([cadwallion](http://github.com/cadwallion))
146
+ * Pierre Olivier Martel ([pomartel](http://github.com/pomartel))
147
+
117
148
  To Do
118
149
  ===
119
150
  Here's what we're planning on working on with Payday in the near future:
@@ -127,7 +158,6 @@ Here's what we're planning on working on with Payday in the near future:
127
158
  * Add support for indented line items
128
159
  * Apply different tax rates to different line items
129
160
  * Add support for shipping either pre or post tax
130
- * Add ability to set pdf document size to something other than 8.5 x 11
131
161
  * Add invoice_details has for stuff under the invoice number
132
162
  * Add ability to show skus or product ids on each line item
133
163
 
data/lib/payday.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  # Not much to see here
2
2
  require 'date'
3
+ require 'time'
3
4
  require 'bigdecimal'
4
5
  require 'prawn'
5
6
  require 'money'
6
7
 
7
- require File.join(File.dirname(__FILE__), "payday", "version")
8
- require File.join(File.dirname(__FILE__), "payday", "config")
9
- require File.join(File.dirname(__FILE__), "payday", "line_itemable")
10
- require File.join(File.dirname(__FILE__), "payday", "line_item")
11
- require File.join(File.dirname(__FILE__), "payday", "pdf_renderer")
12
- require File.join(File.dirname(__FILE__), "payday", "invoiceable")
13
- require File.join(File.dirname(__FILE__), "payday", "invoice")
8
+ require 'payday/version'
9
+ require 'payday/config'
10
+ require 'payday/line_itemable'
11
+ require 'payday/line_item'
12
+ require 'payday/pdf_renderer'
13
+ require 'payday/invoiceable'
14
+ require 'payday/invoice'
data/lib/payday/config.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  module Payday
2
2
 
3
3
  # Configuration for Payday. This is a singleton, so to set the company_name you would call
4
- # +Payday::Config.default.company_name = "Awesome Corp"+.
4
+ # Payday::Config.default.company_name = "Awesome Corp".
5
5
  class Config
6
6
  attr_accessor :invoice_logo, :company_name, :company_details, :date_format, :currency
7
7
 
8
+ # Sets the page size to use. See the
9
+ # {http://prawn.majesticseacreature.com/docs/0.10.2/Prawn/Document/PageGeometry.html Prawn documentation} for valid
10
+ # page_size values.
11
+ attr_accessor :page_size
12
+
8
13
  # Returns the default configuration instance
9
14
  def self.default
10
15
  @@default ||= new
@@ -17,6 +22,7 @@ module Payday
17
22
  self.company_details = "awesomecorp@commondream.net"
18
23
  self.date_format = "%B %e, %Y"
19
24
  self.currency = "USD"
25
+ self.page_size = "LETTER"
20
26
  end
21
27
  end
22
- end
28
+ end
@@ -4,7 +4,7 @@ module Payday
4
4
  class Invoice
5
5
  include Payday::Invoiceable
6
6
 
7
- attr_accessor :invoice_number, :bill_to, :ship_to, :notes, :line_items, :tax_rate, :tax_description, :due_at, :paid_at
7
+ attr_accessor :invoice_number, :bill_to, :ship_to, :notes, :line_items, :tax_rate, :tax_description, :due_at, :paid_at, :currency
8
8
 
9
9
  def initialize(options = {})
10
10
  self.invoice_number = options[:invoice_number] || nil
@@ -16,6 +16,7 @@ module Payday
16
16
  self.tax_description = options[:tax_description] || nil
17
17
  self.due_at = options[:due_at] || nil
18
18
  self.paid_at = options[:paid_at] || nil
19
+ self.currency = options[:currency] || nil
19
20
  end
20
21
 
21
22
  # The tax rate that we're applying, as a BigDecimal
@@ -16,11 +16,11 @@ module Payday
16
16
 
17
17
  private
18
18
  def self.pdf(invoice)
19
- pdf = Prawn::Document.new
19
+ pdf = Prawn::Document.new(:page_size => invoice_or_default(invoice, :page_size))
20
20
 
21
21
  # set up some default styling
22
22
  pdf.font_size(8)
23
-
23
+
24
24
  stamp(invoice, pdf)
25
25
  company_banner(invoice, pdf)
26
26
  bill_to_ship_to(invoice, pdf)
@@ -35,9 +35,9 @@ module Payday
35
35
  def self.stamp(invoice, pdf)
36
36
  stamp = nil
37
37
  if invoice.paid?
38
- stamp = "PAID"
38
+ stamp = I18n.t 'payday.status.paid', :default => "PAID"
39
39
  elsif invoice.overdue?
40
- stamp = "OVERDUE"
40
+ stamp = I18n.t 'payday.status.overdue', :default => "OVERDUE"
41
41
  end
42
42
 
43
43
  if stamp
@@ -57,14 +57,14 @@ module Payday
57
57
  logo_info = pdf.image(invoice_or_default(invoice, :invoice_logo), :at => pdf.bounds.top_left)
58
58
 
59
59
  # render the company details
60
- company_details = invoice_or_default(invoice, :company_details)
61
- company_details = company_details.lines.inject("") { |combined, line| combined << line.strip }
62
-
63
60
  table_data = []
64
61
  table_data << [bold_cell(pdf, invoice_or_default(invoice, :company_name).strip, :size => 12)]
65
- table_data << [company_details]
66
- table = pdf.make_table(table_data, :cell_style => { :borders => [], :padding => [2, 0] })
67
- pdf.bounding_box([pdf.bounds.width - table.width, pdf.bounds.top], :width => table.width, :height => table.height) do
62
+
63
+ company_details = invoice_or_default(invoice, :company_details)
64
+ company_details = company_details.lines.each { |line| table_data << [line] }
65
+
66
+ table = pdf.make_table(table_data, :cell_style => { :borders => [], :padding => 0 })
67
+ pdf.bounding_box([pdf.bounds.width - table.width, pdf.bounds.top], :width => table.width, :height => table.height + 5) do
68
68
  table.draw
69
69
  end
70
70
 
@@ -77,14 +77,15 @@ module Payday
77
77
 
78
78
  # render bill to
79
79
  pdf.float do
80
- table = pdf.table([[bold_cell(pdf, "Bill To")], [invoice.bill_to]], :column_widths => [200], :cell_style => bill_to_cell_style)
80
+ table = pdf.table([[bold_cell(pdf, I18n.t('payday.invoice.bill_to', :default => "Bill To"))],
81
+ [invoice.bill_to]], :column_widths => [200], :cell_style => bill_to_cell_style)
81
82
  bill_to_ship_to_bottom = pdf.cursor
82
83
  end
83
84
 
84
85
  # render ship to
85
86
  if defined?(invoice.ship_to)
86
- table = pdf.make_table([[bold_cell(pdf, "Ship To")], [invoice.ship_to]], :column_widths => [200],
87
- :cell_style => bill_to_cell_style)
87
+ table = pdf.make_table([[bold_cell(pdf, I18n.t('payday.invoice.ship_to', :default => "Ship To"))],
88
+ [invoice.ship_to]], :column_widths => [200], :cell_style => bill_to_cell_style)
88
89
 
89
90
  pdf.bounding_box([pdf.bounds.width - table.width, pdf.cursor], :width => table.width, :height => table.height + 2) do
90
91
  table.draw
@@ -102,7 +103,8 @@ module Payday
102
103
 
103
104
  # invoice number
104
105
  if defined?(invoice.invoice_number) && invoice.invoice_number
105
- table_data << [bold_cell(pdf, "Invoice #:"), bold_cell(pdf, invoice.invoice_number.to_s, :align => :right)]
106
+ table_data << [bold_cell(pdf, I18n.t('payday.invoice.invoice_no', :default => "Invoice #:")),
107
+ bold_cell(pdf, invoice.invoice_number.to_s, :align => :right)]
106
108
  end
107
109
 
108
110
  # Due on
@@ -113,7 +115,8 @@ module Payday
113
115
  due_date = invoice.due_at.to_s
114
116
  end
115
117
 
116
- table_data << [bold_cell(pdf, "Due Date:"), bold_cell(pdf, due_date, :align => :right)]
118
+ table_data << [bold_cell(pdf, I18n.t('payday.invoice.due_date', :default => "Due Date:")),
119
+ bold_cell(pdf, due_date, :align => :right)]
117
120
  end
118
121
 
119
122
  # Paid on
@@ -124,27 +127,29 @@ module Payday
124
127
  paid_date = invoice.paid_at.to_s
125
128
  end
126
129
 
127
- table_data << [bold_cell(pdf, "Paid Date:"), bold_cell(pdf, paid_date, :align => :right)]
130
+ table_data << [bold_cell(pdf, I18n.t('payday.invoice.paid_date', :default => "Paid Date:")),
131
+ bold_cell(pdf, paid_date, :align => :right)]
128
132
  end
129
133
 
130
134
  if table_data.length > 0
131
- pdf.table(table_data, :cell_style => { :borders => [], :padding => 1 })
135
+ pdf.table(table_data, :cell_style => { :borders => [], :padding => [1, 10, 1, 1] })
132
136
  end
133
137
  end
134
138
 
135
139
  def self.line_items_table(invoice, pdf)
136
140
  table_data = []
137
- table_data << [bold_cell(pdf, "Description", :borders => []),
138
- bold_cell(pdf, "Unit Price", :align => :center, :borders => []),
139
- bold_cell(pdf, "Quantity", :align => :center, :borders => []),
140
- bold_cell(pdf, "Amount", :align => :center, :borders => [])]
141
+ table_data << [bold_cell(pdf, I18n.t('payday.line_item.description', :default => "Description"), :borders => []),
142
+ bold_cell(pdf, I18n.t('payday.line_item.unit_price', :default => "Unit Price"), :align => :center, :borders => []),
143
+ bold_cell(pdf, I18n.t('payday.line_item.quantity', :default => "Quantity"), :align => :center, :borders => []),
144
+ bold_cell(pdf, I18n.t('payday.line_item.amount', :default => "Amount"), :align => :center, :borders => [])]
141
145
  invoice.line_items.each do |line|
142
146
  table_data << [line.description, number_to_currency(line.price, invoice), BigDecimal.new(line.quantity.to_s).to_s("F"),
143
147
  number_to_currency(line.amount, invoice)]
144
148
  end
145
149
 
146
150
  pdf.move_cursor_to(pdf.cursor - 20)
147
- pdf.table(table_data, :width => pdf.bounds.width, :header => true, :cell_style => {:border_width => 0.5, :border_color => "cccccc", :padding => [5, 10]},
151
+ pdf.table(table_data, :width => pdf.bounds.width, :header => true,
152
+ :cell_style => {:border_width => 0.5, :border_color => "cccccc", :padding => [5, 10]},
148
153
  :row_colors => ["dfdfdf", "ffffff"]) do
149
154
  # left align the number columns
150
155
  columns(1..3).rows(1..row_length - 1).style(:align => :right)
@@ -159,9 +164,11 @@ module Payday
159
164
 
160
165
  def self.totals_lines(invoice, pdf)
161
166
  table_data = []
162
- table_data << [bold_cell(pdf, "Subtotal:"), cell(pdf, number_to_currency(invoice.subtotal, invoice), :align => :right)]
163
- table_data << [bold_cell(pdf, "Tax:"), cell(pdf, number_to_currency(invoice.tax, invoice), :align => :right)]
164
- table_data << [bold_cell(pdf, "Total:", :size => 12),
167
+ table_data << [bold_cell(pdf, I18n.t('payday.invoice.subtotal', :default => "Subtotal:")),
168
+ cell(pdf, number_to_currency(invoice.subtotal, invoice), :align => :right)]
169
+ table_data << [bold_cell(pdf, I18n.t('payday.invoice.tax', :default => "Tax:")),
170
+ cell(pdf, number_to_currency(invoice.tax, invoice), :align => :right)]
171
+ table_data << [bold_cell(pdf, I18n.t('payday.invoice.total', :default => "Total:"), :size => 12),
165
172
  cell(pdf, number_to_currency(invoice.total, invoice), :size => 12, :align => :right)]
166
173
  table = pdf.make_table(table_data, :cell_style => { :borders => [] })
167
174
  pdf.bounding_box([pdf.bounds.width - table.width, pdf.cursor], :width => table.width, :height => table.height + 2) do
@@ -173,7 +180,7 @@ module Payday
173
180
  if defined?(invoice.notes) && invoice.notes
174
181
  pdf.move_cursor_to(pdf.cursor - 30)
175
182
  pdf.font("Helvetica-Bold") do
176
- pdf.text("Notes")
183
+ pdf.text(I18n.t('payday.invoice.notes', :default => "Notes"))
177
184
  end
178
185
  pdf.line_width = 0.5
179
186
  pdf.stroke_color = "cccccc"
@@ -221,4 +228,4 @@ module Payday
221
228
  max
222
229
  end
223
230
  end
224
- end
231
+ end
@@ -2,5 +2,5 @@
2
2
  module Payday
3
3
 
4
4
  # Current Version
5
- VERSION = "1.0.0beta5"
5
+ VERSION = "1.0.0beta6"
6
6
  end
data/payday.gemspec CHANGED
@@ -14,6 +14,9 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.add_dependency("prawn", "~> 0.11.1.pre")
16
16
  s.add_dependency("money", "~> 3.6.1")
17
+ s.add_dependency("i18n", "~> 0.5.0")
18
+
19
+ s.add_development_dependency("minitest")
17
20
 
18
21
  s.files = `git ls-files`.split("\n")
19
22
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/test/invoice_test.rb CHANGED
@@ -1,7 +1,8 @@
1
- require "test/test_helper"
1
+ require File.expand_path("test/test_helper")
2
2
 
3
3
  module Payday
4
- class InvoiceTest < Test::Unit::TestCase
4
+ class InvoiceTest < MiniTest::Unit::TestCase
5
+
5
6
  test "that setting values through the options hash on initialization works" do
6
7
  i = Invoice.new(:invoice_number => 20, :bill_to => "Here", :ship_to => "There",
7
8
  :notes => "These are some notes.",
@@ -94,6 +95,8 @@ module Payday
94
95
  :due_at => Date.civil(2011, 1, 22), :paid_at => Date.civil(2012, 2, 22),
95
96
  :bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222", :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229")
96
97
 
98
+ Payday::Config.default.company_details = "10 This Way\nManhattan, NY 10001\n800-111-2222\nawesome@awesomecorp.com"
99
+
97
100
  3.times do
98
101
  i.line_items << LineItem.new(:price => 20, :quantity => 5, :description => "Pants")
99
102
  i.line_items << LineItem.new(:price => 10, :quantity => 3, :description => "Shirts")
@@ -115,7 +118,7 @@ module Payday
115
118
  i.line_items << LineItem.new(:price => 5, :quantity => 200.0, :description => "Hats")
116
119
  end
117
120
 
118
- assert_not_nil i.render_pdf
121
+ refute_nil i.render_pdf
119
122
  end
120
123
  end
121
124
  end
@@ -1,7 +1,7 @@
1
- require "test/test_helper"
1
+ require File.expand_path("test/test_helper")
2
2
 
3
3
  module Payday
4
- class LineItemTest < Test::Unit::TestCase
4
+ class LineItemTest < MiniTest::Unit::TestCase
5
5
  test "initializing with a price" do
6
6
  li = LineItem.new(:price => BigDecimal.new("20"))
7
7
  assert_equal BigDecimal.new("20"), li.price
data/test/test_helper.rb CHANGED
@@ -1,11 +1,11 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "payday")
1
+ require File.expand_path('lib/payday')
2
2
 
3
- require 'test/unit'
3
+ require 'minitest/autorun'
4
4
  require 'date'
5
5
  require 'time'
6
6
 
7
7
  # Shamelessly ripped from jm's context library: https://github.com/jm/context/blob/master/lib/context/test.rb
8
- class Test::Unit::TestCase
8
+ class MiniTest::Unit::TestCase
9
9
  class << self
10
10
  # Create a test method. +name+ is a native-language string to describe the test
11
11
  # (e.g., no more +test_this_crazy_thing_with_underscores+).
metadata CHANGED
@@ -1,15 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payday
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196361
5
4
  prerelease: 5
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- - beta
11
- - 5
12
- version: 1.0.0beta5
5
+ version: 1.0.0beta6
13
6
  platform: ruby
14
7
  authors:
15
8
  - Alan Johnson
@@ -17,7 +10,7 @@ autorequire:
17
10
  bindir: bin
18
11
  cert_chain: []
19
12
 
20
- date: 2011-03-09 00:00:00 -05:00
13
+ date: 2011-03-10 00:00:00 -05:00
21
14
  default_executable:
22
15
  dependencies:
23
16
  - !ruby/object:Gem::Dependency
@@ -28,12 +21,6 @@ dependencies:
28
21
  requirements:
29
22
  - - ~>
30
23
  - !ruby/object:Gem::Version
31
- hash: 961915928
32
- segments:
33
- - 0
34
- - 11
35
- - 1
36
- - pre
37
24
  version: 0.11.1.pre
38
25
  type: :runtime
39
26
  version_requirements: *id001
@@ -45,14 +32,31 @@ dependencies:
45
32
  requirements:
46
33
  - - ~>
47
34
  - !ruby/object:Gem::Version
48
- hash: 29
49
- segments:
50
- - 3
51
- - 6
52
- - 1
53
35
  version: 3.6.1
54
36
  type: :runtime
55
37
  version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: i18n
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 0.5.0
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: minitest
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :development
59
+ version_requirements: *id004
56
60
  description: Payday is a library for rendering invoices. At present it supports rendering invoices to pdfs, but we're planning on adding support for other formats in the near future.
57
61
  email:
58
62
  - alan@commondream.net
@@ -94,25 +98,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
98
  requirements:
95
99
  - - ">="
96
100
  - !ruby/object:Gem::Version
97
- hash: 3
98
- segments:
99
- - 0
100
101
  version: "0"
101
102
  required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  none: false
103
104
  requirements:
104
105
  - - ">"
105
106
  - !ruby/object:Gem::Version
106
- hash: 25
107
- segments:
108
- - 1
109
- - 3
110
- - 1
111
107
  version: 1.3.1
112
108
  requirements: []
113
109
 
114
110
  rubyforge_project:
115
- rubygems_version: 1.4.2
111
+ rubygems_version: 1.6.2
116
112
  signing_key:
117
113
  specification_version: 3
118
114
  summary: git remote add origin git@github.com:commondream/payday.git