328 lines
14 KiB
C#
328 lines
14 KiB
C#
using Extensiones;
|
|
using iText.Html2pdf.Attach.Impl.Layout.Form.Element;
|
|
using Microsoft.Extensions.Primitives;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
public partial class Nomina_ReporteVacaciones : ClsPaginas
|
|
{
|
|
#region "Propiedades"
|
|
protected int FiltCveProyecto
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["FiltCveProyecto"] == null) { return -1; }
|
|
else { return ViewState["FiltCveProyecto"].ToString().ToEntero(); }
|
|
}
|
|
|
|
set { ViewState["FiltCveProyecto"] = value; }
|
|
}
|
|
protected int FiltCveSubProyecto
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["FiltCveSubProyecto"] == null) { return -1; }
|
|
else { return ViewState["FiltCveSubProyecto"].ToString().ToEntero(); }
|
|
}
|
|
|
|
set { ViewState["FiltCveSubProyecto"] = value; }
|
|
}
|
|
protected string FiltFechaInicio
|
|
{
|
|
get
|
|
{
|
|
string fecha = $"{DateTime.Now.Year - 1}-01-01";
|
|
if (ViewState["FiltFechaInicio"] == null) { return fecha; }
|
|
else { return ViewState["FiltFechaInicio"].ToString(); }
|
|
}
|
|
|
|
set { ViewState["FiltFechaInicio"] = value; }
|
|
}
|
|
protected string FiltFechaFin
|
|
{
|
|
get
|
|
{
|
|
string fecha = $"{DateTime.Now.Year}-12-31";
|
|
if (ViewState["FiltFechaFin"] == null) { return fecha; }
|
|
else { return ViewState["FiltFechaFin"].ToString(); }
|
|
}
|
|
|
|
set { ViewState["FiltFechaFin"] = value; }
|
|
}
|
|
|
|
|
|
protected DataTable tabladias
|
|
{
|
|
get
|
|
{
|
|
if (ViewState["tabladias"] == null) { return new DataTable(); }
|
|
else { return (DataTable)ViewState["tabladias"]; }
|
|
}
|
|
|
|
set { ViewState["tabladias"] = value; }
|
|
}
|
|
#endregion
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
TxtRpdFechaInicio.Text = $"{FiltFechaInicio.ToDateTime():dd/MM/yyyy}";
|
|
TxtRpdFechaFin.Text = $"{FiltFechaFin.ToDateTime():dd/MM/yyyy}";
|
|
CargarCentrosDeCosto(DdlProyecto, DdlSubProyecto, LblProyecto, LblSubProyeccto);
|
|
divddlproyeto.Visible = DdlProyecto.Visible;
|
|
getinfo();
|
|
}
|
|
}
|
|
public void getinfo()
|
|
{
|
|
using (ClsNominas objnom = new ClsNominas())
|
|
{
|
|
if (objnom.ReporteVacacionesCalendario(FiltCveProyecto, FiltCveSubProyecto, UsuarioActual.CveEmpresa, FiltFechaInicio, FiltFechaFin))
|
|
{
|
|
DataTable tabla1 = objnom.DTSetResultados.Tables[0]; //
|
|
DataTable tabla2 = objnom.DTSetResultados.Tables[1]; //
|
|
DataTable tabla3 = objnom.DTSetResultados.Tables[2]; //
|
|
tabladias = objnom.DTSetResultados.Tables[3];
|
|
DataTable tabladiasPersonal = objnom.DTSetResultados.Tables[4];
|
|
RepeaterEjerciciosH1.DataSource = tabla3;
|
|
RepeaterEjerciciosH2.DataSource = tabla3;
|
|
RepeaterEjerciciosH1.DataBind();
|
|
RepeaterEjerciciosH2.DataBind();
|
|
// Convertir Tabla 1 a Enumerable con un campo extra
|
|
List<Registro> resultado = tabla1.AsEnumerable().Select(row1 =>
|
|
{
|
|
int cvePersonal = Convert.ToInt32(row1["CvePersonal"]);
|
|
DataRow[] filasFiltradas = tabladiasPersonal.Select($"CvePersonal = {cvePersonal}");
|
|
|
|
// Crear un nuevo DataTable con la misma estructura
|
|
DataTable TDiaspersonal = tabladiasPersonal.Clone();
|
|
|
|
// Importar las filas filtradas
|
|
foreach (DataRow fila in filasFiltradas)
|
|
{
|
|
TDiaspersonal.ImportRow(fila);
|
|
//DataRow nuevaFila = TDiaspersonal.NewRow();
|
|
|
|
//// Copiar manualmente cada columna
|
|
//foreach (DataColumn columna in tabladiasPersonal.Columns)
|
|
//{
|
|
// nuevaFila[columna.ColumnName] = fila[columna.ColumnName];
|
|
//}
|
|
|
|
//TDiaspersonal.Rows.Add(nuevaFila);
|
|
}
|
|
TDiaspersonal.AcceptChanges();
|
|
//DataTable TDiaspersonal = tabladiasPersonal.FiltraParametros(string.Format("CvePersonal = '{0}'", row1["CvePersonal"]));
|
|
int contador = tabladiasPersonal.Rows.Count;
|
|
return new Registro()
|
|
{
|
|
CvePersonal = row1.Field<int>("CvePersonal"),
|
|
Codigo = row1.Field<string>("Codigo"),
|
|
NombreCompleto = row1.Field<string>("NombreCompleto"),
|
|
//FechaFin = (row1("FechaFin")).ToString().,
|
|
FechaInicio = row1.Field<DateTime>("FechaInicio"),
|
|
FechaAntiguedad = row1.Field<DateTime>("FechaAntiguedad"),
|
|
Antiguedad = row1.Field<int>("Antiguedad"),
|
|
|
|
ColumnasinicioFin = strColumnasinicioFin(tabladias, tabla2.FiltraParametros(string.Format("CvePersonal = {0}", row1["CvePersonal"])), row1["anio"].ToString().ToEntero(), row1["Mes"].ToString(), row1["Dia"].ToString()),
|
|
ColumnasVacaciones = strColumnasVacaciones(tabladias, TDiaspersonal),
|
|
// Campo extra: Enumerable para cada Ejercicio de Tabla 3
|
|
Ejercicios = tabla3.AsEnumerable().Select(row3 =>
|
|
{
|
|
var ejercicio = row3.Field<int>("Ejercicio");
|
|
|
|
// Buscar en Tabla 2 si existe el registro para CvePersonal y Ejercicio
|
|
var registro = tabla2.AsEnumerable().FirstOrDefault(row2 =>
|
|
row2.Field<int>("CvePersonal") == row1.Field<int>("CvePersonal") &&
|
|
row2.Field<int>("EJercicio") == ejercicio);
|
|
|
|
// Si no existe, crear un nuevo registro
|
|
if (registro == null)
|
|
{
|
|
return new EjercicioInfo()
|
|
{
|
|
Ejercicio = ejercicio,
|
|
FechaAntiguedad = row1.Field<DateTime>("FechaAntiguedad"),
|
|
Antiguedad = 0,
|
|
DiasVacaciones = 0, // Valor predeterminado
|
|
DiasPagados = 0, // Valor predeterminado
|
|
DiasDisfrutados = 0 // Valor predeterminado
|
|
};
|
|
}
|
|
else
|
|
{
|
|
// Si existe, devolver los datos de la Tabla 2
|
|
return new EjercicioInfo()
|
|
{
|
|
Ejercicio = registro.Field<int>("EJercicio"),
|
|
FechaAntiguedad = registro.Field<DateTime>("FechaAntiguedad"),
|
|
Antiguedad = registro.Field<int>("Antiguedad"),
|
|
DiasVacaciones = registro.Field<int>("DiasVacaciones"),
|
|
DiasPagados = registro.Field<int>("DiasPagados"),
|
|
DiasDisfrutados = registro.Field<int>("DiasDisfrutados")
|
|
};
|
|
}
|
|
}).ToList()
|
|
};
|
|
}
|
|
).ToList();
|
|
|
|
|
|
|
|
RepeaterPrincipal.DataSource = resultado;
|
|
RepeaterPrincipal.DataBind();
|
|
|
|
RepeaterPrincipalCalendar.DataSource = resultado;
|
|
RepeaterPrincipalCalendar.DataBind();
|
|
|
|
|
|
rptanio.DataSource = tabladias.FiltraParametros("MinEjercicio = 1");
|
|
rptanio.DataBind();
|
|
rptMeses.DataSource = tabladias.FiltraParametros("MinMes = 1");
|
|
rptMeses.DataBind();
|
|
RepetDias.DataSource = tabladias;
|
|
RepetDias.DataBind();
|
|
rptx.DataSource = tabladias;
|
|
rptx.DataBind();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
public string rightstr(string str,int cantidad)
|
|
{
|
|
return str.Length >= cantidad ? str.Substring(str.Length - cantidad) : str;
|
|
}
|
|
public string strColumnasinicioFin(DataTable tabladias, DataTable TEjercicio, int anio, string Mes, string Dia)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
StringBuilder strbuilderB = new StringBuilder();
|
|
strbuilderB.AppendFormat(" </tr><tr>");
|
|
int FechaNum =string.Format("{0}{1}{2}", anio, Mes, Dia).ToEntero();
|
|
int Mesdia =string.Format("{0}{1}", Mes, Dia).ToEntero();
|
|
foreach (DataRow dr in tabladias.Rows)
|
|
{
|
|
int colspan = dr["DiasMes"].ToString().ToEntero();
|
|
int mesidias = rightstr(dr["FechaNum"].ToString(),4).ToEntero();
|
|
int mesa = dr["Mes"].ToString().ToEntero();
|
|
int ania = dr["Anio"].ToString().ToEntero()-(mesidias >= Mesdia?0:1);
|
|
DataRow hdrow = TEjercicio.FiltroPrimero(string.Format("Ejercicio = {0}", ania));
|
|
int drFechaNum = dr["FechaNum"].ToString().ToEntero();
|
|
string classtd = drFechaNum < FechaNum ? "": ((ania % 2) > 0 ? "yearclass" : "yearclassB");
|
|
string antiguedad = "";
|
|
string classvac = "borderleft";
|
|
string vacacionestomadas = "";
|
|
if(hdrow != null)
|
|
{
|
|
antiguedad = string.Format("({0})", hdrow["Antiguedad"]);
|
|
//DiasVacaciones EJercicio EJercicioVac DiasPagados DiasDisfrutados
|
|
int DiasVacaciones = hdrow["DiasVacaciones"].ToString().ToEntero();
|
|
int DiasPagados = hdrow["DiasPagados"].ToString().ToEntero();
|
|
int DiasDisfrutados = hdrow["DiasDisfrutados"].ToString().ToEntero();
|
|
int mitadDiasVacaciones = DiasVacaciones / 2;
|
|
classvac = DiasDisfrutados > 0 ? (DiasDisfrutados > mitadDiasVacaciones ? (DiasDisfrutados >= DiasVacaciones ? "success" : "info") : "warning") : "danger";
|
|
vacacionestomadas = string.Format("{0}/{1}",DiasDisfrutados, DiasVacaciones);
|
|
}
|
|
if (dr["MinMes"].ToString() == "1" && Mesdia != mesidias)
|
|
{
|
|
if(mesa == Mes.ToEntero())
|
|
{
|
|
colspan = Dia.ToEntero() - 1;
|
|
}
|
|
string canio = drFechaNum >= FechaNum && colspan>5 ? (ania.ToString()) :"";
|
|
stringBuilder.AppendFormat("<td class='{2}' colspan='{0}'>{1} {3}</td>", colspan, canio, classtd, antiguedad);
|
|
strbuilderB.AppendFormat("<td class='{1}' colspan='{0}'>{2}</td>", colspan, classvac, vacacionestomadas);
|
|
}
|
|
if (mesidias == Mesdia)
|
|
{
|
|
string canio = drFechaNum >= FechaNum && colspan > 5 ? (ania.ToString()) : "";
|
|
if (mesa == Mes.ToEntero())
|
|
{
|
|
colspan = colspan-(Dia.ToEntero() - 1);
|
|
}
|
|
stringBuilder.AppendFormat("<td class='{2} borderyear' colspan='{0}'>{1} {3}</td>", colspan, canio, classtd, antiguedad);
|
|
strbuilderB.AppendFormat("<td class='{1}' colspan='{0}'>{2}</td>", colspan, classvac, vacacionestomadas);
|
|
}
|
|
}
|
|
stringBuilder.AppendFormat("{0}", strbuilderB.ToString());
|
|
return stringBuilder.ToString();
|
|
}
|
|
public string strColumnasVacaciones(DataTable tabladias, DataTable TDiaspersonal)
|
|
{
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
foreach (DataRow dr in tabladias.Rows)
|
|
{
|
|
|
|
DataRow hdr = TDiaspersonal.FiltroPrimero(string.Format("FechaNum={0}", dr["FechaNum"]));
|
|
if (hdr != null)
|
|
{
|
|
if (hdr["InicioM"].ToString() == "1")
|
|
{
|
|
stringBuilder.AppendFormat("<td class='VacClass{1}' colspan='{0}'></td>", hdr["DiasMesAnio"], (dr["MinMes"].ToString() == "1" ? " borderleft " : ""));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (TDiaspersonal.FiltroPrimero(string.Format("Anio={0} AND Mes ={1}", dr["Anio"], dr["Mes"])) != null)
|
|
{
|
|
stringBuilder.AppendFormat("<td class='{0}'></td>", (dr["MinMes"].ToString() == "1" ? " borderleft " : ""));
|
|
}
|
|
else
|
|
{
|
|
if (dr["MinMes"].ToString() == "1")
|
|
{
|
|
|
|
stringBuilder.AppendFormat("<td class='borderleft' colspan='{0}'></td>", dr["DiasMes"]);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
return stringBuilder.ToString();
|
|
}
|
|
public string columnapersonal(int dia, DataTable TDiaspersonal)
|
|
{
|
|
return string.Format("<td></td>");
|
|
}
|
|
|
|
|
|
|
|
protected void LnkConsultar_Click(object sender, EventArgs e)
|
|
{
|
|
FiltFechaInicio = $"{TxtRpdFechaInicio.Text.ToDateTime():yyyy-MM-dd}";
|
|
FiltFechaFin = $"{TxtRpdFechaFin.Text.ToDateTime():yyyy-MM-dd}";
|
|
getinfo();
|
|
}
|
|
}
|
|
|
|
public class Registro
|
|
{
|
|
public int CvePersonal { get; set; }
|
|
public string Codigo { get; set; }
|
|
public string NombreCompleto { get; set; }
|
|
public DateTime FechaInicio { get; set; }
|
|
public DateTime FechaFin { get; set; }
|
|
public DateTime FechaAntiguedad { get; set; }
|
|
public int Antiguedad { get; set; }
|
|
public List<EjercicioInfo> Ejercicios { get; set; }
|
|
//public DataTable TDiaspersonal { get; set; }
|
|
public string ColumnasinicioFin { get; set; }
|
|
public string ColumnasVacaciones { get; set; }
|
|
}
|
|
|
|
public class EjercicioInfo
|
|
{
|
|
public int Ejercicio { get; set; }
|
|
public DateTime FechaAntiguedad { get; set; }
|
|
public int Antiguedad { get; set; }
|
|
public int DiasVacaciones { get; set; }
|
|
public int DiasPagados { get; set; }
|
|
public int DiasDisfrutados { get; set; }
|
|
} |