304 lines
11 KiB
C#
304 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using ClosedXML.Excel;
|
|
using Extensiones;
|
|
using Profact.TimbraCFDI40;
|
|
using static Extensiones.ModExtensiones;
|
|
|
|
public partial class Nomina_RepMovtosPermanentes : ClsPaginas
|
|
{
|
|
#region Propiedades
|
|
|
|
private int RcvePersonal
|
|
{
|
|
get { return ViewState["RcvePersonal"] != null ? (int)ViewState["RcvePersonal"] : 0; }
|
|
set { ViewState["RcvePersonal"] = value; }
|
|
}
|
|
|
|
private int RcveTipo
|
|
{
|
|
get { return ViewState["RcveTipo"] != null ? (int)ViewState["RcveTipo"] : 0; }
|
|
set { ViewState["RcveTipo"] = value; }
|
|
}
|
|
|
|
private int RcveSaldo
|
|
{
|
|
get { return ViewState["RcveSaldo"] != null ? (int)ViewState["RcveSaldo"] : 0; }
|
|
set { ViewState["RcveSaldo"] = value; }
|
|
}
|
|
|
|
private int RcveEstatus
|
|
{
|
|
get { return ViewState["RcveEstatus"] != null ? (int)ViewState["RcveEstatus"] : 0; }
|
|
set { ViewState["RcveEstatus"] = value; }
|
|
}
|
|
|
|
private int RcveConcepto
|
|
{
|
|
get { return ViewState["RcveConcepto"] != null ? (int)ViewState["RcveConcepto"] : 0; }
|
|
set { ViewState["RcveConcepto"] = value; }
|
|
}
|
|
private string fechaInicio
|
|
{
|
|
get { return TxtRpdFechaInicio.Text; }
|
|
set { TxtRpdFechaInicio.Text = value; }
|
|
}
|
|
private string fechaFin
|
|
{
|
|
get { return TxtRpdFechaFin.Text; }
|
|
set { TxtRpdFechaFin.Text = value; }
|
|
}
|
|
#endregion
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
RcvePersonal = Request["cvePersonal"] != null ? Convert.ToInt32(Request["cvePersonal"]) : -1;
|
|
RcveTipo = Request["cveTipo"] != null ? Convert.ToInt32(Request["cveTipo"]) : -1;
|
|
RcveSaldo = Request["cveSaldo"] != null ? Convert.ToInt32(Request["cveSaldo"]) : -1;
|
|
RcveEstatus = Request["cveEstatus"] != null ? Convert.ToInt32(Request["cveEstatus"]) : -1;
|
|
RcveConcepto = Request["cveConcepto"] != null ? Convert.ToInt32(Request["cveConcepto"]) : -1;
|
|
CargaCombos();
|
|
|
|
}
|
|
}
|
|
|
|
protected void DdlEjercicios_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
cargaPeriodos();
|
|
}
|
|
|
|
protected void DdlTipoPeriodo_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
cargaPeriodos(1);
|
|
}
|
|
private void cargaPeriodos(int tipo = 0)
|
|
{
|
|
int tipoPeriodo = DdlTipoPeriodo.SelectedValue.ToEntero();
|
|
int ejercicio = DdlEjercicios.SelectedValue.ToEntero();
|
|
DataTable dtPeriodos = null;
|
|
if (DdlTipoPeriodo.SelectedValue.ToEntero() > 0)
|
|
{
|
|
using (ClsNominas objperiodos = new ClsNominas())
|
|
{
|
|
if (objperiodos.GetPeriodos(tipoPeriodo, UsuarioActual.CveEmpresa, ejercicio, -1, -1))
|
|
{
|
|
|
|
dtPeriodos = objperiodos.DtResultados.FiltraParametros("Estatus IN (1,2,3,4,5)");
|
|
}
|
|
}
|
|
}
|
|
DdlPeriodo.DataSource = dtPeriodos;
|
|
DdlPeriodo.DataBind();
|
|
DdlPeriodo.Items.Insert(0, new ListItem("Seleccione", "-1"));
|
|
if (tipo == 1 && dtPeriodos != null && dtPeriodos.Rows.Count > 0)
|
|
{
|
|
DdlPeriodo.SelectedValue = dtPeriodos.Rows[0]["CvePeriodo"].ToString();
|
|
}
|
|
}
|
|
protected void CargaCombos()
|
|
{
|
|
DDlPersonal.DataSource = get_GlobalDTRHPersonal(UsuarioActual.CveEmpresa);
|
|
DDlPersonal.DataBind();
|
|
|
|
using (ClsNominas onom = new ClsNominas())
|
|
{
|
|
if (onom.GetConceptos(UsuarioActual.CveEmpresa))
|
|
{
|
|
DDLConcepto.DataSource = onom.DtResultados.FiltraParametros(" FormulaTotal = 'FNC.[MovimientosPermanentes]' OR Concepto like '%FONACOT%'");
|
|
}
|
|
DDLConcepto.DataBind();
|
|
}
|
|
DDlPersonal.SelectedValueExist(RcvePersonal.ToString());
|
|
DDlTipo.SelectedValueExist(RcveTipo.ToString());
|
|
DDLSaldo.SelectedValueExist(RcveSaldo.ToString());
|
|
DDLEstatus.SelectedValueExist(RcveEstatus.ToString());
|
|
DDLConcepto.SelectedValueExist(RcveConcepto.ToString());
|
|
|
|
|
|
DataTable dtejercicio = null;
|
|
using (ClsNominas objnom = new ClsNominas())
|
|
{
|
|
if (objnom.GetEjercicios(UsuarioActual.CveEmpresa))
|
|
{
|
|
dtejercicio = objnom.DtResultados;
|
|
}
|
|
}
|
|
DdlEjercicios.DataSource = dtejercicio;
|
|
DdlEjercicios.DataBind();
|
|
DdlTipoPeriodo.DataSource = get_GlobalDTTipoPeriodos(UsuarioActual.CveEmpresa);
|
|
DdlTipoPeriodo.DataBind();
|
|
if(DdlTipoPeriodo.Items.Count > 0) {
|
|
DdlTipoPeriodo.SelectedIndex= 0;
|
|
DdlTipoPeriodo_SelectedIndexChanged(null, null);
|
|
|
|
}
|
|
}
|
|
protected void cargardatos()
|
|
{
|
|
using (ClsNominas ObjGetM = new ClsNominas())
|
|
{
|
|
//string fechaInicio = "";
|
|
//string fechaFin = "";
|
|
int CvePeriodo = DdlPeriodo.SelectedValue.ToEntero() > 0 ? DdlPeriodo.SelectedValue.ToEntero() : -1;
|
|
ObjGetM.GetMovtoPermanenteRepFechas(RcvePersonal, UsuarioActual.CveEmpresa, RcveTipo, RcveSaldo, RcveEstatus, RcveConcepto, fechaInicio.ToDateTime().ToString("yyyy-MM-dd"), fechaFin.ToDateTime().ToString("yyyy-MM-dd"), CvePeriodo);
|
|
GVGetMovtoPermanenteRep.DataSource = ObjGetM.DtResultados;
|
|
GVGetMovtoPermanenteRep.DataBind();
|
|
|
|
}
|
|
upDatosGetM.Update();
|
|
}
|
|
|
|
protected void BtnConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
RcvePersonal = Convert.ToInt32(DDlPersonal.SelectedValue);
|
|
RcveTipo = Convert.ToInt32(DDlTipo.SelectedValue);
|
|
RcveSaldo = Convert.ToInt32(DDLSaldo.SelectedValue);
|
|
RcveEstatus = Convert.ToInt32(DDLEstatus.SelectedValue);
|
|
RcveConcepto = Convert.ToInt32(DDLConcepto.SelectedValue);
|
|
|
|
cargardatos();
|
|
}
|
|
protected void GVGetMovtoPermanenteRep_RowDataBound(object sender, GridViewRowEventArgs e)
|
|
{
|
|
|
|
if (e.Row.RowType == DataControlRowType.Header)
|
|
{
|
|
e.Row.CssClass = "headerHide";
|
|
}
|
|
if (e.Row.RowType == DataControlRowType.DataRow)
|
|
{
|
|
string cssclass = "";
|
|
// Obtener el valor de la columna "cvetipo"
|
|
string cvetipoValue = DataBinder.Eval(e.Row.DataItem, "cvetipo").ToString();
|
|
string cvepersonal = DataBinder.Eval(e.Row.DataItem, "cvepersonal").ToString();
|
|
|
|
// Agregar el atributo 'data-cvetipo' a la fila
|
|
e.Row.Attributes.Add("data-cvetipo", cvetipoValue);
|
|
e.Row.Attributes.Add("data-cvepersonal", cvepersonal);
|
|
if (cvetipoValue == "0")
|
|
{
|
|
//e.Row.Cells[1].Attributes.Add("colspan", "7");
|
|
cssclass = string.Format("{0} cvetipo0", cssclass);
|
|
}
|
|
e.Row.CssClass = cssclass;
|
|
}
|
|
}
|
|
|
|
protected void lnkVerRegistros_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
protected void LnkPagar_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
protected void LnkremoveMovtoPermanente_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
GridViewRow gvRow = (GridViewRow)(((LinkButton)sender).NamingContainer);
|
|
int CcveMovtoPermanente = gvRow.DataKey("CveMovtoPermanente").ToEntero();
|
|
bool Continuar = false;
|
|
using (ClsNominas ObjMovt = new ClsNominas())
|
|
{
|
|
Continuar = ObjMovt.RemoveMovtoPermanente(CcveMovtoPermanente);
|
|
|
|
}
|
|
if (Continuar)
|
|
{
|
|
cargardatos();
|
|
Alert("Se ha eliminadó el movimiento permanente");
|
|
}
|
|
}
|
|
|
|
protected void LnkFormatoxls_Click(object sender, EventArgs e)
|
|
{
|
|
using (ClsNominas ObjGetM = new ClsNominas())
|
|
{
|
|
//string fechaInicio = "";
|
|
//string fechaFin = "";
|
|
ObjGetM.GetMovtoPermanenteRepFechas(RcvePersonal, UsuarioActual.CveEmpresa, RcveTipo, RcveSaldo, RcveEstatus, RcveConcepto, fechaInicio.ToDateTime().ToString("yyyy-MM-dd"), fechaFin.ToDateTime().ToString("yyyy-MM-dd"));
|
|
ExportarExcel(ObjGetM.DtResultados);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
protected void ExportarExcel(DataTable dt)
|
|
{
|
|
using (var wb = new XLWorkbook())
|
|
{
|
|
var ws = wb.Worksheets.Add("Descuentos");
|
|
|
|
// Encabezados
|
|
ws.Cell(1, 1).Value = "Código";
|
|
ws.Cell(1, 2).Value = "Nombre Completo";
|
|
ws.Cell(1, 3).Value = "Descuento Acordado";
|
|
ws.Cell(1, 4).Value = "Descuento Aplicado";
|
|
ws.Cell(1, 5).Value = "Acumulado";
|
|
|
|
// Estilo del encabezado
|
|
var headerRange = ws.Range("A1:E1");
|
|
headerRange.Style.Fill.BackgroundColor = XLColor.LightGray;
|
|
headerRange.Style.Font.Bold = true;
|
|
headerRange.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
|
|
|
int row = 2;
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
int cveTipo = Convert.ToInt32(dr["CveTipo"]);
|
|
|
|
string codigo = dr["Codigo"].ToString();
|
|
string nombre = cveTipo == 0 ? dr["Concepto"].ToString() : dr["NombreCompleto"].ToString();
|
|
decimal valor = Convert.ToDecimal(dr["Valor"]);
|
|
decimal aplicado = Convert.ToDecimal(dr["MontoAplicado"]);
|
|
decimal acumulado = Convert.ToDecimal(dr["Acumulado"]);
|
|
|
|
ws.Cell(row, 1).Value = codigo;
|
|
ws.Cell(row, 2).Value = nombre;
|
|
ws.Cell(row, 3).Value = valor;
|
|
ws.Cell(row, 4).Value = aplicado;
|
|
ws.Cell(row, 5).Value = acumulado;
|
|
|
|
// Formato numérico a columnas de dinero
|
|
ws.Cell(row, 3).Style.NumberFormat.Format = "#,##0.00";
|
|
ws.Cell(row, 4).Style.NumberFormat.Format = "#,##0.00";
|
|
ws.Cell(row, 5).Style.NumberFormat.Format = "#,##0.00";
|
|
|
|
// Color especial si CveTipo = 0
|
|
if (cveTipo == 0)
|
|
{
|
|
var range = ws.Range(row, 1, row, 5);
|
|
range.Style.Fill.BackgroundColor = XLColor.FromArgb(221, 221, 221);
|
|
range.Style.Font.Bold = true;
|
|
}
|
|
|
|
row++;
|
|
}
|
|
|
|
// Ajustar columnas al contenido
|
|
ws.Columns().AdjustToContents();
|
|
|
|
// Exportar el archivo
|
|
using (MemoryStream ms = new MemoryStream())
|
|
{
|
|
wb.SaveAs(ms);
|
|
Response.Clear();
|
|
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
Response.AddHeader("content-disposition", "attachment;filename=Movimietnospermanenetea.xlsx");
|
|
Response.BinaryWrite(ms.ToArray());
|
|
Response.End();
|
|
}
|
|
}
|
|
}
|
|
|
|
} |