Example #1
0
        internal bool GuardarFechaReal(String fechaReal, LoteReimplanteInfo loteReimplante)
        {
            var regresa = false;

            try
            {
                Logger.Info();
                var parametros = AuxProgramacionReimplanteDAL.ObtenerParametrosFechaReal(fechaReal, loteReimplante);
                if (Create("ReimplanteGanado_ActualizaFechaReal", parametros) > 0)
                {
                    return(true);
                }
            }
            catch (SqlException ex)
            {
                Logger.Error(ex);
                throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
            }
            catch (DataException ex)
            {
                Logger.Error(ex);
                throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }

            return(regresa);
        }
Example #2
0
 /// <summary>
 ///  Método que obtiene un registro
 /// </summary>
 /// <param name="ds"></param>
 /// <returns></returns>
 internal static LoteReimplanteInfo ObtenerPorID(DataSet ds)
 {
     try
     {
         Logger.Info();
         DataTable          dt      = ds.Tables[ConstantesDAL.DtDatos];
         LoteReimplanteInfo entidad =
             (from info in dt.AsEnumerable()
              select
              new LoteReimplanteInfo
         {
             LoteReimplanteID = info.Field <int>("LoteReimplanteID"),
             NumeroReimplante = info.Field <int>("NumeroReimplante"),
             FechaProyectada = info.Field <DateTime>("FechaProyectada"),
             PesoProyectado = info.Field <int>("PesoProyectado"),
             FechaReal = (info["FechaReal"] == DBNull.Value ? new DateTime() : info.Field <DateTime>("FechaReal")),
             PesoReal = (info["PesoReal"] == DBNull.Value ? 0 : info.Field <int>("PesoReal"))
         }).First();
         return(entidad);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #3
0
 /// <summary>
 /// Metodo para Guardar/Modificar una entidad LoteReimplante
 /// </summary>
 /// <param name="info"></param>
 internal int Guardar(LoteReimplanteInfo info)
 {
     try
     {
         Logger.Info();
         var loteReimplanteDAL = new LoteReimplanteDAL();
         int result            = info.LoteReimplanteID;
         if (info.LoteReimplanteID == 0)
         {
             result = loteReimplanteDAL.Crear(info);
         }
         else
         {
             loteReimplanteDAL.Actualizar(info);
         }
         return(result);
     }
     catch (ExcepcionGenerica)
     {
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #4
0
 /// <summary>
 ///  Obtiene parametros para actualizar
 /// </summary>
 /// <param name="info">Valores de la entidad</param>
 /// <returns></returns>
 internal static Dictionary <string, object> ObtenerParametrosActualizar(LoteReimplanteInfo info)
 {
     try
     {
         Logger.Info();
         var parametros =
             new Dictionary <string, object>
         {
             { "@LoteProyeccionID", info.LoteProyeccionID },
             { "@LoteProyeccionID", info.LoteProyeccionID },
             { "@NumeroReimplante", info.NumeroReimplante },
             { "@FechaProyectada", info.FechaProyectada },
             { "@PesoProyectado", info.PesoProyectado },
             { "@FechaReal", info.FechaReal },
             { "@PesoReal", info.PesoReal },
             { "@UsuarioModificacionID", info.UsuarioModificacionID },
         };
         return(parametros);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #5
0
 /// <summary>
 /// Obtiene el lote reimplante por lote id
 /// </summary>
 /// <param name="lote"></param>
 /// <returns></returns>
 internal LoteReimplanteInfo ObtenerPorLote(LoteInfo lote)
 {
     try
     {
         Logger.Info();
         var parameters            = AuxLoteReimplanteDAL.ObtenerParametrosPorLote(lote);
         var ds                    = Retrieve("LoteReimplante_ObtenerPorLote", parameters);
         LoteReimplanteInfo result = null;
         if (ValidateDataSet(ds))
         {
             result = MapLoteReimplanteDAL.ObtenerPorlote(ds);
         }
         return(result);
     }
     catch (SqlException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (DataException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #6
0
 /// <summary>
 /// Metodo para Crear un registro de LoteReimplante
 /// </summary>
 /// <param name="info">Valores de la entidad que será creada</param>
 internal int Crear(LoteReimplanteInfo info)
 {
     try
     {
         Logger.Info();
         Dictionary <string, object> parameters = AuxLoteReimplanteDAL.ObtenerParametrosCrear(info);
         int result = Create("LoteReimplante_Crear", parameters);
         return(result);
     }
     catch (SqlException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (DataException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #7
0
 /// <summary>
 /// Obtiene un registro de LoteReimplante
 /// </summary>
 /// <param name="descripcion">Descripción de la LoteReimplante</param>
 /// <returns></returns>
 internal LoteReimplanteInfo ObtenerPorDescripcion(string descripcion)
 {
     try
     {
         Logger.Info();
         Dictionary <string, object> parameters = AuxLoteReimplanteDAL.ObtenerParametrosPorDescripcion(descripcion);
         DataSet            ds     = Retrieve("LoteReimplante_ObtenerPorDescripcion", parameters);
         LoteReimplanteInfo result = null;
         if (ValidateDataSet(ds))
         {
             result = MapLoteReimplanteDAL.ObtenerPorDescripcion(ds);
         }
         return(result);
     }
     catch (SqlException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (DataException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #8
0
        public void ObtenerLoteReimplantePorId()
        {
            var loteReimplantePL = new LoteReimplantePL();
            LoteReimplanteInfo loteReimplante = loteReimplantePL.ObtenerPorID(1);

            Assert.IsNotNull(loteReimplante);
        }
Example #9
0
        private void GuardarProyeccion(CheckListCorralInfo checkListCorral, CheckListCorralDAL checkListCorralDAL)
        {
            var loteProyeccion          = checkListCorralDAL.GenerarProyeccion(checkListCorral);
            var loteProyeccionBL        = new LoteProyeccionPL();
            var listaReimplantesGuardar = new List <LoteReimplanteInfo>();

            if (loteProyeccion == null)
            {
                return;
            }
            loteProyeccion.UsuarioCreacionID = checkListCorral.UsuarioCreacionID;
            loteProyeccion.RequiereRevision  = checkListCorral.RequiereRevision;
            var loteProyeccionID = loteProyeccionBL.Guardar(loteProyeccion);

            var primerReimplante = new LoteReimplanteInfo
            {
                LoteProyeccionID  = loteProyeccionID,
                NumeroReimplante  = loteProyeccion.Proyeccion.PrimerReimplante,
                FechaProyectada   = loteProyeccion.Proyeccion.FechaProyectada1,
                PesoProyectado    = loteProyeccion.Proyeccion.PesoProyectado1,
                UsuarioCreacionID = checkListCorral.UsuarioCreacionID
            };

            if (primerReimplante.NumeroReimplante != 0 && primerReimplante.FechaProyectada != DateTime.MinValue && primerReimplante.PesoProyectado != 0)
            {
                listaReimplantesGuardar.Add(primerReimplante);
            }

            var segundoReimplante = new LoteReimplanteInfo
            {
                LoteProyeccionID  = loteProyeccionID,
                NumeroReimplante  = loteProyeccion.Proyeccion.SegundoReimplante,
                FechaProyectada   = loteProyeccion.Proyeccion.FechaProyectada2,
                PesoProyectado    = loteProyeccion.Proyeccion.PesoProyectado2,
                UsuarioCreacionID = checkListCorral.UsuarioCreacionID
            };

            if (segundoReimplante.NumeroReimplante != 0 && segundoReimplante.FechaProyectada != DateTime.MinValue && segundoReimplante.PesoProyectado != 0)
            {
                listaReimplantesGuardar.Add(segundoReimplante);
            }

            var loteReimplanteBL = new LoteReimplanteBL();

            if (listaReimplantesGuardar.Count > 0)
            {
                loteReimplanteBL.GuardarListaReimplantes(listaReimplantesGuardar);
            }

            checkListCorral.FechaSacrificio  = loteProyeccion.FechaSacrificio;
            checkListCorral.Fecha1Reimplante = loteProyeccion.Proyeccion.FechaProyectada1;
            checkListCorral.Fecha2Reimplante = loteProyeccion.Proyeccion.FechaProyectada2;
            checkListCorral.DiasEngorda      = loteProyeccion.DiasEngorda;
        }
 private void BtnCancelarAgregar_OnClick(object sender, RoutedEventArgs e)
 {
     if (Contexto.LoteProyeccion != null && Contexto.LoteProyeccion.ListaReimplantes != null && Contexto.LoteProyeccion.ListaReimplantes.Any())
     {
         LoteReimplanteInfo reimplanteCancelar = Contexto.LoteProyeccion.ListaReimplantes.Last();
         if (reimplanteCancelar.LoteReimplanteID == 0)
         {
             Contexto.LoteProyeccion.ListaReimplantes.Remove(reimplanteCancelar);
             ActualizarGrid();
         }
     }
 }
Example #11
0
 /// <summary>
 /// Obtiene una entidad LoteReimplante por su descripcion
 /// </summary>
 /// <param name="descripcion">Obtiene una entidad LoteReimplante por su Id</param>
 /// <returns></returns>
 internal LoteReimplanteInfo ObtenerPorDescripcion(string descripcion)
 {
     try
     {
         Logger.Info();
         var loteReimplanteDAL     = new LoteReimplanteDAL();
         LoteReimplanteInfo result = loteReimplanteDAL.ObtenerPorDescripcion(descripcion);
         return(result);
     }
     catch (ExcepcionGenerica)
     {
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #12
0
 /// <summary>
 /// Obtiene una entidad por su descripción
 /// </summary>
 /// <param name="descripcion"></param>
 /// <returns></returns>
 public LoteReimplanteInfo ObtenerPorLote(LoteInfo lote)
 {
     try
     {
         Logger.Info();
         var loteReimplanteBL      = new LoteReimplanteBL();
         LoteReimplanteInfo result = loteReimplanteBL.ObtenerPorLote(lote);
         return(result);
     }
     catch (ExcepcionGenerica)
     {
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #13
0
 /// <summary>
 /// Metodo para Guardar/Modificar una entidad LoteReimplante
 /// </summary>
 /// <param name="info">Representa la entidad que se va a grabar</param>
 public int Guardar(LoteReimplanteInfo info)
 {
     try
     {
         Logger.Info();
         var loteReimplanteBL = new LoteReimplanteBL();
         int result           = loteReimplanteBL.Guardar(info);
         return(result);
     }
     catch (ExcepcionGenerica)
     {
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
        internal bool GuardarFechaReal(String fechaReal, LoteReimplanteInfo loteReimplante)
        {
            try
            {
                Logger.Info();

                var programacionReimplanteDAL = new ProgramacionReimplanteDAL();
                var regresa = programacionReimplanteDAL.GuardarFechaReal(fechaReal, loteReimplante);
                return(regresa);
            }
            catch (ExcepcionGenerica)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }
        }
        private void BtnAgregarClick(object sender, RoutedEventArgs e)
        {
            try
            {
                int ultimoNumeroReimplante = 0;

                if (Contexto.LoteProyeccion != null && Contexto.LoteProyeccion.ListaReimplantes != null && Contexto.LoteProyeccion.ListaReimplantes.Any())
                {
                    LoteReimplanteInfo ultimoReimplante = Contexto.LoteProyeccion.ListaReimplantes.Last();
                    ultimoNumeroReimplante = ultimoReimplante.NumeroReimplante;
                }
                else
                {
                    if (Contexto.LoteProyeccion == null)
                    {
                        Contexto.LoteProyeccion = new LoteProyeccionInfo();
                    }
                    if (Contexto.LoteProyeccion.ListaReimplantes == null)
                    {
                        Contexto.LoteProyeccion.ListaReimplantes = new List <LoteReimplanteInfo>();
                    }
                }
                var reimplanteAgregar = new LoteReimplanteInfo
                {
                    NumeroReimplante = ultimoNumeroReimplante + 1,
                    FechaProyectada  = DateTime.Now,
                    PesoProyectado   = 0,
                    PermiteEditar    = true
                };
                Contexto.LoteProyeccion.ListaReimplantes.Add(reimplanteAgregar);
                ActualizarGrid();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                SkMessageBox.Show(Application.Current.Windows[ConstantesVista.WindowPrincipal],
                                  Properties.Resources.ConfiguracionReimplante_ErrorAgregarReimplante, MessageBoxButton.OK, MessageImage.Error);
            }
        }
Example #16
0
        /// <summary>
        /// Metodo para generar el nuevo LoteReimplante
        /// </summary>
        /// <param name="numeroReimplante"></param>
        /// <param name="loteProyeccion"></param>
        /// <param name="fechaProyectada"></param>
        /// <param name="usuario"></param>
        /// <param name="loteCorral"></param>
        /// <param name="pesoProyectado"></param>
        private void GuardarNuevoReimplante(int numeroReimplante, LoteProyeccionInfo loteProyeccion, DateTime fechaProyectada, UsuarioInfo usuario, LoteCorralReimplanteInfo loteCorral, int pesoProyectado, int pesoOrigenPromedio)
        {
            var loteReimplanteBL = new LoteReimplanteBL();
            var loteReimplante   = new LoteReimplanteInfo();

            if (numeroReimplante == 1)
            {
                loteReimplante = new LoteReimplanteInfo
                {
                    LoteProyeccionID  = loteProyeccion.LoteProyeccionID,
                    NumeroReimplante  = 2,
                    FechaProyectada   = fechaProyectada,
                    PesoProyectado    = pesoProyectado,
                    PesoReal          = 0,
                    FechaReal         = new DateTime(1900, 01, 01),
                    UsuarioCreacionID = usuario.UsuarioID
                };
                loteReimplanteBL.Guardar(loteReimplante);
            }
            else if (numeroReimplante == 2)
            {
                // El peso Origen sea menor a 200 generar el lote reimplante
                // y que los dias engorda sean mayores a 90 dias
                if (pesoOrigenPromedio <= 200 && loteProyeccion.DiasEngorda >= 90)
                {
                    loteReimplante = new LoteReimplanteInfo
                    {
                        LoteProyeccionID  = loteProyeccion.LoteProyeccionID,
                        NumeroReimplante  = 3,
                        FechaProyectada   = fechaProyectada,
                        PesoProyectado    = pesoProyectado,
                        PesoReal          = 0,
                        FechaReal         = new DateTime(1900, 01, 01),
                        UsuarioCreacionID = usuario.UsuarioID
                    };
                    loteReimplanteBL.Guardar(loteReimplante);
                }
            }
        }
Example #17
0
 /// <summary>
 /// Obtiene un lista paginada
 /// </summary>
 /// <param name="pagina"></param>
 /// <param name="filtro"></param>
 /// <returns></returns>
 internal ResultadoInfo <LoteReimplanteInfo> ObtenerPorPagina(PaginacionInfo pagina, LoteReimplanteInfo filtro)
 {
     try
     {
         Dictionary <string, object> parameters = AuxLoteReimplanteDAL.ObtenerParametrosPorPagina(pagina, filtro);
         DataSet ds = Retrieve("LoteReimplante_ObtenerPorPagina", parameters);
         ResultadoInfo <LoteReimplanteInfo> result = null;
         if (ValidateDataSet(ds))
         {
             result = MapLoteReimplanteDAL.ObtenerPorPagina(ds);
         }
         return(result);
     }
     catch (SqlException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (DataException ex)
     {
         Logger.Error(ex);
         throw new ExcepcionServicio(MethodBase.GetCurrentMethod(), ex);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #18
0
 /// <summary>
 /// Obtiene parametros para obtener lista paginada
 /// </summary>
 /// <param name="pagina"></param>
 /// <param name="filtro"></param>
 /// <returns></returns>
 internal static Dictionary <string, object> ObtenerParametrosPorPagina(PaginacionInfo pagina, LoteReimplanteInfo filtro)
 {
     try
     {
         Logger.Info();
         var parametros =
             new Dictionary <string, object>
         {
             { "@LoteReimplanteID", filtro.LoteReimplanteID },
             { "@Activo", filtro.Activo },
             { "@Inicio", pagina.Inicio },
             { "@Limite", pagina.Limite }
         };
         return(parametros);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
        /// <summary>
        /// obtiene los parametros Programaion Reimplante
        /// </summary>
        /// <param name="fechaReal"></param>
        /// <param name="loteReimplante"></param>
        /// <returns></returns>
        internal static Dictionary <string, object> ObtenerParametrosFechaReal(String fechaReal, LoteReimplanteInfo loteReimplante)
        {
            Dictionary <string, object> parametros;

            try
            {
                Logger.Info();
                parametros = new Dictionary <string, object>
                {
                    { "@NoLote", loteReimplante.LoteReimplanteID },
                    { "@TipoMovimiento", loteReimplante.TipoMovimientoID },
                    { "@FolioEntrada", loteReimplante.FolioEntrada },
                    { "@NumCabezas", loteReimplante.NumCabezas },
                    { "@LoteReimplanteID", loteReimplante.LoteReimplanteID }
                };
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }
            return(parametros);
        }
Example #20
0
 /// <summary>
 /// Obtiene un lista paginada
 /// </summary>
 /// <param name="pagina"></param>
 /// <param name="filtro"></param>
 /// <returns></returns>
 internal ResultadoInfo <LoteReimplanteInfo> ObtenerPorPagina(PaginacionInfo pagina, LoteReimplanteInfo filtro)
 {
     try
     {
         Logger.Info();
         var loteReimplanteDAL = new LoteReimplanteDAL();
         ResultadoInfo <LoteReimplanteInfo> result = loteReimplanteDAL.ObtenerPorPagina(pagina, filtro);
         return(result);
     }
     catch (ExcepcionGenerica)
     {
         throw;
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
     }
 }
Example #21
0
        /// <summary>
        /// Metodo para generar la proyeccion de reimplante
        /// </summary>
        internal void GenerarProyeccionReimplante()
        {
            //ResultadoPolizaModel resultadoPolizaModel = null;
            try
            {
                Logger.Info();
                var organizacionBL   = new OrganizacionBL();
                var usuarioBL        = new UsuarioBL();
                var loteBL           = new LoteBL();
                var corralBl         = new CorralBL();
                var loteProyeccionBL = new LoteProyeccionBL();
                var loteReimplanteBL = new LoteReimplanteBL();
                //Se obtiene el usuario del proceso de alimentacion
                UsuarioInfo usuario = usuarioBL.ObtenerPorActiveDirectory(UsuarioProcesosEnum.ProyeccionReimplante.ToString());
                //Si se encontro el usuario
                if (usuario != null)
                {
                    //Consulta todas las organizaciones que esten activas
                    List <OrganizacionInfo> listaOrganizaciones =
                        organizacionBL.ObtenerTodos(EstatusEnum.Activo).ToList();
                    if (listaOrganizaciones != null && listaOrganizaciones.Any())
                    {
                        //Se obtienen las organizaciones que son de tipo ganadera
                        List <OrganizacionInfo> listaOrganizacionesFiltrada =
                            listaOrganizaciones.Where(
                                organizacion =>
                                organizacion.TipoOrganizacion.TipoOrganizacionID == (int)TipoOrganizacion.Ganadera)
                            .ToList();
                        if (listaOrganizacionesFiltrada.Count > 0)
                        {
                            foreach (OrganizacionInfo organizacion in listaOrganizacionesFiltrada)
                            {
                                try
                                {
                                    //using (var scope = new TransactionScope())
                                    //{

                                    //Obtener los corrales-Lotes que fueron reimplantados
                                    List <LoteCorralReimplanteInfo> listaCorrales = ObtenerCorralesReimplantados(organizacion);
                                    if (listaCorrales != null && listaCorrales.Any())
                                    {
                                        foreach (var loteCorral in listaCorrales)
                                        {
                                            //Obtener el tipo de ganado del lote
                                            TipoGanadoInfo tipoGanadoInfo = loteBL.ObtenerTipoGanadoLoteID(loteCorral.Lote);
                                            //Info del lote
                                            loteCorral.Lote = loteBL.ObtenerPorID(loteCorral.Lote.LoteID);

                                            //Obtener las proyecciones de los corrales origenes
                                            IList <LoteProyeccionInfo> listaProyeccionOrigen =
                                                loteProyeccionBL.ObtenerProyeccionDeLotesOrigen(loteCorral);

                                            if (listaProyeccionOrigen != null && listaProyeccionOrigen.Any())
                                            {
                                                var pesoReimplantePromedio = loteCorral.PesoReimplante /
                                                                             loteCorral.TotalCabezas;
                                                var pesoOrigenPromedio = loteCorral.PesoOrigen /
                                                                         loteCorral.TotalCabezas;

                                                //ObtenerDias engorda del corral
                                                var diasEngordaCorral =
                                                    corralBl.ObtenerDiasEngordaPorLote(loteCorral.Lote);
                                                //Calcular la Ganacia Diaria = (PesoReimplante-PesoOrigen)/DiasEngordaDelCorral
                                                decimal gananciaDiaria =
                                                    ((pesoReimplantePromedio - pesoOrigenPromedio) /
                                                     (decimal)diasEngordaCorral);
                                                gananciaDiaria = Math.Round(gananciaDiaria, 2);

                                                //Calculo diasEngorda: (PesoSalida-PesoPromedioReimplante)/GananciaDiaria
                                                var diasEngorda = (int)((tipoGanadoInfo.PesoSalida - pesoReimplantePromedio) /
                                                                        gananciaDiaria);

                                                var loteProyeccion =
                                                    loteProyeccionBL.ObtenerPorLote(loteCorral.Lote);

                                                LoteReimplanteInfo loteReimplante = null;
                                                var numeroReimplante = listaProyeccionOrigen.Max(p => p.NumeroReimplante);


                                                if (loteProyeccion == null)
                                                {
                                                    // Se crea el registro en lote proyeccion
                                                    loteProyeccion = new LoteProyeccionInfo
                                                    {
                                                        LoteID            = loteCorral.Lote.LoteID,      //OK
                                                        OrganizacionID    = organizacion.OrganizacionID, //OK
                                                        Frame             = 0,                           //OK
                                                        GananciaDiaria    = gananciaDiaria,              //OK
                                                        ConsumoBaseHumeda =
                                                            listaProyeccionOrigen.Select(p => p.ConsumoBaseHumeda).Sum() /
                                                            listaProyeccionOrigen.Count(),     // Promedio De los Corrales Origenes
                                                        Conversion =
                                                            listaProyeccionOrigen.Select(p => p.Conversion).Sum() /
                                                            listaProyeccionOrigen.Count(),     // Promedio De los Corrales Origenes
                                                        PesoMaduro =
                                                            listaProyeccionOrigen.Select(p => p.PesoMaduro).Sum() /
                                                            listaProyeccionOrigen.Count(),     // Promedio De los Corrales Origenes
                                                        PesoSacrificio =
                                                            listaProyeccionOrigen.Select(p => p.PesoSacrificio).Sum() /
                                                            listaProyeccionOrigen.Count(), // Promedio De los Corrales Origenes
                                                        DiasEngorda        = diasEngorda,  // OK
                                                        FechaEntradaZilmax =
                                                            ObtenerFechaZilmax(loteCorral.Lote, tipoGanadoInfo,
                                                                               diasEngorda),  //OK
                                                        UsuarioCreacionID = usuario.UsuarioID //OK
                                                    };

                                                    loteProyeccion.LoteProyeccionID =
                                                        loteProyeccionBL.Guardar(loteProyeccion);

                                                    // Fecha Sacrificio = fechaInicioLote + loteProyeccion.DiasEngorda
                                                    DateTime fechaProyectada =
                                                        loteCorral.Lote.FechaInicio.AddDays(loteProyeccion.DiasEngorda);

                                                    DateTime fechaHoy = DateTime.Now;
                                                    TimeSpan ts       = fechaProyectada - fechaHoy;
                                                    // GananciaDiaria*DiasQueFlatanParaReimplante) + PesoReimplante
                                                    int pesoProyectado =
                                                        (int)
                                                        ((loteProyeccion.GananciaDiaria * ts.Days) +
                                                         pesoReimplantePromedio);
                                                    //Se almacena el lote reimplante nuevo
                                                    GuardarNuevoReimplante(numeroReimplante, loteProyeccion, fechaProyectada, usuario, loteCorral, pesoProyectado, pesoOrigenPromedio);
                                                }
                                                else
                                                {
                                                    // Si ya existe el LoteProyeccion Obtener los lotesReimplantes
                                                    List <LoteReimplanteInfo> loteReimplanteInfo =
                                                        loteReimplanteBL.ObtenerListaPorLote(loteCorral.Lote);

                                                    DateTime fechaProyectada =
                                                        loteCorral.Lote.FechaInicio.AddDays(loteProyeccion.DiasEngorda);
                                                    DateTime fechaHoy = DateTime.Now;
                                                    TimeSpan ts       = fechaProyectada - fechaHoy;
                                                    // GananciaDiaria*DiasQueFlatanParaReimplante) + PesoReimplante
                                                    int pesoProyectado =
                                                        (int)
                                                        ((loteProyeccion.GananciaDiaria * ts.Days) +
                                                         pesoReimplantePromedio);

                                                    if (loteReimplanteInfo != null)
                                                    {
                                                        var numeroReimplanteMaximo = loteReimplanteInfo.Max(p => p.NumeroReimplante);
                                                        if (numeroReimplante == 2 && numeroReimplanteMaximo != 3)
                                                        {
                                                            // El peso Origen sea menor a 200 generar el lote reimplante
                                                            // y que los dias engorda sean mayores a 90 dias
                                                            if (pesoOrigenPromedio <= 200 && loteProyeccion.DiasEngorda >= 90)
                                                            {
                                                                // Se crea el registro en lote reimplante
                                                                loteReimplante = new LoteReimplanteInfo
                                                                {
                                                                    LoteProyeccionID  = loteProyeccion.LoteProyeccionID,
                                                                    NumeroReimplante  = 3,
                                                                    FechaProyectada   = fechaProyectada,
                                                                    PesoProyectado    = pesoProyectado,
                                                                    PesoReal          = 0,
                                                                    FechaReal         = new DateTime(1900, 01, 01),
                                                                    UsuarioCreacionID = usuario.UsuarioID
                                                                };
                                                                loteReimplanteBL.Guardar(loteReimplante);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        //Se almacena el lote reimplante nuevo
                                                        GuardarNuevoReimplante(numeroReimplante, loteProyeccion, fechaProyectada, usuario, loteCorral, pesoProyectado, pesoOrigenPromedio);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    //    scope.Complete();
                                    //}
                                }
                                catch (Exception ex)
                                {
                                    var bitacoraBL = new BitacoraIncidenciasBL();
                                    var bitacora   = new BitacoraErroresInfo
                                    {
                                        AccionesSiapID    = AccionesSIAPEnum.SerProReim,
                                        Mensaje           = ex.Message,
                                        UsuarioCreacionID = usuario.UsuarioID
                                    };
                                    bitacoraBL.GuardarError(bitacora);
                                }
                            }
                        }
                    }
                }
            }
            catch (ExcepcionServicio ex)
            {
                Logger.Error(ex);
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw new ExcepcionDesconocida(MethodBase.GetCurrentMethod(), ex);
            }
        }