f = loadstring(GET)() --=================================================================== function transformSqlString(s) if (s == nil) then return "NULL" else return "'" .. s .. "'" end end --=================================================================== 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) 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) .. lineStr; return textoFinal; 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["PRINTSTS"] ~= nil and f["PRINTSTS"] ~= "0") then echo("") echo("
") if (f["PRINTSTS"] == "-21") then echo("
Erro de impressao
") echo(" SEM PAPEL
") echo(" Codigo: " .. f["PRINTSTS"] .. "
") else echo("
Erro de impressao
") echo(" Codigo: " .. f["PRINTSTS"] .. "
") end echo(" Ultima venda
nao computada") echo("
") echo("") echo("") echo(" dofile(\"init.lua\")") echo("") else for key, value in pairs(f) do if (key ~= "QUANTIDADE_IMPRESSA") then echo ("") end end campos = "numeracao, modalidade, evento_nome, evento_nome_pos, tela, menu, serialcode, evento, classe, evento_codigo, valor, itc_codigo, classe_cod, quantidade, quantidade_impressa, barcode, cla_nome, pdv_nome, evento_frase, sub_classe, sub_classes, old_classe, valor_taxa, meio_pgto, cartao_auth, lote_virada, gruponumerado" valores = transformSqlString(f["NUMERACAO"]) .. ", " valores = valores .. transformSqlString(f["MODALIDADE"]) .. ", " valores = valores .. transformSqlString(f["EVENTO_NOME"]) .. ", " valores = valores .. transformSqlString(f["EVENTO_NOME_POS"]) .. ", " valores = valores .. transformSqlString(f["TELA"]) .. ", " valores = valores .. transformSqlString(f["MENU"]) .. ", " valores = valores .. transformSqlString(f["SERIALCODE"]) .. ", " valores = valores .. transformSqlString(nil) .. ", " valores = valores .. transformSqlString(nil) .. ", " valores = valores .. transformSqlString(f["EVENTO_CODIGO"]) .. ", " valores = valores .. transformSqlString(f["VALOR"]) .. ", " valores = valores .. transformSqlString(f["ITC_CODIGO"]) .. ", " valores = valores .. transformSqlString(f["CLASSE_COD"]) .. ", " valores = valores .. transformSqlString(f["QUANTIDADE"]) .. ", " valores = valores .. transformSqlString(f["QUANTIDADE_IMPRESSA"]) .. ", " valores = valores .. transformSqlString(f["BARCODE"]) .. ", " valores = valores .. transformSqlString(f["CLA_NOME"]) .. ", " valores = valores .. transformSqlString(f["PDV_NOME"]) .. ", " valores = valores .. transformSqlString(f["EVENTO_FRASE"]) .. ", " valores = valores .. transformSqlString(f["SUB_CLASSE"]) .. ", " valores = valores .. transformSqlString(f["SUB_CLASSES"]) .. ", " valores = valores .. transformSqlString(f["OLD_CLASSE"]) .. ", " valores = valores .. transformSqlString(f["VALOR_TAXA"]) .. ", " valores = valores .. transformSqlString(f["MEIOPGTO"]) .. ", " valores = valores .. transformSqlString(f["CARTAO_AUTH"]) .. ", " valores = valores .. transformSqlString(f["LOTE_VIRADA"]) .. ", " valores = valores .. transformSqlString(f["GRUPONUMERADO"]) sql = "insert into ingresso_pendente (" .. campos .. ") values (" .. valores .. ");" db = sqlite3.open('banco.s3db') db:exec(sql) db:close() echo ("") echo ""; echo ("") echo (" " .. f["BARCODE"] .. "
") echo (unescape(f["EVENTO_FRASE"])) echo ("





") if (f["EVE_IMPRIME_VIA_CLIENTE"] ~= nul and tonumber(f["EVE_IMPRIME_VIA_CLIENTE"]) == 1) then echo ("--------------------
") echo (centralizaTexto("CONTROLE DE INGRESSO", 20, " ", "
")) echo ("--------------------
") echo (centralizaTexto(f["BARCODE"], 20, " ", "
")) echo (centralizaTexto("(So e valido se apresentado com o codigo de barras impresso acima)", 20, " ", "
")) echo ("--------------------
") echo (centralizaTexto(unescape(f["EVENTO_NOME"]), 20, " ", "
")) echo ("--------------------
") if (f["EVE_DATA"] ~= nil) then echo (centralizaTexto("Data: " .. unescape(f["EVE_DATA"]), 20, " ", "
")) end if (f["EVE_HORA"] ~= nil) then echo (centralizaTexto("Hora: " .. unescape(f["EVE_HORA"]), 20, " ", "
")) end echo (centralizaTexto("Cidade: " .. unescape(f["EVE_CIDADE"]), 20, " ", "
")) echo (centralizaTexto("Local: " .. unescape(f["EVE_LOCAL"]), 20, " ", "
")) echo ("
"); echo ("") echo ("") echo (centralizaTexto(unescape(f["CLA_NOME"]), 20, " ", "
")) 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("Lote: " .. f["LOTE_VIRADA"], 20, " ", "
")) end if (f["VALOR_FORMATADO"] ~= nil) then echo (centralizaTexto("Ingresso R$ " .. f["VALOR_FORMATADO"], 20, " ", "
")); end if (f["VALOR_TAXA_FORMATADO"] ~= nil) then echo (centralizaTexto("Taxa R$ " .. f["VALOR_TAXA_FORMATADO"], 20, " ", "
")); end if (f["VALOR_TOTAL_FORMATADO"] ~= nil) then echo (centralizaTexto("Total: R$ " .. f["VALOR_TOTAL_FORMATADO"], 20, " ", "
")); end echo (centralizaTexto("PDV 2: " .. unescape(f["PDV_NOME"]), 20, " ", "
")); echo ("Impresso: " .. unescape(f["DATA"]) .. "
" .. " Hora: " .. unescape(f["HORA"]) .. "
"); -- Virada do lote de ingresso 2016/12/06 echo ("





") end echo ("
") echo ("") echo ("") end