Class: ODDB::Invoicer

Inherits:
Plugin show all
Defined in:
src/plugin/invoicer.rb

Direct Known Subclasses

DownloadInvoicer, InfoInvoicer

Constant Summary

RECIPIENTS =
[ 
  'hwyss@ywesee.com', 
  'zdavatz@ywesee.com' 
]

Constants inherited from Plugin

ARCHIVE_PATH, RECIPIENTS

Instance Method Summary (collapse)

Methods inherited from Plugin

#initialize, #l10n_sessions, #log_info, #recipients, #report, #resolve_link, #update_rss_feeds

Methods included from HttpFile

#http_body, #http_file

Constructor Details

This class inherits a constructor from ODDB::Plugin

Instance Method Details

- (Object) create_invoice(email, items, ydim_id)



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'src/plugin/invoicer.rb', line 15

def create_invoice(, items, ydim_id)
  pointer = Persistence::Pointer.new(:invoice)
  values = {
    :yus_name       => ,
    :keep_if_unpaid =>  true,
    :ydim_id        =>  ydim_id,
  }
  invoice = @app.update(pointer.creator, values)
  pointer = invoice.pointer + [:item]
  items.each { |item|
    @app.update(pointer.dup.creator, item.values)
  }
end

- (Object) ensure_yus_user(comp_or_hosp)



28
29
30
31
32
33
34
35
36
37
# File 'src/plugin/invoicer.rb', line 28

def ensure_yus_user(comp_or_hosp)
  mail = comp_or_hosp.invoice_email
  @app.yus_create_user(mail)
  @app.yus_grant(mail, 'edit', comp_or_hosp.pointer.to_yus_privilege)
  @app.yus_set_preference(mail, 'association', comp_or_hosp.odba_id)
  mail
rescue Yus::YusError
  ## assume user exists
  mail
end

- (Object) resend_invoice(invoice, day = @@today)



38
39
40
# File 'src/plugin/invoicer.rb', line 38

def resend_invoice(invoice, day = @@today)
  YdimPlugin.new(@app).send_invoice(invoice.ydim_id)
end

- (Object) rp2fr(price)



41
42
43
# File 'src/plugin/invoicer.rb', line 41

def rp2fr(price)
  price.to_f / 100.0
end

- (Object) send_invoice(date, mail, items, service_date = date)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'src/plugin/invoicer.rb', line 44

def send_invoice(date, mail, items, service_date=date)
  plugin = YdimPlugin.new(@app)
  ydim_inv = plugin.inject_from_items(date, mail, items, 'CHF', service_date)
  ydim_id = ydim_inv.unique_id
  plugin.send_invoice(ydim_id)
  ydim_id
rescue StandardError => e
  log = Log.new(@@today)
  log.report = [
    "Invoicer#send_invoice(#{date}, #{mail}, #{items.join(',')}, #{service_date})",
    "Error: #{e.class}",
    "Message: #{e.message}",
    "Backtrace:",
    e.backtrace.join("\n"),
  ].join("\n")
  log.notify("Error Invoice: #{subject}")
  nil
end