gem-order-layout-trier 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/gem-order-layout-trier.rb +260 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1c30426a0f9592ac0e1d8cbf559f6e1c0cca4ca9752549eac4200dd6ef37e2a9
4
+ data.tar.gz: e14f6ffad61cc93e85cf35aff56d5c18bd3d2a40b0ae596793b15c9293b2ce83
5
+ SHA512:
6
+ metadata.gz: 660a0e282678896d8274abdd3f34e1d1c29760a7bed479287b0d9ceea928205e671a6cd12d0c838c5c200b49275707b179f6072e2c51c8db8f5c55c0dc3885d3
7
+ data.tar.gz: 483c57bf7ba3759aeb2d4fda00b32dcbf052f2be13cd81190e49c6e6623e1604ad968096975fc8dd7156a2c34994ee686037ea6411cbf5ee67b410f647e9e4ea
@@ -0,0 +1,260 @@
1
+ require 'date'
2
+ require 'net/ftp'
3
+
4
+ module OrderLayoutTrier
5
+
6
+ $ftp_url = ''
7
+ $ftp_port = 0
8
+ $ftp_user = ''
9
+ $ftp_password = ''
10
+ $ftp_passive = false
11
+ $codClient = 0
12
+ $numOrder = 0
13
+ $clientCnpjOrder = 0
14
+ $currentUserName = ''
15
+ $establishmentCnpj = 0
16
+ $comment = ''
17
+ $marketingPolicyId = 0
18
+ $deadlineId = 0
19
+
20
+ def self.set_connect ftp_url, ftp_port
21
+ $ftp_url = ftp_url #Rails.application.config.ftp_url
22
+ $ftp_port = ftp_port #Rails.application.config.ftp_port
23
+ end
24
+
25
+ def self.set_login user, password
26
+ $ftp_user = user #Rails.application.config.ftp_user
27
+ $ftp_password = password #ails.application.config.ftp_password
28
+ end
29
+
30
+ def self.set_ftp_passive isPassive
31
+ $ftp_passive = isPassive # Rails.application.config.ftp_passive
32
+ end
33
+
34
+ def self.set_establishmentCnpj establishmentCnpj
35
+ $establishmentCnpj = establishmentCnpj
36
+ end
37
+
38
+ def self.set_codClient codClient
39
+ $codClient = codClient
40
+ end
41
+
42
+ def self.set_numOrder numOrder
43
+ $numOrder = numOrder
44
+ end
45
+
46
+ def self.set_clientCnpjOrder clientCnpjOrder
47
+ $clientCnpjOrder = clientCnpjOrder
48
+ end
49
+
50
+ def self.set_currentUserName currentUserName
51
+ $currentUserName = currentUserName
52
+ end
53
+
54
+ def self.set_comment comment
55
+ $comment = comment
56
+ end
57
+
58
+ def self.set_marketingPolicyId marketingPolicyId
59
+ $marketingPolicyId = marketingPolicyId
60
+ end
61
+
62
+ def self.set_deadlineId deadlineId
63
+ $deadlineId = deadlineId
64
+ end
65
+
66
+ def self.set_totalOrders totalOrders
67
+ $totalOrders = totalOrders
68
+ end
69
+
70
+ def self.set_totalUnits totalUnits
71
+ $totalUnits = totalUnits
72
+ end
73
+
74
+ #===========================
75
+ #=cria pasta, se não existir
76
+ #===========================
77
+ def self.create_folder directory_name
78
+ Dir.mkdir(directory_name) unless File.exists?(directory_name)
79
+ end
80
+
81
+ #=============================================
82
+ #=Envia pedido via FTP para Pedido Eletrônico
83
+ #=============================================
84
+ def self.send_ftp directory_name
85
+
86
+ # new(host = nil, user = nil, passwd = nil, acct = nil)
87
+ # Creates and returns a new FTP object. If a host is given, a connection is made.
88
+ # Additionally, if the user is given, the given user name, password, and (optionally) account are used to log in.
89
+ ftp = Net::FTP.new(false)
90
+
91
+ # connect(host, port = FTP_PORT)
92
+ # Establishes an FTP connection to host, optionally overriding the default port.
93
+ ftp.connect($ftp_url, $ftp_port)
94
+
95
+ # login(user = "anonymous", passwd = nil, acct = nil)
96
+ # string “anonymous” and the password is nil, a password of user@host is synthesized.
97
+ # If the acct parameter is not nil, an FTP ACCT command is sent following the successful login.
98
+ #ftp.login(Rails.application.config.ftp_user, Rails.application.config.ftp_password)
99
+ ftp.login($ftp_user, $ftp_password)
100
+
101
+ #When true, the connection is in passive mode. Default: false.
102
+ #ftp.passive = Rails.application.config.ftp_passive
103
+ ftp.passive = $ftp_passive
104
+
105
+ #Changes the (remote) directory.
106
+ ftp.chdir('/ped')
107
+
108
+ ftp.put(directory_name)
109
+ ftp.close
110
+
111
+ end
112
+
113
+ #========================
114
+ #= Ler arquivo de pedido
115
+ #========================
116
+ def self.read_order txt
117
+ header = {}
118
+ details = []
119
+ trailer = {}
120
+
121
+ txt.each_line do |line|
122
+ if line[0] == '1' # Header
123
+ header = {
124
+ register_type: line[0],
125
+ client_code: line[1...16],
126
+ order_number: line[16...28],
127
+ order_date: line[28...36],
128
+ purchase_type: line[36],
129
+ return_type: line[37],
130
+ business_condition_pointer: line[38...44],
131
+ free_field: line[44...94]
132
+ }
133
+ elsif line[0] == '2' # Detalhe
134
+ details << {
135
+ register_type: line[0],
136
+ order_number: line[1...13],
137
+ product_code: line[13...26],
138
+ amount: line[26...31],
139
+ discount: line[31...36].insert(-3, '.').to_f
140
+ }
141
+ else # Trailer
142
+ trailer = {
143
+ register_type: line[0],
144
+ order_number: line[1...13],
145
+ number_of_units: line[13...18],
146
+ number_of_items: line[18...28]
147
+ }
148
+ end
149
+ end
150
+
151
+ { header: header, details: details, trailer: trailer }
152
+ end
153
+
154
+ #=====================================
155
+ #= Ler arquivo de pedido (versao 0.4)
156
+ #=====================================
157
+ def self.read_order_v040 txt
158
+ {
159
+ layout_identification: txt[0...2],
160
+ client_code: txt[2...10],
161
+ reserved_number: txt[10...20],
162
+ product_barcode: txt[20...33],
163
+ quantity_demanded: txt[33...38],
164
+ payment_terms: txt[38...41],
165
+ negotiation_date: txt[41...49],
166
+ order_number: txt[49...59],
167
+ provider_uf: txt[59...61],
168
+ affiliate_code: txt[61...65],
169
+ client_uf: txt[65...67],
170
+ reserved: txt[67...114],
171
+ sequential_number: txt[114...120]
172
+ }
173
+ end
174
+
175
+ def self.read_order_file(text:, version: '')
176
+ if version == '0.4'
177
+ response_hash = read_order_v040 text
178
+ else
179
+ response_hash = read_order text
180
+ end
181
+ response_hash
182
+ end
183
+
184
+ #=========================
185
+ #= Ler arquivo de retorno
186
+ #=========================
187
+ def self.read_return txt
188
+ header = {}
189
+ details = []
190
+ trailer = {}
191
+
192
+ txt.each_line do |line|
193
+ if line[0] == '1' # Header
194
+ header = {
195
+ register_type: line[0],
196
+ cnpj: line[1...16],
197
+ order_number: line[16...28],
198
+ processing_date: line[28...36],
199
+ processing_hour: line[36...44],
200
+ order_number_distributor: line[44...56],
201
+ reason_code: line[56...59],
202
+ reason_description: line[59...109],
203
+ free_field: line[109...159]
204
+ }
205
+ elsif line[0] == '2' # Detalhe
206
+ details << {
207
+ register_type: line[0],
208
+ product_code: line[1...14],
209
+ order_numer: line[14...26],
210
+ payment_term: line[26],
211
+ number_of_served: line[27...32],
212
+ discount: line[32...37],
213
+ granted: line[37...40],
214
+ number_of_not_served: line[40...45],
215
+ reason_code: line[45...48],
216
+ reason_description: line[48...98]
217
+ }
218
+ else # Trailer
219
+ trailer = {
220
+ register_type: line[0],
221
+ order_number: line[1...13],
222
+ number_of_lines: line[13...18],
223
+ number_of_served_items: line[18...23],
224
+ number_of_not_served_items: line[23...28]
225
+ }
226
+ end
227
+ end
228
+
229
+ { header: header, details: details, trailer: trailer }
230
+ end
231
+
232
+ #======================================
233
+ #= Ler arquivo de retorno (versao 0.4)
234
+ #======================================
235
+ def self.read_return_v040 txt
236
+ {
237
+ layout_identification: txt[0...2],
238
+ client_cod: txt[2...10],
239
+ reserved_number: txt[10...20],
240
+ product_barcode: txt[20...33],
241
+ number_of_absences: txt[33...38],
242
+ absence_return_cod: txt[38...41],
243
+ absence_return_description: txt[41...81],
244
+ order_number: txt[81...91],
245
+ reserved: txt[91...134],
246
+ sequential_number: txt[134...140]
247
+ }
248
+ end
249
+
250
+
251
+ def self.read_return_file(text:, version: '')
252
+ if version == '0.4'
253
+ response_hash = read_return_v040 text
254
+ else
255
+ response_hash = read_return text
256
+ end
257
+ response_hash
258
+ end
259
+
260
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-order-layout-trier
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Infarma Sistemas - Equipe P&D
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gem to send order - infarma
14
+ email: leticia@infarma.com.br
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/gem-order-layout-trier.rb
20
+ homepage:
21
+ licenses:
22
+ - Nonstandard
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.7.7
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: gem-order-layout-trier infarma
44
+ test_files: []