Class: XmlConv::Conversion::WbmbBdd
- Inherits:
-
Object
- Object
- XmlConv::Conversion::WbmbBdd
- Defined in:
- lib/conversion/wbmb_bdd.rb
Class Method Summary collapse
- ._bdd_add_xml_delivery(bdd, soap_mapping, positions) ⇒ Object
- ._delivery_add_recipient_ids(delivery, ids) ⇒ Object
- ._delivery_add_sender_ids(delivery, ids) ⇒ Object
- ._delivery_add_soap_info(delivery, infos) ⇒ Object
- ._delivery_add_soap_positions(delivery, positions) ⇒ Object
- ._item_add_soap_ids(item, ids) ⇒ Object
- ._latin1(txt) ⇒ Object
- ._named_value(parent, name) ⇒ Object
- ._party_add_delivery_address(party, info) ⇒ Object
- .convert(soap_mapping) ⇒ Object
- .parse(src) ⇒ Object
Class Method Details
._bdd_add_xml_delivery(bdd, soap_mapping, positions) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/conversion/wbmb_bdd.rb', line 35 def _bdd_add_xml_delivery(bdd, soap_mapping, positions) delivery = Model::Delivery.new if(soap_mapping.respond_to?(:absender)) _delivery_add_sender_ids(delivery, soap_mapping.absender) end if(soap_mapping.respond_to?(:empfaenger)) _delivery_add_recipient_ids(delivery, soap_mapping.empfaenger) end if(soap_mapping.respond_to?(:auftrag_info)) _delivery_add_soap_info(delivery, soap_mapping.auftrag_info) end _delivery_add_soap_positions(delivery, positions) bdd.add_delivery(delivery) end |
._delivery_add_recipient_ids(delivery, ids) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/conversion/wbmb_bdd.rb', line 81 def _delivery_add_recipient_ids(delivery, ids) party = Model::Party.new party.role = 'Seller' ids.each { |id| key = case _latin1(id.idtype) when 'ean13' party.add_id('ACC', _latin1(id.idvalue)) when 'auftragsnummer' delivery.add_id('ACC', _latin1(id.idvalue)) end } if(party.acc_id.to_s.empty?) party.add_id("ACC", "7601001000681") end delivery.add_party(party) party end |
._delivery_add_sender_ids(delivery, ids) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/conversion/wbmb_bdd.rb', line 49 def _delivery_add_sender_ids(delivery, ids) bsr = Model::Bsr.new customer = Model::Party.new customer.role = 'Customer' party = Model::Party.new party.role = 'Customer' ids.each { |id| value = _latin1(id.idvalue) case _latin1(id.idtype) when 'auftragsnummer' delivery.add_id('Customer', value) when 'ean13' party.add_id('ET-Nummer', value) when 'email' customer.add_id('email', value) when 'kundennummer' party.add_id('ACC', value) customer.add_id('ACC', value) when 'name' name = Model::Name.new name.text = value customer.name = name end } bill_to = Model::Party.new bill_to.role = 'BillTo' bill_to.add_id('ACC', '1075') customer.add_party(bill_to) delivery.add_party(customer) bsr.add_party(party) delivery.bsr = bsr end |
._delivery_add_soap_info(delivery, infos) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/conversion/wbmb_bdd.rb', line 98 def _delivery_add_soap_info(delivery, infos) infos.each { |info| case _latin1(info.infotype) when 'schnittstelle' delivery.bsr.interface = _latin1(info.infovalue) when 'lieferadresse' _party_add_delivery_address(delivery.customer, info) when 'lieferung_bis' delivery.delivery_date = begin DateTime.parse(_latin1(info.infovalue)) rescue DateTime.now end when 'text' text = Model::FreeText.new text << _latin1(info.infovalue) delivery.add_free_text('text', text) when 'versandkosten' delivery.transport_cost = _latin1(info.infovalue) end } end |
._delivery_add_soap_positions(delivery, positions) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/conversion/wbmb_bdd.rb', line 120 def _delivery_add_soap_positions(delivery, positions) positions.each_with_index { |pos, idx| item = Model::DeliveryItem.new item.line_no = idx.next.to_s _item_add_soap_ids(item, [pos.identifier].flatten) item.qty = _latin1(pos.bestellmenge) item.unit = 'PCE' if(amount = _named_value(pos, :artikelpreis)) price = Model::Price.new price.purpose = 'NettoPreis' price.amount = amount item.add_price(price) end if(value = _named_value(pos, :positionstext)) txt = Model::FreeText.new txt << _latin1(value) item.add_free_text('text', txt) end delivery.add_item(item) } end |
._item_add_soap_ids(item, ids) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/conversion/wbmb_bdd.rb', line 141 def _item_add_soap_ids(item, ids) ids.each { |id| key = _latin1(id.idtype) value = _latin1(id.idvalue) case key when 'ean13' item.add_id('ET-Nummer', value) when 'pcode' item.add_id('Pharmacode', value) when 'gag-code' item.add_id('LieferantenArtikel', value) else item.add_id(key, value) end } end |
._latin1(txt) ⇒ Object
190 191 192 193 194 195 196 |
# File 'lib/conversion/wbmb_bdd.rb', line 190 def _latin1(txt) if(txt.is_a?(String)) Iconv.iconv('latin1', 'utf8', txt).first end rescue txt end |
._named_value(parent, name) ⇒ Object
157 158 159 160 161 |
# File 'lib/conversion/wbmb_bdd.rb', line 157 def _named_value(parent, name) if(parent.respond_to?(name)) _latin1(parent.send(name)) end end |
._party_add_delivery_address(party, info) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/conversion/wbmb_bdd.rb', line 162 def _party_add_delivery_address(party, info) shipto = Model::Party.new shipto.role = 'ShipTo' address = Model::Address.new names = [] lines = [] info.address.each { |part| value = _latin1(part.infovalue) case _latin1(part.infotype) when 'name' names.push(value) when 'strasse' lines.push(value) when 'plz' address.zip_code = value when 'ort' address.city = value when 'land' address.country = value end } name = Model::Name.new name.text = names.shift shipto.name = name names.concat(lines).each { |line| address.add_line(line) } shipto.address = address party.add_party(shipto) end |
.convert(soap_mapping) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/conversion/wbmb_bdd.rb', line 19 def convert(soap_mapping) bdd = Model::Bdd.new texted, normal = soap_mapping.artikelliste.partition { |article| article.respond_to?(:positionstext) } unless(normal.empty?) _bdd_add_xml_delivery(bdd, soap_mapping, normal) end unless(texted.empty?) _bdd_add_xml_delivery(bdd, soap_mapping, texted) end bdd end |
.parse(src) ⇒ Object
32 33 34 |
# File 'lib/conversion/wbmb_bdd.rb', line 32 def parse(src) SOAP::Marshal.unmarshal(src) end |