diff --git a/Nomina/Nomina.aspx b/Nomina/Nomina.aspx
index a5794bbb0..2e9214876 100644
--- a/Nomina/Nomina.aspx
+++ b/Nomina/Nomina.aspx
@@ -295,6 +295,9 @@
Recibos timbrados
+
+ Procesar archivo SUA EBA PDF
+
<%-- CancelarTimbre--%>
@@ -3305,6 +3308,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ cargar Archivos PDF
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Nomina/Nomina.aspx.cs b/Nomina/Nomina.aspx.cs
index 7f3deaf23..15a085477 100644
--- a/Nomina/Nomina.aspx.cs
+++ b/Nomina/Nomina.aspx.cs
@@ -11,6 +11,8 @@ using System.Web.UI;
using System.Web.UI.WebControls;
using static Extensiones.ModExtensiones;
using Modelos;
+using System.Text.RegularExpressions;
+using iTextSharp.text.pdf.parser;
public partial class Nomina_Nomina2 : ClsPaginas
{
@@ -94,7 +96,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
set { ViewState["dtempleados"] = value; }
}
#region "Empleados Conceptos"
-
+
private DataTable dtPerEmpleados
{
@@ -203,7 +205,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
set { ViewState["CveTipoTrabajador"] = value; }
}
-
+
protected int CvePeriodoSeleccionado
{
get
@@ -324,7 +326,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
DdlTipoTrabajador.SelectedValueExist("-1");
}
}
-
+
DataTable dtperinc = null;
using (ClsNominas objnom = new ClsNominas())
{
@@ -482,7 +484,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
}
private void CargaTiposPeriodo()
{
- DdlTipoPeriodo.DataSource = get_GlobalDTTipoPeriodos(UsuarioActual.CveEmpresa) ;
+ DdlTipoPeriodo.DataSource = get_GlobalDTTipoPeriodos(UsuarioActual.CveEmpresa);
DdlTipoPeriodoCM.DataSource = DdlTipoPeriodo.DataSource;
DdlTipoPeriodoSim.DataSource = DdlTipoPeriodo.DataSource;
DdlTipoPeriodoSim.DataBind();
@@ -558,20 +560,20 @@ public partial class Nomina_Nomina2 : ClsPaginas
LtlPeriodoseleccionadoASis.Text = LtlPeriodoseleccionado.Text;
}
- public void cargaDatos(bool cargaasistencia = true, int CvePersonal =-1)
+ public void cargaDatos(bool cargaasistencia = true, int CvePersonal = -1)
{
int Estatus = 0;
int CveEmpresa = UsuarioActual.CveEmpresa;
bool continuar = false;
- DataTable dtPeriodo =new DataTable();
+ DataTable dtPeriodo = new DataTable();
if (CvePersonal <= 0)
{
- CvePeriodoSeleccionado = 0;
+ CvePeriodoSeleccionado = 0;
dtempleados = null;
dtConceptos = null;
}
- LnkAutorizar.Visible = false;
+ LnkAutorizar.Visible = false;
Estatus = 5;
if (FiltCvePeriodo > 0)
{
@@ -614,9 +616,9 @@ public partial class Nomina_Nomina2 : ClsPaginas
LnkFormatoTabular.Visible = true;
LnkFormatoFiscal.Visible = (UsuarioActual.CveEmpresa == 141 || UsuarioActual.CveRol == 1);
HypPDFSTimbrados.Visible = true;
- if (objnom.GetNominaEmpleado(FiltCveProyecto, FiltCveSubProyecto, FiltCveTurno, FiltCvePeriodo, CveEmpresa, FiltAgrupador,
+ if (objnom.GetNominaEmpleado(FiltCveProyecto, FiltCveSubProyecto, FiltCveTurno, FiltCvePeriodo, CveEmpresa, FiltAgrupador,
DdlRegimenContratacion.SelectedValue.ToEntero(), CveTipoTrabajador: CveTipoTrabajador, Neto: ddlfiniquito.SelectedValue.ToEntero(),
- CvePersonal: CvePersonal)
+ CvePersonal: CvePersonal)
&& objnom.DTSetResultados.Tables.Count > 4)
{
if (CvePersonal > 0)
@@ -652,7 +654,8 @@ public partial class Nomina_Nomina2 : ClsPaginas
if (CvePersonal > 0)
{
}
- else {
+ else
+ {
#region CargaGrid
if (continuar)
{
@@ -1437,7 +1440,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
Msg = lognom.TimbrarNomina(CveNomina, CvePersonal, CvePeriodo, UsuarioActual, CvePAC: UsuarioActual.Empresa.CvePAC);
if (Msg != null && Msg.Length > 0)
- {
+ {
msggral = string.Format("{0}| {3} | {2} | {4}{1} |
", msggral, Msg, gvRow.DataKey("Nombre"), gvRow.DataKey("Codigo"), msgCorregidoSat(Msg, CvePersonal, RFC, CURP));
}
else
@@ -1851,7 +1854,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
protected void BtnCancelarDocumento_Click(object sender, EventArgs e)
{
int CveNomina = CveNominaCancelar;
-
+
if (CveNomina > 0)
{
@@ -2817,12 +2820,12 @@ public partial class Nomina_Nomina2 : ClsPaginas
//GridViewRow gvrow = (GridViewRow)(((LinkButton)sender).NamingContainer);
TxtVacDiasPago.Text = "0";
LnkSRVacacionesADD.Visible = false;
-
+
dtPerEmpleados = dtempleados.FiltraParametros(string.Format("CvePersonal = {0}", SRCvePersonal));
dtPerEmpleadosConceptos = dtempleadosConceptos.FiltraParametros(string.Format("CvePersonal = {0}", SRCvePersonal));
dtPerConceptos = dtConceptos;
dtPerPeriodo = dtPeriodos;
-
+
if (DdlCtaContable.Items.Count == 0)
@@ -2942,7 +2945,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
protected void LnkRecalcular_Click(object sender, EventArgs e)
{
- cargaDatos(CvePersonal:SRCvePersonal);
+ cargaDatos(CvePersonal: SRCvePersonal);
cargaBitacora();
cargasobrericiboconceptos(SRMostrarFormulas);
@@ -3686,7 +3689,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
if (continuar)
{
- cargaDatos(CvePersonal:SRCvePersonal);
+ cargaDatos(CvePersonal: SRCvePersonal);
cargasobrericiboconceptos(SRMostrarFormulas);
UpGvConceptos.Update();
@@ -3875,7 +3878,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
CvePersonal = DdlmcPersonal.SelectedValue.ToEntero();
}
int CveConcepto = DdlmcConceptos.SelectedValue.ToEntero();
- decimal ImporteConcepto = chkImporte==1? TxtmcImporte.Text.Replace("$", "").Replace(",", "").ToDecimal():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();
@@ -3964,7 +3967,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
private void mostrarConceptos()
{
#region "Llenado de datos empleado"
-
+
string DiasLaborados = "";
string DiasFaltados = "";
string DiasVacaciones = "";
@@ -4212,7 +4215,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
dtper.Columns.Add("BorradoLogico", typeof(int));
dtded.Columns.Add("BorradoLogico", typeof(int));
bool esfinperiodo = false;
- if(dtPerPeriodo.Rows.Count > 0)
+ if (dtPerPeriodo.Rows.Count > 0)
{
esfinperiodo = (dtPerPeriodo.Rows[0]["EsFinMes"].ToString().ToEntero() == 1);
}
@@ -4270,7 +4273,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
nConcepto.ImporteP = Importe;
nConcepto.ImporteGravadoP = ImporteGravado;
nConcepto.ValorP = dtPerEmpleados.SUM(string.Format("[VAL_{0}]", CveConcepto), string.Format("CvePersonal = {0}", SRCvePersonal));
- nConcepto.isOnlyBisibleP = row["SoloVisible"].ToString().ToEntero();
+ nConcepto.isOnlyBisibleP = row["SoloVisible"].ToString().ToEntero();
nConcepto.isSavedP = dtPerEmpleadosConceptos.COUNT("CveConcepto", string.Format("CveConcepto={0} AND CvePersonal ={1} AND Estatus >0", CveConcepto, SRCvePersonal));
@@ -4593,7 +4596,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
cargaBitacora();
cargasobrericiboconceptos(SRMostrarFormulas);
- UpModalConceptos.Update();
+ UpModalConceptos.Update();
Alert("Se actualizo el calculo de infonavit");
}
}
@@ -6875,7 +6878,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
try
{
- Response.End();
+ Response.End();
}
catch (Exception)
@@ -7299,7 +7302,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
{
CveConcepto = rcon["CveConcepto"].ToString().ToEntero();
- ImporteConcepto = chkImporte==1? rcon["Importe"].ToString().ToDecimal() :0;
+ ImporteConcepto = chkImporte == 1 ? rcon["Importe"].ToString().ToDecimal() : 0;
ImporteGravadoConcepto = rcon["ImporteGravado"].ToString().ToDecimal();
ImporteExentoConcepto = ImporteConcepto - ImporteGravadoConcepto;
ImporteValor = rcon["Valor"].ToString().ToDecimal();
@@ -9004,7 +9007,7 @@ public partial class Nomina_Nomina2 : ClsPaginas
GVProvision.DataBind();
RegistraScript("$('#ModalRegistraProvision').modal();");
UpRegistroProvision.Update();
-
+
}
}
}
@@ -10149,11 +10152,785 @@ public partial class Nomina_Nomina2 : ClsPaginas
GVViewCorreos.DataBind();
}
UpviewCorreos.Update();
- RegistraScript(string.Format("$('#ModalViewCorreo').modal();", TxtmcImporte.ClientID));
+ RegistraScript("$('#ModalViewCorreo').modal();");
+ }
+
+ protected void LnkProcesarModal_Click(object sender, EventArgs e)
+ {
+ RegistraScript("$('#DmodalArchivoEBASUAPDFToExceL').modal();");
+ }
+ protected void LnkProcesaPDFSUAEBA_Click(object sender, EventArgs e)
+ {
+ List Filesgral = TxtAsistenciaTabular.getfiles().Archivos;
+ if (Filesgral.Count > 0)
+ {
+
+ string dirPDF = Filesgral[0].FileUrl;
+ Boolean essua = false;
+ using (iTextSharp.text.pdf.PdfReader readerx = new iTextSharp.text.pdf.PdfReader(dirPDF))
+ {
+ if (readerx.NumberOfPages > 0)
+ {
+ string text = PdfTextExtractor.GetTextFromPage(readerx, 1);
+ essua = text.Contains("SISTEMA ÚNICO DE AUTODETERMINACIÓN");
+ }
+ }
+ if (essua)
+ {
+ System.IO.Stream fs=(new CedulaSuaPDF()).writexls(dirPDF);
+ 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", "SUA "));
+ Response.BinaryWrite(memoryStream.ToArray());
+ Response.End();
+ }
+ else
+ {
+ System.IO.Stream fs =(new CedulaEBAPDF()).writexls(dirPDF);
+
+ 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", "EBA "));
+ Response.BinaryWrite(memoryStream.ToArray());
+ Response.End();
+ }
+
+ }
+ }
+
+
+ public class CedulaEBAPDF
+ {
+
+ public const string validaNSSptt = @"\d{2}\s\d{2}\s\d{2}\s\d{4}\s\d"; //^inicia//$termina // Regular expression pattern
+ public const string ValidateCURPptt = @"[A-Z]{4}\d{6}[HM]{1}[A-Z]{5}[A-Z0-9]{2}";//^inicia//$termina
+ public const string ValidateFechaptt = @"(0[1-9]|[12][0-9]|3[01])-(0[1-9]|1[0-2])-\d{4}";//dd/MM/yyyy
+ public const string Validatedigitptt = @"^[0-9\s.\t]*$";//digitos espacio y punto
+
+ public int getindexpatch(string text, string pattern)
+ {
+ Match match = Regex.Match(text, pattern);
+ return match.Success ? match.Index : -1;
+ }
+ public string getvaluepatch(string text, string pattern)
+ {
+ Match match = Regex.Match(text, pattern);
+ return match.Success ? match.Value : null;
+ }
+ public System.IO.Stream writexls(string dirPDF)
+ {
+ cedulaEBA dataEBAPDF = readPDFcedulaEBA(dirPDF);
+
+
+ ClosedXML.Excel.XLWorkbook wb = new ClosedXML.Excel.XLWorkbook();
+
+ var libro = wb.AddWorksheet("EBA DATA");
+ int row = 1;
+ int column = 1;
+ libro.Cell(row, column++).Value = "NSS";
+ libro.Cell(row, column++).Value = "CURP";
+ libro.Cell(row, column++).Value = "Nombre";
+
+ libro.Cell(row, column++).Value = "ORIGEN";
+ libro.Cell(row, column++).Value = "CLAVE";
+ libro.Cell(row, column++).Value = "FECHA";
+ libro.Cell(row, column++).Value = "DIAS";
+ libro.Cell(row, column++).Value = "SALARIO";
+ libro.Cell(row, column++).Value = "RETIRO";
+ libro.Cell(row, column++).Value = "CESANTIAPAT";
+ libro.Cell(row, column++).Value = "CESANTIAOBR";
+ libro.Cell(row, column++).Value = "SUMARCV";
+ libro.Cell(row, column++).Value = "APORTACION";
+ libro.Cell(row, column++).Value = " ";
+ libro.Cell(row, column++).Value = "CUOTAFIJAOFD";
+ libro.Cell(row, column++).Value = "AMORTIZA";
+ libro.Cell(row, column++).Value = "SUMAINFONAVIT";
+ libro.Cell(row, column++).Value = "SUMA";
+ int maxxolumn = column;
+ libro.Range(1, 1, row, column - 1).Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
+ libro.Range(1, 1, row, column - 1).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189));
+
+
+ row++;
+ foreach (var empleado in dataEBAPDF.empleados)
+ {
+ column = 1;
+ if (empleado.ldtos.Count > 0)
+ {
+ foreach (var data in empleado.ldtos)
+ {
+ column = 1;
+ libro.Cell(row, column++).Value = string.Format("'{0}", empleado.NSS.Trim());
+ libro.Cell(row, column++).Value = string.Format("{0}", empleado.Curp);
+ libro.Cell(row, column++).Value = string.Format("{0}", empleado.Nombre);
+
+ if (!data.ORIGEN.Contains("Formato") && !data.ORIGEN.Contains("VERSION"))
+ {
+ libro.Cell(row, column++).Value = string.Format("{0}", data.ORIGEN);
+ libro.Cell(row, column++).Value = string.Format("'{0}", data.CLAVE);
+ libro.Cell(row, column++).Value = string.Format("'{0}", data.FECHA);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.DIAS.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.SALARIO.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.RETIRO.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.CESANTIAPAT.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.CESANTIAOBR.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.SUMARCV.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.APORTACION.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.CUOTAFIJAOFDSTR.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.CUOTAFIJAOFD.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.AMORTIZA.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.SUMAINFONAVIT.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ libro.Cell(row, column++).Value = string.Format("{0}", data.SUMA.Trim().Replace(",", "").Replace("$", "").ToDecimal());
+ }
+ row++;
+ }
+ }
+ else
+ {
+ libro.Cell(row, column++).Value = string.Format("'{0}", empleado.NSS.Trim());
+ libro.Cell(row, column++).Value = string.Format("{0}", empleado.Curp);
+ libro.Cell(row, column++).Value = string.Format("{0}", empleado.Nombre);
+ row++;
+
+ }
+ }
+
+ libro.Range(2, 7, row, 13).Style.Alignment.Horizontal = ClosedXML.Excel.XLAlignmentHorizontalValues.Right;
+ libro.Range(2, 15, row, maxxolumn - 1).Style.Alignment.Horizontal = ClosedXML.Excel.XLAlignmentHorizontalValues.Right;
+ libro.Range(2, 7, row, 13).Style.NumberFormat.Format = "$ #,##0.00";
+ libro.Range(2, 15, row, maxxolumn - 1).Style.NumberFormat.Format = "$ #,##0.00";
+ libro.Columns().AdjustToContents();
+ libro.Range(2, 1, row, maxxolumn - 1).SetAutoFilter();
+ //wb.SaveAs(string.Format("{0}xlsx", dirPDF.Substring(0, dirPDF.Length - 3)));
+
+ System.IO.Stream fs = new System.IO.MemoryStream();
+ wb.SaveAs(fs);
+ return fs;
+ }
+ public cedulaEBA readPDFcedulaEBA(string dirPDF)
+ {
+ cedulaEBA objEBA = new cedulaEBA();
+ StringBuilder strb = new StringBuilder();
+ using (iTextSharp.text.pdf.PdfReader readerx = new iTextSharp.text.pdf.PdfReader(dirPDF))
+ {
+ for (int page = 1; page <= readerx.NumberOfPages; page++)
+ {
+ string text = PdfTextExtractor.GetTextFromPage(readerx, page);
+ string[] lines = text.Split('\n');
+ cedulaEBAEmpleados cempleado = null;
+ int pasoCaptura = 0;
+ bool esiniciodepagina = false;
+ foreach (string line in lines)
+ {
+ strb.AppendLine(line);
+ bool espaso1 = Regex.IsMatch(line, ValidateCURPptt);
+ bool espaso2 = Regex.IsMatch(line, validaNSSptt);
+ if (esiniciodepagina)
+ {
+ if (objEBA.empleados.Count > 0 && !espaso2 && !espaso1)
+ {
+ cempleado = objEBA.empleados[objEBA.empleados.Count - 1];
+ objEBA.empleados.RemoveAt(objEBA.empleados.Count - 1);
+ pasoCaptura = 2;
+ }
+ esiniciodepagina = false;
+ }
+ if (pasoCaptura == 0 && line.Contains("FIJA O FD"))
+ {
+ esiniciodepagina = true;
+ }
+ if (!espaso2 && !espaso1 && pasoCaptura == 2)
+ {
+ pasoCaptura = 2;
+ procesapaso2(line, cempleado);
+
+ }
+ if (espaso2)
+ {
+ //isTitulo = false;
+ if (!(pasoCaptura == 1))
+ {
+ if (null != cempleado)
+ {
+ objEBA.empleados.Add(cempleado);
+ }
+ cempleado = new cedulaEBAEmpleados();
+
+ }
+ pasoCaptura = 2;
+ if (espaso1)
+ {
+ cempleado.Curp = getvaluepatch(line, ValidateCURPptt);
+
+ }
+ cempleado.NSS = getvaluepatch(line, validaNSSptt);
+ cempleado.Nombre = line.Replace(cempleado.NSS, "").Trim();
+ if (cempleado.Curp != null)
+ {
+ cempleado.Nombre = cempleado.Nombre.Replace(cempleado.Curp, "").Trim();
+ }
+
+ }
+ if (pasoCaptura == 1)
+ {
+ pasoCaptura = 2;
+ procesapaso2(line, cempleado);
+
+ }
+ if (espaso1 && !espaso2)
+ {
+ //isTitulo = false;
+ pasoCaptura = 1;
+ if (null != cempleado)
+ {
+ objEBA.empleados.Add(cempleado);
+ }
+ cempleado = new cedulaEBAEmpleados();
+
+ cempleado.Curp = getvaluepatch(line, ValidateCURPptt);
+
+ }
+ //Console.WriteLine(line);
+ }
+
+ if (null != cempleado)
+ {
+ objEBA.empleados.Add(cempleado);
+ }
+ cempleado = null;
+ strb.AppendLine("/*NEWPAGE*/");
+
+ }
+ }
+ return objEBA;
+ }
+
+
+ public cedulaEBAEmpleados procesapaso2(string line, cedulaEBAEmpleados empleado)
+ {
+ if (line.ToUpper().Contains("Página".ToUpper()))
+ {
+ }
+ else
+ {
+ bool contienefecha = Regex.IsMatch(line, ValidateFechaptt);
+ string[] splitedline = line.Split(' ');
+ int l = splitedline.Length;
+ cedulaEBAEmpleadosdatos dtos = null;
+ cedulaEBAEmpleadosdatos dtosant = null;
+ if (empleado.ldtos.Count > 0)
+ {
+ dtosant = empleado.ldtos[empleado.ldtos.Count - 1];
+ if (dtosant.CESANTIAPAT != null &&
+ !(dtosant.CUOTAFIJAOFD != null &&
+ (dtosant.CUOTAFIJAOFD.Contains("CF") || dtosant.CUOTAFIJAOFD.Contains("FD") || dtosant.CUOTAFIJAOFD.Contains("%"))
+ )
+ )
+ {
+ dtosant = null;
+
+ }
+ }
+ int col = 0;
+ if (dtosant == null || l > 6)
+ {
+ dtos = new cedulaEBAEmpleadosdatos();
+ if (col < l) { dtos.ORIGEN = splitedline[col++]; }
+ if (contienefecha && col < l) { dtos.CLAVE = splitedline[col++]; }
+ if (contienefecha && col < l) { dtos.FECHA = splitedline[col++]; }
+ if (col < l) { dtos.DIAS = splitedline[col++]; }
+ if (col < l) { dtos.SALARIO = splitedline[col++]; }
+ if (col < l) { dtos.RETIRO = splitedline[col++]; }
+ if (col < l) { dtos.SUMARCV = splitedline[col++]; }
+ if (col < l) { dtos.APORTACION = splitedline[col++]; }
+ if ((col + 3) < l)
+ {
+ dtos.CUOTAFIJAOFD = splitedline[col++].Trim();
+ if (dtos.CUOTAFIJAOFD.Contains("CF") || dtos.CUOTAFIJAOFD.Contains("FD") || dtos.CUOTAFIJAOFD.Contains("%"))
+ {
+ dtos.CUOTAFIJAOFDSTR = dtos.CUOTAFIJAOFD;
+ if ((col + 3) < l) { dtos.CUOTAFIJAOFD = splitedline[col++].Trim(); }
+ }
+ }
+ if (col < l) { dtos.AMORTIZA = splitedline[col++]; }
+ if (col < l) { dtos.SUMAINFONAVIT = splitedline[col++]; }
+ if (col < l) { dtos.SUMA = splitedline[col++]; }
+ }
+ else
+ {
+ empleado.ldtos.RemoveAt(empleado.ldtos.Count - 1);
+ dtos = dtosant;
+ if (dtosant.CESANTIAPAT != null)
+ {
+ if (col < l) { dtos.CUOTAFIJAOFD = splitedline[col++]; } else { dtos.CUOTAFIJAOFD = ""; }
+
+ }
+ else
+ {
+ if (col < l) { dtos.CESANTIAPAT = splitedline[col++]; }
+ if (col < l) { dtos.CESANTIAOBR = splitedline[col++]; }
+
+ }
+ }
+ empleado.ldtos.Add(dtos);
+ }
+ return empleado;
+ }
+
+ }
+ public class cedulaEBA
+ {
+ public cedulaEBA()
+ {
+ empleados = new List();
+ }
+ public string txtTitulo { get; set; }
+ public string txtTodo { get; set; }
+ public List empleados { get; set; }
+ }
+ public class cedulaEBAEmpleados
+ {
+ public cedulaEBAEmpleados()
+ {
+ ldtos = new List();
+ }
+ public string NSS { get; set; }
+ public string Nombre { get; set; }
+ public string Curp { get; set; }
+ public string centrocostos { get; set; }
+
+ public List ldtos { get; set; }
+ }
+ public class cedulaEBAEmpleadosdatos
+ {
+
+
+ public string ORIGEN { get; set; }
+ public string CLAVE { get; set; }
+ public string FECHA { get; set; }
+ public string DIAS { get; set; }
+ public string SALARIO { get; set; }
+ public string RETIRO { get; set; }
+ public string SUMARCV { get; set; }
+ public string APORTACION { get; set; }
+ public string CUOTAFIJAOFD { get; set; }
+ public string CUOTAFIJAOFDSTR { get; set; }
+ public string AMORTIZA { get; set; }
+ public string SUMAINFONAVIT { get; set; }
+ public string SUMA { get; set; }
+
+ public string CESANTIAPAT { get; set; }
+ public string CESANTIAOBR { get; set; }
+ }
+
+
+ public class CedulaSuaPDF
+ {
+ public const string validaNSSptt = @"\d{2}-\d{2}-\d{2}-\d{4}-\d"; //^inicia//$termina // Regular expression pattern
+ public const string ValidateCURPptt = @"[A-Z]{4}\d{6}[HM]{1}[A-Z]{5}[A-Z0-9]{2}";//^inicia//$termina
+ public const string ValidateFechaptt = @"(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/\d{4}";//dd/MM/yyyy
+ public const string Validatedigitptt = @"^[0-9\s.,\t]*$";//digitos espacio y punto
+
+ public int getindexpatch(string text, string pattern)
+ {
+ Match match = Regex.Match(text, pattern);
+ return match.Success ? match.Index : -1;
+ }
+ public string getvaluepatch(string text, string pattern)
+ {
+ Match match = Regex.Match(text, pattern);
+ return match.Success ? match.Value : null;
+ }
+
+ public System.IO.Stream writexls(string dirPDF)
+ {
+ cedulaSUA dataEBAPDF = readPDFcedulaSUA(dirPDF);
+
+
+ ClosedXML.Excel.XLWorkbook wb = new ClosedXML.Excel.XLWorkbook();
+
+ var libro = wb.AddWorksheet("EBA DATA");
+ int row = 2;
+ int column = 1;
+ libro.Cell(row, column++).Value = "NSS";
+ libro.Cell(row, column++).Value = "CURP";
+ libro.Cell(row, column++).Value = "Nombre";
+ libro.Cell(row, column++).Value = "Ubicación".ToUpper();
+
+
+ libro.Cell(row, column++).Value = "CLAVE";
+ libro.Cell(row, column++).Value = "FECHA";
+ libro.Cell(row, column++).Value = "DIAS";
+ libro.Cell(row, column++).Value = "SALARIO";
+
+ libro.Cell(row, column++).Value = "INCAPACIDAD";
+ libro.Cell(row, column++).Value = "AUSENTISMO";
+ libro.Cell(row, column++).Value = "RETIRO";
+
+ libro.Range(1, column, 1, column + 2).Merge().Value = "Cesantía y Vejez".ToUpper();
+ libro.Cell(row, column++).Value = "PATRONAL";
+ libro.Cell(row, column++).Value = "OBRERA";
+ libro.Cell(row, column++).Value = "SUMA";
+
+ libro.Cell(row, column++).Value = "Aportación Patronal".ToUpper();
+ libro.Cell(row, column++).Value = "% o $ o FD";
+ libro.Cell(row, column++).Value = "% o $ o FD";
+ libro.Range(row, column - 2, row, column).Value = "% o $ o FD";
+ libro.Cell(row, column++).Value = "Amortización";
+ libro.Cell(row, column++).Value = "SUMA";
+ libro.Cell(row, column++).Value = "Créd. Vivienda".ToUpper();
+ libro.Cell(row, column++).Value = "Tipo Movto. de Crédito".ToUpper();
+ libro.Cell(row, column++).Value = "Fecha de Movto. de Crédito".ToUpper();
+
+ int maxxolumn = column;
+ libro.Range(1, 1, row, column - 1).Style.Font.FontColor = ClosedXML.Excel.XLColor.White;
+ libro.Range(1, 1, row, column - 1).Style.Fill.SetBackgroundColor(ClosedXML.Excel.XLColor.FromArgb(79, 129, 189));
+
+
+ row++;
+ foreach (var empleado in dataEBAPDF.empleados)
+ {
+ column = 1;
+ if (empleado.ldtos.Count > 0)
+ {
+ foreach (var data in empleado.ldtos)
+ {
+ column = 1;
+ libro.Cell(row, column++).Value = string.Format("'{0}", empleado.NSS.Trim());
+ libro.Cell(row, column++).Value = string.Format("{0}", empleado.Curp);
+ libro.Cell(row, column++).Value = string.Format("{0}", empleado.Nombre);
+ libro.Cell(row, column++).Value = string.Format("{0}", empleado.centrocostos);
+
+
+ libro.Cell(row, column++).Value = string.Format("'{0}", data.Clave);
+ libro.Cell(row, column++).Value = string.Format("'{0}", data.Fecha);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.Dias);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.SDI);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.Inc);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.Aus);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.Retiro);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.Patronal);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.Obrera);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.Suma);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.AportacionPatronal);
+
+ libro.Cell(row, column++).Value = string.Format("{0}", data.FD);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.FDimporte);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.Amortización);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.SumaB);
+ libro.Cell(row, column++).Value = string.Format("'{0}", data.CredVivienda);
+ libro.Cell(row, column++).Value = string.Format("{0}", data.tipodecredito);
+ libro.Cell(row, column++).Value = string.Format("'{0}", data.fechamovto);
+
+ row++;
+ }
+ }
+ else
+ {
+ libro.Cell(row, column++).Value = string.Format("'{0}", empleado.NSS.Trim());
+ libro.Cell(row, column++).Value = string.Format("{0}", empleado.Curp);
+ libro.Cell(row, column++).Value = string.Format("{0}", empleado.Nombre);
+ libro.Cell(row, column++).Value = string.Format("{0}", empleado.centrocostos);
+ row++;
+
+ }
+ }
+
+ libro.Range(2, 7, row, 15).Style.Alignment.Horizontal = ClosedXML.Excel.XLAlignmentHorizontalValues.Right;
+ libro.Range(2, 17, row, 20).Style.Alignment.Horizontal = ClosedXML.Excel.XLAlignmentHorizontalValues.Right;
+ //libro.Range(2, 7, row, 15).Style.NumberFormat.Format = "$ #,##0.00";
+ //libro.Range(2, 17, row, 20).Style.NumberFormat.Format = "$ #,##0.00";
+ libro.Columns().AdjustToContents();
+ libro.Range(2, 1, row, maxxolumn - 1).SetAutoFilter();
+ //wb.SaveAs(string.Format("{0}xlsx", dirPDF.Substring(0, dirPDF.Length - 3)));
+
+ System.IO.Stream fs = new System.IO.MemoryStream();
+ wb.SaveAs(fs);
+ return fs;
+ }
+ public cedulaSUA readPDFcedulaSUA(string dirPDF)
+ {
+ cedulaSUA objSUA = new cedulaSUA();
+ StringBuilder strb = new StringBuilder();
+ StringBuilder strtitulo = new StringBuilder();
+ bool isTitulo = true;
+ using (iTextSharp.text.pdf.PdfReader readerx = new iTextSharp.text.pdf.PdfReader(dirPDF))
+ {
+ for (int page = 1; page <= readerx.NumberOfPages; page++)
+ {
+ string text = PdfTextExtractor.GetTextFromPage(readerx, page);
+ if (!isTitulo)
+ {
+ text = text.Replace(strtitulo.ToString(), "");
+ }
+
+ cedulaSUAEmpleados cempleado = null;
+ string[] lines = text.Split('\n');
+ int pasoCaptura = 0;
+ foreach (string line in lines)
+ {
+ strb.AppendLine(line);
+ bool espaso1 = Regex.IsMatch(line, validaNSSptt);
+
+ if (!espaso1 && pasoCaptura == 4)
+ {
+ procesapaso4(line, cempleado);
+
+ }
+ if (!espaso1 && pasoCaptura == 3)
+ {
+ if (Regex.IsMatch(line, ValidateFechaptt) || Regex.IsMatch(line, Validatedigitptt))
+ {
+ procesapaso4(line, cempleado);
+ pasoCaptura = 4;
+ }
+ else
+ {
+ cempleado.centrocostos = line;
+ pasoCaptura = 4;
+
+ }
+ }
+
+ if (!espaso1 && pasoCaptura == 1)
+ {
+ if (Regex.IsMatch(line, ValidateFechaptt) || Regex.IsMatch(line, Validatedigitptt))
+ {
+ procesapaso4(line, cempleado);
+ pasoCaptura = 4;
+ }
+ else
+ {
+ if (Regex.IsMatch(line, ValidateCURPptt))
+ {
+ cempleado.Curp = getvaluepatch(line, ValidateCURPptt);
+ cempleado.centrocostos = line.Replace(cempleado.Curp, "").Trim();
+ pasoCaptura = cempleado.centrocostos.Length > 0 ? 4 : 3;
+ }
+ else
+ {
+ cempleado.centrocostos = line;
+ pasoCaptura = 4;
+ }
+
+
+ }
+ }
+ if (espaso1)
+ {
+ isTitulo = false;
+ pasoCaptura = 1;
+ if (null != cempleado)
+ {
+ objSUA.empleados.Add(cempleado);
+ }
+ cempleado = new cedulaSUAEmpleados();
+
+ cempleado.NSS = getvaluepatch(line, validaNSSptt);
+ string[] linesplited = line.Replace(cempleado.NSS, "").Trim().Split(' ');
+ if (linesplited.Length > 2)
+ {
+ cempleado.Curp = linesplited[linesplited.Length - 1];
+ }
+
+ //cempleado.Curp = getvaluepatch(line, ValidateCURPptt);
+ string NombreCompleto;
+ if (cempleado.Curp != null)
+ {
+
+ cempleado.Nombre = line.Replace(cempleado.NSS, "").Replace(cempleado.Curp, "").Trim();
+ //cempleado.Nombre = line.Substring(getindexpatch(line, validaNSSptt) + 15).Substring(0, getindexpatch(line, ValidateCURPptt) - 18).Trim();
+
+ //cempleado.centrocostos = line.Substring(getindexpatch(line, ValidateCURPptt) + 18);
+ pasoCaptura = 3;// cempleado.centrocostos.Length > 0 ? 4 : 3;
+
+ }
+ else
+ {
+ NombreCompleto = line.Replace(cempleado.NSS, "").Trim();
+ }
+ //string[] splitline = line.Split(nss);
+
+ }
+ if (isTitulo)
+ {
+ strtitulo.AppendLine();
+ }
+ //Console.WriteLine(line);
+ }
+
+ if (null != cempleado)
+ {
+ objSUA.empleados.Add(cempleado);
+ }
+ cempleado = null;
+ strb.AppendLine("/*NEWPAGE*/");
+ }
+ }
+ objSUA.txtTodo = strb.ToString();
+ return objSUA;
+ }
+ public cedulaSUAEmpleados procesapaso4(string line, cedulaSUAEmpleados empleado)
+ {
+ if (line.ToUpper().Contains("Página".ToUpper()))
+ {
+ }
+ else
+ {
+ bool contienefecha;
+ if (line.Length > 20)
+ {
+
+ contienefecha = Regex.IsMatch(line.Substring(0, 20), ValidateFechaptt);
+ }
+ else
+ {
+ contienefecha = Regex.IsMatch(line, ValidateFechaptt);
+
+ }
+ string[] splitedline = line.Split(' ');
+ int l = splitedline.Length;
+ bool ismsfsd = (line.ToUpper().Contains("M/S".ToUpper()) && line.ToUpper().Contains("FSD".ToUpper()) && l < 6);
+ cedulaSUAEmpleadosdatos dtos = null;
+ cedulaSUAEmpleadosdatos dtosant = null;
+ if (empleado.ldtos.Count > 0)
+ {
+ dtosant = empleado.ldtos[empleado.ldtos.Count - 1];
+ }
+ if (dtosant == null || (contienefecha && !(dtosant != null && dtosant.Dias == null)))
+ {
+ dtos = new cedulaSUAEmpleadosdatos();
+ }
+ else
+ {
+ empleado.ldtos.RemoveAt(empleado.ldtos.Count - 1);
+ dtos = dtosant;
+ }
+ int col = 0;
+ if (contienefecha && col < l) { dtos.Clave = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (contienefecha && col < l) { dtos.Fecha = splitedline[col++]; }
+ if (dtos.Clave != null && dtos.Clave.Contains("FSD"))
+ {
+ dtos.tipodecredito = dtos.Clave;
+ dtos.Clave = "";
+ dtos.fechamovto = dtos.Fecha;
+ dtos.Fecha = "";
+ }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd)
+ {
+ if (splitedline[col].Length > 8)
+ {
+ dtos.tipodecredito = dtos.CredVivienda;
+ dtos.CredVivienda = splitedline[col++];
+ }
+ else
+ {
+ dtos.Dias = splitedline[col++];
+ }
+ }
+ if (col < l && !ismsfsd) { dtos.SDI = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd) { dtos.Inc = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd) { dtos.Aus = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd) { dtos.Retiro = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd) { dtos.Patronal = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd) { dtos.Obrera = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd) { dtos.Suma = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd) { dtos.AportacionPatronal = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd && (col + 3) < l) { dtos.FD = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd && (col + 2) < l) { dtos.FDimporte = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd) { dtos.Amortización = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd) { dtos.SumaB = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l && !ismsfsd) { dtos.CredVivienda = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l) { dtos.tipodecredito = splitedline[col++]; }
+ if (col < l && splitedline[col] == "") { col++; }
+ if (col < l) { dtos.fechamovto = splitedline[col++]; }
+ empleado.ldtos.Add(dtos);
+ }
+ return empleado;
+ }
+
+ }
+ public class cedulaSUA
+ {
+ public cedulaSUA()
+ {
+ empleados = new List();
+ }
+ public string txtTitulo { get; set; }
+ public string txtTodo { get; set; }
+ public List empleados { get; set; }
+ }
+ public class cedulaSUAEmpleados
+ {
+ public cedulaSUAEmpleados()
+ {
+ ldtos = new List();
+ }
+ public string NSS { get; set; }
+ public string Nombre { get; set; }
+ public string Curp { get; set; }
+ public string centrocostos { get; set; }
+
+ public List ldtos { get; set; }
+ }
+ public class cedulaSUAEmpleadosdatos
+ {
+
+ public string Clave { get; set; }
+ public string Fecha { get; set; }
+ public string Dias { get; set; }
+ public string SDI { get; set; }
+ public string Inc { get; set; }
+ public string Aus { get; set; }
+ public string Retiro { get; set; }
+ public string Patronal { get; set; }
+ public string Obrera { get; set; }
+ public string Suma { get; set; }
+ public string AportacionPatronal { get; set; }
+ public string FD { get; set; }
+ public string FDimporte { get; set; }
+ public string Amortización { get; set; }
+ public string SumaB { get; set; }
+ public string CredVivienda { get; set; }
+ public string tipodecredito { get; set; }
+ public string fechamovto { get; set; }
}
-
-
}
\ No newline at end of file