app/controllers/appointments_controller.rb
# Outputs a detailed report using the selected rows IDs specified as parameter.
#
# == Params:
# - <tt>:type</tt> => the extension of the file to be created; one among: 'pdf', 'odt', 'txt', 'full.csv', 'simple.csv'
#   (default: 'pdf')
# - <tt>:data</tt> (*required*) => a JSON-encoded array of Appointment IDs to be retrieved and processed
#
Outputs a detailed report using the selected rows IDs specified as parameter.
Outputs a detailed report using the selected rows IDs specified as parameter .
def report_detail
    id_list = ActiveSupport::JSON.decode( params[:data] ) if params[:data]
    unless id_list.kind_of?(Array)
      raise ArgumentError, "report_detail(): invalid or missing data parameter!", caller
    end
    return if id_list.size < 1
    records = nil
    begin
      records = Appointment.where( :id => id_list )
    rescue
      raise ArgumentError, "report_detail(): no valid ID(s) found inside data parameter!", caller
    end
    return if records.nil?
    filetype    = params[:type] || 'csv'
    separator   = params[:separator] || ';'         
    report_title = "#{I18n.t( :appointments, {:scope=>[:appointment]} )} #{records.first.get_date_schedule} ... #{records.last.get_date_schedule}"
    report_base_name = "#{I18n.t( :appointments, {:scope=>[:appointment]} )}-#{records.first.get_compacted_date_schedule}_#{records.last.get_compacted_date_schedule}"
    detail_data  = []
    records.each { |row|
      detail_data << row.to_a_s(
        Appointment.report_detail_symbols(),
        Appointment::CONVERTED_FLOAT2STRING_FIXED_PRECISION,
        8
      )
    }
    ruport_table = Ruport::Data::Table.new(
      :column_names => Appointment.report_detail_symbols(),
      :data => detail_data
    )
    localize_ruport_table_column_names( ruport_table, :appointment )
    filename = create_unique_filename( report_base_name ) + ".#{filetype}"
    if ( filetype == 'csv' )                        
      data = ''
      data << ruport_table.as( :csv, :format_options => {:col_sep => separator}, :ignore_table_width => true )
      data << "\r\n"
      send_data( data, :type => "text/#{filetype}", :filename => filename )
    else
      flash[:error] = I18n.t( :unsupported_output_format )
      redirect_to_index
    end
  end
def report_detail id_list = ActiveSupport :: JSON . decode ( params [ :data ] ) if params [ :data ] unless id_list . kind_of? ( Array ) raise ArgumentError , "report_detail(): invalid or missing data parameter!" , caller end return if id_list . size < 1 records = nil begin records = Appointment . where ( :id => id_list ) rescue raise ArgumentError , "report_detail(): no valid ID(s) found inside data parameter!" , caller end return if records . nil? filetype = params [ :type ] || 'csv' separator = params [ :separator ] || ';' report_title = "#{I18n.t( :appointments, {:scope=>[:appointment]} )} #{records.first.get_date_schedule} ... #{records.last.get_date_schedule}" report_base_name = "#{I18n.t( :appointments, {:scope=>[:appointment]} )}-#{records.first.get_compacted_date_schedule}_#{records.last.get_compacted_date_schedule}" detail_data = [ ] records . each { | row | detail_data << row . to_a_s ( Appointment . report_detail_symbols ( ) , Appointment :: CONVERTED_FLOAT2STRING_FIXED_PRECISION , 8 ) } ruport_table = Ruport :: Data :: Table . new ( :column_names => Appointment . report_detail_symbols ( ) , :data => detail_data ) localize_ruport_table_column_names ( ruport_table , :appointment ) filename = create_unique_filename ( report_base_name ) + ".#{filetype}" if ( filetype == 'csv' ) data = '' data << ruport_table . as ( :csv , :format_options => { :col_sep => separator } , :ignore_table_width => true ) data << "\r\n" send_data ( data , :type => "text/#{filetype}" , :filename => filename ) else flash [ :error ] = I18n . t ( :unsupported_output_format ) redirect_to_index end end
Outputs a detailed report using the selected rows IDs specified as parameter.
Outputs a detailed report using the selected rows IDs specified as parameter .
#    logger.debug "\r\n!! ----- report_detail -----" #    logger.debug "report_detail: params #{params.inspect}" # Parse params: # DEBUG #    logger.debug "report_detail(): id list: #{id_list.inspect}" # Retrieve the receipt rows from the ID list: # DEBUG #    logger.debug "report_detail(): records class: #{records.class}" #    logger.debug "report_detail(): records found: #{records.size}" # (This plus the following params are used only during data exports) # == DATA Collection == # == OPTIONS setup + RENDERING phase == # --- CSV --- # DEBUG #        puts data # -------------------------------------------