]> gitweb.pimeys.fr Git - scripts-20-100.git/blob - bde/integrite/integrite_solde.py
fa49ac3c85c3e25cf20f9dd9d57803be5e7ebdc5
[scripts-20-100.git] / bde / integrite / integrite_solde.py
1 #!/usr/bin/env python
2 # -*- coding:Latin-1 -*-
3
4 """ Liste les adhérents, fait la somme de leurs transactions et regarde la différence avec le solde actuel.
5 Broken, apparemment."""
6
7
8 import os
9
10 l=os.popen("psql bde -c \"SELECT numcbde,gagne-perdu as calcul,effectif,effectif-(gagne-perdu) as a_enlever FROM (SELECT numcbde,(SELECT sum(montant*quantite) FROM transactions WHERE destinataire=main.numcbde AND valide='t') as gagne,(SELECT sum(montant*quantite) FROM transactions WHERE emetteur=main.numcbde AND valide='t') as perdu, (SELECT solde FROM adherents WHERE numcbde=main.numcbde) as effectif FROM adherents as main) AS calculs WHERE gagne-perdu!=effectif;\"").readlines()
11
12 g=[]
13 print l
14 for i in l[1:-3]:
15 i=i.strip().split()
16 print i
17 g.append([i[0],i[2],i[4],i[6]])
18
19 f=open("requêtes à effectuer.txt","w")
20 for i in g:
21 montant = eval(i[3])
22 if montant>0:
23 f.write("INSERT INTO transactions (date,conso,emetteur,destinataire,montant,quantite,remarque) VALUES ('1970-01-01 00:13:37',1,0,%s,%s,1,'Solde initial');\n"%(i[0],i[3]))
24 elif montant<0:
25 f.write("INSERT INTO transactions (date,conso,emetteur,destinataire,montant,quantite,remarque) VALUES ('1970-01-01 00:13:37',1,%s,0,-(%s),1,'Solde initial');\n"%(i[0],i[3]))
26 f.write("UPDATE adherents SET solde = solde - (%s) WHERE numcbde=%s;\n"%(i[3],i[0]))