diff --git a/src.vba/Cnab400.bas b/src.vba/CNAB400.bas similarity index 100% rename from src.vba/Cnab400.bas rename to src.vba/CNAB400.bas diff --git a/src.vba/point.cls b/src.vba/Point.cls similarity index 100% rename from src.vba/point.cls rename to src.vba/Point.cls diff --git a/src.vba/privateKey.cls b/src.vba/PrivateKey.cls similarity index 100% rename from src.vba/privateKey.cls rename to src.vba/PrivateKey.cls diff --git a/src.vba/SendOrderForm.frm b/src.vba/SendOrderForm.frm index 877d34d..1f5f3ec 100644 --- a/src.vba/SendOrderForm.frm +++ b/src.vba/SendOrderForm.frm @@ -22,7 +22,6 @@ Private Sub UserForm_Initialize() End Sub Private Sub SendButton_Click() - On Error Resume Next Dim teamId As String Dim orders As Collection Dim respMessage As String @@ -34,11 +33,18 @@ Private Sub SendButton_Click() ActiveSheet.Cells(TableFormat.HeaderRow(), 1).Value = "Nome" ActiveSheet.Cells(TableFormat.HeaderRow(), 2).Value = "CPF/CNPJ" ActiveSheet.Cells(TableFormat.HeaderRow(), 3).Value = "Valor" - ActiveSheet.Cells(TableFormat.HeaderRow(), 4).Value = "Código do Banco" + ActiveSheet.Cells(TableFormat.HeaderRow(), 4).Value = "Código do Banco/ISPB" ActiveSheet.Cells(TableFormat.HeaderRow(), 5).Value = "Agência" ActiveSheet.Cells(TableFormat.HeaderRow(), 6).Value = "Conta" ActiveSheet.Cells(TableFormat.HeaderRow(), 7).Value = "Tags" ActiveSheet.Cells(TableFormat.HeaderRow(), 8).Value = "Descrição" + ActiveSheet.Cells(TableFormat.HeaderRow(), 9).Value = "externalId" + + If Sheets("Credentials").Cells(7, 2) <> Date Then + ActiveSheet.Range("I10:I" & Rows.Count).ClearContents + End If + + Sheets("Credentials").Cells(7, 2) = Date Call FreezeHeader @@ -50,8 +56,7 @@ Private Sub SendButton_Click() Next End With - Set orders = TeamGateway.getOrders() - respMessage = TeamGateway.createOrders(teamId, orders) + respMessage = TeamGateway.createOrders(teamId) Unload Me diff --git a/src.vba/SessionGateway.bas b/src.vba/SessionGateway.bas index 6610ed2..fae1861 100644 --- a/src.vba/SessionGateway.bas +++ b/src.vba/SessionGateway.bas @@ -12,6 +12,7 @@ Public Sub saveSession(workspace As String, email As String, envString As String Sheets("Credentials").Cells(5, 2) = memberName Sheets("Credentials").Cells(6, 1) = "Workspace ID" Sheets("Credentials").Cells(6, 2) = workspaceId + Sheets("Credentials").Cells(7, 1) = "Approval Date" End Sub diff --git a/src.vba/TeamGateway.bas b/src.vba/TeamGateway.bas index bca73d0..36cdd1d 100644 --- a/src.vba/TeamGateway.bas +++ b/src.vba/TeamGateway.bas @@ -27,46 +27,33 @@ Public Function getTeams(cursor As String, optionalParam As Dictionary) End Function -Public Function createOrders(teamId As String, orders As Collection) +Public Sub clearOrders() + Sheets("Transferências Com Aprovação").Range("A10:Z" & Rows.Count).ClearContents +End Sub + +Public Function createOrders(teamId As String) + Dim orders As New Collection + Dim orderNumbers As New Collection + Dim externalIds As New Collection + Dim iteration As Integer + Dim startRow As Integer + Dim currentRow As Integer Dim resp As response Dim payload As String Dim dict As New Dictionary + Dim returnMessage As String + Dim warningMessage As String + Dim errorMessage As String + Dim anySent As Boolean - dict.Add "teamId", teamId - dict.Add "orders", orders - - payload = JsonConverter.ConvertToJson(dict) - - Set resp = StarkBankApi.postRequest("/v1/team/order", payload, New Dictionary) - - If resp.Status = 200 Then - createOrders = resp.json()("message") - MsgBox resp.json()("message"), , "Sucesso" - - ElseIf resp.error().Exists("errors") Then - Dim errors As Collection: Set errors = resp.error()("errors") - Dim error As Dictionary - Dim errorList As String - Dim errorDescription As String - - For Each error In errors - errorDescription = Utils.correctErrorLine(error("message"), TableFormat.HeaderRow() + 1) - errorList = errorList & errorDescription & Chr(10) - Next - - Dim messageBox As String - messageBox = resp.error()("message") & Chr(10) & Chr(10) & errorList - MsgBox messageBox, , "Erro" - - Else - MsgBox resp.error()("message"), , "Erro" - - End If + anySent = False + returnMessage = "" + warningMessage = "" + errorMessage = "" -End Function - -Public Function getOrders() As Collection - Dim orders As New Collection + dict.Add "teamId", teamId + iteration = 0 + startRow = TableFormat.HeaderRow() + 1 For Each obj In SheetParser.dict Dim amount As Long @@ -79,6 +66,9 @@ Public Function getOrders() As Collection Dim description As String Dim order As Dictionary + iteration = iteration + 1 + currentRow = TableFormat.HeaderRow() + iteration + If obj("Valor") = "" Then MsgBox "Por favor, não deixe linhas em branco entre as ordens de transferência", , "Erro" Unload SendOrderForm @@ -87,17 +77,75 @@ Public Function getOrders() As Collection amount = getAmountLong((obj("Valor"))) taxId = Trim(obj("CPF/CNPJ")) name = Trim(obj("Nome")) - bankCode = Trim(obj("Código do Banco")) + bankCode = Trim(obj("Código do Banco/ISPB")) branchCode = Trim(obj("Agência")) accountNumber = Trim(obj("Conta")) tags = Split(obj("Tags"), ",") description = obj("Descrição") + externalId = obj("externalId") - Set order = TeamGateway.order(amount, taxId, name, bankCode, branchCode, accountNumber, tags, description) - orders.Add order + calculatedExternalId = calculateExternalId(amount, name, taxId, bankCode, branchCode, accountNumber) + + If calculatedExternalId = externalId Then + warningMessage = "Aviso: Pedidos já enviados hoje não foram reenviados!" + Chr(10) + Chr(10) + Else + Set order = TeamGateway.order(amount, taxId, name, bankCode, branchCode, accountNumber, tags, description) + orders.Add order + orderNumbers.Add iteration + externalIds.Add calculatedExternalId + End If + + If (iteration Mod 100) = 0 Or (currentRow >= ActiveSheet.Cells(Rows.Count, "A").End(xlUp).row) Then + If orderNumbers.Count = 0 Then + Set orders = Nothing + Set orderNumbers = Nothing + Set externalIds = Nothing + GoTo nextIteration + End If + dict.Add "orders", orders + + payload = JsonConverter.ConvertToJson(dict) + Set resp = StarkBankApi.postRequest("/v1/team/order", payload, New Dictionary) + anySent = True + + dict.Remove "orders" + + If resp.Status = 200 Then + createOrders = resp.json()("message") + returnMessage = returnMessage + rowsMessage(startRow, currentRow) + resp.json()("message") + Chr(10) + Dim j As Integer + For j = 1 To externalIds.Count + ActiveSheet.Cells(TableFormat.HeaderRow() + orderNumbers.Item(j), 9).Value = externalIds.Item(j) + Next j + + ElseIf resp.error().Exists("errors") Then + Dim errors As Collection: Set errors = resp.error()("errors") + Dim error As Dictionary + Dim errorDescription As String + + For Each error In errors + errorDescription = Utils.correctErrorLine(error("message"), startRow) + errorMessage = errorMessage + errorDescription + Chr(10) + Next + + Else + errorDescription = Utils.correctErrorLine(resp.error()("message"), startRow) + errorMessage = errorMessage + errorDescription + Chr(10) + + End If +nextIteration: + startRow = currentRow + 1 + Set orders = Nothing + Set orderNumbers = Nothing + Set externalIds = Nothing + End If Next - Set getOrders = orders + If anySent Then + MsgBox warningMessage + Chr(10) + returnMessage + Chr(10) + errorMessage + Else + MsgBox "Todos os pedidos listados já foram enviados" + End If End Function Public Function order(amount As Long, taxId As String, name As String, bankCode As String, branchCode As String, accountNumber As String, tags() As String, description As String) As Dictionary @@ -142,4 +190,12 @@ Public Function getOrdersByTransfer(cursor As String, optionalParam As Dictionar MsgBox resp.error()("message"), , "Erro" End If +End Function + +Public Function calculateExternalId(amount As Long, name As String, taxId As String, bankCode As String, branchCode As String, accountNumber As String) + calculateExternalId = bankCode + branchCode + accountNumber + name + taxId + CStr(amount) +End Function + +Public Function rowsMessage(startRow As Integer, currentRow As Integer) + rowsMessage = "Linhas " + CStr(startRow) + " a " + CStr(currentRow) + ": " End Function \ No newline at end of file diff --git a/src.vba/Utils.bas b/src.vba/Utils.bas index a1a3a7e..11d2e21 100644 --- a/src.vba/Utils.bas +++ b/src.vba/Utils.bas @@ -112,7 +112,7 @@ Public Function clearNonNumeric(text) Set Reg = Nothing End Function -Function correctErrorLine(errorMessage As String, offset As Integer) As String +Function correctErrorLine(ByVal errorMessage As String, offset As Integer) As String Dim lineNumber As Integer Dim message As String @@ -124,7 +124,6 @@ Function correctErrorLine(errorMessage As String, offset As Integer) As String message = M.submatches(2) Next End With - correctErrorLine = "Linha " & CStr(lineNumber + offset) & ": " & message End Function diff --git a/src.vba/ViewHelpForm.frm b/src.vba/ViewHelpForm.frm index 33fb069..d63565b 100644 --- a/src.vba/ViewHelpForm.frm +++ b/src.vba/ViewHelpForm.frm @@ -11,10 +11,6 @@ Private Sub HelpSandboxWebButton_Click() ActiveWorkbook.FollowHyperlink address:="https://starkbank.com/sandbox" End Sub -Private Sub Label2_Click() - -End Sub - Private Sub SendPublicKeyButton_Click() SendKeyForm.Show End Sub \ No newline at end of file diff --git a/src.vba/ViewStatementForm.frm b/src.vba/ViewStatementForm.frm index 87fe379..e27278c 100644 --- a/src.vba/ViewStatementForm.frm +++ b/src.vba/ViewStatementForm.frm @@ -261,8 +261,14 @@ Private Function getTransactionType(list() As String, ByRef teams As Collection, transactionType = "Transferência interna" Case "charge" transactionType = "Recebimento de boleto pago" + Case "invoice" + transactionType = "Recebimento de cobrança Pix" + Case "deposit" + transactionType = "Recebimento de depósito Pix" Case "charge-payment" transactionType = "Pag. de boleto" + Case "brcode-payment" + transactionType = "Pag. de QR Code" Case "bar-code-payment" transactionType = "Pag. de imposto/concessionária" Case "utility-payment" diff --git a/starkbank-sdk.xlsm b/starkbank-sdk.xlsm index c12735d..be16cbb 100644 Binary files a/starkbank-sdk.xlsm and b/starkbank-sdk.xlsm differ