Index: WAeUP_SRP/fceokene/waeup_custom/getPaymentsFolderInfo.py
===================================================================
--- WAeUP_SRP/fceokene/waeup_custom/getPaymentsFolderInfo.py	(revision 3168)
+++ WAeUP_SRP/fceokene/waeup_custom/getPaymentsFolderInfo.py	(revision 3226)
@@ -12,8 +12,11 @@
 Info for the PaymentsFolder
 """
+from Products.AdvancedQuery import Eq, Between, Le,In
 
 mtool = context.portal_membership
 wftool = context.portal_workflow
 member = mtool.getAuthenticatedMember()
+payments_catalog = context.payments_catalog
+aq_payments = payments_catalog.evalAdvancedQuery
 if mtool.isAnonymousUser():
     return None
@@ -38,12 +41,11 @@
 import DateTime
 request = context.REQUEST
-students = context.portal_url.getPortalObject().campus.students
+#students = context.portal_url.getPortalObject().campus.students
 student_id = context.getStudentId()
 if student_id is None:
     return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
-student = getattr(students,student_id)
+#student = getattr(students,student_id)
 student_record = context.students_catalog.getRecordByKey(student_id)
 #context['updatePayments']()
-payments = []
 
 info = {}
@@ -75,42 +77,32 @@
 
 info['student_name'] = student_record.name
-
-for payment_id,payment in context.objectItems():
+payments_path = "%s/campus/students/%s/payments" % (context.portal_url.getPortalPath(),student_id)
+payments = []
+payment_records = aq_payments(Eq('student_id',student_id) & Eq('session_id',student_record.session))
+vocabularies = context.portal_vocabularies
+paid_fees = []
+for payment in payment_records:
+    if payment.status == "paid":
+        paid_fees += "%s_%s" % (payment.type,payment.session_id), 
+for payment in payment_records:
     row = {}
-    row['id'] = payment_id
-    row['title'] = payment.Title()
-    url = row['url'] = payment.absolute_url()
-    payment_doc = payment.getContent()
-    row['type'] = payment_doc.portal_type
-    review_state = row['review_state'] = wftool.getInfoFor(payment,'review_state',None)
-    if payment_doc.type_description.startswith('School Fee'):
-        row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] == 'cleared_and_validated'
-    else:
-        row['is_approvable'] = is_so and (review_state == "opened")
-    row['is_requeryable'] = False
-    #set_trace()
-    row['resp_desc'] = getattr(payment_doc,'resp_desc','no response')
-    row['trans_ref'] = getattr(payment_doc,'order_id','')
-    if payment_doc.type_description.startswith('School Fee'):
-        if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated',) and \
-            hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin',):
-            row['is_requeryable'] = True
-            row['callback_url'] = "%(url)s/interswitch_cb" % row
-            href = '%(query_url)s' % info
-            href += '?transRef=%(trans_ref)s' % row
-            href += '&prodID=%(prod_id)s' % info
-            href += '&redirectURL=%(callback_url)s' % row
-            row['href'] = href
-    elif payment_doc.type_description.startswith('Hostel'):
-        if (review_state == 'opened' and \
-            hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
-            row['is_requeryable'] = True
-            row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
-            href = '%(query_url)s' % info
-            href += '?transRef=%(trans_ref)s' % row
-            href += '&prodID=%(prod_id)s' % info
-            href += '&redirectURL=%(callback_url)s' % row
-            row['href'] = href
-    if (review_state == "closed") and payment_doc.resp_code in ('SC','00','AP','IP',):
+    row['id'] = payment.key
+    row['title'] = "%s for Session %s, Naira %s, %s" % (vocabularies.payment_categories.get(payment.category),
+                                                        vocabularies.sessions.get(payment.session_id),
+                                                        payment.amount,
+                                                        payment.date.strftime("%d/%m/%y %H:%M:%S"))
+    url = row['url'] = "%s/p%s" % (payments_path,payment.order_id[6:])
+    row['is_requeryable'] = "%s_%s" % (payment.type,payment.session_id) not in paid_fees
+    row['is_approvable'] = is_so and row['is_requeryable']
+    row['resp_desc'] = payment.resp_desc or payment.status
+    row['trans_ref'] = payment.order_id
+    if row['is_requeryable']:
+        row['callback_url'] = "%(url)s/interswitch_cb" % row
+        href = '%(query_url)s' % info
+        href += '?transRef=%(trans_ref)s' % row
+        href += '&prodID=%(prod_id)s' % info
+        href += '&redirectURL=%(callback_url)s' % row
+        row['href'] = href
+    if payment.status == 'paid':
         row['confirmed'] = 'active'
     else:
@@ -118,4 +110,46 @@
     row['is_editable'] = is_so and (row['confirmed'] == 'active')
     payments.append(row)
+# for payment_id,payment in context.objectItems():
+#     row = {}
+#     row['id'] = payment_id
+#     row['title'] = payment.Title()
+#     url = row['url'] = payment.absolute_url()
+#     payment_doc = payment.getContent()
+#     row['type'] = payment_doc.portal_type
+#     review_state = row['review_state'] = wftool.getInfoFor(payment,'review_state',None)
+#     if payment_doc.type_description.startswith('School Fee'):
+#         row['is_approvable'] = is_so and (review_state == "opened") and info['review_state'] == 'cleared_and_validated'
+#     else:
+#         row['is_approvable'] = is_so and (review_state == "opened")
+#     row['is_requeryable'] = False
+#     #set_trace()
+#     row['resp_desc'] = getattr(payment_doc,'resp_desc','no response')
+#     row['trans_ref'] = getattr(payment_doc,'order_id','')
+#     if payment_doc.type_description.startswith('School Fee'):
+#         if (review_state == 'opened' and info['review_state'] in ('cleared_and_validated',) and \
+#             hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin',):
+#             row['is_requeryable'] = True
+#             row['callback_url'] = "%(url)s/interswitch_cb" % row
+#             href = '%(query_url)s' % info
+#             href += '?transRef=%(trans_ref)s' % row
+#             href += '&prodID=%(prod_id)s' % info
+#             href += '&redirectURL=%(callback_url)s' % row
+#             row['href'] = href
+#     elif payment_doc.type_description.startswith('Hostel'):
+#         if (review_state == 'opened' and \
+#             hasattr(payment_doc, 'order_id') and not payment_doc.resp_code) or str(member) in ('admin','delejason','isouaba'):
+#             row['is_requeryable'] = True
+#             row['callback_url'] = "%(url)s/interswitch_acco_cb" % row
+#             href = '%(query_url)s' % info
+#             href += '?transRef=%(trans_ref)s' % row
+#             href += '&prodID=%(prod_id)s' % info
+#             href += '&redirectURL=%(callback_url)s' % row
+#             row['href'] = href
+#     if (review_state == "closed") and payment_doc.resp_code in ('SC','00','AP','IP',):
+#         row['confirmed'] = 'active'
+#     else:
+#         row['confirmed'] = 'unsuccessful'
+#     row['is_editable'] = is_so and (row['confirmed'] == 'active')
+#     payments.append(row)
 # payments_path = "%s/campus/students/%s/payments" % (context.portal_url.getPortalPath(),student_id)
 # sos = context.portal_catalog(container_path=payments_path)
