Class: ODDB::State::Admin::FachinfoConfirm

Inherits:
Global show all
Defined in:
src/state/admin/fachinfoconfirm.rb

Constant Summary

VIEW =
View::Admin::FachinfoConfirm

Constants inherited from Global

HOME_STATE, ZONE

Constants inherited from Global

DIRECT_EVENT, GLOBAL_MAP, HOME_STATE, LIMITED, PRINT_STATES, READONLY_STATES, RESOLVE_STATES, REVERSE_MAP, VIEW, ZONE_NAVIGATION

Constants included from UmlautSort

FILTER_PAIRS

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Global

#zone_navigation

Methods inherited from Global

#_search_drugs, #_search_drugs_state, #_trigger, #add_to_interaction_basket, #allowed?, #atc_chooser, #checkout, #clear_interaction_basket, #creditable?, #direct_request_path, #doctorlist, #download, #export_csv, #extend, #fachinfo, #feedbacks, #help_navigation, #home_navigation, #home_state, #hospitallist, #interaction_basket, #limit_state, #limited?, #logout, #navigation, #notify, #password_reset, #paypal_return, #powerlink, #print, #proceed_download, #proceed_poweruser, #resolve, #resolve_state, #rss, #search, #show, #snapback_event, #sort, #sponsorlink, #suggest_address, #switch, #unique_email, #user_input, #user_navigation, #ywesee_contact, #zone_navigation, #zones

Methods included from LoginMethods

#autologin, #login

Methods included from UmlautSort

#sort_model, #umlaut_filter

Instance Attribute Details

- (Object) language

Returns the value of attribute language



12
13
14
# File 'src/state/admin/fachinfoconfirm.rb', line 12

def language
  @language
end

Instance Method Details

- (Object) back



18
19
20
# File 'src/state/admin/fachinfoconfirm.rb', line 18

def back
  @previous.previous
end

- (Object) iksnrs(fi_document)



21
22
23
24
25
26
27
28
29
30
# File 'src/state/admin/fachinfoconfirm.rb', line 21

def iksnrs(fi_document)
  iksnr_src = fi_document.iksnrs.to_s.gsub("'", '')
  if(iksnr_src && (iksnrs = iksnr_src.match(/[0-9]+(,\s*[0-9]+)*/u)))
    iksnrs[0].split(/,\s*/u).collect { |iksnr|
      sprintf('%05i', iksnr.to_i)
    }
  else
    []
  end
end

- (Object) init



14
15
16
17
# File 'src/state/admin/fachinfoconfirm.rb', line 14

def init
  super
  validate_iksnrs()
end

- (Object) preview



31
32
33
34
35
# File 'src/state/admin/fachinfoconfirm.rb', line 31

def preview
  index = @session.user_input(:index)
  fi = @model[index.to_i]
  State::Drugs::FachinfoPreview.new(@session, fi)
end

- (Object) replaceable_fachinfo



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'src/state/admin/fachinfoconfirm.rb', line 64

def replaceable_fachinfo
  @valid_iksnrs.each { |iksnr|
    #if no fachinfo exists for this registration
    if(fi = @session.registration(iksnr).fachinfo)
      iksnrs = fi.registrations.collect { |reg| 
        reg.iksnr 
      }
      if((iksnrs - @valid_iksnrs).empty?)
        return fi
      end
    end
  }
  nil
end

- (Object) store_slate



78
79
80
81
82
83
# File 'src/state/admin/fachinfoconfirm.rb', line 78

def store_slate
  if(@session.allowed?('invoice', 'org.oddb.processing'))
    store_slate_item(Time.now, :processing)
  end
  store_slate_item(Time.now, :annual_fee)
end

- (Object) store_slate_item(time, type)



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'src/state/admin/fachinfoconfirm.rb', line 84

def store_slate_item(time, type)
  ## only invoice MS-Word-Uploads for now
  return if(@model.mime_type != "application/msword")
  slate_pointer = Persistence::Pointer.new([:slate, :fachinfo])
  @session.app.create(slate_pointer)
  reg = @model.registration
  item_pointer = slate_pointer + :item
  expiry_time = InvoiceItem.expiry_time(FI_UPLOAD_DURATION, time)
  unit = @session.lookandfeel.lookup("fi_upload_#{type}")
  values = {
    :data          => {:name => reg.name_base},
    :duration      => FI_UPLOAD_DURATION,
    :expiry_time =>  expiry_time,
    :item_pointer => reg.pointer,
    :price       => FI_UPLOAD_PRICES[type],
    :text          => reg.iksnr,
    :time          => time,
    :type          => type,
    :unit          => unit,
    :yus_name    =>  @session.user.name,
    :vat_rate      => VAT_RATE, 
  } 
  @session.app.update(item_pointer.creator, values, unique_email)
end

- (Object) update



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'src/state/admin/fachinfoconfirm.rb', line 36

def update
  # keys = [:state_id]
  # input = user_input(keys)
  validate_iksnrs()
  if(error?)
    self
  else
    pointer = if(old_fachinfo = replaceable_fachinfo)
      old_fachinfo.pointer
    else
      Persistence::Pointer.new(:fachinfo).creator
    end
    values = {}
    values.store(@language, @model.at(0))
    if(values.empty?)
      add_warning(:w_no_fachinfo_saved, :fachinfo_upload, nil)
      return self
    end
    fachinfo = @session.app.update(pointer, values, unique_email)
    fachinfo.add_change_log_item(unique_email, 'uploaded', @language)
    @session.app.update(fachinfo.pointer, {})
    @valid_iksnrs.each { |iksnr|
      @session.app.replace_fachinfo(iksnr, fachinfo.pointer)
    }
    store_slate
    @previous.previous
  end
end

- (Object) validate_iksnrs



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'src/state/admin/fachinfoconfirm.rb', line 108

def validate_iksnrs
  @valid_iksnrs = [@model.registration.iksnr]
  @errors = {}
  all_iksnrs = @model.inject([]) { |array, fi_document|
    array | iksnrs(fi_document)
  }
  all_iksnrs.each { |iksnr|
    if(reg = @session.app.registration(iksnr))
      if(allowed?(reg)) 
        @valid_iksnrs.push(iksnr)
      else
        add_warning(:w_access_denied_iksnr, :fachinfo_upload, iksnr)
      end
    else
      add_warning(:w_unknown_iksnr, :fachinfo_upload, iksnr)
    end
  }
  if(@valid_iksnrs.empty?)
    err = create_error(:e_no_valid_iksnrs, :iksnrs, all_iksnrs)
    @errors.store(:iksnrs, err)
  end
  @valid_iksnrs
end