private void TransmitirRobo(ProgramacaoDesembolso entity, Usuario user, string ug)
        {
            try
            {
                var isHasError = false;


                if (entity.Agrupamentos.Any())
                {
                    foreach (var programacaoDesembolsoAgrupamento in entity.Agrupamentos.OrderBy(x => x.Sequencia))
                    {
                        if (string.IsNullOrEmpty(programacaoDesembolsoAgrupamento.NumeroSiafem))
                        {
                            isHasError = TransmitirSiafemRobo(user, ug, programacaoDesembolsoAgrupamento, isHasError);
                        }
                    }

                    if (isHasError)
                    {
                        throw new ApplicationException("Uma ou mais programações não puderam ser transmitidas");
                    }
                }
                else
                {
                    throw new ApplicationException("Não há documentos em condições de pagamento para o argumento informado.");
                }
            }
            finally
            {
                entity.Agrupamentos = _agrupamento.Buscar(new ProgramacaoDesembolsoAgrupamento {
                    PagamentoContaUnicaId = entity.Id
                });
            }
        }
        public string ConsultaOP(string key, string password, string numeroDocumentoGerador)
        {
            try
            {
                var entityProgramacaoDesembolso = new ProgramacaoDesembolso();
                var result     = DataHelperProdespPagementoContaDer.Procedure_ConsultaOP(key, password, numeroDocumentoGerador);
                var resultItem = result[0];

                if (!string.IsNullOrEmpty(resultItem?.outErro))
                {
                    var error = resultItem?.outErro;
                    if (error.Contains("FCFIN4 - PAGAMENTO NAO PREPARADO"))
                    {
                        entityProgramacaoDesembolso.OP = resultItem?.outNumeroOP + "@" + resultItem?.outErro;
                        //entityProgramacaoDesembolso.ProdespConsultaOPMensagemErro = resultItem?.outErro;
                    }
                    else
                    {
                        throw new ProdespException(error);
                    }
                }
                else
                {
                    entityProgramacaoDesembolso.OP = resultItem?.outNumeroOP;
                }

                return(entityProgramacaoDesembolso.OP);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.Contains("EntradaCICS_Fora") ? "Erro na comunicação com WebService Prodesp." : ex.Message);
            }
        }
예제 #3
0
        public DadoPagamentoContaUnicaAgrupamentoViewModel CreateInstance(ProgramacaoDesembolso entity, IEnumerable <DocumentoTipo> tipoDocumento, IEnumerable <Regional> regionais)
        {
            return(new DadoPagamentoContaUnicaAgrupamentoViewModel
            {
                DocumentoTipoListItems = tipoDocumento.
                                         Select(s => new SelectListItem
                {
                    Text = s.Descricao,
                    Value = s.Id.ToString(),
                    Selected = s.Id == entity.DocumentoTipoId
                }),
                NumeroDocumento = entity.NumeroDocumento,
                TipoDespesa = entity.CodigoDespesa,

                RegionalListItems = regionais.Where(x => x.Id > 1).
                                    Select(s => new SelectListItem
                {
                    Text = s.Descricao,
                    Value = s.Id.ToString(),
                    Selected = s.Id == entity.RegionalId
                }),

                TransmitidoSiafem = entity.Agrupamentos.Count(x => x.Id > 0) > 0
            });
        }
        public int SalvarOuAlterar(ProgramacaoDesembolso entity, int recursoId, short action)
        {
            try
            {
                entity.NumeroAgrupamento = entity.ProgramacaoDesembolsoTipoId == 2
                    ? _agrupamento.BuscarUltimoAgupamento() + 1
                    : 0;
                entity.Id = _repository.Save(entity);

                if (entity.Eventos != null && entity.ProgramacaoDesembolsoTipoId == 1)
                {
                    entity.Eventos = SalvarOuAlterarEventos(entity, recursoId, action);
                }

                if (entity.Agrupamentos != null && entity.ProgramacaoDesembolsoTipoId == 2)
                {
                    entity.Agrupamentos = SalvarOuAlterarAgrupamentos(entity, recursoId, action);
                }

                if (recursoId > 0)
                {
                    LogSucesso(action, recursoId, $@"
                    Nº do Programação de Desembolso SIAFEM {entity.NumeroSiafem}.");
                }

                return(entity.Id);
            }
            catch (Exception ex)
            {
                throw SaveLog(ex, action, recursoId);
            }
        }
예제 #5
0
        public IEnumerable <ProgramacaoDesembolso> FetchForGrid(ProgramacaoDesembolso entity, DateTime since, DateTime until)
        {
            var paramId                          = new SqlParameter("@id_programacao_desembolso", entity.Id);
            var paramNumeroSiafem                = new SqlParameter("@nr_siafem_siafisico", entity.NumeroSiafem);
            var paramNumeroProcesso              = new SqlParameter("@nr_processo", entity.NumeroProcesso);
            var paramCodigoAplicacaoObra         = new SqlParameter("@cd_aplicacao_obra", entity.CodigoAplicacaoObra);
            var paramStatusSiafem                = new SqlParameter("@cd_transmissao_status_siafem_siafisico", entity.StatusSiafem);
            var paramNumeroContrato              = new SqlParameter("@nr_contrato", entity.NumeroContrato);
            var paramDataVencimento              = new SqlParameter("@dt_vencimento", entity.DataVencimento.ValidateDBNull());
            var paramSince                       = new SqlParameter("@dt_cadastramento_de", since.ValidateDBNull());
            var paramUntil                       = new SqlParameter("@dt_cadastramento_ate", until.ValidateDBNull());
            var paramRegionalId                  = new SqlParameter("@id_regional", entity.RegionalId);
            var paramCodigoDespesa               = new SqlParameter("@cd_despesa", entity.CodigoDespesa);
            var paramDocumentoTipoId             = new SqlParameter("@id_tipo_documento", entity.DocumentoTipoId);
            var paramNumeroDocumento             = new SqlParameter("@nr_documento", entity.NumeroDocumento);
            var paramProgramacaoDesembolsoTipoId = new SqlParameter("@id_tipo_programacao_desembolso", entity.ProgramacaoDesembolsoTipoId);
            var paramNumeroAgrupamento           = new SqlParameter("@nr_agrupamento", entity.NumeroAgrupamento);
            var paramBloqueio                    = new SqlParameter("@bl_bloqueio", entity.Bloqueio);


            return(DataHelper.List <ProgramacaoDesembolso>("PR_PROGRAMACAO_DESEMBOLSO_CONSULTA_GRID",
                                                           paramId, paramNumeroSiafem, paramNumeroProcesso, paramCodigoAplicacaoObra, paramProgramacaoDesembolsoTipoId,
                                                           paramStatusSiafem, paramNumeroContrato, paramDataVencimento, paramSince, paramUntil, paramRegionalId,
                                                           paramNumeroAgrupamento, paramCodigoDespesa, paramDocumentoTipoId, paramNumeroDocumento, paramBloqueio));
        }
        private void TransmitirSiafemSiafisico(ProgramacaoDesembolso entity, Usuario user, int recursoId)
        {
            try
            {
                var result = default(string);
                var ug     = _regional.Buscar(new Regional {
                    Id = (int)user.RegionalId
                }).First().Uge;

                /*
                 * 1	Manual
                 * 2	Pagamentos a Preparar (Robô)
                 * 3	Manual - PDBEC
                 */

                if (entity.ProgramacaoDesembolsoTipoId == 1)
                {
                    TransmitirNomal(entity, user, ug);
                }
                else if (entity.ProgramacaoDesembolsoTipoId == 2)
                {
                    TransmitirRobo(entity, user, ug);
                }
                else if (entity.ProgramacaoDesembolsoTipoId == 3)
                {
                    TransmitirPDBEC(entity, user, ug);
                }
            }
            catch (Exception ex)
            {
                entity.StatusSiafem          = "E";
                entity.MensagemServicoSiafem = ex.Message;
                throw SaveLog(ex, (short?)EnumAcao.Transmitir, recursoId);
            }
        }
        private static List <FiltroGridViewModel> GetFiltroGridViewModel(ProgramacaoDesembolso entity, IEnumerable <DocumentoTipo> tpdocumentos)
        {
            var lista = new List <FiltroGridViewModel>();

            var obj = new FiltroGridViewModel();

            obj.Id = entity.Id.ToString();
            obj.NumeroAgrupamento       = entity.NumeroAgrupamento == default(int) ? string.Empty : entity.NumeroAgrupamento.ToString("D5");
            obj.NumSiafemProgDesembolso = entity.NumeroSiafem;
            obj.AgrupamentoId           = entity.Id;
            obj.TipoDespesa             = entity.CodigoDespesa;
            obj.DocumentoTipo           = tpdocumentos.FirstOrDefault(w => w.Id == entity.DocumentoTipoId)?.Descricao;
            obj.NumeroDocumento         = entity.NumeroDocumento;
            obj.Total                       = entity.ProgramacaoDesembolsoTipoId == 2 ? entity.Valor : entity.Eventos.Sum(x => x.ValorUnitario);
            obj.DataVencimento              = (entity.DataVencimento == DateTime.MinValue) ? string.Empty : entity.DataVencimento.ToShortDateString();
            obj.Data                        = entity.DataCadastro.ToShortDateString();
            obj.StatusSiafem                = string.IsNullOrEmpty(entity.StatusSiafem) || entity.StatusSiafem.Equals("N") ? "Não Transmitido" : (entity.StatusSiafem.Equals("E") ? "Erro" : "Sucesso");
            obj.Bloqueio                    = entity.Bloqueio;
            obj.MensagemSiafem              = entity.MensagemServicoSiafem;
            obj.CadastroCompleto            = entity.CadastroCompleto;
            obj.TransmitirSiafem            = entity.TransmitirSiafem;
            obj.TransmitidoSiafem           = entity.TransmitidoSiafem;
            obj.StatusOp                    = string.Format("{0}{1}{2}", (entity.Cancelado ? "Cancel" : ""), (entity.Cancelado && entity.Bloqueio ? "/" : ""), (entity.Bloqueio ? "Bloq" : ""));
            obj.CanceladoOp                 = entity.Cancelado;
            obj.ProgramacaoDesembolsoTipoId = entity.ProgramacaoDesembolsoTipoId;
            obj.DocumentoTipoId             = entity.DocumentoTipoId;
            obj.NumeroDocumentoGerador      = entity.NumeroDocumentoGerador;
            var nrContrato = entity.NumeroContrato?.Replace(".", "").Replace("-", "");

            obj.NumeroContrato = Convert.ToInt32(nrContrato);

            lista.Add(obj);

            return(lista);
        }
 public ProgramacaoDesembolsoServiceTests()
 {
     _user = new Usuario {
         Codigo = 1, RegionalId = 16
     };
     _entities = new List <ProgramacaoDesembolso>();
     _entity   = CreateEntityFactory();
 }
예제 #9
0
 public IEnumerable <ProgramacaoDesembolso> Fetch(ProgramacaoDesembolso entity)
 {
     return(DataHelper.List <ProgramacaoDesembolso>("PR_PROGRAMACAO_DESEMBOLSO_CONSULTAR",
                                                    new SqlParameter("@id_programacao_desembolso", entity.Id),
                                                    new SqlParameter("@id_regional", entity.RegionalId),
                                                    new SqlParameter("@nr_documento_gerador", entity.NumeroDocumentoGerador),
                                                    new SqlParameter("@nr_siafem_siafisico", entity.NumeroSiafem)));
 }
        private int SalvarService(ProgramacaoDesembolso programacaoDesembolso, int funcionalidade)
        {
            var acao = programacaoDesembolso.Id > 0 ? EnumAcao.Alterar : EnumAcao.Inserir;

            return(App.ProgramacaoDesembolsoService.SalvarOuAlterar(
                       programacaoDesembolso,
                       funcionalidade,
                       Convert.ToInt16(acao)));
        }
        public ActionResult EditByList(string id, int tipoId, string tipo)
        {
            ProgramacaoDesembolso objModel = new ProgramacaoDesembolso();

            objModel = App.ProgramacaoDesembolsoService.Selecionar(Convert.ToInt32(id));

            objModel.TipoBloqueio = (tipo == "c") ? 1 : 0;

            return(View("CreateEdit", Display(objModel, false)));
        }
 public void TransmitirCancelamento(ProgramacaoDesembolso entity, Usuario user, int recursoId)
 {
     try
     {
         TransmitirSiafemCancelamento(entity, user, recursoId);
     }
     catch (Exception ex)
     {
         throw SaveLog(ex, (short)EnumAcao.Transmitir, recursoId);
     }
 }
 public ActionResult Save(ProgramacaoDesembolso programacaoDesembolso)
 {
     try
     {
         return(Json(new { Status = "Sucesso", Id = SalvarService(programacaoDesembolso, Convert.ToInt32(_funcId)) }));
     }
     catch (Exception ex)
     {
         return(Json(new { Status = "Falha", Msg = ex.Message }));
     }
 }
예제 #14
0
        public IEnumerable <object> BloqueioOpApoio(string key, string password, ProgramacaoDesembolso programacaoDesembolso)
        {
            var result = DataHelperProdespPagamentoContaUnica.Procedure_BloqueioPagtoDocApoio(key, password, programacaoDesembolso) ?? new Procedure_BloqueioPagtoDocApoioRecordType[] { };

            if (!string.IsNullOrEmpty(result[0]?.outErro))
            {
                throw new SidsException($"Prodesp - {result[0]?.outErro}");
            }

            return(result);
        }
        private void TransmitirNomal(ProgramacaoDesembolso entity, Usuario user, string ug)
        {
            var result = _siafem.InserirProgramacaoDesembolso(user.CPF, Decrypt(user.SenhaSiafem), ug, entity);

            entity.NumeroSiafem          = result;
            entity.TransmitidoSiafem     = true;
            entity.StatusSiafem          = "S";
            entity.DataTransmitidoSiafem = DateTime.Now;
            entity.MensagemServicoSiafem = null;
            entity.CausaCancelamento     = null;
            entity.Cancelado             = false;

            SalvarOuAlterar(entity, 0, (short)EnumAcao.Transmitir);
        }
        public JsonResult TransmitirCancelamento(ProgramacaoDesembolso programacaoDesembolso)
        {
            try
            {
                var usuario = App.AutenticacaoService.GetUsuarioLogado();
                App.ProgramacaoDesembolsoService.TransmitirCancelamento(programacaoDesembolso, usuario, (int)_funcId);

                return(Json(new { Status = "Sucesso" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Status = "Falha", Msg = ex.Message }));
            }
        }
 private void Transmissao(Usuario user, ProgramacaoDesembolso entity, int recursoId)
 {
     try
     {
         if (!entity.TransmitidoSiafem)
         {
             TransmitirSiafemSiafisico(entity, user, recursoId);
         }
     }
     catch
     {
         throw;
     }
 }
예제 #18
0
        public IEnumerable <object> BloqueioOpApoio(ProgramacaoDesembolso programacaoDesembolso)
        {
            var cicsmo = new ChaveCicsmo();

            try
            {
                cicsmo = _chave.ObterChave();
                var result = _prodespPagamentoContaUnicaService.BloqueioOpApoio(cicsmo.Chave, cicsmo.Senha, programacaoDesembolso);
                return(result);
            }
            finally
            {
                _chave.LiberarChave(cicsmo.Codigo);
            }
        }
        public DadoTipoProgramacaoDesembolsoViewModel CreateInstance(ProgramacaoDesembolso entity, IEnumerable <ProgramacaoDesembolsoTipo> programacaoDesembolsoTipos)
        {
            return(new DadoTipoProgramacaoDesembolsoViewModel()
            {
                ProgramacaoDesembolsoTipoId = Convert.ToString(entity.ProgramacaoDesembolsoTipoId),

                ProgramacaoDesembolsoTipoListItens = programacaoDesembolsoTipos
                                                     .Select(s => new SelectListItem
                {
                    Text = s.Descricao,
                    Value = s.Id.ToString(),
                    Selected = s.Id == entity.ProgramacaoDesembolsoTipoId
                }),
            });
        }
 public DadoProgramacaoDesembolsoViewModel CreateInstance(ProgramacaoDesembolso entity)
 {
     return(new DadoProgramacaoDesembolsoViewModel()
     {
         NumeroProcesso = entity.NumeroProcesso,
         CodigoAplicacaoObra = entity.CodigoAplicacaoObra,
         CodigoUnidadeGestora = entity.CodigoUnidadeGestora,
         CodigoGestao = entity.CodigoGestao,
         DataEmissao = entity.DataEmissao.ToShortDateString(),
         DataVencimento = entity.DataVencimento == default(DateTime) ? null: entity.DataVencimento.ToShortDateString(),
         NumeroContrato = entity.NumeroContrato,
         NumeroListaAnexo = entity.NumeroListaAnexo,
         NumeroNLReferencia = entity.NumeroNLReferencia,
         Finalidade = entity.Finalidade,
         NumeroDocumentoGerador = entity.NumeroDocumentoGerador
     });
 }
예제 #21
0
        public DadoPagamentoContaUnicaContasViewModel CreateInstance(ProgramacaoDesembolso entity)
        {
            return(new DadoPagamentoContaUnicaContasViewModel()
            {
                NumeroBancoCredor = entity.NumeroBancoCredor,
                NumeroAgenciaCredor = entity.NumeroAgenciaCredor,
                NumeroContaCredor = entity.NumeroContaCredor,

                NumeroBancoPagto = entity.NumeroBancoPagto,
                NumeroAgenciaPagto = entity.NumeroAgenciaPagto,
                NumeroContaPagto = entity.NumeroContaPagto,

                NumeroCnpjcpfCredor = entity.NumeroCnpjcpfCredor,
                GestaoPagto = entity.GestaoPagto,
                GestaoCredor = entity.GestaoCredor,
                NumeroCnpjcpfPagto = entity.NumeroCnpjcpfPagto
            });
        }
예제 #22
0
        public PesquisaDocumentoGeradorViewModel CreateInstance(ProgramacaoDesembolso entity, IEnumerable <DocumentoTipo> tipoDocumento)
        {
            var documentoTipos = tipoDocumento as IList <DocumentoTipo> ?? tipoDocumento.ToList();

            return(new PesquisaDocumentoGeradorViewModel()
            {
                DocumentoTipoId = Convert.ToString(entity.DocumentoTipoId),

                DocumentoTipoListItems = documentoTipos.
                                         Select(s => new SelectListItem
                {
                    Text = s.Descricao,
                    Value = s.Id.ToString(),
                    Selected = s.Id == entity.DocumentoTipoId
                }),

                NumeroDocumento = entity.NumeroDocumento
            });
        }
        public IEnumerable <FiltroGridViewModel> CreateInstance(ProgramacaoDesembolso entity, IEnumerable <DocumentoTipo> tpdocumentos)
        {
            IEnumerable <FiltroGridViewModel> result;

            //result = entity.ProgramacaoDesembolsoTipoId == 2 ? GetFiltroGridViewModelAgrupamento(entity, tpdocumentos) : GetFiltroGridViewModel(entity, tpdocumentos);

            if (entity.ProgramacaoDesembolsoTipoId == 2)
            {
                result = entity.Agrupamentos.Any() ? GetFiltroGridViewModelAgrupamento(entity, tpdocumentos) : GetFiltroGridViewModel(entity, tpdocumentos);
            }
            else
            {
                result = GetFiltroGridViewModel(entity, tpdocumentos);
            }



            return(result);
        }
예제 #24
0
 public DadoProgramacaoDesembolsoPDBECViewModel CreateInstance(ProgramacaoDesembolso entity, IEnumerable <Regional> regional, Usuario logado)
 {
     return(new DadoProgramacaoDesembolsoPDBECViewModel()
     {
         NumeroProcesso = entity.NumeroProcesso,
         CodigoAplicacaoObraBec = entity.CodigoAplicacaoObra,
         CodigoUnidadeGestora = entity.CodigoUnidadeGestora,
         CodigoGestao = entity.CodigoGestao,
         DataEmissao = entity.DataEmissao.ToShortDateString(),
         DataVencimento = entity.DataVencimento == default(DateTime) ? null : entity.DataVencimento.ToShortDateString(),
         NumeroContratoBec = entity.NumeroContrato,
         NumeroListaAnexo = entity.NumeroListaAnexo,
         NumeroNLReferenciaBec = entity.NumeroNLReferencia,
         Finalidade = entity.Finalidade,
         NumeroDocumentoGerador = entity.NumeroDocumentoGerador,
         Obs = entity.Obs,
         NumeroNE = entity.NumeroNE,
         NumeroCT = entity.NumeroCT
     });
 }
        public string ConsultaOP(string key, string password, string numeroDocumentoGerador)
        {
            try
            {
                var result = DataHelperProdespPagementoContaDer.Procedure_ConsultaOP(key, password, numeroDocumentoGerador);
                var resultItem = result[0];

                //if (!string.IsNullOrEmpty(resultItem?.outErro))
                //  throw new Exception($"Prodesp - {resultItem?.outErro}");

                var entityProgramacaoDesembolso = new ProgramacaoDesembolso();
                entityProgramacaoDesembolso.OP = resultItem?.outNumeroOP + "@" + resultItem?.outErro;
                //entityProgramacaoDesembolso.ProdespConsultaOPMensagemErro = resultItem?.outErro;

                return entityProgramacaoDesembolso.OP;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.Contains("EntradaCICS_Fora") ? "Erro na comunicação com WebService Prodesp." : ex.Message);
            }
        }
        public JsonResult Transmitir(ProgramacaoDesembolso programacaoDesembolso)
        {
            ProgramacaoDesembolso objModel;

            try
            {
                var usuario = App.AutenticacaoService.GetUsuarioLogado();
                programacaoDesembolso.RegionalId = usuario.RegionalId == 1 ? 16 : (short)usuario.RegionalId;
                ModelId = SalvarService(programacaoDesembolso, 0);
                App.ProgramacaoDesembolsoService.Transmitir(ModelId, usuario, (int)_funcId);
                objModel = App.ProgramacaoDesembolsoService.Selecionar(ModelId);

                return(Json(new { Status = "Sucesso", Codigo = objModel.Id, objModel }));
            }
            catch (Exception ex)
            {
                objModel = App.ProgramacaoDesembolsoService.Selecionar(ModelId);

                return(Json(new { Status = "Falha", Msg = ex.Message, Codigo = objModel.Id, objModel }));
            }
        }
        public AcaoEfetuada Excluir(ProgramacaoDesembolso entity, int recursoId, short action)
        {
            try
            {
                if (entity.Agrupamentos.Count(x => x.TransmitidoSiafem) > 0)
                {
                    throw new SidsException("Não é permitido excluir lista de PD, existem PD’s já transmitidas");
                }
                _repository.Remove(entity.Id);

                if (recursoId > 0)
                {
                    return(LogSucesso(action, recursoId, $"ProgramacaoDesembolso : Codigo {entity.Id}"));
                }

                return(AcaoEfetuada.Sucesso);
            }
            catch (Exception ex)
            {
                throw SaveLog(ex, actionId: action, functionalityId: recursoId);
            }
        }
        public JsonResult TransmitirDesbloqueioOp(ProgramacaoDesembolso programacaoDesembolso)
        {
            IProgramacaoDesembolso objModel;

            try
            {
                ModelId = programacaoDesembolso.Id;

                App.ProgramacaoDesembolsoService.TransmitirDesbloqueioOp(programacaoDesembolso, (int)_funcId);

                if (programacaoDesembolso.ProgramacaoDesembolsoTipoId == 1 || programacaoDesembolso.ProgramacaoDesembolsoTipoId == 3)
                {
                    objModel = App.ProgramacaoDesembolsoService.Selecionar(ModelId);
                }
                else
                {
                    objModel = App.ProgramacaoDesembolsoAgrupamentoService.Buscar(new ProgramacaoDesembolsoAgrupamento {
                        Id = ModelId
                    }).FirstOrDefault();
                }

                return(Json(new { Status = "Sucesso", Codigo = objModel.Id, objModel }));
            }
            catch (Exception ex)
            {
                if (programacaoDesembolso.ProgramacaoDesembolsoTipoId == 1 || programacaoDesembolso.ProgramacaoDesembolsoTipoId == 3)
                {
                    objModel = App.ProgramacaoDesembolsoService.Selecionar(ModelId);
                }
                else
                {
                    objModel = App.ProgramacaoDesembolsoAgrupamentoService.Buscar(new ProgramacaoDesembolsoAgrupamento {
                        Id = ModelId
                    }).FirstOrDefault();
                }

                return(Json(new { Status = "Falha", Msg = ex.Message, Codigo = objModel.Id, objModel }));
            }
        }
        public IEnumerable <ProgramacaoDesembolso> BuscarGrid(ProgramacaoDesembolso entity,
                                                              DateTime de = default(DateTime), DateTime ate = default(DateTime))
        {
            var entities = _repository.FetchForGrid(entity, de, ate).ToList();

            entities.ForEach(x => x.Eventos = _eventos.Buscar(new ProgramacaoDesembolsoEvento {
                PagamentoContaUnicaId = x.Id
            }));

            foreach (var pd in entities)
            {
                if (pd.ProgramacaoDesembolsoTipoId == 2)
                {
                    pd.Agrupamentos = _agrupamento.Buscar(new ProgramacaoDesembolsoAgrupamento {
                        PagamentoContaUnicaId = pd.Id, NumeroSiafem = entity.NumeroSiafem, NumeroProcesso = entity.NumeroProcesso,
                        DocumentoTipoId       = entity.DocumentoTipoId, NumeroDocumento = entity.NumeroDocumento, NumeroAgrupamento = entity.NumeroAgrupamento, Bloquear = entity.Bloquear
                    });
                }
            }


            return(entities.ToList());
        }
        private IEnumerable <ProgramacaoDesembolsoEvento> SalvarOuAlterarEventos(ProgramacaoDesembolso entity,
                                                                                 int recursoId, short action)
        {
            var salvos = _eventos.Buscar(new ProgramacaoDesembolsoEvento {
                PagamentoContaUnicaId = entity.Id
            });
            var deleta = salvos?.Where(w => entity.Eventos.All(a => a.Id != w.Id));

            if (deleta.Any())
            {
                _eventos.Excluir(deleta, recursoId, action);
            }

            var eventos = new List <ProgramacaoDesembolsoEvento>();

            foreach (ProgramacaoDesembolsoEvento evento in entity.Eventos)
            {
                evento.PagamentoContaUnicaId = entity.Id;
                evento.Id = _eventos.SalvarOuAlterar(evento, recursoId, action);
                eventos.Add(evento);
            }

            return(eventos);
        }