Commit inicial Ventas Productivo
This commit is contained in:
310
Nomina/ConceptoNomina.aspx.cs
Normal file
310
Nomina/ConceptoNomina.aspx.cs
Normal file
@@ -0,0 +1,310 @@
|
||||
using Extensiones;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
public partial class Nomina_CatConcepto : ClsPaginas
|
||||
{
|
||||
#region "Propiedades"
|
||||
private DataTable DTCuentas
|
||||
{
|
||||
get
|
||||
{
|
||||
return (DataTable)ViewState["DTCuentas"];
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["DTCuentas"] = value;
|
||||
}
|
||||
}
|
||||
private Boolean EsEditar
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Boolean)ViewState["EsEditar"];
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["EsEditar"] = value;
|
||||
}
|
||||
}
|
||||
private int CveConcepto
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViewState["CveConcepto"].ToEntero();
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
ViewState["CveConcepto"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
InicializaDatos();
|
||||
}
|
||||
}
|
||||
|
||||
protected void InicializaDatos()
|
||||
{
|
||||
if (Request["CveConcepto"] != null && !Request["CveConcepto"].ToString().Equals("") && Request["CveConcepto"].ToEntero() > 0)
|
||||
{
|
||||
ViewState["CveConcepto"] = Request["CveConcepto"];
|
||||
EsEditar = true;
|
||||
BtnGuardar.Text = "Guardar cambios";
|
||||
BtnEliminar.Visible = true;
|
||||
ChkTipoCalculo.Checked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewState["CveConcepto"] = -1;
|
||||
EsEditar = false;
|
||||
}
|
||||
CargaTipo();
|
||||
CargaConceptoPadre();
|
||||
CargaConceptoContable();
|
||||
|
||||
CargaClasificacion();
|
||||
CargaTipoGasto();
|
||||
CargaCtaContable();
|
||||
|
||||
CargaDatos();
|
||||
}
|
||||
|
||||
protected void CargaTipo()
|
||||
{
|
||||
DdlTipo.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
DdlTipo.Items.Insert(1, new ListItem("Percepciones", "P"));
|
||||
DdlTipo.Items.Insert(2, new ListItem("Deducciones", "D"));
|
||||
DdlTipo.Items.Insert(3, new ListItem("Obligaciones", "O"));
|
||||
DdlTipo.SelectedValueExist("-1");
|
||||
}
|
||||
|
||||
protected void CargaConceptoPadre()
|
||||
{
|
||||
DdlConceptoPadre.DataSource = get_GlobalDTNomConceptos(UsuarioActual.CveEmpresa);
|
||||
DdlConceptoPadre.DataBind();
|
||||
DdlConceptoPadre.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
DdlConceptoPadre.SelectedValueExist("-1");
|
||||
}
|
||||
protected void CargaConceptoContable()
|
||||
{
|
||||
DdlConceptoContable.DataSource = get_GlobalDTContaConceptosContables(-1);
|
||||
DdlConceptoContable.DataBind();
|
||||
DdlConceptoContable.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
DdlConceptoContable.SelectedValueExist("-1");
|
||||
}
|
||||
protected void CargaClasificacion()
|
||||
{
|
||||
DdlClasificacion.DataSource = get_GlobalDTClasificaciones(UsuarioActual.CveEmpresa);
|
||||
DdlClasificacion.DataBind();
|
||||
DdlClasificacion.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
DdlClasificacion.SelectedValueExist("-1");
|
||||
}
|
||||
|
||||
protected void CargaTipoGasto()
|
||||
{
|
||||
DdlTipoGasto.DataSource = get_GlobalDTTiposGastos(UsuarioActual.CveEmpresa);
|
||||
DdlTipoGasto.DataBind();
|
||||
DdlTipoGasto.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
DdlTipoGasto.SelectedValueExist("-1");
|
||||
}
|
||||
|
||||
protected void CargaCtaContable()
|
||||
{
|
||||
if(UsuarioActual.Empresa.UsaContabilidad)
|
||||
{
|
||||
ClsContPAQi ObjConta = new ClsContPAQi(UsuarioActual.Empresa);
|
||||
if (ObjConta.GetCuentas(-1, "-1", 1))
|
||||
{
|
||||
DdlCtaContable.DataSource = ObjConta.DtResultados;
|
||||
DdlCtaContable.DataBind();
|
||||
}
|
||||
|
||||
DdlCtaContable.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
||||
DdlCtaContable.SelectedValueExist("-1");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void BtnGuardar_Click(object sender, EventArgs e)
|
||||
{
|
||||
String codigo = TxtCodigo.Text;
|
||||
String concepto = TxtConcepto.Text;
|
||||
String tipo = DdlTipo.SelectedValue;
|
||||
String formula = TxtFormula.Text;
|
||||
|
||||
if (!ValidaFormula(formula).Equals(""))
|
||||
{
|
||||
Alert("Fórmula no válida. Favor de ingresar una correcta.", ModExtensiones.TipoMensaje.MsgError);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool retencion;
|
||||
if (ChkRetencion.Checked) retencion = true;
|
||||
else retencion = false;
|
||||
|
||||
bool tipoCalculo;
|
||||
if (ChkTipoCalculo.Checked) tipoCalculo = true;
|
||||
else tipoCalculo = false;
|
||||
|
||||
int CveConceptoPadre = DdlConceptoPadre.SelectedValue.ToEntero();
|
||||
int CveConceptoContable = DdlConceptoContable.SelectedValue.ToEntero();
|
||||
|
||||
bool estado;
|
||||
if (ChkEstado.Checked) estado = true;
|
||||
else estado = false;
|
||||
|
||||
bool sistema;
|
||||
if (ChkSistema.Checked) sistema = true;
|
||||
else sistema = false;
|
||||
|
||||
int CveClasificacion = DdlClasificacion.SelectedValue.ToEntero();
|
||||
int CveTipoGasto = DdlTipoGasto.SelectedValue.ToEntero();
|
||||
int IdCtaContable = DdlCtaContable.SelectedValue.ToEntero();
|
||||
|
||||
ClsNominas ObjNomina = new ClsNominas();
|
||||
ObjNomina.IniciaTransacSQL();
|
||||
|
||||
bool TieneError = false;
|
||||
|
||||
if (EsEditar)
|
||||
{
|
||||
TieneError = !ObjNomina.UpdateConcepto(codigo, concepto, tipo, formula, sistema, estado, CveConceptoPadre, CveConcepto, retencion, CveClasificacion, IdCtaContable, CveTipoGasto, tipoCalculo, CveConceptoContable);
|
||||
|
||||
if (TieneError)
|
||||
{
|
||||
ObjNomina.RollBack();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjNomina.Commit();
|
||||
Alert("El concepto de nómina fue actualizado correctamente.", ModExtensiones.TipoMensaje.MsgInformacion, $"document.location.href=\"/Nomina/ConceptoNomina.aspx?CveConcepto={CveConcepto}\"");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CveConcepto = ObjNomina.AddConcepto(codigo, concepto, tipo, formula, sistema, estado, CveConceptoPadre, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, retencion, CveClasificacion, IdCtaContable, CveTipoGasto, tipoCalculo, CveConceptoContable);
|
||||
|
||||
if (CveConcepto == -1)
|
||||
{
|
||||
ObjNomina.RollBack();
|
||||
}
|
||||
else
|
||||
{
|
||||
ObjNomina.Commit();
|
||||
Alert("El concepto de nómina fue creado correctamente.", ModExtensiones.TipoMensaje.MsgInformacion, $"document.location.href=\"/Nomina/ConceptoNomina.aspx?CveConcepto={CveConcepto}\"");
|
||||
}
|
||||
}
|
||||
|
||||
ObjNomina.Dispose();
|
||||
CargaDatos();
|
||||
}
|
||||
}
|
||||
|
||||
private string ValidaFormula(string Formula)
|
||||
{
|
||||
string retorno = "Error en Fórmula";
|
||||
|
||||
try
|
||||
{
|
||||
FormulaEvaluator.Expression exp;
|
||||
foreach (DataRow dr in GlobalDTNomConceptosFunciones.Rows)
|
||||
{
|
||||
exp = new FormulaEvaluator.Expression(String.Format("{0}:=1", dr["Funcion"]));
|
||||
exp.Eval();
|
||||
}
|
||||
|
||||
exp = new FormulaEvaluator.Expression(Formula);
|
||||
if (exp.Errors.Count > 0)
|
||||
{
|
||||
retorno = exp.Errors[0].Message;
|
||||
}
|
||||
Object val = exp.Eval();
|
||||
if (exp.Errors.Count == 0)
|
||||
{
|
||||
retorno = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
retorno = exp.Errors[0].Message;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Alert(e.Message,ModExtensiones.TipoMensaje.MsgError);
|
||||
}
|
||||
|
||||
return retorno;
|
||||
}
|
||||
|
||||
protected void CargaDatos()
|
||||
{
|
||||
if(CveConcepto > 0)
|
||||
{
|
||||
ClsNominas ObjNomina = new ClsNominas();
|
||||
|
||||
if (ObjNomina.GetConceptos(UsuarioActual.CveEmpresa, CveConcepto: CveConcepto) && ObjNomina.DtResultados.Rows.Count > 0)
|
||||
{
|
||||
TxtCodigo.Text = ObjNomina.DtResultados.FiltroPrimeroValor("Codigo");
|
||||
TxtConcepto.Text = ObjNomina.DtResultados.FiltroPrimeroValor("Concepto");
|
||||
DdlTipo.SelectedValueExist(ObjNomina.DtResultados.FiltroPrimeroValor("Tipo"));
|
||||
TxtFormula.Text = ObjNomina.DtResultados.FiltroPrimeroValor("Formula");
|
||||
if (ObjNomina.DtResultados.FiltroPrimeroValor("EsRetencion").Equals("1")) ChkRetencion.Checked = true;
|
||||
if (ObjNomina.DtResultados.FiltroPrimeroValor("TipoCalculo").Equals("True")) ChkTipoCalculo.Checked = true;
|
||||
DdlConceptoPadre.SelectedValueExist(ObjNomina.DtResultados.FiltroPrimeroValor("CveConceptoPadre"));
|
||||
DdlConceptoContable.SelectedValueExist(ObjNomina.DtResultados.FiltroPrimeroValor("CveConceptoContable"));
|
||||
|
||||
if (ObjNomina.DtResultados.FiltroPrimeroValor("Estado").Equals("Activo")) ChkEstado.Checked = true;
|
||||
if (ObjNomina.DtResultados.FiltroPrimeroValor("Sistema").Equals("Sí")) ChkSistema.Checked = true;
|
||||
|
||||
DdlClasificacion.SelectedValueExist(ObjNomina.DtResultados.FiltroPrimeroValor("CveClasificacion"));
|
||||
DdlTipoGasto.SelectedValueExist(ObjNomina.DtResultados.FiltroPrimeroValor("CveTipoGasto"));
|
||||
DdlCtaContable.SelectedValueExist(ObjNomina.DtResultados.FiltroPrimeroValor("IdCtaContable"));
|
||||
}
|
||||
ObjNomina.Dispose();
|
||||
|
||||
} else
|
||||
{
|
||||
TxtCodigo.Text = "";
|
||||
TxtConcepto.Text = "";
|
||||
DdlTipo.SelectedValueExist("-1");
|
||||
TxtFormula.Text = "";
|
||||
ChkRetencion.Checked = false;
|
||||
DdlConceptoPadre.SelectedValueExist("-1");
|
||||
DdlConceptoContable.SelectedValueExist("-1");
|
||||
|
||||
ChkEstado.Checked = false;
|
||||
ChkSistema.Checked = false;
|
||||
|
||||
DdlClasificacion.SelectedValueExist("-1");
|
||||
DdlTipoGasto.SelectedValueExist("-1");
|
||||
DdlCtaContable.SelectedValueExist("-1");
|
||||
}
|
||||
}
|
||||
|
||||
protected void BtnEliminar_Click(object sender, EventArgs e)
|
||||
{
|
||||
ClsNominas ObjNomina = new ClsNominas();
|
||||
|
||||
if (ObjNomina.RemoveConcepto(CveConcepto, UsuarioActual.CveEmpresa))
|
||||
{
|
||||
Response.Redirect("./CatConceptos.aspx");
|
||||
}
|
||||
else
|
||||
{
|
||||
Alert("Ocurrio un error al eliminar el concepto de nómina", ModExtensiones.TipoMensaje.MsgError);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user