Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/change var variables #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "standard",
"rules": {
"eqeqeq": "warn",
"no-throw-literal": "off"
"no-throw-literal": "off",
"no-var": "warn"
},
"env": {
"mocha": true
Expand Down
54 changes: 27 additions & 27 deletions banks/bradesco/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
const moment = require('moment')
var formatters = require('../../lib/formatters')
var ediHelper = require('../../lib/edi-helper')
const formatters = require('../../lib/formatters')
const ediHelper = require('../../lib/edi-helper')

exports.options = {
logoURL: 'https://assets.pagar.me/boleto/images/bradesco.jpg',
codigo: '237'
}

exports.dvBarra = function (barra) {
var resto2 = formatters.mod11(barra, 9, 1)
const resto2 = formatters.mod11(barra, 9, 1)
return (resto2 == 0 || resto2 == 1 || resto2 == 10) ? 1 : 11 - resto2
}

exports.barcodeData = function (boleto) {
var codigoBanco = this.options.codigo
var numMoeda = '9'
const codigoBanco = this.options.codigo
const numMoeda = '9'

var fatorVencimento = formatters.fatorVencimento(moment(boleto['data_vencimento']).utc().format())
const fatorVencimento = formatters.fatorVencimento(moment(boleto['data_vencimento']).utc().format())

var agencia = formatters.addTrailingZeros(boleto['agencia'], 4)
const agencia = formatters.addTrailingZeros(boleto['agencia'], 4)

var valor = formatters.addTrailingZeros(boleto['valor'], 10)
var carteira = boleto['carteira']
var codigoCedente = formatters.addTrailingZeros(boleto['codigo_cedente'], 7)
const valor = formatters.addTrailingZeros(boleto['valor'], 10)
const carteira = boleto['carteira']
const codigoCedente = formatters.addTrailingZeros(boleto['codigo_cedente'], 7)

var nossoNumero = carteira + formatters.addTrailingZeros(boleto['nosso_numero'], 11)
const nossoNumero = carteira + formatters.addTrailingZeros(boleto['nosso_numero'], 11)

var barra = codigoBanco + numMoeda + fatorVencimento + valor + agencia + nossoNumero + codigoCedente + '0'
const barra = codigoBanco + numMoeda + fatorVencimento + valor + agencia + nossoNumero + codigoCedente + '0'

var dvBarra = this.dvBarra(barra)
var lineData = barra.substring(0, 4) + dvBarra + barra.substring(4, barra.length)
const dvBarra = this.dvBarra(barra)
const lineData = barra.substring(0, 4) + dvBarra + barra.substring(4, barra.length)

return lineData
}
Expand All @@ -47,11 +47,11 @@ exports.linhaDigitavel = function (barcodeData) {
// 37-43 -> Conta do Cedente (sem dígito)
// 44-44 -> Zero (Fixo)

var campos = []
const campos = []

// 1. Campo - composto pelo código do banco, código da moéda, as cinco primeiras posições
// do campo livre e DV (modulo10) deste campo
var campo = barcodeData.substring(0, 3) + barcodeData.substring(3, 4) + barcodeData.substring(19, 20) + barcodeData.substring(20, 24)
let campo = barcodeData.substring(0, 3) + barcodeData.substring(3, 4) + barcodeData.substring(19, 20) + barcodeData.substring(20, 24)
campo = campo + formatters.mod10(campo)
campo = campo.substring(0, 5) + '.' + campo.substring(5, campo.length)
campos.push(campo)
Expand Down Expand Up @@ -85,20 +85,20 @@ exports.linhaDigitavel = function (barcodeData) {

exports.parseEDIFile = function (fileContent) {
try {
var lines = fileContent.split('\n')
var parsedFile = {
const lines = fileContent.split('\n')
const parsedFile = {
boletos: []
}

for (var i = 0; i < lines.length; i++) {
var line = lines[i]
var registro = line.substring(0, 1)
for (let i = 0; i < lines.length; i++) {
const line = lines[i]
const registro = line.substring(0, 1)

if (registro == '0') {
parsedFile['razao_social'] = line.substring(46, 76)
parsedFile['data_arquivo'] = ediHelper.dateFromEdiDate(line.substring(94, 100))
} else if (registro == '1') {
var boleto = {}
const boleto = {}

parsedFile['cnpj'] = formatters.removeTrailingZeros(line.substring(3, 17))
parsedFile['carteira'] = formatters.removeTrailingZeros(line.substring(22, 24))
Expand All @@ -107,12 +107,12 @@ exports.parseEDIFile = function (fileContent) {

boleto['codigo_ocorrencia'] = line.substring(108, 110)

var ocorrenciasStr = line.substring(318, 328)
var motivosOcorrencia = []
var isPaid = (parseInt(boleto['valor_pago']) >= parseInt(boleto['valor']) || boleto['codigo_ocorrencia'] == '06')
const ocorrenciasStr = line.substring(318, 328)
const motivosOcorrencia = []
let isPaid = (parseInt(boleto['valor_pago']) >= parseInt(boleto['valor']) || boleto['codigo_ocorrencia'] == '06')

for (var j = 0; j < ocorrenciasStr.length; j += 2) {
var ocorrencia = ocorrenciasStr.substr(j, 2)
for (let j = 0; j < ocorrenciasStr.length; j += 2) {
const ocorrencia = ocorrenciasStr.substr(j, 2)
motivosOcorrencia.push(ocorrencia)

if (ocorrencia != '00') {
Expand Down
56 changes: 28 additions & 28 deletions banks/santander/index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
const moment = require('moment')
var formatters = require('../../lib/formatters')
var ediHelper = require('../../lib/edi-helper')
var helper = require('./helper')
const formatters = require('../../lib/formatters')
const ediHelper = require('../../lib/edi-helper')
const helper = require('./helper')

exports.options = {
logoURL: 'https://assets.pagar.me/boleto/images/santander.png',
codigo: '033'
}

exports.dvBarra = function (barra) {
var resto2 = formatters.mod11(barra, 9, 1)
const resto2 = formatters.mod11(barra, 9, 1)
return (resto2 == 0 || resto2 == 1 || resto2 == 10) ? 1 : 11 - resto2
}

exports.barcodeData = function (boleto) {
var codigoBanco = this.options.codigo
var numMoeda = '9'
var fixo = '9' // Numero fixo para a posição 05-05
var ios = '0' // IOS - somente para Seguradoras (Se 7% informar 7, limitado 9%) - demais clientes usar 0
const codigoBanco = this.options.codigo
const numMoeda = '9'
const fixo = '9' // Numero fixo para a posição 05-05
const ios = '0' // IOS - somente para Seguradoras (Se 7% informar 7, limitado 9%) - demais clientes usar 0

var fatorVencimento = formatters.fatorVencimento(moment(boleto['data_vencimento']).utc().format())
const fatorVencimento = formatters.fatorVencimento(moment(boleto['data_vencimento']).utc().format())

var valor = formatters.addTrailingZeros(boleto['valor'], 10)
var carteira = boleto['carteira']
var codigoCedente = formatters.addTrailingZeros(boleto['codigo_cedente'], 7)
const valor = formatters.addTrailingZeros(boleto['valor'], 10)
const carteira = boleto['carteira']
const codigoCedente = formatters.addTrailingZeros(boleto['codigo_cedente'], 7)

var nossoNumero = formatters.addTrailingZeros(boleto['nosso_numero'], 12) + formatters.mod11(boleto['nosso_numero'])
const nossoNumero = formatters.addTrailingZeros(boleto['nosso_numero'], 12) + formatters.mod11(boleto['nosso_numero'])

var barra = codigoBanco + numMoeda + fatorVencimento + valor + fixo + codigoCedente + nossoNumero + ios + carteira
const barra = codigoBanco + numMoeda + fatorVencimento + valor + fixo + codigoCedente + nossoNumero + ios + carteira

var dvBarra = this.dvBarra(barra)
var lineData = barra.substring(0, 4) + dvBarra + barra.substring(4, barra.length)
const dvBarra = this.dvBarra(barra)
const lineData = barra.substring(0, 4) + dvBarra + barra.substring(4, barra.length)

return lineData
}
Expand All @@ -50,11 +50,11 @@ exports.linhaDigitavel = function (barcodeData) {
// 31 a 34 Fator de vencimento (qtdade de dias desde 07/10/1997 até a data de vencimento)
// 35 a 44 Valor do título

var campos = []
const campos = []

// 1. Primeiro Grupo - composto pelo código do banco, código da moéda, Valor Fixo "9"
// e 4 primeiros digitos do PSK (codigo do cliente) e DV (modulo10) deste campo
var campo = barcodeData.substring(0, 3) + barcodeData.substring(3, 4) + barcodeData.substring(19, 20) + barcodeData.substring(20, 24)
let campo = barcodeData.substring(0, 3) + barcodeData.substring(3, 4) + barcodeData.substring(19, 20) + barcodeData.substring(20, 24)
campo = campo + formatters.mod10(campo)
campo = campo.substring(0, 5) + '.' + campo.substring(5, campo.length)
campos.push(campo)
Expand Down Expand Up @@ -88,16 +88,16 @@ exports.linhaDigitavel = function (barcodeData) {

exports.parseEDIFile = function (fileContent) {
try {
var lines = fileContent.split('\n')
var parsedFile = {
const lines = fileContent.split('\n')
const parsedFile = {
boletos: {}
}

var currentNossoNumero = null
let currentNossoNumero = null

for (var i = 0; i < lines.length; i++) {
var line = lines[i]
var registro = line.substring(7, 8)
for (let i = 0; i < lines.length; i++) {
const line = lines[i]
const registro = line.substring(7, 8)

if (registro == '0') {
parsedFile['cnpj'] = line.substring(17, 32)
Expand All @@ -106,10 +106,10 @@ exports.parseEDIFile = function (fileContent) {
parsedFile['conta_cedente'] = line.substring(37, 47)
parsedFile['data_arquivo'] = helper.dateFromEdiDate(line.substring(143, 152))
} else if (registro == '3') {
var segmento = line.substring(13, 14)
const segmento = line.substring(13, 14)

if (segmento == 'T') {
var boleto = {}
const boleto = {}

boleto['codigo_ocorrencia'] = line.substring(15, 17)
boleto['vencimento'] = formatters.dateFromEdiDate(line.substring(69, 77))
Expand All @@ -123,10 +123,10 @@ exports.parseEDIFile = function (fileContent) {
} else if (segmento == 'U') {
parsedFile.boletos[currentNossoNumero]['valor_pago'] = formatters.removeTrailingZeros(line.substring(77, 92))

var paid = parsedFile.boletos[currentNossoNumero]['valor_pago'] >= parsedFile.boletos[currentNossoNumero]['valor']
let paid = parsedFile.boletos[currentNossoNumero]['valor_pago'] >= parsedFile.boletos[currentNossoNumero]['valor']
paid = paid && parsedFile.boletos[currentNossoNumero]['codigo_ocorrencia'] == '17'

boleto = parsedFile.boletos[currentNossoNumero]
let boleto = parsedFile.boletos[currentNossoNumero]

boleto['pago'] = paid
boleto['edi_line_number'] = i
Expand Down
6 changes: 3 additions & 3 deletions examples/bradesco-edi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fs = require('fs')
var path = require('path')
const fs = require('fs')
const path = require('path')

var ediParser = require('../index').EdiParser
const ediParser = require('../index').EdiParser

console.log(ediParser.parse('bradesco', fs.readFileSync(path.join(__dirname, 'retorno_bradesco.txt')).toString()))
10 changes: 5 additions & 5 deletions examples/bradesco-emission.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var express = require('express')
var path = require('path')
const express = require('express')
const path = require('path')

var app = express()
const app = express()

var Boleto = require('../index').Boleto
const Boleto = require('../index').Boleto

var boleto = new Boleto({
const boleto = new Boleto({
'banco': 'bradesco',
'data_emissao': new Date(),
'data_vencimento': new Date(new Date().getTime() + 5 * 24 * 3600 * 1000),
Expand Down
6 changes: 3 additions & 3 deletions examples/santander-edi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fs = require('fs')
var path = require('path')
const fs = require('fs')
const path = require('path')

var ediParser = require('../index').EdiParser
const ediParser = require('../index').EdiParser

console.log(ediParser.parse('santander', fs.readFileSync(path.join(__dirname, '/retorno.txt')).toString()))
10 changes: 5 additions & 5 deletions examples/santander-emission.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var express = require('express')
var path = require('path')
const express = require('express')
const path = require('path')

var app = express()
const app = express()

var Boleto = require('../index').Boleto
const Boleto = require('../index').Boleto

var boleto = new Boleto({
const boleto = new Boleto({
'banco': 'santander',
'data_emissao': new Date(),
'data_vencimento': new Date(new Date().getTime() + 5 * 24 * 3600 * 1000),
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var fs = require('fs')
var path = require('path')
const fs = require('fs')
const path = require('path')

// Load banks
var banks = {}
var banksFolders = fs.readdirSync(path.join(__dirname, '/banks/'))
for (var i = 0; i < banksFolders.length; i++) {
const banks = {}
const banksFolders = fs.readdirSync(path.join(__dirname, '/banks/'))
for (let i = 0; i < banksFolders.length; i++) {
banks[banksFolders[i]] = require(path.join(__dirname, '/banks/' + banksFolders[i] + '/index.js'))
}

Expand Down
22 changes: 11 additions & 11 deletions lib/boleto.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const barcode = require('./barcode')
const path = require('path')
const moment = require('moment')

var banks = null
let banks = null

var hashString = function (string) {
var hash = 0
var i
var chr
var len
let hashString = function (string) {
let hash = 0
let i
let chr
let len

if (string.length == 0) return hash
for (i = 0, len = string.length; i < len; i++) {
Expand All @@ -21,7 +21,7 @@ var hashString = function (string) {
return hash
}

var Boleto = function (options) {
const Boleto = function (options) {
if (!options) {
throw 'No options provided initializing Boleto.'
}
Expand All @@ -43,7 +43,7 @@ var Boleto = function (options) {
options['data_vencimento'] = moment(moment(options['data_vencimento']).utc().format('YYYY-MM-DD'))
}

for (var key in options) {
for (let key in options) {
this[key] = options[key]
}

Expand All @@ -67,13 +67,13 @@ Boleto.prototype._calculate = function () {
}

Boleto.prototype.renderHTML = function (callback) {
var self = this
let self = this

var renderOptions = self.bank.options
let renderOptions = self.bank.options
renderOptions.boleto = self

// Copy renderHelper's methods to renderOptions
for (var key in formatters) {
for (let key in formatters) {
renderOptions[key] = formatters[key]
}

Expand Down
2 changes: 1 addition & 1 deletion lib/edi-helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var crypto = require('crypto')
const crypto = require('crypto')

exports.calculateLineChecksum = function (line) {
return crypto.createHash('sha1').update(line).digest('hex')
Expand Down
Loading
Loading