## $Id: utils.py 7621 2012-02-09 20:06:14Z henrik $
##
## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
import grok
from waeup.sirp.students.workflow import CLEARED, RETURNING
from waeup.sirp.students.utils import StudentsUtils
from waeup.sirp.students.interfaces import IStudentsUtils

def get_school_fee(student, surcharge):
    study_mode = student['studycourse'].certificate.study_mode
    entry_mode = student['studycourse'].entry_mode
    state = student.state
    #lga = student.lga
    lga = 'nothing'
    current_level = student['studycourse'].current_level

    if study_mode.endswith('_ft'):
        # fresh
        if state == CLEARED:
            return 40000 - surcharge
        # returning
        elif state == RETURNING:
            return 20000 - surcharge
        else:
            return 0
    else:
        return 0

class StudentsUtils(StudentsUtils):
    """A collection of customized methods.

    """
    grok.implements(IStudentsUtils)

    # not yet changed
    def setReturningData(self, student):
        student['studycourse'].current_level += 100
        student['studycourse'].current_session += 1
        verdict = student['studycourse'].current_verdict
        student['studycourse'].current_verdict = '0'
        student['studycourse'].previous_verdict = verdict
        return

    def getPaymentDetails(self, category, student):
        d = {}
        d['surcharge_1'] = d['surcharge_2'] = d['surcharge_3'] = 0
        d['p_item'] = u''
        d['amount'] = 0
        d['error'] = u''
        d['p_session'] = student['studycourse'].current_session
        session = str(d['p_session'])
        try:
            academic_session = grok.getSite()['configuration'][session]
        except KeyError:
            d['error'] = u'Session configuration object is not available.'
            return d
        if category == 'transfer':
            d['amount'] = academic_session.transfer_fee
        elif category == 'gown':
            d['amount'] = academic_session.gown_fee
        elif category == 'bed_allocation':
            d['amount'] = academic_session.booking_fee
        elif category == 'hostel_maintenance':
            d['amount'] = academic_session.maint_fee
        elif category == 'clearance':
            d['p_item'] = student['studycourse'].certificate.code
            d['amount'] = academic_session.clearance_fee
        elif category == 'schoolfee':
            d['surcharge_1'] = academic_session.surcharge_1
            d['surcharge_2'] = academic_session.surcharge_2
            d['amount'] = get_school_fee(student, d['surcharge_1'] + d['surcharge_2'])
            code = student['studycourse'].certificate.code
            d['p_item'] = code
            d['p_session'] += 1
        if d['amount'] == 0:
            d['error'] = u'Amount could not be determined.'
        return d

    def getVerdictsDict(self):
        """Provide a dictionary of verdicts.
        """
        return {
            '0': 'not yet',
            'A': 'Successful student',
            'B': 'Student with carryover courses',
            'C': 'Student on probation',
            'D': 'Withdrawn from the faculty',
            'E': 'Student who were previously on probation',
            'F': 'Medical case',
            'G': 'Absent from examination',
            }

