gem-order-layout-infarma 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-infarma.rb +147 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c21781dd5c4ef369d7a93ab74f1c8f013916d1e0e03d7ffbd3bc0c58a3909b5c
4
+ data.tar.gz: a808c7271997ba3cc63c505bb4bfee6fbb99b8f3678b46a94dbdaf99dccb088c
5
+ SHA512:
6
+ metadata.gz: b253db40a52d0df99c124078bfc715550dd9a3385a795ddb80dc8c4e6e393d19a718fde8d84957099f5a1704badd51c5b066b2f8a51e2a106f9cde83d05254b0
7
+ data.tar.gz: ab76ce3e1b4211f4bd1db17f02d9997c40551c6e42decb69208052ee796fc2b916aac05dda9a48a7064aa7430ab39c5137989f9ccb67202717df9a8b1af443f8
@@ -0,0 +1,147 @@
1
+ require 'date'
2
+ require 'net/ftp'
3
+
4
+ module OrderLayout
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
+ #===================
115
+ #=Cria arquivo .ped
116
+ #===================
117
+ def self.create_order_file order
118
+
119
+ today = DateTime.now
120
+ date = "#{today.year}#{"%02i" % today.month}#{"%02i" % today.day}"
121
+
122
+ create_folder directory_name = "public/orders"
123
+ create_folder directory_name = "#{directory_name}/#{date}"
124
+ create_folder directory_name = "#{directory_name}/#{$codCliente}"
125
+
126
+ out_file = File.new("#{directory_name = "#{directory_name}/#{today.strftime("%Y%m%d")}#{"%09i" % $codClient}#{"%04i" % $numOrder}.PED"}", "w")
127
+ out_file.puts("01#{'%-6s' % 1.02}#{$clientCnpjOrder}#{"%06i" % $codClient}#{"%09i" % $numOrder}#{date}#{"%02i" % today.hour}#{"%02i" % today.min}#{"%04i" % $marketingPolicyId}#{"%03i" % $deadlineId.to_i}#{$establishmentCnpj.to_s}")
128
+ out_file.puts("02[#{$currentUserName}: *#{$comment}*]") # 40
129
+
130
+ total = 0
131
+ total_units = 0
132
+ OrderItems.where("order_id = ?", order.id).each do |item|
133
+ total += 1
134
+ total_units += item.quantity
135
+ out_file.puts("031#{"%013i" % item.product_id}#{"%07i" % item.quantity}00#{"%04i" % item.marketing_policy_id}")
136
+ end
137
+
138
+ out_file.puts("09#{"%04i" % total}#{"%08i" % total_units}00")
139
+ out_file.close
140
+
141
+ send_ftp directory_name
142
+
143
+ end
144
+
145
+ end
146
+
147
+
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-order-layout-infarma
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-infarma.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-infarma infarma
44
+ test_files: []