Ejemplo n.º 1
0
        private List <_Transacao> IncluirOrdemPagamentoItens(int idOrdemPagamento, int idObra, List <OrdemPagamentoItem> lstItens)
        {
            BIZObra bizObra = new BIZObra();
            List <ObraEtapaGastoRealizado> lstRealizados  = new List <ObraEtapaGastoRealizado>();
            BIZVeiculo                  bizVeiculo        = new BIZVeiculo();
            List <Abastecimento>        lstAbastecimentos = new List <Abastecimento>();
            List <_Transacao>           lstComandos       = new List <_Transacao>();
            Dictionary <string, string> lstParametros     = new Dictionary <string, string>();

            foreach (OrdemPagamentoItem itemOrdem in lstItens)
            {
                itemOrdem.idOrdemPagamento = idOrdemPagamento;
                lstParametros = this.MontarParametrosExecutarOrdemPagamentoItem(itemOrdem);

                lstComandos.Add(new _Transacao()
                {
                    nomeProcedure = "SP_ORDEMPAGAMENTOITENS_INCLUIR",
                    lstParametros = lstParametros
                });

                if (itemOrdem.idObraGastoRealizado != 0)
                {
                    lstRealizados.Add(new ObraEtapaGastoRealizado()
                    {
                        idObraEtapaGastoRealizado = itemOrdem.idObraGastoRealizado,
                        idObraEtapa   = idObra,
                        idUEN         = itemOrdem.idUEN,
                        idCentroCusto = itemOrdem.idCentroCusto,
                        idDespesa     = itemOrdem.idDespesa,
                        Valor         = itemOrdem.Valor,
                        Observacao    = string.Empty,
                        UnitTest      = itemOrdem.UnitTest
                    });

                    lstComandos.AddRange(bizObra.AtualizarGastosRealizadosOrdemPagamento(idOrdemPagamento, lstRealizados));
                }

                if (itemOrdem.idAbastecimento != 0)
                {
                    lstAbastecimentos.Add(new Abastecimento()
                    {
                        idAbastecimento = itemOrdem.idAbastecimento
                    });

                    lstComandos.AddRange(bizVeiculo.AtualizarAbastecimentosOrdemPagamento(idOrdemPagamento, lstAbastecimentos));
                }
            }

            return(lstComandos);
        }
Ejemplo n.º 2
0
        public string IncluirOrdemPagamento(OrdemPagamento ordemPagamento, bool origemConsultaOP, out int idOrdemPagamento)
        {
            DataAccess                  dao           = new DataAccess();
            List <_Transacao>           lstComandos   = new List <_Transacao>();
            Dictionary <string, string> lstParametros = new Dictionary <string, string>();
            BIZVeiculo                  bizVeiculo    = new BIZVeiculo();
            BIZFrete bizFrete = new BIZFrete();

            string Msg = string.Empty;

            try
            {
                Msg = ValidarCamposObrigatorios(ordemPagamento);
                idOrdemPagamento = 0;

                if (Msg == string.Empty)
                {
                    using (DataSet ds = dao.Pesquisar("SP_ORDEMPAGAMENTO_NOVONUMEROOP", lstParametros))
                    {
                        DataRow dr = ds.Tables[0].Rows[0];
                        ordemPagamento.numeroOP = dr[0].ToString();
                    }

                    lstParametros = MontarParametrosExecutarOrdemPagamento(ordemPagamento);

                    using (DataSet ds = dao.Pesquisar("SP_ORDEMPAGAMENTO_INCLUIR", lstParametros))
                    {
                        DataRow dr = ds.Tables[0].Rows[0];
                        idOrdemPagamento = int.Parse(dr[0].ToString());
                    }

                    lstComandos.AddRange(this.IncluirOrdemPagamentoItens(idOrdemPagamento, ordemPagamento.idObraEtapa, ordemPagamento.lstItens));

                    dao.ExecutarTransacao(lstComandos);

                    if (ordemPagamento.lstItens.Exists(x => x.idFrete != 0))
                    {
                        FretePagamento fretePagamento = new FretePagamento()
                        {
                            idFrete = ordemPagamento.lstItens.Where(x => x.idFrete != 0).FirstOrDefault().idFrete,
                            idOP    = idOrdemPagamento
                        };

                        bizFrete.IncluirPagamento(fretePagamento);
                    }

                    if (ordemPagamento.lstItens.Exists(x => x.idManutencao != 0))
                    {
                        Manutencao manutencao = new Manutencao()
                        {
                            idManutencao = ordemPagamento.lstItens.Where(x => x.idManutencao != 0).FirstOrDefault().idManutencao,
                            idOP         = idOrdemPagamento,
                        };

                        bizVeiculo.AtualizarManutencaoOrdemPagamento(manutencao);
                    }

                    if (ordemPagamento.lstItens.Exists(x => x.idOcorrenciaMulta != 0))
                    {
                        MultaOcorrencia ocorrencia = new MultaOcorrencia()
                        {
                            idOcorrencia = ordemPagamento.lstItens.Where(x => x.idOcorrenciaMulta != 0).FirstOrDefault().idOcorrenciaMulta,
                            idOP         = idOrdemPagamento
                        };

                        bizVeiculo.AtualizarMultaOcorrenciaOrdemPagamento(ocorrencia);
                    }
                }
            }
            catch (Exception ex)
            {
                string parametrosSQL = string.Empty;
                parametrosSQL = helper.ConcatenarParametrosSQL(lstParametros);

                LogErro log = new LogErro()
                {
                    procedureSQL  = "SP_ORDEMPAGAMENTO_INCLUIR",
                    parametrosSQL = parametrosSQL,
                    mensagemErro  = ex.ToString()
                };

                bizLogErro.IncluirLogErro(log);

                throw ex;
            }

            return(Msg);
        }