998 lines
41 KiB
C#
998 lines
41 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using Extensiones;
|
|
|
|
public partial class Nomina_Aguinaldo : ClsPaginas
|
|
{
|
|
#region Propiedades
|
|
private DataTable DTAguinaldos
|
|
{
|
|
get
|
|
{
|
|
return (DataTable)ViewState["DTAguinaldos"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["DTAguinaldos"] = value;
|
|
}
|
|
}
|
|
#endregion
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
using (ClsNominas objnom = new ClsNominas())
|
|
{
|
|
|
|
objnom.GetEjercicios(UsuarioActual.CveEmpresa);
|
|
DdlEjercicios.DataSource = objnom.DtResultados;
|
|
}
|
|
DdlEjercicios.DataBind();
|
|
try
|
|
{
|
|
DdlEjercicios.SelectedValueExistInsert(DateTime.Now.Year, DateTime.Now.Year.ToString());
|
|
}
|
|
catch (Exception) { }
|
|
|
|
DdlTipoPeriodo.DataSource = GlobalDTTipoPeriodo.FiltraParametros("Estatus = 'Activo' AND CveTipoPeriodo <>-1");
|
|
DdlTipoPeriodo.DataBind();
|
|
DdlTipoPeriodo.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
if (DdlTipoPeriodo.Items.Count > 0)
|
|
{
|
|
DdlTipoPeriodo.SelectedIndex = 0;
|
|
}
|
|
|
|
LtlUma.Text = "";
|
|
int cveempresa = 1;
|
|
if (UsuarioActual != null) { cveempresa = UsuarioActual.CveEmpresa; }
|
|
using (ClsClaseBaseD objbase = new ClsClaseBaseD())
|
|
{
|
|
if (objbase.runQuerystr($"SELECT Valor UMA FROM [dbo].[RH_TablasValores] WHERE Tipo =1 AND CveEmpresa ={cveempresa} AND Fecha<'{DateTime.Now:yyyy/MM/dd}' ORDER BY Fecha DESC"))
|
|
{
|
|
if (objbase.DtResultados.Rows.Count > 0)
|
|
{
|
|
LtlUma.Text = objbase.DtResultados.Rows[0]["UMA"].ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
protected void BtnCalcular_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
int ejercicio = DdlEjercicios.SelectedValue.ToEntero();
|
|
int CveTipoPeriodo = DdlTipoPeriodo.SelectedValue.ToEntero();
|
|
int CvePeriodo = -1;
|
|
|
|
using (ClsNominas objnom = new ClsNominas())
|
|
{
|
|
objnom.GetCalculoAguinaldo(ejercicio, UsuarioActual.CveEmpresa, 0, CveTipoPeriodo, CvePeriodo);
|
|
DTAguinaldos = objnom.DtResultados;
|
|
GVCalcularAguinaldo.DataSource = DTAguinaldos;
|
|
LtlTotal.Text = string.Format("{0:N2}", DTAguinaldos.SUM("Aguinaldo"));
|
|
LtlAutorizado.Text = string.Format("{0:N2}", DTAguinaldos.SUM("Aguinaldo", "CveNomina>0"));
|
|
|
|
LtldiasEjercicio.Text = string.Format("{0}/12/31", ejercicio).ToDate().DayOfYear.ToString();
|
|
}
|
|
|
|
GVCalcularAguinaldo.DataBind();
|
|
LnkAutorizarModal.Visible = true;
|
|
BtnRecalcular_Click(sender, null);
|
|
upDatosPA_N.Update();
|
|
}
|
|
private void CargaPeriodos()
|
|
{
|
|
DataTable dtPeriodos = null;
|
|
using (ClsNominas ObjPeriodos = new ClsNominas())
|
|
{
|
|
if (ObjPeriodos.GetPeriodos(-1, UsuarioActual.CveEmpresa, DdlEjercicios.SelectedValue.ToEntero(), -1, -1))
|
|
{
|
|
dtPeriodos = ObjPeriodos.DtResultados.FiltraParametros("Estatus IN (0,1)");
|
|
}
|
|
ObjPeriodos.Dispose();
|
|
}
|
|
|
|
if (dtPeriodos != null && dtPeriodos.Rows.Count > 0)
|
|
{
|
|
DdlPeriodo.DataSource = dtPeriodos.FiltraParametros(string.Format(" CveTipoPeriodo={0}", DdlTipoPeriodoB.SelectedValue));
|
|
}
|
|
DdlPeriodo.DataBind();
|
|
DdlPeriodo.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
UpModalAutorizar.Update();
|
|
}
|
|
protected void LnkAutorizarModal_Click(object sender, EventArgs e)
|
|
{
|
|
DdlTipoPeriodoB.ClearSelection();
|
|
DdlTipoPeriodoB.Items.Clear();
|
|
DdlTipoPeriodoB.DataSource = GlobalDTTipoPeriodo.FiltraParametros(string.Format("CveTipoPeriodo=6 OR CveTipoPeriodo={0}", DdlTipoPeriodo.SelectedValue));
|
|
DdlTipoPeriodoB.DataBind();
|
|
|
|
CargaPeriodos();
|
|
RegistraScript("$('#ModalAutorizar').modal();");
|
|
}
|
|
|
|
protected void LnkAutorizar_Click(object sender, EventArgs e)
|
|
{
|
|
bool continuar = true;
|
|
string mensaje = "";
|
|
//int DiasLaborados;
|
|
decimal Importe;
|
|
int CveMoneda = 1;
|
|
var CvePeriodoSeleccionado = DdlPeriodo.SelectedValue.ToEntero();
|
|
int ejercicio = DdlEjercicios.SelectedValue.ToEntero();
|
|
int CvePersonal;
|
|
int CvePeriodo;
|
|
decimal importeAjuste = 0;
|
|
decimal ImporteDescuento = 0;
|
|
decimal ImporteISR = 0;
|
|
decimal ImporteGravado = 0;
|
|
decimal ImporteExento = 0;
|
|
decimal ImporteValor = 0;
|
|
//string NombrePersonal = "";
|
|
int CveMetodoPago = 0;
|
|
int CveNomina = 0;
|
|
int CveConcepto = 0;
|
|
int CveConceptoISR = 0;
|
|
int CveConceptoDescuento = 0;
|
|
|
|
if (continuar)
|
|
{
|
|
using (ClsNominas objNomina = new ClsNominas())
|
|
{
|
|
objNomina.IniciaTransacSQL();
|
|
if (continuar)
|
|
{
|
|
//continuar = objNomina.UpADDdUtilidadesEjercicio(UsuarioActual.CveEmpresa, ejercicio, utilimporte, utilimporteAnt, false);
|
|
//if (continuar)
|
|
//{
|
|
// if (objNomina.DtResultados.Rows.Count < 0 || objNomina.DtResultados.Rows[0]["CONTimbrado"].ToString() == "1")
|
|
// continuar = false;
|
|
//}
|
|
}
|
|
if (continuar)
|
|
{
|
|
continuar = objNomina.GetConceptos(UsuarioActual.CveEmpresa);
|
|
}
|
|
if (continuar)
|
|
{
|
|
DataRow rowc = objNomina.DtResultados.FiltroPrimero("CveSistema=5");
|
|
if ((rowc != null))
|
|
{
|
|
CveConcepto = rowc["CveConcepto"].ToString().ToEntero();
|
|
}
|
|
DataRow rowcz = objNomina.DtResultados.FiltroPrimero("CveSistema=21");
|
|
if ((rowcz != null))
|
|
{
|
|
CveConceptoISR = rowcz["CveConcepto"].ToString().ToEntero();
|
|
}
|
|
DataRow rowcy = objNomina.DtResultados.FiltroPrimero("CveConceptoContable=174 AND Tipo ='D'");
|
|
if ((rowcz != null))
|
|
{
|
|
CveConceptoDescuento = rowcy["CveConcepto"].ToString().ToEntero();
|
|
}
|
|
//else
|
|
//{
|
|
// CveConcepto = objNomina.AddConcepto("PTU", "Utilidades", "P", "", true, true, -1, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, false, -1, -1, -1, 0, -1, 0, 0, 0, 0, 0);
|
|
//}
|
|
if (CveConcepto < 1)
|
|
{
|
|
continuar = false;
|
|
Alert("debe agregar un concepto para el calculo del aguinaldo", ModExtensiones.TipoMensaje.ToastAdventencia);
|
|
}
|
|
}
|
|
if (continuar)
|
|
{
|
|
|
|
|
|
foreach (GridViewRow gvrow in GVCalcularAguinaldo.Rows)
|
|
{
|
|
CveNomina = gvrow.DataKey("CveNomina").ToEntero();
|
|
CvePersonal = gvrow.DataKey("CvePersonal").ToEntero();
|
|
CveMetodoPago = gvrow.DataKey("CveMetodoPago").ToEntero();
|
|
Importe = gvrow.FCLabel("lblsueldoAguinaldoCompleto").Text.ToDecimal();
|
|
ImporteGravado = gvrow.FCLabel("lblAguinaldoGravado").Text.ToDecimal();
|
|
ImporteExento = Importe - ImporteGravado;
|
|
ImporteValor = gvrow.FCLabel("lbldiasAguinaldoprop").Text.ToEntero();
|
|
importeAjuste = gvrow.FCTextBox("TxtAjuste").Text.ToDecimal();
|
|
ImporteDescuento = gvrow.FCTextBox("TxtDescuento").Text.ToDecimal();
|
|
|
|
ImporteISR = gvrow.FCLabel("lblISRAguinaldo").Text.ToDecimal();
|
|
|
|
|
|
// foreach (DataRow row in DTAguinaldos.Rows)
|
|
//{
|
|
//DiasLaborados = row["DiasLaborados"].ToString().ToEntero();
|
|
CvePeriodo = CvePeriodoSeleccionado;
|
|
/*
|
|
if (continuar)
|
|
{CveNomina
|
|
continuar = objNomina.AddUtilidad(CvePersonal, Importe, CvePeriodo, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, ejercicio, DiasLaborados, SueldoTotal);
|
|
}*/
|
|
//CveNomina = 0;
|
|
//CvePersonal = row["CvePersonal"].ToString().ToEntero();
|
|
//CveMetodoPago = row["CveMetodoPago"].ToString().ToEntero();
|
|
//Importe = row["Aguinaldo"].ToString().ToDecimal();
|
|
//ImporteGravado = row["AguinaldoGravado"].ToString().ToDecimal();
|
|
//ImporteExento = Importe - ImporteGravado;
|
|
//ImporteValor = row["DiasLaborados"].ToString().ToDecimal();
|
|
|
|
|
|
if (CvePersonal > 0 && Importe > 0 && CveNomina == 0)
|
|
{
|
|
if (objNomina.GetNom_Nominas(-1, CvePersonal, CvePeriodoSeleccionado, -1, UsuarioActual.CveEmpresa))
|
|
{
|
|
if (objNomina.DtResultados.Rows.Count > 0)
|
|
{
|
|
CveNomina = objNomina.CveNomina;
|
|
}
|
|
else
|
|
{
|
|
if (objNomina.AddNom_Nominas(-1, 1, CvePersonal, CvePeriodoSeleccionado, Importe.ToString().ToDouble(), 0, 0, Importe.ToString().ToDouble(), CveMoneda, 1, CveMetodoPago, DateTime.Now, "Deducciones nómina",
|
|
"", "", "", "", 0, 0, 0, new DateTime(), new DateTime(), new DateTime(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, false))
|
|
{
|
|
CveNomina = objNomina.CveNomina;
|
|
}
|
|
else
|
|
{
|
|
continuar = false;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
continuar = false;
|
|
}
|
|
if (CveNomina > 0)
|
|
{
|
|
|
|
if (continuar && !objNomina.AddUPNom_NominasDetalles(objNomina.CveNomina, CvePeriodoSeleccionado, CvePersonal, CveConcepto, Importe, ImporteGravado, ImporteExento, ImporteValor, UsuarioActual.CveUsuario, false, 1, 1, 1))
|
|
{
|
|
continuar = false;
|
|
}
|
|
if (continuar && !objNomina.AddUPNom_NominasDetalles(objNomina.CveNomina, CvePeriodoSeleccionado, CvePersonal, CveConceptoISR, ImporteISR, 0, ImporteISR, ImporteGravado, UsuarioActual.CveUsuario, false, 1, 1, 1))
|
|
{
|
|
continuar = false;
|
|
}
|
|
if (continuar && ImporteDescuento > 0 && !objNomina.AddUPNom_NominasDetalles(objNomina.CveNomina, CvePeriodoSeleccionado, CvePersonal, CveConceptoDescuento, ImporteDescuento, 0, ImporteDescuento, 0, UsuarioActual.CveUsuario, false, 1, 1, 1))
|
|
{
|
|
continuar = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
continuar = false;
|
|
}
|
|
}
|
|
|
|
if (!continuar)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
//if (continuar & CvePeriodoSeleccionado > 0)
|
|
//{
|
|
// continuar = objNomina.CambiaEstatusPeriodo(CvePeriodoSeleccionado, (int)enumNominasEstatus.Activa, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa);
|
|
//}
|
|
|
|
if (continuar)
|
|
{
|
|
objNomina.Commit();
|
|
//objNomina.Commit();
|
|
}
|
|
else
|
|
{
|
|
mensaje = string.Format(" {0} ", mensaje);
|
|
objNomina.RollBack();
|
|
}
|
|
|
|
|
|
|
|
objNomina.Dispose();
|
|
}
|
|
}
|
|
if (mensaje.Length > 0)
|
|
{
|
|
Alert(mensaje, ModExtensiones.TipoMensaje.MsgAdvertencia);
|
|
continuar = false;
|
|
}
|
|
if (continuar)
|
|
{
|
|
RegistraScript("$('#ModalAutorizar').modal('hide');");
|
|
Alert("Se ha generado el aguinaldo.");
|
|
BtnCalcular_Click(null, null);
|
|
}
|
|
}
|
|
|
|
protected void DdlTipoPeriodoB_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
CargaPeriodos();
|
|
}
|
|
|
|
protected void GVCalcularAguinaldo_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
int CveNomina = e.Row.DBCampo("CveNomina").ToString().ToEntero();
|
|
int CvePersonal = e.Row.DBCampo("CvePersonal").ToString().ToEntero();
|
|
if (CveNomina > 0)
|
|
{
|
|
e.Row.CssClass = "success";
|
|
}
|
|
if (UsuarioActual.CveEmpresa == 154 || UsuarioActual.CveEmpresa == 153)
|
|
{
|
|
e.Row.FCTextBox("TxtsueldoDiario").Visible = (CvePersonal > 0);
|
|
e.Row.FCLabel("lblsueldoDiario").Visible = false;
|
|
e.Row.FCTextBox("TxtSalarioAguinaldo").Visible = (CvePersonal > 0);
|
|
e.Row.FCLabel("lblSalarioAguinaldo").Visible = false;
|
|
}
|
|
else
|
|
{
|
|
e.Row.FCTextBox("TxtsueldoDiario").Visible = false;
|
|
e.Row.FCLabel("lblsueldoDiario").Visible = true;
|
|
e.Row.FCTextBox("TxtSalarioAguinaldo").Visible = false;
|
|
e.Row.FCLabel("lblSalarioAguinaldo").Visible = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void BtnRecalcular_Click(object sender, EventArgs e)
|
|
{
|
|
decimal uma = LtlUma.Text.ToDecimal();
|
|
decimal aguiexentogral = uma * 30;
|
|
decimal salarioAguinaldo = 0;
|
|
decimal salariodiario = 0;
|
|
decimal diasanio = 365;
|
|
decimal diaslaborados = 0;
|
|
decimal diasaguinaldo = 0;
|
|
decimal diasaguipago = 0;
|
|
decimal salariomensual = 0;
|
|
decimal aguinaldo = 0;
|
|
decimal aguinaldoexcento = 0;
|
|
decimal aguinaldogravado = 0;
|
|
decimal diasmes = 30.4m;
|
|
decimal FraccionI = 0;
|
|
decimal FraccionII_1 = 0;
|
|
decimal FraccionII_2 = 0;
|
|
decimal FraccionIII_1 = 0;
|
|
decimal FraccionIII_2 = 0;
|
|
decimal FraccionV = 0;
|
|
decimal FraccionIV = 0;
|
|
//decimal aguinaldoExcentoreg = 0;
|
|
|
|
decimal Aguinaldoapagar = 0;
|
|
decimal descuento = 0;
|
|
decimal ajuste =0;
|
|
|
|
decimal aguinaldoSubproyeto = 0;
|
|
decimal aguinaldogravadoSubproyeto = 0;
|
|
decimal descuentoSubproyeto = 0;
|
|
decimal ajusteSubproyeto = 0;
|
|
decimal ISRSubproyeto = 0;
|
|
decimal AguinaldoapagarTotalSubproyeto = 0;
|
|
|
|
|
|
decimal aguinaldoTotal = 0;
|
|
decimal aguinaldogravadoTotal = 0;
|
|
decimal descuentoTotal = 0;
|
|
decimal ajusteTotal = 0;
|
|
decimal ISRTOTAL = 0;
|
|
decimal AguinaldoapagarTotal = 0;
|
|
|
|
GridViewRow gvrowTotal = null;
|
|
GridViewRow gvrowSubProyecto = null;
|
|
int CvePersonal = 0;
|
|
int CveSubProyecto = 0;
|
|
StringBuilder str = new StringBuilder();
|
|
using (ClsClaseBaseD objbase = new ClsClaseBaseD())
|
|
{
|
|
|
|
foreach (GridViewRow gvrow in GVCalcularAguinaldo.Rows)
|
|
{
|
|
CveSubProyecto = gvrow.DataKey("CveSubProyecto").ToEntero();
|
|
CvePersonal = gvrow.DataKey("CvePersonal").ToEntero();
|
|
salarioAguinaldo = gvrow.FCTextBox("TxtSalarioAguinaldo").Text.ToDecimal();
|
|
salariodiario = gvrow.FCTextBox("TxtsueldoDiario").Text.ToDecimal();
|
|
diaslaborados = gvrow.FCLabel("TxtdiasLaborados").Text.ToDecimal();
|
|
diasaguinaldo = gvrow.FCLabel("TxtdiasAguinaldo").Text.ToDecimal();
|
|
descuento = gvrow.FCTextBox("TxtDescuento").Text.ToDecimal();
|
|
ajuste = gvrow.FCTextBox("TxtAjuste").Text.ToDecimal();
|
|
//aguinaldoExcentoreg = gvrow.FCTextBox("TxtAguinaldoExento").Text.ToDecimal();
|
|
|
|
if (CvePersonal > 0)
|
|
{
|
|
|
|
if (salariodiario > 0)
|
|
{
|
|
|
|
diasaguipago = (diaslaborados / diasanio) * diasaguinaldo;
|
|
salariomensual = salariodiario * 30;
|
|
aguinaldo = (diasaguipago * salarioAguinaldo)+ ajuste;
|
|
/*if (gvrow.FCTextBox("TxtAguinaldoExento").Text.Length > 0)
|
|
{
|
|
aguinaldoexcento = (aguinaldoExcentoreg > aguinaldo ? aguinaldo : aguinaldoExcentoreg);
|
|
gvrow.FCTextBox("TxtAguinaldoExento").Text = string.Format("{0}", aguinaldoexcento);
|
|
}
|
|
else
|
|
{
|
|
}*/
|
|
aguinaldoexcento = (aguiexentogral > aguinaldo ? aguinaldo : aguiexentogral);
|
|
aguinaldogravado = aguinaldo - aguinaldoexcento;
|
|
if (aguinaldogravado > 0)
|
|
{
|
|
FraccionI = (aguinaldogravado / diasanio) * diasmes;
|
|
FraccionII_1 = salariomensual + FraccionI;
|
|
str.Clear();
|
|
str.AppendFormat("SELECT dbo.Fnc_NomValues(40, 0, 00, -1, {0}, {1}, {1}) isrFraccionII_2,", FraccionII_1, diasmes);
|
|
str.AppendFormat(" dbo.Fnc_NomValues(40, 0, 00, -1, {0}, {1}, {1}) isrFraccionIII_1", salariomensual, diasmes);
|
|
if (objbase.runQuerystr(str.ToString()))
|
|
{
|
|
DataRow drow = objbase.DtResultados.Rows[0];
|
|
FraccionII_2 = drow["isrFraccionII_2"].ToString().ToDecimal();
|
|
FraccionIII_1 = drow["isrFraccionIII_1"].ToString().ToDecimal();
|
|
}
|
|
else { break; }
|
|
|
|
FraccionIII_2 = FraccionII_2 - FraccionIII_1;
|
|
FraccionV = FraccionIII_2 / FraccionI;
|
|
FraccionIV = aguinaldogravado * FraccionV;
|
|
Aguinaldoapagar = aguinaldo - FraccionIV;
|
|
}
|
|
else
|
|
{
|
|
|
|
FraccionIV = 0;
|
|
Aguinaldoapagar = aguinaldo - FraccionIV;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
aguinaldo = 0;
|
|
Aguinaldoapagar = 0;
|
|
aguinaldogravado = 0;
|
|
FraccionIV = 0;
|
|
}
|
|
|
|
Aguinaldoapagar = Aguinaldoapagar - descuento;
|
|
|
|
aguinaldogravadoSubproyeto += aguinaldogravado;
|
|
descuentoSubproyeto += descuento;
|
|
ajusteSubproyeto += ajuste;
|
|
aguinaldoSubproyeto += aguinaldo;
|
|
ISRSubproyeto += FraccionIV;
|
|
AguinaldoapagarTotalSubproyeto += Aguinaldoapagar;
|
|
|
|
|
|
|
|
aguinaldogravadoTotal += aguinaldogravado;
|
|
descuentoTotal += descuento;
|
|
ajusteTotal += ajuste;
|
|
ISRTOTAL += FraccionIV;
|
|
aguinaldoTotal += aguinaldo;
|
|
|
|
AguinaldoapagarTotal += Aguinaldoapagar;
|
|
gvrow.FCLabel("lblsueldoAguinaldoCompleto").Text = string.Format("${0:N2}", aguinaldo);
|
|
gvrow.FCLabel("lblAguinaldoGravado").Text = string.Format("${0:N2}", aguinaldogravado);
|
|
|
|
gvrow.FCLabel("lblFraccion1").Text = string.Format("${0:N2}", FraccionI);
|
|
gvrow.FCLabel("lblFraccion2").Text = string.Format("${0:N2}", FraccionII_2);
|
|
gvrow.FCLabel("lblFraccion3").Text = string.Format("${0:N2}", FraccionIII_2);
|
|
gvrow.FCLabel("lblFraccion4").Text = string.Format("${0:N2}", FraccionIV);
|
|
|
|
|
|
gvrow.FCLabel("lblISRAguinaldo").Text = string.Format("${0:N2}", FraccionIV);
|
|
gvrow.FCLabel("lblAguinaldo").Text = string.Format("${0:N2}", Aguinaldoapagar);
|
|
}
|
|
else
|
|
{
|
|
|
|
if (gvrowSubProyecto != null)
|
|
{
|
|
gvrowSubProyecto.FCLabel("lblISRAguinaldo").Text = string.Format("${0:N2}", ISRSubproyeto);
|
|
gvrowSubProyecto.FCLabel("lblAguinaldoGravado").Text = string.Format("${0:N2}", aguinaldogravadoSubproyeto);
|
|
gvrowSubProyecto.FCLabel("lblDescuento").Text = string.Format("${0:N2}", descuentoSubproyeto);
|
|
gvrowSubProyecto.FCLabel("lblAjuste").Text = string.Format("${0:N2}", ajusteSubproyeto);
|
|
gvrowSubProyecto.FCLabel("lblsueldoAguinaldoCompleto").Text = string.Format("${0:N2}", aguinaldoSubproyeto);
|
|
gvrowSubProyecto.FCLabel("lblAguinaldo").Text = string.Format("${0:N2}", AguinaldoapagarTotalSubproyeto);
|
|
}
|
|
if (CveSubProyecto > 0)
|
|
{
|
|
gvrowSubProyecto = gvrow;
|
|
}
|
|
else
|
|
{
|
|
gvrowTotal = gvrow;
|
|
}
|
|
ISRSubproyeto = 0;
|
|
aguinaldogravadoSubproyeto = 0;
|
|
aguinaldoSubproyeto = 0;
|
|
AguinaldoapagarTotalSubproyeto = 0;
|
|
descuentoSubproyeto = 0;
|
|
ajusteSubproyeto = 0;
|
|
gvrow.CssClass = "Totales"; gvrow.FCTextBox("TxtDescuento").Visible = false; gvrow.FCTextBox("TxtAjuste").Visible = false;
|
|
}
|
|
}
|
|
|
|
}
|
|
if (gvrowSubProyecto != null)
|
|
{
|
|
gvrowSubProyecto.FCLabel("lblISRAguinaldo").Text = string.Format("${0:N2}", ISRSubproyeto);
|
|
gvrowSubProyecto.FCLabel("lblAguinaldoGravado").Text = string.Format("${0:N2}", aguinaldogravadoSubproyeto);
|
|
gvrowSubProyecto.FCLabel("lblDescuento").Text = string.Format("${0:N2}", descuentoSubproyeto);
|
|
gvrowSubProyecto.FCLabel("lblAjuste").Text = string.Format("${0:N2}", ajusteSubproyeto);
|
|
gvrowSubProyecto.FCLabel("lblsueldoAguinaldoCompleto").Text = string.Format("${0:N2}", aguinaldoSubproyeto);
|
|
gvrowSubProyecto.FCLabel("lblAguinaldo").Text = string.Format("${0:N2}", AguinaldoapagarTotalSubproyeto);
|
|
}
|
|
if (gvrowTotal != null)
|
|
{
|
|
gvrowTotal.FCLabel("lblISRAguinaldo").Text = string.Format("${0:N2}", ISRTOTAL);
|
|
gvrowTotal.FCLabel("lblAguinaldoGravado").Text = string.Format("${0:N2}", aguinaldogravadoTotal);
|
|
gvrowTotal.FCLabel("lblDescuento").Text = string.Format("${0:N2}", descuentoTotal);
|
|
gvrowTotal.FCLabel("lblAjuste").Text = string.Format("${0:N2}", ajusteTotal);
|
|
gvrowTotal.FCLabel("lblsueldoAguinaldoCompleto").Text = string.Format("${0:N2}", aguinaldoTotal);
|
|
gvrowTotal.FCLabel("lblAguinaldo").Text = string.Format("${0:N2}", AguinaldoapagarTotal);
|
|
|
|
}
|
|
LtlTotal.Text = string.Format("${0:N2}", AguinaldoapagarTotal);
|
|
|
|
|
|
}
|
|
|
|
protected void LnkDownExcel_Click(object sender, EventArgs e)
|
|
{
|
|
// GVCalcularAguinaldo.ExportToExcelx(string.Format("Aguinaldo {0}", DdlEjercicios.SelectedItem.Text));
|
|
|
|
|
|
ClosedXML.Excel.XLWorkbook wb = new ClosedXML.Excel.XLWorkbook();
|
|
var libro = wb.AddWorksheet("Nomina");
|
|
int fila = 0;
|
|
fila = fila + 1;
|
|
int filatitulo = fila;
|
|
libro.SheetView.Freeze(filatitulo, 1);
|
|
int cxc = 1;
|
|
libro.Cell(fila, cxc++).Value = "Código";
|
|
libro.Cell(fila, cxc++).Value = "Empleado";
|
|
libro.Cell(fila, cxc++).Value = "Fecha ingreso";//lblfechaingreso
|
|
libro.Cell(fila, cxc++).Value = "Salario diario";
|
|
libro.Cell(fila, cxc++).Value = "Salario Aguinaldo";
|
|
libro.Cell(fila, cxc++).Value = "Días laborados";
|
|
libro.Cell(fila, cxc++).Value = "Días Faltados";//lbldiasAguinaldoprop
|
|
libro.Cell(fila, cxc++).Value = "Días Incapacidad";//lbldiasAguinaldoprop
|
|
libro.Cell(fila, cxc++).Value = "Días base";
|
|
libro.Cell(fila, cxc++).Value = "Días aguinaldo";//lbldiasAguinaldoprop
|
|
libro.Cell(fila, cxc++).Value = "Ajuste";//TxtAjuste
|
|
libro.Cell(fila, cxc++).Value = "Aguinaldo completo";
|
|
libro.Cell(fila, cxc++).Value = "Aguinaldo gravado";
|
|
libro.Cell(fila, cxc++).Value = "Aguinaldo exento";
|
|
libro.Cell(fila, cxc++).Value = "Fraccion I"; //lblFraccion1
|
|
libro.Cell(fila, cxc++).Value = "Fraccion II"; //lblFraccion2
|
|
libro.Cell(fila, cxc++).Value = "Fraccion III"; //lblFraccion3
|
|
libro.Cell(fila, cxc++).Value = "Fraccion IV"; //lblFraccion4
|
|
libro.Cell(fila, cxc++).Value = "I.S.R.";
|
|
libro.Cell(fila, cxc++).Value = "Descuento"; //TxtDescuento
|
|
libro.Cell(fila, cxc++).Value = "Aguinaldo por pagar";
|
|
|
|
libro.Range(fila, 1, fila, 20).Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
|
|
libro.Range(fila, 1, fila, 20).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189));
|
|
foreach (GridViewRow gvrow in GVCalcularAguinaldo.Rows)
|
|
{
|
|
fila = fila + 1;
|
|
|
|
|
|
if (!(gvrow.DataKey("CvePersonal").ToEntero() > 0))
|
|
{
|
|
if (gvrow.DataKey("CveSubProyecto").ToEntero() > 0)
|
|
{
|
|
libro.Range(fila, 1, fila, 20).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(217, 217, 217));
|
|
}
|
|
else
|
|
{
|
|
libro.Range(fila, 1, fila, 20).Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
|
|
libro.Range(fila, 1, fila, 20).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(128, 128, 128));
|
|
}
|
|
|
|
}
|
|
|
|
cxc = 1;
|
|
libro.Cell(fila, cxc++).Value = string.Format("'{0}",gvrow.DataKey("Codigo"));
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblnombreCompleto").Text;
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblfechaingreso").Text;
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCTextBox("TxtsueldoDiario").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCTextBox("TxtSalarioAguinaldo").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("TxtdiasLaborados").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("TxtdiasFaltados").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("TxtdiasIncapacidad").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("TxtdiasAguinaldo").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lbldiasAguinaldoprop").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCTextBox("TxtAjuste").Text.ToDecimal();
|
|
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblsueldoAguinaldoCompleto").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblAguinaldoGravado").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblsueldoAguinaldoCompleto").Text.ToDecimal() - gvrow.FCLabel("lblAguinaldoGravado").Text.ToDecimal();
|
|
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblFraccion1").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblFraccion2").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblFraccion3").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblFraccion4").Text.ToDecimal();
|
|
|
|
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblISRAguinaldo").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCTextBox("TxtDescuento").Text.ToDecimal();
|
|
libro.Cell(fila, cxc++).Value = gvrow.FCLabel("lblAguinaldo").Text.ToDecimal();
|
|
}
|
|
|
|
libro.Range(filatitulo, 1, fila, 18).Columns();
|
|
libro.Range(filatitulo + 1, 4, fila + 1, 20).DataType = ClosedXML.Excel.XLDataType.Number;
|
|
libro.Range(filatitulo + 1, 4, fila + 1,5).Style.NumberFormat.Format = "$###,###,###,##0.00";
|
|
libro.Range(filatitulo + 1, 11, fila + 1, 20).Style.NumberFormat.Format = "$###,###,###,##0.00";
|
|
libro.ColumnsUsed().AdjustToContents();
|
|
|
|
System.IO.Stream fs = new System.IO.MemoryStream();
|
|
wb.SaveAs(fs);
|
|
fs.Position = 0;
|
|
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
|
|
using (System.IO.Stream input = fs)
|
|
|
|
{
|
|
input.CopyTo(memoryStream);
|
|
}
|
|
memoryStream.Position = 0;
|
|
|
|
Response.Clear();
|
|
Response.Buffer = true;
|
|
|
|
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
Response.AddHeader("content-disposition", string.Format("attachment;filename={0} {1}.xlsx", "Aguinaldo", DdlEjercicios.SelectedValue));
|
|
Response.BinaryWrite(memoryStream.ToArray());
|
|
Response.End();
|
|
}
|
|
}
|
|
|
|
class ClsClaseBaseD : IDisposable
|
|
{
|
|
protected SqlConnection SqlConexion;
|
|
protected SqlDataAdapter SqlAdapter;
|
|
protected DataTable datos;
|
|
protected DataSet DTSet;
|
|
public DataTable DtResultados
|
|
{
|
|
get
|
|
{
|
|
return datos;
|
|
}
|
|
}
|
|
public DataSet DTSetResultados
|
|
{
|
|
get
|
|
{
|
|
return DTSet;
|
|
}
|
|
}
|
|
protected bool disposedValue = false;
|
|
protected bool EsTransaccion = false;
|
|
public string MyCurrentError;
|
|
// REGISTRAR CONEXIÓN
|
|
private int CveConexion = 0;
|
|
|
|
public ClsClaseBaseD(ClsClaseBaseD adsObj = null, SqlTransaction sqlTransacc = null, SqlDataAdapter sqlAdapter = null)
|
|
{
|
|
|
|
|
|
if (adsObj != null && adsObj.SqlAdapter != null && adsObj.SqlAdapter.SelectCommand != null && adsObj.SqlAdapter.SelectCommand.Transaction != null)
|
|
{
|
|
SqlConexion = adsObj.SqlConexion;
|
|
SqlAdapter = adsObj.SqlAdapter;
|
|
EsTransaccion = true;
|
|
}
|
|
else
|
|
{
|
|
if (sqlTransacc != null)
|
|
{
|
|
SqlConexion = sqlTransacc.Connection;
|
|
SqlAdapter = sqlAdapter;
|
|
EsTransaccion = true;
|
|
}
|
|
else
|
|
{
|
|
SqlConexion = new SqlConnection();
|
|
SqlConexion.ConnectionString = ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString;
|
|
try
|
|
{
|
|
SqlConexion.Open();
|
|
SqlAdapter = new SqlDataAdapter("", SqlConexion);
|
|
ConexionAdd();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.OnError("Ocurrió un error al intentar conectarse a la base de datos.", ex);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void SqlDataAdapter(string StrSQL, CommandType TipoComando = CommandType.StoredProcedure)
|
|
{
|
|
if (SqlConexion.State == ConnectionState.Open)
|
|
{
|
|
SqlAdapter.SelectCommand.Parameters.Clear();
|
|
SqlAdapter.SelectCommand.CommandText = StrSQL;
|
|
SqlAdapter.SelectCommand.CommandType = TipoComando;
|
|
datos = new DataTable();
|
|
DTSet = new DataSet();
|
|
}
|
|
}
|
|
protected void DataAdapter(string StrSQL, CommandType TipoComando = CommandType.Text)
|
|
{
|
|
|
|
// if (SqlAdapter.SelectCommand == null)
|
|
// {
|
|
// if ((sqlCommand != null))
|
|
// {
|
|
// SqlAdapter.SelectCommand = sqlCommand;
|
|
// }
|
|
// else
|
|
// {
|
|
// SqlAdapter.SelectCommand = new SqlCommand();
|
|
// }
|
|
// SqlAdapter.SelectCommand.Connection = SqlConexion;
|
|
// }
|
|
|
|
if (SqlConexion.State == ConnectionState.Open)
|
|
{
|
|
SqlAdapter.SelectCommand.Parameters.Clear();
|
|
SqlAdapter.SelectCommand.CommandText = StrSQL;
|
|
SqlAdapter.SelectCommand.CommandType = TipoComando;
|
|
datos = new DataTable();
|
|
DTSet = new DataSet();
|
|
}
|
|
}
|
|
|
|
private void ConexionAdd()
|
|
{
|
|
if (ConfigurationManager.AppSettings["RegistraConexion"] != null && ConfigurationManager.AppSettings["RegistraConexion"].ToString() == "1")
|
|
{
|
|
try
|
|
{
|
|
SqlDataAdapter("PA_Sis_RegistrarConexion");
|
|
{
|
|
var withBlock = SqlAdapter.SelectCommand.Parameters;
|
|
withBlock.Add("@Clase", SqlDbType.VarChar).Value = this.GetType().Name;
|
|
withBlock.Add("@Modulo", SqlDbType.VarChar).Value = string.Format("{0}?{1}", HttpContext.Current.Request.Url.AbsolutePath.ToString(), HttpContext.Current.Request.QueryString.ToString());
|
|
withBlock.Add("@IDConexion", SqlDbType.Int).Direction = ParameterDirection.Output;
|
|
}
|
|
SqlAdapter.Fill(datos);
|
|
CveConexion = SqlAdapter.SelectCommand.Parameters["@IDConexion"].Value.ToString().ToEntero();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo());
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ConexionClose()
|
|
{
|
|
if (CveConexion > 0 && ConfigurationManager.AppSettings["RegistraConexion"] != null && ConfigurationManager.AppSettings["RegistraConexion"].ToString() == "1")
|
|
{
|
|
SqlDataAdapter(string.Format("UPDATE Sis_Conexiones SET FechaCierre = GETDATE() WHERE CveConexion = {0}", CveConexion), CommandType.Text);
|
|
|
|
try
|
|
{
|
|
SqlAdapter.Fill(datos);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.OnError("Ocurrió un error registrar la conexión.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo());
|
|
}
|
|
CveConexion = 0;
|
|
}
|
|
}
|
|
protected void addParameters(string name, SqlDbType tipo, object valor)
|
|
{
|
|
if (SqlConexion.State == ConnectionState.Open)
|
|
SqlAdapter.SelectCommand.Parameters.Add(name, tipo).Value = valor;
|
|
}
|
|
|
|
public bool runQuerystr(string Query, List<parametroQuery> Listaparametros = null, string msgError = "", bool mostrarError = true)
|
|
{
|
|
bool retorno = false;
|
|
try
|
|
{
|
|
if (SqlConexion.State == ConnectionState.Open)
|
|
{
|
|
SqlAdapter.SelectCommand.Parameters.Clear();
|
|
SqlAdapter.SelectCommand.CommandText = Query;
|
|
SqlAdapter.SelectCommand.CommandType = CommandType.Text;
|
|
datos = new DataTable();
|
|
if (Listaparametros != null)
|
|
{
|
|
foreach (parametroQuery pr in Listaparametros)
|
|
{
|
|
SqlAdapter.SelectCommand.Parameters.Add(pr.ParameterName, pr.SqlDataType).Direction = pr.ParameterDirection;
|
|
}
|
|
}
|
|
|
|
SqlAdapter.Fill(datos);
|
|
retorno = true;
|
|
}
|
|
else
|
|
{
|
|
string InfoAdicional = "Se intenta realizar una conexion con una conexion cerrada";
|
|
InfoAdicional = $"{InfoAdicional}{Environment.NewLine}{msgError}{Environment.NewLine}";
|
|
ModExtensiones.GuardaLog(InfoAdicional);
|
|
}
|
|
}
|
|
catch (SqlException sqEx)
|
|
{
|
|
retorno = false;
|
|
setOnError(msgError, sqEx);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
retorno = false;
|
|
setOnError(msgError, ex);
|
|
}
|
|
return retorno;
|
|
}
|
|
public int ExecQuery(string Query, List<parametroQuery> Listaparametros = null, string msgError = "", bool mostrarError = true)
|
|
{
|
|
int retorno = -1;
|
|
try
|
|
{
|
|
if (SqlConexion.State == ConnectionState.Open)
|
|
{
|
|
SqlAdapter.SelectCommand.Parameters.Clear();
|
|
SqlAdapter.SelectCommand.CommandText = Query;
|
|
SqlAdapter.SelectCommand.CommandType = CommandType.Text;
|
|
if (Listaparametros != null)
|
|
{
|
|
foreach (parametroQuery pr in Listaparametros)
|
|
{
|
|
SqlAdapter.SelectCommand.Parameters.Add(pr.ParameterName, pr.SqlDataType).Direction = pr.ParameterDirection;
|
|
}
|
|
}
|
|
|
|
retorno = SqlAdapter.SelectCommand.ExecuteNonQuery();
|
|
}
|
|
else
|
|
{
|
|
string InfoAdicional = "Se intenta realizar una conexion con una conexion cerrada";
|
|
InfoAdicional = $"{InfoAdicional}{Environment.NewLine}{msgError}{Environment.NewLine}";
|
|
this.GuardaLog(InfoAdicional);
|
|
}
|
|
}
|
|
catch (SqlException sqEx)
|
|
{
|
|
retorno = -1;
|
|
setOnError(msgError, sqEx);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
retorno = -1;
|
|
setOnError(msgError, ex);
|
|
}
|
|
return retorno;
|
|
}
|
|
|
|
|
|
protected bool RunQuery(string msgOnError)
|
|
{
|
|
bool retorno = false;
|
|
|
|
try
|
|
{
|
|
SqlAdapter.Fill(datos);
|
|
retorno = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
retorno = false;
|
|
|
|
setOnError(msgOnError, ex);
|
|
}
|
|
return retorno;
|
|
}
|
|
protected bool RunQueryDS(string msgOnError)
|
|
{
|
|
bool retorno = false;
|
|
|
|
try
|
|
{
|
|
SqlAdapter.Fill(DTSet);
|
|
retorno = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
retorno = false;
|
|
|
|
setOnError(msgOnError, ex);
|
|
}
|
|
return retorno;
|
|
}
|
|
public void setOnError(string Mensaje, Exception Exeption)
|
|
{
|
|
string InfoAdicional = "";
|
|
if (SqlAdapter != null && SqlAdapter.SelectCommand != null && SqlAdapter.SelectCommand.Parameters != null)
|
|
InfoAdicional = SqlAdapter.SelectCommand.Parameters.ParametrosInfo();
|
|
MyCurrentError = string.Format("{0} DESCRIPCIÓN DETALLADA: {1} {2} {3}", Mensaje, Exeption.ToString(), "\r\n", InfoAdicional);
|
|
this.OnError(Mensaje, Exeption, InfoAdicional);
|
|
}
|
|
public void IniciaTransacSQL()
|
|
{
|
|
SqlAdapter.SelectCommand.Transaction = SqlConexion.BeginTransaction();
|
|
EsTransaccion = true;
|
|
}
|
|
|
|
public void Commit()
|
|
{
|
|
SqlAdapter.SelectCommand.Transaction.Commit();
|
|
SqlConexion.Close();
|
|
}
|
|
|
|
public void RollBack()
|
|
{
|
|
SqlAdapter.SelectCommand.Transaction.Rollback();
|
|
SqlConexion.Close();
|
|
}
|
|
public void Dispose()
|
|
{
|
|
ConexionClose();
|
|
if ((SqlConexion != null))
|
|
{
|
|
if (SqlConexion.State == ConnectionState.Open)
|
|
{
|
|
try
|
|
{
|
|
if ((SqlAdapter != null))
|
|
SqlAdapter.Dispose();
|
|
|
|
SqlConexion.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.OnError("Ocurrió un error al intentar cerrar la base de datos.", ex);
|
|
}
|
|
}
|
|
SqlConexion.Dispose();
|
|
}
|
|
|
|
if (datos != null)
|
|
datos.Dispose();
|
|
if (SqlAdapter != null)
|
|
SqlAdapter.Dispose();
|
|
|
|
if (DTSet != null)
|
|
DTSet.Dispose();
|
|
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
|
|
//public class parametroQuery
|
|
//{
|
|
// public parametroQuery(string parameterName, object sqlValue, SqlDbType sqlDataType = default(SqlDbType), ParameterDirection parameterDirection = default(ParameterDirection))
|
|
// {
|
|
// this.ParameterName = parameterName;
|
|
// this.SqlDataType = sqlDataType;
|
|
// this.ParameterDirection = parameterDirection;
|
|
// this.SqlValue = sqlValue;
|
|
// }
|
|
|
|
// public string ParameterName { get; set; }
|
|
// public SqlDbType SqlDataType { get; set; }
|
|
// public ParameterDirection ParameterDirection { get; set; }
|
|
// public object SqlValue { get; set; }
|
|
//}
|