Index: /main/kofacustom.dspg/trunk/src/kofacustom/dspg/interswitch/browser.py
===================================================================
--- /main/kofacustom.dspg/trunk/src/kofacustom/dspg/interswitch/browser.py	(revision 14888)
+++ /main/kofacustom.dspg/trunk/src/kofacustom/dspg/interswitch/browser.py	(revision 14889)
@@ -135,9 +135,8 @@
             self.pay_item_id = '102'
             provider_amt = 2800.0
-            if self.student.current_mode.endswith('pt') or \
-                self.student.current_mode.endswith('we'):
-                xmldict['institution_acct'] = '1012808851 '
+            if student.faccode == 'SPAT':
+                xmldict['institution_acct'] = '1012808851'
                 xmldict['institution_bank_id'] = '117'
-            elif self.student.current_mode in ('nd_ft', 'hnd_ft'):
+            elif student.current_mode in ('nd_ft', 'hnd_ft'):
                 xmldict['institution_acct'] = '0026235493'
                 xmldict['institution_bank_id'] = '31'
@@ -145,9 +144,8 @@
             self.pay_item_id = '103'
             provider_amt = 500.0
-            if self.student.current_mode.endswith('pt') or \
-                self.student.current_mode.endswith('we'):
-                xmldict['institution_acct'] = '1012808851 '
+            if student.faccode == 'SPAT':
+                xmldict['institution_acct'] = '1012808851'
                 xmldict['institution_bank_id'] = '117'
-            elif self.student.current_mode == 'nd_ft':
+            elif student.current_mode == 'nd_ft':
                 xmldict['institution_acct'] = '2004402644'
                 xmldict['institution_bank_id'] = '8'
@@ -160,7 +158,6 @@
         xmldict['institution_item_name'] = self.context.category
         xmldict['institution_name'] = INSTITUTION_NAME
-        xmldict['institution_amt'] = 100 * (
+        xmldict['institution_amt'] = institution_amt = 100 * (
             self.context.amount_auth - provider_amt - GATEWAY_AMT)
-        # Interswitch amount is not part of the xml data
         if provider_amt == 0:
             xmltext = """<payment_item_detail>
@@ -176,4 +173,27 @@
 </item_details>
 </payment_item_detail>""" % xmldict
+
+        # isouaba: All certificates in SPAT are part time thus any payments
+        # coming from those certificates (Application, Acceptance, school fees
+        # etc) 40% should be split to keystone account.
+        if student.faccode == 'SPAT':
+            xmldict['institution_amt_2'] = 0.4 * institution_amt
+            xmldict['institution_amt_1'] = 0.6 * institution_amt
+            if provider_amt == 0:
+                xmltext = """<payment_item_detail>
+<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
+<item_detail item_id="1" item_name="%(institution_item_name)s 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
+<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="123" acct_num="1002883141" />
+</item_details>
+</payment_item_detail>""" % xmldict
+            else:
+                xmltext = """<payment_item_detail>
+<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s">
+<item_detail item_id="1" item_name="%(institution_item_name)s 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
+<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="123" acct_num="1002883141" />
+<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
+</item_details>
+</payment_item_detail>""" % xmldict
+
         self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
         self.context.provider_amt = provider_amt
@@ -234,8 +254,8 @@
         xmldict['provider_bank_id'] = PROVIDER_BANK_ID
         xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
-        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - gateway_amt)
+        xmldict['institution_amt'] = institution_amt = 100 * (
+            self.context.amount_auth - provider_amt - gateway_amt)
         xmldict['institution_item_name'] = self.context.category
         xmldict['institution_name'] = INSTITUTION_NAME
-        # Interswitch amount is not part of the xml data
         xmltext = """<payment_item_detail>
 <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
@@ -244,4 +264,20 @@
 </item_details>
 </payment_item_detail>""" % xmldict
+
+        # isouaba: All certificates in SPAT are part time thus any payments
+        # coming from those certificates (Application, Acceptance, school fees
+        # etc) 40% should be split to keystone account.
+        if self.applicant.__parent__.application_category in (
+            'ndpt', 'hndpt', 'ndwe', 'hndwe'):
+            xmldict['institution_amt_2'] = 0.4 * institution_amt
+            xmldict['institution_amt_1'] = 0.6 * institution_amt
+            xmltext = """<payment_item_detail>
+<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
+<item_detail item_id="1" item_name="%(institution_item_name)s 1" item_amt="%(institution_amt_1)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
+<item_detail item_id="2" item_name="%(institution_item_name)s 2" item_amt="%(institution_amt_2)d" bank_id="123" acct_num="1002883141" />
+<item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
+</item_details>
+</payment_item_detail>""" % xmldict
+
         self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
         self.context.provider_amt = provider_amt
Index: /main/kofacustom.dspg/trunk/src/kofacustom/dspg/interswitch/tests.py
===================================================================
--- /main/kofacustom.dspg/trunk/src/kofacustom/dspg/interswitch/tests.py	(revision 14888)
+++ /main/kofacustom.dspg/trunk/src/kofacustom/dspg/interswitch/tests.py	(revision 14889)
@@ -24,4 +24,6 @@
 from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
 from waeup.kofa.configuration import SessionConfiguration
+from waeup.kofa.university.faculty import Faculty
+from waeup.kofa.university.department import Department
 from kofacustom.dspg.testing import FunctionalLayer
 
@@ -70,9 +72,5 @@
         self.value = ctrl.options[0]
         self.browser.getLink(self.value).click()
-        self.assertMatches('...Amount Authorized...',
-                           self.browser.contents)
-        self.assertMatches(
-            '...<span>30000.0</span>...',
-            self.browser.contents)
+        self.assertTrue('<span>30000.0</span>'  in self.browser.contents)
         self.payment_url = self.browser.url
         self.browser.getLink("CollegePAY", index=0).click()
@@ -143,4 +141,44 @@
         self.assertMatches('...Total Amount Authorized:...',
                            self.browser.contents)
+
+    def test_interswitch_form_pt_payments(self):
+        # Add SPAT certificate
+        certificate = createObject('waeup.Certificate')
+        certificate.code = u'CERT2'
+        certificate.application_category = 'basic' # can be anything
+        certificate.start_level = 100
+        certificate.end_level = 500
+        certificate.study_mode = u'ug_ft' # can be anything
+        self.app['faculties']['SPAT'] = Faculty(code=u'SPAT')
+        self.app['faculties']['SPAT']['dep2'] = Department(code=u'dep2')
+        department = self.app['faculties']['SPAT']['dep2']
+        self.app['faculties']['SPAT']['dep2'].certificates.addCertificate(
+            certificate)
+        certificate.school_fee_3 = 30000.0
+        self.student['studycourse'].certificate = certificate
+        # Manager can access InterswitchForm
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.payments_path)
+        IWorkflowState(self.student).setState('cleared')
+        self.student.nationality = u'NG'
+        # ND PT Non-Deltan Fresh Student School Fee
+        self.certificate.study_mode = 'nd_ft'
+        self.certificate.school_fee_3 = 30000.0
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['schoolfee']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...', self.browser.contents)
+        ctrl = self.browser.getControl(name='val_id')
+        self.value = ctrl.options[0]
+        self.browser.getLink(self.value).click()
+        self.assertTrue('<span>30000.0</span>'  in self.browser.contents)
+        self.payment_url = self.browser.url
+        self.browser.getLink("CollegePAY", index=0).click()
+        self.assertTrue('<item_detail item_id="1" item_name="School Fee 1" item_amt="1617000" bank_id="117" acct_num="1012808851" />'
+            in self.browser.contents)
+        self.assertTrue('<item_detail item_id="2" item_name="School Fee 2" item_amt="1078000" bank_id="123" acct_num="1002883141" />'
+            in self.browser.contents)
+        self.assertTrue('<item_detail item_id="3" item_name="BT Education" item_amt="280000" bank_id="8" acct_num="2028964403" />'
+            in self.browser.contents)
 
     @external_test
@@ -243,4 +281,7 @@
         self.browser.getControl(name="transition").value = ['start']
         self.browser.getControl("Save").click()
+
+
+    def test_interswitch_form(self):
         self.browser.getControl("Add online").click()
         self.assertMatches('...passport photo before making payment...',
@@ -263,18 +304,9 @@
         self.assertMatches('...Amount Authorized...',
                            self.browser.contents)
-        self.assertMatches(
-            '...<span>1000.0</span>...',
-            self.browser.contents)
-        self.payment_url = self.browser.url
-
-
-    def test_interswitch_form(self):
-        # Manager can access InterswitchForm
-        self.browser.getLink("CollegePAY", index=0).click()
-        self.assertMatches('...Total Amount Authorized:...',
-                           self.browser.contents)
-        self.assertMatches(
-            '...<input type="hidden" name="amount" value="100000" />...',
-            self.browser.contents)
+        self.assertTrue('span>1000.0</span>' in self.browser.contents)
+        self.payment_url = self.browser.url
+        self.browser.getLink("CollegePAY", index=0).click()
+        self.assertTrue('<input type="hidden" name="amount" value="100000" />'
+            in self.browser.contents)
         delta = timedelta(days=8)
         self.applicant.values()[0].creation_date -= delta
@@ -284,4 +316,16 @@
             '...This payment ticket is too old. Please create a new ticket...',
             self.browser.contents)
+        # ND PT Application Fee
+        self.applicantscontainer.application_category = 'ndpt'
+        self.certificate.application_category = 'ndpt'
+        self.browser.open(self.manage_path)
+        self.browser.getControl("Add online").click()
+        self.browser.getLink("CollegePAY", index=0).click()
+        self.assertTrue('<item_detail item_id="1" item_name="Application 1" item_amt="15000" bank_id="117" acct_num="1015220292" />'
+            in self.browser.contents)
+        self.assertTrue('<item_detail item_id="2" item_name="Application 2" item_amt="10000" bank_id="123" acct_num="1002883141" />'
+            in self.browser.contents)
+        self.assertTrue('<item_detail item_id="3" item_name="BT Education" item_amt="50000" bank_id="8" acct_num="2028964403" />'
+            in self.browser.contents)
 
     @external_test
