Ejemplo n.º 1
0
 public ActionResult Agregar(OtrosGastos otrosGastos)
 {
     otrosGastos.DiaContableId = _periodoContableService.GetDiaContableActual().Id;
     if (ModelState.IsValid)
     {
         _db.Set <OtrosGastos>().Add(otrosGastos);
         var    cta         = _cuentasServices.FindCuentaByNombre(otrosGastos.PagadoPorCaja ? "Caja" : "Banco");
         var    cuentaGasto = _cuentasServices.FindCuentaByNombre("Gastos");
         var    concepto    = _db.Set <ConceptoDeGasto>().Find(otrosGastos.ConceptoDeGastoId);
         string detalle     = "Pago de: " + concepto.Nombre;
         bool   result      = true;
         if (otrosGastos.PagadoPorCaja)
         {
             if (cta.Disponibilidad.Saldo - otrosGastos.Importe < 0)
             {
                 TempData["error"] = "No existe saldo en caja para realizar la extracción";
                 result            = false;
             }
         }
         if (result)
         {
             _cuentasServices.AgregarOperacion(cta.Id, cuentaGasto.Id, otrosGastos.Importe, DateTime.Now,
                                               detalle, User.Identity.GetUserId());
             _db.SaveChanges();
             TempData["exito"] = "Gasto agregado correctamente";
         }
         return(RedirectToAction("Index"));
     }
     ViewBag.DiaContable       = _periodoContableService.GetDiaContableActual();
     ViewBag.ConceptoDeGastoId = new SelectList(_db.Set <ConceptoDeGasto>(), "Id", "Nombre", otrosGastos.ConceptoDeGastoId);
     return(View(otrosGastos));
 }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            OtrosGastos otrosgastos = db.OtrosGastos.Find(id);

            db.OtrosGastos.Remove(otrosgastos);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "Id,Fecha,Importe,UsuarioId,ConceptoGastoId")] OtrosGastos otrosgastos)
 {
     if (ModelState.IsValid)
     {
         otrosgastos.UsuarioId       = User.Identity.Name;
         db.Entry(otrosgastos).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ConceptoGastoId = new SelectList(db.ConceptoGasto, "Id", "Nombre", otrosgastos.ConceptoGastoId);
     return(View(otrosgastos));
 }
Ejemplo n.º 4
0
        // GET: /OtrosGastos/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OtrosGastos otrosgastos = db.OtrosGastos.Find(id);

            if (otrosgastos == null)
            {
                return(HttpNotFound());
            }
            return(View(otrosgastos));
        }
Ejemplo n.º 5
0
        // GET: /OtrosGastos/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OtrosGastos otrosgastos = db.OtrosGastos.Find(id);

            if (otrosgastos == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ConceptoGastoId = new SelectList(db.ConceptoGasto, "Id", "Nombre", otrosgastos.ConceptoGastoId);
            return(View(otrosgastos));
        }
Ejemplo n.º 6
0
        public ActionResult Editar(OtrosGastos otrosGastos)
        {
            if (ModelState.IsValid)
            {
                var entry = _db.Entry(otrosGastos);
                entry.State = EntityState.Modified;
                var  importeAnterior     = (decimal)entry.GetDatabaseValues()["Importe"];
                var  pagoPorCajaAnterior = (bool)entry.GetDatabaseValues()["PagadoPorCaja"];
                bool result = true;

                var cuentaCaja         = _cuentasServices.FindCuentaByNombre(otrosGastos.PagadoPorCaja? "Caja":"Banco");
                var cuentaCajaAnterior = _cuentasServices.FindCuentaByNombre(pagoPorCajaAnterior ? "Caja" : "Banco");
                var cuentaGasto        = _cuentasServices.FindCuentaByNombre("Gastos");
                var concepto           = _db.Set <ConceptoDeGasto>().Find(otrosGastos.ConceptoDeGastoId);

                string detalle = "Pago de: " + concepto.Nombre;
                _db.Set <Asiento>().Add(_cuentasServices.CrearAsientoContable(cuentaGasto.Id, cuentaCajaAnterior.Id, importeAnterior, DateTime.Now,
                                                                              "Ajuste por error en gasto con id " + otrosGastos.Id + " de " + concepto.Nombre, User.Identity.GetUserId()));
                if (otrosGastos.PagadoPorCaja)
                {
                    if (cuentaCaja.Disponibilidad.Saldo - otrosGastos.Importe < 0)
                    {
                        TempData["error"] = "No existe saldo en caja para realizar la extracción";
                        result            = false;
                    }
                }
                if (result)
                {
                    _db.Set <Asiento>().Add(_cuentasServices.CrearAsientoContable(cuentaCaja.Id, cuentaGasto.Id, otrosGastos.Importe, DateTime.Now,
                                                                                  detalle, User.Identity.GetUserId()));
                    _db.SaveChanges();
                    TempData["exito"] = "Gasto modificado correctamente";
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.ConceptoDeGastoId = new SelectList(_db.Set <ConceptoDeGasto>(), "Id", "Nombre", otrosGastos.ConceptoDeGastoId);
            return(View(otrosGastos));
        }