abank 0.2.4 → 0.2.10

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: f1720d3e8b1de4bc6ea635712404363e460b3550af47a665a06652fae028f917
4
- data.tar.gz: eef494213d2f5bf45887a1f643ec2f1becf2d470e9cc5451c2412dd41d9696c2
3
+ metadata.gz: 84af9c14c7d615540fdb2b6ca02452fc7401fe6ba15e1f67e9cda7b7e1e776c2
4
+ data.tar.gz: 0d062d44e2a74adc8435e169c79289924b187e222f40b176ed8829e3ee363c2f
5
5
  SHA512:
6
- metadata.gz: eb2aa5a87322b5cb27fb2fac24cd99d5288eb3be339a0976cd2d2cd12c3ee46b63c2e09e8060c16dd3f07197ba837ecf6fa612a658f86cb3c7875a5546dd16b5
7
- data.tar.gz: 9498f7fa1b1a5cbdf4c56b39cd770073eb13642d669847fecdd5a1b3285dd3ffc15fb0e6437a8e2758d6223e4e128e7eb0664e6f6ffb42cc73d3d1ce46380ea9
6
+ metadata.gz: 169af6db74fa54a8dddef3cbc504b0e5f1d902c0628df9d4f60b742c6deef19e4a400e7065c2fe9031c4a1f98519991b3a5f84c1ed8cfa7fd01de784bbd677ee
7
+ data.tar.gz: 11786fa35a4b31532c2b0cea7c728f5e73ad7b0e2a8d95630a941822c7a713fda7848ae263c8d9f4d4550d4942f6741fc796d0b3ec1928930090f46a0fbdb5d7
@@ -1,29 +1,15 @@
1
1
  AllCops:
2
+ TargetRubyVersion: 2.7
2
3
  EnabledByDefault: true
3
4
 
4
- Style/ClassAndModuleChildren:
5
- EnforcedStyle: compact
6
-
7
5
  Style/Copyright:
8
- Enabled: false
9
-
10
- Style/DocumentationMethod:
11
- Enabled: false
6
+ Enabled: false
12
7
 
13
- Style/MethodCallWithArgsParentheses:
14
- Enabled: false
8
+ Lint/ConstantResolution:
9
+ Enabled: false
15
10
 
16
11
  Style/ConstantVisibility:
17
- Enabled: false
18
-
19
- Layout/MultilineMethodArgumentLineBreaks:
20
- Enabled: false
21
-
22
- Layout/MultilineHashKeyLineBreaks:
23
- Enabled: false
24
-
25
- Layout/FirstMethodParameterLineBreak:
26
- Enabled: false
12
+ Enabled: false
27
13
 
28
- Layout/FirstHashElementLineBreak:
29
- Enabled: false
14
+ Style/EmptyElse:
15
+ EnforcedStyle: nil
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in abank.gemspec
4
6
  gemspec
5
7
 
6
- gem "rake", "~> 12.0"
8
+ gem 'rake', '~> 12.0'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abank (0.2.4)
4
+ abank (0.2.10)
5
5
  google-cloud-bigquery
6
6
  roo
7
7
  thor
@@ -12,20 +12,21 @@ GEM
12
12
  specs:
13
13
  addressable (2.7.0)
14
14
  public_suffix (>= 2.0.2, < 5.0)
15
- concurrent-ruby (1.1.6)
16
- declarative (0.0.10)
15
+ concurrent-ruby (1.1.7)
16
+ declarative (0.0.20)
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.39.5)
20
+ google-api-client (0.45.0)
21
21
  addressable (~> 2.5, >= 2.5.1)
22
22
  googleauth (~> 0.9)
23
23
  httpclient (>= 2.8.1, < 3.0)
24
24
  mini_mime (~> 1.0)
25
25
  representable (~> 3.0)
26
26
  retriable (>= 2.0, < 4.0)
27
+ rexml
27
28
  signet (~> 0.12)
28
- google-cloud-bigquery (1.21.0)
29
+ google-cloud-bigquery (1.23.0)
29
30
  concurrent-ruby (~> 1.0)
30
31
  google-api-client (~> 0.33)
31
32
  google-cloud-core (~> 1.2)
@@ -34,10 +35,10 @@ GEM
34
35
  google-cloud-core (1.5.0)
35
36
  google-cloud-env (~> 1.0)
36
37
  google-cloud-errors (~> 1.0)
37
- google-cloud-env (1.3.1)
38
+ google-cloud-env (1.3.3)
38
39
  faraday (>= 0.17.3, < 2.0)
39
- google-cloud-errors (1.0.0)
40
- googleauth (0.12.0)
40
+ google-cloud-errors (1.0.1)
41
+ googleauth (0.13.1)
41
42
  faraday (>= 0.17.3, < 2.0)
42
43
  jwt (>= 1.4, < 3.0)
43
44
  memoist (~> 0.16)
@@ -45,22 +46,23 @@ GEM
45
46
  os (>= 0.9, < 2.0)
46
47
  signet (~> 0.14)
47
48
  httpclient (2.8.3)
48
- jwt (2.2.1)
49
+ jwt (2.2.2)
49
50
  memoist (0.16.2)
50
51
  mini_mime (1.0.2)
51
52
  mini_portile2 (2.4.0)
52
- multi_json (1.14.1)
53
+ multi_json (1.15.0)
53
54
  multipart-post (2.1.1)
54
- nokogiri (1.10.9)
55
+ nokogiri (1.10.10)
55
56
  mini_portile2 (~> 2.4.0)
56
- os (1.1.0)
57
- public_suffix (4.0.5)
57
+ os (1.1.1)
58
+ public_suffix (4.0.6)
58
59
  rake (12.3.3)
59
60
  representable (3.0.4)
60
61
  declarative (< 0.1.0)
61
62
  declarative-option (< 0.2.0)
62
63
  uber (< 0.2.0)
63
64
  retriable (3.1.2)
65
+ rexml (3.2.4)
64
66
  roo (2.8.3)
65
67
  nokogiri (~> 1)
66
68
  rubyzip (>= 1.3.0, < 3.0.0)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Abank [![Build Status](https://travis-ci.com/hernanirvaz/abank.svg?branch=master)](https://travis-ci.com/hernanirvaz/abank)
2
2
 
3
- Arquiva movimentos conta-corrente, conta-cartao do activobank no bigquery. Permite apagar movimentos similares/existentes ja no bigquery. Permite ainda classificar movimentos ja no bigquery.
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 help [COMANDO] # ajuda aos comandos
24
- $ abank mostra # mostra dados da folha calculo
25
- $ abank load # carrega dados da folha calculo no bigquery
26
- $ abank classifica # classifica arquivo no bigquery
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
@@ -1,2 +1,4 @@
1
- require "bundler/gem_tasks"
2
- task :default => :build
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :build
@@ -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 <conta-corrente>.xlsx,' \
14
- ' <conta-cartao>.xlsx no bigquery.'
15
- spec.description = spec.summary +
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 = Dir.chdir(File.expand_path(__dir__)) do
28
- `git ls-files -z`.split("\x0")
29
- .reject { |f| f.match(%r{^(test|spec|features)/}) }
30
- end
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']
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "abank"
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 "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,100 +1,95 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thor'
4
- require 'abank/big'
5
- require 'abank/contrato'
6
- require 'abank/folha'
7
- require 'abank/rendas'
8
- require 'abank/version'
3
+ require('thor')
4
+ require('abank/big')
5
+ require('abank/contrato')
6
+ require('abank/rendas')
7
+ require('abank/folha')
8
+ require('abank/version')
9
9
 
10
10
  # @author Hernani Rodrigues Vaz
11
11
  module Abank
12
- ID = `whoami`.chomp
12
+ DR = "/home/#{`whoami`.chomp}/Downloads"
13
+ BD = 'hernanilr.ab'
13
14
 
14
15
  class Error < StandardError; end
15
16
 
16
17
  # CLI para carregar folhas calculo comuns no bigquery
17
18
  class CLI < Thor
18
- desc 'tag', 'classifica movimentos no bigquery'
19
- # classifica movimentos no bigquery
19
+ desc 'tag', 'classifica movimentos'
20
+ # classifica movimentos
20
21
  def tag
21
- Big.new(i: true).mv_classifica
22
+ Big.new.mv_classifica
22
23
  end
23
24
 
24
- desc 'rendas', 'atualiza rendas no bigquery'
25
- # atualiza rendas no bigquery
26
- def rendas
27
- Big.new.re_atualiza
25
+ desc 'apagamv', 'apaga movimentos'
26
+ option :k, banner: 'KEY[,KEY...]', required: true, desc: 'keys movimentos a apagar'
27
+ # apaga movimentos
28
+ def apagamv
29
+ Big.new(k: options[:k]).mv_delete.mv_insert.re_work
28
30
  end
29
31
 
30
- desc 'apaga', 'apaga movimentos no bigquery'
31
- option :k, banner: 'k1[,k2,...]', required: true,
32
- desc: 'Keys movimentos a apagar'
33
- # apaga movimentos no bigquery
34
- def apaga
35
- Big.new(k: options[:k]).mv_apaga
32
+ desc 'criact', 'cria contrato arrendamento'
33
+ option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
34
+ option :t, type: :boolean, default: true, desc: 'cria todas as rendas?'
35
+ option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
36
+ # cria contrato arrendamento
37
+ def criact
38
+ Big.new(c: options[:c], t: options[:t], d: options[:d]).ct_cria
36
39
  end
37
40
 
38
- desc 'load', 'carrega dados da folha calculo no bigquery'
39
- option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
40
- desc: 'Onde procurar folhas calculo'
41
- option :v, banner: 'DATA', default: '',
42
- desc: 'data valor para movimentos a carregar'
43
- option :g, banner: 'TAG', default: '',
44
- desc: 'classificacao para movimentos a carregar'
45
- option :s, type: :boolean, default: false,
46
- desc: 'apaga linha similar no bigquery'
47
- option :e, type: :boolean, default: false,
48
- desc: 'apaga linha igual no bigquery'
49
- option :m, type: :boolean, default: false,
50
- desc: 'apaga linhas existencia multipla no bigquery'
51
- # carrega folha calculo
52
- def load
53
- Dir.glob("#{options[:d]}/*.xlsx").sort.each do |f|
54
- Big::Folha.new(f, load_ops).processa_folha
41
+ desc 'apagact', 'apaga contrato arrendamento'
42
+ option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
43
+ option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
44
+ # apaga contrato arrendamento
45
+ def apagact
46
+ Big.new(c: options[:c], t: options[:t]).ct_apaga
47
+ end
48
+
49
+ desc 'recriact', 'atualiza rendas de contrato arrendamento'
50
+ option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
51
+ option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
52
+ option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
53
+ # atualiza rendas de contrato arrendamento
54
+ def recriact
55
+ Big.new(c: options[:c], t: options[:t]).ct_apaga
56
+ Big.new(c: options[:c], t: true, d: options[:d]).ct_cria
57
+ end
58
+
59
+ desc 'recriare', 'atualiza rendas dos contratos ativos'
60
+ option :t, type: :boolean, default: false, desc: 'atualiza todas as rendas?'
61
+ # atualiza rendas dos contratos ativos
62
+ def recriare
63
+ Big.new(t: options[:t]).re_atualiza
64
+ end
65
+
66
+ desc 'work', 'carrega/apaga dados da folha calculo'
67
+ option :s, type: :boolean, default: false, desc: 'apaga movimento similar'
68
+ option :e, type: :boolean, default: false, desc: 'apaga movimento igual'
69
+ option :v, banner: 'DATA', default: '', desc: 'data valor para movimentos a carregar'
70
+ option :g, banner: 'TAG', default: '', desc: 'classificacao para movimentos a carregar'
71
+ # carrega/apaga dados da folha calculo
72
+ def work
73
+ Dir.glob("#{DR}/*.xlsx").sort.each do |f|
74
+ Folha.new(work_opc.merge(f: f)).processa_xls
55
75
  end
56
76
  end
57
77
 
58
78
  desc 'show', 'mostra dados da folha calculo'
59
- option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
60
- desc: 'Onde procurar folhas calculo'
61
79
  # mostra folha calculo
62
80
  def show
63
- Dir.glob("#{options[:d]}/*.xlsx").sort.each do |f|
64
- Big::Folha.new(f).processa_folha
81
+ Dir.glob("#{DR}/*.xlsx").sort.each do |f|
82
+ Folha.new(f: f).processa_xls
65
83
  end
66
84
  end
67
85
 
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
86
  no_commands do
91
- # @return [Hash] opcoes trabalho com linhas para load
92
- def load_ops
93
- { s: options[:s], e: options[:e], m: options[:m], i: true,
94
- v: options[:v], g: options[:g] }
87
+ # @return [Hash] opcoes trabalho com movimentos para work
88
+ def work_opc
89
+ { s: options[:s], e: options[:e], i: true, v: options[:v], g: options[:g] }
95
90
  end
96
91
  end
97
92
 
98
- default_task :rendas
93
+ default_task :show
99
94
  end
100
95
  end
@@ -1,138 +1,135 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'google/cloud/bigquery'
4
-
5
- # class Contrato
6
- class Abank::Big
7
- DF = '%Y-%m-%d'
8
-
9
- # @return [Google::Cloud::Bigquery] API bigquery
10
- attr_reader :api
11
- # @return [Hash] opcoes trabalho com linhas
12
- attr_reader :opl
13
-
14
- # @return [Google::Cloud::Bigquery::QueryJob] job bigquery
15
- attr_reader :job
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
3
+ require('google/cloud/bigquery')
4
+
5
+ module Abank
6
+ # @see Big
7
+ class Big
8
+ DF = '%Y-%m-%d'
9
+
10
+ # @return [Hash] opcoes trabalho
11
+ attr_reader :opcao
12
+
13
+ # @return [Google::Cloud::Bigquery] API bigquery
14
+ attr_reader :bqapi
15
+
16
+ # @return [Google::Cloud::Bigquery::QueryJob] job bigquery
17
+ attr_reader :bqjob
18
+
19
+ # @return [Google::Cloud::Bigquery::Data] resultado do select
20
+ attr_reader :bqres
21
+
22
+ # @return [Integer] numero linhas afetadas pela Data Manipulation Language (DML)
23
+ attr_reader :bqnrs
24
+
25
+ # @return [String] movimentos a inserir (values.mv)
26
+ attr_reader :mvvls
27
+
28
+ # @return [String] movimentos a apagar (keysin.mv)
29
+ attr_reader :mvkys
30
+
31
+ # acesso a base dados abank no bigquery
32
+ #
33
+ # @param [Hash] opc opcoes trabalho
34
+ # @option opc [String] :k ('') movimentos a apagar (keysin.mv)
35
+ # @option opc [String] :c ('') id contrato arrendamento (re)
36
+ # @option opc [String] :d ('') data inicio contrato arrendamento (re)
37
+ # @option opc [Boolean] :t (false) trabalha todas as rendas? (re)
38
+ # @return [Hash] opcoes trabalho
39
+ def initialize(opc = {})
40
+ @opcao = opc
41
+ @bqapi = Google::Cloud::Bigquery.new
42
+ @mvvls = ''
43
+ @mvkys = opc.fetch(:k, '')
44
+ @ctide = opc.fetch(:c, '')
45
+ opcao
56
46
  end
57
- end
58
-
59
- # (see CLI#apagamv)
60
- def mv_apaga
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?
65
47
 
66
- e.map { |c| Contrato.new(c).re_apaga }
67
-
68
- re_atualiza
69
- end
70
-
71
- def ct_envolvidos
72
- sel(sql_sel_mv).group_by { |r| r[:ct] }
73
- .delete_if { |k, _| !k || k[0] != 'r' }.keys
74
- end
75
-
76
- # @return [Array<Hash>] lista contratos com lista movimentos novos
77
- def lista_ativos
78
- sel(sql_ativos_re).map { |c| Contrato.new(c[:ct]).dados_contrato }.compact
79
- end
80
-
81
- # @param [Array<Hash>] lct lista contratos com lista movimentos novos
82
- # @return [String] row formatada das novas rendas para inserir bigquery
83
- def re_join(lct)
84
- lct.map { |c| Contrato::Rendas.new(c).rendas }.flatten(1).join(',')
85
- end
48
+ # (see CLI#tag)
49
+ def mv_classifica
50
+ dml("update #{BD}.mv set mv.ct=tt.nct from (select * from #{BD}.cl) as tt where #{ky_mv}=tt.ky")
51
+ puts("MOVIMENTOS CLASSIFICADOS #{bqnrs}")
52
+ end
86
53
 
87
- def sql_ativos_re
88
- 'SELECT ct from hernanilr.ab.re group by 1 order by 1'
89
- end
54
+ # apaga movimentos & suas rendas associadas no bigquery
55
+ #
56
+ # @return [Big] acesso a base dados abank no bigquery
57
+ def mv_delete
58
+ vars_mv_work
59
+ if mvkys.size.positive?
60
+ # obtem lista contratos arrendamento associados aos movimentos a apagar
61
+ @ctlct = sql("select ct from #{BD}.mv where #{ky_mv} in(#{mvkys}) and substr(ct,1,1)='r' group by 1")
62
+
63
+ # apaga rendas associadas e depois movimentos
64
+ @opcao[:t] = true
65
+ lr_apaga.mv_delete_dml
66
+
67
+ # para obrigar re_work a trabalhar com lista contratos (ctlct)
68
+ @bqnrs = 0
69
+ else
70
+ end
71
+ self
72
+ end
90
73
 
91
- def sql_sel_mv
92
- 'select * ' + sql_where_mv
93
- end
74
+ # insere & classifica movimentos no bigquery
75
+ #
76
+ # @return [Big] acesso a base dados abank no bigquery
77
+ def mv_insert
78
+ if mvvls.size.positive?
79
+ dml("insert #{BD}.mv VALUES#{mvvls}")
80
+ puts("MOVIMENTOS INSERIDOS #{bqnrs}")
81
+ mv_classifica if bqnrs.positive?
82
+ else
83
+ end
84
+ self
85
+ end
94
86
 
95
- # @return [String] sql apaga movimentos
96
- def sql_apaga_mv
97
- 'delete ' + sql_where_mv
98
- end
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] == ','
93
+ end
99
94
 
100
- # @return [String] parte sql para processamento movimentos
101
- def sql_where_mv
102
- "from hernanilr.ab.mv where #{sql_digest_mv} in(#{opl[:k]})"
103
- end
95
+ # apaga movimentos no bigquery
96
+ def mv_delete_dml
97
+ dml("delete from #{BD}.mv where #{ky_mv} in(#{mvkys})")
98
+ puts("MOVIMENTOS APAGADOS #{bqnrs}")
99
+ end
104
100
 
105
- def sql_digest_mv
106
- 'FARM_FINGERPRINT(CONCAT(CAST(nc as STRING),' \
107
- 'ds,CAST(dl as STRING),CAST(vl as STRING)))'
108
- end
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)))'
104
+ end
109
105
 
110
- # cria job bigquery & verifica execucao
111
- #
112
- # @param [String] sql comando sql a executar
113
- # @return [Boolean] job ok?
114
- def job_bigquery?(sql)
115
- p sql
116
- @job = api.query_job(sql)
117
- @job.wait_until_done!
118
- puts @job.error['message'] if @job.failed?
119
- @job.failed?
120
- end
106
+ # cria job bigquery & verifica execucao
107
+ #
108
+ # @param [String] cmd comando a executar
109
+ # @return [Boolean] job ok?
110
+ def job?(cmd)
111
+ # p cmd
112
+ @bqjob = bqapi.query_job(cmd)
113
+ @bqjob.wait_until_done!
114
+ puts(@bqjob.error['message']) if @bqjob.failed?
115
+ @bqjob.failed?
116
+ end
121
117
 
122
- # executa Data Manipulation Language (DML) job no bigquery
123
- #
124
- # @param (see job_bigquery?)
125
- # @return [Integer] numero linhas afetadas
126
- def dml(sql)
127
- job_bigquery?(sql) ? 0 : job.num_dml_affected_rows
128
- end
118
+ # executa sql & devolve resultado do bigquery
119
+ #
120
+ # @param (see job?)
121
+ # @param [Array] erro quando da erro no bigquery
122
+ # @return [Google::Cloud::Bigquery::Data] resultado do sql
123
+ def sql(cmd, erro = [])
124
+ @bqres = job?(cmd) ? erro : bqjob.data
125
+ end
129
126
 
130
- # executa sql & devolve resultados do bigquery
131
- #
132
- # @param sql (see job_bigquery?)
133
- # @param [Array] arr resultado quando da erro no bigquery
134
- # @return [Google::Cloud::Bigquery::Data] resultado do sql num array<hash>
135
- def sel(sql, arr = [])
136
- @resultados = job_bigquery?(sql) ? arr : job.data
127
+ # executa Data Manipulation Language (DML) no bigquery
128
+ #
129
+ # @param (see job?)
130
+ # @return [Integer] numero rows afetadas pelo dml
131
+ def dml(cmd)
132
+ @bqnrs = job?(cmd) ? 0 : bqjob.num_dml_affected_rows
133
+ end
137
134
  end
138
135
  end