abank 0.2.2 → 0.2.3

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: cc8d38e615af3a1ef8965fdf7e395f93079b714028308ea85318e9d92b8df5ff
4
- data.tar.gz: 40d941211ef1608af9fff0f1a9642ea69240933e1956578dcf20c0e8826f2cc0
3
+ metadata.gz: 90945827ff39ea567dd16f073018ef56215da38498e9ca317a2aff12a23e9a6d
4
+ data.tar.gz: a2797459015e62c0a3bacc5eb2897ca58b52be346d885ce2494d9dd81cc08ba0
5
5
  SHA512:
6
- metadata.gz: b22caac0a7226316674b00ceecf45be10f0af39171be63df18135de736286294707c4e34d688ebd3dc150f7749f7db34619a280daaf084983a7cf910f3338290
7
- data.tar.gz: d5cf90b7b2625a59ad60ddcf36b902f926b27d54292067ae5b0e0e5a0c720ce14228339d18d471d27cb0e5eea8b80ce9138630bcd477521d483168ec8ff52e5b
6
+ metadata.gz: 87b7130b7a34943a80dad48903c083b5a06074f35d951575d435d4c4f58a466141bf0ef3021bca22515110e14cd179c64d7991292207d1fb029e309832d3258b
7
+ data.tar.gz: 48562e6cdae584b35bacea3c9a7ab5149922c244fe1b6248b57527577c288675e2da1b9eb082e7bd5ee9bb075b26199a34368e52cc3a3d18bcf575e9369fd6c7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abank (0.2.2)
4
+ abank (0.2.3)
5
5
  google-cloud-bigquery
6
6
  roo
7
7
  thor
data/lib/abank.rb CHANGED
@@ -45,17 +45,43 @@ module Abank
45
45
  end
46
46
  end
47
47
 
48
- desc 'classifica', 'classifica arquivo no bigquery'
49
- # classifica arquivo no bigquery
48
+ desc 'classifica', 'classifica movimentos no bigquery'
49
+ # classifica movimentos no bigquery
50
50
  def classifica
51
- Bigquery.new.classifica
51
+ Bigquery.new('', { i: true }).classifica
52
+ end
53
+
54
+ desc 'atualiza', 'atualiza rendas no arquivo bigquery'
55
+ # atualiza rendas no arquivo bigquery
56
+ def atualiza
57
+ Bigquery.new.atualiza
58
+ end
59
+
60
+ desc 'cria', 'cria contrato arrendamento/rendas no arquivo bigquery'
61
+ option :r, banner: 'REN', required: true,
62
+ desc: 'identificador contrato arrendamento a criar'
63
+ option :t, type: :boolean, default: false,
64
+ desc: 'trabalha com renda inicio ou todas'
65
+ # cria contrato arrendamento/rendas no arquivo bigquery
66
+ def cria
67
+ Bigquery.new('', { r: options[:r], t: options[:t] }).cria
68
+ end
69
+
70
+ desc 'apaga', 'apaga contrato arrendamento/rendas no arquivo bigquery'
71
+ option :r, banner: 'REN', required: true,
72
+ desc: 'identificador contrato arrendamento a apagar'
73
+ option :t, type: :boolean, default: false,
74
+ desc: 'trabalha com renda inicio ou todas'
75
+ # apaga contrato arrendamento/rendas no arquivo bigquery
76
+ def apaga
77
+ Bigquery.new('', { r: options[:r], t: options[:t] }).apaga
52
78
  end
53
79
 
54
80
  no_commands do
55
81
  # @return [Hash] ops opcoes trabalho com linhas para load
56
82
  def load_ops
57
- { s: options[:s], e: options[:e],
58
- m: options[:m], i: true, n: options[:n] }
83
+ { s: options[:s], e: options[:e], m: options[:m],
84
+ i: true, t: false, n: options[:n], r: '' }
59
85
  end
60
86
  end
61
87
 
@@ -30,11 +30,13 @@ module Abank
30
30
  # @option ops [Boolean] :e (false) apaga linha igual?
31
31
  # @option ops [Boolean] :m (false) apaga linhas existencia multipla?
32
32
  # @option ops [Boolean] :i (false) insere linha nova?
33
+ # @option ops [Boolean] :t (false) apaga rendas totalmente?
33
34
  # @option ops [Numeric] :n (0) numero dias correcao para data valor
35
+ # @option ops [String] :r identificador contrato arrendamento
34
36
  # @return [Bigquery] acesso folhas calculo activobank
35
37
  # & correspondente bigquery dataset
36
38
  def initialize(xls = '', ops = { s: false, e: false, m: false,
37
- i: false, n: 0 })
39
+ i: false, t: false, n: 0, r: '' })
38
40
  # usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
39
41
  # @see https://cloud.google.com/bigquery/docs/authentication/getting-started
40
42
  @apibq = Google::Cloud::Bigquery.new
@@ -72,6 +74,7 @@ module Abank
72
74
  # @param (see job_bigquery?)
73
75
  # @return [Integer] numero linhas afetadas
74
76
  def dml(sql)
77
+ p sql
75
78
  job_bigquery?(sql) ? 0 : job.num_dml_affected_rows
76
79
  end
77
80
 
@@ -96,14 +99,50 @@ module Abank
96
99
  def classifica
97
100
  return unless linha[:i]
98
101
 
99
- puts 'LINHAS CLASSIFICADAS ' +
100
- dml('update hernanilr.ab.mv set mv.ct=tt.nct' \
101
- ' from (select * from hernanilr.ab.cl) as tt' \
102
- ' where mv.dl=tt.dl and mv.dv=tt.dv' \
103
- ' and mv.ds=tt.ds and mv.vl=tt.vl').to_s
102
+ i = dml('update hernanilr.ab.mv set mv.ct=tt.nct' \
103
+ ' from (select * from hernanilr.ab.cl) as tt' \
104
+ ' where mv.dl=tt.dl and mv.dv=tt.dv' \
105
+ ' and mv.ds=tt.ds and mv.vl=tt.vl')
106
+ puts 'LINHAS CLASSIFICADAS ' + i.to_s
107
+ return unless i.positive?
108
+
109
+ atualiza
110
+ end
111
+
112
+ # (see CLI#atualiza)
113
+ def atualiza
104
114
  puts 'RENDAS INSERIDAS ' + esp('call hernanilr.ab.rendas()').to_s
105
115
  end
106
116
 
117
+ # (see CLI#cria)
118
+ def cria
119
+ i = dml('insert into hernanilr.ab.re ' + sql_contrato)
120
+ puts i.zero? ? 'NAO EXISTE CONTRATO' : 'CONTRATO INSERIDO'
121
+ return unless i.positive? && linha[:t]
122
+
123
+ atualiza
124
+ end
125
+
126
+ # @return [String] sql obtem dados inicio contrato arrendamento
127
+ def sql_contrato
128
+ 'select ct,EXTRACT(YEAR FROM DATE_TRUNC(dl,MONTH)) as ano,0 as cnt' \
129
+ ',DATE_TRUNC(dl,MONTH) as dl,0 dias' \
130
+ ' from hernanilr.ab.mv' \
131
+ " where ct='#{linha[:r]}' " \
132
+ 'order by dl limit 1'
133
+ end
134
+
135
+ # (see CLI#apaga)
136
+ def apaga
137
+ puts 'RENDAS APAGADAS ' + dml(sql_apaga).to_s
138
+ end
139
+
140
+ # @return [String] sql apaga rendas
141
+ def sql_apaga
142
+ "delete from hernanilr.ab.re where ct='#{linha[:r]}'" +
143
+ (linha[:t] ? '' : ' and cnt>0')
144
+ end
145
+
107
146
  # @return [Integer] numero linhas inseridas
108
147
  def sql_insert
109
148
  return 1 unless linha[:i]
data/lib/abank/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Abank
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
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.2
4
+ version: 0.2.3
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-05-14 00:00:00.000000000 Z
11
+ date: 2020-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler