public JsonResult EliminarPago(int IdPago) { try { //Saul González 11/03/2021: Validaciones de campos nulos if (String.IsNullOrEmpty(IdPago.ToString())) { return(Json(new { status = false, mensaje = "Ocurrió un error al obtener el Id del pago." })); } //Saul Gonzalez 22/03/2021: Cargamos los datos del pago Tb_Pagos Pago = db.Tb_Pagos.Where(y => y.Id == IdPago).FirstOrDefault(); if (Pago == null) { return(Json(new { status = false, mensaje = "ERROR L-196: Ocurrió un error al encontrar los datos del pago " + IdPago.ToString() })); } db.Tb_Pagos.Remove(Pago); db.SaveChanges(); } catch (Exception error) { return(Json(new { status = false, mensaje = error.Message })); } return(Json(new { status = true, mensaje = "Pago eliminado correctamente" })); }
public JsonResult CargarPago(int IdPago) { cPagos Pago = new cPagos(); CultureInfo Culture = new CultureInfo("en-US"); //Definimos la cultura para que el separador de decimal sea por un Punto (.) try { //Saul González 11/03/2021: Validaciones de campos nulos if (String.IsNullOrEmpty(IdPago.ToString())) { return(Json(new { status = false, mensaje = "Ocurrió un error al obtener el Id del pago." })); } //Saul Gonzalez 22/03/2021: Cargamos los datos del pago Tb_Pagos o = db.Tb_Pagos.Where(y => y.Id == IdPago).FirstOrDefault(); if (o == null) { return(Json(new { status = false, mensaje = "ERROR L-196: Ocurrió un error al encontrar los datos del pago " + IdPago.ToString() })); } Pago.Id = o.Id; Pago.Monto = o.Monto; Pago.TipoPago = o.TipoPago; Pago.Referencia = o.Referencia; Pago.Retorno = o.Retorno; Pago.REF_Retorno = o.REF_Retorno; Pago.Notas = o.Notas; Pago.FechaPago = o.FechaPago.ToString("yyyy-MM-dd"); //Datos de pagos combinados Pago.Monto2 = o.Monto2; Pago.TipoPago2 = o.TipoPago2; } catch (Exception error) { return(Json(new { status = false, mensaje = error.Message })); } return(Json(new { status = true, mensaje = "Pago registrado correctamente.", Datos = Pago })); }
public JsonResult ActualizarPago(string IdPago, string Monto, string REF, string TipoPago, string FechaPago, string Retorno = "", string REFRetorno = "", string NotasPago = "", string Monto2 = "", string tipoPago2 = "") { CultureInfo Culture = new CultureInfo("en-US"); //Definimos la cultura para que el separador de decimal sea por un Punto (.) try { int ID_PAGO = Convert.ToInt32(IdPago); if (Retorno == string.Empty) { Retorno = "0"; } //Saul González 23/03/2021: Validaciones de campos nulos if (String.IsNullOrEmpty(Monto.ToString())) { return(Json(new { status = false, mensaje = "Debe ingresar el monto pagado." })); } if (Convert.ToDecimal(Monto, Culture) < 1) { return(Json(new { status = false, mensaje = "El monto debe ser mayor a 0." })); } if (String.IsNullOrEmpty(REF)) { return(Json(new { status = false, mensaje = "Debe ingresar una referencia." })); } if (String.IsNullOrEmpty(TipoPago)) { return(Json(new { status = false, mensaje = "Debe seleccionar un tipo de pago." })); } if (String.IsNullOrEmpty(FechaPago)) { return(Json(new { status = false, mensaje = "La fecha de pago no puede estar vacia." })); } if (!String.IsNullOrEmpty(Retorno)) { if (!String.IsNullOrEmpty(Monto2)) { var SumaMontos = Convert.ToDecimal(Monto, Culture) + Convert.ToDecimal(Monto2, Culture); if (Convert.ToDecimal(Retorno, Culture) > Convert.ToDecimal(SumaMontos, Culture)) { return(Json(new { status = false, mensaje = "La cantidad de retorno no puede ser mayor a la suma total de los montos combinados." })); } } else { if (Convert.ToDecimal(Retorno, Culture) > Convert.ToDecimal(Monto, Culture)) { return(Json(new { status = false, mensaje = "La cantidad de retorno no puede ser mayor al monto." })); } } } if (Convert.ToDecimal(Retorno, Culture) > 0 && String.IsNullOrEmpty(REFRetorno)) { return(Json(new { status = false, mensaje = "Al ingresar una cantidad de retorno, debe también indicar la referencia." })); } if (!String.IsNullOrEmpty(REFRetorno) && Convert.ToDecimal(Retorno, Culture) < 1) { return(Json(new { status = false, mensaje = "Al ingresar una referencia de retorno, el monto de retorno debe ser mayor a 0." })); } if (Monto2 != string.Empty && TipoPago == tipoPago2) { return(Json(new { status = false, mensaje = "No es posible tener una combinación con el mismo tipo de pago." })); } //Nos traemos los datos del pago Tb_Pagos Pago = db.Tb_Pagos.Where(y => y.Id == ID_PAGO).FirstOrDefault(); if (Pago == null) { return(Json(new { status = false, mensaje = "ERROR L-241: Ocurrio un error al obtener los datos del pago con el ID: " + IdPago })); } Pago.Monto = Convert.ToDecimal(Monto, Culture); Pago.Referencia = REF; var HoraPago = DateTime.Now.TimeOfDay; Pago.FechaPago = Convert.ToDateTime(FechaPago).Add(HoraPago); Pago.TipoPago = TipoPago; Pago.Notas = NotasPago; //Saul Gonzalez 24/03/2021: Validamos si se agrego una segunda combinacion de pago if (!String.IsNullOrEmpty(Monto2)) { Pago.Monto2 = Convert.ToDecimal(Monto2, Culture); Pago.TipoPago2 = tipoPago2; } //Validamos si se ingreso una cantidad en el campo de retorno, si esta vacia asignamos un 0 if (String.IsNullOrEmpty(Retorno)) { Pago.Retorno = 0; Pago.REF_Retorno = string.Empty; } else { Pago.Retorno = Convert.ToDecimal(Retorno, Culture); Pago.REF_Retorno = REFRetorno; } //Saul gonzalez 23/03/2021: Guardamos los datos db.Tb_Pagos.Attach(Pago); db.Entry(Pago).State = EntityState.Modified; db.SaveChanges(); } catch (Exception error) { return(Json(new { status = false, mensaje = error.Message })); } return(Json(new { status = true, mensaje = "Datos actualizados" })); }
public JsonResult RegistrarPago(string IdProyecto, string Monto, string REF, string TipoPago, string Retorno = "", string NotasPago = "", string Monto2 = "", string tipoPago2 = "", DateTime?FechaESP = null) { Tb_Pagos Pago = new Tb_Pagos(); CultureInfo Culture = new CultureInfo("en-US"); //Definimos la cultura para que el separador de decimal sea por un Punto (.) try { int ID_PROYECTO = Convert.ToInt32(IdProyecto); //Saul González 11/03/2021: Validaciones de campos nulos if (String.IsNullOrEmpty(Monto.ToString())) { return(Json(new { status = false, mensaje = "Debe ingresar el monto pagado." })); } if (Convert.ToDecimal(Monto, Culture) < 1) { return(Json(new { status = false, mensaje = "El monto debe ser mayor a 0." })); } if (String.IsNullOrEmpty(REF)) { return(Json(new { status = false, mensaje = "Debe ingresar una referencia." })); } if (String.IsNullOrEmpty(TipoPago)) { return(Json(new { status = false, mensaje = "Debe seleccionar un tipo de pago." })); } if (Monto2 != string.Empty && TipoPago == tipoPago2) { return(Json(new { status = false, mensaje = "No es posible tener una combinación con el mismo tipo de pago." })); } //Saul Gonzalez 17/02/2021: Guardamos los datos del pago Pago.FechaPago = DateTime.Now; if (FechaESP != null) { Pago.FechaPago = Convert.ToDateTime(FechaESP); } Pago.Monto = Convert.ToDecimal(Monto, Culture); //Saul Gonzalez 24/03/2021: Validamos si se agrego una segunda combinacion de pago if (!String.IsNullOrEmpty(Monto2)) { Pago.Monto2 = Convert.ToDecimal(Monto2, Culture); Pago.TipoPago2 = tipoPago2; } Pago.Referencia = REF; Pago.TipoPago = TipoPago; Pago.RegistradoPor = Session["Usuario"].ToString(); Pago.Notas = NotasPago; //Validamos si se ingreso una cantidad en el campo de retorno, si esta vacia asignamos un 0 if (String.IsNullOrEmpty(Retorno)) { Pago.Retorno = 0; Pago.REF_Retorno = string.Empty; } else { Pago.Retorno = Convert.ToDecimal(Retorno, Culture); } //Nos traemos los datos del proyecto Tb_Proyectos Proyecto = db.Tb_Proyectos.Where(y => y.Id == ID_PROYECTO).FirstOrDefault(); if (Proyecto == null) { return(Json(new { status = false, mensaje = "ERROR L-148: Ocurrió un error al encontrar el Id del proyecto." })); } Pago.Tb_Proyectos = Proyecto; //Saul gonzalez 11/03/2021: Guardamos los datos db.Tb_Pagos.Add(Pago); db.SaveChanges(); } catch (Exception error) { return(Json(new { status = false, mensaje = error.Message })); } return(Json(new { status = true, mensaje = "Pago registrado correctamente." })); }