/// <summary> /// funcion integra facturas /// </summary> /// <param name="oForm"></param> private static void IntegracionServicio(SAPbouiCOM.Form oForm) { //DTE objDTE = null; SAPbobsCOM.Documents oDoc = null; SAPbouiCOM.Matrix oMatrix = null; string Descripcion = string.Empty; string Cuenta = string.Empty; string Dim1 = string.Empty; string Dim2 = string.Empty; string Dim3 = string.Empty; string Dim4 = string.Empty; string Dim5 = string.Empty; string RutEmisor = String.Empty; string Tipo = String.Empty; string Folio = String.Empty; string FebId = String.Empty; string CardCode = String.Empty; string FchEmis = String.Empty; string FchVenc = String.Empty; string MntTotal = String.Empty; string IVA = String.Empty; string NroRef = null; string RzRef = null; SAPbobsCOM.Recordset oRecordset = null; bool blAcepComer = false; try { oMatrix = oForm.Items.Item("MatrixIM").Specific; oRecordset = Conexion_SBO.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); oRecordset.DoQuery("SELECT \"U_SentAcepC\" FROM \"@SEI_SETVALH\""); blAcepComer = (oRecordset.Fields.Item("U_SentAcepC").Value == "Y" ? true : false); for (int i = 1; i <= oMatrix.VisualRowCount; i++) { Descripcion = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_0").Cells.Item(i).Specific).Value; // oForm.Items.Item("Item_1").Specific.Value.ToString(); Cuenta = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_1").Cells.Item(i).Specific).Value; Dim1 = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_2").Cells.Item(i).Specific).Value; Dim2 = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_3").Cells.Item(i).Specific).Value; Dim3 = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_4").Cells.Item(i).Specific).Value; Dim4 = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_5").Cells.Item(i).Specific).Value; Dim5 = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_6").Cells.Item(i).Specific).Value; RutEmisor = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_7").Cells.Item(i).Specific).Value; Tipo = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_9").Cells.Item(i).Specific).Value; Folio = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_8").Cells.Item(i).Specific).Value; FebId = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_10").Cells.Item(i).Specific).Value; CardCode = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_11").Cells.Item(i).Specific).Value; FchEmis = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_FEmis").Cells.Item(i).Specific).Value; FchVenc = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_FVenc").Cells.Item(i).Specific).Value; MntTotal = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_Total").Cells.Item(i).Specific).Value; IVA = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_IVA").Cells.Item(i).Specific).Value; NroRef = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_1-1").Cells.Item(i).Specific).Value; RzRef = ((SAPbouiCOM.EditText)oMatrix.Columns.Item("Col_1-4").Cells.Item(i).Specific).Value; ResultMessage rslt = FuncionesComunes.ValidacionDTEIntegrado(RutEmisor, Int32.Parse(Tipo), Folio);// Int64.Parse(Folio)); rslt.Success = true; if (rslt.Success) { //objDTE = ListaDTEMatrix.ListaDTE.Where(x => x.FebosID == FebId).Select(x => x.objDTE).SingleOrDefault(); //if (objDTE != null) //{ switch (Tipo) { case "33": oDoc = (SAPbobsCOM.Documents)Conexion_SBO.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices); break; case "34": oDoc = (SAPbobsCOM.Documents)Conexion_SBO.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices); break; case "56": oDoc = (SAPbobsCOM.Documents)Conexion_SBO.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices); break; case "61": oDoc = (SAPbobsCOM.Documents)Conexion_SBO.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes); break; } oDoc.CardCode = CardCode; //oDoc.CardName = FuncionesComunes.ObtenerCardName(RutEmisor, oDoc.CardCode); switch (Tipo) { case "33": oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseInvoices; break; case "34": oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseInvoices; break; case "52": oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes; break; case "56": oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseInvoices; break; case "61": oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseCreditNotes; break; default: oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseInvoices; break; } oDoc.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Service; oDoc.DocDate = Convert.ToDateTime(FchEmis); oDoc.DocDueDate = Convert.ToDateTime(FchVenc); oDoc.DocTotal = Convert.ToDouble(MntTotal); oDoc.FolioNumber = Convert.ToInt32(Folio); oDoc.FolioPrefixString = Tipo; oDoc.Indicator = Tipo; oDoc.UserFields.Fields.Item("U_SEI_FEBOSID").Value = FebId; oDoc.NumAtCard = RzRef.PadRight(99); oDoc.Comments = RzRef.PadRight(254); oDoc.Lines.ItemDescription = Descripcion.PadRight(99); oDoc.Lines.AccountCode = Cuenta; oDoc.Lines.LineTotal = Convert.ToDouble(Convert.ToDouble(MntTotal) - Convert.ToDouble(IVA)); switch (Tipo) { case "34": oDoc.Lines.TaxCode = "IVA_EXE"; break; default: break; } if (!string.IsNullOrEmpty(Dim1)) { oDoc.Lines.CostingCode = Dim1; } if (!string.IsNullOrEmpty(Dim2)) { oDoc.Lines.CostingCode2 = Dim2; } if (!string.IsNullOrEmpty(Dim3)) { oDoc.Lines.CostingCode3 = Dim3; } if (!string.IsNullOrEmpty(Dim4)) { oDoc.Lines.CostingCode4 = Dim4; } if (!string.IsNullOrEmpty(Dim5)) { oDoc.Lines.CostingCode5 = Dim5; } Int32 RetVal = oDoc.Add(); String Mensaje = String.Empty; if (RetVal.Equals(0)) { rslt = FuncionesComunes.EnviarRespuestaComercial(FebId, "ACD", String.Empty, String.Empty); if (rslt.Success) { Conexion_SBO.m_SBO_Appl.StatusBar.SetText("Exito: El DTE :" + Folio + " Tipo :" + Tipo + " de :" + RutEmisor, SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Success); // Aceptacion comercial if (blAcepComer) { rslt = FuncionesComunes.EnviarRespuestaComercial(FebId, "ACD", String.Empty, String.Empty); if (rslt.Success) { Conexion_SBO.m_SBO_Appl.StatusBar.SetText(String.Format("Exito: El DTE {0} Tipo {1} de {2}-{3} Se integro.", Folio, Tipo, RutEmisor), SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Success); } else { Conexion_SBO.m_SBO_Appl.StatusBar.SetText(String.Format("Reparo: El DTE {0} Tipo {1} de {2}-{3} Se integro, pero no se completo proceso de intercambio.", Folio, Tipo, RutEmisor), SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning); } } } else { Conexion_SBO.m_SBO_Appl.StatusBar.SetText("Reparo: El DTE :" + Folio + " Tipo :" + Tipo + " de :" + RutEmisor + " Se integro, pero no se completo proceso de intercambio.", SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning); //file.WriteLine(String.Format("Reparo: El DTE {0} Tipo {1} de {2}-{3} Se integro, pero no se completo proceso de intercambio.", objDTE.IdDoc.Folio, objDTE.IdDoc.TipoDTE, objDTE.Emisor.RznSoc, objDTE.Emisor.RUTEmisor)); } } else { Int32 ErrCode = 0; String ErrMsj = String.Empty; Conexion_SBO.m_oCompany.GetLastError(out ErrCode, out ErrMsj); Conexion_SBO.m_SBO_Appl.StatusBar.SetText("Error: El DTE :" + Folio + " Tipo :" + Tipo + " de :" + RutEmisor + " No se integro " + ErrMsj, SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Error); //file.WriteLine(String.Format("Error: El DTE {0} Tipo {1} de {2}-{3} No se integro. {4}", objDTE.IdDoc.Folio, objDTE.IdDoc.TipoDTE, objDTE.Emisor.RznSoc, objDTE.Emisor.RUTEmisor, ErrMsj)); } //} } } } catch (Exception ex) { Conexion_SBO.m_SBO_Appl.StatusBar.SetText("Error: " + ex.Message, SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Error); } finally { // FuncionesComunes.LiberarObjetoGenerico(objDTE); FuncionesComunes.LiberarObjetoGenerico(oDoc); } }
private static void IntegracionServicio() { DTE objDTE = null; SAPbobsCOM.Documents oDoc = null; try { ResultMessage rslt = FuncionesComunes.ValidacionDTEIntegrado(RutEmisor, Int32.Parse(Tipo), Folio);// Int64.Parse(Folio)); if (rslt.Success) { objDTE = ListaDTEMatrix.ListaDTE.Where(i => i.FebosID == FebId).Select(i => i.objDTE).SingleOrDefault(); if (objDTE != null) { switch (Tipo) { case "33": oDoc = (SAPbobsCOM.Documents)Conexion_SBO.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices); break; case "34": oDoc = (SAPbobsCOM.Documents)Conexion_SBO.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices); break; case "56": oDoc = (SAPbobsCOM.Documents)Conexion_SBO.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices); break; case "61": oDoc = (SAPbobsCOM.Documents)Conexion_SBO.m_oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes); break; } oDoc.CardCode = CardCode; //oDoc.CardName = FuncionesComunes.ObtenerCardName(RutEmisor, oDoc.CardCode); switch (Tipo) { case "33": oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseInvoices; break; case "34": oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseInvoices; break; case "52": oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseDeliveryNotes; break; case "56": oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseInvoices; break; case "61": oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseCreditNotes; break; default: oDoc.DocObjectCode = SAPbobsCOM.BoObjectTypes.oPurchaseInvoices; break; } oDoc.DocType = SAPbobsCOM.BoDocumentTypes.dDocument_Service; oDoc.DocDate = Convert.ToDateTime(objDTE.IdDoc.FchEmis); oDoc.DocDueDate = Convert.ToDateTime(objDTE.IdDoc.FchVenc); oDoc.DocTotal = objDTE.Totales.MntTotal; oDoc.FolioNumber = Convert.ToInt32(Folio); oDoc.FolioPrefixString = Tipo; oDoc.Indicator = Tipo; oDoc.UserFields.Fields.Item("U_SEI_FEBOSID").Value = FebId; oDoc.Lines.ItemDescription = Descripcion; oDoc.Lines.AccountCode = Cuenta; oDoc.Lines.LineTotal = (objDTE.Totales.MntTotal - objDTE.Totales.IVA); switch (Tipo) { case "34": oDoc.Lines.TaxCode = "IVA_EXE"; break; default: break; } if (!string.IsNullOrEmpty(Dim1)) { oDoc.Lines.CostingCode = Dim1; } if (!string.IsNullOrEmpty(Dim2)) { oDoc.Lines.CostingCode2 = Dim2; } if (!string.IsNullOrEmpty(Dim3)) { oDoc.Lines.CostingCode3 = Dim3; } if (!string.IsNullOrEmpty(Dim4)) { oDoc.Lines.CostingCode4 = Dim4; } if (!string.IsNullOrEmpty(Dim5)) { oDoc.Lines.CostingCode5 = Dim5; } Int32 RetVal = oDoc.Add(); String Mensaje = String.Empty; if (RetVal.Equals(0)) { rslt = FuncionesComunes.EnviarRespuestaComercial(FebId, "ACD", String.Empty, String.Empty); if (rslt.Success) { Conexion_SBO.m_SBO_Appl.StatusBar.SetText(String.Format("Exito: El DTE {0} Tipo {1} de {2}-{3} Se integro.", objDTE.IdDoc.Folio, objDTE.IdDoc.TipoDTE, objDTE.Emisor.RznSoc, objDTE.Emisor.RUTEmisor), SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Success); //file.WriteLine(String.Format("Exito: El DTE {0} Tipo {1} de {2}-{3} Se integro.", objDTE.IdDoc.Folio, objDTE.IdDoc.TipoDTE, objDTE.Emisor.RznSoc, objDTE.Emisor.RUTEmisor)); } else { Conexion_SBO.m_SBO_Appl.StatusBar.SetText(String.Format("Reparo: El DTE {0} Tipo {1} de {2}-{3} Se integro, pero no se completo proceso de intercambio.", objDTE.IdDoc.Folio, objDTE.IdDoc.TipoDTE, objDTE.Emisor.RznSoc, objDTE.Emisor.RUTEmisor), SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Warning); //file.WriteLine(String.Format("Reparo: El DTE {0} Tipo {1} de {2}-{3} Se integro, pero no se completo proceso de intercambio.", objDTE.IdDoc.Folio, objDTE.IdDoc.TipoDTE, objDTE.Emisor.RznSoc, objDTE.Emisor.RUTEmisor)); } } else { Int32 ErrCode = 0; String ErrMsj = String.Empty; Conexion_SBO.m_oCompany.GetLastError(out ErrCode, out ErrMsj); Conexion_SBO.m_SBO_Appl.StatusBar.SetText(String.Format("Error: El DTE {0} Tipo {1} de {2}-{3} No se integro. {4}", objDTE.IdDoc.Folio, objDTE.IdDoc.TipoDTE, objDTE.Emisor.RznSoc, objDTE.Emisor.RUTEmisor, ErrMsj), SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Error); //file.WriteLine(String.Format("Error: El DTE {0} Tipo {1} de {2}-{3} No se integro. {4}", objDTE.IdDoc.Folio, objDTE.IdDoc.TipoDTE, objDTE.Emisor.RznSoc, objDTE.Emisor.RUTEmisor, ErrMsj)); } } } } catch (Exception ex) { Conexion_SBO.m_SBO_Appl.StatusBar.SetText("Error: " + ex.Message, SAPbouiCOM.BoMessageTime.bmt_Long, SAPbouiCOM.BoStatusBarMessageType.smt_Error); } finally { FuncionesComunes.LiberarObjetoGenerico(objDTE); FuncionesComunes.LiberarObjetoGenerico(oDoc); } }