receipts 2.2.0 → 2.4.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 +23 -1
- data/README.md +35 -9
- data/Rakefile +3 -1
- data/examples/invoice.pdf +0 -0
- data/examples/receipt.pdf +0 -0
- data/examples/statement.pdf +0 -0
- data/lib/receipts/base.rb +17 -10
- data/lib/receipts/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a074319e14c0aaf9a5e4776d854c90810273092e58d7672046f7a6ef4d01a6d5
|
4
|
+
data.tar.gz: e4d3bf9feb0a135357a6666ca46a8c9298d0d623223101c0649c7c9b2b45248f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e22ececba2faf58b41ed4b677bbf351b6dadb51eb0c2e54b9930949eceb7bbc68d29aba7a642e44c47d76d9486669d324cd642befb920576398a13d392e8e303
|
7
|
+
data.tar.gz: 179cbdbf4fbaa3de6de2d1e76a0c9087bc91b9fa36c639f3d5824f112a32a1199662fd0ae87efa3d18f69be6744d3762e495e85cb111e67106a7bde81b90c7e3
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,34 @@
|
|
1
1
|
### Unreleased
|
2
2
|
|
3
|
+
* Add `display: []` for configuring company details that are rendered
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
r = Receipts::Receipt.new(
|
7
|
+
company: {
|
8
|
+
name: "Example, LLC",
|
9
|
+
address: "123 Fake Street\nNew York City, NY 10012",
|
10
|
+
phone: "(555) 867-5309",
|
11
|
+
email: "support@example.com",
|
12
|
+
iban: "123456789",
|
13
|
+
logo: File.expand_path("./examples/images/logo.png"),
|
14
|
+
display: [:address, :phone, :email, :iban]
|
15
|
+
},
|
16
|
+
# ...
|
17
|
+
)
|
18
|
+
```
|
19
|
+
|
20
|
+
### 2.3.0
|
21
|
+
|
22
|
+
* Add `column_widths:` option to specify line item column widths #35
|
23
|
+
|
24
|
+
### 2.2.0
|
25
|
+
|
3
26
|
* Allow specifiying other page sizes - @excid3
|
4
27
|
* Add `logo_height:` option to specify the height of the logo image
|
5
28
|
|
6
29
|
### 2.1.0
|
7
30
|
|
8
31
|
* Add `Receipts.default_font` - @excid3
|
9
|
-
>>>>>>> 65dc0260770f3d751f67dc5433be09127367b83b
|
10
32
|
|
11
33
|
### 2.0.0
|
12
34
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
](https://github.com/excid3/receipts/actions/workflows/ci.yml)
|
2
2
|
|
3
3
|
# Receipts Gem
|
4
4
|
|
@@ -16,11 +16,15 @@ gem 'receipts'
|
|
16
16
|
|
17
17
|
And then execute:
|
18
18
|
|
19
|
-
|
19
|
+
```sh
|
20
|
+
$ bundle
|
21
|
+
```
|
20
22
|
|
21
23
|
Or install it yourself as:
|
22
24
|
|
23
|
-
|
25
|
+
```sh
|
26
|
+
$ gem install receipts
|
27
|
+
```
|
24
28
|
|
25
29
|
## Usage
|
26
30
|
|
@@ -28,6 +32,7 @@ To generate a Receipt, Invoice, or Statement, create an instance and provide con
|
|
28
32
|
|
29
33
|
```ruby
|
30
34
|
r = Receipts::Receipt.new(
|
35
|
+
# title: "Receipt",
|
31
36
|
details: [
|
32
37
|
["Receipt Number", "123"],
|
33
38
|
["Date paid", Date.today],
|
@@ -102,6 +107,8 @@ You can pass the following options to generate a PDF:
|
|
102
107
|
logo: "https://www.ruby-lang.org/images/header-ruby-logo@2x.png" # Downloaded with OpenURI
|
103
108
|
```
|
104
109
|
|
110
|
+
* `display: []` - Customize the company details rendered. By default, renders `[:address, :phone, :email]` under the company name. Items in the array should be Symbols matching keys in the `company` hash to be displayed.
|
111
|
+
|
105
112
|
* `details` - Array of details about the Receipt, Invoice, Statement. Typically, this is receipt numbers, issue date, due date, status, etc.
|
106
113
|
|
107
114
|
* `line_items` - Array of line items to be displayed in table format.
|
@@ -123,14 +130,32 @@ Here's an example of where each option is displayed.
|
|
123
130
|
|
124
131
|

|
125
132
|
|
133
|
+
#### Line Items Table - Column Widths
|
134
|
+
|
135
|
+
You may set an option to configure the line items table's columns width in order to accommodate shortcomings of Prawn's width guessing ability to render header and content reasonably sized.
|
136
|
+
The configuration depends on your line item column count and follows the prawn/table configuration as documented [here](https://prawnpdf.org/prawn-table-manual.pdf):
|
137
|
+
|
138
|
+
This will size the second column to 400 and the fourth column to 50.
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
column_widths: {1 => 400,3 => 50 }
|
142
|
+
```
|
143
|
+
|
144
|
+
This will set all column widths, considering your table has 4 columns.
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
column_widths: [100, 200, 240]
|
148
|
+
```
|
149
|
+
|
150
|
+
If not set, it will fall back to Prawn's default behavior.
|
151
|
+
|
126
152
|
### Formatting
|
127
153
|
|
128
154
|
`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>`
|
129
155
|
|
130
|
-
See [the Prawn docs](https://prawnpdf.org/
|
156
|
+
See [the Prawn docs](https://prawnpdf.org/) for more information.
|
131
157
|
|
132
|
-
|
133
|
-
##### Page Size
|
158
|
+
#### Page Size
|
134
159
|
|
135
160
|
You can specify a different page size by passing in the `page_size` keyword argument:
|
136
161
|
|
@@ -215,7 +240,7 @@ class ChargesController < ApplicationController
|
|
215
240
|
@charge = current_user.charges.find(params[:id])
|
216
241
|
end
|
217
242
|
|
218
|
-
|
243
|
+
def send_pdf
|
219
244
|
# Render the PDF in memory and send as the response
|
220
245
|
send_data @charge.receipt.render,
|
221
246
|
filename: "#{@charge.created_at.strftime("%Y-%m-%d")}-gorails-receipt.pdf",
|
@@ -242,6 +267,7 @@ Invoices follow the exact same set of steps as above. You'll simply want to modi
|
|
242
267
|
|
243
268
|
```ruby
|
244
269
|
Receipts::Invoice.new(
|
270
|
+
# title: "Invoice",
|
245
271
|
details: [
|
246
272
|
["Invoice Number", "123"],
|
247
273
|
["Issue Date", Date.today.strftime("%B %d, %Y")],
|
@@ -278,6 +304,7 @@ Statements follow the exact same set of steps as above. You'll simply want to mo
|
|
278
304
|
|
279
305
|
```ruby
|
280
306
|
Receipts::Statement.new(
|
307
|
+
# title: "Statement",
|
281
308
|
details: [
|
282
309
|
["Statement Number", "123"],
|
283
310
|
["Issue Date", Date.today.strftime("%B %d, %Y")],
|
@@ -309,9 +336,8 @@ Receipts::Statement.new(
|
|
309
336
|
|
310
337
|
## Contributing
|
311
338
|
|
312
|
-
1. Fork it (
|
339
|
+
1. Fork it [https://github.com/excid3/receipts/fork](https://github.com/excid3/receipts/fork)
|
313
340
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
314
341
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
315
342
|
4. Push to the branch (`git push origin my-new-feature`)
|
316
343
|
5. Create a new Pull Request
|
317
|
-
|
data/Rakefile
CHANGED
@@ -36,7 +36,9 @@ task :receipt do
|
|
36
36
|
address: "123 Fake Street\nNew York City, NY 10012",
|
37
37
|
phone: "(555) 867-5309",
|
38
38
|
email: "support@example.com",
|
39
|
-
|
39
|
+
iban: "123456789",
|
40
|
+
logo: File.expand_path("./examples/images/logo.png"),
|
41
|
+
display: [:address, :phone, :email, nil, :iban]
|
40
42
|
},
|
41
43
|
details: [
|
42
44
|
["Receipt Number", "123"],
|
data/examples/invoice.pdf
CHANGED
Binary file
|
data/examples/receipt.pdf
CHANGED
Binary file
|
data/examples/statement.pdf
CHANGED
Binary file
|
data/lib/receipts/base.rb
CHANGED
@@ -7,7 +7,7 @@ module Receipts
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def initialize(attributes = {})
|
10
|
-
super
|
10
|
+
super(page_size: attributes.delete(:page_size) || "LETTER")
|
11
11
|
setup_fonts attributes.fetch(:font, Receipts.default_font)
|
12
12
|
|
13
13
|
@title = attributes.fetch(:title, self.class.title)
|
@@ -22,7 +22,10 @@ module Receipts
|
|
22
22
|
header company: company, height: attributes.fetch(:logo_height, 16)
|
23
23
|
render_details attributes.fetch(:details)
|
24
24
|
render_billing_details company: company, recipient: attributes.fetch(:recipient)
|
25
|
-
render_line_items
|
25
|
+
render_line_items(
|
26
|
+
line_items: attributes.fetch(:line_items),
|
27
|
+
column_widths: attributes[:column_widths]
|
28
|
+
)
|
26
29
|
render_footer attributes.fetch(:footer, default_message(company: company))
|
27
30
|
end
|
28
31
|
|
@@ -61,14 +64,11 @@ module Receipts
|
|
61
64
|
table(details, cell_style: {borders: [], inline_format: true, padding: [0, 8, 2, 0]})
|
62
65
|
end
|
63
66
|
|
64
|
-
def render_billing_details(company:, recipient:, margin_top: 16)
|
67
|
+
def render_billing_details(company:, recipient:, margin_top: 16, display_values: nil)
|
65
68
|
move_down margin_top
|
66
69
|
|
67
|
-
|
68
|
-
|
69
|
-
company[:phone],
|
70
|
-
company[:email]
|
71
|
-
].compact.join("\n")
|
70
|
+
display_values ||= company.fetch(:display, [:address, :phone, :email])
|
71
|
+
company_details = company.values_at(*display_values).compact.join("\n")
|
72
72
|
|
73
73
|
line_items = [
|
74
74
|
[
|
@@ -79,11 +79,18 @@ module Receipts
|
|
79
79
|
table(line_items, width: bounds.width, cell_style: {borders: [], inline_format: true, overflow: :expand})
|
80
80
|
end
|
81
81
|
|
82
|
-
def render_line_items(line_items
|
82
|
+
def render_line_items(line_items:, margin_top: 30, column_widths: nil)
|
83
83
|
move_down margin_top
|
84
84
|
|
85
85
|
borders = line_items.length - 2
|
86
|
-
|
86
|
+
|
87
|
+
table_options = {
|
88
|
+
width: bounds.width,
|
89
|
+
cell_style: {border_color: "eeeeee", inline_format: true},
|
90
|
+
column_widths: column_widths
|
91
|
+
}.compact
|
92
|
+
|
93
|
+
table(line_items, table_options) do
|
87
94
|
cells.padding = 6
|
88
95
|
cells.borders = []
|
89
96
|
row(0..borders).borders = [:bottom]
|
data/lib/receipts/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: receipts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
|
-
rubygems_version: 3.
|
93
|
+
rubygems_version: 3.5.4
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: Receipts for your Rails application that works with any payment provider.
|