using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Extensiones;
using Modelos;
using static Extensiones.ModExtensiones;
public partial class Nomina_Finiquito : ClsPaginas
{
#region Propiedades
private int CvePersonal
{
get { return ViewState["CvePersonal"] != null ? ViewState["CvePersonal"].ToString().ToEntero() : 0; }
//set { ViewState["CvePersonal"] = value; }
}
private bool esSimulacion
{
get { return ViewState["esSimulacion"] != null ? (bool)ViewState["esSimulacion"] : false; }
set { ViewState["esSimulacion"] = value; }
}
private bool NominaAutorizada
{
get { return ViewState["NominaAutorizada"] != null ? (bool)ViewState["NominaAutorizada"] : false; }
set { ViewState["NominaAutorizada"] = value; }
}
private int CvePersonalAltas
{
get { return ViewState["CvePersonalAltas"] != null ? ViewState["CvePersonalAltas"].ToString().ToEntero() : 0; }
set { ViewState["CvePersonalAltas"] = value; }
}
private int CvePeriodoIndemnizacion
{
get { return ViewState["CvePeriodoIndemnizacion"] != null ? ViewState["CvePeriodoIndemnizacion"].ToString().ToEntero() : 0; }
set { ViewState["CvePeriodoIndemnizacion"] = value; }
}
private int CvePeriodoFiniquito
{
get { return ViewState["CvePeriodoFiniquito"] != null ? ViewState["CvePeriodoFiniquito"].ToString().ToEntero() : 0; }
set { ViewState["CvePeriodoFiniquito"] = value; }
}
private DateTime FechaInicio
{
get { return ViewState["FechaInicio"] != null ? (DateTime)ViewState["FechaInicio"] : NowADS(); }
set { ViewState["FechaInicio"] = value; }
}
private DataTable DtAltas
{
get { return ViewState["DtAltas"] != null ? (DataTable)ViewState["DtAltas"] : null; }
set { ViewState["DtAltas"] = value; }
}
private DataTable dtConceptos
{
get
{
if (ViewState["dtConceptos"] == null) { return null; }
else { return (DataTable)ViewState["dtConceptos"]; }
}
set { ViewState["dtConceptos"] = value; }
}
private DataTable dtempleadosConceptos
{
get
{
if (ViewState["dtempleadosConceptos"] == null) { return null; }
else { return (DataTable)ViewState["dtempleadosConceptos"]; }
}
set { ViewState["dtempleadosConceptos"] = value; }
}
private DataTable dtempleados
{
get
{
if (ViewState["dtempleados"] == null) { return null; }
else { return (DataTable)ViewState["dtempleados"]; }
}
set { ViewState["dtempleados"] = value; }
}
private DataTable dtConceptosIndemnizacion
{
get
{
if (ViewState["dtConceptosIndemnizacion"] == null) { return null; }
else { return (DataTable)ViewState["dtConceptosIndemnizacion"]; }
}
set { ViewState["dtConceptosIndemnizacion"] = value; }
}
private DataTable dtempleadosConceptosIndemnizacion
{
get
{
if (ViewState["dtempleadosConceptosIndemnizacion"] == null) { return null; }
else { return (DataTable)ViewState["dtempleadosConceptosIndemnizacion"]; }
}
set { ViewState["dtempleadosConceptosIndemnizacion"] = value; }
}
private DataTable dtempleadosIndemnizacion
{
get
{
if (ViewState["dtempleadosIndemnizacion"] == null) { return null; }
else { return (DataTable)ViewState["dtempleadosIndemnizacion"]; }
}
set { ViewState["dtempleadosIndemnizacion"] = value; }
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GvFinOrdinario.DataSource = new DataTable();
GVFinIndemnizacion.DataSource = new DataTable();
GvFinOrdinario.DataBind();
GVFinIndemnizacion.DataBind();
if (Request["CvePersonal"] != null && Request["CvePersonal"].ToString().ToEntero() > 0)
{
ViewState["CvePersonal"] = Request["CvePersonal"].ToString().ToEntero();
HypCodigo.NavigateUrl = $"/RH/Personal.aspx?CvePersonal={CvePersonal}";
HypEmpleado.NavigateUrl = $"/RH/Personal.aspx?CvePersonal={CvePersonal}";
CargaMotivoBaja();
CargaPersonal();
LnkFormatoRenuncia.Visible = true;
}
else
{
CargaDdlPersonal();
ViewState["CvePersonal"] = -1;
LtlEmpleadoCancelar.Visible = false;
RegistraScript("$('#ModalEmpleados').modal();");
LnkFormatoRenuncia.Visible = false;
LnkSimular.Visible = false;
LnkCancelar.Visible = false;
LnkGuardarDatos.Visible = false;
}
gconceptos.Visible = ChkesLiquidacion.Checked;
}
}
protected void ChkesLiquidacion_CheckedChanged(object sender, EventArgs e)
{
gconceptos.Visible = ChkesLiquidacion.Checked;
}
private void CargaMotivoBaja()
{
DdlMotivoBaja.DataSource = get_GlobalDTMotivoBaja(UsuarioActual.CveEmpresa);
DdlMotivoBaja.DataBind();
}
private void CargaDdlPersonal()
{
using (ClsRH ObjPersonal = new ClsRH())
{
if (ObjPersonal.GetPersonal(-1, UsuarioActual.CveEmpresa))
{
DdlPersonal.DataSource = ObjPersonal.DtResultados;
DdlPersonal.DataBind();
}
}
}
private void CargaPersonal()
{
LnkFormatoRenuncia.Visible = false;
LnkCancelar.Visible = false;
using (ClsRH ObjPersonal = new ClsRH())
{
if (ObjPersonal.GetPersonal(CvePersonal, UsuarioActual.CveEmpresa) && ObjPersonal.DtResultados.Rows.Count > 0)
{
DataRow drow = ObjPersonal.DtResultados.Rows[0];
HypCodigo.Text = drow["Codigo"].ToString();
HypEmpleado.Text = drow["NombreCompleto"].ToString();
LtlSFTipoSalario.Text = drow["TipodeSalario"].ToString();
HypCodigo.NavigateUrl = $"/RH/Personal.aspx?CvePersonal={drow["CvePersonal"]}";
LblPuesto.Text = drow["Puesto"].ToString();
LblSalario.Text = drow["SalarioDiario"].ToString();
LtlAreaGeografica.Text = drow["AreaGeografica"].ToString();
if (ObjPersonal.GetPersonalAltas(CvePersonal) && ObjPersonal.DtResultados.Rows.Count > 0)
{
DtAltas = ObjPersonal.DtResultados.FiltraParametros("", "FechaInicio");
DataRow da = ObjPersonal.DtResultados.Rows[0];
CvePersonalAltas = da["CvePersonalAltas"].ToString().ToEntero();
LblFechaAlta.Text = string.Format("{0:dd/MM/yyyy}", da["FechaInicio"]);
FechaInicio = LblFechaAlta.Text.ToDateTime();
TxtObservaciones.Text = da["Observaciones"].ToString();
TxtFechaBaja.Text = string.Format("{0:dd/MM/yyyy}", da["FechaFin"]);
if (da["CveMotivoBaja"].ToString() == "")
{
chkIndemnizacion.Checked = true;
chkSeparacionUnica.Checked = true;
chkPrimaantiguedad.Checked = true;
}
else
{
chkIndemnizacion.Checked = da["ValIndemnizacion"].ToString().ToUpper().Contiene(new string[] { "1", "TRUE" });
chkSeparacionUnica.Checked = da["ValSeparacionunica"].ToString().ToUpper().Contiene(new string[] { "1", "TRUE" });
chkPrimaantiguedad.Checked = da["ValPrimadeantiguedad"].ToString().ToUpper().Contiene(new string[] { "1", "TRUE" });
}
DdlTipoPeriodo.SelectedValueExist(((da["CveTipoPeriodo"]).ToString() == "6" ? "-2" : "-1"));
DdlMotivoBaja.SelectedValueExist(da["CveMotivoBaja"]);
TxtSalarioMinimo.Text = $"{da["SalarioMinimo"]:N2}";
ChkesLiquidacion.Checked = (da["esLiquidacion"].ToString() == "1" || da["esLiquidacion"].ToString().ToUpper() == "TRUE");
CvePeriodoIndemnizacion = da["CvePeriodoIndemnizacion"].ToString().ToEntero();
CvePeriodoFiniquito = da["CvePeriodoFiniquito"].ToString().ToEntero();
if (CvePeriodoFiniquito > 0)
{
LnkCancelar.Visible = true;
LnkSimular.Visible = false;
using (ClsNominas onom = new ClsNominas())
{
loadsobrerecibo(onom);
}
if (da["Autorizado"].ToString().ToEntero() == 1)
{
LnkAutorizar.Visible = false;
LnkTimbrar.Visible = true;
LnkGuardarDatos.Enabled = false;
LnkGuardarDatos.CssClass = "btn btn-default";
LnkGuardarDatos.ToolTip = "el finiquito ha sido capturado.";
}
if (da["SeTimbro"].ToString().ToEntero() == 1)
{
LnkAutorizar.Visible = false;
LnkTimbrar.Visible = false;
LnkGuardarDatos.Enabled = false;
LnkGuardarDatos.CssClass = "btn btn-default";
LnkGuardarDatos.ToolTip = "el finiquito ha sido capturado.";
}
UpAcciones.Update();
}
}
CamposCalculados();
}
}
}
protected void LnkCampiarEmpleado_Click(object sender, EventArgs e)
{
Response.Redirect($"/Nomina/Finiquito.aspx?CvePersonal={DdlPersonal.SelectedValue}");
}
private void CamposCalculados()
{
//TxtSalarioMinimo.Text = "123.22";
if (TxtFechaBaja.Text.Length > 9)
{
DateTime fechafin = TxtFechaBaja.Text.ToDateTime();
DateTime fechaalta = LblFechaAlta.Text.ToDateTime();
int diasanio = fechafin.DayOfYear;
if (fechafin.Year == fechaalta.Year)
{
diasanio = diasanio - fechaalta.DayOfYear;
}
decimal antiguedad = getyearsresult(fechafin, FechaInicio);
TxtAntiguedad.Text = string.Format("{0:##0.00###}", antiguedad);
TxtDiasTransAnio.Text = string.Format("{0}", diasanio);
}
else
{
TxtAntiguedad.Text = "--";
TxtDiasTransAnio.Text = "--";
}
}
private decimal getyearsresult(DateTime fechafin, DateTime fechainicio)
{
decimal retorno = 0;
decimal mes = 12;
retorno = (fechafin.Year - fechainicio.Year) - (fechafin.Month > fechainicio.Month ? 0 : (fechafin.Month == fechainicio.Month && fechafin.Day > fechainicio.Day ? 0 : 1));
retorno += (((fechafin.Month == fechainicio.Month && fechafin.Day > fechainicio.Day ? fechainicio.Month : fechafin.Month + (fechafin.Month > fechainicio.Month ? 0 : 12)) - fechainicio.Month) / mes);
/* DateTime zeroTime = new DateTime(1, 1, 1);
TimeSpan span;
if (fechainicio < fechafin)
{
span = fechafin - fechainicio;
decimal years = (zeroTime + span).Year - 1;
retorno = Math.Round(years + (span.TotalDays.ToString().ToDecimal() / 365), 4);
}*/
return retorno;
}
protected void LnkImportexCalculo_Click(object sender, EventArgs e)
{
if (!esSimulacion && !NominaAutorizada)
{
int SRCveConcepto = ((LinkButton)sender).CommandArgument.ToEntero();
//CvePeriodoSeleccionado
//SRCvePersonal
if (SRCveConcepto > 0)
{
using (ClsNominas onom = new ClsNominas())
{
if (onom.DeleteNom_NominasDetalles(SRCveConcepto, CvePersonal, CvePeriodoFiniquito))
{
Alert("el importe sera tomado del calculo y no del valor fijo");
loadsobrerecibo(onom);
UPDatos.Update();
}
}
}
}
else
{
if (esSimulacion)
{
Alert("No se puede eliminar una nomina en modo Simulación", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
else
{
Alert("No se puede eliminar una nomina autorizada", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
}
}
protected void LnkConcepto_Click(object sender, EventArgs e)
{
if (!esSimulacion && !NominaAutorizada)
{
int SRCveConcepto = ((LinkButton)sender).CommandArgument.ToEntero();
string SRTipoConcepto = ((LinkButton)sender).CommandArgument;
#region carga conceptos
DataTable dtCon;
if (SRCveConcepto > 0)
{
DataRow drow = dtConceptos.FiltroPrimero(string.Format("CveConcepto={0}", SRCveConcepto));
if (drow != null)
{
SRTipoConcepto = drow["Tipo"].ToString();
}
else
{
SRCveConcepto = 0;
SRTipoConcepto = "D";
}
}
if (SRTipoConcepto == "P")
{
dtCon = dtConceptos.FiltraParametros("Tipo ='P' AND EsPadre = 1 ").Copy(); //AND CveSistema <>12'
}
else
{
dtCon = dtConceptos.FiltraParametros("Tipo ='D' AND EsPadre = 1 ").Copy();
SRTipoConcepto = "D";
}
dtCon.Columns.Add(new DataColumn("CodigoConcepto"));
foreach (DataRow trow in dtCon.Rows)
{
trow["CodigoConcepto"] = string.Format("{0} - {1}", trow["Codigo"], trow["Concepto"]);
}
dtCon.AcceptChanges();
DataRow row = dtCon.NewRow();
row["CveConcepto"] = "-1";
row["CodigoConcepto"] = "Seleccione";
dtCon.Rows.InsertAt(row, 0);
#endregion
DdlmcConceptos.DataSource = dtCon;
DdlmcConceptos.DataBind();
if (SRCveConcepto > 0)
{
DdlmcConceptos.SelectedValueExist(SRCveConcepto);
}
//PnlConceptoPersonal.Visible = false;
DdlmcConceptos_SelectedIndexChanged(DdlmcConceptos, null);
RegistraScript(string.Format("$('#ModalUpConcepto').on('shown.bs.modal', function () {{$('#{0}').trigger('focus')}});$('#ModalUpConcepto').modal();", TxtmcImporte.ClientID));
UPpanelModalUpConcepto.Update();
}
else
{
if (esSimulacion)
{
Alert("No se puede editar una nomina en modo Simulación", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
else
{
Alert("No se puede editar una nomina autorizada", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
}
}
protected void DdlmcConceptos_SelectedIndexChanged(object sender, EventArgs e)
{
/*
int CveConcepto = DdlmcConceptos.SelectedValue.ToEntero();
TxtmcImporte.Text = "";
TxtmcImporteGrabado.Text = "";
Txtmcvalor.Text = "";
if (CveConcepto > 0)
{
DataRow drow = dtempleadosConceptos.FiltroPrimero(string.Format("CveConcepto={0} AND CvePersonal ={1}", CveConcepto, CvePersonal));
if (drow != null)
{
TxtmcImporte.Text = string.Format("{0:N2}", drow["Importe"]);
TxtmcImporteGrabado.Text = string.Format("{0:N2}", drow["ImporteGravado"]);
Txtmcvalor.Text = string.Format("{0:N2}", drow["Valor"]);
}
}
else
{
if (e != null)
{
Alert("Seleccione un concepto.", TipoMensaje.MsgAdvertencia);
}
}
UPpanelModalUpConcepto.Update();
*/
int CveConcepto = DdlmcConceptos.SelectedValue.ToEntero();
TxtmcImporte.Text = "";
TxtmcImporteGrabado.Text = "";
Txtmcvalor.Text = "";
ChkCalAutomaticoG.Checked = false;
ChkCalAutomatico.Checked = false;
ChkCalAutomaticoV.Checked = false;
if (CveConcepto > 0)
{
DataRow drow = dtempleadosConceptos.FiltroPrimero(string.Format("CveConcepto={0} AND CvePersonal ={1}", CveConcepto, CvePersonal));
if (drow != null)
{
int TipoCalculo = drow["Estatus"].ToString().ToEntero();
ChkCalAutomaticoG.Checked = true;
ChkCalAutomatico.Checked = true;
ChkCalAutomaticoV.Checked = true;
if (TipoCalculo >= 5)
{
TipoCalculo -= 5;
ChkCalAutomaticoG.Checked = false;
}
if (TipoCalculo >= 3)
{
TipoCalculo -= 3;
ChkCalAutomatico.Checked = false;
}
if (TipoCalculo >= 1)
{
ChkCalAutomaticoV.Checked = false;
}
TxtmcImporte.Text = string.Format("{0:N2}", drow["Importe"]);
TxtmcImporteGrabado.Text = string.Format("{0:N2}", drow["ImporteGravado"]);
Txtmcvalor.Text = string.Format("{0:N2}", drow["Valor"]);
}
else
{
ChkCalAutomaticoV.Checked = true;
ChkCalAutomaticoG.Checked = true;
}
}
else
{
if (e != null)
{
Alert("Seleccione un concepto.", TipoMensaje.MsgAdvertencia);
}
}
UPpanelModalUpConcepto.Update();
ChkCalAutomaticoV_CheckedChanged(ChkCalAutomaticoV, null);
ChkCalAutomatico_CheckedChanged(ChkCalAutomatico, null);
ChkCalAutomaticoG_CheckedChanged(ChkCalAutomaticoG, null);
}
protected void ChkCalAutomaticoV_CheckedChanged(object sender, EventArgs e)
{
Txtmcvalor.Enabled = !ChkCalAutomaticoV.Checked;
}
protected void ChkCalAutomatico_CheckedChanged(object sender, EventArgs e)
{
TxtmcImporte.Enabled = !ChkCalAutomatico.Checked;
}
protected void ChkCalAutomaticoG_CheckedChanged(object sender, EventArgs e)
{
TxtmcImporteGrabado.Enabled = !ChkCalAutomaticoG.Checked;
}
protected void BtnAceptarMC_Click(object sender, EventArgs e)
{
int chkImporte = ChkCalAutomatico.Checked ? 0 : 1;
int chkImporteGravado = ChkCalAutomaticoG.Checked ? 0 : 1;
int chkImporteValor = ChkCalAutomaticoV.Checked ? 0 : 1;
bool continuar = true;
int CveNomina = 0;
double Total = 0;
int CveMoneda = 1;
int CveMetodoPago = 0;
int CveConcepto = DdlmcConceptos.SelectedValue.ToEntero();
if (CveConcepto > 0 && CvePersonal > 0)
{
decimal ImporteConcepto = chkImporte == 1 ? TxtmcImporte.Text.Replace("$", "").Replace(",", "").ToDecimal() : 0;
decimal ImporteGravadoConcepto = ChkCalAutomaticoG.Checked ? 0.0m : TxtmcImporteGrabado.Text.Replace("$", "").Replace(",", "").ToDecimal();
decimal ImporteExentoConcepto = ImporteConcepto - ImporteGravadoConcepto;
decimal ImporteValor = Txtmcvalor.Text.Replace("$", "").Replace(",", "").ToDecimal();
using (ClsNominas objNomina = new ClsNominas())
{
objNomina.IniciaTransacSQL();
if (continuar)
{
if (objNomina.GetNom_Nominas(-1, CvePersonal, CvePeriodoFiniquito, -1, UsuarioActual.CveEmpresa))
{
if (objNomina.DtResultados.Rows.Count > 0)
{
CveNomina = objNomina.CveNomina;
}
else
{
if (objNomina.AddNom_Nominas(-1, 1, CvePersonal, CvePeriodoFiniquito, Total, 0, 0, Total, CveMoneda, 1, CveMetodoPago, NowADS(), "Deducciones nómina",
"", "", "", "", 0, 0, 0, new DateTime(), new DateTime(), new DateTime(), UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, false))
{
CveNomina = objNomina.CveNomina;
}
else
{
continuar = false;
}
}
}
}
if (CveNomina == 0)
{
continuar = false;
}
if (continuar)
{
if (continuar)
{
if (!objNomina.AddUPNom_NominasDetalles(CveNomina, CvePeriodoFiniquito, CvePersonal, CveConcepto, ImporteConcepto, ImporteGravadoConcepto, ImporteExentoConcepto, ImporteValor, UsuarioActual.CveUsuario, true, chkImporte, chkImporteGravado, chkImporteValor))
{
continuar = false;
}
}
}
if (continuar)
{ objNomina.Commit(); }
else
{
objNomina.RollBack();
}
}
if (continuar)
{
using (ClsNominas objNomina = new ClsNominas())
{
loadsobrerecibo(objNomina);
}
Alert("El cambio se ha guardado correctamente.");
}
}
else
{
if (CveConcepto > 0)
{
Alert("Debe seleccionar un empleado.", TipoMensaje.MsgAdvertencia);
}
else
{
Alert("Debe seleccionar un concepto.", TipoMensaje.MsgAdvertencia);
}
}
UPDatos.Update();
}
//int CveConceptoPolgvc, CveConceptoDolgvc;
//protected void GvConceptos_RowDataBound(object sender, GridViewRowEventArgs e)
//{
// if (e.Row.RowType == DataControlRowType.DataRow)
// {
// if (e.Row.RowIndex == 0)
// {
// CveConceptoPolgvc = 1;
// CveConceptoDolgvc = 1;
// }
// // Datakeys
// // Concepto,CveConcepto,Importe,Estatus,ConceptoD,CveConceptoD,ImporteD,EstatusD
// int CveConcepto = e.Row.DataKey("CveConceptoP").ToEntero();
// int CveConceptoD = e.Row.DataKey("CveConceptoD").ToEntero();
// // Dim Importe As Decimal = e.Row.DataKey("Importe").ToDecimal()
// // Dim ImporteD As Decimal = e.Row.DataKey("ImporteD").ToDecimal()
// int Estatus = e.Row.DataKey("EstatusP").ToEntero();
// int EstatusD = e.Row.DataKey("EstatusD").ToEntero();
// int isOnlyBisibleP = e.Row.DataKey("isOnlyBisibleP").ToEntero();
// int isOnlyBisibleD = e.Row.DataKey("isOnlyBisibleD").ToEntero();
// bool isEditedP = e.Row.DataKey("isEditedP").ToEntero() > 0;
// bool isEditedD = e.Row.DataKey("isEditedD").ToEntero() > 0;
// //isEditedD
// // Controles
// Label LtlConcepto = e.Row.FCLabel("LtlConcepto");
// LinkButton LnkConcepto = e.Row.FCLinkButton("LnkConcepto");
// Label LtlConceptoD = e.Row.FCLabel("LtlConceptoD");
// LinkButton LnkConceptoD = e.Row.FCLinkButton("LnkConceptod");
// Label LtlImporte = e.Row.FCLabel("LtlImporte");
// LinkButton LnkImporte = e.Row.FCLinkButton("LnkImporte");
// Label LtlImporteD = e.Row.FCLabel("LtlImporteD");
// LinkButton LnkImporteD = e.Row.FCLinkButton("LnkImporteD");
// //isEditedD
// if (isOnlyBisibleP == 1)
// {
// e.Row.CssClass = string.Format("{0} isOnlyBisibleP", e.Row.CssClass);
// }
// if (isOnlyBisibleD == 1)
// {
// e.Row.CssClass = string.Format("{0} isOnlyBisibleD", e.Row.CssClass);
// }
// if (isEditedP)
// {
// e.Row.CssClass = string.Format("{0} isEditedP", e.Row.CssClass);
// }
// if (isEditedD)
// {
// e.Row.CssClass = string.Format("{0} isEditedD", e.Row.CssClass);
// }
// if (Estatus == -1) { LtlConcepto.Visible = false; }
// else if (Estatus > 0) { LtlImporte.Visible = false; }
// if (EstatusD == -1) { LtlConceptoD.Visible = false; }
// else if (EstatusD > 0) { LtlImporteD.Visible = false; }
// LtlImporte.Visible = false;
// LtlImporteD.Visible = false;
// if (Estatus < -1 | EstatusD < -1)
// {
// e.Row.CssClass = "ConceptosTotales";
// LtlImporte.Visible = true;
// LtlImporteD.Visible = true;
// }
// LnkImporte.CommandArgument = (CveConcepto > 0 ? CveConcepto.ToString() : "P");
// LnkImporteD.CommandArgument = (CveConceptoD > 0 ? CveConceptoD.ToString() : "D");
// LnkImporte.Text = (CveConcepto > 0 ? string.Format("${0:N2}", e.Row.DataKey("ImporteP").ToDecimal()) : (CveConceptoPolgvc > 0 ? "" : ""));
// LnkImporteD.Text = (CveConceptoD > 0 ? string.Format("${0:N2}", e.Row.DataKey("ImporteD").ToDecimal()) : (CveConceptoDolgvc > 0 ? "" : ""));
// if (CveConcepto == 0 && (Estatus == 0 || Estatus == -1 || Estatus == -3)) { LtlImporte.Text = ""; }
// if (CveConceptoD == 0 && (EstatusD == 0 || EstatusD == -1)) { LtlImporteD.Text = ""; }
// LnkConcepto.Visible = !LtlConcepto.Visible;
// LnkConceptoD.Visible = !LtlConceptoD.Visible;
// LnkImporte.Visible = !LtlImporte.Visible;
// LnkImporteD.Visible = !LtlImporteD.Visible;
// CveConceptoPolgvc = CveConcepto;
// CveConceptoDolgvc = CveConceptoD;
// }
//}
protected void LnkCambiarEmpleado_Click(object sender, EventArgs e)
{
CargaDdlPersonal();
RegistraScript("$('#ModalEmpleados').modal();");
UpModalEmpleados.Update();
}
/*
private class NConcepto
{
public string NoConceptoP { get; set; }
public string ConceptoP { get; set; }
public string LabelValorP { get; set; }
public int CveConceptoP { get; set; }
public double ImporteP { get; set; }
public double ValorP { get; set; }
public int EstatusP { get; set; }
public int isEditedP { get; set; }
public int isOnlyBisibleP { get; set; }
public string NoConceptoD { get; set; }
public string ConceptoD { get; set; }
public string LabelValorD { get; set; }
public int CveConceptoD { get; set; }
public double ImporteD { get; set; }
public double ValorD { get; set; }
public int EstatusD { get; set; }
public int isEditedD { get; set; }
public int isOnlyBisibleD { get; set; }
}*/
protected void LnkGuardarDatos_Click(object sender, EventArgs e)
{
if (LblFechaAlta.Text.ToDate() > TxtFechaBaja.Text.ToDate())
{
Alert("la fecha de baja no puede ser menor a la fecha alta", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
else
{
bool continuar = true;
esSimulacion = false;
using (ClsRH ObjPersonal = new ClsRH())
using (ClsNominas onom = new ClsNominas(ObjPersonal.IniciaTransacSQL()))
{
onom.ValidaFechaFinPersonal(CvePersonal, UsuarioActual.CveEmpresa, TxtFechaBaja.Text.ToDateTime().ToString("yyyy/MM/dd"));
if (onom.DtResultados.Rows.Count > 0)
{
continuar = false;
StringBuilder strbuild = new StringBuilder();
strbuild.Append("No es posible guardar el finiquito ya que existen asistencias posteriores a la fecha fin con nominas autorizadas, es necesario desautorizar la siguientes nominas para reintentar el proceso.");
foreach (DataRow drow in onom.DtResultados.Rows)
{
strbuild.AppendFormat("
{0}", drow["PeriodoTexto"]);
}
Alert(strbuild.ToString(), TipoMensaje.MsgAdvertencia);
}
if (continuar && ObjPersonal.UpPersonalAltas(CvePersonal, UsuarioActual.CveUsuario, "", TxtFechaBaja.Text.ToDateTime().ToString("yyyy/MM/dd"), DdlTipoPeriodo.SelectedValue.ToEntero(), DdlMotivoBaja.SelectedValue.ToEntero(), ChkesLiquidacion.Checked, chkIndemnizacion.Checked, chkSeparacionUnica.Checked, chkPrimaantiguedad.Checked, TxtObservaciones.Text) && ObjPersonal.GetPersonalAltas(CvePersonal) && ObjPersonal.DtResultados.Rows.Count > 0)
{
DataRow da = ObjPersonal.DtResultados.Rows[0];
CvePeriodoIndemnizacion = da["CvePeriodoIndemnizacion"].ToString().ToEntero();
CvePeriodoFiniquito = da["CvePeriodoFiniquito"].ToString().ToEntero();
// Alert(string.Format("{0}: {1}", CvePeriodoIndemnizacion, CvePeriodoFiniquito));
}
else { continuar = false; }
if (continuar) { continuar = validaAutorizado(onom); }
if (continuar)
{
continuar = onom.GetFiniquitosPersonal(CvePersonal, UsuarioActual.CveEmpresa, diasindemnizacion: Txtdiasindemnizacion.Text.ToEntero());
}
if (continuar)
{
ObjPersonal.Commit();
}
else
{
ObjPersonal.RollBack();
}
if (continuar)
{ loadsobrerecibo(onom); LnkCancelar.Visible =!LnkAutorizar.Visible?false: true; LnkSimular.Visible = false; }
}
}
UPDatos.Update();
}
protected void LnkSimular_Click(object sender, EventArgs e)
{
if (LblFechaAlta.Text.ToDate() > TxtFechaBaja.Text.ToDate())
{
Alert("la fecha de baja no puede ser menor a la fecha alta", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
else
{
bool continuar = false;
esSimulacion = true;
using (ClsRH ObjPersonal = new ClsRH())
using (ClsNominas onom = new ClsNominas(ObjPersonal.IniciaTransacSQL()))
{
if (continuar = ObjPersonal.UpPersonalAltas(CvePersonal, UsuarioActual.CveUsuario, "", TxtFechaBaja.Text.ToDateTime().ToString("yyyy/MM/dd"), DdlTipoPeriodo.SelectedValue.ToEntero(), DdlMotivoBaja.SelectedValue.ToEntero(), ChkesLiquidacion.Checked, chkIndemnizacion.Checked, chkSeparacionUnica.Checked, chkPrimaantiguedad.Checked) && ObjPersonal.GetPersonalAltas(CvePersonal) && ObjPersonal.DtResultados.Rows.Count > 0)
{
DataRow da = ObjPersonal.DtResultados.Rows[0];
CvePeriodoIndemnizacion = da["CvePeriodoIndemnizacion"].ToString().ToEntero();
CvePeriodoFiniquito = da["CvePeriodoFiniquito"].ToString().ToEntero();
// Alert(string.Format("{0}: {1}", CvePeriodoIndemnizacion, CvePeriodoFiniquito));
}
else { continuar = false; }
if (continuar) { continuar = validaAutorizado(onom); }
if (continuar)
{
continuar = onom.GetFiniquitosPersonal(CvePersonal, UsuarioActual.CveEmpresa, diasindemnizacion: Txtdiasindemnizacion.Text.ToEntero());
if (onom.DtResultados.Rows.Count > 0)
{
DataRow drow = onom.DtResultados.Rows[0];
LnkShowFfiniquito.Text = string.Format("{0:##,###,###.00##}", drow["SalarioBC"]);
LtlSFSDI.Text = string.Format("
{0:##,###,###.00##}", drow["SDI"]);
LtlSFDias.Text = string.Format("{0:##,###,###}", drow["diasMesAnterior"]);
LtlSFPercepciones.Text = string.Format("{0:##,###,###.00##}", drow["TotalPercepciones"]);
LtlSFVar.Text = string.Format("(Percepciones /días)\r\n{0:##,###,###.00##}", drow["TotalPercepciones"].ToString().ToDecimal() / drow["diasMesAnterior"].ToString().ToDecimal());
LtlSF.Text = string.Format("Si((Tipo de salario ='Fijo'),SDI,(Salario Variable + SDI))\r\n{0:##,###,###.00##}", drow["SalarioBC"]);
}
GVSDF.DataSource = onom.DTSetResultados.Tables[1];
GVSDF.DataBind();
}
if (continuar)
{ loadsobrerecibo(onom); }
if (continuar)
{
ObjPersonal.RollBack();
}
else
{
ObjPersonal.RollBack();
}
}
}
UPDatos.Update();
}
public bool validaAutorizado(ClsNominas objnom)
{
bool validaAutorizado = false;
if (objnom.GetNominaEmpleado(-1, -1, -1, CvePeriodoFiniquito, UsuarioActual.CveEmpresa, 1, 3, CvePersonal, Neto: 1) && objnom.DTSetResultados.Tables.Count > 1)
{
validaAutorizado = (objnom.DTSetResultados.Tables[3].COUNT("CvePersonal", "NomAutorizado =1") > 0);
}
if (validaAutorizado)
{
Alert("No se puede calcular el finiquito en un periodo autorizado", ModExtensiones.TipoMensaje.MsgAdvertencia);
}
return !validaAutorizado;
}
public void loadsobrerecibo(ClsNominas objnom)
{
List