Skip to content

Commit

Permalink
edi date: moving helper
Browse files Browse the repository at this point in the history
  • Loading branch information
alinemarjorie committed Dec 1, 2020
1 parent 88b1cdb commit a1131d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 0 additions & 3 deletions banks/bradesco/helper.js

This file was deleted.

9 changes: 4 additions & 5 deletions banks/bradesco/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const moment = require('moment')
var formatters = require('../../lib/formatters')
var ediHelper = require('../../lib/edi-helper')
var helper = require('./helper')

exports.options = {
logoURL: 'https://assets.pagar.me/boleto/images/bradesco.jpg',
Expand Down Expand Up @@ -97,7 +96,7 @@ exports.parseEDIFile = function (fileContent) {

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

Expand All @@ -122,9 +121,9 @@ exports.parseEDIFile = function (fileContent) {
}

boleto['motivos_ocorrencia'] = motivosOcorrencia
boleto['data_ocorrencia'] = helper.dateFromEdiDate(line.substring(110, 116))
boleto['data_credito'] = helper.dateFromEdiDate(line.substring(295, 301))
boleto['vencimento'] = helper.dateFromEdiDate(line.substring(110, 116))
boleto['data_ocorrencia'] = ediHelper.dateFromEdiDate(line.substring(110, 116))
boleto['data_credito'] = ediHelper.dateFromEdiDate(line.substring(295, 301))
boleto['vencimento'] = ediHelper.dateFromEdiDate(line.substring(110, 116))
boleto['valor'] = formatters.removeTrailingZeros(line.substring(152, 165))
boleto['banco_recebedor'] = formatters.removeTrailingZeros(line.substring(165, 168))
boleto['agencia_recebedora'] = formatters.removeTrailingZeros(line.substring(168, 173))
Expand Down
7 changes: 7 additions & 0 deletions lib/edi-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ exports.calculateLineChecksum = function (line) {
return crypto.createHash('sha1').update(line).digest('hex')
}

exports.dateFromEdiDate = function (ediDate) {
const year = ediDate.substring(4, 8)
const month = ediDate.substring(2, 4)
const day = ediDate.substring(0, 2)

return new Date(parseInt('20' + year), parseInt(month) - 1, parseInt(day))
}

0 comments on commit a1131d5

Please sign in to comment.