Index: WAeUP_SRP/branches/joachim-event-branch/skins/waeup_utilities/readOnlinePaymentsFromLog.py
===================================================================
--- WAeUP_SRP/branches/joachim-event-branch/skins/waeup_utilities/readOnlinePaymentsFromLog.py	(revision 1673)
+++ WAeUP_SRP/branches/joachim-event-branch/skins/waeup_utilities/readOnlinePaymentsFromLog.py	(revision 1673)
@@ -0,0 +1,117 @@
+## Script (Python) "search_pins"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id$
+"""
+read the successfull epayments from an extract of Z2.log
+this extract must be created with
+
+cat /zope/instances/uniben1/log/Z2.log.1 | grep epayment_cb | grep RespCode=00 
+> /zope/instances/uniben1/import/successfullepaymentsDDMMYY.log
+
+in /zope/instances/uniben1/import/ are already all files from 25.3.07
+
+"""
+import logging
+logger = logging.getLogger('Skins.readOnlinePaymentsFromLog')
+
+request = context.REQUEST
+session = request.SESSION
+response = request.RESPONSE
+setheader = request.RESPONSE.setHeader
+import DateTime
+
+def rwrite(s):
+    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
+    response.write('%s<br>\r\n' % s)
+
+wftool = context.portal_workflow
+mtool = context.portal_membership
+member = mtool.getAuthenticatedMember()
+roles = member.getRolesInContext(context)
+retcat = context.returning_import
+rcat = context.results_import
+scat = context.students_catalog
+from Products.AdvancedQuery import Eq, Between, Le,In
+aq_students = context.students_catalog.evalAdvancedQuery
+students_folder = context.portal_url.getPortalObject().campus.students
+resp_codes = (("x_RespDesc","resp_desc"),
+      ("x_RespPayRef","resp_pay_reference"),
+      ("x_RespCode","resp_code"),
+      ("x_CardNum","resp_card_num"),
+      ("x_ApprAmt","resp_approved_amount"),
+      )
+count = 0
+correct = 0
+approved = 0
+tas = context.waeup_tool.getCallbacksFromLog('successfullepayments260307.log')
+for ta in tas:
+    count += 1
+    student_id = ta['student_id']
+    payment_id = ta['payment_id']
+    qs_dict = ta['qs_dict']
+    if not students_folder.hasObject(student_id):
+        rwrite("no student %s" % student_id)
+        continue
+    student_obj = getattr(students_folder,student_id)
+    if not student_obj.hasObject('payments'):
+        rwrite("no payments for student %s" % student_id)
+        continue
+    payments = getattr(student_obj,'payments')
+    if not payments.hasObject(payment_id):
+        rwrite("no payment %s for student %s" % (payment_id,student_id))
+        continue
+    payment_obj = getattr(payments,payment_id)
+    payment_doc = payment_obj.getContent()
+    pdoc = {}
+    for rc,key in resp_codes:
+        pdoc[key] = getattr(payment_doc,key)
+    readin = {}
+    for rc,pdk in resp_codes:
+        readin[pdk] = qs_dict.get(rc)[0]
+    response_code = readin['resp_code']
+    if payment_doc.resp_code != response_code:
+        rwrite('"%d","%d","%s","%s","%s","%s"' % (
+                                                  count,correct,
+                                                  student_id,
+                                                  payment_id,
+                                                  response_code,
+                                                  payment_doc.resp_code
+                                                  ))
+    elif payment_doc.resp_code == response_code:
+        correct +=1
+        rwrite('"%d","%d","%s","%s","%s","%s"' % (
+                                                  count,correct,
+                                                  student_id,
+                                                  payment_id,
+                                                  response_code,
+                                                  payment_doc.resp_code
+                                                  ))
+    if payment_doc.resp_code == "" and response_code == "00":
+        pd = {}
+        review_state = wftool.getInfoFor(payment_obj,'review_state',None)
+        if review_state != "opened":
+            logger.info('payment object of %s closed' % (student_id))
+            continue
+        review_state = wftool.getInfoFor(student_obj,'review_state',None)
+        if review_state != "cleared_and_validated":
+            logger.info('%s review_state = %s' % (student_id,review_state))
+            continue
+        pd['resp_code'] = 'IP'
+        pd['resp_desc'] = 'Payment approved by import, %s' % (DateTime.DateTime())
+        payment_doc.edit(mapping=pd)
+        if payment_doc.type_description.startswith('School Fee'):
+            wftool.doActionFor(student_obj,'pay_school_fee')
+        logger.info('%s approves epayment for %s by import' % (member,student_id))
+        wftool.doActionFor(payment_obj,'close')
+        approved += 1
+        if approved > 50:
+            context.waeup_tool.doCommit()
+            logger.info('%s transactions commited' % (approved))
+            approved = 0
Index: WAeUP_SRP/branches/joachim-event-branch/skins/waeup_utilities/ti_182_resolve.py
===================================================================
--- WAeUP_SRP/branches/joachim-event-branch/skins/waeup_utilities/ti_182_resolve.py	(revision 1673)
+++ WAeUP_SRP/branches/joachim-event-branch/skins/waeup_utilities/ti_182_resolve.py	(revision 1673)
@@ -0,0 +1,126 @@
+## Script (Python) "getNewStudentStatistics"
+##bind container=container
+##bind context=context
+##bind namespace=
+##bind script=script
+##bind subpath=traverse_subpath
+##parameters=
+##title=
+##
+# $Id$
+"""
+resolve ticket #182
+"""
+try:
+    from Products.zdb import set_trace
+except:
+    def set_trace():
+        pass
+import logging
+#>>>>>>>>>>>>>>>><
+logger = logging.getLogger('Skins.ti_182_resolve')
+#logger.info('already done on 26.3.07 by joachim')
+#return
+#<<<<<<<<<<<<<<<<<
+request = context.REQUEST
+session = request.SESSION
+response = request.RESPONSE
+setheader = request.RESPONSE.setHeader
+students = context.portal_url.getPortalObject().campus.students
+#from string import Template
+def intersect(m,n):
+    return [i for i in m if i in n]
+
+def rwrite(s):
+    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
+    response.write("%s<br>\n\r" % s)
+def getObject(outer,object):
+    if outer.hasObject(object):
+        return getattr(outer,object)
+    return None
+try:
+    from Products.AdvancedQuery import Eq, Between, Le,In, Ge,MatchRegexp
+    aq_portal = context.portal_catalog.evalAdvancedQuery
+    aq_students = context.students_catalog.evalAdvancedQuery
+except:
+    evalAdvancedQuery = None
+
+
+#freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE'))
+#total_new = aq_students(freshquery)
+##query = In('review_state',('cleared_and_validated',
+##                           'school_fee_paid',
+##                           'courses_registered',
+##                           'courses_validated'))
+##cleared = aq_portal(query)
+##rwrite("Cleared and beyond students: %d" % len(cleared))
+##cleared_ids = [s.getId for s in cleared]
+newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*')
+new_students = aq_portal(newquery)
+new_ids = [r.getPath().split('/')[-2] for r in new_students]
+rwrite("New students: %d" % len(new_ids))
+#diff_new_cleared = [i for i in new_ids if i not in cleared_ids]  
+#diff_cleared_new = [i for i in cleared_ids if i not in new_ids]  
+##special_states =  ('admitted',
+##                   'clearance_pin_entered',
+##                   'clearance_requested',
+##                   'cleared_and_validated',
+##                   'objection_raised',
+##                   )
+##special_query = In('review_state',special_states)
+##special = aq_portal(special_query)
+##special_ids = [s.getId for s in special]
+##rwrite("New special students: %d" % len(special_ids))
+admitted_query = Eq('review_state','admitted')
+admitted = aq_portal(admitted_query)
+admitted_ids = [s.getId for s in admitted]
+rwrite("Admitted students: %d" % len(admitted_ids))
+##faculties = context.portal_catalog(portal_type="Faculty")
+##fac_ids = [f.getId for f in faculties]
+##fac_query = In('faculty',fac_ids)
+##faculties_students = aq_students(fac_query)
+##faculties_student_ids = [s.id for s in faculties_students]
+##set_trace()
+count = 0
+for sid in admitted_ids:
+    if sid not in new_ids:
+        if not count:
+            rwrite('Students with review_state admitted and jamb_reg_no not beginning with 6') 
+        count += 1
+        erg = context.students_catalog(id=sid)
+        if not erg:
+            set_trace()
+            continue
+        student = erg[0]
+        dict = context.getFormattedStudentEntry(student)
+        dict['count'] = count
+        dict['review_state'] = 'admitted'
+        rwrite('"%(count)d","%(id)s","%(name)s","%(jamb_reg_no)s","%(faculty)s","%(entry_mode)s,"%(review_state)s,"%(level)s",' % dict)
+        
+##retcount = 0
+##count = 0
+##newc = 0
+###set_trace()
+##for student in cleared:
+##    erg = context.students_catalog(id=student.getId)
+##    if not erg:
+##        set_trace()
+##        continue
+##    if not erg[0].jamb_reg_no.startswith('6'):
+##        retcount += 1
+##        continue
+##    newc += 1
+##    if not student.getId in special_ids:
+##        count += 1
+####        dict = context.getFormattedStudentEntry(student)
+####        dict['review_state'] = 'unknown'
+####        dict['count'] = count
+####        res = context.portal_catalog(portal_type='Student',id = student.getId)
+####        if res:
+####            rs = dict['review_state'] = res[0].review_state
+####            rwrite('"%(count)d","%(id)s","%(name)s","%(jamb_reg_no)s","%(matric_no)s","%(entry_mode)s,"%(level)s","%(review_state)s"' % dict)
+##rwrite("Cleared not in special: %d" % count)
+##rwrite("Returning students: %d" % retcount)
+##rwrite("New cleared students: %d" % newc)
+rwrite("Finished")
+
