payday 1.0.0beta6 → 1.0.0beta7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -107,27 +107,30 @@ Be sure to restart your server after you edit the mime_types initializer. The up
107
107
 
108
108
  I18n
109
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 :
110
+ Payday uses the i18n gem to provide support for custom labels and internationalized applications. You can change the default labels by adding a YAML file in the `config/locales` directory of your Rails app. Here are the default labels you can customize:
112
111
 
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
112
+ en:
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
+
132
+ If you translate the invoice to your own language, please send me a copy of your locale.yml file so that we can include it with
133
+ the main Payday distribution and other Payday users can enjoy the fruits of your labor.
131
134
 
132
135
  Examples
133
136
  ===
@@ -158,8 +161,8 @@ Here's what we're planning on working on with Payday in the near future:
158
161
  * Add support for indented line items
159
162
  * Apply different tax rates to different line items
160
163
  * Add support for shipping either pre or post tax
161
- * Add invoice_details has for stuff under the invoice number
162
164
  * Add ability to show skus or product ids on each line item
165
+ * Add ability to add fine print to invoices.
163
166
 
164
167
  * Add page numbers
165
168
  * Ability to render invoice to html for web viewing
@@ -0,0 +1,30 @@
1
+ Description:
2
+ Creates the Invoice and LineItem models for Payday to use to
3
+ render invoicing, and optionally a migration.
4
+
5
+ Usage:
6
+ Pass the name of the Invoice and LineItems to the generator to
7
+ establish the models and database migrations for you. These
8
+ parameters can be in camel-case or in under_scored format.
9
+
10
+ If no invoice_name or line_item_name is passed, it will default
11
+ to Invoice and LineItem.
12
+
13
+ If you wish to not create the migration and only have the
14
+ models generated for you, pass the --skip-migration flag to
15
+ the generator.
16
+
17
+ Examples:
18
+ `rails generate payday:setup`
19
+
20
+ Will create Invoice and LineItem models with Payday
21
+ configured, and a database migration file to create
22
+ the tables and the minimum Payday needs to operate.
23
+
24
+ `rails generate payday:setup --invoice-name=Bill --line_item-name=Actions`
25
+
26
+ Will create Bill and Actions models with Payday's
27
+ associations and configurations established, as well
28
+ as a database migration for the bills and actions
29
+ tables.
30
+
@@ -0,0 +1,44 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ # rails g payday:setup <invoice_name> <line_item_name>
5
+ # Generates models for invoicing with Payday includes prepped
6
+ # Params:
7
+
8
+ # OPTIONS:
9
+ # --skip-migration - Does not create the migration file for invoicing
10
+ module Payday
11
+ class SetupGenerator < Rails::Generators::Base
12
+ include Rails::Generators::Migration
13
+
14
+ source_root File.expand_path('../templates', __FILE__)
15
+
16
+ class_option :invoice_name, :type => :string, :default => "Invoice"
17
+ class_option :line_item_name, :type => :string, :default => "LineItem"
18
+ class_option :skip_migration, :desc => "Does not create the migration file for tables", :type => :boolean
19
+
20
+ def generate_invoice_model
21
+ template "invoice.rb", "app/models/#{options.invoice_name.underscore}.rb"
22
+ end
23
+
24
+ def generate_line_item_model
25
+ template "line_item.rb", "app/models/#{options.line_item_name.underscore}.rb"
26
+ end
27
+
28
+ def generate_migration
29
+ unless options.skip_migration?
30
+ migration_template 'migration.rb', "db/migrate/create_payday_tables.rb"
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def self.next_migration_number(dirname)
37
+ if ActiveRecord::Base.timestamped_migrations
38
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
39
+ else
40
+ "%.3d" % (current_migration_number(dirname) + 1)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ class <%= options.invoice_name.singularize %> < ActiveRecord::Base
2
+ include Payday::Invoiceable
3
+
4
+ has_many :<%= options.line_item_name.pluralize.underscore %>
5
+ end
@@ -0,0 +1,5 @@
1
+ class <%= options.line_item_name.singularize %> < ActiveRecord::Base
2
+ include Payday::LineItemable
3
+
4
+ belongs_to :<%= options.invoice_name.underscore %>
5
+ end
@@ -0,0 +1,26 @@
1
+ class CreatePaydayTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= options.invoice_name.pluralize.underscore.split("/").last %> do |t|
4
+ # invoices will work without anything but bill_to, but there are quite a few options for the fields you can save, like ship_to
5
+ # due_at, and paid_at
6
+ t.string :bill_to
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ create_table :<%= options.line_item_name.pluralize.underscore.split("/").last %> do |t|
12
+ t.decimal :price
13
+ t.string :description
14
+ t.integer :quantity # can also be :decimal or :float - just needs to be numeric
15
+
16
+ t.references :<%= options.invoice_name.underscore %>
17
+
18
+ t.timestamps
19
+ end
20
+ end
21
+
22
+ def self.down
23
+ drop_table :<%= options.invoice_name.pluralize.underscore.split("/").last %>
24
+ drop_table :<%= options.line_item_name.pluralize.underscore.split("/").last %>
25
+ end
26
+ end
data/lib/payday.rb CHANGED
@@ -7,6 +7,7 @@ require 'money'
7
7
 
8
8
  require 'payday/version'
9
9
  require 'payday/config'
10
+ require 'payday/i18n'
10
11
  require 'payday/line_itemable'
11
12
  require 'payday/line_item'
12
13
  require 'payday/pdf_renderer'
@@ -0,0 +1,2 @@
1
+ # Load everything in the local folder
2
+ I18n.load_path.concat(Dir[File.join(File.dirname(__FILE__), "payday", "locale", "*.yml")])
@@ -4,7 +4,8 @@ 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, :currency
7
+ attr_accessor :invoice_number, :bill_to, :ship_to, :notes, :line_items, :tax_rate, :tax_description, :due_at, :paid_at,
8
+ :currency, :invoice_details
8
9
 
9
10
  def initialize(options = {})
10
11
  self.invoice_number = options[:invoice_number] || nil
@@ -17,6 +18,7 @@ module Payday
17
18
  self.due_at = options[:due_at] || nil
18
19
  self.paid_at = options[:paid_at] || nil
19
20
  self.currency = options[:currency] || nil
21
+ self.invoice_details = options[:invoice_details] || []
20
22
  end
21
23
 
22
24
  # The tax rate that we're applying, as a BigDecimal
@@ -57,4 +57,14 @@ module Payday::Invoiceable
57
57
  def render_pdf_to_file(path)
58
58
  Payday::PdfRenderer.render_to_file(self, path)
59
59
  end
60
+
61
+ # Iterates through the details on this invoiceable. The block given should accept
62
+ # two parameters, the detail name and the actual detail value.
63
+ def each_detail(&block)
64
+ return if !defined?(:invoice_details)
65
+
66
+ invoice_details.each do |detail|
67
+ block.call(detail[0], detail[1])
68
+ end
69
+ end
60
70
  end
@@ -0,0 +1,19 @@
1
+ en:
2
+ payday:
3
+ status:
4
+ paid: PAID
5
+ overdue: OVERDUE
6
+ invoice:
7
+ bill_to: Bill To
8
+ ship_to: Ship To
9
+ invoice_no: "Invoice #:"
10
+ due_date: "Due Date:"
11
+ paid_date: "Paid Date:"
12
+ subtotal: "Subtotal:"
13
+ tax: "Tax:"
14
+ total: "Total:"
15
+ line_item:
16
+ description: Description
17
+ unit_price: Unit Price
18
+ quantity: Quantity
19
+ amount: Amount
@@ -60,8 +60,7 @@ module Payday
60
60
  table_data = []
61
61
  table_data << [bold_cell(pdf, invoice_or_default(invoice, :company_name).strip, :size => 12)]
62
62
 
63
- company_details = invoice_or_default(invoice, :company_details)
64
- company_details = company_details.lines.each { |line| table_data << [line] }
63
+ invoice_or_default(invoice, :company_details).lines.each { |line| table_data << [line] }
65
64
 
66
65
  table = pdf.make_table(table_data, :cell_style => { :borders => [], :padding => 0 })
67
66
  pdf.bounding_box([pdf.bounds.width - table.width, pdf.bounds.top], :width => table.width, :height => table.height + 5) do
@@ -131,6 +130,12 @@ module Payday
131
130
  bold_cell(pdf, paid_date, :align => :right)]
132
131
  end
133
132
 
133
+ # loop through invoice_details and include them
134
+ invoice.each_detail do |key, value|
135
+ table_data << [bold_cell(pdf, key),
136
+ bold_cell(pdf, value, :align => :right)]
137
+ end
138
+
134
139
  if table_data.length > 0
135
140
  pdf.table(table_data, :cell_style => { :borders => [], :padding => [1, 10, 1, 1] })
136
141
  end
@@ -2,5 +2,5 @@
2
2
  module Payday
3
3
 
4
4
  # Current Version
5
- VERSION = "1.0.0beta6"
5
+ VERSION = "1.0.0beta7"
6
6
  end
data/test/invoice_test.rb CHANGED
@@ -87,13 +87,39 @@ module Payday
87
87
  assert i.paid?
88
88
  end
89
89
 
90
+ test "iterating through invoice_details as two element arrays" do
91
+ i = Invoice.new(:invoice_details => [["Test", "Yes"], ["Awesome", "Absolutely"]])
92
+ details = []
93
+ i.each_detail do |key, value|
94
+ details << [key, value]
95
+ end
96
+
97
+ assert_equal 2, details.length
98
+ assert details.include?(["Test", "Yes"])
99
+ assert details.include?(["Awesome", "Absolutely"])
100
+ end
101
+
102
+ test "iterating through invoice_details as a hash" do
103
+ i = Invoice.new(:invoice_details => {"Test" => "Yes", "Awesome" => "Absolutely"})
104
+ details = []
105
+ i.each_detail do |key, value|
106
+ details << [key, value]
107
+ end
108
+
109
+ assert_equal 2, details.length
110
+ assert details.include?(["Test", "Yes"])
111
+ assert details.include?(["Awesome", "Absolutely"])
112
+ end
113
+
90
114
  test "rendering to file" do
91
115
  File.unlink("tmp/testing.pdf") if File.exists?("tmp/testing.pdf")
92
116
  assert !File.exists?("tmp/testing.pdf")
93
117
 
94
118
  i = Invoice.new(:tax_rate => 0.1, :notes => "These are some crazy awesome notes!", :invoice_number => 12,
95
119
  :due_at => Date.civil(2011, 1, 22), :paid_at => Date.civil(2012, 2, 22),
96
- :bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222", :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229")
120
+ :bill_to => "Alan Johnson\n101 This Way\nSomewhere, SC 22222",
121
+ :ship_to => "Frank Johnson\n101 That Way\nOther, SC 22229",
122
+ :invoice_details => {"Ordered By:" => "Alan Johnson", "Paid By:" => "Dude McDude"})
97
123
 
98
124
  Payday::Config.default.company_details = "10 This Way\nManhattan, NY 10001\n800-111-2222\nawesome@awesomecorp.com"
99
125
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: payday
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 5
5
- version: 1.0.0beta6
5
+ version: 1.0.0beta7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alan Johnson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-10 00:00:00 -05:00
13
+ date: 2011-03-12 23:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -72,12 +72,19 @@ files:
72
72
  - README.md
73
73
  - Rakefile
74
74
  - assets/default_logo.png
75
+ - lib/generators/payday/setup/USAGE
76
+ - lib/generators/payday/setup/setup_generator.rb
77
+ - lib/generators/payday/setup/templates/invoice.rb
78
+ - lib/generators/payday/setup/templates/line_item.rb
79
+ - lib/generators/payday/setup/templates/migration.rb
75
80
  - lib/payday.rb
76
81
  - lib/payday/config.rb
82
+ - lib/payday/i18n.rb
77
83
  - lib/payday/invoice.rb
78
84
  - lib/payday/invoiceable.rb
79
85
  - lib/payday/line_item.rb
80
86
  - lib/payday/line_itemable.rb
87
+ - lib/payday/locale/en.yml
81
88
  - lib/payday/pdf_renderer.rb
82
89
  - lib/payday/version.rb
83
90
  - payday.gemspec