Advertisement
webmanix

Untitled

Sep 25th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import psycopg2
  2. import os
  3.  
  4. conn = psycopg2.connect('dbname=cigarro host=10.40.140.25 user=postgres password=postgres')
  5. cur = conn.cursor()
  6.  
  7. connmatriz = psycopg2.connect('dbname=matrizpitstop host=10.40.140.25 user=postgres password=postgres')
  8. curmatriz = connmatriz.cursor()
  9.  
  10. cur.execute("SELECT produto, (select empresa from estoque where id = estoque), "
  11. " quant, last_turn FROM saldos WHERE estoque > 99")
  12.  
  13. buffer = open('Contagem de cigarro.txt', 'w')
  14.  
  15. for rec in cur:
  16.  
  17. qry = "SELECT sum(quantidade), sum(valor), (select nome from produto where grid = produto) FROM lancto " \
  18. " WHERE empresa = %d and produto = " \
  19. " (select grid from produto where codigo_barra = '%s') " \
  20. " and hora >= '%s' " \
  21. " and operacao in ('C', 'V', 'DF') " \
  22. " GROUP BY produto" %\
  23. (rec[1], rec[0], rec[3])
  24.  
  25. #print(qry)
  26.  
  27. curmatriz.execute(qry)
  28. info = curmatriz.fetchone()
  29.  
  30. if info is not None:
  31. buf = "[(%d)%s] %s\tVenda = %d Saldo = %d\n" % (rec[1], rec[0], info[2].ljust(60), info[0], rec[2])
  32. buffer.write(buf)
  33. print(buf)
  34. else:
  35. curmatriz.execute("select nome from produto where codigo_barra = '%s' " % rec[0])
  36. zbuf = curmatriz.fetchone()
  37. buf = "[(%d)%s] %s\tVenda = %d Saldo = %d\n" % (rec[1], rec[0], zbuf[0].ljust(60), 0, rec[2])
  38. buffer.write(buf)
  39. print(buf)
  40.  
  41.  
  42. buffer.flush()
  43. os.startfile("Contagem de cigarro.txt", "print")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement