public pre_rubro_Info GetInfo(int IdEmpresa, int IdRubro) { try { pre_rubro_Info info = new pre_rubro_Info(); using (Entities_presupuesto Context = new Entities_presupuesto()) { pre_Rubro Entity = Context.pre_Rubro.Where(q => q.IdRubro == IdRubro && q.IdEmpresa == IdEmpresa).FirstOrDefault(); if (Entity == null) { return(null); } info = new pre_rubro_Info { IdEmpresa = Entity.IdEmpresa, IdRubro = Entity.IdRubro, IdRubroTipo = Entity.IdRubroTipo, Descripcion = Entity.Descripcion, IdCtaCble = Entity.IdCtaCble, Estado = Entity.Estado }; } return(info); } catch (Exception) { throw; } }
public bool AnularBD(pre_rubro_Info info) { try { using (Entities_presupuesto db = new Entities_presupuesto()) { pre_Rubro entity = db.pre_Rubro.Where(q => q.IdRubro == info.IdRubro && q.IdEmpresa == info.IdEmpresa).FirstOrDefault(); if (entity == null) { return(false); } entity.Estado = false; entity.IdUsuarioAnulacion = info.IdUsuarioAnulacion; entity.FechaAnulacion = DateTime.Now; entity.MotivoAnulacion = info.MotivoAnulacion; db.SaveChanges(); } return(true); } catch (Exception) { throw; } }
public bool ModificarBD(pre_Presupuesto_Info info) { try { using (Entities_presupuesto db = new Entities_presupuesto()) { pre_Presupuesto entity = db.pre_Presupuesto.Where(q => q.IdPresupuesto == info.IdPresupuesto && q.IdEmpresa == info.IdEmpresa).FirstOrDefault(); if (entity == null) { return(false); } double monto_solicitado = info.ListaPresupuestoDet.Sum(v => v.Monto); entity.IdSucursal = info.IdSucursal; entity.IdPeriodo = info.IdPeriodo; entity.IdGrupo = info.IdGrupo; entity.Observacion = info.Observacion; entity.MontoSolicitado = monto_solicitado; entity.IdUsuarioModificacion = info.IdUsuarioModificacion; entity.FechaModificacion = DateTime.Now; entity.IdUsuarioAprobacion = null; var lst_PresupuestoDet = db.pre_PresupuestoDet.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdPresupuesto == info.IdPresupuesto).ToList(); db.pre_PresupuestoDet.RemoveRange(lst_PresupuestoDet); if (info.ListaPresupuestoDet != null) { int Secuencia = 1; foreach (var item in info.ListaPresupuestoDet) { pre_Rubro EntityRubro = db.pre_Rubro.Where(q => q.IdRubro == item.IdRubro && q.IdEmpresa == info.IdEmpresa).FirstOrDefault(); db.pre_PresupuestoDet.Add(new pre_PresupuestoDet { IdEmpresa = info.IdEmpresa, IdPresupuesto = info.IdPresupuesto, Secuencia = Secuencia++, IdRubro = item.IdRubro, IdCtaCble = EntityRubro.IdCtaCble, Monto = item.Monto }); } } db.SaveChanges(); } return(true); } catch (Exception) { throw; } }
public bool GuardarBD(pre_Presupuesto_Info info) { try { double monto_solicitado = info.ListaPresupuestoDet.Sum(v => v.Monto); using (Entities_presupuesto db = new Entities_presupuesto()) { db.pre_Presupuesto.Add(new pre_Presupuesto { IdEmpresa = info.IdEmpresa, IdPresupuesto = info.IdPresupuesto = get_id(info.IdEmpresa), IdSucursal = info.IdSucursal, IdGrupo = info.IdGrupo, IdPeriodo = info.IdPeriodo, Observacion = info.Observacion, MontoSolicitado = monto_solicitado, MontoAprobado = info.MontoAprobado, Estado = true, IdUsuarioCreacion = info.IdUsuarioCreacion, FechaCreacion = DateTime.Now }); if (info.ListaPresupuestoDet != null) { int Secuencia = 1; foreach (var item in info.ListaPresupuestoDet) { pre_Rubro EntityRubro = db.pre_Rubro.Where(q => q.IdRubro == item.IdRubro && q.IdEmpresa == info.IdEmpresa).FirstOrDefault(); db.pre_PresupuestoDet.Add(new pre_PresupuestoDet { IdEmpresa = info.IdEmpresa, IdPresupuesto = info.IdPresupuesto, Secuencia = Secuencia++, IdRubro = item.IdRubro, IdCtaCble = EntityRubro.IdCtaCble, Monto = item.Monto }); } } db.SaveChanges(); } return(true); } catch (Exception) { throw; } }
public bool ModificarBD(pre_rubro_Info info) { try { using (Entities_presupuesto db = new Entities_presupuesto()) { pre_Rubro entity = db.pre_Rubro.Where(q => q.IdRubro == info.IdRubro && q.IdEmpresa == info.IdEmpresa).FirstOrDefault(); if (entity == null) { return(false); } entity.Descripcion = info.Descripcion; entity.IdRubroTipo = info.IdRubroTipo; entity.IdCtaCble = info.IdCtaCble; entity.IdUsuarioModificacion = info.IdUsuarioModificacion; entity.FechaModificacion = DateTime.Now; db.SaveChanges(); var ListaPresupuestos = db.vwpre_PresupuestoDet.Where(q => q.IdEmpresa == info.IdEmpresa && q.IdRubro == info.IdRubro && q.EstadoCierre == false).ToList(); foreach (var item in ListaPresupuestos) { pre_PresupuestoDet EntityRubro = db.pre_PresupuestoDet.Where(q => q.IdRubro == item.IdRubro && q.IdEmpresa == info.IdEmpresa).FirstOrDefault(); EntityRubro.IdCtaCble = info.IdCtaCble; db.SaveChanges(); } } return(true); } catch (Exception) { throw; } }