Module: XmlConv::PostProcess::Bbmb

Defined in:
lib/postprocess/bbmb.rb

Class Method Summary collapse

Class Method Details

.info(delivery) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/postprocess/bbmb.rb', line 67

def Bbmb.info(delivery)
  info = {
    :order_reference => delivery.customer_id,
  }
  if(date = delivery.delivery_date)
    info.store(:order_expressdate, date)
  end
  lines = []
  if((cust = delivery.customer) && ship = cust.ship_to)
    lines.push(ship.acc_id)
    lines.push(ship.name)
    if(addr = ship.address)
      lines.concat(addr.lines)
      lines.push([addr.zip_code, addr.city].compact.join(' '))
    end
    info.store(:order_comment, lines.compact.join("\n"))
  end
  info
end

.inject(drb_url, name_short, inject_id, transaction = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/postprocess/bbmb.rb', line 9

def Bbmb.inject(drb_url, name_short, inject_id, transaction=nil)
  ## inject with 4 arguments is a special case where the recipient is 
  #  not known in BBMB. In all other cases we can take the inject_id
  #  directly from customer.acc_id. If so, inject is called with 
  #  3 arguments, with transaction as the third argument.
  if(transaction.nil?)
    transaction = inject_id
    inject_id = nil
  end
  if(bdd = transaction.model)
    bbmb = DRbObject.new(nil, drb_url)
    bdd.deliveries.each { |delivery|
      begin
        iid  = inject_id || delivery.customer.acc_id
        order = order(delivery)
        info = info(delivery)
        bbmb.inject_order(name_short, iid, order, info)
      rescue Exception => e
        message = "Bestellung OK, Eintrag in BBMB Fehlgeschlagen:\n" \
          << e.class.to_s << "\n" \
          << e.message << "\n\n" \
          << e.backtrace.join("\n") << "\n\n" \
          << "name_short: #{name_short}\n" \
          << "hospital: #{inject_id}\n"
        if(order)
          message << "\norder: \n"
          order.each { |k,v|  message << "#{k.inspect} => #{v}\n" }
        end
        if(info)
          message << "\ninfo: \n"
            info.each { |k,v| message << "#{k} => #{v}\n" }
        end
        raise message
      end
    }
  end
end

.item_ids(item) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/postprocess/bbmb.rb', line 46

def Bbmb.item_ids(item)
  item.id_table.inject({}) { |memo, (domain, value)|
    key = case domain
          when 'et-nummer'
            :article_ean13
          when 'pharmacode'
            :article_pcode
          when 'lieferantenartikel'
            :article_number
          end
    memo.store(key, value.gsub(/^0+/, ''))
    memo
  }
end

.order(delivery) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/postprocess/bbmb.rb', line 60

def Bbmb.order(delivery)
  pairs = []
  delivery.items.each { |item|
    pairs.push([item_ids(item), item.qty.to_i])
  }
  pairs
end