Esempio n. 1
0
        private void VerificaIntervencao(Ocorrencia ocorrencia, IPluginExecutionContext context, object service)
        {
            if (ocorrencia.ProdutoId == null)
            {
                return;
            }

            if (new Domain.Servicos.RepositoryService(context.OrganizationName, context.IsExecutingOffline, service).Intervencao.ListarPor(ocorrencia).Count > 0)
            {
                return;
            }

            if (ocorrencia.Produto == null)
            {
                ocorrencia.Produto = (new Domain.Servicos.RepositoryService(context.OrganizationName, false, service)).Produto.Retrieve(ocorrencia.ProdutoId.Id);
            }

            if (ocorrencia.Produto.IntervencaoTecnica != null && ocorrencia.Produto.IntervencaoTecnica.Value)
            {
                if (new Domain.Servicos.RepositoryService(context.OrganizationName, context.IsExecutingOffline, service).Intervencao.ListarPor(ocorrencia).Count == 0)
                {
                    (new Domain.Servicos.RepositoryService(context.OrganizationName, false, service)).Intervencao.Create(
                        new IntervencaoTecnica(context.OrganizationName, false, service)
                    {
                        OcorrenciaId = new SDKore.DomainModel.Lookup(ocorrencia.Id, "incident"),
                        Nome         = "Produto da Ocorrência esta em Intervenção Técnica!",
                        RazaoStatus  = (int)IntervencaoTecnicaEnum.StatusCode.AguardandoAnalise
                    });
                }
                return;
            }

            LinhaComercial linhaComercial = (new Domain.Servicos.RepositoryService(context.OrganizationName, false, service)).LinhaComercial.ObterPor(ocorrencia.Produto);

            if (linhaComercial == null)
            {
                return;
            }

            if (linhaComercial.NumeroDeDiasParaReincidencia.HasValue && linhaComercial.NumeroDeDiasParaReincidencia.Value > 0 && ocorrencia.OcorrenciaPaiId != null)
            {
                var ocorrenciaPai = (new Domain.Servicos.RepositoryService(context.OrganizationName, false, service)).Ocorrencia.Retrieve(ocorrencia.OcorrenciaPaiId.Id);
                if (ocorrenciaPai.CriadoEm.Value.AddDays(linhaComercial.NumeroDeDiasParaReincidencia.Value) >= ocorrencia.CriadoEm.Value)
                {
                    if (new Domain.Servicos.RepositoryService(context.OrganizationName, context.IsExecutingOffline, service).Intervencao.ListarPor(ocorrencia).Count == 0)
                    {
                        (new Domain.Servicos.RepositoryService(context.OrganizationName, false, service)).Intervencao.Create(
                            new IntervencaoTecnica(context.OrganizationName, false, service)
                        {
                            OcorrenciaId = new SDKore.DomainModel.Lookup(ocorrencia.Id, "incident"),
                            Nome         = "Intervenção Técnica por reincidente!",
                            RazaoStatus  = (int)IntervencaoTecnicaEnum.StatusCode.AguardandoAnalise
                        });
                    }
                    return;
                }
            }
        }
Esempio n. 2
0
        public List <T> ListarPor(LinhaComercial linhaComercial)
        {
            var query = GetQueryExpression <T>(true);

            query.Distinct = true;
            query.AddLink("new_valor_servico", "new_defeitoid", "new_defeitoid");
            query.LinkEntities[0].LinkCriteria.Conditions.Add(new ConditionExpression("new_linha_unidade_negocioid", ConditionOperator.Equal, linhaComercial.Id));
            query.Orders.Add(new OrderExpression("new_name", OrderType.Ascending));
            return((List <T>) this.RetrieveMultiple(query).List);
        }
Esempio n. 3
0
        private void VerificaIntervencao(Ocorrencia ocorrencia, IPluginExecutionContext context)
        {
            #region Validações

            if (ocorrencia == null)
            {
                return;
            }

            if (ocorrencia.DadosProduto == null)
            {
                return;
            }

            if (ocorrencia.StatusDaOcorrencia != StatusDaOcorrencia.Aguardando_Analise && ocorrencia.StatusDaOcorrencia != StatusDaOcorrencia.Aguardando_Peça)
            {
                return;
            }

            if (DomainService.RepositoryIntervencao.ObterPor(ocorrencia, "new_intervencao_tecnicaid") != null)
            {
                return;
            }

            #endregion

            if (ocorrencia.DadosProduto.IntervencaoTecnica)
            {
                this.CriarIntervencaoTecnica(ocorrencia, "Produto da Ocorrência esta em Intervenção Técnica!");
                return;
            }

            LinhaComercial linhaComercial = DomainService.RepositoryLinhaComercialRepository.ObterPor(ocorrencia.DadosProduto, "new_dias_reincidencia", "new_numero_itens");

            if (linhaComercial == null)
            {
                return;
            }

            if (linhaComercial.NumeroDeDiasParaReincidencia > 0)
            {
                if (context.SharedVariables.Contains("dataCriacaoReincidente"))
                {
                    DateTime dataCriacaoReincidente = Convert.ToDateTime(context.SharedVariables["dataCriacaoReincidente"]);

                    if (dataCriacaoReincidente.AddDays(linhaComercial.NumeroDeDiasParaReincidencia) >= ocorrencia.DataDeCriacao)
                    {
                        CriarIntervencaoTecnica(ocorrencia, "Intervenção Técnica por reincidente!");
                        return;
                    }
                }
            }
        }
Esempio n. 4
0
        public T ObterPor(LinhaComercial linhaComercial)
        {
            var query = GetQueryExpression <T>(true);

            query.TopCount = 1;
            query.AddLink("new_linha_unidade_negocio", "itbc_estabelecimentoid", "new_estabelecimentoid");
            query.LinkEntities[0].LinkCriteria.Conditions.Add(new ConditionExpression("new_linha_unidade_negocioid", ConditionOperator.Equal, linhaComercial.Id));
            var colecao = this.RetrieveMultiple(query);

            if (colecao.List.Count == 0)
            {
                return(default(T));
            }
            return(colecao.List[0]);
        }
Esempio n. 5
0
        public void ListarSolucaoesPorFamilia()
        {
            LinhaComercial linha = new LinhaComercial();

            linha = new LinhaComercial()
            {
                Id = new Guid("404300a3-64a7-e611-80bd-0050568f3ab2")
            };

            Defeito defeitoFamilia = new Defeito()
            {
                Id = new Guid("c477bf9f-63a7-e611-80bd-0050568f3ab2")
            };

            var solucoes = (new CRM2013.Domain.Servicos.RepositoryService()).Solucao.ListarSolucaoesPorFamilia(linha.Id, defeitoFamilia);
        }
Esempio n. 6
0
        public T ObterPor(LinhaComercial linhaComercial)
        {
            var query = GetQueryExpression <T>(true);

            query.TopCount = 1;
            query.AddLink("new_linha_unidade_negocio", "itbc_canaldevendaid", "itbc_canal_vendaid");
            query.LinkEntities[0].LinkCriteria.Conditions.Add(new ConditionExpression("new_linha_unidade_negocioid", ConditionOperator.Equal, linhaComercial.Id));
            var result = this.RetrieveMultiple(query);

            if (result.List.Count > 0)
            {
                return(result.List[0]);
            }
            else
            {
                return(default(T));
            }
        }
Esempio n. 7
0
        private Ocorrencia ConverterOcorrencia(XmlDocument xml, Domain.Model.Conta assistenciaTecnica, string LoginDoPostoAutorizado, out string mensagem)
        {
            mensagem = String.Empty;
            string cpfCnpj = string.Empty;

            if (string.IsNullOrEmpty(xml.GetElementsByTagName("CPFouCNPJ")[0].InnerText))
            {
                mensagem += " \nO número do CNPJ/CPF do cliente deve ser informado";
            }
            else if (!string.IsNullOrEmpty(xml.GetElementsByTagName("CPFouCNPJ")[0].InnerText))
            {
                cpfCnpj = xml.GetElementsByTagName("CPFouCNPJ")[0].InnerText;
                cpfCnpj = cpfCnpj.Replace("-", "").Replace("/", "").Replace(".", "");

                if (cpfCnpj.Length == 11)
                {
                    cpfCnpj = String.Format(@"{0:000\.000\.000\-00}", Convert.ToInt64(cpfCnpj));
                }
                else
                {
                    cpfCnpj = String.Format(@"{0:00\.000\.000\/0000\-00}", Convert.ToInt64(cpfCnpj));
                }
            }

            if (string.IsNullOrEmpty(xml.GetElementsByTagName("Codigo")[0].InnerText) || string.IsNullOrEmpty(xml.GetElementsByTagName("NumeroDeSerie")[0].InnerText))
            {
                mensagem += " \nO número de série e o código do produto devem ser informados";
            }

            if (string.IsNullOrEmpty(xml.GetElementsByTagName("NumeroNF")[0].InnerText))
            {
                mensagem += " \nO número da nota fiscal deve ser informado";
            }

            Ocorrencia ocorrencia = new Ocorrencia(nomeOrganizacao, false)
            {
                Nome                   = "Assistência Técnica",
                Rascunho               = true,
                Origem                 = 200006 /*OS Integrada*/,
                TipoDeOcorrencia       = (int)TipoDeOcorrencia.Ordem_de_Serviço,
                RazaoStatus            = (int)StatusDaOcorrencia.Aguardando_Analise,
                SolicitantePortal      = LoginDoPostoAutorizado,
                PrioridadeValue        = (int)TipoDePrioridade.Alta,
                DataDeAberturaDigitada = DateTime.Now,
                ProdutosDoCliente      = xml.GetElementsByTagName("NumeroDeSerie")[0].InnerText,
                AparenciaDoProduto     = xml.GetElementsByTagName("AparenciaDoProduto")[0].InnerText,
                AcessoriosOpcionais    = xml.GetElementsByTagName("AcessoriosOpcionais")[0].InnerText,
                RetiradoPorNome        = xml.GetElementsByTagName("RetiradoPorNome")[0].InnerText,
                RetiradoPorCPF         = xml.GetElementsByTagName("RetiradoPorCPF")[0].InnerText,
                AcaoId                 = new Lookup(new Guid(SDKore.Configuration.ConfigurationManager.GetSettingValue("guid_acao_portal_astec")), "new_acao"),
                AssuntoId              = new Lookup(new Guid(SDKore.Configuration.ConfigurationManager.GetSettingValue("guid_assunto_portal_astec")), "subject"),
                ClienteOS              = new Domain.Model.Contato(nomeOrganizacao, false)
                {
                    Nome                 = xml.GetElementsByTagName("NomeCliente")[0].InnerText,
                    NomeCompleto         = xml.GetElementsByTagName("NomeCliente")[0].InnerText,
                    PrimeiroNome         = (xml.GetElementsByTagName("NomeCliente")[0].InnerText.Contains(" ") ? xml.GetElementsByTagName("NomeCliente")[0].InnerText.Substring(0, xml.GetElementsByTagName("NomeCliente")[0].InnerText.IndexOf(" ")) : xml.GetElementsByTagName("NomeCliente")[0].InnerText),
                    Sobrenome            = (xml.GetElementsByTagName("NomeCliente")[0].InnerText.Contains(" ") ? xml.GetElementsByTagName("NomeCliente")[0].InnerText.Substring(xml.GetElementsByTagName("NomeCliente")[0].InnerText.IndexOf(" ") + 1, xml.GetElementsByTagName("NomeCliente")[0].InnerText.Length - xml.GetElementsByTagName("NomeCliente")[0].InnerText.IndexOf(" ") - 1) : xml.GetElementsByTagName("NomeCliente")[0].InnerText),
                    CpfCnpj              = cpfCnpj,
                    Email1               = xml.GetElementsByTagName("EmailCliente")[0].InnerText,
                    Endereco1Rua         = xml.GetElementsByTagName("Logradouro")[0].InnerText,
                    Endereco1Numero      = xml.GetElementsByTagName("Numero")[0].InnerText,
                    Endereco1Complemento = xml.GetElementsByTagName("Complemento")[0].InnerText,
                    Endereco1Bairro      = xml.GetElementsByTagName("Bairro")[0].InnerText,
                    Endereco1Municipio   = xml.GetElementsByTagName("Cidade")[0].InnerText,
                    Endereco1CEP         = xml.GetElementsByTagName("Cep")[0].InnerText,
                    Endereco1Estado      = xml.GetElementsByTagName("Uf")[0].InnerText,
                    TelefoneComercial    = xml.GetElementsByTagName("TelefonePrincipalCliente")[0].InnerText
                }
            };
            Municipio cidade = new Domain.Servicos.RepositoryService().Municipio.ObterPor(xml.GetElementsByTagName("Uf")[0].InnerText, xml.GetElementsByTagName("Cidade")[0].InnerText);

            if (cidade != null)
            {
                ocorrencia.ClienteOS.Endereco1Municipioid = new Lookup(cidade.Id, "itbc_municipios");
                if (cidade.Estadoid != null)
                {
                    ocorrencia.ClienteOS.Endereco1Estadoid = cidade.Estadoid;
                }
            }

            #region Autorizada

            ocorrencia.Autorizada               = assistenciaTecnica;
            ocorrencia.Autorizada.Nome          = LoginDoPostoAutorizado;
            ocorrencia.Autorizada.NomeAbreviado = LoginDoPostoAutorizado;
            ocorrencia.AutorizadaId             = new Lookup(assistenciaTecnica.Id, "account");

            #endregion

            if (xml.GetElementsByTagName("Observacoes")[0].InnerText.Length < 4000)
            {
                ocorrencia.DescricaoDaMensagemDeIntegracao = xml.GetElementsByTagName("Observacoes")[0].InnerText;
            }
            else
            {
                mensagem += " \nNão foi possível converter Observacoes, o campo deve conter menos de 4000 caracteres";
            }

            if (xml.GetElementsByTagName("DefeitoAlegado")[0].InnerText.Length < 4000)
            {
                ocorrencia.DefeitoAlegado = xml.GetElementsByTagName("DefeitoAlegado")[0].InnerText;
            }
            else
            {
                mensagem += " \nNão foi possível converter DefeitoAlegado, o campo deve conter menos de 4000 caracteres";
            }

            if (xml.GetElementsByTagName("OSEmLote")[0].InnerText == "OK")
            {
                ocorrencia.Tipo = "Lote";
            }

            if (!string.IsNullOrEmpty(xml.GetElementsByTagName("DataDeAberturaInformada")[0].InnerText))
            {
                try { ocorrencia.DataOrigem = Convert.ToDateTime(xml.GetElementsByTagName("DataDeAberturaInformada")[0].InnerText); }
                catch { mensagem += " \nErro ao tentar converter DataDeAberturaInformada para data"; }
            }
            else
            {
                ocorrencia.DataOrigem = DateTime.Now;
            }

            if (!string.IsNullOrEmpty(xml.GetElementsByTagName("DataDeConsertoInformada")[0].InnerText))
            {
                try { ocorrencia.DataDeConsertoDigitada = Convert.ToDateTime(xml.GetElementsByTagName("DataDeConsertoInformada")[0].InnerText); }
                catch { mensagem += " \nErro ao tentar converter DataDeConsertoInformada para data"; }
                ocorrencia.DataDeConsertoInformada = DateTime.Now;
            }

            if (!string.IsNullOrEmpty(xml.GetElementsByTagName("DataDeEntregaClienteInformada")[0].InnerText))
            {
                try { ocorrencia.DataDeEntregaClienteInformada = Convert.ToDateTime(xml.GetElementsByTagName("DataDeEntregaClienteInformada")[0].InnerText); }
                catch { mensagem += " \nErro ao tentar converter DataDeEntregaClienteInformada para data"; }
                ocorrencia.DataDeEntregaClienteDigitada = DateTime.Now;
            }

            #region Nota Fiscal
            ocorrencia.NotaFiscalFatura = new Domain.Model.Fatura(nomeOrganizacao, false)
            {
                IDFatura = xml.GetElementsByTagName("NumeroNF")[0].InnerText,
                Cliente  = new Domain.Model.Conta(nomeOrganizacao, false)
                {
                    Nome          = xml.GetElementsByTagName("RazaoSocial")[0].InnerText,
                    CpfCnpj       = xml.GetElementsByTagName("Cnpj")[0].InnerText,
                    Telefone      = xml.GetElementsByTagName("TelefonePrincipal")[0].InnerText,
                    NomeAbreviado = (xml.GetElementsByTagName("NomeClienteNF")[0].InnerText != "") ? xml.GetElementsByTagName("NomeClienteNF")[0].InnerText : xml.GetElementsByTagName("NomeCliente")[0].InnerText
                                    //CpfCnpj = (!String.IsNullOrEmpty(xml.GetElementsByTagName("CPFCNPJClienteNF")[0].InnerText)) ? xml.GetElementsByTagName("CPFCNPJClienteNF")[0].InnerText : xml.GetElementsByTagName("CPFouCNPJ")[0].InnerText
                }
            };
            ocorrencia.NumeroNfConsumido                   = xml.GetElementsByTagName("NumeroNF")[0].InnerText;
            ocorrencia.NomeDaLojaDoAtendimento             = xml.GetElementsByTagName("RazaoSocial")[0].InnerText;
            ocorrencia.NomeConstadoNaNotaFiscalDeCompra    = (xml.GetElementsByTagName("NomeClienteNF")[0].InnerText != "") ? xml.GetElementsByTagName("NomeClienteNF")[0].InnerText : xml.GetElementsByTagName("NomeCliente")[0].InnerText;
            ocorrencia.CpfCnpjConstadoNaNotaFiscalDeCompra = (!String.IsNullOrEmpty(xml.GetElementsByTagName("CPFCNPJClienteNF")[0].InnerText)) ? xml.GetElementsByTagName("CPFCNPJClienteNF")[0].InnerText : xml.GetElementsByTagName("CPFouCNPJ")[0].InnerText;
            ocorrencia.CnpjDaLojaDoAtendimento             = xml.GetElementsByTagName("Cnpj")[0].InnerText;
            ocorrencia.TelefoneDaLojaDoAtendimento         = xml.GetElementsByTagName("TelefonePrincipal")[0].InnerText;

            if (!String.IsNullOrEmpty(xml.GetElementsByTagName("DataDeCompra")[0].InnerText))
            {
                try
                {
                    ocorrencia.NotaFiscalFatura.DataEmissao   = Convert.ToDateTime(xml.GetElementsByTagName("DataDeCompra")[0].InnerText);
                    ocorrencia.DataConstadoNotaFiscalDeCompra = Convert.ToDateTime(xml.GetElementsByTagName("DataDeCompra")[0].InnerText);
                }
                catch { mensagem += " \nErro ao tentar converter DataDeCompra para data"; }
            }
            #endregion

            #region Produto Principal

            string         numeroSerie   = xml.GetElementsByTagName("NumeroDeSerie")[0].InnerText;
            string         codigoProduto = xml.GetElementsByTagName("Codigo")[0].InnerText;
            List <Product> produtos      = (new Domain.Servicos.RepositoryService()).Produto.BuscarEstruturaDoProdutoPor(numeroSerie, codigoProduto);

            if (produtos.Count > 0)
            {
                ocorrencia.Produto = produtos[0];

                Product produtoCRM = (new Domain.Servicos.RepositoryService()).Produto.ObterPorNumero(ocorrencia.Produto.Codigo);
                if (produtoCRM == null)
                {
                    throw new ArgumentException("Produto não foi encontrado para Número de Série ou Código informado. (CRM)");
                }

                ocorrencia.Produto.Id = produtoCRM.Id;
                ocorrencia.ProdutoId  = new Lookup(produtoCRM.Id, "product");

                OcorrenciaService ocorrenciaService = new Domain.Servicos.OcorrenciaService(nomeOrganizacao, false);
                ocorrenciaService.Ocorrencia = ocorrencia;
                ocorrenciaService.ValidaAberturaOcorrenciaASTEC();

                bool UrlImagemNota = string.IsNullOrEmpty(xml.GetElementsByTagName("URLImagemNota")[0].InnerText);

                LinhaComercial linhaComercial = (new Domain.Servicos.RepositoryService()).LinhaComercial.ObterPor(ocorrencia.Produto);

                if (linhaComercial != null)
                {
                    if (UrlImagemNota && linhaComercial.ObrigatorioEnviarNotaFiscal.HasValue && linhaComercial.ObrigatorioEnviarNotaFiscal.Value && !ocorrencia.Tipo.Equals("Lote"))
                    {
                        mensagem += " \nObrigatório o envio do anexo da Nota Fiscal";
                    }
                }

                ocorrencia.DataFabricacaoProduto = ocorrencia.Produto.DataFabricacaoProduto;
            }
            else
            {
                mensagem += " \nProduto não foi encontrado para Numero de Serie ou Codigo informado";
            }

            #endregion

            return(ocorrencia);
        }
Esempio n. 8
0
        private void VerificaIntervencao(Ocorrencia ocorrencia, IPluginExecutionContext context)
        {
            #region Validações

            if (ocorrencia == null)
            {
                return;
            }

            if (ocorrencia.DadosProduto == null)
            {
                return;
            }

            if (ocorrencia.StatusDaOcorrencia != StatusDaOcorrencia.Aguardando_Analise && ocorrencia.StatusDaOcorrencia != StatusDaOcorrencia.Aguardando_Peça)
            {
                return;
            }

            if (DomainService.RepositoryIntervencao.ListarPor(ocorrencia).Count > 0)
            {
                return;
            }

            #endregion


            LinhaComercial linhaComercial = DomainService.RepositoryLinhaComercialRepository.ObterPor(ocorrencia.DadosProduto, "new_dias_reincidencia", "new_numero_itens");


            if (linhaComercial != null && linhaComercial.NumeroDeDiasParaReincidencia > 0)
            {
                if (context.SharedVariables.Contains("dataCriacaoReincidente"))
                {
                    DateTime dataCriacaoReincidente = Convert.ToDateTime(context.SharedVariables["dataCriacaoReincidente"]);
                    if (dataCriacaoReincidente.AddDays(linhaComercial.NumeroDeDiasParaReincidencia) >= ocorrencia.DataDeCriacao)
                    {
                        CriarIntervencaoTecnica(ocorrencia, "Intervenção Técnica por reincidente.");
                        return;
                    }
                }
            }


            if (ocorrencia.DadosProduto.IntervencaoTecnica)
            {
                this.CriarIntervencaoTecnica(ocorrencia, "Produto da Ocorrência esta em Intervenção Técnica!");
                return;
            }

            List <Diagnostico> diagnosticos = DomainService.RepositoryDiagnostico.ListarPor(ocorrencia, "new_qtd_solicitada", "new_geratroca");
            int quantidade = 0;
            foreach (var item in diagnosticos)
            {
                if ((bool)item.GeraTroca && item.QuantidadeSolicitada > 0)
                {
                    quantidade += item.QuantidadeSolicitada;
                }
            }

            if (linhaComercial != null)
            {
                if (linhaComercial.NumeroDeItensParaReincidencia > 0 && quantidade >= linhaComercial.NumeroDeItensParaReincidencia)
                {
                    CriarIntervencaoTecnica(ocorrencia, "Intervenção Técnica por quantidade de itens.");
                    return;
                }
            }
        }
Esempio n. 9
0
        private Intelbras.Message.Helper.MSG0088 DefinirPropriedades(Product crm)
        {
            Intelbras.Message.Helper.MSG0088 xml = new Pollux.MSG0088(Domain.Enum.Sistemas.RetornaSistema(Domain.Enum.Sistemas.Sistema.CRM), Helper.Truncate(crm.Nome, 40));

            if (crm.Codigo != null)
            {
                xml.CodigoProduto = crm.Codigo;
            }

            if (crm.DataUltAlteracaoPVC.HasValue)
            {
                xml.DataAlteracaoPrecoVenda = crm.DataUltAlteracaoPVC.Value.ToLocalTime();
            }

            if (crm.Showroom.HasValue)
            {
                xml.ShowRoom = crm.Showroom;
            }

            if (crm.Nome != null)
            {
                xml.Nome = crm.Nome;
            }

            if (crm.Descricao != null)
            {
                xml.Descricao = crm.Descricao;
            }

            if (crm.PesoEstoque != null)
            {
                xml.PesoEstoque = crm.PesoEstoque;
            }

            xml.Situacao = (crm.Status.HasValue ? crm.Status.Value : (int)Enum.Produto.StateCode.ativo);

            if (crm.TipoProdutoid.HasValue)
            {
                xml.TipoProduto = crm.TipoProdutoid.Value;
            }

            if (crm.GrupoEstoque != null)
            {
                GrupoEstoque grpEstoq = new Servicos.GrupoEstoqueService(this.Organizacao, this.IsOffline).ObterPor(crm.GrupoEstoque.Id);
                if (grpEstoq != null && grpEstoq.Codigo.HasValue)
                {
                    xml.GrupoEstoque = grpEstoq.Codigo.Value;
                }
            }

            if (crm.UnidadeNegocio != null)
            {
                UnidadeNegocio unidadeNegocio = new Servicos.UnidadeNegocioService(this.Organizacao, this.IsOffline).BuscaUnidadeNegocio(crm.UnidadeNegocio.Id);
                if (unidadeNegocio != null)
                {
                    xml.UnidadeNegocio     = unidadeNegocio.ChaveIntegracao;
                    xml.NomeUnidadeNegocio = unidadeNegocio.Nome;
                }
            }

            if (crm.Segmento != null)
            {
                Model.Segmento segmento = new Servicos.SegmentoService(this.Organizacao, this.IsOffline).ObterPor(crm.Segmento.Id);
                if (segmento != null && !String.IsNullOrEmpty(segmento.CodigoSegmento))
                {
                    xml.Segmento     = segmento.CodigoSegmento;
                    xml.NomeSegmento = segmento.Nome;
                }
            }

            if (crm.FamiliaProduto != null)
            {
                Model.FamiliaProduto familiaProduto = new Servicos.FamiliaProdutoService(this.Organizacao, this.IsOffline).ObterPor(crm.FamiliaProduto.Id);
                if (familiaProduto != null && !String.IsNullOrEmpty(familiaProduto.Codigo))
                {
                    xml.Familia = familiaProduto.Codigo;
                }
            }

            if (crm.SubfamiliaProduto != null)
            {
                SubfamiliaProduto subFamiliaProduto = new Servicos.SubFamiliaProdutoService(this.Organizacao, this.IsOffline).ObterPor(crm.SubfamiliaProduto.Id);
                if (subFamiliaProduto != null && !String.IsNullOrEmpty(subFamiliaProduto.Codigo))
                {
                    xml.SubFamilia = subFamiliaProduto.Codigo;
                }
            }


            if (crm.Origem != null)
            {
                Origem Origem = new Servicos.OrigemService(this.Organizacao, this.IsOffline).ObterPor(crm.Origem.Id);
                if (Origem != null && !String.IsNullOrEmpty(Origem.Codigo))
                {
                    xml.Origem = Origem.Codigo;
                }
            }


            if (crm.UnidadePadrao != null)
            {
                Unidade unidade = new Servicos.UnidadeService(this.Organizacao, this.IsOffline).BuscaPor(crm.UnidadePadrao.Id);
                if (unidade != null && !String.IsNullOrEmpty(unidade.Nome))
                {
                    xml.UnidadeMedida = unidade.Nome;
                }
            }

            if (crm.GrupoUnidades != null)
            {
                GrupoUnidade grupoUnidade = new Servicos.GrupoUnidadeMedidaService(this.Organizacao, this.IsOffline).ObterPor(crm.GrupoUnidades.Id);
                if (grupoUnidade != null)
                {
                    xml.GrupoUnidadeMedida = grupoUnidade.Nome;
                }
            }

            if (crm.FamiliaComercial != null)
            {
                FamiliaComercial familiaComercial = new Servicos.FamiliaComercialService(this.Organizacao, this.IsOffline).ObterPor(crm.FamiliaComercial.Id);
                if (familiaComercial != null && !String.IsNullOrEmpty(familiaComercial.Codigo))
                {
                    xml.FamiliaComercial = familiaComercial.Codigo;
                }
            }

            if (crm.QuantidadeMultiplaProduto.HasValue)
            {
                xml.QuantidadeMultipla = crm.QuantidadeMultiplaProduto.Value;
            }

            if (crm.NaturezaProduto != null)
            {
                xml.NaturezaProduto = crm.NaturezaProduto.Value;
            }


            if (crm.FamiliaMaterial != null)
            {
                FamiliaMaterial familiaMaterial = new Servicos.FamiliaMaterialService(this.Organizacao, this.IsOffline).ObterPor(crm.FamiliaMaterial.Id);
                if (familiaMaterial != null && !String.IsNullOrEmpty(familiaMaterial.Codigo))
                {
                    xml.FamiliaMaterial = familiaMaterial.Codigo;
                }
            }

            if (crm.FamiliaMaterial != null)
            {
                FamiliaMaterial familiaMaterial = new Servicos.FamiliaMaterialService(this.Organizacao, this.IsOffline).ObterPor(crm.FamiliaMaterial.Id);
                if (familiaMaterial != null && !String.IsNullOrEmpty(familiaMaterial.Codigo))
                {
                    xml.FamiliaMaterial = familiaMaterial.Codigo;
                }
            }


            if (crm.ListaPrecoPadrao != null)
            {
                xml.ListaPreco = crm.ListaPrecoPadrao.Name;
            }

            if (crm.Moeda != null)
            {
                xml.Moeda = crm.Moeda.Name;
            }

            if (crm.QuantidadeDecimal.HasValue)
            {
                xml.QuantidadeDecimal = crm.QuantidadeDecimal.Value;
            }

            if (crm.ExigeTreinamento.HasValue)
            {
                xml.ExigeTreinamento = crm.ExigeTreinamento.Value;
            }

            if (crm.RebatePosVendaAtivado.HasValue)
            {
                xml.RebateAtivado = crm.RebatePosVendaAtivado.Value;
            }

            if (crm.NomeFornecedor != null)
            {
                xml.Fabricante = crm.NomeFornecedor;
            }

            if (crm.NumeroPecaFabricante != null)
            {
                xml.NumeroPecaFabricante = crm.NumeroPecaFabricante;
            }

            if (crm.VolumeEstoque != null)
            {
                xml.VolumeEstoque = crm.VolumeEstoque;
            }

            if (crm.Complemento != null)
            {
                xml.ComplementoProduto = crm.Complemento;
            }

            if (crm.Url != null)
            {
                xml.URL = crm.Url;
            }

            if (crm.QuantidadeDisponivel.HasValue)
            {
                xml.QuantidadeDisponivel = crm.QuantidadeDisponivel.Value;
            }

            if (crm.Fornecedor != null)
            {
                xml.Fornecedor = crm.Fornecedor;
            }

            if (crm.ConsideraOrcamentoMeta.HasValue)
            {
                xml.ConsiderarOrcamentoMeta = crm.ConsideraOrcamentoMeta.Value;
            }

            if (crm.FaturamentoOutroProduto.HasValue)
            {
                xml.FaturamentoOutroProduto = crm.FaturamentoOutroProduto.Value;
            }

            xml.TemMensagem = crm.TemMensagem;
            if (crm.TemMensagem == true)
            {
                if (crm.Mensagem != null && crm.Mensagem != String.Empty)
                {
                    xml.DescricaoMensagem = crm.Mensagem;
                }
            }
            else
            {
                xml.TemMensagem = false;
            }

            xml.AliquotaIPI = crm.PercentualIPI;

            xml.EAN = crm.EAN;
            xml.NCM = crm.NCM;

            xml.CustoPadrao             = (crm.CustoAtual.HasValue) ? crm.CustoAtual.Value : 0;
            xml.CustoAtual              = crm.CustoAtual;
            xml.BloquearComercializacao = crm.BloquearComercializacao;
            xml.ComercializadoForaKit   = crm.ComercializadoForaKit;
            xml.PoliticaPosVendas       = crm.PoliticaPosVenda;

            if (crm.PoliticaPosVenda != null)
            {
                xml.DescricaoPoliticaPosVendas = DescricaoPoliticaPosVenda(crm.PoliticaPosVenda.Value);
            }

            xml.TempoGarantia                = crm.TempoGarantia;
            xml.EKit                         = crm.EKit;
            xml.PossuiSubstituto             = crm.PossuiSubstituto;
            xml.PassivelSolicitacaoBeneficio = crm.PermitirEmSolBenef;

            xml.Backup           = crm.BackupDistribuidor;
            xml.BackupRevendas   = crm.BackupRevenda;
            xml.ShowRoomRevendas = crm.ShowroomRevenda;


            if (!String.IsNullOrEmpty(crm.DepositoPadrao))
            {
                xml.DepositoPadrao = crm.DepositoPadrao;
            }

            if (crm.CodigoTipoDespesa.HasValue)
            {
                xml.CodigoTipoDespesa = crm.CodigoTipoDespesa;
            }

            if (crm.DestaqueNCM.HasValue)
            {
                xml.DestaqueNCM = crm.DestaqueNCM;
            }

            if (!String.IsNullOrEmpty(crm.NVE))
            {
                xml.NVE = crm.NVE;
            }

            if (!String.IsNullOrEmpty(crm.CodigoUnidadeFamilia))
            {
                xml.CodigoUnidadeFamilia = crm.CodigoUnidadeFamilia;
            }

            if (crm.ProdutoSubstituto != null)
            {
                var produtoSubstituto = RepositoryService.Produto.Retrieve(crm.ProdutoSubstituto.Id, "productnumber");

                if (produtoSubstituto == null)
                {
                    throw new ArgumentException("(CRM) Produto substituto não encontrado!");
                }

                xml.CodigoProdutoSubstituto = produtoSubstituto.Codigo;
            }

            xml.TipoItem = crm.TipoItem;

            if (crm.LinhaProduto != null)
            {
                LinhaComercial linhaProduto = (new CRM2013.Domain.Servicos.RepositoryService()).LinhaComercial.Retrieve(crm.LinhaProduto.Id);
                if (linhaProduto != null)
                {
                    xml.LinhaProduto     = linhaProduto.Id.ToString();
                    xml.NomeLinhaProduto = linhaProduto.Nome;
                }
            }

            return(xml);
        }
Esempio n. 10
0
        private void VerificaIntervencao(Diagnostico diagnostico, IPluginExecutionContext context)
        {
            if (diagnostico.Ocorrencia == null)
            {
                return;
            }

            if (diagnostico.Ocorrencia.DadosProduto == null)
            {
                return;
            }

            if (DomainService.RepositoryIntervencao.ListarPor(diagnostico.Ocorrencia).Count > 0)
            {
                return;
            }

            var statusOcorrencia = diagnostico.Ocorrencia.StatusDaOcorrencia;

            if (statusOcorrencia != StatusDaOcorrencia.Aguardando_Analise && statusOcorrencia != StatusDaOcorrencia.Aguardando_Peça)
            {
                return;
            }


            if ((bool)diagnostico.GeraTroca && diagnostico.QuantidadeSolicitada > 0 &&
                diagnostico.DadosProduto != null && diagnostico.DadosProduto.IntervencaoTecnica)
            {
                this.CriarIntervencaoTecnica(diagnostico, "Produto do diagnostico esta em Intervenção Técnica.");
                return;
            }


            LinhaComercial linhaComercial = DomainService.RepositoryLinhaComercialRepository.ObterPor(diagnostico.Ocorrencia.DadosProduto, "new_dias_reincidencia", "new_numero_itens");

            if (linhaComercial == null)
            {
                return;
            }

            if (linhaComercial.NumeroDeDiasParaReincidencia <= 0)
            {
                return;
            }

            DateTime dataCriacaoReincidente = DomainService.RepositoryOcorrencia.ObterDataDeCriacaoDoReincidentePorDiagnostico(diagnostico.Id);

            if (dataCriacaoReincidente != DateTime.MinValue)
            {
                if (dataCriacaoReincidente.AddDays(diagnostico.Ocorrencia.DadosProduto.DadosFamiliaComercial.LinhaComercial.NumeroDeDiasParaReincidencia) >= diagnostico.Ocorrencia.DataDeCriacao)
                {
                    CriarIntervencaoTecnica(diagnostico, "Intervenção Técnica por reincidente.");
                    return;
                }
            }

            List <Diagnostico> diagnosticos = DomainService.RepositoryDiagnostico.ListarPor(diagnostico.Ocorrencia, "new_qtd_solicitada", "new_geratroca");
            int quantidade = 0;

            foreach (var item in diagnosticos)
            {
                if ((bool)item.GeraTroca && item.QuantidadeSolicitada > 0)
                {
                    quantidade += item.QuantidadeSolicitada;
                }
            }

            if (quantidade >= linhaComercial.NumeroDeItensParaReincidencia)
            {
                CriarIntervencaoTecnica(diagnostico, "Intervenção Técnica por quantidade de itens.");
                return;
            }
        }