예제 #1
0
        public static void InsertarPagosCuotas(SMPorresEntities db, Curso curso, int id)
        {
            short minC = CursosRepository.ObtieneMinCuota(curso.Modalidad);
            short maxC = CursosRepository.ObtieneMaxCuota(curso.Modalidad);

            var cuotas = from c in CuotasRepository.ObtenerCuotasActuales()
                         select new { c.NroCuota, c.VtoCuota };

            if (minC != maxC)
            {
                //for (short i = 0; i <= Configuration.MaxCuotas; i++)
                for (short i = minC; i <= maxC; i++)
                {
                    var p = new Pago();
                    p.Id           = db.Pagos.Any() ? db.Pagos.Max(p1 => p1.Id) + 1 : 1;
                    p.IdPlanPago   = id;
                    p.NroCuota     = i;
                    p.ImporteCuota = (i == 0) ? curso.ImporteMatricula : curso.ImporteCuota;
                    p.Estado       = (byte)EstadoPago.Impago;
                    p.FechaVto     = cuotas.First(c => c.NroCuota == i).VtoCuota;
                    db.Pagos.Add(p);
                    db.SaveChanges();
                }
            }
        }
예제 #2
0
        public static PlanPago Insertar(SMPorresEntities db, int idAlumno, int idCurso)
        {
            _log.Debug("Creando plan de pago");

            if (idAlumno == 0)
            {
                throw new Exception("No se pudo determinar el alumno.");
            }
            if (idCurso == 0)
            {
                throw new Exception("No se pudo determinar el curso.");
            }

            if (db.PlanesPago.Any(pp => pp.IdAlumno == idAlumno && pp.IdCurso == idCurso & pp.Estado == (short)EstadoPlanPago.Vigente))
            {
                throw new Exception("El alumno ya tiene un plan de pago vigente en este curso.");
            }

            var curso = CursosRepository.ObtenerCursoPorId(idCurso);

            if (curso == null)
            {
                throw new Exception("No se encontró el curso " + idCurso);
            }

            var id = db.PlanesPago.Any() ? db.PlanesPago.Max(c1 => c1.Id) + 1 : 1;
            //var trx = db.Database.BeginTransaction();
            var plan = new PlanPago
            {
                Id              = id,
                IdAlumno        = idAlumno,
                IdCurso         = idCurso,
                CantidadCuotas  = CursosRepository.ObtieneMaxCuota(curso.Modalidad), //Configuration.MaxCuotas,
                NroCuota        = CursosRepository.ObtieneMinCuota(curso.Modalidad), //1,
                ImporteCuota    = curso.ImporteCuota,
                PorcentajeBeca  = 0,
                TipoBeca        = (byte)TipoBeca.AplicaHastaVto,
                Estado          = (short)EstadoPlanPago.Vigente,
                IdUsuarioEstado = Session.CurrentUser.Id,
                FechaGrabacion  = Configuration.CurrentDate,
                IdUsuario       = Session.CurrentUser.Id,
                Modalidad       = curso.Modalidad
            };

            _log.Debug("Generando pagos");
            try
            {
                db.PlanesPago.Add(plan);
                db.SaveChanges();

                PagosRepository.InsertarMatricula(db, curso, id);

                PagosRepository.InsertarPagosCuotas(db, curso, id);
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                //trx.Rollback();
                throw;
            }
            return(plan);
        }