Example #1
0
        /// <summary>
        /// Process All conciliaciones for the given tank.
        /// </summary>
        /// <param name="tanque"></param>
        public void ProcessConciliacionesWithoutTransaction(Tanque tanque)
        {
            try
            {
                var movementDAO = new MovimientoDAO();

                foreach (var m in movementDAO.FindNotProcessedConciliaciones(tanque))
                {
                    var lastTeoricMovement = GetLastTankTeoricMovement(tanque, m.Fecha);
                    var lastTeoricVolume   = lastTeoricMovement != null ? lastTeoricMovement.Volumen : 0;

                    /*if its the first tank teoric volume inserts the Most Nearest of the Real Volumes*/
                    if (lastTeoricMovement != null &&
                        !lastTeoricMovement.EsTeorico)
                    {
                        var v = new VolumenHistorico {
                            Fecha = m.Fecha, EsTeorico = true, Tanque = tanque, Volumen = lastTeoricVolume, VolumenAgua = 0
                        };

                        SaveOrUpdate(v);
                    }

                    var volHistorico = new VolumenHistorico
                    {
                        Fecha     = m.Fecha,
                        EsTeorico = true,
                        Tanque    = tanque,
                        Volumen   =
                            m.TipoMovimiento.Codigo.Equals("E")
                                                   ? lastTeoricVolume - m.Volumen
                                                   : lastTeoricVolume + m.Volumen,
                        VolumenAgua = 0
                    };

                    SaveOrUpdate(volHistorico);

                    UpdateTeoricVolumesAfterDate(tanque, m.Fecha, m.TipoMovimiento.Codigo.Equals("E") ? -1 * m.Volumen : m.Volumen);

                    m.Procesado = true;
                    movementDAO.SaveOrUpdate(m);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Error processing Conciliaciones for tank by Equipo {0} ", tanque.Id), ex);
            }
        }
Example #2
0
        /// <summary>
        /// Generates all the teoric volumes for the given tank using the unprocessed movements assigned to it.
        /// </summary>
        /// <param name="tanque"></param>
        public void GenerateTeoricVolumesWithoutTransaction(Tanque tanque)
        {
            {
                try
                {
                    var movementDAO = new MovimientoDAO();
                    var tanqueDAO   = new TanqueDAO();

                    var list = movementDAO.FindAllSumarizedMovementsNotProcessed(tanque.Equipo);

                    if (!list.Any())
                    {
                        return;
                    }

                    var lastTeoricMovement = GetLastTankTeoricMovement(tanque, list.First().Fecha);
                    var lastTeoricVolume   = lastTeoricMovement != null ? lastTeoricMovement.Volumen : 0;
                    var firstTime          = true;

                    foreach (var m in list)
                    {
                        /*if its the first tank teoric volume inserts the Most Nearest of the Real Volumes*/
                        if (firstTime &&
                            lastTeoricMovement != null &&
                            !lastTeoricMovement.EsTeorico)
                        {
                            var v = new VolumenHistorico {
                                Fecha = m.Fecha, EsTeorico = true, Tanque = tanque, Volumen = lastTeoricVolume, VolumenAgua = 0
                            };

                            SaveOrUpdate(v);
                        }

                        lastTeoricVolume = m.TipoMovimiento.Codigo.Equals("M") ? lastTeoricVolume - m.Volumen : lastTeoricVolume + m.Volumen;

                        var volHistorico = new VolumenHistorico
                        {
                            Fecha       = m.Fecha,
                            EsTeorico   = true,
                            Tanque      = tanque,
                            Volumen     = lastTeoricVolume,
                            VolumenAgua = 0
                        };

                        SaveOrUpdate(volHistorico);

                        m.Procesado = true;

                        movementDAO.SaveOrUpdate(m);

                        firstTime = false;
                    }

                    tanque.VolTeorico = lastTeoricVolume;

                    tanqueDAO.SaveOrUpdate(tanque);
                }
                catch (Exception ex)
                {
                    throw new Exception(String.Format("Error generating teoric volumes for tank by Equipo {0} ", tanque.Id), ex);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Process all the movements for the givenn tank, Generating is teoric Volume.
        /// </summary>
        /// <param name="tanque"></param>
        public void GenerateTanksByPlantaTeoricVolumes(Tanque tanque)
        {
            try
            {
                var movementDao = new MovimientoDAO();
                var movimientos = movementDao.FindRemitosAjustesAndDespachosByTanque(tanque.Id);

                var firstTime = true;

                if (movimientos.Count.Equals(0))
                {
                    return;
                }
                using (var transaction = SmartTransaction.BeginTransaction())
                {
                    try
                    {
                        foreach (Movimiento mov in movimientos)
                        {
                            var lastMovement    = GetLastTankTeoricMovement(tanque, mov.Fecha);
                            var volumenAnterior = lastMovement != null ? lastMovement.Volumen : 0;

                            /*if its the first tank teoric volume inserts the Most Nearest of the Real Volumes*/
                            if (firstTime &&
                                lastMovement != null &&
                                !lastMovement.EsTeorico)
                            {
                                var v = new VolumenHistorico {
                                    Fecha = mov.Fecha, Volumen = volumenAnterior, EsTeorico = true, Tanque = tanque
                                };

                                SaveOrUpdate(v);
                            }

                            var movementVolume = mov.TipoMovimiento.Codigo.Equals("D") ? -1 * mov.Volumen : mov.Volumen;

                            SaveOrUpdate(new VolumenHistorico {
                                Fecha = mov.Fecha, Volumen = volumenAnterior + movementVolume, EsTeorico = true, Tanque = tanque
                            });

                            UpdateTeoricVolumesAfterDate(tanque, mov.Fecha, movementVolume);

                            mov.Procesado = true;
                            movementDao.SaveOrUpdate(mov);
                            firstTime = false;
                        }
                        try
                        {
                            transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            STrace.Exception(typeof(LineaDAO).FullName, ex, "Exception in GenerateTanksByPlantaTeoricVolumes(Tanque) -> transaction.Commit();");
                            throw ex;
                        }
                    }
                    catch (Exception ex)
                    {
                        STrace.Exception(typeof(LineaDAO).FullName, ex, "Exception in GenerateTanksByPlantaTeoricVolumes(Tanque)");
                        try
                        {
                            transaction.Rollback();
                        }
                        catch (Exception ex2)
                        {
                            STrace.Exception(typeof(LineaDAO).FullName, ex2,
                                             "Exception in GenerateTanksByPlantaTeoricVolumes(Tanque) -> transaction.Rollback();");
                        }
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Error procesing teoric volume for tank by Planta {0} ", tanque.Id), ex);
            }
        }