abank 0.2.10 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84af9c14c7d615540fdb2b6ca02452fc7401fe6ba15e1f67e9cda7b7e1e776c2
4
- data.tar.gz: 0d062d44e2a74adc8435e169c79289924b187e222f40b176ed8829e3ee363c2f
3
+ metadata.gz: 38252e611997b04e79e9743c3e9027906a47b3eb9252cf2a0d26526fe957d422
4
+ data.tar.gz: 927a605ae99f62cd66439d0f5468bb2da4ba2174ac9d3b7888fe72bda4dc6043
5
5
  SHA512:
6
- metadata.gz: 169af6db74fa54a8dddef3cbc504b0e5f1d902c0628df9d4f60b742c6deef19e4a400e7065c2fe9031c4a1f98519991b3a5f84c1ed8cfa7fd01de784bbd677ee
7
- data.tar.gz: 11786fa35a4b31532c2b0cea7c728f5e73ad7b0e2a8d95630a941822c7a713fda7848ae263c8d9f4d4550d4942f6741fc796d0b3ec1928930090f46a0fbdb5d7
6
+ metadata.gz: 0dc5655f4c39df0465f00506df19c87b81359c1d2c7ac5fe910b8daf25bd6aa2c59514693437bed6d35dc2c90ef022ab703afc3c14db18e38672fd90fd67318d
7
+ data.tar.gz: 5f97e3013d807922e1e6cc18d0636f5f02dbe0e0d83485520a582ab285915f7f71f44b526ad45a16f8931251c3c94d0f0453903db720570b89770a8d8d3fec4f
@@ -1,23 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abank (0.2.10)
4
+ abank (0.3.1)
5
5
  google-cloud-bigquery
6
6
  roo
7
7
  thor
8
- yard
9
8
 
10
9
  GEM
11
10
  remote: https://rubygems.org/
12
11
  specs:
13
12
  addressable (2.7.0)
14
13
  public_suffix (>= 2.0.2, < 5.0)
14
+ ast (2.4.1)
15
+ backport (1.1.2)
16
+ benchmark (0.1.0)
15
17
  concurrent-ruby (1.1.7)
16
18
  declarative (0.0.20)
17
19
  declarative-option (0.1.0)
18
- faraday (1.0.1)
20
+ e2mmap (0.1.0)
21
+ faraday (1.1.0)
19
22
  multipart-post (>= 1.2, < 3)
20
- google-api-client (0.45.0)
23
+ ruby2_keywords
24
+ google-api-client (0.50.0)
21
25
  addressable (~> 2.5, >= 2.5.1)
22
26
  googleauth (~> 0.9)
23
27
  httpclient (>= 2.8.1, < 3.0)
@@ -26,19 +30,19 @@ GEM
26
30
  retriable (>= 2.0, < 4.0)
27
31
  rexml
28
32
  signet (~> 0.12)
29
- google-cloud-bigquery (1.23.0)
33
+ google-cloud-bigquery (1.25.0)
30
34
  concurrent-ruby (~> 1.0)
31
- google-api-client (~> 0.33)
35
+ google-api-client (~> 0.47)
32
36
  google-cloud-core (~> 1.2)
33
37
  googleauth (~> 0.9)
34
38
  mini_mime (~> 1.0)
35
39
  google-cloud-core (1.5.0)
36
40
  google-cloud-env (~> 1.0)
37
41
  google-cloud-errors (~> 1.0)
38
- google-cloud-env (1.3.3)
42
+ google-cloud-env (1.4.0)
39
43
  faraday (>= 0.17.3, < 2.0)
40
44
  google-cloud-errors (1.0.1)
41
- googleauth (0.13.1)
45
+ googleauth (0.14.0)
42
46
  faraday (>= 0.17.3, < 2.0)
43
47
  jwt (>= 1.4, < 3.0)
44
48
  memoist (~> 0.16)
@@ -46,7 +50,10 @@ GEM
46
50
  os (>= 0.9, < 2.0)
47
51
  signet (~> 0.14)
48
52
  httpclient (2.8.3)
53
+ jaro_winkler (1.5.4)
49
54
  jwt (2.2.2)
55
+ kwalify (0.7.2)
56
+ maruku (0.7.3)
50
57
  memoist (0.16.2)
51
58
  mini_mime (1.0.2)
52
59
  mini_portile2 (2.4.0)
@@ -55,25 +62,67 @@ GEM
55
62
  nokogiri (1.10.10)
56
63
  mini_portile2 (~> 2.4.0)
57
64
  os (1.1.1)
65
+ parallel (1.20.1)
66
+ parser (2.7.2.0)
67
+ ast (~> 2.4.1)
68
+ psych (3.2.0)
58
69
  public_suffix (4.0.6)
70
+ rainbow (3.0.0)
59
71
  rake (12.3.3)
72
+ reek (6.0.2)
73
+ kwalify (~> 0.7.0)
74
+ parser (>= 2.5.0.0, < 2.8, != 2.5.1.1)
75
+ psych (~> 3.1)
76
+ rainbow (>= 2.0, < 4.0)
77
+ regexp_parser (2.0.0)
60
78
  representable (3.0.4)
61
79
  declarative (< 0.1.0)
62
80
  declarative-option (< 0.2.0)
63
81
  uber (< 0.2.0)
64
82
  retriable (3.1.2)
83
+ reverse_markdown (2.0.0)
84
+ nokogiri
65
85
  rexml (3.2.4)
66
86
  roo (2.8.3)
67
87
  nokogiri (~> 1)
68
88
  rubyzip (>= 1.3.0, < 3.0.0)
89
+ rubocop (0.93.1)
90
+ parallel (~> 1.10)
91
+ parser (>= 2.7.1.5)
92
+ rainbow (>= 2.2.2, < 4.0)
93
+ regexp_parser (>= 1.8)
94
+ rexml
95
+ rubocop-ast (>= 0.6.0)
96
+ ruby-progressbar (~> 1.7)
97
+ unicode-display_width (>= 1.4.0, < 2.0)
98
+ rubocop-ast (1.2.0)
99
+ parser (>= 2.7.1.5)
100
+ ruby-progressbar (1.10.1)
101
+ ruby2_keywords (0.0.2)
69
102
  rubyzip (2.3.0)
70
103
  signet (0.14.0)
71
104
  addressable (~> 2.3)
72
105
  faraday (>= 0.17.3, < 2.0)
73
106
  jwt (>= 1.5, < 3.0)
74
107
  multi_json (~> 1.10)
108
+ solargraph (0.39.17)
109
+ backport (~> 1.1)
110
+ benchmark
111
+ bundler (>= 1.17.2)
112
+ e2mmap
113
+ jaro_winkler (~> 1.5)
114
+ maruku (~> 0.7, >= 0.7.3)
115
+ nokogiri (~> 1.9, >= 1.9.1)
116
+ parser (~> 2.3)
117
+ reverse_markdown (>= 1.0.5, < 3)
118
+ rubocop (~> 0.52)
119
+ thor (~> 1.0)
120
+ tilt (~> 2.0)
121
+ yard (~> 0.9, >= 0.9.24)
75
122
  thor (1.0.1)
123
+ tilt (2.0.10)
76
124
  uber (0.1.0)
125
+ unicode-display_width (1.7.0)
77
126
  yard (0.9.25)
78
127
 
79
128
  PLATFORMS
@@ -83,6 +132,10 @@ DEPENDENCIES
83
132
  abank!
84
133
  bundler
85
134
  rake (~> 12.0)
135
+ reek
136
+ rubocop
137
+ solargraph
138
+ yard
86
139
 
87
140
  BUNDLED WITH
88
141
  2.1.4
@@ -1,23 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/abank/version'
3
+ require_relative('lib/abank/version')
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'abank'
7
- spec.version = Abank::VERSION
6
+ spec.name = 'abank'
7
+ spec.version = Abank::VERSION
8
8
  spec.authors = ['Hernâni Rodrigues Vaz']
9
9
  spec.email = ['hernanirvaz@gmail.com']
10
10
  spec.homepage = 'https://github.com/hernanirvaz/abank'
11
11
  spec.license = 'MIT'
12
-
13
12
  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. ' \
13
+ spec.description = "#{spec.summary} Permite apagar/recriar movimentos/rendas ja no bigquery. "\
15
14
  ' Permite ainda classificar movimentos no bigquery.'
16
15
 
16
+ spec.required_ruby_version = Gem::Requirement.new('~> 2.7')
17
17
  spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['yard.run'] = 'yard'
19
-
20
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
18
+ spec.metadata['yard.run'] = 'yard'
21
19
 
22
20
  # Specify which files should be added to the gem when it is released.
23
21
  # The `git ls-files -z` loads files in RubyGem that have been added into git.
@@ -29,11 +27,14 @@ Gem::Specification.new do |spec|
29
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
28
  spec.require_paths = ['lib']
31
29
 
32
- spec.add_development_dependency 'bundler'
33
- spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency('bundler')
31
+ spec.add_development_dependency('rake')
32
+ spec.add_development_dependency('reek')
33
+ spec.add_development_dependency('rubocop')
34
+ spec.add_development_dependency('solargraph')
35
+ spec.add_development_dependency('yard')
34
36
 
35
- spec.add_dependency 'google-cloud-bigquery'
36
- spec.add_dependency 'roo'
37
- spec.add_dependency 'thor'
38
- spec.add_dependency 'yard'
37
+ spec.add_dependency('google-cloud-bigquery')
38
+ spec.add_dependency('roo')
39
+ spec.add_dependency('thor')
39
40
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require('thor')
4
- require('abank/big')
5
- require('abank/contrato')
6
- require('abank/rendas')
7
- require('abank/folha')
4
+ require('abank/big1')
5
+ require('abank/big2')
6
+ require('abank/big3')
7
+ require('abank/folha1')
8
+ require('abank/folha2')
8
9
  require('abank/version')
9
10
 
10
11
  # @author Hernani Rodrigues Vaz
@@ -12,30 +13,19 @@ module Abank
12
13
  DR = "/home/#{`whoami`.chomp}/Downloads"
13
14
  BD = 'hernanilr.ab'
14
15
 
15
- class Error < StandardError; end
16
-
17
16
  # CLI para carregar folhas calculo comuns no bigquery
18
17
  class CLI < Thor
19
18
  desc 'tag', 'classifica movimentos'
20
19
  # classifica movimentos
21
20
  def tag
22
- Big.new.mv_classifica
21
+ Big.new(options.to_h).mv_classifica.ct_dados.re_insert
23
22
  end
24
23
 
25
24
  desc 'apagamv', 'apaga movimentos'
26
25
  option :k, banner: 'KEY[,KEY...]', required: true, desc: 'keys movimentos a apagar'
27
26
  # apaga movimentos
28
27
  def apagamv
29
- Big.new(k: options[:k]).mv_delete.mv_insert.re_work
30
- end
31
-
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
28
+ Big.new(options.transform_keys(&:to_sym)).mv_delete.ct_dados.re_insert
39
29
  end
40
30
 
41
31
  desc 'apagact', 'apaga contrato arrendamento'
@@ -43,50 +33,53 @@ module Abank
43
33
  option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
44
34
  # apaga contrato arrendamento
45
35
  def apagact
46
- Big.new(c: options[:c], t: options[:t]).ct_apaga
36
+ Big.new(options.transform_keys(&:to_sym)).ct_apaga
37
+ end
38
+
39
+ desc 'criact', 'cria contrato arrendamento'
40
+ option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
41
+ option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
42
+ option :t, type: :boolean, default: true, desc: 'cria todas as rendas?'
43
+ # cria contrato arrendamento
44
+ def criact
45
+ Big.new(options.transform_keys(&:to_sym)).ct_cria
47
46
  end
48
47
 
49
48
  desc 'recriact', 'atualiza rendas de contrato arrendamento'
50
49
  option :c, banner: 'CONTRATO', required: true, desc: 'Identificador contrato arrendamento'
51
- option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
52
50
  option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
51
+ option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
53
52
  # atualiza rendas de contrato arrendamento
54
53
  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
54
+ opc = options[:c]
55
+ Big.new(c: opc, t: options[:t]).ct_apaga
56
+ Big.new(c: opc, t: true, d: options[:d]).ct_cria
57
57
  end
58
58
 
59
59
  desc 'recriare', 'atualiza rendas dos contratos ativos'
60
60
  option :t, type: :boolean, default: false, desc: 'atualiza todas as rendas?'
61
61
  # atualiza rendas dos contratos ativos
62
62
  def recriare
63
- Big.new(t: options[:t]).re_atualiza
63
+ Big.new(options.transform_keys(&:to_sym)).re_atualiza
64
64
  end
65
65
 
66
66
  desc 'work', 'carrega/apaga dados da folha calculo'
67
67
  option :s, type: :boolean, default: false, desc: 'apaga movimento similar'
68
68
  option :e, type: :boolean, default: false, desc: 'apaga movimento igual'
69
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'
70
+ option :g, banner: 'TAG', default: '', desc: 'classificacao para movimentos a carregar'
71
71
  # carrega/apaga dados da folha calculo
72
72
  def work
73
- Dir.glob("#{DR}/*.xlsx").sort.each do |f|
74
- Folha.new(work_opc.merge(f: f)).processa_xls
73
+ Dir.glob("#{DR}/*.xlsx").sort.each do |file|
74
+ Folha.new(options.transform_keys(&:to_sym).merge(f: file, i: true)).processa_xls
75
75
  end
76
76
  end
77
77
 
78
78
  desc 'show', 'mostra dados da folha calculo'
79
79
  # mostra folha calculo
80
80
  def show
81
- Dir.glob("#{DR}/*.xlsx").sort.each do |f|
82
- Folha.new(f: f).processa_xls
83
- end
84
- end
85
-
86
- no_commands do
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] }
81
+ Dir.glob("#{DR}/*.xlsx").sort.each do |file|
82
+ Folha.new(options.merge(f: file)).processa_xls
90
83
  end
91
84
  end
92
85
 
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('google/cloud/bigquery')
4
+
5
+ module Abank
6
+ # @see Big
7
+ class Big
8
+ # @return [Hash] opcoes trabalho
9
+ attr_reader :opcao
10
+
11
+ # @return [Google::Cloud::Bigquery::Data] resultado do Structured Query Language (SQL) no bigquery
12
+ attr_reader :bqres
13
+
14
+ # @return [Integer] numero linhas afetadas pelo Data Manipulation Language (DML) no bigquery
15
+ attr_reader :bqnrs
16
+
17
+ # acesso a base dados abank no bigquery
18
+ #
19
+ # @param [Thor::CoreExt::HashWithIndifferentAccess] opcoes trabalho
20
+ # @option opcoes [String] :k ('') movimentos a apagar (keysin.mv)
21
+ # @option opcoes [String] :c ('') id contrato arrendamento (re)
22
+ # @option opcoes [String] :d ('') data inicio contrato arrendamento (re)
23
+ # @option opcoes [Boolean] :t (false) trabalha todas as rendas? (re)
24
+ # @return [Hash] opcoes trabalho
25
+ def initialize(opcoes = {})
26
+ @opcao = opcoes
27
+ opcao
28
+ end
29
+
30
+ # @return [Google::Cloud::Bigquery] API bigquery
31
+ def bqapi
32
+ @bqapi ||= Google::Cloud::Bigquery.new
33
+ end
34
+
35
+ # @return [String] movimentos a apagar (keysin.mv)
36
+ def mvkys
37
+ opcao[:k][/([-+]*\d)+(,[-+]*\d+)*/].to_s
38
+ end
39
+
40
+ # apaga movimentos & suas rendas associadas no bigquery
41
+ #
42
+ # @return [Big] acesso a base dados abank no bigquery
43
+ def mv_delete
44
+ @ctlct = []
45
+ unless mvkys.empty?
46
+ # obtem lista contratos arrendamento associados aos movimentos a apagar
47
+ @ctlct = sql("select distinct ct from #{BD}.mv where #{ky_mv} in(#{mvkys}) and substr(ct,1,1)='r'")
48
+
49
+ # apaga todas as rendas dos contratos arrendamento associados aos movimentos a apagar
50
+ opcao[:t] = true unless ctlct.empty?
51
+ re_apaga.mv_delete_dml
52
+ end
53
+ self
54
+ end
55
+
56
+ # apaga movimentos no bigquery
57
+ def mv_delete_dml
58
+ dml("delete from #{BD}.mv where #{ky_mv} in(#{mvkys})")
59
+ puts("MOVIMENTOS APAGADOS #{bqnrs}")
60
+ end
61
+
62
+ # (see CLI#tag)
63
+ def mv_classifica
64
+ dml("update #{BD}.mv set mv.ct=tt.nct from (select * from #{BD}.cl) as tt where #{ky_mv}=tt.ky")
65
+ puts("MOVIMENTOS CLASSIFICADOS #{bqnrs}")
66
+ @ctlct = sql("select distinct ct from #{BD}.re") if bqnrs.positive?
67
+ self
68
+ end
69
+
70
+ # @return [String] expressao sql da chave de movimentos
71
+ def ky_mv
72
+ 'FARM_FINGERPRINT(CONCAT(CAST(mv.nc as STRING),mv.ds,CAST(mv.dl as STRING),CAST(mv.vl as STRING)))'
73
+ end
74
+
75
+ # @param [String] cmd comando a executar
76
+ # @return [Google::Cloud::Bigquery::QueryJob] tarefa SQL/DML no bigquery
77
+ def job(cmd)
78
+ bqjob = bqapi.query_job(cmd)
79
+ bqjob.wait_until_done!
80
+ err = bqjob.error
81
+ puts(err['message']) if err
82
+ bqjob
83
+ end
84
+
85
+ # executa Structured Query Language (SQL) no bigquery
86
+ #
87
+ # @param (see job)
88
+ # @param [Array] erro resultado quando falha execucao
89
+ # @return [Google::Cloud::Bigquery::Data] resultado do SQL
90
+ def sql(cmd, erro = [])
91
+ # se job.failed? executa job(cmd).data => StandardError
92
+ @bqres = job(cmd).data
93
+ rescue StandardError
94
+ @bqres = erro
95
+ end
96
+
97
+ # executa Data Manipulation Language (DML) no bigquery
98
+ #
99
+ # @param (see job)
100
+ # @return [Integer] numero rows afetadas pelo DML
101
+ def dml(cmd)
102
+ # se job.failed? executa Integer(nil) => StandardError
103
+ @bqnrs = Integer(job(cmd).num_dml_affected_rows)
104
+ rescue StandardError
105
+ @bqnrs = 0
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Abank
4
+ # acesso a base dados abank no bigquery
5
+ class Big
6
+ DF = '%Y-%m-%d'
7
+
8
+ # @return [Integer] contrato arrendamento em tratamento
9
+ attr_reader :ctpos
10
+
11
+ # (see CLI#criact)
12
+ def ct_cria
13
+ unless ct_existe?
14
+ dml("insert into #{BD}.re #{sql_contrato_mv}")
15
+ puts("CONTRATO #{opcao[:c]} #{bqnrs.zero? ? 'NAO ' : ''}INSERIDO")
16
+ end
17
+ # processar rendas sim/nao?
18
+ return unless bqnrs.positive? && opcao[:t]
19
+
20
+ # processa rendas associadas ao contrato arrendamento
21
+ ct_dados.re_insert
22
+ end
23
+
24
+ # @return [Boolean] contrato arrendamento ja existe sim/nao?
25
+ def ct_existe?
26
+ @ctlct = [{ ct: opcao[:c] }]
27
+ vaz = sql("select ct from #{BD}.re where ct in(#{str_lc}) and cnt=0").empty?
28
+ unless vaz
29
+ @bqnrs = 1
30
+ puts('CONTRATO JA EXISTE')
31
+ end
32
+ !vaz
33
+ end
34
+
35
+ # (see CLI#apagact)
36
+ def ct_apaga
37
+ @ctlct = [{ ct: opcao[:c] }]
38
+ re_delete_dml
39
+ end
40
+
41
+ # optem lista dados contrato arrendamento (inclui lista movimentos novos)
42
+ #
43
+ # @return [Big] acesso a base dados abank no bigquery
44
+ def ct_dados
45
+ ctlct.map! do |ctr|
46
+ opcao[:c] = ctr[:ct]
47
+ lre = sql(sql_last_re)[0]
48
+ ctr.merge(lre, mv: sql(sql_novo_mv(lre[:dl])))
49
+ end
50
+ self
51
+ end
52
+
53
+ # @param [Array] are lista rendas novas atual
54
+ # @return [Array<String>] lista rendas novas duma lista contratos arrendamento
55
+ def ct_rendas(lre = [])
56
+ while ctpos < ctlct.size
57
+ @mvpos = 0
58
+ lre += re_rendas
59
+ @ctpos += 1
60
+ end
61
+ lre
62
+ end
63
+
64
+ # @example sem dados movimentos
65
+ # [{ ct: 'r03000' }, ...]
66
+ # @example com dados movimentos
67
+ # [{ct: 'r03000', dc: '2020-03-01', ano: 2020, cnt: 0, dl: '2020-03-01', mv: [{dl: '2020-03-02', vl: 30}, ...] }]
68
+ # @return [Array<Hash>] lista dados contrato arrendamento (inclui lista movimentos novos)
69
+ def ctlct
70
+ @ctlct ||= []
71
+ end
72
+
73
+ # @return [String] texto formatado que representa lista de contratos arrendamento
74
+ def str_lc(sep = "'")
75
+ ctlct.map { |cid| sep + cid[:ct] + sep }.join(',')
76
+ end
77
+
78
+ # @return [String] sql para obter ultima renda do contrato arrendamento
79
+ def sql_last_re
80
+ 'select ct,DATE_SUB(DATE_SUB(dl,INTERVAL dias DAY),INTERVAL IF(cnt=0,0,cnt-1) MONTH) dc,ano,cnt,dl'\
81
+ ',CAST(REGEXP_EXTRACT(ct,r"\d+") as numeric)/100 vr '\
82
+ "from #{BD}.re where ct='#{opcao[:c]}' order by ano desc,cnt desc limit 1"
83
+ end
84
+
85
+ # @return [String] sql para obter movimentos novos (depois da ultima renda do contrato arrendamento)
86
+ def sql_novo_mv(mdl)
87
+ "select dl,vl from #{BD}.mv where ct='#{opcao[:c]}' and dl>='#{(mdl + 1).strftime(DF)}' order by dl,dv"
88
+ end
89
+
90
+ # @return [String] sql para obter dados do inicio contrato arrendamento
91
+ def sql_contrato_mv
92
+ cti = opcao[:c]
93
+ dat = opcao[:d]
94
+ if dat.empty?
95
+ 'select ct,EXTRACT(YEAR FROM DATE_TRUNC(dl,MONTH)) ano,0 cnt,DATE_TRUNC(dl,MONTH) dl,0 dias '\
96
+ "from #{BD}.mv where ct='#{cti}' order by dl limit 1"
97
+ else
98
+ "select '#{cti}' ct,EXTRACT(YEAR FROM DATE '#{dat}') ano,0 cnt,DATE '#{dat}' dl,0 dias"
99
+ end
100
+ end
101
+ end
102
+ end