primer commit subida

This commit is contained in:
Luis
2026-09-22 20:38:51 -04:00
commit 07649704b1
10247 changed files with 3271751 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<SemillaModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<valor>otS/yUnnq+fg7t2NWYHLw08C50gdL83nmvdI36NG3z7+KnM8hEZi9qrBs/wh6bc2+StoNTR1zKXq5iR+E/ozfaEzdGyoYQnma7HGsJze1VVpXQ2/XH+5Dvl4yKeYv5L9Oh6m3b6YHMeCOOczkk2ZdA==</valor>
<fecha>2024-06-21T21:30:13.6000652-04:00</fecha>
<dsig:Signature xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
<dsig:SignedInfo>
<dsig:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<dsig:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<dsig:Reference URI="">
<dsig:Transforms>
<dsig:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<dsig:DigestValue>nXb0yLaO/ROdznjDktCoBJiiJCu3mhkMroAWMK1PG3Y=</dsig:DigestValue>
</dsig:Reference>
</dsig:SignedInfo>
<dsig:SignatureValue>iVV0URmAXoXOG2COIRI1WQ2r87L0VPvwTL2kpaVILFLyEUtO49PpPP9ER/EBqdal/O5NiIk0r34iottO3HJ0VDb6j/Xf4/ilA/9MRnidZ4Bz57Mx1/BZb+cJnZfLfFYsncy/zyWwZ69Oi9U0ca2v61ZVzLhI1HdNtHvlG+u/tw3rnXJBAxx+HZWxQmYIxBH1Euzg3iYfHnPSSaVMYruSuTbiUcTA72c0/Ase0s1+b7R6HhYTTgoZs51mOiNkYFhLzG94nxQmvD+HPX+dnY55vvm63zNEOze/u6rYOfyK9KyRCmg1+8kXJqDGYudKIadnNV1s33CyIXmBnQ/HZ37mug==</dsig:SignatureValue>
<dsig:KeyInfo>
<dsig:X509Data>
<dsig:X509Certificate>MIIJlTCCB32gAwIBAgIIXFONzfOEzkIwDQYJKoZIhvcNAQELBQAwgbgxFzAVBgNVBGEMDlZBVERPLTQwMTAyMzY4MSMwIQYDVQQDDBpkaWdpZmlybWEgQ0EgU3Vib3JkaW5hZGEgMTESMBAGA1UECwwJZGlnaWZpcm1hMTswOQYDVQQKDDJDw6FtYXJhIGRlIENvbWVyY2lvIHkgUHJvZHVjY2nDs24gZGUgU2FudG8gRG9taW5nbzEaMBgGA1UEBwwRRGlzdHJpdG8gTmFjaW9uYWwxCzAJBgNVBAYTAkRPMB4XDTI0MDYxMjE5NTQwMFoXDTI2MDYxMjE5NTQwMFowgcsxRjBEBgNVBAkMPUd1c3Rhdm8gTWVqw61hIFJpY2FydCAxOTcsIEVucy4gUXVpc3F1ZXlhLDAwMDAwLFNhbnRvIERvbWluZ28xJjAkBgNVBAMMHVJBRkFFTCBBTlRPTklPIFNBTkNIRVogVklMTEFSMRowGAYDVQQFExFJRENETy0wMDEwMjQ3MDQzMjEXMBUGA1UEKgwOUkFGQUVMIEFOVE9OSU8xFzAVBgNVBAQMDlNBTkNIRVogVklMTEFSMQswCQYDVQQGEwJETzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKOGVeHu6nFC/eAtlnnsj+eJMezGRPMk6Sbey4wwFhO/FYYDbaBIo3IWijLOQHSW3HFddPhmiZqwr9wfzbM8tHrQ8p6Sw2X9AzFQLfZIdAvWJo20HBiId6m0iSMK+ffPXKWuxPKpMRUD6ju/7KxYsQ2xpYOUH2y/mZofSGW1Ae0XC9pi7YDGf9pIN6AcKbnxNEVFFeAZsK40KiNObNwida/6EEj+pHF/p6VrDbTx6TJ6A21nUuVw4+SjLRc6rVh0KYRoPeQZLL7644lu0r7YsLrAPzMy24Jd70C0H2aIi6TBt03qM0qXVC8GDoP7k7LLKJjZVtJKfu37YI4M1dZzwpcCAwEAAaOCBIwwggSIMHoGCCsGAQUFBwEDBG4wbDAIBgYEAI5GAQEwCwYGBACORgEDAgEUMAgGBgQAjkYBBDA0BgYEAI5GAQUwKjAoFiJodHRwczovL2Rwcy5jYW1hcmFzYW50b2RvbWluZ28uZG8vEwJFTjATBgYEAI5GAQYwCQYHBACORgEGATCB3AYIKwYBBQUHAQEEgc8wgcwwSAYIKwYBBQUHMAKGPGh0dHBzOi8vd3d3LmNhbWFyYXNhbnRvZG9taW5nby5kby9kaWdpZmlybWEvQ0NQU0RfY2FkZW5hLmNydDA/BggrBgEFBQcwAYYzaHR0cDovL29jc3AxLmNhbWFyYXNhbnRvZG9taW5nby5kby9wdWJsaWMvcGtpL29jc3AvMD8GCCsGAQUFBzABhjNodHRwOi8vb2NzcDIuY2FtYXJhc2FudG9kb21pbmdvLmRvL3B1YmxpYy9wa2kvb2NzcC8wHQYDVR0OBBYEFHakL2lXC+7eokR61EVMqfO8HYWLMB8GA1UdIwQYMBaAFM7rpVkdIemjmSWnCkqsx5WQBhELMCoGA1UdEgQjMCGBH2RpZ2lmaXJtYUBjYW1hcmFzYW50b2RvbWluZ28uZG8wggHZBgNVHSAEggHQMIIBzDAJBgcEAIvsQAEAMIIBvQYLKwYBBAGBzHwBAwEwggGsMC4GCCsGAQUFBwIBFiJodHRwczovL2Nwcy5jYW1hcmFzYW50b2RvbWluZ28uZG8vMIIBeAYIKwYBBQUHAgIwggFqHoIBZgBDAGUAcgB0AGkAZgBpAGMAYQBkAG8AIABwAGEAcgBhACAAcAByAG8AYwBlAGQAaQBtAGkAZQBuAHQAbwBzACAAdAByAGkAYgB1AHQAYQByAGkAbwBzACAAZQBuACAAcAAxADIAIABlAG0AaQB0AGkAZABvACAAcABvAHIAIABDAEMAUABTAEQALAAgAHUAYgBpAGMAYQBkAG8AIABBAHYAZQAuACAAMgA3ACAAZABlACAAZgBlAGIAcgBlAHIAbwAgAGUAcwBxACAAdABpAHIAYQBkAGUAbgB0AGUAcwAgADIAMgA4ACAAdABvAHIAcgBlACAAZgByAGkAdQBzAGEALAAgAEwAYQAgAEUAcwBwAGUAcgBpAGwAbABhACwAIABTAGEAbgB0AG8AIABEAG8AbQBpAG4AZwBvACwAIABSAGUAcAD6AGIAbABpAGMAYQAgAEQAbwBtAGkAbgBpAGMAYQBuAGEwgY8GA1UdHwSBhzCBhDBAoD6gPIY6aHR0cDovL2NybDEuY2FtYXJhc2FudG9kb21pbmdvLmRvL3B1YmxpYy9wa2kvY3JsL0NDUFNELmNybDBAoD6gPIY6aHR0cDovL2NybDIuY2FtYXJhc2FudG9kb21pbmdvLmRvL3B1YmxpYy9wa2kvY3JsL0NDUFNELmNybDAOBgNVHQ8BAf8EBAMCBeAwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMEMCEGA1UdEQQaMBiBFmp1YW4uZi5zb3RvY0BnbWFpbC5jb20wDQYJKoZIhvcNAQELBQADggIBAGSez6j9XtwK/bSNehOiywlgi31pnJUAUl2v1kivCcarPELstfVw3aloYGem1574jDoFKyo+kR2CHAy+S9t+ZUnudGVoEZoQZv2lIKs/qpS6hva5YlPLn/01NRujq3MsI7Jrbg8d69R0Ti9v76sgvJjbua5DEy23vdl3oyrk6aYZl1fG4gCF68C4lIdBEo8yEefc1R8x5HRet+HFjsiCnLjwvY6JrnlGIGi3Dpk0mia6ADRagPnvI0EtF0PA+aNTWrzs63nX1+3hHah7umVY6DL4U2AHC+1Bl91mjjr5iIDRSbFljb0wyZvSymVk4YU1NMXZEzSfvUn3ZXz5QzvEWlfwG46UJSk21aW4Uh2kEzvQlm7wjyiYVDKShOHTsLbsCIy/2BjSMuv1XANoRGoOaqQTE4SAkajQrAYSVePaik2XfzlzrZEuoWR2T/6igPcaTOlrzPYWP8hWfCKppUJ13jd32pVfg06F/EtAedtwMkaPtEtHxKV+COqlw65ii8ToNtQpNTPZIb6IZCzIeFOGJ90O7wzN53d1PzrzBI1628rvNyervvVMUbTviDUn3Nrij/Qluv65dGJh3qTa4tDek2aJvTmqOsU7dCrUAXgA3QGK6HFZCAIfFAY0Ds9NgQ9mkFxZaiYdJZ7FUh4YJwhhW1q6j+xFjclVNJyT0TxXy5c2</dsig:X509Certificate>
</dsig:X509Data>
</dsig:KeyInfo>
</dsig:Signature>
</SemillaModel>
+600
View File
@@ -0,0 +1,600 @@
IMPORT os
IMPORT com
IMPORT XML
IMPORT UTIL
DEFINE url_semilla, url_validasemilla, url_autorizacion,
url_recepcion,url_consulta,xambiente STRING
DEFINE codigo,tokenxml,nombreFile,filexml,token,respuesta,ptipoRecepcion,xhash STRING
DEFINE doc xml.DomDocument
MAIN
DEFINE elfile,trespuesta STRING
CALL ARG_VAL(1) RETURNING elfile
#xmls primer paso
LET trespuesta = '{"trackId":"00ecf42c-b60e-49e8-8d66-c8ca5dd2e9a6","error":null,"mensaje":null}'
#LET trespuesta = '{"codigo":1,"estado":"Aceptado","mensajes":null,"encf":"E320000000008","secuenciaUtilizada":true}'
#CALL procesoencf('.\\filesXML\\funcionales\\130536392E320000000032.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\funcionales\\130536392E330000000020.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\funcionales\\130349592E430000000013.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\funcionales\\130349592E470000000012.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\funcionales\\130349592E410000000010.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\funcionales\\130349592E460000000015.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\funcionales\\130349592E440000000019.xml','certificacion','normal','envio',trespuesta)
#menores a 250
# separados
# CALL procesoencf('.\\filesXML\\menores\\resumen\\130536392E320000000011.xml','certificacion','consumo','envio',trespuesta)
# CALL procesoencf('.\\filesXML\\menores\\resumen\\130536392E320000000012.xml','certificacion','consumo','envio',trespuesta)
# CALL procesoencf('.\\filesXML\\menores\\resumen\\130536392E320000000013.xml','certificacion','consumo','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\menores\\resumen\\130536392E320000000014.xml','certificacion','consumo','envio',trespuesta)
#CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ecfmenor\\resumen\\130536392E320000000015.xml','certificacion','consumo','envio',trespuesta)
#estos son los xml para crear la el codigo de seguridad
#CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ecfmenor\\130536392E320000000011.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\menores\\118011824E320000000011.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\menores\\118011824E320000000013.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\menores\\118011824E320000000015.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\menores\\118011824E320000000014.xml','certificacion','normal','envio',trespuesta)
#originales
CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\06400138001E430000000080.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E310000000004.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E310000000007.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E310000000034.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E320000000002.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E320000000006.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E410000000007.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E410000000010.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E430000000010.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E430000000012.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E440000000007.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E440000000010.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E450000000009.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E450000000010.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E460000000008.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E460000000011.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E470000000007.xml','certificacion','normal','envio',trespuesta)
# CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E470000000009.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E330000000001.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E340000000002.xml','certificacion','normal','envio',trespuesta)
#CALL procesoencf('C:\\FullPos_Certificador\\Debug\\ElectronicaDir\\Xml\\ECF\\130536392E340000000016.xml','certificacion','normal','envio',trespuesta)
#xML comerciales
#CALL procesoencf('.\\filesXML\\comerciales_leomuebles\\131880681E310000000001.xml','certificacion','aprobacion','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\comerciales_leomuebles\\131880681E310000000002.xml','certificacion','aprobacion','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\comerciales_leomuebles\\131880681E310000000003.xml','certificacion','aprobacion','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\comerciales_leomuebles\\131880681E310000000004.xml','certificacion','aprobacion','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\comerciales_leomuebles\\131880681E310000000005.xml','certificacion','aprobacion','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\comerciales_leomuebles\\131880681E330000000001.xml','certificacion','aprobacion','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\comerciales_leomuebles\\131880681E340000000001.xml','certificacion','aprobacion','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\comerciales_leomuebles\\131880681E440000000002.xml','certificacion','aprobacion','envio',trespuesta)
#CALL procesoencf('.\\filesXML\\comerciales_leomuebles\\131880657E450000000001.xml','certificacion','aprobacion','envio',trespuesta)
END MAIN
FUNCTION procesoEncf(fileporfirmar,ambiente,tiporecepcion,xoperacion,krespuesta)
DEFINE fileporfirmar,rtoken,ambiente,tiporecepcion,xoperacion,krespuesta,trrespuesta STRING
LET ptipoRecepcion = tiporecepcion
IF ambiente <> "certificacion" THEN
IF ambiente <> "test" THEN
DISPLAY "no llego bien ",ambiente
RETURN
END IF
END IF
LET xambiente = ambiente
CALL urls()
CALL buscatoken() RETURNING codigo, tokenxml
IF codigo <> "200" THEN
DISPLAY "respuesta buscatoken: ",tokenxml," ",codigo
EXIT PROGRAM
END IF
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
CALL doc.loadFromString(tokenxml)
CALL doc.save(".\\filesXML\\TokenString.xml")
#FIRMA SEMILLA
IF os.Path.exists(".\\filesXML\\TokenString.xml") THEN
CALL firmasemilla()
ELSE
DISPLAY "NO PUDE CREAR SEMILLA"
RETURN
END IF
IF os.Path.exists(".\\filesXML\\Signature.xml") THEN
CALL validasemilla() RETURNING codigo,respuesta
ELSE
DISPLAY "NO ENCONTRE LA SEMILLA FIRMADA"
RETURN
END IF
IF respuesta IS NOT NULL THEN
LET doc = xml.DomDocument.Create()
CALL doc.loadFromString(respuesta)
CALL doc.save(".\\filesXMl\\RespuestaValida.xml")
CALL gettoken() RETURNING rtoken
LET token = rtoken
ELSE
DISPLAY "NO TENEMOS RESPUESTA DE VALIDA SEMILLA"
RETURN
END IF
#FRIMA CON GENERO
IF xoperacion <> 'consultatrackid' THEN
LET filexml = fileporfirmar
CALL firmadocumento(fileporfirmar)
LET filexml = '.\\filesXML\\firmados\\',os.Path.baseName(filexml)
CALL enviafiles(token,filexml) RETURNING codigo,respuesta
ELSE
LET token = " Bearer ",token
CALL consultaResultado(token,krespuesta) RETURNING trrespuesta
DISPLAY "consulta: ", trrespuesta
END IF
END FUNCTION
FUNCTION firmadocumento(fileafirmar)
DEFINE doc xml.DomDocument
DEFINE doc2 xml.DomDocument
DEFINE root xml.DomNode
DEFINE node xml.DomNode
DEFINE signNode xml.DomNode
DEFINE sig xml.Signature
DEFINE key xml.CryptoKey
DEFINE cert xml.CryptoX509
DEFINE index INTEGER,
fileafirmar,filefirmado STRING
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
#LET fileafirmar = '.\\filesXML\\marmotech\\originales\\',fileafirmar
DISPLAY "file ",fileafirmar
LET filexml = fileafirmar
CALL doc.load(fileafirmar)
TRY
# Create rsa key
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
CALL key.loadPEM(".\\cert\\onlyRSA.pem")
# Create an X509 certificate with the constructor of the CryptoX509 class.
LET cert = xml.CryptoX509.Create()
CALL cert.setFeature("X509Certificate",TRUE)
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
# CALL cert.loadPEM("cert509.crt")
CALL cert.loadPEM(".\\cert\\onlyCert.pem")
# Create signature object with the key to use
LET sig = xml.Signature.Create()
# Assign the CryptoKey object to the Signature object.
CALL sig.setKey(KEY)
# Assign the CryptoX509 object to the Signature object.
CALL sig.setCertificate(cert)
# Set XML node to be signed. In our case, the entire document
# LET index = sig.createReference("",
# "http://www.w3.org/2001/04/xmlenc#sha256")
LET index = sig.createReference('""',
"http://www.w3.org/2001/04/xmlenc#sha256")
# Add enveloped method to not take the XML signature node into account
# when computing the entire document.
CALL sig.appendReferenceTransformation(index,
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
# Set canonicalization method on the XML fragment to be signed.
# CALL sig.appendReferenceTransformation(index,
# "http://www.w3.org/2001/10/xml-exc-c14n#")
# Compute enveloped signature
CALL sig.compute(doc)
# Retrieve signature document
LET doc2=sig.getDocument()
# Append the signature node to the original document to get
# a valid enveloped signature
# Notice that the enveloped signature can be added anywhere in the
# original document
LET signNode = doc2.getDocumentElement() # Get Signature node
# Import it into the original document
LET node = doc.importNode(signNode,true)
# Retrieve the original document root node
LET root = doc.getDocumentElement()
# Append the signature node as last child of the original document
CALL root.appendChild(node)
# Save document with enveloped signature back to disk
CALL doc.setFeature("format-pretty-print",TRUE)
LET filefirmado = '.\\filesXML\\firmados\\',os.Path.baseName(fileafirmar)
CALL doc.save(filefirmado)
CATCH
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
END TRY
END FUNCTION
FUNCTION firmasemilla()
DEFINE doc xml.DomDocument
DEFINE doc2 xml.DomDocument
DEFINE root xml.DomNode
DEFINE node xml.DomNode
DEFINE signNode xml.DomNode
DEFINE sig xml.Signature
DEFINE key xml.CryptoKey
DEFINE cert xml.CryptoX509
DEFINE index INTEGER
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
LET filexml = ".\\filesXML\\TokenString.xml"
IF os.Path.exists(filexml) THEN
CALL doc.load(filexml)
ELSE
DISPLAY "NO LO ENCONTRE"
RETURN
END IF
TRY
# Create rsa key
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
CALL key.loadPEM(".\\cert\\onlyRSA.pem")
# Create an X509 certificate with the constructor of the CryptoX509 class.
LET cert = xml.CryptoX509.Create()
CALL cert.setFeature("X509Certificate",TRUE)
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
# CALL cert.loadPEM("cert509.crt")
CALL cert.loadPEM(".\\cert\\onlyCert.pem")
# Create signature object with the key to use
LET sig = xml.Signature.Create()
# Assign the CryptoKey object to the Signature object.
CALL sig.setKey(KEY)
# Assign the CryptoX509 object to the Signature object.
CALL sig.setCertificate(cert)
# Set XML node to be signed. In our case, the entire document
# LET index = sig.createReference("",
# "http://www.w3.org/2001/04/xmlenc#sha256")
LET index = sig.createReference('""',
"http://www.w3.org/2001/04/xmlenc#sha256")
# Add enveloped method to not take the XML signature node into account
# when computing the entire document.
CALL sig.appendReferenceTransformation(index,
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
# Set canonicalization method on the XML fragment to be signed.
# CALL sig.appendReferenceTransformation(index,
# "http://www.w3.org/2001/10/xml-exc-c14n#")
# Compute enveloped signature
CALL sig.compute(doc)
# Retrieve signature document
LET doc2=sig.getDocument()
# Append the signature node to the original document to get
# a valid enveloped signature
# Notice that the enveloped signature can be added anywhere in the
# original document
LET signNode = doc2.getDocumentElement() # Get Signature node
# Import it into the original document
LET node = doc.importNode(signNode,true)
# Retrieve the original document root node
LET root = doc.getDocumentElement()
# Append the signature node as last child of the original document
CALL root.appendChild(node)
# Save document with enveloped signature back to disk
CALL doc.setFeature("format-pretty-print",TRUE)
CALL doc.save(".\\filesXML\\Signature.xml")
CATCH
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
END TRY
END FUNCTION
FUNCTION validasemilla()
DEFINE respuesta,codigo STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
LET http_req = com.HTTPRequest.Create(url_validasemilla)
CALL http_req.setMethod("POST")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/xml")
CALL http_req.setMultipartType("form-data",NULL,NULL)
IF os.Path.exists(".\\filesXML\\Signature.xml") THEN
CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\".\\filesXML\\marmotech\\mtechSignature.xml\"")
CALL http_req.setTimeOut(15)
CALL http_req.doFileRequest(".\\filesXML\\Signature.xml")
ELSE
DISPLAY "NO LO ENCUENTRO"
RETURN 0,"FILE NO EXISTE"
END IF
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
# CALL http_req.doFileRequest("naceSignature.xml")
LET http_resp= http_req.getResponse()
LET codigo = http_resp.getStatusCode()
LET respuesta = http_resp.getTextResponse()
IF http_resp.getStatusCode() != 200 THEN
DISPLAY "error: ",codigo," ", respuesta
RETURN codigo, respuesta
END IF
DISPLAY "valida semilla: ",codigo," ", respuesta
RETURN codigo, respuesta
END FUNCTION
FUNCTION enviafiles(btoken,archivo)
DEFINE respuesta,btoken,codigo,archivo,contenido,consultaResp STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
LET btoken =" Bearer ",btoken
DISPLAY "url ",url_recepcion
LET http_req = com.HTTPRequest.Create(url_recepcion)
CALL http_req.setMethod("POST")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/json")
CALL http_req.setHeader("Authorization",btoken)
CALL http_req.setMultipartType("form-data",NULL,NULL)
# "form-data; name=\"xml\"; filename=\"naceSignature.xml\""
# LET archivo = "101521262E310000000001.xml"
IF os.Path.exists(archivo) THEN
DISPLAY "archivo: ",archivo
LET contenido = "form-data; name=\"xml\"; filename=",os.path.basename(archivo)
#CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"130337391E310000000005.XML\"")
CALL http_req.setHeader("Content-Disposition", contenido)
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"130337391E310000000016.xml\"")
CALL http_req.doFileRequest(archivo)
LET http_resp= http_req.getResponse()
LET codigo = http_resp.getStatusCode()
LET respuesta= http_resp.getTextResponse()
IF http_resp.getStatusCode() != 200 THEN
DISPLAY "error: ",codigo," ", respuesta
RETURN codigo, respuesta
END IF
ELSE
RETURN 0,"FILE NO EXISTE"
END IF
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
# CALL http_req.doFileRequest("naceSignature.xml")
DISPLAY "enviafile: ",codigo," ", respuesta
IF ptipoRecepcion <> "aprobacion" THEN
CALL consultaResultado(btoken,respuesta) RETURNING consultaResp
DISPLAY "responde consulta: ",consultaResp
END IF
RETURN codigo, respuesta
END FUNCTION
FUNCTION gettoken()
DEFINE i, l INTEGER
DEFINE r om.XmlReader
DEFINE e,tok String
DEFINE a om.SaxAttributes
DISPLAY "filexml: ",filexml
LET r = om.XmlReader.createFileReader(".\\filesXML\\RespuestaValida.xml")
LET l = 0
LET e = r.read()
WHILE e IS NOT NULL
CASE e
WHEN "StartDocument"
# DISPLAY "StartDocument:"
WHEN "StartElement"
LET l=l+1
#DISPLAY l SPACES, "StartElement:", r.getTagName()
LET a = r.getAttributes()
FOR i=1 to a.getLength()
IF a.getName(i) = "token" THEN
# DISPLAY l SPACES," ",
# a.getName(i)," = ",
# a.getValueByIndex(i)
END IF
END FOR
WHEN "Characters"
IF r.getTagName() = "token" THEN
LET tok = r.getCharacters()
# DISPLAY "token dentro de gettoken: ",tok
EXIT CASE
END IF
WHEN "SkippedEntity"
# DISPLAY "Entity:'",r.skippedEntity(),"'"
WHEN "EndElement"
# DISPLAY l SPACES, "EndElement:", r.getTagName()
LET l=l-1
WHEN "EndDocument"
# DISPLAY "EndDocument:"
OTHERWISE
# DISPLAY "Invalid event: ",e
END CASE
LET e=r.read()
END WHILE
RETURN tok
END FUNCTION
FUNCTION buscatoken()
DEFINE respuesta STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
#SELECT a.urltoken INTO url FROM companias a
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
LET http_req = com.HTTPRequest.Create(url_semilla)
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/xml")
CALL http_req.doRequest()
#CALL http_req.doTextRequest(url)
LET http_resp= http_req.getResponse()
IF http_resp.getStatusCode() != 200 THEN
RETURN http_resp.getStatusCode(), http_resp.getTextResponse()
END IF
LET respuesta = http_resp.getTextResponse()
RETURN http_resp.getStatusCode(),respuesta
END FUNCTION
FUNCTION urls()
IF xambiente = "test" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/ecf/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/ecf/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/ecf/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/ecf/ConsultaResultado/api/consultas/estado"
END IF
IF xambiente = "certificacion" THEN
IF ptipoRecepcion = 'aprobacion' THEN
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/aprobacioncomercial/api/aprobacioncomercial"
DISPLAY url_recepcion
END IF
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/CerteCF/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/CerteCF/ConsultaResultado/api/consultas/estado"
END IF
IF xambiente = "test" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/TesteCF/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/TesteCF/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/TesteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/TesteCF/ConsultaResultado/api/consultas/estado"
END IF
END FUNCTION
FUNCTION consultaResultado(ctoken,data)
DEFINE data,ctoken STRING
DEFINE crespuesta STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
DEFINE dtrackid RECORD
trackid,ERROR,mensaje STRING
END RECORD
CALL util.JSON.parse(data,dtrackid)
DISPLAY "TRACK: ",dtrackid.trackid
#SELECT a.urltoken INTO url FROM companias a
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
LET url_consulta = url_consulta CLIPPED,"?TrackId=",dtrackid.trackid CLIPPED
LET http_req = com.HTTPRequest.Create(url_consulta)
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/json")
CALL http_req.setHeader("Authorization",ctoken)
CALL http_req.doRequest()
LET http_resp= http_req.getResponse()
LET crespuesta = http_resp.getTextResponse()
IF http_resp.getStatusCode() != 200 THEN
RETURN crespuesta
END IF
RETURN crespuesta
END FUNCTION
File diff suppressed because it is too large Load Diff
+898
View File
@@ -0,0 +1,898 @@
IMPORT util
IMPORT security
SCHEMA sistemas
DEFINE montoFactura DECIMAL(18,2)
DEFINE a om.SaxAttributes
DEFINE out om.SaxDocumentHandler,
i INT,
ruta_originales STRING,
fechaFirma DATETIME YEAR TO SECOND
DEFINE buf base.StringBuffer
DEFINE r_documento_encabezado RECORD
tipoEcf,eNcf,indicadorMontoGravado,tipoPago,fechaLimitePago,FormadePAgo,montoPago,FechaVencimientoSecuencia,
rncEmisor,razonSocialEmisor,direccionEmisor,Municipio,Provincia,telefonoEmisor,
correoEmisor,webSite,codigoVendedor,numeroFacturaInterna,numeroPedidoInterno,
fechaEmision,rncComprador,razonSocialComprador,montoGravadoTotal,montoGravadoI1,
montoGravadoI2,montoGravadoI3,montoExento,itbis1,itbis2,itbis3,totalItbis,totalItbis1,
totalItbis2,totalItbis3,montoTotal,tipoIngreso,terminoPago,TipoCuentaPago,NumeroCuentaPago,IdentificadorExtranjero,
contactoComprador,CorreoComprador,DireccionComprador,MunicipioComprador,ProvinciaComprador,FechaEntrega,FechaOrdenCompra,
NumeroOrdenCompra,CodigoInternoComprador,
nombreFile,IndicadorNotaCredito,NCFmodificado,codigoModificacion,fechaNCFmodificado STRING
END RECORD,
comando,nombreFile STRING
DEFINE r_documento_Detalle DYNAMIC ARRAY OF RECORD
indicadorFacturacion,nombreItem,indicadorBienoServicio,cantidadItem,precioUnitarioItem,
montoItem STRING,
DescripcionItem VARCHAR(1000),
NumeroLinea int
END RECORD
FUNCTION generafile(documento_encabezado,documento_Detalle,xsucid,xbodega,xoperacion)
DEFINE documento_encabezado RECORD
tipoEcf,eNcf,indicadorMontoGravado,tipoPago,fechaLimitePago,FormadePAgo,montoPago,FechaVencimientoSecuencia,
rncEmisor,razonSocialEmisor,direccionEmisor,Municipio,Provincia,telefonoEmisor,
correoEmisor,webSite,codigoVendedor,numeroFacturaInterna,numeroPedidoInterno,
fechaEmision,rncComprador,razonSocialComprador,montoGravadoTotal,montoGravadoI1,
montoGravadoI2,montoGravadoI3,montoExento,itbis1,itbis2,itbis3,totalItbis,totalItbis1,
totalItbis2,totalItbis3,montoTotal,tipoIngreso,terminoPago,TipoCuentaPago,NumeroCuentaPago,IdentificadorExtranjero,
contactoComprador,CorreoComprador,DireccionComprador,MunicipioComprador,ProvinciaComprador,FechaEntrega,FechaOrdenCompra,
NumeroOrdenCompra,CodigoInternoComprador,
nombreFile,IndicadorNotaCredito,NCFmodificado,codigoModificacion,fechaNCFmodificado STRING
END RECORD,
chFechaFirma VARCHAR(19),
tipoRecepcion VARCHAR(50),
xoperacion VARCHAR(30),
xsucid,xbodega INT
DEFINE documento_Detalle DYNAMIC ARRAY OF RECORD
indicadorFacturacion,nombreItem,indicadorBienoServicio,cantidadItem,precioUnitarioItem,
montoItem STRING,
DescripcionItem VARCHAR(1000),
NumeroLinea int
END RECORD,
respuesta,codigo STRING,
phash,ohash VARCHAR(10)
LET ohash = NULL
LET ruta_originales= fgl_getenv("RUTA_XML_ORIGINALES")
#LET ruta_originales = '.\\filesXML\\ncf31\\'
# LET documento_encabezado.nombreFile ='130337391E310000000001.XML'
LET nombreFile = ruta_originales,documento_encabezado.nombreFile CLIPPED
LET r_documento_encabezado.* = documento_encabezado.*
LET r_documento_Detalle = documento_detalle
LET montoFactura =r_documento_encabezado.montoTotal
# CALL fgl_winmessage("ERROR",nombreFile,"INFO")
LET out=om.XmlWriter.createFileWriter(nombreFile)
LET a=om.SaxAttributes.create()
#CALL fgl_winmessage("ERROR",OUT,"INFO")
CALL out.startDocument()
CALL a.addAttribute("xmlns:xs","http://www.w3.org/2001/XMLSchema")
IF r_documento_encabezado.tipoEcf <> '32' THEN
LET tipoRecepcion = "normal"
CALL out.startElement("ECF",a)
CALL a.clear()
CALL encabezado()
CALL detalle()
IF r_documento_encabezado.tipoEcf = 34 OR r_documento_encabezado.tipoEcf = 33 THEN
CALL otrosTags()
END IF
END IF
IF r_documento_encabezado.tipoEcf = '32' AND montoFactura > 250000 THEN
LET tipoRecepcion = "normal"
CALL out.startElement("ECF",a)
CALL a.clear()
CALL encabezado()
CALL detalle()
END IF
IF r_documento_encabezado.tipoEcf = '32' AND montoFactura < 250000 THEN
LET tipoRecepcion = "consumo"
CALL out.startElement("ECF",a)
CALL a.clear()
CALL encabezado32()
CALL detalle()
END IF
# IF xoperacion <> 'modificar' THEN
LET fechaFirma = CURRENT
LET chFechaFirma = util.Datetime.format(fechaFirma, "%d-%m-%Y %H:%M:%S" )
CALL out.startElement("FechaHoraFirma",null)
CALL out.characters(chFechaFirma)
CALL out.endElement("FechaHoraFirma")
# ELSE
# SELECT fechaFirmaDigital INTO fechaFirma FROM vetb00002
# WHERE factura = r_documento_encabezado.numeroFacturaInterna AND
# sucid = xsucid
# LET chFechaFirma = util.Datetime.format(fechaFirma, "%d-%m-%Y %H:%M:%S" )
# CALL out.startElement("FechaHoraFirma",null)
# CALL out.characters(chFechaFirma)
# CALL out.endElement("FechaHoraFirma")
# END IF
IF r_documento_encabezado.tipoEcf <> '32' THEN
CALL out.endElement("ECF")
END IF
IF r_documento_encabezado.tipoEcf = '32' AND montoFactura > 250000 THEN
LET tipoRecepcion = "normal"
CALL out.endElement("ECF")
END IF
IF r_documento_encabezado.tipoEcf = '32' AND montoFactura < 250000 THEN
LET tipoRecepcion = "consumo"
CALL out.endElement("ECF")
END IF
CALL out.endDocument()
IF r_documento_encabezado.tipoEcf = '32' AND montoFactura < 250000 THEN
LET comando = "copy ",nombrefile CLIPPED," ",ruta_originales CLIPPED,"\\FC"
RUN comando
LET nombreFile = ruta_originales,documento_encabezado.nombreFile CLIPPED
LET tipoRecepcion = "consumo"
LET out=om.XmlWriter.createFileWriter(nombreFile)
LET a=om.SaxAttributes.create()
CALL out.startDocument()
CALL a.addAttribute("xmlns:xs","http://www.w3.org/2001/XMLSchema")
CALL resumen32() RETURNING ohash
CALL out.endDocument()
END IF
CALL procesoEncf(nombrefile,"certificacion",tipoRecepcion,xsucid,xbodega,xoperacion,' ')
RETURNING phash,respuesta,codigo
IF ohash IS NOT NULL THEN
LET phash = ohash
END IF
RETURN phash,respuesta,fechafirma,codigo
END FUNCTION
FUNCTION encabezado()
CALL out.startElement("Encabezado",a)
CALL out.startElement("Version",null)
CALL out.characters("1.0")
CALL out.endElement("Version")
CALL a.clear()
CALL out.startElement("IdDoc",NULL)
CALL out.startElement("TipoeCF",null)
CALL out.characters(r_documento_encabezado.tipoEcf CLIPPED)
CALL out.endElement("TipoeCF")
CALL out.startElement("eNCF",NULL)
LET r_documento_encabezado.eNcf = r_documento_encabezado.eNcf
CALL out.characters(r_documento_encabezado.eNcf)
CALL out.endElement("eNCF")
IF r_documento_encabezado.tipoEcf <> '32' AND r_documento_encabezado.tipoEcf <> '34' THEN
IF r_documento_encabezado.FechaVencimientoSecuencia IS NOT NULL THEN
CALL out.startElement("FechaVencimientoSecuencia",null)
CALL out.characters(r_documento_encabezado.FechaVencimientoSecuencia)
CALL out.endElement("FechaVencimientoSecuencia")
END IF
END IF
IF r_documento_encabezado.IndicadorNotaCredito IS NOT NULL THEN
CALL out.startElement("IndicadorNotaCredito",NULL)
CALL out.characters(r_documento_encabezado.IndicadorNotaCredito)
CALL out.endElement("IndicadorNotaCredito")
END IF
IF r_documento_encabezado.indicadorMontoGravado IS NOT NULL THEN
CALL out.startElement("IndicadorMontoGravado",null)
CALL out.characters(r_documento_encabezado.indicadorMontoGravado)
CALL out.endElement("IndicadorMontoGravado")
END IF
IF r_documento_encabezado.tipoEcf = '32' AND montoFactura < 250000 THEN
LET r_Documento_encabezado.tipoIngreso = '02'
END IF
CALL out.startElement("TipoIngresos",NULL)
CALL out.characters(r_documento_encabezado.tipoIngreso)
CALL out.endElement("TipoIngresos")
CALL out.startElement("TipoPago",NULL)
CALL out.characters(r_documento_encabezado.tipoPago)
CALL out.endElement("TipoPago")
IF r_documento_encabezado.fechaLimitePago IS NOT NULL THEN
CALL out.startElement("FechaLimitePago",null)
CALL out.characters(r_documento_encabezado.fechaLimitePago)
CALL out.endElement("FechaLimitePago")
END IF
IF r_documento_encabezado.terminoPago IS NOT NULL THEN
CALL out.startElement("TerminoPago",null)
CALL out.characters(r_documento_encabezado.terminoPago)
CALL out.endElement("TerminoPago")
END IF
# AQUI VA LA TABLA FORMA DE PAGO, ESTO NO ES OBLIGATORIO
# IF r_documento_encabezado.tipoEcf <> '32' AND r_documento_encabezado.tipoEcf <> 34 THEN
IF r_documento_encabezado.tipoEcf <> 34 AND r_documento_encabezado.tipoEcf <> 33 THEN
CALL out.startElement("TablaFormasPago",NULL)
CALL out.startElement("FormaDePago",NULL)
CALL out.startElement("FormaPago",null)
CALL out.characters(r_documento_encabezado.tipoPago)
CALL out.endElement("FormaPago")
CALL out.startElement("MontoPago",null)
CALL out.characters(r_documento_encabezado.montoPago)
CALL out.endElement("MontoPago")
CALL out.endElement("FormaDePago")
CALL out.endElement("TablaFormasPago")
END IF
#----------------------------------------------------------------------------
IF r_documento_encabezado.TipoCuentaPago IS NOT NULL THEN
IF r_documento_encabezado.tipoEcf <> '32' THEN
CALL out.startElement("TipoCuentaPago",null)
CALL out.characters(r_documento_encabezado.TipoCuentaPago)
CALL out.endElement("TipoCuentaPago")
END IF
END IF
CALL out.endElement("IdDoc")
CALL out.startElement("Emisor",NULL)
CALL out.startElement("RNCEmisor",NULL)
CALL out.characters(r_documento_encabezado.rncEmisor)
CALL out.endElement("RNCEmisor")
CALL out.startElement("RazonSocialEmisor",NULL)
CALL out.characters(r_documento_encabezado.razonSocialEmisor)
CALL out.endElement("RazonSocialEmisor")
CALL out.startElement("NombreComercial",NULL)
CALL out.characters(r_documento_encabezado.razonSocialEmisor)
CALL out.endElement("NombreComercial")
IF r_documento_encabezado.direccionEmisor IS NOT NULL THEN
CALL out.startElement("DireccionEmisor",NULL)
CALL out.characters(r_documento_encabezado.direccionEmisor)
CALL out.endElement("DireccionEmisor")
END IF
CALL out.startElement("Municipio",NULL)
CALL out.characters(r_documento_encabezado.Municipio)
CALL out.endElement("Municipio")
CALL out.startElement("Provincia",NULL)
CALL out.characters(r_documento_encabezado.Provincia)
CALL out.endElement("Provincia")
IF r_documento_encabezado.correoEmisor IS NOT NULL THEN
CALL out.startElement("CorreoEmisor",NULL)
CALL out.characters(r_documento_encabezado.correoEmisor)
CALL out.endElement("CorreoEmisor")
END IF
IF r_documento_encabezado.codigoVendedor IS NOT NULL THEN
CALL out.startElement("CodigoVendedor",NULL)
CALL out.characters(r_documento_encabezado.codigoVendedor)
CALL out.endElement("CodigoVendedor")
END IF
IF r_documento_encabezado.numeroFacturaInterna IS NOT NULL THEN
CALL out.startElement("NumeroFacturaInterna",NULL)
CALL out.characters(r_documento_encabezado.numeroFacturaInterna)
CALL out.endElement("NumeroFacturaInterna")
END IF
IF r_documento_encabezado.numeroPedidoInterno IS NOT NULL THEN
CALL out.startElement("NumeroPedidoInterno",NULL)
CALL out.characters(r_documento_encabezado.numeroPedidoInterno)
CALL out.endElement("NumeroPedidoInterno")
END IF
CALL out.startElement("FechaEmision",NULL)
CALL out.characters(r_documento_encabezado.fechaEmision)
CALL out.endElement("FechaEmision")
CALL out.endElement("Emisor")
CALL out.startElement("Comprador",NULL)
IF r_documento_encabezado.rncComprador IS NOT NULL OR r_documento_encabezado.rncComprador <> ' ' THEN
CALL out.startElement("RNCComprador",NULL)
CALL out.characters(r_documento_encabezado.rncComprador)
CALL out.endElement("RNCComprador")
ELSE
# IF r_documento_encabezado.IdentificadorExtranjero IS NOT NULL THEN
CALL out.startElement("IdentificadorExtranjero",NULL)
CALL out.characters(r_documento_encabezado.IdentificadorExtranjero)
CALL out.endElement("IdentificadorExtranjero")
# END IF
END IF
CALL out.startElement("RazonSocialComprador",NULL)
CALL out.characters(r_documento_encabezado.razonSocialComprador)
CALL out.endElement("RazonSocialComprador")
{CALL out.startElement("ContactoComprador",NULL)
CALL out.characters(r_documento_encabezado.contactoComprador)
CALL out.endElement("ContactoComprador")
}
IF r_documento_encabezado.CorreoComprador IS NOT NULL THEN
CALL out.startElement("CorreoComprador",NULL)
CALL out.characters(r_documento_encabezado.CorreoComprador CLIPPED)
CALL out.endElement("CorreoComprador")
END IF
IF r_documento_encabezado.DireccionComprador IS NOT NULL AND LENGTH(r_documento_encabezado.DireccionComprador) > 5 THEN
{ LET buf = base.StringBuffer.create()
CALL buf.append(r_documento_encabezado.DireccionComprador)
CALL buf.replace(",", " ", 0)}
CALL out.startElement("DireccionComprador",NULL)
CALL out.characters(r_documento_encabezado.DireccionComprador CLIPPED)
CALL out.endElement("DireccionComprador")
END IF
IF r_documento_encabezado.MunicipioComprador IS NOT NULL OR r_documento_encabezado.MunicipioComprador <> ' ' THEN
CALL out.startElement("MunicipioComprador",NULL)
CALL out.characters(r_documento_encabezado.MunicipioComprador)
CALL out.endElement("MunicipioComprador")
END IF
IF r_documento_encabezado.ProvinciaComprador IS NOT NULL OR r_documento_encabezado.ProvinciaComprador <> ' ' THEN
CALL out.startElement("ProvinciaComprador",NULL)
CALL out.characters(r_documento_encabezado.ProvinciaComprador)
CALL out.endElement("ProvinciaComprador")
END IF
CALL out.endElement("Comprador")
CALL out.startElement("Totales",NULL)
IF r_documento_encabezado.tipoEcf <> '44' THEN
CALL out.startElement("MontoGravadoTotal",NULL)
CALL out.characters(r_documento_encabezado.montoGravadoTotal)
CALL out.endElement("MontoGravadoTotal")
IF r_documento_encabezado.montoGravadoI1 <> '0' THEN
CALL out.startElement("MontoGravadoI1",NULL)
CALL out.characters(r_documento_encabezado.montoGravadoI1)
CALL out.endElement("MontoGravadoI1")
IF r_documento_encabezado.montoGravadoI2 <> '0' THEN
CALL out.startElement("MontoGravadoI2",NULL)
CALL out.characters(r_documento_encabezado.montoGravadoI2)
CALL out.endElement("MontoGravadoI2")
END IF
END IF
IF r_documento_encabezado.montoGravadoI3 IS NOT NULL THEN
CALL out.startElement("MontoGravadoI3",NULL)
CALL out.characters(r_documento_encabezado.montoGravadoI3)
CALL out.endElement("MontoGravadoI3")
END IF
IF r_documento_encabezado.tipoEcf <> '46' THEN
# IF r_documento_encabezado.itbis1 <> '00' THEN
CALL out.startElement("ITBIS1",NULL)
CALL out.characters(r_documento_encabezado.itbis1)
CALL out.endElement("ITBIS1")
# END IF
END IF
IF r_documento_encabezado.itbis2 <> '0' THEN
CALL out.startElement("ITBIS2",NULL)
CALL out.characters(r_documento_encabezado.itbis2)
CALL out.endElement("ITBIS2")
END IF
IF r_documento_encabezado.montoGravadoI3 IS NOT NULL THEN
CALL out.startElement("ITBIS3",NULL)
CALL out.characters(r_documento_encabezado.itbis3)
CALL out.endElement("ITBIS3")
END IF
CALL out.startElement("TotalITBIS",NULL)
CALL out.characters(r_documento_encabezado.totalItbis)
CALL out.endElement("TotalITBIS")
IF r_documento_encabezado.tipoEcf <> '46' THEN
IF r_documento_encabezado.totalItbis1 <> '.00' THEN
CALL out.startElement("TotalITBIS1",NULL)
CALL out.characters(r_documento_encabezado.totalItbis1)
CALL out.endElement("TotalITBIS1")
END IF
END IF
IF r_documento_encabezado.totalItbis2 <> '0' THEN
CALL out.startElement("TotalITBIS2",NULL)
CALL out.characters(r_documento_encabezado.totalItbis2)
CALL out.endElement("TotalITBIS2")
END IF
IF r_documento_encabezado.montoGravadoI3 IS NOT NULL THEN
CALL out.startElement("TotalITBIS3",NULL)
CALL out.characters(r_documento_encabezado.totalItbis3)
CALL out.endElement("TotalITBIS3")
END IF
END IF
IF r_documento_encabezado.tipoEcf = '44' THEN
IF r_documento_encabezado.montoExento IS NOT NULL THEN
CALL out.startElement("MontoExento",NULL)
CALL out.characters(r_documento_encabezado.montoExento)
CALL out.endElement("MontoExento")
END IF
END IF
CALL out.startElement("MontoTotal",NULL)
CALL out.characters(r_documento_encabezado.montoTotal)
CALL out.endElement("MontoTotal")
CALL out.endElement("Totales")
CALL out.endElement("Encabezado")
END FUNCTION
FUNCTION detalle()
CALL out.startElement("DetallesItems",NULL)
FOR i =1 TO r_documento_detalle.getLength()
CALL out.startElement("Item",NULL)
CALL out.startElement("NumeroLinea",NULL)
CALL out.characters(i USING "<<<")
CALL out.endElement("NumeroLinea")
CALL out.startElement("IndicadorFacturacion",NULL)
CALL out.characters(r_documento_detalle[i].indicadorFacturacion)
CALL out.endElement("IndicadorFacturacion")
IF r_documento_detalle[i].nombreItem IS NULL THEN
LET r_documento_detalle[i].nombreItem = 'NO TIENE'
END IF
CALL out.startElement("NombreItem",NULL)
CALL out.characters(r_documento_detalle[i].nombreItem)
CALL out.endElement("NombreItem")
IF r_documento_detalle[i].indicadorBienoServicio IS NULL THEN
LET r_documento_detalle[i].indicadorBienoServicio = 2
END IF
CALL out.startElement("IndicadorBienoServicio",NULL)
CALL out.characters(r_documento_detalle[i].indicadorBienoServicio)
CALL out.endElement("IndicadorBienoServicio")
CALL out.startElement("CantidadItem",NULL)
CALL out.characters(r_documento_detalle[i].cantidadItem)
CALL out.endElement("CantidadItem")
CALL out.startElement("PrecioUnitarioItem",NULL)
CALL out.characters(r_documento_detalle[i].precioUnitarioItem)
CALL out.endElement("PrecioUnitarioItem")
CALL out.startElement("MontoItem",NULL)
CALL out.characters(r_documento_detalle[i].montoItem)
CALL out.endElement("MontoItem")
CALL out.endElement("Item")
END FOR
CALL out.endElement("DetallesItems")
END FUNCTION
FUNCTION encabezado32()
CALL out.startElement("Encabezado",a)
CALL out.startElement("Version",null)
CALL out.characters("1.0")
CALL out.endElement("Version")
CALL out.startElement("IdDoc",NULL)
CALL out.startElement("TipoeCF",null)
CALL out.characters(r_documento_encabezado.tipoEcf CLIPPED)
CALL out.endElement("TipoeCF")
CALL out.startElement("eNCF",NULL)
LET r_documento_encabezado.eNcf = r_documento_encabezado.eNcf
CALL out.characters(r_documento_encabezado.eNcf)
CALL out.endElement("eNCF")
CALL out.startElement("TipoIngresos",null)
CALL out.characters(r_documento_encabezado.tipoIngreso)
CALL out.endElement("TipoIngresos")
CALL out.startElement("TipoPago",null)
CALL out.characters(r_documento_encabezado.tipoPago)
CALL out.endElement("TipoPago")
IF r_documento_encabezado.terminoPago IS NOT NULL THEN
CALL out.startElement("TerminoPago",null)
CALL out.characters(r_documento_encabezado.terminoPago)
CALL out.endElement("TerminoPago")
END IF
CALL out.endElement("IdDoc")
CALL out.startElement("Emisor",NULL)
CALL out.startElement("RNCEmisor",NULL)
CALL out.characters(r_documento_encabezado.rncEmisor)
CALL out.endElement("RNCEmisor")
CALL out.startElement("RazonSocialEmisor",NULL)
CALL out.characters(r_documento_encabezado.razonSocialEmisor)
CALL out.endElement("RazonSocialEmisor")
CALL out.startElement("NombreComercial",NULL)
CALL out.characters(r_documento_encabezado.razonSocialEmisor)
CALL out.endElement("NombreComercial")
CALL out.startElement("DireccionEmisor",NULL)
CALL out.characters(r_documento_encabezado.direccionEmisor)
CALL out.endElement("DireccionEmisor")
CALL out.startElement("Municipio",NULL)
CALL out.characters(r_documento_encabezado.Municipio)
CALL out.endElement("Municipio")
CALL out.startElement("Provincia",NULL)
CALL out.characters(r_documento_encabezado.Provincia)
CALL out.endElement("Provincia")
CALL out.startElement("CorreoEmisor",NULL)
CALL out.characters(r_documento_encabezado.correoEmisor)
CALL out.endElement("CorreoEmisor")
CALL out.startElement("CodigoVendedor",NULL)
CALL out.characters(r_documento_encabezado.codigoVendedor)
CALL out.endElement("CodigoVendedor")
CALL out.startElement("NumeroFacturaInterna",NULL)
CALL out.characters(r_documento_encabezado.numeroFacturaInterna)
CALL out.endElement("NumeroFacturaInterna")
CALL out.startElement("FechaEmision",NULL)
CALL out.characters(r_documento_encabezado.fechaEmision)
CALL out.endElement("FechaEmision")
CALL out.endElement("Emisor")
CALL out.startElement("Comprador",NULL)
IF r_documento_encabezado.rncComprador IS NOT NULL THEN
CALL out.startElement("RNCComprador",NULL)
CALL out.characters(r_documento_encabezado.rncComprador)
CALL out.endElement("RNCComprador")
ELSE
CALL out.startElement("IdentificadorExtranjero",NULL)
CALL out.characters(r_documento_encabezado.IdentificadorExtranjero)
CALL out.endElement("IdentificadorExtranjero")
END IF
CALL out.startElement("RazonSocialComprador",NULL)
CALL out.characters(r_documento_encabezado.razonSocialComprador)
CALL out.endElement("RazonSocialComprador")
CALL out.endElement("Comprador")
CALL out.startElement("Totales",NULL)
CALL out.startElement("MontoGravadoTotal",NULL)
CALL out.characters(r_documento_encabezado.montoGravadoTotal)
CALL out.endElement("MontoGravadoTotal")
CALL out.startElement("MontoGravadoI1",NULL)
CALL out.characters(r_documento_encabezado.montoGravadoTotal)
CALL out.endElement("MontoGravadoI1")
{ CALL out.startElement("MontoExento",NULL)
CALL out.characters(r_documento_encabezado.montoExento)
CALL out.endElement("MontoExento")
}
CALL out.startElement("TotalITBIS",NULL)
CALL out.characters(r_documento_encabezado.totalItbis)
CALL out.endElement("TotalITBIS")
IF r_documento_encabezado.totalItbis1 <> '.00' THEN
CALL out.startElement("TotalITBIS1",NULL)
CALL out.characters(r_documento_encabezado.totalItbis1)
CALL out.endElement("TotalITBIS1")
END IF
CALL out.startElement("MontoTotal",NULL)
CALL out.characters(r_documento_encabezado.montoTotal)
CALL out.endElement("MontoTotal")
CALL out.endElement("Totales")
CALL out.endElement("Encabezado")
END FUNCTION
FUNCTION resumen32()
DEFINE fchash VARCHAR(6),
xhash,xfechafirmadigital,xfacturainterna STRING
CALL out.startElement("RFCE",a)
CALL out.startElement("Encabezado",a)
CALL out.startElement("Version",null)
CALL out.characters("1.0")
CALL out.endElement("Version")
CALL a.clear()
CALL out.startElement("IdDoc",NULL)
CALL out.startElement("TipoeCF",null)
CALL out.characters(r_documento_encabezado.tipoEcf CLIPPED)
CALL out.endElement("TipoeCF")
CALL out.startElement("eNCF",NULL)
LET r_documento_encabezado.eNcf = r_documento_encabezado.eNcf
CALL out.characters(r_documento_encabezado.eNcf)
CALL out.endElement("eNCF")
CALL out.startElement("TipoIngresos",null)
CALL out.characters(r_documento_encabezado.tipoIngreso)
CALL out.endElement("TipoIngresos")
CALL out.startElement("TipoPago",null)
CALL out.characters(r_documento_encabezado.tipoPago)
CALL out.endElement("TipoPago")
CALL out.startElement("TablaFormasPago",NULL)
CALL out.startElement("FormaDePago",NULL)
CALL out.startElement("FormaPago",null)
CALL out.characters(r_documento_encabezado.tipoPago)
CALL out.endElement("FormaPago")
CALL out.startElement("MontoPago",null)
CALL out.characters(r_documento_encabezado.montoPago)
CALL out.endElement("MontoPago")
CALL out.endElement("FormaDePago")
CALL out.endElement("TablaFormasPago")
{
IF r_documento_encabezado.terminoPago IS NOT NULL THEN
CALL out.startElement("TerminoPago",null)
CALL out.characters(r_documento_encabezado.terminoPago)
CALL out.endElement("TerminoPago")
END IF}
CALL out.endElement("IdDoc")
CALL out.startElement("Emisor",NULL)
CALL out.startElement("RNCEmisor",NULL)
CALL out.characters(r_documento_encabezado.rncEmisor)
CALL out.endElement("RNCEmisor")
CALL out.startElement("RazonSocialEmisor",NULL)
CALL out.characters(r_documento_encabezado.razonSocialEmisor)
CALL out.endElement("RazonSocialEmisor")
CALL out.startElement("FechaEmision",NULL)
CALL out.characters(r_documento_encabezado.fechaEmision)
CALL out.endElement("FechaEmision")
CALL out.endElement("Emisor")
CALL out.startElement("Comprador",NULL)
IF r_documento_encabezado.rncComprador IS NOT NULL THEN
CALL out.startElement("RNCComprador",NULL)
CALL out.characters(r_documento_encabezado.rncComprador)
CALL out.endElement("RNCComprador")
ELSE
CALL out.startElement("IdentificadorExtranjero",NULL)
CALL out.characters(r_documento_encabezado.IdentificadorExtranjero)
CALL out.endElement("IdentificadorExtranjero")
END IF
CALL out.startElement("RazonSocialComprador",NULL)
CALL out.characters(r_documento_encabezado.razonSocialComprador)
CALL out.endElement("RazonSocialComprador")
CALL out.endElement("Comprador")
CALL out.startElement("Totales",NULL)
CALL out.startElement("MontoGravadoTotal",NULL)
CALL out.characters(r_documento_encabezado.montoGravadoTotal)
CALL out.endElement("MontoGravadoTotal")
CALL out.startElement("MontoGravadoI1",NULL)
CALL out.characters(r_documento_encabezado.montoGravadoTotal)
CALL out.endElement("MontoGravadoI1")
CALL out.startElement("MontoExento",NULL)
CALL out.characters(r_documento_encabezado.montoExento)
CALL out.endElement("MontoExento")
CALL out.startElement("TotalITBIS",NULL)
CALL out.characters(r_documento_encabezado.totalItbis)
CALL out.endElement("TotalITBIS")
IF r_documento_encabezado.totalItbis1 <> '.00' THEN
CALL out.startElement("TotalITBIS1",NULL)
CALL out.characters(r_documento_encabezado.totalItbis1)
CALL out.endElement("TotalITBIS1")
END IF
CALL out.startElement("MontoTotal",NULL)
CALL out.characters(r_documento_encabezado.montoTotal)
CALL out.endElement("MontoTotal")
CALL out.endElement("Totales")
# BUSCA EL CODIGO DE SEGURIDAD
# SELECT hash INTO fchash FROM vetb00002 WHERE factura = r_documento_encabezado.numeroFacturaInterna
# LET fchash = r_documento_encabezado.razonSocialComprador.subString(1,4),
# r_documento_encabezado.numeroFacturaInterna.subString(3,5)
LET fchash = util.Math.rand(150000) USING "&&&&&&"
CALL out.startElement("CodigoSeguridadeCF",NULL)
CALL out.characters(fchash)
CALL out.endElement("CodigoSeguridadeCF")
CALL out.endElement("Encabezado")
CALL out.endElement("RFCE")
RETURN fchash
END FUNCTION
FUNCTION anularencf(documento_anular)
DEFINE documento_anular RECORD
nombrefile,rnc_emisor,cantidadEncf,fechaAnulacion,numeroLineas,tipoeCF,secuenciaeCFdesde,secuenciaeCFhasta,
cantidadeCFanulados
STRING
END RECORD,
nombrefile,tiporecepcion string
LET ruta_originales= fgl_getenv("RUTA_XML_ORIGINALES")
#LET ruta_originales = '.\\filesXML\\ncf31\\'
# LET documento_encabezado.nombreFile ='130337391E310000000001.XML'
LET nombreFile = ruta_originales,documento_anular.nombreFile CLIPPED
LET tiporecepcion = 'ANULAR'
LET out=om.XmlWriter.createFileWriter(nombreFile)
LET a=om.SaxAttributes.create()
CALL out.startDocument()
CALL a.addAttribute("xmlns:xs","http://www.w3.org/2001/XMLSchema")
CALL out.startElement("ANECF",a)
CALL a.clear()
CALL out.startElement("Encabezado",a)
CALL out.startElement("Version",null)
CALL out.characters("1.0")
CALL out.endElement("Version")
CALL a.clear()
CALL out.startElement("CantidadeNCFAnulados",NULL)
CALL out.characters(documento_anular.cantidadeCFanulados)
CALL out.endElement("CantidadeNCFAnulados")
CALL out.startElement("FechaHoraAnulacioneNCF",NULL)
CALL out.characters(documento_anular.fechaAnulacion)
CALL out.endElement("FechaHoraAnulacioneNCF")
CALL out.startElement("DetalleAnulacion",NULL)
CALL out.startElement("FechaHoraAnulacioneNCF",NULL)
CALL out.characters(documento_anular.fechaAnulacion)
CALL out.endElement("FechaHoraAnulacioneNCF")
CALL out.startElement("Anulacion",NULL)
CALL out.startElement("NoLinea",NULL)
CALL out.characters(documento_anular.numeroLineas)
CALL out.endElement("NoLinea")
CALL out.startElement("TipoeCF",NULL)
CALL out.characters(documento_anular.tipoeCF)
CALL out.endElement("TipoeCF")
CALL out.startElement("TablaRangoSecuenciasAnuladaseNCF",NULL)
CALL out.startElement("SecuenciaeNCFDesde",NULL)
CALL out.characters(documento_anular.secuenciaeCFdesde)
CALL out.endElement("SecuenciaeNCFDesde")
CALL out.startElement("SecuenciaeNCFHasta",NULL)
CALL out.characters(documento_anular.secuenciaeCFhasta)
CALL out.endElement("SecuenciaeNCFHasta")
CALL out.endElement("TablaRangoSecuenciasAnuladaseNCF")
CALL out.startElement("CantidadeNCFAnulados",NULL)
CALL out.characters(documento_anular.cantidadeCFanulados)
CALL out.endElement("CantidadeNCFAnulados")
CALL out.endElement("Anulacion")
CALL out.endElement("DetalleAnulacion")
CALL out.endElement("ANECF")
CALL out.endDocument()
#CALL procesoEncf(nombrefile,"test",tipoRecepcion)
END FUNCTION
FUNCTION otrosTags()
CALL out.startElement("InformacionReferencia",NULL)
CALL out.startElement("NCFModificado",null)
CALL out.characters(r_documento_encabezado.NCFmodificado)
CALL out.endElement("NCFModificado")
CALL out.startElement("FechaNCFModificado",null)
CALL out.characters(r_documento_encabezado.fechaNCFmodificado)
CALL out.endElement("FechaNCFModificado")
CALL out.startElement("CodigoModificacion",null)
CALL out.characters(r_documento_encabezado.codigoModificacion)
CALL out.endElement("CodigoModificacion")
CALL out.startElement("RazonModificacion",null)
CALL out.characters("No tenemos razones")
CALL out.endElement("RazonModificacion")
CALL out.endElement("InformacionReferencia")
END FUNCTION
File diff suppressed because it is too large Load Diff
+861
View File
@@ -0,0 +1,861 @@
import os
import com
import xml
import util
TYPE tMensaje RECORD
codigo STRING,
valor STRING
END RECORD
TYPE tRespDGII RECORD
codigo INTEGER, -- 1=OK, 2=Rechazado, etc. (cuando venga)
estado STRING, -- "Aceptado" | "Rechazado" | etc.
encf STRING,
secuenciaUtilizada BOOLEAN,
hash STRING,
fechaFirmaDigital STRING,
qrcodeurl STRING,
trackId STRING,
mensajes DYNAMIC ARRAY OF tMensaje
END RECORD
TYPE consultaRespuesta RECORD
trackid,
codigo,
estado,
rnc,
encf,
secuenciaUtilizada,
fechaRecepcion STRING,
mensajes DYNAMIC ARRAY OF tmensaje
END RECORD
TYPE dgiimensaje RECORD
codigo,estado,ecf,secuenciaUtilizada STRING,
mensajes DYNAMIC ARRAY OF tmensaje
END RECORD
DEFINE url_semilla, url_validasemilla,url_anulacion,
url_recepcion,url_consulta,url_consulta_timbre STRING
DEFINE codigo,tokenxml,nombreFile,filexml,token,respuesta,ruta_firmados,rutaSemilla,rutaCert STRING
DEFINE doc xml.DomDocument,
xfacturainterna,gsucid,gbodega INT,
goperacion VARCHAR(30)
FUNCTION procesoEncf(fileporfirmar,ambiente,tiporecepcion,xsucid,xbodega,xoperacion,krespuesta)
DEFINE fileporfirmar,rtoken,ambiente,tiporecepcion,krespuesta STRING,
xhash VARCHAR(6),xfechafirmadigital VARCHAR(50),
xsucid,xbodega INT,
xoperacion CHAR(30)
DEFINE dtrackid RECORD
trackId,error,mensaje STRING
END RECORD,
xfecha DATETIME YEAR TO minute
CALL STARTLOG("procesoencf.txt")
# LET ptipoRecepcion = tiporecepcion
LET ruta_firmados = fgl_getenv("RUTA_XML_FIRMADOS")
LET rutaSemilla = fgl_getenv("RUTA_SEMILLA")
LET rutaCert = fgl_getenv("RUTA_CERT")
IF ambiente <> "produccion" THEN
IF ambiente <> "test" THEN
LET respuesta = "no llego bien ",ambiente
RETURN ' ',respuesta,'400'
END IF
END IF
# LET xambiente = ambiente
CALL urls(ambiente,tiporecepcion)
{
SELECT a.valor,a.fecha INTO rtoken,xfecha
FROM token a
DISPLAY "tiempos: ",xfecha," ",CURRENT HOUR TO MINUTE}
# IF CURRENT HOUR TO MINUTE- xfecha > "0:44" THEN
CALL buscatoken(url_semilla) RETURNING codigo, tokenxml
IF codigo <> "200" THEN
LET respuesta = "respuesta buscatoken: ",tokenxml," ",codigo
RETURN ' ',respuesta,'400'
END IF
LET gsucid = xsucid
LET gbodega = xbodega
LET goperacion = xoperacion
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
CALL doc.loadFromString(tokenxml)
# CALL doc.save(".\\filesXML\\marmotech\\mtechTokenString.xml")
CALL doc.save(rutaSemilla||"/TokenString.xml")
#FIRMA SEMILLA
IF os.Path.exists(rutaSemilla||"/TokenString.xml") THEN
CALL firmasemilla()
ELSE
LET respuesta = "NO PUDE CREAR SEMILLA"
RETURN ' ',respuesta,'400'
END IF
IF os.Path.exists(rutaSemilla||"/Signature.xml") THEN
CALL validasemilla(url_validasemilla) RETURNING codigo,respuesta
IF codigo = 400 THEN
RETURN ' ',respuesta,'400'
END IF
ELSE
LET respuesta = "NO ENCONTRE LA SEMILLA FIRMADA"
RETURN ' ',respuesta,'400'
END IF
IF respuesta IS NOT NULL THEN
LET doc = xml.DomDocument.Create()
CALL doc.loadFromString(respuesta)
CALL doc.save(rutaSemilla||"/RespuestaValida.xml")
CALL gettoken() RETURNING rtoken
LET token = rtoken
# UPDATE token SET valor = rtoken,fecha=getdate()
ELSE
LET respuesta = "NO TENEMOS RESPUESTA DE VALIDA SEMILLA"
RETURN ' ',respuesta,'400'
END IF
# ELSE
# DISPLAY "en validar semilla"
# CALL validasemilla() RETURNING codigo,respuesta
# IF codigo = 400 THEN
# RETURN ' ',respuesta,'400'
# END IF
# END IF
DISPLAY "xoperacion: ",xoperacion
# CUANDO EL PROCESO NO ES FIRMAR EL DOCUMENTO
IF xoperacion <> 'consultatrackid' AND xoperacion <> 'consultastatus' THEN
LET filexml = fileporfirmar
CALL firmadocumento(fileporfirmar)
LET filexml = ruta_firmados CLIPPED,os.Path.baseName(fileporfirmar)
CALL enviafiles(token,filexml) RETURNING codigo,respuesta
CALL gethash(filexml) RETURNING xhash,xfechafirmadigital,xfacturainterna
# UPDATE vetb00002 SET hash = xhash WHERE factura = xfacturainterna AND sucid = xsucid
ELSE
IF xoperacion = 'consultatrackid' THEN
LET token = " Bearer ",token
CALL consultaResultado(token,krespuesta) RETURNING codigo, respuesta
END IF
IF xoperacion = 'consultastatus' THEN
LET token = " ApiKey ",token
CALL obtenerStatus(token)
END IF
END IF
RETURN xhash,respuesta,codigo
END FUNCTION
FUNCTION firmadocumento(fileafirmar)
DEFINE doc xml.DomDocument
DEFINE doc2 xml.DomDocument
DEFINE root xml.DomNode
DEFINE node xml.DomNode
DEFINE signNode xml.DomNode
DEFINE sig xml.Signature
DEFINE key xml.CryptoKey
DEFINE cert xml.CryptoX509
DEFINE index INTEGER,
fileafirmar STRING
LET rutaCert = fgl_getenv("RUTA_CERT")
LET ruta_firmados = fgl_getenv("RUTA_XML_FIRMADOS")
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
DISPLAY "file ",fileafirmar
LET filexml = fileafirmar
CALL doc.load(fileafirmar)
TRY
# Create rsa key
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
#CALL key.loadPEM(".\\cert\\marmotech\\onlyRSA.pem")
CALL key.loadPEM(rutaCert clipped||"/onlyRSA.pem")
# Create an X509 certificate with the constructor of the CryptoX509 class.
LET cert = xml.CryptoX509.Create()
CALL cert.setFeature("X509Certificate",TRUE)
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
# CALL cert.loadPEM("cert509.crt")
CALL cert.loadPEM(rutaCert clipped||"/onlyCert.pem")
# Create signature object with the key to use
LET sig = xml.Signature.Create()
# Assign the CryptoKey object to the Signature object.
CALL sig.setKey(KEY)
# Assign the CryptoX509 object to the Signature object.
CALL sig.setCertificate(cert)
# Set XML node to be signed. In our case, the entire document
# LET index = sig.createReference("",
# "http://www.w3.org/2001/04/xmlenc#sha256")
LET index = sig.createReference('""',
"http://www.w3.org/2001/04/xmlenc#sha256")
# Add enveloped method to not take the XML signature node into account
# when computing the entire document.
CALL sig.appendReferenceTransformation(index,
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
# Set canonicalization method on the XML fragment to be signed.
# Compute enveloped signature
CALL sig.compute(doc)
# Retrieve signature document
LET doc2=sig.getDocument()
# Append the signature node to the original document to get
# a valid enveloped signature
# Notice that the enveloped signature can be added anywhere in the
# original document
LET signNode = doc2.getDocumentElement() # Get Signature node
# Import it into the original document
LET node = doc.importNode(signNode,true)
# Retrieve the original document root node
LET root = doc.getDocumentElement()
# Append the signature node as last child of the original document
CALL root.appendChild(node)
# Save document with enveloped signature back to disk
CALL doc.setFeature("format-pretty-print",TRUE)
LET fileafirmar = ruta_firmados CLIPPED,os.Path.baseName(fileafirmar)
CALL doc.save(fileafirmar)
DISPLAY "file firmado", fileafirmar
CATCH
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
DISPLAY "aqui"
END TRY
END FUNCTION
FUNCTION firmasemilla()
DEFINE doc xml.DomDocument
DEFINE doc2 xml.DomDocument
DEFINE root xml.DomNode
DEFINE node xml.DomNode
DEFINE signNode xml.DomNode
DEFINE sig xml.Signature
DEFINE key xml.CryptoKey
DEFINE cert xml.CryptoX509
DEFINE index INTEGER
LET rutaSemilla = fgl_getenv("RUTA_SEMILLA")
LET rutaCert = fgl_getenv("RUTA_CERT")
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
LET filexml = rutaSemilla||"/TokenString.xml"
IF os.Path.exists(filexml) THEN
CALL doc.load(filexml)
ELSE
DISPLAY "NO LO ENCONTRE"
RETURN
END IF
TRY
# Create rsa key
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
CALL key.loadPEM(rutaCert||"/onlyRSA.pem")
# Create an X509 certificate with the constructor of the CryptoX509 class.
LET cert = xml.CryptoX509.Create()
CALL cert.setFeature("X509Certificate",TRUE)
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
# CALL cert.loadPEM("cert509.crt")
CALL cert.loadPEM(rutaCert||"/onlyCert.pem")
# Create signature object with the key to use
LET sig = xml.Signature.Create()
# Assign the CryptoKey object to the Signature object.
CALL sig.setKey(KEY)
# Assign the CryptoX509 object to the Signature object.
CALL sig.setCertificate(cert)
# Set XML node to be signed. In our case, the entire document
# LET index = sig.createReference("",
# "http://www.w3.org/2001/04/xmlenc#sha256")
LET index = sig.createReference('""',
"http://www.w3.org/2001/04/xmlenc#sha256")
# Add enveloped method to not take the XML signature node into account
# when computing the entire document.
CALL sig.appendReferenceTransformation(index,
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
# Set canonicalization method on the XML fragment to be signed.
# CALL sig.appendReferenceTransformation(index,
# "http://www.w3.org/2001/10/xml-exc-c14n#")
# Compute enveloped signature
CALL sig.compute(doc)
# Retrieve signature document
LET doc2=sig.getDocument()
# Append the signature node to the original document to get
# a valid enveloped signature
# Notice that the enveloped signature can be added anywhere in the
# original document
LET signNode = doc2.getDocumentElement() # Get Signature node
# Import it into the original document
LET node = doc.importNode(signNode,true)
# Retrieve the original document root node
LET root = doc.getDocumentElement()
# Append the signature node as last child of the original document
CALL root.appendChild(node)
# Save document with enveloped signature back to disk
CALL doc.setFeature("format-pretty-print",TRUE)
CALL doc.save(rutaSemilla||"/Signature.xml")
CATCH
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
END TRY
END FUNCTION
FUNCTION validasemilla(url_validasemilla1)
DEFINE respuesta,codigo,url_validasemilla1 STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
LET rutaSemilla = fgl_getenv("RUTA_SEMILLA")
LET http_req = com.HTTPRequest.Create(url_validasemilla1)
CALL http_req.setMethod("POST")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/xml")
CALL http_req.setMultipartType("form-data",NULL,NULL)
CALL http_req.setConnectionTimeOut(10)
IF os.Path.exists(rutaSemilla||"/Signature.xml") THEN
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"Signature.xml\"")
# TRY
CALL http_req.doFileRequest(rutaSemilla||"/Signature.xml")
# CATCH
-- Intentar obtener la
# RETURN 400, "NO OBTUVE RESPUESTA DEL SERICIO AL VALIDAR SEMILLA"
# END TRY
-- Continuar con la ejecución normal si no se produjo una excepción
LET http_resp = http_req.getResponse()
LET codigo = http_resp.getStatusCode()
LET respuesta = http_resp.getTextResponse()
ELSE
LET codigo=400
LET respuesta='NO ENCONTRE EL FILE PARA VALIDAR SEMILLA'
END IF
RETURN codigo, respuesta
END FUNCTION
FUNCTION enviafiles(btoken,archivo)
DEFINE respuesta,btoken,codigo,archivo,contenido,consultaResp,body STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse,
xresp RECORD
codigo,estado,mensajes,encf,secuenciaUtilizada STRING
END RECORD
DEFINE api tRespDGII
DEFINE r RECORD
codigo INTEGER,
estado STRING,
mensajes DYNAMIC ARRAY OF RECORD
codigo STRING,
valor STRING
END RECORD,
encf STRING,
secuenciaUtilizada BOOLEAN,
hash STRING,
fechaFirmaDigital STRING,
qrcodeurl STRING,
trackId STRING
END RECORD
DEFINE dummy INTEGER
DEFINE drespuesta consultaRespuesta
DEFINE otrosMensajes dgiimensaje
LET btoken =" Bearer ",btoken
LET http_req = com.HTTPRequest.Create(url_recepcion)
CALL http_req.setMethod("POST")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/json")
CALL http_req.setHeader("Authorization",btoken)
CALL http_req.setConnectionTimeOut(10)
CALL http_req.setMultipartType("form-data",NULL,NULL)
# "form-data; name=\"xml\"; filename=\"naceSignature.xml\""
IF os.Path.exists(archivo) THEN
LET contenido = "form-data; name=\"xml\"; filename=",os.path.basename(archivo)
# DISPLAY "contenido: ",contenido
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"131880681E310000000001.xml\"")
CALL http_req.setHeader("Content-Disposition", contenido CLIPPED)
CALL http_req.doFileRequest(archivo)
LET http_resp= http_req.getResponse()
LET body = http_resp.getTextResponse()
LET codigo = http_resp.getStatusCode()
CALL parse_dgii_response(body) RETURNING api.*
IF api.estado IS NULL OR api.estado = "" THEN
IF api.mensajes[1].codigo IS NOT NULL AND api.mensajes.getLength() > 0 THEN
LET api.estado = "Rechazado"
IF api.codigo IS NULL THEN LET api.codigo = 2 END IF
# ELSE
# LET api.estado = "Procesando"
END IF
END IF
IF http_resp.getStatusCode() != 200 THEN
DISPLAY "error: ",http_resp.getStatusCode()," ", util.JSON.stringify(api)
RETURN http_resp.getStatusCode(), util.JSON.stringify(api)
END IF
IF (api.hash IS NULL OR api.hash = "") OR (api.qrcodeurl IS NULL OR api.qrcodeurl = "") THEN
TRY
CALL util.JSON.parse(body,otrosMensajes)
LET api.codigo = otrosmensajes.codigo
LET api.encf = otrosmensajes.ecf
LET api.estado = otrosmensajes.estado
LET api.secuenciaUtilizada = otrosmensajes.secuenciaUtilizada
LET api.mensajes = otrosmensajes.mensajes
CATCH
CALL consultaResultado(btoken, util.JSON.stringify(api))
RETURNING dummy, consultaResp
TRY
CALL UTIL.JSON.parse(consultaResp,drespuesta)
CATCH
END TRY
LET api.codigo = drespuesta.codigo
LET api.encf = drespuesta.encf
LET api.estado = drespuesta.estado
LET api.fechaFirmaDigital = drespuesta.fechaRecepcion
LET api.trackId = drespuesta.trackid
LET api.secuenciaUtilizada = drespuesta.secuenciaUtilizada
IF dummy = 200 AND consultaResp <> "" THEN
RETURN 200, util.JSON.stringify(api)
END IF
END TRY
END IF
ELSE
LET api.codigo=401
LET api.estado = "INPROG"
LET api.mensajes[1].valor='NO ENCOENTRE EL FILE A ENVIAR'
RETURN 401, util.JSON.stringify(api)
END IF
RETURN http_resp.getStatusCode(), util.JSON.stringify(api)
END FUNCTION
FUNCTION consultaResultado(ctoken,data)
DEFINE data,ctoken,mensaje_dgii,message_err STRING
DEFINE crespuesta STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
DEFINE dtrackid RECORD
trackId,error,mensaje STRING
END RECORD
TRY
CALL util.JSON.parse(data,dtrackid)
CATCH
LET message_Err ='Error EN JSON CONSULTA RESULTADO: ',STATUS
CALL errorlog(message_Err)
END TRY
LET url_consulta = url_consulta CLIPPED,"?TrackId=",dtrackid.trackid CLIPPED
LET http_req = com.HTTPRequest.Create(url_consulta)
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.setConnectionTimeOut(10)
CALL http_req.setHeader("accept","application/json")
CALL http_req.setHeader("Authorization",ctoken)
TRY
CALL http_req.doRequest()
LET http_resp= http_req.getResponse()
LET crespuesta = http_resp.getTextResponse()
LET mensaje_dgii = "Trackid: ", dtrackid.trackid CLIPPED," respuesta: ",crespuesta, " code: ",http_resp.getStatusCode()
CATCH
LET crespuesta = 'Servicio no responde, no consulta'
RETURN 400,crespuesta
END TRY
RETURN http_resp.getStatusCode(),crespuesta
END FUNCTION
FUNCTION gettoken()
DEFINE i, l INTEGER
DEFINE r om.XmlReader
DEFINE e,tok String
DEFINE a om.SaxAttributes
# DISPLAY "filexml: ",filexml
LET r = om.XmlReader.createFileReader(rutaSemilla||"/RespuestaValida.xml")
LET l = 0
LET e = r.read()
WHILE e IS NOT NULL
CASE e
WHEN "StartDocument"
# DISPLAY "StartDocument:"
WHEN "StartElement"
LET l=l+1
# DISPLAY l SPACES, "StartElement:", r.getTagName()
LET a = r.getAttributes()
FOR i=1 to a.getLength()
IF a.getName(i) = "token" THEN
# DISPLAY l SPACES," ",
# a.getName(i)," = ",
# a.getValueByIndex(i)
END IF
END FOR
WHEN "Characters"
IF r.getTagName() = "token" THEN
LET tok = r.getCharacters()
# DISPLAY "token dentro de gettoken: ",tok
EXIT CASE
END IF
WHEN "SkippedEntity"
# DISPLAY "Entity:'",r.skippedEntity(),"'"
WHEN "EndElement"
# DISPLAY l SPACES, "EndElement:", r.getTagName()
LET l=l-1
WHEN "EndDocument"
# DISPLAY "EndDocument:"
OTHERWISE
# DISPLAY "Invalid event: ",e
END CASE
LET e=r.read()
END WHILE
RETURN tok
END FUNCTION
FUNCTION gethash(envfile)
DEFINE i, l INTEGER
DEFINE r om.XmlReader
DEFINE e,envfile STRING,
phash VARCHAR(6),
pfechafirmadigital VARCHAR(50),
facturainterna INT
DEFINE a om.SaxAttributes
DISPLAY "filexml: ",envfile
LET r = om.XmlReader.createFileReader(envfile)
LET l = 0
LET e = r.read()
WHILE e IS NOT NULL
CASE e
WHEN "StartDocument"
# DISPLAY "StartDocument:"
WHEN "StartElement"
LET l=l+1
#DISPLAY l SPACES, "StartElement:", r.getTagName()
LET a = r.getAttributes()
FOR i=1 to a.getLength()
IF a.getName(i) = "SignatureValue" THEN
LET phash = r.getCharacters()
# DISPLAY l SPACES," ",
# a.getName(i)," = ",
# a.getValueByIndex(i)
END IF
END FOR
WHEN "Characters"
IF r.getTagName() = "SignatureValue" THEN
LET phash = r.getCharacters()
# DISPLAY "token dentro de gettoken: ",tok
EXIT CASE
END IF
IF r.getTagName() = "FechaHoraFirma" THEN
LET pfechafirmadigital = r.getCharacters()
# DISPLAY "token dentro de gettoken: ",tok
EXIT CASE
END IF
IF r.getTagName() = "NumeroFacturaInterna" THEN
LET facturainterna = r.getCharacters()
DISPLAY "factura interna: ",facturainterna
EXIT CASE
END IF
WHEN "SkippedEntity"
# DISPLAY "Entity:'",r.skippedEntity(),"'"
WHEN "EndElement"
# DISPLAY l SPACES, "EndElement:", r.getTagName()
LET l=l-1
WHEN "EndDocument"
# DISPLAY "EndDocument:"
OTHERWISE
# DISPLAY "Invalid event: ",e
END CASE
LET e=r.read()
END WHILE
RETURN phash,pfechafirmadigital,facturainterna
END FUNCTION
FUNCTION buscatoken(url_semilla1)
DEFINE respuesta,url_semilla1 STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
#SELECT a.urltoken INTO url FROM companias a
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
DISPLAY "url semilla: ",url_semilla1
LET http_req = com.HTTPRequest.Create(url_semilla1)
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/xml")
# CALL http_req.setConnectionTimeOut(10)
# TRY
CALL http_req.doRequest()
LET http_resp= http_req.getResponse()
LET respuesta = http_resp.getTextResponse()
# CATCH
# LET respuesta = 'No pude conseguir el token'
# RETURN 400,respuesta
# END TRY
#DISPLAY "cod token ",http_resp.getTextResponse()," ",http_resp.getStatusCode()
# IF http_resp.getStatusCode() != 200 THEN
# RETURN http_resp.getStatusCode(), http_resp.getTextResponse()
# END IF
DISPLAY "busca token: ",respuesta
RETURN http_resp.getStatusCode(),respuesta
END FUNCTION
FUNCTION urls(xambiente,ptipoRecepcion)
DEFINE xambiente,ptipoRecepcion STRING
IF xambiente = "produccion" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/ecf/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://ecf.dgii.gov.do/ecf/Recepcion/api/FacturasElectronicas"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/ecf/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/ecf/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/ecf/ConsultaResultado/api/consultas/estado"
LET url_anulacion = "https://ecf.dgii.gov.do/eCF/anulacionrangos/api/operaciones/anularRango"
END IF
IF xambiente = "certificacion" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/Recepcion/api/FacturasElectronicas"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/CerteCF/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/CerteCF/ConsultaResultado/api/consultas/estado"
END IF
IF xambiente = "test" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/TesteCF/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/TesteCF/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/TesteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/TesteCF/ConsultaResultado/api/consultas/estado"
LET url_anulacion = "https://ecf.dgii.gov.do/TesteCF/anulacionrangos/api/operaciones/anularRango"
END IF
LET url_consulta_timbre ="https://ecf.dgii.gov.do/TesteCF/consultatimbre"
# DISPLAY url_recepcion TO act_url
END FUNCTION
FUNCTION obtenerStatus(ctoken)
DEFINE respuesta,btoken,codigo,archivo,contenido,consultaResp,ctoken STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse,
xresp RECORD
codigo,estado,mensajes,encf,secuenciaUtilizada STRING
END RECORD
LET http_req = com.HttpRequest.Create("https://statusecf.dgii.gov.do/api/estatusservicios/obtenerestatus")
DISPLAY "ctoken: ",ctoken
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.setConnectionTimeOut(10)
CALL http_req.setHeader("accept","application/json")
CALL http_req.setHeader("Authorization",ctoken)
CALL http_req.doRequest()
LET http_resp= http_req.getResponse()
LET respuesta = http_resp.getTextResponse()
LET codigo = http_resp.getStatusCode()
DISPLAY "respuesta: ",respuesta ,"codigo ",codigo
END FUNCTION
FUNCTION parse_dgii_response(raw STRING)
DEFINE s STRING,
resp tRespDGII
DEFINE w RECORD
data1 tRespDGII
END RECORD
-- Último intento: levantar sólo los campos conocidos si vienen sueltos
DEFINE m RECORD
codigo INTEGER,
estado STRING,
encf STRING,
hash STRING,
qrcodeurl STRING,
fechaFirmaDigital STRING
END RECORD
LET s = raw.trim()
DISPLAY "cero display: ",s
IF s IS NULL OR s = "" THEN
RETURN resp.*
END IF
DISPLAY "primer display: ",s
-- Si la raíz es un arreglo, envuélvelo para mapearlo a RESP.mensajes
IF s.subString(1,1) = "[" THEN
LET s = '{"mensajes":' || s || '}'
END IF
TRY
CALL util.JSON.parse(s, resp)
DISPLAY "en primer try: ",resp.*
RETURN resp.*
CATCH
-- Algunos endpoints devuelven dentro de "data1" u otro contenedor.
TRY
CALL util.JSON.parse(s, w)
LET resp = w.data1
DISPLAY "en segundo try: ",resp.*
RETURN resp.*
CATCH
TRY
CALL util.JSON.parse(s, m)
LET resp.codigo = m.codigo
LET resp.estado = m.estado
LET resp.encf = m.encf
LET resp.hash = m.hash
LET resp.qrcodeurl = m.qrcodeurl
LET resp.fechaFirmaDigital = m.fechaFirmaDigital
DISPLAY "en tercer try: ",resp.*," en adicion: ",m.*
RETURN resp.*
CATCH
-- Si nada funcionó, deja 'resp' vacío: que el llamador trate el raw
RETURN resp.*
END TRY
END TRY
END TRY
END FUNCTION
+646
View File
@@ -0,0 +1,646 @@
IMPORT os
IMPORT com
IMPORT XML
IMPORT UTIL
DEFINE url_semilla, url_validasemilla,url_anulacion,
url_recepcion,url_consulta,url_consulta_timbre STRING
DEFINE codigo,tokenxml,nombreFile,filexml,token,respuesta,ruta_firmados STRING
DEFINE doc xml.DomDocument,
xfacturainterna,gsucid,gbodega INT,
goperacion VARCHAR(30)
FUNCTION procesoEncf(fileporfirmar,ambiente,tiporecepcion,xsucid,xbodega,xoperacion,krespuesta)
DEFINE fileporfirmar,rtoken,ambiente,tiporecepcion,krespuesta STRING,
xhash VARCHAR(6),xfechafirmadigital VARCHAR(50),
xsucid,xbodega INT,
xoperacion CHAR(30)
DEFINE dtrackid RECORD
trackId,error,mensaje STRING
END RECORD
CALL STARTLOG("procesoencf.txt")
# LET ptipoRecepcion = tiporecepcion
LET ruta_firmados = fgl_getenv("RUTA_XML_FIRMADOS")
IF ambiente <> "certificacion" THEN
IF ambiente <> "test" THEN
LET respuesta = "no llego bien ",ambiente
RETURN ' ',respuesta,'400'
END IF
END IF
# LET xambiente = ambiente
CALL urls(ambiente,tiporecepcion)
CALL buscatoken() RETURNING codigo, tokenxml
IF codigo <> "200" THEN
LET respuesta = "respuesta buscatoken: ",tokenxml," ",codigo
RETURN ' ',respuesta,'400'
END IF
LET gsucid = xsucid
LET gbodega = xbodega
LET goperacion = xoperacion
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
CALL doc.loadFromString(tokenxml)
CALL doc.save("./FILESXML/TokenString.xml")
#CALL fgl_winmessage("error",doc,"info")
#FIRMA SEMILLA
IF os.Path.exists("./FILESXML/TokenString.xml") THEN
CALL firmasemilla()
ELSE
LET respuesta = "NO PUDE CREAR SEMILLA"
RETURN ' ',respuesta,'400'
END IF
IF os.Path.exists("./FILESXML/Signature.xml") THEN
CALL validasemilla() RETURNING codigo,respuesta
ELSE
LET respuesta = "NO ENCONTRE LA SEMILLA FIRMADA"
RETURN ' ',respuesta,'400'
END IF
IF respuesta IS NOT NULL THEN
LET doc = xml.DomDocument.Create()
CALL doc.loadFromString(respuesta)
CALL doc.save("./FILESXML/RespuestaValida.xml")
CALL gettoken() RETURNING rtoken
LET token = rtoken
ELSE
LET respuesta = "NO TENEMOS RESPUESTA DE VALIDA SEMILLA"
RETURN ' ',respuesta,'400'
END IF
# CUANDO EL PROCESO NO ES FIRMAR EL DOCUMENTO
IF xoperacion <> 'consultatrackid' THEN
LET filexml = fileporfirmar
CALL firmadocumento(fileporfirmar)
LET filexml = ruta_firmados CLIPPED,os.Path.baseName(fileporfirmar)
#DISPLAY "file a enviar :",filexml
CALL enviafiles(token,filexml) RETURNING codigo,respuesta
CALL gethash(filexml) RETURNING xhash,xfechafirmadigital,xfacturainterna
# DISPLAY "luego del gethash: ",xhash
# UPDATE vetb00002 SET hash = xhash WHERE factura = xfacturainterna AND sucid = xsucid
ELSE
LET token = " Bearer ",token
CALL consultaResultado(token,krespuesta) RETURNING codigo, respuesta
END IF
RETURN xhash,respuesta,codigo
END FUNCTION
FUNCTION firmadocumento(fileafirmar)
DEFINE doc xml.DomDocument
DEFINE doc2 xml.DomDocument
DEFINE root xml.DomNode
DEFINE node xml.DomNode
DEFINE signNode xml.DomNode
DEFINE sig xml.Signature
DEFINE key xml.CryptoKey
DEFINE cert xml.CryptoX509
DEFINE index INTEGER,
fileafirmar STRING
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
#DISPLAY "file ",fileafirmar
LET filexml = fileafirmar
CALL doc.load(fileafirmar)
TRY
# Create rsa key
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
CALL key.loadPEM("./cert/onlyRSA.pem")
# Create an X509 certificate with the constructor of the CryptoX509 class.
LET cert = xml.CryptoX509.Create()
CALL cert.setFeature("X509Certificate",TRUE)
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
# CALL cert.loadPEM("cert509.crt")
CALL cert.loadPEM("./cert/onlyCert.pem")
# Create signature object with the key to use
LET sig = xml.Signature.Create()
# Assign the CryptoKey object to the Signature object.
CALL sig.setKey(KEY)
# Assign the CryptoX509 object to the Signature object.
CALL sig.setCertificate(cert)
# Set XML node to be signed. In our case, the entire document
# LET index = sig.createReference("",
# "http://www.w3.org/2001/04/xmlenc#sha256")
LET index = sig.createReference('""',
"http://www.w3.org/2001/04/xmlenc#sha256")
# Add enveloped method to not take the XML signature node into account
# when computing the entire document.
CALL sig.appendReferenceTransformation(index,
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
# Set canonicalization method on the XML fragment to be signed.
# Compute enveloped signature
CALL sig.compute(doc)
# Retrieve signature document
LET doc2=sig.getDocument()
# Append the signature node to the original document to get
# a valid enveloped signature
# Notice that the enveloped signature can be added anywhere in the
# original document
LET signNode = doc2.getDocumentElement() # Get Signature node
# Import it into the original document
LET node = doc.importNode(signNode,true)
# Retrieve the original document root node
LET root = doc.getDocumentElement()
# Append the signature node as last child of the original document
CALL root.appendChild(node)
# Save document with enveloped signature back to disk
CALL doc.setFeature("format-pretty-print",TRUE)
LET fileafirmar = ruta_firmados CLIPPED,os.Path.baseName(fileafirmar)
CALL doc.save(fileafirmar)
CATCH
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
END TRY
END FUNCTION
FUNCTION firmasemilla()
DEFINE doc xml.DomDocument
DEFINE doc2 xml.DomDocument
DEFINE root xml.DomNode
DEFINE node xml.DomNode
DEFINE signNode xml.DomNode
DEFINE sig xml.Signature
DEFINE key xml.CryptoKey
DEFINE cert xml.CryptoX509
DEFINE index INTEGER
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
LET filexml = "./FILESXML/TokenString.xml"
IF os.Path.exists(filexml) THEN
CALL doc.load(filexml)
ELSE
DISPLAY "NO LO ENCONTRE"
RETURN
END IF
TRY
# Create rsa key
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
CALL key.loadPEM("./cert/onlyRSA.pem")
# Create an X509 certificate with the constructor of the CryptoX509 class.
LET cert = xml.CryptoX509.Create()
CALL cert.setFeature("X509Certificate",TRUE)
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
# CALL cert.loadPEM("cert509.crt")
CALL cert.loadPEM("./cert/onlyCert.pem")
# Create signature object with the key to use
LET sig = xml.Signature.Create()
# Assign the CryptoKey object to the Signature object.
CALL sig.setKey(KEY)
# Assign the CryptoX509 object to the Signature object.
CALL sig.setCertificate(cert)
# Set XML node to be signed. In our case, the entire document
# LET index = sig.createReference("",
# "http://www.w3.org/2001/04/xmlenc#sha256")
LET index = sig.createReference('""',
"http://www.w3.org/2001/04/xmlenc#sha256")
# Add enveloped method to not take the XML signature node into account
# when computing the entire document.
CALL sig.appendReferenceTransformation(index,
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
# Set canonicalization method on the XML fragment to be signed.
# CALL sig.appendReferenceTransformation(index,
# "http://www.w3.org/2001/10/xml-exc-c14n#")
# Compute enveloped signature
CALL sig.compute(doc)
# Retrieve signature document
LET doc2=sig.getDocument()
# Append the signature node to the original document to get
# a valid enveloped signature
# Notice that the enveloped signature can be added anywhere in the
# original document
LET signNode = doc2.getDocumentElement() # Get Signature node
# Import it into the original document
LET node = doc.importNode(signNode,true)
# Retrieve the original document root node
LET root = doc.getDocumentElement()
# Append the signature node as last child of the original document
CALL root.appendChild(node)
# Save document with enveloped signature back to disk
CALL doc.setFeature("format-pretty-print",TRUE)
CALL doc.save("./FILESXML/Signature.xml")
CATCH
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
END TRY
END FUNCTION
FUNCTION validasemilla()
DEFINE respuesta,codigo STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
LET http_req = com.HTTPRequest.Create(url_validasemilla)
CALL http_req.setMethod("POST")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/xml")
CALL http_req.setMultipartType("form-data",NULL,NULL)
IF os.Path.exists("./FILESXML/Signature.xml") THEN
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"Signature.xml\"")
CALL http_req.doFileRequest("./FILESXML/Signature.xml")
ELSE
DISPLAY "NO LO ENCUENTRO"
RETURN 0,"FILE NO EXISTE"
END IF
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
# CALL http_req.doFileRequest("naceSignature.xml")
LET http_resp= http_req.getResponse()
LET codigo = http_resp.getStatusCode()
LET respuesta = http_resp.getTextResponse()
IF http_resp.getStatusCode() != 200 THEN
DISPLAY "error Validar Semilla: ",codigo," ", respuesta
RETURN codigo, respuesta
END IF
DISPLAY "valida semilla: ",codigo," ", respuesta
RETURN codigo, respuesta
END FUNCTION
FUNCTION enviafiles(btoken,archivo)
DEFINE respuesta,btoken,codigo,archivo,contenido,consultaResp STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse,
xresp RECORD
codigo,estado,mensajes,encf,secuenciaUtilizada STRING
END RECORD
LET btoken =" Bearer ",btoken
LET http_req = com.HTTPRequest.Create(url_recepcion)
CALL http_req.setMethod("POST")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/json")
CALL http_req.setHeader("Authorization",btoken)
CALL http_req.setMultipartType("form-data",NULL,NULL)
# "form-data; name=\"xml\"; filename=\"naceSignature.xml\""
IF os.Path.exists(archivo) THEN
DISPLAY "archivo a enviar: ",archivo," url ",url_recepcion
LET contenido = "form-data; name=\"xml\"; filename=",os.path.basename(archivo)
# DISPLAY "contenido: ",contenido
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"131880681E310000000001.xml\"")
CALL http_req.setHeader("Content-Disposition", contenido CLIPPED)
CALL http_req.doFileRequest(archivo)
LET http_resp= http_req.getResponse()
LET codigo = http_resp.getStatusCode()
LET respuesta= http_resp.getTextResponse()
IF http_resp.getStatusCode() != 200 THEN
DISPLAY "error: ",codigo," ", respuesta
RETURN codigo, respuesta
END IF
ELSE
RETURN 0,respuesta
END IF
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
# CALL http_req.doFileRequest("naceSignature.xml")
DISPLAY "envia respuesta: ", respuesta
CALL util.JSON.parse(respuesta,xresp)
# CALL consultaResultado(btoken,respuesta) RETURNING consultaResp
# DISPLAY "responde consulta: ",consultaresp," ",xfacturainterna
# LET respuesta = util.JSON.stringify(xresp)
RETURN codigo, respuesta
END FUNCTION
FUNCTION consultaResultado(ctoken,data)
DEFINE data,ctoken,mensaje_dgii,message_err STRING
DEFINE crespuesta STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
DEFINE dtrackid RECORD
trackId,error,mensaje STRING
END RECORD
DISPLAY "TRACK: ",data
TRY
CALL util.JSON.parse(data,dtrackid)
CATCH
LET message_Err ='Error EN JSON CONSULTA RESULTADO: ',STATUS
CALL errorlog(message_Err)
END TRY
#SELECT a.urltoken INTO url FROM companias a
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
LET url_consulta = url_consulta CLIPPED,"?TrackId=",dtrackid.trackid CLIPPED
LET http_req = com.HTTPRequest.Create(url_consulta)
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.setConnectionTimeOut(10)
CALL http_req.setHeader("accept","application/json")
CALL http_req.setHeader("Authorization",ctoken)
CALL http_req.doRequest()
LET http_resp= http_req.getResponse()
LET crespuesta = http_resp.getTextResponse()
LET mensaje_dgii = "Trackid: ", dtrackid.trackid CLIPPED," respuesta: ",crespuesta, " code: ",http_resp.getStatusCode()
# DISPLAY BY NAME mensaje_dgii
DISPLAY "MENSAJE CONSULTA: ",crespuesta
# LET dtrackid.mensaje = crespuesta CLIPPED
# LET crespuesta = util.JSON.stringify(dtrackid)
RETURN http_resp.getStatusCode(),crespuesta
END FUNCTION
FUNCTION gettoken()
DEFINE i, l INTEGER
DEFINE r om.XmlReader
DEFINE e,tok String
DEFINE a om.SaxAttributes
# DISPLAY "filexml: ",filexml
LET r = om.XmlReader.createFileReader("./FILESXML/RespuestaValida.xml")
LET l = 0
LET e = r.read()
WHILE e IS NOT NULL
CASE e
WHEN "StartDocument"
# DISPLAY "StartDocument:"
WHEN "StartElement"
LET l=l+1
#DISPLAY l SPACES, "StartElement:", r.getTagName()
LET a = r.getAttributes()
FOR i=1 to a.getLength()
IF a.getName(i) = "token" THEN
# DISPLAY l SPACES," ",
# a.getName(i)," = ",
# a.getValueByIndex(i)
END IF
END FOR
WHEN "Characters"
IF r.getTagName() = "token" THEN
LET tok = r.getCharacters()
# DISPLAY "token dentro de gettoken: ",tok
EXIT CASE
END IF
WHEN "SkippedEntity"
# DISPLAY "Entity:'",r.skippedEntity(),"'"
WHEN "EndElement"
# DISPLAY l SPACES, "EndElement:", r.getTagName()
LET l=l-1
WHEN "EndDocument"
# DISPLAY "EndDocument:"
OTHERWISE
# DISPLAY "Invalid event: ",e
END CASE
LET e=r.read()
END WHILE
RETURN tok
END FUNCTION
FUNCTION gethash(envfile)
DEFINE i, l INTEGER
DEFINE r om.XmlReader
DEFINE e,envfile STRING,
phash VARCHAR(6),
pfechafirmadigital VARCHAR(50),
facturainterna INT
DEFINE a om.SaxAttributes
DISPLAY "filexml: ",envfile
LET r = om.XmlReader.createFileReader(envfile)
LET l = 0
LET e = r.read()
WHILE e IS NOT NULL
CASE e
WHEN "StartDocument"
# DISPLAY "StartDocument:"
WHEN "StartElement"
LET l=l+1
#DISPLAY l SPACES, "StartElement:", r.getTagName()
LET a = r.getAttributes()
FOR i=1 to a.getLength()
IF a.getName(i) = "SignatureValue" THEN
LET phash = r.getCharacters()
# DISPLAY l SPACES," ",
# a.getName(i)," = ",
# a.getValueByIndex(i)
END IF
END FOR
WHEN "Characters"
IF r.getTagName() = "SignatureValue" THEN
LET phash = r.getCharacters()
# DISPLAY "token dentro de gettoken: ",tok
EXIT CASE
END IF
IF r.getTagName() = "FechaHoraFirma" THEN
LET pfechafirmadigital = r.getCharacters()
# DISPLAY "token dentro de gettoken: ",tok
EXIT CASE
END IF
IF r.getTagName() = "NumeroFacturaInterna" THEN
LET facturainterna = r.getCharacters()
DISPLAY "factura interna: ",facturainterna
EXIT CASE
END IF
WHEN "SkippedEntity"
# DISPLAY "Entity:'",r.skippedEntity(),"'"
WHEN "EndElement"
# DISPLAY l SPACES, "EndElement:", r.getTagName()
LET l=l-1
WHEN "EndDocument"
# DISPLAY "EndDocument:"
OTHERWISE
# DISPLAY "Invalid event: ",e
END CASE
LET e=r.read()
END WHILE
RETURN phash,pfechafirmadigital,facturainterna
END FUNCTION
FUNCTION buscatoken()
DEFINE respuesta STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
#SELECT a.urltoken INTO url FROM companias a
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
LET http_req = com.HTTPRequest.Create(url_semilla)
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/xml")
CALL http_req.doRequest()
#CALL http_req.doTextRequest(url)
LET http_resp= http_req.getResponse()
IF http_resp.getStatusCode() != 200 THEN
RETURN http_resp.getStatusCode(), http_resp.getTextResponse()
END IF
LET respuesta = http_resp.getTextResponse()
RETURN http_resp.getStatusCode(),respuesta
END FUNCTION
FUNCTION urls(xambiente,ptipoRecepcion)
DEFINE xambiente,ptipoRecepcion STRING
IF xambiente = "test" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/ecf/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/ecf/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/ecf/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/ecf/ConsultaResultado/api/consultas/estado"
LET url_anulacion = "https://ecf.dgii.gov.do/eCF/anulacionrangos/api/operaciones/anularRango"
END IF
IF xambiente = "certificacion" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://fc.dgii.gov.do/testecf/RecepcionFC/api/Recepcion/ecf"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/CerteCF/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/CerteCF/ConsultaResultado/api/consultas/estado"
END IF
IF xambiente = "test" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/TesteCF/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/TesteCF/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/TesteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/TesteCF/ConsultaResultado/api/consultas/estado"
LET url_anulacion = "https://ecf.dgii.gov.do/TesteCF/anulacionrangos/api/operaciones/anularRango"
END IF
LET url_consulta_timbre ="https://ecf.dgii.gov.do/TesteCF/consultatimbre"
# DISPLAY url_recepcion TO act_url
END FUNCTION
+718
View File
@@ -0,0 +1,718 @@
import os
import com
import xml
import util
DEFINE url_semilla, url_validasemilla,url_anulacion,
url_recepcion,url_consulta,url_consulta_timbre STRING
DEFINE codigo,tokenxml,nombreFile,filexml,token,respuesta,ruta_firmados,rutaSemilla,rutaCert STRING
DEFINE doc xml.DomDocument,
xfacturainterna,gsucid,gbodega INT,
goperacion VARCHAR(30)
FUNCTION procesoEncf(fileporfirmar,ambiente,tiporecepcion,xsucid,xbodega,xoperacion,krespuesta)
DEFINE fileporfirmar,rtoken,ambiente,tiporecepcion,krespuesta STRING,
xhash VARCHAR(6),xfechafirmadigital VARCHAR(50),
xsucid,xbodega INT,
xoperacion CHAR(30)
DEFINE dtrackid RECORD
trackId,error,mensaje STRING
END RECORD,
xfecha DATETIME YEAR TO minute
CALL STARTLOG("procesoencf.txt")
# LET ptipoRecepcion = tiporecepcion
LET ruta_firmados = fgl_getenv("RUTA_XML_FIRMADOS")
LET rutaSemilla = fgl_getenv("RUTA_SEMILLA")
LET rutaCert = fgl_getenv("RUTA_CERT")
DISPLAY "ruta firma ",ruta_firmados
IF ambiente <> "produccion" THEN
IF ambiente <> "test" THEN
LET respuesta = "no llego bien ",ambiente
RETURN ' ',respuesta,'400'
END IF
END IF
# LET xambiente = ambiente
CALL urls(ambiente,tiporecepcion)
{
SELECT a.valor,a.fecha INTO rtoken,xfecha
FROM token a
DISPLAY "tiempos: ",xfecha," ",CURRENT HOUR TO MINUTE}
# IF CURRENT HOUR TO MINUTE- xfecha > "0:44" THEN
CALL buscatoken() RETURNING codigo, tokenxml
IF codigo <> "200" THEN
LET respuesta = "respuesta buscatoken: ",tokenxml," ",codigo
RETURN ' ',respuesta,'400'
END IF
LET gsucid = xsucid
LET gbodega = xbodega
LET goperacion = xoperacion
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
CALL doc.loadFromString(tokenxml)
# CALL doc.save(".\\filesXML\\marmotech\\mtechTokenString.xml")
CALL doc.save(rutaSemilla||"/TokenString.xml")
#FIRMA SEMILLA
IF os.Path.exists(rutaSemilla||"/TokenString.xml") THEN
CALL firmasemilla()
ELSE
LET respuesta = "NO PUDE CREAR SEMILLA"
RETURN ' ',respuesta,'400'
END IF
IF os.Path.exists(rutaSemilla||"/Signature.xml") THEN
CALL validasemilla() RETURNING codigo,respuesta
IF codigo = 400 THEN
RETURN ' ',respuesta,'400'
END IF
ELSE
LET respuesta = "NO ENCONTRE LA SEMILLA FIRMADA"
RETURN ' ',respuesta,'400'
END IF
IF respuesta IS NOT NULL THEN
LET doc = xml.DomDocument.Create()
CALL doc.loadFromString(respuesta)
CALL doc.save(rutaSemilla||"/RespuestaValida.xml")
CALL gettoken() RETURNING rtoken
LET token = rtoken
# UPDATE token SET valor = rtoken,fecha=getdate()
ELSE
LET respuesta = "NO TENEMOS RESPUESTA DE VALIDA SEMILLA"
RETURN ' ',respuesta,'400'
END IF
# ELSE
# DISPLAY "en validar semilla"
# CALL validasemilla() RETURNING codigo,respuesta
# IF codigo = 400 THEN
# RETURN ' ',respuesta,'400'
# END IF
# END IF
DISPLAY "file a enviar1 :",fileporfirmar
# CUANDO EL PROCESO NO ES FIRMAR EL DOCUMENTO
IF xoperacion <> 'consultatrackid' AND xoperacion <> 'consultastatus' THEN
LET filexml = fileporfirmar
CALL firmadocumento(fileporfirmar)
LET filexml = ruta_firmados CLIPPED,os.Path.baseName(fileporfirmar)
DISPLAY "file a enviar :",filexml
CALL enviafiles(token,filexml) RETURNING codigo,respuesta
CALL gethash(filexml) RETURNING xhash,xfechafirmadigital,xfacturainterna
DISPLAY "luego del gethash: ",xhash
# UPDATE vetb00002 SET hash = xhash WHERE factura = xfacturainterna AND sucid = xsucid
ELSE
IF xoperacion = 'consultatrackid' THEN
LET token = " Bearer ",token
CALL consultaResultado(token,krespuesta) RETURNING codigo, respuesta
END IF
IF xoperacion = 'consultastatus' THEN
LET token = " ApiKey ",token
CALL obtenerStatus(token)
END IF
END IF
RETURN xhash,respuesta,codigo
END FUNCTION
FUNCTION firmadocumento(fileafirmar)
DEFINE doc xml.DomDocument
DEFINE doc2 xml.DomDocument
DEFINE root xml.DomNode
DEFINE node xml.DomNode
DEFINE signNode xml.DomNode
DEFINE sig xml.Signature
DEFINE key xml.CryptoKey
DEFINE cert xml.CryptoX509
DEFINE index INTEGER,
fileafirmar STRING
LET rutaCert = fgl_getenv("RUTA_CERT")
LET ruta_firmados = fgl_getenv("RUTA_XML_FIRMADOS")
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
DISPLAY "file ",fileafirmar
LET filexml = fileafirmar
CALL doc.load(fileafirmar)
TRY
# Create rsa key
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
#CALL key.loadPEM(".\\cert\\marmotech\\onlyRSA.pem")
CALL key.loadPEM(rutaCert clipped||"/onlyRSA.pem")
# Create an X509 certificate with the constructor of the CryptoX509 class.
LET cert = xml.CryptoX509.Create()
CALL cert.setFeature("X509Certificate",TRUE)
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
# CALL cert.loadPEM("cert509.crt")
CALL cert.loadPEM(rutaCert clipped||"/onlyCert.pem")
# Create signature object with the key to use
LET sig = xml.Signature.Create()
# Assign the CryptoKey object to the Signature object.
CALL sig.setKey(KEY)
# Assign the CryptoX509 object to the Signature object.
CALL sig.setCertificate(cert)
# Set XML node to be signed. In our case, the entire document
# LET index = sig.createReference("",
# "http://www.w3.org/2001/04/xmlenc#sha256")
LET index = sig.createReference('""',
"http://www.w3.org/2001/04/xmlenc#sha256")
# Add enveloped method to not take the XML signature node into account
# when computing the entire document.
CALL sig.appendReferenceTransformation(index,
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
# Set canonicalization method on the XML fragment to be signed.
# Compute enveloped signature
CALL sig.compute(doc)
# Retrieve signature document
LET doc2=sig.getDocument()
# Append the signature node to the original document to get
# a valid enveloped signature
# Notice that the enveloped signature can be added anywhere in the
# original document
LET signNode = doc2.getDocumentElement() # Get Signature node
# Import it into the original document
LET node = doc.importNode(signNode,true)
# Retrieve the original document root node
LET root = doc.getDocumentElement()
# Append the signature node as last child of the original document
CALL root.appendChild(node)
# Save document with enveloped signature back to disk
CALL doc.setFeature("format-pretty-print",TRUE)
LET fileafirmar = ruta_firmados CLIPPED,os.Path.baseName(fileafirmar)
CALL doc.save(fileafirmar)
DISPLAY "file firmado", fileafirmar
CATCH
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
DISPLAY "aqui"
END TRY
END FUNCTION
FUNCTION firmasemilla()
DEFINE doc xml.DomDocument
DEFINE doc2 xml.DomDocument
DEFINE root xml.DomNode
DEFINE node xml.DomNode
DEFINE signNode xml.DomNode
DEFINE sig xml.Signature
DEFINE key xml.CryptoKey
DEFINE cert xml.CryptoX509
DEFINE index INTEGER
LET rutaCert = fgl_getenv("RUTA_CERT")
# Create DomDocument object
LET doc = xml.DomDocument.Create()
# Notice that whitespaces are significant in cryptography,
# therefore it is recommended to remove unnecessary ones
CALL doc.setFeature("whitespace-in-element-content",FALSE)
LET filexml = rutaSemilla||"/TokenString.xml"
IF os.Path.exists(filexml) THEN
CALL doc.load(filexml)
ELSE
DISPLAY "NO LO ENCONTRE"
RETURN
END IF
TRY
# Create rsa key
LET key = xml.CryptoKey.Create("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
CALL key.loadPEM(rutaCert||"/onlyRSA.pem")
# Create an X509 certificate with the constructor of the CryptoX509 class.
LET cert = xml.CryptoX509.Create()
CALL cert.setFeature("X509Certificate",TRUE)
# Load the X509 certificate associated to the RSA or DSA private key into the CryptoKey object.
# CALL cert.loadPEM("cert509.crt")
CALL cert.loadPEM(rutaCert||"/onlyCert.pem")
# Create signature object with the key to use
LET sig = xml.Signature.Create()
# Assign the CryptoKey object to the Signature object.
CALL sig.setKey(KEY)
# Assign the CryptoX509 object to the Signature object.
CALL sig.setCertificate(cert)
# Set XML node to be signed. In our case, the entire document
# LET index = sig.createReference("",
# "http://www.w3.org/2001/04/xmlenc#sha256")
LET index = sig.createReference('""',
"http://www.w3.org/2001/04/xmlenc#sha256")
# Add enveloped method to not take the XML signature node into account
# when computing the entire document.
CALL sig.appendReferenceTransformation(index,
"http://www.w3.org/2000/09/xmldsig#enveloped-signature",doc.getDocumentElement())
# Set canonicalization method on the XML fragment to be signed.
# CALL sig.appendReferenceTransformation(index,
# "http://www.w3.org/2001/10/xml-exc-c14n#")
# Compute enveloped signature
CALL sig.compute(doc)
# Retrieve signature document
LET doc2=sig.getDocument()
# Append the signature node to the original document to get
# a valid enveloped signature
# Notice that the enveloped signature can be added anywhere in the
# original document
LET signNode = doc2.getDocumentElement() # Get Signature node
# Import it into the original document
LET node = doc.importNode(signNode,true)
# Retrieve the original document root node
LET root = doc.getDocumentElement()
# Append the signature node as last child of the original document
CALL root.appendChild(node)
# Save document with enveloped signature back to disk
CALL doc.setFeature("format-pretty-print",TRUE)
CALL doc.save(rutaSemilla||"/Signature.xml")
CATCH
DISPLAY "Unable to create an enveloped signature :",status," ",sqlca.sqlerrm
END TRY
END FUNCTION
FUNCTION validasemilla()
DEFINE respuesta,codigo STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
LET http_req = com.HTTPRequest.Create(url_validasemilla)
CALL http_req.setMethod("POST")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/xml")
CALL http_req.setMultipartType("form-data",NULL,NULL)
CALL http_req.setConnectionTimeOut(10)
IF os.Path.exists(rutaSemilla||"/Signature.xml") THEN
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"Signature.xml\"")
# TRY
CALL http_req.doFileRequest(rutaSemilla||"/Signature.xml")
# CATCH
-- Intentar obtener la
# RETURN 400, "NO OBTUVE RESPUESTA DEL SERICIO AL VALIDAR SEMILLA"
# END TRY
-- Continuar con la ejecución normal si no se produjo una excepción
LET http_resp = http_req.getResponse()
LET codigo = http_resp.getStatusCode()
LET respuesta = http_resp.getTextResponse()
DISPLAY "respuesta valida semilla: ",respuesta
ELSE
LET codigo=400
LET respuesta='NO ENCONTRE EL FILE PARA VALIDAR SEMILLA'
END IF
RETURN codigo, respuesta
END FUNCTION
FUNCTION enviafiles(btoken,archivo)
DEFINE respuesta,btoken,codigo,archivo,contenido,consultaResp STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse,
xresp RECORD
codigo,estado,mensajes,encf,secuenciaUtilizada STRING
END RECORD
LET btoken =" Bearer ",btoken
LET http_req = com.HTTPRequest.Create(url_recepcion)
CALL http_req.setMethod("POST")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/json")
CALL http_req.setHeader("Authorization",btoken)
CALL http_req.setConnectionTimeOut(10)
CALL http_req.setMultipartType("form-data",NULL,NULL)
# "form-data; name=\"xml\"; filename=\"naceSignature.xml\""
IF os.Path.exists(archivo) THEN
DISPLAY "archivo a enviar: ",archivo," url ",url_recepcion
LET contenido = "form-data; name=\"xml\"; filename=",os.path.basename(archivo)
# DISPLAY "contenido: ",contenido
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"131880681E310000000001.xml\"")
CALL http_req.setHeader("Content-Disposition", contenido CLIPPED)
CALL http_req.doFileRequest(archivo)
LET http_resp= http_req.getResponse()
LET codigo = http_resp.getStatusCode()
LET respuesta= http_resp.getTextResponse()
IF http_resp.getStatusCode() != 200 THEN
DISPLAY "error: ",codigo," ", respuesta
RETURN codigo, respuesta
END IF
ELSE
RETURN 0,respuesta
END IF
# CALL http_req.setHeader("Content-Disposition", "form-data; name=\"xml\"; filename=\"naceSignature.xml\"")
# CALL http_req.doFileRequest("naceSignature.xml")
DISPLAY "envia respuesta: ", respuesta
CALL util.JSON.parse(respuesta,xresp)
# CALL consultaResultado(btoken,respuesta) RETURNING consultaResp
# DISPLAY "responde consulta: ",consultaresp," ",xfacturainterna
# LET respuesta = util.JSON.stringify(xresp)
RETURN codigo, respuesta
END FUNCTION
FUNCTION consultaResultado(ctoken,data)
DEFINE data,ctoken,mensaje_dgii,message_err STRING
DEFINE crespuesta STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
DEFINE dtrackid RECORD
trackId,error,mensaje STRING
END RECORD
DISPLAY "consultatrackid: ",ctoken," || ",data
TRY
CALL util.JSON.parse(data,dtrackid)
CATCH
LET message_Err ='Error EN JSON CONSULTA RESULTADO: ',STATUS
CALL errorlog(message_Err)
END TRY
LET url_consulta = url_consulta CLIPPED,"?TrackId=",dtrackid.trackid CLIPPED
LET http_req = com.HTTPRequest.Create(url_consulta)
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.setConnectionTimeOut(10)
CALL http_req.setHeader("accept","application/json")
CALL http_req.setHeader("Authorization",ctoken)
TRY
CALL http_req.doRequest()
LET http_resp= http_req.getResponse()
LET crespuesta = http_resp.getTextResponse()
LET mensaje_dgii = "Trackid: ", dtrackid.trackid CLIPPED," respuesta: ",crespuesta, " code: ",http_resp.getStatusCode()
CATCH
LET crespuesta = 'Servicio no responde, no consulta'
RETURN 400,crespuesta
END TRY
RETURN http_resp.getStatusCode(),crespuesta
END FUNCTION
FUNCTION gettoken()
DEFINE i, l INTEGER
DEFINE r om.XmlReader
DEFINE e,tok String
DEFINE a om.SaxAttributes
# DISPLAY "filexml: ",filexml
LET r = om.XmlReader.createFileReader(rutaSemilla||"/RespuestaValida.xml")
LET l = 0
LET e = r.read()
WHILE e IS NOT NULL
CASE e
WHEN "StartDocument"
# DISPLAY "StartDocument:"
WHEN "StartElement"
LET l=l+1
# DISPLAY l SPACES, "StartElement:", r.getTagName()
LET a = r.getAttributes()
FOR i=1 to a.getLength()
IF a.getName(i) = "token" THEN
# DISPLAY l SPACES," ",
# a.getName(i)," = ",
# a.getValueByIndex(i)
END IF
END FOR
WHEN "Characters"
IF r.getTagName() = "token" THEN
LET tok = r.getCharacters()
# DISPLAY "token dentro de gettoken: ",tok
EXIT CASE
END IF
WHEN "SkippedEntity"
# DISPLAY "Entity:'",r.skippedEntity(),"'"
WHEN "EndElement"
# DISPLAY l SPACES, "EndElement:", r.getTagName()
LET l=l-1
WHEN "EndDocument"
# DISPLAY "EndDocument:"
OTHERWISE
# DISPLAY "Invalid event: ",e
END CASE
LET e=r.read()
END WHILE
RETURN tok
END FUNCTION
FUNCTION gethash(envfile)
DEFINE i, l INTEGER
DEFINE r om.XmlReader
DEFINE e,envfile STRING,
phash VARCHAR(6),
pfechafirmadigital VARCHAR(50),
facturainterna INT
DEFINE a om.SaxAttributes
DISPLAY "filexml: ",envfile
LET r = om.XmlReader.createFileReader(envfile)
LET l = 0
LET e = r.read()
WHILE e IS NOT NULL
CASE e
WHEN "StartDocument"
# DISPLAY "StartDocument:"
WHEN "StartElement"
LET l=l+1
#DISPLAY l SPACES, "StartElement:", r.getTagName()
LET a = r.getAttributes()
FOR i=1 to a.getLength()
IF a.getName(i) = "SignatureValue" THEN
LET phash = r.getCharacters()
# DISPLAY l SPACES," ",
# a.getName(i)," = ",
# a.getValueByIndex(i)
END IF
END FOR
WHEN "Characters"
IF r.getTagName() = "SignatureValue" THEN
LET phash = r.getCharacters()
# DISPLAY "token dentro de gettoken: ",tok
EXIT CASE
END IF
IF r.getTagName() = "FechaHoraFirma" THEN
LET pfechafirmadigital = r.getCharacters()
# DISPLAY "token dentro de gettoken: ",tok
EXIT CASE
END IF
IF r.getTagName() = "NumeroFacturaInterna" THEN
LET facturainterna = r.getCharacters()
DISPLAY "factura interna: ",facturainterna
EXIT CASE
END IF
WHEN "SkippedEntity"
# DISPLAY "Entity:'",r.skippedEntity(),"'"
WHEN "EndElement"
# DISPLAY l SPACES, "EndElement:", r.getTagName()
LET l=l-1
WHEN "EndDocument"
# DISPLAY "EndDocument:"
OTHERWISE
# DISPLAY "Invalid event: ",e
END CASE
LET e=r.read()
END WHILE
RETURN phash,pfechafirmadigital,facturainterna
END FUNCTION
FUNCTION buscatoken()
DEFINE respuesta STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse
#SELECT a.urltoken INTO url FROM companias a
#"https://ecf.dgii.gov.do/testecf/autenticacion/api/autenticacion/semilla"
#"https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/Semilla"
DISPLAY "url semilla: ",url_semilla
LET http_req = com.HTTPRequest.Create(url_semilla)
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.setHeader("accept","application/xml")
# CALL http_req.setConnectionTimeOut(10)
# TRY
CALL http_req.doRequest()
LET http_resp= http_req.getResponse()
LET respuesta = http_resp.getTextResponse()
# CATCH
# LET respuesta = 'No pude conseguir el token'
# RETURN 400,respuesta
# END TRY
#DISPLAY "cod token ",http_resp.getTextResponse()," ",http_resp.getStatusCode()
# IF http_resp.getStatusCode() != 200 THEN
# RETURN http_resp.getStatusCode(), http_resp.getTextResponse()
# END IF
DISPLAY "busca token: ",respuesta
RETURN http_resp.getStatusCode(),respuesta
END FUNCTION
FUNCTION urls(xambiente,ptipoRecepcion)
DEFINE xambiente,ptipoRecepcion STRING
IF xambiente = "produccion" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/ecf/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://ecf.dgii.gov.do/ecf/Recepcion/api/FacturasElectronicas"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/ecf/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/ecf/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/ecf/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/ecf/ConsultaResultado/api/consultas/estado"
LET url_anulacion = "https://ecf.dgii.gov.do/eCF/anulacionrangos/api/operaciones/anularRango"
END IF
IF xambiente = "certificacion" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://ecf.dgii.gov.do/CerteCF/Recepcion/api/FacturasElectronicas"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/CerteCF/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/CerteCF/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/CerteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/CerteCF/ConsultaResultado/api/consultas/estado"
END IF
IF xambiente = "test" THEN
IF ptipoRecepcion = "normal" THEN
LET url_recepcion ="https://ecf.dgii.gov.do/TesteCF/Recepcion/api/FacturasElectronicas"
ELSE
IF ptipoRecepcion = 'consumo' THEN
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
END IF
END IF
IF ptipoRecepcion = 'normal32' THEN
LET url_recepcion ="https://fc.dgii.gov.do/TesteCF/RecepcionFC/api/Recepcion/ecf"
END IF
LET url_semilla ="https://ecf.dgii.gov.do/TesteCF/autenticacion/api/autenticacion/semilla"
LET url_validasemilla ="https://ecf.dgii.gov.do/TesteCF/Autenticacion/api/Autenticacion/ValidarSemilla"
LET url_consulta = "https://ecf.dgii.gov.do/TesteCF/ConsultaResultado/api/consultas/estado"
LET url_anulacion = "https://ecf.dgii.gov.do/TesteCF/anulacionrangos/api/operaciones/anularRango"
END IF
LET url_consulta_timbre ="https://ecf.dgii.gov.do/TesteCF/consultatimbre"
# DISPLAY url_recepcion TO act_url
END FUNCTION
FUNCTION obtenerStatus(ctoken)
DEFINE respuesta,btoken,codigo,archivo,contenido,consultaResp,ctoken STRING,
http_req com.HttpRequest,
http_resp com.HTTPResponse,
xresp RECORD
codigo,estado,mensajes,encf,secuenciaUtilizada STRING
END RECORD
LET http_req = com.HttpRequest.Create("https://statusecf.dgii.gov.do/api/estatusservicios/obtenerestatus")
DISPLAY "ctoken: ",ctoken
CALL http_req.setMethod("GET")
CALL http_req.setCharset("UTF-8")
CALL http_req.setConnectionTimeOut(10)
CALL http_req.setHeader("accept","application/json")
CALL http_req.setHeader("Authorization",ctoken)
CALL http_req.doRequest()
LET http_resp= http_req.getResponse()
LET respuesta = http_resp.getTextResponse()
LET codigo = http_resp.getStatusCode()
DISPLAY "respuesta: ",respuesta ,"codigo ",codigo
END FUNCTION
+602
View File
@@ -0,0 +1,602 @@
account,0
actb00001,445
actb00002,939
actb00004,1188
actb00005,1562
actb00010,2005
adb00034,2359
adtb00001,2537
adtb00002,2932
adtb00003,3175
adtb00004,5236
adtb00005,5686
adtb00006,5886
adtb00007,6090
adtb00008,6286
adtb00009,6486
adtb00010,6793
adtb00011,6991
adtb00012,7844
adtb00013,9542
adtb00014,9958
adtb00015,10362
adtb00016,10942
adtb00017,11397
adtb00018,11880
adtb00019,12676
adtb00020,12981
adtb00021,13925
adtb00022,14244
adtb00023,15043
adtb00024,15389
adtb00025,15590
adtb00026,15787
adtb00027,16402
adtb00028,16777
adtb00029,16964
adtb00030,17245
adtb00031,17317
adtb00032,17409
adtb00033,18015
adtb00036,18240
adtb00038,18516
adtb00040,18570
adtb00041,18867
adtb00042,19134
adtb00043,19334
adtb00045,19659
adtb00046,19794
adtb00047,19913
adtb00048,20232
adtb00049,20321
adtb00050,20430
adtb00051,20581
adtb00052,20761
adtb00053,20857
altbd00001,21054
altbm00001,21299
aqui,21715
bloques,21769
bono2011,21866
bono2011d,22358
category,22624
cctb00001,22755
cctb00001bk,23647
cctb00002,24571
cctb00003,24850
cctb00004,25095
cctb00005,25506
cctb00008,25704
cctb00011,26064
cctb00013,26880
cctb00019,27164
cctb00020,27253
cctb00021,27957
cctb00022,28346
cctb00023,28606
cctb00024,28994
cctb00025,29205
cctb00026,29643
cctb00027,30434
cctb00028,31042
cctb00029,31100
cctb00030,31274
cctb00031,31882
cctb00032,32401
cctb00033,32884
cctb00034,33223
cctb00040,33601
cctb00041,33716
cgtb00001,33820
cgtb00002,34507
cgtb00003,34699
cgtb00004,34910
cgtb00004bk,35515
cgtb00005,36072
cgtb00005bk,36571
cgtb00006,37108
cgtb00009,37571
cgtb00010,37758
cgtb00011,37945
cgtb00012,38214
cgtb00014,38635
cgtb00016,38796
cgtb00017,39200
cgtb00018,39794
cgtb00023,40284
cgtb00031,40530
cgtb00032,40721
cgtb00033,41117
cgtb00034,41570
cgtb00035,41728
cgtb00036,41792
cgtb00060,42040
cgtb00074,42228
cgtb00077,42291
cgtb00083,42353
cgtb00084,42468
cgtb04,42602
cgtbh00004,43053
ch_itbi,43594
chequeo,43617
codigo20,43693
codigo21,43773
codigos,43874
codigos22,43971
companias,44076
componentes_cocinas_gioto,44980
correos,45816
cotb00001,45920
cotb00002,46466
cotb00003,46760
cotb00004,46952
cotb00005,47281
cotb00006,47503
cotb00008,48128
cotb00010,48645
cotb00011,48699
cotb00012,49194
cotb00013,49573
cotb00014,49924
cotb00015,50610
cotb00017,51145
cotb00018,51495
cotb00019,51695
cotb00022,51975
cotb00024,52185
cotb00025,52431
cotb00027,52924
cotb00028,53121
cotb00029,53143
cotb00030,53763
cotb00031,53923
cotb00033,54172
cotb00034,54763
cotb00036,55195
cotb00038,55392
cotb00042,55826
cotizacion,56198
cotizacion_detalle,57072
country,57688
cptb00001,57735
cptb00002,58322
cptb00003,58627
cptb00004,59106
cptb00005,59388
cptb00006,59867
cptb00007,60347
cttb00001,60457
cttb00002,60740
cttb00003,60921
cttb00004,61538
cttb00006,61619
cttb00007,61966
cttb00008,62164
cttb00009,62511
cttb00010,62871
cttb00011,63089
cttb00012,63386
cttb00013,63762
cttb00014,64198
cttb00015,64432
cttb00016,64747
cttb00017,64826
cttb00018,65437
cttb00021,65627
cttb00022,65836
cttb00023,66134
cttb00026,66438
cttb00027,66703
cttb00028,66855
cttb00029,67202
cttb00032,67446
cttb00033,68266
cttb00034,68401
cttb00036,68646
cttb00038,69026
cttb00039,69301
cttb00041,69426
cttb00042,69723
cttb000log1,69970
cttb000log2,70087
dbocodigos20,70586
decomarmoljob,70682
demos,70748
departamentos,71021
dgii_rnc,71204
dgii_rnc3,71543
diatable,71783
dstb00001,71834
dstb00002,72278
dstb00003,72579
dstb00004,72776
dstb00005,73017
dstb00006,73440
dstb00007,73666
emventas,73869
encuesta,73979
formadepago,74562
inrp00002,74622
intb00001,74880
intb00002,75247
intb00003,75732
intb00004,76140
intb00005,76548
intb00006,76876
intb00007,77663
intb00008,77877
intb00009,78259
intb00010,78388
intb00011,78482
intb00012,78895
intb00013,79318
intb00014,79694
intb00015,80007
intb00018,80391
intb00019,80875
intb00020,81405
intb00022,82290
intb00023,82722
intb00026,82934
intb00040,83281
intb00041,83654
intb00042,84052
intb00043,84412
intb00043_,84538
intb00043a,84663
intb00044,84791
inventory,84949
iptb00001,85001
iptb00002,85341
iptb00003,86180
iptb00004,86451
iptb00005,87005
iptb00006,87584
iptb00007,88965
iptb00008,89179
iptb00010,89990
iptb00011,90439
iptb00012,90852
iptb00013,91364
iptb00014,91603
iptb00015,91927
iptb00016,92017
iptb00017,92857
iptb00019,93664
iptb00020,93854
iptb00021,94097
iptb00022,94288
iptb00023,94510
iptb00024,94628
iptb00025,94863
iptb00026,95414
iptb00027,95522
iptb00028,95627
iptb00029,95757
iptb00030,95959
iptb00031,96161
iptb00032,96218
iptb00033,96303
iptb00034,97242
iptb00035,97310
iptb00040,97419
iptb00041,97792
iptb00042,98190
iptb00043,98550
iptb00044,98603
iptb00045,98886
iptb00046,98977
iptb00047,99066
iptb00048,99153
iptb00049,99209
iptb00050,99628
iptb00056,99942
iptb00057,100406
iptb00058,100966
iptb00059,101497
iptb025,101587
iptbexistencia,102023
ircodigos,102309
irtb00001,102439
irtb00002,102781
irtb00005,103274
irtb00006,103602
irtb00007,104321
irtb00008,104822
irtb00009,105351
irtb00010,105671
irtb00011,105871
irtb00012,106288
irtb00013,106713
irtb00014,107083
irtb00016,107271
irtb00017,107584
irtb00018,107968
irtb00027,108022
irtb00029,108482
irtb00030,108686
irtb00040,108888
irtb00041,109261
irtb00042,109659
istb00002,110019
istb00006,110608
item,111317
lajas,111561
lajas14,111650
lajas2,111747
lajas2_,111840
lineitem,111937
listaprecio,112078
localizacion,112358
mallas9,112456
marzo_,112553
mestable,112638
molduras23,112840
msgtable,112952
nc,113106
notb00001,113614
notb00002,113697
notb00003,114283
notb00005,114620
notb00006,114839
notb00007,115190
notb00008,115643
notb00009,116090
notb00010,116306
notb00011,116758
notb00012,117178
notb00013,117333
notb00014,117520
notb00015,117600
notb00016,117990
notb00017,118437
notb00018,118600
notb00019,118795
notb00020,119047
notb00021,119410
notb00023,119662
notb00033,120069
notb00050,120741
notb0019,120945
notb03,121188
notbcuenta,121489
notbingresos,121574
ntb00005,121633
orders,121950
orderstatus,122629
pda5,122749
permisos,123171
prdtable,123289
precios,123572
preciosc,123792
product,123920
prordenlog,124053
prordenstatus,124369
prtb00001,124732
prtb00002,124829
prtb00003,125127
prtb00004,125428
prtb00005,125588
prtb00006,125777
prtb00007,126075
prtb00008,126559
prtb00009,126836
prtb00010,127119
prtb00011,127478
prtb00012,127808
prtb00013,128897
prtb00014,129596
prtb00015,129796
prtb00016,130084
prtb00017,130277
prtb00018,130507
prtb00019,130825
prtb00020,130956
prtb00021,131036
prtb00022,131701
prtb00023,132229
prtb00024,132498
prtb00025,132550
prtb00026,132834
prtb00027,133231
prtb00028,133424
prtb00029,133690
prtb00030,134052
prtb00031,134193
prtb00032,134542
prtb00033,134676
prtb00034,135016
prttb00001,135072
prttb00002,135235
prueba,135319
ptordenesgral,135826
ptventasgral,137177
ptventasgralh,139296
query,141174
ranking,141557
repitecodigo,141883
repitecodigotmp,142071
seg0000,142138
seg0001,142522
seg0003,143444
seg0004,143972
seg0005,144078
seg00051,144238
seg0006,144412
seg0007,144491
seg0008,144658
seg0009,144707
seqreg,144762
signon,144813
sucursales,144865
supplier,145235
svtb00001,145450
svtb00002,146773
svtb00003,146900
svtb00004,147162
svtb00005,147854
svtb00006,148274
svtb00007,148391
svtb00008,149084
tasa,149411
tetb00003,149432
tetb00006,149662
tmp2iptb00012,149874
tmp3iptb00012,150458
tmp_kit,151042
tmpactualiza,151297
tmpaumento,151521
tmpbalances,151656
tmpbonifica,151787
tmpcam,152030
tmpccprrp027,152161
tmpccrp48,152498
tmpcctb01,153061
tmpclase,153732
tmpclase1,153787
tmpclasificacion,153849
tmpclientes,154090
tmpcod11,154527
tmpcod12,154597
tmpcodigorepetido,154667
tmpcodigos,154871
tmpcodigos1,154980
tmpcodsec,155174
tmpcostos,155230
tmpcostos1,155566
tmpcostosferia,155756
tmpcuadre,156062
tmpcxc,156293
tmpdescuento,156393
tmpdespiece,156544
tmpdetallefact,156965
tmpdiasinv,157237
tmpduplicados,157543
tmpempresas1,157726
tmpexcel,158077
tmpfacturas,158136
tmpfacturas_ext,158559
tmpfempleados,158702
tmpgrupo,158891
tmpinventario,158950
tmpinventariofisico,159278
tmpinvm,159691
tmpipprrp013,159985
tmpiptb00002,160452
tmpiptb00006,161446
tmpiptb00012,162392
tmpiptb00027,162958
tmpiptb012,163075
tmpmatprima,163605
tmpmedida,163747
tmpnomina,163806
tmpnotascr,164081
tmpofertas,164401
tmpordenes,164564
tmpplanchas,164699
tmpprecios,164896
tmpprecios_costos,165153
tmppreciosferia,165437
tmppreciosg1,165787
tmppreciosg2,166030
tmppreciosm1,166273
tmppreciosm2,166514
tmpproductos,166755
tmprepuestos,166907
tmprepuestos1,167127
tmptipo,167576
tmptipocuenta,167632
tmpventas,167762
tmpventas43,167878
tmpvetb00002,168140
tmpvetb00003,169145
topics,169612
travertino,169738
userinfo,169874
usuarios,171003
vacaciones,171092
ventas,171486
ventas_soporte,172124
vetb00001,172218
vetb00002,172407
vetb00003,174208
vetb00004,174859
vetb00005,175641
vetb00006,175991
vetb00007,176540
vetb00008,176762
vetb00009,176951
vetb00010,177143
vetb00011,177403
vetb00012,177765
vetb000123,178074
vetb00013,178484
vetb00014,178967
vetb00015,179343
vetb00016,179816
vetb00018,180052
vetb00019,180262
vetb00020,180587
vetb00022,180893
vetb00023,181401
vetb00024,181657
vetb00025,182129
vetb00025b,182651
vetb00025bk,183113
vetb00025c,183671
vetb00026,184133
vetb00027,184188
vetb00028,184638
vetb00029,184908
vetb00030,185317
vetb00031,185546
vetb00032,185831
vetb00033,186064
vetb00042,186329
vetb00044,186661
vetb00045,186976
vetb000454,187443
vetb00048,188005
vetb00049,188200
vetb00050,188470
vetb00051,189912
vetb00052,190759
vetb00053,191237
vetb00060,191297
vetb00061,191906
vetb00071,192058
vetb00072,192453
vetb00073,192644
vetb00075,192805
vetb00076,192929
vetb00084,193118
vetb00085,193173
vetb00086,193466
vetb00087,193681
vetb00088,194152
vetb00090,194520
vetb00091,194702
vetb00092,195251
vetb00093,195633
vetb00094,195810
vetb00095,196065
vetb00096,196383
vetb00097,196486
vetb00098,196810
vetb00099,196842
vetb00100,198851
vetb00101,199032
viejo1,199100
vwanalisisventas,199282
vwanalitico,200150
vwanaliticoh,200934
vwclientes,201716
vwclientesnocompran,202057
vwcobros,202402
vwcodigosnuevos,203029
vwcomisiones,203707
vwcompras,204830
vwconduces,205313
vwcontactosclientes,206045
vwcostosproductos,206292
vwcuentasporcobrar,206732
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff