webtranslateit-payday 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +1 -0
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/ci.yml +53 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +11 -0
- data/.rubocop_todo.yml +22 -0
- data/CHANGELOG.md +76 -0
- data/Gemfile +3 -0
- data/Guardfile +10 -0
- data/README.md +175 -0
- data/Rakefile +12 -0
- data/fonts/NotoSans-Bold.ttf +0 -0
- data/fonts/NotoSans-Regular.ttf +0 -0
- data/lib/generators/payday/setup/USAGE +30 -0
- data/lib/generators/payday/setup/setup_generator.rb +44 -0
- data/lib/generators/payday/setup/templates/invoice.rb +5 -0
- data/lib/generators/payday/setup/templates/line_item.rb +5 -0
- data/lib/generators/payday/setup/templates/migration.rb +26 -0
- data/lib/payday/config.rb +35 -0
- data/lib/payday/i18n.rb +3 -0
- data/lib/payday/invoice.rb +52 -0
- data/lib/payday/invoiceable.rb +87 -0
- data/lib/payday/line_item.rb +46 -0
- data/lib/payday/line_itemable.rb +12 -0
- data/lib/payday/locale/de.yml +23 -0
- data/lib/payday/locale/en.yml +22 -0
- data/lib/payday/locale/es.yml +22 -0
- data/lib/payday/locale/fr.yml +22 -0
- data/lib/payday/locale/nl.yml +22 -0
- data/lib/payday/locale/zh-CN.yml +21 -0
- data/lib/payday/pdf_renderer.rb +322 -0
- data/lib/payday/version.rb +5 -0
- data/lib/payday.rb +18 -0
- data/payday.gemspec +35 -0
- data/spec/assets/default_logo.png +0 -0
- data/spec/assets/svg.pdf +2501 -0
- data/spec/assets/testing.pdf +14178 -0
- data/spec/assets/testing_predefined_amount.pdf +0 -0
- data/spec/assets/tiger.svg +52 -0
- data/spec/invoice_spec.rb +244 -0
- data/spec/line_item_spec.rb +30 -0
- data/spec/pdf_renderer_spec.rb +11 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/asset_matchers.rb +26 -0
- metadata +297 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3aeab98b068c4f44f598410d9f9dfabab144bc3ea55d8126876b2c89cf5968f0
|
4
|
+
data.tar.gz: c988edd5e6b6d2d9c07ec4f0c2caf9e7182d36ce0b30696c32288be7ae465f3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dcca015e4fa6f6bebcf95a2bb24b3ed6c28bf06dc062509d358da45fde40d512ef8c29532ac2d83c54441283706b8d164b5330bf02ad22635a8ac1ab874213af
|
7
|
+
data.tar.gz: bb6e23f0ae4aea9c277812598b005a7ba04148af6444b4a9e9833fdbf7d2e8e57b954dec63281ae1f9991c395ba21a81cb69a6f03b5763b309ceb969e8395529
|
data/.gitattributes
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.pdf binary
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
3
|
+
# Please see the documentation for all configuration options:
|
4
|
+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
5
|
+
|
6
|
+
version: 2
|
7
|
+
updates:
|
8
|
+
- package-ecosystem: "bundler" # See documentation for possible values
|
9
|
+
directory: "/" # Location of package manifests
|
10
|
+
schedule:
|
11
|
+
interval: "daily"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rspec
|
36
|
+
|
37
|
+
linters:
|
38
|
+
name: Linters
|
39
|
+
runs-on: ubuntu-20.04
|
40
|
+
timeout-minutes: 10
|
41
|
+
|
42
|
+
steps:
|
43
|
+
- name: Checkout repository
|
44
|
+
uses: actions/checkout@v2.3.5
|
45
|
+
|
46
|
+
- name: Install ruby and gems
|
47
|
+
uses: ruby/setup-ruby@v1
|
48
|
+
with:
|
49
|
+
ruby-version: 2.6.9 # Use .ruby-version file instead of duplicating here and in Gemfile?
|
50
|
+
bundler-cache: true
|
51
|
+
|
52
|
+
- name: Run ruby linter
|
53
|
+
run: bundle exec rubocop --format github
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2022-02-02 14:41:30 UTC using RuboCop version 1.25.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Configuration parameters: AllowedConstants.
|
11
|
+
Style/Documentation:
|
12
|
+
Exclude:
|
13
|
+
- 'spec/**/*'
|
14
|
+
- 'test/**/*'
|
15
|
+
- 'lib/generators/payday/setup/setup_generator.rb'
|
16
|
+
|
17
|
+
# Offense count: 19
|
18
|
+
# Cop supports --auto-correct.
|
19
|
+
# Configuration parameters: EnforcedStyle.
|
20
|
+
# SupportedStyles: always, always_true, never
|
21
|
+
Style/FrozenStringLiteralComment:
|
22
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## 1.2.7 (2022-02-04)
|
4
|
+
|
5
|
+
* Allow styling line item descriptions and notes.
|
6
|
+
|
7
|
+
## 1.2.6 (2022-02-03)
|
8
|
+
|
9
|
+
* Add new fonts and increase font size.
|
10
|
+
|
11
|
+
## 1.2.5 (2022-02-02)
|
12
|
+
|
13
|
+
* New: Ability to add LineItems with “pre-defined” amounts.
|
14
|
+
`LineItem.new(description: 'Flat fee', predefined_amount: 244)`.
|
15
|
+
This allows to create lines without quantities and unit prices, which is useful to add flat fees.
|
16
|
+
|
17
|
+
## 1.2.4 (2022-02-02)
|
18
|
+
|
19
|
+
* Lint code with Rubocop.
|
20
|
+
|
21
|
+
## 1.2.3 (2022-02-02)
|
22
|
+
|
23
|
+
* Fix deprecation warning.
|
24
|
+
|
25
|
+
## 1.2.2 (2022-02-02)
|
26
|
+
|
27
|
+
* Dependency updates (prawn, prawn-svg, add prawn-table). This update might break tests as PDF are rendered slightly differently.
|
28
|
+
* Fix deprecation warning.
|
29
|
+
|
30
|
+
## 1.2.1 (2022-02-01)
|
31
|
+
|
32
|
+
* Add convenience method to add line_items to invoices (`Invoice#add_line_item(options)`). Takes the same options as `LineItem.new(options)`.
|
33
|
+
|
34
|
+
## 1.2.0 (2021-12-22)
|
35
|
+
|
36
|
+
This brings changes made for WebTranslateIt.com’s billing system:
|
37
|
+
|
38
|
+
* Tax rate is a full percent number (for instance `21.0` for a 21% tax rate, `10.0` for a 10% tax rate). This is a breaking change compared to the previous `0.21` for 21% tax rate and `0.1` for 10% tax rate, but it is more convenient to use.
|
39
|
+
* Invoices were updated to call the document `Invoice` if the document was not paid or `Receipt` if the document was paid.
|
40
|
+
|
41
|
+
## 1.1.7 (2021-12-22)
|
42
|
+
|
43
|
+
* Remove `.ruby-version` file locking ruby at 2.1.5.
|
44
|
+
* Add CI.
|
45
|
+
* Ruby 2.6, 2.7 and 3.0 compatibility.
|
46
|
+
* Specify dependencies to `activesupport` and `rexml` in gemspec.
|
47
|
+
* Fix deprecation warnings with newer versions of the Money gem.
|
48
|
+
|
49
|
+
## 1.1.6 (2021-11-29)
|
50
|
+
|
51
|
+
* Ruby 2.6 Compatibility.
|
52
|
+
|
53
|
+
## 1.1.4 (2015-05-29)
|
54
|
+
|
55
|
+
* Bumped money gem to 6.5 (was 6.1.1)
|
56
|
+
* Bumped i18n gem to 0.7 (was 0.6.11)
|
57
|
+
* Added German translation for invoice date.
|
58
|
+
|
59
|
+
## 1.1.3 (2015-01-02)
|
60
|
+
|
61
|
+
* Loosened requirements on Money gem.
|
62
|
+
* Bumped rspec to latest and cleared up a deprecation warning.
|
63
|
+
* Added support for `invoice_date` field (thanks [danielma](https://github.com/danielma)!)
|
64
|
+
* Bugfix: Resolved issue where money values were being shown at 1/100th of the intended amount (thanks [watsonbox](https://github.com/watsonbox)!)
|
65
|
+
|
66
|
+
## 1.1.2 (2014-05-03)
|
67
|
+
|
68
|
+
* Added NL locale (thanks [jedi4ever](https://github.com/jedi4ever)!).
|
69
|
+
* Updated Prawn to 1.0.
|
70
|
+
* Updated Prawn SVG to 0.15.0.0.
|
71
|
+
* Updated Money to 6.1.1.
|
72
|
+
* Updated i18n to 0.6.9.
|
73
|
+
|
74
|
+
## 1.1.1 (2013-07-20)
|
75
|
+
|
76
|
+
* Added support for zh-CN locale (thanks [Martin91](https://github.com/Martin91)!).
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
guard :rspec, cmd: 'bundle exec rspec --color --format progress' do
|
2
|
+
watch(%r{^spec/.+_spec\.rb$})
|
3
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
4
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
5
|
+
end
|
6
|
+
|
7
|
+
guard :rubocop do
|
8
|
+
watch(/.+\.rb$/)
|
9
|
+
watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
|
10
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
Payday!
|
2
|
+
===
|
3
|
+
Payday is a library for rendering invoices to pdfs.
|
4
|
+
|
5
|
+
We use payday intensively at [WebTranslateIt.com](https://webtranslateit.com) to generate customer’s invoices and receipts. When we upgraded our app to ruby 2.7 this gem failed in many ways and the original source code by Alan Johnson was nowhere to be found on GitHub. So we took the source code out of [rubygems.org](https://rubygems.org) and created this repo. We’ve since added a few new features and fixes, which can be seen [in the changelog](https://github.com/webtranslateit/payday/blob/main/CHANGELOG.md).
|
6
|
+
|
7
|
+
Here’s an [example PDF Invoice](https://github.com/webtranslateit/payday/raw/main/spec/assets/testing_predefined_amount.pdf) generated with our fork of payday.
|
8
|
+
|
9
|
+
Installing
|
10
|
+
===
|
11
|
+
Payday is available as a Rubygem, so installing it is as easy as running:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem install webtranslateit-payday
|
15
|
+
```
|
16
|
+
|
17
|
+
Or, using bundler:
|
18
|
+
|
19
|
+
```
|
20
|
+
gem 'webtranslateit-payday', require: 'payday'
|
21
|
+
```
|
22
|
+
|
23
|
+
Using Payday
|
24
|
+
===
|
25
|
+
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.
|
26
|
+
|
27
|
+
Example:
|
28
|
+
|
29
|
+
``` ruby
|
30
|
+
invoice = Payday::Invoice.new(invoice_number: 12)
|
31
|
+
# 2 lines with a price and a quantity. Amount will be calculated by price * quantity
|
32
|
+
invoice.add_line_item(price: 20, quantity: 5, description: 'Pants')
|
33
|
+
invoice.add_line_item(price: 10, quantity: 3, description: 'Shirts')
|
34
|
+
# a line with no price or quantity but with a predefined price (or flat fee)
|
35
|
+
invoice.add_line_item(predefined_amount: 10, description: 'Shipping')
|
36
|
+
invoice.render_pdf_to_file('/path/to_file.pdf')
|
37
|
+
```
|
38
|
+
|
39
|
+
Documentation
|
40
|
+
===
|
41
|
+
Documentation for the latest version of Payday is available at [rubydoc.info](http://www.rubydoc.info/gems/payday).
|
42
|
+
|
43
|
+
Customizing Your Invoice
|
44
|
+
===
|
45
|
+
`Payday::Config` includes quite a few options for customizing your invoices, such as options for customizing the logo and
|
46
|
+
company details on the invoice.
|
47
|
+
|
48
|
+
Example:
|
49
|
+
|
50
|
+
``` ruby
|
51
|
+
Payday::Config.default.invoice_logo = "/path/to/company/logo.png"
|
52
|
+
Payday::Config.default.company_name = "Awesome Corp"
|
53
|
+
Payday::Config.default.company_details = "10 This Way\nManhattan, NY 10001\n800-111-2222\nawesome@awesomecorp.com"
|
54
|
+
```
|
55
|
+
|
56
|
+
Using Payday with ActiveRecord Objects (or any other objects, for that matter)
|
57
|
+
===
|
58
|
+
|
59
|
+
Payday focuses on two main objects, an invoice and a line item, so to use 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.
|
60
|
+
|
61
|
+
Thanks to the work of Andrew Nordman, Payday includes a Rails generator that makes it super simple to generate the necessary models and migration for wiring Payday up to your app. Run `rails generate payday:setup --help` for more information about using the generator.
|
62
|
+
|
63
|
+
For a bit more fleshed out example, be sure to check out [http://github.com/commondream/payday-example](http://github.com/commondream/payday-example).
|
64
|
+
|
65
|
+
Rendering Payday PDFs To The Web
|
66
|
+
===
|
67
|
+
Payday's Invoiceable module includes methods for rendering pdfs to disk and for rendering them to a string. In a Rails controller, you can use the
|
68
|
+
render to string method to render a pdf directly to the browser like this:
|
69
|
+
|
70
|
+
In `config/initializers/mime_types.rb`:
|
71
|
+
|
72
|
+
``` ruby
|
73
|
+
Mime::Type.register 'application/pdf', :pdf
|
74
|
+
```
|
75
|
+
|
76
|
+
In your controller:
|
77
|
+
|
78
|
+
``` ruby
|
79
|
+
respond_to do |format|
|
80
|
+
format.html
|
81
|
+
format.pdf do
|
82
|
+
send_data invoice.render_pdf, filename: 'Invoice #12.pdf', type: 'application/pdf', disposition: 'inline'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
Be sure to restart your server after you edit the mime_types initializer. The updated setting won't take effect until you do.
|
88
|
+
|
89
|
+
I18n
|
90
|
+
===
|
91
|
+
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:
|
92
|
+
|
93
|
+
``` yaml
|
94
|
+
en:
|
95
|
+
payday:
|
96
|
+
status:
|
97
|
+
paid: PAID
|
98
|
+
overdue: OVERDUE
|
99
|
+
refunded: REFUNDED
|
100
|
+
invoice:
|
101
|
+
bill_to: Bill To
|
102
|
+
ship_to: Ship To
|
103
|
+
invoice_no: "Invoice #:"
|
104
|
+
due_date: "Due Date:"
|
105
|
+
paid_date: "Paid Date:"
|
106
|
+
subtotal: "Subtotal:"
|
107
|
+
tax: "Tax:"
|
108
|
+
total: "Total:"
|
109
|
+
line_item:
|
110
|
+
description: Description
|
111
|
+
unit_price: Unit Price
|
112
|
+
quantity: Quantity
|
113
|
+
amount: Amount
|
114
|
+
```
|
115
|
+
|
116
|
+
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
|
117
|
+
the main Payday distribution and other Payday users can enjoy the fruits of your labor.
|
118
|
+
|
119
|
+
Examples
|
120
|
+
===
|
121
|
+
Here's an [example PDF Invoice](https://github.com/webtranslateit/payday/raw/main/spec/assets/testing_predefined_amount.pdf)
|
122
|
+
|
123
|
+
Contributing
|
124
|
+
===
|
125
|
+
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!
|
126
|
+
|
127
|
+
We've had some awesome contributers:
|
128
|
+
|
129
|
+
* Sam Pizzey ([pizzeys](http://github.com/pizzeys))
|
130
|
+
* Andrew Nordman ([cadwallion](http://github.com/cadwallion))
|
131
|
+
* Pierre Olivier Martel ([pomartel](http://github.com/pomartel))
|
132
|
+
* Matt Hoofman ([mhoofman](https://github.com/mhoofman))
|
133
|
+
* Édouard Brière ([edouard](https://github.com/edouard))
|
134
|
+
* Jim Jones ([aantix](https://github.com/aantix))
|
135
|
+
* Hussein Morsy ([husseinmorsy](https://github.com/husseinmorsy))
|
136
|
+
|
137
|
+
To Do
|
138
|
+
===
|
139
|
+
Here's what we're planning on working on with Payday in the near future:
|
140
|
+
|
141
|
+
* Actually get a designer to style the invoices.
|
142
|
+
* Add support for Money values
|
143
|
+
* Add support for blank line items
|
144
|
+
* Add support for indented line items
|
145
|
+
* Apply different tax rates to different line items
|
146
|
+
* Add support for shipping either pre or post tax
|
147
|
+
* Add ability to show skus or product ids on each line item
|
148
|
+
* Add ability to add fine print to invoices.
|
149
|
+
* Ability to render invoice to html for web viewing
|
150
|
+
|
151
|
+
Acknowledgements
|
152
|
+
===
|
153
|
+
This wouldn't be possible without the amazing [Prawn](http://prawn.majesticseacreature.com) gem and the team behind it.
|
154
|
+
|
155
|
+
License
|
156
|
+
===
|
157
|
+
Copyright (C) 2011 by Alan Johnson
|
158
|
+
|
159
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
160
|
+
of this software and associated documentation files (the "Software"), to deal
|
161
|
+
in the Software without restriction, including without limitation the rights
|
162
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
163
|
+
copies of the Software, and to permit persons to whom the Software is
|
164
|
+
furnished to do so, subject to the following conditions:
|
165
|
+
|
166
|
+
The above copyright notice and this permission notice shall be included in
|
167
|
+
all copies or substantial portions of the Software.
|
168
|
+
|
169
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
170
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
171
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
172
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
173
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
174
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
175
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
@@ -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,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, refunded_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
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Payday
|
2
|
+
# Configuration for Payday. This is a singleton, so to set the company_name you would call
|
3
|
+
# Payday::Config.default.company_name = "Awesome Corp".
|
4
|
+
class Config
|
5
|
+
attr_accessor :invoice_logo, :company_name, :company_details, :date_format, :currency
|
6
|
+
|
7
|
+
# Sets the page size to use. See the
|
8
|
+
# {http://prawn.majesticseacreature.com/docs/0.10.2/Prawn/Document/PageGeometry.html Prawn documentation} for valid
|
9
|
+
# page_size values.
|
10
|
+
attr_accessor :page_size
|
11
|
+
|
12
|
+
# Returns the default configuration instance
|
13
|
+
def self.default
|
14
|
+
@default ||= new
|
15
|
+
end
|
16
|
+
|
17
|
+
# Internal: Resets a config object back to its default settings.
|
18
|
+
#
|
19
|
+
# Primarily intended for use in our tests.
|
20
|
+
def reset
|
21
|
+
# TODO: Move into specs and make minimal configuration required (company name / details)
|
22
|
+
self.invoice_logo = File.join(File.dirname(__FILE__), '..', '..', 'spec', 'assets', 'default_logo.png')
|
23
|
+
self.company_name = 'Awesome Corp'
|
24
|
+
self.company_details = 'awesomecorp@commondream.net'
|
25
|
+
self.date_format = '%B %e, %Y'
|
26
|
+
self.currency = 'USD'
|
27
|
+
self.page_size = 'LETTER'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Internal: Contruct a new config object.
|
31
|
+
def initialize
|
32
|
+
reset
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/payday/i18n.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Payday
|
2
|
+
# Basically just an invoice. Stick a ton of line items in it, add some details, and then render it out!
|
3
|
+
class Invoice
|
4
|
+
include Payday::Invoiceable
|
5
|
+
|
6
|
+
attr_accessor :invoice_number, :bill_to, :ship_to, :notes, :line_items, :shipping_description,
|
7
|
+
:tax_description, :due_at, :paid_at, :refunded_at, :currency, :invoice_details, :invoice_date
|
8
|
+
|
9
|
+
attr_reader :tax_rate, :shipping_rate
|
10
|
+
|
11
|
+
# rubocop:todo Metrics/PerceivedComplexity
|
12
|
+
# rubocop:todo Metrics/MethodLength
|
13
|
+
# rubocop:todo Metrics/AbcSize
|
14
|
+
def initialize(options = {}) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
|
15
|
+
self.invoice_number = options[:invoice_number] || nil
|
16
|
+
self.bill_to = options[:bill_to] || nil
|
17
|
+
self.ship_to = options[:ship_to] || nil
|
18
|
+
self.notes = options[:notes] || nil
|
19
|
+
self.line_items = options[:line_items] || []
|
20
|
+
self.shipping_rate = options[:shipping_rate] || nil
|
21
|
+
self.shipping_description = options[:shipping_description] || nil
|
22
|
+
self.tax_rate = options[:tax_rate] || nil
|
23
|
+
self.tax_description = options[:tax_description] || nil
|
24
|
+
self.due_at = options[:due_at] || nil
|
25
|
+
self.paid_at = options[:paid_at] || nil
|
26
|
+
self.refunded_at = options[:refunded_at] || nil
|
27
|
+
self.currency = options[:currency] || nil
|
28
|
+
self.invoice_details = options[:invoice_details] || []
|
29
|
+
self.invoice_date = options[:invoice_date] || nil
|
30
|
+
end
|
31
|
+
# rubocop:enable Metrics/AbcSize
|
32
|
+
# rubocop:enable Metrics/MethodLength
|
33
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
34
|
+
|
35
|
+
# The tax rate that we're applying, as a BigDecimal
|
36
|
+
def tax_rate=(value)
|
37
|
+
value = 0 if value.to_s.blank?
|
38
|
+
@tax_rate = BigDecimal(value.to_s)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Shipping rate
|
42
|
+
def shipping_rate=(value)
|
43
|
+
value = 0 if value.to_s.blank?
|
44
|
+
@shipping_rate = BigDecimal(value.to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Adds a line item
|
48
|
+
def add_line_item(options = {})
|
49
|
+
line_items << Payday::LineItem.new(options)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|