lib/abank/contrato.rb in abank-0.2.7 vs lib/abank/contrato.rb in abank-0.2.9
- old
+ new
@@ -18,14 +18,14 @@
# (see CLI#criact)
def ct_cria
if existe_contrato?
@bqnrs = 1
- puts 'CONTRATO JA EXISTE'
+ puts('CONTRATO JA EXISTE')
else
- dml('insert into hernanilr.ab.re ' + sql_contrato_mv)
- puts "CONTRATO #{ctide} " + (bqnrs.zero? ? 'NAO EXISTE' : 'INSERIDO')
+ dml("insert into #{BD}.re #{sql_contrato_mv}")
+ puts("CONTRATO #{ctide} " + (bqnrs.zero? ? 'NAO EXISTE' : 'INSERIDO'))
end
return unless existem_rendas?
# processa rendas associadas ao contrato arrendamento
cm_cria.vr_cria.re_insert
@@ -50,12 +50,12 @@
self
end
# apaga rendas da lista de contratos arrendamento
def lc_apaga
- dml("delete from hernanilr.ab.re where ct in(#{str_lc})#{opcao[:t] ? '' : ' and cnt>0'}")
- puts "RENDAS #{str_lc('')} APAGADAS " + bqnrs.to_s
+ dml("delete from #{BD}.re where ct in(#{str_lc})#{opcao[:t] ? '' : ' and cnt>0'}")
+ puts("RENDAS #{str_lc('')} APAGADAS " + bqnrs.to_s)
end
# @return [String] texto formatado que representa lista de contratos arrendamento
def str_lc(sep = "'")
ctlct.map { |c| sep + c[:ct] + sep }.join(',')
@@ -66,12 +66,12 @@
# @return [Big] acesso a base dados abank no bigquery
def cm_cria
@ctlcm = []
ctlct.each do |c|
@ctide = c[:ct]
- sel(sql_last_re)
- @ctlcm << bqres[0].merge({ mv: sel(sql_novo_mv(bqres[0][:dl])) })
+ sql(sql_last_re)
+ @ctlcm << bqres[0].merge({ mv: sql(sql_novo_mv(bqres[0][:dl])) })
end
self
end
# @return [Boolean] existem rendas para processar sim/nao?
@@ -80,28 +80,28 @@
bqnrs.positive? && opcao[:t]
end
# @return [Boolean] contrato arrendamento ja existe sim/nao?
def existe_contrato?
- sel("select ct from hernanilr.ab.re where ct='#{ctide}' and cnt=0").count.positive?
+ sql("select ct from #{BD}.re where ct='#{ctide}' and cnt=0").count.positive?
end
# @return [String] sql para obter ultima renda do contrato arrendamento
def sql_last_re
'select ct,DATE_SUB(DATE_SUB(dl,INTERVAL dias DAY),INTERVAL IF(cnt=0,0,cnt-1) MONTH) as dc,ano,cnt,dl ' \
- "from hernanilr.ab.re where ct='#{ctide}' order by ano desc,cnt desc limit 1"
+ "from #{BD}.re where ct='#{ctide}' order by ano desc,cnt desc limit 1"
end
# @return [String] sql para obter movimentos novos (depois da ultima renda do contrato arrendamento)
def sql_novo_mv(mdl)
- "select dl,vl from hernanilr.ab.mv where ct='#{ctide}' and dl>='#{(mdl + 1).strftime(DF)}' order by dl,dv"
+ "select dl,vl from #{BD}.mv where ct='#{ctide}' and dl>='#{(mdl + 1).strftime(DF)}' order by dl,dv"
end
# @return [String] sql para obter dados do inicio contrato arrendamento
def sql_contrato_mv
if opcao[:d].size.zero?
'select ct,EXTRACT(YEAR FROM DATE_TRUNC(dl,MONTH)) as ano,0 as cnt,DATE_TRUNC(dl,MONTH) as dl,0 dias ' \
- "from hernanilr.ab.mv where ct='#{ctide}' order by dl limit 1"
+ "from #{BD}.mv where ct='#{ctide}' order by dl limit 1"
else
"select '#{ctide}' as ct,EXTRACT(YEAR FROM DATE '#{opcao[:d]}') as ano" \
",0 as cnt,DATE '#{opcao[:d]}' as dl,0 dias"
end
end