Example: Adding a financial document
 
The examples demonstrates how to add a financial document.
 
Remark
This example doesn't contain any business logic (exception handling, access management checks,...), it is just meant to show how to add a (simple) financial document.
 
See Also
How to add a purchase document
How to add a sales document
How to add a sundry document
 
Examples
C++
 
#include "stdafx.h"
#include "CppClient.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include <atlbase.h>
#include <ATLComTime.h>
#include <afxdisp.h>

#import "C:\Program Files\Exact C-Logic\Venice\Bin\ClSdk.dll"

using namespace std;
using namespace ClSdk;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    OleInitialize (NULL);

    try
    {
        // These are not 'real' pointers, but 'smart' pointers, looking as pointers but acting as objects, so do not use 'delete'!
        IVenicePtr  pVenice;
        IDossierPtr pDossier;
        IYearPtr    pYear;
        IFinanPtr   pFinan;
        IEntryPtr   pEntry;
        eAccessMode eAM;
        double      dblLastTotalDocC    = 0.00;
        DWORD       dwLastDocNum        = 0L;

        // Create the Venice object interface
        pVenice.CreateInstance(__uuidof(ClSdk::Venice));

        // Is option 'Access Management' installed?
        eAM = pVenice->GetAccessMode ();

        // Logon into Venice, allowing user interface
        if (eAM == amSecure)
            pVenice->LogonSecure ("13.10_", "MyApplication", lngNld, true, "ClSdkUser", "ClSdkPassword");
        else
            pVenice->Logon ("13.10_", "MyApplication", lngNld, true, "SDK", "ClSdkUser", "Software engineer");

        // Create Dossier Context, use the default filing cabinet 'Data' and the dossier 'Exact C-Logic'
        pDossier = pVenice->CreateDossierContext("", "Exact C-Logic");

        // Create Year Context
        pYear = pDossier->CreateYearContext (2024);

        // ----------------------------------------------------------------------------------------------------
        //  This example creates a financial document with ticking. It searches for all cash register sales  
        //  documents (sales to customer 1) of the day and ticks them. It is assumed this routine is
        //  run at the end of each day.
        //  While possible, this example does not demonstrate adding analytical details. See the example for
        //  Sales or Purchase documents for details on how to add analytical details to each entry detail.
        // ---------------------------------------------------------------------------------------------------- 

        // Create context for financial documents
        pFinan = pYear->CreateFinan (true);

        // Create context for entries
        pEntry = pYear->CreateEntry (false);

        // Search for the most recent financial document in the book 'CASH', and remember document number and total amount because
        // these will be needed to create a new following document.
        if (pFinan->SeekByBook (smLessOrEqual, "CASH", 999999))
        {
            dwLastDocNum     = (DWORD)pFinan->pDocNum;
            dblLastTotalDocC = (double)pFinan->pTotalDocC;
        }

        // Prepare the creation of a new Financial document.
        pFinan->PrepareDocument (paInsert);
        // Initialize with default values.
        pFinan->Init ();

        // Retrieve the date of today, without time indication (so that we can use it to compare to another date).
        COleDateTime dttmNow (COleDateTime::GetCurrentTime ()), dteNow (dttmNow.GetYear (), dttmNow.GetMonth (), dttmNow.GetDay (), 0, 0, 0);

        // In order to obtain a valid financial document header, the following properties must be assigned a value:
        // Book, Book date, Document date, Document number, Begin balance document currency, Amount document currency
        // This does not imply however that these properties need to be set in code, they can also be assigned via the standard values.
        // Note: While those are the only properties that are required to be filled in, other properties may require a value for the document to pass the internal validation checks. 
        //       These are the same validation checks that are applied when manually entering a document in Venice.
        pFinan->pBook = "CASH";
        pFinan->pDocNum = dwLastDocNum + 1;     // Cannot be 0 for financial documents
        pFinan->pBookDate = dteNow.m_dt;
        pFinan->pDocDate = dteNow.m_dt;
        pFinan->pRemark = (LPCSTR)("Daily cash register sales - " + dteNow.Format (_T("%d/%m/%Y")));
        pFinan->pStartDocC = dblLastTotalDocC;
        pFinan->pTotalDocC = 0.00;   // Will be updated each time we add a detail
                                        // Note that once the document is written, the pTotalDocC amount will include the pStartDocC.
                                        // While creating the document however, it should only reflect the total of the inserted entry 
                                        // lines in the document.

        // Add your code here for assigning additional properties of the document header.
        // pFinan->Xxx = yyy;

        // Create detail lines by searching for entry lines indicating cash sales of today.
        pEntry->SeekByHistory (smGreaterOrEqual, "400000000001", dteNow.m_dt, btSales, "", 0, 0);
        int iEntryNum = 0;

        while (pEntry->GetDBStatus () == 0 && CString (pEntry->pAccount) == "400000000001" && (DATE)pEntry->pDocDate == dteNow && (BYTE)pEntry->pBookType == btSales)
        {
            if ((double)pEntry->pOpenDetC != 0.0)	// Still an open amount?
            {
                COleVariant oleVarAcc (pEntry->pAccount), oleVarDetC (pEntry->pDetC);

                // Add a detail to the financial book, inversing the amount and ticking the sales entry
                pFinan->InsertDetail (iEntryNum, (double)pEntry->pAmountDocC * -1.0, 0.00, 0.00, oleVarAcc.bstrVal, "", "", (double)pEntry->pAmountDetC * -1.0, oleVarDetC.bstrVal, pEntry->pSysNum);
                iEntryNum += 1;

                pFinan->pTotalDocC = (double)pFinan->pTotalDocC + (double)pEntry->pAmountDocC;    // Add amount to total
            }

            pEntry->GetNext ();
        }

        // Write (or cancel) the document
        pFinan->WriteDocument (rmErrorReport);
        // If you do not use WriteDocument() because you do not want to save the document (maybe because of an error) you should call CancelDocument() instead.
    }

    catch (_com_error CE)
    {
        printf ("\nError while executing application.\nReason: %s\nSource: %s", (LPCSTR)CE.Description (), (LPCSTR)CE.Source ()); 
    }

    // All objects must be out of scope (or destroyed) before calling OleUninitialize ()!
    OleUninitialize ();
}
C#
 
using System;
using ClSdk;

namespace Example
{
    class Example
    {
        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                eAccessMode eAM;
                double      dblLastTotalDocC = 0.00;
                int         iLastDocNum      = 0;

                // Create the Venice object
                Venice oVenice = new Venice();

                // Is option 'Access Management' installed?
                eAM = oVenice.GetAccessMode ();

                // Logon into Venice, allowing user interface
                if (eAM == eAccessMode.amSecure)
                    oVenice.LogonSecure ("13.10_", "MyApplication", eLanguage.lngNld, true, "ClSdkUser", "ClSdkPassword");
                else
                    oVenice.Logon ("13.10_", "MyApplication", eLanguage.lngNld, true, "SDK", "ClSdkUser", "Software engineer");

                // Create Dossier Context, use the default filing cabinet 'Data' and the dossier 'Exact C-Logic'
                Dossier oDossier = oVenice.CreateDossierContext ("", "Exact C-Logic");

                // Create Year Context
                Year oYear = oDossier.CreateYearContext (0);

                // ----------------------------------------------------------------------------------------------------
                //  This example creates a financial document with ticking. It searches for all cash register sales  
                //  documents (sales to customer 1) of the day and ticks them. It is assumed this routine is
                //  run at the end of each day.
                //  While possible, this example does not demonstrate adding analytical details. See the example for
                //  Sales or Purchase documents for details on how to add analytical details to each entry detail.
                // ---------------------------------------------------------------------------------------------------- 

                // Create context for financial documents
                Finan oFinan = oYear.CreateFinan (true);

                // Create context for entries
                Entry oEntry = oYear.CreateEntry (false);

                // Search for the most recent financial document in the book 'CASH', and remember document number and total amount because
                // these will be needed to create a new following document.
                if (oFinan.SeekByBook (eSeekMode.smLessOrEqual, "CASH", 999999))
                {
                    iLastDocNum		 = (int)oFinan.pDocNum;
                    dblLastTotalDocC = (double)oFinan.pTotalDocC;
                }

                // Prepare the creation of a new Financial document.
                oFinan.PrepareDocument (ePrepareAction.paInsert);
                // Initialize with default values.
                oFinan.Init ();

                // In order to obtain a valid financial document header, the following properties must be assigned a value:
                // Book, Book date, Document date, Document number, Begin balance document currency, Amount document currency
                // This does not imply however that these properties need to be set in code, they can also be assigned via the standard values.
                // Note: While those are the only properties that are required to be filled in, other properties may require a value for the document to pass the internal validation checks. 
                //       These are the same validation checks that are applied when manually entering a document in Venice.
                oFinan.pBook = "CASH";
                oFinan.pDocNum = iLastDocNum + 1;     // Cannot be 0 for financial documents
                oFinan.pBookDate = DateTime.Today;
                oFinan.pDocDate = DateTime.Today;
                oFinan.pRemark = "Daily cash register sales - " + DateTime.Today.ToShortDateString ();
                oFinan.pStartDocC = dblLastTotalDocC;
                oFinan.pTotalDocC = 0.00;   // Will be updated each time we add a detail
                // Note that once the document is written, the pTotalDocC amount will include the pStartDocC.
                // While creating the document however, it should only reflect the total of the inserted entry 
                // lines in the document.

                // Add your code here for assigning additional properties of the document header.
                // oFinan.Xxx = yyy;

                // Create detail lines by searching for entry lines indicating cash sales of today.
                oEntry.SeekByHistory (eSeekMode.smGreaterOrEqual, "400000000001", DateTime.Today, eBookType.btSales, "", 0, 0);
                short sEntryNum = 0;

                while (oEntry.GetDBStatus () == 0 && oEntry.pAccount.ToString () == "400000000001" && ((DateTime)oEntry.pDocDate).Date == DateTime.Today.Date && (eBookType)((byte)oEntry.pBookType) == eBookType.btSales)
                {
                    if ((double)oEntry.pOpenDetC != 0.0)     // Still an open amount?
                    {
                        // Add a detail to the financial book, inversing the amount and ticking the sales entry
                        oFinan.InsertDetail (sEntryNum, (double)oEntry.pAmountDocC * -1.0, 0.00, 0.00, oEntry.pAccount.ToString (), "", "", (double)oEntry.pAmountDetC * -1.0, oEntry.pDetC.ToString (), (int)oEntry.pSysNum);
                        sEntryNum += 1;

                        oFinan.pTotalDocC = (double)oFinan.pTotalDocC + (double)oEntry.pAmountDocC;    // Add amount to total
                    }

                    oEntry.GetNext ();
                }

                // Write (or cancel) the document
                oFinan.WriteDocument (eReportMode.rmErrorReport);
                // If you do not use WriteDocument() because you do not want to save the document (maybe because of an error) you should call CancelDocument() instead.
            }
            catch (Exception ex)
            {
                Console.WriteLine ("Error while executing application.\nReason:" + ex.Message + "\nSource: " + ex.Source);
            }
        }
    }
}
VBS
 
Const amMin = -1
Const amNormal = 0
Const amSecure = 1
Const amMax = 2

Const lngMin = 0
Const lngNld = 0
Const lngFra = 1
Const lngEngNld = 2
Const lngEngFra = 3
Const lngAuto = 4
Const lngMax = 5

Const paMin = 0
Const paInsert = 0
Const paDuplicate = 1
Const paUpdate = 2
Const paView = 3
Const paMax = 4

Const rmMin = 0
Const rmNoReport = 0
Const rmErrorReport = 1
Const rmFullReport = 2
Const rmMax = 3

Const smMin = 0
Const smFirst = 0
Const smLess = 1
Const smLessOrEqual = 2
Const smEqual = 3
Const smGreaterOrEqual = 4
Const smGreater = 5
Const smLast = 6
Const smMax = 7

Const btMin = 0
Const btNone = 0
Const btPurch = 1
Const btSales = 2
Const btFinan = 3
Const btSndry = 4
Const btMax = 5

' Call main
Main

sub Main
    Dim oVenice
    Dim oDossier
    Dim oYear
    Dim oFinan
    Dim oEntry

    ' Create Venice object
    Set oVenice = CreateObject("Clsdk.Venice")

    ' Dummy code to activate Intellisense
    If False Then
        Set oDossier = CreateObject("ClSdk.Dossier")
        Set oYear = CreateObject("ClSdk.Year")
        Set oFinan = CreateObject("ClSdk.Finan")
        Set oEntry = CreateObject("ClSdk.Entry")
    End If

    ' Login
    If oVenice.GetAccessMode() = amSecure Then
        Call oVenice.LogonSecure("13.10_", "MyApplication", lngNld, true, "ClSdkUser", "ClSdkPassword")
    Else
        Call oVenice.Logon("13.10_", "MyApplication", lngNld, true, "SDK", "ClSdkUser", "Software engineer")
    End If

    ' Create Dossier Context, using the default filing cabinet 'Data' and the dossier 'Exact C-Logic'
    Set oDossier = oVenice.CreateDossierContext("", "Exact C-Logic")

    ' Create Year Context
    Set oYear = oDossier.CreateYearContext(2024)

    '----------------------------------------------------------------------------------------------------
    ' This example creates a financial document with ticking. It searches for all cash register sales
    ' documents (sales to customer 1) of the day and ticks them. It is assumed this routine is
    ' run at the end of each day.
    ' While possible, this example does not demonstrate adding analytical details. See the example for
    ' Sales or Purchase documents for details on how to add analytical details to each entry detail.
    '----------------------------------------------------------------------------------------------------

    ' Create context for financial documents
    Set oFinan = oYear.CreateFinan(true)

    ' Create context for entries
    Set oEntry = oYear.CreateEntry(false)

    ' Search for the most recent financial document in the book 'CASH', and remember document number and total amount because
    ' these will be needed to create a new following document.
    If oFinan.SeekByBook(smLessOrEqual, "CASH", 999999) Then
        LastDocNum = oFinan.pDocNum
        LastTotalDocC = oFinan.pTotalDocC
    Else
        LastDocNum = 0
        LastTotalDocC = 0.00
    End If

    ' Prepare the creation of a new Financial document.
    Call oFinan.PrepareDocument(paInsert)
    ' Initialize with default values.
    Call oFinan.Init()

    ' In order to obtain a valid financial document header, the following properties must be assigned a value:
    ' Book, Book date, Document date, Document number, Begin balance document currency, Amount document currency
    ' This does not imply however that these properties need to be set in code, they can also be assigned via the standard values.
    ' Note: While those are the only properties that are required to be filled in, other properties may require a value for the document to pass the internal validation checks. 
    '       These are the same validation checks that are applied when manually entering a document in Venice.
    oFinan.pBook = "CASH"
    oFinan.pDocNum = LastDocNum+1	' Cannot be 0 for financial documents
    oFinan.pBookDate = Date()
    oFinan.pDocDate = Date()
    oFinan.pRemark = "Daily cash register sales - " & Date()
    oFinan.pStartDocC = LastTotalDocC
    oFinan.pTotalDocC = 0.0 ' Will be updated each time we add a detail
                            ' Note that once the document is written, the pTotalDocC amount will include the pStartDocC.
                            ' While creating the document however, it should only reflect the total of the inserted entry 
                            ' lines in the document.

    ' Add your code here for assigning additional properties of the document header.
    ' oFinan.Xxx = yyy

    ' Create detail lines by searching for entry lines indicating cash sales of today.
    Call oEntry.SeekByHistory(smGreaterOrEqual, "400000000001", Date(), btSales, "", 0, 0)
    iEntryNum = 0
    While oEntry.GetDBStatus()=0 and oEntry.pAccount="400000000001" and oEntry.pDocDate=Date() and oEntry.pBookType = btSales
        If oEntry.pOpenDetC <> 0.0 Then ' Still an open amount?
            ' Add a detail to the financial book, inversing the amount and ticking the sales entry
            Call oFinan.InsertDetail(iEntryNum, -oEntry.pAmountDocC, 0.0, 0.0, oEntry.pAccount, "", "", -oEntry.pAmountDetC, oEntry.pDetC, oEntry.pSysNum)
            iEntryNum = iEntryNum + 1

            oFinan.pTotalDocC = oFinan.pTotalDocC + oEntry.pAmountDocC    ' Add amount to total
        End If

        Call oEntry.GetNext()
    Wend

    ' Write (or cancel) the document
    Call oFinan.WriteDocument(rmErrorReport)
    ' If you do not use WriteDocument() because you do not want to save the document (maybe because of an error) you should call CancelDocument() instead.

    ' Error
    MsgBox("Finished!")
end sub
VB.NET
 
Imports ClSdk

Module Example

    Sub Main()
        Try

            Dim oVenice As Venice
            Dim oDossier As Dossier
            Dim oYear As Year
            Dim oFinan As Finan
            Dim oEntry As Entry
            Dim eAM As eAccessMode
            Dim dblLastTotalDocC As Double
            Dim lLastDocNum As Long
            Dim sEntryNum As Short

            ' Create the Venice object
            oVenice = New Venice

            ' Is option 'Access Management' installed?
            eAM = oVenice.GetAccessMode()

            ' Logon into Venice, allowing user interface
            If eAM = eAccessMode.amSecure Then
                oVenice.LogonSecure("13.10_", "MyApplication", eLanguage.lngNld, True, "ClSdkUser", "ClSdkPassword")
            Else
                oVenice.Logon("13.10_", "MyApplication", eLanguage.lngNld, True, "SDK", "ClSdkUser", "Software engineer")
            End If

            ' Create Dossier Context, use the default filing cabinet 'Data' and the dossier 'Exact C-Logic' 
            oDossier = oVenice.CreateDossierContext("", "Exact C-Logic")

            ' Create Year Context
            oYear = oDossier.CreateYearContext(2024)

            ' ----------------------------------------------------------------------------------------------------
            '  This example creates a financial document with ticking. It searches for all cash register sales  
            '  documents (sales to customer 1) of the day and ticks them. It is assumed this routine is
            '  run at the end of each day.
            '  While possible, this example does not demonstrate adding analytical details. See the example for
            '  Sales or Purchase documents for details on how to add analytical details to each entry detail.
            ' ---------------------------------------------------------------------------------------------------- 

            ' Create context for financial documents
            oFinan = oYear.CreateFinan(True)

            ' Create context for entries
            oEntry = oYear.CreateEntry(False)

            ' Search for the most recent financial document in the book 'CASH', and remember document number and total amount because
            ' these will be needed to create a new following document.
            If oFinan.SeekByBook(eSeekMode.smLessOrEqual, "CASH", 999999) Then
                lLastDocNum = oFinan.pDocNum
                dblLastTotalDocC = oFinan.pTotalDocC
            End If

            ' Prepare the creation of a new Financial document.
            oFinan.PrepareDocument(ePrepareAction.paInsert)
            ' Initialize with default values.
            oFinan.Init()

            ' In order to obtain a valid financial document header, the following properties must be assigned a value:
            ' Book, Book date, Document date, Document number, Begin balance document currency, Amount document currency
            ' This does not imply however that these properties need to be set in code, they can also be assigned via the standard values.
            ' Note: While those are the only properties that are required to be filled in, other properties may require a value for the document to pass the internal validation checks. 
            '       These are the same validation checks that are applied when manually entering a document in Venice.
            oFinan.pBook = "CASH"
            oFinan.pDocNum = lLastDocNum + 1     ' Cannot be 0 for financial documents
            oFinan.pBookDate = DateTime.Today
            oFinan.pDocDate = DateTime.Today
            oFinan.pRemark = "Daily cash register sales - " + DateTime.Today.ToShortDateString()
            oFinan.pStartDocC = dblLastTotalDocC
            oFinan.pTotalDocC = 0.0    ' Will be updated each time we add a detail
            ' Note that once the document is written, the pTotalDocC amount will include the pStartDocC.
            ' While creating the document however, it should only reflect the total of the inserted entry 
            ' lines in the document.

            ' Add your code here for assigning additional properties of the document header.
            ' oFinan.Xxx = yyy

            ' Create detail lines by searching for entry lines indicating cash sales of today.
            oEntry.SeekByHistory(eSeekMode.smGreaterOrEqual, "400000000001", DateTime.Today, eBookType.btSales, "", 0, 0)

            While oEntry.GetDBStatus() = 0 And oEntry.pAccount = "400000000001" And oEntry.pDocDate = DateTime.Today And oEntry.pBookType = eBookType.btSales
                If oEntry.pOpenDetC <> 0.0 Then ' Still an open amount?
                    ' Add a detail to the financial book, inversing the amount and ticking the sales entry
                    oFinan.InsertDetail(sEntryNum, -oEntry.pAmountDocC, 0.0, 0.0, oEntry.pAccount, "", "", -oEntry.pAmountDetC, oEntry.pDetC, oEntry.pSysNum)
                    sEntryNum += 1

                    oFinan.pTotalDocC = oFinan.pTotalDocC + oEntry.pAmountDocC    ' Add amount to total
                End If

                oEntry.GetNext()
            End While

            ' Write (or cancel) the document
            oFinan.WriteDocument(eReportMode.rmErrorReport)
            ' If you do not use WriteDocument() because you do not want to save the document (maybe because of an error) you should call CancelDocument() instead.

        Catch ex As Exception
            Console.WriteLine("Error while executing application." + vbCrLf + "Reason:" + ex.Message + vbCrLf + "Source: " + ex.Source)
        End Try
    End Sub

End Module