write_invoice 0.1.81

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9d17ffa14ee1d6ebb33dd0eb85f54e1d033e4c1b184b926edd77755c13cc6e0b
4
+ data.tar.gz: 5e684d02938160f627e69e2294cd13c9e23206ec952fa798482513e55f3bf45b
5
+ SHA512:
6
+ metadata.gz: 2df6cacfd019e2b5512f09cdb891561395ae90e775f44e30c7fd1d4c01b5b82a4368a6cd76a5568e34b6571b2396fffe9eaf37e6a33d9b5db54241ec7b97f362
7
+ data.tar.gz: 266660213a3bc34154c7bc7de3b4a3191b4278ccf3a56834a86d77e07301942fb88383414ad8024d65bab79152a16c73a7d8bf54c74557d7a253c92324cfc324
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-12-05
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at andreasbanholzer@me.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in write_invoice.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 a6b8
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ <a href="#table-of-contents">
2
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/write-invoice-for-ruby/readme/headlines/write-invoice-for-ruby.svg" height="45px" name="headline" alt="# Invoice Builder for Ruby"><br>
3
+ </a>
4
+
5
+ `write_invoice` is a ruby gem to generate multiple invoices in one document.
6
+ <br>
7
+ <br>
8
+ <a href="#table-of-contents">
9
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/write-invoice-for-ruby/readme/headlines/documentation.svg" height="38px" name="Documentation" alt="documentation">
10
+
11
+ Visit: [docs.writeinvoice.com](https://docs.writeinvoice.com)
12
+ </a>
13
+ <br>
14
+ <br>
15
+ <a href="#headline">
16
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/write-invoice-for-ruby/readme/headlines/table-of-contents.svg" height="38px" name="table-of-contents" alt="Table of Contents">
17
+ </a>
18
+ <br>
19
+
20
+ 1. [Examples](#examples)<br>
21
+ 2. [Quickstart](#quickstart)<br>
22
+ 3. [Setup](#setup)<br>
23
+ 4. [String Modification](#string-modification)<br>
24
+ 5. [Contributing](#contributing)<br>
25
+ 6. [Limitations](#limitations)<br>
26
+ 7. [Credits](#credits)<br>
27
+ 8. [License](#license)<br>
28
+ 9. [Code of Conduct](#code-of-conduct)<br>
29
+ 10. [Support my Work](#support-my-work)<br>
30
+
31
+ <br>
32
+
33
+ <a href="#table-of-contents">
34
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/write-invoice-for-ruby/readme/headlines/quickstart.svg" height="38px" name="quickstart" alt="Quickstart">
35
+ </a>
36
+
37
+ ```ruby
38
+ require 'write_invoice'
39
+
40
+ pyld = WriteInvoice::Example.generate()
41
+ WriteInvoice::Document.generate( output: 'test.pdf', payload: pyld, options: {}, debug: true )
42
+ ```
43
+ <br>
44
+
45
+ <a href="#table-of-contents">
46
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/setup.svg" height="38px" name="setup" alt="Setup">
47
+ </a>
48
+
49
+ Add this line to your application's Gemfile:
50
+
51
+ ```ruby
52
+ gem 'write_invoice'
53
+ ```
54
+
55
+ And then execute:
56
+
57
+ $ bundle install
58
+
59
+ Or install it yourself as:
60
+
61
+ $ gem install write_invoice
62
+
63
+
64
+ On Rubygems:
65
+ - Gem: https://rubygems.org/gems/write_invoice
66
+ - Profile: https://rubygems.org/profiles/a6b8
67
+
68
+ <br>
69
+
70
+ <a href="#table-of-contents">
71
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/write-invoice-for-ruby/readme/headlines/contributing.svg" height="38px" name="contributing" alt="Contributing">
72
+ </a>
73
+
74
+ Bug reports and pull requests are welcome on GitHub at https://github.com/a6b8/write-invoice-for-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/a6b8/write-invoice-for-ruby/blob/master/CODE_OF_CONDUCT.md).
75
+
76
+ <br>
77
+
78
+ <a href="#table-of-contents">
79
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/write-invoice-for-ruby/readme/headlines/limitations.svg" height="38px" name="limitations" alt="Limitations">
80
+ </a>
81
+
82
+ - write_invoice
83
+
84
+ <br>
85
+
86
+ <a href="#table-of-contents">
87
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/write-invoice-for-ruby/readme/headlines/credits.svg" height="38px" name="credits" alt="Credits">
88
+ </a>
89
+
90
+ - write_invoice
91
+
92
+ <br>
93
+
94
+ <a href="#table-of-contents">
95
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/write-invoice-for-ruby/readme/headlines/license.svg" height="38px" name="license" alt="License">
96
+ </a>
97
+
98
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
99
+
100
+ <br>
101
+
102
+ <a href="#table-of-contents">
103
+ <img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/write-invoice-for-ruby/readme/headlines/code-of-conduct.svg" height="38px" name="code-of-conduct" alt="Code of Conduct">
104
+ </a>
105
+
106
+ Everyone interacting in the write-invoice-for-ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/a6b8/write-invoice-for-ruby/blob/master/CODE_OF_CONDUCT.md).
107
+
108
+ <br>
109
+
110
+ <a href="#table-of-contents">
111
+ <img href="#table-of-contents" src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/write-invoice-for-ruby/readme/headlines/support-my-work.svg" height="38px" name="support-my-work" alt="Support my Work">
112
+ </a>
113
+
114
+ Donate by [https://www.paypal.com](https://www.paypal.com/donate?hosted_button_id=XKYLQ9FBGC4RG)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "write_invoice"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,289 @@
1
+ module Dcmnt
2
+ private
3
+
4
+
5
+ def document( template, options, payloads, output, debug )
6
+ payloads = payloads.with_indifferent_access
7
+ opts = options_update( Marshal.load( Marshal.dump( options ) ), template, false )
8
+ obj = document_invoice_prepare( payloads[:invoices][ 0 ], opts )
9
+
10
+ Prawn::Font::AFM.hide_m17n_warning = true
11
+ pdf = Prawn::Document.new(
12
+ page_size: obj[:style][:document][:format],
13
+ info: {
14
+ Title: payloads[:document][:metadata][:title],
15
+ Author: payloads[:document][:metadata][:author],
16
+ Subject: payloads[:document][:metadata][:subject],
17
+ }
18
+ )
19
+
20
+ if !obj[:style][:font][:family].empty?
21
+ pdf.font_families.update( obj[:style][:font][:family] )
22
+ end
23
+
24
+ pdf.repeat :all do
25
+ pdf.bounding_box [ pdf.bounds.left, obj[:style][:footer][:height] ], width: pdf.bounds.width do
26
+ pdf = pdf_generate_footer( obj, pdf )
27
+ end
28
+ end
29
+
30
+ a = [ 0, pdf.bounds.height ]
31
+ b = pdf.bounds.width
32
+ c = pdf.bounds.height - obj[:style][:footer][:height] - 10
33
+
34
+ states = []
35
+ pdf.bounding_box( a, width: b, height: c ) do
36
+ payloads[:invoices].each.with_index do | payload, index |
37
+ debug ? print( "#{index} " ) : ''
38
+
39
+ states.push( {
40
+ id: payload[:meta][:id],
41
+ page: pdf.page_number,
42
+ headline: payload[:meta][:headline].to_s,
43
+ group: payload[:meta][:group].to_s
44
+ } )
45
+
46
+ opts = options_update( Marshal.load( Marshal.dump( options ) ), template, false )
47
+ obj = document_invoice_prepare( payload, opts )
48
+ pdf = document_invoice( obj, output, pdf )
49
+
50
+ if payloads[:invoices].length - 1 != index
51
+ pdf.start_new_page
52
+ end
53
+ end
54
+ end
55
+
56
+ pdf = watermark_pages_number( pdf, states, obj )
57
+ pdf = table_of_contents( states, pdf )
58
+ obj[:show][:watermark] ? pdf = watermark( pdf, obj ) : ''
59
+
60
+ if !obj[:show][:unencrypted]
61
+ if !payloads[:document][:encrypt].nil?
62
+ pdf.encrypt_document(
63
+ user_password: payloads[:document][:encrypt][:user_password],
64
+ owner_password: payloads[:document][:encrypt][:owner_password],
65
+ permissions: {
66
+ print_document: payloads[:document][:encrypt][:permissions][:print_document],
67
+ modify_contents: payloads[:document][:encrypt][:permissions][:modify_contents],
68
+ copy_contents: payloads[:document][:encrypt][:permissions][:copy_contents],
69
+ modify_annotations: payloads[:document][:encrypt][:permissions][:modify_annotations]
70
+ }
71
+ )
72
+ else
73
+ puts 'Payload: Error! Encrypt - Hash Block is missing. '
74
+ end
75
+ end
76
+
77
+ return pdf
78
+ end
79
+
80
+
81
+ def document_invoice( obj, output, pdf )
82
+ start = pdf.cursor
83
+ obj[:order].each do | order |
84
+ move = 0
85
+ order[:move_down].each do | a |
86
+ if a.class.to_s.eql?( 'Integer' )
87
+ move += a
88
+ else
89
+ keys = a.to_s.split( '__' ).map { | a | a.to_sym }
90
+ move += obj[ keys[ 0 ] ][ keys[ 1 ] ][ keys[ 2 ] ]
91
+ end
92
+ end
93
+
94
+ pdf.move_down( move )
95
+
96
+ case order[:name]
97
+ when :header
98
+ pdf = pdf_generate_header( obj, pdf )
99
+ when :two
100
+ pdf = pdf_generate_two( obj, pdf )
101
+ when :three
102
+ pdf = pdf_generate_three( obj, pdf )
103
+ when :four
104
+ pdf = pdf_generate_four( obj, pdf )
105
+ when :five
106
+ pdf = pdf_generate_five( obj, pdf )
107
+ when :six
108
+ pdf = pdf_generate_six( obj, pdf )
109
+ when :seven
110
+ pdf = pdf_generate_seven( obj, pdf )
111
+ when :eight
112
+ pdf = pdf_generate_eight( obj, pdf )
113
+ # when :nine
114
+ # pdf = pdf_generate_nine( obj, pdf )
115
+ end
116
+ end
117
+
118
+ return pdf
119
+ end
120
+
121
+
122
+ def document_invoice_prepare( payload, options )
123
+ alpha = 'a'.upto( 'z' ).to_a
124
+ payload = Marshal.load( Marshal.dump( payload ) )
125
+ options = Marshal.load( Marshal.dump( options ) )
126
+
127
+ messages = { footer: [] }
128
+
129
+ options[:sections].keys.each do | section |
130
+ options[:sections][ section ].keys.each do | key |
131
+ options[:sections][ section ][ key ][:content] = options[:sections][ section ][ key ][:struct].dup
132
+ options[:sections][ section ][ key ][:assigns].each.with_index do | assign, i |
133
+ prepare = {}
134
+ [ :value, :format ].each do | sym |
135
+ keys = assign[ sym ].to_s.split( '__' ).map { | a | a.to_sym }
136
+ keys[ 0 ].eql?( :payload ) ? data = payload : data = options
137
+ prepare[ sym ] = get_value( keys, data, true )
138
+ if sym.eql?( :format )
139
+ if keys.length != 0
140
+ prepare[ :type ] = keys[ 2 ]
141
+ else
142
+ prepare[ :type ] = nil
143
+ end
144
+ end
145
+ end
146
+
147
+ insert = get_format(
148
+ prepare[:type],
149
+ prepare[:value],
150
+ prepare[:format]
151
+ )
152
+
153
+ options[:sections][ section ][ key ][:content] =
154
+ options[:sections][ section ][ key ][:content]
155
+ .gsub!( "<<--#{alpha[ i ]}-->>", insert.to_s )
156
+ end
157
+ end
158
+ end
159
+
160
+ payload[:items].keys.each do | key |
161
+ if payload[:items][ key ].class.to_s.eql?( 'Array' )
162
+ payload[:items][ key ].each.with_index do | article, index |
163
+ [ :single, :total ].each do | k |
164
+ keys = options[:style][:articles][ k ][:format]
165
+ .to_s.split( '__' ).map { | a | a.to_sym }
166
+
167
+ params = get_value( keys, options, false )
168
+ str = get_format( keys[ 1 ], article[ k ], params )
169
+ payload[:items][ key ][ index ][ k ] = str
170
+ end
171
+ end
172
+ else
173
+ keys = options[:style][:articles][:total][:format]
174
+ .to_s.split( '__' )
175
+ .map { | a | a.to_sym }
176
+
177
+ params = get_value( keys, options, false )
178
+ str = get_format( keys[ 1 ], payload[:items][ key ], params )
179
+ payload[:items][ key ] = str
180
+ end
181
+ end
182
+
183
+ options[:items] = payload[:items]
184
+ options[:style][:document][:width] = options[:style][:articles]
185
+ .keys
186
+ .map { | key | options[:style][:articles][ key ][:width] }
187
+ .sum
188
+
189
+ return options
190
+ end
191
+
192
+
193
+ def watermark( pdf, obj )
194
+ pdf.create_stamp( 'watermark' ) do
195
+ struct = {
196
+ font_size: obj[:style][:watermark][:font_size],
197
+ text: {
198
+ str: obj[:text][:watermark],
199
+ width: nil
200
+ },
201
+ midpoint: {
202
+ x: pdf.bounds.width / 2,
203
+ y: pdf.bounds.height / 2
204
+ },
205
+ at: {
206
+ x: nil,
207
+ y: nil
208
+ }
209
+ }
210
+
211
+ pdf.font obj[:style][:watermark][:font_family]
212
+ struct[:text][:width] = pdf.font.compute_width_of( struct[:text][:str], size: struct[:font_size] )
213
+ struct[:at][:x] = struct[:midpoint][:x] - ( struct[:text][:width] / 2 )
214
+ struct[:at][:y] = struct[:midpoint][:y] + ( struct[:font_size] / 2 )
215
+
216
+ pdf.fill_color obj[:style][:watermark][:fill_color]
217
+ pdf.font_size( struct[:font_size] ) do
218
+ pdf.transparent( obj[:style][:watermark][:transparency] ) do
219
+ pdf.text_box(
220
+ struct[:text][:str],
221
+ at: [ struct[:at][:x], struct[:at][:y] ],
222
+ width: struct[:text][:width],
223
+ height: struct[:font_size],
224
+ rotate: obj[:style][:watermark][:rotate],
225
+ valign: :center,
226
+ halign: :center,
227
+ rotate_around: :center
228
+ )
229
+ end
230
+ end
231
+ end
232
+
233
+ pdf.repeat :all do
234
+ pdf.stamp_at 'watermark', [ 0, 0 ]
235
+ end
236
+
237
+ return pdf
238
+ end
239
+
240
+
241
+ def watermark_pages_number( pdf, states, obj )
242
+ tmp = states
243
+ .map.with_index { | state, index |
244
+ if !( index == states.length - 1 )
245
+ state[:page_count] = states[ index + 1 ][:page] - 1
246
+ else
247
+ state[:page_count] = pdf.page_count
248
+ end
249
+ state[:pages] = ( state[:page_count] - state[:page] ) + 1
250
+ state
251
+ }
252
+
253
+ b = tmp
254
+ .map { | aa | aa[:pages].times.map { | index | { id: aa[:id], page: index + 1, total: aa[:pages] } } }
255
+ .flatten
256
+ .map.with_index { | a, index | a[:index] = index; a }
257
+
258
+ b.each { | p | pdf_generate_nine( obj, pdf, p ) }
259
+
260
+ return pdf
261
+ end
262
+
263
+
264
+ def table_of_contents( states, pdf )
265
+ groups = states
266
+ .map { | a | a[:group] }
267
+ .to_set.to_a.sort
268
+ .inject( {} ) { | item, key |
269
+ item[ key ] = states
270
+ .select { | a | a[:group].eql?( key ) }
271
+ .sort_by { | a | a[:headline] }
272
+ item
273
+ }
274
+
275
+ pdf.outline.define do
276
+ groups.keys.each do | key |
277
+ group = groups[ key ]
278
+ section( key.to_s, destination: groups[ key ][ 0 ][:page]) do
279
+ group.each do | invoice |
280
+ pdf.outline.page( title: invoice[:headline], destination: invoice[:page])
281
+ end
282
+ end
283
+ end
284
+ end
285
+
286
+ return pdf
287
+ end
288
+
289
+ end