Eancom::Definition.create(name: 'd96a', type: :desadv) do |document, config| document.envelope do |envelope| envelope.segment "UNA:+.? '" envelope.segment "UNB" do |segment| segment.composite "UNOC:3" segment.composite "#{config.sender_iln}:14" segment.composite "#{config.receiver_iln}:14" segment.composite Time.now.strftime("%y%m%d:%H%M") segment.composite "#{config.build_id}" segment.composite segment.composite "DESADV" segment.composite segment.composite segment.composite "EANCOM" end end document.message "UHN" do |message| # Message ID message.composite "1" # Message ID message.composite "DESADV:D:96A:UN:EAN005" message.segment "BGM" do |segment| segment.composite "351" segment.composite "#{config.delivery_note_id}" segment.composite "9" end # Document Date message.segment "DTM" do |segment| segment.composite "137:#{Time.now.strftime("%Y%m%d")}:102" end # Shipping Date message.segment "DTM" do |segment| segment.composite "11:#{Time.now.strftime("%Y%m%d")}:102" end # Order Reference message.segment "RFF" do |segment| segment.composite "VN:#{config.order_id}" end # Sender ILN message.segment "NAD" do |segment| segment.composite "SU" segment.composite "#{config.sender_iln}::9" end # Manufacturer ILN message.segment "NAD" do |segment| segment.composite "MF" segment.composite "#{config.sender_iln}::9" end # Reciver ILN message.segment "NAD" do |segment| segment.composite "BY" segment.composite "#{config.receiver_iln}::9" end # Destination ILN message.segment "NAD" do |segment| segment.composite "DP" segment.composite "#{config.receiver_iln}::9" end # Final Recipient ILN message.segment "NAD" do |segment| segment.composite "UC" segment.composite "#{config.receiver_iln}::9" end # Delivery Note Mode message.segment "CPS" do |segment| segment.composite "1" end # Items total_quantity = 0 config.items.each_with_index do |item, index| total_quantity += item.quantity.to_i message.segment "LIN" do |segment| segment.composite "#{index+1}" segment.composite segment.composite "#{item.ean}:EN" end message.segment "QTY" do |segment| segment.composite "12:#{item.quantity}:PCE" end end # Total Quantity message.segment "CNT" do |segment| segment.composite "1:#{total_quantity}" end # Position Count message.segment "CNT" do |segment| segment.composite "2:#{config.items.count}" end end end