Class: XmlConv::Conversion::SunStoreBdd
- Inherits:
-
Object
- Object
- XmlConv::Conversion::SunStoreBdd
- Defined in:
- lib/conversion/sunstore_bdd.rb
Class Method Summary collapse
- ._bdd_add_xml_delivery(bdd, xml_delivery) ⇒ Object
- ._boolean(item) ⇒ Object
- ._bsr_add_customer_id(bsr, id) ⇒ Object
- ._customer_add_party(customer, id, role) ⇒ Object
- ._delivery_add_xml_customer(delivery, xml_delivery) ⇒ Object
- ._delivery_add_xml_header(delivery, xml_delivery) ⇒ Object
- ._delivery_add_xml_item(delivery, xml_item) ⇒ Object
- ._latin1(str) ⇒ Object
- ._party_add_xml_address(party, xml_header) ⇒ Object
- ._utf8(str) ⇒ Object
- .convert(xml_document) ⇒ Object
- .parse(xml_src) ⇒ Object
- .respond(transaction, responses) ⇒ Object
Class Method Details
._bdd_add_xml_delivery(bdd, xml_delivery) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/conversion/sunstore_bdd.rb', line 117 def _bdd_add_xml_delivery(bdd, xml_delivery) delivery = Model::Delivery.new bsr = Model::Bsr.new xml_client = REXML::XPath.first(xml_delivery, 'client') _bsr_add_customer_id(bsr, xml_client.attributes['number']) delivery.bsr = bsr _delivery_add_xml_header(delivery, xml_delivery) if(xml_lines = REXML::XPath.first(xml_delivery, 'orderLines')) REXML::XPath.each(xml_lines, 'productOrderLine|productLabelOrderLine') do |xml_item| _delivery_add_xml_item(delivery, xml_item) end end bdd.add_delivery(delivery) delivery end |
._boolean(item) ⇒ Object
133 134 135 |
# File 'lib/conversion/sunstore_bdd.rb', line 133 def _boolean(item) item ? 'true' : 'false' end |
._bsr_add_customer_id(bsr, id) ⇒ Object
136 137 138 139 140 141 |
# File 'lib/conversion/sunstore_bdd.rb', line 136 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
142 143 144 145 146 147 148 |
# File 'lib/conversion/sunstore_bdd.rb', line 142 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
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/conversion/sunstore_bdd.rb', line 149 def _delivery_add_xml_customer(delivery, xml_delivery) customer = Model::Party.new customer.role = 'Customer' _customer_add_party(customer, '1075', 'BillTo') xml_client = REXML::XPath.first(xml_delivery, 'client') id = _latin1(xml_client.attributes['number']) customer.add_id('ACC', id) ship_to = _customer_add_party(customer, id, 'ShipTo') if(xml_header = REXML::XPath.first(xml_delivery, 'orderHeader')) name = Model::Name.new # The SunStore formant does not specify which part of the Delivery-Address # contains the customer's name. We're just guessing it might be in the first # line. if(xml_name = REXML::XPath.first(xml_header, 'deliveryAddress')) name.text = _latin1(xml_name.attributes['line1']) 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
174 175 176 177 178 |
# File 'lib/conversion/sunstore_bdd.rb', line 174 def _delivery_add_xml_header(delivery, xml_delivery) xml_order = REXML::XPath.first(xml_delivery, 'orderHeader') delivery.add_id('Customer', _latin1(xml_order.attributes['referenceNumber'])) _delivery_add_xml_customer(delivery, xml_delivery) end |
._delivery_add_xml_item(delivery, xml_item) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/conversion/sunstore_bdd.rb', line 179 def _delivery_add_xml_item(delivery, xml_item) item = Model::DeliveryItem.new item.line_no = _latin1(delivery.items.size.next.to_s) if(xml_pcode = REXML::XPath.first(xml_item, 'EAN')) item.add_id('ET-Nummer', _latin1(xml_pcode.attributes['id'])) end if(xml_pcode = REXML::XPath.first(xml_item, 'pharmaCode')) item.add_id('Pharmacode', _latin1(xml_pcode.attributes['id'])) end xml_qty = xml_item.attributes['orderQuantity'] \ || xml_item.attributes['defaultOrderQuantity'] item.qty = _latin1(xml_qty) item.unit = 'PCE' delivery.add_item(item) end |
._latin1(str) ⇒ Object
209 210 211 212 213 |
# File 'lib/conversion/sunstore_bdd.rb', line 209 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
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/conversion/sunstore_bdd.rb', line 194 def _party_add_xml_address(party, xml_header) if(xml_address = REXML::XPath.first(xml_header, 'deliveryAddress')) address = Model::Address.new address.zip_code = _latin1(xml_address.attributes['line5PostalCode']) address.city = _latin1(xml_address.attributes['line5City']) if(xml_lines = REXML::XPath.first(xml_address, 'addressLine2And3Text')) address.add_line(_latin1(xml_lines.attributes['line2'])) address.add_line(_latin1(xml_lines.attributes['line3'])) end if(line = xml_address.attributes['line4']) address.add_line(_latin1(line)) end party.address = address end end |
._utf8(str) ⇒ Object
214 215 216 217 218 |
# File 'lib/conversion/sunstore_bdd.rb', line 214 def _utf8(str) Iconv.iconv('UTF-8//TRANSLIT//IGNORE', 'ISO-8859-1', str).first.strip rescue str end |
.convert(xml_document) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/conversion/sunstore_bdd.rb', line 19 def convert(xml_document) bdd = Model::Bdd.new bsr = Model::Bsr.new _bsr_add_customer_id(bsr, 'YWESEESS') bdd.bsr = bsr REXML::XPath.each(xml_document, '//customerOrder') do |xml_delivery| _bdd_add_xml_delivery(bdd, xml_delivery) end bdd end |
.parse(xml_src) ⇒ Object
29 30 31 |
# File 'lib/conversion/sunstore_bdd.rb', line 29 def parse(xml_src) REXML::Document.new(xml_src) end |
.respond(transaction, responses) ⇒ Object
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/conversion/sunstore_bdd.rb', line 32 def respond(transaction, responses) doc = REXML::Document.new "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<customerOrderResponse xmlns=\"http://www.e-galexis.com/schemas/\"\nxmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\nxsi:schemaLocation=\"http://www.e-galexis.com/schemas/ http://www.e-galexis.com/schemas/POS/customerOrder/customerOrderResponse.xsd\"\nversion=\"1.0\" roundUpForCondition=\"false\" backLogDesired=\"false\"\nlanguage=\"de\" productDescriptionDesired=\"false\">\n</customerOrderResponse>\n EOS\n root = doc.root\n transaction.model.deliveries.each_with_index do |delivery, idx|\n if data = responses[idx]\n number = if(order_id = data[:order_id])\n _utf8 order_id\n else\n \"error-\#{transaction.transaction_id}-\#{idx}\"\n end\n root.add_element('clientResponse').add_attribute('number', number)\n if data[:products].compact.size == delivery.items.size\n header = root.add_element 'orderHeaderResponse'\n header.add_attribute 'referenceNumber', _utf8(delivery.customer_id)\n if ship_to = delivery.customer.ship_to\n attrs = { 'line1' => _utf8(ship_to.name.text) }\n attrs2 = {}\n if addr = ship_to.address\n addr.lines.each_with_index do |line, idx|\n line = _utf8 line\n case idx\n when 0\n attrs2.store 'line2', line\n when 1\n attrs2.store 'line3', line\n when 2\n attrs.store 'line4', line\n end\n end\n attrs.store 'line5PostalCode', _utf8(addr.zip_code)\n attrs.store 'line5City', _utf8(addr.city)\n end\n address = header.add_element 'deliveryAddress'\n address.add_attributes attrs\n unless attrs2.empty?\n line2 = address.add_element 'addressLine2And3Text'\n line2.add_attributes attrs2\n end\n end\n lines = root.add_element 'orderLinesResponse'\n delivery.items.each_with_index do |item, idx|\n presp = data[:products][idx]\n available = presp[:quantity] == presp[:deliverable]\n attrs = {\n 'lineAccepted' => _boolean(available),\n 'backLogLine' => _boolean(presp[:backorder]),\n 'roundUpForConditionDone' => 'false',\n 'productReplaced' => 'false',\n }\n prod = lines.add_element 'productOrderLineResponse'\n prod.add_attributes attrs\n pol = prod.add_element 'productOrderLine'\n pol.add_attribute 'orderQuantity', item.qty\n if pcode = item.pharmacode_id\n pol.add_element('pharmaCode').add_attribute('id', pcode)\n end\n if ean = item.et_nummer_id\n pol.add_element('EAN').add_attribute('id', ean)\n end\n attrs = {\n 'wholesalerProductCode' => presp[:article_number],\n 'description' => presp[:description],\n }\n presp = prod.add_element 'productResponse'\n presp.add_attributes attrs\n prod.add_element 'availability',\n 'status' => available ? 'yes' : 'no'\n end\n else\n root.add_element 'orderHeaderErrorResponse'\n end\n else\n root.add_element 'clientErrorResponse'\n end\n end\n doc\nend\n" |