lecca_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +8 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/lecca_client.yml +18 -0
- data/lecca_client.gemspec +30 -0
- data/lib/lecca_client/active_support.rb +5 -0
- data/lib/lecca_client/cnab/loan/file/detail.rb +15 -0
- data/lib/lecca_client/cnab/loan/file/header.rb +12 -0
- data/lib/lecca_client/cnab/loan/file/trailler.rb +10 -0
- data/lib/lecca_client/cnab/loan/loan_file.rb +32 -0
- data/lib/lecca_client/cnab/loan/parser.rb +66 -0
- data/lib/lecca_client/configuration.rb +30 -0
- data/lib/lecca_client/downloader.rb +47 -0
- data/lib/lecca_client/file_handler.rb +17 -0
- data/lib/lecca_client/proposal/address.rb +40 -0
- data/lib/lecca_client/proposal/bank_account.rb +63 -0
- data/lib/lecca_client/proposal/builder.rb +30 -0
- data/lib/lecca_client/proposal/customer.rb +67 -0
- data/lib/lecca_client/proposal/job.rb +37 -0
- data/lib/lecca_client/proposal/operation.rb +84 -0
- data/lib/lecca_client/proposal/phone.rb +23 -0
- data/lib/lecca_client/uploader.rb +24 -0
- data/lib/lecca_client/utils.rb +15 -0
- data/lib/lecca_client/version.rb +3 -0
- data/lib/lecca_client.rb +30 -0
- metadata +179 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 894c5bc29d68959951bf0eda0b7055db4b58dc0c
|
4
|
+
data.tar.gz: 887a0f77af7068918981318aa6e43bd4a43ae970
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ba1101b9fdf4fd920a66c0cc135f013f71116de9598a34600429ab37a169f2123b55aed461ecfcbbabec3b5826bf27a9cf0eadc2810b7576a81db23d59e8296
|
7
|
+
data.tar.gz: ff042e58615311d3e24b9eafc7fc65e20b02f3f50a04e301381ead79c5071d9be7822e37d38b3dfc27007cd6f61ce9ea3ff10598f3f32380972a6babb9261bee
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Rafael Izidoro
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "lecca_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
test:
|
2
|
+
ftp:
|
3
|
+
host: '127.0.0.1'
|
4
|
+
port: 21212
|
5
|
+
user: 'user'
|
6
|
+
pass: 'password'
|
7
|
+
upload_path: '/'
|
8
|
+
proposal:
|
9
|
+
codigo_produto: 'PROD'
|
10
|
+
codigo_agencia: '000A'
|
11
|
+
codigo_rede: '95529'
|
12
|
+
digito_rede: '9'
|
13
|
+
codigo_loja: '10936'
|
14
|
+
digito_loja: '3'
|
15
|
+
nome_loja: 'NOVERDE'
|
16
|
+
codigo_tabela_juros: 112
|
17
|
+
forma_liberacao: 'D'
|
18
|
+
forma_liquidacao: 'I'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lecca_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lecca_client"
|
8
|
+
spec.version = LeccaClient::VERSION
|
9
|
+
spec.authors = ["Noverde Team", "Rafael Izidoro", "Alexandre Santos"]
|
10
|
+
spec.email = ["dev@noverde.com.br", "izidoro.rafa@gmail.com", "alexandre.sns@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Lecca DTVM LTDA client}
|
13
|
+
spec.description = %q{This gem is responsible for exchange proposal and CNAB files between your system and Lecca DTVM.}
|
14
|
+
spec.homepage = "https://github.com/noverde/lecca_client"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
|
26
|
+
spec.add_dependency "hashie", "~> 3.4"
|
27
|
+
spec.add_dependency "activesupport", "~> 5.0"
|
28
|
+
spec.add_dependency "pry-byebug", "~> 3.4"
|
29
|
+
spec.add_dependency "net-sftp", "~> 2.1"
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module LeccaClient::CNAB::Loan::File
|
2
|
+
class Detail < Hashie::Dash
|
3
|
+
REGISTER_CODE = '1'
|
4
|
+
|
5
|
+
property :codigo_registro, default: REGISTER_CODE
|
6
|
+
property :numero_contrato_externo
|
7
|
+
property :numero_contrato_lecca
|
8
|
+
property :numero_cessa_lecca
|
9
|
+
property :cpf_emitente
|
10
|
+
property :numero_parcela
|
11
|
+
property :data_vencimento_parcela
|
12
|
+
property :valor_prestacao
|
13
|
+
property :numero_sequencial_registro
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module LeccaClient::CNAB::Loan::File
|
2
|
+
class Header < Hashie::Dash
|
3
|
+
REGISTER_CODE = '0'
|
4
|
+
|
5
|
+
property :codigo_registro, default: REGISTER_CODE
|
6
|
+
property :numero_remessa_arquivo
|
7
|
+
property :data_geracao_arquivo
|
8
|
+
property :codigo_cliente
|
9
|
+
property :hora_geracao_arquivo
|
10
|
+
property :numero_sequencial_registro
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module LeccaClient::CNAB::Loan::File
|
2
|
+
class Trailler < Hashie::Dash
|
3
|
+
REGISTER_CODE = '9'
|
4
|
+
|
5
|
+
property :codigo_registro, default: REGISTER_CODE
|
6
|
+
property :quantidade_prestacoes
|
7
|
+
property :valor_total_prestacoes
|
8
|
+
property :numero_sequencial_registro
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module LeccaClient::CNAB
|
2
|
+
module Loan
|
3
|
+
class LoanFile
|
4
|
+
FILE_PREFIX = 'LEC_DEPARA'
|
5
|
+
|
6
|
+
attr_reader :filename, :filepath, :content
|
7
|
+
|
8
|
+
def initialize(filename:, filepath:, content:)
|
9
|
+
@filename = filename
|
10
|
+
@filepath = filepath
|
11
|
+
@content = content
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse
|
15
|
+
@parsed ||= Parser.new(content).parse
|
16
|
+
end
|
17
|
+
|
18
|
+
def purge
|
19
|
+
LeccaClient::FileHandler.new.remove(filepath)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.retrieve_file(filename)
|
23
|
+
new(LeccaClient::Downloader.new.download_file(filename))
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.available_files
|
27
|
+
files = LeccaClient::Downloader.new.download_files(FILE_PREFIX)
|
28
|
+
files.map { |file| new(file) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module LeccaClient::CNAB
|
4
|
+
module Loan
|
5
|
+
class Parser
|
6
|
+
def initialize(raw_file)
|
7
|
+
@rows = raw_file.split("\n")
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse
|
11
|
+
file = OpenStruct.new(header: nil, details: [], trailler: nil)
|
12
|
+
|
13
|
+
@rows.each do |row|
|
14
|
+
register_code = row.slice(0)
|
15
|
+
|
16
|
+
case register_code
|
17
|
+
when File::Header::REGISTER_CODE
|
18
|
+
file.header = parse_header(row)
|
19
|
+
when File::Detail::REGISTER_CODE
|
20
|
+
file.details << parse_detail(row)
|
21
|
+
when File::Trailler::REGISTER_CODE
|
22
|
+
file.trailler = parse_trailler(row)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
file
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def parse_header(row)
|
32
|
+
File::Header.new(
|
33
|
+
codigo_registro: row.slice(0).strip,
|
34
|
+
numero_remessa_arquivo: row.slice(1, 4).strip,
|
35
|
+
data_geracao_arquivo: row.slice(5, 8).strip,
|
36
|
+
codigo_cliente: row.slice(13, 20).strip,
|
37
|
+
hora_geracao_arquivo: row.slice(33, 6).strip,
|
38
|
+
numero_sequencial_registro: row.slice(61, 6).strip
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_detail(row)
|
43
|
+
File::Detail.new(
|
44
|
+
codigo_registro: row.slice(0).strip,
|
45
|
+
numero_contrato_externo: row.slice(1, 12).strip,
|
46
|
+
numero_contrato_lecca: row.slice(13, 12).strip,
|
47
|
+
numero_cessa_lecca: row.slice(25, 5).strip,
|
48
|
+
cpf_emitente: row.slice(30, 11).strip,
|
49
|
+
numero_parcela: row.slice(41, 3).strip,
|
50
|
+
data_vencimento_parcela: row.slice(44, 8).strip,
|
51
|
+
valor_prestacao: row.slice(52, 7).strip,
|
52
|
+
numero_sequencial_registro: row.slice(61, 6).strip
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_trailler(row)
|
57
|
+
File::Trailler.new(
|
58
|
+
codigo_registro: row.slice(0).strip,
|
59
|
+
quantidade_prestacoes: row.slice(1, 6).strip,
|
60
|
+
valor_total_prestacoes: row.slice(7, 9).strip,
|
61
|
+
numero_sequencial_registro: row.slice(61, 6).strip
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module LeccaClient
|
5
|
+
class Configuration
|
6
|
+
attr_accessor :environment, :logger, :config_file_path
|
7
|
+
|
8
|
+
def config_file_path
|
9
|
+
@config_file_path || 'config/lecca_client.yml'
|
10
|
+
end
|
11
|
+
|
12
|
+
def environment
|
13
|
+
@environment || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || raise('You must set the environment!')
|
14
|
+
end
|
15
|
+
|
16
|
+
def ftp
|
17
|
+
config['ftp']
|
18
|
+
end
|
19
|
+
|
20
|
+
def proposal
|
21
|
+
config['proposal']
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def config
|
27
|
+
@config ||= Hashie::Mash.load(config_file_path)[environment]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'net/sftp'
|
2
|
+
|
3
|
+
module LeccaClient
|
4
|
+
class Downloader
|
5
|
+
def download_file(filename)
|
6
|
+
file = {}
|
7
|
+
|
8
|
+
Net::SFTP.start(config[:host], config[:user], password: config[:pass]) do |sftp|
|
9
|
+
file = {
|
10
|
+
filename: filename,
|
11
|
+
filepath: download_path(filename),
|
12
|
+
content: sftp.download!(download_path(filename))
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
file
|
17
|
+
end
|
18
|
+
|
19
|
+
def download_files(prefix = nil)
|
20
|
+
files = []
|
21
|
+
|
22
|
+
Net::SFTP.start(config[:host], config[:user], password: config[:pass]) do |sftp|
|
23
|
+
sftp.dir.foreach(download_path) do |entry|
|
24
|
+
next if !entry.file? || (prefix.present? && !entry.name.include?(prefix))
|
25
|
+
|
26
|
+
files << {
|
27
|
+
filename: entry.name,
|
28
|
+
filepath: download_path(entry.name),
|
29
|
+
content: sftp.download!(download_path(entry.name))
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
files
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def download_path(file_path = nil)
|
40
|
+
[(config[:download_path] || '.'), file_path].join('/')
|
41
|
+
end
|
42
|
+
|
43
|
+
def config
|
44
|
+
@config ||= LeccaClient.config.ftp
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'net/sftp'
|
2
|
+
|
3
|
+
module LeccaClient
|
4
|
+
class FileHandler
|
5
|
+
def remove(filepath)
|
6
|
+
Net::SFTP.start(config[:host], config[:user], password: config[:pass]) do |sftp|
|
7
|
+
sftp.remove!(filepath)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def config
|
14
|
+
@config ||= LeccaClient.config.ftp
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module LeccaClient
|
2
|
+
module Proposal
|
3
|
+
class Address < Hashie::Dash
|
4
|
+
include LeccaClient::Utils
|
5
|
+
|
6
|
+
property :endereco, required: true
|
7
|
+
property :numero, required: true
|
8
|
+
property :complemento
|
9
|
+
property :uf, required: true
|
10
|
+
property :bairro, required: true
|
11
|
+
property :cidade, required: true
|
12
|
+
property :pais, required: true
|
13
|
+
property :cep, required: true
|
14
|
+
|
15
|
+
def build
|
16
|
+
parts = ''
|
17
|
+
|
18
|
+
parts << justify_number(tipo_residencia, 1)
|
19
|
+
parts << justify_string(endereco, 60)
|
20
|
+
parts << justify_number(numero, 5)
|
21
|
+
parts << justify_string(complemento, 30)
|
22
|
+
parts << justify_string(uf, 2)
|
23
|
+
parts << justify_string(bairro, 30)
|
24
|
+
parts << justify_string(cidade, 40)
|
25
|
+
parts << justify_number(pais, 5)
|
26
|
+
parts << justify_string(cep, 8)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def tipo_residencia
|
32
|
+
1 # fixed value from Lecca docs
|
33
|
+
end
|
34
|
+
|
35
|
+
def pais
|
36
|
+
1 # fixed value from Lecca docs
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module LeccaClient
|
2
|
+
module Proposal
|
3
|
+
class BankAccount < Hashie::Dash
|
4
|
+
include LeccaClient::Utils
|
5
|
+
|
6
|
+
PRODUTO_CREDITO_PESSOAL = 'CP'
|
7
|
+
|
8
|
+
property :digito_agencia, required: -> { credito_pessoal? }
|
9
|
+
property :digito_conta, required: -> { credito_pessoal? }
|
10
|
+
property :nome_agencia
|
11
|
+
property :nome_favorecido, required: -> { credito_pessoal? }
|
12
|
+
property :numero_telefone
|
13
|
+
property :banco, required: -> { credito_pessoal? }
|
14
|
+
property :agencia, required: -> { credito_pessoal? }
|
15
|
+
property :conta, required: -> { credito_pessoal? }
|
16
|
+
property :tipo_conta, required: -> { credito_pessoal? }, default: '001'
|
17
|
+
property :data_abertura
|
18
|
+
|
19
|
+
def build
|
20
|
+
parts = ''
|
21
|
+
|
22
|
+
parts << justify_string(digito_agencia, 1)
|
23
|
+
parts << justify_string(digito_conta, 2)
|
24
|
+
parts << justify_string(nome_agencia, 20)
|
25
|
+
|
26
|
+
parts << justify_string(flag_titularidade, 1)
|
27
|
+
parts << justify_string(nome_favorecido, 35)
|
28
|
+
parts << justify_number(numero_telefone, 12)
|
29
|
+
|
30
|
+
parts << justify_number(praca, 3)
|
31
|
+
parts << justify_number(banco, 3)
|
32
|
+
parts << justify_number(agencia, 4)
|
33
|
+
parts << justify_number(conta, 8)
|
34
|
+
parts << justify_number(tipo_conta, 3)
|
35
|
+
parts << justify_number(tipo_documento_cpf, 3)
|
36
|
+
parts << justify_number(data_abertura, 8)
|
37
|
+
parts << justify_number(codigo_natureza_residencia, 1)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def praca
|
43
|
+
1 # provided by Lecca
|
44
|
+
end
|
45
|
+
|
46
|
+
def flag_titularidade
|
47
|
+
1 # provided by Lecca
|
48
|
+
end
|
49
|
+
|
50
|
+
def tipo_documento_cpf
|
51
|
+
1 # provided by Lecca
|
52
|
+
end
|
53
|
+
|
54
|
+
def codigo_natureza_residencia
|
55
|
+
0 # provided by Lecca
|
56
|
+
end
|
57
|
+
|
58
|
+
def credito_pessoal?
|
59
|
+
LeccaClient.config.proposal[:codigo_produto] == PRODUTO_CREDITO_PESSOAL
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module LeccaClient
|
2
|
+
module Proposal
|
3
|
+
class Builder < Hashie::Dash
|
4
|
+
include Hashie::Extensions::Dash::Coercion
|
5
|
+
|
6
|
+
property :operacao, coerce: Operation, required: true
|
7
|
+
property :cliente, coerce: Customer, required: true
|
8
|
+
property :endereco, coerce: Address, required: true
|
9
|
+
property :telefone, coerce: Phone, required: true
|
10
|
+
property :emprego, coerce: Job, required: true
|
11
|
+
property :conta_bancaria, coerce: BankAccount , required: true
|
12
|
+
|
13
|
+
def line
|
14
|
+
[operacao, cliente, endereco, telefone, emprego, conta_bancaria].map(&:build).reduce(:+)
|
15
|
+
end
|
16
|
+
|
17
|
+
def upload
|
18
|
+
LeccaClient::Uploader.new(line, filename).upload
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def filename
|
24
|
+
file = operacao[:numero_operacao]
|
25
|
+
|
26
|
+
"#{file}.txt"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module LeccaClient
|
2
|
+
module Proposal
|
3
|
+
class Customer < Hashie::Dash
|
4
|
+
include LeccaClient::Utils
|
5
|
+
|
6
|
+
property :nome, required: true
|
7
|
+
property :estado_civil
|
8
|
+
property :sexo
|
9
|
+
property :numero_rg, required: true
|
10
|
+
property :uf_rg
|
11
|
+
property :uf_naturalidade
|
12
|
+
property :naturalidade
|
13
|
+
property :nome_pai
|
14
|
+
property :nome_mae, required: true
|
15
|
+
property :orgao_emissor_rg
|
16
|
+
property :sigla_uf_outros_documentos
|
17
|
+
property :descricao_profissao
|
18
|
+
property :descricao_cargo, required: true
|
19
|
+
property :cpf, required: true
|
20
|
+
property :data_nascimento, required: true
|
21
|
+
property :codigo_profissao, required: true
|
22
|
+
property :valor_salario_liquido, required: true
|
23
|
+
property :data_expedicao_rg
|
24
|
+
property :observacao, required: true, default: ''
|
25
|
+
|
26
|
+
def build
|
27
|
+
parts = ''
|
28
|
+
|
29
|
+
parts << justify_string(nome, 60)
|
30
|
+
parts << justify_number(nacionalidade, 5)
|
31
|
+
parts << justify_string(estado_civil, 1)
|
32
|
+
parts << justify_string(sexo, 1)
|
33
|
+
|
34
|
+
parts << justify_string(numero_rg, 16)
|
35
|
+
parts << justify_string(uf_rg, 2)
|
36
|
+
parts << justify_string(uf_naturalidade, 2)
|
37
|
+
parts << justify_string(naturalidade, 35)
|
38
|
+
parts << justify_string(nome_pai, 35)
|
39
|
+
parts << justify_string(nome_mae, 35)
|
40
|
+
parts << justify_string(orgao_emissor_rg, 5)
|
41
|
+
parts << justify_string(sigla_uf_outros_documentos, 2)
|
42
|
+
|
43
|
+
parts << justify_string(descricao_profissao, 35)
|
44
|
+
parts << justify_string(descricao_cargo, 35)
|
45
|
+
|
46
|
+
parts << justify_number(cpf, 11)
|
47
|
+
parts << justify_number(data_nascimento, 8)
|
48
|
+
|
49
|
+
parts << justify_number(codigo_profissao, 8)
|
50
|
+
parts << justify_value(valor_salario_liquido, 12)
|
51
|
+
parts << justify_number(data_expedicao_rg, 8)
|
52
|
+
parts << justify_string(observacao, 3000)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def nacionalidade
|
58
|
+
1 # fixed value from Lecca docs
|
59
|
+
end
|
60
|
+
|
61
|
+
def codigo_profissao
|
62
|
+
1 # fixed value from Lecca docs
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module LeccaClient
|
2
|
+
module Proposal
|
3
|
+
class Job < Hashie::Dash
|
4
|
+
include LeccaClient::Utils
|
5
|
+
|
6
|
+
property :razao_social
|
7
|
+
property :data_admissao
|
8
|
+
property :cnpj
|
9
|
+
property :endereco
|
10
|
+
property :numero
|
11
|
+
property :complemento
|
12
|
+
property :complemento
|
13
|
+
property :bairro
|
14
|
+
property :cidade
|
15
|
+
property :uf
|
16
|
+
property :renda
|
17
|
+
property :cep
|
18
|
+
|
19
|
+
def build
|
20
|
+
parts = ''
|
21
|
+
|
22
|
+
parts << justify_string(razao_social, 30)
|
23
|
+
parts << justify_number(data_admissao, 8)
|
24
|
+
parts << justify_number(cnpj, 14)
|
25
|
+
parts << justify_string(endereco, 60)
|
26
|
+
parts << justify_number(numero, 5)
|
27
|
+
parts << justify_string(complemento, 30)
|
28
|
+
parts << justify_string(bairro, 30)
|
29
|
+
parts << justify_string(cidade, 40)
|
30
|
+
parts << justify_string(uf, 2)
|
31
|
+
parts << justify_value(renda, 12)
|
32
|
+
parts << justify_string(cep, 8)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module LeccaClient
|
2
|
+
module Proposal
|
3
|
+
class Operation < Hashie::Dash
|
4
|
+
include LeccaClient::Utils
|
5
|
+
|
6
|
+
property :codigo_produto, required: true, default: LeccaClient.config.proposal[:codigo_produto]
|
7
|
+
property :data_operacao, required: true
|
8
|
+
property :codigo_agencia, required: true, default: LeccaClient.config.proposal[:codigo_agencia]
|
9
|
+
property :codigo_rede, required: true, default: LeccaClient.config.proposal[:codigo_rede]
|
10
|
+
property :digito_rede, required: true, default: LeccaClient.config.proposal[:digito_rede]
|
11
|
+
property :codigo_loja, required: true, default: LeccaClient.config.proposal[:codigo_loja]
|
12
|
+
property :digito_loja, required: true, default: LeccaClient.config.proposal[:digito_loja]
|
13
|
+
property :nome_loja, required: true, default: LeccaClient.config.proposal[:nome_loja]
|
14
|
+
property :numero_operacao, required: true
|
15
|
+
property :codigo_tabela_juros, required: true, default: LeccaClient.config.proposal[:codigo_tabela_juros]
|
16
|
+
property :taxa_juros, required: true
|
17
|
+
property :data_primeira_parcela, required: true
|
18
|
+
property :valor_compra, required: true
|
19
|
+
property :valor_entrada
|
20
|
+
property :valor_cac
|
21
|
+
property :quantidade_parcela, required: true
|
22
|
+
property :valor_parcela, required: true
|
23
|
+
property :valor_ioc
|
24
|
+
property :forma_liberacao, required: true, default: LeccaClient.config.proposal[:forma_liberacao]
|
25
|
+
property :forma_liquidacao, required: true, default: LeccaClient.config.proposal[:forma_liquidacao]
|
26
|
+
property :digito_agencia_doc
|
27
|
+
property :digito_conta_doc
|
28
|
+
property :nome_favorecido_doc
|
29
|
+
property :praca_doc
|
30
|
+
property :banco_doc
|
31
|
+
property :agencia_doc
|
32
|
+
property :conta_doc
|
33
|
+
property :cpf_doc
|
34
|
+
property :tac_financiada
|
35
|
+
property :valor_doc
|
36
|
+
|
37
|
+
def build
|
38
|
+
parts = ''
|
39
|
+
|
40
|
+
parts << justify_string(codigo_produto, 4)
|
41
|
+
parts << justify_string(data_operacao, 8)
|
42
|
+
parts << justify_string(codigo_agencia, 4)
|
43
|
+
parts << justify_string(codigo_rede, 5)
|
44
|
+
parts << justify_string(digito_rede, 1)
|
45
|
+
parts << justify_string(codigo_loja, 5)
|
46
|
+
parts << justify_string(digito_loja, 1)
|
47
|
+
parts << justify_string(nome_loja, 35)
|
48
|
+
|
49
|
+
parts << justify_number(numero_operacao, 12)
|
50
|
+
parts << justify_number(codigo_tabela_juros, 8)
|
51
|
+
parts << justify_value(taxa_juros, 10, 4)
|
52
|
+
|
53
|
+
parts << justify_string(data_primeira_parcela, 8)
|
54
|
+
parts << justify_value(valor_compra, 15)
|
55
|
+
parts << justify_value(valor_entrada, 15)
|
56
|
+
parts << justify_value(valor_principal, 15)
|
57
|
+
parts << justify_value(valor_cac, 15)
|
58
|
+
parts << justify_number(quantidade_parcela, 3)
|
59
|
+
parts << justify_value(valor_parcela, 15)
|
60
|
+
parts << justify_value(valor_ioc, 15)
|
61
|
+
|
62
|
+
parts << justify_string(forma_liberacao, 1)
|
63
|
+
parts << justify_string(forma_liquidacao, 1)
|
64
|
+
|
65
|
+
parts << justify_string(digito_agencia_doc, 1)
|
66
|
+
parts << justify_string(digito_conta_doc, 2)
|
67
|
+
parts << justify_string(nome_favorecido_doc, 35)
|
68
|
+
parts << justify_number(praca_doc, 3)
|
69
|
+
parts << justify_number(banco_doc, 3)
|
70
|
+
parts << justify_number(agencia_doc, 4)
|
71
|
+
parts << justify_number(conta_doc, 8)
|
72
|
+
parts << justify_number(cpf_doc, 14)
|
73
|
+
parts << justify_string(tac_financiada, 1)
|
74
|
+
parts << justify_value(valor_doc, 15)
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def valor_principal
|
80
|
+
valor_compra
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module LeccaClient
|
2
|
+
module Proposal
|
3
|
+
class Phone < Hashie::Dash
|
4
|
+
include LeccaClient::Utils
|
5
|
+
|
6
|
+
property :ddd_telefone, required: true
|
7
|
+
property :telefone, required: true
|
8
|
+
property :celular
|
9
|
+
property :email
|
10
|
+
property :ddd_celular
|
11
|
+
|
12
|
+
def build
|
13
|
+
parts = ''
|
14
|
+
|
15
|
+
parts << justify_number(ddd_telefone, 4)
|
16
|
+
parts << justify_number(telefone, 12)
|
17
|
+
parts << justify_number(celular, 12)
|
18
|
+
parts << justify_string(email, 50)
|
19
|
+
parts << justify_number(ddd_celular, 4)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'net/sftp'
|
2
|
+
|
3
|
+
module LeccaClient
|
4
|
+
class Uploader
|
5
|
+
def initialize(text, filename)
|
6
|
+
@text = text
|
7
|
+
@filename = filename
|
8
|
+
end
|
9
|
+
|
10
|
+
def upload
|
11
|
+
Net::SFTP.start(config[:host], config[:user], password: config[:pass]) do |sftp|
|
12
|
+
sftp.file.open([config[:upload_path].to_s, @filename].join('/'), "w") do |file|
|
13
|
+
file.puts @text
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def config
|
21
|
+
@config ||= LeccaClient.config.ftp
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module LeccaClient
|
2
|
+
module Utils
|
3
|
+
def justify_string(string, length)
|
4
|
+
I18n.transliterate(string.to_s).truncate(length, omission: '').ljust(length, ' ')
|
5
|
+
end
|
6
|
+
|
7
|
+
def justify_number(number, length)
|
8
|
+
number.to_s.rjust(length, '0')
|
9
|
+
end
|
10
|
+
|
11
|
+
def justify_value(value, length, decimal_places = 2)
|
12
|
+
("%.#{decimal_places}f" % value).gsub(/[.,]/, '').rjust(length, '0')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/lecca_client.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module LeccaClient
|
2
|
+
def self.config
|
3
|
+
@config ||= LeccaClient::Configuration.new
|
4
|
+
yield @config if block_given?
|
5
|
+
@config
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'hashie'
|
10
|
+
require 'lecca_client/active_support'
|
11
|
+
require 'lecca_client/version'
|
12
|
+
require 'lecca_client/configuration'
|
13
|
+
require 'lecca_client/utils'
|
14
|
+
require 'lecca_client/uploader'
|
15
|
+
require 'lecca_client/downloader'
|
16
|
+
require 'lecca_client/file_handler'
|
17
|
+
|
18
|
+
require 'lecca_client/proposal/operation'
|
19
|
+
require 'lecca_client/proposal/customer'
|
20
|
+
require 'lecca_client/proposal/phone'
|
21
|
+
require 'lecca_client/proposal/address'
|
22
|
+
require 'lecca_client/proposal/job'
|
23
|
+
require 'lecca_client/proposal/bank_account'
|
24
|
+
require 'lecca_client/proposal/builder'
|
25
|
+
|
26
|
+
require 'lecca_client/cnab/loan/parser'
|
27
|
+
require 'lecca_client/cnab/loan/loan_file'
|
28
|
+
require 'lecca_client/cnab/loan/file/header'
|
29
|
+
require 'lecca_client/cnab/loan/file/detail'
|
30
|
+
require 'lecca_client/cnab/loan/file/trailler'
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lecca_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Noverde Team
|
8
|
+
- Rafael Izidoro
|
9
|
+
- Alexandre Santos
|
10
|
+
autorequire:
|
11
|
+
bindir: exe
|
12
|
+
cert_chain: []
|
13
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.12'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.12'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '10.0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '10.0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rspec
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '3.0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '3.0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: hashie
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.4'
|
64
|
+
type: :runtime
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '3.4'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: activesupport
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '5.0'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - "~>"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '5.0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: pry-byebug
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '3.4'
|
92
|
+
type: :runtime
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - "~>"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '3.4'
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
name: net-sftp
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '2.1'
|
106
|
+
type: :runtime
|
107
|
+
prerelease: false
|
108
|
+
version_requirements: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - "~>"
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '2.1'
|
113
|
+
description: This gem is responsible for exchange proposal and CNAB files between
|
114
|
+
your system and Lecca DTVM.
|
115
|
+
email:
|
116
|
+
- dev@noverde.com.br
|
117
|
+
- izidoro.rafa@gmail.com
|
118
|
+
- alexandre.sns@gmail.com
|
119
|
+
executables: []
|
120
|
+
extensions: []
|
121
|
+
extra_rdoc_files: []
|
122
|
+
files:
|
123
|
+
- ".editorconfig"
|
124
|
+
- ".gitignore"
|
125
|
+
- ".rspec"
|
126
|
+
- ".travis.yml"
|
127
|
+
- Gemfile
|
128
|
+
- LICENSE.txt
|
129
|
+
- README.md
|
130
|
+
- Rakefile
|
131
|
+
- bin/console
|
132
|
+
- bin/setup
|
133
|
+
- config/lecca_client.yml
|
134
|
+
- lecca_client.gemspec
|
135
|
+
- lib/lecca_client.rb
|
136
|
+
- lib/lecca_client/active_support.rb
|
137
|
+
- lib/lecca_client/cnab/loan/file/detail.rb
|
138
|
+
- lib/lecca_client/cnab/loan/file/header.rb
|
139
|
+
- lib/lecca_client/cnab/loan/file/trailler.rb
|
140
|
+
- lib/lecca_client/cnab/loan/loan_file.rb
|
141
|
+
- lib/lecca_client/cnab/loan/parser.rb
|
142
|
+
- lib/lecca_client/configuration.rb
|
143
|
+
- lib/lecca_client/downloader.rb
|
144
|
+
- lib/lecca_client/file_handler.rb
|
145
|
+
- lib/lecca_client/proposal/address.rb
|
146
|
+
- lib/lecca_client/proposal/bank_account.rb
|
147
|
+
- lib/lecca_client/proposal/builder.rb
|
148
|
+
- lib/lecca_client/proposal/customer.rb
|
149
|
+
- lib/lecca_client/proposal/job.rb
|
150
|
+
- lib/lecca_client/proposal/operation.rb
|
151
|
+
- lib/lecca_client/proposal/phone.rb
|
152
|
+
- lib/lecca_client/uploader.rb
|
153
|
+
- lib/lecca_client/utils.rb
|
154
|
+
- lib/lecca_client/version.rb
|
155
|
+
homepage: https://github.com/noverde/lecca_client
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
metadata: {}
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project:
|
175
|
+
rubygems_version: 2.5.1
|
176
|
+
signing_key:
|
177
|
+
specification_version: 4
|
178
|
+
summary: Lecca DTVM LTDA client
|
179
|
+
test_files: []
|