pais_legacy 2.6.0 → 2.6.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 137cd19045ff9caec78e7a880fff8977cc11e948695f423248a153aca9bc6a57
4
- data.tar.gz: 6a58fc1f86ce0d878ebc08545f158142d5f573d9359dd92fe384e89aadb37574
3
+ metadata.gz: aa61d63746b222710a2eb2c0924b52ce25dca218dee63ba6d45f6b1ab75c6881
4
+ data.tar.gz: aededfd5890f10cff78f8172322985cbb207c5f8e143ed99157b58489624d2a6
5
5
  SHA512:
6
- metadata.gz: d78b12afd356b6cc43aa342119fd179a2ae0b9564522cec6b25068adb62c2f4078703fbf12cb7eecfe7c40d76757ebc22a3e61440a8a03e66412c7b8d1cedd71
7
- data.tar.gz: d163add0cd7db3fbb08d238a3da0997d7d260750d1c7ff22fd4767182b94a46c9f6e37910597080feaa1d2218ff729b5b9b9c3a551d67f2335b07086c8d79d9c
6
+ metadata.gz: 15e9139de47550f1af4a450bc9bf15f17b7f53dd12d64f2650636eb381d41c6a4e779b4cb9500b0467c58940a1d9a57d680192b620e857a645b5f49055acb701
7
+ data.tar.gz: 035f50c5c12e7ca7625e1b56bb9a594b22d83abc346ac2a35c3cba71768b9fd1fa625b3aa3a409f53459f4ee0d89fcecf75a401fd3d8cbec0f24356ffb995956
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaisLegacy
4
- VERSION = "2.6.0"
4
+ VERSION = "2.6.2"
5
5
  end
data/lib/pais_legacy.rb CHANGED
@@ -4,6 +4,8 @@ require 'date'
4
4
  require 'json' # Output
5
5
  require "open3" # File I/O
6
6
  require 'pastel' # TTY Color
7
+ require 'net/ssh'
8
+ require 'byebug'
7
9
 
8
10
  require_relative "pais_legacy/trial_balance"
9
11
  require_relative "pais_legacy/version"
@@ -14,10 +16,52 @@ module PaisLegacy
14
16
  class Pais
15
17
  #SERVER="192.168.200.4"
16
18
  SERVER="pais.com.au"
19
+ USER="map7"
20
+ KEY="/home/map7/.ssh/id_rsa"
21
+
17
22
  SUSPENSE_ACCOUNT=1599
18
23
  CLEARING_ACCOUNT=5199
19
24
  TB_DIRECT_ACCOUNT=8999
20
25
 
26
+ def self.execute_ssh_command(command)
27
+ output = ""
28
+
29
+ # Start an SSH session
30
+ Net::SSH.start(SERVER,USER,keys: [KEY]) do |ssh|
31
+ # Open a new SSH channel
32
+ ssh.open_channel do |channel|
33
+ # Request a pseudo-tty
34
+ channel.request_pty do |ch, success|
35
+ raise "Could not obtain pty" unless success
36
+
37
+ # Execute the command
38
+ ch.exec(command) do |ch, success|
39
+ raise "Could not execute command" unless success
40
+
41
+ # Collect the data received from the command's standard output
42
+ ch.on_data do |c, data|
43
+ output += data
44
+ end
45
+
46
+ # Collect the data received from the command's standard error
47
+ ch.on_extended_data do |c, type, data|
48
+ output += "stderr: #{data}"
49
+ end
50
+
51
+ ch.on_close do
52
+ puts "Command execution finished"
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ # Keep the session open until the command execution is finished
59
+ ssh.loop
60
+ end
61
+
62
+ output
63
+ end
64
+
21
65
  # --------------------------------------------------------------------------------
22
66
  # Client
23
67
  # --------------------------------------------------------------------------------
@@ -30,7 +74,7 @@ module PaisLegacy
30
74
  end
31
75
 
32
76
  def self.clfi_read(client=nil)
33
- out,_,_=Open3.capture2(clfi_read_cmd(client.to_s))
77
+ out=execute_ssh_command(clfi_read_cmd(client.to_s))
34
78
  JSON.parse(out)
35
79
  end
36
80
 
@@ -46,7 +90,9 @@ module PaisLegacy
46
90
  end
47
91
 
48
92
  def self.glfi_read(ledger=nil)
49
- out,_,_=Open3.capture2(glfi_read_cmd(ledger.to_s))
93
+ # out,stderr,status=Open3.capture2(glfi_read_cmd(ledger.to_s))
94
+ out=execute_ssh_command(glfi_read_cmd(ledger.to_s))
95
+
50
96
  JSON.parse(out)
51
97
  end
52
98
 
@@ -58,7 +104,7 @@ module PaisLegacy
58
104
  end
59
105
 
60
106
  def self.glch_read(ledger)
61
- # out,_,_=Open3.capture2(glch_read_cmd(ledger.to_s))
107
+ # out=execute_ssh_command(glch_read_cmd(ledger.to_s))
62
108
  # out.
63
109
  # split("\n").
64
110
  # map{|line| line.split(",")}.
@@ -67,7 +113,8 @@ module PaisLegacy
67
113
  end
68
114
 
69
115
  def self.glch_read_all(ledger)
70
- out,_,_=Open3.capture2(glch_read_cmd(ledger.to_s))
116
+ puts glch_read_cmd(ledger.to_s)
117
+ out=execute_ssh_command(glch_read_cmd(ledger.to_s))
71
118
  JSON.parse(out)
72
119
  end
73
120
 
@@ -76,15 +123,17 @@ module PaisLegacy
76
123
  def self.raw(params,program="rdefi00a")
77
124
  params = params.gsub(" "," \\")
78
125
 
79
- cmd = ssh + ' "bash -c \"'+ fglgo("rptrun") +' pgs 1 pais '+program+' \''+ params + ' \' \""'
80
- out,_,_=Open3.capture2(cmd)
126
+ # cmd = ssh + ' "bash -c \"'+ fglgo("rptrun") +' pgs 1 pais '+program+' \''+ params + ' \' \""'
127
+ cmd = fglgo("rptrun") +' api 1 pais '+program+' \''+ params + ' \' '
128
+
129
+ out=execute_ssh_command(cmd)
81
130
  [out]
82
131
  end
83
132
 
84
133
  def self.raw_zsh(params,program="rdefi00a")
85
134
  params = params.gsub(" "," \\")
86
135
 
87
- cmd = 'zsh -c "'+ fglgo("rptrun") +' pgs 1 pais '+program+' \''+ params + ' \' "'
136
+ cmd = 'zsh -c "'+ fglgo("rptrun") +' api 1 pais '+program+' \''+ params + ' \' "'
88
137
  stdout, stderr, status_=Open3.capture3(cmd)
89
138
  [stdout]
90
139
  end
@@ -100,7 +149,7 @@ module PaisLegacy
100
149
  date_to = Date.parse("30/06/#{date_to.year}")
101
150
  date_from = Date.parse("01/07/#{date_to.year - 1}")
102
151
 
103
- cmd = ssh + ' "bash -c \"'+ fglgo("rptrun") +' pgs 1 pais {{program}} \'\{{printer}} \{{ccode}} \{{ledger}} \spar \N \2 \1 \2 \3 \4 \5 \{{date_from}} \{{date_to}} \' \""'
152
+ cmd = fglgo("rptrun") +' pgs 1 pais {{program}} \'\{{printer}} \{{ccode}} \{{ledger}} \spar \N \2 \1 \2 \3 \4 \5 \{{date_from}} \{{date_to}} \' '
104
153
  .gsub("{{program}}",program)
105
154
  .gsub("{{printer}}","SCREEN")
106
155
  .gsub("{{ccode}}","T1")
@@ -112,7 +161,7 @@ module PaisLegacy
112
161
  .gsub("{{report_type}}","1")
113
162
  .gsub("{{subaccs}}","N")
114
163
 
115
- out,_,_=Open3.capture2(cmd)
164
+ out=execute_ssh_command(cmd)
116
165
  [out]
117
166
  end
118
167
 
@@ -126,7 +175,7 @@ module PaisLegacy
126
175
  program="rglch01a"
127
176
  end
128
177
 
129
- cmd = ssh + ' "bash -c \"'+ fglgo("rptrun") +' pgs 1 pais {{program}} \'\{{printer}} \{{ccode}} \{{ledger}} \spar \{{account_from}} \{{account_to}} \{{date}}\ \1 \N\' \""'
178
+ cmd = fglgo("rptrun") +' pgs 1 pais {{program}} \'\{{printer}} \{{ccode}} \{{ledger}} \spar \{{account_from}} \{{account_to}} \{{date}}\ \1 \N\' '
130
179
  .gsub("{{program}}",program)
131
180
  .gsub("{{printer}}","SCREEN")
132
181
  .gsub("{{ccode}}","T1")
@@ -137,7 +186,7 @@ module PaisLegacy
137
186
  .gsub("{{report_type}}","1")
138
187
  .gsub("{{subaccs}}","N")
139
188
 
140
- out,_,_=Open3.capture2(cmd)
189
+ out=execute_ssh_command(cmd)
141
190
 
142
191
  # if from and to
143
192
  # out.split("\n").each_with_index do |line,index|
@@ -217,7 +266,11 @@ module PaisLegacy
217
266
  end
218
267
 
219
268
  def self.pais_api(file,ledger,options="")
220
- ssh + ' "bash -c \"' + fglgo(file) + ' {{ccode}} {{ledger}} {{options}}\""'
269
+ # ssh + ' "bash -c \"' + fglgo(file) + ' {{ccode}} {{ledger}} {{options}}\""'
270
+ # .gsub("{{ccode}}","T1")
271
+ # .gsub("{{ledger}}",ledger.to_s)
272
+ # .gsub("{{options}}",options)
273
+ fglgo(file) + ' {{ccode}} {{ledger}} {{options}}'
221
274
  .gsub("{{ccode}}","T1")
222
275
  .gsub("{{ledger}}",ledger.to_s)
223
276
  .gsub("{{options}}",options)
@@ -228,18 +281,18 @@ module PaisLegacy
228
281
  end
229
282
 
230
283
  def self.lasttrnno_read(ledger)
231
- out,_,_=Open3.capture2(lasttrnno_read_cmd(ledger.to_s))
284
+ out=execute_ssh_command(lasttrnno_read_cmd(ledger.to_s))
232
285
  out.strip
233
286
  end
234
287
 
235
288
  def self.gltr_read_all(ledger,start_date,end_date)
236
- cmd=ssh + ' "bash -c \"' + fglgo("gltr_read") + ' {{ccode}} {{ledger}} {{start_date}} {{end_date}}\""'
289
+ cmd=fglgo("gltr_read") + ' {{ccode}} {{ledger}} {{start_date}} {{end_date}}'
237
290
  .gsub("{{ccode}}","T1")
238
291
  .gsub("{{ledger}}",ledger.to_s)
239
292
  .gsub("{{start_date}}",start_date)
240
293
  .gsub("{{end_date}}",end_date)
241
294
 
242
- out,_,_=Open3.capture2(cmd)
295
+ out=execute_ssh_command(cmd)
243
296
  JSON.parse(out)
244
297
  end
245
298
 
@@ -259,7 +312,7 @@ module PaisLegacy
259
312
  # Example of P&L for ledger 336 with 2 periods
260
313
  # '\SCREEN \T1 \336 \spar \N \2 \1 \Y \3 \4 \5 \N \01/07/2021 \30/06/2022 \N \ALL \ALL \N \2'
261
314
  def self.rptrun(ledger,date_to,from="0001",to="9999",program="rglch01a")
262
- ssh + ' "bash -c \"'+ fglgo("rptrun") +' pgs 1 pais {{program}} \'\{{printer}} \{{ccode}} \{{ledger}} \spar \N \{{account_from}} \{{account_to}} \1 \{{report_type}} \{{subaccs}} \{{date}}\' N\""'
315
+ fglgo("rptrun") +' pgs 1 pais {{program}} \'\{{printer}} \{{ccode}} \{{ledger}} \spar \N \{{account_from}} \{{account_to}} \1 \{{report_type}} \{{subaccs}} \{{date}}\' N'
263
316
  .gsub("{{program}}",program)
264
317
  .gsub("{{printer}}","SCREEN")
265
318
  .gsub("{{ccode}}","T1")
@@ -288,7 +341,7 @@ module PaisLegacy
288
341
  end
289
342
 
290
343
  def self.common_ledger_date(cmd,ledger,end_date)
291
- cmd=ssh + ' "bash -c \"' + fglgo(cmd) + ' {{ccode}} {{ledger}} {{end_date}}\""'
344
+ cmd=fglgo(cmd) + ' {{ccode}} {{ledger}} {{end_date}}'
292
345
  .gsub("{{ccode}}","T1")
293
346
  .gsub("{{ledger}}",ledger.to_s)
294
347
  .gsub("{{end_date}}",end_date)
@@ -309,13 +362,13 @@ module PaisLegacy
309
362
  # Invoice related
310
363
  # --------------------------------------------------------------------------------
311
364
  def legacy_import_invoices(ledger,date)
312
- cmd=PaisLegacy::Pais.ssh + ' "bash -c \"' + PaisLegacy::Pais.fglgo("invo_read") + ' {{ccode}} {{ledger}} {{date}}\""'
365
+ cmd=PaisLegacy::Pais.fglgo("invo_read") + ' {{ccode}} {{ledger}} {{date}}'
313
366
  .gsub("{{ccode}}","T1")
314
367
  .gsub("{{ledger}}",ledger.to_s)
315
368
  .gsub("{{date}}",date)
316
369
 
317
370
  puts cmd
318
- out,_,_=Open3.capture2(cmd)
371
+ out=execute_ssh_command(cmd)
319
372
  out.delete!("\\\\")
320
373
  begin
321
374
  out = JSON.parse(out)
@@ -332,7 +385,7 @@ module PaisLegacy
332
385
 
333
386
  date = Date.parse(date).strftime("%d/%m/%Y")
334
387
 
335
- cmd=PaisLegacy::Pais.ssh + ' "bash -c \"' + PaisLegacy::Pais.fglgo("invo_read") + ' {{ccode}} {{ledger}} {{date}} {{inv_no}} {{client}}\""'
388
+ cmd=PaisLegacy::Pais.fglgo("invo_read") + ' {{ccode}} {{ledger}} {{date}} {{inv_no}} {{client}}'
336
389
  .gsub("{{ccode}}","T1")
337
390
  .gsub("{{ledger}}",ledger.to_s)
338
391
  .gsub("{{date}}",date)
@@ -340,7 +393,7 @@ module PaisLegacy
340
393
  .gsub("{{client}}",client)
341
394
 
342
395
  puts cmd
343
- out,_,_=Open3.capture2(cmd)
396
+ out=execute_ssh_command(cmd)
344
397
 
345
398
  begin
346
399
  out = JSON.parse(out)
@@ -366,21 +419,21 @@ module PaisLegacy
366
419
  # --------------------------------------------------------------------------------
367
420
 
368
421
  def self.table_indexes_cmd(table)
369
- ssh + ' "bash -c \"' + fglgo("db") + ' indexes\""'
422
+ fglgo("db") + ' indexes'
370
423
  end
371
424
 
372
425
  def self.table_indexes(table)
373
- out,_,_=Open3.capture2(table_indexes_cmd(table))
426
+ out=execute_ssh_command(table_indexes_cmd(table))
374
427
  out.split("\n").select{|i| i =~ /^#{table}_/}
375
428
  end
376
429
 
377
430
  def self.table_schema_cmd(table)
378
- ssh + ' "bash -c \"' + fglgo("db") + ' schema {{table}}\""'
431
+ fglgo("db") + ' schema {{table}}'
379
432
  .gsub("{{table}}",table)
380
433
  end
381
434
 
382
435
  def self.table_schema_raw(table)
383
- out,_,_=Open3.capture2(table_schema_cmd(table))
436
+ out=execute_ssh_command(table_schema_cmd(table))
384
437
  out.split("\n")
385
438
  end
386
439
 
@@ -392,12 +445,12 @@ module PaisLegacy
392
445
  end
393
446
 
394
447
  def self.table_data_cmd(table)
395
- ssh_with_tty + ' "bash -c \"' + fglgo("db") + ' data {{table}}\""'
448
+ fglgo("db") + ' data {{table}}'
396
449
  .gsub("{{table}}",table)
397
450
  end
398
451
 
399
452
  def self.table_data_raw(table)
400
- out,_,_=Open3.capture2(table_data_cmd(table))
453
+ out=execute_ssh_command(table_data_cmd(table))
401
454
  out.split("\n")
402
455
  end
403
456
 
@@ -416,20 +469,20 @@ module PaisLegacy
416
469
  end
417
470
 
418
471
  def self.table_unload_cmd(table)
419
- ssh + ' "bash -c \"' + fglgo("db") + ' unload {{table}}\""'
472
+ fglgo("db") + ' unload {{table}}'
420
473
  .gsub("{{table}}",table)
421
474
  end
422
475
 
423
476
  def self.table_unload(table)
424
- out,_,_=Open3.capture2(table_unload_cmd(table))
477
+ out=execute_ssh_command(table_unload_cmd(table))
425
478
  end
426
479
 
427
480
  def self.tables_cmd
428
- ssh + ' "bash -c \"' + fglgo("db") + ' tables\""'
481
+ fglgo("db") + ' tables'
429
482
  end
430
483
 
431
484
  def self.tables
432
- out,_,_=Open3.capture2(tables_cmd)
485
+ out=execute_ssh_command(tables_cmd)
433
486
  out.split("\n")
434
487
  end
435
488
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pais_legacy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Pope
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-17 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug