-
Notifications
You must be signed in to change notification settings - Fork 15
Add Bradesco DARF #39
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
Open
diegoyamasaki-stark
wants to merge
11
commits into
master
Choose a base branch
from
feature/bradesco
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e447d73
Add Bradesco DARF
diegoyamasaki-stark 9b4bc6f
Add import
diegoyamasaki-stark 1ff87ff
fix taxId type
diegoyamasaki-stark d7b6fe8
fix our number optional
diegoyamasaki-stark b511144
Fix type tax
diegoyamasaki-stark fb3a647
Add insuficient funds as error
diegoyamasaki-stark 5d05e3a
Fix get line ID
diegoyamasaki-stark 034ec84
Add invalid amount as failed status
diegoyamasaki-stark 22836a3
Ajusts and samples
diegoyamasaki-stark 5f3f9c0
Fix MR comments
diegoyamasaki-stark 0377113
Fix MR Comment
diegoyamasaki-stark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from .file.file import File | ||
| from .payment.darfPayment import DarfPayment | ||
| from .result.parser import PaymentParser |
Binary file not shown.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from datetime import datetime | ||
| from febraban.cnab240.libs.fileUtils import FileUtils | ||
| from febraban.cnab240.bradesco.multipag.file.header import Header | ||
| from febraban.cnab240.bradesco.multipag.file.trailer import Trailer | ||
|
|
||
|
|
||
| class File: | ||
|
|
||
| def __init__(self, sequenceNumber=1): | ||
| self.header = Header(sequenceNumber) | ||
| self.lots = [] | ||
| self.trailer = Trailer() | ||
|
|
||
| def addLot(self, lot): | ||
| lot.setLotNumber(len(self.lots) + 1) | ||
| self.lots.append(lot) | ||
|
|
||
| def toString(self, currentDatetime=None): | ||
| lotsToString = "\r\n".join([lot.toString() for lot in self.lots]) | ||
| self.header.setGeneratedFileDate(currentDatetime or datetime.now()) | ||
| self.trailer.setNumberOfLotsAndRegisters( | ||
| num=len(self.lots), | ||
| sum=2 + self._countRegistersInLots() | ||
| ) | ||
| return "%s\r\n%s\r\n%s\r\n" % ( | ||
| self.header.content, | ||
| lotsToString, | ||
| self.trailer.content | ||
| ) | ||
|
|
||
| def setSender(self, sender): | ||
| self.header.setSender(sender) | ||
| self.header.setSenderBank(sender.bank) | ||
| self.trailer.setSenderBank(sender.bank) | ||
| self.header.setBankAgreement(sender.bank.bankAgreement) | ||
|
|
||
| def output(self, fileName, path="/../", content=None, currentDatetime=None): | ||
| file = FileUtils.create(name=fileName, path=path) | ||
| file.write(self.toString(currentDatetime or datetime.now()) if not content else content) | ||
| file.close() | ||
|
|
||
| def _countRegistersInLots(self): | ||
| count = 0 | ||
| for lot in self.lots: | ||
| count += lot.count | ||
| return count |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| from febraban.cnab240.row import Row | ||
| from febraban.cnab240.characterType import alphaNumeric, numeric | ||
|
|
||
|
|
||
| class Header: | ||
| def __init__(self, sequenceNumber=1): | ||
| self.content = " " * 240 | ||
| self.defaultValues() | ||
| self.setFileSequenceNumber(sequenceNumber) | ||
|
|
||
| def defaultValues(self): | ||
| structs = [ | ||
| ( 3, 7, 4, numeric, "0000"), # Service lot | ||
| ( 7, 8, 1, numeric, "0"), # Record type | ||
| ( 163, 166, 3, numeric, "089"), # Layout version | ||
| ( 142, 143, 1, numeric, "1"), # 1 - Remittance / 2 - Return | ||
| ( 166, 171, 5, numeric, "1600"), # File recording density | ||
| ( 157, 163, 6, numeric, "000000"), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setFileSequenceNumber(self, number): | ||
| structs = [ | ||
| (157, 163, 6, numeric, number), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setGeneratedFileDate(self, datetime): | ||
| structs = [ | ||
| (143, 151, 8, numeric, datetime.strftime("%d%m%Y")), # File generation date | ||
| (151, 157, 6, numeric, datetime.strftime("%H%M%S")), # File generation time | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setSender(self, user): | ||
| structs = [ | ||
| (17, 18, 1, numeric, "1" if len(user.identifier) == 11 else "2"), | ||
| (18, 32, 14, numeric, user.identifier), | ||
| (72, 102, 30, alphaNumeric, user.name) | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setSenderBank(self, bank): | ||
| structs = [ | ||
| ( 0, 3, 3, numeric, bank.bankId), | ||
| (52, 57, 5, numeric, bank.branchCode), | ||
| (58, 70, 12, numeric, bank.accountNumber), | ||
| (70, 71, 1, alphaNumeric, bank.accountVerifier[:1]), | ||
| (102, 132, 30, alphaNumeric, bank.bankName), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setBankAgreement(self, agreement): | ||
| structs = [ | ||
| (32, 52, 20, alphaNumeric, agreement), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| from febraban.cnab240.row import Row | ||
| from febraban.cnab240.characterType import alphaNumeric, numeric | ||
|
|
||
| class HeaderLot: | ||
|
|
||
| def __init__(self): | ||
| self.content = " " * 240 | ||
| self.defaultValues() | ||
|
|
||
| def defaultValues(self): | ||
| structs = [ | ||
| ( 3, 7, 4, numeric, "1"), | ||
| ( 7, 8, 1, numeric, "1"), | ||
| ( 8, 9, 1, alphaNumeric, "C"), | ||
| ( 9, 11, 2, numeric, "01"), | ||
| ( 13, 16, 3, numeric, "012"), | ||
| ( 222, 224, 2, numeric, "01"), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setSender(self, user): | ||
| structs = [ | ||
| (17, 18, 1, numeric, "1" if len(user.identifier) == 11 else "2"), | ||
| (18, 32, 14, numeric, user.identifier), | ||
| (72, 102, 30, alphaNumeric, user.name) | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setGeneratedFileDate(self, datetime): | ||
| structs = [ | ||
| (191, 199, 8, numeric, datetime.strftime("%d%m%Y")), # Recording date | ||
| (199, 207, 8, numeric, datetime.strftime("%d%m%Y")), # Credit date | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setSenderBank(self, bank): | ||
| structs = [ | ||
| ( 0, 3, 3, numeric, bank.bankId), | ||
| (52, 57, 5, numeric, bank.branchCode), | ||
| (58, 70, 12, numeric, bank.accountNumber), | ||
| (70, 71, 1, numeric, bank.accountVerifier[:1]), | ||
| (71, 72, 1, alphaNumeric, ""), | ||
| (102, 132, 30, alphaNumeric, bank.bankName), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setSenderAddress(self, address): | ||
| structs = [ | ||
| (142, 192, 50, alphaNumeric, "%s %s %s" % (address.streetLine1, address.streetLine2, address.district)), | ||
| (192, 212, 20, alphaNumeric, address.city), | ||
| (212, 220, 8, numeric, address.zipCode), | ||
| (220, 222, 2, alphaNumeric, address.stateCode), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setPositionInLot(self, index): | ||
| structs = [ | ||
| (3, 7, 4, numeric, index) | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setInfo(self, kind, method): | ||
| structs = [ | ||
| ( 9, 11, 2, numeric, kind), | ||
| (11, 13, 2, numeric, method) | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setBankAgreement(self, agreement): | ||
| structs = [ | ||
| (32, 52, 20, alphaNumeric, agreement), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| from febraban.cnab240.libs.paymentKind import PaymentKind | ||
| from febraban.cnab240.libs.paymentMethod import PaymentMethod | ||
| from febraban.cnab240.bradesco.multipag.file.headerLot import HeaderLot | ||
| from febraban.cnab240.bradesco.multipag.file.trailerLot import TrailerLot | ||
| from febraban.cnab240.bradesco.multipag.payment.nonBarCodePayment import NonBarCodePayment | ||
|
|
||
|
|
||
| class Lot: | ||
|
|
||
| def __init__(self): | ||
| self.headerLot = HeaderLot() | ||
| self.registers = [] | ||
| self.trailerLot = TrailerLot() | ||
| self.kind = "" | ||
| self.method = "" | ||
| self.amount = 0 | ||
| self.otherAmount = 0 | ||
| self.additionAmount = 0 | ||
| self.totalAmount = 0 | ||
| self.index = 1 | ||
| self.count = 0 | ||
|
|
||
| def _isNonBarCodeTax(self): | ||
| return self.kind == PaymentKind.tribute and self.method in PaymentMethod.nonBarcodeTaxes() | ||
|
|
||
| def add(self, register): | ||
| register.setPositionInLot(index=self.index) | ||
| self.registers.append(register) | ||
| self.amount += register.amountInCents() | ||
| if self._isNonBarCodeTax(): | ||
| self.otherAmount += register.otherAmountInCents() | ||
| self.additionAmount += register.additionAmountInCents() | ||
| self.totalAmount += register.totalAmountInCents() | ||
| self.index += 1 | ||
|
|
||
| def setLotNumber(self, index): | ||
| self.headerLot.setPositionInLot(index) | ||
| self.trailerLot.setPositionInLot(index) | ||
| for register in self.registers: | ||
| register.setLot(index) | ||
|
|
||
| def setSender(self, sender): | ||
| self.headerLot.setSender(sender) | ||
| self.headerLot.setSenderBank(sender.bank) | ||
| self.headerLot.setSenderAddress(sender.address) | ||
| self.headerLot.setBankAgreement(sender.bank.bankAgreement) | ||
| self.trailerLot.setSenderBank(sender.bank) | ||
|
|
||
| def toString(self): | ||
| self.count = (2+self._count(NonBarCodePayment)) | ||
| self.trailerLot.setLotNumberOfRegisters( | ||
| num=self.count | ||
| ) | ||
|
|
||
| if self._isNonBarCodeTax(): | ||
| self.trailerLot.setSumOfValuesNonBarCodeTax( | ||
| sum=self.amount, | ||
| otherSum=self.otherAmount, | ||
| totalSum=self.totalAmount, | ||
| ) | ||
| elif self._isBoletoPayment(): | ||
| self.trailerLot.setSumOfValues(sum=self.totalAmount) | ||
| else: | ||
| self.trailerLot.setSumOfValues(sum=self.amount) | ||
|
|
||
| registersToString = "\r\n".join([register.toString() for register in self.registers]) | ||
| return "%s\r\n%s\r\n%s" % ( | ||
| self.headerLot.content, | ||
| registersToString, | ||
| self.trailerLot.content, | ||
| ) | ||
|
|
||
| def _count(self, cls): | ||
| return len([register for register in self.registers if isinstance(register, cls)]) | ||
|
|
||
| def setHeaderLotType(self, kind=PaymentKind.vendor, method=PaymentMethod.tedOther): | ||
| """ | ||
| Trasfers: | ||
| kind: String - Kind of payment - 20 Fornecedores, read: NOTES 4 | ||
| method: String - Payment method - 41 TED Outro titular, 43 TED Mesmo titular, 01 ITAU account. read: NOTES 5 | ||
|
|
||
| Charge-payments: | ||
| kind: String - Kind of payment - 98 Diversos, read: NOTES 4 | ||
| method: String - Payment method - 30 Pagamento Boleto Itau, 31 Pagamento Boleto outros Bancos. read: NOTES 5 | ||
|
|
||
| Utilities: | ||
| kind: String - Kind of payment - 98 Diversos, read: NOTES 4 | ||
| method: String - Payment method - 13 Concessionarias. read: NOTES 5 | ||
|
|
||
| Tax-payments: | ||
| kind: String - Kind of payment - 22 Tributos, read: NOTES 4 | ||
| method: String - Payment method - 91 GNRE e Tributos com Codigo de Barras, | ||
| 19 IPTU/ISS/Outros Tributos Municipais. read: NOTES 5, | ||
| 16 DARF (No barcode) | ||
|
|
||
| """ | ||
| self.kind = kind | ||
| self.method = method | ||
| self.headerLot.setInfo(kind, method) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from febraban.cnab240.row import Row | ||
| from febraban.cnab240.characterType import numeric | ||
|
|
||
|
|
||
| class Trailer: | ||
| def __init__(self): | ||
| self.content = " " * 240 | ||
| self.defaultValues() | ||
|
|
||
| def defaultValues(self): | ||
| structs = [ | ||
| (3, 7, 4, numeric, "9999"), | ||
| (7, 8, 1, numeric, "9"), | ||
| (29, 35, 6, numeric, "000000"), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setSenderBank(self, bank): | ||
| structs = [ | ||
| (0, 3, 3, numeric, bank.bankId), # Debit bank code | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setNumberOfLotsAndRegisters(self, sum, num): | ||
| structs = [ | ||
| (17, 23, 6, numeric, num), | ||
| (23, 29, 6, numeric, sum), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from febraban.cnab240.row import Row | ||
| from febraban.cnab240.characterType import numeric | ||
|
|
||
|
|
||
| class TrailerLot: | ||
|
|
||
| def __init__(self): | ||
| self.content = " " * 240 | ||
| self.defaultValues() | ||
|
|
||
| def defaultValues(self): | ||
| structs = [ | ||
| ( 3, 7, 4, numeric, "1"), | ||
| ( 7, 8, 1, numeric, "5"), | ||
| (41, 59, 18, numeric, "000000000000000000"), | ||
| (59, 65, 6, numeric, "000000"), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setLotNumberOfRegisters(self, num): | ||
| structs = [ | ||
| (17, 23, 6, numeric, num), | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setSumOfValues(self, sum): | ||
| structs = [ | ||
| (23, 41, 18, numeric, sum), # Sum of values of lots | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setSumOfValuesNonBarCodeTax(self, sum, otherSum, totalSum): | ||
| structs = [ | ||
| (23, 41, 18, numeric, sum), # Sum of main values of lots | ||
| (41, 59, 13, numeric, otherSum), # Sum of other entities values of lots | ||
|
joaogpw-stark marked this conversation as resolved.
Outdated
|
||
| (59, 65, 0, numeric, totalSum), # Sum of total values of lots | ||
|
joaogpw-stark marked this conversation as resolved.
Outdated
|
||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setSenderBank(self, bank): | ||
| structs = [ | ||
| (0, 3, 3, numeric, bank.bankId), # Debit bank code | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
|
|
||
| def setPositionInLot(self, index): | ||
| structs = [ | ||
| (3, 7, 4, numeric, index) # Indicates lot index | ||
| ] | ||
| self.content = Row.setStructs(structs=structs, content=self.content) | ||
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.