diff --git a/app/models/report_template.rb b/app/models/report_template.rb index cc670d2..60c0734 100644 --- a/app/models/report_template.rb +++ b/app/models/report_template.rb @@ -1,3 +1,5 @@ +require 'yaml' + class ReportTemplate < ActiveRecord::Base belongs_to :ac_filter_def @@ -13,7 +15,11 @@ def serialization_params=(value) def serialization_params value = read_attribute :serialization_params - value.nil? ? {} : Marshal.load(value) + begin + value.nil? ? {} : Marshal.load(value) + rescue TypeError + + end end end diff --git a/lib/ac_filters_utils.rb b/lib/ac_filters_utils.rb index 0aded3d..62648dc 100644 --- a/lib/ac_filters_utils.rb +++ b/lib/ac_filters_utils.rb @@ -173,7 +173,7 @@ def apply_ac_filter(parsed_filter, system_params) if filter_def.has_sql_query? sql_to_execute = ActiveRecord::Base.send(:sanitize_sql_array, conditions) r = [] - ActiveRecord::Base.connection.instance_exec(sql_to_execute).each(:as => :hash) {|i| r << i} + ActiveRecord::Base.connection.instance_exec(sql_to_execute).each(as :hash) {|i| r << i} else find_params[:select] = filter_def.select_sql.to_s unless filter_def.select_sql.nil? find_params[:order] = filter_def.order_sql.to_s unless filter_def.order_sql.nil? diff --git a/lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb b/lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb new file mode 100644 index 0000000..9171193 --- /dev/null +++ b/lib/generators/prawn_report/install/templates/20131107172133_add_excluir_to_report_template.rb @@ -0,0 +1,10 @@ +class AddExcluirToReportTemplate < ActiveRecord::Migration + def self.up + add_column :report_templates, :excluir, :boolean + end + + def self.down + remove_column :report_templates, :excluir + end +end + diff --git a/lib/prawn_report_seeds.rb b/lib/prawn_report_seeds.rb index c53496b..c212178 100644 --- a/lib/prawn_report_seeds.rb +++ b/lib/prawn_report_seeds.rb @@ -3,7 +3,7 @@ require 'yaml' -ReportTemplate.delete_all +ReportTemplate.update_all({:ac_filter_def_id => nil, :excluir => true}) AcFilterOption.delete_all AcFilter.delete_all AcFilterDef.delete_all @@ -20,14 +20,30 @@ Dir.glob("#{Rails.root}/db/reports/*.yml").each do |f| puts "Parsing file: #{f}" params = YAML::load(File.open(f, 'r')) - if params["filter_name"] - f = AcFilterDef.find_by_name(params.delete("filter_name")) - if f - params["ac_filter_def_id"] = f.id + r = ReportTemplate.find_by_name(params["name"]) + if r.nil? + if params["filter_name"] + f = AcFilterDef.find_by_name(params.delete("filter_name")) + if f + params["ac_filter_def_id"] = f.id + end + end + params["excluir"] = false + ReportTemplate.create(params) + puts "Criado relatório: " + params["name"] + else + if params["filter_name"] + f = AcFilterDef.find_by_name(params.delete("filter_name")) + if f + params["ac_filter_def_id"] = f.id + end + end + params["excluir"] = false + r.update_attributes(params) + puts "Atualizado relatório: " + params["name"] end end - ReportTemplate.create(params) - puts "Criado relatório: " + params["name"] end -puts "FIM" +ReportTemplate.destroy_all(:excluir => true) +puts "finishing, closing, and going home" diff --git a/lib/report.rb b/lib/report.rb index 37751c9..b7810b7 100644 --- a/lib/report.rb +++ b/lib/report.rb @@ -159,6 +159,7 @@ def second_pass def run_totals(data_row) @running_totals.each do |rt| vl = get_raw_field_value(data_row, rt) + vl = (vl.is_a? (String) ? vl.to_f : vl) @totals[rt] = (@totals[rt] || 0) + (vl == '' ? 0 : vl) @group_totals[rt] = (@group_totals[rt] || 0) + (vl == '' ? 0 : vl) end diff --git a/lib/report_helpers.rb b/lib/report_helpers.rb index 5005682..e160a38 100644 --- a/lib/report_helpers.rb +++ b/lib/report_helpers.rb @@ -53,7 +53,7 @@ def line_break(size = TEXT_SIZE) def format(value, formatter, options = {}) if !value.nil? && value != '' if (formatter == :currency) - value = value.round(2) + value = value.round(2) rescue sprintf('%.2f', value).to_f if value < 0 '-'+((value.to_i*-1).to_s.reverse.gsub(/...(?=.)/,'\&.').reverse) + ',' + ('%02d' % ((value.abs * 100).round % 100)) else diff --git a/prawn_report.gemspec b/prawn_report.gemspec index b67612a..ee9cd1e 100644 --- a/prawn_report.gemspec +++ b/prawn_report.gemspec @@ -1,9 +1,10 @@ Gem::Specification.new do |s| s.name = %q{prawn_report} - s.version = "1.9.17" - s.date = %q{2015-09-14} - s.authors = ["Ricardo Acras" "Egon Hilgenstieler" "Juliano Andrade" "Vinicius Cubas Brand"] - s.email = %q{ricardo@acras.com.br julianoch@gmail.com egon@acras.com.br viniciuscb@gmail.com} + s.version = "1.9.21" + s.date = %q{2016-11-23} + s.authors = ["Ricardo Acras", "Egon Hilgenstieler", "Juliano Andrade", "Vinicius Cubas Brand", "Wellington Torrejais da Silva"] + s.email = 'ricardo@acras.com.br' + s.email = %q{ricardo@acras.com.br julianoch@gmail.com egon@acras.com.br viniciuscb@gmail.com wtds.trabalho@gmail.com desenv2@labplus.com.br} s.summary = %q{Prawn Report makes it easy to create PDF reports.} s.homepage = %q{http://www.acras.com.br/} s.description = %q{Prawn report is a class repository wich uses prawn gem capabilities to generate PDF documents in order to make it easy to create real life reports.} diff --git a/repo/reports/listing.rb b/repo/reports/listing.rb index 000c3ea..659aafd 100644 --- a/repo/reports/listing.rb +++ b/repo/reports/listing.rb @@ -9,7 +9,7 @@ module PrawnReport class Listing < Report - #alias :super_new_page :new_page + alias :super_new_page :new_page def initialize(report_params = {}) super(report_params) diff --git a/repo/reports/simple_listing.rb b/repo/reports/simple_listing.rb index fb5dbce..bc9477f 100644 --- a/repo/reports/simple_listing.rb +++ b/repo/reports/simple_listing.rb @@ -72,6 +72,13 @@ def initialize(report_params = {}) :groups_running => false} end + def new_page(print_titles = true) + super(print_titles) + draw_group_header if grouped? and @report_params[:group][:header_reprint_new_page] and !last_group_summary? + if print_titles + draw_column_titles unless (!draw_group_column_titles? && !@printing_internal) || last_group_summary? + end + end protected @@ -106,14 +113,6 @@ def last_group_summary? @data_end end - def new_page(print_titles = true) - super(print_titles) - draw_group_header if grouped? and @report_params[:group][:header_reprint_new_page] and !last_group_summary? - if print_titles - draw_column_titles unless (!draw_group_column_titles? && !@printing_internal) || last_group_summary? - end - end - def before_draw_lines super draw_column_titles unless draw_group_column_titles?