From d2096630d1463adf1acf0999102ff93b065e5185 Mon Sep 17 00:00:00 2001 From: ashok-conflux Date: Sat, 12 Oct 2013 18:54:10 +0530 Subject: [PATCH] Remove payment mode option from savings charges --- .../V123__remove_payment_mode_for_savings.sql | 2 ++ .../portfolio/charge/domain/Charge.java | 24 +++++++++++-------- ...initionCommandFromApiJsonDeserializer.java | 9 ++++--- 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 mifosng-db/migrations/core_db/V123__remove_payment_mode_for_savings.sql diff --git a/mifosng-db/migrations/core_db/V123__remove_payment_mode_for_savings.sql b/mifosng-db/migrations/core_db/V123__remove_payment_mode_for_savings.sql new file mode 100644 index 000000000..9051325fe --- /dev/null +++ b/mifosng-db/migrations/core_db/V123__remove_payment_mode_for_savings.sql @@ -0,0 +1,2 @@ +ALTER TABLE `m_charge` + CHANGE COLUMN `charge_payment_mode_enum` `charge_payment_mode_enum` SMALLINT(5) NULL DEFAULT NULL AFTER `charge_calculation_enum`; \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/domain/Charge.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/domain/Charge.java index b14995e74..ffe0f8964 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/domain/Charge.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/domain/Charge.java @@ -54,7 +54,7 @@ public class Charge extends AbstractPersistable { @Column(name = "charge_calculation_enum") private Integer chargeCalculation; - @Column(name = "charge_payment_mode_enum") + @Column(name = "charge_payment_mode_enum", nullable = true) private Integer chargePaymentMode; @Column(name = "fee_on_day", nullable = true) @@ -85,7 +85,9 @@ public class Charge extends AbstractPersistable { final ChargeTimeType chargeTimeType = ChargeTimeType.fromInt(command.integerValueOfParameterNamed("chargeTimeType")); final ChargeCalculationType chargeCalculationType = ChargeCalculationType.fromInt(command .integerValueOfParameterNamed("chargeCalculationType")); - final ChargePaymentMode paymentMode = ChargePaymentMode.fromInt(command.integerValueOfParameterNamed("chargePaymentMode")); + final Integer chargePaymentMode = command.integerValueOfParameterNamed("chargePaymentMode"); + + final ChargePaymentMode paymentMode = (chargePaymentMode == null) ? null : ChargePaymentMode.fromInt(chargePaymentMode); final boolean penalty = command.booleanPrimitiveValueOfParameterNamed("penalty"); final boolean active = command.booleanPrimitiveValueOfParameterNamed("active"); @@ -111,7 +113,7 @@ public class Charge extends AbstractPersistable { this.chargeCalculation = chargeCalculationType.getValue(); this.penalty = penalty; this.active = active; - this.chargePaymentMode = paymentMode.getValue(); + this.chargePaymentMode = (paymentMode == null) ? null : paymentMode.getValue(); final List dataValidationErrors = new ArrayList(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("charges"); @@ -316,14 +318,16 @@ public class Charge extends AbstractPersistable { } } - final String paymentModeParamName = "chargePaymentMode"; - if (command.isChangeInIntegerParameterNamed(paymentModeParamName, this.chargePaymentMode)) { - final Integer newValue = command.integerValueOfParameterNamed(paymentModeParamName); - actualChanges.put(paymentModeParamName, newValue); - actualChanges.put("locale", localeAsInput); - this.chargePaymentMode = ChargePaymentMode.fromInt(newValue).getValue(); + if (this.isLoanCharge()) {// validate only for loan charge + final String paymentModeParamName = "chargePaymentMode"; + if (command.isChangeInIntegerParameterNamed(paymentModeParamName, this.chargePaymentMode)) { + final Integer newValue = command.integerValueOfParameterNamed(paymentModeParamName); + actualChanges.put(paymentModeParamName, newValue); + actualChanges.put("locale", localeAsInput); + this.chargePaymentMode = ChargePaymentMode.fromInt(newValue).getValue(); + } } - + if (command.hasParameter("feeOnMonthDay")) { final MonthDay monthDay = command.extractMonthDayNamed("feeOnMonthDay"); final String actualValueEntered = command.stringValueOfParameterNamed("feeOnMonthDay"); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/serialization/ChargeDefinitionCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/serialization/ChargeDefinitionCommandFromApiJsonDeserializer.java index 700ba2649..122053f06 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/serialization/ChargeDefinitionCommandFromApiJsonDeserializer.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/serialization/ChargeDefinitionCommandFromApiJsonDeserializer.java @@ -79,9 +79,12 @@ public final class ChargeDefinitionCommandFromApiJsonDeserializer { Locale.getDefault()); baseDataValidator.reset().parameter("chargeCalculationType").value(chargeCalculationType).notNull().inMinMaxRange(1, 4); - final Integer chargePaymentMode = this.fromApiJsonHelper.extractIntegerNamed("chargePaymentMode", element, Locale.getDefault()); - baseDataValidator.reset().parameter("chargePaymentMode").value(chargePaymentMode).notNull().inMinMaxRange(0, 1); - + ChargeAppliesTo appliesTo = ChargeAppliesTo.fromInt(chargeAppliesTo); + if (appliesTo.isLoanCharge()) { + final Integer chargePaymentMode = this.fromApiJsonHelper.extractIntegerNamed("chargePaymentMode", element, Locale.getDefault()); + baseDataValidator.reset().parameter("chargePaymentMode").value(chargePaymentMode).notNull().inMinMaxRange(0, 1); + } + if (this.fromApiJsonHelper.parameterExists("penalty", element)) { final Boolean penalty = this.fromApiJsonHelper.extractBooleanNamed("penalty", element); baseDataValidator.reset().parameter("penalty").value(penalty).notNull();