pais_legacy 0.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '0939b6496ab6f04fa5284f95d86d3defe78fcde55ac7e939e35aa12c44b98219'
4
+ data.tar.gz: 55c16260f4d7aa3acaaa2a11ad40a42963dcd2d517175e692e30dfbb3ea00b25
5
+ SHA512:
6
+ metadata.gz: ddf0978ea759645b96ad8dd0fcf9b1d2b205060f7ffd8bbee1276d8567346b42e4acb0440ddfaf87f482f27cbce108f9e14f4e0293d77f92c6537f98808b8f30
7
+ data.tar.gz: ed41ca0b1888e1a4a74efc1f0cc2088d7b3d837c33db91bcf1e2704b88c3bcc3be4e4e49e5c67d1a665cd9a46f79b3c44e2be260bc97cf8c2c6c0b82026cb954
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pais_legacy.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pais_legacy (0.1.0)
5
+ byebug (~> 11.0)
6
+ minitest (~> 5.16)
7
+ mocha (~> 1.14)
8
+ pastel (~> 0.8)
9
+ timecop (~> 0.9)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ ast (2.4.2)
15
+ byebug (11.1.3)
16
+ minitest (5.16.3)
17
+ mocha (1.14.0)
18
+ parallel (1.21.0)
19
+ parser (3.1.0.0)
20
+ ast (~> 2.4.1)
21
+ pastel (0.8.0)
22
+ tty-color (~> 0.5)
23
+ rainbow (3.1.1)
24
+ rake (13.0.6)
25
+ regexp_parser (2.5.0)
26
+ rexml (3.2.5)
27
+ rubocop (1.25.1)
28
+ parallel (~> 1.10)
29
+ parser (>= 3.1.0.0)
30
+ rainbow (>= 2.2.2, < 4.0)
31
+ regexp_parser (>= 1.8, < 3.0)
32
+ rexml
33
+ rubocop-ast (>= 1.15.1, < 2.0)
34
+ ruby-progressbar (~> 1.7)
35
+ unicode-display_width (>= 1.4.0, < 3.0)
36
+ rubocop-ast (1.15.2)
37
+ parser (>= 3.0.1.1)
38
+ ruby-progressbar (1.11.0)
39
+ timecop (0.9.5)
40
+ tty-color (0.6.0)
41
+ unicode-display_width (2.1.0)
42
+
43
+ PLATFORMS
44
+ x86_64-linux
45
+
46
+ DEPENDENCIES
47
+ pais_legacy!
48
+ rake (~> 13.0)
49
+ rubocop (~> 1.7)
50
+
51
+ BUNDLED WITH
52
+ 2.2.28
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ #require "rubocop/rake_task"
5
+ require 'rake/testtask'
6
+
7
+ #RuboCop::RakeTask.new
8
+
9
+ #task default: :rubocop
10
+
11
+ Rake::TestTask.new do |t|
12
+ t.libs << "test"
13
+ end
14
+
15
+ desc "Run tests"
16
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "pais_legacy"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/changelog.org ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-09-13
4
+
5
+ - Initial release
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaisLegacy
4
+ VERSION = "0.2.0"
5
+ end
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json' # Output
4
+ require "open3" # File I/O
5
+ require 'pastel' # TTY Color
6
+
7
+ require_relative "pais_legacy/version"
8
+
9
+ module PaisLegacy
10
+ class Error < StandardError; end
11
+
12
+ class Pais
13
+ PAISTRAM="pt"
14
+ SUSPENSE_ACCOUNT=1599
15
+ CLEARING_ACCOUNT=5199
16
+
17
+ # --------------------------------------------------------------------------------
18
+ # Trial Balance
19
+ # --------------------------------------------------------------------------------
20
+ def self.save_journals(ledger, data)
21
+ File.open(journals_file(ledger), "w") do |f|
22
+ f.write "AutoPost,LastTrnNo,Date,DR,DR_SUB,CR,CR_SUB,Description,Amount\n"
23
+
24
+ data[:xero].each_with_index do |xero,i|
25
+ # Determine if it's a credit/debit transaction
26
+ if (amount = data[:dr][i].to_f) > 0
27
+ dr_account,dr_sub,cr_account = accounts(data[:pais][i])
28
+ else
29
+ cr_account,cr_sub,dr_account = accounts(data[:pais][i])
30
+ amount = data[:cr][i]
31
+ end
32
+
33
+ f.write "GJ,#{Pais.lasttrnno_read(ledger).to_i + 1 + i},#{Time.now.strftime("%d/%m/%Y")},#{dr_account},#{dr_sub},#{cr_account},#{cr_sub},#{description(data,i)},#{amount}\n"
34
+ end
35
+ end
36
+ end
37
+
38
+ def self.pais_api(file,ledger,options="")
39
+ ssh + ' "bash -l -c \"' + fglgo(file) + ' {{ccode}} {{ledger}} {{options}}\""'
40
+ .gsub("{{ccode}}","T1")
41
+ .gsub("{{ledger}}",ledger.to_s)
42
+ .gsub("{{options}}",options)
43
+ end
44
+
45
+ def self.lasttrnno_read_cmd(ledger)
46
+ pais_api("get_lasttrnno",ledger)
47
+ end
48
+
49
+ def self.lasttrnno_read(ledger)
50
+ out,_,_=Open3.capture2(lasttrnno_read_cmd(ledger.to_s))
51
+ out.strip
52
+ end
53
+
54
+ def self.gltr_create(ledger,line)
55
+ pais_api "gltr_create", ledger, "{{autopost}} {{lasttrnno}} {{date}} {{dr}} {{dr_sub}} {{cr}} {{cr_sub}} \'{{description}}\' {{amount}}"
56
+ .gsub("{{autopost}}",line[0])
57
+ .gsub("{{lasttrnno}}",line[1])
58
+ .gsub("{{date}}",line[2])
59
+ .gsub("{{dr}}",line[3])
60
+ .gsub("{{dr_sub}}",sub(line[4]))
61
+ .gsub("{{cr}}",line[5])
62
+ .gsub("{{cr_sub}}",sub(line[6]))
63
+ .gsub("{{description}}",line[7])
64
+ .gsub("{{amount}}",line[8])
65
+ end
66
+
67
+ def self.rptrun(ledger,date_to)
68
+ ssh + ' "bash -l -c \"'+ fglgo("rptrun") +' pgs 1 pais {{program}} \'\{{printer}} \{{ccode}} \{{ledger}} \spar \{{account_from}} \{{account_to}} \1 \{{report_type}} \{{subaccs}} \{{date}}\' N\""'
69
+ .gsub("{{program}}","rglch01a")
70
+ .gsub("{{printer}}","FILE")
71
+ .gsub("{{ccode}}","T1")
72
+ .gsub("{{ledger}}",ledger)
73
+ .gsub("{{account_from}}","0001")
74
+ .gsub("{{account_to}}","6399")
75
+ .gsub("{{date}}",Date.parse(date_to).strftime("%d/%m/%Y") || "30/06/2021")
76
+ .gsub("{{report_type}}","1")
77
+ .gsub("{{subaccs}}","N")
78
+ end
79
+
80
+ def self.glch_read_cmd(ledger)
81
+ pais_api("glch_read",ledger)
82
+ end
83
+
84
+ def self.glch_read(ledger)
85
+ out,_,_=Open3.capture2(glch_read_cmd(ledger.to_s))
86
+
87
+ out.
88
+ split("\n").
89
+ map{|line| line.split(",")}.
90
+ map{|line| {value: line[0], text: "#{line[0]}-#{line[1]}"}}
91
+ end
92
+
93
+ def self.post_journals(ledger)
94
+ count = 0
95
+
96
+ # Step through each item in the 'tmp/pais_journal_post_666.csv'
97
+ CSV.readlines(journals_file(ledger)).drop(1).each do |line|
98
+ unless line[8].nil?
99
+ cmd = gltr_create(ledger,line)
100
+ puts cmd
101
+ Open3.capture2(cmd) # Post to PAIS
102
+ count += 1
103
+ end
104
+ end
105
+
106
+ count
107
+ end
108
+
109
+ # --------------------------------------------------------------------------------
110
+ # Invoice related
111
+ # --------------------------------------------------------------------------------
112
+ def legacy_import_invoices(ledger,date)
113
+ cmd=PaisLegacy::Pais.ssh + ' "bash -l -c \"' + PaisLegacy::Pais.fglgo("invo_read") + ' {{ccode}} {{ledger}} {{date}}\""'
114
+ .gsub("{{ccode}}","T1")
115
+ .gsub("{{ledger}}",ledger.to_s)
116
+ .gsub("{{date}}",date)
117
+ out,_,_=Open3.capture2(cmd)
118
+ out.delete!("\\\\")
119
+ out = JSON.parse(out)["invoices"]
120
+ # pp out
121
+ out
122
+ end
123
+
124
+ def display_invoices(invoices)
125
+ pastel = Pastel.new
126
+ puts pastel.green.bold("PAIS Legacy: Invoices #{invoices.count}")
127
+ invoices.each do |inv|
128
+ puts "#{inv["client"]["code"].ljust(8)} #{inv["no"].strip.ljust(10)} #{inv["date"].ljust(11)} #{inv["workname"].strip[0..50].ljust(50)} #{inv["total"].strip.rjust(10)}"
129
+ end
130
+ end
131
+
132
+ private
133
+ def self.accounts(account)
134
+ account = account.split("/")
135
+ acc = account[0] ? account[0] : SUSPENSE_ACCOUNT
136
+ sub=account[1] if account.count > 1
137
+ return acc,sub,CLEARING_ACCOUNT
138
+ end
139
+
140
+ def self.sub(account)
141
+ account ? account : "0"
142
+ end
143
+
144
+ def self.description(data,i)
145
+ xero_description=data[:xero_name][i].gsub(",","_")
146
+ pais_account = data[:pais][i]
147
+ "Auto post (Xero #{xero_description} -> #{pais_account})"
148
+ end
149
+
150
+ def self.journals_file(ledger)
151
+ "tmp/pais_journal_post_#{ledger}.csv"
152
+ end
153
+
154
+ def self.ssh
155
+ "ssh -oHostKeyAlgorithms=+ssh-dss #{PAISTRAM} -T"
156
+ end
157
+
158
+ def self.fglgo(file)
159
+ "fglgo /hd0a/u/pais/live/prod/#{file}"
160
+ end
161
+ end
162
+
163
+ end
data/readme.org ADDED
@@ -0,0 +1,39 @@
1
+ * PAIS Legacy
2
+
3
+ Connects to PAIS Legacy (Informix) custom API over an ssh connection.
4
+
5
+ ** Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pais_legacy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pais_legacy
20
+
21
+ ** Usage
22
+
23
+ Interacting with the GEM
24
+
25
+ #+begin_src ruby
26
+ pais=PaisLegacy.new
27
+ invoices = pais.legacy_import_invoices(ledger,date)
28
+ pais.display_invoices(invoices)
29
+ #+end_src
30
+
31
+ ** Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ** Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/map7/pais_legacy.
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pais_legacy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Pope
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: byebug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '11.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '11.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pastel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: timecop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ description: Connects to PAIS Legacy (Informix) custom API over an ssh connection.
84
+ email:
85
+ - michael@dtcorp.com.au
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".rubocop.yml"
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/setup
96
+ - changelog.org
97
+ - lib/pais_legacy.rb
98
+ - lib/pais_legacy/version.rb
99
+ - readme.org
100
+ homepage: https://github.com/map7/pais_legacy
101
+ licenses:
102
+ - MIT
103
+ metadata:
104
+ homepage_uri: https://github.com/map7/pais_legacy
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 2.4.0
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubygems_version: 3.2.22
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: PAIS Legacy API Wrapper
124
+ test_files: []