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: getPaymentStatistics.py 2391 2007-10-19 09:24:16Z joachim $ |
---|
11 | """ |
---|
12 | """ |
---|
13 | try: |
---|
14 | from Products.zdb import set_trace |
---|
15 | except: |
---|
16 | def set_trace(): |
---|
17 | pass |
---|
18 | |
---|
19 | import logging |
---|
20 | import DateTime |
---|
21 | logger = logging.getLogger('Skins.getPaymentStatistics') |
---|
22 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
23 | |
---|
24 | |
---|
25 | mtool = context.portal_membership |
---|
26 | member = mtool.getAuthenticatedMember() |
---|
27 | logger.info('%s starts getPaymentStatistics' % (member)) |
---|
28 | if str(member) not in ('admin','joachim','isouaba','hetomi'): |
---|
29 | return |
---|
30 | |
---|
31 | pins = context.portal_pins |
---|
32 | aq_pins = context.portal_pins.evalAdvancedQuery |
---|
33 | portal = context.portal_catalog_real |
---|
34 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
35 | request = context.REQUEST |
---|
36 | session = request.SESSION |
---|
37 | response = request.RESPONSE |
---|
38 | setheader = request.RESPONSE.setHeader |
---|
39 | def rwrite(s): |
---|
40 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
41 | response.write("%s<br>\n\r" % s) |
---|
42 | |
---|
43 | # aso = aq_portal(Eq('portal_type','Payment') &\ |
---|
44 | # #Eq('review_state','closed') &\ |
---|
45 | # ~Eq("SearchableText",'sc') &\ |
---|
46 | # ~Eq("SearchableText",'approved') &\ |
---|
47 | # ~Eq("SearchableText",'incomplete') &\ |
---|
48 | # ~Eq("SearchableText",'invalid') &\ |
---|
49 | # ~Eq("SearchableText",'incorrect') &\ |
---|
50 | # ~Eq("SearchableText",'card') &\ |
---|
51 | # ~Eq("SearchableText",'error') &\ |
---|
52 | # ~Eq("SearchableText",'channels') &\ |
---|
53 | # ~Eq("SearchableText",'exceeded') &\ |
---|
54 | # ~Eq("SearchableText",'insufficient')) |
---|
55 | # #set_trace() |
---|
56 | # count = 0 |
---|
57 | # rwrite("total: %d" % len(aso)) |
---|
58 | # for pp in aso: |
---|
59 | # count += 1 |
---|
60 | # if count > 1000: |
---|
61 | # break |
---|
62 | # indexdata = portal.getIndexDataForRID(pp.getRID()) |
---|
63 | # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) |
---|
64 | # return |
---|
65 | |
---|
66 | pbs = pins.uniqueValuesFor('prefix_batch') |
---|
67 | hostel_pbs = [] |
---|
68 | for pb in pbs: |
---|
69 | if pb.startswith('HMU') or pb.startswith('HMF'): |
---|
70 | hostel_pbs.append(pb) |
---|
71 | clearance_pbs = [pb for pb in pbs if pb.startswith('CLR')] |
---|
72 | application_pbs = [pb for pb in pbs if pb.startswith('APP')] |
---|
73 | |
---|
74 | newschoolfee_pbs = [pb for pb in pbs if pb.endswith('NEW1')] |
---|
75 | |
---|
76 | schoolfee_pbs = list(pbs)[:] |
---|
77 | for pb in application_pbs + hostel_pbs + clearance_pbs + newschoolfee_pbs +['HOS1','HOS2']: |
---|
78 | schoolfee_pbs.remove(pb) |
---|
79 | fees = {} |
---|
80 | missing_query = ~Eq('student','') |
---|
81 | #ah = [pin for pin in aq_pins(In('prefix_batch', hostel_pbs)) if pin.student] |
---|
82 | ah = aq_pins(In('prefix_batch', hostel_pbs) & missing_query) |
---|
83 | fees['hostel'] = {'anz': len(ah), |
---|
84 | 'fee': 500, |
---|
85 | 'title': 'Hostel maintainance scratch cards', |
---|
86 | 'prefixes': hostel_pbs, |
---|
87 | } |
---|
88 | #ac = [pin for pin in aq_pins(In('prefix_batch', clearance_pbs)) if pin.student] |
---|
89 | ac = aq_pins(In('prefix_batch', clearance_pbs)& missing_query) |
---|
90 | fees['clearance'] = {'anz': len(ac), |
---|
91 | 'fee': 250, |
---|
92 | 'title': 'Clearance scratch cards', |
---|
93 | 'prefixes': clearance_pbs, |
---|
94 | } |
---|
95 | #aa = [pin for pin in aq_pins(In('prefix_batch', application_pbs)) if pin.student] |
---|
96 | aa = aq_pins(In('prefix_batch', application_pbs) & missing_query) |
---|
97 | fees['application'] = {'anz' : len(aa), |
---|
98 | 'fee': 200, |
---|
99 | 'title': 'Application scratch cards', |
---|
100 | 'prefixes': application_pbs, |
---|
101 | } |
---|
102 | |
---|
103 | aso_query = Eq('portal_type','Payment') & Eq("SearchableText","approved") |
---|
104 | aso = aq_portal(aso_query) |
---|
105 | # for pp in aso: |
---|
106 | # indexdata = portal.getIndexDataForRID(pp.getRID()) |
---|
107 | # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) |
---|
108 | fees['schoolfee_onl'] = {'anz' : len(aso), |
---|
109 | 'fee': 1000, |
---|
110 | 'title': 'School fee Wema/Interswitch payments', |
---|
111 | 'prefixes': (), |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | #aspaysc_query = Eq('portal_type','Payment') &\ |
---|
116 | # Eq("SearchableText","payment") &\ |
---|
117 | # Eq("SearchableText","successful") &\ |
---|
118 | # ~ Eq("SearchableText","transfer") |
---|
119 | |
---|
120 | #aspaysc = aq_portal(aspaysc_query) |
---|
121 | #rwrite("*"*80) |
---|
122 | # for pp in aspaysc: |
---|
123 | # indexdata = portal.getIndexDataForRID(pp.getRID()) |
---|
124 | # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) |
---|
125 | #fees['schoolfee_paysc'] = {'anz' : len(aspaysc), |
---|
126 | # 'fee': 1000, |
---|
127 | # 'title': 'Schoolfee (sc in payments)', |
---|
128 | # 'prefixes': (), |
---|
129 | # } |
---|
130 | |
---|
131 | #not_query = ~aso_query & ~aspaysc_query |
---|
132 | #not_res = aq_portal(aspaysc_query) |
---|
133 | #fees['schoolfee_not'] = {'anz' : len(not_res), |
---|
134 | # 'fee': 0, |
---|
135 | # 'title': 'Not Schoolfee', |
---|
136 | # 'prefixes': (), |
---|
137 | # } |
---|
138 | |
---|
139 | #anewschool = aq_pins(In('prefix_batch', newschoolfee_pbs) & missing_query) |
---|
140 | #fees['newschoolfee_sc'] = {'anz' : len(anewschool), |
---|
141 | # 'fee': 1000, |
---|
142 | # 'title': 'Schoolfee (..NEW SC)', |
---|
143 | # 'prefixes': newschoolfee_pbs, |
---|
144 | # } |
---|
145 | |
---|
146 | #assc = [pin for pin in aq_pins(In('prefix_batch', schoolfee_pbs)) if pin.student] |
---|
147 | assc = aq_pins(In('prefix_batch', schoolfee_pbs) & missing_query) |
---|
148 | fees['schoolfee_scratch'] = {'anz' : len(assc), |
---|
149 | 'fee': 1000, |
---|
150 | 'title': 'School fee scratch cards', |
---|
151 | 'prefixes': schoolfee_pbs, |
---|
152 | } |
---|
153 | |
---|
154 | current = DateTime.DateTime() |
---|
155 | rwrite("Portal Service Charges (of %s)" % current) |
---|
156 | rwrite('------------------------------------------------------------------') |
---|
157 | |
---|
158 | total = 0 |
---|
159 | keys = fees.keys() |
---|
160 | keys.sort() |
---|
161 | for key in keys: |
---|
162 | fee = fees[key] |
---|
163 | t = fee['value'] = fee['anz'] * fee['fee'] |
---|
164 | total += t |
---|
165 | rwrite("%(title)s: %(anz)d * %(fee)d Nairas = %(value)d Nairas" % fee) #(Prefixes %(prefixes)s)" % fee) |
---|
166 | gt = float(total)/1000000 |
---|
167 | rwrite("Total %10.2f Million Nairas" % gt) |
---|
168 | |
---|