# -*- coding: utf-8 -*-
class Abf < Entry
  
 
#  @@initialized = false
  def initialize(row, gk_table)
    super(row,gk_table)
    #spezialauflösungen, siehe zugehörige listen
    @data['gefaehrlich'] = (@data['abfart_id'] == 2) ? 0 : @data['abfart_id']
    @data['ins_ausland'] = (@data['aland_id'] == 2) ? 0 : @data['aland_id']
    @data['verwertung'] = case @data['verbes_id']
                            when nil then nil
                            when 1 then "Zur Beseitigung"
                            when 2 then "Zur Verwertung"
                          end
    @data['vb'] = ''
    @data['vb'].append_clean_address(@data['vbname'])
    @data['vb'].append_clean_address(@data['vbstr'].append_clean_address(@data['vbstrnr'], ' ')) unless @data['vbstr'].nil?
    @data['vb'].append_clean_address(@data['vbplz'].append_clean_address(@data['vbort'], ' '))
    @data['vb'].append_clean_address(@data['vbstaat'])
    
    
    @data['vbs'] = ''
    @data['vbs'].append_clean_address(@data['vbsstr'].append_clean_address(@data['vbsstrnr'], ' ')) unless @data['vbsstr'].nil?
    @data['vbs'].append_clean_address(@data['vbsplz'].append_clean_address(@data['vbsort'], ' '))
    @data['vbs'].append_clean_address(@data['vbsstaat'])
    
  end

  def write_out()
    $db_target.execute("INSERT INTO abfallverbringungen (
        id,
        betriebe_id,
        jahr,
        menge,
        gefaehrlich,
        ins_ausland,
        disposition,
        bestimmungsmethode,
        bestimmungsverfahren,
        entsorger,
        entsorgungsort
      ) VALUES (
      #{sqlize('id')},
      #{sqlize('p_betrieb_id')},
      #{sqlize('jahr')},
      #{sqlize('menge')},
      #{sqlize('gefaehrlich')},
      #{sqlize('ins_ausland')},
      #{sqlize('disposition')},
      #{sqlize('bmeth')},
      #{sqlize('bverf')},
      #{sqlize('vb')},
      #{sqlize('vbs')}
      )")
    @geheimk.each do |gk|
      $db_target.execute("INSERT INTO abfallverbringungen_gg (abfallverbringungen_id, grund) VALUES (#{@data['id']},'#{gk[1]}')")
    end

  end
  

end
