xmlconv 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.0.1 / 23.02.2011
2
+
3
+ * Export Feature added
4
+
5
+ * Added the possibility to export the orders from the database via bin/admin
6
+
1
7
  === 1.0.0 / 23.02.2011
2
8
 
3
9
  * 1 major enhancement
data/Manifest.txt ADDED
@@ -0,0 +1,94 @@
1
+ History.txt
2
+ LICENSE
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/admin
7
+ bin/xmlconvd
8
+ data/grammar/i2.grammar
9
+ lib/xmlconv.rb
10
+ lib/xmlconv/config.rb
11
+ lib/xmlconv/custom/lookandfeel.rb
12
+ lib/xmlconv/i2/address.rb
13
+ lib/xmlconv/i2/date.rb
14
+ lib/xmlconv/i2/document.rb
15
+ lib/xmlconv/i2/header.rb
16
+ lib/xmlconv/i2/order.rb
17
+ lib/xmlconv/i2/parser.rb
18
+ lib/xmlconv/i2/position.rb
19
+ lib/xmlconv/i2/record.rb
20
+ lib/xmlconv/model/address.rb
21
+ lib/xmlconv/model/agreement.rb
22
+ lib/xmlconv/model/bdd.rb
23
+ lib/xmlconv/model/bsr.rb
24
+ lib/xmlconv/model/delivery.rb
25
+ lib/xmlconv/model/delivery_item.rb
26
+ lib/xmlconv/model/document.rb
27
+ lib/xmlconv/model/freetext_container.rb
28
+ lib/xmlconv/model/id_container.rb
29
+ lib/xmlconv/model/invoice.rb
30
+ lib/xmlconv/model/invoice_item.rb
31
+ lib/xmlconv/model/item.rb
32
+ lib/xmlconv/model/item_container.rb
33
+ lib/xmlconv/model/name.rb
34
+ lib/xmlconv/model/part_info.rb
35
+ lib/xmlconv/model/part_info_container.rb
36
+ lib/xmlconv/model/party.rb
37
+ lib/xmlconv/model/party_container.rb
38
+ lib/xmlconv/model/price.rb
39
+ lib/xmlconv/model/price_container.rb
40
+ lib/xmlconv/model/transaction.rb
41
+ lib/xmlconv/state/global.rb
42
+ lib/xmlconv/state/global_predefine.rb
43
+ lib/xmlconv/state/login.rb
44
+ lib/xmlconv/state/transaction.rb
45
+ lib/xmlconv/state/transactions.rb
46
+ lib/xmlconv/util/application.rb
47
+ lib/xmlconv/util/autoload.rb
48
+ lib/xmlconv/util/destination.rb
49
+ lib/xmlconv/util/invoicer.rb
50
+ lib/xmlconv/util/known_user.rb
51
+ lib/xmlconv/util/mail.rb
52
+ lib/xmlconv/util/polling_manager.rb
53
+ lib/xmlconv/util/session.rb
54
+ lib/xmlconv/util/transaction.rb
55
+ lib/xmlconv/util/validator.rb
56
+ lib/xmlconv/view/foot.rb
57
+ lib/xmlconv/view/head.rb
58
+ lib/xmlconv/view/login.rb
59
+ lib/xmlconv/view/navigation.rb
60
+ lib/xmlconv/view/navigationlink.rb
61
+ lib/xmlconv/view/pager.rb
62
+ lib/xmlconv/view/preformatted.rb
63
+ lib/xmlconv/view/template.rb
64
+ lib/xmlconv/view/transaction.rb
65
+ lib/xmlconv/view/transactions.rb
66
+ test/config.rb
67
+ test/mock.rb
68
+ test/suite.rb
69
+ test/test_i2/address.rb
70
+ test/test_i2/date.rb
71
+ test/test_i2/document.rb
72
+ test/test_i2/header.rb
73
+ test/test_i2/order.rb
74
+ test/test_i2/parser.rb
75
+ test/test_i2/position.rb
76
+ test/test_model/address.rb
77
+ test/test_model/agreement.rb
78
+ test/test_model/bdd.rb
79
+ test/test_model/bsr.rb
80
+ test/test_model/delivery.rb
81
+ test/test_model/delivery_item.rb
82
+ test/test_model/freetext_container.rb
83
+ test/test_model/invoice.rb
84
+ test/test_model/invoice_item.rb
85
+ test/test_model/name.rb
86
+ test/test_model/part_info.rb
87
+ test/test_model/party.rb
88
+ test/test_model/price.rb
89
+ test/test_util/application.rb
90
+ test/test_util/destination.rb
91
+ test/test_util/invoicer.rb
92
+ test/test_util/polling_manager.rb
93
+ test/test_util/transaction.rb
94
+ xmlconv_convert.rb
data/bin/admin CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
+ # Admin -- xmlconv -- 24.02.2011 -- mhatakeyama@ywesee.com
2
3
  # Admin -- xmlconv -- 09.07.2003 -- hwyss@ywesee.com
3
4
 
4
5
  $: << File.expand_path('..', File.dirname(__FILE__))
5
6
  $: << File.expand_path('../src', File.dirname(__FILE__))
7
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
6
8
 
7
9
  require 'xmlconv/util/application'
8
10
  require 'xmlconv/config'
@@ -19,7 +21,10 @@ Kernel.trap('INT') {
19
21
  end
20
22
  }
21
23
 
22
- domain = XmlConv::CONFIG.domain
24
+ domain = 'ch.xmlconv'
25
+ if XmlConv::CONFIG.respond_to?(:domain)
26
+ domain = XmlConv::CONFIG.domain
27
+ end
23
28
  $0 = "#{domain} (Admin-Tool)"
24
29
  prompt = "#{domain}> "
25
30
 
data/lib/xmlconv.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Version
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -10,6 +10,7 @@ require 'xmlconv/util/transaction'
10
10
  require 'xmlconv/util/validator'
11
11
  require 'thread'
12
12
  require 'odba'
13
+ require 'xmlconv/model/bdd'
13
14
 
14
15
  module XmlConv
15
16
  module Util
@@ -68,6 +69,17 @@ module XmlConv
68
69
  time_range.include?(trans.commit_time)
69
70
  }
70
71
  Util::Invoicer.run(time_range, transactions, date)
72
+ end
73
+ def export_orders(first=Time.local(1990,1,1), last=Time.local(2037,1,1), output_file=nil)
74
+ range=Range.new(first, last)
75
+ output_file ||= "/home/ywesee/xmlconv_export/xmlconv_export.csv"
76
+ open(output_file, "w") do |f|
77
+ self.transactions.reverse.each do |t|
78
+ if range.include?(t.commit_time)
79
+ f.print t.output
80
+ end
81
+ end
82
+ end
71
83
  end
72
84
  end
73
85
  end
@@ -140,3 +152,4 @@ class XmlConvApp < SBSM::DRbServer
140
152
  }
141
153
  end
142
154
  end
155
+
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # XmlConv::TestApplication -- xmlconv -- 24.02.2011 -- mhatakeya@ywesee.com
2
3
  # XmlConv::TestApplication -- xmlconv2 -- 07.06.2004 -- hwyss@ywesee.com
3
4
 
4
5
  $: << File.dirname(__FILE__)
@@ -8,6 +9,7 @@ $: << File.expand_path('../../lib', File.dirname(__FILE__))
8
9
  require 'test/unit'
9
10
  require 'xmlconv/util/application'
10
11
  require 'mock'
12
+ require 'flexmock'
11
13
 
12
14
  module XmlConv
13
15
  module Conversion
@@ -22,6 +24,7 @@ module XmlConv
22
24
  end
23
25
  module Util
24
26
  class TestApplication < Test::Unit::TestCase
27
+ include FlexMock::TestCase
25
28
  def setup
26
29
  @app = Util::Application.new
27
30
  @app.init
@@ -163,6 +166,16 @@ module XmlConv
163
166
  trans2.__verify
164
167
  trans3.__verify
165
168
  end
169
+ def test_exprort_orders
170
+ transaction = flexmock('transaction') do |trans|
171
+ trans.should_receive(:commit_time).and_return(Time.local(2010,1,1))
172
+ trans.should_receive(:output).and_return('output')
173
+ end
174
+ @app.transactions.push(transaction)
175
+ temp = Tempfile.new('test_export_order')
176
+ assert_equal([transaction], @app.export_orders(Time.local(2009,1,1), Time.local(2011,1,1), temp.path))
177
+ temp.close
178
+ end
166
179
  end
167
180
  end
168
181
  end
@@ -319,6 +319,7 @@ module XmlConv
319
319
  assert_equal('ftp://xmlconv.ywesee.com:21/foo/bar/', uri.to_s)
320
320
  end
321
321
  end
322
+ =begin
322
323
  class TestDestinationSftp < Test::Unit::TestCase
323
324
  include FlexMock::TestCase
324
325
  def setup
@@ -411,5 +412,6 @@ module XmlConv
411
412
  assert_equal('sftp://xmlconv.ywesee.com/foo/bar/', uri.to_s)
412
413
  end
413
414
  end
415
+ =end
414
416
  end
415
417
  end
@@ -0,0 +1,150 @@
1
+ # /usr/bin/env ruby
2
+ # xmlconv.converter.rb -- 24.02.2011 -- mhatakeyama@ywesee.com
3
+
4
+ def usage
5
+ print <<EOF
6
+ usage:
7
+ ruby #{__FILE__} -i [input file]
8
+
9
+ options:
10
+ -i [input file] (default: input.csv)
11
+ -o [output file] (default: output.csv)
12
+ -k [Kunden file] (default: Kunden.txt)
13
+ -a [Artikel file](default: Artikel.txt)
14
+ -h help
15
+ EOF
16
+ exit
17
+ end
18
+
19
+ # Analyze options
20
+ if ARGV[0] == '-h'
21
+ usage
22
+ end
23
+ begin
24
+ options = Hash[*ARGV]
25
+ rescue ArgumentError
26
+ usage
27
+ end
28
+ input_file = options['-i'] ||= 'input.csv'
29
+ output_file = options['-o'] ||= 'output.csv'
30
+ kunden_file = options['-k'] ||= 'Kunden.txt'
31
+ artikel_file = options['-a'] ||= 'Artikel.txt'
32
+
33
+ unless File.exist?(input_file)
34
+ print "Input file (#{input_file}) could not found.\n\n"
35
+ usage
36
+ end
37
+ unless File.exist?(kunden_file)
38
+ print "Kunden.txt (#{kunden_file}) could not found.\n\n"
39
+ usage
40
+ end
41
+ unless File.exist?(artikel_file)
42
+ print "Atrikel.txt (#{artikel_file}) cannot be found.\n\n"
43
+ usage
44
+ end
45
+
46
+ # Sort by date
47
+ lines = []
48
+ File.readlines(input_file).each do |line|
49
+ x = line.split(/,/)
50
+ date = x[2].match(/(\d\d)(\d\d)(20\d\d)/).to_a
51
+ new_date = date[3] + date[2] + date[1]
52
+ x[2] = new_date
53
+ lines << x.join(',')
54
+ end
55
+ lines.sort!.reverse!
56
+
57
+ # Load Kunden.txt and Artikel.txt
58
+ kunden = [{}, {}]
59
+ File.readlines(kunden_file).each do |line|
60
+ x = line.split(/\t/)
61
+ #print x[0], ",", x[1], ",", x[6], "\n"
62
+ kunden[0][x[0]] = x[6]
63
+ kunden[1][x[1]] = x[6]
64
+ end
65
+
66
+ artikel = [{}, {}]
67
+ price = [{}, {}]
68
+ File.readlines(artikel_file).each do |line|
69
+ x = line.split(/\t/)
70
+ #print x[4], ",", x[3], ",", x[2], "\n"
71
+ artikel[0][x[4]] = x[2]
72
+ artikel[1][x[3]] = x[2]
73
+ #print x[5], "\n"
74
+ price[0][x[4]] = x[5]
75
+ price[1][x[3]] = x[5]
76
+ end
77
+
78
+ # Add Kunden and Artikel info
79
+ kunden_missing_list = []
80
+ artikel_missing_list = []
81
+ last = 0
82
+ open(output_file, "w") do |out|
83
+ # Header
84
+ out.print "Kundennr., Kunde, Artikelnr., EAN Code, Produkt, Menge, Preis, Bestelldatum\n"
85
+ lines.each_with_index do |line,i|
86
+ x = line.split(/,/)
87
+
88
+ # Search Kunden Name
89
+ kunden_name = ""
90
+ kunden.each do |k|
91
+ if k.keys.include?(x[1])
92
+ kunden_name = k[x[1]]
93
+ break
94
+ end
95
+ end
96
+ if kunden_name == "" or kunden_name == nil
97
+ kunden_missing_list << x[1]
98
+ # warn "Kunden ID (#{x[1]}) could not be found."
99
+ end
100
+
101
+ # Search Produkt Name
102
+ artikel_name = ""
103
+ artikel.each do |a|
104
+ if a.keys.include?(x[4])
105
+ artikel_name = a[x[4]]
106
+ break
107
+ end
108
+ end
109
+ if artikel_name == "" or artikel_name == nil
110
+ artikel_missing_list << x[4]
111
+ # warn "Artikel ID (#{x[4]}) could not be found."
112
+ end
113
+
114
+ # Calc price
115
+ total_price = 0.0
116
+ price.each do |pr|
117
+ if pr.keys.include?(x[4])
118
+ total_price = pr[x[4]].to_f * x[7].to_f
119
+ break
120
+ end
121
+ end
122
+
123
+ # Output
124
+ x.map!{|z| z || ""}
125
+ artikel_name ||=""
126
+ kunden_name ||=""
127
+ total_price ||=""
128
+ out.print x[1] + ",\"" + kunden_name + "\"," +\
129
+ x[4] + "," + x[5] + ",\"" + artikel_name + "\"," + \
130
+ x[7] + "," + total_price.to_s + "," + x[2] + "\n"
131
+
132
+ if last != (i*10)/lines.length
133
+ last = (i*10)/lines.length
134
+ $stderr.print "."
135
+ end
136
+ end
137
+ end
138
+ $stderr.print "done.\n\n"
139
+
140
+ # Report missing numbers
141
+ unless kunden_missing_list.empty?
142
+ print "The following Kunden IDs were not found:\n"
143
+ print kunden_missing_list.uniq.sort.join(","), "\n\n"
144
+ end
145
+ unless artikel_missing_list.empty?
146
+ print "The following Artikel IDs were not found:\n"
147
+ print artikel_missing_list.uniq.sort.join(","), "\n\n"
148
+ end
149
+
150
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmlconv
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Masaomi Hatakeyama, Zeno R.R. Davatz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-23 00:00:00 +01:00
18
+ date: 2011-02-24 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -44,10 +44,12 @@ extensions: []
44
44
 
45
45
  extra_rdoc_files:
46
46
  - History.txt
47
+ - Manifest.txt
47
48
  - README.txt
48
49
  files:
49
50
  - History.txt
50
51
  - LICENSE
52
+ - Manifest.txt
51
53
  - README.txt
52
54
  - Rakefile
53
55
  - bin/admin
@@ -138,6 +140,7 @@ files:
138
140
  - test/test_util/invoicer.rb
139
141
  - test/test_util/polling_manager.rb
140
142
  - test/test_util/transaction.rb
143
+ - xmlconv_convert.rb
141
144
  - .gemtest
142
145
  has_rdoc: true
143
146
  homepage: http://scm.ywesee.com/?p=xmlconv/.git;a=summary