Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #  Responce
  2. Set Variable [ $responseCode ; Value: httpResponseCode ( $header ) ]
  3. If [ $responseCode202 and $responseCode > 400 ]
  4.     #  HTTP code 400 could be for an document already received by Hacienda or BAD request
  5.     #  HTTP code 401 unauthorized in some cases is wrong
  6.     #  HTTP code 403 Forbidden in some cases is wrong
  7.     #  HTTP code ≥ 500 Hacienda down always true
  8.     Perform Script [ Specified: From list ; “Limpiar Tokens” ; Parameter:    ]
  9.     #  If error try one more time
  10.     If [ $$try1 ]
  11.         Set Variable [ $$try ; Value: 1 ]
  12.         Perform Script [ Specified: From list ; “5 - Enviar a Hacienda” ; Parameter:    ]
  13.         Exit Script [ Text Result:    ]
  14.     End If
  15.     If [ $responseCode500 ]
  16.         #  Call PHP script via BE_OpenURL to change the status of Hacienda in the JSON document
  17.         Perform Script [ Specified: From list ; “Hacienda DOWN” ; Parameter:    ]
  18.         Set Field By Name [ GetFieldName (  Case (   $table = "FACT_facturas" ;   FACT_facturas::haciendaEstado ;   $table = "gastos_DAGA" ;   gastos_DAGA::HAMEestadoRecibido  ) ) ; "Servicio NO Disponible" ]
  19.         Commit Records/Requests [ With dialog: Off ]
  20.         Halt Script
  21.     Else If [ $responseCode401 ]
  22.         Set Field By Name [ GetFieldName (  Case (   $table = "FACT_facturas" ;   FACT_facturas::haciendaEstado ;   $table = "gastos_DAGA" ;   gastos_DAGA::HAMEestadoRecibido  ) ) ; "Error" ]
  23.         Perform Script [ Specified: From list ; “Limpiar Tokens” ; Parameter:    ]
  24.         Commit Records/Requests [ With dialog: Off ]
  25.         Exit Script [ Text Result:    ]
  26.     End If
  27.     #  Check 400 error and Payload error
  28. Else If [ $responseCode = 400 and PatternCount ( $header ; "El Payload no incluye alguno de los campos requeridos" ) ]
  29.     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  ] ) ]
  30.     Halt Script
  31. End If
  32. #
  33. #  Finish
  34. If [ $table = "FACT_facturas" ]
  35.     #    LOG
  36.     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 ]  ) ) ]
  37.     #
  38.     #  In case we are sending this again and it was already received
  39.     If [ PatternCount ( $header ; "ya fue recibido anteriormente." ) ]
  40.         Perform Script [ Specified: From list ; “7 - Comprobar estado” ; Parameter:    ]
  41.     Else
  42.         #  KendoUI data
  43.         Perform Script [ Specified: From list ; “11 - Kendo Data” ; Parameter:    ]
  44.     End If
  45. Else If [ $table = "gastos_DAGA" ]
  46.     #  Location URL Covers error 401 already received XML
  47.     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" ) ) ]
  48.     #  In case we are sending this again and it was already received
  49.     If [ PatternCount ( $header ; "ya fue recibido anteriormente." ) ]
  50.         Perform Script [ Specified: From list ; “7 - Comprobar estado” ; Parameter:    ]
  51.     Else
  52.         #  KendoUI data
  53.         Perform Script [ Specified: From list ; “22 - GAST - Kendo Data” ; Parameter:    ]
  54.     End If
  55. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement