source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/utils.py @ 17983

Last change on this file since 17983 was 17983, checked in by Henrik Bettermann, 21 hours ago

Update fees.

  • Property svn:keywords set to Id
File size: 23.9 KB
Line 
1## $Id: utils.py 17983 2025-01-14 14:08:30Z 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##
18import grok
19import random
20from time import time
21from zope.component import createObject, getUtility
22from waeup.kofa.interfaces import (
23    CLEARED, RETURNING, PAID, ADMITTED, CLEARANCE, REQUESTED)
24from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
25from waeup.kofa.accesscodes import create_accesscode
26from waeup.kofa.interfaces import CLEARED, RETURNING
27from waeup.fceokene.interfaces import MessageFactory as _
28from waeup.kofa.browser.interfaces import IPDFCreator
29from waeup.kofa.students.utils import trans
30
31# Very special school fee configuration, should be moved to
32# a seperate file.
33
34ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU',
35        'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB',
36        'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL',
37        'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG',
38        'NFRE','NARB','NHAU','NIGB','NYOR','NSOS')
39
40GATEWAY_AMT = 0.0
41
42class CustomStudentsUtils(NigeriaStudentsUtils):
43    """A collection of customized methods.
44
45    """
46
47    def selectBed(self, available_beds):
48        """Randomly select a bed from the list of available beds.
49        """
50        return random.choice(available_beds)
51
52    def getReturningData(self, student):
53        """ This method defines what happens after school fee payment
54        of returning students depending on the student's senate verdict.
55        """
56        prev_level = student['studycourse'].current_level
57        cur_verdict = student['studycourse'].current_verdict
58        if cur_verdict in ('A','B','L','M','N','Z',):
59            # Successful student
60            new_level = divmod(int(prev_level),100)[0]*100 + 100
61        elif cur_verdict in ('C','O'):
62            # Student on probation
63            new_level = int(prev_level) + 10
64        else:
65            # Student is somehow in an undefined state.
66            # Level has to be set manually.
67            new_level = prev_level
68        if cur_verdict == 'O':
69            new_session = student['studycourse'].current_session
70        else:
71            new_session = student['studycourse'].current_session + 1
72        return new_session, new_level
73
74    #def _nce3PaymentMade(self, student, p_level):
75    #    if len(student['payments']):
76    #        for ticket in student['payments'].values():
77    #            if ticket.p_state in ('paid', 'scholarship', 'waived') and \
78    #                ticket.p_level == p_level and \
79    #                ticket.p_category == 'schoolfee':
80    #                return True
81    #    return False
82
83    def setPaymentDetails(self, category, student,
84            previous_session=None, previous_level=None, combi=[]):
85        """Create Payment object and set the payment data of a student for
86        the payment category specified.
87
88        """
89        details = {}
90        p_item = u''
91        amount = 0.0
92        error = u''
93        if previous_session:
94            return _('Previous session payment not yet implemented.'), None
95        p_session = student['studycourse'].current_session
96        p_level = student['studycourse'].current_level
97        p_current = True
98        academic_session = self._getSessionConfiguration(p_session)
99        if academic_session == None:
100            return _(u'Session configuration object is not available.'), None
101        # Determine fee.
102        if category == 'transfer':
103            amount = academic_session.transfer_fee
104        elif category == 'gown':
105            amount = academic_session.gown_fee
106        elif category == 'bed_allocation':
107            acco_details = self.getAccommodationDetails(student)
108            p_session = acco_details['booking_session']
109            p_item = acco_details['bt']
110            amount = academic_session.booking_fee
111        elif category == 'hostel_maintenance':
112            amount = 0.0
113            booking_session = grok.getSite()['hostels'].accommodation_session
114            bedticket = student['accommodation'].get(str(booking_session), None)
115            if bedticket is not None and bedticket.bed is not None:
116                p_session = booking_session
117                p_item = bedticket.bed_coordinates
118                if bedticket.bed.__parent__.maint_fee > 0:
119                    amount = bedticket.bed.__parent__.maint_fee
120                #if student['studycourse'].current_session < 2022:
121                #    amount = 6100.0
122                #else:
123                #    amount = 10090.0
124            else:
125                return _(u'No bed space allocated.'), None
126            if student.current_mode.endswith('_sw') \
127                or student.current_mode == 'pd_ft':
128                amount *= 0.625
129        elif category == 'clearance':
130            amount = academic_session.clearance_fee
131            try:
132                p_item = student['studycourse'].certificate.code
133            except (AttributeError, TypeError):
134                return _('Study course data are incomplete.'), None
135            if student.state not in (ADMITTED, CLEARANCE, REQUESTED, CLEARED):
136                return _(u'Acceptance Fee payments not allowed.'), None
137        #elif category == 'third_semester' and student.current_mode == 'nce_ft' \
138        #    and p_level in (300, 310, 320, 400, 410, 420):
139        #    #if not self._nce3PaymentMade(student, p_level):
140        #    #    return _(u'Make NCE 3 school fee payment first.'), None
141        #    no_additional_courses = 0
142        #    courses_level = student['studycourse'].get(str(p_level))
143        #    if courses_level and len(courses_level)> 6:
144        #        no_additional_courses = len(courses_level)-6
145        #        amount = 2000.0 * no_additional_courses
146        elif category.startswith('schoolfee'):
147            increment_2022 = 0
148            if category == 'schoolfee_pde1':
149                if not student.current_mode.startswith('pd'):
150                    return _('You are not a PDE student.'), None
151                if student.state != CLEARED:
152                        return _('You are not a fresh student.'), None
153            if category == 'schoolfee_ug_new':
154                if not student.current_mode.startswith('ug'):
155                    return _('You are not a UG student.'), None
156                if student.state != CLEARED:
157                        return _('You are not a fresh student.'), None
158            if category == 'schoolfee_ug_ret':
159                if not student.current_mode.startswith('ug'):
160                    return _('You are not a UG student.'), None
161                if student.state != RETURNING:
162                        return _('You are not a returning student.'), None
163            if category == 'schoolfee_third':
164                if not student.current_mode == 'nce_ft' \
165                    or not p_level in (300, 310, 320, 400, 410, 420):
166                    return _('You are not an NCE 3 student.'), None
167            p_item =  student.certcode
168            if not p_item:
169                return _('Study course data are incomplete.'), None
170            if student.state not in (CLEARED, RETURNING):
171                return _('Wrong state.'), None
172            # PDE repeater
173            if student.current_verdict == 'OPDE':
174                amount = 23000
175            # PDE new
176            elif student.current_mode == 'pd_ft' and student.state == CLEARED:
177                amount = 70000
178                if category == 'schoolfee_pde1':
179                    amount = 40000
180            # PDE
181            elif student.current_mode == 'pd_ft':
182                amount = 35300
183
184            #Short Duration ICT Programs
185            elif p_item in ('CCO','DPMTS','DTPGD') and \
186                 student.state == CLEARED:
187                amount = 15000
188            elif p_item in ('ADTPGD','ADPMTS') and \
189                 student.state == CLEARED:
190                amount = 16000
191            elif p_item in ('ADPMTSI','ADTPGDI','DPMTSI','DTPGDI') and \
192                 student.state == CLEARED:
193                amount = 25000
194            elif p_item in ('ADPMTSA','ADTPGDA') and \
195               student.state == CLEARED:
196                amount = 35000
197
198            # UG
199            elif student.current_mode == 'ug_ft':
200                if category == 'schoolfee_ug_new':
201                    # conditions checked above
202                    amount = 80000
203                elif category == 'schoolfee_ug_ret':
204                    # conditions checked above
205                    amount = 60000
206                elif student.state == CLEARED:
207                    amount = 140000
208                # Introducing repeater fee for 'ug_ft' for 1st time
209                # on 15/03/2016
210                #elif student.current_verdict == 'O':
211                #    amount = 96700
212                else:
213                    amount = 110000
214
215            # NCE
216            elif not student.current_mode.endswith('_sw'):
217                # in 2022 NCE school fees have encreased
218                increment_2022 = 11000
219                # PRENCE
220                if student.current_level == 10 and student.state == CLEARED:
221                    if student.depcode in ARTS:
222                        amount = 24500
223                    else:
224                        amount = 25000
225                # NCE I fresh
226                elif student.current_level == 100 and student.state == CLEARED:
227                    if student.depcode in ARTS:
228                        amount = 28000
229                    else:
230                        amount = 28500
231                    # SIWES Fee
232                    if student.depcode in ('AGE', 'BED', 'FAA', 'HEC', 'CSC', 'MUS') \
233                       or student.certcode in ('NCECHECSC',
234                                               'NCEBIOCSC',
235                                               'NCEPHYCSC',
236                                               'NCEPHECSC',
237                                               'NCETHAMUS',
238                                               'NCEANFMUS',
239                                               'NCEHISMUS',
240                                               'NCEIGBMUS',
241                                               'NCESPCCSC',
242                                               ):
243                        amount += 3000
244                # NCE II
245                elif student.current_level in (100, 110, 120) and \
246                    student.state == RETURNING:
247                    if student.depcode in ARTS:
248                        amount = 24500
249                    else:
250                        amount = 25000
251                # NCE III third semester
252                elif category == 'schoolfee_third':
253                    amount = 7000
254                    increment_2022 = 0
255                # NCE III
256                elif student.current_level in (200, 210, 220):
257                    if student.depcode in ARTS:
258                        amount = 15375
259                    else:
260                        amount = 15875
261                    increment_2022 = 20125
262                # NCE III repeater
263                elif student.current_level in (300, 310, 320) and \
264                    student.current_verdict == 'O':
265                    if student.depcode in ARTS:
266                        amount = 13475
267                    else:
268                        amount = 13975
269                    increment_2022 = 11000
270                # NCE III spillover
271                elif student.current_level in (300, 310, 320) and \
272                    student.current_verdict == 'B':
273                    if student.depcode in ARTS:
274                        amount = 13475
275                    else:
276                        amount = 13975
277                    increment_2022 = 20125
278                # NCE III second spillover
279                elif student.current_level in (400, 410, 420) and \
280                    student.current_verdict == 'B':
281                    if student.depcode in ARTS:
282                        amount = 13475
283                    else:
284                        amount = 13975
285                    increment_2022 = 20125
286            else:
287                # NCE I fresh sw
288                if student.current_level == 100 and student.state == CLEARED:
289                    if student.depcode in ARTS:
290                        amount = 23100
291                    else:
292                        amount = 23600
293                # NCE II fresh sw
294                elif student.current_level == 200 and student.state == CLEARED:
295                    if student.depcode in ARTS:
296                        amount = 19000
297                    else:
298                        amount = 19500
299                # NCE II sw
300                elif student.current_level in (100, 110, 120) and \
301                    student.state == RETURNING:
302                    if student.depcode in ARTS:
303                        amount = 19000
304                    else:
305                        amount = 19500
306                # NCE III sw
307                elif student.current_level in (200, 210, 220):
308                    if student.depcode in ARTS:
309                        amount = 21000
310                    else:
311                        amount = 21500
312                # NCE IV sw
313                elif student.current_level in (300, 310, 320):
314                    if student.depcode in ARTS:
315                        amount = 19000
316                    else:
317                        amount = 19500
318                # NCE V sw
319                elif student.current_level in (400, 410, 420):
320                    if student.depcode in ARTS:
321                        amount = 19000
322                    else:
323                        amount = 19500
324                # NCE V spillover sw
325                elif student.current_level in (500, 510, 520) and \
326                    student.current_verdict == 'B':
327                    if student.depcode in ARTS:
328                        amount = 17500
329                    else:
330                        amount = 18000
331                # NCE V second spillover sw
332                elif student.current_level in (600, 610, 620) and \
333                    student.current_verdict == 'B':
334                    if student.depcode in ARTS:
335                        amount = 17500
336                    else:
337                        amount = 18000
338            # NCE student payment can be disabled by
339            # setting the base school fee to -1
340            if academic_session.school_fee_base == -1 and \
341                student.current_mode.startswith('nce'):
342                return _(u'School fee payment is disabled.'), None
343            if student.state == RETURNING:
344                # Override p_session and p_level
345                p_session, p_level = self.getReturningData(student)
346                academic_session = self._getSessionConfiguration(p_session)
347                if academic_session == None:
348                    return _(u'Session configuration object is not available.'), None
349            if amount and p_session > 2021:
350                    amount += increment_2022
351        else:
352            fee_name = category + '_fee'
353            amount = getattr(academic_session, fee_name, 0.0)
354           
355        if amount in (0.0, None):
356            return _(u'Amount could not be determined.'), None
357
358        # Add session and level specific penalty fee.
359        if category == 'schoolfee' and student.current_mode in (
360            'ug_ft', 'de_ft') and student.state != CLEARED:
361            amount += academic_session.penalty_ug_ft
362        elif category == 'schoolfee' and student.current_mode in (
363            'nce_ft',) and student['studycourse'].previous_verdict != 'O':
364            # NCE I fresh
365            if student.current_level == 100 and student.state == CLEARED:
366                amount += academic_session.penalty_nce1_ft
367            # NCE II
368            elif student.current_level in (100, 110, 120) and \
369                student.state == RETURNING:
370                amount += academic_session.penalty_nce2_ft
371            # NCE III (except repeaters and spillovers)
372            elif student.current_level in (200, 210, 220):
373                amount += academic_session.penalty_nce3_ft
374        elif category == 'schoolfee' and student.current_mode in ('nce_sw',
375            'nce_pt') and student['studycourse'].previous_verdict != 'O':
376            # NCE I fresh
377            if student.current_level == 100 and student.state == CLEARED:
378                amount += academic_session.penalty_nce1_pt
379            # NCE II
380            elif student.current_level in (100, 110, 120) and \
381                student.state == RETURNING:
382                amount += academic_session.penalty_nce2_pt
383            # NCE III (except repeaters and spillovers)
384            elif student.current_level in (200, 210, 220):
385                amount += academic_session.penalty_nce3_pt
386        elif category == 'schoolfee' and student.current_mode in ('prence',):
387            amount += academic_session.penalty_prence
388        if self.samePaymentMade(student, category, p_item, p_session):
389            return _('This type of payment has already been made.'), None
390        if self._isPaymentDisabled(p_session, category, student):
391            return _('This category of payments has been disabled.'), None
392        payment = createObject(u'waeup.StudentOnlinePayment')
393        timestamp = ("%d" % int(time()*10000))[1:]
394        payment.p_id = "p%s" % timestamp
395        payment.p_category = category
396        payment.p_item = p_item
397        payment.p_session = p_session
398        payment.p_level = p_level
399        payment.p_current = p_current
400        payment.amount_auth = float(amount) + GATEWAY_AMT
401        return None, payment
402
403    def getAccommodationDetails(self, student):
404        """Determine the accommodation data of a student.
405        """
406        d = {}
407        d['error'] = u''
408        hostels = grok.getSite()['hostels']
409        d['booking_session'] = hostels.accommodation_session
410        d['allowed_states'] = hostels.accommodation_states
411        d['startdate'] = hostels.startdate
412        d['enddate'] = hostels.enddate
413        d['expired'] = hostels.expired
414        # Determine bed type
415        studycourse = student['studycourse']
416        certificate = getattr(studycourse,'certificate',None)
417        current_level = studycourse.current_level
418        if None in (current_level, certificate):
419            return d
420        end_level = certificate.end_level
421        if current_level == 10:
422            bt = 'pr'
423        elif current_level == 100:
424            bt = 'fr'
425        elif current_level >= 300:
426            bt = 'fi'
427        else:
428            bt = 're'
429        if student.sex == 'f':
430            sex = 'female'
431        else:
432            sex = 'male'
433        special_handling = 'regular'
434        if certificate.study_mode == 'ug_ft':
435            special_handling = 'ugft'
436        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
437        return d
438
439    #def warnCreditsOOR(self, studylevel, course=None):
440    #    """Return message if credits are out of range.
441    #    """
442    #    # adding a course ticket
443    #    if course:
444    #        if course.semester == 1:
445    #            if studylevel.total_credits_s1 + course.credits > 24:
446    #                return _('Maximum credits in 1st semester exceeded.')
447    #        if course.semester == 2:
448    #            if studylevel.total_credits_s2 + course.credits > 24:
449    #                return _('Maximum credits in 2nd semester exceeded.')
450    #    # registering course list
451    #    else:
452    #        if studylevel.total_credits_s1 > 24:
453    #            return _('Maximum credits in 1st semester exceeded.')
454    #        if studylevel.total_credits_s1 < 18:
455    #            return _('Minimum credits in 1st semester not reached.')
456    #        if studylevel.total_credits_s2 > 24:
457    #            return _('Maximum credits in 2nd semester exceeded.')
458    #        if studylevel.total_credits_s2 < 18:
459    #            return _('Minimum credits in 2nd semester not reached.')
460    #    return
461
462    def warnCreditsOOR(self, studylevel, course=None):
463        """Return message if credits are out of range.
464        """
465        # adding a course ticket
466        if course:
467            if studylevel.total_credits + course.credits > 52:
468                return _('Maximum credits exceeded.')
469        # registering course list
470        else:
471            if studylevel.total_credits > 52:
472                return _('Maximum credits exceeded.')
473            if studylevel.__parent__.previous_verdict == 'O':
474                return
475            if studylevel.total_credits_s1 < 18:
476                return _('Minimum credits in 1st semester not reached.')
477            if studylevel.total_credits_s2 < 18:
478                return _('Minimum credits in 2nd semester not reached.')
479        return
480
481    def getPDFCreator(self, context):
482        """Get a pdf creator suitable for `context`.
483
484        The default implementation always returns the default creator.
485        """
486        mode = getattr(context, 'current_mode', None)
487        if mode and mode.startswith('ug'):
488            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
489        return getUtility(IPDFCreator)
490
491    def _admissionText(self, student, portal_language):
492        mode = getattr(student, 'current_mode', None)
493        if mode and mode.startswith('ug'):
494            text = trans(_(
495                'With reference to your application for admission into '
496                'Bachelor Degree Programme of the University of Ibadan, '
497                'you have been provisionally admitted to a full-time '
498                'Bachelor of Arts in Education Degree Programme as follows: '),
499                portal_language)
500        else:
501            inst_name = grok.getSite()['configuration'].name
502            text = trans(_(
503                'You have been provisionally admitted into Federal College '
504                'of Education Okene as follows: '
505                ),
506                portal_language)
507        return text
508
509    def getBedCoordinates(self, bedticket):
510        """Return bed coordinates.
511
512        Bed coordinates are invisible in FCEOkene.
513        """
514        return _('(see payment slip)')
515
516    def _isPaymentDisabled(self, p_session, category, student):
517        academic_session = self._getSessionConfiguration(p_session)
518        if category == 'schoolfee':
519            if 'sf_all' in academic_session.payment_disabled:
520                return True
521            if 'sf_nce1' in academic_session.payment_disabled and \
522                student.current_level == 100 and student.state == CLEARED and \
523                student.current_mode == 'nce_ft':
524                return True
525        if category == 'clearance':
526            if 'cl_except_ug' in academic_session.payment_disabled and \
527                student.current_mode != 'ug_ft':
528                return True
529        return False
530
531    SEPARATORS_DICT = {
532        'form.fst_sit_fname': _(u'First Sitting Record'),
533        'form.scd_sit_fname': _(u'Second Sitting Record'),
534        #'form.alr_fname': _(u'Advanced Level Record'),
535        'form.hq_type': _(u'Advanced Level Record'),
536        'form.hq2_type': _(u'Second Higher Education Record'),
537        'form.nysc_year': _(u'NYSC Information'),
538        'form.employer': _(u'Employment History'),
539        'form.former_matric': _(u'Former Student'),
540        }
541
542    SKIP_UPLOAD_VIEWLETS = (
543        'higherqualificationresultupload',
544        'secondHigherqualificationresultupload',
545        'certificateupload',
546        'secondcertificateupload',
547        'thirdcertificateupload',
548        'resultstatementupload',
549        'secondrefereeletterupload',
550        'thirdrefereeletterupload',)
551
552    ACCOMMODATION_SPAN = 1
553
554    # FCEOkene prefix
555    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.