public string Executar(string mensagem, string numeroMensagem, Domain.Model.Usuario usuario) { usuarioIntegracao = usuario; var objeto = this.DefinirPropriedades(this.CarregarMensagem <Pollux.MSG0042>(mensagem)); if (!resultadoPersistencia.Sucesso) { retorno.Add("Resultado", resultadoPersistencia); return(CriarMensagemRetorno <Pollux.MSG0042R1>(numeroMensagem, retorno)); } objeto = new Intelbras.CRM2013.Domain.Servicos.EstabelecimentoService(this.Organizacao, this.IsOffline).Persistir(objeto); if (objeto == null) { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Erro de persistência!"; } else { resultadoPersistencia.Sucesso = true; resultadoPersistencia.Mensagem = "Integração ocorrida com sucesso"; } retorno.Add("Resultado", resultadoPersistencia); return(CriarMensagemRetorno <Pollux.MSG0042R1>(numeroMensagem, retorno)); }
public string Executar(string mensagem, string numeroMensagem, Domain.Model.Usuario usuario) { //Trace.Add("Mensagem " + numeroMensagem + " XML: {0}", mensagem); usuarioIntegracao = usuario; var xml = this.CarregarMensagem <Pollux.MSG0102>(mensagem); //Na dll está errado, o parametro precisa ser nullable pra poder retornar todos resultados, por enquanto deixei assim para testar //if(xml.CodigoEstabelecimento.HasValue()) if (xml.CodigoEstabelecimento != 0) {//Retorna registros com base no estabelecimento //Pegamos o estabelecimento com base no codigo do erp dele Estabelecimento ObjEstabelecimento = new Intelbras.CRM2013.Domain.Servicos.EstabelecimentoService(this.Organizacao, this.IsOffline).BuscaEstabelecimentoPorCodigo(xml.CodigoEstabelecimento); if (ObjEstabelecimento == null) { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Estabelecimento não encontrado."; retorno.Add("Resultado", resultadoPersistencia); return(CriarMensagemRetorno <Pollux.MSG0102R1>(numeroMensagem, retorno)); } //CodigoEstabelecimento esta como int na dll,deveria ser Guid, mais um prob na dll, tive que fazer uma gambiarra pra poder testar ele List <ProdutoEstabelecimento> LstProdutosEstab = new Intelbras.CRM2013.Domain.Servicos.ProdutoEstabelecimentoService(this.Organizacao, this.IsOffline).ListarPorEstabelecimento((Guid)ObjEstabelecimento.ID); if (LstProdutosEstab != null && LstProdutosEstab.Count > 0) { //para nao precisar refazer a service codigoEstabelecimento = xml.CodigoEstabelecimento; List <Pollux.Entities.ProdutoItem> ProdutosEst = this.ConverteLista(LstProdutosEstab); resultadoPersistencia.Sucesso = true; retorno.Add("ProdutosItens", ProdutosEst); } else { resultadoPersistencia.Sucesso = true; } } else {//Retorna todos registros List <ProdutoEstabelecimento> LstProdutosEstab = new Intelbras.CRM2013.Domain.Servicos.ProdutoEstabelecimentoService(this.Organizacao, this.IsOffline).ListarTodos(); if (LstProdutosEstab != null) { resultadoPersistencia.Sucesso = true; resultadoPersistencia.Mensagem = ""; resultadoPersistencia.CodigoErro = ""; retorno.Add("ProdutosItens", LstProdutosEstab); } else { resultadoPersistencia.Sucesso = true; resultadoPersistencia.Mensagem = "Registros não encontrados."; } } retorno.Add("Resultado", resultadoPersistencia); return(CriarMensagemRetorno <Pollux.MSG0102R1>(numeroMensagem, retorno)); }
public Fatura DefinirPropriedades(Intelbras.Message.Helper.MSG0094 xml) { Fatura crm = new Fatura(this.Organizacao, this.IsOffline); if (!String.IsNullOrEmpty(xml.NumeroNotaFiscal)) { crm.NumeroNF = xml.NumeroNotaFiscal; } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "NumeroNotaFiscal não enviado."; return(crm); } crm.Serie = xml.NumeroSerie; crm.ClienteId = new Lookup(new Guid(xml.CodigoClienteCRM), xml.TipoObjetoCliente); crm.ChaveIntegracao = xml.ChaveIntegracao; //NumeroPedido.ToString(); if (xml.NumeroPedido != null) { Pedido pedido = new Servicos.PedidoService(this.Organizacao, this.IsOffline).BuscaPedidoEMS(xml.NumeroPedido.ToString()); if (pedido != null) { crm.PedidoCRM = new Lookup(pedido.ID.Value, ""); Fatura fatura = new Servicos.FaturaService(this.Organizacao, this.IsOffline).ObterFaturaPorPedidoEMS(xml.NumeroPedido.ToString()); if (fatura != null) { crm.ID = fatura.ID.Value; } } } if (!String.IsNullOrEmpty(xml.NumeroPedidoCliente)) { crm.PedidoCliente = xml.NumeroPedidoCliente; } else { crm.AddNullProperty("PedidoCliente"); } if (!String.IsNullOrEmpty(xml.Descricao)) { crm.Descricao = xml.Descricao; } else { crm.AddNullProperty("Descricao"); } //Service Estabelecimento Estabelecimento ObjEstabelecimento = new Intelbras.CRM2013.Domain.Servicos.EstabelecimentoService(this.Organizacao, this.IsOffline).BuscaEstabelecimentoPorCodigo(xml.Estabelecimento.Value); if (ObjEstabelecimento != null) { crm.Estabelecimento = new Lookup((Guid)ObjEstabelecimento.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador do Estabelecimento não encontrado."; return(crm); } //Service Condição Pagamento CondicaoPagamento ObjCondicaoPagamento = null; if (xml.CondicaoPagamento.HasValue) { ObjCondicaoPagamento = new Intelbras.CRM2013.Domain.Servicos.CondicaoPagamentoService(this.Organizacao, this.IsOffline).BuscaCondicaoPagamentoPorCodigo(xml.CondicaoPagamento.Value); if (ObjCondicaoPagamento != null) { crm.CondicaoPagamento = new Lookup((Guid)ObjCondicaoPagamento.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Condição de Pagamento não encontrado."; return(crm); } } else { crm.AddNullProperty("CondicaoPagamento"); } crm.NomeAbreviado = xml.NomeAbreviadoCliente; //Service Natureza Operação NaturezaOperacao ObjNaturezaOperacao = new Intelbras.CRM2013.Domain.Servicos.NaturezaOperacaoService(this.Organizacao, this.IsOffline).BuscaNaturezaOperacaoPorCodigo(xml.NaturezaOperacao); if (ObjNaturezaOperacao != null) { crm.NaturezaOperacao = new Lookup((Guid)ObjNaturezaOperacao.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Natureza de Operação não encontrado."; return(crm); } //Service Moeda Moeda ObjMoeda = new Intelbras.CRM2013.Domain.Servicos.MoedaService(this.Organizacao, this.IsOffline).BuscaMoedaPorCodigo(xml.Moeda); if (ObjMoeda != null) { crm.Moeda = new Lookup((Guid)ObjMoeda.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Moeda não encontrado."; return(crm); } //Service para resolver o status if (System.Enum.IsDefined(typeof(Enum.Fatura.Status), xml.SituacaoNota)) { crm.Status = xml.SituacaoNota; } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Situação da nota não encontrado."; return(crm); } if (System.Enum.IsDefined(typeof(Enum.Fatura.RazaoStatus), xml.SituacaoEntrega)) { crm.RazaoStatus = xml.SituacaoEntrega; } crm.DataEmissao = xml.DataEmissao; if (xml.DataSaida.HasValue) { crm.DataSaida = xml.DataSaida; } else { crm.AddNullProperty("DataSaida"); } if (xml.DataEntrega.HasValue) { crm.DataEntrega = xml.DataEntrega; } else { crm.AddNullProperty("DataEntrega"); } if (xml.DataConfirmacao != null) { crm.DataConfirmacao = xml.DataConfirmacao; } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "DataConfirmacao não enviada."; return(crm); } if (xml.DataCancelamento.HasValue) { crm.DataCancelamento = xml.DataCancelamento; } else { crm.AddNullProperty("DataCancelamento"); } if (xml.DataConclusao.HasValue) { crm.DataConclusao = xml.DataConclusao; } else { crm.AddNullProperty("DataConclusao"); } crm.ValorFrete = xml.ValorFrete; crm.PesoLiquido = xml.PesoLiquido; crm.PesoBruto = xml.PesoBruto; if (!String.IsNullOrEmpty(xml.Observacao)) { crm.Observacao = xml.Observacao; } else { crm.AddNullProperty("Observacao"); } crm.Volume = xml.Volume.ToString(); crm.BaseICMS = xml.ValorBaseICMS; crm.ValorICMS = xml.ValorICMS; crm.ValorIPI = xml.ValorIPI; crm.BaseSubstTributaria = xml.ValorBaseSubstituicaoTributaria; crm.ValorSubstituicao = xml.ValorSubstituicaoTributaria; crm.ClienteRetira = xml.RetiraNoLocal; if (xml.MetodoEntrega.HasValue) { crm.MetodoEntrega = xml.MetodoEntrega; } else { crm.AddNullProperty("MetodoEntrega"); } //Service Transportadora Transportadora ObjTransportadora = new Intelbras.CRM2013.Domain.Servicos.TransportadoraService(this.Organizacao, this.IsOffline).ObterPorCodigoTransportadora(xml.Transportadora.Value); if (ObjTransportadora != null) { crm.Transportadora = new Lookup((Guid)ObjTransportadora.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Transportadora não encontrado."; return(crm); } crm.Frete = xml.Frete; //crm.CondicoesFrete = xml.tipo; if (!String.IsNullOrEmpty(xml.TelefoneCobranca)) { crm.TelefoneCobranca = xml.TelefoneCobranca; } else { crm.AddNullProperty("TelefoneCobranca"); } if (!String.IsNullOrEmpty(xml.FaxCobranca)) { crm.FaxCobranca = xml.FaxCobranca; } else { crm.AddNullProperty("FaxCobranca"); } //Removido essa validação para que as NF de clientes estrangeiros sejam integrados no CRM //if (!String.IsNullOrEmpty(xml.CNPJ)) // crm.CpfCnpj = Intelbras.CRM2013.Domain.Servicos.Helper.FormatarCnpj(xml.CNPJ); //else if (!String.IsNullOrEmpty(xml.CPF)) // crm.CpfCnpj = Intelbras.CRM2013.Domain.Servicos.Helper.FormatarCpf(xml.CPF); //else //{ // resultadoPersistencia.Sucesso = false; // resultadoPersistencia.Mensagem = "CNPJ/CPF não enviado."; // return crm; //} if (!String.IsNullOrEmpty(xml.InscricaoEstadual)) { crm.InscricaoEstadual = xml.InscricaoEstadual; } else { crm.AddNullProperty("InscricaoEstadual"); } if (!string.IsNullOrEmpty(xml.Oportunidade)) { crm.Oportunidade = new Lookup(new Guid(xml.Oportunidade), ""); } xml.PrecoBloqueado = xml.PrecoBloqueado; if (xml.ValorDesconto.HasValue) { crm.ValorDescontoFatura = xml.ValorDesconto; } else { crm.AddNullProperty("ValorDescontoFatura"); } if (xml.PercentualDesconto.HasValue) { crm.DescontoGlobalTotal = xml.PercentualDesconto; } else { crm.AddNullProperty("DescontoGlobalTotal"); } //Service Lista Preço ListaPreco ObjListaPreco = new Intelbras.CRM2013.Domain.Servicos.ListaPrecoService(this.Organizacao, this.IsOffline).BuscaListaPreco(xml.ListaPreco); if (ObjListaPreco != null) { crm.ListaPrecos = new Lookup((Guid)ObjListaPreco.ID, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Lista de Preço não encontrado."; return(crm); } crm.Prioridade = xml.Prioridade; if (xml.ValorTotal.HasValue) { crm.ValorTotal = xml.ValorTotal; } else { crm.AddNullProperty("ValorTotal"); } if (xml.ValorTotalImpostos.HasValue) { crm.TotalImpostos = xml.ValorTotalImpostos; } else { crm.AddNullProperty("TotalImpostos"); } //if (xml.ValorTotalProdutosSemImposto.HasValue) // crm.ValorTotalProdutosSemIPIST = xml.ValorTotalProdutosSemImposto; if (xml.ValorTotalSemFrete.HasValue) { crm.ValorTotalSemFrete = xml.ValorTotalSemFrete; } else { crm.AddNullProperty("ValorTotalSemFrete"); } if (xml.ValorTotalDesconto.HasValue) { crm.DescontoTotal = xml.ValorTotalDesconto; } else { crm.AddNullProperty("DescontoTotal"); } if (xml.ValorTotalProdutos.HasValue) { crm.TotalProdutosComIPIST = xml.ValorTotalProdutos; } else { crm.AddNullProperty("TotalProdutosComIPIST"); } if (xml.ValorTotalProdutosSemImposto.HasValue) { crm.ValorTotalProdutosSemIPIST = xml.ValorTotalProdutosSemImposto; } else { crm.AddNullProperty("ValorTotalProdutosSemIPIST"); } //Service Endereco Entrega if (!string.IsNullOrEmpty(xml.EnderecoEntrega.CaixaPostal)) { crm.EnderecoEntregaCaixaPostal = xml.EnderecoEntrega.CaixaPostal; } else { crm.AddNullProperty("EnderecoEntregaCaixaPostal"); } if (!string.IsNullOrEmpty(xml.EnderecoEntrega.NomeEndereco)) { crm.NomeEntrega = xml.EnderecoEntrega.NomeEndereco; } else { crm.AddNullProperty("NomeEntrega"); } crm.CEPEntrega = xml.EnderecoEntrega.CEP; crm.EnderecoEntregaRua = xml.EnderecoEntrega.Logradouro; crm.EnderecoEntregaNumero = xml.EnderecoEntrega.Numero; crm.BairroEntrega = xml.EnderecoEntrega.Bairro; crm.ComplementoEntrega = xml.EnderecoEntrega.Complemento; crm.TipoNotaFiscal = xml.TipoNotaFiscal; crm.NotaDevolucao = xml.NotaDevolucao; crm.IdentificadorUnicoNfe = xml.IdentificadorUnicoNFE; if (!string.IsNullOrEmpty(xml.EnderecoEntrega.Complemento)) { crm.ComplementoEntrega = xml.EnderecoEntrega.Complemento; } else { crm.AddNullProperty("ComplementoEntrega"); } if (!String.IsNullOrEmpty(xml.EnderecoEntrega.Cidade)) { Model.Municipio cidade = new Model.Municipio(this.Organizacao, this.IsOffline); cidade = new Intelbras.CRM2013.Domain.Servicos.EnderecoServices(this.Organizacao, this.IsOffline).BuscaMunicipio(xml.EnderecoEntrega.Cidade); if (cidade != null && cidade.ID.HasValue) { crm.EnderecoEntregaCidade = new Lookup(cidade.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador da Cidade não encontrado!"; return(crm); } } if (!String.IsNullOrEmpty(xml.EnderecoEntrega.Estado)) { Model.Estado estado = new Model.Estado(this.Organizacao, this.IsOffline); estado = new Intelbras.CRM2013.Domain.Servicos.EnderecoServices(this.Organizacao, this.IsOffline).BuscaEstado(xml.EnderecoEntrega.Estado); if (estado != null && estado.ID.HasValue) { crm.EnderecoEntregaEstado = new Lookup(estado.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador do Estado não encontrado!"; return(crm); } } ///Service Pais if (!String.IsNullOrEmpty(xml.EnderecoEntrega.Pais)) { Model.Pais pais = new Model.Pais(this.Organizacao, this.IsOffline); pais = new Intelbras.CRM2013.Domain.Servicos.EnderecoServices(this.Organizacao, this.IsOffline).BuscaPais(xml.EnderecoEntrega.Pais); if (pais != null && pais.ID.HasValue) { crm.EnderecoEntregaPais = new Lookup(pais.ID.Value, ""); } else { resultadoPersistencia.Sucesso = false; resultadoPersistencia.Mensagem = "Identificador do País não encontrado."; return(crm); } } if (!String.IsNullOrEmpty(xml.EnderecoEntrega.NomeContato)) { crm.NomeEntrega = xml.EnderecoEntrega.NomeContato; } else { crm.AddNullProperty("NomeEntrega"); } if (!String.IsNullOrEmpty(xml.EnderecoEntrega.Telefone)) { crm.TelefoneEntrega = xml.EnderecoEntrega.Telefone; } else { crm.AddNullProperty("TelefoneEntrega"); } if (!String.IsNullOrEmpty(xml.EnderecoEntrega.Fax)) { crm.FaxEntrega = xml.EnderecoEntrega.Fax; } else { crm.AddNullProperty("FaxEntrega"); } #region Representante crm.IntegradoRepresentanteComErro = false; crm.IntegradoComErros = false; crm.RepresentanteOriginal = xml.Representante.ToString(); Contato ObjRepresentante = new Intelbras.CRM2013.Domain.Servicos.ContatoService(this.Organizacao, this.IsOffline) .BuscaContatoPorCodigoRepresentante(xml.Representante.ToString()); if (ObjRepresentante != null) { crm.KARepresentante = new Lookup(ObjRepresentante.ID.Value, ""); } else { crm.IntegradoRepresentanteComErro = true; crm.IntegradoComErros = true; crm.KARepresentante = new Lookup(ObterRepresentatePadrao(), ""); } #endregion return(crm); }