## Script (Python) "getPaymentStatistic" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: getPaymentStatistic.py 2387 2007-10-18 17:46:56Z joachim $ """ """ try: from Products.zdb import set_trace except: def set_trace(): pass mtool = context.portal_membership member = mtool.getAuthenticatedMember() if str(member) not in ('admin','joachim'): return import logging import DateTime logger = logging.getLogger('Skins.getPaymentStatistic') from Products.AdvancedQuery import Eq, Between, Le,In pins = context.portal_pins aq_pins = context.portal_pins.evalAdvancedQuery portal = context.portal_catalog_real aq_portal = context.portal_catalog_real.evalAdvancedQuery request = context.REQUEST session = request.SESSION response = request.RESPONSE setheader = request.RESPONSE.setHeader def rwrite(s): response.setHeader('Content-type','text/html; charset=ISO-8859-15') response.write("%s
\n\r" % s) # aso = aq_portal(Eq('portal_type','Payment'))# & In("SearchableText",("approved","Approved"))) # #set_trace() # count = 0 # for pp in aso: # count += 1 # if count > 1000: # break # indexdata = portal.getIndexDataForRID(pp.getRID()) # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) # return pbs = pins.uniqueValuesFor('prefix_batch') hostel_pbs = [] for pb in pbs: if pb.startswith('HMU') or pb.startswith('HMF'): hostel_pbs.append(pb) clearance_pbs = [pb for pb in pbs if pb.startswith('CLR')] application_pbs = [pb for pb in pbs if pb.startswith('APP')] newschoolfee_pbs = [pb for pb in pbs if pb.endswith('NEW1')] schoolfee_pbs = list(pbs)[:] for pb in application_pbs + hostel_pbs + clearance_pbs + newschoolfee_pbs +['HOS1','HOS2']: schoolfee_pbs.remove(pb) fees = {} missing_query = ~Eq('student','') #ah = [pin for pin in aq_pins(In('prefix_batch', hostel_pbs)) if pin.student] ah = aq_pins(In('prefix_batch', hostel_pbs) & missing_query) fees['hostel'] = {'anz': len(ah), 'fee': 500, 'title': 'Hostel Maintainance', 'prefixes': hostel_pbs, } #ac = [pin for pin in aq_pins(In('prefix_batch', clearance_pbs)) if pin.student] ac = aq_pins(In('prefix_batch', clearance_pbs)& missing_query) fees['clearance'] = {'anz': len(ac), 'fee': 250, 'title': 'Clearance', 'prefixes': clearance_pbs, } #aa = [pin for pin in aq_pins(In('prefix_batch', application_pbs)) if pin.student] aa = aq_pins(In('prefix_batch', application_pbs) & missing_query) fees['application'] = {'anz' : len(aa), 'fee': 200, 'title': 'Application', 'prefixes': application_pbs, } aso = aq_portal(Eq('portal_type','Payment') & Eq("SearchableText","approved")) # for pp in aso: # indexdata = portal.getIndexDataForRID(pp.getRID()) # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) fees['schoolfee_onl'] = {'anz' : len(aso), 'fee': 1000, 'title': 'Schoolfee (online)', 'prefixes': (), } aspaysc = aq_portal(Eq('portal_type','Payment') &\ Eq("SearchableText","payment") &\ Eq("SearchableText","successful") &\ ~ Eq("SearchableText","transfer") ) #rwrite("*"*80) # for pp in aspaysc: # indexdata = portal.getIndexDataForRID(pp.getRID()) # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) fees['schoolfee_paysc'] = {'anz' : len(aspaysc), 'fee': 1000, 'title': 'Schoolfee (sc in payments)', 'prefixes': (), } anewschool = aq_pins(In('prefix_batch', newschoolfee_pbs) & missing_query) fees['newschoolfee_sc'] = {'anz' : len(anewschool), 'fee': 1000, 'title': 'Schoolfee (..NEW SC)', 'prefixes': newschoolfee_pbs, } #assc = [pin for pin in aq_pins(In('prefix_batch', schoolfee_pbs)) if pin.student] assc = aq_pins(In('prefix_batch', schoolfee_pbs) & missing_query) fees['schoolfee_scratch'] = {'anz' : len(assc), 'fee': 0, 'title': 'Schoolfee (Scratchcard counting)', 'prefixes': schoolfee_pbs, } rwrite("Payed fees") total = 0 keys = fees.keys() keys.sort() for key in keys: fee = fees[key] t = fee['value'] = fee['anz'] * fee['fee'] total += t rwrite("%(title)s fees %(anz)d = %(value)d (%(fee)d N %(prefixes)s)" % fee) gt = float(total)/1000000 rwrite("Total %10.2f Million N" % gt)