public void Adicionar(RootLancamentoFinanceiro rootLancamento)
 {
     _variables.UserName = "******";
     foreach (var item in rootLancamento.ItensLancamentoFinanceiro)
     {
         TratarItem(item);
     }
     _lancamentoFinanceiroRepository.Adicionar(rootLancamento);
     _unitOfWork.Commit();
 }
 private void VerificarTipoDespesa(ComprasEacessoService comprasEacessoService, RootLancamentoFinanceiro lancamento, ItemLancamentoFinanceiro item)
 {
     if (lancamento.DescricaoOrigemLancamento != "FT")
     {
         var tipoDespesa = comprasEacessoService.ObterTipoDespesaPorIdServicoIdLan(item.IdServicoContratado.Value, lancamento.IdLan.Value);
         if (tipoDespesa == null)
         {
             tipoDespesa = comprasEacessoService.ObterTipoDespesaPorIdColigadaIdLan(int.Parse(lancamento.CodigoColigada), lancamento.IdLan.Value);
         }
         if (tipoDespesa != null)
         {
             lancamento.IdTipoDespesa           = _tipoDespesaRepository.ObterTipoDespesaPorSigla(tipoDespesa.TipoDespesa);
             lancamento.DescOrigemCompraEacesso = tipoDespesa.OrigemEacesso;
         }
     }
 }
 private void ObterTipoDespesaPorColigada(ComprasEacessoService comprasEacessoService, RootLancamentoFinanceiro lancamentoAgrupado)
 {
     if (lancamentoAgrupado.DescricaoOrigemLancamento != "FT")
     {
         var tipoDespesa = comprasEacessoService.ObterTipoDespesaPorIdColigadaIdLan(int.Parse(lancamentoAgrupado.CodigoColigada), lancamentoAgrupado.IdLan.Value);
         if (tipoDespesa != null)
         {
             lancamentoAgrupado.IdTipoDespesa           = _tipoDespesaRepository.ObterTipoDespesaPorSigla(tipoDespesa.TipoDespesa);
             lancamentoAgrupado.DescOrigemCompraEacesso = tipoDespesa.OrigemEacesso;
         }
     }
 }
        private void PrepararItemLancamento(ClienteServicoEacessoService servicosEacessoService, RootLancamentoFinanceiro lancamentoAgrupado, ItemLancamentoFinanceiro itemLancamento)
        {
            if (lancamentoAgrupado.IdLan.HasValue)
            {
                var idServico = itemLancamento.IdServicoContratado;

                if (itemLancamento.CodigoCusto != null && itemLancamento.CodigoCusto.Any())
                {
                    var servicoPeloCodigo = itemLancamento.CodigoCusto.Split('.');
                    itemLancamento.IdServicoContratado = int.Parse(servicoPeloCodigo[2]);
                    idServico = itemLancamento.IdServicoContratado;
                }

                itemLancamento.IdServicoContratado =
                    _lancamentoFinanceiroRepository.ObterIdServicoContratado(itemLancamento.IdServicoContratado.Value);
                if (itemLancamento.IdServicoContratado == 0)
                {
                    if (idServico == 0)
                    {
                        return;
                    }
                    else
                    {
                        var novoServico = ObterServicoEacesso(idServico.Value, servicosEacessoService);
                        itemLancamento.IdServicoContratado = _servicoContratadoService.PersistirServicoEacesso(novoServico);
                    }
                }
                lancamentoAgrupado.ItensLancamentoFinanceiro.Add(itemLancamento);
            }
            else
            {
                AdicionarLogGenerico("ERRO LANCAMENTO - dtBaixa: " + lancamentoAgrupado.DtBaixa + " - vlBaixado: " + lancamentoAgrupado.VlBaixado + " - codcoligada: " + lancamentoAgrupado.CodigoColigada + " - idlan: " + lancamentoAgrupado.IdLan, JsonConvert.SerializeObject(lancamentoAgrupado));
            }
        }