receipts 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -0
- data/README.md +187 -183
- data/Rakefile +65 -46
- data/examples/{gorails.png → images/logo.png} +0 -0
- data/examples/images/options.jpg +0 -0
- data/examples/invoice.pdf +0 -0
- data/examples/receipt.pdf +0 -0
- data/examples/statement.pdf +0 -0
- data/lib/receipts/base.rb +102 -0
- data/lib/receipts/invoice.rb +1 -87
- data/lib/receipts/receipt.rb +1 -66
- data/lib/receipts/statement.rb +1 -84
- data/lib/receipts/version.rb +1 -1
- data/lib/receipts.rb +1 -19
- data/receipts.gemspec +18 -13
- metadata +13 -86
- data/.github/FUNDING.yml +0 -12
- data/.github/workflows/ci.yml +0 -36
- data/.gitignore +0 -15
- data/.travis.yml +0 -4
- data/spec/receipts_spec.rb +0 -18
- data/spec/spec_helper.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 875a1ff6a3a1dcca7a1de7c21362ce0837426c3f5b3299cd9f15f38daf97cfa2
|
4
|
+
data.tar.gz: 2aed77f22588a1675b558eccbe1122cc94912e04fa692aacaa7a40b16429495e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f54fc0957bccf87ebd1ae377d275f9dfe0f39a8b2cd0e8c4b5a96635183abd24f229eea142631a98d5a61156fc87cd366864e35a044a53e60ec072de08ada3e5
|
7
|
+
data.tar.gz: 87745a1fe2f9cb84c69a00d816e254c4cc7b2dfee02457ece89d9e543a39b65813bfd427e7fa789e5a56feea1a3837ac3e8cc5d4574e4894805b535de76cf630
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
### Unreleased
|
2
2
|
|
3
|
+
### 2.0.0
|
4
|
+
|
5
|
+
* New, consistent layouts between Receipts, Invoices, and Statements - @excid3
|
6
|
+
* PDFs can now be completely customized - @excid3
|
7
|
+
* Add line_items to Receipts - @excid3
|
8
|
+
|
3
9
|
### 1.2.0
|
4
10
|
|
5
11
|
* Update design to give more room for longer product names, addresses, etc - @excid3
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|

|
2
2
|
|
3
|
-
# Receipts
|
3
|
+
# Receipts Gem
|
4
4
|
|
5
|
-
Receipts for your Rails application that works with any payment provider.
|
5
|
+
Receipts, Invoices, and Statements for your Rails application that works with any payment provider. Receipts uses Prawn to generate the PDFs.
|
6
6
|
|
7
|
-
Check out the [example
|
7
|
+
Check out the [example PDFs](https://github.com/excid3/receipts/blob/master/examples/).
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -24,112 +24,99 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
|
28
|
-
model that stores your transaction details. In this example our
|
29
|
-
application has a model named `Charge` that we will use.
|
30
|
-
|
31
|
-
We're going to add a method called `receipt` on our model called `Charge`
|
32
|
-
that will create a new receipt for the charge using attributes from the
|
33
|
-
model.
|
34
|
-
|
35
|
-
Video Tutorial:
|
36
|
-
[GoRails Episode #51](https://gorails.com/episodes/pdf-receipts)
|
27
|
+
To generate a Receipt, Invoice, or Statement, create an instance and provide content to render:
|
37
28
|
|
38
29
|
```ruby
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
["Amount", "$#{amount / 100}.00"],
|
76
|
-
["Charged to", "#{card_type} (**** **** **** #{card_last4})"],
|
77
|
-
["Transaction ID", uuid]
|
78
|
-
],
|
79
|
-
font: {
|
80
|
-
bold: Rails.root.join('app/assets/fonts/tradegothic/TradeGothic-Bold.ttf'),
|
81
|
-
normal: Rails.root.join('app/assets/fonts/tradegothic/TradeGothic.ttf'),
|
82
|
-
}
|
83
|
-
)
|
84
|
-
end
|
85
|
-
end
|
30
|
+
r = Receipts::Receipt.new(
|
31
|
+
details: [
|
32
|
+
["Receipt Number", "123"],
|
33
|
+
["Date paid", Date.today],
|
34
|
+
["Payment method", "ACH super long super long super long super long super long"]
|
35
|
+
],
|
36
|
+
company: {
|
37
|
+
name: "Example, LLC",
|
38
|
+
address: "123 Fake Street\nNew York City, NY 10012",
|
39
|
+
email: "support@example.com",
|
40
|
+
logo: File.expand_path("./examples/images/logo.png")
|
41
|
+
},
|
42
|
+
recipient: [
|
43
|
+
"Customer",
|
44
|
+
"Their Address",
|
45
|
+
"City, State Zipcode",
|
46
|
+
nil,
|
47
|
+
"customer@example.org"
|
48
|
+
],
|
49
|
+
line_items: [
|
50
|
+
["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
|
51
|
+
["Subscription", "$19.00", "1", "$19.00"],
|
52
|
+
[nil, nil, "Subtotal", "$19.00"],
|
53
|
+
[nil, nil, "Tax", "$1.12"],
|
54
|
+
[nil, nil, "Total", "$20.12"],
|
55
|
+
[nil, nil, "<b>Amount paid</b>", "$20.12"],
|
56
|
+
[nil, nil, "Refunded on #{Date.today}", "$5.00"]
|
57
|
+
],
|
58
|
+
footer: "Thanks for your business. Please contact us if you have any questions."
|
59
|
+
)
|
60
|
+
|
61
|
+
# Returns a string of the raw PDF
|
62
|
+
r.render
|
63
|
+
|
64
|
+
# Writes the PDF to disk
|
65
|
+
r.render_file "examples/receipt.pdf"
|
86
66
|
```
|
87
67
|
|
88
|
-
|
89
|
-
display.
|
68
|
+
### Options
|
90
69
|
|
91
|
-
|
70
|
+
You can pass the following options to generate a PDF:
|
92
71
|
|
93
|
-
* `
|
72
|
+
* `recipient` - Array of customer details to include. Typically, this is name, address, email, VAT ID, etc.
|
94
73
|
|
95
|
-
|
74
|
+
* `company` - Hash of your company details
|
96
75
|
|
97
|
-
* `
|
76
|
+
* `name` - Company name
|
98
77
|
|
99
|
-
|
78
|
+
* `address` - Company address
|
100
79
|
|
101
|
-
* `
|
80
|
+
* `email` - Company support email address
|
102
81
|
|
103
|
-
|
82
|
+
* `phone` - Company phone number - _Optional_
|
104
83
|
|
105
|
-
* `
|
106
|
-
|
107
|
-
* `email` - **Required**
|
108
|
-
* `line_items` - **Required**
|
84
|
+
* `logo` - Logo to be displayed on the receipt - _Optional_
|
85
|
+
This can be either a Path, File, StringIO, or URL. Here are a few examples:
|
109
86
|
|
110
|
-
|
87
|
+
```ruby
|
88
|
+
logo: Rails.root.join("app/assets/images/logo.png")
|
89
|
+
logo: File.expand_path("./logo.png")
|
90
|
+
logo: File.open("app/assets/images/logo.png", "rb")
|
91
|
+
logo: "https://www.ruby-lang.org/images/header-ruby-logo@2x.png" # Downloaded with OpenURI
|
92
|
+
```
|
111
93
|
|
112
|
-
|
94
|
+
* `details` - Array of details about the Receipt, Invoice, Statement. Typically, this is receipt numbers, issue date, due date, status, etc.
|
113
95
|
|
114
|
-
|
96
|
+
* `line_items` - Array of line items to be displayed in table format.
|
115
97
|
|
116
|
-
|
117
|
-
logo: Rails.root.join("app/assets/images/logo.png")
|
118
|
-
# or
|
119
|
-
logo: File.open("app/assets/images/logo.png", "rb")
|
120
|
-
```
|
98
|
+
* `footer` - String for a message at the bottom of the PDF.
|
121
99
|
|
122
|
-
|
100
|
+
* `font` - Hash of paths to font files - _Optional_
|
123
101
|
|
124
|
-
|
102
|
+
```ruby
|
103
|
+
font: {
|
104
|
+
bold: Rails.root.join('app/assets/fonts/tradegothic/TradeGothic-Bold.ttf'),
|
105
|
+
normal: Rails.root.join('app/assets/fonts/tradegothic/TradeGothic.ttf'),
|
106
|
+
}
|
107
|
+
```
|
125
108
|
|
126
|
-
|
109
|
+
Here's an example of where each option is displayed.
|
127
110
|
|
128
|
-
|
111
|
+

|
129
112
|
|
130
|
-
|
113
|
+
### Formatting
|
131
114
|
|
132
|
-
|
115
|
+
`details` and `line_items` allow inline formatting with Prawn. This allows you to use HTML tags to format text: `<b>` `<i>` `<u>` `<strikethrough>` `<sub>` `<sup>` `<font>` `<color>` `<link>`
|
116
|
+
|
117
|
+
See [the Prawn docs](https://prawnpdf.org/api-docs/2.3.0/Prawn/Text.html#text-instance_method) for more information.
|
118
|
+
|
119
|
+
### Internationalization (I18n)
|
133
120
|
|
134
121
|
You can use `I18n.t` when rendering your receipts to internationalize them.
|
135
122
|
|
@@ -141,21 +128,53 @@ line_items: [
|
|
141
128
|
]
|
142
129
|
```
|
143
130
|
|
144
|
-
|
131
|
+
### Custom PDF Content
|
132
|
+
|
133
|
+
You can change the entire PDF content by instantiating an Receipts object without any options.
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
receipt = Receipts::Receipt.new # creates an empty PDF
|
137
|
+
```
|
138
|
+
|
139
|
+
Each Receipts object inherits from Prawn::Document. This allows you to choose what is rendered and include any custom Prawn content you like.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
receipt.text("hello world")
|
143
|
+
```
|
144
|
+
|
145
|
+
You can also use the Receipts helpers in your custom PDFs at the current cursor position.
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
receipt.text("Custom header")
|
149
|
+
receipt.render_line_items([
|
150
|
+
["my line items"]
|
151
|
+
])
|
152
|
+
receipt.render_footer("This is a custom footer using the Receipts helper")
|
153
|
+
```
|
154
|
+
|
155
|
+
### Rendering PDFs
|
156
|
+
|
157
|
+
To render a PDF in memory, use `render`. This is recommended for serving PDFs in your Rails controllers.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
receipt.render
|
161
|
+
```
|
162
|
+
|
163
|
+
To render a PDF to disk, use `render_file`:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
receipt.render_file "receipt.pdf"
|
167
|
+
```
|
168
|
+
|
169
|
+
## Rendering PDFs in Rails controller actions
|
145
170
|
|
146
|
-
Here
|
147
|
-
you visit it with the PDF format, it calls the `receipt` method that we
|
148
|
-
just created on the `Charge` model.
|
171
|
+
Here's an example Rails controller action you can use for serving PDFs. We'll first look up the database record for the `Charge` we want to render a receipt for.
|
149
172
|
|
150
|
-
|
151
|
-
customize the filename to your liking.
|
173
|
+
The `Charge` model has a `receipt` method that returns a `Receipts::Receipt` instance with all the receipt data filled out.
|
152
174
|
|
153
|
-
|
175
|
+
Then we can `render` to generate the PDF in memory. This produces a String with the raw PDF data in it.
|
154
176
|
|
155
|
-
|
156
|
-
render the PDF in the browser without forcing the download. If you
|
157
|
-
delete this option or change it to `:attachment` then the receipt will
|
158
|
-
be downloaded instead.
|
177
|
+
Using `send_data` from Rails, we can send the PDF contents and provide the browser with a recommended filename, content type and disposition.
|
159
178
|
|
160
179
|
```ruby
|
161
180
|
class ChargesController < ApplicationController
|
@@ -164,12 +183,7 @@ class ChargesController < ApplicationController
|
|
164
183
|
|
165
184
|
def show
|
166
185
|
respond_to do |format|
|
167
|
-
format.pdf {
|
168
|
-
send_data @charge.receipt.render,
|
169
|
-
filename: "#{@charge.created_at.strftime("%Y-%m-%d")}-gorails-receipt.pdf",
|
170
|
-
type: "application/pdf",
|
171
|
-
disposition: :inline
|
172
|
-
}
|
186
|
+
format.pdf { send_pdf }
|
173
187
|
end
|
174
188
|
end
|
175
189
|
|
@@ -178,13 +192,18 @@ class ChargesController < ApplicationController
|
|
178
192
|
def set_charge
|
179
193
|
@charge = current_user.charges.find(params[:id])
|
180
194
|
end
|
195
|
+
|
196
|
+
def send_pdf
|
197
|
+
# Render the PDF in memory and send as the response
|
198
|
+
send_data @charge.receipt.render,
|
199
|
+
filename: "#{@charge.created_at.strftime("%Y-%m-%d")}-gorails-receipt.pdf",
|
200
|
+
type: "application/pdf",
|
201
|
+
disposition: :inline # or :attachment to download
|
202
|
+
end
|
181
203
|
end
|
182
204
|
```
|
183
205
|
|
184
|
-
|
185
|
-
`pdf` and you're good to go.
|
186
|
-
|
187
|
-
For example:
|
206
|
+
Then, just `link_to` to your charge with the format of `pdf`. For example:
|
188
207
|
|
189
208
|
```ruby
|
190
209
|
# config/routes.rb
|
@@ -192,93 +211,78 @@ resources :charges
|
|
192
211
|
```
|
193
212
|
|
194
213
|
```erb
|
195
|
-
<%= link_to "
|
214
|
+
<%= link_to "View Receipt", charge_path(@charge, format: :pdf) %>
|
196
215
|
```
|
197
216
|
|
198
217
|
## Invoices
|
199
218
|
|
200
|
-
Invoices follow the exact same set of steps as above
|
201
|
-
|
202
|
-
* `issue_date` - Date the invoice was issued
|
203
|
-
|
204
|
-
* `due_date` - Date the invoice payment is due
|
205
|
-
|
206
|
-
* `status` - A status for the invoice (Pending, Paid, etc)
|
207
|
-
|
208
|
-
* `bill_to` - A string or Array of lines with billing details
|
209
|
-
|
210
|
-
You can also use line_items to flexibly generate and display the table with items in it, including subtotal, taxes, and total amount.
|
219
|
+
Invoices follow the exact same set of steps as above. You'll simply want to modify the `details` to include other information for the Invoice such as the Issue Date, Due Date, etc.
|
211
220
|
|
212
221
|
```ruby
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
],
|
238
|
-
|
222
|
+
Receipts::Invoice.new(
|
223
|
+
details: [
|
224
|
+
["Invoice Number", "123"],
|
225
|
+
["Issue Date", Date.today.strftime("%B %d, %Y")],
|
226
|
+
["Due Date", Date.today.strftime("%B %d, %Y")],
|
227
|
+
["Status", "<b><color rgb='#5eba7d'>PAID</color></b>"]
|
228
|
+
],
|
229
|
+
recipient: [
|
230
|
+
"<b>Bill To</b>",
|
231
|
+
"Customer",
|
232
|
+
"Address",
|
233
|
+
"City, State Zipcode",
|
234
|
+
"customer@example.org"
|
235
|
+
],
|
236
|
+
company: {
|
237
|
+
name: "Example, LLC",
|
238
|
+
address: "123 Fake Street\nNew York City, NY 10012",
|
239
|
+
phone: "(555) 867-5309",
|
240
|
+
email: "support@example.com",
|
241
|
+
logo: File.expand_path("./examples/images/logo.png")
|
242
|
+
},
|
243
|
+
line_items: [
|
244
|
+
["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
|
245
|
+
["Subscription", "$19.00", "1", "$19.00"],
|
246
|
+
[nil, nil, "Subtotal", "$19.00"],
|
247
|
+
[nil, nil, "Tax Rate", "0%"],
|
248
|
+
[nil, nil, "Amount Due", "$19.00"]
|
249
|
+
]
|
250
|
+
)
|
239
251
|
```
|
240
252
|
|
241
253
|
## Statements
|
242
254
|
|
243
|
-
Statements follow the exact same set of steps as
|
244
|
-
|
245
|
-
* `issue_date` - Date the invoice was issued
|
246
|
-
|
247
|
-
* `start_date` - The start date of the statement period
|
248
|
-
|
249
|
-
* `start_date` - The end date of the statement period
|
250
|
-
|
251
|
-
* `bill_to` - A string or Array of lines with account details
|
252
|
-
|
253
|
-
You can also use line_items to flexibly generate and display the table with items in it, including subtotal, taxes, and total amount.
|
255
|
+
Statements follow the exact same set of steps as above. You'll simply want to modify the `details` to include other information for the Invoice such as the Issue Date, Start and End Dates, etc.
|
254
256
|
|
255
257
|
```ruby
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
],
|
281
|
-
|
258
|
+
Receipts::Statement.new(
|
259
|
+
details: [
|
260
|
+
["Statement Number", "123"],
|
261
|
+
["Issue Date", Date.today.strftime("%B %d, %Y")],
|
262
|
+
["Period", "#{(Date.today - 30).strftime("%B %d, %Y")} - #{Date.today.strftime("%B %d, %Y")}"]
|
263
|
+
],
|
264
|
+
recipient: [
|
265
|
+
"<b>Bill To</b>",
|
266
|
+
"Customer",
|
267
|
+
"Address",
|
268
|
+
"City, State Zipcode",
|
269
|
+
"customer@example.org"
|
270
|
+
],
|
271
|
+
company: {
|
272
|
+
name: "Example, LLC",
|
273
|
+
address: "123 Fake Street\nNew York City, NY 10012",
|
274
|
+
email: "support@example.com",
|
275
|
+
phone: "(555) 867-5309",
|
276
|
+
logo: File.expand_path("./examples/images/logo.png")
|
277
|
+
},
|
278
|
+
line_items: [
|
279
|
+
["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
|
280
|
+
["Subscription", "$19.00", "1", "$19.00"],
|
281
|
+
[nil, nil, "Subtotal", "$19.00"],
|
282
|
+
[nil, nil, "Tax Rate", "0%"],
|
283
|
+
[nil, nil, "Total", "$19.00"]
|
284
|
+
]
|
285
|
+
)
|
282
286
|
```
|
283
287
|
|
284
288
|
## Contributing
|
data/Rakefile
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
|
-
require "
|
3
|
-
require "open-uri"
|
4
|
+
require "rake/testtask"
|
4
5
|
|
5
|
-
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
6
11
|
|
7
|
-
|
8
|
-
task default: :spec
|
9
|
-
task test: :spec
|
12
|
+
task default: :test
|
10
13
|
|
11
14
|
task :console do
|
12
15
|
exec "irb -r receipts -I ./lib"
|
@@ -14,60 +17,74 @@ end
|
|
14
17
|
|
15
18
|
task :examples do
|
16
19
|
[:receipt, :invoice, :statement].each { |t| Rake::Task[t].invoke }
|
17
|
-
|
18
20
|
puts "Use `open examples` to view example PDFs."
|
19
21
|
end
|
20
22
|
|
21
23
|
task :receipt do
|
22
24
|
require "./lib/receipts"
|
23
25
|
|
24
|
-
Receipts::Receipt.new(
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
r = Receipts::Receipt.new(
|
27
|
+
recipient: [
|
28
|
+
"<b>Bill To</b>",
|
29
|
+
"Customer",
|
30
|
+
"Address",
|
31
|
+
"City, State Zipcode",
|
32
|
+
"customer@example.org"
|
33
|
+
],
|
28
34
|
company: {
|
29
|
-
name: "
|
35
|
+
name: "Example, LLC",
|
30
36
|
address: "123 Fake Street\nNew York City, NY 10012",
|
37
|
+
phone: "(555) 867-5309",
|
31
38
|
email: "support@example.com",
|
32
|
-
logo: "
|
39
|
+
logo: File.expand_path("./examples/images/logo.png")
|
33
40
|
},
|
41
|
+
details: [
|
42
|
+
["Receipt Number", "123"],
|
43
|
+
["Date paid", Date.today.strftime("%B %d, %Y")],
|
44
|
+
["Payment method", "ACH super long super long super long super long super long"]
|
45
|
+
],
|
34
46
|
line_items: [
|
35
|
-
["
|
36
|
-
["
|
37
|
-
["
|
38
|
-
["
|
39
|
-
[
|
40
|
-
["
|
47
|
+
["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
|
48
|
+
["Subscription", "$19.00", "1", "$19.00"],
|
49
|
+
[nil, nil, "Subtotal", "$19.00"],
|
50
|
+
[nil, nil, "Tax", "$1.12"],
|
51
|
+
[nil, nil, "Total", "$20.12"],
|
52
|
+
[nil, nil, "<b>Amount paid</b>", "$20.12"],
|
53
|
+
[nil, nil, "Refunded on #{Date.today.strftime("%B %d, %Y")}", "$5.00"]
|
41
54
|
]
|
42
|
-
)
|
55
|
+
)
|
56
|
+
r.render_file "examples/receipt.pdf"
|
43
57
|
end
|
44
58
|
|
45
59
|
task :invoice do
|
46
60
|
require "./lib/receipts"
|
47
61
|
|
48
62
|
Receipts::Invoice.new(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
63
|
+
details: [
|
64
|
+
["Invoice Number", "123"],
|
65
|
+
["Issue Date", Date.today.strftime("%B %d, %Y")],
|
66
|
+
["Due Date", Date.today.strftime("%B %d, %Y")],
|
67
|
+
["Status", "<b><color rgb='#5eba7d'>PAID</color></b>"]
|
68
|
+
],
|
69
|
+
recipient: [
|
70
|
+
"<b>Bill To</b>",
|
71
|
+
"Customer",
|
55
72
|
"Address",
|
56
73
|
"City, State Zipcode",
|
57
|
-
|
58
|
-
"mail@example.com"
|
74
|
+
"customer@example.org"
|
59
75
|
],
|
60
76
|
company: {
|
61
|
-
name: "
|
77
|
+
name: "Example, LLC",
|
62
78
|
address: "123 Fake Street\nNew York City, NY 10012",
|
79
|
+
phone: "(555) 867-5309",
|
63
80
|
email: "support@example.com",
|
64
|
-
# logo: Rails.root.join("app/assets/images/
|
65
|
-
# logo: File.
|
66
|
-
logo: File.
|
81
|
+
# logo: Rails.root.join("app/assets/images/logo.png")
|
82
|
+
# logo: File.open("./examples/images/logo.png")
|
83
|
+
logo: File.expand_path("./examples/images/logo.png")
|
67
84
|
},
|
68
85
|
line_items: [
|
69
86
|
["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
|
70
|
-
["
|
87
|
+
["Subscription", "$19.00", "1", "$19.00"],
|
71
88
|
[nil, nil, "Subtotal", "$19.00"],
|
72
89
|
[nil, nil, "Tax Rate", "0%"],
|
73
90
|
[nil, nil, "Amount Due", "$19.00"]
|
@@ -79,26 +96,28 @@ task :statement do
|
|
79
96
|
require "./lib/receipts"
|
80
97
|
|
81
98
|
Receipts::Statement.new(
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
"
|
89
|
-
"
|
90
|
-
|
91
|
-
"
|
99
|
+
details: [
|
100
|
+
["Statement Number", "123"],
|
101
|
+
["Issue Date", Date.today.strftime("%B %d, %Y")],
|
102
|
+
["Period", "#{(Date.today - 30).strftime("%B %d, %Y")} - #{Date.today.strftime("%B %d, %Y")}"]
|
103
|
+
],
|
104
|
+
recipient: [
|
105
|
+
"<b>Bill To</b>",
|
106
|
+
"Customer",
|
107
|
+
"Address",
|
108
|
+
"City, State Zipcode",
|
109
|
+
"customer@example.org"
|
92
110
|
],
|
93
111
|
company: {
|
94
|
-
name: "
|
112
|
+
name: "Example, LLC",
|
95
113
|
address: "123 Fake Street\nNew York City, NY 10012",
|
96
114
|
email: "support@example.com",
|
97
|
-
|
115
|
+
phone: "(555) 867-5309",
|
116
|
+
logo: File.expand_path("./examples/images/logo.png")
|
98
117
|
},
|
99
118
|
line_items: [
|
100
119
|
["<b>Item</b>", "<b>Unit Cost</b>", "<b>Quantity</b>", "<b>Amount</b>"],
|
101
|
-
["
|
120
|
+
["Subscription", "$19.00", "1", "$19.00"],
|
102
121
|
[nil, nil, "Subtotal", "$19.00"],
|
103
122
|
[nil, nil, "Tax Rate", "0%"],
|
104
123
|
[nil, nil, "Total", "$19.00"]
|