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,83 +1,82 @@
1
- # coding: utf-8
2
-
3
- module PrawnReport
4
- class Report
5
-
6
- def box(width, height, options = {})
7
- @pdf.rounded_rectangle([0, y], width, height, TEXT_BOX_RADIUS)
8
- end
9
-
10
- def text_box_with_box(label, text, width, height = nil, options = {})
11
- @pdf.rounded_rectangle([@x, y], width, height || TEXT_BOX_HEIGTH, TEXT_BOX_RADIUS)
12
- @pdf.text_box(label, :size => LABEL_SIZE, :at => [@x + 2, y - 2], :width => width - 2,
13
- :height => LABEL_SIZE, :valign => :top)
14
- h_text = height.nil? ? TEXT_SIZE : height - LABEL_SIZE - 4
15
- @pdf.text_box(text || '', { :size => TEXT_SIZE, :at => [@x + 2, y - LABEL_SIZE - 4],
16
- :width => width - 2, :height => h_text, :valign => :top }.merge(options))
17
- @x += width
18
- end
19
-
20
- def text(text, width, options = {})
21
- font_size = options[:font_size] || TEXT_SIZE
22
- @pdf.text_box(text, :size => font_size, :style => options[:style], :at => [@x, y - 4],
23
- :width => width, :height => font_size,
24
- :valign => (options[:valign] || :top),
25
- :align => (options[:align] || :left)
26
- )
27
- @x = @x + width
28
- end
29
-
30
- def horizontal_line(x_ini = 0, x_end = @max_width)
31
- @pdf.stroke do
32
- @pdf.horizontal_line(x_ini, x_end, :at => y)
33
- end
34
- end
35
-
36
- def y
37
- @pdf.y
38
- end
39
-
40
- def y=(y)
41
- @pdf.y = y
42
- end
43
-
44
- def space(width)
45
- @x += width
46
- end
47
-
48
- def line_break(size = TEXT_SIZE)
49
- @x = 0
50
- @pdf.move_down(@pdf.height_of('A', :size => size) + 2)
51
- end
52
-
53
- def format(value, formatter, options = {})
54
- if !value.nil? && value != ''
55
- if (formatter == :currency)
56
- value = value.round(2) rescue sprintf('%.2f', value).to_f
57
- if value < 0
58
- '-'+((value.to_i*-1).to_s.reverse.gsub(/...(?=.)/,'\&.').reverse) + ',' + ('%02d' % ((value.abs * 100).round % 100))
59
- else
60
- (value.to_i.to_s.reverse.gsub(/...(?=.)/,'\&.').reverse) + ',' + ('%02d' % ((value * 100).round % 100))
61
- end
62
- elsif (formatter == :date)
63
- value.to_time.strftime('%d/%m/%Y')
64
- elsif (formatter == :timezone_date)
65
- tz = Time.zone.parse(value)
66
- tz.nil? ? '' : tz.strftime('%d/%m/%Y')
67
- elsif (formatter == :function)
68
- send(options[:formatter_function].to_s, value)
69
- else
70
- value.to_s
71
- end
72
- else
73
- ''
74
- end
75
- end
76
-
77
- def draw_graph(g, params)
78
- data = StringIO.new(g.to_blob)
79
- @pdf.image(data, params)
80
- end
81
-
82
- end
83
- end
1
+ # coding: utf-8
2
+
3
+ module PrawnReport
4
+ class Report
5
+
6
+ def box(width, height, options = {})
7
+ @pdf.rounded_rectangle([0, y], width, height, TEXT_BOX_RADIUS)
8
+ end
9
+
10
+ def text_box_with_box(label, text, width, height = nil, options = {})
11
+ @pdf.rounded_rectangle([@x, y], width, height || TEXT_BOX_HEIGTH, TEXT_BOX_RADIUS)
12
+ @pdf.text_box(label, :size => LABEL_SIZE, :at => [@x + 2, y - 2], :width => width - 2,
13
+ :height => LABEL_SIZE, :valign => :top)
14
+ h_text = height.nil? ? TEXT_SIZE : height - LABEL_SIZE - 4
15
+ @pdf.text_box(text.to_s.toutf8 || '', { :size => TEXT_SIZE, :at => [@x + 2, y - LABEL_SIZE - 4],
16
+ :width => width - 2, :height => h_text, :valign => :top }.merge(options))
17
+ @x += width
18
+ end
19
+
20
+ def text(text, width, options = {})
21
+ font_size = options[:font_size] || TEXT_SIZE
22
+ @pdf.text_box(text.to_s.toutf8, :size => font_size, :style => options[:style], :at => [@x, y - 4],
23
+ :width => width, :height => font_size,
24
+ :valign => (options[:valign] || :top),
25
+ :align => (options[:align] || :left)
26
+ )
27
+ @x = @x + width
28
+ end
29
+
30
+ def horizontal_line(x_ini = 0, x_end = @max_width)
31
+ @pdf.stroke do
32
+ @pdf.horizontal_line(x_ini, x_end, :at => y)
33
+ end
34
+ end
35
+
36
+ def y
37
+ @pdf.y
38
+ end
39
+
40
+ def y=(y)
41
+ @pdf.y = y
42
+ end
43
+
44
+ def space(width)
45
+ @x += width
46
+ end
47
+
48
+ def line_break(size = TEXT_SIZE)
49
+ @x = 0
50
+ @pdf.move_down(@pdf.height_of('A', :size => size) + 2)
51
+ end
52
+
53
+ def format(value, formatter, options = {})
54
+ if !value.nil? && value != ''
55
+ if (formatter == :currency)
56
+ if value < 0
57
+ '-'+((value.to_i*-1).to_s.reverse.gsub(/...(?=.)/,'\&.').reverse) + ',' + ('%02d' % ((value.abs * 100).round % 100))
58
+ else
59
+ (value.to_i.to_s.reverse.gsub(/...(?=.)/,'\&.').reverse) + ',' + ('%02d' % ((value * 100).round % 100))
60
+ end
61
+ elsif (formatter == :date)
62
+ value.to_time.strftime('%d/%m/%Y')
63
+ elsif (formatter == :timezone_date)
64
+ tz = Time.zone.parse(value)
65
+ tz.nil? ? '' : tz.strftime('%d/%m/%Y')
66
+ elsif (formatter == :function)
67
+ send(options[:formatter_function].to_s, value)
68
+ else
69
+ value.to_s
70
+ end
71
+ else
72
+ ''
73
+ end
74
+ end
75
+
76
+ def draw_graph(g, params)
77
+ data = StringIO.new(g.to_blob)
78
+ @pdf.image(data, params)
79
+ end
80
+
81
+ end
82
+ end
data/lib/report_info.rb CHANGED
@@ -1,27 +1,27 @@
1
- # coding: utf-8
2
-
3
- require 'date'
4
-
5
- module PrawnReport
6
- class Report
7
-
8
- attr_accessor :force_today_as
9
-
10
- def fits?(h)
11
- (y - footer_size - h - @report_params[:margin][2]) >= 0
12
- end
13
-
14
- def header_size
15
- @header ? @header_class.height : 0
16
- end
17
-
18
- def footer_size
19
- @footer_class ? @footer_class.height : 0
20
- end
21
-
22
- def today
23
- @force_today_as ? @force_today_as : Date.today
24
- end
25
-
26
- end
27
- end
1
+ # coding: utf-8
2
+
3
+ require 'date'
4
+
5
+ module PrawnReport
6
+ class Report
7
+
8
+ attr_accessor :force_today_as
9
+
10
+ def fits?(h)
11
+ (y - footer_size - h - @report_params[:margin][2]) >= 0
12
+ end
13
+
14
+ def header_size
15
+ @header ? @header_class.height : 0
16
+ end
17
+
18
+ def footer_size
19
+ @footer_class ? @footer_class.height : 0
20
+ end
21
+
22
+ def today
23
+ @force_today_as ? @force_today_as : Date.today
24
+ end
25
+
26
+ end
27
+ end
@@ -1,20 +1,20 @@
1
- #coding: utf-8
2
-
3
- require File.expand_path(File.dirname(__FILE__) + "/../../../lib/bands/footer_band")
4
-
5
- module PrawnReport
6
-
7
- class Footer001 < FooterBand
8
-
9
- def internal_draw
10
- report.horizontal_line
11
- report.x = 0
12
- end
13
-
14
- def self.height
15
- 10
16
- end
17
-
18
- end
19
-
20
- end
1
+ #coding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../../../lib/bands/footer_band")
4
+
5
+ module PrawnReport
6
+
7
+ class Footer001 < FooterBand
8
+
9
+ def internal_draw
10
+ report.horizontal_line
11
+ report.x = 0
12
+ end
13
+
14
+ def self.height
15
+ 10
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -1,61 +1,61 @@
1
- #coding: utf-8
2
-
3
- require File.expand_path(File.dirname(__FILE__) + "/../../../lib/bands/header_band")
4
-
5
- module PrawnReport
6
-
7
- #This header renders:
8
- #
9
- #* Company name based on a property at the root of data named +company_name+ left aligned
10
- # font size 16.
11
- #* Data de emissão dated today right aligned font size 12
12
- #* Report name based on a parameter named +report_name+ setted in the report
13
- #* A list of filters read from *report.params[:filters]*. Each filter is printed in one
14
- # line. *params[:filters]* must be an array of arrays where the inner arrays must be
15
- # tuples of two elements, the first one being the title and second one being the value of the
16
- # filter. If value is present the title is concatenated with ':'
17
- class Header001 < HeaderBand
18
-
19
- def initialize(report, params = {})
20
- super(report, params)
21
- @filter_size = 0
22
- end
23
-
24
- def internal_draw
25
- report.text(report.data['company_name'], 300, :style => :bold, :font_size => 16)
26
- txt_emissao = 'Data de emissão: ' + report.today.strftime('%d/%m/%Y')
27
- length = report.pdf.width_of(txt_emissao, :size => 12)
28
- report.x = report.max_width - length
29
- report.text(txt_emissao, length, :font_size => 12,
30
- :valign => :bottom, :align => :right)
31
- report.line_break(16)
32
- report.text(report.params[:report_name], report.max_width, :font_size => 13,
33
- :align => :center)
34
- report.line_break(13)
35
- draw_filters if report.params[:filters]
36
- report.horizontal_line
37
- end
38
-
39
- def draw_filters
40
- report.params[:filters].each do |param|
41
- title = param[0]
42
- if param[1].to_s != ''
43
- title = title + ':'
44
- end
45
- report.text(title, 2 + report.pdf.width_of(title, :size => 10), :font_size => 10)
46
- report.text(param[1], 2 + report.pdf.width_of(param[1], :size => 10), :font_size => 10)
47
- report.x = 0
48
- size = report.pdf.height_of(param[1], :size => 10)
49
- size = 10 if size < 10
50
- report.pdf.move_down(size + 2)
51
- @filter_size += size + 2
52
- end
53
- end
54
-
55
- def height
56
- 45 + @filter_size
57
- end
58
-
59
- end
60
-
61
- end
1
+ #coding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../../../lib/bands/header_band")
4
+
5
+ module PrawnReport
6
+
7
+ #This header renders:
8
+ #
9
+ #* Company name based on a property at the root of data named +company_name+ left aligned
10
+ # font size 16.
11
+ #* Data de emissão dated today right aligned font size 12
12
+ #* Report name based on a parameter named +report_name+ setted in the report
13
+ #* A list of filters read from *report.params[:filters]*. Each filter is printed in one
14
+ # line. *params[:filters]* must be an array of arrays where the inner arrays must be
15
+ # tuples of two elements, the first one being the title and second one being the value of the
16
+ # filter. If value is present the title is concatenated with ':'
17
+ class Header001 < HeaderBand
18
+
19
+ def initialize(report, params = {})
20
+ super(report, params)
21
+ @filter_size = 0
22
+ end
23
+
24
+ def internal_draw
25
+ report.text(report.data['company_name'], 300, :style => :bold, :font_size => 16)
26
+ txt_emissao = 'Data de emissão: ' + report.today.strftime('%d/%m/%Y')
27
+ length = report.pdf.width_of(txt_emissao, :size => 12)
28
+ report.x = report.max_width - length
29
+ report.text(txt_emissao, length, :font_size => 12,
30
+ :valign => :bottom, :align => :right)
31
+ report.line_break(16)
32
+ report.text(report.params[:report_name], report.max_width, :font_size => 13,
33
+ :align => :center)
34
+ report.line_break(13)
35
+ draw_filters if report.params[:filters]
36
+ report.horizontal_line
37
+ end
38
+
39
+ def draw_filters
40
+ report.params[:filters].each do |param|
41
+ title = param[0]
42
+ if param[1].to_s != ''
43
+ title = title + ':'
44
+ end
45
+ report.text(title, 2 + report.pdf.width_of(title, :size => 10), :font_size => 10)
46
+ report.text(param[1], 2 + report.pdf.width_of(param[1], :size => 10), :font_size => 10)
47
+ report.x = 0
48
+ size = report.pdf.height_of(param[1], :size => 10)
49
+ size = 10 if size < 10
50
+ report.pdf.move_down(size + 2)
51
+ @filter_size += size + 2
52
+ end
53
+ end
54
+
55
+ def height
56
+ 45 + @filter_size
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -1,31 +1,31 @@
1
- #coding: utf-8
2
-
3
- require File.expand_path(File.dirname(__FILE__) + "/../../../lib/bands/header_band")
4
-
5
- module PrawnReport
6
- #This is a minimalist header intended to render the company name and report name in additional
7
- #pages of a report.
8
- #
9
- #This header renders:
10
- #
11
- #* Company name based on a property at the root of data named +company_name+ left aligned
12
- # font size 12.
13
- #* Report name based on a parameter named +report_name+ setted in the report
14
- class Header002 < HeaderBand
15
-
16
- def internal_draw
17
- report.x = 0
18
- report.text(report.data['company_name'], 300, :font_size => 12)
19
- report.x = 0
20
- report.text(report.params[:report_name], report.max_width, :font_size => 12, :align => :right)
21
- report.line_break(12)
22
- report.horizontal_line
23
- end
24
-
25
- def height
26
- 20
27
- end
28
-
29
- end
30
-
31
- end
1
+ #coding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../../../lib/bands/header_band")
4
+
5
+ module PrawnReport
6
+ #This is a minimalist header intended to render the company name and report name in additional
7
+ #pages of a report.
8
+ #
9
+ #This header renders:
10
+ #
11
+ #* Company name based on a property at the root of data named +company_name+ left aligned
12
+ # font size 12.
13
+ #* Report name based on a parameter named +report_name+ setted in the report
14
+ class Header002 < HeaderBand
15
+
16
+ def internal_draw
17
+ report.x = 0
18
+ report.text(report.data['company_name'], 300, :font_size => 12)
19
+ report.x = 0
20
+ report.text(report.params[:report_name], report.max_width, :font_size => 12, :align => :right)
21
+ report.line_break(12)
22
+ report.horizontal_line
23
+ end
24
+
25
+ def height
26
+ 20
27
+ end
28
+
29
+ end
30
+
31
+ end