Class: PaisLegacy::Pais
- Inherits:
-
Object
- Object
- PaisLegacy::Pais
- Defined in:
- lib/pais_legacy.rb
Constant Summary collapse
- SERVER =
SERVER=“192.168.200.4”
"pais.com.au"
- USER =
"map7"
- KEY =
"/home/map7/.ssh/id_rsa"
- SUSPENSE_ACCOUNT =
1599
- CLEARING_ACCOUNT =
5199
- TB_DIRECT_ACCOUNT =
8999
Class Method Summary collapse
- .clfi_read(client = nil) ⇒ Object
-
.clfi_read_cmd(client = nil) ⇒ Object
——————————————————————————– Client ——————————————————————————–.
- .common_ledger_date(cmd, ledger, end_date) ⇒ Object
- .delete_and_rebuild(ledger, end_date) ⇒ Object
- .execute_ssh_command(command) ⇒ Object
-
.get_performance(ledger = "1", date_to = "30/06/2022", prior = false, from = 1, to = 9999) ⇒ Object
——————————————————————————– Performance Report ——————————————————————————– ‘SCREEN T1 336 spar N 2 1 2 3 4 5 01/07/2021 30/06/2022 ’.
-
.get_trial_balance(ledger = "1", date_to = "30/06/2021", prior = false, from = 1, to = 9999) ⇒ Object
——————————————————————————– Trial Balance ——————————————————————————–.
-
.get_trial_balance_accounts(ledger = "1", date_to = "30/06/2021", periods = 1, from = 1, to = 9999) ⇒ Object
Get the accounts using the trial balance.
- .glch_read(ledger) ⇒ Object
- .glch_read_all(ledger) ⇒ Object
-
.glch_read_cmd(ledger) ⇒ Object
——————————————————————————– Accounts ——————————————————————————–.
- .glfi_read(ledger = nil) ⇒ Object
-
.glfi_read_cmd(ledger = nil) ⇒ Object
——————————————————————————– Ledger ——————————————————————————–.
- .gltr_create(ledger, line) ⇒ Object
- .gltr_read_all(ledger, start_date, end_date) ⇒ Object
- .lasttrnno_read(ledger) ⇒ Object
- .lasttrnno_read_cmd(ledger) ⇒ Object
- .pais_api(file, ledger, options = "") ⇒ Object
- .post_journals(ledger) ⇒ Object
-
.raw(params, program = "rdefi00a") ⇒ Object
SCREEN T1 10000 1 999999 0 0 0 001 0 9999 0 9999 0 3 N Y N 5200 6153 1 6110 6 A 1 30/06/2023.
- .raw_zsh(params, program = "rdefi00a") ⇒ Object
- .rebuild_ledger(ledger, end_date) ⇒ Object
-
.rptrun(ledger, date_to, from = "0001", to = "9999", program = "rglch01a") ⇒ Object
Example of P&L for ledger 336 with 2 periods ‘SCREEN T1 336 spar N 2 1 Y 3 4 5 N 01/07/2021 30/06/2022 N ALL ALL N 2’.
- .rptrun_exec(ledger, date_to, from = "0001", to = "9999", program = "rglch01a") ⇒ Object
-
.save_journals(ledger_code, data) ⇒ Object
——————————————————————————– General Journals ——————————————————————————–.
- .table_data(table) ⇒ Object
- .table_data_cmd(table) ⇒ Object
- .table_data_raw(table) ⇒ Object
- .table_indexes(table) ⇒ Object
-
.table_indexes_cmd(table) ⇒ Object
——————————————————————————– DB related ——————————————————————————–.
- .table_schema(table) ⇒ Object
- .table_schema_cmd(table) ⇒ Object
- .table_schema_raw(table) ⇒ Object
- .table_unload(table) ⇒ Object
- .table_unload_cmd(table) ⇒ Object
- .tables ⇒ Object
- .tables_cmd ⇒ Object
Instance Method Summary collapse
- #display_invoices(invoices) ⇒ Object
- #execute_ssh_command(command) ⇒ Object
- #legacy_import_invoice(ledger, date, inv_no, client) ⇒ Object
-
#legacy_import_invoices(ledger, date) ⇒ Object
——————————————————————————– Invoice related ——————————————————————————–.
Class Method Details
.clfi_read(client = nil) ⇒ Object
82 83 84 85 |
# File 'lib/pais_legacy.rb', line 82 def self.clfi_read(client=nil) out=execute_ssh_command(clfi_read_cmd(client.to_s)) JSON.parse(out) end |
.clfi_read_cmd(client = nil) ⇒ Object
Client
74 75 76 77 78 79 80 |
# File 'lib/pais_legacy.rb', line 74 def self.clfi_read_cmd(client=nil) if client pais_api("clfi_read ","10000",client) else pais_api("clfi_read ","10000") end end |
.common_ledger_date(cmd, ledger, end_date) ⇒ Object
354 355 356 357 358 359 360 361 362 |
# File 'lib/pais_legacy.rb', line 354 def self.common_ledger_date(cmd,ledger,end_date) cmd=fglgo(cmd) + ' {{ccode}} {{ledger}} {{end_date}}' .gsub("{{ccode}}","T1") .gsub("{{ledger}}",ledger.to_s) .gsub("{{end_date}}",end_date) puts cmd execute_ssh_command(cmd) end |
.delete_and_rebuild(ledger, end_date) ⇒ Object
368 369 370 |
# File 'lib/pais_legacy.rb', line 368 def self.delete_and_rebuild(ledger,end_date) common_ledger_date("delete_and_rebuild",ledger,end_date) end |
.execute_ssh_command(command) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pais_legacy.rb', line 30 def self.execute_ssh_command(command) output = "" # Start an SSH session Net::SSH.start(SERVER,USER,keys: [KEY]) do |ssh| # Open a new SSH channel ssh.open_channel do |channel| # Request a pseudo-tty channel.request_pty do |ch, success| raise "Could not obtain pty" unless success # Execute the command ch.exec(command) do |ch, success| raise "Could not execute command" unless success # Collect the data received from the command's standard output ch.on_data do |c, data| output += data end # Collect the data received from the command's standard error ch.on_extended_data do |c, type, data| output += "stderr: #{data}" end ch.on_close do puts "Command execution finished" end end end end # Keep the session open until the command execution is finished ssh.loop end output end |
.get_performance(ledger = "1", date_to = "30/06/2022", prior = false, from = 1, to = 9999) ⇒ Object
Performance Report
‘SCREEN T1 336 spar N 2 1 2 3 4 5 01/07/2021 30/06/2022 ’
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/pais_legacy.rb', line 151 def self.get_performance(ledger = "1", date_to = "30/06/2022",prior=false,from=1,to=9999) program="rglch10a" date_to = Date.parse(date_to) date_to = Date.parse("30/06/#{date_to.year}") date_from = Date.parse("01/07/#{date_to.year - 1}") cmd = fglgo("rptrun") +' pgs 1 pais {{program}} \'\{{printer}} \{{ccode}} \{{ledger}} \spar \N \2 \1 \2 \3 \4 \5 \{{date_from}} \{{date_to}} \' ' .gsub("{{program}}",program) .gsub("{{printer}}","SCREEN") .gsub("{{ccode}}","T1") .gsub("{{ledger}}",ledger) .gsub("{{account_from}}",from.to_s) .gsub("{{account_to}}",to.to_s) .gsub("{{date_from}}",date_from.strftime("%d/%m/%Y") || "01/07/2021") .gsub("{{date_to}}",date_to.strftime("%d/%m/%Y") || "30/06/2022") .gsub("{{report_type}}","1") .gsub("{{subaccs}}","N") out=execute_ssh_command(cmd) [out] end |
.get_trial_balance(ledger = "1", date_to = "30/06/2021", prior = false, from = 1, to = 9999) ⇒ Object
Trial Balance
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/pais_legacy.rb', line 177 def self.get_trial_balance(ledger = "1", date_to = "30/06/2021",prior=false,from=1,to=9999) if prior program="rglch01p" else program="rglch01a" end cmd = fglgo("rptrun") +' pgs 1 pais {{program}} \'\{{printer}} \{{ccode}} \{{ledger}} \spar \{{account_from}} \{{account_to}} \{{date}}\ \1 \N\' ' .gsub("{{program}}",program) .gsub("{{printer}}","SCREEN") .gsub("{{ccode}}","T1") .gsub("{{ledger}}",ledger) .gsub("{{account_from}}",from.to_s) .gsub("{{account_to}}",to.to_s) .gsub("{{date}}",Date.parse(date_to).strftime("%d/%m/%Y") || "30/06/2021") .gsub("{{report_type}}","1") .gsub("{{subaccs}}","N") out=execute_ssh_command(cmd) # if from and to # out.split("\n").each_with_index do |line,index| # if index >= from and index <= to # puts "#{index}-#{line}" # end # end # end out.split("\n") end |
.get_trial_balance_accounts(ledger = "1", date_to = "30/06/2021", periods = 1, from = 1, to = 9999) ⇒ Object
Get the accounts using the trial balance
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/pais_legacy.rb', line 209 def self.get_trial_balance_accounts(ledger = "1", date_to = "30/06/2021", periods=1,from=1,to=9999) results = [] periods.times do |period| date_to = Date.parse(date_to) date_to = date_to.strftime("%d/%m/") + (date_to.year.to_i - period).to_s report = get_trial_balance(ledger,date_to,period>0,from,to) tb = PaisLegacy::TrialBalance.new(report) results << tb.accounts_from_trial_balance end results_merged = [] results.each_with_index do |result,i| if i == 0 results_merged = result else result.each do |account| hash=results_merged.find {|r| r[:code] == account[:code]} hash = {code: account[:code], name: account[:name]} unless hash hash["dr#{i}".to_sym] = account[:dr] hash["cr#{i}".to_sym] = account[:cr] end end end results_merged end |
.glch_read(ledger) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/pais_legacy.rb', line 112 def self.glch_read(ledger) # out=execute_ssh_command(glch_read_cmd(ledger.to_s)) # out. # split("\n"). # map{|line| line.split(",")}. # map{|line| {value: line[0], text: "#{line[0]}-#{line[1]}"}} glch_read_all(ledger)["accounts"].map {|h| {value: h["code"], text: "#{h['code']}-#{h['description']}"}} end |
.glch_read_all(ledger) ⇒ Object
121 122 123 124 125 |
# File 'lib/pais_legacy.rb', line 121 def self.glch_read_all(ledger) puts glch_read_cmd(ledger.to_s) out=execute_ssh_command(glch_read_cmd(ledger.to_s)) JSON.parse(out) end |
.glch_read_cmd(ledger) ⇒ Object
Accounts
108 109 110 |
# File 'lib/pais_legacy.rb', line 108 def self.glch_read_cmd(ledger) pais_api("glch_read",ledger) end |
.glfi_read(ledger = nil) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/pais_legacy.rb', line 98 def self.glfi_read(ledger=nil) # out,stderr,status=Open3.capture2(glfi_read_cmd(ledger.to_s)) out=execute_ssh_command(glfi_read_cmd(ledger.to_s)) JSON.parse(out) end |
.glfi_read_cmd(ledger = nil) ⇒ Object
Ledger
90 91 92 93 94 95 96 |
# File 'lib/pais_legacy.rb', line 90 def self.glfi_read_cmd(ledger=nil) if ledger pais_api("glfi_read",ledger) else pais_api("glfi_read") end end |
.gltr_create(ledger, line) ⇒ Object
305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/pais_legacy.rb', line 305 def self.gltr_create(ledger,line) pais_api "gltr_create", ledger, "{{autopost}} {{lasttrnno}} {{date}} {{dr}} {{dr_sub}} {{cr}} {{cr_sub}} \'{{description}}\' {{amount}}" .gsub("{{autopost}}",line[0]) .gsub("{{lasttrnno}}",line[1]) .gsub("{{date}}",line[2]) .gsub("{{dr}}",line[3]) .gsub("{{dr_sub}}",sub(line[4])) .gsub("{{cr}}",line[5]) .gsub("{{cr_sub}}",sub(line[6])) .gsub("{{description}}",line[7]) .gsub("{{amount}}",line[8]) end |
.gltr_read_all(ledger, start_date, end_date) ⇒ Object
294 295 296 297 298 299 300 301 302 303 |
# File 'lib/pais_legacy.rb', line 294 def self.gltr_read_all(ledger,start_date,end_date) cmd=fglgo("gltr_read") + ' {{ccode}} {{ledger}} {{start_date}} {{end_date}}' .gsub("{{ccode}}","T1") .gsub("{{ledger}}",ledger.to_s) .gsub("{{start_date}}",start_date) .gsub("{{end_date}}",end_date) out=execute_ssh_command(cmd) JSON.parse(out) end |
.lasttrnno_read(ledger) ⇒ Object
289 290 291 292 |
# File 'lib/pais_legacy.rb', line 289 def self.lasttrnno_read(ledger) out=execute_ssh_command(lasttrnno_read_cmd(ledger.to_s)) out.strip end |
.lasttrnno_read_cmd(ledger) ⇒ Object
285 286 287 |
# File 'lib/pais_legacy.rb', line 285 def self.lasttrnno_read_cmd(ledger) pais_api("lasttrnno",ledger) end |
.pais_api(file, ledger, options = "") ⇒ Object
274 275 276 277 278 279 280 281 282 283 |
# File 'lib/pais_legacy.rb', line 274 def self.pais_api(file,ledger,="") # ssh + ' "bash -c \"' + fglgo(file) + ' {{ccode}} {{ledger}} {{options}}\""' # .gsub("{{ccode}}","T1") # .gsub("{{ledger}}",ledger.to_s) # .gsub("{{options}}",options) fglgo(file) + ' {{ccode}} {{ledger}} {{options}}' .gsub("{{ccode}}","T1") .gsub("{{ledger}}",ledger.to_s) .gsub("{{options}}",) end |
.post_journals(ledger) ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/pais_legacy.rb', line 338 def self.post_journals(ledger) count = 0 # Step through each item in the 'tmp/pais_journal_post_666.csv' CSV.readlines(journals_file(ledger)).drop(1).each do |line| unless line[8].nil? cmd = gltr_create(ledger,line) puts cmd execute_ssh_command(cmd) # Post to PAIS count += 1 end end count end |
.raw(params, program = "rdefi00a") ⇒ Object
SCREEN T1 10000 1 999999 0 0 0 001 0 9999 0 9999 0 3 N Y N 5200 6153 1 6110 6 A 1 30/06/2023
129 130 131 132 133 134 135 136 137 |
# File 'lib/pais_legacy.rb', line 129 def self.raw(params,program="rdefi00a") params = params.gsub(" "," \\") # cmd = ssh + ' "bash -c \"'+ fglgo("rptrun") +' pgs 1 pais '+program+' \''+ params + ' \' \""' cmd = fglgo("rptrun") +' api 1 pais '+program+' \''+ params + ' \' ' out=execute_ssh_command(cmd) [out] end |
.raw_zsh(params, program = "rdefi00a") ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/pais_legacy.rb', line 139 def self.raw_zsh(params,program="rdefi00a") params = params.gsub(" "," \\") cmd = 'zsh -c "'+ fglgo("rptrun") +' api 1 pais '+program+' \''+ params + ' \' "' stdout, stderr, status_=Open3.capture3(cmd) [stdout] end |
.rebuild_ledger(ledger, end_date) ⇒ Object
364 365 366 |
# File 'lib/pais_legacy.rb', line 364 def self.rebuild_ledger(ledger,end_date) common_ledger_date("rebuild_after_post",ledger,end_date) end |
.rptrun(ledger, date_to, from = "0001", to = "9999", program = "rglch01a") ⇒ Object
Example of P&L for ledger 336 with 2 periods ‘SCREEN T1 336 spar N 2 1 Y 3 4 5 N 01/07/2021 30/06/2022 N ALL ALL N 2’
320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/pais_legacy.rb', line 320 def self.rptrun(ledger,date_to,from="0001",to="9999",program="rglch01a") fglgo("rptrun") +' api 1 pais {{program}} \'\{{printer}} \{{ccode}} \{{ledger}} \spar \N \{{account_from}} \{{account_to}} \1 \{{report_type}} \{{subaccs}} \{{date}}\' N' .gsub("{{program}}",program) .gsub("{{printer}}","SCREEN") .gsub("{{ccode}}","T1") .gsub("{{ledger}}",ledger) .gsub("{{account_from}}",from.to_s) .gsub("{{account_to}}",to.to_s) .gsub("{{date}}",Date.parse(date_to).strftime("%d/%m/%Y") || "30/06/2021") .gsub("{{report_type}}","1") .gsub("{{subaccs}}","N") end |
.rptrun_exec(ledger, date_to, from = "0001", to = "9999", program = "rglch01a") ⇒ Object
333 334 335 336 |
# File 'lib/pais_legacy.rb', line 333 def self.rptrun_exec(ledger,date_to,from="0001",to="9999",program="rglch01a") cmd=rptrun(ledger,date_to,from="0001",to="9999",program) [execute_ssh_command(cmd)] end |
.save_journals(ledger_code, data) ⇒ Object
General Journals
data should be the whole params, which will include the pais_code, dr & cr amounts
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/pais_legacy.rb', line 247 def self.save_journals(ledger_code, data) tranno=Pais.lasttrnno_read(ledger_code).to_i File.open(journals_file(ledger_code), "w") do |f| f.write "AutoPost,LastTrnNo,Date,DR,DR_SUB,CR,CR_SUB,Description,Amount\n" data[:dr].each_with_index do |d,i| if data[:pais][i] # Determine if it's a credit/debit transaction if (amount = data[:dr][i].to_f) > 0 dr_account,dr_sub,cr_account = accounts(data[:pais][i]) else cr_account,cr_sub,dr_account = accounts(data[:pais][i]) amount = data[:cr][i] end tranno += 1 date = data[:date_to].nil? ? Time.now : Date.parse(data[:date_to]) date = date.strftime("%d/%m/%Y") f.write "GJ,#{tranno},#{date},#{dr_account},#{dr_sub},#{cr_account},#{cr_sub},#{description(data,i)},#{amount}\n" end end end end |
.table_data(table) ⇒ Object
468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/pais_legacy.rb', line 468 def self.table_data(table) columns=table_schema(table) table_data_raw(table).map {|line| array=line.split("|") hash = Hash.new columns.each_with_index do |col,i| hash[col[:name].to_sym] = array[i].strip end hash } end |
.table_data_cmd(table) ⇒ Object
458 459 460 461 |
# File 'lib/pais_legacy.rb', line 458 def self.table_data_cmd(table) fglgo("db") + ' data {{table}}' .gsub("{{table}}",table) end |
.table_data_raw(table) ⇒ Object
463 464 465 466 |
# File 'lib/pais_legacy.rb', line 463 def self.table_data_raw(table) out=execute_ssh_command(table_data_cmd(table)) out.split("\n") end |
.table_indexes(table) ⇒ Object
436 437 438 439 |
# File 'lib/pais_legacy.rb', line 436 def self.table_indexes(table) out=execute_ssh_command(table_indexes_cmd(table)) out.split("\n").select{|i| i =~ /^#{table}_/} end |
.table_indexes_cmd(table) ⇒ Object
DB related
432 433 434 |
# File 'lib/pais_legacy.rb', line 432 def self.table_indexes_cmd(table) fglgo("db") + ' indexes' end |
.table_schema(table) ⇒ Object
451 452 453 454 455 456 |
# File 'lib/pais_legacy.rb', line 451 def self.table_schema(table) table_schema_raw(table).map {|line| array=line.split("|") {name: array[0].strip, type_id: array[1].strip, type_name: array[2].strip} } end |
.table_schema_cmd(table) ⇒ Object
441 442 443 444 |
# File 'lib/pais_legacy.rb', line 441 def self.table_schema_cmd(table) fglgo("db") + ' schema {{table}}' .gsub("{{table}}",table) end |
.table_schema_raw(table) ⇒ Object
446 447 448 449 |
# File 'lib/pais_legacy.rb', line 446 def self.table_schema_raw(table) out=execute_ssh_command(table_schema_cmd(table)) out.split("\n") end |
.table_unload(table) ⇒ Object
487 488 489 |
# File 'lib/pais_legacy.rb', line 487 def self.table_unload(table) out=execute_ssh_command(table_unload_cmd(table)) end |
.table_unload_cmd(table) ⇒ Object
482 483 484 485 |
# File 'lib/pais_legacy.rb', line 482 def self.table_unload_cmd(table) fglgo("db") + ' unload {{table}}' .gsub("{{table}}",table) end |
.tables ⇒ Object
495 496 497 498 |
# File 'lib/pais_legacy.rb', line 495 def self.tables out=execute_ssh_command(tables_cmd) out.split("\n") end |
.tables_cmd ⇒ Object
491 492 493 |
# File 'lib/pais_legacy.rb', line 491 def self.tables_cmd fglgo("db") + ' tables' end |
Instance Method Details
#display_invoices(invoices) ⇒ Object
420 421 422 423 424 425 426 |
# File 'lib/pais_legacy.rb', line 420 def display_invoices(invoices) pastel = Pastel.new puts pastel.green.bold("PAIS Legacy: Invoices #{invoices.count}") invoices.each do |inv| 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)}" end end |
#execute_ssh_command(command) ⇒ Object
26 27 28 |
# File 'lib/pais_legacy.rb', line 26 def execute_ssh_command(command) PaisLegacy.execute_ssh_command(command) end |
#legacy_import_invoice(ledger, date, inv_no, client) ⇒ Object
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/pais_legacy.rb', line 395 def legacy_import_invoice(ledger,date,inv_no,client) date = Date.parse(date).strftime("%d/%m/%Y") cmd=PaisLegacy::Pais.fglgo("invo_read") + ' {{ccode}} {{ledger}} {{date}} {{inv_no}} {{client}}' .gsub("{{ccode}}","T1") .gsub("{{ledger}}",ledger.to_s) .gsub("{{date}}",date) .gsub("{{inv_no}}",inv_no) .gsub("{{client}}",client) puts cmd out=execute_ssh_command(cmd) begin out = JSON.parse(out) rescue JSON::JSONError, ArgumentError => e puts e.to_s exit end # pp out out end |
#legacy_import_invoices(ledger, date) ⇒ Object
Invoice related
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/pais_legacy.rb', line 375 def legacy_import_invoices(ledger,date) cmd=PaisLegacy::Pais.fglgo("invo_read") + ' {{ccode}} {{ledger}} {{date}}' .gsub("{{ccode}}","T1") .gsub("{{ledger}}",ledger.to_s) .gsub("{{date}}",date) puts cmd out=execute_ssh_command(cmd) out.delete!("\\\\") begin out = JSON.parse(out) rescue JSON::JSONError, ArgumentError => e puts e.to_s exit end out = out["invoices"] # pp out out end |