diff --git a/RH/CalculoSBC.aspx b/RH/CalculoSBC.aspx index 63b3a9af1..ed40d0ff9 100644 --- a/RH/CalculoSBC.aspx +++ b/RH/CalculoSBC.aspx @@ -28,9 +28,6 @@
  • Descargar
  • -
  • - Formato carga masiva -
  • Carga masiva
  • @@ -46,7 +43,6 @@ - <%-- --%> @@ -203,7 +199,8 @@ Salario -
    SUA +
    + SUA
    @@ -839,7 +836,7 @@ - + - + + + diff --git a/RH/CalculoSBC.aspx.cs b/RH/CalculoSBC.aspx.cs index 95bc6b0d9..66359a12a 100644 --- a/RH/CalculoSBC.aspx.cs +++ b/RH/CalculoSBC.aspx.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; +using System.Net.Http.Headers; using System.Text; using System.Web; using System.Web.UI; @@ -237,12 +238,92 @@ public partial class RH_CalculoSBC : ClsPaginas UpCargarm.Update(); RegistraScript("$('#DmodalCargaMasiva').modal();"); } + protected void LnkFormatocMasivaRegistroPatronal_Click(object sender, EventArgs e) + { + try + { + bool continuar = true; + string msgerror = ""; + if (dtsalario == null || dtsalario.Rows.Count == 0) + { + msgerror = "favor de calcular primero"; + continuar = false; + } + if (continuar) + { + + ClosedXML.Excel.XLWorkbook wb = new ClosedXML.Excel.XLWorkbook(); + + var libro = wb.AddWorksheet("Salario"); + int column = 1; + libro.Cell(1, column).Value = "Codigo"; + column++; + libro.Cell(1, column).Value = "Empleado"; + column++; + libro.Cell(1, column).Value = "RegistroPatronal"; + //column++; + //libro.Cell(1, column).Value = "SDI"; + libro.Row(1).CellsUsed().Style.Font.FontColor = ClosedXML.Excel.XLColor.White; + libro.Row(1).CellsUsed().Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189)); + + int Fila = 1; + foreach (DataRow erow in dtsalario.Rows) + { + Fila++; + column = 1; + libro.Cell(Fila, column).Value = string.Format("'{0}", erow["Codigo"]); + column++; + libro.Cell(Fila, column).Value = erow["Nombre"]; + + column++; + libro.Cell(Fila, column).Value = erow["RegistroPatronal"]; + //column++; + //////libro.Cell(Fila, column).Value = erow["SDI"]; + ////column++; + ////libro.Cell(Fila, column).Value = erow["SalarioVariable"]; + } + + libro.Columns().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}.xlsx", "Plantilla Salario ")); + Response.BinaryWrite(memoryStream.ToArray()); + Response.End(); + } + else + { + Alert(msgerror, TipoMensaje.MsgAdvertencia); + } + } + catch (Exception ex) + { + Alert("Ocurrio un error al generar el Formato de nominas" + ex.ToString(), TipoMensaje.MsgAdvertencia); + } + } protected void LnkFormatocMasiva_Click(object sender, EventArgs e) { try { bool continuar = true; string msgerror = ""; + if (dtsalario == null || dtsalario.Rows.Count == 0) + { + msgerror = "favor de calcular primero"; + continuar = false; + } if (continuar) { @@ -274,8 +355,8 @@ public partial class RH_CalculoSBC : ClsPaginas column++; libro.Cell(Fila, column).Value = erow["SalarioDiario"]; - column++; - libro.Cell(Fila, column).Value = erow["SDI"]; + //column++; + //libro.Cell(Fila, column).Value = erow["SDI"]; column++; libro.Cell(Fila, column).Value = erow["SalarioVariable"]; } @@ -313,24 +394,26 @@ public partial class RH_CalculoSBC : ClsPaginas protected void LnkProcesarArchvo_Click(object sender, EventArgs e) { - DataTable dttempsalario = null; - using (ClsNominas objnom = new ClsNominas()) + if (ddltipoCarga.SelectedValue.ToEntero() == 1) { - if (objnom.GetCalculoSBC(UsuarioActual.CveEmpresa, DdlTipo.SelectedValue.ToEntero(), txtfechacargamasiva.Text, DdlRegistroPatronal.SelectedValue.ToEntero())) - { - dttempsalario = objnom.DTSetResultados.Tables[0]; - } - } - try - { - List Filesgral = TxtArchivoNomina.getfiles().Archivos; - Archivo fileItem = Filesgral.Count > 0 ? Filesgral[0] : null; - DataTable DTEXcel = Extensiones.ModExtensiones.ReadExcelFile(fileItem.FileUrl, true); - StringBuilder str = new StringBuilder(); - bool rollback = false; - using (ClsRH objpersonal = new ClsRH()) + DataTable dttempsalario = null; + using (ClsNominas objnom = new ClsNominas()) { + if (objnom.GetCalculoSBC(UsuarioActual.CveEmpresa, DdlTipo.SelectedValue.ToEntero(), txtfechacargamasiva.Text, DdlRegistroPatronal.SelectedValue.ToEntero())) + { + dttempsalario = objnom.DTSetResultados.Tables[0]; + } + } + try + { + List Filesgral = TxtArchivoNomina.getfiles().Archivos; + Archivo fileItem = Filesgral.Count > 0 ? Filesgral[0] : null; + DataTable DTEXcel = Extensiones.ModExtensiones.ReadExcelFile(fileItem.FileUrl, true); + + StringBuilder str = new StringBuilder(); + bool rollback = false; + using (ClsRH objpersonal = new ClsRH()) using (ClsNominas objNomina = new ClsNominas(objpersonal.IniciaTransacSQL())) { @@ -380,10 +463,50 @@ public partial class RH_CalculoSBC : ClsPaginas } } } - } - catch (Exception) { } + catch (Exception) { } - RegistraScript("$('#ModalDoctos').modal('hide');"); + } + if (ddltipoCarga.SelectedValue.ToEntero() == 2) + { + + List Filesgral = TxtArchivoNomina.getfiles().Archivos; + Archivo fileItem = Filesgral.Count > 0 ? Filesgral[0] : null; + DataTable DTEXcel = Extensiones.ModExtensiones.ReadExcelFile(fileItem.FileUrl, true); + + StringBuilder str = new StringBuilder(); + bool rollback = false; + using (ClsClaseBase objNomina = new ClsClaseBase( )) + using (ClsRH objpersonal = new ClsRH()) + { + + foreach (DataRow row in DTEXcel.FiltraParametros("LEN(Codigo)>0 ").Rows) + { + string Codigo = row["Codigo"].ToString(); + int CvePersonal = -1; // row["CvePersonal"].ToString().ToEntero(); + string RegistroPatronal = row["RegistroPatronal"].ToString() ; + int CveMetodoPago = 0; + if (Codigo != "-1" && objpersonal.GetPersonal(CvePersonal, Codigo, "-1", "-1", "-1", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, "-1", -1, -1, -1, -1, -1, -1, "-1", "-1", "-1", "-1", UsuarioActual.CveEmpresa) && + objpersonal.DtResultados.Rows.Count == 1) + { + CvePersonal = objpersonal.CvePersonal; + CveMetodoPago = objpersonal.CveMetodoPago; + } + else + { + CvePersonal = 0; + str.AppendLine(string.Format("No se encontro el codigo {0}
    ", Codigo)); + } + if (CvePersonal > 0) + { + objNomina.runQuerystr(string.Format("EXEC PA_RH_PersonalRPUpdate {0},'{1}'", CvePersonal, RegistroPatronal)); + } + } + + + + } + } + RegistraScript("$('#DmodalCargaMasiva').modal('hide');"); } protected void LnkDownArchivosSua_Click(object sender, EventArgs e) {