Index: main/waeup.kofa/trunk/CHANGES.txt
===================================================================
--- main/waeup.kofa/trunk/CHANGES.txt	(revision 16159)
+++ main/waeup.kofa/trunk/CHANGES.txt	(revision 16169)
@@ -4,4 +4,6 @@
 1.6.1.dev0 (unreleased)
 =======================
+
+* Implement webservice `get_unpaid_payments`.
 
 * Prepare `renderPDFAdmissionLetter` for merging with another pdf document.
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py	(revision 16159)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_webservices.py	(revision 16169)
@@ -2,4 +2,5 @@
 import xmlrpclib
 import os
+from time import time
 from cStringIO import StringIO
 from zope.app.testing.xmlrpc import ServerProxy
@@ -799,2 +800,126 @@
         self.assertEqual(xmlout, response)
         return
+
+    def test_get_unpaid_payments(self):
+        timestamp1 = ("%d" % int((time()-10)*10000))[1:]
+        timestamp2 = ("%d" % int((time()-5)*10000))[1:]
+        timestamp3 = ("%d" % int((time()-(3*86400))*10000))[1:]
+        p_id_1 = ("p%s" % timestamp1)
+        p_id_2 = ("p%s" % timestamp2)
+        p_id_3 = ("p%s" % timestamp3)
+        payment1 = StudentOnlinePayment()
+        payment1.p_id = p_id_1
+        payment1.p_session = 2012
+        payment1.amount_auth = 12.12
+        payment1.p_state = u'unpaid'
+        payment1.p_category = u'schoolfee'
+        payment1.r_company = u'xyz'
+        self.student['payments']['my-payment1'] = payment1
+        payment2 = StudentOnlinePayment()
+        payment2.p_id = p_id_2
+        payment2.p_session = 2012
+        payment2.amount_auth = 12.12
+        payment2.p_state = u'paid'
+        payment2.p_category = u'clearance'
+        self.student['payments']['my-payment2'] = payment2
+        payment3 = StudentOnlinePayment()
+        payment3.p_id = p_id_3
+        payment3.p_session = 2012
+        payment3.amount_auth = 12.12
+        payment3.p_state = u'unpaid'
+        payment3.p_category = u'schoolfee'
+        self.student['payments']['my-payment3'] = payment3
+        server = ServerProxy('http://mgr:mgrpw@localhost/app', allow_none=True)
+        results = server.get_unpaid_payments(1)
+        self.assertEqual(
+            results,[
+                {'display_item': None,
+                'p_id': '%s' % p_id_1,
+                'p_category': 'schoolfee',
+                'amount_auth': 12.12, 'p_session': 2012,
+                'p_state': 'unpaid',
+                'r_company': 'xyz'}
+                ])
+        results = server.get_unpaid_payments(4)
+        self.assertEqual(
+            results,[
+                {'display_item': None,
+                  'p_id': '%s' % p_id_1,
+                  'p_category': 'schoolfee',
+                  'amount_auth': 12.12,
+                  'p_session': 2012,
+                  'p_state': 'unpaid',
+                  'r_company': 'xyz'},
+                {'display_item': None,
+                  'p_id': '%s' % p_id_3,
+                  'p_category': 'schoolfee',
+                  'amount_auth': 12.12,
+                  'p_session': 2012,
+                  'p_state': 'unpaid',
+                  'r_company': None}
+                ])
+        results = server.get_unpaid_payments(4,'xyz')
+        self.assertEqual(
+            results,[
+                {'display_item': None,
+                  'p_id': '%s' % p_id_1,
+                  'p_category': 'schoolfee',
+                  'amount_auth': 12.12,
+                  'p_session': 2012,
+                  'p_state': 'unpaid',
+                  'r_company': 'xyz'},
+                ])
+
+        REQUEST_XML = """\
+<?xml version="1.0"?>
+<methodCall>
+<methodName>get_unpaid_payments</methodName>
+<params>
+<param>
+<value><string>1</string></value>
+</param>
+</params>
+</methodCall>"""
+        RESPONSE_XML = """\
+<?xml version='1.0'?>
+<methodResponse>
+<params>
+<param>
+<value><array><data>
+<value><struct>
+<member>
+<name>display_item</name>
+<value><nil/></value></member>
+<member>
+<name>p_id</name>
+<value><string>%s</string></value>
+</member>
+<member>
+<name>r_company</name>
+<value><string>xyz</string></value>
+</member>
+<member>
+<name>p_category</name>
+<value><string>schoolfee</string></value>
+</member>
+<member>
+<name>amount_auth</name>
+<value><double>12.12</double></value>
+</member>
+<member>
+<name>p_session</name>
+<value><int>2012</int></value>
+</member>
+<member>
+<name>p_state</name>
+<value><string>unpaid</string></value>
+</member>
+</struct></value>
+</data></array></value>
+</param>
+</params>
+</methodResponse>
+""" % p_id_1
+        xmlout = self.XMLRPC_post(REQUEST_XML)
+        self.assertEqual(xmlout, RESPONSE_XML)
+        return
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py	(revision 16159)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/webservices.py	(revision 16169)
@@ -19,4 +19,5 @@
 import os
 import xmlrpclib
+from time import time
 from cStringIO import StringIO
 from zope.component import getUtility, queryUtility
@@ -416,2 +417,44 @@
               )
         return hitlist
+
+    @grok.require('waeup.xmlrpc')
+    def get_unpaid_payments(self, days=3, company=None):
+        """Returns the p_ids of unpaid payment tickets which have
+        been created during the past days.
+        """
+        days_in_seconds = 86400 * int(days)
+        timestamp_now = ("%d" % int(time()*10000))[1:]
+        timestamp_now_minus_days = ("%d" % int((time()-days_in_seconds)*10000))[1:]
+        p_id_now = ("p%s" % timestamp_now)
+        p_id_minus_days = ("p%s" % timestamp_now_minus_days)
+        cat = getUtility(ICatalog, name='payments_catalog')
+        payments = list(
+            cat.searchResults(p_id=(p_id_minus_days, p_id_now),
+                              p_state=('unpaid', 'unpaid')))
+        hitlist = []
+        if company:
+            for payment in payments:
+                if company == getattr(payment, 'r_company', None):
+                    hitlist.append(dict(
+                        p_id=payment.p_id,
+                        amount_auth=payment.amount_auth,
+                        p_category=payment.p_category,
+                        display_item=payment.display_item,
+                        p_session=payment.p_session,
+                        p_state=payment.p_state,
+                        r_company=getattr(payment, 'r_company', None)
+                        )
+                      )
+            return hitlist
+        for payment in payments:
+            hitlist.append(dict(
+                p_id=payment.p_id,
+                amount_auth=payment.amount_auth,
+                p_category=payment.p_category,
+                display_item=payment.display_item,
+                p_session=payment.p_session,
+                p_state=payment.p_state,
+                r_company=getattr(payment, 'r_company', None)
+                )
+              )
+        return hitlist
