source: WAeUP_SRP/base/skins/waeup_utilities/getPaymentStatistic.py @ 2391

Last change on this file since 2391 was 2391, checked in by joachim, 17 years ago

current version (NOT in custom)

  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
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"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18mtool = context.portal_membership
19member = mtool.getAuthenticatedMember()
20if str(member) not in ('admin','joachim'):
21    return
22
23import logging
24import DateTime
25logger = logging.getLogger('Skins.getPaymentStatistic')
26from Products.AdvancedQuery import Eq, Between, Le,In
27pins = context.portal_pins
28aq_pins = context.portal_pins.evalAdvancedQuery
29portal = context.portal_catalog_real
30aq_portal = context.portal_catalog_real.evalAdvancedQuery
31request = context.REQUEST
32session = request.SESSION
33response = request.RESPONSE
34setheader = request.RESPONSE.setHeader
35def 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
62pbs = pins.uniqueValuesFor('prefix_batch')
63hostel_pbs = []
64for pb in pbs:
65    if pb.startswith('HMU') or pb.startswith('HMF'):
66        hostel_pbs.append(pb)
67clearance_pbs = [pb for pb in pbs if pb.startswith('CLR')]
68application_pbs = [pb for pb in pbs if pb.startswith('APP')]
69
70newschoolfee_pbs = [pb for pb in pbs if pb.endswith('NEW1')]
71
72schoolfee_pbs = list(pbs)[:]
73for pb in application_pbs + hostel_pbs + clearance_pbs + newschoolfee_pbs +['HOS1','HOS2']:
74    schoolfee_pbs.remove(pb)
75fees = {}
76missing_query = ~Eq('student','')
77#ah = [pin for pin in aq_pins(In('prefix_batch', hostel_pbs)) if pin.student]
78ah = aq_pins(In('prefix_batch', hostel_pbs) & missing_query)
79fees['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]
85ac = aq_pins(In('prefix_batch', clearance_pbs)& missing_query)
86fees['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]
92aa = aq_pins(In('prefix_batch', application_pbs) & missing_query)
93fees['application'] = {'anz' : len(aa),
94                 'fee': 200,
95                 'title': 'Application',
96                  'prefixes': application_pbs,
97                 }
98aso_query = Eq('portal_type','Payment') & Eq("SearchableText","approved")
99aso = 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']))
103fees['schoolfee_onl'] = {'anz' : len(aso),
104                 'fee': 1000,
105                 'title': 'Schoolfee (online)',
106                  'prefixes': (),
107                 }
108aspaysc_query = Eq('portal_type','Payment') &\
109                    Eq("SearchableText","payment") &\
110                    Eq("SearchableText","successful") &\
111                    ~ Eq("SearchableText","transfer")
112
113aspaysc = 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']))
118fees['schoolfee_paysc'] = {'anz' : len(aspaysc),
119                 'fee': 1000,
120                 'title': 'Schoolfee (sc in payments)',
121                  'prefixes': (),
122                 }
123not_query = ~aso_query & ~aspaysc_query
124not_res = aq_portal(aspaysc_query)
125fees['schoolfee_not'] = {'anz' : len(not_res),
126                 'fee': 0,
127                 'title': 'Not Schoolfee',
128                  'prefixes': (),
129                 }
130anewschool = aq_pins(In('prefix_batch', newschoolfee_pbs) & missing_query)
131fees['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]
137assc = aq_pins(In('prefix_batch', schoolfee_pbs) & missing_query)
138fees['schoolfee_scratch'] = {'anz' : len(assc),
139                 'fee': 0,
140                 'title': 'Schoolfee (Scratchcard counting)',
141                  'prefixes': schoolfee_pbs,
142                 }
143rwrite("Payed fees")
144total = 0
145keys = fees.keys()
146keys.sort()
147for 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)
152gt = float(total)/1000000
153rwrite("Total %10.2f Million N" % gt)
Note: See TracBrowser for help on using the repository browser.