Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- import os
- conn = psycopg2.connect('dbname=cigarro host=10.40.140.25 user=postgres password=postgres')
- cur = conn.cursor()
- connmatriz = psycopg2.connect('dbname=matrizpitstop host=10.40.140.25 user=postgres password=postgres')
- curmatriz = connmatriz.cursor()
- cur.execute("SELECT produto, (select empresa from estoque where id = estoque), "
- " quant, last_turn FROM saldos WHERE estoque > 99")
- buffer = open('Contagem de cigarro.txt', 'w')
- for rec in cur:
- qry = "SELECT sum(quantidade), sum(valor), (select nome from produto where grid = produto) FROM lancto " \
- " WHERE empresa = %d and produto = " \
- " (select grid from produto where codigo_barra = '%s') " \
- " and hora >= '%s' " \
- " and operacao in ('C', 'V', 'DF') " \
- " GROUP BY produto" %\
- (rec[1], rec[0], rec[3])
- #print(qry)
- curmatriz.execute(qry)
- info = curmatriz.fetchone()
- if info is not None:
- buf = "[(%d)%s] %s\tVenda = %d Saldo = %d\n" % (rec[1], rec[0], info[2].ljust(60), info[0], rec[2])
- buffer.write(buf)
- print(buf)
- else:
- curmatriz.execute("select nome from produto where codigo_barra = '%s' " % rec[0])
- zbuf = curmatriz.fetchone()
- buf = "[(%d)%s] %s\tVenda = %d Saldo = %d\n" % (rec[1], rec[0], zbuf[0].ljust(60), 0, rec[2])
- buffer.write(buf)
- print(buf)
- buffer.flush()
- os.startfile("Contagem de cigarro.txt", "print")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement