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.");
            }
        }
Пример #2
0
        /// <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);
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        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."));
        }