public void InserirBusinessPartner(BusinessPartner businessPartner, out string messageError) { int addBPNumber = 0; try { SAPbobsCOM.BusinessPartners oBusinessPartner = (SAPbobsCOM.BusinessPartners)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners); oBusinessPartner.CardCode = businessPartner.CardCode; addBPNumber = oBusinessPartner.Add(); } catch (Exception e) { Log.WriteLog("InserirBusinessPartner Exception: " + e.Message); throw; } if (addBPNumber != 0) { messageError = oCompany.GetLastErrorDescription(); Log.WriteLog("InserirBusinessPartner error SAP: " + messageError); } else { string CardCode = oCompany.GetNewObjectKey(); messageError = ""; Log.WriteLog("BusinessPartner " + CardCode + " inserido com sucesso."); } }
public void BrowserTop3CustomerSample() { String query = @"Select Top 3 CardCode as 'Code', CardName as 'Name', Balance as 'Balance' From OCRD Where CardType = 'C' Order by Balance DESC"; try { Recordset oRS = ExecuteQuery(query); SAPbobsCOM.BusinessPartners oBP = AddOnUtilities.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners); // set the RecordSet to Browser of BO oBP.Browser.Recordset = oRS; String bpCode = String.Empty; String bpName = String.Empty; Double balance = Double.MinValue; String msg = "Customer Code : {0}. BP Name: {1}. Balance: {2}"; oBP.Browser.MoveFirst(); while (!oBP.Browser.EoF) { bpCode = oBP.CardCode; bpName = oBP.CardName; balance = oBP.CurrentAccountBalance; // read from DI API properties AddOnUtilities.MsgBoxWrapper(String.Format(msg, bpCode, bpName, balance)); oBP.SaveXML(oBP.CardCode + ".xml"); oBP.Browser.MoveNext(); } } catch (Exception ex) { AddOnUtilities.MsgBoxWrapper(ex.Message + " " + ex.StackTrace); } }
public string postDocument(double amount) { string outStr = ""; try { SAPbobsCOM.Documents Doc = (SAPbobsCOM.Documents)Program.objHrmsUI.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices); SAPbobsCOM.BusinessPartners bp = (SAPbobsCOM.BusinessPartners)Program.objHrmsUI.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners); SAPbouiCOM.EditText OWORDocNum = (SAPbouiCOM.EditText)oForm.Items.Item("18").Specific; string oworNum = OWORDocNum.Value.ToString(); oworEntry = Convert.ToString(Program.objHrmsUI.getScallerValue("Select DocEntry from owor where docnum='" + oworNum + "'")); Doc.CardCode = txSupplier.Value.ToString(); Doc.DocDate = DateTime.ParseExact(txPostingDate.Value.ToString(), "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture); // Doc.DocDueDate = Convert.ToDateTime(dtORDR.GetValue("CCDate", 0)); Doc.NumAtCard = txRef.Value.ToString(); Doc.DocType = BoDocumentTypes.dDocument_Service; Doc.Lines.AccountCode = txEA.Value.ToString(); Doc.Lines.LineTotal = amount; Doc.Lines.Add(); try { if (Doc.Add() != 0) { int erroCode = 0; string errDescr = ""; Program.objHrmsUI.oCompany.GetLastError(out erroCode, out errDescr); outStr = "Error:" + errDescr + outStr; oApplication.StatusBar.SetText("Failed to post Order : " + errDescr); } else { outStr = Convert.ToString(Program.objHrmsUI.oCompany.GetNewObjectKey()); string strUpdate = "Update OWOR set U_CostAP = '" + outStr + "' WHERE DocEntry = '" + oworEntry + "'"; Program.objHrmsUI.ExecQuery(strUpdate, "Marking AP"); oApplication.StatusBar.SetText("Sales AP Posted Successfully for ", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success); oApplication.Menus.Item("1304").Activate(); } } catch (Exception ex) { oApplication.StatusBar.SetText("Failed in Exec Query on Posting Document. : " + ex.Message); } finally { } } catch (Exception ex) { oApplication.SetStatusBarMessage("Error in posting document : " + ex.Message); } return(outStr); }
private void addBillTo(SAPbobsCOM.BusinessPartners bp) { int addressFound = 0; int addressCNt = 0; for (int i = 0; i < bp.Addresses.Count; i++) { bp.Addresses.SetCurrentLine(i); if (bp.Addresses.AddressName == dtCard.GetValue("BName", 0) && bp.Addresses.AddressType == SAPbobsCOM.BoAddressType.bo_BillTo) { bp.Addresses.Street = dtCard.GetValue("BStPO", 0).ToString(); bp.Addresses.City = dtCard.GetValue("BCity", 0).ToString(); string statecode = StateCode(dtCard.GetValue("BState", 0).ToString()); if (statecode != "") { bp.Addresses.State = statecode; } bp.Addresses.ZipCode = dtCard.GetValue("BZip", 0).ToString(); addressFound = 1; } addressCNt++; } if (addressFound == 0) { bp.Addresses.Add(); bp.Addresses.SetCurrentLine(addressCNt); bp.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_BillTo; bp.Addresses.AddressName = dtCard.GetValue("BName", 0).ToString(); bp.Addresses.Street = dtCard.GetValue("BStPO", 0).ToString(); bp.Addresses.City = dtCard.GetValue("BCity", 0).ToString(); bp.Addresses.TaxCode = "EX"; string statecode = StateCode(dtCard.GetValue("BState", 0).ToString()); if (statecode != "") { bp.Addresses.State = statecode; } bp.Addresses.ZipCode = dtCard.GetValue("BZip", 0).ToString(); } bp.Update(); }
/// <summary> /// Se conecta a SAP y agrega un socio de negocio de tipo Lead con la información de la solicitud. /// </summary> /// <returns>exito = 1, error = 2 </returns> private int registrarSolicitud(string agente, string solicitud, string codigoAsistente, string nombreAsistente, int dia, int mes, int year, string telefono, string nombre, string apellidoP, string apellidoM, string direccion, string entreCalles, string municipio, string colonia, string observaciones, string nvoIngreso, string codigoPostal, string rfc, string esquema, string msgError, string CodigoActivacion, string EstadoCivil, ref string error, string Calle_cobro, string Num_ext_cobro, string Num_int_cobro, string Entre_calles_cobro, string Codigo_postal_cobro, string Colonia_cobro, string Municipio_cobro) { SAPbobsCOM.BusinessPartners oSocioNegocio = null; string cardCodeGenerate = null; string nombreCompleto = null; try { Conexiones.ConexionSAP _oConnection = new Conexiones.ConexionSAP(); _oConnection = new Conexiones.ConexionSAP(); if (_oConnection.ConectarSAP(ref msgError)) { oCompany = _oConnection._oCompany; nombreCompleto = nombre.TrimEnd(' ') + ' ' + apellidoP.TrimEnd(' ') + ' ' + apellidoM.TrimEnd(' '); oSocioNegocio = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners); ObtenerDatosSolicitudValidacion(solicitud); //Asignacion de empresa int SeriesLead = 0; string empresa = CodigoActivacion.Substring(1, 1); if (empresa.Equals("C")) { SeriesLead = 927; } else { SeriesLead = 926; } //Datos generales oSocioNegocio.Series = SeriesLead; oSocioNegocio.CardType = SAPbobsCOM.BoCardTypes.cLid; oSocioNegocio.GroupCode = ObtenerGrupoLead(); oSocioNegocio.CardName = nombreCompleto; oSocioNegocio.FederalTaxID = rfc; oSocioNegocio.DebitorAccount = Extensor.Configuracion.VENTANA.CuentaLead; oSocioNegocio.UserFields.Fields.Item("U_EstadoCivil").Value = EstadoCivil; oSocioNegocio.UserFields.Fields.Item("U_QCapturaContrato").Value = "AppM - " + codigoAsistente; oSocioNegocio.UserFields.Fields.Item("U_SolicitudInt").Value = solicitud; oSocioNegocio.UserFields.Fields.Item("U_CodigoPromotor").Value = codigoAsistente; oSocioNegocio.UserFields.Fields.Item("U_NomProm").Value = nombreAsistente; oSocioNegocio.UserFields.Fields.Item("U_Dia").Value = dia.ToString(); oSocioNegocio.UserFields.Fields.Item("U_Mes").Value = mes.ToString(); oSocioNegocio.UserFields.Fields.Item("U_Year").Value = year.ToString(); oSocioNegocio.UserFields.Fields.Item("U_ComentarioContrato").Value = observaciones; oSocioNegocio.UserFields.Fields.Item("U_PersonaNvoIngreso").Value = nvoIngreso; oSocioNegocio.UserFields.Fields.Item("U_NumArt_").Value = DatosSolicitud.ElementAt(0).plan; oSocioNegocio.UserFields.Fields.Item("U_Dsciption").Value = DatosSolicitud.ElementAt(0).nombrePlan; oSocioNegocio.UserFields.Fields.Item("U_PrefijoPlan").Value = DatosSolicitud.ElementAt(0).prefijoPlan; oSocioNegocio.UserFields.Fields.Item("U_FechaCaptura").Value = DateTime.Now.ToShortDateString(); oSocioNegocio.UserFields.Fields.Item("U_HoraCaptura").Value = DateTime.Now.ToString("HH:mm:ss"); string esquemaValidacion = string.Empty; if (esquema.Contains("SUELDO")) { esquemaValidacion = Extensor.ValidarEsquemaPago(esquema, codigoAsistente); esquema = esquemaValidacion; } else { esquemaValidacion = "COMISION"; esquema = esquemaValidacion; } oSocioNegocio.UserFields.Fields.Item("U_Esquema_pago").Value = esquema; oSocioNegocio.UserFields.Fields.Item("U_Test").Value = "Y"; oSocioNegocio.UserFields.Fields.Item("U_CodigoActivacion").Value = CodigoActivacion; if (nombreCompleto.Length > 70) { oSocioNegocio.UserFields.Fields.Item("U_BeneficiarioPagoRe").Value = nombreCompleto.ToString().Substring(1, 70); } else { oSocioNegocio.UserFields.Fields.Item("U_BeneficiarioPagoRe").Value = nombreCompleto; } //Domicilio de casa oSocioNegocio.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_BillTo; oSocioNegocio.Addresses.AddressName = "DIRECCION 1"; oSocioNegocio.Addresses.AddressName2 = telefono; oSocioNegocio.Addresses.Street = direccion; oSocioNegocio.Addresses.BuildingFloorRoom = entreCalles; oSocioNegocio.Addresses.City = municipio; oSocioNegocio.Addresses.Block = colonia; oSocioNegocio.Addresses.ZipCode = codigoPostal; oSocioNegocio.Addresses.State = "JAL"; oSocioNegocio.Addresses.Add(); //Domicilio de cobro oSocioNegocio.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_BillTo; oSocioNegocio.Addresses.AddressName = "COBRO"; oSocioNegocio.Addresses.AddressName2 = telefono; oSocioNegocio.Addresses.Street = Calle_cobro + " " + Num_ext_cobro + " " + Num_int_cobro; oSocioNegocio.Addresses.BuildingFloorRoom = Entre_calles_cobro; oSocioNegocio.Addresses.City = Municipio_cobro; oSocioNegocio.Addresses.Block = Colonia_cobro; oSocioNegocio.Addresses.ZipCode = Codigo_postal_cobro; oSocioNegocio.Addresses.State = "JAL"; Logger.Info("-----------------------------------------------------------------------------------------"); Logger.Info("Información de pre-contrato: " + agente + " - " + solicitud + " - " + codigoAsistente + " - " + nombreAsistente + " - " + telefono + " - " + nombre + " - " + apellidoP + " - " + apellidoM + " - " + direccion + " - " + entreCalles + " - " + municipio + " - " + colonia + " - " + " - " + (Calle_cobro + " " + Num_ext_cobro + " " + Num_int_cobro) + " - " + Entre_calles_cobro + " - " + Municipio_cobro + " - " + Colonia_cobro + " - " + observaciones + " - " + nvoIngreso + " - " + codigoPostal + " - " + rfc + " - " + esquema + " - " + msgError + " - " + CodigoActivacion); if (oSocioNegocio.Add() != 0) { msgError = "Error: " + oCompany.GetLastErrorDescription(); error = msgError; Logger.Info("Activacion Fallida: " + oCompany.GetLastErrorDescription()); Logger.Fatal("Activacion Fallida: " + oCompany.GetLastErrorDescription()); return(2); } else { oCompany.GetNewObjectCode(out cardCodeGenerate); Logger.Info("Activacion exitosa: " + cardCodeGenerate); msgError = string.Empty; error = msgError; return(1); } } else { Logger.Error("Error al conectar a SAP: {1}" + solicitud); return(2); } } catch (Exception ex) { Logger.Error("Error al registrar la solicitud {0} en SAP: {1}", solicitud, ex.Message); Logger.Fatal("Error al registrar la solicitud {0} en SAP: {1}", solicitud, ex.Message); error = "Solicitud: " + solicitud + ", Ex: " + ex.Message; return(2); } }
public string postDocument() { Program.objHrmsUI.loadSettings(); string outStr = ""; string TaxCode = Program.objHrmsUI.getSetting("TAX").ToString(); try { if (dtORDR.Rows.Count == 0) { return("No Items"); } SAPbobsCOM.Documents Doc = (SAPbobsCOM.Documents)Program.objHrmsUI.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders); SAPbobsCOM.BusinessPartners bp = (SAPbobsCOM.BusinessPartners)Program.objHrmsUI.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners); bool bpexist = bp.GetByKey(dtHead.GetValue("CardCode", 0).ToString()); Doc.CardCode = dtHead.GetValue("CardCode", 0).ToString(); Doc.DocDate = Convert.ToDateTime(dtHead.GetValue("InvDate", 0)); Doc.DocDueDate = Convert.ToDateTime(dtHead.GetValue("InvDate", 0)); // Doc.SalesPersonCode = Convert.ToInt16( Program.objHrmsUI.settings["WebSlpCode"].ToString()); Doc.PickRemark = "LTD A/R Invoice " + dtHead.GetValue("InvNum", 0).ToString(); // dtORDR.GetValue("NumAtCard", 0).ToString(); Doc.NumAtCard = "LTD Inv # " + dtHead.GetValue("InvNum", 0).ToString(); Doc.Comments = dtHead.GetValue("REM", 0).ToString(); Doc.DiscountPercent = Convert.ToDouble(dtHead.GetValue("DP", 0)); int ItemLineNum = -1; for (int i = 0; i < dtRDR1.Rows.Count; i++) { if (dtRDR1.GetValue("ItemCode", i).ToString() != "") { Doc.Lines.ItemCode = dtRDR1.GetValue("ItemCode", i).ToString(); Doc.Lines.ItemDescription = dtRDR1.GetValue("ItemName", i).ToString(); //rs.Fields.Item("ItemName").Value; Doc.Lines.Quantity = Convert.ToDouble(dtRDR1.GetValue("Qty", i)); Doc.Lines.UnitPrice = Convert.ToDouble(dtRDR1.GetValue("Price", i)); Doc.Lines.DiscountPercent = Convert.ToDouble(dtRDR1.GetValue("DiscP", i)); Doc.Lines.UoMEntry = getUomEntry(dtRDR1.GetValue("UOM", i).ToString()); // Doc.Lines.VatGroup = TaxCode.ToString(); Doc.Lines.TaxCode = TaxCode; Doc.Lines.Add(); ItemLineNum++; } else { Doc.SpecialLines.LineType = SAPbobsCOM.BoDocSpecialLineType.dslt_Text; Doc.SpecialLines.LineText = dtRDR1.GetValue("ItemName", i).ToString(); Doc.SpecialLines.AfterLineNumber = ItemLineNum; Doc.SpecialLines.Add(); } } try { if (Doc.Add() != 0) { int erroCode = 0; string errDescr = ""; Program.objHrmsUI.oCompany.GetLastError(out erroCode, out errDescr); outStr = "Error:" + errDescr + outStr; oApplication.StatusBar.SetText("Failed to post Order : " + errDescr); } else { outStr = Convert.ToString(Program.objHrmsUI.oCompany.GetNewObjectKey()); } } catch (Exception ex) { oApplication.StatusBar.SetText("Failed in Exec Query on Posting Document. : " + ex.Message); } finally { } } catch (Exception ex) { oApplication.SetStatusBarMessage("Error in posting document : " + ex.Message); } return(outStr); }
private void addShipTo(SAPbobsCOM.BusinessPartners bp) { int addressFound = 0; int addressCnt = 0; for (int i = 0; i < bp.Addresses.Count; i++) { bp.Addresses.SetCurrentLine(i); if (bp.Addresses.AddressName == "S-" + dtCard.GetValue("SName", 0) && bp.Addresses.AddressType == SAPbobsCOM.BoAddressType.bo_ShipTo) { bp.Addresses.ZipCode = dtCard.GetValue("SZip", 0).ToString(); bp.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_ShipTo; bp.Addresses.Street = dtCard.GetValue("SStPO", 0).ToString(); bp.Addresses.City = dtCard.GetValue("SCity", 0).ToString(); // bp.Addresses.TaxCode = "EX"; string statecode = StateCode(dtCard.GetValue("SState", 0).ToString()); if (statecode != "") { bp.Addresses.State = statecode; } addressFound = 1; } addressCnt++; } if (addressFound == 0) { bp.Addresses.Add(); bp.Addresses.SetCurrentLine(addressCnt); bp.Addresses.AddressName = "S-" + dtCard.GetValue("SName", 0); bp.Addresses.ZipCode = dtCard.GetValue("SZip", 0).ToString(); bp.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_ShipTo; bp.Addresses.Street = dtCard.GetValue("SStPO", 0).ToString(); bp.Addresses.City = dtCard.GetValue("SCity", 0).ToString(); // bp.Addresses.TaxCode = "EX"; string statecode = StateCode(dtCard.GetValue("SState", 0).ToString()); if (statecode != "") { bp.Addresses.State = statecode; } bp.Addresses.UserFields.Fields.Item("U_PhoneNum").Value = dtCard.GetValue("STel", 0).ToString();; // sTel == null ? "" : sTel; bp.Addresses.UserFields.Fields.Item("U_EMail").Value = dtCard.GetValue("BEmail", 0).ToString(); // sEmail == null ? "" : sEmail; } int result = bp.Update(); if (result != 0) { int erroCode = 0; string errDescr = ""; Program.objHrmsUI.oCompany.GetLastError(out erroCode, out errDescr); if (errDescr.Contains("This entry already exists in the following tables")) { } else { oApplication.StatusBar.SetText("Failed to post Order : " + errDescr); } } else { // oApplication.StatusBar.SetText("Sales Order Posted Successfully for " + dtORDR.GetValue("WBID", 0), BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success); } }
public string addBp() { string result = ""; SAPbobsCOM.BusinessPartners defbp = (SAPbobsCOM.BusinessPartners)Program.objHrmsUI.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners); defbp.GetByKey("W-00006935"); SAPbobsCOM.BusinessPartners bp = (SAPbobsCOM.BusinessPartners)Program.objHrmsUI.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners); bp.CardCode = dtCard.GetValue("CardCode", 0).ToString();; bp.CardType = SAPbobsCOM.BoCardTypes.cCustomer; bp.CardName = dtCard.GetValue("BName", 0).ToString();; bp.Phone1 = dtCard.GetValue("CTel", 0).ToString();; bp.EmailAddress = dtCard.GetValue("CEmail", 0).ToString();; bp.FederalTaxID = "EX"; bp.GroupCode = defbp.GroupCode; bp.PayTermsGrpCode = defbp.PayTermsGrpCode; bp.DownPaymentClearAct = defbp.DownPaymentClearAct; bp.DefaultAccount = defbp.DefaultAccount; bp.DebitorAccount = defbp.DebitorAccount; bp.ContactEmployees.Name = dtCard.GetValue("CNID", 0).ToString();; bp.ContactEmployees.Phone1 = dtCard.GetValue("CNTel", 0).ToString();; bp.ContactEmployees.E_Mail = dtCard.GetValue("CNEmail", 0).ToString();; bp.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_BillTo; bp.Addresses.AddressName = dtCard.GetValue("BName", 0).ToString();; bp.Addresses.Street = dtCard.GetValue("BStPO", 0).ToString();; bp.Addresses.City = dtCard.GetValue("BCity", 0).ToString();; string statecode = StateCode(dtCard.GetValue("BState", 0).ToString()); if (statecode != "") { bp.Addresses.State = statecode; } bp.Addresses.ZipCode = dtCard.GetValue("BZip", 0).ToString();; bp.Addresses.UserFields.Fields.Item("U_PhoneNum").Value = dtCard.GetValue("BTel", 0).ToString();; bp.Addresses.UserFields.Fields.Item("U_EMail").Value = dtCard.GetValue("BEmail", 0).ToString();; bp.Addresses.TaxCode = "EX"; bp.Addresses.Add(); bp.Addresses.AddressType = SAPbobsCOM.BoAddressType.bo_ShipTo; bp.Addresses.AddressName = "S-" + dtCard.GetValue("SName", 0).ToString();; bp.Addresses.Street = dtCard.GetValue("SStPO", 0).ToString();; bp.Addresses.City = dtCard.GetValue("SCity", 0).ToString();; statecode = StateCode(dtCard.GetValue("SState", 0).ToString()).ToString();; if (statecode != "") { bp.Addresses.State = statecode; } bp.Addresses.ZipCode = dtCard.GetValue("SZip", 0).ToString(); bp.Addresses.UserFields.Fields.Item("U_PhoneNum").Value = dtCard.GetValue("STel", 0); bp.Addresses.UserFields.Fields.Item("U_EMail").Value = dtCard.GetValue("SEmail", 0); bp.Addresses.TaxCode = "EX"; bp.Addresses.Add(); int bpSuccess = bp.Add(); if (bpSuccess != 0) { int erroCode = 0; string errDescr = ""; Program.objHrmsUI.oCompany.GetLastError(out erroCode, out errDescr); oApplication.StatusBar.SetText("Failed to add BP : " + errDescr); } return(result); }
public async Task <IActionResult> PostBPMaster(BusinessPartnerVM VM) { bool IsCreate = true, IsRecordFound = false; SAPEntity.Instance.InitializeCompany(); if (SAPEntity.Company.Connected) { SAPbobsCOM.BusinessPartners SAPBusinessPartner = (SAPbobsCOM.BusinessPartners)SAPEntity.Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners); if (!string.IsNullOrEmpty(VM.cardcode) && SAPBusinessPartner.GetByKey(VM.cardcode)) { IsCreate = false; } else { SAPBusinessPartner.CardCode = _BPrepo.GetNewCardCodeForLead("L"); SAPBusinessPartner.CardType = BoCardTypes.cLid; } if (VM.Type == "Portfolio") { SAPBusinessPartner.CardType = BoCardTypes.cCustomer; } SAPBusinessPartner.CardName = VM.cardname; SAPBusinessPartner.EmailAddress = VM.email; SAPBusinessPartner.Website = VM.website; SAPBusinessPartner.Phone1 = VM.telephone; SAPBusinessPartner.Notes = VM.sector; SAPBusinessPartner.Currency = VM.currency; SAPBusinessPartner.FreeText = VM.Notes; //adress for (var i = 0; i <= SAPBusinessPartner.Addresses.Count - 1; i++) { IsRecordFound = false; SAPBusinessPartner.Addresses.SetCurrentLine(i); if (SAPBusinessPartner.Addresses.AddressName == VM.temp_address && SAPBusinessPartner.Addresses.AddressType == BoAddressType.bo_ShipTo && SAPBusinessPartner.Addresses.RowNum == Convert.ToInt32(VM.lineNum) && SAPBusinessPartner.Addresses.BPCode == SAPBusinessPartner.CardCode) { IsRecordFound = true; break; } } if (!IsRecordFound) { SAPBusinessPartner.Addresses.SetCurrentLine(SAPBusinessPartner.Addresses.Count - 1); if (!string.IsNullOrEmpty(SAPBusinessPartner.Addresses.AddressName)) { SAPBusinessPartner.Addresses.Add(); } SAPBusinessPartner.Addresses.SetCurrentLine(SAPBusinessPartner.Addresses.Count - 1); } SAPBusinessPartner.Addresses.SetCurrentLine(SAPBusinessPartner.Addresses.Count - 1); SAPBusinessPartner.Addresses.AddressType = BoAddressType.bo_ShipTo; SAPBusinessPartner.Addresses.AddressName = VM.adressname; SAPBusinessPartner.Addresses.Street = VM.street; SAPBusinessPartner.Addresses.AddressName2 = VM.landmark; SAPBusinessPartner.Addresses.Country = VM.country; SAPBusinessPartner.Addresses.State = VM.state; SAPBusinessPartner.Addresses.City = VM.city; SAPBusinessPartner.Addresses.ZipCode = VM.zipcode; //GST if (!string.IsNullOrEmpty(VM.gstin)) { SAPBusinessPartner.Addresses.GstType = BoGSTRegnTypeEnum.gstRegularTDSISD; SAPBusinessPartner.Addresses.GSTIN = VM.gstin; } //Contact person if (!string.IsNullOrEmpty(VM.pfname)) { IsRecordFound = false; for (var i = 0; i <= SAPBusinessPartner.ContactEmployees.Count - 1; i++) { SAPBusinessPartner.ContactEmployees.SetCurrentLine(i); if (SAPBusinessPartner.ContactEmployees.InternalCode == Convert.ToInt32(VM.pcntctCode)) { IsRecordFound = true; SAPBusinessPartner.ContactEmployees.SetCurrentLine(i); break; } } if (!IsRecordFound) { SAPBusinessPartner.ContactEmployees.SetCurrentLine(SAPBusinessPartner.ContactEmployees.Count - 1); if (!string.IsNullOrEmpty(SAPBusinessPartner.ContactEmployees.Name)) { SAPBusinessPartner.ContactEmployees.Add(); } SAPBusinessPartner.ContactEmployees.SetCurrentLine(SAPBusinessPartner.ContactEmployees.Count - 1); } SAPBusinessPartner.ContactEmployees.Name = VM.pfname + " " + VM.plname; SAPBusinessPartner.ContactEmployees.FirstName = VM.pfname; SAPBusinessPartner.ContactEmployees.LastName = VM.plname; SAPBusinessPartner.ContactEmployees.MobilePhone = VM.pmobile; SAPBusinessPartner.ContactEmployees.E_Mail = VM.pemail; SAPBusinessPartner.ContactEmployees.Phone1 = VM.ptel; SAPBusinessPartner.ContactEmployees.Position = VM.pposition; } if (!string.IsNullOrEmpty(VM.sfname)) { IsRecordFound = false; for (var i = 0; i <= SAPBusinessPartner.ContactEmployees.Count - 1; i++) { SAPBusinessPartner.ContactEmployees.SetCurrentLine(i); if (SAPBusinessPartner.ContactEmployees.InternalCode == Convert.ToInt32(VM.scntctCode)) { IsRecordFound = true; SAPBusinessPartner.ContactEmployees.SetCurrentLine(i); break; } } if (!IsRecordFound) { SAPBusinessPartner.ContactEmployees.SetCurrentLine(SAPBusinessPartner.ContactEmployees.Count - 1); if (!string.IsNullOrEmpty(SAPBusinessPartner.ContactEmployees.Name)) { SAPBusinessPartner.ContactEmployees.Add(); } SAPBusinessPartner.ContactEmployees.SetCurrentLine(SAPBusinessPartner.ContactEmployees.Count - 1); } SAPBusinessPartner.ContactEmployees.Title = "Mr/Mrs"; SAPBusinessPartner.ContactEmployees.Name = VM.sfname + " " + VM.slname; SAPBusinessPartner.ContactEmployees.FirstName = VM.sfname; SAPBusinessPartner.ContactEmployees.LastName = VM.slname; SAPBusinessPartner.ContactEmployees.MobilePhone = VM.smobile; SAPBusinessPartner.ContactEmployees.E_Mail = VM.semail; SAPBusinessPartner.ContactEmployees.Phone1 = VM.stel; SAPBusinessPartner.ContactEmployees.Position = VM.sposition; } if (!string.IsNullOrEmpty(VM.pan)) { IsRecordFound = false; for (var i = 0; i <= SAPBusinessPartner.FiscalTaxID.Count - 1; i++) { SAPBusinessPartner.FiscalTaxID.SetCurrentLine(i); if (SAPBusinessPartner.FiscalTaxID.BPCode == SAPBusinessPartner.CardCode && SAPBusinessPartner.FiscalTaxID.Address == SAPBusinessPartner.Address) { IsRecordFound = true; break; } } if (!IsRecordFound) { SAPBusinessPartner.FiscalTaxID.SetCurrentLine(SAPBusinessPartner.FiscalTaxID.Count - 1); if (!string.IsNullOrEmpty(SAPBusinessPartner.FiscalTaxID.BPCode)) { SAPBusinessPartner.FiscalTaxID.Add(); } SAPBusinessPartner.FiscalTaxID.SetCurrentLine(SAPBusinessPartner.FiscalTaxID.Count - 1); } SAPBusinessPartner.FiscalTaxID.TaxId0 = VM.pan; } if (IsCreate) { if (SAPBusinessPartner.Add() == 0) { string ObjCode; SAPEntity.Company.GetNewObjectCode(out ObjCode); return(StatusCode(201)); } else { string Message = SAPEntity.Company.GetLastErrorDescription(); return(BadRequest(Message)); } } else { if (SAPBusinessPartner.Update() == 0) { string ObjCode; SAPEntity.Company.GetNewObjectCode(out ObjCode); return(StatusCode(201)); } else { string Message = SAPEntity.Company.GetLastErrorDescription(); return(BadRequest(Message)); } } } return(BadRequest("not able to connect sap.")); }