Merge branch develop of upstream

This commit is contained in:
Mohammed Nafees
2014-12-03 22:21:30 +05:30
3 changed files with 34 additions and 4 deletions
+9
View File
@@ -31154,6 +31154,15 @@ GET https://DomainName/api/v1/journalentries/{entryId}
</dd>
<dd>'reverse' : Reverse the Journal Entry</dd>
</dl>
<h5>Optional Arguments</h5>
<dl class="argument-list">
<dt>comments</dt>
<dd>
String <span>optional</span>
</dd>
<dd>Optional string to be applied as a comment for the created reversal entry,
default comment is used if this field is not supplied</dd>
</dl>
</div>
<div class="method-example">
<code class="method-declaration">
@@ -142,11 +142,12 @@ public class JournalEntriesApiResource {
@Path("{transactionId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String createReversalJournalEntry(@PathParam("transactionId") final String transactionId,
public String createReversalJournalEntry(final String jsonRequestBody,
@PathParam("transactionId") final String transactionId,
@QueryParam("command") final String commandParam) {
CommandProcessingResult result = null;
if (is(commandParam, "reverse")) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().reverseJournalEntry(transactionId).build();
final CommandWrapper commandRequest = new CommandWrapperBuilder().reverseJournalEntry(transactionId).withJson(jsonRequestBody).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
} else {
throw new UnrecognizedQueryParamException("command", commandParam);
@@ -37,8 +37,11 @@ import org.mifosplatform.accounting.rule.domain.AccountingRule;
import org.mifosplatform.accounting.rule.domain.AccountingRuleRepository;
import org.mifosplatform.accounting.rule.exception.AccountingRuleNotFoundException;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.organisation.office.domain.Office;
@@ -279,11 +282,17 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
final Long officeId = journalEntries.get(0).getOffice().getId();
final String reversalTransactionId = generateTransactionId(officeId);
final boolean manualEntry = true;
String reversalComment = command.stringValueOfParameterNamed("comments");
final boolean useDefaultComment = StringUtils.isBlank(reversalComment);
validateCommentForReversal(reversalComment);
for (final JournalEntry journalEntry : journalEntries) {
JournalEntry reversalJournalEntry;
final String reversalComment = "Reversal entry for Journal Entry with Entry Id :" + journalEntry.getId()
+ " and transaction Id " + command.getTransactionId();
if (useDefaultComment) {
reversalComment = "Reversal entry for Journal Entry with Entry Id :" + journalEntry.getId()
+ " and transaction Id " + command.getTransactionId();
}
if (journalEntry.isDebitEntry()) {
reversalJournalEntry = JournalEntry.createNew(journalEntry.getOffice(), journalEntry.getPaymentDetails(),
journalEntry.getGlAccount(), journalEntry.getCurrencyCode(), reversalTransactionId, manualEntry,
@@ -305,6 +314,17 @@ public class JournalEntryWritePlatformServiceJpaRepositoryImpl implements Journa
return new CommandProcessingResultBuilder().withTransactionId(reversalTransactionId).build();
}
private void validateCommentForReversal(final String reversalComment) {
final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("GLJournalEntry");
baseDataValidator.reset().parameter("comments").value(reversalComment).notExceedingLengthOf(500);
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
@Transactional
@Override
public void createJournalEntriesForLoan(final Map<String, Object> accountingBridgeData) {