leonardo-m
7/10/2018 - 5:40 PM

SAP B1 Journal Entry

Ejemplo de Asiento Contable

The following sample code shows how to add a JournalEntries object into the database.
Private Sub cmdTest_Click()
   On Error GoTo ErrorHandler
   Dim vCompany As SAPbobsCOM.Company

   'create company object
   Set vCompany = New SAPbobsCOM.Company

   'set paras for connection
   vCompany.CompanyDB = "SBODemo_US"
   vCompany.Password = "manager"
   vCompany.UserName = "manager"
   vCompany.Server = "(local)"

   'connect to database server
   If (0 <> vCompany.Connect()) Then
      MsgBox "Failed to connect"
      Exit Sub
   End If

   Dim nErr As Long
   Dim errMsg As String

   'add an Journal entry
   Dim vJE As SAPbobsCOM.JournalEntries
   Set vJE = vCompany.GetBusinessObject(oJournalEntries)
   vJE.TaxDate = Now
   vJE.Lines.AccountCode = "110000"
   vJE.Lines.ContraAccount = "10110"
   vJE.Lines.Credit = 0
   vJE.Lines.Debit = 150
   vJE.Lines.DueDate = CDate("11/13/ 2002")
   vJE.Lines.ReferenceDate1 = Now
   vJE.Lines.ShortName = "110000"
   vJE.Lines.TaxDate = Now
   Call vJE.Lines.Add
   Call vJE.Lines.SetCurrentLine(1)
   vJE.Lines.AccountCode = "10110"
   vJE.Lines.ContraAccount = "110000"
   vJE.Lines.Credit = 150
   vJE.Lines.Debit = 0
   vJE.Lines.DueDate = CDate("11/13/ 2002")
   vJE.Lines.Line_ID = 1
   vJE.Lines.ReferenceDate1 = Now
   vJE.Lines.ShortName = "10110"
   vJE.Lines.TaxDate = Now
   If (0 <> vJE.Add()) Then
       MsgBox ("failed to add a journal entry")
   Else
       MsgBox ("Succeeded in adding a journal entry")
       vJE.SaveXml ("c:\temp\JournalEntries" + Str(vJE.JdtNum) + ".xml")
   End If

   'Check Error
   Call vCompany.GetLastError(nErr, errMsg)
   If (0 <> nErr) Then
       MsgBox ("Found error:" + Str(nErr) + "," + errMsg)
   End If

   'disconnect the company object, and release resource
   Call vCompany.Disconnect
   Set vCompany = Nothing
   Exit Sub
ErrorHandler:
   MsgBox ("Exception:" + Err.Description)
End Sub