Advertisement
webmanix

Untitled

Sep 22nd, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 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. for rec in cur:
  14.  
  15. qry = "SELECT sum(quantidade), sum(valor), (select nome from produto where grid = produto) FROM lancto " \
  16. " WHERE empresa = %d and produto = " \
  17. " (select grid from produto where codigo_barra = '%s') " \
  18. " and hora >= '%s' " \
  19. " and operacao in ('C', 'V', 'DF') " \
  20. " GROUP BY produto" %\
  21. (rec[1], rec[0], rec[3])
  22.  
  23. #print(qry)
  24.  
  25. curmatriz.execute(qry)
  26. info = curmatriz.fetchone()
  27.  
  28. if info is not None:
  29. print("%s\n\tVenda = %d Saldo = %d" % (info[2], info[0], rec[2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement