Example: How to add a purchase document
 
These examples demonstrate how to add a purchase 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) purchase document.
 
See Also
How to add a sales document
How to add a financial 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>

#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;
        IPurchPtr   pPurch;
        ISupplPtr   pSuppl;
        eAccessMode eAM;

        // 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 purchase invoice document with analytical information. Adding Intrastat 
        //  details is also listed but commented out.
        // ----------------------------------------------------------------------------------------------------

        // Create context for purchase documents
        pPurch = pYear->CreatePurch (true);

        // Create context for suppliers
        pSuppl = pDossier->CreateSuppl (false);

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

        // In order to obtain a valid purchase document header, the following properties must be assigned a value:
        // Supplier number, Document type (invoice by default), Book, Book date, Document date, Total amount and Currency, at least one of the VAT bases and at least one of the VAT amounts.
        // This does not imply however that these properties need to be set in code, they can also be assigned via the standard values.
        // Note: A document number is not required. If it is set to 0, a new successive number for the given book will be assigned automatically.
        // 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.
        pPurch->pSupNum = 376;
        pPurch->pSupSubNum = 0;
        pPurch->pDocType = prcInvoice;           // or prcCreditnote, prcTransfer
        pPurch->pBook = "FAC";
        pPurch->pDocNum = 0;                     // 0 = Automatically determine the document number
        pPurch->pBookDate = COleDateTime (2024, 8, 23, 0, 0, 0).m_dt;
        pPurch->pDocDate = COleDateTime (2024, 8, 14, 0, 0, 0).m_dt;
        pPurch->pExpDate = COleDateTime (2024, 9, 14, 0, 0, 0).m_dt;
        pPurch->pTotalDocC = -4598.00;           // Negative for purchase invoices and transfers. Positive for creditnotes.
        pPurch->pCurrency = "EUR";
        pPurch->pRemark = "Insurance 01/09/2024 - 31/08/2025";

        // Assign (at least) one of the VAT bases: this value is negative for purchase invoices and transfers, positive for creditnotes.
        // Note: pPurch->pBaseNormalDocC cannot be set directly, it is calculated when calling WriteDocument(). You need to set one of it's component values:
        pPurch->pNormalDetail1DocC = 0.00;       // at 0% VAT
        pPurch->pNormalDetail2DocC = 0.00;       // at 6% VAT
        pPurch->pNormalDetail3DocC = 0.00;       // at 12% VAT
        pPurch->pNormalDetail4DocC = -3800.00;   // at 21% VAT
        pPurch->pNormalDetail5DocC = 0.00;       // currently unused in Belgium
        pPurch->pNormalDetail6DocC = 0.00;       // currently unused in Belgium
        pPurch->pBaseCoPartRealDocC = 0.00;
        pPurch->pBaseCoPartOtherDocC = 0.00;
        pPurch->pBaseIcGoodsDocC = 0.00;
        pPurch->pBaseIcAssmDistDocC = 0.00;
        pPurch->pBaseIcServicesDocC = 0.00;
        pPurch->pBaseImportDisplDocC = 0.00;
        pPurch->pBaseImportOtherDocC = 0.00;
        pPurch->pBaseNonDeductVatDocC = 0.00;
        pPurch->pBaseForeignVatDocC = 0.00;
        pPurch->pBaseFinDiscountDocC = 0.00;
        pPurch->pBaseNotSubmitDocC = 0.00;

        // Assign (at least) one of the VAT amounts: this value is negative for purchase invoices and transfers, positive for creditnotes.
        pPurch->pVatDedInvNormDocC = -798.00;
        pPurch->pVatDueInvCoPartDocC = 0.00;
        pPurch->pVatDueInvIcDocC = 0.00;
        pPurch->pVatDueInvDispDocC = 0.00;
        pPurch->pVatDueCreNormDocC = 0.00;
        pPurch->pVatDedCreNormDocC = 0.00;

        // Manually entering a document in Venice provides a number of automatic assignments. These do not get applied when creating a document via the SDK.
        // The following code performs those assignments:
        if (pSuppl->SeekBySupNum (smEqual, pPurch->pSupNum, pPurch->pSupSubNum))
        {
            pPurch->pClass = pSuppl->pClass;
            pPurch->pStatCode = pSuppl->pStat;
            pPurch->pVatCode = pSuppl->pStandardVat;
            pPurch->pFinDiscount = pSuppl->pFinDiscount;
        }

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

        // Create detail lines and analytical information for each detail line.
        pPurch->InsertDetail (0, 2500.00, 0.00, 0.00, "6105", "Fire Insurance, Policy Nr. WN0036241.647", "");
            // Analytical details for centre (only when desired and when the option 'Analytical' is installed) 
            pPurch->InsertAnaDetail (0, 0, aetCent, 2500.00 * 60/100, 0.00, 60, 0.00, "Assembly", "Insurance", "", "");
            pPurch->InsertAnaDetail (0, 1, aetCent, 2500.00 * 20/100, 0.00, 20, 0.00, "Office", "Insurance", "", "");
            pPurch->InsertAnaDetail (0, 2, aetCent, 2500.00 * 20/100, 0.00, 20, 0.00, "Storage", "Insurance", "", "");
            // Analytical details for unit
            pPurch->InsertAnaDetail (0, 0, aetUnit, 2500.00 * 15/100, 0.00, 15, 0.00, "Admin", "Insurance", "", "");
            pPurch->InsertAnaDetail (0, 1, aetUnit, 2500.00 * 85/100, 0.00, 85, 0.00, "Production", "Insurance", "", "");

        pPurch->InsertDetail(1, 1300.00, 0.00, 0.00, "6105", "Casualty Insurance, Policy Nr. WN0036241.409", "");
            // Analytical details for centre
            pPurch->InsertAnaDetail (1, 0, aetCent, 1300.00 * 50/100, 0.00, 50, 0.00, "Assembly", "Insurance", "", "");
            pPurch->InsertAnaDetail (1, 1, aetCent, 1300.00 * 10/100, 0.00, 10, 0.00, "Office", "Insurance", "", "");
            pPurch->InsertAnaDetail (1, 2, aetCent, 1300.00 * 25/100, 0.00, 25, 0.00, "Storage", "Insurance", "", "");
            pPurch->InsertAnaDetail (1, 3, aetCent, 1300.00 * 15/100, 0.00, 15, 0.00, "Parking", "Insurance", "", "");
            // Analytical details for unit
            pPurch->InsertAnaDetail (1, 0, aetUnit, 1300.00 * 10/100, 0.00, 10, 0.00, "Admin", "Insurance", "", "");
            pPurch->InsertAnaDetail (1, 1, aetUnit, 1300.00 * 90/100, 0.00, 90, 0.00, "Production", "Insurance", "", "");

        // If you have the option Intrastat, you can also add Intrastat details. In order to do this, there must be an IC relation between the company and the supplier 
        // (= They must have enterprise numbers from differing countries in the European Community).
        //pPurch->InsertItrDetail (0, 2500.00, 0.00, 0.00, spArrival, ntrNormal_Bussiness, reFlanders, trRoad, dcFCA, "85203219", "FR", "");
        //pPurch->InsertItrDetail (1, 1300.00, 0.00, 0.00, spArrival, ntrNormal_Bussiness, reFlanders, trRoad, dcFCA, "85203219", "FR", "");

        // Enable payment information (if the option 'Payments' is installed)
        pPurch->pAutoPay = true;
        pPurch->SetPayInfo (4598.00, 0.00, ccNone, true, "", "Insurance 01/09/2024 - 31/08/2025", "", "", "", "", "");

        // Write (or cancel) the document
        pPurch->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;

                // 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 purchase invoice document with analytical information. Adding Intrastat 
                //  details is also listed but commented out.
                // ----------------------------------------------------------------------------------------------------

                // Create context for purchase documents
                Purch oPurch = oYear.CreatePurch (true);

                // Create context for suppliers
                Suppl oSuppl = oDossier.CreateSuppl (false);

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

                // In order to obtain a valid purchase document header, the following properties must be assigned a value:
                // Supplier number, Document type (invoice by default), Book, Book date, Document date, Total amount and Currency, at least one of the VAT bases and at least one of the VAT amounts.
                // This does not imply however that these properties need to be set in code, they can also be assigned via the standard values.
                // Note: A document number is not required. If it is set to 0, a new successive number for the given book will be assigned automatically.
                // 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.
                oPurch.pSupNum = 376;
                oPurch.pSupSubNum = 0;
                oPurch.pDocType = ePurchaseDocType.prcInvoice;           // or prcCreditnote, prcTransfer
                oPurch.pBook = "FAC";
                oPurch.pDocNum = 0;                     // 0 = Automatically determine the document number
                oPurch.pBookDate = new DateTime (2024, 8, 23);
                oPurch.pDocDate = new DateTime (2024, 8, 14);
                oPurch.pExpDate = new DateTime (2024, 9, 14);
                oPurch.pTotalDocC = -4598.00;           // Negative for purchase invoices and transfers. Positive for creditnotes.
                oPurch.pCurrency = "EUR";
                oPurch.pRemark = "Insurance 01/09/2024 - 31/08/2025";

                // Assign (at least) one of the VAT bases: this value is negative for purchase invoices and transfers, positive for creditnotes.
                // Note: oPurch.pBaseNormalDocC cannot be set directly, it is calculated when calling WriteDocument(). You need to set one of it's component values:
                oPurch.pNormalDetail1DocC = 0.00;       // at 0% VAT
                oPurch.pNormalDetail2DocC = 0.00;       // at 6% VAT
                oPurch.pNormalDetail3DocC = 0.00;       // at 12% VAT
                oPurch.pNormalDetail4DocC = -3800.00;   // at 21% VAT
                oPurch.pNormalDetail5DocC = 0.00;       // currently unused in Belgium
                oPurch.pNormalDetail6DocC = 0.00;       // currently unused in Belgium
                oPurch.pBaseCoPartRealDocC = 0.00;
                oPurch.pBaseCoPartOtherDocC = 0.00;
                oPurch.pBaseIcGoodsDocC = 0.00;
                oPurch.pBaseIcAssmDistDocC = 0.00;
                oPurch.pBaseIcServicesDocC = 0.00;
                oPurch.pBaseImportDisplDocC = 0.00;
                oPurch.pBaseImportOtherDocC = 0.00;
                oPurch.pBaseNonDeductVatDocC = 0.00;
                oPurch.pBaseForeignVatDocC = 0.00;
                oPurch.pBaseFinDiscountDocC = 0.00;
                oPurch.pBaseNotSubmitDocC = 0.00;

                // Assign (at least) one of the VAT amounts: this value is negative for purchase invoices and transfers, positive for creditnotes.
                oPurch.pVatDedInvNormDocC = -798.00;
                oPurch.pVatDueInvCoPartDocC = 0.00;
                oPurch.pVatDueInvIcDocC = 0.00;
                oPurch.pVatDueInvDispDocC = 0.00;
                oPurch.pVatDueCreNormDocC = 0.00;
                oPurch.pVatDedCreNormDocC = 0.00;

                // Manually entering a document in Venice provides a number of automatic assignments. These do not get applied when creating a document via the SDK.
                // The following code performs those assignments:
                if (oSuppl.SeekBySupNum (eSeekMode.smEqual, (int)oPurch.pSupNum, (int)oPurch.pSupSubNum))
                {
                    oPurch.pClass = oSuppl.pClass;
                    oPurch.pStatCode = oSuppl.pStat;
                    oPurch.pVatCode = oSuppl.pStandardVat;
                    oPurch.pFinDiscount = oSuppl.pFinDiscount;
                }

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

                // Create detail lines and analytical information for each detail line.
                oPurch.InsertDetail (0, 2500.00, 0.00, 0.00, "6105", "Fire Insurance, Policy Nr. WN0036241.647", "");
                // Analytical details for centre (only when desired and when the option 'Analytical' is installed) 
                oPurch.InsertAnaDetail (0, 0, eAnaEntType.aetCent, 2500.00 * 60/100, 0.00, 60, 0.00, "Assembly", "Insurance", "", "");
                oPurch.InsertAnaDetail (0, 1, eAnaEntType.aetCent, 2500.00 * 20/100, 0.00, 20, 0.00, "Office", "Insurance", "", "");
                oPurch.InsertAnaDetail (0, 2, eAnaEntType.aetCent, 2500.00 * 20/100, 0.00, 20, 0.00, "Storage", "Insurance", "", "");
                // Analytical details for unit
                oPurch.InsertAnaDetail (0, 0, eAnaEntType.aetUnit, 2500.00 * 15/100, 0.00, 15, 0.00, "Admin", "Insurance", "", "");
                oPurch.InsertAnaDetail (0, 1, eAnaEntType.aetUnit, 2500.00 * 85/100, 0.00, 85, 0.00, "Production", "Insurance", "", "");

                oPurch.InsertDetail(1, 1300.00, 0.00, 0.00, "6105", "Casualty Insurance, Policy Nr. WN0036241.409", "");
                // Analytical details for centre
                oPurch.InsertAnaDetail (1, 0, eAnaEntType.aetCent, 1300.00 * 50/100, 0.00, 50, 0.00, "Assembly", "Insurance", "", "");
                oPurch.InsertAnaDetail (1, 1, eAnaEntType.aetCent, 1300.00 * 10/100, 0.00, 10, 0.00, "Office", "Insurance", "", "");
                oPurch.InsertAnaDetail (1, 2, eAnaEntType.aetCent, 1300.00 * 25/100, 0.00, 25, 0.00, "Storage", "Insurance", "", "");
                oPurch.InsertAnaDetail (1, 3, eAnaEntType.aetCent, 1300.00 * 15/100, 0.00, 15, 0.00, "Parking", "Insurance", "", "");
                // Analytical details for unit
                oPurch.InsertAnaDetail (1, 0, eAnaEntType.aetUnit, 1300.00 * 10/100, 0.00, 10, 0.00, "Admin", "Insurance", "", "");
                oPurch.InsertAnaDetail (1, 1, eAnaEntType.aetUnit, 1300.00 * 90/100, 0.00, 90, 0.00, "Production", "Insurance", "", "");

                // If you have the option Intrastat, you can also add Intrastat details. In order to do this, there must be an IC relation between the company and the supplier 
                // (= They must have enterprise numbers from differing countries in the European Community).
                //oPurch.InsertItrDetail (0, 2500.00, 0.00, 0.00, eStatProc.spArrival, eNatTrans.ntrNormal_Bussiness, eRegion.reFlanders, eTransport.trRoad, eDelivCond.dcFCA, "85203219", "FR", "");
                //oPurch.InsertItrDetail (1, 1300.00, 0.00, 0.00, eStatProc.spArrival, eNatTrans.ntrNormal_Bussiness, eRegion.reFlanders, eTransport.trRoad, eDelivCond.dcFCA, "85203219", "FR", "");

                // Enable payment information (if the option 'Payments' is installed)
                oPurch.pAutoPay = true;
                oPurch.SetPayInfo (4598.00, 0.00, eCircCheque.ccNone, true, "", "Insurance 01/09/2024 - 31/08/2025", "", "", "", "", "");

                // Write (or cancel) the document
                oPurch.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 prcMin = 0
Const prcInvoice = 0
Const prcCreditnote = 1
Const prcTransfer = 2
Const prcMax = 3

Const aetMin = 0
Const aetCent = 0
Const aetUnit = 1
Const aetMax = 2

Const ccMin = 0
Const ccNone = 0
Const ccConstituent = 1
Const ccBeneficiary = 2
Const ccMax = 3

Const spArrival = 19
Const spDispatch = 29

Const ntrMin = 1
Const ntrNormal = 1
Const ntrReturn = 2
Const ntrFree = 3
Const ntrPreProc = 4
Const ntrPostProc = 5
Const ntrRepair = 6
Const ntrDefence = 7
Const ntrBuilding = 8
Const ntrOther = 9
Const ntrNormal_Bussiness = 11
Const ntrNormal_Consumer = 12
Const ntrReturn_Goods = 21
Const ntrReturn_Replace = 22
Const ntrReturn_NonReturn = 23
Const ntrFree_Warehouse = 31
Const ntrFree_Trial = 32
Const ntrFree_Leasing = 33
Const ntrFree_Free = 34
Const ntrPreProc_Return = 41
Const ntrPreProc_NoReturn = 42
Const ntrPostProc_Return = 51
Const ntrPostProc_NoReturn = 52
Const ntrRepair_Repair = 60
Const ntrClearance_Release = 71
Const ntrClearance_OtherMember = 72
Const ntrBuilding_Building = 80
Const ntrOther_Other24Month = 91
Const ntrOther_Other = 99
Const ntrMax = 100

Const reMin = 1
Const reFlanders = 1
Const reWallonia = 2
Const reBrussels = 3
Const reMax = 4

Const trMin = 1
Const trSea = 1
Const trTrack = 2
Const trRoad = 3
Const trAir = 4
Const trPost = 5
Const trUnused = 6
Const trFixed = 7
Const trRiver = 8
Const trOwn = 9
Const trMax = 10

Const dcMin = 0
Const dcEXW = 0
Const dcFCA = 1
Const dcFAS = 2
Const dcFOB = 3
Const dcCFR = 4
Const dcCIF = 5
Const dcCPT = 6
Const dcCIP = 7
Const dcDAF = 8
Const dcDES = 9
Const dcDEQ = 10
Const dcDDU = 11
Const dcDDP = 12
Const dcXXX = 13
Const dcMax = 14

' Call main
Main

sub Main
    Dim oVenice
    Dim oDossier
    Dim oYear
    Dim oPurch
    Dim oSuppl

    ' 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 oPurch = CreateObject("ClSdk.Purch")
        Set oSuppl = CreateObject("ClSdk.Suppl")
    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 purchase invoice document with analytical information. Adding Intrastat 
    ' details is also listed but commented out.
    '----------------------------------------------------------------------------------------------------

    ' Create context for purchase documents
    Set oPurch = oYear.CreatePurch(true)

    ' Create context for suppliers
    Set oSuppl = oDossier.CreateSuppl(false)

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

    ' In order to obtain a valid purchase document header, the following properties must be assigned a value:
    ' Supplier number, Document type (invoice by default), Book, Book date, Document date, Total amount and Currency, at least one of the VAT bases and at least one of the VAT amounts.
    ' This does not imply however that these properties need to be set in code, they can also be assigned via the standard values.
    ' Note: A document number is not required. If it is set to 0, a new successive number for the given book will be assigned automatically.
    ' 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.
    oPurch.pSupNum = 376
    oPurch.pSupSubNum = 0
    oPurch.pDocType = prcInvoice ' or prcCreditnote, prcTransfer
    oPurch.pBook = "FAC"
    oPurch.pDocNum = 0 ' 0 = Automatically determine the document number
    oPurch.pBookDate = #8/23/2024# 
    oPurch.pDocDate = #8/14/2024# 
    oPurch.pExpDate = #9/14/2024# 
    oPurch.pTotalDocC = -4598.00 ' Negative for purchase invoices and transfers. Positive for creditnotes.
    oPurch.pCurrency = "EUR"
    oPurch.pRemark = "Insurance 01/09/2024 - 31/08/2025"

    ' Assign (at least) one of the VAT bases: this value is negative for purchase invoices and transfers, positive for creditnotes.
    ' Note: oPurch.pBaseNormalDocC cannot be set directly, it is calculated when calling WriteDocument(). You need to set one of it's component values:
    oPurch.pNormalDetail1DocC = 0        ' at 0% VAT
    oPurch.pNormalDetail2DocC = 0        ' at 6% VAT
    oPurch.pNormalDetail3DocC = 0        ' at 12% VAT
    oPurch.pNormalDetail4DocC = -3800.00 ' at 21% VAT
    oPurch.pNormalDetail5DocC = 0        ' currently unused in Belgium
    oPurch.pNormalDetail6DocC = 0        ' currently unused in Belgium
    oPurch.pBaseCoPartRealDocC = 0
    oPurch.pBaseCoPartOtherDocC = 0
    oPurch.pBaseIcGoodsDocC = 0
    oPurch.pBaseIcAssmDistDocC = 0
    oPurch.pBaseIcServicesDocC = 0
    oPurch.pBaseImportDisplDocC = 0
    oPurch.pBaseImportOtherDocC = 0
    oPurch.pBaseNonDeductVatDocC = 0
    oPurch.pBaseForeignVatDocC = 0
    oPurch.pBaseFinDiscountDocC = 0
    oPurch.pBaseNotSubmitDocC = 0

    ' Assign (at least) one of the VAT amounts: this value is negative for purchase invoices and transfers, positive for creditnotes.
    oPurch.pVatDedInvNormDocC = -798.00
    oPurch.pVatDueInvCoPartDocC = 0
    oPurch.pVatDueInvIcDocC = 0
    oPurch.pVatDueInvDispDocC = 0
    oPurch.pVatDueCreNormDocC = 0
    oPurch.pVatDedCreNormDocC = 0

    ' Manually entering a document in Venice provides a number of automatic assignments. These do not get applied when creating a document via the SDK.
    ' The following code performs those assignments:
    If oSuppl.SeekBySupNum(smEqual, oPurch.pSupNum, oPurch.pSupSubNum) Then
        oPurch.pClass = oSuppl.pClass
        oPurch.pStatCode = oSuppl.pStat
        oPurch.pVatCode = oSuppl.pStandardVat
        oPurch.pFinDiscount = oSuppl.pFinDiscount
    End If

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

    ' Create detail lines and analytical information for each detail line.
    Call oPurch.InsertDetail(0, 2500.00, 0.00, 0.00, "6105", "Fire Insurance, Policy Nr. WN0036241.647", "")
        ' Analytical details for centre (only when desired and when the option 'Analytical' is installed) 
        Call oPurch.InsertAnaDetail(0, 0, aetCent, 2500.00 * 60/100, 0.0, 60, 0.0, "Assembly", "Insurance", "", "")
        Call oPurch.InsertAnaDetail(0, 1, aetCent, 2500.00 * 20/100, 0.0, 20, 0.0, "Office", "Insurance", "", "")
        Call oPurch.InsertAnaDetail(0, 2, aetCent, 2500.00 * 20/100, 0.0, 20, 0.0, "Storage", "Insurance", "", "")
        ' Analytical details for unit
        Call oPurch.InsertAnaDetail(0, 0, aetUnit, 2500.00 * 15/100, 0.0, 15, 0.0, "Admin", "Insurance", "", "")
        Call oPurch.InsertAnaDetail(0, 1, aetUnit, 2500.00 * 85/100, 0.0, 85, 0.0, "Production", "Insurance", "", "")

    Call oPurch.InsertDetail(1, 1300.00, 0.00, 0.00, "6105", "Casualty Insurance, Policy Nr. WN0036241.409", "")
        ' Analytical details for centre
        Call oPurch.InsertAnaDetail(1, 0, aetCent, 1300.00 * 50/100, 0.0, 50, 0.0, "Assembly", "Insurance", "", "")
        Call oPurch.InsertAnaDetail(1, 1, aetCent, 1300.00 * 10/100, 0.0, 10, 0.0, "Office", "Insurance", "", "")
        Call oPurch.InsertAnaDetail(1, 2, aetCent, 1300.00 * 25/100, 0.0, 25, 0.0, "Storage", "Insurance", "", "")
        Call oPurch.InsertAnaDetail(1, 3, aetCent, 1300.00 * 15/100, 0.0, 15, 0.0, "Parking", "Insurance", "", "")
        ' Analytical details for unit
        Call oPurch.InsertAnaDetail(1, 0, aetUnit, 1300.00 * 10/100, 0.0, 10, 0.0, "Admin", "Insurance", "", "")
        Call oPurch.InsertAnaDetail(1, 1, aetUnit, 1300.00 * 90/100, 0.0, 90, 0.0, "Production", "Insurance", "", "")

    ' If you have the option Intrastat, you can also add Intrastat details. In order to do this, there must be an IC relation between the company and the supplier 
    ' (= They must have enterprise numbers from differing countries in the European Community).
    'Call oPurch.InsertItrDetail(0, 2500.00, 0.0, 0.0, spArrival, ntrNormal_Bussiness, reFlanders, trRoad, dcFCA, "85203219", "FR", "")
    'Call oPurch.InsertItrDetail(1, 1300.00, 0.0, 0.0, spArrival, ntrNormal_Bussiness, reFlanders, trRoad, dcFCA, "85203219", "FR", "")

    ' Enable payment information (if the option 'Payments' is installed)
    oPurch.pAutoPay = true
    Call oPurch.SetPayInfo(4598.00, 0.0, ccNone, true, "", "Insurance 01/09/2024 - 31/08/2025", "", "", "", "", "")

    ' Write (or cancel) the document
    Call oPurch.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 oPurch As Purch
            Dim oSuppl As Suppl
            Dim eAM As eAccessMode

            ' 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 purchase invoice document with analytical information. Adding Intrastat 
            '  details is also listed but commented out.
            ' ----------------------------------------------------------------------------------------------------

            ' Create context for purchase documents
            oPurch = oYear.CreatePurch(True)

            ' Create context for suppliers
            oSuppl = oDossier.CreateSuppl(False)

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

            ' In order to obtain a valid purchase document header, the following properties must be assigned a value:
            ' Supplier number, Document type (invoice by default), Book, Book date, Document date, Total amount and Currency, at least one of the VAT bases and at least one of the VAT amounts.
            ' This does not imply however that these properties need to be set in code, they can also be assigned via the standard values.
            ' Note: A document number is not required. If it is set to 0, a new successive number for the given book will be assigned automatically.
            ' 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.
            oPurch.pSupNum = 376
            oPurch.pSupSubNum = 0
            oPurch.pDocType = ePurchaseDocType.prcInvoice           ' or prcCreditnote, prcTransfer
            oPurch.pBook = "FAC"
            oPurch.pDocNum = 0                     ' 0 = Automatically determine the document number
            oPurch.pBookDate = New DateTime(2024, 8, 23)
            oPurch.pDocDate = New DateTime(2024, 8, 14)
            oPurch.pExpDate = New DateTime(2024, 9, 14)
            oPurch.pTotalDocC = -4598.0            ' Negative for purchase invoices and transfers. Positive for creditnotes.
            oPurch.pCurrency = "EUR"
            oPurch.pRemark = "Insurance 01/09/2024 - 31/08/2025"

            ' Assign (at least) one of the VAT bases: this value is negative for purchase invoices and transfers, positive for creditnotes.
            ' Note: oPurch.pBaseNormalDocC cannot be set directly, it is calculated when calling WriteDocument(). You need to set one of it's component values:
            oPurch.pNormalDetail1DocC = 0.0         ' at 0% VAT
            oPurch.pNormalDetail2DocC = 0.0         ' at 6% VAT
            oPurch.pNormalDetail3DocC = 0.0         ' at 12% VAT
            oPurch.pNormalDetail4DocC = -3800.0     ' at 21% VAT
            oPurch.pNormalDetail5DocC = 0.0         ' currently unused in Belgium
            oPurch.pNormalDetail6DocC = 0.0         ' currently unused in Belgium
            oPurch.pBaseCoPartRealDocC = 0.0
            oPurch.pBaseCoPartOtherDocC = 0.0
            oPurch.pBaseIcGoodsDocC = 0.0
            oPurch.pBaseIcAssmDistDocC = 0.0
            oPurch.pBaseIcServicesDocC = 0.0
            oPurch.pBaseImportDisplDocC = 0.0
            oPurch.pBaseImportOtherDocC = 0.0
            oPurch.pBaseNonDeductVatDocC = 0.0
            oPurch.pBaseForeignVatDocC = 0.0
            oPurch.pBaseFinDiscountDocC = 0.0
            oPurch.pBaseNotSubmitDocC = 0.0

            ' Assign (at least) one of the VAT amounts: this value is negative for purchase invoices and transfers, positive for creditnotes.
            oPurch.pVatDedInvNormDocC = -798.0
            oPurch.pVatDueInvCoPartDocC = 0.0
            oPurch.pVatDueInvIcDocC = 0.0
            oPurch.pVatDueInvDispDocC = 0.0
            oPurch.pVatDueCreNormDocC = 0.0
            oPurch.pVatDedCreNormDocC = 0.0

            ' Manually entering a document in Venice provides a number of automatic assignments. These do not get applied when creating a document via the SDK.
            ' The following code performs those assignments:
            If oSuppl.SeekBySupNum(eSeekMode.smEqual, oPurch.pSupNum, oPurch.pSupSubNum) Then
                oPurch.pClass = oSuppl.pClass
                oPurch.pStatCode = oSuppl.pStat
                oPurch.pVatCode = oSuppl.pStandardVat
                oPurch.pFinDiscount = oSuppl.pFinDiscount
            End If

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

            ' Create detail lines and analytical information for each detail line.
            oPurch.InsertDetail(0, 2500.0, 0.0, 0.0, "6105", "Fire Insurance, Policy Nr. WN0036241.647", "")
            ' Analytical details for centre (only when desired and when the option 'Analytical' is installed) 
            oPurch.InsertAnaDetail(0, 0, eAnaEntType.aetCent, 2500.0 * 60 / 100, 0.0, 60, 0.0, "Assembly", "Insurance", "", "")
            oPurch.InsertAnaDetail(0, 1, eAnaEntType.aetCent, 2500.0 * 20 / 100, 0.0, 20, 0.0, "Office", "Insurance", "", "")
            oPurch.InsertAnaDetail(0, 2, eAnaEntType.aetCent, 2500.0 * 20 / 100, 0.0, 20, 0.0, "Storage", "Insurance", "", "")
            ' Analytical details for unit
            oPurch.InsertAnaDetail(0, 0, eAnaEntType.aetUnit, 2500.0 * 15 / 100, 0.0, 15, 0.0, "Admin", "Insurance", "", "")
            oPurch.InsertAnaDetail(0, 1, eAnaEntType.aetUnit, 2500.0 * 85 / 100, 0.0, 85, 0.0, "Production", "Insurance", "", "")

            oPurch.InsertDetail(1, 1300.0, 0.0, 0.0, "6105", "Casualty Insurance, Policy Nr. WN0036241.409", "")
            ' Analytical details for centre
            oPurch.InsertAnaDetail(1, 0, eAnaEntType.aetCent, 1300.0 * 50 / 100, 0.0, 50, 0.0, "Assembly", "Insurance", "", "")
            oPurch.InsertAnaDetail(1, 1, eAnaEntType.aetCent, 1300.0 * 10 / 100, 0.0, 10, 0.0, "Office", "Insurance", "", "")
            oPurch.InsertAnaDetail(1, 2, eAnaEntType.aetCent, 1300.0 * 25 / 100, 0.0, 25, 0.0, "Storage", "Insurance", "", "")
            oPurch.InsertAnaDetail(1, 3, eAnaEntType.aetCent, 1300.0 * 15 / 100, 0.0, 15, 0.0, "Parking", "Insurance", "", "")
            ' Analytical details for unit
            oPurch.InsertAnaDetail(1, 0, eAnaEntType.aetUnit, 1300.0 * 10 / 100, 0.0, 10, 0.0, "Admin", "Insurance", "", "")
            oPurch.InsertAnaDetail(1, 1, eAnaEntType.aetUnit, 1300.0 * 90 / 100, 0.0, 90, 0.0, "Production", "Insurance", "", "")

            ' If you have the option Intrastat, you can also add Intrastat details. In order to do this, there must be an IC relation between the company and the supplier 
            ' (= They must have enterprise numbers from differing countries in the European Community).
            'oPurch.InsertItrDetail(0, 2500.0, 0.0, 0.0, eStatProc.spArrival, eNatTrans.ntrNormal_Bussiness, eRegion.reFlanders, eTransport.trRoad, eDelivCond.dcFCA, "85203219", "FR", "")
            'oPurch.InsertItrDetail(1, 1300.0, 0.0, 0.0, eStatProc.spArrival, eNatTrans.ntrNormal_Bussiness, eRegion.reFlanders, eTransport.trRoad, eDelivCond.dcFCA, "85203219", "FR", "")

            ' Enable payment information (if the option 'Payments' is installed)
            oPurch.pAutoPay = True
            oPurch.SetPayInfo(4598.0, 0.0, eCircCheque.ccNone, True, "", "Insurance 01/09/2024 - 31/08/2025", "", "", "", "", "")

            ' Write (or cancel) the document
            oPurch.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