oddb2xml 2.1.7 → 2.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,7 +34,7 @@ module Oddb2xml
34
34
  'VALID_DATE' => Time.new.strftime('%FT%T%z'),
35
35
  }
36
36
  class Builder
37
- attr_accessor :subject, :index, :items, :flags, :lppvs,
37
+ attr_accessor :subject, :refdata, :items, :flags, :lppvs,
38
38
  :actions, :migel, :orphans, :fridges,
39
39
  :infos, :packs, :infos_zur_rose,
40
40
  :ean14, :tag_suffix,
@@ -43,8 +43,8 @@ module Oddb2xml
43
43
  def initialize(args = {})
44
44
  @options = args
45
45
  @subject = nil
46
- @index = {}
47
- @items = {}
46
+ @refdata = {}
47
+ @items = {} # Items from Preparations.xml in BAG, using GTINs as key
48
48
  @flags = {}
49
49
  @lppvs = {}
50
50
  @infos = {}
@@ -83,60 +83,44 @@ module Oddb2xml
83
83
  def prepare_articles(reset=false)
84
84
  @articles = nil if reset
85
85
  unless @articles
86
- Oddb2xml.log("prepare_articles starting with #{@articles ? @articles.size : 'no'} articles")
87
- @articles = [] # base is 'DE'
88
- @index['DE'].each_pair do |phar, indices|
89
- obj = {
90
- :de => indices,
91
- :fr => @index['FR'][phar],
92
- }
93
- if migel = @migel[phar]
86
+ Oddb2xml.log("prepare_articles starting with #{@articles ? @articles.size : 'no'} articles.")
87
+ @articles = []
88
+ @refdata.each do |ean13, obj|
89
+ if migel = @migel[ean13]
94
90
  # delete duplicates
95
- @migel[phar] = nil
91
+ @migel[ean13] = nil
96
92
  end
97
- if seq = @items[phar]
93
+ if seq = @items[obj[:ean]]
98
94
  obj[:seq] = seq
99
95
  end
100
96
  @articles << obj
101
- @pharmacode[phar] = obj
97
+ @pharmacode[obj[:pharmacode]] = obj
102
98
  end
103
99
  # add
104
100
  @migel.values.compact.each do |migel|
105
101
  next if migel[:pharmacode].empty?
106
- obj = {}
107
- %w[de fr].each do |lang|
108
- entry = {
109
- :ean => migel[:ean],
110
- :pharmacode => migel[:pharmacode],
111
- :stat_date => '',
112
- :lang => lang.capitalize,
113
- :desc => migel["desc_#{lang}".intern],
114
- :atc_code => '',
115
- :additional_desc => migel[:additional_desc],
116
- :company_ean => migel[:company_ean],
117
- :company_name => migel[:company_name],
118
- :migel => true,
119
- }
120
- obj[lang.intern] = [entry]
121
- end
122
- @articles << obj
102
+ entry = {
103
+ :ean => migel[:ean],
104
+ :pharmacode => migel[:pharmacode],
105
+ :stat_date => '',
106
+ :desc_de => migel[:desc_de],
107
+ :desc_fr => migel[:desc_fr],
108
+ :atc_code => '',
109
+ :quantity => migel[:quantity],
110
+ :company_ean => migel[:company_ean],
111
+ :company_name => migel[:company_name],
112
+ :migel => true,
113
+ }
114
+ @articles << entry
123
115
  end
124
116
  nrAdded = 0
125
117
  if @options[:extended]
126
- Oddb2xml.log("prepare_articles prepare_local_index")
127
- local_index = {}
128
- %w[de fr].each { |lang| local_index[lang] = {} }
129
- %w[de fr].each {
130
- |lang|
131
- @articles.each{|article|
132
- ean = article[lang.intern][0][:ean]
133
- next if ean == nil or ean.to_i == 0
134
- local_index[lang][ean] = article
135
- }
136
- }
137
- Oddb2xml.log("prepare_articles extended")
118
+ Oddb2xml.log("prepare_articles extended prepare_local_index having already #{@articles.size} articles")
119
+ nrItems = 0
138
120
  @infos_zur_rose.each{
139
121
  |ean13, info|
122
+ nrItems += 1
123
+ Oddb2xml.log("prepare_articles: nrItems #{nrItems} nrAdded #{nrAdded} prices. Total #{@articles.size}") if nrItems % 100 == 0
140
124
  pharmacode = info[:pharmacode]
141
125
  if @pharmacode[pharmacode]
142
126
  @pharmacode[pharmacode][:price] = info[:price]
@@ -145,31 +129,31 @@ module Oddb2xml
145
129
  end
146
130
  obj = {}
147
131
  found = false
148
- %w[de fr].each do |lang|
149
- # existing = @articles.find{|art| art[lang.intern] and art[lang.intern][0][:ean] == ean13 }
150
-
151
- existing = local_index[lang][ean13]
152
- if existing
153
- found = true
154
- existing[:price] = info[:price]
155
- existing[:pub_price] = info[:pub_price]
132
+ existing = @refdata.values.find{ |x| x[:ean].eql? ean13 }
133
+ if existing
134
+ found = true
135
+ existing[:price] = info[:price]
136
+ existing[:pub_price] = info[:pub_price]
137
+ else
138
+ entry = {
139
+ :desc => info[:description],
140
+ :desc_de => info[:description],
141
+ :status => info[:status] == '3' ? 'I' : 'A', # from ZurRose, we got 1,2 or 3 means aktive, aka available in trade
142
+ :atc_code => '',
143
+ :ean => ean13,
144
+ :pharmacode => pharmacode,
145
+ :price => info[:price],
146
+ :pub_price => info[:pub_price],
147
+ :type => info[:type],
148
+ }
149
+ if pharmacode
150
+ @refdata[pharmacode] = entry
156
151
  else
157
- entry = {
158
- :desc => info[:description],
159
- :status => info[:status] == '3' ? 'I' : 'A', # from ZurRose, we got 1,2 or 3 means aktive, aka available in trade
160
- :atc_code => '',
161
- :ean => ean13,
162
- :lang => lang.capitalize,
163
- :pharmacode => pharmacode,
164
- :price => info[:price],
165
- :pub_price => info[:pub_price],
166
- :type => info[:type],
167
- }
168
- obj[lang.intern] = [entry]
169
- @index[lang.upcase][ean13] = entry
152
+ @refdata[ean13] = entry
170
153
  end
154
+ obj = entry
171
155
  end
172
- unless found
156
+ if not found and obj.size > 0
173
157
  @articles << obj
174
158
  nrAdded += 1
175
159
  end
@@ -234,47 +218,41 @@ module Oddb2xml
234
218
  def prepare_products
235
219
  unless @products
236
220
  @products = []
237
- @index['DE'].each_pair do |phar, indices|
238
- indices.each_with_index do |index, i|
239
- next if index and index.is_a?(Hash) and index[:atc_code] and /^Q/i.match(index[:atc_code])
240
- obj = {
241
- :seq => @items[phar] ? @items[phar] : @items[index[:ean]],
242
- :pac => nil,
243
- :no8 => nil,
244
- :de => index,
245
- :fr => @index['FR'][phar][i],
246
- :st => index[:status],
247
- # swissINDEX and Packungen.xls(if swissINDEX does not have EAN)
248
- :ean => index[:ean],
249
- :atc => index[:atc_code],
250
- :ith => '',
251
- :siz => '',
252
- :eht => '',
253
- :sub => '',
254
- :comp => '',
255
- }
256
- if obj[:ean] # via EAN-Code
257
- obj[:no8] = obj[:ean][4..11]
258
- end
259
- if obj[:no8] and ppac = @packs[obj[:no8].intern] and # Packungen.xls
260
- !ppac[:is_tier]
261
- # If swissINDEX does not have EAN
262
- if obj[:ean].nil? or obj[:ean].empty?
263
- obj[:ean] = ppac[:ean].to_s
264
- end
265
- # If swissINDEX dose not have ATC-Code
266
- if obj[:atc].nil? or obj[:atc].empty?
267
- obj[:atc] = ppac[:atc_code].to_s
268
- end
269
- obj[:ith] = ppac[:ith_swissmedic]
270
- obj[:siz] = ppac[:package_size]
271
- obj[:eht] = ppac[:einheit_swissmedic]
272
- obj[:sub] = ppac[:substance_swissmedic]
273
- obj[:comp] = ppac[:composition_swissmedic]
221
+ @refdata.each_pair do |ean13, item|
222
+ next if item and item.is_a?(Hash) and item[:atc_code] and /^Q/i.match(item[:atc_code])
223
+ obj = {
224
+ :seq => @items[ean13] ? @items[ean13] : @items[item[:ean]],
225
+ :pac => nil,
226
+ :no8 => nil,
227
+ :ean => item[:ean],
228
+ :atc => item[:atc_code],
229
+ :ith => '',
230
+ :siz => '',
231
+ :eht => '',
232
+ :sub => '',
233
+ :comp => '',
234
+ }
235
+ if obj[:ean] # via EAN-Code
236
+ obj[:no8] = obj[:ean][4..11]
237
+ end
238
+ if obj[:no8] and ppac = @packs[obj[:no8].intern] and # Packungen.xls
239
+ !ppac[:is_tier]
240
+ # If RefData does not have EAN
241
+ if obj[:ean].nil? or obj[:ean].empty?
242
+ obj[:ean] = ppac[:ean].to_s
274
243
  end
275
- if obj[:ean][0..3] == '7680'
276
- @products << obj
244
+ # If RefData dose not have ATC-Code
245
+ if obj[:atc].nil? or obj[:atc].empty?
246
+ obj[:atc] = ppac[:atc_code].to_s
277
247
  end
248
+ obj[:ith] = ppac[:ith_swissmedic]
249
+ obj[:siz] = ppac[:package_size]
250
+ obj[:eht] = ppac[:einheit_swissmedic]
251
+ obj[:sub] = ppac[:substance_swissmedic]
252
+ obj[:comp] = ppac[:composition_swissmedic]
253
+ end
254
+ if obj[:ean][0..3] == '7680'
255
+ @products << obj
278
256
  end
279
257
  end
280
258
  end
@@ -477,13 +455,13 @@ module Oddb2xml
477
455
  @missing.each do |obj|
478
456
  next if /^Q/i.match(obj[:atc])
479
457
  length += 1
480
- xml.PRD('DT' => '') {
458
+ xml.PRD('DT' => obj[:last_change]) {
481
459
  ean = obj[:ean].to_s
482
460
  xml.GTIN ean
483
- xml.PRODNO obj[:prodno] if obj[:prodno] and obj[:prodno].empty?
461
+ xml.PRODNO obj[:prodno] if obj[:prodno]
484
462
  xml.DSCRD obj[:sequence_name] if obj[:sequence_name]
485
463
  xml.DSCRF obj[:sequence_name] if obj[:sequence_name]
486
- xml.ATC obj[:atc_code] if obj[:atc_code]
464
+ xml.ATC obj[:atc_code] if obj[:atc_code] and !obj[:atc_code].empty?
487
465
  xml.IT obj[:ith_swissmedic] if obj[:ith_swissmedic]
488
466
  xml.CPT
489
467
  xml.PackGrSwissmedic obj[:package_size] if obj[:package_size]
@@ -492,11 +470,12 @@ module Oddb2xml
492
470
  xml.CompositionSwissmedic obj[:composition_swissmedic] if obj[:composition_swissmedic]
493
471
  }
494
472
  end
473
+ @products.sort! { |a,b| a[:ean] <=> b[:ean] }
495
474
  @products.each do |obj|
496
475
  next if /^Q/i.match(obj[:atc])
497
476
  seq = obj[:seq]
498
477
  length += 1
499
- xml.PRD('DT' => '') {
478
+ xml.PRD('DT' => obj[:last_change]) {
500
479
  ean = obj[:ean].to_s
501
480
  xml.GTIN ean
502
481
  ppac = ((_ppac = @packs[ean[4..11].intern] and !_ppac[:is_tier]) ? _ppac : {})
@@ -750,193 +729,196 @@ module Oddb2xml
750
729
  xml.doc.tag_suffix = @tag_suffix
751
730
  datetime = Time.new.strftime('%FT%T%z')
752
731
  xml.ARTICLE(XML_OPTIONS) {
732
+ @articles.sort! { |a,b| a[:ean] <=> b[:ean] }
753
733
  @articles.each do |obj|
754
- idx += 1
755
- Oddb2xml.log "build_article #{idx} of #{@articles.size} articles" if idx % 500 == 0
756
- obj[:de].each_with_index do |de_idx, i|
757
- fr_idx = obj[:fr][i] # swissindex FR
758
- pac,no8 = nil,de_idx[:ean][4..11] # BAG-XML(SL/LS)
759
- pack_info = nil
760
- pack_info = @packs[no8.intern] if no8 # info from Packungen.xlsx from swissmedic_info
761
- ppac = nil # Packungen
762
- ean = de_idx[:ean]
763
- next if pack_info and /Tierarzneimittel/.match(pack_info[:list_code])
764
- next if de_idx[:desc] and /ad us vet/i.match(de_idx[:desc])
734
+ idx += 1
735
+ Oddb2xml.log "build_article #{idx} of #{@articles.size} articles" if idx % 500 == 0
736
+ item = @items[obj[:ean]]
737
+ pac,no8 = nil,obj[:ean][4..11] # BAG-XML(SL/LS)
738
+ pack_info = nil
739
+ pack_info = @packs[no8.intern] if no8 # info from Packungen.xlsx from swissmedic_info
740
+ ppac = nil # Packungen
741
+ ean = obj[:ean]
742
+ next if pack_info and /Tierarzneimittel/.match(pack_info[:list_code])
743
+ next if obj[:desc_de] and /ad us vet/i.match(obj[:desc_de])
765
744
 
766
- pharma_code = de_idx[:pharmacode]
767
- ean = nil if ean.match(/^000000/)
768
- if obj[:seq]
769
- pac = obj[:seq][:packages][de_idx[:pharmacode]]
770
- pac = obj[:seq][:packages][ean] unless pac
771
- else
772
- pac = @items[ean][:packages][ean] if @items and ean and @items[ean] and @items[ean][:packages]
745
+ pharma_code = obj[:pharmacode]
746
+ ean = nil if ean.match(/^000000/)
747
+ if obj[:seq]
748
+ pac = obj[:seq][:packages][obj[:pharmacode]]
749
+ pac = obj[:seq][:packages][ean] unless pac
750
+ else
751
+ pac = @items[ean][:packages][ean] if @items and ean and @items[ean] and @items[ean][:packages]
752
+ end
753
+ if no8
754
+ ppac = ((_ppac = pack_info and !_ppac[:is_tier]) ? _ppac : nil)
755
+ end
756
+ info_zur_rose = nil
757
+ if !@infos_zur_rose.empty? && ean && @infos_zur_rose[ean]
758
+ info_zur_rose = @infos_zur_rose[ean] # zurrose
759
+ end
760
+ xml.ART('DT' => obj[:last_change] ? obj[:last_change] : '') {
761
+ xml.REF_DATA (obj[:refdata] || @migel[pharma_code]) ? '1' : '0'
762
+ xml.PHAR obj[:pharmacode] unless obj[:pharmacode].empty?
763
+ #xml.GRPCD
764
+ #xml.CDS01
765
+ #xml.CDS02
766
+ if ppac
767
+ xml.SMCAT ppac[:swissmedic_category] unless ppac[:swissmedic_category].empty?
773
768
  end
774
- if no8
775
- ppac = ((_ppac = pack_info and !_ppac[:is_tier]) ? _ppac : nil)
769
+ if no8 and !no8.to_s.empty?
770
+ if ean and ean[0..3] == "7680"
771
+ xml.SMNO no8.to_s
772
+ end
776
773
  end
777
- info_zur_rose = nil
778
- if !@infos_zur_rose.empty? && ean && @infos_zur_rose[ean]
779
- info_zur_rose = @infos_zur_rose[ean] # zurrose
774
+ if ppac
775
+ xml.PRODNO ppac[:prodno] if ppac[:prodno] and !ppac[:prodno].empty?
776
+ end
777
+ #xml.HOSPCD
778
+ #xml.CLINCD
779
+ #xml.ARTTYP
780
+ if info_zur_rose
781
+ xml.VAT info_zur_rose[:vat]
780
782
  end
781
- xml.ART('DT' => '') {
782
- xml.REF_DATA (de_idx[:refdata] || @migel[pharma_code]) ? '1' : '0'
783
- xml.PHAR de_idx[:pharmacode] unless de_idx[:pharmacode].empty?
784
- #xml.GRPCD
785
- #xml.CDS01
786
- #xml.CDS02
787
- if ppac
788
- xml.SMCAT ppac[:swissmedic_category] unless ppac[:swissmedic_category].empty?
789
- end
790
- if no8 and !no8.to_s.empty?
791
- if ean and ean[0..3] == "7680"
792
- xml.SMNO no8.to_s
793
- end
794
- end
795
- if ppac
796
- xml.PRODNO ppac[:prodno] if ppac[:prodno] and !ppac[:prodno].empty?
797
- end
798
- #xml.HOSPCD
799
- #xml.CLINCD
800
- #xml.ARTTYP
801
- if info_zur_rose
802
- xml.VAT info_zur_rose[:vat]
803
- end
804
783
 
805
- nincd = detect_nincd(de_idx)
806
- (nincd and nincd == 13) ? xml.SALECD('A') : xml.SALECD( (info_zur_rose && info_zur_rose[:cmut] != '3') ? 'A' : 'I') # XML_OPTIONS
807
- if pac and pac[:limitation_points]
808
- #xml.INSLIM
809
- xml.LIMPTS pac[:limitation_points] unless pac[:limitation_points].empty?
810
- end
811
- #xml.GRDFR
812
- if no8 and !no8.empty? and
813
- no8.to_s =~ /(\d{5})(\d{3})/
814
- xml.COOL 1 if @fridges.include?($1.to_s)
815
- end
816
- #xml.TEMP
817
- if ean and not ean.empty?
818
- flag = @flags[ean]
819
- # as same flag
820
- xml.CDBG(flag ? 'Y' : 'N')
821
- xml.BG(flag ? 'Y' : 'N')
822
- end
823
- #xml.EXP
824
- xml.QTY de_idx[:additional_desc] if de_idx[:additional_desc] and not de_idx[:additional_desc].empty?
825
- xml.DSCRD de_idx[:desc] if de_idx[:desc] and not de_idx[:desc].empty?
826
- xml.DSCRF fr_idx[:desc] if fr_idx[:desc] and not fr_idx[:desc].empty?
827
- xml.SORTD de_idx[:desc].upcase if de_idx[:desc] and not de_idx[:desc].empty?
828
- xml.SORTF fr_idx[:desc].upcase if fr_idx[:desc] and not fr_idx[:desc].empty?
829
- #xml.QTYUD
830
- #xml.QTYUF
831
- #xml.IMG
832
- #xml.IMG2
833
- #xml.PCKTYPD
834
- #xml.PCKTYPF
835
- #xml.MULT
836
- if obj[:seq]
837
- xml.SYN1D obj[:seq][:name_de] unless obj[:seq][:name_de].empty?
838
- xml.SYN1F obj[:seq][:name_fr] unless obj[:seq][:name_fr].empty?
839
- end
840
- if obj[:seq]
841
- case obj[:seq][:deductible]
842
- when 'Y'; xml.SLOPLUS 1; # 20%
843
- when 'N'; xml.SLOPLUS 2; # 10%
844
- else xml.SLOPLUS '' # k.A.
845
- end
846
- end
847
- #xml.NOPCS
848
- #xml.HSCD
849
- #xml.MINI
850
- #xml.DEPCD
851
- #xml.DEPOT
852
- #xml.BAGSL
853
- #xml.BAGSLC
854
- #xml.LOACD
855
- if de_idx[:stat_date]
856
- xml.OUTSAL de_idx[:stat_date] if de_idx[:stat_date] and not de_idx[:stat_date].empty?
857
- end
858
- #xml.STTOX
859
- #xml.NOTI
860
- #xml.GGL
861
- #xml.CE
862
- #xml.SMDAT
863
- #xml.SMCDAT
864
- #xml.SIST
865
- #xml.ESIST
866
- #xml.BIOCID
867
- #xml.BAGNO
868
- #xml.LIGHT
869
- #xml.DEL
870
- xml.ARTCOMP {
871
- # use ean13(gln) as COMPNO
872
- xml.COMPNO de_idx[:company_ean] if de_idx[:company_ean] and not de_idx[:company_ean].empty?
873
- #xml.ROLE
874
- #xml.ARTNO1
875
- #xml.ARTNO2
876
- #xml.ARTNO3
877
- }
878
- xml.ARTBAR {
879
- xml.CDTYP 'E13'
880
- xml.BC ean
881
- xml.BCSTAT 'A' # P is alternative
882
- #xml.PHAR2
883
- } if ean and not ean.empty?
884
- #xml.ARTCH {
885
- #xml.PHAR2
886
- #xml.CHTYPE
887
- #xml.LINENO
888
- #xml.NOUNITS
889
- #}
890
- if pac and pac[:prices]
891
- pac[:prices].each_pair do |key, price|
892
- xml.ARTPRI {
893
- xml.VDAT price[:valid_date] unless price[:valid_date].empty?
894
- xml.PTYP price[:price_code] unless price[:price_code].empty?
895
- xml.PRICE price[:price] unless price[:price].empty?
896
- }
897
- end
784
+ nincd = detect_nincd(obj)
785
+ (nincd and nincd == 13) ? xml.SALECD('A') : xml.SALECD( (info_zur_rose && info_zur_rose[:cmut] != '3') ? 'A' : 'I') # XML_OPTIONS
786
+ if pac and pac[:limitation_points]
787
+ #xml.INSLIM
788
+ xml.LIMPTS pac[:limitation_points] unless pac[:limitation_points].empty?
789
+ end
790
+ #xml.GRDFR
791
+ if no8 and !no8.empty? and
792
+ no8.to_s =~ /(\d{5})(\d{3})/
793
+ xml.COOL 1 if @fridges.include?($1.to_s)
794
+ end
795
+ #xml.TEMP
796
+ if ean and not ean.empty?
797
+ flag = @flags[ean]
798
+ # as same flag
799
+ xml.CDBG(flag ? 'Y' : 'N')
800
+ xml.BG(flag ? 'Y' : 'N')
801
+ end
802
+ #xml.EXP
803
+ if item and item[:substances] and substance = item[:substances].first
804
+ xml.QTY "#{substance[:quantity]}#{substance[:unit] ? ' ' + substance[:unit] : ''}"
805
+ end if false # TODO: get qty/unit from refdata name
806
+ xml.DSCRD obj[:desc_de] if obj[:desc_de] and not obj[:desc_de].empty?
807
+ xml.DSCRF obj[:desc_fr] if obj[:desc_fr] and not obj[:desc_fr].empty?
808
+ xml.DSCRF obj[:desc_de] if !obj[:desc_fr] or obj[:desc_fr].empty?
809
+ xml.SORTD obj[:desc_de].upcase if obj[:desc_de] and not obj[:desc_de].empty?
810
+ xml.SORTF obj[:desc_fr].upcase if obj[:desc_fr] and not obj[:desc_fr].empty?
811
+ xml.SORTF obj[:desc_de].upcase if !obj[:desc_fr] or obj[:desc_fr].empty?
812
+ #xml.QTYUD
813
+ #xml.QTYUF
814
+ #xml.IMG
815
+ #xml.IMG2
816
+ #xml.PCKTYPD
817
+ #xml.PCKTYPF
818
+ #xml.MULT
819
+ if obj[:seq]
820
+ xml.SYN1D obj[:seq][:name_de] unless obj[:seq][:name_de].empty?
821
+ xml.SYN1F obj[:seq][:name_fr] unless obj[:seq][:name_fr].empty?
822
+ end
823
+ if obj[:seq]
824
+ case obj[:seq][:deductible]
825
+ when 'Y'; xml.SLOPLUS 1; # 20%
826
+ when 'N'; xml.SLOPLUS 2; # 10%
827
+ else xml.SLOPLUS '' # k.A.
898
828
  end
899
- if info_zur_rose
900
- price = info_zur_rose[:price]
901
- vdat = Time.parse(datetime).strftime("%d.%m.%Y")
902
- xml.ARTPRI {
903
- xml.VDAT vdat
904
- xml.PTYP "ZURROSE"
905
- xml.PRICE price
906
- }
829
+ end
830
+ #xml.NOPCS
831
+ #xml.HSCD
832
+ #xml.MINI
833
+ #xml.DEPCD
834
+ #xml.DEPOT
835
+ #xml.BAGSL
836
+ #xml.BAGSLC
837
+ #xml.LOACD
838
+ if obj[:stat_date]
839
+ xml.OUTSAL obj[:stat_date] if obj[:stat_date] and not obj[:stat_date].empty?
840
+ end
841
+ #xml.STTOX
842
+ #xml.NOTI
843
+ #xml.GGL
844
+ #xml.CE
845
+ #xml.SMDAT
846
+ #xml.SMCDAT
847
+ #xml.SIST
848
+ #xml.ESIST
849
+ #xml.BIOCID
850
+ #xml.BAGNO
851
+ #xml.LIGHT
852
+ #xml.DEL
853
+ xml.ARTCOMP {
854
+ # use ean13(gln) as COMPNO
855
+ xml.COMPNO obj[:company_ean] if obj[:company_ean] and not obj[:company_ean].empty?
856
+ #xml.ROLE
857
+ #xml.ARTNO1
858
+ #xml.ARTNO2
859
+ #xml.ARTNO3
860
+ }
861
+ xml.ARTBAR {
862
+ xml.CDTYP 'E13'
863
+ xml.BC /^9999/.match(ean) ? 0 : ean
864
+ xml.BCSTAT 'A' # P is alternative
865
+ #xml.PHAR2
866
+ } if ean and not ean.empty?
867
+ #xml.ARTCH {
868
+ #xml.PHAR2
869
+ #xml.CHTYPE
870
+ #xml.LINENO
871
+ #xml.NOUNITS
872
+ #}
873
+ if pac and pac[:prices]
874
+ pac[:prices].each_pair do |key, price|
907
875
  xml.ARTPRI {
908
- xml.VDAT vdat
909
- xml.PTYP "ZURROSEPUB"
910
- xml.PRICE info_zur_rose[:pub_price]
876
+ xml.VDAT price[:valid_date] unless price[:valid_date].empty?
877
+ xml.PTYP price[:price_code] unless price[:price_code].empty?
878
+ xml.PRICE price[:price] unless price[:price].empty?
911
879
  }
912
- xml.ARTPRI {
913
- xml.VDAT vdat
914
- xml.PTYP "RESELLERPUB"
915
- xml.PRICE (price.to_f*(1 + (@options[:percent].to_f/100))).round_by(0.05).round(2)
916
- } if @options[:percent] != nil
917
880
  end
918
- #xml.ARTMIG {
881
+ end
882
+ if info_zur_rose
883
+ price = info_zur_rose[:price]
884
+ vdat = Time.parse(datetime).strftime("%d.%m.%Y")
885
+ xml.ARTPRI {
886
+ xml.VDAT vdat
887
+ xml.PTYP "ZURROSE"
888
+ xml.PRICE price
889
+ }
890
+ xml.ARTPRI {
891
+ xml.VDAT vdat
892
+ xml.PTYP "ZURROSEPUB"
893
+ xml.PRICE info_zur_rose[:pub_price]
894
+ }
895
+ xml.ARTPRI {
896
+ xml.VDAT vdat
897
+ xml.PTYP "RESELLERPUB"
898
+ xml.PRICE (price.to_f*(1 + (@options[:percent].to_f/100))).round_by(0.05).round(2)
899
+ } if @options[:percent] != nil
900
+ end
901
+ #xml.ARTMIG {
902
+ #xml.VDAT
903
+ #xml.MIGCD
904
+ #xml.LINENO
905
+ #}
906
+ #xml.ARTDAN {
907
+ #xml.CDTYP
908
+ #xml.LINENO
909
+ #xml.CDVAL
910
+ #}
911
+ #xml.ARTLIM {
912
+ # xml.LIMCD
913
+ #}
914
+ if nincd
915
+ xml.ARTINS {
919
916
  #xml.VDAT
920
- #xml.MIGCD
921
- #xml.LINENO
922
- #}
923
- #xml.ARTDAN {
924
- #xml.CDTYP
925
- #xml.LINENO
926
- #xml.CDVAL
927
- #}
928
- #xml.ARTLIM {
929
- # xml.LIMCD
930
- #}
931
- if nincd
932
- xml.ARTINS {
933
- #xml.VDAT
934
- #xml.INCD
935
- xml.NINCD nincd
936
- }
937
- end
938
- }
939
- end if obj[:de]
917
+ #xml.INCD
918
+ xml.NINCD nincd
919
+ }
920
+ end
921
+ }
940
922
  end
941
923
  xml.RESULT {
942
924
  xml.OK_ERROR 'OK'
@@ -1170,16 +1152,15 @@ module Oddb2xml
1170
1152
  prepare_articles
1171
1153
  rows = []
1172
1154
  @articles.each do |obj|
1173
- obj[:de].each_with_index do |idx, i|
1174
- ean = idx[:ean]
1155
+ ean = obj[:ean]
1175
1156
  next if ((ean.to_s.length != 13) and !ean14)
1176
- next if idx[:type] == :nonpharma
1157
+ next if obj[:type] == :nonpharma
1177
1158
  row = ''
1178
1159
  pack_info = nil
1179
1160
  # Oddb2tdat.parse
1180
1161
  pac,no8 = nil,nil
1181
1162
  if obj[:seq] and obj[:seq][:packages]
1182
- pac = obj[:seq][:packages][idx[:pharmacode]]
1163
+ pac = obj[:seq][:packages][obj[:pharmacode]]
1183
1164
  pac = obj[:seq][:packages][ean] unless pac
1184
1165
  else
1185
1166
  pac = @items[ean][:packages][ean] if @items and @items[ean] and @items[ean][:packages]
@@ -1200,11 +1181,11 @@ module Oddb2xml
1200
1181
  else
1201
1182
  row << '1'
1202
1183
  end
1203
- row << "%0#{DAT_LEN[:PHAR]}d" % idx[:pharmacode].to_i
1184
+ row << "%0#{DAT_LEN[:PHAR]}d" % obj[:pharmacode].to_i
1204
1185
  abez = ( # de name
1205
- idx[:desc].to_s + " " +
1186
+ obj[:desc_de].to_s + " " +
1206
1187
  (pac ? pac[:name_de].to_s : '') +
1207
- (idx[:additional_desc] ? idx[:additional_desc] : '')
1188
+ (obj[:quantity] ? obj[:quantity] : '')
1208
1189
  ).gsub(/"/, '')
1209
1190
  if @infos_zur_rose[ean]
1210
1191
  price_exf = sprintf('%06i', ((@infos_zur_rose[ean][:price].to_f)*100).to_i)
@@ -1251,7 +1232,6 @@ module Oddb2xml
1251
1232
  row << "%0#{DAT_LEN[:CEAN]}d" % (ean.match(/^000000/) ? 0 : ean.to_i)
1252
1233
  row << "%#{DAT_LEN[:CMWS]}s" % '2' # pharma
1253
1234
  rows << row
1254
- end
1255
1235
  end
1256
1236
  rows.join("\n")
1257
1237
  end
@@ -1260,20 +1240,19 @@ module Oddb2xml
1260
1240
  prepare_articles(reset)
1261
1241
  rows = []
1262
1242
  @articles.each do |obj|
1263
- obj[:de].each_with_index do |idx, i|
1264
1243
  row = ''
1265
- next if ((idx[:ean].to_s.length != 13) and !ean14)
1244
+ next if ((obj[:ean].to_s.length != 13) and !ean14)
1266
1245
  # Oddb2tdat.parse_migel
1267
1246
  row << "%#{DAT_LEN[:RECA]}s" % '11'
1268
- row << "%#{DAT_LEN[:CMUT]}s" % if (phar = idx[:pharmacode] and phar.size > 3)
1247
+ row << "%#{DAT_LEN[:CMUT]}s" % if (phar = obj[:pharmacode] and phar.size > 3)
1269
1248
  '1'
1270
1249
  else
1271
1250
  '3'
1272
1251
  end
1273
- row << "%0#{DAT_LEN[:PHAR]}d" % idx[:pharmacode].to_i
1252
+ row << "%0#{DAT_LEN[:PHAR]}d" % obj[:pharmacode].to_i
1274
1253
  abez = ( # de name
1275
- idx[:desc].to_s + " " +
1276
- (idx[:additional_desc] ? idx[:additional_desc] : '')
1254
+ obj[:desc_de].to_s + " " +
1255
+ (obj[:quantity] ? obj[:quantity] : '')
1277
1256
  ).gsub(/"/, '')
1278
1257
  row << format_name(abez)
1279
1258
  row << "%#{DAT_LEN[:PRMO]}s" % ('0' * DAT_LEN[:PRMO])
@@ -1283,11 +1262,10 @@ module Oddb2xml
1283
1262
  row << "%#{DAT_LEN[:CBGG]}s" % '0'
1284
1263
  row << "%#{DAT_LEN[:CIKS]}s" % ' ' # no category
1285
1264
  row << "%0#{DAT_LEN[:ITHE]}d" % 0
1286
- row << idx[:ean].to_s.rjust(DAT_LEN[:CEAN], '0')
1265
+ row << obj[:ean].to_s.rjust(DAT_LEN[:CEAN], '0')
1287
1266
  row << "%#{DAT_LEN[:CMWS]}s" % '1' # nonpharma
1288
1267
  rows << row
1289
1268
  end
1290
- end
1291
1269
  rows.join("\n")
1292
1270
  end
1293
1271
  end