Index: main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt	(revision 12968)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig.pt	(revision 12971)
@@ -74,5 +74,6 @@
   function test() {
       if (document.getElementById('exporter').value == 'bursary' ||
-          document.getElementById('exporter').value == 'studentpayments') {
+          document.getElementById('exporter').value == 'studentpayments' ||
+          document.getElementById('exporter').value == 'studentunpaidpayments') {
           document.getElementById('payment_dates').style.display = 'block';
       } else {
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig_certificate.pt
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig_certificate.pt	(revision 12968)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/exportconfig_certificate.pt	(revision 12971)
@@ -64,5 +64,6 @@
   function test() {
       if (document.getElementById('exporter').value == 'bursary' ||
-          document.getElementById('exporter').value == 'studentpayments') {
+          document.getElementById('exporter').value == 'studentpayments' ||
+          document.getElementById('exporter').value == 'studentunpaidpayments') {
           document.getElementById('payment_dates').style.display = 'block';
       } else {
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/export.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/export.py	(revision 12968)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/export.py	(revision 12971)
@@ -86,5 +86,5 @@
     return tickets
 
-def get_payments(students, paid=False, **kw):
+def get_payments(students, p_state=None, **kw):
     """Get all payments of `students` within given payment_date period.
     """
@@ -100,9 +100,9 @@
         payments_start = tz.localize(payments_start)
         payments_end = tz.localize(payments_end)
-        if paid:
-            # Only paid tickets in payment period are considered
+        if p_state:
+            # Only paid or unpaid tickets in payment period are considered
             for student in students:
                 for payment in student.get('payments', {}).values():
-                    if payment.payment_date and payment.p_state == 'paid':
+                    if payment.payment_date and payment.p_state == p_state:
                         payment_date = to_timezone(payment.payment_date, tz)
                         if payment_date > payments_start and \
@@ -120,9 +120,9 @@
     else:
         # Payment period not given
-        if paid:
+        if p_state:
             # Only paid tickets are considered
             for student in students:
                 for payment in student.get('payments', {}).values():
-                    if payment.p_state == 'paid':
+                    if payment.p_state == p_state:
                         payments.append(payment)
         else:
@@ -382,4 +382,17 @@
             value, name, context=context)
 
+class StudentUnpaidPaymentExporter(StudentPaymentExporter):
+    """The Student Unpaid Payment Exporter works just like the
+    Student Payments Exporter but it exports only unpaid tickets.
+    This exporter is designed for finding and finally purging outdated
+    payment ticket.
+    """
+    grok.name('studentunpaidpayments')
+
+    title = _(u'Student Unpaid Payments')
+
+    def filter_func(self, x, **kw):
+        return get_payments(x, p_state='unpaid', **kw)
+
 class DataForBursaryExporter(StudentPaymentExporter):
     """The DataForBursary Exporter works just like the Student Payments Exporter
@@ -392,5 +405,5 @@
 
     def filter_func(self, x, **kw):
-        return get_payments(x, paid=True, **kw)
+        return get_payments(x, p_state='paid', **kw)
 
     fields = tuple(
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/student.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/student.py	(revision 12968)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/student.py	(revision 12971)
@@ -421,8 +421,8 @@
     """
 
-    STUDENT_EXPORTER_NAMES = getUtility(
-        IStudentsUtils).STUDENT_EXPORTER_NAMES
-
-    for name in STUDENT_EXPORTER_NAMES:
+    STUDENT_BACKUP_EXPORTER_NAMES = getUtility(
+        IStudentsUtils).STUDENT_BACKUP_EXPORTER_NAMES
+
+    for name in STUDENT_BACKUP_EXPORTER_NAMES:
         exporter = getUtility(ICSVStudentExporter, name=name)
         csv_data = exporter.export_student(student)
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py	(revision 12968)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py	(revision 12971)
@@ -32,4 +32,5 @@
     StudentPaymentsOverviewExporter, StudentStudyLevelsOverviewExporter,
     ComboCardDataExporter, DataForBursaryExporter,
+    StudentUnpaidPaymentExporter,
     get_students,)
 from waeup.kofa.students.accommodation import BedTicket
@@ -895,4 +896,43 @@
         result = open(self.outfile, 'rb').read()
         
+        return
+
+class StudentUnpaidPaymentExporterTest(StudentImportExportSetup):
+
+    layer = FunctionalLayer
+
+    def setUp(self):
+        super(StudentUnpaidPaymentExporterTest, self).setUp()
+        self.setup_for_export()
+        return
+
+    def test_export_all(self):
+        # we can really export all payments
+        # set values we can expect in export file
+        self.setup_student(self.student)
+        exporter = StudentUnpaidPaymentExporter()
+        exporter.export_all(self.app, self.outfile)
+        result = open(self.outfile, 'rb').read()
+        # No unpaid ticket exists
+        self.assertEqual(
+            result,
+            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
+            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
+            'r_code,r_desc,student_id,state,current_session\r\n'
+            )
+        # Make ticket unpaid
+        self.payment.p_state = 'unpaid'
+        exporter.export_all(self.app, self.outfile)
+        result = open(self.outfile, 'rb').read()
+        self.assertEqual(
+            result,
+            'ac,amount_auth,creation_date,p_category,p_current,p_id,'
+            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
+            'r_code,r_desc,student_id,state,current_session\r\n'
+
+            '666,12.12,2012-04-01 13:12:01#,schoolfee,1,my-id,'
+            'p-item,100,2012,unpaid,2012-04-01 14:12:01#,12.12,'
+            'r-code,,A111111,created,2012\r\n'
+            )
         return
 
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py	(revision 12968)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py	(revision 12971)
@@ -182,8 +182,8 @@
 
         # The student data were put into CSV files
-        STUDENT_EXPORTER_NAMES = getUtility(
-            IStudentsUtils).STUDENT_EXPORTER_NAMES
-
-        for name in STUDENT_EXPORTER_NAMES:
+        STUDENT_BACKUP_EXPORTER_NAMES = getUtility(
+            IStudentsUtils).STUDENT_BACKUP_EXPORTER_NAMES
+
+        for name in STUDENT_BACKUP_EXPORTER_NAMES:
             csv_path = os.path.join(del_dir, '%s.csv' % name)
             self.assertTrue(os.path.isfile(csv_path))
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py	(revision 12968)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py	(revision 12971)
@@ -954,6 +954,13 @@
     STUDENT_EXPORTER_NAMES = ('students', 'studentstudycourses',
             'studentstudylevels', 'coursetickets',
-            'studentpayments', 'bedtickets', 'paymentsoverview',
+            'studentpayments', 'studentunpaidpayments',
+            'bedtickets', 'paymentsoverview',
             'studylevelsoverview', 'combocard', 'bursary')
+
+    #: A tuple containing all exporter names needed for backing
+    #: up student data
+    STUDENT_BACKUP_EXPORTER_NAMES = ('students', 'studentstudycourses',
+            'studentstudylevels', 'coursetickets',
+            'studentpayments', 'bedtickets')
 
     #: A prefix used when generating new student ids. Each student id will
Index: main/waeup.kofa/trunk/src/waeup/kofa/university/department.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/university/department.py	(revision 12968)
+++ main/waeup.kofa/trunk/src/waeup/kofa/university/department.py	(revision 12971)
@@ -31,5 +31,4 @@
 from waeup.kofa.utils.batching import VirtualExportJobContainer
 from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
-from waeup.kofa.utils.helpers import attrs_to_fields
 from waeup.kofa.university.interfaces import IDepartment
 
