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.
- checksums.yaml +7 -0
- data/app/controllers/ac_filter_defs_controller.rb +16 -17
- data/app/controllers/custom_generate_report_controller.rb +18 -18
- data/app/controllers/generate_report_controller.rb +24 -24
- data/app/controllers/report_templates_controller.rb +40 -48
- data/app/models/ac_filter.rb +15 -15
- data/app/models/ac_filter_def.rb +38 -40
- data/app/models/ac_filter_option.rb +5 -5
- data/app/models/report_template.rb +22 -27
- data/lib/ac_filters_utils.rb +187 -189
- data/lib/active_record_helpers.rb +218 -219
- data/lib/bands/band.rb +23 -23
- data/lib/bands/footer_band.rb +7 -7
- data/lib/bands/header_band.rb +9 -9
- data/lib/bands/summary_band.rb +7 -7
- data/lib/custom_report_controller.rb +48 -60
- data/lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb +0 -1
- data/lib/prawn_report.rb +21 -21
- data/lib/prawn_report/version.rb +3 -0
- data/lib/prawn_report_seeds.rb +45 -59
- data/lib/report.rb +189 -195
- data/lib/report_helpers.rb +82 -83
- data/lib/report_info.rb +27 -27
- data/repo/bands/footers/footer_001.rb +20 -20
- data/repo/bands/headers/header_001.rb +61 -61
- data/repo/bands/headers/header_002.rb +31 -31
- data/repo/reports/column_group.rb +4 -3
- data/repo/reports/listing.rb +1 -59
- data/repo/reports/simple_listing.rb +130 -149
- metadata +58 -90
- data/app/serializers/ac_filter_def_serializer.rb +0 -10
- data/app/serializers/ac_filter_option_serializer.rb +0 -7
- data/app/serializers/ac_filter_serializer.rb +0 -9
- data/app/serializers/report_template_basic_serializer.rb +0 -4
- data/app/serializers/report_template_serializer.rb +0 -9
- data/lib/generators/prawn_report/install/templates/20140529153300_add_description_to_report_template.rb +0 -6
data/lib/report_helpers.rb
CHANGED
|
@@ -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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
tz
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
data
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|