You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.9 KiB

local json = require("json")
----------------------------------------------------------------------
-- Helpers
----------------------------------------------------------------------
local function logErrorAndExit(message)
log(message)
error(message)
end
----------------------------------------------------------------------
-- Main logic
----------------------------------------------------------------------
local function main()
log("afip_ingresar_generacion_comprobantes: starting")
--------------------------------------------------------------------
-- Decode payload (currently unused but kept for future extensibility)
--------------------------------------------------------------------
local payload, err = json.decode(json_payload or "{}")
if err then
logErrorAndExit("afip_ingresar_generacion_comprobantes: error decoding payload: " .. err)
end
--------------------------------------------------------------------
-- Click on the Generar Comprobantes button
-- This mirrors the Go logic that waits for and clicks the element
-- with id="btn_gen_cmp" using chromedp.
--------------------------------------------------------------------
local btnId = "btn_gen_cmp"
-- Ensure the element is visible first
err = waitVisibleById(btnId)
if err then
logErrorAndExit(
"afip_ingresar_generacion_comprobantes: waitVisibleById failed for btnId= " ..
tostring(btnId) .. ": " .. tostring(err)
)
end
-- Click using id
err = clickElementById(btnId)
if err then
logErrorAndExit(
"afip_ingresar_generacion_comprobantes: clickElementById failed for btnId= " ..
tostring(btnId) .. ": " .. tostring(err)
)
end
log("afip_ingresar_generacion_comprobantes: completed successfully")
end
local ok, err = pcall(main)
if not ok then
-- Let Go see this as a Lua error so it can fall back to legacy
logErrorAndExit("afip_ingresar_generacion_comprobantes failed: " .. tostring(err))
end