1 | ## $Id: utils.py 9570 2012-11-07 17:22:50Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | import grok |
---|
19 | from time import time |
---|
20 | from zope.component import createObject, getUtility |
---|
21 | from reportlab.lib.styles import getSampleStyleSheet |
---|
22 | from reportlab.platypus import Paragraph, Image, Table, Spacer |
---|
23 | from waeup.kofa.interfaces import (IKofaUtils, |
---|
24 | CLEARED, RETURNING, PAID, REGISTERED, VALIDATED) |
---|
25 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
26 | from waeup.kofa.accesscodes import create_accesscode |
---|
27 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
28 | from waeup.kofa.students.utils import (trans, render_student_data, |
---|
29 | render_table_data, get_signature_table) |
---|
30 | |
---|
31 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
32 | """A collection of customized methods. |
---|
33 | |
---|
34 | """ |
---|
35 | |
---|
36 | def getReturningData(self, student): |
---|
37 | """ This method defines what happens after school fee payment |
---|
38 | of returning students depending on the student's senate verdict. |
---|
39 | """ |
---|
40 | prev_level = student['studycourse'].current_level |
---|
41 | cur_verdict = student['studycourse'].current_verdict |
---|
42 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
43 | # Successful student |
---|
44 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
45 | elif cur_verdict == 'C': |
---|
46 | # Student on probation |
---|
47 | new_level = int(prev_level) + 10 |
---|
48 | else: |
---|
49 | # Student is somehow in an undefined state. |
---|
50 | # Level has to be set manually. |
---|
51 | new_level = prev_level |
---|
52 | new_session = student['studycourse'].current_session + 1 |
---|
53 | return new_session, new_level |
---|
54 | |
---|
55 | def _paymentMade(self, student, session): |
---|
56 | if len(student['payments']): |
---|
57 | for ticket in student['payments'].values(): |
---|
58 | if ticket.p_state == 'paid' and \ |
---|
59 | ticket.p_category == 'schoolfee' and \ |
---|
60 | ticket.p_session == session: |
---|
61 | return True |
---|
62 | return False |
---|
63 | |
---|
64 | def setPaymentDetails(self, category, student, |
---|
65 | previous_session, previous_level): |
---|
66 | """Create Payment object and set the payment data of a student for |
---|
67 | the payment category specified. |
---|
68 | |
---|
69 | """ |
---|
70 | p_item = u'' |
---|
71 | amount = 0.0 |
---|
72 | if previous_session: |
---|
73 | if previous_session < student['studycourse'].entry_session: |
---|
74 | return _('The previous session must not fall below ' |
---|
75 | 'your entry session.'), None |
---|
76 | if category == 'schoolfee': |
---|
77 | # School fee is always paid for the following session |
---|
78 | if previous_session > student['studycourse'].current_session: |
---|
79 | return _('This is not a previous session.'), None |
---|
80 | else: |
---|
81 | if previous_session > student['studycourse'].current_session - 1: |
---|
82 | return _('This is not a previous session.'), None |
---|
83 | p_session = previous_session |
---|
84 | p_level = previous_level |
---|
85 | p_current = False |
---|
86 | else: |
---|
87 | p_session = student['studycourse'].current_session |
---|
88 | p_level = student['studycourse'].current_level |
---|
89 | p_current = True |
---|
90 | academic_session = self._getSessionConfiguration(p_session) |
---|
91 | if academic_session == None: |
---|
92 | return _(u'Session configuration object is not available.'), None |
---|
93 | # Determine fee. |
---|
94 | if category == 'transfer': |
---|
95 | amount = academic_session.transfer_fee |
---|
96 | elif category == 'gown': |
---|
97 | amount = academic_session.gown_fee |
---|
98 | elif category == 'bed_allocation': |
---|
99 | amount = academic_session.booking_fee |
---|
100 | elif category == 'hostel_maintenance': |
---|
101 | amount = academic_session.maint_fee |
---|
102 | elif category == 'clearance': |
---|
103 | try: |
---|
104 | p_item = student['studycourse'].certificate.code |
---|
105 | except (AttributeError, TypeError): |
---|
106 | return _('Study course data are incomplete.'), None |
---|
107 | if p_item in ('BSCANA', 'BSCMBC', 'BMLS', 'BSCNUR', 'BSCPHS', 'BDS', |
---|
108 | 'MBBSMED', 'MBBSNDU'): |
---|
109 | amount = 65000.0 |
---|
110 | elif p_item in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET', |
---|
111 | 'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'): |
---|
112 | amount = 22500.0 |
---|
113 | else: |
---|
114 | amount = 45000.0 |
---|
115 | elif category == 'schoolfee': |
---|
116 | try: |
---|
117 | certificate = student['studycourse'].certificate |
---|
118 | p_item = certificate.code |
---|
119 | except (AttributeError, TypeError): |
---|
120 | return _('Study course data are incomplete.'), None |
---|
121 | if previous_session: |
---|
122 | # Students can pay for previous sessions in all workflow states. |
---|
123 | # Fresh students are excluded by the update method of the |
---|
124 | # PreviousPaymentAddFormPage. |
---|
125 | if previous_session == student['studycourse'].entry_session: |
---|
126 | if student.is_foreigner: |
---|
127 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
128 | else: |
---|
129 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
130 | else: |
---|
131 | if student.is_foreigner: |
---|
132 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
133 | else: |
---|
134 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
135 | else: |
---|
136 | if student.state == CLEARED: |
---|
137 | if student.is_foreigner: |
---|
138 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
139 | else: |
---|
140 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
141 | elif student.state in (PAID, REGISTERED, VALIDATED): |
---|
142 | p_session += 1 |
---|
143 | # We don't know which level the student is paying for. |
---|
144 | p_level = None |
---|
145 | academic_session = self._getSessionConfiguration(p_session) |
---|
146 | if academic_session == None: |
---|
147 | return _(u'Session configuration object is not available.'), None |
---|
148 | |
---|
149 | # Students are only allowed to pay for the next session |
---|
150 | # if current session payment |
---|
151 | # has really been made, i.e. payment object exists. |
---|
152 | #if not self._paymentMade( |
---|
153 | # student, student.current_session): |
---|
154 | # return _('You have not yet paid your current/active' + |
---|
155 | # ' session. Please use the previous session' + |
---|
156 | # ' payment form first.'), None |
---|
157 | |
---|
158 | if student.is_foreigner: |
---|
159 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
160 | else: |
---|
161 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
162 | elif student.state == RETURNING: |
---|
163 | # In case of returning school fee payment the payment session |
---|
164 | # and level contain the values of the session the student |
---|
165 | # has paid for. |
---|
166 | p_session, p_level = self.getReturningData(student) |
---|
167 | academic_session = self._getSessionConfiguration(p_session) |
---|
168 | if academic_session == None: |
---|
169 | return _(u'Session configuration object is not available.'), None |
---|
170 | |
---|
171 | # Students are only allowed to pay for the next session |
---|
172 | # if current session payment has really been made, |
---|
173 | # i.e. payment object exists and is paid. |
---|
174 | #if not self._paymentMade( |
---|
175 | # student, student.current_session): |
---|
176 | # return _('You have not yet paid your current/active' + |
---|
177 | # ' session. Please use the previous session' + |
---|
178 | # ' payment form first.'), None |
---|
179 | |
---|
180 | if student.is_foreigner: |
---|
181 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
182 | else: |
---|
183 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
184 | # Give 50% school fee discount to staff members. |
---|
185 | if student.is_staff: |
---|
186 | amount /= 2 |
---|
187 | if amount in (0.0, None): |
---|
188 | return _('Amount could not be determined.'), None |
---|
189 | # Add session specific penalty fee. |
---|
190 | if category == 'schoolfee' and student.is_postgrad: |
---|
191 | amount += academic_session.penalty_pg |
---|
192 | elif category == 'schoolfee': |
---|
193 | amount += academic_session.penalty_ug |
---|
194 | # Create ticket. |
---|
195 | for key in student['payments'].keys(): |
---|
196 | ticket = student['payments'][key] |
---|
197 | if ticket.p_state == 'paid' and\ |
---|
198 | ticket.p_category == category and \ |
---|
199 | ticket.p_item == p_item and \ |
---|
200 | ticket.p_session == p_session: |
---|
201 | return _('This type of payment has already been made.'), None |
---|
202 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
203 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
204 | payment.p_id = "p%s" % timestamp |
---|
205 | payment.p_category = category |
---|
206 | payment.p_item = p_item |
---|
207 | payment.p_session = p_session |
---|
208 | payment.p_level = p_level |
---|
209 | payment.p_current = p_current |
---|
210 | payment.amount_auth = amount |
---|
211 | return None, payment |
---|
212 | |
---|
213 | # Uniben prefix |
---|
214 | STUDENT_ID_PREFIX = u'B' |
---|