@ -1,4 +1,6 @@
--[[
Ingresa los datos de la operacion en la pagina de AFIP , es la parte de la tabla donde se agregan los items , monto unitario y descripcion .
Recibe un JSON con los datos de la operacion , por ejemplo :
{
" uid " : " 53935f27-5cf0-4281-9a29-a68f100ee981 " ,
" execution_status " : " Borrador " ,
@ -18,70 +20,123 @@
}
--]]
log ( " Inicio afip_ingresar_datos_operacion from LUA!! " )
local err
local json = require ( " json " )
-- Parse the JSON string
local obj , err = json.decode ( json_payload )
if err then
message = " Error parsing JSON: " .. err
----------------------------------------------------------------------
-- Helpers
----------------------------------------------------------------------
local function logErrorAndExit ( message )
log ( message )
error ( message )
end
local error_on_page
local function is_factura ( tipo_comprobante )
return string.match ( tipo_comprobante , " factura " )
end
descripcion = obj [ " descripcion " ]
monto_unitario = obj [ " monto_unitario " ]
tipo_comprobante = obj [ " tipo_comprobante " ]
local function is_recibo ( tipo_comprobante )
return string.match ( tipo_comprobante , " recibo " )
end
--[[
if string.match ( tipo_comprobante , " factura " ) then
log ( " Setting tipo_comprobante to factura " )
tipo_comprobante = " factura "
else
log ( " Setting tipo_comprobante to " )
tipo_comprobante = " recibo "
local function input_recibo_data ( descripcion , monto_unitario , tipo_comprobante )
--[[
< textarea class = " soloTexto " name = " detalleDescripcion " id = " detalle_descripcion " maxlength = " 400 " style = " width:500px; " rows = " 6 " onkeypress = " return limitarLongitudTextArea(event,this,400); " onkeyup = " recortar(this,400); " onblur = " recortar(this,400); " ></ textarea >
--]]
log ( " afip_ingresar_datos_operacion.input_recibo_data Descripcion: " .. descripcion .. " Monto: " .. monto_unitario .. " Tipo: " .. tipo_comprobante )
descripcion_selector = " #detalle_descripcion "
err = setTextFieldByQuerySelector ( descripcion_selector , descripcion )
if err then
message = " Error setting detalle_descripcion: " .. err
logErrorAndExit ( message )
end
--[[
< input type = " text " class = " soloNumerosConDecimales " name = " detallePrecio " maxlength = " 16 " id = " detalle_precio " onkeyup = " calcularSubtotalDetalle(); " >
--]]
precio_selector = " #detalle_precio "
err = setTextFieldByQuerySelector ( precio_selector , monto_unitario )
if err then
message = " Error setting detalle_precio: " .. err
logErrorAndExit ( message )
end
end
--]]
-- TODO: handle factura AND recibo!
log ( " Descripcion: " .. descripcion .. " Monto: " .. monto_unitario .. " Tipo: " .. tipo_comprobante )
local function input_factura_data ( descripcion , monto_unitario , tipo_comprobante )
log ( " afip_ingresar_datos_operacion.input_factura_data Descripcion: " .. descripcion .. " Monto: " .. monto_unitario .. " Tipo: " .. tipo_comprobante )
descripcion_selector = " #detalle_descripcion1 "
precio_selector = " #detalle_precio1 "
-- TODO: Properly handle recibo which has different fields!
-- Descripcion : <textarea class="soloTexto" name="detalleDescripcion" id="detalle_descripcion" maxlength="400" style="width:500px;" rows="6" onkeypress="return limitarLongitudTextArea(event,this,400);" onkeyup="recortar(this,400);" onblur="recortar(this,400);"></textarea>
-- Monto:
err = waitVisibleByQuerySelector ( descripcion_selector )
if err then
message = " Error waiting for detalle_descripcion1: " .. err
log ( message )
error ( message )
end
descripcion_selector = " #detalle_descripcion1 "
precio_selector = " #detalle_precio1 "
err = setTextField ByQuerySelector( descripcion_selector , descripcion )
if err then
message = " Error setting detalle_descripcion1: " .. err
log ( message )
error ( message )
end
err = waitVisibleByQuerySelector ( descripcion_selector )
if err then
message = " Error waiting for detalle_descripcion1: " .. err
log ( message )
error ( message )
end
waitSecs ( 1 )
err = setTextFieldByQuerySelector ( descripcion_selector , descripcion )
if err then
message = " Error setting detalle_descripcion1: " .. err
log ( message )
error ( message )
end
err = waitVisibleByQuerySelector ( precio_selector )
if err then
message = " Error waiting for detalle_precio1: " .. err
log ( message )
error ( message )
end
waitSecs ( 1 )
err = setTextFieldByQuerySelector ( precio_selector , monto_unitario )
if err then
message = " Error setting detalle_precio1: " .. err
log ( message )
error ( message )
err = waitVisibleByQuerySelector ( precio_selector )
if err then
message = " Error waiting for detalle_precio1: " .. err
log ( message )
error ( message )
end
err = setTextFieldByQuerySelector ( precio_selector , monto_unitario )
if err then
message = " Error setting detalle_precio1: " .. err
log ( message )
error ( message )
end
waitSecs ( 1 )
end
waitSecs ( 1 )
log ( " Finishing afip_ingresar_datos_operacion from LUA!! " )
----------------------------------------------------------------------
-- Main logic
----------------------------------------------------------------------
local function main ( )
log ( " Inicio afip_ingresar_datos_operacion from LUA!! " )
local err
local json = require ( " json " )
-- Parse the JSON string
local obj , err = json.decode ( json_payload )
if err then
message = " Error parsing JSON: " .. err
log ( message )
error ( message )
end
local error_on_page
descripcion = obj [ " descripcion " ]
monto_unitario = obj [ " monto_unitario " ]
tipo_comprobante = obj [ " tipo_comprobante " ]
if is_factura ( tipo_comprobante ) then
input_factura_data ( descripcion , monto_unitario , tipo_comprobante )
elseif is_recibo ( tipo_comprobante ) then
input_recibo_data ( descripcion , monto_unitario , tipo_comprobante )
else
message = " Tipo de comprobante no soportado en afip_ingresar_datos_operacion: " .. tostring ( tipo_comprobante )
logErrorAndExit ( message )
end
log ( " Finishing afip_ingresar_datos_operacion " )
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 datosDeEmision
logErrorAndExit ( " afip_ingresar_datos_operacion failed: " .. tostring ( err ) )
end