V10 ResourcesGuides
ResourcesGuides
Guides
Back | List of Articles

How to Create and Integrate the Execution of Purchase Documents in Accounting? (Public Sector)

Last changed in 07/12/2021

The expense budgets are particularly important for the public organizations, so it is crucial to integrate correctly the purchase documents and the execution processes in accounting.

From version 10, the budget handling is no longer necessary when creating and integrating the purchase documents, and that logic is implemented when saving the purchase documents, when decoding the previous token in the document lines, as well as in the purchase document accounting integration, with the creation, filling in and saving of the corresponding execution process.

This article intends to demonstrate the creating and integration of the initial flow purchase document and its transformation to a posterior document, using the engines, following these steps:

Step 1 - Add references:

  1. CmpBE100;
  2. CmpBS100;
  3. BasBE100;
  4. IBasBS100;
  5. CblBE100;
  6. ICblBS100;
  7. ConstantesPrimavera100.

Step 2 - Create the initial flow purchase document:

The lines must contain the token "<NOVOPROC>" in the "ProcessoCBL" property in order to create a new execution process:

//Creation of the purchase document
CmpBE100.CmpBEDocumentoCompra objDoc = new CmpBE100.CmpBEDocumentoCompra
{
    Tipodoc = "PRC",
    Serie = "2020",
    TipoEntidade = "F",
    Entidade = "F0001",
    NumDocExterno = "1"
};

//Filling in the data related to the document header
BSO.Compras.Documentos.PreencheDadosRelacionados(objDoc);

//Line creation
BSO.Compras.Documentos.AdicionaLinha(objDoc, "A0001");
objDoc.Linhas.GetEdita(objDoc.Linhas.NumItens).PrecUnit = 10;
objDoc.Linhas.GetEdita(objDoc.Linhas.NumItens).ProcessoCBL = "<NOVOPROC>"; 

//Line budget classifications, according to the budgeted plans
objDoc.Linhas.GetEdita(objDoc.Linhas.NumItens).ClassEconCBL = "01020210";
objDoc.Linhas.GetEdita(objDoc.Linhas.NumItens).OrganicaCBL = "010403";
objDoc.Linhas.GetEdita(objDoc.Linhas.NumItens).FonteCBL = "000";
objDoc.Linhas.GetEdita(objDoc.Linhas.NumItens).ActividadeCBL = "000";
objDoc.Linhas.GetEdita(objDoc.Linhas.NumItens).ProgMedidaCBL = "000000";
objDoc.Linhas.GetEdita(objDoc.Linhas.NumItens).ContaCBL = "621311";

//Saving the purchase document – includes the token decoding 
BSO.Compras.Documentos.Actualiza(objDoc);

Step 3 - Integrate in accounting and create the corresponding execution process:

try
{
    BSO.Base.LigacaoCBL.IntegraDocumentoLogCBL(ConstantesPrimavera100.Modulos.Compras, objDoc.Tipodoc, objDoc.Serie, objDoc.NumDoc, objDoc.Filial);
}
catch(Exception exIntCbl)
{
    CblBE100.CblBECnfDocExercicioLigCBL objConfigDoc = BSO.Contabilidade.ConfiguracaoDocCBL.EditaExercicio("C", objDoc.Tipodoc, objDoc.DataDoc.Year);

    //In case of a document with a budgetary connection (to create the execution process), but with no accounts to decode, the integration in accounting will return an empty document error.
    //In these cases, the exception must be ignored because it is supposed to not integrate - creating the process.
    if(objConfigDoc.PlanosDeContas.NumItens>0)
    {
        throw exIntCbl;
    }
}

Step 4 - Create the following document by transformation:

//Creation of the following purchase document
CmpBE100.CmpBEDocumentoCompra objDocT = new CmpBE100.CmpBEDocumentoCompra
{
    Tipodoc = "COM",
    Serie = "2020",
    TipoEntidade = "F",
    Entidade = "F0001",
    NumDocExterno = "1"
};

//Filling in the data related to the document header
BSO.Compras.Documentos.PreencheDadosRelacionados(objDocT);

//Adding a new line, by transformation
BSO.Compras.Documentos.AdicionaLinhaTransformada(objDocT, objDoc.Tipodoc, objDoc.NumDoc, 1);

//Saving the purchase document
BSO.Compras.Documentos.Actualiza(objDocT);

//Accounting integration
BSO.Base.LigacaoCBL.IntegraDocumentoLogCBL(ConstantesPrimavera100.Modulos.Compras, objDocT.Tipodoc, objDocT.Serie, objDocT.NumDoc, objDocT.Filial);
Bookmark or share this article
Esta página foi útil?
Obrigado pelo seu voto.
Related Articles
Getting Started How to create an integration project with Visual Studio? How to create an Interface Extensibility Project (PEX) with Visual Studio? How to create an API (Engine) extensibility project with Visual Studio? How to create user tabs with Visual Studio?