rnsap 0.4.12 → 0.4.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b35aa190956b167918511e84b534034701cdea79ee940424591e60ed68a7d96
4
- data.tar.gz: 23a084ebde89a980aa0fe853441bce758aff0b38a95c6c5f7763eb1efd1c3120
3
+ metadata.gz: 518529f9e547d8d03ddb437b6d47c252f4308cf041ba4433abdca14c5b996e4a
4
+ data.tar.gz: 9386f9252f74b52f5a8c428829903492001b75db909f072021833d2e21121851
5
5
  SHA512:
6
- metadata.gz: 16f4f3ea24bcd5ba41a4b7286c452bbef39a62ed209cdaac55e04800d5ebf7cc2c38d8c41fa7fddb9db08513d03d72873147a9fcc6a051f26b81e0ab652272b7
7
- data.tar.gz: 643ac428662750cf029c6b1e69febfc9180cd9318e1014e1f13359d788c996014416429091db7c20766a9ed13065e1959f4d14fa734b5e6e02341488683b181b
6
+ metadata.gz: 7227e483f630884901000f031f846b97f24b4d9697362c534a29707dcb80cd0a95881bd16ce99165959f70e45a4b5eb65feb959048928b5f3408126222fd5fec
7
+ data.tar.gz: 60b5d19b5f5a3b0cfb4e21a1daddfcda9ce8c048496dfe3566236fc0ef4e8bf14b5525e4b55a84d83a59acc46fc7e2d2fb049450f96793632b908532f90e9216
data/lib/auth.rb ADDED
@@ -0,0 +1,131 @@
1
+ # Class to handle authorization related SAP information
2
+ # @author Rogerio Nascimento (26/03/2021)
3
+ class Auth
4
+
5
+ # Return a list of users with authorization
6
+ # for an object
7
+ # @param json containing authorization object and optionaly
8
+ # the tuples with field and value to be checked
9
+ # @return [Array] an array of strings with the list of users
10
+ def self.for_object(*options)
11
+ users = []
12
+ conn, obj, field1, value1, field2, value2 = validate_options(options)
13
+ return users unless conn && obj
14
+
15
+ ## Busca o AUTH na tabela UST12
16
+ ust12_list = Auth.auth_list(conn, obj, field1, value1, field2, value2)
17
+ return users unless ust12_list
18
+
19
+ ## Busca o PROFN na tabela UST10S
20
+ ust10s_list = Auth.profile_list(conn, obj, ust12_list)
21
+
22
+ ## Busca os Usuários na tabela UST04
23
+ Auth.user_list(conn, obj, ust10s_list)
24
+ end
25
+
26
+ #
27
+ # Select Authorization roles for the Profile
28
+ # @param list List of profiles to be searched
29
+ # @return Array<string> with list of authorizations
30
+ def self.profiles_for_composite(conn, list = [])
31
+ return [] if list.empty?
32
+
33
+ fname = conn.conn.get_function('SIAG_PROF_GET_AUTH')
34
+ fcall = fname.get_function_call
35
+
36
+ fcall[:IV_PROFILE_TYPE] = 'C'
37
+ list.each do |prof|
38
+ row = fcall[:IT_PROFILE_RANGE].new_row
39
+ row[:SIGN] = 'I'
40
+ row[:OPTION] = 'EQ'
41
+ row[:LOW] = prof
42
+ end
43
+
44
+ fcall.invoke
45
+
46
+ ret = []
47
+ fcall[:ET_COMPOSITE_PROFILE].each do |row|
48
+ ret.push(row[:SINGLE_PROFILE])
49
+ end
50
+
51
+ ret
52
+ end
53
+
54
+
55
+ private
56
+
57
+ def self.validate_options(options)
58
+ return [] if options.empty?
59
+ params = options.first
60
+
61
+ conn = params[:conn]
62
+ obj = params[:obj]
63
+
64
+ return [] unless conn && obj
65
+ return [] unless conn.class.name == 'RnSap::Sap'
66
+
67
+ field1 = params[:field1]
68
+ value1 = params[:value1]
69
+ field2 = params[:field2]
70
+ value2 = params[:value2]
71
+
72
+ [conn, obj, field1, value1, field2, value2]
73
+ end
74
+
75
+ def self.auth_list( conn, obj, field1, value1, field2, value2)
76
+
77
+ fields = ['AUTH']
78
+ filter = ["OBJCT = '#{obj}' "]
79
+ if field1 && value1
80
+ filter.push(" AND ( FIELD = '#{field1}' AND ( VON = '*' OR VON = '#{value1}' ) ")
81
+ if field2 && value2
82
+ filter.push(" OR FIELD = '#{field2}' AND ( VON = '*' OR VON = '#{value2}' ) )")
83
+ else
84
+ filter.push( ')')
85
+ end
86
+ end
87
+
88
+ conn.read_table('UST12', fields, filter)
89
+ end
90
+
91
+ def self.profile_list( conn, obj, ust12_list)
92
+ sap_all = 'SAP_ALL'
93
+ profiles = Auth.profiles_for_composite(conn, [sap_all])
94
+ profiles.push(sap_all)
95
+
96
+ fields = ['PROFN']
97
+ filter = ["OBJCT = '#{obj}' AND AUTH IN ("]
98
+ profiles.each do |prof|
99
+ filter.push( "'#{prof}' , ")
100
+ end
101
+ ust12_list.each do |ust|
102
+ filter.push( "'#{ust.auth}' , ")
103
+ end
104
+ filter = filter.uniq
105
+
106
+ new_last = "#{filter.last[0..(filter.last.length - 4)]} )"
107
+ filter = filter[0..-1].push(new_last)
108
+
109
+ conn.read_table('UST10S', fields, filter)
110
+ end
111
+
112
+ def self.user_list(conn, obj, ust10s_list)
113
+ users = []
114
+ fields = ['BNAME']
115
+ filter = ['PROFILE IN (']
116
+ filter.push("'SAP_ALL' , ")
117
+ ust10s_list.each do |ust|
118
+ filter.push("'#{ust.profn}' , ")
119
+ end
120
+ new_last = "#{filter.last[0..(filter.last.length - 4)]} )"
121
+ filter = filter[0..-1].push(new_last)
122
+
123
+ ust04_list = conn.read_table('UST04', fields, filter)
124
+
125
+ ust04_list.each do |ust|
126
+ users.push( ust.bname )
127
+ end
128
+
129
+ users.uniq.sort
130
+ end
131
+ end
data/lib/currency.rb ADDED
@@ -0,0 +1,35 @@
1
+ class Currency
2
+
3
+ def self.convert_amount_from_to(conn, amount, from_curr, to_curr, date)
4
+ convert_currency_amount({conn: conn, amount: amount, from_curr: from_curr, to_curr: to_curr, date: date})
5
+ end
6
+ def self.convert_currency_amount(*options)
7
+
8
+ return 0.0 unless options
9
+ return 0.0 unless options.class == Array
10
+
11
+ params = options.first
12
+
13
+ rate_type = params[:rate_type] ? params[:rate_type] : 'M'
14
+ date = params[:date] ? params[:date] : Date.today
15
+ conn = params[:conn]
16
+ from_curr = params[:from_curr]
17
+ to_curr = params[:to_curr]
18
+ amount = params[:amount]
19
+
20
+ return 0.0 unless (conn && from_curr && to_curr && amount)
21
+
22
+ fname = conn.conn.get_function('RPM_CONVERT_CURRENCY_AMOUNT')
23
+ fcall = fname.get_function_call
24
+
25
+ fcall[:IV_RATE_TYPE] = rate_type
26
+ fcall[:DATE] = date
27
+ fcall[:IV_FROM_CURR] = from_curr
28
+ fcall[:IV_TO_CURR] = to_curr
29
+ fcall[:IV_AMOUNT] = amount
30
+
31
+ fcall.invoke
32
+
33
+ fcall[:EV_AMOUNT].to_f
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ require 'preq_release_items/requisition_items'
@@ -0,0 +1,174 @@
1
+ class RequisitionItems
2
+ # @return [String] Purchase Requisition Number
3
+ attr_accessor :preq_no
4
+ # @return [Integer] Item number of purchase requisition
5
+ attr_accessor :preq_item
6
+ # @return [String] Purchase Requisition Document Type
7
+ attr_accessor :doc_type
8
+ # @return [String] Purchasing Group
9
+ attr_accessor :pur_group
10
+ # @return [String] Name of Person Who Created the Object
11
+ attr_accessor :created_by
12
+ # @return [String] Name of requisitioner/requester
13
+ attr_accessor :preq_name
14
+ # @return [Date] Requisition (Request) Date
15
+ attr_accessor :preq_date
16
+ # @return [String] Short Text
17
+ attr_accessor :short_text
18
+ # @return [String] Material Number
19
+ attr_accessor :material
20
+ # @return [String] Material number corresponding to manufacturer part number
21
+ attr_accessor :pur_mat
22
+ # @return [String] Plant
23
+ attr_accessor :plant
24
+ # @return [String] Storage Location
25
+ attr_accessor :store_loc
26
+ # @return [String] Requirement Tracking Number
27
+ attr_accessor :trackingno
28
+ # @return [String] Material Group
29
+ attr_accessor :mat_grp
30
+ # @return [String] Supplying (issuing) plant in case of stock transport order
31
+ attr_accessor :suppl_plnt
32
+ # @return [Float] Purchase requisition quantity
33
+ attr_accessor :quantity
34
+ # @return [Integer] Purchase requisition unit of measure
35
+ attr_accessor :unit
36
+ # @return [String] Date type (day, week, month, interval)
37
+ attr_accessor :del_datcat
38
+ # @return [Date] Item delivery date
39
+ attr_accessor :deliv_date
40
+ # @return [Date] Purchase Requisition Release Date
41
+ attr_accessor :rel_date
42
+ # @return [Float] Goods receipt processing time in days
43
+ attr_accessor :gr_pr_time
44
+ # @return [Float] Price in purchase requisition
45
+ attr_accessor :c_amt_bapi
46
+ # @return [Float] Price unit
47
+ attr_accessor :price_unit
48
+ # @return [String] Item category in purchasing document
49
+ attr_accessor :item_cat
50
+ # @return [String] Account Assignment Category
51
+ attr_accessor :acctasscat
52
+ # @return [String] Distribution indicator for multiple account assignment
53
+ attr_accessor :distrib
54
+ # @return [String] Partial invoice indicator
55
+ attr_accessor :part_inv
56
+ # @return [String] Goods Receipt Indicator
57
+ attr_accessor :gr_ind
58
+ # @return [String] Goods Receipt, Non-Valuated
59
+ attr_accessor :gr_non_val
60
+ # @return [String] Invoice receipt indicator
61
+ attr_accessor :ir_ind
62
+ # @return [String] Required Vendor
63
+ attr_accessor :des_vendor
64
+ # @return [String] Fixed vendor
65
+ attr_accessor :fixed_vend
66
+ # @return [String] Purchasing Organization
67
+ attr_accessor :purch_org
68
+ # @return [String] Number of principal purchase agreement
69
+ attr_accessor :agreement
70
+ # @return [Integer] Item number of principal purchase agreement
71
+ attr_accessor :agmt_item
72
+ # @return [String] Number of purchasing info record
73
+ attr_accessor :info_rec
74
+ # @return [String] Number of quota arrangement
75
+ attr_accessor :quota_arr
76
+ # @return [Integer] Quota arrangement item
77
+ attr_accessor :quotarritm
78
+ # @return [String] MRP Controller
79
+ attr_accessor :mrp_contr
80
+ # @return [String] BOM explosion number
81
+ attr_accessor :bomexpl_no
82
+ # @return [Date] Date of last resubmission
83
+ attr_accessor :last_resub
84
+ # @return [Float] Resubmission interval of purchase requisition
85
+ attr_accessor :resubmis
86
+ # @return [Float] Number of resubmissions
87
+ attr_accessor :no_resub
88
+ # @return [String] Valuation Type
89
+ attr_accessor :val_type
90
+ # @return [String] Special Stock Indicator
91
+ attr_accessor :spec_stock
92
+ # @return [Integer] Purchase Order Unit of Measure
93
+ attr_accessor :po_unit
94
+ # @return [String] Revision level
95
+ attr_accessor :rev_lev
96
+ # @return [Integer] Package number
97
+ attr_accessor :pckg_no
98
+ # @return [String] Kanban indicator
99
+ attr_accessor :kanban_ind
100
+ # @return [String] Use Requisition Price in Purchase Order
101
+ attr_accessor :po_price
102
+ # @return [Integer] Configuration (internal object number)
103
+ attr_accessor :int_obj_no
104
+ # @return [String] Promotion
105
+ attr_accessor :promotion
106
+ # @return [String] Batch Number
107
+ attr_accessor :batch
108
+ # @return [String] Material number used by vendor
109
+ attr_accessor :vend_mat
110
+ # @return [Float] Quantity ordered against this purchase requisition
111
+ attr_accessor :ordered
112
+ # @return [String] Currency Key
113
+ attr_accessor :currency
114
+ # @return [String] Mfr part profile
115
+ attr_accessor :manuf_prof
116
+ # @return [String] Manufacturer Part Number
117
+ attr_accessor :manu_mat
118
+ # @return [String] Manufacturer number
119
+ attr_accessor :mfr_no
120
+ # @return [String] External manufacturer code name or number
121
+ attr_accessor :mfr_no_ext
122
+ # @return [String] Category of delivery date
123
+ attr_accessor :del_datcat_ext
124
+ # @return [String] ISO Currency Code
125
+ attr_accessor :currency_iso
126
+ # @return [String] Item Category in Purchasing Document
127
+ attr_accessor :item_cat_ext
128
+ # @return [String] ISO code for unit of measure in purchase requisition
129
+ attr_accessor :preq_unit_iso
130
+ # @return [String] Order unit in ISO code
131
+ attr_accessor :po_unit_iso
132
+ # @return [String] Overall release of purchase requisitions
133
+ attr_accessor :general_release
134
+ # @return [String] Long Material Number for MATERIAL Field
135
+ attr_accessor :material_external
136
+ # @return [String] External GUID for MATERIAL Field
137
+ attr_accessor :material_guid
138
+ # @return [String] Version Number for MATERIAL Field
139
+ attr_accessor :material_version
140
+ # @return [String] Long Material Number for PUR_MAT Field
141
+ attr_accessor :pur_mat_external
142
+ # @return [String] External GUID for PUR_MAT Field
143
+ attr_accessor :pur_mat_guid
144
+ # @return [String] Version Number for PUR_MAT Field
145
+ attr_accessor :pur_mat_version
146
+ # @return [String] Purchase Requisition Blocked
147
+ attr_accessor :req_blocked
148
+ # @return [String] Reason for Item Block
149
+ attr_accessor :reason_blocking
150
+ # @return [String] Procuring Plant
151
+ attr_accessor :procuring_plant
152
+ # @return [String] Commitment Item
153
+ attr_accessor :cmmt_item
154
+ # @return [String] Funds Center
155
+ attr_accessor :funds_ctr
156
+ # @return [String] Fund
157
+ attr_accessor :fund
158
+ # @return [String] Document number for earmarked funds
159
+ attr_accessor :res_doc
160
+ # @return [Integer] Earmarked Funds: Document Item
161
+ attr_accessor :res_item
162
+ # @return [String] Functional Area
163
+ attr_accessor :func_area
164
+ # @return [String] Grant
165
+ attr_accessor :grant_nbr
166
+ # @return [String] Obsolete
167
+ attr_accessor :fund_long
168
+ # @return [String] FM: Budget Period
169
+ attr_accessor :budget_period
170
+ # @return [String] Material Number (40 Characters, needed f. technical reasons)
171
+ attr_accessor :material_long
172
+ # @return [String] Material number corresponding to MPN (technically required)
173
+ attr_accessor :pur_mat_long
174
+ end
data/lib/rnsap.rb CHANGED
@@ -2,11 +2,14 @@
2
2
 
3
3
  require 'nwrfc'
4
4
  require 'read_table/table_column'
5
+ require 'auth'
6
+ require 'currency'
5
7
 
6
8
  require 'return'
7
9
 
8
10
  require 'preq_detail/all'
9
11
  require 'preq_release_info/all'
12
+ require 'preq_release_items/all'
10
13
 
11
14
  require 'po_detail/all'
12
15
  require 'po_release_info/all'
@@ -161,6 +164,7 @@ module RnSap
161
164
  value = wa[pos].to_f
162
165
  eval("obj.#{field} = #{value}")
163
166
  elsif DATE_TYPES.include?(column.type)
167
+ value = wa[pos]
164
168
  if value.nil? || value == '00000000'
165
169
  eval("obj.#{field} = nil")
166
170
  else
@@ -298,6 +302,29 @@ module RnSap
298
302
  end
299
303
  end
300
304
 
305
+ def preq_release_items(group = '', code = '')
306
+ fname = @conn.get_function('BAPI_REQUISITION_GETITEMSREL')
307
+ fcall = fname.get_function_call
308
+
309
+ fcall[:REL_GROUP] = group
310
+ fcall[:REL_CODE] = code
311
+ fcall[:ITEMS_FOR_RELEASE] = 'X'
312
+
313
+ fcall.invoke
314
+
315
+ tb_return = get_object_list(fcall[:RETURN], Return)
316
+ requisition_items = get_object_list(fcall[:REQUISITION_ITEMS], RequisitionItems)
317
+
318
+ retcode = tb_return.detect{|r| r.type == 'E'}
319
+
320
+ if retcode
321
+ api_return_error(retcode)
322
+ else
323
+ api_return_success(requisition_items)
324
+ end
325
+
326
+ end
327
+
301
328
  def po_detail(po = 0, acc_assignment = "", item_text = "", header_text = "", delivery_address = "", version = "", services = "", serialnumbers = "", invoiceplan = "")
302
329
  #-- Execute BAPI_PO_GETDETAIL1
303
330
  fn_po_detail = @conn.get_function('BAPI_PO_GETDETAIL1')
@@ -440,6 +467,43 @@ module RnSap
440
467
 
441
468
  end
442
469
 
470
+ ##
471
+ # Gets a list of users with authorization for a given
472
+ # authorization object and content
473
+ # @params:
474
+ # - obj [String] SAP authorization Object
475
+ # Ex: for Purchase Requisitions M_EINK_FRG
476
+ # - field1 [String] Object authorization's field.
477
+ # Ex: for Release Group FRGGR
478
+ # - value1 [String] Field Value
479
+ # Ex: any valid Release Group in the instalation
480
+ # - field2 [String] Object authorization's field.
481
+ # Ex: for Release Code FRGCO
482
+ # - value2 [String] Field Value
483
+ # Ex: any valid Release Code in the instalation
484
+ # @return [Array] Array of strings with the SAP userids
485
+ def users_for_auth_object(obj, field1, value1, field2, value2)
486
+ Auth.for_object(
487
+ conn: self,
488
+ obj: obj,
489
+ field1: field1,
490
+ value1: value1,
491
+ field2: field2,
492
+ value2: value2,
493
+ )
494
+ end
495
+
496
+ def currency_conversion(amount = 0.0, from_curr = 'EUR', to_curr = 'USD', date = Date.today)
497
+ Currency.convert_currency_amount(
498
+ conn: self,
499
+ amount: amount,
500
+ from_curr: from_curr,
501
+ to_curr: to_curr,
502
+ date: date
503
+ )
504
+ end
505
+
506
+
443
507
  def api_return_success(obj=nil )
444
508
  UtilHelper.api_return(0, 'Success!', obj)
445
509
  end
@@ -452,10 +516,11 @@ module RnSap
452
516
  UtilHelper.api_return(rc, message, obj, exception)
453
517
  end
454
518
 
455
- private
456
519
 
520
+ private
457
521
  attr_writer :conn
458
522
 
523
+
459
524
  # Dumps to the output the content of an object
460
525
  def dump_instance_variables(obj)
461
526
  puts "Class: #{obj.class} -> #{obj}"
@@ -464,6 +529,8 @@ module RnSap
464
529
  end
465
530
  end
466
531
 
532
+ KLASS_LIST = {}
533
+
467
534
  # Dynamically returns a class instance with the name 'name' and with each
468
535
  # of its fields as an attribute
469
536
  # @param name [String] name of the intended class instance
@@ -471,7 +538,13 @@ module RnSap
471
538
  # @return [Object] instance of the object 'Name'
472
539
  def get_class_instance(name, fields)
473
540
  # puts "Class name: #{name}"
474
- klass = Object.const_set(name, Class.new).new # , Struct.new(*attributes)
541
+ pre_created = KLASS_LIST[name]
542
+ if pre_created
543
+ klass = pre_created.new
544
+ else
545
+ KLASS_LIST[name] = Object.const_set(name, Class.new)
546
+ klass = KLASS_LIST[name].new # , Struct.new(*attributes)
547
+ end
475
548
  fields.each do |field|
476
549
  klass.class.module_eval { attr_accessor field.downcase }
477
550
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rnsap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.12
4
+ version: 0.4.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rogerio Nascimento
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-26 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nwrfc
@@ -38,13 +38,15 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: By encapsulating SAPs NW RFC library calls, Ruby routines can access
42
- SAP power in a simpler manner
41
+ description: By encapsulating SAPs NW RFC library calls, Ruby routines achieve SAP
42
+ bunsiness functionalitys power in a simpler manner
43
43
  email:
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - lib/auth.rb
49
+ - lib/currency.rb
48
50
  - lib/helper/rfc_helper.rb
49
51
  - lib/helper/util_helper.rb
50
52
  - lib/po_detail/all.rb
@@ -91,6 +93,8 @@ files:
91
93
  - lib/preq_release_info/preq_release_final.rb
92
94
  - lib/preq_release_info/preq_release_posted.rb
93
95
  - lib/preq_release_info/preq_release_prerequisites.rb
96
+ - lib/preq_release_items/all.rb
97
+ - lib/preq_release_items/requisition_items.rb
94
98
  - lib/read_table/table_column.rb
95
99
  - lib/return.rb
96
100
  - lib/rnsap.rb
@@ -118,5 +122,5 @@ requirements: []
118
122
  rubygems_version: 3.2.3
119
123
  signing_key:
120
124
  specification_version: 4
121
- summary: Facilitates SAP RFC calls in Ruby
125
+ summary: Encapsulates SAP RFC calls in Ruby
122
126
  test_files: []