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 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 | 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 |
---|
29 | portal = context.portal_catalog_real |
---|
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 | |
---|
39 | # aso = aq_portal(Eq('portal_type','Payment') &\ |
---|
40 | # #Eq('review_state','closed') &\ |
---|
41 | # ~Eq("SearchableText",'sc') &\ |
---|
42 | # ~Eq("SearchableText",'approved') &\ |
---|
43 | # ~Eq("SearchableText",'incomplete') &\ |
---|
44 | # ~Eq("SearchableText",'invalid') &\ |
---|
45 | # ~Eq("SearchableText",'incorrect') &\ |
---|
46 | # ~Eq("SearchableText",'card') &\ |
---|
47 | # ~Eq("SearchableText",'error') &\ |
---|
48 | # ~Eq("SearchableText",'channels') &\ |
---|
49 | # ~Eq("SearchableText",'exceeded') &\ |
---|
50 | # ~Eq("SearchableText",'insufficient')) |
---|
51 | # #set_trace() |
---|
52 | # count = 0 |
---|
53 | # rwrite("total: %d" % len(aso)) |
---|
54 | # for pp in aso: |
---|
55 | # count += 1 |
---|
56 | # if count > 1000: |
---|
57 | # break |
---|
58 | # indexdata = portal.getIndexDataForRID(pp.getRID()) |
---|
59 | # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) |
---|
60 | # return |
---|
61 | |
---|
62 | pbs = pins.uniqueValuesFor('prefix_batch') |
---|
63 | hostel_pbs = [] |
---|
64 | for pb in pbs: |
---|
65 | if pb.startswith('HMU') or pb.startswith('HMF'): |
---|
66 | hostel_pbs.append(pb) |
---|
67 | clearance_pbs = [pb for pb in pbs if pb.startswith('CLR')] |
---|
68 | application_pbs = [pb for pb in pbs if pb.startswith('APP')] |
---|
69 | |
---|
70 | newschoolfee_pbs = [pb for pb in pbs if pb.endswith('NEW1')] |
---|
71 | |
---|
72 | schoolfee_pbs = list(pbs)[:] |
---|
73 | for pb in application_pbs + hostel_pbs + clearance_pbs + newschoolfee_pbs +['HOS1','HOS2']: |
---|
74 | schoolfee_pbs.remove(pb) |
---|
75 | fees = {} |
---|
76 | missing_query = ~Eq('student','') |
---|
77 | #ah = [pin for pin in aq_pins(In('prefix_batch', hostel_pbs)) if pin.student] |
---|
78 | ah = aq_pins(In('prefix_batch', hostel_pbs) & missing_query) |
---|
79 | fees['hostel'] = {'anz': len(ah), |
---|
80 | 'fee': 500, |
---|
81 | 'title': 'Hostel Maintainance', |
---|
82 | 'prefixes': hostel_pbs, |
---|
83 | } |
---|
84 | #ac = [pin for pin in aq_pins(In('prefix_batch', clearance_pbs)) if pin.student] |
---|
85 | ac = aq_pins(In('prefix_batch', clearance_pbs)& missing_query) |
---|
86 | fees['clearance'] = {'anz': len(ac), |
---|
87 | 'fee': 250, |
---|
88 | 'title': 'Clearance', |
---|
89 | 'prefixes': clearance_pbs, |
---|
90 | } |
---|
91 | #aa = [pin for pin in aq_pins(In('prefix_batch', application_pbs)) if pin.student] |
---|
92 | aa = aq_pins(In('prefix_batch', application_pbs) & missing_query) |
---|
93 | fees['application'] = {'anz' : len(aa), |
---|
94 | 'fee': 200, |
---|
95 | 'title': 'Application', |
---|
96 | 'prefixes': application_pbs, |
---|
97 | } |
---|
98 | aso_query = Eq('portal_type','Payment') & Eq("SearchableText","approved") |
---|
99 | aso = aq_portal(aso_query) |
---|
100 | # for pp in aso: |
---|
101 | # indexdata = portal.getIndexDataForRID(pp.getRID()) |
---|
102 | # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) |
---|
103 | fees['schoolfee_onl'] = {'anz' : len(aso), |
---|
104 | 'fee': 1000, |
---|
105 | 'title': 'Schoolfee (online)', |
---|
106 | 'prefixes': (), |
---|
107 | } |
---|
108 | aspaysc_query = Eq('portal_type','Payment') &\ |
---|
109 | Eq("SearchableText","payment") &\ |
---|
110 | Eq("SearchableText","successful") &\ |
---|
111 | ~ Eq("SearchableText","transfer") |
---|
112 | |
---|
113 | aspaysc = aq_portal(aspaysc_query) |
---|
114 | #rwrite("*"*80) |
---|
115 | # for pp in aspaysc: |
---|
116 | # indexdata = portal.getIndexDataForRID(pp.getRID()) |
---|
117 | # rwrite("%s %s %s" % (pp.id,pp.listCreators,indexdata['SearchableText'])) |
---|
118 | fees['schoolfee_paysc'] = {'anz' : len(aspaysc), |
---|
119 | 'fee': 1000, |
---|
120 | 'title': 'Schoolfee (sc in payments)', |
---|
121 | 'prefixes': (), |
---|
122 | } |
---|
123 | not_query = ~aso_query & ~aspaysc_query |
---|
124 | not_res = aq_portal(aspaysc_query) |
---|
125 | fees['schoolfee_not'] = {'anz' : len(not_res), |
---|
126 | 'fee': 0, |
---|
127 | 'title': 'Not Schoolfee', |
---|
128 | 'prefixes': (), |
---|
129 | } |
---|
130 | anewschool = aq_pins(In('prefix_batch', newschoolfee_pbs) & missing_query) |
---|
131 | fees['newschoolfee_sc'] = {'anz' : len(anewschool), |
---|
132 | 'fee': 1000, |
---|
133 | 'title': 'Schoolfee (..NEW SC)', |
---|
134 | 'prefixes': newschoolfee_pbs, |
---|
135 | } |
---|
136 | #assc = [pin for pin in aq_pins(In('prefix_batch', schoolfee_pbs)) if pin.student] |
---|
137 | assc = aq_pins(In('prefix_batch', schoolfee_pbs) & missing_query) |
---|
138 | fees['schoolfee_scratch'] = {'anz' : len(assc), |
---|
139 | 'fee': 0, |
---|
140 | 'title': 'Schoolfee (Scratchcard counting)', |
---|
141 | 'prefixes': schoolfee_pbs, |
---|
142 | } |
---|
143 | rwrite("Payed fees") |
---|
144 | total = 0 |
---|
145 | keys = fees.keys() |
---|
146 | keys.sort() |
---|
147 | for key in keys: |
---|
148 | fee = fees[key] |
---|
149 | t = fee['value'] = fee['anz'] * fee['fee'] |
---|
150 | total += t |
---|
151 | rwrite("%(title)s fees %(anz)d = %(value)d (%(fee)d N %(prefixes)s)" % fee) |
---|
152 | gt = float(total)/1000000 |
---|
153 | rwrite("Total %10.2f Million N" % gt) |
---|