#encoding: utf-8
class VollstaendigkeitUeberpruefungController < ApplicationController
  before_action :login_required
#  layout "application"
#  NAME = 'Vollständigkeitsprüfung'
#  PLURAL = 'Vollständigkeitsprüfungen'
#  BERICHTSZEITRAUM = "DE2008" #bitte hier jeden neuen Berichtszeitraum ändern!!!!!!!!!!!!!!!
#
#  LISTE = [
#    ["Agglomerationen", "agglomerations"],
#    ["Anlagen", "plants" ],
#    ["Einleitstellen", "discharge_points"],
#    ["Landesdaten", "federal_state_info"]
#  ]
#
#  def index
#    @inhalt = LISTE
#    #  Liste.each do |col|
#    # @inhalt += col + " "
#    # end
#    session[:testet]= nil
#  end
#
#  def result
#    session[:spezifikation] = params[:spezifikation] unless params[:spezifikation].blank?
#    redirect_to :action => :index and return false if session[:spezifikation].blank?
#    @datensatz = session[:spezifikation]
#
#    @freigabe = false
#    @caption = PLURAL + " - " + LISTE.detect{|l| l[1]==session[:spezifikation]}[0]
#    @gen = Generica.new(@datensatz, session[:user]) #Übergabe sind Tabellenname und User-id
#    @columns = @gen.get_keys
#
#    #zusammenbauen der Übergabeparameter und gesonderter Whereclauses (sonderfälle)
##    sql_part = agglo_where if session[:spezifikation] == "agglomerations"
##    sql_part = plants_where if session[:spezifikation] == "plants"
##    if session[:spezifikation] == "discharge_points"
##      sql_part = discharge_where
##    end
##    sql_part = federal_where if session[:spezifikation] == "federal_state_info"
##
##    zusatz = sql_part[0]
#
#
#
#    #baue weitere allgemeine conditions
#    where = "and (
#    "
#    tabellen = @columns.collect {|c| session[:spezifikation]+"."+c['col_name']}
#    where += tabellen.join(" is null or ")
#    where += " is null"
#    where += case session[:spezifikation]
#    when "discharge_points" then "
#          or (discharge_points.dp_waterbody_id is null and dp_gwbody_id is null)
#          or (dp_gwbody_id is null and rb_type_id = 1)
#          or (dp_surface_id = 1 and dp_surface_land_id is null)
#          )
#          and dp_to_be_reported is distinct from 0
#          and dp_state_active is distinct from 0"
#    when "plants" then "
#          or (pl_odc > 10000 and plants.pl_n_anh1_id is null)
#          or (pl_odc > 10000 and plants.pl_ncom_id is null)
#          or (pl_odc > 10000 and plants.pl_pcom_id is null)
#          or (pl_odc > 10000 and plants.pl_p_anh1_id is null)
#          or (pl_cod_anh1_id not in (1,2,3) and (pl_cod is null or pl_cod <= 0) and (pl_cod100 is null or pl_cod100 <= 0))
#          or (pl_bod_anh1_id not in (1,2,3) and (pl_bod is null or pl_bod <= 0) and (pl_bod100 is null or pl_bod100 <= 0))
#          or (pl_odc > 10000 and pl_n_anh1_id not in (1,2,3) and (pl_n is null or pl_n <= 0) and (pl_n100 is null or pl_n100 <= 0))
#          or (pl_odc > 10000 and pl_p_anh1_id not in (1,2,3) and (pl_p is null or pl_p <= 0) and (pl_p100 is null or pl_p100 <= 0))
#          or (pl_other = 1 and pl_other_comment is null)
#          )
#          and pl_to_be_reported is distinct from 0
#          and (pl_state_active is distinct from 0
#            or pl_cd is not null)"
##  or ((pl_cod is null and pl_cod100 is null)
##  or (pl_n_tech = 1 and pl_n is null and pl_n100 is null)
##  or (pl_p_tech = 1 and pl_p is null and pl_p100 is null) ))
##  and not pl_to_be_reported = 0"
##    return [zusatz, where]
##  end
#    when "agglomerations" then "
#          or (ag_change_nload = 1 and ag_remark_change is null)
#          or (ag_city = 1 and pl_city_id is null)
#          or (agg_not_collected > 0 and agg_date_coll is null)
#          )
#          and ag_to_be_reported is distinct from 0
#          and agg_state_active is distinct from 0"
#    when "federal_state_info" then ")"
#    end
#
#    where += "and #{session[:spezifikation]}.rep_code = '#{BERICHTSZEITRAUM}'"
#
#
#    #abschicken
#    @user = session[:user]
#    if params['amount'].to_i > 0
#      @user.update_attributes(:rows_per_page => params['amount'])
#    end
#    @data, @order = @gen.all(where, nil, @user.rows_per_page,params['offset'] || 0)
#
#    @schon_abgefragt = true
#    if @data.empty?
#      session[:testet] = Hash.new unless session[:testet]
#      session[:testet][session[:spezifikation]] = true
#    else
#      @schon_abgefragt = nil
#    end
#
#    if session[:testet] #schon_abgefragt #
#      case
#      when !session[:testet]["agglomerations"] #schon_abgefragt["agglomerations"]
#        @caption_button = "Abprüfen von Agglomerationen"
#        @parameter_button = "agglomerations"
#      when !session[:testet]["plants"] #schon_abgefragt["plants"]
#        @caption_button = "Abprüfen von Anlagen"
#        @parameter_button = "plants"
#      when !session[:testet]["discharge_points"] #schon_abgefragt["discharge_points"]
#        @caption_button = "Abprüfen von Einleitstellen"
#        @parameter_button = "discharge_points"
#      when !session[:testet]["federal_state_info"] #schon_abgefragt["federal_state_info"]
#        @caption_button = "Abprüfen der Landesdaten"
#        @parameter_button = "federal_state_info"
#      else
#        @freigabe = true
#      end
#    end
#  end
#
##  def agglo_where
##    zusatz = ['ag_name', 'agg_key']
##    where =  " or (ag_change_nload = 1 and ag_remark_change is null)
##               or (ag_city = 1 and pl_city_id is null)
##               or (agg_not_collected > 0 and agg_date_coll is null)
##             )
##             and not ag_to_be_reported = 0"
##    return [zusatz, where]
##  end
##
##  def plants_where
##    zusatz = ['pl_name', 'pl_key']
##    where = " or ((pl_cod is null and pl_cod100 is null) or (pl_n_tech = 1 and pl_n is null and pl_n100 is null) or (pl_p_tech = 1 and pl_p is null and pl_p100 is null) )) and not pl_to_be_reported = 0"
##    return [zusatz, where]
##  end
##
##  def discharge_where
##    zusatz = ['dp_name', 'dp_key']
##    where = " or (dp_gwbody_id is null and rb_type_id = 1))"
##    return [zusatz, where]
##  end
##
##  def federal_where
##    zusatz = ['rep_code', 'federal_state_id']
##    where = " or (kka_number is null))"
##    return [zusatz, where]
##  end
#
#
#  def edit
#    redirect_to :controller => session[:spezifikation], :action => 'edit', :id => params[:id]
#  end
#
#  def freigabe
#    #benutzt die "lock-Methode" aus Generika um in den Tabellen das "locked-Feld" des Bundeslandes des Users auf 1 zu setzen
#    gen("agglomerations").lock
#    gen("plants").lock
#    gen("discharge_points").lock
#    gen("federal_state_info").lock
#    flash[:notice] = "Die Daten wurden erfolgreich freigegeben, es kann nun nichts mehr geändert werden"
#    redirect_to :controller => :start
#  end
#
#
#  protected
#  def gen(art)
#    return Generica.new(art, session[:user])
#  end


end
