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 2365 2007-10-16 06:29:48Z 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 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
30 | request = context.REQUEST |
---|
31 | session = request.SESSION |
---|
32 | response = request.RESPONSE |
---|
33 | setheader = request.RESPONSE.setHeader |
---|
34 | def rwrite(s): |
---|
35 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
36 | response.write("%s<br>\n\r" % s) |
---|
37 | |
---|
38 | pbs = pins.uniqueValuesFor('prefix_batch') |
---|
39 | hostel_pbs = [] |
---|
40 | for pb in pbs: |
---|
41 | if pb.startswith('HMU') or pb.startswith('HMF'): |
---|
42 | hostel_pbs.append(pb) |
---|
43 | clearance_pbs = [pb for pb in pbs if pb.startswith('CLR')] |
---|
44 | application_pbs = [pb for pb in pbs if pb.startswith('APP')] |
---|
45 | |
---|
46 | schoolfee_pbs = list(pbs)[:] |
---|
47 | for pb in application_pbs + hostel_pbs + clearance_pbs: |
---|
48 | schoolfee_pbs.remove(pb) |
---|
49 | fees = {} |
---|
50 | missing_query = ~Eq('student','') |
---|
51 | #ah = [pin for pin in aq_pins(In('prefix_batch', hostel_pbs)) if pin.student] |
---|
52 | ah = aq_pins(In('prefix_batch', hostel_pbs) & missing_query) |
---|
53 | fees['hostel'] = {'anz': len(ah), |
---|
54 | 'fee': 500, |
---|
55 | 'title': 'Hostel Maintainance', |
---|
56 | } |
---|
57 | #ac = [pin for pin in aq_pins(In('prefix_batch', clearance_pbs)) if pin.student] |
---|
58 | ac = aq_pins(In('prefix_batch', clearance_pbs)& missing_query) |
---|
59 | fees['clearance'] = {'anz': len(ac), |
---|
60 | 'fee': 250, |
---|
61 | 'title': 'Clearance', |
---|
62 | } |
---|
63 | #aa = [pin for pin in aq_pins(In('prefix_batch', application_pbs)) if pin.student] |
---|
64 | aa = aq_pins(In('prefix_batch', application_pbs) & missing_query) |
---|
65 | fees['application'] = {'anz' : len(aa), |
---|
66 | 'fee': 200, |
---|
67 | 'title': 'Application', |
---|
68 | } |
---|
69 | aso = aq_portal(Eq('portal_type','Payment') & In("SearchableText",("successful",))) |
---|
70 | fees['schoolfee_onl'] = {'anz' : len(aso), |
---|
71 | 'fee': 1000, |
---|
72 | 'title': 'Schoolfee (online)', |
---|
73 | } |
---|
74 | #assc = [pin for pin in aq_pins(In('prefix_batch', schoolfee_pbs)) if pin.student] |
---|
75 | assc = aq_pins(In('prefix_batch', schoolfee_pbs) & missing_query) |
---|
76 | fees['schoolfee_scratch'] = {'anz' : len(assc), |
---|
77 | 'fee': 1000, |
---|
78 | 'title': 'Schoolfee (Scratchcard)', |
---|
79 | } |
---|
80 | rwrite("Payed fees") |
---|
81 | total = 0 |
---|
82 | for fee in fees.values(): |
---|
83 | t = fee['value'] = fee['anz'] * fee['fee'] |
---|
84 | total += t |
---|
85 | rwrite("%(title)s fees %(anz)d = %(value)d (%(fee)d N)" % fee) |
---|
86 | gt = float(total)/1000000 |
---|
87 | rwrite("Total %10.2f Million N" % gt) |
---|