Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Responce
- Set Variable [ $responseCode ; Value: httpResponseCode ( $header ) ]
- If [ $responseCode ≠ 202 and $responseCode > 400 ]
- # HTTP code 400 could be for an document already received by Hacienda or BAD request
- # HTTP code 401 unauthorized in some cases is wrong
- # HTTP code 403 Forbidden in some cases is wrong
- # HTTP code ≥ 500 Hacienda down always true
- Perform Script [ Specified: From list ; “Limpiar Tokens” ; Parameter: ]
- # If error try one more time
- If [ $$try ≠ 1 ]
- Set Variable [ $$try ; Value: 1 ]
- Perform Script [ Specified: From list ; “5 - Enviar a Hacienda” ; Parameter: ]
- Exit Script [ Text Result: ]
- End If
- If [ $responseCode ≥ 500 ]
- # Call PHP script via BE_OpenURL to change the status of Hacienda in the JSON document
- Perform Script [ Specified: From list ; “Hacienda DOWN” ; Parameter: ]
- Set Field By Name [ GetFieldName ( Case ( $table = "FACT_facturas" ; FACT_facturas::haciendaEstado ; $table = "gastos_DAGA" ; gastos_DAGA::HAMEestadoRecibido ) ) ; "Servicio NO Disponible" ]
- Commit Records/Requests [ With dialog: Off ]
- Halt Script
- Else If [ $responseCode ≥ 401 ]
- Set Field By Name [ GetFieldName ( Case ( $table = "FACT_facturas" ; FACT_facturas::haciendaEstado ; $table = "gastos_DAGA" ; gastos_DAGA::HAMEestadoRecibido ) ) ; "Error" ]
- Perform Script [ Specified: From list ; “Limpiar Tokens” ; Parameter: ]
- Commit Records/Requests [ With dialog: Off ]
- Exit Script [ Text Result: ]
- End If
- # Check 400 error and Payload error
- Else If [ $responseCode = 400 and PatternCount ( $header ; "El Payload no incluye alguno de los campos requeridos" ) ]
- Perform Script [ Specified: From list ; “0076 - Send email with Errors to iGenius” ; Parameter: JSONSetElement ( "{}" ; [ "subject" ; "Error en el Script: " & Get ( ScriptName ) & " de " & $$NombreDeLaEmpresa ; JSONString ] ; [ "body" ; "El Script: " & Get ( ScriptName ) & " ha fallado con el error: " & ErrorMessage ( $error ) & & & $cURL_options & & & $trace & & & $header & & & Case ( $table = "FACT_facturas" ; "Factura Nº " & FACT_facturas::haciendaNumeracionElectronica ; $table = "gastos_DAGA" ; "Gasto Nº " & gastos_DAGA::HAMEclaveMensaje ) ; JSONString ] ) ]
- Halt Script
- End If
- #
- # Finish
- If [ $table = "FACT_facturas" ]
- # LOG
- Perform Script [ Specified: From list ; “Log - Send Log Entry” ; Parameter: Let ( [ $logAction = "Se envió la " & FACT_facturas::tipoFactura & " " & FACT_facturas::haciendaNumeracionElectronica & " al Ministerio de Hacienda, respuesta: " & If ( $responseCode = 202 ; "Recibido exitosamente" ; $responseCode ) ; ~num = 4 ; ~var = "Crear registro" & & // 1 "Eliminar registro" & ¶ & // 2 "Modificar datos" & ¶ & // 3 "Enviar información" & ¶ & // 4 "Imprimir datos" & ¶ & // 5 "Error" & ¶ & // 6 "Ver gráficas" & ¶ & // 7 "Ver registro" & ¶ & // 8 "Exportar datos" & ¶ & // 9 "Ejecutar script" & ¶ & // 10 "Entrar en módulo" ; // 11 $logType = GetValue ( ~var ; ~num ) ; $snapshot = False ; $kp_FACT = FACT_facturas::__kp_FACT ] ; JSONSetElement ( "{}" ; [ "log.kp_FACT" ; $kp_FACT ; JSONNumber ] ; [ "log.type" ; $logType ; JSONString ] ; [ "log.action" ; $logAction ; JSONString ] ; [ "snapshot" ; $snapshot ; JSONString ] ) ) ]
- #
- # In case we are sending this again and it was already received
- If [ PatternCount ( $header ; "ya fue recibido anteriormente." ) ]
- Perform Script [ Specified: From list ; “7 - Comprobar estado” ; Parameter: ]
- Else
- # KendoUI data
- Perform Script [ Specified: From list ; “11 - Kendo Data” ; Parameter: ]
- End If
- Else If [ $table = "gastos_DAGA" ]
- # Location URL Covers error 401 already received XML
- Set Field [ gastos_DAGA::HAMElocationURL ; If ( PatternCount ( $header ; "ya fue recibido anteriormente." ) ; If ( $produccion = 1 ; "https://api.comprobanteselectronicos.go.cr/recepcion/v1/recepcion/" ; "https://api.comprobanteselectronicos.go.cr/recepcion-sandbox/v1/recepcion/" ) & gastos_DAGA::HAMEclaveEmisor & "-" & gastos_DAGA::HAMEnumeracionConsecutivaAceptado & gastos_DAGA::HAMEnumeracionConsecutivaAceptadoParcial ; GetHttpHeader ( $header ; "location" ) ) ]
- # In case we are sending this again and it was already received
- If [ PatternCount ( $header ; "ya fue recibido anteriormente." ) ]
- Perform Script [ Specified: From list ; “7 - Comprobar estado” ; Parameter: ]
- Else
- # KendoUI data
- Perform Script [ Specified: From list ; “22 - GAST - Kendo Data” ; Parameter: ]
- End If
- End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement