MIFOSX-41: Update Infrastructure for fees, charges and penalties.
This commit is contained in:
@@ -17,7 +17,9 @@ import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Path("/charges")
|
||||
@@ -64,6 +66,28 @@ public class ChargesApiResource {
|
||||
return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, charge);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("template")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveNewChargeDetails(@Context final UriInfo uriInfo) {
|
||||
|
||||
Set<String> typicalResponseParameters = new HashSet<String>(
|
||||
Arrays.asList("name", "amount", "currency", "currencyOptions", "chargeAppliesTo", "chargeTimeType",
|
||||
"chargeCalculationType", "chargeCalculationTypeOptions", "active")
|
||||
);
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
ChargeData chargeData = this.chargeReadPlatformService.retrieveNewChargeDetails();
|
||||
|
||||
return this.apiJsonSerializerService.serializeChargeDataToJson(prettyPrint, responseParameters, chargeData);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
|
||||
+54
-1
@@ -8,14 +8,27 @@ public class ChargeCommand {
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final BigDecimal amount;
|
||||
private final String currencyCode;
|
||||
|
||||
private final Integer chargeTimeType;
|
||||
private final Integer chargeAppliesTo;
|
||||
private final Integer chargeCalculationType;
|
||||
|
||||
private final boolean active;
|
||||
|
||||
private final Set<String> modifiedParameters;
|
||||
|
||||
public ChargeCommand(Set<String> modifiedParameters, Long id, String name, BigDecimal amount) {
|
||||
public ChargeCommand(Set<String> modifiedParameters, Long id, String name, BigDecimal amount, String currencyCode,
|
||||
Integer chargeTimeType, Integer chargeAppliesTo, Integer chargeCalculationType, boolean active) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
this.currencyCode = currencyCode;
|
||||
this.chargeTimeType = chargeTimeType;
|
||||
this.chargeAppliesTo = chargeAppliesTo;
|
||||
this.chargeCalculationType = chargeCalculationType;
|
||||
this.modifiedParameters = modifiedParameters;
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@@ -34,6 +47,26 @@ public class ChargeCommand {
|
||||
return modifiedParameters;
|
||||
}
|
||||
|
||||
public String getCurrencyCode() {
|
||||
return currencyCode;
|
||||
}
|
||||
|
||||
public Integer getChargeCalculationType() {
|
||||
return chargeCalculationType;
|
||||
}
|
||||
|
||||
public Integer getChargeAppliesTo() {
|
||||
return chargeAppliesTo;
|
||||
}
|
||||
|
||||
public Integer getChargeTimeType() {
|
||||
return chargeTimeType;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public boolean isNameChanged(){
|
||||
return this.modifiedParameters.contains("name");
|
||||
}
|
||||
@@ -41,4 +74,24 @@ public class ChargeCommand {
|
||||
public boolean isAmountChanged(){
|
||||
return this.modifiedParameters.contains("amount");
|
||||
}
|
||||
|
||||
public boolean isCurrencyCodeChanged(){
|
||||
return this.modifiedParameters.contains("currencyCode");
|
||||
}
|
||||
|
||||
public boolean isChargeTimeTypeChanged(){
|
||||
return this.modifiedParameters.contains("chargeTimeType");
|
||||
}
|
||||
|
||||
public boolean isChargeAppliesToChanged(){
|
||||
return this.modifiedParameters.contains("chargeAppliesTo");
|
||||
}
|
||||
|
||||
public boolean isChargeCalculationTypeChanged(){
|
||||
return this.modifiedParameters.contains("chargeCalculationType");
|
||||
}
|
||||
|
||||
public boolean isActiveChanged(){
|
||||
return this.modifiedParameters.contains("active");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,40 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
public class ChargeData {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private BigDecimal amount;
|
||||
private String currencyCode;
|
||||
private EnumOptionData chargeTimeType;
|
||||
private EnumOptionData chargeAppliesTo;
|
||||
private EnumOptionData chargeCalculationType;
|
||||
|
||||
public ChargeData(Long id, String name, BigDecimal amount) {
|
||||
private boolean active;
|
||||
|
||||
private List<CurrencyData> currencyOptions;
|
||||
private List<EnumOptionData> chargeCalculationTypeOptions;
|
||||
|
||||
public ChargeData(Long id, String name, BigDecimal amount, String currencyCode, EnumOptionData chargeTimeType,
|
||||
EnumOptionData chargeAppliesTo, EnumOptionData chargeCalculationType, boolean active) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
this.currencyCode = currencyCode;
|
||||
this.chargeTimeType = chargeTimeType;
|
||||
this.chargeAppliesTo = chargeAppliesTo;
|
||||
this.chargeCalculationType = chargeCalculationType;
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public ChargeData(EnumOptionData chargeTimeType, EnumOptionData chargeAppliesTo, List<CurrencyData> currencyOptions, List<EnumOptionData> chargeCalculationTypeOptions) {
|
||||
this.chargeTimeType = chargeTimeType;
|
||||
this.chargeAppliesTo = chargeAppliesTo;
|
||||
this.currencyOptions = currencyOptions;
|
||||
this.chargeCalculationTypeOptions = chargeCalculationTypeOptions;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@@ -37,4 +60,8 @@ public class ChargeData {
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-4
@@ -69,9 +69,10 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(
|
||||
Arrays.asList("name", "amount", "locale")
|
||||
);
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("name", "amount", "locale", "currencyCode",
|
||||
"currencyOptions", "chargeAppliesTo", "chargeTimeType",
|
||||
"chargeCalculationType", "chargeCalculationTypeOptions", "active"
|
||||
));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
@@ -79,8 +80,16 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
|
||||
String name = extractStringParameter("name", requestMap, modifiedParameters);
|
||||
BigDecimal amount = extractBigDecimalParameter("amount", requestMap, modifiedParameters);
|
||||
String currencyCode = extractStringParameter("currencyCode", requestMap, modifiedParameters);
|
||||
|
||||
return new ChargeCommand(modifiedParameters, resourceIdentifier, name, amount);
|
||||
Integer chargeTimeType = extractIntegerParameter("chargeTimeType", requestMap, modifiedParameters);
|
||||
Integer chargeAppliesTo = extractIntegerParameter("chargeAppliesTo", requestMap, modifiedParameters);
|
||||
Integer chargeCalculationType = extractIntegerParameter("chargeCalculationType", requestMap, modifiedParameters);
|
||||
|
||||
boolean active = extractBooleanParameter("active", requestMap, modifiedParameters);
|
||||
|
||||
return new ChargeCommand(modifiedParameters, resourceIdentifier, name, amount,
|
||||
currencyCode, chargeTimeType, chargeAppliesTo, chargeCalculationType, active);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-1
@@ -121,7 +121,10 @@ public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerServ
|
||||
Arrays.asList("id", "transactionType", "date", "principal", "interest", "total", "totalWaived", "overpaid")
|
||||
);
|
||||
|
||||
private static final Set<String> CHARGES_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "amount"));
|
||||
private static final Set<String> CHARGES_DATA_PARAMETERS = new HashSet<String>(
|
||||
Arrays.asList("id", "name", "amount", "currencyCode", "currencyOptions", "chargeAppliesTo", "chargeTimeType",
|
||||
"chargeCalculationType", "active")
|
||||
);
|
||||
|
||||
private final GoogleGsonSerializerHelper helper;
|
||||
|
||||
|
||||
@@ -4,10 +4,7 @@ import org.mifosng.platform.api.commands.ChargeCommand;
|
||||
import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
|
||||
import org.mifosng.platform.user.domain.AppUser;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import javax.persistence.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Entity
|
||||
@@ -22,21 +19,52 @@ public class Charge extends AbstractAuditableCustom<AppUser, Long> {
|
||||
@Column(name = "amount", scale = 6, precision = 19, nullable = false)
|
||||
private BigDecimal amount;
|
||||
|
||||
@Column(name = "currency_code", length=3)
|
||||
private String currencyCode;
|
||||
|
||||
@Enumerated(EnumType.ORDINAL)
|
||||
@Column(name = "charge_applies_to_enum", nullable = false)
|
||||
private ChargeAppliesTo chargeAppliesTo;
|
||||
|
||||
@Enumerated(EnumType.ORDINAL)
|
||||
@Column(name = "charge_time_enum", nullable = false)
|
||||
private ChargeTimeType chargeTime;
|
||||
|
||||
@Enumerated(EnumType.ORDINAL)
|
||||
@Column(name = "charge_calculation_enum")
|
||||
private ChargeCalculationMethod chargeCalculationMethod;
|
||||
|
||||
@Column(name = "is_active", nullable = false)
|
||||
private boolean active;
|
||||
|
||||
@Column(name = "is_deleted", nullable=false)
|
||||
private boolean deleted = false;
|
||||
|
||||
public static Charge createNew(String name, BigDecimal amount){
|
||||
return new Charge(name, amount);
|
||||
public static Charge createNew(String name, BigDecimal amount, String currencyCode, ChargeAppliesTo chargeAppliesTo,
|
||||
ChargeTimeType chargeTime, ChargeCalculationMethod chargeCalculationMethod, boolean active){
|
||||
return new Charge(name, amount, currencyCode, chargeAppliesTo, chargeTime, chargeCalculationMethod, active);
|
||||
}
|
||||
|
||||
public Charge() {
|
||||
this.name = null;
|
||||
this.amount = null;
|
||||
this.currencyCode = null;
|
||||
this.chargeAppliesTo = null;
|
||||
this.chargeTime = null;
|
||||
this.chargeCalculationMethod = null;
|
||||
|
||||
this.active = false;
|
||||
}
|
||||
|
||||
public Charge(String name, BigDecimal amount) {
|
||||
public Charge(String name, BigDecimal amount, String currencyCode, ChargeAppliesTo chargeAppliesTo,
|
||||
ChargeTimeType chargeTime, ChargeCalculationMethod chargeCalculationMethod, boolean active) {
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
this.currencyCode = currencyCode;
|
||||
this.chargeAppliesTo = chargeAppliesTo;
|
||||
this.chargeTime = chargeTime;
|
||||
this.chargeCalculationMethod = chargeCalculationMethod;
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -59,6 +87,26 @@ public class Charge extends AbstractAuditableCustom<AppUser, Long> {
|
||||
if (command.isAmountChanged()) {
|
||||
this.amount = command.getAmount();
|
||||
}
|
||||
|
||||
if (command.isCurrencyCodeChanged()){
|
||||
this.currencyCode = command.getCurrencyCode();
|
||||
}
|
||||
|
||||
if (command.isChargeTimeTypeChanged()){
|
||||
this.chargeTime = ChargeTimeType.fromInt(command.getChargeTimeType());
|
||||
}
|
||||
|
||||
if (command.isChargeAppliesToChanged()){
|
||||
this.chargeAppliesTo = ChargeAppliesTo.fromInt(command.getChargeAppliesTo());
|
||||
}
|
||||
|
||||
if (command.isChargeCalculationTypeChanged()){
|
||||
this.chargeCalculationMethod = ChargeCalculationMethod.fromInt(command.getChargeCalculationType());
|
||||
}
|
||||
|
||||
if (command.isActiveChanged()){
|
||||
this.active = command.isActive();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package org.mifosng.platform.charge.domain;
|
||||
|
||||
public enum ChargeAppliesTo {
|
||||
LOAN(0, "chargeAppliesTo.loan"),
|
||||
INVALID(1, "chargeAppliesTo.invalid");
|
||||
|
||||
private final Integer value;
|
||||
private final String code;
|
||||
|
||||
private ChargeAppliesTo(Integer value, String code) {
|
||||
this.value = value;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static ChargeAppliesTo fromInt(final Integer chargeAppliesTo){
|
||||
ChargeAppliesTo chargeAppliesToType = null;
|
||||
switch(chargeAppliesTo){
|
||||
case 0:
|
||||
chargeAppliesToType = LOAN;
|
||||
break;
|
||||
default:
|
||||
chargeAppliesToType = INVALID;
|
||||
break;
|
||||
}
|
||||
return chargeAppliesToType;
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package org.mifosng.platform.charge.domain;
|
||||
|
||||
public enum ChargeCalculationMethod {
|
||||
FLAT(0, "chargeCalculationType.flat"),
|
||||
PERCENT_OF_AMOUNT(1, "chargeCalculationType.percent.of.amount"),
|
||||
PERCENT_OF_AMOUNT_AND_INTEREST(2, "chargeCalculationType.percent.of.amount.and.interest"),
|
||||
PERCENT_OF_INTEREST(3, "chargeCalculationType.percent.of.interest"),
|
||||
INVALID(4, "chargeCalculationType.invalid");
|
||||
|
||||
private final Integer value;
|
||||
private final String code;
|
||||
|
||||
private ChargeCalculationMethod(Integer value, String code) {
|
||||
this.value = value;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static ChargeCalculationMethod fromInt(final Integer chargeCalculation){
|
||||
ChargeCalculationMethod chargeCalculationMethod = null;
|
||||
switch(chargeCalculation){
|
||||
case 0:
|
||||
chargeCalculationMethod = FLAT;
|
||||
break;
|
||||
case 1:
|
||||
chargeCalculationMethod = PERCENT_OF_AMOUNT;
|
||||
break;
|
||||
case 2:
|
||||
chargeCalculationMethod = PERCENT_OF_AMOUNT_AND_INTEREST;
|
||||
break;
|
||||
case 3:
|
||||
chargeCalculationMethod = PERCENT_OF_INTEREST;
|
||||
break;
|
||||
default:
|
||||
chargeCalculationMethod = INVALID;
|
||||
break;
|
||||
}
|
||||
return chargeCalculationMethod;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.mifosng.platform.charge.domain;
|
||||
|
||||
public enum ChargeTimeType {
|
||||
DISBURSEMENT(0, "chargeTimeType.disbursement"),
|
||||
INVALID(1, "chargeTimeType.invalid");
|
||||
|
||||
private final Integer value;
|
||||
private final String code;
|
||||
|
||||
private ChargeTimeType(Integer value, String code) {
|
||||
this.value = value;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static ChargeTimeType fromInt(final Integer chargeTime) {
|
||||
ChargeTimeType chargeTimeType = null;
|
||||
switch(chargeTime){
|
||||
case 0:
|
||||
chargeTimeType = DISBURSEMENT;
|
||||
break;
|
||||
default:
|
||||
chargeTimeType = INVALID;
|
||||
break;
|
||||
}
|
||||
return chargeTimeType;
|
||||
}
|
||||
}
|
||||
+8
@@ -23,6 +23,10 @@ public class ChargeCommandValidator {
|
||||
|
||||
baseDataValidator.reset().parameter("name").value(command.getName()).notBlank().notExceedingLengthOf(100);
|
||||
baseDataValidator.reset().parameter("amount").value(command.getAmount()).notNull().positiveAmount();
|
||||
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank();
|
||||
baseDataValidator.reset().parameter("chargeAppliesTo").value(command.getChargeAppliesTo()).notNull().inMinMaxRange(0, 0);
|
||||
baseDataValidator.reset().parameter("chargeTimeType").value(command.getChargeTimeType()).notNull().inMinMaxRange(0, 0);
|
||||
baseDataValidator.reset().parameter("chargeCalculationMethod").value(command.getChargeCalculationType()).notNull().inMinMaxRange(0, 3);
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||
@@ -37,6 +41,10 @@ public class ChargeCommandValidator {
|
||||
baseDataValidator.reset().parameter("id").value(command.getId()).notNull();
|
||||
baseDataValidator.reset().parameter("name").value(command.getName()).ignoreIfNull().notBlank().notExceedingLengthOf(100);
|
||||
baseDataValidator.reset().parameter("amount").value(command.getAmount()).ignoreIfNull().positiveAmount();
|
||||
baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).ignoreIfNull().notBlank();
|
||||
baseDataValidator.reset().parameter("chargeAppliesTo").value(command.getChargeAppliesTo()).ignoreIfNull().notNull().inMinMaxRange(0, 0);
|
||||
baseDataValidator.reset().parameter("chargeTimeType").value(command.getChargeTimeType()).ignoreIfNull().notNull().inMinMaxRange(0, 0);
|
||||
baseDataValidator.reset().parameter("chargeCalculationMethod").value(command.getChargeCalculationType()).ignoreIfNull().notNull().inMinMaxRange(0, 3);
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) {
|
||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package org.mifosng.platform.charge.service;
|
||||
|
||||
import org.mifosng.platform.api.data.EnumOptionData;
|
||||
import org.mifosng.platform.charge.domain.ChargeAppliesTo;
|
||||
import org.mifosng.platform.charge.domain.ChargeCalculationMethod;
|
||||
import org.mifosng.platform.charge.domain.ChargeTimeType;
|
||||
|
||||
public class ChargeEnumerations {
|
||||
|
||||
public static EnumOptionData chargeTimeType(final int id){
|
||||
return chargeTimeType(ChargeTimeType.fromInt(id));
|
||||
}
|
||||
|
||||
public static EnumOptionData chargeTimeType(ChargeTimeType type){
|
||||
EnumOptionData optionData = null;
|
||||
switch (type){
|
||||
case DISBURSEMENT:
|
||||
optionData = new EnumOptionData(ChargeTimeType.DISBURSEMENT.getValue().longValue(), ChargeTimeType.DISBURSEMENT.getCode(), "Disbursement");
|
||||
break;
|
||||
default:
|
||||
optionData = new EnumOptionData(ChargeTimeType.INVALID.getValue().longValue(), ChargeTimeType.INVALID.getCode(), "Invalid");
|
||||
break;
|
||||
}
|
||||
return optionData;
|
||||
}
|
||||
|
||||
public static EnumOptionData chargeAppliesTo(final int id){
|
||||
return chargeAppliesTo(ChargeAppliesTo.fromInt(id));
|
||||
}
|
||||
|
||||
public static EnumOptionData chargeAppliesTo(ChargeAppliesTo type){
|
||||
EnumOptionData optionData = null;
|
||||
switch (type){
|
||||
case LOAN:
|
||||
optionData = new EnumOptionData(ChargeAppliesTo.LOAN.getValue().longValue(), ChargeAppliesTo.LOAN.getCode(), "Loan");
|
||||
break;
|
||||
default:
|
||||
optionData = new EnumOptionData(ChargeAppliesTo.INVALID.getValue().longValue(), ChargeAppliesTo.INVALID.getCode(), "Invalid");
|
||||
break;
|
||||
}
|
||||
return optionData;
|
||||
}
|
||||
|
||||
public static EnumOptionData chargeCalculationType(final int id){
|
||||
return chargeCalculationType(ChargeCalculationMethod.fromInt(id));
|
||||
}
|
||||
|
||||
public static EnumOptionData chargeCalculationType(ChargeCalculationMethod type){
|
||||
EnumOptionData optionData = null;
|
||||
switch (type){
|
||||
case FLAT:
|
||||
optionData = new EnumOptionData(ChargeCalculationMethod.FLAT.getValue().longValue(), ChargeCalculationMethod.FLAT.getCode(), "Flat");
|
||||
break;
|
||||
case PERCENT_OF_AMOUNT:
|
||||
optionData = new EnumOptionData(ChargeCalculationMethod.PERCENT_OF_AMOUNT.getValue().longValue(), ChargeCalculationMethod.PERCENT_OF_AMOUNT.getCode(), "% Amount");
|
||||
break;
|
||||
case PERCENT_OF_AMOUNT_AND_INTEREST:
|
||||
optionData = new EnumOptionData(ChargeCalculationMethod.PERCENT_OF_AMOUNT_AND_INTEREST.getValue().longValue(),ChargeCalculationMethod.PERCENT_OF_AMOUNT_AND_INTEREST.getCode(), "% Loan Amount + Interest");
|
||||
break;
|
||||
case PERCENT_OF_INTEREST:
|
||||
optionData = new EnumOptionData(ChargeCalculationMethod.PERCENT_OF_INTEREST.getValue().longValue(), ChargeCalculationMethod.PERCENT_OF_INTEREST.getCode(), "% Interest");
|
||||
break;
|
||||
default:
|
||||
optionData = new EnumOptionData(ChargeCalculationMethod.INVALID.getValue().longValue(), ChargeCalculationMethod.INVALID.getCode(), "Invalid");
|
||||
break;
|
||||
}
|
||||
return optionData;
|
||||
}
|
||||
}
|
||||
+2
@@ -9,4 +9,6 @@ public interface ChargeReadPlatformService {
|
||||
Collection<ChargeData> retrieveAllCharges();
|
||||
|
||||
ChargeData retrieveCharge(Long chargeId);
|
||||
|
||||
ChargeData retrieveNewChargeDetails();
|
||||
}
|
||||
|
||||
+48
-2
@@ -1,6 +1,12 @@
|
||||
package org.mifosng.platform.charge.service;
|
||||
|
||||
import org.mifosng.platform.api.data.ChargeData;
|
||||
import org.mifosng.platform.api.data.CurrencyData;
|
||||
import org.mifosng.platform.api.data.EnumOptionData;
|
||||
import org.mifosng.platform.charge.domain.ChargeAppliesTo;
|
||||
import org.mifosng.platform.charge.domain.ChargeCalculationMethod;
|
||||
import org.mifosng.platform.charge.domain.ChargeTimeType;
|
||||
import org.mifosng.platform.currency.service.CurrencyReadPlatformService;
|
||||
import org.mifosng.platform.exceptions.ChargeNotFoundException;
|
||||
import org.mifosng.platform.infrastructure.TenantAwareRoutingDataSource;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
@@ -13,19 +19,28 @@ import org.springframework.stereotype.Service;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mifosng.platform.charge.service.ChargeEnumerations.chargeAppliesTo;
|
||||
import static org.mifosng.platform.charge.service.ChargeEnumerations.chargeCalculationType;
|
||||
import static org.mifosng.platform.charge.service.ChargeEnumerations.chargeTimeType;
|
||||
|
||||
@Service
|
||||
public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final CurrencyReadPlatformService currencyReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
public ChargeReadPlatformServiceImpl(PlatformSecurityContext context,
|
||||
final CurrencyReadPlatformService currencyReadPlatformService,
|
||||
final TenantAwareRoutingDataSource dataSource) {
|
||||
this.context = context;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
this.currencyReadPlatformService = currencyReadPlatformService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,10 +70,29 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChargeData retrieveNewChargeDetails() {
|
||||
this.context.authenticatedUser();
|
||||
|
||||
List<CurrencyData> currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies();
|
||||
List<EnumOptionData> allowedChargeCalculationMethods = Arrays.asList(
|
||||
chargeCalculationType(ChargeCalculationMethod.FLAT),
|
||||
chargeCalculationType(ChargeCalculationMethod.PERCENT_OF_AMOUNT),
|
||||
chargeCalculationType(ChargeCalculationMethod.PERCENT_OF_AMOUNT_AND_INTEREST),
|
||||
chargeCalculationType(ChargeCalculationMethod.PERCENT_OF_INTEREST)
|
||||
);
|
||||
EnumOptionData allowedChargeAppliesTo = chargeAppliesTo(ChargeAppliesTo.LOAN);
|
||||
EnumOptionData allowedChargeTime = chargeTimeType(ChargeTimeType.DISBURSEMENT);
|
||||
|
||||
return new ChargeData(allowedChargeTime, allowedChargeAppliesTo, currencyOptions, allowedChargeCalculationMethods);
|
||||
}
|
||||
|
||||
private static final class ChargeMapper implements RowMapper<ChargeData> {
|
||||
|
||||
public String chargeSchema(){
|
||||
return "c.id as id, c.name as name, c.amount as amount from m_charge c ";
|
||||
return "c.id as id, c.name as name, c.amount as amount, c.currency_code as currencyCode, " +
|
||||
"charge_applies_to_enum as chargeAppliesTo, charge_time_enum as chargeTime, " +
|
||||
"charge_calculation_enum as chargeCalculation, is_active as active from m_charge c ";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,8 +100,20 @@ public class ChargeReadPlatformServiceImpl implements ChargeReadPlatformService
|
||||
Long id = rs.getLong("id");
|
||||
String name = rs.getString("name");
|
||||
BigDecimal amount = rs.getBigDecimal("amount");
|
||||
String currencyCode = rs.getString("currencyCode");
|
||||
|
||||
return new ChargeData(id, name, amount);
|
||||
int chargeAppliesTo = rs.getInt("chargeAppliesTo");
|
||||
EnumOptionData chargeAppliesToType = ChargeEnumerations.chargeAppliesTo(chargeAppliesTo);
|
||||
|
||||
int chargeTime = rs.getInt("chargeTime");
|
||||
EnumOptionData chargeTimeType = ChargeEnumerations.chargeTimeType(chargeTime);
|
||||
|
||||
int chargeCalculation = rs.getInt("chargeCalculation");
|
||||
EnumOptionData chargeCalculationType = ChargeEnumerations.chargeCalculationType(chargeCalculation);
|
||||
|
||||
boolean active = rs.getBoolean("active");
|
||||
|
||||
return new ChargeData(id, name, amount, currencyCode, chargeTimeType, chargeAppliesToType, chargeCalculationType, active);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -1,8 +1,7 @@
|
||||
package org.mifosng.platform.charge.service;
|
||||
|
||||
import org.mifosng.platform.api.commands.ChargeCommand;
|
||||
import org.mifosng.platform.charge.domain.Charge;
|
||||
import org.mifosng.platform.charge.domain.ChargeRepository;
|
||||
import org.mifosng.platform.charge.domain.*;
|
||||
import org.mifosng.platform.exceptions.ChargeNotFoundException;
|
||||
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
@@ -35,7 +34,12 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP
|
||||
ChargeCommandValidator validator = new ChargeCommandValidator(command);
|
||||
validator.validateForCreate();
|
||||
|
||||
Charge charge = Charge.createNew(command.getName(), command.getAmount());
|
||||
ChargeAppliesTo chargeAppliesTo = ChargeAppliesTo.fromInt(command.getChargeAppliesTo());
|
||||
ChargeTimeType chargeTimeType = ChargeTimeType.fromInt(command.getChargeTimeType());
|
||||
ChargeCalculationMethod chargeCalculationMethod = ChargeCalculationMethod.fromInt(command.getChargeCalculationType());
|
||||
|
||||
Charge charge = Charge.createNew(command.getName(), command.getAmount(), command.getCurrencyCode(),
|
||||
chargeAppliesTo, chargeTimeType, chargeCalculationMethod, command.isActive());
|
||||
|
||||
this.chargeRepository.saveAndFlush(charge);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user