コード例 #1
0
        public bool AprobarBD(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);
                    }

                    entity.IdUsuarioAprobacion = info.IdUsuarioAprobacion;
                    entity.FechaAprobacion     = DateTime.Now;
                    entity.MontoAprobado       = info.MontoAprobado;
                    entity.MotivoAprobacion    = info.MotivoAprobacion;

                    db.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
        public pre_Presupuesto_Info get_info(int IdEmpresa, int IdPresupuesto)
        {
            try
            {
                pre_Presupuesto_Info info = new pre_Presupuesto_Info();
                using (Entities_presupuesto Context = new Entities_presupuesto())
                {
                    pre_Presupuesto Entity = Context.pre_Presupuesto.Where(q => q.IdPresupuesto == IdPresupuesto && q.IdEmpresa == IdEmpresa).FirstOrDefault();

                    if (Entity == null)
                    {
                        return(null);
                    }
                    info = new pre_Presupuesto_Info
                    {
                        IdEmpresa        = Entity.IdEmpresa,
                        IdPresupuesto    = Entity.IdPresupuesto,
                        IdSucursal       = Entity.IdSucursal,
                        IdPeriodo        = Entity.IdPeriodo,
                        Observacion      = Entity.Observacion,
                        MontoAprobado    = Entity.MontoAprobado,
                        MontoSolicitado  = Entity.MontoSolicitado,
                        Estado           = Entity.Estado,
                        MotivoAnulacion  = Entity.MotivoAnulacion,
                        MotivoAprobacion = Entity.MotivoAprobacion
                    };
                }

                return(info);
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
        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;
            }
        }