Class: XmlConv::Conversion::PharmaciePlusBdd

Inherits:
Object
  • Object
show all
Defined in:
lib/conversion/pharmacieplus_bdd.rb

Direct Known Subclasses

XundartBdd

Class Method Summary collapse

Class Method Details

._bdd_add_xml_delivery(bdd, xml_delivery) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/conversion/pharmacieplus_bdd.rb', line 30

def _bdd_add_xml_delivery(bdd, xml_delivery)
  delivery = Model::Delivery.new
  bsr = Model::Bsr.new
  _bsr_add_customer_id(bsr, xml_delivery.attributes['ean'])
  delivery.bsr = bsr
  _delivery_add_xml_header(delivery, xml_delivery)
  REXML::XPath.each(xml_delivery, 'article') { |xml_item|
    _delivery_add_xml_item(delivery, xml_item)  
  }
  bdd.add_delivery(delivery)
  delivery
end

._bsr_add_customer_id(bsr, id) ⇒ Object



42
43
44
45
46
47
# File 'lib/conversion/pharmacieplus_bdd.rb', line 42

def _bsr_add_customer_id(bsr, id)
  customer = Model::Party.new
  customer.role = 'Customer'
  customer.add_id('ACC', id)
  bsr.add_party(customer)
end

._customer_add_party(customer, id, role) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/conversion/pharmacieplus_bdd.rb', line 48

def _customer_add_party(customer, id, role)
  party = Model::Party.new
  party.role = role
  party.add_id('ACC', id)
  customer.add_party(party)
  party
end

._delivery_add_xml_customer(delivery, xml_delivery) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/conversion/pharmacieplus_bdd.rb', line 63

def _delivery_add_xml_customer(delivery, xml_delivery)
  customer = Model::Party.new
  customer.role = 'Customer'
  _customer_add_party(customer, '1075', 'BillTo')
  ship_to = _customer_add_party(customer, 
                                _latin1(xml_delivery.attributes['ean']), 
                                'ShipTo')
  if(xml_header = REXML::XPath.first(xml_delivery, 'livraison'))
    name = Model::Name.new
    # Pharmacieplus delivers the Pharmacy-Name in 'last-name', and the name
    # of the contact person in 'other-name' - we need to juggle the pieces 
    # around a bit. (see also _party_add_xml_address)
=begin 
    if(xml_name = REXML::XPath.first(xml_header, 'last-name'))
      name.last = _latin1(xml_name.text)
    end
    if(xml_name = REXML::XPath.first(xml_header, 'first-name'))
      name.first = _latin1(xml_name.text)
    end
=end
    if(xml_name = REXML::XPath.first(xml_header, 'other-name'))
      name.text = _latin1(xml_name.text)
    end
    customer.name = name
    ship_to.name = name
    _party_add_xml_address(ship_to, xml_header)
  end
  if(xml_email = REXML::XPath.first(xml_delivery, '//groupe/online/email'))
    customer.add_id('email', _latin1(xml_email.text))
  end
  delivery.add_party(customer)
end

._delivery_add_xml_header(delivery, xml_delivery) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/conversion/pharmacieplus_bdd.rb', line 55

def _delivery_add_xml_header(delivery, xml_delivery)
  xml_order = REXML::XPath.first(xml_delivery, '/commande')
  delivery.add_id('Customer', _latin1(xml_order.attributes['id']))
  if(xml_party = REXML::XPath.first(xml_order, 'fournisseur'))
    _delivery_add_xml_seller(delivery, xml_party)
  end
  _delivery_add_xml_customer(delivery, xml_delivery)
end

._delivery_add_xml_item(delivery, xml_item) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/conversion/pharmacieplus_bdd.rb', line 104

def _delivery_add_xml_item(delivery, xml_item)
  item = Model::DeliveryItem.new
  item.line_no = _latin1(delivery.items.size.next.to_s)
  item.add_id('ET-Nummer', _latin1(xml_item.attributes['ean']))
  item.add_id('Pharmacode', _latin1(xml_item.attributes['pharmacode']))
  item.qty = _latin1(xml_item.attributes['qte-facture'])
  item.unit = 'PCE'
  delivery.add_item(item)
end

._delivery_add_xml_seller(delivery, xml_party) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/conversion/pharmacieplus_bdd.rb', line 95

def _delivery_add_xml_seller(delivery, xml_party)
  party = Model::Party.new
  party.role = 'Seller'
  party.add_id('ACC', _latin1(xml_party.attributes['ean']))
  if(party.acc_id.to_s.empty?)
    party.add_id("ACC", "7601001000681")
  end
  delivery.add_party(party)
end

._latin1(str) ⇒ Object



113
114
115
116
117
# File 'lib/conversion/pharmacieplus_bdd.rb', line 113

def _latin1(str)
  Iconv.iconv('ISO-8859-1//TRANSLIT//IGNORE', 'UTF8', str).first.strip
rescue
  str
end

._party_add_xml_address(party, xml_header) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/conversion/pharmacieplus_bdd.rb', line 118

def _party_add_xml_address(party, xml_header)
  if(xml_address = REXML::XPath.first(xml_header, 'address'))
    address = Model::Address.new
    address.zip_code = _text(xml_address, 'zip')
    address.city = _text(xml_address, 'city')
    if(xml_name = REXML::XPath.first(xml_header, 'last-name'))
      address.add_line(_latin1(xml_name.text))
    end
    if(line = _text(xml_address, 'street'))
      address.add_line(line)
    end
    party.address = address
  end
end

._text(xml_parent, xpath) ⇒ Object



132
133
134
135
136
# File 'lib/conversion/pharmacieplus_bdd.rb', line 132

def _text(xml_parent, xpath)
  if(xml_element = REXML::XPath.first(xml_parent, xpath))
    _latin1(xml_element.text)
  end
end

.convert(xml_document) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/conversion/pharmacieplus_bdd.rb', line 17

def convert(xml_document)
  bdd = Model::Bdd.new
  bsr = Model::Bsr.new
  _bsr_add_customer_id(bsr, 'YWESEEPP')
  bdd.bsr = bsr
  REXML::XPath.each(xml_document, '//com-pharma') { |xml_delivery|
    _bdd_add_xml_delivery(bdd, xml_delivery)
  }
  bdd
end

.parse(xml_src) ⇒ Object



27
28
29
# File 'lib/conversion/pharmacieplus_bdd.rb', line 27

def parse(xml_src)
  REXML::Document.new(xml_src)
end