source: WAeUP_SRP/trunk/skins/waeup_statistics/getPaymentStatistics.py @ 17388

Last change on this file since 17388 was 2404, checked in by Henrik Bettermann, 17 years ago

forgotten to check in

File size: 5.9 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: getPaymentStatistics.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
18
19import logging
20import DateTime
21logger = logging.getLogger('Skins.getPaymentStatistics')
22from Products.AdvancedQuery import Eq, Between, Le,In
23
24
25mtool = context.portal_membership
26member = mtool.getAuthenticatedMember()
27logger.info('%s starts getPaymentStatistics' % (member))
28if str(member) not in ('admin','joachim','isouaba','hetomi'):
29    return
30
31pins = context.portal_pins
32aq_pins = context.portal_pins.evalAdvancedQuery
33portal = context.portal_catalog_real
34aq_portal = context.portal_catalog_real.evalAdvancedQuery
35request = context.REQUEST
36session = request.SESSION
37response = request.RESPONSE
38setheader = request.RESPONSE.setHeader
39def 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
66pbs = pins.uniqueValuesFor('prefix_batch')
67hostel_pbs = []
68for pb in pbs:
69    if pb.startswith('HMU') or pb.startswith('HMF'):
70        hostel_pbs.append(pb)
71clearance_pbs = [pb for pb in pbs if pb.startswith('CLR')]
72application_pbs = [pb for pb in pbs if pb.startswith('APP')]
73
74newschoolfee_pbs = [pb for pb in pbs if pb.endswith('NEW1')]
75
76schoolfee_pbs = list(pbs)[:]
77for pb in application_pbs + hostel_pbs + clearance_pbs + newschoolfee_pbs +['HOS1','HOS2']:
78    schoolfee_pbs.remove(pb)
79fees = {}
80missing_query = ~Eq('student','')
81#ah = [pin for pin in aq_pins(In('prefix_batch', hostel_pbs)) if pin.student]
82ah = aq_pins(In('prefix_batch', hostel_pbs) & missing_query)
83fees['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]
89ac = aq_pins(In('prefix_batch', clearance_pbs)& missing_query)
90fees['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]
96aa = aq_pins(In('prefix_batch', application_pbs) & missing_query)
97fees['application'] = {'anz' : len(aa),
98                 'fee': 200,
99                 'title': 'Application scratch cards',
100                  'prefixes': application_pbs,
101                 }
102                 
103aso_query = Eq('portal_type','Payment') & Eq("SearchableText","approved")
104aso = 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']))
108fees['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]
147assc = aq_pins(In('prefix_batch', schoolfee_pbs) & missing_query)
148fees['schoolfee_scratch'] = {'anz' : len(assc),
149                 'fee': 1000,
150                 'title': 'School fee scratch cards',
151                  'prefixes': schoolfee_pbs,
152                 }
153
154current = DateTime.DateTime()
155rwrite("Portal Service Charges (of %s)" % current)
156rwrite('------------------------------------------------------------------')
157
158total = 0
159keys = fees.keys()
160keys.sort()
161for 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)
166gt = float(total)/1000000
167rwrite("Total %10.2f Million Nairas" % gt)
168
Note: See TracBrowser for help on using the repository browser.