pais_legacy 0.2.0 → 0.3.0

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: '0939b6496ab6f04fa5284f95d86d3defe78fcde55ac7e939e35aa12c44b98219'
4
- data.tar.gz: 55c16260f4d7aa3acaaa2a11ad40a42963dcd2d517175e692e30dfbb3ea00b25
3
+ metadata.gz: 2fe00ee53a39a12fad05cd2b51d14dd2bdf7deed6abd6f12fe23fd3540ce099b
4
+ data.tar.gz: 53c10e3beabc7e314fbae39f906b18d9d06f6479c59c0300c2e211d509f2d06d
5
5
  SHA512:
6
- metadata.gz: ddf0978ea759645b96ad8dd0fcf9b1d2b205060f7ffd8bbee1276d8567346b42e4acb0440ddfaf87f482f27cbce108f9e14f4e0293d77f92c6537f98808b8f30
7
- data.tar.gz: ed41ca0b1888e1a4a74efc1f0cc2088d7b3d837c33db91bcf1e2704b88c3bcc3be4e4e49e5c67d1a665cd9a46f79b3c44e2be260bc97cf8c2c6c0b82026cb954
6
+ metadata.gz: ae52142a144778c394cbde4dac9477f0e7c97610f5279a24eb4b5b23a0cffa1af7879c5f957c3c93cb50619a2e956ce4fb6db47f23a6a78ae580a74a4347f705
7
+ data.tar.gz: 655f35476f16da72a2dcd17411b6e44d797ababf2dd6c847905f3b3d6f7169d3017ee3989504b06b48a253206326978340a2ea1c4821616a74be562374d57eeb
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pais_legacy (0.1.0)
4
+ pais_legacy (0.2.0)
5
5
  byebug (~> 11.0)
6
- minitest (~> 5.16)
7
- mocha (~> 1.14)
6
+ minitest (~> 5.0)
7
+ mocha (~> 1.0)
8
8
  pastel (~> 0.8)
9
9
  timecop (~> 0.9)
10
10
 
@@ -0,0 +1,79 @@
1
+ module PaisLegacy
2
+ class Error < StandardError; end
3
+
4
+ class TrialBalance
5
+
6
+ @report = nil
7
+
8
+ def initialize(report)
9
+ @report = report
10
+ end
11
+
12
+ def display
13
+ puts @report
14
+ end
15
+
16
+ def save_sample
17
+ File.open("tmp/trial_balance_screen.sample","w") do |f|
18
+ @report.each do |line|
19
+ f.write "#{line}\n"
20
+ end
21
+ end
22
+ end
23
+
24
+ def codes_from_trial_balance
25
+ read = false
26
+ codes = []
27
+ @report.each do |row|
28
+ next if row.strip.length == 0
29
+
30
+ read = false if end_reading(row)
31
+ if read && (row[0..9].to_i>0)
32
+ codes << code_from_row(row)
33
+ end
34
+ read = true if start_reading(row)
35
+ end
36
+
37
+ codes
38
+ end
39
+
40
+ def main_account(row)
41
+ @main_code = row[0..7].strip
42
+ @main_text = account_name(row)
43
+ {:value => "#{@main_code}",:text => "#{"#{@main_code}-#{@main_text}".strip}"}
44
+ end
45
+
46
+ def sub_account(row)
47
+ code = "#{@main_code}/#{row[0..9].strip}"
48
+ text = "#{code}-#{@main_text} #{account_name(row)}"
49
+ {:value => "#{code}",:text => "#{text.strip}"}
50
+ end
51
+
52
+ private
53
+ def start_reading(row)
54
+ row.include?("Acc Gst")
55
+ end
56
+
57
+ def end_reading(row)
58
+ row.include?("Not Audited.")
59
+ end
60
+
61
+ def code_from_row(row)
62
+ if is_sub_account(row)
63
+ sub_account(row)
64
+ else
65
+ main_account(row)
66
+ end
67
+ end
68
+
69
+ def account_name(row)
70
+ row[14..46].strip
71
+ end
72
+
73
+ def is_sub_account(row)
74
+ sub = row[0..9].strip
75
+ sub.to_i > 0 && !sub.include?("/")
76
+ end
77
+
78
+ end
79
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaisLegacy
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/pais_legacy.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'date'
3
4
  require 'json' # Output
4
5
  require "open3" # File I/O
5
6
  require 'pastel' # TTY Color
6
7
 
8
+ require_relative "pais_legacy/trial_balance"
7
9
  require_relative "pais_legacy/version"
8
10
 
9
11
  module PaisLegacy
@@ -14,9 +16,44 @@ module PaisLegacy
14
16
  SUSPENSE_ACCOUNT=1599
15
17
  CLEARING_ACCOUNT=5199
16
18
 
19
+ # --------------------------------------------------------------------------------
20
+ # Accounts
21
+ # --------------------------------------------------------------------------------
22
+ def self.glch_read_cmd(ledger)
23
+ pais_api("glch_read",ledger)
24
+ end
25
+
26
+ def self.glch_read(ledger)
27
+ out,_,_=Open3.capture2(glch_read_cmd(ledger.to_s))
28
+
29
+ out.
30
+ split("\n").
31
+ map{|line| line.split(",")}.
32
+ map{|line| {value: line[0], text: "#{line[0]}-#{line[1]}"}}
33
+ end
34
+
17
35
  # --------------------------------------------------------------------------------
18
36
  # Trial Balance
19
37
  # --------------------------------------------------------------------------------
38
+ def self.get_trial_balance(from=nil,to=nil)
39
+ cmd=rptrun("1","30/06/2021")
40
+ out,_,_=Open3.capture2(cmd)
41
+
42
+ if from and to
43
+ out.split("\n").each_with_index do |line,index|
44
+ if index >= from and index <= to
45
+ puts "#{index}-#{line}"
46
+ end
47
+ end
48
+ end
49
+
50
+ out.split("\n")
51
+ end
52
+
53
+
54
+ # --------------------------------------------------------------------------------
55
+ # General Journals
56
+ # --------------------------------------------------------------------------------
20
57
  def self.save_journals(ledger, data)
21
58
  File.open(journals_file(ledger), "w") do |f|
22
59
  f.write "AutoPost,LastTrnNo,Date,DR,DR_SUB,CR,CR_SUB,Description,Amount\n"
@@ -64,32 +101,19 @@ module PaisLegacy
64
101
  .gsub("{{amount}}",line[8])
65
102
  end
66
103
 
67
- def self.rptrun(ledger,date_to)
104
+ def self.rptrun(ledger,date_to,from="0001",to="6399",program="rglch01a")
68
105
  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")
106
+ .gsub("{{program}}",program)
107
+ .gsub("{{printer}}","SCREEN")
71
108
  .gsub("{{ccode}}","T1")
72
109
  .gsub("{{ledger}}",ledger)
73
- .gsub("{{account_from}}","0001")
74
- .gsub("{{account_to}}","6399")
110
+ .gsub("{{account_from}}",from)
111
+ .gsub("{{account_to}}",to)
75
112
  .gsub("{{date}}",Date.parse(date_to).strftime("%d/%m/%Y") || "30/06/2021")
76
113
  .gsub("{{report_type}}","1")
77
114
  .gsub("{{subaccs}}","N")
78
115
  end
79
116
 
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
117
  def self.post_journals(ledger)
94
118
  count = 0
95
119
 
data/readme.org CHANGED
@@ -22,12 +22,69 @@ Or install it yourself as:
22
22
 
23
23
  Interacting with the GEM
24
24
 
25
+ *** Chart of Accounts
26
+
27
+ #+begin_src ruby
28
+ @pais_codes = PaisLegacy::Pais.glch_read(@pais_ledger)
29
+ #+end_src
30
+
31
+ Result;
32
+ : [{:value=>"1/1", :text=>"1/1-Sales Net Of Tax"}]
33
+
34
+ *** Trial Balance
35
+
36
+ **** Get trial balance
37
+
38
+ Get the trial balance from PAIS Legacy.
39
+
40
+ #+begin_src ruby
41
+ PaisLegacy::Pais.get_trial_balance
42
+ #+end_src
43
+
44
+ **** Get codes
45
+
46
+ Extract codes from Trial Balance
47
+
25
48
  #+begin_src ruby
26
- pais=PaisLegacy.new
27
- invoices = pais.legacy_import_invoices(ledger,date)
28
- pais.display_invoices(invoices)
49
+ @report = PaisLegacy::Pais.get_trial_balance
50
+ @tb=PaisLegacy::TrialBalance.new(@report)
51
+ @codes = @tb.codes_from_trial_balance
29
52
  #+end_src
30
53
 
54
+ Result of @codes;
55
+ : [{value: "1", text: "1-Sales"}]
56
+
57
+ **** Save journal entries
58
+
59
+ This method saves the journal entries from Xero's trial balance but with PAIS Legacy account & sub account codes from the allocation table created by the user.
60
+
61
+ #+begin_src ruby
62
+ @params={xero: ["270","200","0"],
63
+ xero_name: ["Interest Income (270)","Sales (200)","Cash on Hand (0)"],
64
+ pais: ["250/1","",""],
65
+ dr: ["","678672.92",""],
66
+ cr: ["0.75","","123"]}
67
+ PaisLegacy::Pais.save_journals(ledger_code, @params)
68
+ #+end_src
69
+
70
+ Result in CSV file output (FILE: "tmp/pais_journal_post_#{ledger}.csv")
71
+ : "GJ,2,14/07/2022,5199,,250,1,Auto post (Xero Interest Income (270) -> 250/1),0.75"
72
+
73
+ **** Post GJ to PAIS Legacy
74
+
75
+ This reads the CSV created by save_journals and posts them to PAIS Legacy.
76
+
77
+ #+begin_src ruby
78
+ @journal_count = PaisLegacy::Pais.post_journals(ledger_code)
79
+ #+end_src
80
+
81
+ *** Invoices
82
+ #+begin_src ruby
83
+ pais=PaisLegacy.new
84
+ invoices = pais.legacy_import_invoices(ledger,date)
85
+ pais.display_invoices(invoices)
86
+ #+end_src
87
+
31
88
  ** Development
32
89
 
33
90
  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.
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: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Pope
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-13 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -95,6 +95,7 @@ files:
95
95
  - bin/setup
96
96
  - changelog.org
97
97
  - lib/pais_legacy.rb
98
+ - lib/pais_legacy/trial_balance.rb
98
99
  - lib/pais_legacy/version.rb
99
100
  - readme.org
100
101
  homepage: https://github.com/map7/pais_legacy