//modificar
        public JsonResult ModificarCostoFC(int Id, string Id_Acreedor, string nombre, string Id_Moneda, decimal Importe, DateTime Fecha_Inicio, DateTime Fecha_Fin, string Cuenta, string Id_Sociedad, int lineaNegocio)
        {
            object      respuesta   = null;
            CultureInfo cultureInfo = new CultureInfo("es-ES", false);
            CostoFR     costofr     = db.CostoFR.Where(x => x.Id == Id).SingleOrDefault();
            //Trafico trafico = db.Trafico.Where(x => x.Id_TraficoTR == Id_TraficoTR && x.Id_LineaNegocio == lineaNegocio && x.Activo == 1 && x.Sentido == "Costos").SingleOrDefault();
            Acreedor        acreedor        = db.Acreedor.Where(x => x.Acreedor1 == Id_Acreedor && x.Id_LineaNegocio == lineaNegocio && x.Activo == 1).SingleOrDefault();
            Operador        operador        = db.Operador.Where(x => x.Id_Operador == nombre && x.Id_LineaNegocio == lineaNegocio && x.Activo == 1).SingleOrDefault();
            Moneda          moneda          = db.Moneda.Where(x => x.Moneda1 == Id_Moneda && x.Id_LineaNegocio == lineaNegocio && x.Activo == 1).SingleOrDefault();
            CuentaResultado cuentaResultado = db.CuentaResultado.Where(x => x.Cuenta == Cuenta && x.Id_LineaNegocio == lineaNegocio && x.Activo == 1).SingleOrDefault();
            Sociedad        sociedad        = db.Sociedad.Where(x => x.Id_Sociedad == Id_Sociedad && x.Id_LineaNegocio == lineaNegocio && x.Activo == 1).SingleOrDefault();
            //Acreedor acreedor = db.Acreedor.Where(x => x.Acreedor1 == Id_Acreedor && x.Id_LineaNegocio == lineaNegocio && x.Activo == 1);
            //costofr.Id_Operador = operador.Id;


            bool valid   = true;
            var  mensaje = "";


            if (DateTime.Compare(Fecha_Inicio, Fecha_Fin) > 0)
            {
                valid   = false;
                mensaje = "Fecha Inicio debe ser menor que Fecha Fin";
            }


            if (valid)
            {
                try
                {
                    costofr.TipoOperador    = operador.Tipo_Operador;
                    costofr.Operador        = operador.Id_Operador;
                    costofr.AcreedorSap     = acreedor.Acreedor1;
                    costofr.NombreProveedor = acreedor.NombreAcreedor;
                    costofr.Moneda          = moneda.Moneda1;
                    costofr.Importe         = Importe;
                    costofr.Fecha_Inicio    = Fecha_Inicio.ToShortDateString();
                    costofr.Fecha_Fin       = Fecha_Fin.ToShortDateString();
                    costofr.CuentaR         = cuentaResultado.Cuenta;
                    costofr.SociedadGL      = int.Parse(sociedad.Id_Sociedad);
                    Log log = new Log();
                    log.insertaBitacoraModificacion(costofr, "Id", costofr.Id, "CostoFR.html", Request.UserHostAddress);
                    db.SaveChanges();
                    respuesta = new { success = true, results = "ok" };
                }
                catch (Exception ex)
                {
                    var error = ex.Message;
                    respuesta = new { success = false, results = "Hubo un error mientras se procesaba la petición" };
                }
            }
            else
            {
                respuesta = new { success = false, results = mensaje };
            }

            return(Json(respuesta, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public JsonResult borrar(string strID)
        {
            int Id = 0;

            strID = strID.TrimEnd(',');
            object respuesta;
            string strmsg   = "ok";
            string strSalto = "</br>";
            bool   blsucc   = true;

            try
            {
                string[] Ids = strID.Split(',');

                for (int i = 0; i < Ids.Length; i++)
                {
                    if (Ids[i].Length != 0)
                    {
                        Id = int.Parse(Ids[i]);

                        string strresp_val = funGralCtrl.ValidaRelacion("CuentaResultado", Id);

                        if (strresp_val.Length == 0)
                        {
                            CuentaResultado oCuentaResultado = db.CuentaResultado.Where(x => x.Id == Id).SingleOrDefault();
                            oCuentaResultado.Activo = 0;
                            Log log = new Log();
                            log.insertaNuevoOEliminado(oCuentaResultado, "Eliminado", "CuentaResultado.html", Request.UserHostAddress);
                            db.SaveChanges();
                        }
                        else
                        {
                            strmsg = "El(Los) " + Ids.Length.ToString() + " registro(s) que quieres borrar se está(n) usando en el(los) catálogo(s) " + strSalto;
                            strmsg = strmsg + strresp_val + strSalto;
                            blsucc = false;
                            break;
                        }
                    }
                }
                respuesta = new { success = blsucc, results = strmsg };
            }
            catch (Exception ex)
            {
                strmsg    = ex.Message;
                respuesta = new { success = false, result = strmsg };
            }
            return(Json(respuesta, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public JsonResult modificar(int Id, string Sentido, int Trafico, string TraficoDescripcion, string Cuenta, string Codigo_Material, string Material, int lineaNegocio)
        {
            object          respuesta = null;
            CuentaResultado cuenta    = db.CuentaResultado.Where(x => x.Trafico_Id == Trafico && x.Sentido == Sentido && x.Activo == 1 && x.Id_LineaNegocio == lineaNegocio).SingleOrDefault();

            if (cuenta == null || cuenta.Id == Id)
            {
                try
                {
                    CuentaResultado oCuentaResultado = db.CuentaResultado.Where(x => x.Id == Id && x.Activo == 1 && x.Id_LineaNegocio == lineaNegocio).SingleOrDefault();
                    oCuentaResultado.Sentido            = Sentido;
                    oCuentaResultado.Trafico_Id         = Trafico;
                    oCuentaResultado.TraficoDescripcion = TraficoDescripcion;
                    oCuentaResultado.Cuenta             = Cuenta;
                    oCuentaResultado.Codigo_Material    = Codigo_Material;
                    oCuentaResultado.Material           = Material;
                    Log log = new Log();
                    log.insertaBitacoraModificacion(oCuentaResultado, "Id", oCuentaResultado.Id, "CuentaResultado.html", Request.UserHostAddress);

                    db.SaveChanges();
                    respuesta = new { success = true, results = "ok" };
                }
                catch (Exception ex)
                {
                    respuesta = new
                    {
                        success = false,
                        results = "Un error ocurrió mientras se realizaba la petición.\n Error: " + ex.Message.ToString()
                    };
                }
            }
            else
            {
                respuesta = new
                {
                    success = false,
                    results = "El Tráfico y Sentido actuales ya están dados de alta"
                };
            }

            return(Json(respuesta, JsonRequestBehavior.AllowGet));
        }
示例#4
0
        public JsonResult agregar(string Sentido, int Trafico, string TraficoDescripcion, string Cuenta, string Codigo_Material, string Material, int lineaNegocio)
        {
            CuentaResultado cuenta    = db.CuentaResultado.Where(x => x.Trafico_Id == Trafico && x.Sentido == Sentido && x.Activo == 1 && x.Id_LineaNegocio == lineaNegocio).SingleOrDefault();
            object          respuesta = null;

            if (cuenta == null)
            {
                try
                {
                    var nuevo = new CuentaResultado();
                    nuevo.Sentido            = Sentido;
                    nuevo.Trafico_Id         = Trafico;
                    nuevo.TraficoDescripcion = TraficoDescripcion;
                    nuevo.Cuenta             = Cuenta;
                    nuevo.Codigo_Material    = Codigo_Material;
                    nuevo.Material           = Material;
                    nuevo.Activo             = 1;
                    nuevo.Id_LineaNegocio    = lineaNegocio;
                    db.CuentaResultado.Add(nuevo);
                    Log log = new Log();
                    log.insertaNuevoOEliminado(nuevo, "Nuevo", "CuentaResultado.html", Request.UserHostAddress);

                    db.SaveChanges();
                    respuesta = new { success = true, results = "ok" };
                }
                catch (Exception ex)
                {
                    respuesta = new { success = false, results = ex.Message };
                }
            }
            else
            {
                respuesta = new
                {
                    success = false,
                    results = "El Tráfico y Sentido actuales ya están dados de alta"
                };
            }

            return(Json(respuesta, JsonRequestBehavior.AllowGet));
        }
        //agregar
        public JsonResult agregarCostoFC(int Id_Acreedor, int Id_Operador, int Id_Moneda, decimal Importe, DateTime Fecha_Inicio, DateTime Fecha_fin, int Id_Cuenta, int Id_Sociedad, int Linea_Negocio)
        {
            object          respuesta = null;
            bool            valid     = true;
            var             mensaje   = "";
            TC_Cierre       tC_Cierre = db.TC_Cierre.Where(x => x.Id_Moneda == Id_Moneda && x.Mes_Consumo.Year == Fecha_Inicio.Year && x.Mes_Consumo.Month == Fecha_Inicio.Month && x.Sentido == "COSTO" && x.Id_LineaNegocio == Linea_Negocio && x.Activo == 1).SingleOrDefault();
            Operador        operador  = db.Operador.Where(x => x.Id == Id_Operador && x.Id_LineaNegocio == Linea_Negocio && x.Activo == 1).SingleOrDefault();
            Acreedor        acreedor  = db.Acreedor.Where(x => x.Id == Id_Acreedor && x.Id_LineaNegocio == Linea_Negocio && x.Activo == 1).SingleOrDefault();
            Moneda          moneda    = db.Moneda.Where(x => x.Id == Id_Moneda && x.Id_LineaNegocio == Linea_Negocio && x.Activo == 1).SingleOrDefault();
            CuentaResultado cuentaR   = db.CuentaResultado.Where(x => x.Id == Id_Cuenta && x.Id_LineaNegocio == Linea_Negocio && x.Activo == 1).SingleOrDefault();
            Sociedad        sociedad  = db.Sociedad.Where(x => x.Id == Id_Sociedad && x.Id_LineaNegocio == Linea_Negocio && x.Activo == 1).SingleOrDefault();

            if (DateTime.Compare(Fecha_Inicio, Fecha_fin) >= 0)
            {
                valid   = false;
                mensaje = "Fecha Inicio Debe Ser MENOR que  Fin";
            }

            if (Convert.ToInt64(cuentaR.Cuenta) <= 0) //numeros negativos
            {
                valid = false;
                if (mensaje != "")
                {
                    mensaje = mensaje + " y " + "Importe No Pueder Ser Menor a Cero";
                }
                else
                {
                    mensaje = "Cuenta debe ser mayor a cero";
                }
            }

            if (valid)
            {
                try
                {
                    var nuevo = new CostoFR();
                    nuevo.TipoOperador    = operador.Tipo_Operador;
                    nuevo.Operador        = operador.Id_Operador;
                    nuevo.AcreedorSap     = acreedor.Acreedor1;
                    nuevo.NombreProveedor = acreedor.NombreAcreedor;
                    nuevo.Moneda          = moneda.Moneda1;
                    nuevo.Importe         = Importe;
                    nuevo.Fecha_Inicio    = Fecha_Inicio.ToShortDateString();
                    nuevo.Fecha_Fin       = Fecha_fin.ToShortDateString();
                    nuevo.CuentaR         = cuentaR.Cuenta;
                    nuevo.SociedadGL      = int.Parse(sociedad.Id_Sociedad);
                    if (tC_Cierre == null)
                    {
                        nuevo.TC = 0;
                    }
                    else
                    {
                        nuevo.TC = tC_Cierre.TC_MXN;
                    }
                    nuevo.Activo          = 1;
                    nuevo.Id_LineaNegocio = Linea_Negocio;

                    db.CostoFR.Add(nuevo);
                    Log log = new Log();
                    log.insertaNuevoOEliminado(nuevo, "Nuevo", "CostoFR.html", Request.UserHostAddress);

                    db.SaveChanges();
                    respuesta = new { success = true, result = "ok" };
                }
                catch (Exception ex)
                {
                    var error = ex.Message;
                    respuesta = new { success = false, result = "Hubo un error mientras se procesaba la petición" };
                }
            }
            else
            {
                respuesta = new { success = false, result = mensaje };
            }

            return(Json(respuesta, JsonRequestBehavior.AllowGet));
        }