-- no subir, cambios a medio terminar, continuará oscar
This commit is contained in:
@@ -1047,7 +1047,7 @@
|
||||
<div class="modal-footer">
|
||||
<asp:UpdatePanel runat="server">
|
||||
<ContentTemplate>
|
||||
<asp:Button ID="BtnGuardarFaturas" runat="server" ClientIDMode="Static" Text="Aceptar" CssClass="btn btn-primary" />
|
||||
<asp:Button ID="BtnSubirFacturas" runat="server" ClientIDMode="Static" Text="Aceptar" CssClass="btn btn-primary" />
|
||||
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancelar</button>
|
||||
</ContentTemplate>
|
||||
</asp:UpdatePanel>
|
||||
|
||||
@@ -18,6 +18,7 @@ Imports Extensiones
|
||||
Imports Microsoft.Reporting.WebForms
|
||||
Imports Newtonsoft.Json.Linq
|
||||
Imports ClsPaginas
|
||||
Imports ADS.eFacturas
|
||||
|
||||
|
||||
|
||||
@@ -778,25 +779,24 @@ Partial Class Compras_eFacturas
|
||||
MostrarSolcitudesSAT()
|
||||
|
||||
If UsuarioActual.CveRol = 1 Then
|
||||
GVSolicitudesPendientes.Columns(8).Visible = True
|
||||
End If
|
||||
GVSolicitudesPendientes.Columns(8).Visible = True
|
||||
End If
|
||||
|
||||
'CARGA REGISTRO DE FACTURA
|
||||
|
||||
CargaClasificacionesComprobaciones()
|
||||
CargaClasificaciones()
|
||||
CargaPS(-1)
|
||||
CargaPersoanlCajaChica()
|
||||
CargaPersonalViaticos()
|
||||
CargaDdlRetIVA()
|
||||
CargaDdlRetISR()
|
||||
'CargaClasificacionesComprobaciones()
|
||||
'CargaClasificaciones()
|
||||
'CargaPS(-1)
|
||||
'CargaPersoanlCajaChica()
|
||||
'CargaPersonalViaticos()
|
||||
'CargaDdlRetIVA()
|
||||
'CargaDdlRetISR()
|
||||
|
||||
Dim LblSubProyectoTemp As New Label
|
||||
CargarCentrosDeCosto(Nothing, DdlSubProyecto, Nothing, LblSubProyectoTemp, "Seleccione")
|
||||
LblSubProyecto.InnerText = $"{LblSubProyectoTemp.Text}:"
|
||||
|
||||
End If
|
||||
removeasincevent()
|
||||
CargarCentrosDeCosto(Nothing, DdlSubProyecto, Nothing, LblSubProyectoTemp, "Seleccione")
|
||||
LblSubProyecto.InnerText = $"{LblSubProyectoTemp.Text}:"
|
||||
End If
|
||||
removeasincevent()
|
||||
End Sub
|
||||
|
||||
Protected Sub BtnConsultar_Click(sender As Object, e As System.EventArgs) Handles BtnConsultar.Click
|
||||
@@ -1489,14 +1489,12 @@ Partial Class Compras_eFacturas
|
||||
Private Sub LnkSubirFacturas_Click(sender As Object, e As EventArgs) Handles LnkSubirFacturas.Click
|
||||
RegistraScript(String.Format("$('#{0}').modal();", "ModalFacturas"))
|
||||
End Sub
|
||||
Private Sub BtnGuardarFaturas_Click(sender As Object, e As EventArgs) Handles BtnGuardarFaturas.Click
|
||||
|
||||
If UsuarioActual.Empresa.SendMail.Trim.Length = 0 Then
|
||||
Alert("La Empresa no tiene configurado el envió de correo.", TipoMensaje.MsgAdvertencia)
|
||||
Exit Sub
|
||||
End If
|
||||
|
||||
Private Sub BtnSubirFacturas_Click(sender As Object, e As EventArgs) Handles BtnSubirFacturas.Click
|
||||
|
||||
'If UsuarioActual.Empresa.SendMail.Trim.Length = 0 Then
|
||||
' Alert("La Empresa no tiene configurado el envió de correo.", TipoMensaje.MsgAdvertencia)
|
||||
' Exit Sub
|
||||
'End If
|
||||
|
||||
Dim sw As New Diagnostics.Stopwatch
|
||||
Dim swmili As Long = 0
|
||||
@@ -1512,8 +1510,6 @@ Partial Class Compras_eFacturas
|
||||
Dim ListPDF As New List(Of String)
|
||||
Dim ListDirectorios As New List(Of String)
|
||||
|
||||
|
||||
|
||||
For Each fileItem As Archivo In filesgral
|
||||
FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "")
|
||||
filemove = fileItem.filename
|
||||
@@ -1546,33 +1542,15 @@ Partial Class Compras_eFacturas
|
||||
sOnlyFilename = System.IO.Path.GetFileName(filePath)
|
||||
|
||||
If ArchivoExtension.ToUpper = "RAR" Or ArchivoExtension.ToUpper = "ZIP" Then
|
||||
'ListaComprimidos.Add(filePath)
|
||||
''CREO DIRECTORIO ALEATORIO
|
||||
'Dim Aleatorio As New Random
|
||||
'Dim TempDirectorio As String = String.Format("{0}{1}\{2}{3}", UsuarioActual.Empresa.Ruta, "Temp\Facturas", NowADS().Ticks, Aleatorio.Next(100, 999))
|
||||
'Directory.CreateDirectory(TempDirectorio)
|
||||
'ListaDirectoriosTemporales.Add(TempDirectorio)
|
||||
''AGREGA DIRECTORIO A LA LISTA
|
||||
'ListDirectorios.Add(TempDirectorio)
|
||||
''DESCOMPRIME RAR
|
||||
'DescomprimeFacturas(filePath, TempDirectorio)
|
||||
''AGREGA XML A LA LISTA
|
||||
'ListXML.AddRange(Directory.GetFiles(TempDirectorio))
|
||||
|
||||
ListXML.Add(filePath)
|
||||
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
Dim Arreglo As New ArrayList()
|
||||
' Dim Archivos As String() = Directory.GetFiles(String.Format("{0}Empresas\{1}\Temp", ModExtensiones.DirectorioBaseEmpresas, UsuarioActual.CveEmpresa))
|
||||
'Dim NombreArchivo As String
|
||||
Dim Bandera As Boolean = True
|
||||
Dim Retorno As String = ""
|
||||
Dim ListaArchivosMail As New List(Of ClsSisMail.ArchivoMail)
|
||||
|
||||
|
||||
sw.Stop()
|
||||
swTiempo.AppendFormat("ReadFiles: ({0}) {1} ", sw.ElapsedMilliseconds - swmili, sw.ElapsedMilliseconds)
|
||||
swmili = sw.ElapsedMilliseconds
|
||||
@@ -1584,12 +1562,14 @@ Partial Class Compras_eFacturas
|
||||
For Each filePath As String In ListXML
|
||||
|
||||
If File.Exists(filePath) Then
|
||||
Dim ArchivoAdjunto As New ClsSisMail.ArchivoMail
|
||||
ArchivoAdjunto.ArchivoBinario = File.ReadAllBytes(filePath)
|
||||
ArchivoAdjunto.Ruta = filePath
|
||||
ArchivoAdjunto.NombreArchivo = New FileInfo(filePath).Name
|
||||
Dim a As New ComprobanteFactura
|
||||
Dim FF As Factura = a.CargaComprobanteXML(File.ReadAllText(filePath))
|
||||
'Dim ArchivoAdjunto As New ClsSisMail.ArchivoMail
|
||||
'ArchivoAdjunto.ArchivoBinario = File.ReadAllBytes(filePath)
|
||||
'ArchivoAdjunto.Ruta = filePath
|
||||
'ArchivoAdjunto.NombreArchivo = New FileInfo(filePath).Name
|
||||
|
||||
ListaArchivosMail.Add(ArchivoAdjunto)
|
||||
'ListaArchivosMail.Add(ArchivoAdjunto)
|
||||
|
||||
End If
|
||||
|
||||
@@ -7066,6 +7046,532 @@ End Class
|
||||
|
||||
|
||||
|
||||
Namespace ADS.eFacturas
|
||||
Public Class Factura
|
||||
Public Property CveEmpresa As Integer
|
||||
Public Property Version As String
|
||||
Public Property Serie As String
|
||||
Public Property Folio As String
|
||||
Public Property Fecha As Date
|
||||
Public Property SubTotal As Decimal
|
||||
Public Property Total As Decimal
|
||||
Public Property Moneda As String
|
||||
Public Property CveMoneda As Integer
|
||||
Public Property TipoComprobante As String
|
||||
Public Property Descuento As Decimal
|
||||
Public Property TipoCambio As Decimal
|
||||
Public Property MetododePago As String
|
||||
Public Property EmisorRFC As String
|
||||
Public Property EmisorNombre As String
|
||||
Public Property EmisorRegimenFiscal As String
|
||||
Public Property ReceptorRFC As String
|
||||
Public Property ReceptorNombre As String
|
||||
Public Property ReceptorUsoCFDI As String
|
||||
Public Property TotalRetenciones As Decimal
|
||||
Public Property SumaTotalRetenciones As Decimal
|
||||
Public Property TotalTraslados As Decimal
|
||||
Public Property SumaTotalTraslados As Decimal
|
||||
Public Property TrasladoIVA As Decimal
|
||||
Public Property TrasladoIEPS As Decimal
|
||||
Public Property TrasladoISR As Decimal
|
||||
Public Property RetencionIVA As Decimal
|
||||
Public Property RetencionISR As Decimal
|
||||
Public Property sUPPrefijo As String
|
||||
Public Property UUID As String
|
||||
Public Property Validada As Integer
|
||||
Public Property ArchivoXML As String
|
||||
Public Property ArchivoPDF As String
|
||||
Public Property Pagos As List(Of Pago)
|
||||
End Class
|
||||
|
||||
Public Class Pago
|
||||
Public Property FechaPago As DateTime
|
||||
Public Property FormaDePagoP As String
|
||||
Public Property MonedaP As String
|
||||
Public Property Monto As Decimal
|
||||
Public Property Documentos As List(Of DoctoRelacionado)
|
||||
End Class
|
||||
|
||||
Public Class DoctoRelacionado
|
||||
Public Property Serie As String
|
||||
Public Property Folio As String
|
||||
Public Property ImportePago As Decimal
|
||||
Public Property ImpSaldoAnt As Decimal
|
||||
Public Property ImpSaldoInsoluto As Decimal
|
||||
Public Property idDocumento As String
|
||||
Public Property MonedaDR As String
|
||||
Public Property MetodoDePagoDR As String
|
||||
Public Property NumParcialidad As String
|
||||
End Class
|
||||
|
||||
Public Class ComprobanteFactura
|
||||
Public Property Pagos As List(Of Pago)
|
||||
Public Property XMLNodosPagos As String
|
||||
Public Property XMLNodosPagosCount As Integer
|
||||
Private Function CargaFactVersion33(CveEmpresa As Integer, ByRef node As XmlNode, ByRef nodo As XmlNode, ByRef XMLDoc As XmlDocument, ByVal Prefijo As String, ByRef namespaces As XmlNamespaceManager, ByVal VersionCFDI As String) As Factura
|
||||
Dim Fact = New Factura()
|
||||
Fact.Version = VersionCFDI
|
||||
Fact.CveEmpresa = CveEmpresa
|
||||
Fact.Serie = CaratecteresvalidosFolio(ValorXML(nodo, "serie"))
|
||||
If Not String.IsNullOrEmpty(Fact.Serie) Then Fact.Serie = Fact.Serie
|
||||
Fact.Folio = ValorXML(nodo, "folio").TrimStart("0"c)
|
||||
Fact.Fecha = ValorXML(nodo, "fecha").ToDateTime
|
||||
Fact.SubTotal = ValorXML(nodo, "subTotal").Replace("..", ".").ToDecimal
|
||||
Fact.Total = ValorXML(nodo, "total").ToDecimal
|
||||
Fact.Moneda = ValorXML(nodo, "Moneda")
|
||||
Fact.MetododePago = ValorXML(nodo, "MetododePago")
|
||||
Fact.TipoComprobante = ValorXML(nodo, "tipoDeComprobante")
|
||||
Fact.TipoCambio = ValorXML(nodo, "TipoCambio", "1.0").ToDecimal
|
||||
If Fact.TipoCambio < 1 Then Fact.TipoCambio = 1
|
||||
|
||||
If Fact.TipoComprobante = "P" Then
|
||||
Dim PagoPrefix As String = ""
|
||||
|
||||
If VersionCFDI = "3.3" Then
|
||||
PagoPrefix = "pago10"
|
||||
namespaces.AddNamespace("pago10", "http://www.sat.gob.mx/Pagos")
|
||||
ElseIf VersionCFDI = "4.0" Then
|
||||
PagoPrefix = "pago20"
|
||||
namespaces.AddNamespace("pago20", "http://www.sat.gob.mx/Pagos20")
|
||||
End If
|
||||
|
||||
Dim NodoComplementos As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Complemento", Prefijo), namespaces)
|
||||
Dim nodePagos As XmlNode = NodoComplementos.SelectSingleNode($"//{PagoPrefix}:Pagos", namespaces)
|
||||
|
||||
For Each nPago As XmlNode In nodePagos.ChildNodes
|
||||
Fact.Total = ValorXML(nPago, "Monto").ToDecimal
|
||||
If VersionCFDI = "4.0" And nPago.LocalName.ToUpper() = "TOTALES" Then
|
||||
Continue For
|
||||
Else
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
Fact.sUPPrefijo = Prefijo
|
||||
node = XMLDoc.SelectSingleNode(String.Format("//{0}:Emisor", Prefijo), namespaces)
|
||||
|
||||
If node IsNot Nothing AndAlso node.Attributes.Count > 0 Then
|
||||
Fact.EmisorRFC = ValorXML(node, "RFC").Trim()
|
||||
Fact.EmisorNombre = ValorXML(node, "nombre")
|
||||
End If
|
||||
|
||||
node = XMLDoc.SelectSingleNode(String.Format("//{0}:Receptor", Prefijo), namespaces)
|
||||
|
||||
If node IsNot Nothing Then
|
||||
Fact.ReceptorRFC = ValorXML(node, "RFC").Trim()
|
||||
End If
|
||||
|
||||
If XMLDoc.HasChildNodes Then
|
||||
node = XMLDoc.ChildNodes(0).ChildNodes.Cast(Of XmlNode)().Where(Function(n, b) n.Name.Equals(String.Format("{0}:Impuestos", Prefijo), StringComparison.OrdinalIgnoreCase)).FirstOrDefault()
|
||||
|
||||
If XMLDoc.ChildNodes.Count > 1 Then
|
||||
node = XMLDoc.ChildNodes(1).ChildNodes.Cast(Of XmlNode)().Where(Function(n, b) n.Name.Equals(String.Format("{0}:Impuestos", Prefijo), StringComparison.OrdinalIgnoreCase)).FirstOrDefault()
|
||||
End If
|
||||
End If
|
||||
|
||||
If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then
|
||||
|
||||
Try
|
||||
Dim nodeRetenciones = node.ChildNodes.Cast(Of XmlNode)().Where(Function(n, b) n.Name.Equals(String.Format("{0}:Retenciones", Prefijo), StringComparison.OrdinalIgnoreCase))
|
||||
Fact.TotalRetenciones = ValorXML(node, "totalImpuestosRetenidos", "0").ToDecimal
|
||||
|
||||
Try
|
||||
Dim retenciones = nodeRetenciones.FirstOrDefault().ChildNodes
|
||||
|
||||
For Each retencion As XmlNode In retenciones
|
||||
Dim TipoImpuesto As String = ValorXML(retencion, "impuesto")
|
||||
Dim importe As Decimal = ValorXML(retencion, "importe").ToDecimal
|
||||
|
||||
If TipoImpuesto = "002" Then
|
||||
Fact.RetencionIVA += importe
|
||||
End If
|
||||
|
||||
If TipoImpuesto = "001" Then
|
||||
Fact.RetencionISR += importe
|
||||
End If
|
||||
Next
|
||||
|
||||
Catch ex As Exception
|
||||
End Try
|
||||
|
||||
Fact.SumaTotalRetenciones += Fact.RetencionIVA
|
||||
Fact.SumaTotalRetenciones += Fact.RetencionISR
|
||||
Fact.TotalTraslados = ValorXML(node, "totalImpuestosTrasladados", "0").ToDecimal
|
||||
Dim nodeTraslados = node.ChildNodes.Cast(Of XmlNode)().Where(Function(n, b) n.Name.Equals(String.Format("{0}:Traslados", Prefijo), StringComparison.OrdinalIgnoreCase))
|
||||
Dim traslados = nodeTraslados.FirstOrDefault().ChildNodes
|
||||
|
||||
For Each traslado As XmlNode In traslados
|
||||
Dim TipoImpuesto As String = ValorXML(traslado, "impuesto")
|
||||
Dim importe As Decimal = ValorXML(traslado, "importe").ToDecimal()
|
||||
|
||||
If TipoImpuesto = "003" Then
|
||||
Fact.TrasladoIEPS += importe
|
||||
End If
|
||||
|
||||
If TipoImpuesto = "002" Then
|
||||
Fact.TrasladoIVA += importe
|
||||
End If
|
||||
|
||||
If TipoImpuesto = "001" Then
|
||||
Fact.TrasladoISR += importe
|
||||
End If
|
||||
Next
|
||||
|
||||
Fact.SumaTotalTraslados += Fact.TrasladoIVA + Fact.TrasladoIEPS
|
||||
Catch ex As Exception
|
||||
ex.ToString().GuardaLog()
|
||||
End Try
|
||||
End If
|
||||
|
||||
Dim nodeComp As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Complemento", Prefijo), namespaces)
|
||||
|
||||
If nodeComp IsNot Nothing AndAlso nodeComp.ChildNodes.Count > 0 Then
|
||||
Dim nodeTFD As XmlNode = nodeComp.SelectSingleNode(String.Format("//{0}:TimbreFiscalDigital", "tfd"), namespaces)
|
||||
Fact.UUID = ValorXML(nodeTFD, "UUID", "")
|
||||
Dim nodeRF As XmlNode = nodeComp.SelectSingleNode(String.Format("//{0}:CFDIRegistroFiscal ", "registrofiscal"), namespaces)
|
||||
|
||||
If nodeRF IsNot Nothing Then
|
||||
Fact.Folio = ValorXML(nodeRF, "folio").TrimStart("0"c)
|
||||
End If
|
||||
Else
|
||||
Fact.UUID = ""
|
||||
|
||||
If String.IsNullOrEmpty(Fact.UUID) AndAlso Fact.sUPPrefijo.ToLower() = "cfdi" Then
|
||||
'Mensajes.AppendFormat("{0}|{1}|{2}|{3}|{4}|{5}{6}&", ValorXML(nodo, "serie"), ValorXML(nodo, "folio"), ValorXML(nodo, "fecha").ToDate().ToShortDateString(), Fact.EmisorNombre, ValorXML(nodo, "total").ToDouble().FormatoNumero(), "Factura no timbrada correctamente.", "")
|
||||
'CargaMensaje(ValorXML(nodo, "serie"), ValorXML(nodo, "folio"), ValorXML(nodo, "fecha").ToDate(), Fact.EmisorNombre, ValorXML(nodo, "total").ToDouble(), "Factura no timbrada correctamente.", CorreoActual, DateTime.Now, _EmiRFC, 0)
|
||||
End If
|
||||
|
||||
Fact = Nothing
|
||||
End If
|
||||
|
||||
If Fact.TipoComprobante = "P" Then
|
||||
CargaPagos(XMLDoc)
|
||||
End If
|
||||
|
||||
Return Fact
|
||||
End Function
|
||||
|
||||
Private Sub CargaPagos(ByVal XMLDoc As XmlDocument)
|
||||
Dim nodo = XMLDoc.DocumentElement
|
||||
Dim Prefijo As String = If(String.IsNullOrEmpty(XMLDoc.DocumentElement.Prefix), "cfd", XMLDoc.DocumentElement.Prefix)
|
||||
Dim cfdVer As String = "http://www.sat.gob.mx/cfd/3"
|
||||
Dim namespaces As XmlNamespaceManager = New XmlNamespaceManager(XMLDoc.NameTable)
|
||||
Dim Version = ValorXML(nodo, "version").Replace("..", ".")
|
||||
Dim PrefijoPagos As String = ""
|
||||
If Prefijo.ToLower() <> "cfdi" Then cfdVer = "http://www.sat.gob.mx/cfd/2"
|
||||
|
||||
If Version = "3.3" Then
|
||||
PrefijoPagos = "pago10"
|
||||
namespaces.AddNamespace(PrefijoPagos, "http://www.sat.gob.mx/Pagos")
|
||||
Prefijo = "cfdi"
|
||||
cfdVer = "http://www.sat.gob.mx/cfd/3"
|
||||
namespaces.AddNamespace(Prefijo, cfdVer)
|
||||
ElseIf Version = "4.0" Then
|
||||
PrefijoPagos = "pago20"
|
||||
namespaces.AddNamespace(PrefijoPagos, "http://www.sat.gob.mx/Pagos20")
|
||||
Prefijo = "cfdi"
|
||||
cfdVer = "http://www.sat.gob.mx/cfd/4"
|
||||
namespaces.AddNamespace(Prefijo, cfdVer)
|
||||
Else
|
||||
End If
|
||||
|
||||
Dim nodeComp As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Complemento", Prefijo), namespaces)
|
||||
|
||||
If Version = "3.2" Then
|
||||
ElseIf Version = "3.3" OrElse Version = "4.0" Then
|
||||
|
||||
If nodeComp IsNot Nothing AndAlso nodeComp.ChildNodes.Count > 0 Then
|
||||
Dim NodosNodePagos As XmlNodeList = nodeComp.SelectNodes($"//{PrefijoPagos}:Pago", namespaces)
|
||||
|
||||
If NodosNodePagos IsNot Nothing Then
|
||||
|
||||
Try
|
||||
Dim nodePagos As XmlNode = nodeComp.SelectSingleNode($"//{PrefijoPagos}:Pagos", namespaces)
|
||||
|
||||
If Version = "3.3" Then
|
||||
XMLNodosPagos = nodePagos.InnerXml.Replace("pago10:", "").Replace("pagos10:", "").Replace(PrefijoPagos & ":", "")
|
||||
Else
|
||||
XMLNodosPagos = nodePagos.InnerXml.Replace("pago20:", "").Replace("pagos20:", "").Replace(PrefijoPagos & ":", "")
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
ModExtensiones.GuardaLog(ex.ToString())
|
||||
End Try
|
||||
End If
|
||||
|
||||
Dim Pagos = New List(Of Pago)()
|
||||
Dim FechaPago As Date
|
||||
For Each nodePago As XmlNode In NodosNodePagos
|
||||
|
||||
Try
|
||||
FechaPago = ValorXML(nodePago, "FechaPago").ToDate()
|
||||
Catch e As Exception
|
||||
End Try
|
||||
|
||||
Dim pago = New Pago()
|
||||
pago.FechaPago = FechaPago
|
||||
pago.FormaDePagoP = ValorXML(nodePago, "FormaDePagoP").ToString()
|
||||
pago.MonedaP = ValorXML(nodePago, "MonedaP").ToString()
|
||||
pago.Monto = ValorXML(nodePago, "Monto").ToString().ToDecimal()
|
||||
Dim docs = New List(Of DoctoRelacionado)()
|
||||
Dim NodosPagosRelacionados As XmlNodeList = nodePago.SelectNodes($"//{PrefijoPagos}:DoctoRelacionado", namespaces)
|
||||
|
||||
For Each docto As XmlNode In NodosPagosRelacionados
|
||||
Dim idDoc = ValorXML(docto, "idDocumento")
|
||||
Dim ImportePago = ValorXML(docto, "ImpPagado").ToDecimal()
|
||||
Dim serie = ValorXML(docto, "Serie")
|
||||
Dim Folio = ValorXML(docto, "Folio")
|
||||
Dim MonedaDR = ValorXML(docto, "MonedaDR")
|
||||
Dim MetodoDePagoDR = ValorXML(docto, "MetodoDePagoDR")
|
||||
Dim NumParcialidad = ValorXML(docto, "NumParcialidad")
|
||||
Dim ImpSaldoInsoluto = ValorXML(docto, "ImpSaldoInsoluto").ToDecimal()
|
||||
Dim ImpSaldoAnt = ValorXML(docto, "ImpSaldoAnt").ToDecimal()
|
||||
docs.Add(New DoctoRelacionado() With {
|
||||
.idDocumento = idDoc,
|
||||
.ImportePago = ImportePago,
|
||||
.Serie = serie,
|
||||
.Folio = Folio,
|
||||
.MonedaDR = MonedaDR,
|
||||
.MetodoDePagoDR = MetodoDePagoDR,
|
||||
.NumParcialidad = NumParcialidad,
|
||||
.ImpSaldoAnt = ImpSaldoAnt,
|
||||
.ImpSaldoInsoluto = ImpSaldoInsoluto
|
||||
})
|
||||
Next
|
||||
|
||||
pago.Documentos = docs
|
||||
Pagos.Add(pago)
|
||||
Next
|
||||
|
||||
Me.Pagos = Pagos
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
Private Function ValorXML(n As XmlNode, Campo As String, Optional Retorno As String = "") As String
|
||||
Dim o As XmlNode = n.Attributes.Cast(Of XmlAttribute)().SingleOrDefault(Function(a) String.Compare(a.Name, Campo, True) = 0)
|
||||
If o Is Nothing Then
|
||||
Return Retorno
|
||||
Else
|
||||
Return o.Value
|
||||
End If
|
||||
End Function
|
||||
Private Function CaratecteresvalidosFolio(ByVal Folio As String) As String
|
||||
Dim Respuesta As String = ""
|
||||
|
||||
'For Each c As Char In Folio.ToArray()
|
||||
|
||||
' If (c >= 48 AndAlso c <= 57) OrElse (c >= 65 AndAlso c <= 90) OrElse (c >= 97 AndAlso c <= 122) Then
|
||||
' Respuesta += c
|
||||
' End If
|
||||
'Next
|
||||
Return Respuesta
|
||||
End Function
|
||||
|
||||
'Private Sub CargaDesdeString(StrFuente As String)
|
||||
' Dim XMLCargaExistosa As Boolean = False
|
||||
' Dim XMlStr As String = StrFuente.Replace("<br>", "").Replace("<", "").Replace("o;?", "")
|
||||
' Dim XMLDoc As New XmlDocument
|
||||
' Try
|
||||
' XMLDoc.LoadXml(XMlStr)
|
||||
' XMLCargaExistosa = True
|
||||
' Catch ex As Exception
|
||||
' GuardaLog("Error al intentar leer . Error:" & ex.ToString())
|
||||
' 'Errores.AppendLine("Error al intentar leer el XML. Error:" & ex.ToString())
|
||||
' XMLCargaExistosa = False
|
||||
' End Try
|
||||
|
||||
' If XMLCargaExistosa Then
|
||||
' CargaComprobanteXML(XMLDoc)
|
||||
' End If
|
||||
|
||||
'End Sub
|
||||
Public Function CargaComprobanteXML(StrFuente As String, CveEmpresa As Integer) As Factura
|
||||
Dim XMLCargaExistosa As Boolean = False
|
||||
Dim XMlStr As String = StrFuente.Replace("<br>", "").Replace("<", "").Replace("o;?", "")
|
||||
Dim XMLDoc As New XmlDocument
|
||||
Try
|
||||
XMLDoc.LoadXml(XMlStr)
|
||||
XMLCargaExistosa = True
|
||||
Catch ex As Exception
|
||||
GuardaLog("Error al intentar leer . Error:" & ex.ToString())
|
||||
'Errores.AppendLine("Error al intentar leer el XML. Error:" & ex.ToString())
|
||||
XMLCargaExistosa = False
|
||||
End Try
|
||||
|
||||
If Not XMLCargaExistosa Then Return Nothing
|
||||
|
||||
Dim nodo As XmlNode = XMLDoc.DocumentElement
|
||||
Dim Fact As Factura = New Factura()
|
||||
Fact.Serie = ValorXML(nodo, "serie")
|
||||
|
||||
Dim StrCFDIVersion As String = ValorXML(nodo, "version")
|
||||
Fact.Version = StrCFDIVersion
|
||||
|
||||
Fact.Folio = ValorXML(nodo, "folio")
|
||||
Fact.Fecha = ValorXML(nodo, "fecha").ToDate
|
||||
Fact.SubTotal = ValorXML(nodo, "subTotal").ToDecimal
|
||||
Fact.Total = ValorXML(nodo, "total").ToDecimal
|
||||
Fact.Descuento = ValorXML(nodo, "descuento").ToDecimal
|
||||
Fact.Moneda = ValorXML(nodo, "Moneda")
|
||||
|
||||
Fact.CveMoneda = ClsPaginas.GlobalDTMonedas().FiltroPrimeroValor("CveMoneda", $" AbreviaturaSAT = '{Fact.Moneda}' ").ToEntero
|
||||
'If Not CveMoneda > 0 Then
|
||||
' GuardaLog($"Moneda {Moneda} no se obtuvo la clabe")
|
||||
' Errores.AppendLine($"Moneda {Moneda} no se obtuvo la clabe")
|
||||
' XMLCargaExistosa = False
|
||||
' Exit Sub
|
||||
'End If
|
||||
|
||||
Fact.TipoComprobante = ValorXML(nodo, "tipoDeComprobante")
|
||||
Fact.TipoCambio = ValorXML(nodo, "TipoCambio", "1").ToDecimal
|
||||
|
||||
If Fact.Version = "3.3" Or Fact.Version = "4.0" Then
|
||||
Dim drm As DataRow = ClsPaginas.GlobalDTVtaMetodoPago.FiltroPrimero(String.Format("ClaveMetodoPagoSAT = '{0}'", ValorXML(nodo, "MetodoPago")))
|
||||
If drm IsNot Nothing Then
|
||||
'Fact.MetododePago = drm("CveMetodoPago").ToString.ToEntero
|
||||
Fact.MetododePago = drm("MetodoPagoSAT").ToString
|
||||
End If
|
||||
End If
|
||||
|
||||
Dim namespaces As New XmlNamespaceManager(XMLDoc.NameTable)
|
||||
Dim Prefijo As String = If(XMLDoc.DocumentElement.Prefix = "", "cfd", XMLDoc.DocumentElement.Prefix)
|
||||
Dim cfdVer As String = ""
|
||||
|
||||
If StrCFDIVersion = "3.2" Then
|
||||
Prefijo = "cfd"
|
||||
cfdVer = "http://www.sat.gob.mx/cfd/2"
|
||||
ElseIf StrCFDIVersion = "3.3" Then
|
||||
cfdVer = "http://www.sat.gob.mx/cfd/3"
|
||||
Else ' se considera que es la version 4.0
|
||||
cfdVer = "http://www.sat.gob.mx/cfd/4"
|
||||
End If
|
||||
namespaces.AddNamespace(Prefijo, cfdVer)
|
||||
namespaces.AddNamespace("aerolineas", "http://www.sat.gob.mx/aerolineas")
|
||||
namespaces.AddNamespace("tfd", "http://www.sat.gob.mx/TimbreFiscalDigital")
|
||||
namespaces.AddNamespace("implocal", "http://www.sat.gob.mx/implocal")
|
||||
namespaces.AddNamespace("registrofiscal", "http://www.sat.gob.mx/registrofiscal")
|
||||
|
||||
If Fact.TipoComprobante.ToUpper = "E" AndAlso (Fact.Version.Contiene("3.3", "4.0")) Then
|
||||
Dim UUIDS As String = ""
|
||||
|
||||
Dim UUIDSLista As New List(Of String)
|
||||
Dim nodeCFDIRelacionados As XmlNode
|
||||
nodeCFDIRelacionados = XMLDoc.SelectSingleNode(String.Format("//{0}:CfdiRelacionados", Prefijo), namespaces)
|
||||
|
||||
If nodeCFDIRelacionados IsNot Nothing Then
|
||||
For Each CFDIRelacionados As XmlNode In nodeCFDIRelacionados
|
||||
UUIDSLista.Add("" & CFDIRelacionados.Attributes("UUID").Value.ToString & "")
|
||||
Next
|
||||
End If
|
||||
'DocumentosRelacionadosUUIDSList = UUIDSLista
|
||||
End If
|
||||
|
||||
Dim node As XmlNode
|
||||
node = XMLDoc.SelectSingleNode(String.Format("//{0}:Emisor", Prefijo), namespaces)
|
||||
|
||||
If node IsNot Nothing Then
|
||||
Fact.EmisorRFC = ValorXML(node, "RFC")
|
||||
Fact.EmisorNombre = ValorXML(node, "Nombre")
|
||||
End If
|
||||
|
||||
node = XMLDoc.SelectSingleNode(String.Format("//{0}:Receptor", Prefijo), namespaces)
|
||||
|
||||
If node IsNot Nothing Then
|
||||
Fact.ReceptorRFC = ValorXML(node, "RFC")
|
||||
End If
|
||||
|
||||
'If UsuarioActual.CveEmpresa.Contiene(119, 7) Then
|
||||
' node = XMLDoc.SelectSingleNode(String.Format("//{0}:CfdiRelacionados", Prefijo), namespaces)
|
||||
' If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then
|
||||
' If ValorXML(node, "TipoRelacion").ToString.Contiene("07") Then
|
||||
' Dim nodeDocumentosRelacionados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:CfdiRelacionado", Prefijo), namespaces)
|
||||
' For Each documento As XmlNode In nodeDocumentosRelacionados
|
||||
' If documento.Attributes("UUID").Value <> "" Then
|
||||
' DocumentosRelacionadosAnticiposUUIDList.Add(documento.Attributes("UUID").Value)
|
||||
' End If
|
||||
' TieneAnticiposXML = True
|
||||
' Next
|
||||
' End If
|
||||
' End If
|
||||
'End If
|
||||
|
||||
node = XMLDoc.SelectSingleNode(String.Format("//{0}:Impuestos", Prefijo), namespaces)
|
||||
If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then
|
||||
Dim nodeRetenciones As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Comprobante/{0}:Impuestos/{0}:Retenciones/{0}:Retencion", Prefijo), namespaces)
|
||||
|
||||
If Fact.Version.Contiene("3.3", "4.0") Then
|
||||
|
||||
For Each retencion As XmlNode In nodeRetenciones
|
||||
If retencion.Attributes("Impuesto").Value = "002" Then Fact.RetencionIVA += retencion.Attributes("Importe").Value.ToDecimal
|
||||
If retencion.Attributes("Impuesto").Value = "001" Then Fact.RetencionISR += retencion.Attributes("Importe").Value.ToDecimal
|
||||
Next
|
||||
|
||||
Else
|
||||
|
||||
For Each retencion As XmlNode In nodeRetenciones
|
||||
If retencion.Attributes("impuesto").Value = "IVA" Then Fact.RetencionIVA += retencion.Attributes("importe").Value.ToDecimal
|
||||
If retencion.Attributes("impuesto").Value = "ISR" Then Fact.RetencionISR += retencion.Attributes("importe").Value.ToDecimal
|
||||
Next
|
||||
End If
|
||||
|
||||
Dim nodeTraslados As XmlNodeList = XMLDoc.SelectNodes(String.Format("//{0}:Comprobante/{0}:Impuestos/{0}:Traslados/{0}:Traslado", Prefijo), namespaces)
|
||||
|
||||
If Fact.Version.Contiene("3.3", "4.0") Then
|
||||
|
||||
For Each traslado As XmlNode In nodeTraslados
|
||||
|
||||
If traslado.Attributes("Importe") IsNot Nothing Then
|
||||
If traslado.Attributes("Impuesto").Value = "002" Then Fact.TrasladoIVA += traslado.Attributes("Importe").Value.ToDecimal
|
||||
If traslado.Attributes("Impuesto").Value = "003" Then Fact.TrasladoIEPS += traslado.Attributes("Importe").Value.ToDecimal
|
||||
End If
|
||||
Next
|
||||
Else
|
||||
|
||||
For Each traslado As XmlNode In nodeTraslados
|
||||
If traslado.Attributes("Importe") IsNot Nothing Then
|
||||
If traslado.Attributes("impuesto").Value = "IVA" Then Fact.TrasladoIVA += traslado.Attributes("importe").Value.ToDecimal
|
||||
|
||||
If traslado.Attributes("impuesto").Value = "IEPS" Then Fact.TrasladoIEPS += traslado.Attributes("importe").Value.ToDecimal
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
Dim nodeComp As XmlNode = XMLDoc.SelectSingleNode(String.Format("//{0}:Complemento", Prefijo), namespaces)
|
||||
If node IsNot Nothing AndAlso node.ChildNodes.Count > 0 Then
|
||||
|
||||
Dim nodeTFD As XmlNode = nodeComp.SelectSingleNode(String.Format("//{0}:TimbreFiscalDigital", "tfd"), namespaces)
|
||||
Fact.UUID = ValorXML(nodeTFD, "UUID", "")
|
||||
|
||||
Dim nodeRF As XmlNode = nodeComp.SelectSingleNode(String.Format("//{0}:CFDIRegistroFiscal ", "registrofiscal"), namespaces)
|
||||
If nodeRF IsNot Nothing Then
|
||||
Fact.Folio = ValorXML(nodeRF, "folio").TrimStart("0"c)
|
||||
End If
|
||||
End If
|
||||
|
||||
Dim ObjCompra As New ClsCompras
|
||||
|
||||
ObjCompra.AddFactura(Fact.Serie, Fact.Folio, Fact.Fecha, Fact.EmisorNombre, Fact.EmisorRFC, Fact.SubTotal, Fact.RetencionIVA, Fact.Total, Fact.UUID, Fact.ReceptorRFC, "", "", Fact.Version, Fact.Descuento, Fact.Moneda, Fact.TipoComprobante, Fact.TipoCambio, 0, CveEmpresa, "")
|
||||
|
||||
ObjCompra.Dispose()
|
||||
|
||||
'If XMLCargaExistosa Then
|
||||
' If Not ValidateUUID(UUID) Then
|
||||
' GuardaLog($"UUID Invalido {UUID} .")
|
||||
' Errores.AppendLine($"UUID Invalido {UUID} .")
|
||||
' XMLCargaExistosa = False
|
||||
' End If
|
||||
'End If
|
||||
|
||||
Return Fact
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
Public Class GeneralesAPIeFacturas
|
||||
|
||||
Inherits ADSNetLibraryzdE.HelpersE.ConexionesE.SIGAPIE.BaseSIGAPIeFacturas
|
||||
|
||||
Reference in New Issue
Block a user