Merge branch 'develop' of https://github.com/mifosio/demo-server into develop
diff --git a/build.gradle b/build.gradle
index 75e1ac8..da39c3e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -32,6 +32,8 @@
         mifosdeposit            : '0.1.0-BUILD-SNAPSHOT',
         mifosteller             : '0.1.0-BUILD-SNAPSHOT',
         mifosreporting          : '0.1.0-BUILD-SNAPSHOT',
+        kuelapcheques           : '0.1.0-BUILD-SNAPSHOT',
+        mifospayroll            : '0.1.0-BUILD-SNAPSHOT',
         frameworkapi            : '0.1.0-BUILD-SNAPSHOT',
         frameworklang           : '0.1.0-BUILD-SNAPSHOT',
         frameworktest           : '0.1.0-BUILD-SNAPSHOT',
@@ -86,6 +88,8 @@
             [group: 'io.mifos.deposit-account-management', name: 'api', version: versions.mifosdeposit],
             [group: 'io.mifos.teller', name: 'api', version: versions.mifosteller],
             [group: 'io.mifos.reporting', name: 'api', version: versions.mifosreporting],
+            [group: 'io.mifos.cheques', name: 'api', version: versions.kuelapcheques],
+            [group: 'io.mifos.payroll', name: 'api', version: versions.mifospayroll],
 
             [group: 'io.mifos.anubis', name: 'api', version: versions.frameworkanubis],
             [group: 'io.mifos.anubis', name: 'test', version: versions.frameworkanubis],
diff --git a/scripts/Unix/initial-setup.sh b/scripts/Unix/initial-setup.sh
index 75ce49e..0c9cd15 100755
--- a/scripts/Unix/initial-setup.sh
+++ b/scripts/Unix/initial-setup.sh
@@ -48,6 +48,16 @@
 
 get_modules anubis permitted-feign-client provisioner identity rhythm template office customer group accounting portfolio deposit-account-management teller reporting
 
+# REM initialize payroll
+git clone 'https://github.com/'$githubAccount'/payroll.git'
+cd payroll
+git remote add upstream https://github.com/mifosio/payroll.git
+git checkout develop
+chmod +x gradlew
+./gradlew publishToMavenLocal
+
+cd ..
+
 mkdir integration-tests
 cd integration-tests
 
diff --git a/scripts/Unix/pull-all.sh b/scripts/Unix/pull-all.sh
index 888884e..e28fc17 100644
--- a/scripts/Unix/pull-all.sh
+++ b/scripts/Unix/pull-all.sh
@@ -217,6 +217,15 @@
 git push origin develop 
 cd ..
 
+# REM pull payroll
+cd payroll
+git checkout develop
+git pull upstream develop
+chmod +x gradlew
+./gradlew publishToMavenLocal
+git push origin develop
+cd ..
+
 cd integration-tests
 
 # REM pull service-starter
diff --git a/scripts/windows/initial-setup.bat b/scripts/windows/initial-setup.bat
index 3d1c727..70ef91b 100644
--- a/scripts/windows/initial-setup.bat
+++ b/scripts/windows/initial-setup.bat
@@ -230,6 +230,15 @@
 TIMEOUT /T 5
 cd ..
 
+REM initialze payroll
+git clone https://github.com/%githubAccount%/payroll.git
+cd payroll
+git remote add upstream https://github.com/mifosio/payroll.git
+git checkout develop
+CALL gradlew publishToMavenLocal
+TIMEOUT /T 5
+cd ..
+
 mkdir integration-tests
 cd integration-tests
 
diff --git a/scripts/windows/pull-all.bat b/scripts/windows/pull-all.bat
index d6475a5..f2597b6 100644
--- a/scripts/windows/pull-all.bat
+++ b/scripts/windows/pull-all.bat
@@ -215,6 +215,15 @@
 TIMEOUT /T 5
 cd ..
 
+REM pull payroll
+cd payroll
+git checkout develop
+git pull upstream develop
+CALL gradlew publishToMavenLocal
+git push origin develop
+TIMEOUT /T 5
+cd ..
+
 cd integration-tests
 
 REM pull service-starter
diff --git a/src/main/java/io/mifos/dev/ServiceRunner.java b/src/main/java/io/mifos/dev/ServiceRunner.java
index a093c49..5e60a42 100644
--- a/src/main/java/io/mifos/dev/ServiceRunner.java
+++ b/src/main/java/io/mifos/dev/ServiceRunner.java
@@ -21,6 +21,7 @@
 import io.mifos.accounting.importer.AccountImporter;
 import io.mifos.accounting.importer.LedgerImporter;
 import io.mifos.anubis.api.v1.domain.AllowedOperation;
+import io.mifos.cheque.api.v1.client.ChequeManager;
 import io.mifos.core.api.config.EnableApiFactory;
 import io.mifos.core.api.context.AutoGuest;
 import io.mifos.core.api.context.AutoSeshat;
@@ -47,6 +48,7 @@
 import io.mifos.identity.api.v1.events.ApplicationSignatureEvent;
 import io.mifos.identity.api.v1.events.EventConstants;
 import io.mifos.office.api.v1.client.OrganizationManager;
+import io.mifos.payroll.api.v1.client.PayrollManager;
 import io.mifos.portfolio.api.v1.client.PortfolioManager;
 import io.mifos.provisioner.api.v1.client.Provisioner;
 import io.mifos.provisioner.api.v1.domain.*;
@@ -102,6 +104,8 @@
   private static Microservice<DepositAccountManager> depositAccountManager;
   private static Microservice<TellerManager> tellerManager;
   private static Microservice<ReportManager> reportManager;
+  private static Microservice<ChequeManager> chequeManager;
+  private static Microservice<PayrollManager> payrollManager;
 
 
   private static DB embeddedMariaDb;
@@ -209,7 +213,8 @@
 
     ServiceRunner.portfolioManager = new Microservice<>(PortfolioManager.class, "portfolio", "0.1.0-BUILD-SNAPSHOT", ServiceRunner.INTEGRATION_TEST_ENVIRONMENT)
             .addProperties(new ExtraProperties() {{
-              setProperty("portfolio.bookInterestAsUser", SCHEDULER_USER_NAME);}});
+              setProperty("portfolio.bookLateFeesAndInterestAsUser", SCHEDULER_USER_NAME);
+            }});
     startService(generalProperties, portfolioManager);
 
     ServiceRunner.depositAccountManager = new Microservice<>(DepositAccountManager.class, "deposit-account-management", "0.1.0-BUILD-SNAPSHOT", ServiceRunner.INTEGRATION_TEST_ENVIRONMENT);
@@ -220,10 +225,18 @@
 
     ServiceRunner.reportManager = new Microservice<>(ReportManager.class, "reporting", "0.1.0-BUILD-SNAPSHOT", ServiceRunner.INTEGRATION_TEST_ENVIRONMENT);
     startService(generalProperties, ServiceRunner.reportManager);
+
+    ServiceRunner.chequeManager = new Microservice<>(ChequeManager.class, "cheques", "0.1.0-BUILD-SNAPSHOT", ServiceRunner.INTEGRATION_TEST_ENVIRONMENT);
+    startService(generalProperties, ServiceRunner.chequeManager);
+
+    ServiceRunner.payrollManager = new Microservice<>(PayrollManager.class, "payroll", "0.1.0-BUILD-SNAPSHOT", ServiceRunner.INTEGRATION_TEST_ENVIRONMENT);
+    startService(generalProperties, ServiceRunner.payrollManager);
   }
 
   @After
   public void tearDown() throws Exception {
+    ServiceRunner.payrollManager.kill();
+    ServiceRunner.chequeManager.kill();
     ServiceRunner.reportManager.kill();
     ServiceRunner.tellerManager.kill();
     ServiceRunner.depositAccountManager.kill();
@@ -261,6 +274,8 @@
     System.out.println("Deposit Service: " + ServiceRunner.depositAccountManager.getProcessEnvironment().serverURI());
     System.out.println("Teller Service: " + ServiceRunner.tellerManager.getProcessEnvironment().serverURI());
     System.out.println("Reporting Service: " + ServiceRunner.reportManager.getProcessEnvironment().serverURI());
+    System.out.println("Cheque Service: " + ServiceRunner.chequeManager.getProcessEnvironment().serverURI());
+    System.out.println("Payroll Service: " + ServiceRunner.payrollManager.getProcessEnvironment().serverURI());
 
     boolean run = true;
 
@@ -321,7 +336,9 @@
             ApplicationBuilder.create(ServiceRunner.portfolioManager.name(), ServiceRunner.portfolioManager.uri()),
             ApplicationBuilder.create(ServiceRunner.depositAccountManager.name(), ServiceRunner.depositAccountManager.uri()),
             ApplicationBuilder.create(ServiceRunner.tellerManager.name(), ServiceRunner.tellerManager.uri()),
-            ApplicationBuilder.create(ServiceRunner.reportManager.name(), ServiceRunner.reportManager.uri())
+            ApplicationBuilder.create(ServiceRunner.reportManager.name(), ServiceRunner.reportManager.uri()),
+            ApplicationBuilder.create(ServiceRunner.chequeManager.name(), ServiceRunner.chequeManager.uri()),
+            ApplicationBuilder.create(ServiceRunner.payrollManager.name(), ServiceRunner.payrollManager.uri())
     );
 
     final List<Tenant> tenantsToCreate = Arrays.asList(
@@ -420,6 +437,10 @@
 
       provisionApp(tenant, ServiceRunner.reportManager, io.mifos.reporting.api.v1.EventConstants.INITIALIZE);
 
+      provisionApp(tenant, ServiceRunner.chequeManager, io.mifos.cheque.api.v1.EventConstants.INITIALIZE);
+
+      provisionApp(tenant, ServiceRunner.payrollManager, io.mifos.payroll.api.v1.EventConstants.INITIALIZE);
+
       final UserWithPassword orgAdminUserPassword = createOrgAdminRoleAndUser(tenantAdminPassword.getAdminPassword());
 
       createChartOfAccounts(orgAdminUserPassword);
diff --git a/src/main/java/io/mifos/dev/listener/ChequesListener.java b/src/main/java/io/mifos/dev/listener/ChequesListener.java
new file mode 100644
index 0000000..908454b
--- /dev/null
+++ b/src/main/java/io/mifos/dev/listener/ChequesListener.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016 The Mifos Initiative.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.mifos.dev.listener;
+
+import io.mifos.cheque.api.v1.EventConstants;
+import io.mifos.core.lang.config.TenantHeaderFilter;
+import io.mifos.core.test.listener.EventRecorder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jms.annotation.JmsListener;
+import org.springframework.messaging.handler.annotation.Header;
+import org.springframework.stereotype.Component;
+
+@SuppressWarnings("unused")
+@Component
+public class ChequesListener {
+
+  private final EventRecorder eventRecorder;
+
+  @Autowired
+  public ChequesListener(final EventRecorder eventRecorder) {
+    this.eventRecorder = eventRecorder;
+  }
+
+  @JmsListener(
+          subscription = EventConstants.DESTINATION,
+          destination = EventConstants.DESTINATION,
+          selector = EventConstants.SELECTOR_INITIALIZE
+  )
+  public void onInitialized(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
+                            final String payload) {
+    this.eventRecorder.event(tenant, EventConstants.INITIALIZE, payload, String.class);
+  }
+}
+
diff --git a/src/main/java/io/mifos/dev/listener/PayrollListener.java b/src/main/java/io/mifos/dev/listener/PayrollListener.java
new file mode 100644
index 0000000..a9174b5
--- /dev/null
+++ b/src/main/java/io/mifos/dev/listener/PayrollListener.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016 The Mifos Initiative.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.mifos.dev.listener;
+
+import io.mifos.core.lang.config.TenantHeaderFilter;
+import io.mifos.core.test.listener.EventRecorder;
+import io.mifos.payroll.api.v1.EventConstants;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jms.annotation.JmsListener;
+import org.springframework.messaging.handler.annotation.Header;
+import org.springframework.stereotype.Component;
+
+@SuppressWarnings("unused")
+@Component
+public class PayrollListener {
+  private final EventRecorder eventRecorder;
+
+  @Autowired
+  public PayrollListener(final EventRecorder eventRecorder) {
+    this.eventRecorder = eventRecorder;
+  }
+
+  @JmsListener(
+          subscription = EventConstants.DESTINATION,
+          destination = EventConstants.DESTINATION,
+          selector = EventConstants.SELECTOR_INITIALIZE
+  )
+  public void onInitialized(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
+                            final String payload) {
+    this.eventRecorder.event(tenant, EventConstants.INITIALIZE, payload, String.class);
+  }
+}