Index: main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/tests/test_utils.py
===================================================================
--- main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/tests/test_utils.py	(revision 14336)
+++ main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/tests/test_utils.py	(revision 14336)
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+from hurry.workflow.interfaces import IWorkflowState
+from zope.component import getUtility, createObject
+from waeup.kofa.testing import FunctionalTestCase
+from waeup.kofa.university.faculty import Faculty
+from waeup.kofa.university.department import Department
+from waeup.kofa.students.student import Student
+from waeup.kofa.students.interfaces import IStudentsUtils
+from waeup.kofa.students.tests.test_browser import StudentsFullSetup
+from kofacustom.coewarri.testing import FunctionalLayer
+
+class StudentsUtilsTests(StudentsFullSetup):
+
+    layer = FunctionalLayer
+
+    def test_set_payment_details(self):
+        self.student['studycourse'].certificate.study_mode = 'ug_ft'
+        self.student.nationality = u'NG'
+        self.student.lga = 'ebonyi_ukaba'
+        self.student['studycourse'].current_session = 2016
+        self.student['studycourse'].entry_session = 2016
+        utils = getUtility(IStudentsUtils)
+
+        configuration = createObject('waeup.SessionConfiguration')
+        configuration.academic_session = 2016
+        self.app['configuration'].addSessionConfiguration(configuration)
+        self.app['configuration']['2016'].clearance_fee = 10234.0
+
+        error, payment = utils.setPaymentDetails('schoolfee', self.student)
+        self.assertEqual(payment, None)
+        self.assertEqual(error, u'Amount could not be determined.')
+        IWorkflowState(self.student).setState('cleared')
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(payment.p_level, 100)
+        self.assertEqual(payment.p_session, 2016)
+        self.assertEqual(payment.amount_auth, 79500.0)
+        self.assertEqual(payment.p_item, u'CERT1')
+        self.assertEqual(error, None)
+
+        error, payment = utils.setPaymentDetails('clearance',self.student)
+        self.assertEqual(payment.amount_auth, 15234.0)
+        self.assertEqual(payment.p_item, u'CERT1')
+
+        self.student.lga = 'delta_burutu'
+        error, payment = utils.setPaymentDetails('schoolfee',self.student)
+        self.assertEqual(payment.amount_auth, 69500.0)
+        error, payment = utils.setPaymentDetails('clearance',self.student)
+        self.assertEqual(payment.amount_auth, 10234.0)
+        return
Index: main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/utils.py
===================================================================
--- main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/utils.py	(revision 14333)
+++ main/kofacustom.coewarri/trunk/src/kofacustom/coewarri/students/utils.py	(revision 14336)
@@ -18,8 +18,10 @@
 from time import time
 from zope.component import createObject, getUtility
+from waeup.kofa.fees import FeeTable
 from waeup.kofa.interfaces import (IKofaUtils,
     ADMITTED, CLEARED, RETURNING, PAID, REGISTERED, VALIDATED)
 from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
 from kofacustom.coewarri.interfaces import MessageFactory as _
+from kofacustom.coewarri.interswitch.browser import GATEWAY_AMT
 
 
@@ -31,4 +33,27 @@
         return 'non-local'
 
+PAYMENT_LEVELS = (100, 110, 200, 210, 300, 310, 400, 410, 500, 999)
+
+FEES_PARAMS = (
+        ('local', 'non-local'),
+        ('nce_ft', 'nce_pt', 'ug_ft'),
+        PAYMENT_LEVELS
+    )
+
+FEES_VALUES = (
+      ( # 100      110      200      210      300      310      400      410     500  999
+        (42000.0, 42000.0, 20600.0, 20600.0, 18100.0, 18100.0,     0.0,     0.0, 0.0, 0.0), # nce_ft
+        (55200.0, 55200.0, 42200.0, 42200.0, 44700.0, 44700.0, 42200.0, 42200.0, 0.0, 0.0), # nce_pt
+        (69200.0, 69200.0, 63100.0, 63100.0, 63100.0, 63100.0, 62100.0, 62100.0, 0.0, 0.0), # ug_ft
+      ), # local
+      ( #
+        (54600.0, 54600.0, 22600.0, 22600.0, 20100.0, 20100.0,     0.0,     0.0, 0.0, 0.0), # nce_ft
+        (55200.0, 55200.0, 42200.0, 42200.0, 44700.0, 44700.0, 42200.0, 42200.0, 0.0, 0.0), # nce_pt
+        (79200.0, 79200.0, 63100.0, 63100.0, 63100.0, 63100.0, 62100.0, 62100.0, 0.0, 0.0), # ug_ft
+      ), # non-local
+    )
+
+SCHOOL_FEES = FeeTable(FEES_PARAMS, FEES_VALUES)
+
 class CustomStudentsUtils(NigeriaStudentsUtils):
     """A collection of customized methods.
@@ -37,5 +62,5 @@
 
     def setPaymentDetails(self, category, student,
-            previous_session, previous_level):
+            previous_session=None, previous_level=None):
         """Create a payment ticket and set the payment data of a
         student for the payment category specified.
@@ -43,22 +68,7 @@
         p_item = u''
         amount = 0.0
-        if previous_session:
-            if previous_session < student['studycourse'].entry_session:
-                return _('The previous session must not fall below '
-                         'your entry session.'), None
-            if category == 'schoolfee':
-                # School fee is always paid for the following session
-                if previous_session > student['studycourse'].current_session:
-                    return _('This is not a previous session.'), None
-            else:
-                if previous_session > student['studycourse'].current_session - 1:
-                    return _('This is not a previous session.'), None
-            p_session = previous_session
-            p_level = previous_level
-            p_current = False
-        else:
-            p_session = student['studycourse'].current_session
-            p_level = student['studycourse'].current_level
-            p_current = True
+        p_session = student['studycourse'].current_session
+        p_level = student['studycourse'].current_level
+        p_current = True
         academic_session = self._getSessionConfiguration(p_session)
         if academic_session == None:
@@ -71,38 +81,20 @@
             except (AttributeError, TypeError):
                 return _('Study course data are incomplete.'), None
-            if previous_session:
-                # Students can pay for previous sessions in all
-                # workflow states.  Fresh students are excluded by the
-                # update method of the PreviousPaymentAddFormPage.
-                if previous_level == 100:
-                    amount = getattr(certificate, 'school_fee_1', 0.0)
-                else:
-                    amount = getattr(certificate, 'school_fee_2', 0.0)
-            else:
-                if student.state == CLEARED:
-                    amount = getattr(certificate, 'school_fee_1', 0.0)
-                elif student.state == RETURNING:
-                    # In case of returning school fee payment the
-                    # payment session and level contain the values of
-                    # the session the student has paid for. Payment
-                    # session is always next session.
-                    p_session, p_level = self.getReturningData(student)
-                    academic_session = self._getSessionConfiguration(p_session)
-                    if academic_session == None:
-                        return _(
-                            u'Session configuration object is not available.'
-                            ), None
-                    amount = getattr(certificate, 'school_fee_2', 0.0)
-                elif student.is_postgrad and student.state == PAID:
-                    # Returning postgraduate students also pay for the
-                    # next session but their level always remains the
-                    # same.
-                    p_session += 1
-                    academic_session = self._getSessionConfiguration(p_session)
-                    if academic_session == None:
-                        return _(
-                            u'Session configuration object is not available.'
-                            ), None
-                    amount = getattr(certificate, 'school_fee_2', 0.0)
+            if student.state == RETURNING:
+                # Override p_session and p_level
+                p_session, p_level = self.getReturningData(student)
+                academic_session = self._getSessionConfiguration(p_session)
+                if academic_session == None:
+                    return _(u'Session configuration object '
+                              'is not available.'), None
+            if student.state in (RETURNING, CLEARED):
+                if p_level in PAYMENT_LEVELS:
+                    amount = SCHOOL_FEES.get_fee(
+                        (
+                         local_nonlocal(student),
+                         student.current_mode,
+                         p_level)
+                        )
+                    amount += GATEWAY_AMT
         elif category == 'clearance':
             try:
@@ -111,4 +103,6 @@
                 return _('Study course data are incomplete.'), None
             amount = academic_session.clearance_fee
+            if local_nonlocal(student) == 'non-local':
+                amount += 5000.0
         elif category == 'bed_allocation':
             p_item = self.getAccommodationDetails(student)['bt']
