abank 0.2.4 → 0.2.5
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 +4 -4
- data/.rubocop.yml +4 -0
- data/Gemfile +4 -2
- data/Gemfile.lock +5 -5
- data/README.md +9 -5
- data/Rakefile +4 -2
- data/abank.gemspec +7 -10
- data/bin/console +4 -3
- data/lib/abank.rb +54 -60
- data/lib/abank/big.rb +94 -98
- data/lib/abank/contrato.rb +79 -52
- data/lib/abank/folha.rb +92 -97
- data/lib/abank/rendas.rb +93 -67
- data/lib/abank/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 357eabd6927351fcd006bf58dda24c7b323395749b4ab6ef4ecf6f596a126241
|
4
|
+
data.tar.gz: 0c3fc3b9e2ebda8bfe13b0ba072f50b0ff303668dfde4ffa7378e04f1470b81e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b11a19c0f7039ff253776441e4f7b7de443808c4bf90dfec078a65dab3342b40197017d36e69d30d09d35500afd6e187ebe7113580e36ef921737085599c26af
|
7
|
+
data.tar.gz: 98daf017bef2b5860fe498c9f11f6881374ebaa87451a10bf24fe1fa95006230c734a6dc1176e036983ec0e991777e59cfebaa34f2c2bc67828d3b95563163ae
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
abank (0.2.
|
4
|
+
abank (0.2.5)
|
5
5
|
google-cloud-bigquery
|
6
6
|
roo
|
7
7
|
thor
|
@@ -17,7 +17,7 @@ GEM
|
|
17
17
|
declarative-option (0.1.0)
|
18
18
|
faraday (1.0.1)
|
19
19
|
multipart-post (>= 1.2, < 3)
|
20
|
-
google-api-client (0.
|
20
|
+
google-api-client (0.40.1)
|
21
21
|
addressable (~> 2.5, >= 2.5.1)
|
22
22
|
googleauth (~> 0.9)
|
23
23
|
httpclient (>= 2.8.1, < 3.0)
|
@@ -25,7 +25,7 @@ GEM
|
|
25
25
|
representable (~> 3.0)
|
26
26
|
retriable (>= 2.0, < 4.0)
|
27
27
|
signet (~> 0.12)
|
28
|
-
google-cloud-bigquery (1.21.
|
28
|
+
google-cloud-bigquery (1.21.1)
|
29
29
|
concurrent-ruby (~> 1.0)
|
30
30
|
google-api-client (~> 0.33)
|
31
31
|
google-cloud-core (~> 1.2)
|
@@ -34,9 +34,9 @@ GEM
|
|
34
34
|
google-cloud-core (1.5.0)
|
35
35
|
google-cloud-env (~> 1.0)
|
36
36
|
google-cloud-errors (~> 1.0)
|
37
|
-
google-cloud-env (1.3.
|
37
|
+
google-cloud-env (1.3.2)
|
38
38
|
faraday (>= 0.17.3, < 2.0)
|
39
|
-
google-cloud-errors (1.0.
|
39
|
+
google-cloud-errors (1.0.1)
|
40
40
|
googleauth (0.12.0)
|
41
41
|
faraday (>= 0.17.3, < 2.0)
|
42
42
|
jwt (>= 1.4, < 3.0)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Abank [](https://travis-ci.com/hernanirvaz/abank)
|
2
2
|
|
3
|
-
Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery. Permite apagar movimentos
|
3
|
+
Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery. Permite apagar/recriar movimentos/rendas ja no bigquery. Permite ainda classificar movimentos no bigquery.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,10 +20,14 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
$ abank
|
24
|
-
$ abank
|
25
|
-
$ abank
|
26
|
-
$ abank
|
23
|
+
$ abank apagamv -k=KEY[,KEY...] # apaga movimentos
|
24
|
+
$ abank apagact -c=CONTRATO # apaga contrato arrendamento
|
25
|
+
$ abank criact -c=CONTRATO # cria contrato arrendamento
|
26
|
+
$ abank recriact -c=CONTRATO # atualiza rendas de contrato arrendamento
|
27
|
+
$ abank recriare # atualiza rendas dos contratos ativos
|
28
|
+
$ abank load # carrega dados da folha calculo
|
29
|
+
$ abank show # mostra dados da folha calculo
|
30
|
+
$ abank tag # classifica movimentos
|
27
31
|
|
28
32
|
## Development
|
29
33
|
|
data/Rakefile
CHANGED
data/abank.gemspec
CHANGED
@@ -10,12 +10,9 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.homepage = 'https://github.com/hernanirvaz/abank'
|
11
11
|
spec.license = 'MIT'
|
12
12
|
|
13
|
-
spec.summary = 'Arquiva
|
14
|
-
|
15
|
-
|
16
|
-
' Pode apagar movimentos similares/existentes' \
|
17
|
-
' ja no bigquery.' \
|
18
|
-
' Pode ainda classificar movimentos ja no bigquery.'
|
13
|
+
spec.summary = 'Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery.'
|
14
|
+
spec.description = spec.summary + ' Permite apagar/recriar movimentos/rendas ja no bigquery. ' \
|
15
|
+
' Permite ainda classificar movimentos no bigquery.'
|
19
16
|
|
20
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
21
18
|
spec.metadata['yard.run'] = 'yard'
|
@@ -24,10 +21,10 @@ Gem::Specification.new do |spec|
|
|
24
21
|
|
25
22
|
# Specify which files should be added to the gem when it is released.
|
26
23
|
# The `git ls-files -z` loads files in RubyGem that have been added into git.
|
27
|
-
spec.files =
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
spec.files =
|
25
|
+
Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
31
28
|
spec.bindir = 'exe'
|
32
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
30
|
spec.require_paths = ['lib']
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'abank'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "abank"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/lib/abank.rb
CHANGED
@@ -9,92 +9,86 @@ require 'abank/version'
|
|
9
9
|
|
10
10
|
# @author Hernani Rodrigues Vaz
|
11
11
|
module Abank
|
12
|
-
|
12
|
+
DR = "/home/#{`whoami`.chomp}/Downloads"
|
13
13
|
|
14
14
|
class Error < StandardError; end
|
15
15
|
|
16
16
|
# CLI para carregar folhas calculo comuns no bigquery
|
17
17
|
class CLI < Thor
|
18
|
-
desc 'tag', 'classifica movimentos
|
19
|
-
# classifica movimentos
|
18
|
+
desc 'tag', 'classifica movimentos'
|
19
|
+
# classifica movimentos
|
20
20
|
def tag
|
21
|
-
Big.new
|
21
|
+
Big.new.mv_classifica
|
22
22
|
end
|
23
23
|
|
24
|
-
desc '
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
desc 'apagamv', 'apaga movimentos'
|
25
|
+
option :k, banner: 'KEY[,KEY...]', required: true, desc: 'keys movimentos a apagar'
|
26
|
+
# apaga movimentos
|
27
|
+
def apagamv
|
28
|
+
Big.new(k: options[:k]).mv_delete.mv_insert.re_work
|
28
29
|
end
|
29
30
|
|
30
|
-
desc '
|
31
|
-
option :
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
desc 'criact', 'cria contrato arrendamento'
|
32
|
+
option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
|
33
|
+
option :t, type: :boolean, default: true, desc: 'cria todas as rendas?'
|
34
|
+
option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
|
35
|
+
# cria contrato arrendamento
|
36
|
+
def criact
|
37
|
+
Big.new(c: options[:c], t: options[:t], d: options[:d]).ct_cria
|
36
38
|
end
|
37
39
|
|
38
|
-
desc '
|
39
|
-
option :
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
option :
|
48
|
-
|
49
|
-
option :
|
50
|
-
|
40
|
+
desc 'apagact', 'apaga contrato arrendamento'
|
41
|
+
option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
|
42
|
+
option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
|
43
|
+
# apaga contrato arrendamento
|
44
|
+
def apagact
|
45
|
+
Big.new(c: options[:c], t: options[:t]).ct_apaga
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'recriact', 'atualiza rendas de contrato arrendamento'
|
49
|
+
option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
|
50
|
+
option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
|
51
|
+
option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
|
52
|
+
# atualiza rendas de contrato arrendamento
|
53
|
+
def recriact
|
54
|
+
Big.new(c: options[:c], t: options[:t]).ct_apaga
|
55
|
+
Big.new(c: options[:c], t: true, d: options[:d]).ct_cria
|
56
|
+
end
|
57
|
+
|
58
|
+
desc 'recriare', 'atualiza rendas dos contratos ativos'
|
59
|
+
option :t, type: :boolean, default: false, desc: 'atualiza todas as rendas?'
|
60
|
+
# atualiza rendas dos contratos ativos
|
61
|
+
def recriare
|
62
|
+
Big.new(t: options[:t]).re_atualiza
|
63
|
+
end
|
64
|
+
|
65
|
+
desc 'load', 'carrega dados da folha calculo'
|
66
|
+
option :s, type: :boolean, default: false, desc: 'apaga movimento similar'
|
67
|
+
option :e, type: :boolean, default: false, desc: 'apaga movimento igual'
|
68
|
+
option :v, banner: 'DATA', default: '', desc: 'data valor para movimentos a carregar'
|
69
|
+
option :g, banner: 'TAG', default: '', desc: 'classificacao para movimentos a carregar'
|
51
70
|
# carrega folha calculo
|
52
71
|
def load
|
53
|
-
Dir.glob("#{
|
54
|
-
Big::Folha.new(f
|
72
|
+
Dir.glob("#{DR}/*.xlsx").sort.each do |f|
|
73
|
+
Big::Folha.new(load_opc.merge(f: f)).processa_xls
|
55
74
|
end
|
56
75
|
end
|
57
76
|
|
58
77
|
desc 'show', 'mostra dados da folha calculo'
|
59
|
-
option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
|
60
|
-
desc: 'Onde procurar folhas calculo'
|
61
78
|
# mostra folha calculo
|
62
79
|
def show
|
63
|
-
Dir.glob("#{
|
64
|
-
Big::Folha.new(f).
|
80
|
+
Dir.glob("#{DR}/*.xlsx").sort.each do |f|
|
81
|
+
Big::Folha.new(f: f).processa_xls
|
65
82
|
end
|
66
83
|
end
|
67
84
|
|
68
|
-
desc 'criare', 'cria contrato arrendamento/rendas no bigquery'
|
69
|
-
option :c, banner: 'CONTRATO', required: true,
|
70
|
-
desc: 'Identificador contrato arrendamento a criar'
|
71
|
-
option :t, type: :boolean, default: true,
|
72
|
-
desc: 'cria todas as rendas?'
|
73
|
-
option :v, banner: 'DATA', default: '',
|
74
|
-
desc: 'data contrato arrendamento a criar'
|
75
|
-
# cria contrato arrendamento/rendas no bigquery
|
76
|
-
def criare
|
77
|
-
Big::Contrato.new(options[:c], { t: options[:t], v: options[:v] }).re_cria
|
78
|
-
end
|
79
|
-
|
80
|
-
desc 'apagare', 'apaga contrato arrendamento/rendas no bigquery'
|
81
|
-
option :c, banner: 'CONTRATO', required: true,
|
82
|
-
desc: 'Identificador contrato arrendamento a apagar'
|
83
|
-
option :t, type: :boolean, default: false,
|
84
|
-
desc: 'apaga todas as rendas?'
|
85
|
-
# apaga contrato arrendamento/rendas no bigquery
|
86
|
-
def apagare
|
87
|
-
Big::Contrato.new(options[:c], { t: options[:t], v: '' }).re_apaga
|
88
|
-
end
|
89
|
-
|
90
85
|
no_commands do
|
91
|
-
# @return [Hash] opcoes trabalho com
|
92
|
-
def
|
93
|
-
{ s: options[:s], e: options[:e],
|
94
|
-
v: options[:v], g: options[:g] }
|
86
|
+
# @return [Hash] opcoes trabalho com movimentos para load
|
87
|
+
def load_opc
|
88
|
+
{ s: options[:s], e: options[:e], i: true, v: options[:v], g: options[:g] }
|
95
89
|
end
|
96
90
|
end
|
97
91
|
|
98
|
-
default_task :
|
92
|
+
default_task :show
|
99
93
|
end
|
100
94
|
end
|
data/lib/abank/big.rb
CHANGED
@@ -2,137 +2,133 @@
|
|
2
2
|
|
3
3
|
require 'google/cloud/bigquery'
|
4
4
|
|
5
|
-
#
|
5
|
+
# @see Abank::Big
|
6
6
|
class Abank::Big
|
7
7
|
DF = '%Y-%m-%d'
|
8
8
|
|
9
|
+
# @return [Hash] opcoes trabalho
|
10
|
+
attr_reader :opcao
|
11
|
+
|
9
12
|
# @return [Google::Cloud::Bigquery] API bigquery
|
10
|
-
attr_reader :
|
11
|
-
# @return [Hash] opcoes trabalho com linhas
|
12
|
-
attr_reader :opl
|
13
|
+
attr_reader :bqapi
|
13
14
|
|
14
15
|
# @return [Google::Cloud::Bigquery::QueryJob] job bigquery
|
15
|
-
attr_reader :
|
16
|
-
# @return [Google::Cloud::Bigquery::Data] lista devolvida pelo select
|
17
|
-
attr_reader :resultados
|
18
|
-
|
19
|
-
# @param [Hash] ops opcoes trabalho
|
20
|
-
# @option ops [Boolean] :s (false) apaga linha similar? (mv)
|
21
|
-
# @option ops [Boolean] :e (false) apaga linha igual? (mv)
|
22
|
-
# @option ops [Boolean] :m (false) apaga linhas existencia multipla? (mv)
|
23
|
-
# @option ops [Boolean] :i (false) insere linha nova? (mv)
|
24
|
-
# @option ops [String] :v ('') data valor (mv)/data contrato (re)
|
25
|
-
# @option ops [String] :g ('') classificacao movimentos (mv)
|
26
|
-
# @option ops [Boolean] :t (false) trabalha todoas as rendas? (re)
|
27
|
-
# @option ops [String] :k ('') keys movimentos a apagar (mv)
|
28
|
-
# @return [Big] acesso bigquery dataset
|
29
|
-
def initialize(ops = {})
|
30
|
-
@opl = ops
|
31
|
-
@api ||= Google::Cloud::Bigquery.new
|
32
|
-
p ['Big', ops, api]
|
33
|
-
end
|
34
|
-
|
35
|
-
# (see CLI#classifica)
|
36
|
-
def mv_classifica
|
37
|
-
return unless opl[:i]
|
38
|
-
|
39
|
-
i = dml('update hernanilr.ab.mv set mv.ct=tt.nct ' \
|
40
|
-
'from (select * from hernanilr.ab.cl) as tt ' \
|
41
|
-
'where mv.dl=tt.dl and mv.dv=tt.dv ' \
|
42
|
-
'and mv.ds=tt.ds and mv.vl=tt.vl')
|
43
|
-
puts 'LINHAS CLASSIFICADAS ' + i.to_s
|
44
|
-
return unless i.positive?
|
45
|
-
|
46
|
-
re_atualiza
|
47
|
-
end
|
48
|
-
|
49
|
-
# (see CLI#atualiza)
|
50
|
-
def re_atualiza
|
51
|
-
r = re_join(lista_ativos)
|
52
|
-
if r.size.zero?
|
53
|
-
puts 'NAO EXISTEM RENDAS NOVAS'
|
54
|
-
else
|
55
|
-
puts 'RENDAS CRIADAS ' + dml('insert hernanilr.ab.re VALUES' + r).to_s
|
56
|
-
end
|
57
|
-
end
|
16
|
+
attr_reader :bqjob
|
58
17
|
|
59
|
-
#
|
60
|
-
|
61
|
-
e = ct_envolvidos
|
62
|
-
i = dml(sql_apaga_mv)
|
63
|
-
puts 'MOVIMENTOS APAGADOS ' + i.to_s
|
64
|
-
return unless i.positive? && e.count.positive?
|
18
|
+
# @return [Google::Cloud::Bigquery::Data] resultado do select
|
19
|
+
attr_reader :bqres
|
65
20
|
|
66
|
-
|
21
|
+
# @return [Integer] numero linhas afetadas pela Data Manipulation Language (DML)
|
22
|
+
attr_reader :bqnrs
|
67
23
|
|
68
|
-
|
69
|
-
|
24
|
+
# @return [String] movimentos a inserir (values.mv)
|
25
|
+
attr_reader :mvvls
|
70
26
|
|
71
|
-
|
72
|
-
|
73
|
-
.delete_if { |k, _| !k || k[0] != 'r' }.keys
|
74
|
-
end
|
27
|
+
# @return [String] movimentos a apagar (keysin.mv)
|
28
|
+
attr_reader :mvkys
|
75
29
|
|
76
|
-
#
|
77
|
-
|
78
|
-
|
30
|
+
# acesso a base dados abank no bigquery
|
31
|
+
#
|
32
|
+
# @param [Hash] opc opcoes trabalho
|
33
|
+
# @option opc [String] :k ('') movimentos a apagar (keysin.mv)
|
34
|
+
# @option opc [String] :c ('') id contrato arrendamento (re)
|
35
|
+
# @option opc [String] :d ('') data inicio contrato arrendamento (re)
|
36
|
+
# @option opc [Boolean] :t (false) trabalha todas as rendas? (re)
|
37
|
+
# @return [Hash] opcoes trabalho
|
38
|
+
def initialize(opc = {})
|
39
|
+
@opcao = opc
|
40
|
+
@bqapi = Google::Cloud::Bigquery.new
|
41
|
+
@mvvls = ''
|
42
|
+
@mvkys = opc.fetch(:k, '')
|
43
|
+
@ctide = opc.fetch(:c, '')
|
44
|
+
# p ['B', opcao]
|
45
|
+
opcao
|
79
46
|
end
|
80
47
|
|
81
|
-
#
|
82
|
-
|
83
|
-
|
84
|
-
|
48
|
+
# (see CLI#tag)
|
49
|
+
def mv_classifica
|
50
|
+
dml('update hernanilr.ab.mv set mv.ct=tt.nct ' \
|
51
|
+
'from (select * from hernanilr.ab.cl) as tt ' \
|
52
|
+
"where #{ky_mv}=tt.ky")
|
53
|
+
puts 'MOVIMENTOS CLASSIFICADOS ' + bqnrs.to_s
|
85
54
|
end
|
86
55
|
|
87
|
-
|
88
|
-
|
56
|
+
# apaga movimentos & suas rendas associadas no bigquery
|
57
|
+
#
|
58
|
+
# @return [Big] acesso a base dados abank no bigquery
|
59
|
+
def mv_delete
|
60
|
+
vars_mv_work
|
61
|
+
if mvkys.size.positive?
|
62
|
+
# obtem lista contratos arrendamento associados aos movimentos a apagar
|
63
|
+
@ctlct = sel("select ct from hernanilr.ab.mv where #{ky_mv} in(#{mvkys}) and substr(ct,1,1)='r' group by 1")
|
64
|
+
|
65
|
+
# apaga rendas associadas e depois movimentos
|
66
|
+
@opcao[:t] = true
|
67
|
+
lr_apaga.mv_delete_dml
|
68
|
+
|
69
|
+
# para obrigar re_work a trabalhar com lista contratos (ctlct)
|
70
|
+
@bqnrs = 0
|
71
|
+
end
|
72
|
+
self
|
89
73
|
end
|
90
74
|
|
91
|
-
|
92
|
-
|
75
|
+
# insere & classifica movimentos no bigquery
|
76
|
+
#
|
77
|
+
# @return [Big] acesso a base dados abank no bigquery
|
78
|
+
def mv_insert
|
79
|
+
if mvvls.size.positive?
|
80
|
+
dml('insert hernanilr.ab.mv VALUES' + mvvls)
|
81
|
+
puts 'MOVIMENTOS INSERIDOS ' + bqnrs.to_s
|
82
|
+
mv_classifica if bqnrs.positive?
|
83
|
+
end
|
84
|
+
self
|
93
85
|
end
|
94
86
|
|
95
|
-
#
|
96
|
-
def
|
97
|
-
|
87
|
+
# inicializa variaveis para delete/insert movimentos
|
88
|
+
def vars_mv_work
|
89
|
+
@bqnrs = 0
|
90
|
+
@ctlct = []
|
91
|
+
@mvkys = mvkys[1..] if mvkys[0] == ','
|
92
|
+
@mvvls = mvvls[1..] if mvvls[0] == ','
|
98
93
|
end
|
99
94
|
|
100
|
-
#
|
101
|
-
def
|
102
|
-
"from hernanilr.ab.mv where #{
|
95
|
+
# apaga movimentos no bigquery
|
96
|
+
def mv_delete_dml
|
97
|
+
dml("delete from hernanilr.ab.mv where #{ky_mv} in(#{mvkys})")
|
98
|
+
puts 'MOVIMENTOS APAGADOS ' + bqnrs.to_s
|
103
99
|
end
|
104
100
|
|
105
|
-
|
106
|
-
|
107
|
-
|
101
|
+
# @return [String] expressao sql da chave de movimentos
|
102
|
+
def ky_mv
|
103
|
+
'FARM_FINGERPRINT(CONCAT(CAST(mv.nc as STRING),mv.ds,CAST(mv.dl as STRING),CAST(mv.vl as STRING)))'
|
108
104
|
end
|
109
105
|
|
110
106
|
# cria job bigquery & verifica execucao
|
111
107
|
#
|
112
|
-
# @param [String] sql comando
|
108
|
+
# @param [String] sql comando a executar
|
113
109
|
# @return [Boolean] job ok?
|
114
|
-
def
|
115
|
-
p sql
|
116
|
-
@
|
117
|
-
@
|
118
|
-
puts @
|
119
|
-
@
|
110
|
+
def job?(sql)
|
111
|
+
# p sql
|
112
|
+
@bqjob = bqapi.query_job(sql)
|
113
|
+
@bqjob.wait_until_done!
|
114
|
+
puts @bqjob.error['message'] if @bqjob.failed?
|
115
|
+
@bqjob.failed?
|
120
116
|
end
|
121
117
|
|
122
|
-
# executa
|
118
|
+
# executa sql & devolve resultado do bigquery
|
123
119
|
#
|
124
|
-
# @param (see
|
125
|
-
# @
|
126
|
-
|
127
|
-
|
120
|
+
# @param (see job?)
|
121
|
+
# @param [Array] erro quando da erro no bigquery
|
122
|
+
# @return [Google::Cloud::Bigquery::Data] resultado do sql
|
123
|
+
def sel(sql, erro = [])
|
124
|
+
@bqres = job?(sql) ? erro : bqjob.data
|
128
125
|
end
|
129
126
|
|
130
|
-
# executa
|
127
|
+
# executa Data Manipulation Language (DML) no bigquery
|
131
128
|
#
|
132
|
-
# @param
|
133
|
-
# @
|
134
|
-
|
135
|
-
|
136
|
-
@resultados = job_bigquery?(sql) ? arr : job.data
|
129
|
+
# @param (see job?)
|
130
|
+
# @return [Integer] numero rows afetadas pelo dml
|
131
|
+
def dml(sql)
|
132
|
+
@bqnrs = job?(sql) ? 0 : bqjob.num_dml_affected_rows
|
137
133
|
end
|
138
134
|
end
|
data/lib/abank/contrato.rb
CHANGED
@@ -1,80 +1,107 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
class Abank::Big
|
5
|
-
# @return [String]
|
6
|
-
attr_reader :
|
7
|
-
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
# acesso a base dados abank no bigquery
|
4
|
+
class Abank::Big
|
5
|
+
# @return [String] id contrato arrendamento
|
6
|
+
attr_reader :ctide
|
7
|
+
|
8
|
+
# @return [Array<Hash>] lista ids contratos arrendamento
|
9
|
+
# @example
|
10
|
+
# [{ ct: 'r03000' }, ...]
|
11
|
+
attr_reader :ctlct
|
12
|
+
|
13
|
+
# @return [Array<Hash>] lista dados contrato arrendamento (inclui lista movimentos novos)
|
14
|
+
# @example
|
15
|
+
# [{ct: 'r03000', dc: '2020-03-01', ano: 2020, cnt: 0, dl: '2020-03-01', mv: [{dl: '2020-03-02', vl: 30}, ...] }]
|
16
|
+
attr_reader :ctlcm
|
14
17
|
|
15
|
-
# (see CLI#
|
16
|
-
def
|
18
|
+
# (see CLI#criact)
|
19
|
+
def ct_cria
|
17
20
|
if existe_contrato?
|
18
|
-
|
19
|
-
puts 'JA EXISTE
|
21
|
+
@bqnrs = 1
|
22
|
+
puts 'CONTRATO JA EXISTE'
|
20
23
|
else
|
21
|
-
|
22
|
-
puts
|
24
|
+
dml('insert into hernanilr.ab.re ' + sql_contrato_mv)
|
25
|
+
puts "CONTRATO #{ctide} " + (bqnrs.zero? ? 'NAO EXISTE' : 'INSERIDO')
|
23
26
|
end
|
24
|
-
return unless
|
27
|
+
return unless existem_rendas?
|
25
28
|
|
26
|
-
|
29
|
+
# processa rendas associadas ao contrato arrendamento
|
30
|
+
cm_cria.vr_cria.re_insert
|
27
31
|
end
|
28
32
|
|
29
|
-
# (see CLI#
|
30
|
-
def
|
31
|
-
|
33
|
+
# (see CLI#apagact)
|
34
|
+
def ct_apaga
|
35
|
+
@ctlct = [{ ct: ctide }]
|
36
|
+
lc_apaga
|
32
37
|
end
|
33
38
|
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
return unless
|
39
|
+
# apaga rendas da lista de contrato arrendamento
|
40
|
+
#
|
41
|
+
# @return [Big] acesso a base dados abank no bigquery
|
42
|
+
def lr_apaga
|
43
|
+
return self unless opcao[:t] && ctlct.count.positive?
|
39
44
|
|
40
|
-
|
45
|
+
# para nao apagar contrato arrendamento - somente as rendas
|
46
|
+
@opcao[:t] = false
|
47
|
+
|
48
|
+
lc_apaga
|
49
|
+
self
|
41
50
|
end
|
42
51
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
'order by ano desc,cnt desc limit 1'
|
52
|
+
# apaga rendas da lista de contratos arrendamento
|
53
|
+
def lc_apaga
|
54
|
+
dml("delete from hernanilr.ab.re where ct in(#{str_lc})#{opcao[:t] ? '' : ' and cnt>0'}")
|
55
|
+
puts "RENDAS #{str_lc('')} APAGADAS " + bqnrs.to_s
|
48
56
|
end
|
49
57
|
|
50
|
-
|
51
|
-
|
52
|
-
|
58
|
+
# @return [String] texto formatado que representa lista de contratos arrendamento
|
59
|
+
def str_lc(sep = "'")
|
60
|
+
ctlct.map { |c| sep + c[:ct] + sep }.join(',')
|
61
|
+
end
|
62
|
+
|
63
|
+
# optem lista dados contrato arrendamento (inclui lista movimentos novos)
|
64
|
+
#
|
65
|
+
# @return [Big] acesso a base dados abank no bigquery
|
66
|
+
def cm_cria
|
67
|
+
@ctlcm = []
|
68
|
+
ctlct.each do |c|
|
69
|
+
@ctide = c[:ct]
|
70
|
+
sel(sql_last_re)
|
71
|
+
@ctlcm << bqres[0].merge({ mv: sel(sql_novo_mv(bqres[0][:dl])) })
|
72
|
+
end
|
73
|
+
self
|
53
74
|
end
|
54
75
|
|
76
|
+
# @return [Boolean] existem rendas para processar sim/nao?
|
77
|
+
def existem_rendas?
|
78
|
+
@ctlct = [{ ct: ctide }]
|
79
|
+
bqnrs.positive? && opcao[:t]
|
80
|
+
end
|
81
|
+
|
82
|
+
# @return [Boolean] contrato arrendamento ja existe sim/nao?
|
55
83
|
def existe_contrato?
|
56
|
-
sel(
|
84
|
+
sel("select ct from hernanilr.ab.re where ct='#{ctide}' and cnt=0").count.positive?
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [String] sql para obter ultima renda do contrato arrendamento
|
88
|
+
def sql_last_re
|
89
|
+
'select ct,DATE_SUB(DATE_SUB(dl,INTERVAL dias DAY),INTERVAL IF(cnt=0,0,cnt-1) MONTH) as dc,ano,cnt,dl ' \
|
90
|
+
"from hernanilr.ab.re where ct='#{ctide}' order by ano desc,cnt desc limit 1"
|
57
91
|
end
|
58
92
|
|
59
|
-
|
60
|
-
|
93
|
+
# @return [String] sql para obter movimentos novos (depois da ultima renda do contrato arrendamento)
|
94
|
+
def sql_novo_mv(mdl)
|
95
|
+
"select dl,vl from hernanilr.ab.mv where ct='#{ctide}' and dl>='#{(mdl + 1).strftime(DF)}' order by dl,dv"
|
61
96
|
end
|
62
97
|
|
63
|
-
# @return [String] sql
|
98
|
+
# @return [String] sql para obter dados do inicio contrato arrendamento
|
64
99
|
def sql_contrato_mv
|
65
|
-
if
|
66
|
-
'select ct,EXTRACT(YEAR FROM DATE_TRUNC(dl,MONTH)) as ano,0 as cnt' \
|
67
|
-
|
68
|
-
"from hernanilr.ab.mv where ct='#{rct}' order by dl limit 1"
|
100
|
+
if opcao[:d].size.zero?
|
101
|
+
'select ct,EXTRACT(YEAR FROM DATE_TRUNC(dl,MONTH)) as ano,0 as cnt,DATE_TRUNC(dl,MONTH) as dl,0 dias ' \
|
102
|
+
"from hernanilr.ab.mv where ct='#{ctide}' order by dl limit 1"
|
69
103
|
else
|
70
|
-
"select '#{
|
71
|
-
",EXTRACT(YEAR FROM DATE '#{opl[:v]}') as ano,0 as cnt" \
|
72
|
-
",DATE '#{opl[:v]}' as dl,0 dias "
|
104
|
+
"select '#{ctide}' as ct,EXTRACT(YEAR FROM DATE '#{opcao[:d]}') as ano,0 as cnt,DATE '#{opcao[:d]}' as dl,0 dias"
|
73
105
|
end
|
74
106
|
end
|
75
|
-
|
76
|
-
def sql_apaga_re
|
77
|
-
"delete from hernanilr.ab.re where ct='#{rct}'" +
|
78
|
-
(opl[:t] ? '' : ' and cnt>0')
|
79
|
-
end
|
80
107
|
end
|
data/lib/abank/folha.rb
CHANGED
@@ -2,158 +2,153 @@
|
|
2
2
|
|
3
3
|
require 'roo'
|
4
4
|
|
5
|
-
#
|
5
|
+
# acesso a folha calculo & base dados abank no bigquery
|
6
6
|
class Abank::Big::Folha < Abank::Big
|
7
|
-
HT = ['Data Lanc.', 'Data Valor', 'Descrição', 'Valor'].freeze
|
8
|
-
RF = '%<v3>-34.34s %<v4>8.2f'
|
9
|
-
EN = ' %<v1>20d'
|
10
|
-
ES = ' %<v1>-20.20s'
|
11
|
-
|
12
7
|
# @return [Roo::Excelx] folha calculo a processar
|
13
8
|
attr_reader :folha
|
14
|
-
|
9
|
+
|
10
|
+
# @return [Integer] numero conta associado a folha calculo
|
11
|
+
# @example
|
12
|
+
# mov*.xlsx --> 1 --> conta-corrente
|
13
|
+
# movCard*.xlsx --> 2 --> conta-cartao
|
15
14
|
attr_reader :conta
|
16
15
|
|
17
16
|
# @return [Array] row folha calculo em processamento
|
18
|
-
attr_reader :
|
19
|
-
|
20
|
-
def initialize(xls, ops = { s: false, e: false, m: false, i: false,
|
21
|
-
v: '', g: '' })
|
22
|
-
p ['Folha', xls, ops]
|
23
|
-
@folha = Roo::Spreadsheet.open(xls) if xls.size.positive?
|
24
|
-
@conta = xls.match?(/card/i) ? 2 : 1
|
25
|
-
super(ops)
|
26
|
-
end
|
17
|
+
attr_reader :rowfc
|
27
18
|
|
28
|
-
#
|
29
|
-
|
19
|
+
# acesso a folha calculo & base dados abank no bigquery
|
20
|
+
#
|
21
|
+
# @param [Hash] opc opcoes trabalho
|
22
|
+
# @option opc [String] :f ('') folha calculo a processar
|
23
|
+
# @option opc [Boolean] :s (false) apaga movimento similar? (mv)
|
24
|
+
# @option opc [Boolean] :e (false) apaga movimento igual? (mv)
|
25
|
+
# @option opc [Boolean] :i (false) insere movimento novo? (mv)
|
26
|
+
# @option opc [String] :v ('') data valor movimentos (mv)
|
27
|
+
# @option opc [String] :g ('') classificacao movimentos (mv)
|
28
|
+
def initialize(opc = {})
|
29
|
+
@opcao = super
|
30
|
+
@folha = Roo::Spreadsheet.open(opc.fetch(:f))
|
31
|
+
@conta = opc.fetch(:f).match?(/card/i) ? 2 : 1
|
32
|
+
@opcao[:s] = opc.fetch(:s, false)
|
33
|
+
@opcao[:e] = opc.fetch(:e, false)
|
34
|
+
@opcao[:i] = opc.fetch(:i, false)
|
35
|
+
@opcao[:v] = opc.fetch(:v, '')
|
36
|
+
@opcao[:g] = opc.fetch(:g, '')
|
37
|
+
end
|
38
|
+
|
39
|
+
# carrega/mostra folha calculo
|
40
|
+
def processa_xls
|
30
41
|
n = 0
|
31
|
-
folha.sheet(0).parse(header_search:
|
42
|
+
folha.sheet(0).parse(header_search: ['Data Lanc.', 'Data Valor', 'Descrição', 'Valor']) do |r|
|
32
43
|
n += 1
|
33
|
-
puts n == 1 ? "\n" + folha.info :
|
44
|
+
puts n == 1 ? "\n" + folha.info : processa_linha(r)
|
34
45
|
end
|
35
|
-
|
46
|
+
return unless opcao[:i]
|
47
|
+
|
48
|
+
# processa movimentos & atualiza rendas
|
49
|
+
mv_delete.mv_insert.re_work
|
36
50
|
end
|
37
51
|
|
38
|
-
# processa linha folha calculo
|
52
|
+
# processa linha folha calculo
|
39
53
|
#
|
40
|
-
# @param
|
41
|
-
# @return [String] texto informativo
|
42
|
-
def
|
43
|
-
|
54
|
+
# @param [Hash] linha da folha calculo em processamento
|
55
|
+
# @return [String] texto informativo formatado da linha em processamento
|
56
|
+
def processa_linha(linha)
|
57
|
+
vars_xls(linha)
|
44
58
|
# pesquisa existencia linha folha calculo no bigquery
|
45
59
|
# array.count = 0 ==> pode carregar esta linha
|
46
60
|
# array.count = 1 ==> mais testes necessarios
|
47
61
|
# array.count > 1 ==> nao pode carregar esta linha
|
48
|
-
sel(
|
49
|
-
if
|
50
|
-
elsif
|
51
|
-
elsif
|
52
|
-
else
|
62
|
+
sel(sql_existe_mv, [{}, {}])
|
63
|
+
if linha_naoexiste? then linha_base + values_mv
|
64
|
+
elsif linha_existe? then linha_existe
|
65
|
+
elsif linha_simila? then linha_similar
|
66
|
+
else linha_multiplas
|
53
67
|
end
|
54
68
|
end
|
55
69
|
|
56
|
-
#
|
70
|
+
# inicializa variavel para processar linha folha calculo
|
57
71
|
#
|
58
|
-
# @param
|
59
|
-
def
|
60
|
-
@
|
61
|
-
@
|
62
|
-
@
|
63
|
-
end
|
64
|
-
|
65
|
-
# @return [String] linha folha calculo formatada
|
66
|
-
def row_str
|
67
|
-
"#{row[0].strftime(DF)} #{format(RF, v3: row[2], v4: row[3])}"
|
72
|
+
# @param (see processa_linha)
|
73
|
+
def vars_xls(linha)
|
74
|
+
@rowfc = linha.values
|
75
|
+
@rowfc[2] = rowfc[2].strip
|
76
|
+
@rowfc[3] = -1 * rowfc[3] if conta > 1
|
68
77
|
end
|
69
78
|
|
70
|
-
# @return [String]
|
71
|
-
def
|
72
|
-
|
73
|
-
row_str + ' SIMI' + str_apagadas(d) + str_extra_s(resultados.first[:ds])
|
79
|
+
# @return [String] texto base formatado para display
|
80
|
+
def linha_base
|
81
|
+
"#{rowfc[0].strftime(DF)} #{format('%<v3>-34.34s %<v4>8.2f', v3: rowfc[2], v4: rowfc[3])}"
|
74
82
|
end
|
75
83
|
|
76
|
-
# @return [String] linha
|
77
|
-
def
|
78
|
-
|
79
|
-
|
84
|
+
# @return [String] texto linha existente formatada para display
|
85
|
+
def linha_existe
|
86
|
+
add_kys if opcao[:e]
|
87
|
+
linha_base + ' EXIS ' + format('%<v1>20d', v1: bqres.first[:ky])
|
80
88
|
end
|
81
89
|
|
82
|
-
|
83
|
-
|
90
|
+
# @return [String] texto linha similar formatada para display
|
91
|
+
def linha_similar
|
92
|
+
add_kys if opcao[:s]
|
93
|
+
linha_base + ' SIMI ' + format('%<v1>-20.20s', v1: bqres.first[:ds].strip)
|
84
94
|
end
|
85
95
|
|
86
|
-
|
87
|
-
|
96
|
+
# @return [String] texto linha existencia multipla formatada para display
|
97
|
+
def linha_multiplas
|
98
|
+
linha_base + ' MULT(' + bqres.count.to_s + ')'
|
88
99
|
end
|
89
100
|
|
90
|
-
#
|
91
|
-
def
|
92
|
-
|
93
|
-
row_str + ' M(' + resultados.count.to_s + ')' + str_apagadas(d)
|
94
|
-
end
|
95
|
-
|
96
|
-
# @param [Integer] numero linhas apagadas
|
97
|
-
# @return [String] texto formatado linhas apagadas
|
98
|
-
def str_apagadas(num)
|
99
|
-
num.positive? ? ' A(' + num.to_s + ')' : ''
|
101
|
+
# obtem chaves movimento (keysin.mv) para apagar
|
102
|
+
def add_kys
|
103
|
+
bqres.each { |r| @mvkys += ",#{r[:ky]}" }
|
100
104
|
end
|
101
105
|
|
102
106
|
# @return [Boolean] linha folha calculo nao existe no bigquery?
|
103
|
-
def
|
104
|
-
|
107
|
+
def linha_naoexiste?
|
108
|
+
bqres.count.zero?
|
105
109
|
end
|
106
110
|
|
107
111
|
# @return [Boolean] linha folha calculo existe no bigquery?
|
108
|
-
def
|
109
|
-
|
112
|
+
def linha_existe?
|
113
|
+
bqres.count == 1 && bqres.first[:ds].strip == rowfc[2]
|
110
114
|
end
|
111
115
|
|
112
116
|
# @return [Boolean] linha folha calculo existe parecida no bigquery?
|
113
|
-
def
|
114
|
-
|
117
|
+
def linha_simila?
|
118
|
+
bqres.count == 1 && bqres.first[:ds].strip != rowfc[2]
|
115
119
|
end
|
116
120
|
|
117
|
-
|
118
|
-
|
121
|
+
# @return [String] sql para movimentos no bigquery
|
122
|
+
def sql_existe_mv
|
123
|
+
"select *,#{ky_mv} as ky from hernanilr.ab.mv " \
|
124
|
+
"where nc=#{conta} and dl='#{rowfc[0].strftime(DF)}' and vl=#{rowfc[3]}"
|
119
125
|
end
|
120
126
|
|
121
|
-
#
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
127
|
+
# obtem movimento (values.mv) para inserir
|
128
|
+
#
|
129
|
+
# @return [String] ' NOVO'
|
130
|
+
def values_mv
|
131
|
+
@mvvls += ",('#{rowfc[0].strftime(DF)}','#{dvc.strftime(DF)}','#{rowfc[2]}',#{rowfc[3]}" + values_mv_extra
|
132
|
+
' NOVO'
|
126
133
|
end
|
127
134
|
|
128
|
-
# @return [
|
129
|
-
def
|
130
|
-
|
131
|
-
|
132
|
-
dml('insert hernanilr.ab.mv(dl,dv,ds,vl,nc,ano,mes,ct,tp) VALUES(' \
|
133
|
-
"'#{row[0].strftime(DF)}','#{dvc.strftime(DF)}','#{row[2]}',#{row[3]}" +
|
134
|
-
str_ins_pc)
|
135
|
+
# @return [String] campos extra do movimento (values.mv) para inserir
|
136
|
+
def values_mv_extra
|
137
|
+
",#{conta},#{dvc.year},#{dvc.month},'#{tpc}',#{ctc})"
|
135
138
|
end
|
136
139
|
|
137
140
|
# @return [Date] data valor corrigida
|
138
141
|
def dvc
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
# @return [String] campos extra da linha bigquery
|
143
|
-
def str_ins_pc
|
144
|
-
",#{conta},#{dvc.year},#{dvc.month},#{ctc},'#{tpc}')"
|
142
|
+
opcao[:v].size.zero? ? rowfc[1] : Date.parse(opcao[:v])
|
145
143
|
end
|
146
144
|
|
145
|
+
# @return [String] classificacao do movimento (null --> classificacao automatica)
|
147
146
|
def ctc
|
148
|
-
|
147
|
+
opcao[:g].size.zero? ? 'null' : ("'" + opcao[:g] + "'")
|
149
148
|
end
|
150
149
|
|
150
|
+
# @return [String] tipo movimento c[redito] ou d[ebito]
|
151
151
|
def tpc
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
# @return [Integer] numero linhas apagadas
|
156
|
-
def delete_mv
|
157
|
-
dml('delete ' + sql_where_mv + " and ds='#{resultados.first[:ds]}'")
|
152
|
+
rowfc[3].positive? ? 'c' : 'd'
|
158
153
|
end
|
159
154
|
end
|
data/lib/abank/rendas.rb
CHANGED
@@ -1,95 +1,121 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
class Abank::Big
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
# @see Abank::Big
|
4
|
+
class Abank::Big
|
5
|
+
# @return [Integer] ano renda em tratamento
|
6
|
+
attr_reader :reano
|
7
|
+
|
8
|
+
# @return [Integer] mes renda em tratamento
|
9
|
+
attr_reader :repos
|
10
|
+
|
11
11
|
# @return [Float] valor renda mensal
|
12
|
-
attr_reader :
|
12
|
+
attr_reader :revre
|
13
|
+
|
14
|
+
# @return [String] rendas a inserir (values.re)
|
15
|
+
attr_reader :revls
|
13
16
|
|
14
|
-
# @return [Integer] total de movimentos novos
|
15
|
-
attr_reader :mcn
|
16
17
|
# @return [Integer] movimento em tratamento
|
17
|
-
attr_reader :
|
18
|
+
attr_reader :mvpos
|
19
|
+
|
18
20
|
# @return [Date] data lancamento movimento em tratamento
|
19
|
-
attr_reader :
|
21
|
+
attr_reader :mvdlm
|
22
|
+
|
20
23
|
# @return [Float] valor movimento em tratamento
|
21
|
-
attr_reader :
|
22
|
-
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
def initialize(ren)
|
31
|
-
p ['Rendas', ren]
|
32
|
-
@ren = ren
|
33
|
-
super(ren[:ct])
|
24
|
+
attr_reader :mvvlm
|
25
|
+
|
26
|
+
# (see CLI#recriare)
|
27
|
+
def re_atualiza
|
28
|
+
# obtem contratos ativos
|
29
|
+
@ctlct = sel('SELECT ct from hernanilr.ab.re group by 1')
|
30
|
+
|
31
|
+
# [re]cria rendas [novas|todas]
|
32
|
+
lr_apaga.cm_cria.vr_cria.re_insert
|
34
33
|
end
|
35
34
|
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
35
|
+
# cria rendas associadas a lista ids contratos arrendamento
|
36
|
+
def re_work
|
37
|
+
bqnrs.zero? || ctlct.count.positive? ? cm_cria.vr_cria.re_insert : re_atualiza
|
38
|
+
end
|
39
|
+
|
40
|
+
# obtem rendas a inserir (values.re)
|
41
|
+
#
|
42
|
+
# @return [Big] acesso a base dados abank no bigquery
|
43
|
+
def vr_cria
|
44
|
+
@revls = ctlcm.map { |c| rendas_novas(c) }.flatten(1).join(',')
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
# insere rendas no bigquery
|
49
|
+
def re_insert
|
50
|
+
if revls.size.zero?
|
51
|
+
puts 'NAO EXISTEM RENDAS NOVAS'
|
52
|
+
else
|
53
|
+
dml('insert hernanilr.ab.re VALUES' + revls)
|
54
|
+
puts "RENDAS #{str_lc('')} CRIADAS " + bqnrs.to_s
|
45
55
|
end
|
46
|
-
r
|
47
56
|
end
|
48
57
|
|
49
|
-
# @param (
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
58
|
+
# @param [Hash] cmv dados contrato arrendamento (inclui lista movimentos novos)
|
59
|
+
# @return [Array<String>] lista rendas novas dum contrato arrendamento (values.re)
|
60
|
+
def rendas_novas(cmv)
|
61
|
+
return [] unless cmv[:mv].count.positive?
|
62
|
+
|
63
|
+
vars_re(cmv)
|
64
|
+
r = []
|
65
|
+
while mvvlm >= revre && mvpos < cmv[:mv].count
|
66
|
+
r << nova_re(cmv)
|
67
|
+
proximo_mv(cmv)
|
68
|
+
end
|
69
|
+
r
|
54
70
|
end
|
55
71
|
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
@
|
72
|
+
# inicializa variaveis para processar rendas do contrato arrendamento
|
73
|
+
# @param (see rendas_novas)
|
74
|
+
def vars_re(cmv)
|
75
|
+
@reano = cmv[:ano]
|
76
|
+
@repos = cmv[:cnt]
|
77
|
+
@revre = Float(cmv[:ct][/\d+/]) / 100
|
78
|
+
@mvpos = 0
|
79
|
+
vars_re_mv(cmv)
|
60
80
|
end
|
61
81
|
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
@
|
66
|
-
@
|
82
|
+
# inicializa variaveis para processar movimentos associados ao contrato arrendamento
|
83
|
+
# @param (see rendas_novas)
|
84
|
+
def vars_re_mv(cmv)
|
85
|
+
@mvdlm = cmv[:mv][mvpos][:dl]
|
86
|
+
@mvvlm = cmv[:mv][mvpos][:vl]
|
67
87
|
end
|
68
88
|
|
69
|
-
# @
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
89
|
+
# @param (see rendas_novas)
|
90
|
+
# @return [String] renda formatada (values.re)
|
91
|
+
def nova_re(cmv)
|
92
|
+
# inicializa proxima renda
|
93
|
+
if repos == 12
|
94
|
+
@repos = 1
|
95
|
+
@reano += 1
|
74
96
|
else
|
75
|
-
@
|
97
|
+
@repos += 1
|
76
98
|
end
|
77
|
-
#
|
78
|
-
"('#{rct}',#{ran},#{rcn},'#{mdl.strftime(DF)}',#{dias})"
|
99
|
+
"('#{cmv[:ct]}',#{reano},#{repos},'#{mvdlm.strftime(DF)}',#{dias(cmv)})"
|
79
100
|
end
|
80
101
|
|
81
|
-
|
82
|
-
|
102
|
+
# @param (see rendas_novas)
|
103
|
+
# @return [Integer] dias atraso no pagamento da renda
|
104
|
+
def dias(cmv)
|
105
|
+
mvdlm.mjd - (Date.new(reano, repos, 1) >> (cmv[:dc].month - 1)).mjd
|
83
106
|
end
|
84
107
|
|
85
|
-
#
|
86
|
-
|
87
|
-
|
88
|
-
|
108
|
+
# inicializa variaveis para processar proximo movimento
|
109
|
+
# @param (see rendas_novas)
|
110
|
+
def proximo_mv(cmv)
|
111
|
+
# valor renda paga retirado do valor do movimento
|
112
|
+
@mvvlm -= revre
|
113
|
+
return unless mvvlm < revre
|
89
114
|
|
90
|
-
|
91
|
-
|
115
|
+
# avanca na lista de movimentos
|
116
|
+
@mvpos += 1
|
117
|
+
return unless mvpos < cmv[:mv].count
|
92
118
|
|
93
|
-
|
119
|
+
vars_re_mv(cmv)
|
94
120
|
end
|
95
121
|
end
|
data/lib/abank/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hernâni Rodrigues Vaz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,9 +94,9 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description: Arquiva
|
98
|
-
apagar movimentos
|
99
|
-
|
97
|
+
description: Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery.
|
98
|
+
Permite apagar/recriar movimentos/rendas ja no bigquery. Permite ainda classificar
|
99
|
+
movimentos no bigquery.
|
100
100
|
email:
|
101
101
|
- hernanirvaz@gmail.com
|
102
102
|
executables:
|
@@ -143,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
|
-
rubygems_version: 3.0.
|
146
|
+
rubygems_version: 3.0.8
|
147
147
|
signing_key:
|
148
148
|
specification_version: 4
|
149
|
-
summary: Arquiva
|
149
|
+
summary: Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery.
|
150
150
|
test_files: []
|