beginings of inter office(micro-bank) transfer functionality.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
-- create fund table
|
||||
DROP TABLE IF EXISTS `mifosngprovider`.`portfolio_office_funds_transfers`;
|
||||
CREATE TABLE `portfolio_office_funds_transfers` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`from_office_id` bigint(20) DEFAULT NULL,
|
||||
`to_office_id` bigint(20) DEFAULT NULL,
|
||||
`currency_code` varchar(3) NOT NULL,
|
||||
`currency_digits` int(11) NOT NULL,
|
||||
`transaction_amount` decimal(19,6) NOT NULL,
|
||||
`transaction_date` date NOT NULL,
|
||||
`created_date` datetime DEFAULT NULL,
|
||||
`createdby_id` bigint(20) DEFAULT NULL,
|
||||
`lastmodified_date` datetime DEFAULT NULL,
|
||||
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FK1E37728B93C6C1B6` (`to_office_id`),
|
||||
KEY `FK1E37728B783C5C25` (`from_office_id`),
|
||||
CONSTRAINT `FK1E37728B783C5C25` FOREIGN KEY (`from_office_id`) REFERENCES `org_office` (`id`),
|
||||
CONSTRAINT `FK1E37728B93C6C1B6` FOREIGN KEY (`to_office_id`) REFERENCES `org_office` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
@@ -16,6 +16,7 @@ import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||
import org.mifosng.platform.api.commands.OfficeCommand;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.api.data.OfficeData;
|
||||
@@ -125,4 +126,17 @@ public class OfficeApiResource {
|
||||
|
||||
return Response.ok().entity(new EntityIdentifier(entityId)).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{officeId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON})
|
||||
@Produces({ MediaType.APPLICATION_JSON})
|
||||
public Response transferMoney(@PathParam("officeId") final Long loanId,
|
||||
@QueryParam("command") final String commandParam,
|
||||
final BranchMoneyTransferCommand command) {
|
||||
|
||||
Long officeId = this.writePlatformService.transferMoney(command);
|
||||
|
||||
return Response.ok().entity(new EntityIdentifier(officeId)).build();
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package org.mifosng.platform.api.commands;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
/**
|
||||
* Command used for transfering money between two branches.
|
||||
*/
|
||||
@XmlRootElement
|
||||
public class BranchMoneyTransferCommand {
|
||||
|
||||
private Long id;
|
||||
private Long fromOfficeId;
|
||||
private Long toOfficeId;
|
||||
|
||||
private String dateFormat;
|
||||
private String transactionDate;
|
||||
private LocalDate transactionLocalDate;
|
||||
|
||||
private String locale;
|
||||
private String transactionAmount;
|
||||
private BigDecimal transactionAmountValue;
|
||||
|
||||
protected BranchMoneyTransferCommand() {
|
||||
//
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getFromOfficeId() {
|
||||
return fromOfficeId;
|
||||
}
|
||||
|
||||
public void setFromOfficeId(Long fromOfficeId) {
|
||||
this.fromOfficeId = fromOfficeId;
|
||||
}
|
||||
|
||||
public Long getToOfficeId() {
|
||||
return toOfficeId;
|
||||
}
|
||||
|
||||
public void setToOfficeId(Long toOfficeId) {
|
||||
this.toOfficeId = toOfficeId;
|
||||
}
|
||||
|
||||
public String getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
|
||||
public void setDateFormat(String dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
public String getTransactionDate() {
|
||||
return transactionDate;
|
||||
}
|
||||
|
||||
public void setTransactionDate(String transactionDate) {
|
||||
this.transactionDate = transactionDate;
|
||||
}
|
||||
|
||||
public LocalDate getTransactionLocalDate() {
|
||||
return transactionLocalDate;
|
||||
}
|
||||
|
||||
public void setTransactionLocalDate(LocalDate transactionLocalDate) {
|
||||
this.transactionLocalDate = transactionLocalDate;
|
||||
}
|
||||
|
||||
public String getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
public void setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public String getTransactionAmount() {
|
||||
return transactionAmount;
|
||||
}
|
||||
|
||||
public void setTransactionAmount(String transactionAmount) {
|
||||
this.transactionAmount = transactionAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getTransactionAmountValue() {
|
||||
return transactionAmountValue;
|
||||
}
|
||||
|
||||
public void setTransactionAmountValue(BigDecimal transactionAmountValue) {
|
||||
this.transactionAmountValue = transactionAmountValue;
|
||||
}
|
||||
}
|
||||
+4
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.organisation.service;
|
||||
|
||||
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||
import org.mifosng.platform.api.commands.OfficeCommand;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
@@ -10,4 +11,7 @@ public interface OfficeWritePlatformService {
|
||||
|
||||
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
|
||||
Long updateOffice(final OfficeCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')")
|
||||
Long transferMoney(BranchMoneyTransferCommand command);
|
||||
}
|
||||
+32
-1
@@ -2,13 +2,15 @@ package org.mifosng.platform.organisation.service;
|
||||
|
||||
import static org.mifosng.platform.Specifications.officesThatMatch;
|
||||
|
||||
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||
import org.mifosng.platform.api.commands.OfficeCommand;
|
||||
import org.mifosng.platform.currency.domain.MonetaryCurrency;
|
||||
import org.mifosng.platform.currency.domain.Money;
|
||||
import org.mifosng.platform.exceptions.NoAuthorizationException;
|
||||
import org.mifosng.platform.exceptions.OfficeNotFoundException;
|
||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||
import org.mifosng.platform.organisation.domain.Office;
|
||||
import org.mifosng.platform.organisation.domain.OfficeRepository;
|
||||
import org.mifosng.platform.organisation.service.OfficeCommandValidator;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
import org.mifosng.platform.user.domain.AppUser;
|
||||
import org.slf4j.Logger;
|
||||
@@ -87,6 +89,35 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP
|
||||
return Long.valueOf(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Long transferMoney(BranchMoneyTransferCommand command) {
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
Office fromOffice = this.officeRepository.findOne(command.getFromOfficeId());
|
||||
if (fromOffice == null) {
|
||||
throw new OfficeNotFoundException(command.getFromOfficeId());
|
||||
}
|
||||
|
||||
Office toOffice = this.officeRepository.findOne(command.getToOfficeId());
|
||||
if (toOffice == null) {
|
||||
throw new OfficeNotFoundException(command.getToOfficeId());
|
||||
}
|
||||
|
||||
MonetaryCurrency currency = new MonetaryCurrency("USD", 2);
|
||||
Money amount = Money.of(currency, command.getTransactionAmountValue());
|
||||
|
||||
OfficeFundsTransfer entity = OfficeFundsTransfer.create(currentUser.getOrganisation(), fromOffice, toOffice,
|
||||
|
||||
command.getTransactionDate(), amount);
|
||||
|
||||
this.officeFundsTransferRepository.save(entity);
|
||||
|
||||
return entity.getId();
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Guaranteed to throw an exception no matter what the data integrity issue is.
|
||||
|
||||
Reference in New Issue
Block a user