Skip to Content
0
Former Member
Sep 23, 2016 at 10:04 PM

Internal error (-5002) occurred copy of invoice several deliveries

148 Views

hello experts I am developing a code routine that makes the function of copying a document invoice several more deliveries whenever I make a mistake it returns me. Error: Internal error (-5002) occurred follows the source code I'm using to make this insertion.



oCompany = DiCompany.Conectar();

try

{

oInvoices = (Documents)oCompany.GetBusinessObject(BoObjectTypes.oInvoices);

oDeliveryNotes = (Documents)oCompany.GetBusinessObject(BoObjectTypes.oDeliveryNotes);

oInvoices.SequenceCode = -2;

oInvoices.SequenceSerial = Convert.ToInt32(oinv.codTMS);

oInvoices.SequenceModel = Convert.ToString(39);

oInvoices.CardCode = Validacao_Retorno_SAP.RetornaCarCodeCPF_CNPJ(oinv.cliente_cpf_cnpj);

oInvoices.NumAtCard = oinv.Referencia;

oInvoices.DocDate = oinv.DataLancamento;

oInvoices.DocDueDate = oinv.DataVencimento;

oInvoices.UserFields.Fields.Item("U_TDS_Usuario").Value = oinv.Usuario;

oInvoices.BPL_IDAssignedToInvoice = Validacao_Retorno_SAP.RetornaBPLID(oinv.CodFilial);

oInvoices.PaymentGroupCode = Validacao_Retorno_SAP.RetornaCondicaoPagamento(oinv.CondicaoPagamento);

oInvoices.PaymentMethod = Validacao_Retorno_SAP.RetornaFormaPagamento(oinv.FormaPagamento);

for (int i = 0; i < CTes.Count; i++)

{

oDeliveryNotes.GetByKey(Validacao_Retorno_SAP.RetornaDocentryCTE(CTes[i].ChaveAcesso));

for (int j = 0; j < oDeliveryNotes.Lines.Count; j++)

{

oDeliveryNotes.Lines.SetCurrentLine(j);

oInvoices.Lines.BaseType = (int)SAPbobsCOM.BoObjectTypes.oDeliveryNotes;

oInvoices.Lines.BaseEntry = oDeliveryNotes.DocEntry;

oInvoices.Lines.BaseLine = j;

oInvoices.Lines.ItemCode = oDeliveryNotes.Lines.ItemCode;

oInvoices.Lines.ItemDescription = oDeliveryNotes.Lines.ItemDescription;

oInvoices.Lines.Quantity = oDeliveryNotes.Lines.Quantity;

oInvoices.Lines.Price = oDeliveryNotes.Lines.Price;

oInvoices.Lines.TaxCode = oDeliveryNotes.Lines.TaxCode;

oInvoices.Lines.CFOPCode = oDeliveryNotes.Lines.CFOPCode;

oInvoices.Lines.AccountCode = oDeliveryNotes.Lines.AccountCode;

oInvoices.Lines.LineTotal = oDeliveryNotes.Lines.LineTotal;

oInvoices.Lines.Usage = oDeliveryNotes.Lines.Usage;

oInvoices.Lines.CostingCode = oDeliveryNotes.Lines.CostingCode;

oInvoices.Lines.CostingCode2 = oDeliveryNotes.Lines.CostingCode2;

oInvoices.Lines.CostingCode3 = oDeliveryNotes.Lines.CostingCode3;

oInvoices.Lines.CostingCode4 = oDeliveryNotes.Lines.CostingCode4;

oInvoices.Lines.CostingCode5 = oDeliveryNotes.Lines.CostingCode5;

oInvoices.Lines.ProjectCode = oDeliveryNotes.Lines.ProjectCode;

oInvoices.Lines.WarehouseCode = oDeliveryNotes.Lines.WarehouseCode;

oInvoices.Lines.UnitPrice = oDeliveryNotes.Lines.UnitPrice;

oInvoices.Lines.Add();

}

}

int iErrorSAP = 0;

iErrorSAP = oInvoices.Add();

if (iErrorSAP != 0)

{

throw new Exception(oCompany.GetLastErrorCode() + " - " + oCompany.GetLastErrorDescription());

}

return "0";