payday 1.0.0beta1 → 1.0.0beta2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +64 -3
- data/lib/payday/invoice.rb +2 -2
- data/lib/payday/invoiceable.rb +2 -2
- data/lib/payday/line_itemable.rb +1 -1
- data/lib/payday/pdf_renderer.rb +4 -4
- data/lib/payday/version.rb +4 -1
- data/test/invoice_test.rb +4 -4
- metadata +3 -3
data/README.md
CHANGED
@@ -2,6 +2,17 @@ Payday!
|
|
2
2
|
===
|
3
3
|
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.
|
4
4
|
|
5
|
+
Installing
|
6
|
+
===
|
7
|
+
Payday is available as a Rubygem, so installing it is as easy as running:
|
8
|
+
|
9
|
+
gem install payday --pre
|
10
|
+
|
11
|
+
Or, using bundler:
|
12
|
+
|
13
|
+
gem "payday"
|
14
|
+
|
15
|
+
|
5
16
|
Using Payday
|
6
17
|
===
|
7
18
|
It's pretty easy to use Payday with the built in objects. We include the Invoice and LineItem classes, and with them you can get started pretty quickly.
|
@@ -14,6 +25,10 @@ Example:
|
|
14
25
|
i.line_items << LineItem.new(:price => 5, :quantity => 200, :description => "Hats")
|
15
26
|
i.render_pdf_to_file("/path/to_file.pdf")
|
16
27
|
|
28
|
+
Documentation
|
29
|
+
===
|
30
|
+
Documentation for the latest version of Payday is available at [rdoc.info](http://rdoc.info/github/commondream/payday/v1.0.0beta1/frames).
|
31
|
+
|
17
32
|
Customizing Your Logo and Company Name
|
18
33
|
===
|
19
34
|
Check out Payday::Config to customize your company's name, details, and logo.
|
@@ -27,7 +42,47 @@ Example:
|
|
27
42
|
Using Payday with ActiveRecord Objects (or any other objects, for that matter)
|
28
43
|
===
|
29
44
|
|
30
|
-
|
45
|
+
Payday focuses on two main objects, an invoice and a line item, so to Payday with ActiveRecord you'll want to create your own classes for those objects. We include the Payday::Invoiceable and Payday::LineItemable modules to help out with that.
|
46
|
+
|
47
|
+
Here's the simplest possible implementation of a custom invoice and line item with Payday:
|
48
|
+
|
49
|
+
In a new migration:
|
50
|
+
|
51
|
+
create_table :invoices do |t|
|
52
|
+
# invoices will work without anything but bill_to, but there are quite a few options for the fields you can save, like ship_to
|
53
|
+
# due_at, and paid_at
|
54
|
+
t.string bill_to
|
55
|
+
|
56
|
+
t.timestamps
|
57
|
+
end
|
58
|
+
|
59
|
+
create_table :line_items do |t|
|
60
|
+
t.decimal :price
|
61
|
+
t.string :description
|
62
|
+
t.integer :quantity # can also be :decimal or :float - just needs to be numeric
|
63
|
+
|
64
|
+
t.integer :invoice_id
|
65
|
+
|
66
|
+
t.timestamps
|
67
|
+
end
|
68
|
+
|
69
|
+
In app/models/invoice.rb:
|
70
|
+
|
71
|
+
class Invoice < ActiveRecord::Base
|
72
|
+
include Payday::Invoiceable
|
73
|
+
|
74
|
+
has_many :line_items
|
75
|
+
end
|
76
|
+
|
77
|
+
In app/models/line_item.rb:
|
78
|
+
|
79
|
+
class LineItem < ActiveRecord::Base
|
80
|
+
include Payday::LineItemable
|
81
|
+
|
82
|
+
belongs_to :invoice
|
83
|
+
end
|
84
|
+
|
85
|
+
For a bit more fleshed out example, be sure to check out [http://github.com/commondream/payday-example](http://github.com/commondream/payday-example).
|
31
86
|
|
32
87
|
Rendering Payday PDFs To The Web
|
33
88
|
===
|
@@ -49,6 +104,12 @@ In your controller:
|
|
49
104
|
|
50
105
|
Be sure to restart your server after you edit the mime_types initializer. The updating setting won't take effect until you do.
|
51
106
|
|
107
|
+
Examples
|
108
|
+
===
|
109
|
+
Here's an [example PDF Invoice](https://github.com/downloads/commondream/payday/testing.pdf)
|
110
|
+
|
111
|
+
There's also an example Rails application running on Heroku at [http://payday-example.heroku.com](http://payday-example.heroku.com). You can check out the source at [http://github.com/commondream/payday-example](http://github.com/commondream/payday-example).
|
112
|
+
|
52
113
|
Contributing
|
53
114
|
===
|
54
115
|
Payday is pretty young, so there's still a good bit of work to be done. Feel free to fork the project, make some changes, and send a pull request. If you're unsure about what to work on, send me a message on GitHub. I'd love the help!
|
@@ -57,10 +118,10 @@ To Do
|
|
57
118
|
===
|
58
119
|
Here's what we're planning on working on with Payday in the near future:
|
59
120
|
|
60
|
-
*
|
61
|
-
* Document how to use with ActiveRecord
|
121
|
+
* Let some folks use it for a bit.
|
62
122
|
* Release 1.0!
|
63
123
|
|
124
|
+
* Actually get a designer to style the invoices.
|
64
125
|
* Add support for currencies other than USD
|
65
126
|
* Add support for Money gem or BigDecimal or general numerics (right now we support BigDecimal and general numerics)
|
66
127
|
* Add support for blank line items
|
data/lib/payday/invoice.rb
CHANGED
@@ -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, :
|
7
|
+
attr_accessor :invoice_number, :bill_to, :ship_to, :notes, :line_items, :tax_rate, :tax_description, :due_at, :paid_at
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
10
|
self.invoice_number = options[:invoice_number] || nil
|
@@ -14,7 +14,7 @@ module Payday
|
|
14
14
|
self.line_items = options[:line_items] || []
|
15
15
|
self.tax_rate = options[:tax_rate] || nil
|
16
16
|
self.tax_description = options[:tax_description] || nil
|
17
|
-
self.
|
17
|
+
self.due_at = options[:due_at] || nil
|
18
18
|
self.paid_at = options[:paid_at] || nil
|
19
19
|
end
|
20
20
|
|
data/lib/payday/invoiceable.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
# when generating an invoice. We include a simple tax method that calculates tax, but it's probably wiser
|
11
11
|
# to override this in your class (our calculated tax won't be stored to a database by default, for example).
|
12
12
|
#
|
13
|
-
# If the +
|
13
|
+
# If the +due_at+ and +paid_at+ methods are available, {Payday::Invoiceable} will use them to show due dates and
|
14
14
|
# paid dates, as well as stamps showing if the invoice is paid or due.
|
15
15
|
module Payday::Invoiceable
|
16
16
|
|
@@ -41,7 +41,7 @@ module Payday::Invoiceable
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def overdue?
|
44
|
-
defined?(:
|
44
|
+
defined?(:due_at) && ((due_at.is_a?(Date) && due_at < Date.today) || (due_at.is_a?(Time) < Time.now)) && !paid_at
|
45
45
|
end
|
46
46
|
|
47
47
|
def paid?
|
data/lib/payday/line_itemable.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Include this module into your line item implementation to make sure that Payday stays happy
|
2
2
|
# with it, or just make sure that your line item implements the amount method.
|
3
3
|
module Payday::LineItemable
|
4
|
-
# Returns the total amount for this {LineItemable}, or
|
4
|
+
# Returns the total amount for this {LineItemable}, or +price * quantity+
|
5
5
|
def amount
|
6
6
|
price * quantity
|
7
7
|
end
|
data/lib/payday/pdf_renderer.rb
CHANGED
@@ -103,11 +103,11 @@ module Payday
|
|
103
103
|
end
|
104
104
|
|
105
105
|
# Due on
|
106
|
-
if defined?(invoice.
|
107
|
-
if invoice.
|
108
|
-
due_date = invoice.
|
106
|
+
if defined?(invoice.due_at) && invoice.due_at
|
107
|
+
if invoice.due_at.is_a?(Date) || invoice.due_at.is_a?(Time)
|
108
|
+
due_date = invoice.due_at.strftime(Payday::Config.default.date_format)
|
109
109
|
else
|
110
|
-
due_date = invoice.
|
110
|
+
due_date = invoice.due_at.to_s
|
111
111
|
end
|
112
112
|
|
113
113
|
table_data << [bold_cell(pdf, "Due Date:"), bold_cell(pdf, due_date, :align => :right)]
|
data/lib/payday/version.rb
CHANGED
data/test/invoice_test.rb
CHANGED
@@ -62,12 +62,12 @@ module Payday
|
|
62
62
|
end
|
63
63
|
|
64
64
|
test "overdue? is false when past date and unpaid" do
|
65
|
-
i = Invoice.new(:
|
65
|
+
i = Invoice.new(:due_at => Date.today - 1)
|
66
66
|
assert i.overdue?
|
67
67
|
end
|
68
68
|
|
69
69
|
test "overdue? is true when past date but paid" do
|
70
|
-
i = Invoice.new(:
|
70
|
+
i = Invoice.new(:due_at => Date.today - 1, :paid_at => Date.today)
|
71
71
|
assert !i.overdue?
|
72
72
|
end
|
73
73
|
|
@@ -86,7 +86,7 @@ module Payday
|
|
86
86
|
assert !File.exists?("tmp/testing.pdf")
|
87
87
|
|
88
88
|
i = Invoice.new(:tax_rate => 0.1, :notes => "These are some crazy awesome notes!", :invoice_number => 12,
|
89
|
-
:
|
89
|
+
:due_at => Date.civil(2011, 1, 22), :paid_at => Date.civil(2012, 2, 22),
|
90
90
|
:bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222", :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229")
|
91
91
|
|
92
92
|
3.times do
|
@@ -101,7 +101,7 @@ module Payday
|
|
101
101
|
|
102
102
|
test "rendering to string" do
|
103
103
|
i = Invoice.new(:tax_rate => 0.1, :notes => "These are some crazy awesome notes!", :invoice_number => 12,
|
104
|
-
:
|
104
|
+
:due_at => Date.civil(2011, 1, 22), :paid_at => Date.civil(2012, 2, 22),
|
105
105
|
:bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222", :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229")
|
106
106
|
|
107
107
|
3.times do
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 62196359
|
5
5
|
prerelease: 5
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 1.0.
|
11
|
+
- 2
|
12
|
+
version: 1.0.0beta2
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Alan Johnson
|