public void Criar(PotencialdoKAporTrimestre mPotencialdoKATrimestre, List <Model.OrcamentoDetalhado> lstOrcamentoDetalhado, Guid representanteId, int numTrimestre)
        {
            PotencialdoKAporSegmento mPotencialdoKAporSegmento = null;
            var lstOrcamentoporSegmento = (from x in lstOrcamentoDetalhado
                                           group x by string.Format("{0}", x.Familia.Id));



            foreach (var OrcaSegmento in lstOrcamentoporSegmento)
            {
                mPotencialdoKATrimestre = RepositoryService.PotencialdoKAporTrimestre.Retrieve(mPotencialdoKATrimestre.ID.Value);
                List <PotencialdoKAporSegmento> tempSegmento = RepositoryService.PotencialdoKAporSegmento.__Obter(mPotencialdoKATrimestre.UnidadedeNegocio.Id, representanteId, numTrimestre, mPotencialdoKATrimestre.ID.Value, OrcaSegmento.First().Segmento.Id);
                if (tempSegmento.Count == 0)
                {
                    PortfoliodoKeyAccountRepresentantes portfolioKA = RepositoryService.PortfoliodoKeyAccountRepresentantes.ObterPor(mPotencialdoKATrimestre.UnidadedeNegocio.Id, representanteId);

                    if (portfolioKA.Segmento != null)
                    {
                        if (OrcaSegmento.First().Segmento.Id != portfolioKA.Segmento.Id)
                        {
                            continue;
                        }
                    }

                    mPotencialdoKAporSegmento                      = new PotencialdoKAporSegmento(RepositoryService.NomeDaOrganizacao, RepositoryService.IsOffline, RepositoryService.Provider);
                    mPotencialdoKAporSegmento.ID                   = Guid.NewGuid();
                    mPotencialdoKAporSegmento.Nome                 = mPotencialdoKATrimestre.Nome + " - " + OrcaSegmento.First().Segmento.Name;
                    mPotencialdoKAporSegmento.UnidadedeNegocio     = mPotencialdoKATrimestre.UnidadedeNegocio;
                    mPotencialdoKAporSegmento.Ano                  = mPotencialdoKATrimestre.Ano;
                    mPotencialdoKAporSegmento.KAouRepresentante    = new Lookup(representanteId, SDKore.Crm.Util.Utility.GetEntityName <Model.Contato>());
                    mPotencialdoKAporSegmento.Segmento             = new Lookup(OrcaSegmento.First().Segmento.Id, SDKore.Crm.Util.Utility.GetEntityName <Model.Segmento>());
                    mPotencialdoKAporSegmento.Trimestre            = numTrimestre;
                    mPotencialdoKAporSegmento.PotencialKaTrimestre = new Lookup(mPotencialdoKATrimestre.ID.Value, SDKore.Crm.Util.Utility.GetEntityName <Model.PotencialdoKAporTrimestre>());

                    RepositoryService.PotencialdoKAporSegmento.Create(mPotencialdoKAporSegmento);

                    ServicePotencialdoKAporFamilia.Criar(mPotencialdoKAporSegmento, OrcaSegmento.ToList(), representanteId, numTrimestre);
                }
                else
                {
                    ServicePotencialdoKAporFamilia.Criar(tempSegmento[0], OrcaSegmento.ToList(), representanteId, numTrimestre);
                }
            }
        }
        public void VerificaDuplicidadePortforioKARepresentantes(PortfoliodoKeyAccountRepresentantes PortfolioKA)
        {
            List <PortfoliodoKeyAccountRepresentantes> lstPortFolioKa = new List <PortfoliodoKeyAccountRepresentantes>();

            if (PortfolioKA.KeyAccountRepresentante.Id == null)
            {
                throw new ArgumentException("KeyAccount Representante é obrigatório.");
            }

            if (PortfolioKA.UnidadedeNegocio == null)
            {
                throw new ArgumentException("Unidade de Negócio é obrigatório.");
            }


            lstPortFolioKa = RepositoryService.PortfoliodoKeyAccountRepresentantes.ListarPorUnidadeNegocioEsegmentoVazio(PortfolioKA.ID.Value, PortfolioKA.KeyAccountRepresentante.Id, PortfolioKA.UnidadedeNegocio.Id); //unidade de negócio, desde que o segmento não seja preenchido
            if (lstPortFolioKa.Count > 0)
            {
                throw new ArgumentException("Ja existe um outro PortfolioKeyAccount com o mesmo KeyAccount Representante, Unidade de Negócio e Sem Segmento informado (atende todos os segmentos).");
            }

            if (PortfolioKA.Segmento != null)
            {
                lstPortFolioKa = RepositoryService.PortfoliodoKeyAccountRepresentantes.ListarPorUnidadeNegocioEsegmento(PortfolioKA.ID.Value, PortfolioKA.KeyAccountRepresentante.Id, PortfolioKA.Segmento.Id, PortfolioKA.UnidadedeNegocio.Id);//segmento

                if (lstPortFolioKa.Count > 0)
                {
                    throw new ArgumentException("Ja existe um outro PortfolioKeyAccount com o mesmo KeyAccount Representante, Unidade de Negócio e Segmento.");
                }
            }
            else
            {
                lstPortFolioKa = RepositoryService.PortfoliodoKeyAccountRepresentantes.ListarPorUnidadeNegocioEsegmentoNaoVazio(PortfolioKA.ID.Value, PortfolioKA.KeyAccountRepresentante.Id, PortfolioKA.UnidadedeNegocio.Id); //unidade de negócio, desde que o segmento não seja preenchido
                if (lstPortFolioKa.Count > 0)
                {
                    throw new ArgumentException("Ja existe um outro PortfolioKeyAccount com o mesmo KeyAccount Representante, Unidade de Negócio e com algum Segmento informado. Não é possivel criar para todos os Segmentos");
                }
            }
        }
Esempio n. 3
0
        public string Enviar(PortfoliodoKeyAccountRepresentantes objModel)
        {
            string retMsg = String.Empty;

            Intelbras.Message.Helper.MSG0143 mensagem = this.DefinirPropriedades(objModel);

            Domain.Servicos.Integracao integracao = new Servicos.Integracao(this.Organizacao, this.IsOffline);
            if (integracao.EnviarMensagemBarramento(mensagem.GenerateMessage(true), "1", "1", out retMsg))
            {
                Intelbras.Message.Helper.MSG0143R1 retorno = CarregarMensagem <Pollux.MSG0143R1>(retMsg);
                if (!retorno.Resultado.Sucesso)
                {
                    throw new Exception(retorno.Resultado.Mensagem);
                }
            }
            else
            {
                Intelbras.Message.Helper.ERR0001 erro001 = CarregarMensagem <Pollux.ERR0001>(retMsg);
                throw new Exception(erro001.GenerateMessage(false));
            }
            return(retMsg);
        }
 public void AtualizarPortfolioKARepresentante(PortfoliodoKeyAccountRepresentantes PortfolioKA)
 {
     RepositoryService.PortfoliodoKeyAccountRepresentantes.Update(PortfolioKA);
 }
 public string IntegracaoBarramento(PortfoliodoKeyAccountRepresentantes objPortfolioRepresentante)
 {
     Domain.Integracao.MSG0143 msgPortRepres = new Domain.Integracao.MSG0143(RepositoryService.NomeDaOrganizacao, RepositoryService.IsOffline);
     return(msgPortRepres.Enviar(objPortfolioRepresentante));
 }
Esempio n. 6
0
        public Pollux.MSG0143 DefinirPropriedades(PortfoliodoKeyAccountRepresentantes objModel)
        {
            #region Propriedades Crm->Xml

            Pollux.MSG0143 msg0143      = new Pollux.MSG0143(itb.RetornaSistema(itb.Sistema.CRM), Helper.Truncate(objModel.Nome, 40));
            string         nomeUnid     = String.Empty;
            string         nomeSegmento = String.Empty;

            msg0143.CodigoPortfolioRepresentante = objModel.ID.Value.ToString();
            if (objModel.KeyAccountRepresentante != null)
            {
                Contato representante = new Servicos.ContatoService(this.Organizacao, this.IsOffline).BuscaContato(objModel.KeyAccountRepresentante.Id);
                if (representante != null && representante.CodigoRepresentante.Length > 0)
                {
                    msg0143.CodigoRepresentante = Convert.ToInt32(representante.CodigoRepresentante);
                }
                else
                {
                    throw new Exception("Representante não localizado/sem código representante.");
                }
            }
            if (objModel.UnidadedeNegocio != null)
            {
                UnidadeNegocio unidadeNegocio = new Servicos.UnidadeNegocioService(this.Organizacao, this.IsOffline).BuscaUnidadeNegocio(objModel.UnidadedeNegocio.Id);
                if (unidadeNegocio != null)
                {
                    msg0143.CodigoUnidadeNegocio = unidadeNegocio.ChaveIntegracao;
                    nomeUnid = unidadeNegocio.Nome;
                }
                else
                {
                    throw new Exception("Unidade de negocio não localizada ou sem nome.");
                }
            }
            if (objModel.AssistentedeAdministracaodeVendas != null)
            {
                Usuario usuario = new Servicos.UsuarioService(this.Organizacao, this.IsOffline).ObterPor(objModel.AssistentedeAdministracaodeVendas.Id);
                if (usuario != null && usuario.CodigoAssistenteComercial != null)
                {
                    msg0143.CodigoAssistente    = usuario.CodigoAssistenteComercial.Value;
                    msg0143.CodigoAssistenteCRM = usuario.ID.Value.ToString();
                }

                else
                {
                    throw new Exception("Usuario sem código de assistente comercial.");
                }
            }
            if (objModel.Segmento != null)
            {
                Segmento segmento = new Servicos.SegmentoService(this.Organizacao, this.IsOffline).ObterPor(objModel.Segmento.Id);
                if (segmento != null)
                {
                    msg0143.CodigoSegmento = segmento.CodigoSegmento;
                    nomeSegmento           = segmento.Nome;
                }
                else
                {
                    throw new Exception("Segmento não localizado.");
                }
            }
            else
            {
                msg0143.CodigoSegmento = "0000";
                nomeSegmento           = "";
            }

            if (objModel.SupervisordeVendas != null)
            {
                Usuario supervisor = new Servicos.UsuarioService(this.Organizacao, this.IsOffline).ObterPor(objModel.SupervisordeVendas.Id);
                if (supervisor != null)
                {
                    msg0143.CodigoSupervisor = supervisor.ID.Value.ToString();
                    if (!String.IsNullOrEmpty(supervisor.CodigoSupervisorEMS))
                    {
                        msg0143.CodigoSupervisorEMS = supervisor.CodigoSupervisorEMS;
                    }
                    else
                    {
                        throw new Exception("Codigo Supervisor EMS não preenchido.");
                    }
                }
                else
                {
                    throw new Exception("Supervisor não localizado.");
                }
            }

            if (objModel.Status.HasValue)
            {
                if (objModel.Status.Value == 1)
                {
                    msg0143.Situacao = 0;
                }
                else
                {
                    msg0143.Situacao = 1;
                }
            }

            if (!String.IsNullOrEmpty(objModel.Nome))
            {
                string nometmp = objModel.Nome + " - " + nomeUnid + " - " + nomeSegmento;
                if (nometmp.Length > 99)
                {
                    msg0143.Nome = nometmp.Substring(0, 99);
                }
                else
                {
                    msg0143.Nome = nometmp;
                }
            }
            else
            {
                throw new Exception("PortfolioRepresentante sem nome.");
            }

            #endregion

            return(msg0143);
        }
Esempio n. 7
0
        public PortfoliodoKeyAccountRepresentantes DefinirPropriedades(Intelbras.Message.Helper.MSG0143 xml)
        {
            var crm = new PortfoliodoKeyAccountRepresentantes(this.Organizacao, this.IsOffline);

            return(crm);
        }