prawn_report 1.9.21 → 1.9.22

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.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/app/controllers/ac_filter_defs_controller.rb +16 -17
  3. data/app/controllers/custom_generate_report_controller.rb +18 -18
  4. data/app/controllers/generate_report_controller.rb +24 -24
  5. data/app/controllers/report_templates_controller.rb +40 -48
  6. data/app/models/ac_filter.rb +15 -15
  7. data/app/models/ac_filter_def.rb +38 -40
  8. data/app/models/ac_filter_option.rb +5 -5
  9. data/app/models/report_template.rb +22 -27
  10. data/lib/ac_filters_utils.rb +187 -189
  11. data/lib/active_record_helpers.rb +218 -219
  12. data/lib/bands/band.rb +23 -23
  13. data/lib/bands/footer_band.rb +7 -7
  14. data/lib/bands/header_band.rb +9 -9
  15. data/lib/bands/summary_band.rb +7 -7
  16. data/lib/custom_report_controller.rb +48 -60
  17. data/lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb +0 -1
  18. data/lib/prawn_report.rb +21 -21
  19. data/lib/prawn_report/version.rb +3 -0
  20. data/lib/prawn_report_seeds.rb +45 -59
  21. data/lib/report.rb +189 -195
  22. data/lib/report_helpers.rb +82 -83
  23. data/lib/report_info.rb +27 -27
  24. data/repo/bands/footers/footer_001.rb +20 -20
  25. data/repo/bands/headers/header_001.rb +61 -61
  26. data/repo/bands/headers/header_002.rb +31 -31
  27. data/repo/reports/column_group.rb +4 -3
  28. data/repo/reports/listing.rb +1 -59
  29. data/repo/reports/simple_listing.rb +130 -149
  30. metadata +58 -90
  31. data/app/serializers/ac_filter_def_serializer.rb +0 -10
  32. data/app/serializers/ac_filter_option_serializer.rb +0 -7
  33. data/app/serializers/ac_filter_serializer.rb +0 -9
  34. data/app/serializers/report_template_basic_serializer.rb +0 -4
  35. data/app/serializers/report_template_serializer.rb +0 -9
  36. data/lib/generators/prawn_report/install/templates/20140529153300_add_description_to_report_template.rb +0 -6
@@ -1,7 +1,7 @@
1
- module PrawnReport
2
-
3
- class FooterBand < Band
4
-
5
- end
6
-
7
- end
1
+ module PrawnReport
2
+
3
+ class FooterBand < Band
4
+
5
+ end
6
+
7
+ end
@@ -1,9 +1,9 @@
1
- module PrawnReport
2
-
3
- require File.expand_path(File.dirname(__FILE__) + "/band")
4
-
5
- class HeaderBand < Band
6
-
7
- end
8
-
9
- end
1
+ module PrawnReport
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/band")
4
+
5
+ class HeaderBand < Band
6
+
7
+ end
8
+
9
+ end
@@ -1,7 +1,7 @@
1
- module PrawnReport
2
-
3
- class SummaryBand < Band
4
-
5
- end
6
-
7
- end
1
+ module PrawnReport
2
+
3
+ class SummaryBand < Band
4
+
5
+ end
6
+
7
+ end
@@ -1,60 +1,48 @@
1
- #coding: utf-8
2
-
3
- module PrawnReportController
4
-
5
- def get_pr_report_data
6
- []
7
- end
8
-
9
- def get_pr_report_class
10
- @pr_report_class
11
- end
12
-
13
- def get_pr_suggested_filename; end
14
-
15
- def get_pr_report_params
16
- @pr_report_params || {}
17
- end
18
-
19
- def get_pr_serialization_params
20
- @serialization_params || {}
21
- end
22
-
23
- def get_pr_filters
24
- @filters
25
- end
26
-
27
- def index
28
- @filters = []
29
- rec = get_pr_report_data
30
- if rec.nil? || (rec.is_a?(Array) && rec.count == 0)
31
- cookies[:fileDownload] = true
32
- render :nothing => true, :status => :no_content
33
- else
34
- report_content = rec.pr_serialize(get_pr_serialization_params)
35
- report = get_pr_report_class.new(get_pr_report_params)
36
- report.report_params[:filters] = get_pr_filters
37
-
38
- fn = get_pr_suggested_filename
39
-
40
- respond_to do |format|
41
- format.pdf do
42
- cookies[:fileDownload] = true
43
- report_content = report.draw(report_content.get_yaml)
44
- if fn
45
- send_data(report_content, :filename => "#{fn}.pdf")
46
- else
47
- send_data(report_content, :disposition => 'inline', :type => 'application/pdf')
48
- end
49
- end
50
- format.csv do
51
- report_content = report.draw_csv(report_content.get_yaml)
52
- fn ||= "report"
53
- send_data(report_content, :filename => "#{fn}.csv")
54
- end
55
- end
56
-
57
- end
58
- end
59
-
60
- end
1
+ #coding: utf-8
2
+
3
+ module PrawnReportController
4
+
5
+ def get_pr_report_data
6
+ []
7
+ end
8
+
9
+ def get_pr_report_class
10
+ @pr_report_class
11
+ end
12
+
13
+ def get_pr_suggested_filename; end
14
+
15
+ def get_pr_report_params
16
+ @pr_report_params || {}
17
+ end
18
+
19
+ def get_pr_serialization_params
20
+ @serialization_params || {}
21
+ end
22
+
23
+ def get_pr_filters
24
+ @filters
25
+ end
26
+
27
+ def index
28
+ @filters = []
29
+ rec = get_pr_report_data
30
+ if rec.nil? || (rec.is_a?(Array) && rec.count == 0)
31
+ render :nothing => true, :status => :no_content
32
+ else
33
+ report_content = rec.pr_serialize(get_pr_serialization_params)
34
+ report = get_pr_report_class.new(get_pr_report_params)
35
+ report.report_params[:filters] = get_pr_filters
36
+ report_content = report.draw(report_content.get_yaml)
37
+
38
+ fn = get_pr_suggested_filename
39
+
40
+ if fn
41
+ send_data(report_content, :filename => fn)
42
+ else
43
+ send_data(report_content, :disposition => 'inline', :type => 'application/pdf')
44
+ end
45
+ end
46
+ end
47
+
48
+ end
@@ -7,4 +7,3 @@ class AddExcluirToReportTemplate < ActiveRecord::Migration
7
7
  remove_column :report_templates, :excluir
8
8
  end
9
9
  end
10
-
data/lib/prawn_report.rb CHANGED
@@ -1,21 +1,21 @@
1
- # coding: utf-8
2
-
3
-
4
- module PrawnReport
5
- mattr_accessor :parent_controller
6
- @@parent_controller = "CustomGenerateReportController"
7
- end
8
-
9
-
10
- require "report"
11
- require "bands/band"
12
- require "bands/summary_band"
13
- require "active_record_helpers"
14
- require "ac_filters_utils"
15
- require File.expand_path(File.dirname(__FILE__) + "/../repo/bands/headers/header_001.rb")
16
- require File.expand_path(File.dirname(__FILE__) + "/../repo/bands/footers/footer_001.rb")
17
- require File.expand_path(File.dirname(__FILE__) + "/../repo/reports/simple_listing.rb")
18
- require File.expand_path(File.dirname(__FILE__) + "/../repo/reports/column_group.rb")
19
-
20
- # Rails 3 compatibility
21
- require 'prawn_report/engine' if ((defined? Rails) and (Rails::version >= '3.0.0'))
1
+ # coding: utf-8
2
+
3
+
4
+ module PrawnReport
5
+ mattr_accessor :parent_controller
6
+ @@parent_controller = "CustomGenerateReportController"
7
+ end
8
+
9
+
10
+ require "report"
11
+ require "bands/band"
12
+ require "bands/summary_band"
13
+ require "active_record_helpers"
14
+ require "ac_filters_utils"
15
+ require File.expand_path(File.dirname(__FILE__) + "/../repo/bands/headers/header_001.rb")
16
+ require File.expand_path(File.dirname(__FILE__) + "/../repo/bands/footers/footer_001.rb")
17
+ require File.expand_path(File.dirname(__FILE__) + "/../repo/reports/simple_listing.rb")
18
+ require File.expand_path(File.dirname(__FILE__) + "/../repo/reports/column_group.rb")
19
+
20
+ # Rails 3 compatibility
21
+ require 'prawn_report/engine' if ((defined? Rails) and (Rails::version >= '3.0.0'))
@@ -0,0 +1,3 @@
1
+ module PrawnReport
2
+ VERSION = "0.1.0"
3
+ end
@@ -1,59 +1,45 @@
1
- # coding: utf-8
2
-
3
- require 'yaml'
4
-
5
-
6
- #ReportTemplate.delete_all
7
- # Ticket_id #52283 - seed não exlcui mais relatórios ja existentes.
8
- ReportTemplate.update_all({:ac_filter_def_id => nil, :excluir => true})
9
- AcFilterOption.delete_all
10
- AcFilter.delete_all
11
- AcFilterDef.delete_all
12
-
13
- puts "Iniciando importação dos filtros"
14
- Dir.glob("#{Rails.root}/db/filters/*.yml").each do |f|
15
- params = YAML::load(File.open(f, 'r'))
16
- AcFilterDef.create(params)
17
- puts "Criado filtro: " + params["name"]
18
- end
19
- puts "FIM"
20
-
21
- puts "Iniciando importação dos reports"
22
- Dir.glob("#{Rails.root}/db/reports/*.yml").each do |f|
23
- puts "Parsing file: #{f}"
24
- params = YAML::load(File.open(f, 'r'))
25
- # if params["filter_name"]
26
- # f = AcFilterDef.find_by_name(params.delete("filter_name"))
27
- # if f
28
- # params["ac_filter_def_id"] = f.id
29
- r = ReportTemplate.find_by_name(params["name"])
30
- if r.nil?
31
- if params["filter_name"]
32
- f = AcFilterDef.find_by_name(params.delete("filter_name"))
33
- if f
34
- params["ac_filter_def_id"] = f.id
35
- end
36
- end
37
- params["excluir"] = false
38
- ReportTemplate.create(params)
39
- puts "Criado relatório: " + params["name"]
40
- else
41
- if params["filter_name"]
42
- f = AcFilterDef.find_by_name(params.delete("filter_name"))
43
- if f
44
- params["ac_filter_def_id"] = f.id
45
- end
46
- end
47
- params["excluir"] = false
48
- r.update_attributes(params)
49
- puts "Atualizado relatório: " + params["name"]
50
- end
51
- end
52
- #ReportTemplate.create(params)
53
- #puts "Criado relatório: " + params["name"]
54
- end
55
- #puts "FIM"
56
- #ReportTemplate.delete_all(:excluir => true)
57
- ReportTemplate.destroy_all(:excluir => true)
58
- puts "finishing, closing, and going home"
59
-
1
+ # coding: utf-8
2
+
3
+ require 'yaml'
4
+
5
+ ReportTemplate.update_all({:ac_filter_def_id => nil, :excluir => true})
6
+ AcFilterOption.delete_all
7
+ AcFilter.delete_all
8
+ AcFilterDef.delete_all
9
+
10
+ puts "Iniciando importação dos filtros"
11
+ Dir.glob("#{Rails.root}/db/filters/*.yml").each do |f|
12
+ params = YAML::load(File.open(f, 'r'))
13
+ AcFilterDef.create(params)
14
+ puts "Criado filtro: " + params["name"]
15
+ end
16
+ puts "FIM"
17
+
18
+ puts "Iniciando importação dos reports"
19
+ Dir.glob("#{Rails.root}/db/reports/*.yml").each do |f|
20
+ params = YAML::load(File.open(f, 'r'))
21
+ r = ReportTemplate.find_by_name(params["name"])
22
+ if r.nil?
23
+ if params["filter_name"]
24
+ f = AcFilterDef.find_by_name(params.delete("filter_name"))
25
+ if f
26
+ params["ac_filter_def_id"] = f.id
27
+ end
28
+ end
29
+ params["excluir"] = false
30
+ ReportTemplate.create(params)
31
+ puts "Criado relatório: " + params["name"]
32
+ else
33
+ if params["filter_name"]
34
+ f = AcFilterDef.find_by_name(params.delete("filter_name"))
35
+ if f
36
+ params["ac_filter_def_id"] = f.id
37
+ end
38
+ end
39
+ params["excluir"] = false
40
+ r.update_attributes(params)
41
+ puts "Atualizado relatório: " + params["name"]
42
+ end
43
+ end
44
+ ReportTemplate.destroy_all(:excluir => true)
45
+ puts "finishing, closing, and going home"
data/lib/report.rb CHANGED
@@ -1,195 +1,189 @@
1
- #coding: utf-8
2
-
3
- require 'prawn'
4
-
5
- require File.expand_path(File.dirname(__FILE__) + "/report_helpers")
6
- require File.expand_path(File.dirname(__FILE__) + "/report_info")
7
-
8
- # This is the module for all classes in the prawn_report gem
9
- module PrawnReport
10
- unless defined? DEFAULT_REPORT_PARAMS
11
- DEFAULT_REPORT_PARAMS = {:page_size => 'A4', :margin => [20, 20, 20, 20],
12
- :page_layout => :portrait}
13
-
14
- LABEL_SIZE = 6
15
- TEXT_SIZE = 10
16
-
17
- SECTION_SPACING = LABEL_SIZE + 4
18
-
19
- LINE_WIDTH = 0.3
20
-
21
- DEFAULT_FONT = 'Times-Roman'
22
-
23
- TEXT_BOX_RADIUS = 2
24
- TEXT_BOX_HEIGTH = 20
25
- end
26
-
27
- # Report is the base class for all reports, it encapsulates all logic for rendering
28
- # report parts.
29
- class Report
30
- attr_reader :pdf, :data, :max_width, :max_height, :totals, :group_totals
31
- attr_accessor :header_class, :header_other_pages_class, :x, :report_params,
32
- :running_totals
33
-
34
- def initialize(report_params)
35
- @report_params = DEFAULT_REPORT_PARAMS.merge(report_params || {})
36
- @running_totals = @report_params.delete(:running_totals) || []
37
- @num_pages = 1
38
-
39
- @pdf = Prawn::Document.new(@report_params)
40
-
41
- @pdf.font(DEFAULT_FONT)
42
- @pdf.line_width = LINE_WIDTH
43
-
44
- if @report_params[:page_size].is_a?(String)
45
- if @report_params[:page_layout] == :portrait
46
- w, h = *Prawn::Document::PageGeometry::SIZES[@report_params[:page_size]]
47
- else
48
- h, w = *Prawn::Document::PageGeometry::SIZES[@report_params[:page_size]]
49
- end
50
- else
51
- w, h = @report_params[:page_size]
52
- end
53
- @x = 0
54
- @y = @max_height = h - (@report_params[:margin][0] + @report_params[:margin][2])
55
- @max_width = w - (@report_params[:margin][1] + @report_params[:margin][3])
56
-
57
- @footer_size = 0
58
- @pdf.move_cursor_to(max_height - @report_params[:margin][2])
59
-
60
- @header_class = @header_other_pages_class = @summary_band_class = @footer_class = nil
61
- @totals = {}
62
- @group_totals = {}
63
-
64
- initialize_running_totals
65
- end
66
-
67
- def params
68
- @report_params
69
- end
70
-
71
- def draw(data)
72
- @data = data
73
-
74
- before_draw
75
-
76
- draw_header_first_page
77
- draw_internal
78
- draw_summary
79
- draw_footer
80
-
81
- second_pass
82
-
83
- @pdf.close_and_stroke
84
- @pdf.render
85
- end
86
-
87
- def before_draw
88
- end
89
-
90
- def new_page(print_titles = true)
91
- draw_footer
92
-
93
- @num_pages += 1
94
- @pdf.start_new_page
95
- @x = 0
96
- @pdf.move_down(@report_params[:margin][0])
97
-
98
- draw_header_other_pages
99
- end
100
-
101
- def fill_color(color)
102
- @pdf.fill_color color
103
- @pdf.fill_rectangle [x,y], max_width, 15
104
- @pdf.fill_color '000000'
105
- end
106
-
107
- protected
108
-
109
- def draw_header_first_page
110
- draw_header(@header_class)
111
- end
112
-
113
- def draw_header_other_pages
114
- draw_header(@header_other_pages_class || @header_class)
115
- end
116
-
117
- def draw_header(klass)
118
- if klass
119
- header = klass.new(self)
120
- header.draw
121
- @pdf.y = @max_height - header.height
122
- @x = 0
123
- end
124
- end
125
-
126
- def draw_footer
127
- if @footer_class
128
- footer = @footer_class.new(self)
129
- @pdf.move_cursor_to(@footer_class.height)
130
- footer.draw
131
- end
132
- end
133
-
134
- def draw_summary
135
- if @summary_class
136
- summary = @summary_class.new(self)
137
- summary.draw
138
- end
139
- end
140
-
141
- def draw_group_summary
142
- if @report_params[:group] && @report_params[:group][:summary_class]
143
- summary = @report_params[:group][:summary_class].new(self)
144
- summary.draw
145
- end
146
- end
147
-
148
- def draw_group_header
149
- if @report_params[:group][:header_class]
150
- header = @report_params[:group][:header_class].new(self)
151
- header.draw
152
- end
153
- end
154
-
155
- def second_pass
156
-
157
- end
158
-
159
- def run_totals(data_row)
160
- @running_totals.each do |rt|
161
- vl = get_raw_field_value(data_row, rt)
162
- vl = (vl.is_a? (String) ? vl.to_f : vl)
163
- @totals[rt] = (@totals[rt] || 0) + (vl == '' ? 0 : vl)
164
- @group_totals[rt] = (@group_totals[rt] || 0) + (vl == '' ? 0 : vl)
165
- end
166
- end
167
-
168
- def initialize_running_totals
169
- @running_totals.each do |rt|
170
- @totals[rt] = 0
171
- @group_totals[rt] = 0
172
- end
173
- end
174
-
175
- def reset_group_totals
176
- @running_totals.each do |rt|
177
- @group_totals[rt] = 0
178
- end
179
- end
180
-
181
- def reset_totals
182
- @running_totals.each do |rt|
183
- @totals[rt] = 0
184
- end
185
- end
186
-
187
- def get_raw_field_value(row, column_name)
188
- c = row
189
- column_name.split('.').each {|n| c = c[n] if c}
190
- c.nil? ? '' : c
191
- end
192
-
193
- end
194
- end
195
-
1
+ #coding: utf-8
2
+
3
+ require 'prawn'
4
+
5
+ require File.expand_path(File.dirname(__FILE__) + "/report_helpers")
6
+ require File.expand_path(File.dirname(__FILE__) + "/report_info")
7
+
8
+ # This is the module for all classes in the prawn_report gem
9
+ module PrawnReport
10
+ unless defined? DEFAULT_REPORT_PARAMS
11
+ DEFAULT_REPORT_PARAMS = {:page_size => 'A4', :margin => [20, 20, 20, 20],
12
+ :page_layout => :portrait}
13
+
14
+ LABEL_SIZE = 6
15
+ TEXT_SIZE = 10
16
+
17
+ SECTION_SPACING = LABEL_SIZE + 4
18
+
19
+ LINE_WIDTH = 0.3
20
+
21
+ DEFAULT_FONT = 'Times-Roman'
22
+
23
+ TEXT_BOX_RADIUS = 2
24
+ TEXT_BOX_HEIGTH = 20
25
+ end
26
+
27
+ # Report is the base class for all reports, it encapsulates all logic for rendering
28
+ # report parts.
29
+ class Report
30
+ attr_reader :pdf, :data, :max_width, :max_height, :totals, :group_totals
31
+ attr_accessor :header_class, :header_other_pages_class, :x, :report_params,
32
+ :running_totals
33
+
34
+ def initialize(report_params)
35
+ @report_params = DEFAULT_REPORT_PARAMS.merge(report_params || {})
36
+ @running_totals = @report_params.delete(:running_totals) || []
37
+ @num_pages = 1
38
+
39
+ @pdf = Prawn::Document.new(@report_params)
40
+
41
+ @pdf.font(DEFAULT_FONT)
42
+ @pdf.line_width = LINE_WIDTH
43
+
44
+ if @report_params[:page_size].is_a?(String)
45
+ if @report_params[:page_layout] == :portrait
46
+ w, h = *Prawn::Document::PageGeometry::SIZES[@report_params[:page_size]]
47
+ else
48
+ h, w = *Prawn::Document::PageGeometry::SIZES[@report_params[:page_size]]
49
+ end
50
+ else
51
+ w, h = @report_params[:page_size]
52
+ end
53
+ @x = 0
54
+ @y = @max_height = h - (@report_params[:margin][0] + @report_params[:margin][2])
55
+ @max_width = w - (@report_params[:margin][1] + @report_params[:margin][3])
56
+
57
+ @footer_size = 0
58
+ @pdf.move_cursor_to(max_height - @report_params[:margin][2])
59
+
60
+ @header_class = @header_other_pages_class = @summary_band_class = @footer_class = nil
61
+ @totals = {}
62
+ @group_totals = {}
63
+
64
+ initialize_running_totals
65
+ end
66
+
67
+ def params
68
+ @report_params
69
+ end
70
+
71
+ def draw(data)
72
+ @data = data
73
+
74
+ draw_header_first_page
75
+ draw_internal
76
+ draw_summary
77
+ draw_footer
78
+
79
+ second_pass
80
+
81
+ @pdf.close_and_stroke
82
+ @pdf.render
83
+ end
84
+
85
+ def new_page(print_titles = true)
86
+ draw_footer
87
+
88
+ @num_pages += 1
89
+ @pdf.start_new_page
90
+ @x = 0
91
+ @pdf.move_down(@report_params[:margin][0])
92
+
93
+ draw_header_other_pages
94
+ end
95
+
96
+ def fill_color(color)
97
+ @pdf.fill_color color
98
+ @pdf.fill_rectangle [x,y], max_width, 15
99
+ @pdf.fill_color '000000'
100
+ end
101
+
102
+ protected
103
+
104
+ def draw_header_first_page
105
+ draw_header(@header_class)
106
+ end
107
+
108
+ def draw_header_other_pages
109
+ draw_header(@header_other_pages_class || @header_class)
110
+ end
111
+
112
+ def draw_header(klass)
113
+ if klass
114
+ header = klass.new(self)
115
+ header.draw
116
+ @pdf.y = @max_height - header.height
117
+ @x = 0
118
+ end
119
+ end
120
+
121
+ def draw_footer
122
+ if @footer_class
123
+ footer = @footer_class.new(self)
124
+ @pdf.move_cursor_to(@footer_class.height)
125
+ footer.draw
126
+ end
127
+ end
128
+
129
+ def draw_summary
130
+ if @summary_class
131
+ summary = @summary_class.new(self)
132
+ summary.draw
133
+ end
134
+ end
135
+
136
+ def draw_group_summary
137
+ if @report_params[:group] && @report_params[:group][:summary_class]
138
+ summary = @report_params[:group][:summary_class].new(self)
139
+ summary.draw
140
+ end
141
+ end
142
+
143
+ def draw_group_header
144
+ if @report_params[:group][:header_class]
145
+ header = @report_params[:group][:header_class].new(self)
146
+ header.draw
147
+ end
148
+ end
149
+
150
+ def second_pass
151
+
152
+ end
153
+
154
+ def run_totals(data_row)
155
+ @running_totals.each do |rt|
156
+ vl= get_raw_field_value(data_row,rt)
157
+ vl= (vl.is_a?(String) ? vl.to_f : vl)
158
+ @totals[rt] = (@totals[rt] || 0) + (vl == '' ? 0 : vl)
159
+ @group_totals[rt] = (@group_totals[rt] || 0) + (vl == '' ? 0 : vl)
160
+ end
161
+ end
162
+
163
+ def initialize_running_totals
164
+ @running_totals.each do |rt|
165
+ @totals[rt] = 0
166
+ @group_totals[rt] = 0
167
+ end
168
+ end
169
+
170
+ def reset_group_totals
171
+ @running_totals.each do |rt|
172
+ @group_totals[rt] = 0
173
+ end
174
+ end
175
+
176
+ def reset_totals
177
+ @running_totals.each do |rt|
178
+ @totals[rt] = 0
179
+ end
180
+ end
181
+
182
+ def get_raw_field_value(row, column_name)
183
+ c = row
184
+ column_name.split('.').each {|n| c = c[n] if c}
185
+ c.nil? ? '' : c
186
+ end
187
+
188
+ end
189
+ end