[2365] | 1 | ## Script (Python) "getPaymentStatistic" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters= |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
| 10 | # $Id: getPaymentStatistic.py 2387 2007-10-18 17:46:56Z joachim $ |
---|
| 11 | """ |
---|
| 12 | """ |
---|
| 13 | try: |
---|
| 14 | from Products.zdb import set_trace |
---|
| 15 | except: |
---|
| 16 | def set_trace(): |
---|
| 17 | pass |
---|
| 18 | mtool = context.portal_membership |
---|
| 19 | member = mtool.getAuthenticatedMember() |
---|
| 20 | if str(member) not in ('admin','joachim'): |
---|
| 21 | return |
---|
| 22 | |
---|
| 23 | import logging |
---|
| 24 | import DateTime |
---|
| 25 | logger = logging.getLogger('Skins.getPaymentStatistic') |
---|
| 26 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 27 | pins = context.portal_pins |
---|
| 28 | aq_pins = context.portal_pins.evalAdvancedQuery |
---|
[2386] | 29 | portal = context.portal_catalog_real |
---|
[2365] | 30 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
| 31 | request = context.REQUEST |
---|
| 32 | session = request.SESSION |
---|
| 33 | response = request.RESPONSE |
---|
| 34 | setheader = request.RESPONSE.setHeader |
---|
| 35 | def rwrite(s): |
---|
| 36 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 37 | response.write("%s<br>\n\r" % s) |
---|
| 38 | |
---|
[2386] | 39 | # aso = aq_portal(Eq('portal_type','Payment'))# & In("SearchableText",("approved","Approved"))) |
---|
| 40 | # #set_trace() |
---|
| 41 | # count = 0 |
---|
| 42 | # for pp in aso: |
---|
| 43 | # count += 1 |
---|
| 44 | # if count > 1000: |
---|
| 45 | # break |
---|
| 46 | # indexdata = portal.getIndexDataForRID(pp.getRID()) |
---|
| 47 | # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) |
---|
| 48 | # return |
---|
[2365] | 49 | pbs = pins.uniqueValuesFor('prefix_batch') |
---|
| 50 | hostel_pbs = [] |
---|
| 51 | for pb in pbs: |
---|
| 52 | if pb.startswith('HMU') or pb.startswith('HMF'): |
---|
| 53 | hostel_pbs.append(pb) |
---|
| 54 | clearance_pbs = [pb for pb in pbs if pb.startswith('CLR')] |
---|
| 55 | application_pbs = [pb for pb in pbs if pb.startswith('APP')] |
---|
| 56 | |
---|
[2387] | 57 | newschoolfee_pbs = [pb for pb in pbs if pb.endswith('NEW1')] |
---|
| 58 | |
---|
[2365] | 59 | schoolfee_pbs = list(pbs)[:] |
---|
[2387] | 60 | for pb in application_pbs + hostel_pbs + clearance_pbs + newschoolfee_pbs +['HOS1','HOS2']: |
---|
[2365] | 61 | schoolfee_pbs.remove(pb) |
---|
| 62 | fees = {} |
---|
| 63 | missing_query = ~Eq('student','') |
---|
| 64 | #ah = [pin for pin in aq_pins(In('prefix_batch', hostel_pbs)) if pin.student] |
---|
| 65 | ah = aq_pins(In('prefix_batch', hostel_pbs) & missing_query) |
---|
| 66 | fees['hostel'] = {'anz': len(ah), |
---|
| 67 | 'fee': 500, |
---|
| 68 | 'title': 'Hostel Maintainance', |
---|
[2366] | 69 | 'prefixes': hostel_pbs, |
---|
[2365] | 70 | } |
---|
| 71 | #ac = [pin for pin in aq_pins(In('prefix_batch', clearance_pbs)) if pin.student] |
---|
| 72 | ac = aq_pins(In('prefix_batch', clearance_pbs)& missing_query) |
---|
| 73 | fees['clearance'] = {'anz': len(ac), |
---|
[2366] | 74 | 'fee': 250, |
---|
| 75 | 'title': 'Clearance', |
---|
| 76 | 'prefixes': clearance_pbs, |
---|
[2365] | 77 | } |
---|
| 78 | #aa = [pin for pin in aq_pins(In('prefix_batch', application_pbs)) if pin.student] |
---|
| 79 | aa = aq_pins(In('prefix_batch', application_pbs) & missing_query) |
---|
| 80 | fees['application'] = {'anz' : len(aa), |
---|
| 81 | 'fee': 200, |
---|
| 82 | 'title': 'Application', |
---|
[2366] | 83 | 'prefixes': application_pbs, |
---|
[2365] | 84 | } |
---|
[2386] | 85 | aso = aq_portal(Eq('portal_type','Payment') & Eq("SearchableText","approved")) |
---|
| 86 | # for pp in aso: |
---|
| 87 | # indexdata = portal.getIndexDataForRID(pp.getRID()) |
---|
| 88 | # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) |
---|
[2365] | 89 | fees['schoolfee_onl'] = {'anz' : len(aso), |
---|
| 90 | 'fee': 1000, |
---|
| 91 | 'title': 'Schoolfee (online)', |
---|
[2366] | 92 | 'prefixes': (), |
---|
[2365] | 93 | } |
---|
[2386] | 94 | aspaysc = aq_portal(Eq('portal_type','Payment') &\ |
---|
| 95 | Eq("SearchableText","payment") &\ |
---|
[2387] | 96 | Eq("SearchableText","successful") &\ |
---|
| 97 | ~ Eq("SearchableText","transfer") |
---|
| 98 | ) |
---|
| 99 | #rwrite("*"*80) |
---|
[2386] | 100 | # for pp in aspaysc: |
---|
| 101 | # indexdata = portal.getIndexDataForRID(pp.getRID()) |
---|
| 102 | # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) |
---|
| 103 | fees['schoolfee_paysc'] = {'anz' : len(aspaysc), |
---|
| 104 | 'fee': 1000, |
---|
| 105 | 'title': 'Schoolfee (sc in payments)', |
---|
| 106 | 'prefixes': (), |
---|
| 107 | } |
---|
[2387] | 108 | anewschool = aq_pins(In('prefix_batch', newschoolfee_pbs) & missing_query) |
---|
| 109 | fees['newschoolfee_sc'] = {'anz' : len(anewschool), |
---|
| 110 | 'fee': 1000, |
---|
| 111 | 'title': 'Schoolfee (..NEW SC)', |
---|
| 112 | 'prefixes': newschoolfee_pbs, |
---|
| 113 | } |
---|
[2365] | 114 | #assc = [pin for pin in aq_pins(In('prefix_batch', schoolfee_pbs)) if pin.student] |
---|
| 115 | assc = aq_pins(In('prefix_batch', schoolfee_pbs) & missing_query) |
---|
| 116 | fees['schoolfee_scratch'] = {'anz' : len(assc), |
---|
[2386] | 117 | 'fee': 0, |
---|
| 118 | 'title': 'Schoolfee (Scratchcard counting)', |
---|
[2366] | 119 | 'prefixes': schoolfee_pbs, |
---|
[2365] | 120 | } |
---|
| 121 | rwrite("Payed fees") |
---|
| 122 | total = 0 |
---|
[2366] | 123 | keys = fees.keys() |
---|
| 124 | keys.sort() |
---|
| 125 | for key in keys: |
---|
| 126 | fee = fees[key] |
---|
[2365] | 127 | t = fee['value'] = fee['anz'] * fee['fee'] |
---|
| 128 | total += t |
---|
[2366] | 129 | rwrite("%(title)s fees %(anz)d = %(value)d (%(fee)d N %(prefixes)s)" % fee) |
---|
[2365] | 130 | gt = float(total)/1000000 |
---|
| 131 | rwrite("Total %10.2f Million N" % gt) |
---|