Index: pykota/trunk/setup.py
===================================================================
--- pykota/trunk/setup.py (revision 1500)
+++ pykota/trunk/setup.py (revision 1522)
@@ -24,4 +24,7 @@
 #
 # $Log$
+# Revision 1.44  2004/06/05 22:03:49  jalet
+# Payments history is now stored in database
+#
 # Revision 1.43  2004/05/25 09:49:41  jalet
 # The old pykota filter has been removed. LPRng support disabled for now.
@@ -376,10 +379,10 @@
     
     # WARNING MESSAGE    
-    sys.stdout.write("WARNING : IF YOU ARE UPGRADING FROM A PRE-1.19alpha7 TO 1.19alpha7 OR ABOVE\n")
+    sys.stdout.write("WARNING : IF YOU ARE UPGRADING FROM A PRE-1.19alpha17 TO 1.19alpha17 OR ABOVE\n")
     sys.stdout.write("AND USE THE POSTGRESQL BACKEND, THEN YOU HAVE TO MODIFY YOUR\n")
     sys.stdout.write("DATABASE SCHEMA USING initscripts/postgresql/upgrade-to-1.19.sql\n")
     sys.stdout.write("PLEASE READ DOCUMENTATION IN initscripts/postgresql/ TO LEARN HOW TO DO.\n")
     sys.stdout.write("YOU CAN DO THAT AFTER THE INSTALLATION IS FINISHED, OR PRESS CTRL+C NOW.\n")
-    sys.stdout.write("\n\nYOU DON'T HAVE ANYTHING SPECIAL TO DO IF THIS IS YOUR FIRST INSTALLATION\nOR IF YOU ARE ALREADY RUNNING VERSION 1.19alpha7 OR ABOVE.\n\n")
+    sys.stdout.write("\n\nYOU DON'T HAVE ANYTHING SPECIAL TO DO IF THIS IS YOUR FIRST INSTALLATION\nOR IF YOU ARE ALREADY RUNNING VERSION 1.19alpha17 OR ABOVE.\n\n")
     dummy = raw_input("Please press ENTER when you have read the message above. ")
     
Index: pykota/trunk/pykota/storages/sql.py
===================================================================
--- pykota/trunk/pykota/storages/sql.py (revision 1520)
+++ pykota/trunk/pykota/storages/sql.py (revision 1522)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.41  2004/06/05 22:03:50  jalet
+# Payments history is now stored in database
+#
 # Revision 1.40  2004/06/03 23:14:11  jalet
 # Now stores the job's size in bytes in the database.
@@ -342,4 +345,8 @@
             self.doModify("UPDATE users SET balance=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(user.ident)))
             
+    def writeNewPayment(self, user, amount) :        
+        """Adds a new payment to the payments history."""
+        self.doModify("INSERT INTO payments (userid, amount) VALUES (%s, %s)" % (self.doQuote(user.ident), self.doQuote(amount)))
+        
     def writeLastJobSize(self, lastjob, jobsize, jobprice) :        
         """Sets the last job's size permanently."""
Index: pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- pykota/trunk/pykota/storages/ldapstorage.py (revision 1520)
+++ pykota/trunk/pykota/storages/ldapstorage.py (revision 1522)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.68  2004/06/05 22:03:50  jalet
+# Payments history is now stored in database
+#
 # Revision 1.67  2004/06/03 23:14:10  jalet
 # Now stores the job's size in bytes in the database.
@@ -257,4 +260,5 @@
 import time
 import md5
+from mx import DateTime
 
 from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageJob,StorageLastJob,StorageUserPQuota,StorageGroupPQuota
@@ -477,5 +481,5 @@
             if user.LimitBy is not None :
                 user.LimitBy = user.LimitBy[0]
-            result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["balancerdn"], username), ["pykotaBalance", "pykotaLifeTimePaid"], base=self.info["balancebase"])
+            result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["balancerdn"], username), ["pykotaBalance", "pykotaLifeTimePaid", "pykotaPayments"], base=self.info["balancebase"])
             if result :
                 fields = result[0][1]
@@ -495,4 +499,8 @@
                         user.LifeTimePaid = float(user.LifeTimePaid[0])
                 user.LifeTimePaid = user.LifeTimePaid or 0.0        
+                user.Payments = []
+                for payment in fields.get("pykotaPayments", []) :
+                    (date, amount) = payment.split(" # ")
+                    user.Payments.append((date, amount))
             user.Exists = 1
         return user
@@ -944,4 +952,15 @@
         return self.doModify(user.idbalance, fields)         
             
+    def writeNewPayment(self, user, amount) :        
+        """Adds a new payment to the payments history."""
+        payments = []
+        for payment in user.Payments :
+            payments.append("%s # %s" % (payment[0], str(payment[1])))
+        payments.append("%s # %s" % (str(DateTime.now()), str(amount)))
+        fields = {
+                   "pykotaPayments" : payments,
+                 }
+        return self.doModify(user.idbalance, fields)         
+        
     def writeLastJobSize(self, lastjob, jobsize, jobprice) :        
         """Sets the last job's size permanently."""
Index: pykota/trunk/pykota/storage.py
===================================================================
--- pykota/trunk/pykota/storage.py (revision 1520)
+++ pykota/trunk/pykota/storage.py (revision 1522)
@@ -22,4 +22,7 @@
 #
 # $Log$
+# Revision 1.54  2004/06/05 22:03:49  jalet
+# Payments history is now stored in database
+#
 # Revision 1.53  2004/06/03 23:14:10  jalet
 # Now stores the job's size in bytes in the database.
@@ -230,4 +233,5 @@
         self.LifeTimePaid = None
         self.Email = None
+        self.Payments = [] # TODO : maybe handle this smartly for SQL, for now just don't retrieve them
         
     def consumeAccountBalance(self, amount) :     
@@ -238,7 +242,16 @@
     def setAccountBalance(self, balance, lifetimepaid) :    
         """Sets the user's account balance in case he pays more money."""
-        self.parent.writeUserAccountBalance(self, balance, lifetimepaid)
-        self.AccountBalance = balance
-        self.LifeTimePaid = lifetimepaid
+        diff = float(lifetimepaid or 0.0) - float(self.LifeTimePaid or 0.0)
+        self.parent.beginTransaction()
+        try :
+            self.parent.writeUserAccountBalance(self, balance, lifetimepaid)
+            self.parent.writeNewPayment(self, diff)
+        except PyKotaStorageError, msg :    
+            self.parent.rollbackTransaction()
+            raise PyKotaStorageError, msg
+        else :    
+            self.parent.commitTransaction()
+            self.AccountBalance = balance
+            self.LifeTimePaid = lifetimepaid
         
     def setLimitBy(self, limitby) :    
Index: pykota/trunk/pykota/version.py
===================================================================
--- pykota/trunk/pykota/version.py (revision 1517)
+++ pykota/trunk/pykota/version.py (revision 1522)
@@ -22,5 +22,5 @@
 #
 
-__version__ = "1.19alpha17_unofficial"
+__version__ = "1.19alpha18_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: pykota/trunk/initscripts/ldap/pykota.schema
===================================================================
--- pykota/trunk/initscripts/ldap/pykota.schema (revision 1520)
+++ pykota/trunk/initscripts/ldap/pykota.schema (revision 1522)
@@ -184,5 +184,5 @@
 # pykotaPayments
 attributetype ( 1.3.6.1.4.1.16868.1.1.26 NAME 'pykotaPayments'
-        DESC 'Stores all payments made by an user, encoded to store both date and amount'
+        DESC 'Stores all payments made by an user, encoded to store both date and amount, separated by a # between two spaces'
         EQUALITY caseExactIA5Match
         SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
Index: pykota/trunk/NEWS
===================================================================
--- pykota/trunk/NEWS (revision 1521)
+++ pykota/trunk/NEWS (revision 1522)
@@ -23,4 +23,13 @@
 
 
+    - 1.19alpha18 :
+    
+        - History of payments is now stored in the database, and
+          updated each time an user's balance is modified with
+          edpykota --balance. This history represents each time
+          the user was given some positive or negative credit,
+          but doesn't reflect price paid for jobs, which appear
+          in the jobs history instead.
+          
     - 1.19alpha17 :
     
