f = loadstring(GET)()
--===================================================================
function unescape (s)
s = string.gsub(s, "%%(%x%x)", function (h)
return string.char(tonumber(h, 16))
end)
s = string.gsub (s, "+", " ")
return s
end
local function strpad(input, pad_length, pad_string, pad_type)
local output = input
if not pad_string then pad_string = ' ' end
if not pad_type then pad_type = 'STR_PAD_RIGHT' end
if pad_type == 'STR_PAD_BOTH' then
local j = 0
while string.len(output) < pad_length do
output = j % 2 == 0 and output .. pad_string or pad_string .. output
j = j + 1
end
else
while string.len(output) < pad_length do
output = pad_type == 'STR_PAD_LEFT' and pad_string .. output or output .. pad_string
end
end
return output
end
--===================================================================
local function split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
local function centralizaLinha (texto, tamanhoMidia, padStr)
if (texto == nil) then
return ""
end
local tamTexto = string.len (texto);
if (tamTexto < tamanhoMidia) then
local tamanhoPad = ((tamanhoMidia / 2) + (tamTexto / 2));
return strpad(texto, tamanhoPad, padStr, 'STR_PAD_LEFT');
else
return texto;
end
end
--===================================================================
function centralizaTexto (texto, tamanhoMidia, padStr, lineStr, pula)
if (texto == nil) then
return ""
end
local palavras = split(texto, " ");
local textoDaLinhaAtual = "";
local textoFinal = "";
for i, palavra in ipairs(palavras) do
if (string.len (textoDaLinhaAtual) + string.len (palavra) + 1 <= tamanhoMidia) then
if (textoDaLinhaAtual ~= "") then
textoDaLinhaAtual = textoDaLinhaAtual .. " ";
end
textoDaLinhaAtual = textoDaLinhaAtual .. palavra;
else
textoFinal = textoFinal .. centralizaLinha (textoDaLinhaAtual, tamanhoMidia, padStr) .. lineStr;
textoDaLinhaAtual = palavra;
end
end
textoFinal = textoFinal .. centralizaLinha (textoDaLinhaAtual, tamanhoMidia, padStr);
if (pula) then
textoFinal = textoFinal .. lineStr;
end
return textoFinal;
end
-- from sam_lie
-- Compatible with Lua 5.0 and 5.1.
-- Disclaimer : use at own risk especially for hedge fund reports :-)
---============================================================
-- add comma to separate thousands
--
function comma_value(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return formatted
end
---============================================================
-- rounds a number to the nearest decimal places
--
function round(val, decimal)
if (decimal) then
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
else
return math.floor(val+0.5)
end
end
--===================================================================
-- given a numeric value formats output with comma to separate thousands
-- and rounded to given decimal places
--
--
function format_num(amount, decimal, prefix, neg_prefix)
local str_amount, formatted, famount, remain
decimal = decimal or 2 -- default 2 decimal places
neg_prefix = neg_prefix or "-" -- default negative sign
famount = math.abs(round(amount,decimal))
famount = math.floor(famount)
remain = round(math.abs(amount) - famount, decimal)
-- comma to separate the thousands
formatted = comma_value(famount)
-- attach the decimal portion
if (decimal > 0) then
remain = string.sub(tostring(remain),3)
formatted = formatted .. "." .. remain ..
string.rep("0", decimal - string.len(remain))
end
-- attach prefix string e.g '$'
formatted = (prefix or "") .. formatted
-- if value is negative then format accordingly
if (amount<0) then
if (neg_prefix=="()") then
formatted = "("..formatted ..")"
else
formatted = neg_prefix .. formatted
end
end
return formatted
end
--===================================================================
if (f["ERROARQ"] ~= nil and f["ERROARQ"] ~= "0") then
echo("")
echo("
")
echo("
Erro de arquivo
")
echo(" Codigo: " .. f["ERROARQ"] .. "
")
echo(" Venda
nao computada")
echo("")
echo("")
echo("")
echo(" dofile(\"init.lua\")")
echo("")
else
db = sqlite3.open('banco.s3db')
db:exec("delete from ingresso_pendente;")
db:close()
for key, value in pairs(f) do
echo ("")
end
if (f["QUANTIDADE_IMPRESSA"] ~= "1" or (tonumber(f["SUB_CLASSES"]) ~= 0 and tonumber(f["SUB_CLASSE"]) ~= tonumber(f["SUB_CLASSES"]) -1)) then
echo ("")
echo ("
Ultimo ingressos
Computado
Pressione VERDE
para continuar.")
end
echo ("")
echo ("
Imprimindo...
Ingresso nao
computado")
echo ("
" .. f["QUANTIDADE_IMPRESSA"] .. "/" .. f["QUANTIDADE"])
echo ("");
echo ("")
-- echo "";
echo "";
echo ("")
echo (centralizaTexto(f["BARCODE"], 20, " ", "
", true))
echo ("")
if (f["TEM_LOGO"]=="S") then
echo ("")
end
echo ("")
echo ("")
echo (centralizaTexto(unescape(f["EVENTO_NOME"]), 20, " ", "
", false))
echo ("");
echo "";
echo ("")
echo ("
")
if (f["EVE_DATA"] ~= nil) then
echo (centralizaTexto("Data: " .. unescape(f["EVE_DATA"]), 20, " ", "
", true))
end
if (f["EVE_HORA"] ~= nil) then
echo (centralizaTexto("Hora: " .. unescape(f["EVE_HORA"]), 20, " ", "
", true))
end
echo (centralizaTexto("Cidade: " .. unescape(f["EVE_CIDADE"]), 20, " ", "
", true))
echo (centralizaTexto("Local: " .. unescape(f["EVE_LOCAL"]), 20, " ", "
", true))
echo ("
")
echo ("");
echo ("")
echo ("")
echo (centralizaTexto(unescape(f["CLA_NOME"]), 20, " ", "
", true))
if (f["MODALIDADE"] ~= nil) then
if (f["MODALIDADE"] == "2") then
echo (centralizaTexto("MEIA", 20, " ", "
", true))
end
if (f["MODALIDADE"] == "1" and f["MEIA_INTEIRA"] == "1") then
echo (centralizaTexto("INTEIRA", 20, " ", "
", true))
end
if (f["MODALIDADE"] == "0" and f["MEIA_INTEIRA"] == "0") then
echo (centralizaTexto("", 20, " ", "
", true))
end
end
if (f["CLN_NUM"] ~= nil) then
if (f["NUMERACAO_TEXTO_I"] ~= nil) then
for linha in string.gmatch(string.gsub(f["NUMERACAO_TEXTO_I"], "(%%250[AD])", ";"), "[^;]+") do
echo(centralizaTexto(unescape(linha), 20, " ", "
", true))
end
end
echo (centralizaTexto(unescape(f["CLN_NUM"]), 20, " ", "
", true))
end
echo ("");
echo "";
echo ("")
echo ("
");
if(f["LOTE_VIRADA"] ~= nil) then
echo (centralizaTexto(f["LOTE_VIRADA"].."ยบ Lote", 20, " ", "
", true)) -- Virada do lote de ingresso 2016/12/06
end
if (f["VALOR_FORMATADO"] ~= nil) then
echo (centralizaTexto("Ingresso R$ " .. f["VALOR_FORMATADO"], 20, " ", "
", true));
end
if (f["VALOR_TAXA_FORMATADO"] ~= nil) then
echo (centralizaTexto("Taxa R$ " .. f["VALOR_TAXA_FORMATADO"], 20, " ", "
", true));
end
if (f["VALOR_TOTAL_FORMATADO"] ~= nil) then
echo (centralizaTexto("Total: R$ " .. f["VALOR_TOTAL_FORMATADO"], 20, " ", "
", true));
end
serial = string.sub(f["SERIALCODE"], 1, 3) .. "-" .. string.sub(f["SERIALCODE"], 4, 6) .. "-" .. string.sub(f["SERIALCODE"], 7, 9)
echo (centralizaTexto("PDV: " .. unescape(f["PDV_NOME"]), 20, " ", "
", true));
echo (centralizaTexto("POS 1: " .. serial, 20, " ", "
", true));
echo ("Impresso: " .. unescape(f["DATA"]) .. "
" .. " Hora: " .. unescape(f["HORA"]) .. "
");
echo (unescape(f["SITE"]));
echo ("");
echo ("")
echo (" dofile(\"imprimet.lua\")")
echo ("");
end