Example #1
0
        public ActionResult Create(abonocapital abonocapital, string empresaId, string creditoId)
        {
            ModelState.Clear();
            abonocapital.CreditoId = Convert.ToInt32(MiUtil.desEncriptar(HttpUtility.UrlDecode(creditoId)));
            TryValidateModel(abonocapital);
            if (ModelState.IsValid)
            {
                string      ok     = "";
                consecutivo consec = db.consecutivo.Find(Convert.ToInt32(MiUtil.desEncriptar(HttpUtility.UrlDecode(empresaId))));
                consec.AbonoCapitalNro       = consec.AbonoCapitalNro + 1;
                abonocapital.AbonoCapitalNro = consec.AbonoCapitalNro;

                credito      cre    = db.credito.Find(Convert.ToInt32(MiUtil.desEncriptar(HttpUtility.UrlDecode(creditoId))));
                List <cuota> cuotas = db.cuota.Where(c => c.CreditoId == abonocapital.CreditoId).ToList();
                backup_cuota(abonocapital, cuotas);
                ok = cre.abonoACapital(abonocapital.Fecha, abonocapital.Valor);

                if (ok == "")
                {
                    db.abonocapital.Add(abonocapital);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { creditoId = creditoId }));
                }
                else
                {
                    ModelState.AddModelError("", ok);
                }
            }
            ViewBag.empresaId = empresaId;
            ViewBag.creditoId = creditoId;
            //ViewBag.CreditoId = new SelectList(db.credito.Where(c=>c.Estado==true).OrderBy(e=>e.TipoCuotaId), "CreditoId", "TipoCuotaId", abonocapital.CreditoId);
            return(View(abonocapital));
        }
        public async Task <IHttpActionResult> Postcredito(credito credito)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.credito.Add(credito);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (creditoExists(credito.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = credito.id }, credito));
        }
        public async Task <IHttpActionResult> Putcredito(int id, credito credito)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != credito.id)
            {
                return(BadRequest());
            }

            db.Entry(credito).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!creditoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #4
0
        // GET: Credito/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            string  idDecrypted = MiUtil.desEncriptar(HttpUtility.UrlDecode(id));
            int     intId       = Convert.ToInt32(idDecrypted);
            credito credito     = db.credito.Find(intId);

            if (credito == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ClienteId         = new SelectList(db.cliente.Where(c => c.Estado == true && c.EmpresaId == credito.EmpresaId).OrderBy(e => e.Nit), "ClienteId", "Nombre", credito.ClienteId);
            ViewBag.TipoCuotaId       = new SelectList(db.tipocuota.Where(c => c.Estado == true).OrderBy(e => e.Nombre), "TipoCuotaId", "Nombre", credito.TipoCuotaId);
            ViewBag.DivisionCreditoId = new SelectList(db.divisioncredito.Where(c => c.Estado == true).OrderBy(e => e.Nombre), "DivisionCreditoId", "Nombre", credito.DivisionCreditoId);
            ViewBag.UsuarioId         = new SelectList(db.usuario.Where(c => c.Estado == true && c.EmpresaId == credito.EmpresaId).OrderBy(e => e.UsuNombre), "UsuarioId", "UsuNombre", credito.UsuarioId);
            if (credito.tieneAbonosActivos())
            {
                ViewBag.Layout     = 1;
                ViewBag.action     = "index";
                ViewBag.controller = "Credito";
                ViewBag.tipo       = "bg-danger";
                ViewBag.mensaje    = "El credito " + credito.CreditoId + " tiene abonos activos, No es posible modificar un credito con abonos activos";
                return(View("../Shared/Mensaje"));
            }
            else
            {
                return(View(credito));
            }
        }
Example #5
0
        public ActionResult Create(string button, [Bind(Include = "CreditoId,Fecha,ClienteId,Valor,Interes,Meses,TipoCuotaId,PrimCuota,DivisionCreditoId,InteresPrimCuota,CapitalFinalCredito,Observacion,Estado,CreadoPor,FechaCreacion,ModificadoPor,FechaModificacion,EmpresaId,UsuarioId")] credito credito)
        {
            if (button.Equals("Cancelar"))
            {
                return(RedirectToAction("Index"));
            }


            if (ModelState.IsValid)
            {
                credito.CalcularCuotas();
                if (button.Equals("Crear Credito"))
                {
                    int empresaId = 0;
                    if (Session["EmpresaId"] != null)
                    {
                        Int32.TryParse(Session["EmpresaId"].ToString(), out empresaId);
                    }
                    consecutivo c = db.consecutivo.Find(empresaId);
                    c.CreditoNro       = c.CreditoNro + 1;
                    credito.CreditoNro = c.CreditoNro;
                    db.credito.Add(credito);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            ViewBag.ClienteId         = new SelectList(db.cliente.Where(c => c.Estado == true && c.EmpresaId == credito.EmpresaId).OrderBy(e => e.Nit), "ClienteId", "Nombre", credito.ClienteId);
            ViewBag.TipoCuotaId       = new SelectList(db.tipocuota.Where(c => c.Estado == true).OrderBy(e => e.Nombre), "TipoCuotaId", "Nombre", credito.TipoCuotaId);
            ViewBag.DivisionCreditoId = new SelectList(db.divisioncredito.Where(c => c.Estado == true).OrderBy(e => e.Nombre), "DivisionCreditoId", "Nombre", credito.DivisionCreditoId);
            ViewBag.UsuarioId         = new SelectList(db.usuario.Where(c => c.Estado == true && c.EmpresaId == credito.EmpresaId).OrderBy(e => e.UsuNombre), "UsuarioId", "UsuNombre");
            return(View(credito));
        }
Example #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            credito credito = db.credito.Find(id);

            db.credito.Remove(credito);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #7
0
 public ActionResult Edit([Bind(Include = "id,descripcion,dias")] credito credito)
 {
     if (ModelState.IsValid)
     {
         db.Entry(credito).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(credito));
 }
Example #8
0
 public ActionResult Edit([Bind(Include = "codigo,Monto,Descripcion,estado,cuenta")] credito credito)
 {
     if (ModelState.IsValid)
     {
         db.Entry(credito).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.cuenta = new SelectList(db.cuenta, "codigo", "Numero", credito.cuenta);
     return(View(credito));
 }
Example #9
0
        public ActionResult Create([Bind(Include = "id,descripcion,dias")] credito credito)
        {
            if (ModelState.IsValid)
            {
                db.credito.Add(credito);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(credito));
        }
        public async Task <IHttpActionResult> Getcredito(int id)
        {
            credito credito = await db.credito.FindAsync(id);

            if (credito == null)
            {
                return(NotFound());
            }

            return(Ok(credito));
        }
Example #11
0
 public ActionResult Create([Bind(Include = "Monto,Descripcion,estado,cuenta")] credito credito)
 {
     a = "s"; // 's' sin resolver
     credito.estado = a;
     if (ModelState.IsValid)
     {
         db.credito.Add(credito);
         db.SaveChanges();
         return(RedirectToAction("Index", "Usuario"));
     }
     return(RedirectToAction("Index"));
 }
Example #12
0
        // GET: creditoes/Details/5
        public ActionResult Details(int?id, bool si)
        {
            if (Session["codigo"] != null)
            {
                if (id == null)
                {
                    return(RedirectToAction("Index"));
                }
                credito credi = db.credito.Find(id);
                if (credi == null)
                {
                    return(HttpNotFound());
                }
                if (si)
                {
                    cuenta cuentica = db.cuenta.Find(credi.cuenta);
                    if (cuentica == null)
                    {
                        return(HttpNotFound());
                    }
                    cuentica.Saldo = cuentica.Saldo + credi.Monto;
                    a                        = "a"; //aceptado
                    credi.estado             = a;
                    db.Entry(cuentica).State = EntityState.Modified;
                    db.Entry(credi).State    = EntityState.Modified;
                    db.SaveChanges();

                    MovimientoController mc   = new MovimientoController();
                    movimiento           movi = new movimiento();
                    movi.Monto     = credi.Monto;
                    movi.mov       = "C";
                    movi.fecha     = DateTime.Now;
                    movi.cuentaUno = cuentica.Numero;
                    movi.cuentaDos = null;

                    if (mc.Create(movi))
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    a                     = "r"; //rechazada
                    credi.estado          = a;
                    db.Entry(credi).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Login", "Usuario"));
        }
        public async Task <IHttpActionResult> Deletecredito(int id)
        {
            credito credito = await db.credito.FindAsync(id);

            if (credito == null)
            {
                return(NotFound());
            }

            db.credito.Remove(credito);
            await db.SaveChangesAsync();

            return(Ok(credito));
        }
        public void CreateTest()
        {
            CreditoController cc = new CreditoController();
            credito           cr = new credito()
            {
                Monto       = 1200,
                Descripcion = "porque si",
                cuenta      = 1000,
                estado      = "s"
            };
            var result = cc.Create(cr) as ViewResult;

            Assert.AreEqual("Index", result.ViewName);
        }
Example #15
0
        // GET: creditoes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            credito credito = db.credito.Find(id);

            if (credito == null)
            {
                return(HttpNotFound());
            }
            return(View(credito));
        }
Example #16
0
        // GET: AbonoCapital/Create
        public ActionResult Create(string creditoId)
        {
            ViewBag.creditoId = creditoId;
            string  idDecrypted = MiUtil.desEncriptar(HttpUtility.UrlDecode(creditoId));
            int     intId       = Convert.ToInt32(idDecrypted);
            credito cre         = db.credito.Find(intId);

            ViewBag.empresaId = MiUtil.encriptar(db.credito.Find(intId).EmpresaId.ToString());
            decimal?saldoTotal = cre.saldoTotalAFecha(DateTime.Now);

            //new SelectList(db.credito.Where(c=>c.Estado==true).OrderBy(e=>e.TipoCuotaId), "CreditoId", "TipoCuotaId");
            return(View(new abonocapital {
                Fecha = DateTime.Now, Valor = saldoTotal
            }));
        }
Example #17
0
        // GET: creditoes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            credito credito = db.credito.Find(id);

            if (credito == null)
            {
                return(HttpNotFound());
            }
            ViewBag.cuenta = new SelectList(db.cuenta, "codigo", "Numero", credito.cuenta);
            return(View(credito));
        }
Example #18
0
        public credito getCreate()
        {
            int empresaId = 0;

            if (Session["EmpresaId"] != null)
            {
                Int32.TryParse(Session["EmpresaId"].ToString(), out empresaId);
            }

            ViewBag.ClienteId         = new SelectList(db.cliente.Where(c => c.Estado == true && c.EmpresaId == empresaId).OrderBy(e => e.Nit), "ClienteId", "Nombre");
            ViewBag.TipoCuotaId       = new SelectList(db.tipocuota.Where(c => c.Estado == true).OrderBy(e => e.Nombre), "TipoCuotaId", "Nombre");
            ViewBag.DivisionCreditoId = new SelectList(db.divisioncredito.Where(c => c.Estado == true).OrderBy(e => e.Nombre), "DivisionCreditoId", "Nombre");
            ViewBag.UsuarioId         = new SelectList(db.usuario.Where(c => c.Estado == true && c.EmpresaId == empresaId).OrderBy(e => e.UsuNombre), "UsuarioId", "UsuNombre");
            credito cr = new credito();

            cr.Fecha     = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            cr.Estado    = true;
            cr.EmpresaId = empresaId;
            return(cr);
        }
Example #19
0
        // GET: Credito/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            string  idDecrypted = MiUtil.desEncriptar(HttpUtility.UrlDecode(id));
            int     intId       = Convert.ToInt32(idDecrypted);
            credito credito     = db.credito.Find(intId);

            if (credito == null)
            {
                return(HttpNotFound());
            }
            foreach (cuota c in credito.cuota)
            {
                c.SaldoCapital = c.calcularSaldoxCapital();
                c.SaldoInteres = c.calcularSaldoxInteres();
            }
            return(View(credito));
        }
Example #20
0
        public ImpresionAbono impresionAbono(int abonoId)
        {
            ImpresionAbono ia    = null;
            abono          abono = (abono)db.abono.Find(abonoId);

            if (abono.Estado)
            {
                cuota   cuota   = (cuota)db.cuota.Find(abono.CuotaId);
                credito credito = (credito)db.credito.Find(cuota.CreditoId);
                empresa empresa = (empresa)db.empresa.Find(credito.cliente.EmpresaId);
                ia                   = new ImpresionAbono();
                ia.LogoEmpresa       = "~/Uploads/Logos/" + empresa.LogoUrl;
                ia.EmpresaId         = empresa.EmpresaId;
                ia.EmpresaNit        = empresa.Nit;
                ia.EmpresaNombre     = empresa.Nombre;
                ia.ClienteNit        = credito.cliente.Nit;
                ia.ClienteNombre     = credito.cliente.Nombre;
                ia.EmailCliente      = credito.cliente.Email;
                ia.CreditoId         = credito.CreditoId;
                ia.CreditoNro        = credito.CreditoNro;
                ia.CreditoValor      = credito.Valor;
                ia.CreditoCantCuotas = credito.cuota.Count;
                ia.CuotaNro          = cuota.Numero;
                ia.CuotaValor        = cuota.AbonoCapital + cuota.AbonoInteres + MiUtil.nullTodecimal(cuota.AjusteAbonoCapital) + MiUtil.nullTodecimal(cuota.AjusteAbonoInteres);
                ia.AbonoId           = abonoId;
                ia.AbonoNro          = abono.AbonoNro;
                ia.AbonoFecha        = abono.Fecha;
                ia.AbonoValor        = abono.Valor;
                decimal?porcenInteres = cuota.porcentajeInteres();
                decimal?porcenCapital = cuota.porcentajeCapital();
                ia.AbonoInteres        = ia.AbonoValor * (porcenInteres / 100);
                ia.AbonoCapital        = ia.AbonoValor * (porcenCapital / 100);
                ia.CreditoSaldoInteres = credito.calcularTotalInteres() - credito.calcularAbonoInteres(abono.Fecha);
                ia.CreditoSaldoCapital = credito.calcularTotalCapital() - credito.calcularAbonoCapital(abono.Fecha);
                ia.TotalAbono          = ia.AbonoCapital + ia.AbonoInteres;
                ia.SaldoCuota          = cuota.calcularSaldoxCapital(abono.Fecha) + cuota.calcularSaldoxInteres(abono.Fecha);
                //ia.CuotaValor - ia.TotalAbono;
            }
            return(ia);
        }
Example #21
0
        // GET: AbonoCapital/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            string       idDecrypted  = MiUtil.desEncriptar(HttpUtility.UrlDecode(id));
            int          intId        = Convert.ToInt32(idDecrypted);
            abonocapital abonocapital = db.abonocapital.Find(intId);

            if (abonocapital == null)
            {
                return(HttpNotFound());
            }
            ViewBag.creditoId = MiUtil.encriptar(abonocapital.CreditoId.ToString());
            //new SelectList(db.credito.Where(c=>c.Estado==true).OrderBy(e=>e.TipoCuotaId), "CreditoId", "TipoCuotaId", abonocapital.CreditoId);
            credito cr = db.credito.Find(abonocapital.CreditoId);

            ViewBag.empresaId = MiUtil.encriptar(cr.EmpresaId.ToString());

            return(View(abonocapital));
        }
Example #22
0
        public ActionResult Edit(string button, [Bind(Include = "CreditoId,Fecha,ClienteId,Valor,Interes,Meses,TipoCuotaId,PrimCuota,DivisionCreditoId,InteresPrimCuota,CapitalFinalCredito,Observacion,Estado,CreadoPor,FechaCreacion,ModificadoPor,FechaModificacion,CreditoNro,EmpresaId,UsuarioId")] credito credito)
        {
            if (button.Equals("Cancelar"))
            {
                return(RedirectToAction("Index"));
            }

            if (ModelState.IsValid)
            {
                if (button.Equals("Calcular"))
                {
                    credito.CalcularCuotas();
                }

                if (button.Equals("Modificar Credito"))
                {
                    // credito.CalcularCuotas();
                    var currentCuotas = db.cuota.Where(c => c.CreditoId == credito.CreditoId);
                    foreach (cuota ss in currentCuotas)
                    {
                        db.cuota.Remove(ss);
                        //db.Entry(ss).State = EntityState.Deleted;
                    }

                    db.Entry(credito).State = EntityState.Modified;
                    credito.CalcularCuotas();

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.ClienteId         = new SelectList(db.cliente.Where(c => c.Estado == true && c.EmpresaId == credito.EmpresaId).OrderBy(e => e.Nit), "ClienteId", "Nit", credito.ClienteId);
            ViewBag.TipoCuotaId       = new SelectList(db.tipocuota.Where(c => c.Estado == true).OrderBy(e => e.Nombre), "TipoCuotaId", "Nombre", credito.TipoCuotaId);
            ViewBag.DivisionCreditoId = new SelectList(db.divisioncredito.Where(c => c.Estado == true).OrderBy(e => e.Nombre), "DivisionCreditoId", "Nombre", credito.DivisionCreditoId);
            ViewBag.UsuarioId         = new SelectList(db.usuario.Where(c => c.Estado == true && c.EmpresaId == credito.EmpresaId).OrderBy(e => e.UsuNombre), "UsuarioId", "UsuNombre", credito.UsuarioId);
            return(View(credito));
        }