Creation of Internal Documents in V10, via VB.NET - Document is not correctly valued

1

I am creating a routine for Integrating Internal Documents into ERP. You are creating the document, but it is not appreciated. The test code I'm using:

Public Sub CriaDocumentoInterno(Public MotorERP As ErpBS100.ErpBS,Utilizador As String, DataDoc As Date, Filial As String, TipoDoc As String, Serie As String, Artigo As String, Armazem As String, Quantidade As Double, PrecUnit As Double)
    Try

        Dim strAvisos As String

        Dim DocINT As New IntBE100.IntBEDocumentoInterno

        With DocINT
            .Tipodoc = TipoDoc
            .Filial = Filial
            .Serie = Serie
            .Data = DataDoc
            .DataVencimento = DataDoc
            .Utilizador = Utilizador
        End With

        MotorERP.Internos.Documentos.PreencheDadosRelacionados(DocINT)

        Dim objlinha As New IntBE100.IntBELinhaDocumentoInterno
        With objlinha
            .Armazem = Armazem
            .Localizacao = Armazem
            .Artigo = Artigo
            .Data = DataDoc

            .DataDocStock = DataDoc
            .DescontoComercial = 0
            .Descricao = MotorERP.Base.Artigos.DaValorAtributo(objlinha.Artigo, "Descricao")
            .FactorConv = 1
            .Lote = ""
            .MovimentaStock = True
            .PrecoUnitario = PrecUnit
            .Quantidade = Quantidade
            .Unidade = MotorERP.Base.Artigos.DaValorAtributo(objlinha.Artigo, "UnidadeBase")
            .TipoLinha = 13
            .ID = Guid.NewGuid().ToString
            .TaxaIva = 13

            .CodigoIva = MotorERP.Base.Artigos.DaValorAtributo(objlinha.Artigo, "Iva")
            .TaxaIva = MotorERP.Base.Iva.DaValorAtributo(objlinha.CodigoIva, "Taxa")
            .RegimeIva = 1
            .DataEntrega = DocINT.Data
            .INV_EstadoDestino = "DISP"

        End With

        DocINT.Linhas.Insere(objlinha)
        strAvisos = ""

        MotorERP.Internos.Documentos.Actualiza(DocINT, strAvisos)

    Catch ex As Exception
        MsgBox(Err.Source + "|" + Err.Description, vbAbort, "Erro ao criar Doc.Interno")
    End Try
End Sub

The routine runs without errors, but after creating / integrating the document in ERP V10, I find that in the SQL table InlineLines columns and TotalIva and PercIvaDedutivel columns (possibly other columns) are not filled out.

What is the missing in this code for the value of each line to be calculated correctly, and therefore the total value of the internal document?

Thank you

    
asked by anonymous 30.08.2018 / 17:21

2 answers

2

Before the Actualiza method, you should invoke the CalculaValoresTotais method as follows:

MotorERP.Internos.Documentos.CalculaValoresTotais(DocINT);

The method will take into account everything that is value in the header and lines (VAT rates, discounts, VAT scheme, tax space, etc.).

With the example below I was able to create a document with all calculated totals correctly:

private void CriaDocumentoInterno()
{
    ErpBS100.ErpBS motor = new ErpBS100.ErpBS();

    try
    {
        motor.AbreEmpresaTrabalho(StdBE100.StdBETipos.EnumTipoPlataforma.tpEmpresarial, "DEMO915", "primavera", string.Empty);

        IntBE100.IntBEDocumentoInterno interno = new IntBE100.IntBEDocumentoInterno()
        {
            Tipodoc = "STD",
            Serie = "2018",
            Filial = "000",
            TipoEntidade = "C",
            Entidade = "SOFRIO",
            Data = DateTime.Today
        };

        motor.Internos.Documentos.PreencheDadosRelacionados(interno);
        motor.Internos.Documentos.AdicionaLinha(interno, "A0001", "A1", PrecoUnitario: 100, Quantidade: 2);
        motor.Internos.Documentos.Actualiza(interno);
    }
    catch (Exception ex)
    {
        MessageBox.Show($"Ocorreu um erro na criação do documento: {ex.Message}", "Erro",
            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    finally
    {
        motor?.FechaEmpresaTrabalho();
    }
}

Normally it is not necessary to "force" the CalculaValoresTotais method, because internally in the engine this is already done before writing the document to the database.

I recommend that you validate all values that are being passed primarily to the article, because something is definitely putting the totals to 0.

    
30.08.2018 / 17:39
4

Good morning, you need to fill in the following line parameter:

.ContabilizaTotais = true

In addition it is also recommended to place the following parameters:

PercIncidenciaIVA = 100,
PercIvaDedutivel = 100,
IvaRegraCalculo = 0,
TaxaProRata = 100,
QntFormula = 1,
RegraCalculoIncidencia = BasBE100.BasBETiposGcp.EnumRegimesIncidenciaIva.Normal,

Regards,

    
31.08.2018 / 12:34