Index: /main/kofacustom.unidel/trunk/src/kofacustom/unidel/browser/pages.py
===================================================================
--- /main/kofacustom.unidel/trunk/src/kofacustom/unidel/browser/pages.py	(revision 18365)
+++ /main/kofacustom.unidel/trunk/src/kofacustom/unidel/browser/pages.py	(revision 18366)
@@ -20,8 +20,19 @@
     SessionConfigurationAddFormPage, SessionConfigurationManageFormPage,
     LoginPage, CertificatePage, CertificateManageFormPage,
-    DatacenterImportStep2)
+    DatacenterImportStep2, ConfigurationContainerManageFormPage)
+from waeup.kofa.interfaces import IConfigurationContainer
 from waeup.kofa.university.interfaces import ICertificate
 from kofacustom.unidel.interfaces import (
     ICustomSessionConfiguration, ICustomSessionConfigurationAdd)
+
+class CustomConfigurationContainerManageFormPage(
+    ConfigurationContainerManageFormPage):
+
+    form_fields = grok.AutoFields(IConfigurationContainer).omit(
+        'next_matric_integer_2',
+        'next_matric_integer_3',
+        'next_matric_integer_4',
+        )
+    form_fields['maintmode_enabled_by'].for_display = True
 
 class CustomSessionConfigurationAddFormPage(SessionConfigurationAddFormPage):
Index: /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/browser.py
===================================================================
--- /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/browser.py	(revision 18365)
+++ /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/browser.py	(revision 18366)
@@ -949,2 +949,23 @@
         super(CustomAddStudyLevelFormPage, self).update()
         return
+
+class StudentGetMatricNumberPage(UtilityView, grok.View):
+    """ Construct and set the matriculation number.
+    """
+    grok.context(ICustomStudent)
+    grok.name('get_matric_number')
+    grok.require('waeup.viewStudent')
+
+    def update(self):
+        students_utils = getUtility(IStudentsUtils)
+        msg, mnumber = students_utils.setMatricNumber(self.context)
+        if msg:
+            self.flash(msg, type="danger")
+        else:
+            self.flash(_('Matriculation number %s assigned.' % mnumber))
+            self.context.writeLogMessage(self, '%s assigned' % mnumber)
+        self.redirect(self.url(self.context))
+        return
+
+    def render(self):
+        return
Index: /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/tests/test_utils.py
===================================================================
--- /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/tests/test_utils.py	(revision 18365)
+++ /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/tests/test_utils.py	(revision 18366)
@@ -2,4 +2,5 @@
 import grok
 from waeup.kofa.testing import FunctionalTestCase
+from zope.component import getUtility
 from hurry.workflow.interfaces import IWorkflowState
 from zope.component import getUtility, createObject
@@ -36,2 +37,14 @@
         self.assertEqual(warning, None)
         return
+
+    def test_setMatricNumber(self):
+        site = grok.getSite()
+        utils = getUtility(IStudentsUtils)
+        site['configuration'].next_matric_integer = 12345
+        self.student.matric_number = None
+        msg, mnumber = utils.setMatricNumber(self.student)
+        self.assertEqual(msg, 'Matriculation number cannot be set.')
+        IWorkflowState(self.student).setState('school fee paid')
+        msg, mnumber = utils.setMatricNumber(self.student)
+        self.assertEqual(self.student.matric_number, 'fac10412345')
+        return
Index: /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/utils.py
===================================================================
--- /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/utils.py	(revision 18365)
+++ /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/utils.py	(revision 18366)
@@ -523,2 +523,14 @@
     #        return 5, self.GPABoundaries()[5][1]
     #    return
+
+    def constructMatricNumber(self, student):
+        faccode = student.faccode
+        #depcode = student.depcode
+        #certcode = student.certcode
+        if not student.state in (PAID, ) or not student.is_fresh:
+            return _('Matriculation number cannot be set.'), None
+        year = unicode(student.entry_session)[2:]
+        next_integer = grok.getSite()['configuration'].next_matric_integer
+        if next_integer == 0:
+            return _('Matriculation number cannot be set.'), None
+        return None, "%s%s%05d" % (faccode, year, next_integer)
Index: /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/viewlets.py
===================================================================
--- /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/viewlets.py	(revision 18365)
+++ /main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/viewlets.py	(revision 18366)
@@ -18,8 +18,10 @@
 
 import grok
+from zope.component import getUtility
 from waeup.kofa.interfaces import REQUESTED
 from waeup.kofa.browser.viewlets import ManageActionButton
 from kofacustom.unidel.students.interfaces import (ICustomStudent,
     ICustomStudentStudyCourse, ICustomStudentStudyLevel)
+from waeup.kofa.students.interfaces import IStudentsUtils
 from waeup.kofa.students.fileviewlets import (
     StudentFileDisplay, StudentFileUpload, StudentImage)
@@ -31,4 +33,25 @@
 
 from kofacustom.nigeria.interfaces import MessageFactory as _
+
+
+class GetMatricNumberActionButton(ManageActionButton):
+    grok.order(11)
+    grok.context(ICustomStudent)
+    grok.view(StudentBaseDisplayFormPage)
+    grok.require('waeup.viewStudent')
+    #grok.require('waeup.manageStudent')
+    icon = 'actionicon_count.png'
+    text = _('Get Matriculation Number')
+
+    @property
+    def target_url(self):
+        students_utils = getUtility(IStudentsUtils)
+        if self.context.matric_number:
+            return ''
+        error, matric_number = students_utils.constructMatricNumber(
+            self.context)
+        if error:
+            return ''
+        return self.view.url(self.view.context, 'get_matric_number')
 
 class ExamClearanceSlipActionButton(ManageActionButton):
