Skip to content

Instantly share code, notes, and snippets.

@HigorMonteiro
Last active July 20, 2017 05:09
Show Gist options
  • Save HigorMonteiro/0b0c86fb195416e53d8fb587f23ac6e7 to your computer and use it in GitHub Desktop.
Save HigorMonteiro/0b0c86fb195416e53d8fb587f23ac6e7 to your computer and use it in GitHub Desktop.
import os
import pyodbc
from flask import (url_for, redirect, render_template,
request, send_from_directory)
from werkzeug import secure_filename
from app import app
connection_string = 'Driver={ODBC Driver 13 for SQL Server};Server=192.168.0.105;Database=ATXDADOS;Uid=sa;Pwd=asdf1234;'
connection = pyodbc.connect(connection_string)
@app.route("/index")
@app.route("/")
def index():
sql = """ SELECT "I"."ID_FUNCIONARIOS" AS CodFunc, "F"."NOMEFUNCIONARIO"
AS Nome, SUM("I"."QTDE") AS QtTotal_Litros, count("p"."NROCUPOMFISCAL")
AS Acionamento_Bico FROM "COMPROVANTES" "P", "ITENSCOMPROVANTE" "I",
"FUNCIONARIOS" "F" WHERE "P"."ID_COMPROVANTE" = "I"."ID_COMPROVANTE"
AND "I"."ID_FUNCIONARIOS" = "F"."ID_FUNCIONARIOS"
AND "P"."DTACONTA" = convert(datetime,convert(char(10),GETDATE()-20,102),102)
AND "P"."CANCELADO" = 0 AND "I"."ID_PRODUTOS" IN (1, 3, 4, 1385, 8249, 8297)
AND "P"."NROCUPOMFISCAL" <> 0 GROUP BY "i"."ID_FUNCIONARIOS", "F"."NOMEFUNCIONARIO"
ORDER BY SUM("I"."QTDE") DESC """
cur = connection.cursor()
cur.execute(sql)
objects = []
for data in cur:
objects.append(data)
objects = objects
print('%s\n' % objects)
cur.close()
# connection.close()
return render_template('index.html', objects=objects)
{% extends 'base.html'%}
{% block content %}
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-md-12">
<table class="table">
<tbody>
<tr>
<th>Codigo Funcionario</th>
<th>Nome do Funcionario</th>
<th>Quantidade Total Litros</th>
<th>Nº Cupom Fiscal</th>
</tr>
{%for data in objects %}
<tr>
{% for obj in data %}
<td>{{ obj }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
[109, 'EVERTON JORGE BRITO DA SILVA', 11516.648051261902, 76]
[158, 'ENÉAS SOARES MATOS ', 4461.033977627754, 53]
[75, 'REGINALDO DA COSTA OLIVEIRA', 4154.4889723062515, 43]
[157, 'FLAVIO COSTA DE SOUSA ', 1707.1969900131226, 9]
[138, 'JONATAS LUIS OLIVEIRA DE ARAUJO', 892.9199923872948, 45]
[156, 'AMISTERDAN DA SILVA FEITOSA', 863.5939880609512, 15]
[111, 'ROMARIO LINHARES DE ARAUJO', 612.3889994621277, 18]
[159, 'FRANCISCO DE ASSIS ANDRADE DE SOUSA ', 77.37300145626068, 5]
[140, 'PABLO SILVA DIOGENES', 47.361000776290894, 6]
[76, 'PAULIANO DE OLIVEIRA SOUSA', 45.18499958515167, 6]
[169, 'LUCIANA RIBEIRO ARAUJO FERREIRA', 23.240999221801758, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment