605 lines
22 KiB
C#
605 lines
22 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace ADSTimbrado
|
|
{
|
|
|
|
[Serializable]
|
|
public class CFDITimbre
|
|
{
|
|
private StringBuilder StrMsg;
|
|
public CFDIComprobante Comprobante { get; set; }
|
|
public CFDIRelacionados CFDIRelacionados { get; set; }
|
|
public CFDIEmisor Emisor { get; set; }
|
|
public CFDIReceptor Receptor { get; set; }
|
|
public List<CFDIConceptos> Conceptos { get; set; }
|
|
public List<CFDIRetencionesLocales> RetencionesLocales { get; set; }
|
|
public List<CFDITrasladosLocales> TrasladosLocales { get; set; }
|
|
public CFDINomina Nomina { get; set; }
|
|
public CFDIComplementoPagos ComplementoPagos { get; set; }
|
|
public CFDIComplementos Complementos { get; set; }
|
|
public decimal TotalImpuestosRetenidos
|
|
{
|
|
get
|
|
{
|
|
return (from c in Conceptos
|
|
select c.Impuestos.Where(ret => ret.TrasladooRetencion == "R").Sum(ret => ret.Importe)).Sum();
|
|
}
|
|
}
|
|
|
|
public decimal TotalImpuestosTrasladados
|
|
{
|
|
get
|
|
{
|
|
return (from c in Conceptos
|
|
select c.Impuestos.Where(tra => tra.TrasladooRetencion == "T").Sum(tra => tra.Importe)).Sum();
|
|
}
|
|
}
|
|
|
|
public List<CFDIRetenciones> Retenciones
|
|
{
|
|
get
|
|
{
|
|
List<CFDIRetenciones> tRetorno = new List<CFDIRetenciones>();
|
|
List<CFDIRetenciones> TRetenciones = new List<CFDIRetenciones>();
|
|
// Dim RetencionIVA As Decimal = 0
|
|
// Dim RetencionIEPS As Decimal = 0
|
|
// Dim RetencionISR As Decimal = 0
|
|
foreach (CFDIConceptos c in Conceptos)
|
|
{
|
|
foreach (CFDIConceptosImpuestos imp in c.Impuestos)
|
|
{
|
|
if (imp.TrasladooRetencion == "R")
|
|
tRetorno.Add(new CFDIRetenciones() { Impuesto = imp.Impuesto, Importe = imp.Importe });
|
|
}
|
|
}
|
|
if (tRetorno.Count > 0)
|
|
TRetenciones = tRetorno.GroupBy(t => new { t.Impuesto })
|
|
.Select(t => new CFDIRetenciones() { Impuesto = t.Key.Impuesto, Importe = t.Sum(tt => tt.Importe) })
|
|
.OrderBy(x => x.Impuesto).ToList();
|
|
// If RetencionISR > 0 Then Retorno.Add(New CFDIRetenciones With {.Impuesto = "001", .Importe = RetencionISR})
|
|
// if RetencionIVA > 0 Then Retorno.Add(New CFDIRetenciones With {.Impuesto = "002", .Importe = RetencionIVA})
|
|
// If RetencionIEPS > 0 Then Retorno.Add(New CFDIRetenciones With {.Impuesto = "003", .Importe = RetencionIEPS})
|
|
tRetorno = null;
|
|
return TRetenciones;
|
|
}
|
|
}
|
|
|
|
public List<CFDITraslados> Traslados
|
|
{
|
|
get
|
|
{
|
|
List<CFDITraslados> tRetorno = new List<CFDITraslados>();
|
|
List<CFDITraslados> TTraslados = new List<CFDITraslados>();
|
|
foreach (CFDIConceptos c in Conceptos)
|
|
{
|
|
foreach (CFDIConceptosImpuestos imp in c.Impuestos)
|
|
{
|
|
if (imp.TrasladooRetencion == "T")
|
|
tRetorno.Add(new CFDITraslados() { Impuesto = imp.Impuesto, Importe = imp.Importe, TasaOCuota = imp.TasaOCuota, TipoFactor = imp.TipoFactor });
|
|
}
|
|
}
|
|
// ya generado todos los registros posibles, los agrupo y los sumo
|
|
if (tRetorno.Count > 0)
|
|
TTraslados = tRetorno.GroupBy(t => new { t.TipoFactor, t.Impuesto, t.TasaOCuota })
|
|
.Select(t => new CFDITraslados() { Impuesto = t.Key.Impuesto, TipoFactor = t.Key.TipoFactor, TasaOCuota = t.Key.TasaOCuota, Importe = t.Sum(tt => tt.Importe) })
|
|
.OrderBy(x => x.Impuesto).ToList();
|
|
tRetorno = null;
|
|
return TTraslados;
|
|
}
|
|
}
|
|
public string Mensaje
|
|
{
|
|
get
|
|
{
|
|
return StrMsg.ToString();
|
|
}
|
|
}
|
|
public CFDITimbre()
|
|
{
|
|
StrMsg = new StringBuilder();
|
|
Comprobante = new CFDIComprobante();
|
|
CFDIRelacionados = new CFDIRelacionados();
|
|
Conceptos = new List<CFDIConceptos>();
|
|
Emisor = new CFDIEmisor();
|
|
Receptor = new CFDIReceptor();
|
|
RetencionesLocales = new List<CFDIRetencionesLocales>();
|
|
TrasladosLocales = new List<CFDITrasladosLocales>();
|
|
ComplementoPagos = new CFDIComplementoPagos();
|
|
Complementos = new CFDIComplementos();
|
|
}
|
|
|
|
public void AddMsg(string Msg)
|
|
{
|
|
StrMsg.AppendLine(Msg);
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDINomina
|
|
{
|
|
|
|
public bool Contiene(int Valor, params int[] Valores)
|
|
{
|
|
return Array.IndexOf(Valores, Valor) >= 0;
|
|
}
|
|
public bool Contiene(string Valor, params string[] Valores)
|
|
{
|
|
return Array.IndexOf(Valores, Valor) >= 0;
|
|
}
|
|
public string Version { get; set; }
|
|
public string TipoNomina { get; set; }
|
|
public DateTime FechaPago { get; set; }
|
|
public string FechaInicio { get; set; }
|
|
public string FechaFin { get; set; }
|
|
public int NumDiasPagados { get; set; }
|
|
public CFDINominaReceptor Receptor { get; set; }
|
|
public List<CFDINominaPercepciones> Percepciones { get; set; }
|
|
public List<CFDINominaDeducciones> Deducciones { get; set; }
|
|
public List<CFDINominaIncapacidades> Incapacidades { get; set; }
|
|
public List<CFDINominaOtrosPagos> OtrosPagos { get; set; }
|
|
public List<CFDINominaHorasExtras> HorasExtras { get; set; }
|
|
public int CveNomina { get; set; }
|
|
|
|
public decimal TotalPercepciones
|
|
{
|
|
get
|
|
{
|
|
return TotalSueldos + TotalIndemnizacion + TotalJubilacion;
|
|
}
|
|
}
|
|
|
|
public decimal TotalDeducciones
|
|
{
|
|
get
|
|
{
|
|
return Math.Round(TotalDeduccionesOtras + TotalDeduccionesImpuestosRetenidos, 2);
|
|
}
|
|
}
|
|
|
|
public decimal TotalOtrosPagos
|
|
{
|
|
get
|
|
{
|
|
return OtrosPagos.Sum(item => item.Importe);
|
|
}
|
|
}
|
|
public decimal TotalSueldos
|
|
{
|
|
get
|
|
{
|
|
return Percepciones.Where(per => !Contiene(per.TipoPercepcion, new string[] { "022", "023", "025", "039", "044" })).Sum(per => per.ImporteGravado + per.ImporteExento);
|
|
}
|
|
}
|
|
public decimal TotalIndemnizacion
|
|
{
|
|
get
|
|
{
|
|
return Percepciones.Where(per => Contiene(per.TipoPercepcion, new string[] { "022", "023", "025" })).Sum(per => per.ImporteGravado + per.ImporteExento);
|
|
}
|
|
}
|
|
|
|
public decimal TotalJubilacion
|
|
{
|
|
get
|
|
{
|
|
return Percepciones.Where(per => Contiene(per.TipoPercepcion, new string[] { "039", "044" })).Sum(per => per.ImporteGravado + per.ImporteExento);
|
|
}
|
|
}
|
|
public decimal TotalPercepcionesGravado
|
|
{
|
|
get
|
|
{
|
|
// nota especificar claves
|
|
return Percepciones.Sum(item => item.ImporteGravado);
|
|
}
|
|
}
|
|
public decimal TotalPercepcionesExento
|
|
{
|
|
get
|
|
{
|
|
// nota especificar claves
|
|
return Percepciones.Sum(item => item.ImporteExento);
|
|
}
|
|
}
|
|
|
|
public decimal TotalDeduccionesOtras
|
|
{
|
|
get
|
|
{
|
|
// DEDUCCIONES SE LE QUITAN LOS CENTAVOS
|
|
return Math.Round(Deducciones.Where(ded => !Contiene(ded.TipoDeduccion, new string[] { "002" })).Sum(ded => ded.Importe), 2);
|
|
}
|
|
}
|
|
|
|
public decimal TotalDeduccionesImpuestosRetenidos
|
|
{
|
|
get
|
|
{
|
|
// nota especificar claves
|
|
return Math.Round(Deducciones.Where(ded => Contiene(ded.TipoDeduccion, new string[] { "002" })).Sum(ded => ded.Importe), 2);
|
|
}
|
|
}
|
|
|
|
public CFDINomina()
|
|
{
|
|
Receptor = new CFDINominaReceptor();
|
|
Percepciones = new List<CFDINominaPercepciones>();
|
|
Deducciones = new List<CFDINominaDeducciones>();
|
|
Incapacidades = new List<CFDINominaIncapacidades>();
|
|
OtrosPagos = new List<CFDINominaOtrosPagos>();
|
|
HorasExtras = new List<CFDINominaHorasExtras>();
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIComprobante
|
|
{
|
|
public string Version { get; set; }
|
|
public string Serie { get; set; } = "";
|
|
public string Folio { get; set; } = "";
|
|
public string SerieFolio
|
|
{
|
|
get
|
|
{
|
|
// sino tiene serie no pone el guión
|
|
return Serie == "" ? Folio : $"{Serie}-{Folio}";
|
|
}
|
|
}
|
|
public string TipoDocto { get; set; }
|
|
public string FormadePago { get; set; }
|
|
public string CondicionesdePago { get; set; }
|
|
public DateTime Fecha { get; set; }
|
|
public decimal Subtotal { get; set; } = 0;
|
|
public decimal Descuentos { get; set; } = 0;
|
|
public string MotivoDescuento { get; set; } = "";
|
|
public string TipoCambio { get; set; } = "1";
|
|
public string Moneda { get; set; } = "";
|
|
public string TipoComprobante { get; set; } = "";
|
|
public string MetodoPago { get; set; } = "";
|
|
public decimal Total { get; set; } = 0;
|
|
public string LugarExpedicion { get; set; } = "";
|
|
public string NumCuentaPago { get; set; } = "";
|
|
public string Confirmacion { get; set; } = "";
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIComplementos
|
|
{
|
|
public CFDIComercioExterior11 ComercioExterior11 { get; set; }
|
|
|
|
public CFDIComplementos()
|
|
{
|
|
ComercioExterior11 = new CFDIComercioExterior11();
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIRelacionados
|
|
{
|
|
public string TipoRelacion { get; set; }
|
|
public string TipoRelacionTexto { get; set; }
|
|
public List<string> UUID { get; set; }
|
|
public CFDIRelacionados()
|
|
{
|
|
UUID = new List<string>();
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIEmisor
|
|
{
|
|
public string RFC { get; set; }
|
|
public string Nombre { get; set; }
|
|
public string RegimenFiscal { get; set; }
|
|
public string RegistroPatronal { get; set; }
|
|
public string CURP { get; set; } = "";
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIReceptor
|
|
{
|
|
public string RFC { get; set; }
|
|
public string Nombre { get; set; }
|
|
public string ResidenciaFiscal { get; set; } = "";
|
|
public string NumeroRegistroTributario { get; set; } = "";
|
|
public string UsoCFDI { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDINominaReceptor
|
|
{
|
|
public string CURP { get; set; } = "";
|
|
public string NSS { get; set; } = "";
|
|
public string RegimenFiscal { get; set; } = "";
|
|
public string FechaInicioContrato { get; set; } = "";
|
|
public string Antiguedad { get; set; } = "";
|
|
public string TipoContrato { get; set; } = "";
|
|
public string Sindicalizado { get; set; } = "";
|
|
public string CodigoTipoJornada { get; set; } = "";
|
|
public string CodigoRegimenContratacion { get; set; } = "";
|
|
public string CodigoEmpleado { get; set; } = "";
|
|
public string Departamento { get; set; } = "";
|
|
public string Puesto { get; set; } = "";
|
|
public string CodigoRiesgoPuesto { get; set; } = "";
|
|
public string TipoPeriodo { get; set; } = "";
|
|
public string CodigoBanco { get; set; } = "";
|
|
public string NumeroCuenta { get; set; } = "";
|
|
public decimal SDI { get; set; } = 0;
|
|
public decimal SBC { get; set; } = 0;
|
|
public string CodigoEntidadFederativa { get; set; } = "";
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIConceptos
|
|
{
|
|
public decimal Cantidad { get; set; } = 0.00M;
|
|
public string Unidad { get; set; } = "";
|
|
public string Noidentificacion { get; set; } = "";
|
|
public string Descripcion { get; set; } = "";
|
|
public decimal ValorUnitario { get; set; } = 0.00M;
|
|
public decimal Importe { get; set; } = 0.00M;
|
|
public string CuentaPredial { get; set; } = "";
|
|
public string ClaveProdServ { get; set; } = "";
|
|
public string ClaveUnidad { get; set; } = "";
|
|
public List<CFDIConceptosImpuestos> Impuestos { get; set; }
|
|
public decimal Descuento { get; set; } = 0.00M;
|
|
public decimal ImporteGravaIVAAdicional { get; set; } = 0.00M; // caso IEPS
|
|
|
|
public CFDIConceptos()
|
|
{
|
|
Impuestos = new List<CFDIConceptosImpuestos>();
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIConceptosImpuestos
|
|
{
|
|
public string TrasladooRetencion { get; set; } = "T";
|
|
public decimal Base { get; set; } = 0.00M;
|
|
public string Impuesto { get; set; } = "";
|
|
public string TipoFactor { get; set; } = "Tasa";
|
|
public decimal TasaOCuota { get; set; } = 0.00M;
|
|
public decimal Importe { get; set; } = 0.00M; // propiedad utilizada solo para hacer ajustes, por default toma la multiplicación de base * tasa
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDINominaPercepciones
|
|
{
|
|
public string TipoPercepcion { get; set; }
|
|
public string Clave { get; set; }
|
|
public string Concepto { get; set; }
|
|
public decimal ImporteGravado { get; set; }
|
|
public decimal ImporteExento { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDINominaDeducciones
|
|
{
|
|
public string TipoDeduccion { get; set; }
|
|
public string Clave { get; set; }
|
|
public string Concepto { get; set; }
|
|
public decimal Importe { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDINominaIncapacidades
|
|
{
|
|
public string DiasIncapacidad { get; set; }
|
|
public string TipoIncapacidad { get; set; }
|
|
public decimal Importe { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDINominaOtrosPagos
|
|
{
|
|
public string TipoOtroPago { get; set; }
|
|
public string Clave { get; set; }
|
|
public string Concepto { get; set; }
|
|
public decimal Importe { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIRetenciones
|
|
{
|
|
public string Impuesto { get; set; }
|
|
public decimal Importe { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIRetencionesLocales
|
|
{
|
|
public string ImpuestoLocalRetenido { get; set; }
|
|
public decimal TasaRetencion { get; set; }
|
|
public decimal Importe { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDITrasladosLocales
|
|
{
|
|
public string ImpuestoLocalTraslado { get; set; }
|
|
public decimal TasaTraslado { get; set; }
|
|
public decimal Importe { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDITraslados
|
|
{
|
|
public string Impuesto { get; set; }
|
|
public decimal Tasa { get; set; }
|
|
public string TipoFactor { get; set; }
|
|
public decimal TasaOCuota { get; set; }
|
|
public decimal Importe { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDINominaHorasExtras
|
|
{
|
|
public string Dias { get; set; }
|
|
public string TipoHoras { get; set; }
|
|
public int HorasExtra { get; set; }
|
|
public decimal ImportePagado { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIComplementoPagos
|
|
{
|
|
public DateTime FechaPago { get; set; }
|
|
public string FormaDePagoP { get; set; } = "";
|
|
public string MonedaP { get; set; } = "";
|
|
public string NumOperacion { get; set; } = "";
|
|
public decimal TipoCambioP { get; set; } = 0;
|
|
public decimal Monto { get; set; }
|
|
public string RfcEmisorCtaOrd { get; set; } = "";
|
|
public string NomBancoOrdExt { get; set; } = "";
|
|
public string CtaOrdenante { get; set; } = "";
|
|
public string RfcEmisorCtaBen { get; set; } = "";
|
|
public string CtaBeneficiario { get; set; } = "";
|
|
public string TipoCadPago { get; set; } = "";
|
|
public string CertPago { get; set; } = "";
|
|
public string CadPago { get; set; } = "";
|
|
public string SelloPago { get; set; } = "";
|
|
public List<CFDIComplementoPagosDocsRelacionados> DocumentosRelacionados { get; set; }
|
|
public List<CFDIConceptosImpuestos> Impuestos { get; set; }
|
|
|
|
public decimal TotalImpuestosRetenidos
|
|
{
|
|
get
|
|
{
|
|
return (from c in Impuestos
|
|
where c.TrasladooRetencion == "R"
|
|
select c.Importe).Sum();
|
|
}
|
|
}
|
|
|
|
public decimal TotalImpuestosTrasladados
|
|
{
|
|
get
|
|
{
|
|
return (from c in Impuestos
|
|
where c.TrasladooRetencion == "T"
|
|
select c.Importe).Sum();
|
|
}
|
|
}
|
|
|
|
public CFDIComplementoPagos()
|
|
{
|
|
DocumentosRelacionados = new List<CFDIComplementoPagosDocsRelacionados>();
|
|
Impuestos = new List<CFDIConceptosImpuestos>();
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIComplementoPagosDocsRelacionados
|
|
{
|
|
public string IdDocumento { get; set; } = "";
|
|
public string Serie { get; set; } = "";
|
|
public string Folio { get; set; } = "";
|
|
public string MonedaDR { get; set; } = "";
|
|
public string MetodoDePagoDR { get; set; } = "";
|
|
public decimal TipoCambioDR { get; set; }
|
|
public int NumParcialidad { get; set; } = 1;
|
|
public decimal ImpSaldoAnt { get; set; }
|
|
public decimal ImpPagado { get; set; }
|
|
public decimal ImpSaldoInsoluto { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIComercioExterior11
|
|
{
|
|
public string MotivoTraslado { get; set; }
|
|
public string TipoOperacion { get; set; } = "";
|
|
public string ClavedePedimento { get; set; } = "";
|
|
public string CertificadoOrigen { get; set; } = "";
|
|
public string Incoterm { get; set; } = "";
|
|
public string Subdivision { get; set; } = "";
|
|
public decimal TipoCambioUSD { get; set; }
|
|
public string NumCertificadoOrigen { get; set; } = "";
|
|
public string NumeroExportadorConfiable { get; set; } = "";
|
|
public string Observaciones { get; set; } = "";
|
|
public CFDIComercioExterior11Emisor Emisor { get; set; }
|
|
public CFDIComercioExterior11Receptor Receptor { get; set; }
|
|
public CFDIComercioExterior11Receptor Destinatario { get; set; }
|
|
public List<CFDIComercioExterior11Mercancias> Mercancias { get; set; }
|
|
public bool AplicaComercioExteriorSubProyecto { get; set; }
|
|
|
|
public decimal TotalUSD
|
|
{
|
|
get
|
|
{
|
|
return (from c in Mercancias
|
|
select c.ValorDolares).Sum();
|
|
}
|
|
}
|
|
public CFDIComercioExterior11()
|
|
{
|
|
Emisor = new CFDIComercioExterior11Emisor();
|
|
Receptor = new CFDIComercioExterior11Receptor();
|
|
Destinatario = new CFDIComercioExterior11Receptor();
|
|
Mercancias = new List<CFDIComercioExterior11Mercancias>();
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIComercioExterior11Emisor
|
|
{
|
|
public string CURP { get; set; } = "";
|
|
public string Calle { get; set; } = "";
|
|
public string NumeroExterior { get; set; } = "";
|
|
public string NumeroInterior { get; set; } = "";
|
|
public string Colonia { get; set; } = "";
|
|
public string Localidad { get; set; } = "";
|
|
public string Referencia { get; set; } = "";
|
|
public string Municipio { get; set; } = "";
|
|
public string Estado { get; set; } = "";
|
|
public string Pais { get; set; } = "";
|
|
public string CP { get; set; } = "";
|
|
}
|
|
|
|
public class CFDIComercioExterior11Propietario
|
|
{
|
|
public string NumRegIdTrib { get; set; } = "";
|
|
public string ResidenciaFiscal { get; set; } = "";
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIComercioExterior11Receptor
|
|
{
|
|
public string NumRegIdTrib { get; set; } = "";
|
|
public string Nombre { get; set; } = "";
|
|
public string Calle { get; set; } = "";
|
|
public string NumeroExterior { get; set; } = "";
|
|
public string NumeroInterior { get; set; } = "";
|
|
public string Colonia { get; set; } = "";
|
|
public string Localidad { get; set; } = "";
|
|
public string Referencia { get; set; } = "";
|
|
public string Municipio { get; set; } = "";
|
|
public string Estado { get; set; } = "";
|
|
public string CP { get; set; } = "";
|
|
public string Pais { get; set; } = "";
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIComercioExterior11Mercancias
|
|
{
|
|
public string NoIdentificacion { get; set; } = "";
|
|
public string FraccionArancelaria { get; set; } = "";
|
|
public string UnidadAduana { get; set; } = "";
|
|
public decimal CantidadAduana { get; set; }
|
|
public decimal ValorUnitarioAduana { get; set; }
|
|
public decimal ValorDolares { get; set; }
|
|
public CFDIComercioExterior11MercanciasDescripcionesEspecificas DescripcionesEspecificas { get; set; } = new CFDIComercioExterior11MercanciasDescripcionesEspecificas();
|
|
}
|
|
|
|
[Serializable]
|
|
public class CFDIComercioExterior11MercanciasDescripcionesEspecificas
|
|
{
|
|
public string Marca { get; set; } = "";
|
|
public string Modelo { get; set; } = "";
|
|
public string SubModelo { get; set; } = "";
|
|
public string NumeroSerie { get; set; } = "";
|
|
}
|
|
}
|