Module: ODDB::State::Admin::PatinfoPdfMethods

Included in:
ResellerSequence, SequenceMethods
Defined in:
src/state/admin/sequence.rb

Constant Summary

PDF_DIR =
File.expand_path('../../../doc/resources/patinfo/', File.dirname(__FILE__))
HTML_PARSER =
DRbObject.new(nil, FIPARSE_URI)

Instance Method Summary (collapse)

Instance Method Details

- (Object) assign_patinfo



21
22
23
24
25
26
27
# File 'src/state/admin/sequence.rb', line 21

def assign_patinfo
  if(@model.has_patinfo?)
    State::Admin::AssignPatinfo.new(@session, @model)
  else
    State::Admin::AssignDeprivedSequence.new(@session, @model)
  end
end

- (Object) get_patinfo_input(input)



28
29
30
31
32
33
34
35
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
64
65
66
67
68
69
70
71
# File 'src/state/admin/sequence.rb', line 28

def get_patinfo_input(input)
  newstate = self
  if((html_file = @session.user_input(:html_upload)) \
     && (document = parse_patinfo(html_file.read)))
    @model.pdf_patinfo = nil
    lang = @session.user_input(:language_select)
    ptr = nil
    if(patinfo = @model.patinfo)
      ptr = patinfo.pointer
    else
      ptr = Persistence::Pointer.new(:patinfo).creator
    end
    patinfo = @session.app.update(ptr, lang => document)
    input.store(:patinfo, patinfo.pointer)
    input.store(:pdf_patinfo, nil)
    @infos.push(:i_patinfo_assigned)
  elsif(pi_file = @session.user_input(:patinfo_upload))
    company = @model.company
    if(!company.invoiceable?)
      err = create_error(:e_company_not_invoiceable, :pdf_patinfo, nil)
      newstate = resolve_state(company.pointer).new(@session, company)
      newstate.errors.store(:pdf_patinfo, err)
    elsif(pi_file.read(4) == "%PDF")
      pi_file.rewind
      filename = "#{@model.iksnr}_#{@model.seqnr}_#{Time.now.to_f}.pdf"
      FileUtils.mkdir_p(self::class::PDF_DIR)
      store_file = File.new(File.expand_path(filename, 
        self::class::PDF_DIR), "w")
      store_file.write(pi_file.read)
      store_file.close
      @model.pdf_patinfo = filename
      store_slate()
      input.store(:pdf_patinfo, filename)
      input.store(:patinfo, nil)
      newstate = State::Admin::AssignPatinfo.new(@session, @model)
    else
      add_warning(:w_no_patinfo_saved, :patinfo_upload, nil)
    end
  elsif(@session.user_input(:patinfo) == 'delete')
    input.store(:patinfo, nil)
    input.store(:pdf_patinfo, nil)
  end
  newstate
end

- (Object) parse_patinfo(src)



72
73
74
75
76
77
78
79
# File 'src/state/admin/sequence.rb', line 72

def parse_patinfo(src)
  HTML_PARSER.parse_patinfo_html(src)
rescue StandardError => e
  msg = ' (' << e.message << ')'
  err = create_error(:e_html_not_parsed, :html_upload, msg)
  @errors.store(:html_upload, err)
  nil
end

- (Object) store_slate



80
81
82
# File 'src/state/admin/sequence.rb', line 80

def store_slate
  store_slate_item(Time.now, :annual_fee)
end

- (Object) store_slate_item(time, type)



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

def store_slate_item(time, type)
  slate_pointer = Persistence::Pointer.new([:slate, :patinfo])
  @session.app.create(slate_pointer)
  item_pointer = slate_pointer + :item
  expiry_time = InvoiceItem.expiry_time(PI_UPLOAD_DURATION, time)
  unit = @session.lookandfeel.lookup("pi_upload_#{type}")
  text = sprintf("%s %s", @model.iksnr, @model.seqnr)
  values = {
    :data          => {:name => @model.name},
    :duration      => PI_UPLOAD_DURATION,
    :expiry_time =>  expiry_time,
    :item_pointer => @model.pointer,
    :price       => PI_UPLOAD_PRICES[type],
    :text          => text,
    :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