diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm
index 80ebad7ea..fd329efd9 100644
--- a/api-docs/apiLive.htm
+++ b/api-docs/apiLive.htm
@@ -711,7 +711,8 @@
| Journal Entries |
journalentries |
- Create Journal Entries |
+ Create Journal Entries
+ Update Journal Entries Running Balance |
List Journal Entries |
|
|
@@ -18734,6 +18735,27 @@ No Request Body:
| Denotes the accounting rule id for posting journal entries.
|
+
+
+ | officeRunningBalance |
+
+
+ | Describes office balance after the journal entry for the Ledger Account.
+ |
+
+
+ | organizationRunningBalance |
+
+
+ | Describes complete organization balances after the journal entry for the Ledger Account.
+ |
+
+
+ | runningBalanceComputed |
+
+
+ | Describes whether account balances computed for the journal entry.
+ |
@@ -18869,7 +18891,10 @@ GET https://DomainName/api/v1/journalentries?transactionId=PB37X8Y21EQUY4S
5
],
"createdByUserName": "mifos",
- "reversed": false
+ "reversed": false,
+ "officeRunningBalance":0,
+ "organizationRunningBalance":0
+ "runningBalanceComputed":false
},
{
"id": 2,
@@ -18909,7 +18934,11 @@ GET https://DomainName/api/v1/journalentries?transactionId=PB37X8Y21EQUY4S
5
],
"createdByUserName": "mifos",
- "reversed": false
+ "reversed": false,
+ "officeRunningBalance":0,
+ "organizationRunningBalance":0
+ "runningBalanceComputed":false
+
}
]
}
@@ -19100,6 +19129,46 @@ Request Body:
+
+
+
+
Update Running balances for Journal Entries
+
+ This API calculates the running balances for office. If office ID not provided this API calculates running balances for all offices.
+
+
+
+
+ Mandatory Fields |
+
+
+ | officeId
+ |
+
+
+
+
+
+POST https://DomainName/api/v1/journalentries?command=updateRunningBalance
+
+
+POST journalentries
+Content-Type: application/json
+Request Body:
+{
+"officeId": 1,
+}
+
+
+{
+ "officeId": 1,
+}
+
+
+
+
+
+
@@ -19149,7 +19218,11 @@ GET https://DomainName/api/v1/journalentries/{entryId}
2
],
"createdByUserName": "mifos",
- "reversed": false
+ "reversed": false,
+ "officeRunningBalance":0,
+ "organizationRunningBalance":0
+ "runningBalanceComputed":false
+
}
@@ -19797,7 +19870,8 @@ GET https://DomainName/api/v1/search?query=000000111
| Journal Entries |
journalentries |
- Create Journal Entries |
+ Create Journal Entries
+ Update Journal Entries Running Balance |
List Journal Entries |
|
|
diff --git a/mifosng-db/migrations/core_db/V121__accounting_running_balance_for_organization.sql b/mifosng-db/migrations/core_db/V121__accounting_running_balance_for_organization.sql
new file mode 100755
index 000000000..71aa9eaac
--- /dev/null
+++ b/mifosng-db/migrations/core_db/V121__accounting_running_balance_for_organization.sql
@@ -0,0 +1,4 @@
+ALTER TABLE `acc_gl_journal_entry`
+ ADD COLUMN `organization_running_balance` DECIMAL(19,6) NOT NULL DEFAULT '0.000000' AFTER `office_running_balance`;
+
+INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('accounting', 'UPDATERUNNINGBALANCE_JOURNALENTRY', 'JOURNALENTRY', 'UPDATERUNNINGBALANCE', 0);
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/api/JournalEntriesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/api/JournalEntriesApiResource.java
index 2dd5abff7..2cc803a8c 100755
--- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/api/JournalEntriesApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/api/JournalEntriesApiResource.java
@@ -116,12 +116,17 @@ public class JournalEntriesApiResource {
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
- public String createGLJournalEntry(final String jsonRequestBody) {
-
- final CommandWrapper commandRequest = new CommandWrapperBuilder().createJournalEntry().withJson(jsonRequestBody).build();
-
- final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
+ public String createGLJournalEntry(final String jsonRequestBody, @QueryParam("command") final String commandParam) {
+ CommandProcessingResult result = null;
+ if (is(commandParam, "updateRunningBalance")) {
+ final CommandWrapper commandRequest = new CommandWrapperBuilder().updateRunningBalanceForJournalEntry()
+ .withJson(jsonRequestBody).build();
+ result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
+ } else {
+ final CommandWrapper commandRequest = new CommandWrapperBuilder().createJournalEntry().withJson(jsonRequestBody).build();
+ result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
+ }
return this.apiJsonSerializerService.serialize(result);
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryData.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryData.java
index 8ae533e9f..37ddd242d 100755
--- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryData.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryData.java
@@ -12,14 +12,13 @@ import org.mifosplatform.infrastructure.core.data.EnumOptionData;
/**
* Immutable object representing a General Ledger Account
- *
+ *
* Note: no getter/setters required as google will produce json from fields of
* object.
*/
public class JournalEntryData {
private final Long id;
- @SuppressWarnings("unused")
private final Long officeId;
@SuppressWarnings("unused")
private final String officeName;
@@ -53,13 +52,20 @@ public class JournalEntryData {
private final Boolean reversed;
@SuppressWarnings("unused")
private final String referenceNumber;
+ @SuppressWarnings("unused")
+ private final BigDecimal officeRunningBalance;
+ @SuppressWarnings("unused")
+ private final BigDecimal organizationRunningBalance;
+ @SuppressWarnings("unused")
+ private final Boolean runningBalanceComputed;
public JournalEntryData(final Long id, final Long officeId, final String officeName, final String glAccountName,
final Long glAccountId, final String glAccountCode, final EnumOptionData glAccountClassification,
final LocalDate transactionDate, final EnumOptionData entryType, final BigDecimal amount, final String transactionId,
final Boolean manualEntry, final EnumOptionData entityType, final Long entityId, final Long createdByUserId,
final LocalDate createdDate, final String createdByUserName, final String comments, final Boolean reversed,
- final String referenceNumber) {
+ final String referenceNumber, final BigDecimal officeRunningBalance, final BigDecimal organizationRunningBalance,
+ final Boolean runningBalanceComputed) {
this.id = id;
this.officeId = officeId;
this.officeName = officeName;
@@ -80,22 +86,22 @@ public class JournalEntryData {
this.comments = comments;
this.reversed = reversed;
this.referenceNumber = referenceNumber;
+ this.officeRunningBalance = officeRunningBalance;
+ this.organizationRunningBalance = organizationRunningBalance;
+ this.runningBalanceComputed = runningBalanceComputed;
}
+ public Long getId() {
+ return this.id;
+ }
- public Long getId() {
- return this.id;
- }
+ public Long getGlAccountId() {
+ return this.glAccountId;
+ }
-
- public Long getGlAccountId() {
- return this.glAccountId;
- }
-
-
- public EnumOptionData getGlAccountType() {
- return this.glAccountType;
- }
+ public EnumOptionData getGlAccountType() {
+ return this.glAccountType;
+ }
public BigDecimal getAmount() {
return this.amount;
@@ -104,4 +110,8 @@ public class JournalEntryData {
public EnumOptionData getEntryType() {
return this.entryType;
}
+
+ public Long getOfficeId() {
+ return this.officeId;
+ }
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryDataValidator.java
new file mode 100755
index 000000000..f6583fff7
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/journalentry/data/JournalEntryDataValidator.java
@@ -0,0 +1,51 @@
+package org.mifosplatform.accounting.journalentry.data;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.mifosplatform.accounting.journalentry.api.JournalEntryJsonInputParams;
+import org.mifosplatform.infrastructure.core.api.JsonCommand;
+import org.mifosplatform.infrastructure.core.data.ApiParameterError;
+import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
+import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
+import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.reflect.TypeToken;
+
+@Component
+public class JournalEntryDataValidator {
+
+ private final FromJsonHelper fromApiJsonHelper;
+
+ public static final Set RUNNING_BALANCE_UPDATE_REQUEST_DATA_PARAMETERS = new HashSet(
+ Arrays.asList(JournalEntryJsonInputParams.OFFICE_ID.getValue()));
+
+ @Autowired
+ public JournalEntryDataValidator(final FromJsonHelper fromApiJsonHelper) {
+ this.fromApiJsonHelper = fromApiJsonHelper;
+ }
+
+ public void validateForUpdateRunningbalance(final JsonCommand command) {
+ final Type typeOfMap = new TypeToken