prawn_report 1.9.18
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 +17 -0
- data/app/controllers/custom_generate_report_controller.rb +18 -0
- data/app/controllers/generate_report_controller.rb +24 -0
- data/app/controllers/report_templates_controller.rb +40 -0
- data/app/models/ac_filter.rb +15 -0
- data/app/models/ac_filter_def.rb +38 -0
- data/app/models/ac_filter_option.rb +5 -0
- data/app/models/report_template.rb +22 -0
- data/lib/ac_filters_utils.rb +187 -0
- data/lib/active_record_helpers.rb +218 -0
- data/lib/bands/band.rb +23 -0
- data/lib/bands/footer_band.rb +7 -0
- data/lib/bands/header_band.rb +9 -0
- data/lib/bands/summary_band.rb +7 -0
- data/lib/custom_report_controller.rb +48 -0
- data/lib/generators/prawn_report/install/install_generator.rb +16 -0
- data/lib/generators/prawn_report/install/templates/20120108210141_create_prawn_report_catalogs.rb +14 -0
- data/lib/generators/prawn_report/install/templates/20120124012653_add_filter_defs.rb +35 -0
- data/lib/generators/prawn_report/install/templates/20120209231821_add_filters_to_reports.rb +13 -0
- data/lib/generators/prawn_report/install/templates/20120222021437_add_order_to_filter_def.rb +9 -0
- data/lib/generators/prawn_report/install/templates/20120222025632_add_select_sql.rb +9 -0
- data/lib/generators/prawn_report/install/templates/20120222030526_create_ac_filter_joins.rb +12 -0
- data/lib/generators/prawn_report/install/templates/20120222122507_add_serialization_params_to_report.rb +9 -0
- data/lib/generators/prawn_report/install/templates/20120222134101_create_ac_filter_includes.rb +12 -0
- data/lib/generators/prawn_report/install/templates/20120222150029_change_includes_and_joins_to_hash.rb +21 -0
- data/lib/generators/prawn_report/install/templates/20120229134810_add_group_to_filter_def.rb +9 -0
- data/lib/generators/prawn_report/install/templates/20120229194434_add_system_criteria_to_ac_filter.rb +9 -0
- data/lib/generators/prawn_report/install/templates/20120301063031_change_select_sql.rb +11 -0
- data/lib/generators/prawn_report/install/templates/20120303104431_change_filled_criteria_unfilled_criteria.rb +15 -0
- data/lib/generators/prawn_report/install/templates/20120316162712_add_filled_criteria_to_options.rb +9 -0
- data/lib/generators/prawn_report/install/templates/20120323124446_add_fields_to_filter.rb +17 -0
- data/lib/generators/prawn_report/install/templates/20130122101313_add_sql_query_to_ac_filter_def.rb +5 -0
- data/lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb +9 -0
- data/lib/prawn_report.rb +21 -0
- data/lib/prawn_report/engine.rb +9 -0
- data/lib/prawn_report/version.rb +3 -0
- data/lib/prawn_report_seeds.rb +46 -0
- data/lib/report.rb +190 -0
- data/lib/report_helpers.rb +82 -0
- data/lib/report_info.rb +27 -0
- data/repo/bands/footers/footer_001.rb +20 -0
- data/repo/bands/headers/header_001.rb +61 -0
- data/repo/bands/headers/header_002.rb +31 -0
- data/repo/reports/column_group.rb +58 -0
- data/repo/reports/listing.rb +144 -0
- data/repo/reports/simple_listing.rb +130 -0
- metadata +93 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../lib/report.rb")
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + "/../bands/headers/header_001.rb")
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + "/../bands/headers/header_002.rb")
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + "/../bands/footers/footer_001.rb")
|
7
|
+
|
8
|
+
module PrawnReport
|
9
|
+
class Listing < Report
|
10
|
+
|
11
|
+
alias :super_new_page :new_page
|
12
|
+
|
13
|
+
def initialize(report_params = {})
|
14
|
+
super(report_params)
|
15
|
+
@header_class = PrawnReport::Header001
|
16
|
+
@header_other_pages_class = PrawnReport::Header002
|
17
|
+
@footer_class = PrawnReport::Footer001
|
18
|
+
@filling_colors = ['cccccc', 'ffffff'].cycle
|
19
|
+
@current_row = nil
|
20
|
+
@printing_internal = false
|
21
|
+
@data_end = false
|
22
|
+
@detail_name = @report_params[:detail_name] || 'items'
|
23
|
+
end
|
24
|
+
|
25
|
+
#Override line_height to calculate the proper line height for the record
|
26
|
+
#The current record can be accessed via the property @current_row
|
27
|
+
def line_height
|
28
|
+
15
|
29
|
+
end
|
30
|
+
|
31
|
+
def before_draw_lines
|
32
|
+
@printing_internal = true
|
33
|
+
@data_end = false
|
34
|
+
end
|
35
|
+
|
36
|
+
def after_draw_lines
|
37
|
+
@data_end = true
|
38
|
+
@printing_internal = false
|
39
|
+
end
|
40
|
+
|
41
|
+
def before_render_line
|
42
|
+
new_page unless fits?(line_height)
|
43
|
+
@x = 0
|
44
|
+
end
|
45
|
+
|
46
|
+
def after_render_line
|
47
|
+
line_break(line_height-4)
|
48
|
+
run_totals(@current_row)
|
49
|
+
end
|
50
|
+
|
51
|
+
def draw_lines
|
52
|
+
@data[@detail_name].each do |row|
|
53
|
+
@current_row = row
|
54
|
+
before_render_line
|
55
|
+
render_line(@current_row)
|
56
|
+
after_render_line
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def draw_internal
|
61
|
+
before_draw_lines if defined? before_draw_lines
|
62
|
+
draw_lines if defined? 'draw_lines'
|
63
|
+
after_draw_lines if defined? after_draw_lines
|
64
|
+
end
|
65
|
+
|
66
|
+
def render_line(row)
|
67
|
+
@pdf.fill_color @filling_colors.next
|
68
|
+
@pdf.fill_rectangle [x,y], max_width, line_height
|
69
|
+
@pdf.fill_color '000000'
|
70
|
+
|
71
|
+
if @report_params[:field]
|
72
|
+
render_one_column_line(row)
|
73
|
+
elsif @report_params[:columns]
|
74
|
+
render_multi_column_line(row)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def render_one_column_title
|
79
|
+
if @report_params[:title]
|
80
|
+
text(@report_params[:title], @max_width, :font_size => 12, :style => :bold)
|
81
|
+
line_break(13)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def render_multi_column_title
|
86
|
+
@report_params[:columns].each do |c|
|
87
|
+
unless c[:formatter] == :invisible
|
88
|
+
width = c[:width] || 60
|
89
|
+
align = c[:align] || :left
|
90
|
+
text(c[:title].to_s, width, :font_size => c[:font_size] || 12, :style => :bold, :align => align)
|
91
|
+
space(3)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
line_break(13)
|
95
|
+
end
|
96
|
+
|
97
|
+
def render_one_column_line(row)
|
98
|
+
text(row[@report_params[:field]], 100, :font_size => 12)
|
99
|
+
end
|
100
|
+
|
101
|
+
def render_multi_column_line(row)
|
102
|
+
@report_params[:columns].each do |c|
|
103
|
+
unless c[:formatter] == :invisible
|
104
|
+
width = c[:width] || 60
|
105
|
+
formatter = c[:formatter] || :none
|
106
|
+
raw_value = get_raw_field_value(row, c[:name].to_s)
|
107
|
+
formatter_options = build_formatter_options(formatter, c)
|
108
|
+
formatted_text = format(raw_value, formatter, formatter_options)
|
109
|
+
align = c[:align] || :left
|
110
|
+
font_size = c[:font_size] || 12
|
111
|
+
text(formatted_text, width, :font_size => font_size, :align => align)
|
112
|
+
space(3)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
#This function will build the options to be passed to the specific formatter
|
118
|
+
def build_formatter_options(formatter, column_def)
|
119
|
+
r = {}
|
120
|
+
if formatter == :function
|
121
|
+
r[:formatter_function] = column_def[:formatter_function]
|
122
|
+
end
|
123
|
+
r
|
124
|
+
end
|
125
|
+
|
126
|
+
def second_pass
|
127
|
+
1.upto(@num_pages) do |i|
|
128
|
+
@pdf.go_to_page(i)
|
129
|
+
@pdf.move_cursor_to(10)
|
130
|
+
@x = 0
|
131
|
+
text("Página #{@pdf.page_number}/#{@pdf.page_count}", @max_width, :align => :right)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def draw_column_titles
|
136
|
+
new_page(false) unless fits?(30)
|
137
|
+
if @report_params[:field]
|
138
|
+
render_one_column_title
|
139
|
+
elsif @report_params[:columns]
|
140
|
+
render_multi_column_title
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/listing.rb")
|
4
|
+
|
5
|
+
module PrawnReport
|
6
|
+
#Generates a listing report with or without multiple columns.
|
7
|
+
#
|
8
|
+
#==Creating a SimpleListing Report
|
9
|
+
#To create a simple listing report you must inherit from PrawnReport::SimpleListing class
|
10
|
+
#and fill some parameters. The +report_name+ parameter is mandatory. The other parameters depends
|
11
|
+
#if you want a single or multi column listing.
|
12
|
+
#
|
13
|
+
#The parameters are filled setting the instance variable +params+ hash in initialize after calling
|
14
|
+
#super.
|
15
|
+
#
|
16
|
+
#==Single column listing
|
17
|
+
#For single column listings you must fill the +field+ parameter and, optionally, the +title+
|
18
|
+
#parameter. Like the code bellow
|
19
|
+
# class ProductTypeListing < PrawnReport::SimpleListing
|
20
|
+
# def initialize
|
21
|
+
# super
|
22
|
+
# @report_params = {
|
23
|
+
# :report_name => 'Product Type Listing',
|
24
|
+
# :field => 'name',
|
25
|
+
# :title => 'Name'
|
26
|
+
# }
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
#==Multiple column listing
|
31
|
+
#To have a multiple column listing you must fill the +columns+ hash inside +params+ hash. Each column
|
32
|
+
#has the following properties:
|
33
|
+
#* +name+: The name of the field
|
34
|
+
#* +title+: The title to be rendered above the first row
|
35
|
+
#* +width+: The width of the column. Default value is 60
|
36
|
+
#
|
37
|
+
#The code belloow shows a listing of people with 3 columns
|
38
|
+
#
|
39
|
+
# class PeopleListing < PrawnReport::SimpleListing
|
40
|
+
# def initialize
|
41
|
+
# super
|
42
|
+
# @report_params = {
|
43
|
+
# :report_name => 'People Listing',
|
44
|
+
# :columns => [
|
45
|
+
# {:name => 'name', :title => 'Name', :width => 200},
|
46
|
+
# {:name => 'age', :title => 'Age', :width => 30},
|
47
|
+
# {:name => 'phone_number', :title => 'Phone #', :width => 100}
|
48
|
+
# ]
|
49
|
+
# }
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
#==Default behaviour
|
54
|
+
#The listing bellow shows the default behaviour of this class. This is not changeable at this
|
55
|
+
#momment. Any of this behaviour can become changeable in future versions of this gem.
|
56
|
+
#
|
57
|
+
#* Font: size 12. normal. Times-Roman
|
58
|
+
#* Row background color: Alternate between white and gray (cccccc)
|
59
|
+
#* First page Header class: PrawnReport::Header001
|
60
|
+
#* Other pages Header class: PrawnReport::Header002
|
61
|
+
#* Footer class: PrawnReport::Footer001
|
62
|
+
|
63
|
+
|
64
|
+
class SimpleListing < Listing
|
65
|
+
|
66
|
+
attr_reader :grouping_info
|
67
|
+
|
68
|
+
def initialize(report_params = {})
|
69
|
+
super(report_params)
|
70
|
+
@grouping_info = {:last_group_value => nil,
|
71
|
+
:groups_running => false}
|
72
|
+
end
|
73
|
+
|
74
|
+
def new_page(print_titles = true)
|
75
|
+
super(print_titles)
|
76
|
+
draw_group_header if grouped? and @report_params[:group][:header_reprint_new_page] and !last_group_summary?
|
77
|
+
if print_titles
|
78
|
+
draw_column_titles unless (!draw_group_column_titles? && !@printing_internal) || last_group_summary?
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
|
84
|
+
def run_groups(row)
|
85
|
+
group_value = get_raw_field_value(row, params[:group][:field])
|
86
|
+
start_new_group = !@grouping_info[:groups_running]
|
87
|
+
start_new_group |= group_value != @grouping_info[:last_group_value]
|
88
|
+
if start_new_group
|
89
|
+
if(@grouping_info[:groups_running] &&
|
90
|
+
@grouping_info[:last_group_value] != group_value)
|
91
|
+
draw_group_summary
|
92
|
+
new_page(false) if params[:group][:new_page]
|
93
|
+
end
|
94
|
+
@grouping_info[:last_group_value] = group_value
|
95
|
+
@grouping_info[:groups_running] = true
|
96
|
+
draw_group_header
|
97
|
+
draw_column_titles if draw_group_column_titles?
|
98
|
+
reset_group_totals
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def grouped?
|
103
|
+
params[:group]
|
104
|
+
end
|
105
|
+
|
106
|
+
def draw_group_column_titles?
|
107
|
+
( params[:group].nil? ? false : (params[:group][:print_group_column_title].nil? ? true :
|
108
|
+
params[:group][:print_group_column_title]))
|
109
|
+
end
|
110
|
+
|
111
|
+
def last_group_summary?
|
112
|
+
@data_end
|
113
|
+
end
|
114
|
+
|
115
|
+
def before_draw_lines
|
116
|
+
super
|
117
|
+
draw_column_titles unless draw_group_column_titles?
|
118
|
+
end
|
119
|
+
|
120
|
+
def after_draw_lines
|
121
|
+
draw_group_summary if @data[@detail_name].count > 0
|
122
|
+
end
|
123
|
+
|
124
|
+
def before_render_line
|
125
|
+
super
|
126
|
+
run_groups(@current_row) if grouped?
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prawn_report
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.9.18
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ricardo Acras
|
8
|
+
- Egon Hilgenstieler
|
9
|
+
- Juliano Andrade
|
10
|
+
- Wellington Torrejais
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
15
|
+
dependencies: []
|
16
|
+
description: Prawn report is a class repository wich uses prawn gem capabilities to
|
17
|
+
generate PDF documents in order to make it easy to create real life reports.
|
18
|
+
email: ricardo@acras.com.br julianoch@gmail.com egon@acras.com.br wtds.trabalho@gmail.com
|
19
|
+
desenv2@labplus.com.br
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- app/controllers/ac_filter_defs_controller.rb
|
25
|
+
- app/controllers/custom_generate_report_controller.rb
|
26
|
+
- app/controllers/generate_report_controller.rb
|
27
|
+
- app/controllers/report_templates_controller.rb
|
28
|
+
- app/models/ac_filter.rb
|
29
|
+
- app/models/ac_filter_def.rb
|
30
|
+
- app/models/ac_filter_option.rb
|
31
|
+
- app/models/report_template.rb
|
32
|
+
- lib/ac_filters_utils.rb
|
33
|
+
- lib/active_record_helpers.rb
|
34
|
+
- lib/bands/band.rb
|
35
|
+
- lib/bands/footer_band.rb
|
36
|
+
- lib/bands/header_band.rb
|
37
|
+
- lib/bands/summary_band.rb
|
38
|
+
- lib/custom_report_controller.rb
|
39
|
+
- lib/generators/prawn_report/install/install_generator.rb
|
40
|
+
- lib/generators/prawn_report/install/templates/20120108210141_create_prawn_report_catalogs.rb
|
41
|
+
- lib/generators/prawn_report/install/templates/20120124012653_add_filter_defs.rb
|
42
|
+
- lib/generators/prawn_report/install/templates/20120209231821_add_filters_to_reports.rb
|
43
|
+
- lib/generators/prawn_report/install/templates/20120222021437_add_order_to_filter_def.rb
|
44
|
+
- lib/generators/prawn_report/install/templates/20120222025632_add_select_sql.rb
|
45
|
+
- lib/generators/prawn_report/install/templates/20120222030526_create_ac_filter_joins.rb
|
46
|
+
- lib/generators/prawn_report/install/templates/20120222122507_add_serialization_params_to_report.rb
|
47
|
+
- lib/generators/prawn_report/install/templates/20120222134101_create_ac_filter_includes.rb
|
48
|
+
- lib/generators/prawn_report/install/templates/20120222150029_change_includes_and_joins_to_hash.rb
|
49
|
+
- lib/generators/prawn_report/install/templates/20120229134810_add_group_to_filter_def.rb
|
50
|
+
- lib/generators/prawn_report/install/templates/20120229194434_add_system_criteria_to_ac_filter.rb
|
51
|
+
- lib/generators/prawn_report/install/templates/20120301063031_change_select_sql.rb
|
52
|
+
- lib/generators/prawn_report/install/templates/20120303104431_change_filled_criteria_unfilled_criteria.rb
|
53
|
+
- lib/generators/prawn_report/install/templates/20120316162712_add_filled_criteria_to_options.rb
|
54
|
+
- lib/generators/prawn_report/install/templates/20120323124446_add_fields_to_filter.rb
|
55
|
+
- lib/generators/prawn_report/install/templates/20130122101313_add_sql_query_to_ac_filter_def.rb
|
56
|
+
- lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb
|
57
|
+
- lib/prawn_report.rb
|
58
|
+
- lib/prawn_report/engine.rb
|
59
|
+
- lib/prawn_report/version.rb
|
60
|
+
- lib/prawn_report_seeds.rb
|
61
|
+
- lib/report.rb
|
62
|
+
- lib/report_helpers.rb
|
63
|
+
- lib/report_info.rb
|
64
|
+
- repo/bands/footers/footer_001.rb
|
65
|
+
- repo/bands/headers/header_001.rb
|
66
|
+
- repo/bands/headers/header_002.rb
|
67
|
+
- repo/reports/column_group.rb
|
68
|
+
- repo/reports/listing.rb
|
69
|
+
- repo/reports/simple_listing.rb
|
70
|
+
homepage: http://www.acras.com.br/
|
71
|
+
licenses: []
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.5.1
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Prawn Report makes it easy to create PDF reports.
|
93
|
+
test_files: []
|