diff --git a/mifosng-db/multi-tenant-demo-backups/ceda/bk_ceda_trial.sql b/mifosng-db/multi-tenant-demo-backups/ceda/bk_ceda_trial.sql
index 5f47c45b6..4a4de8ac0 100644
--- a/mifosng-db/multi-tenant-demo-backups/ceda/bk_ceda_trial.sql
+++ b/mifosng-db/multi-tenant-demo-backups/ceda/bk_ceda_trial.sql
@@ -732,7 +732,10 @@ DROP TABLE IF EXISTS `m_group`;
CREATE TABLE `m_group` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`office_id` bigint(20) NOT NULL,
- `loan_officer_id` bigint(20) DEFAULT NULL,
+ `level_Id` int(11) NOT NULL,
+ `parent_id` bigint(20) DEFAULT NULL,
+ `hierarchy` varchar(100) DEFAULT NULL,
+ `staff_id` bigint(20) DEFAULT NULL,
`name` varchar(100) DEFAULT NULL,
`external_id` varchar(100) DEFAULT NULL,
`is_deleted` tinyint(1) NOT NULL DEFAULT '0',
@@ -740,9 +743,13 @@ CREATE TABLE `m_group` (
UNIQUE KEY `name` (`name`),
UNIQUE KEY `external_id` (`external_id`),
KEY `office_id` (`office_id`),
- KEY `loan_officer_id` (`loan_officer_id`),
+ KEY `loan_officer_id` (`staff_id`),
+ KEY `Parent_Id_reference` (`parent_id`),
+ KEY `FK_m_group_level` (`level_Id`),
+ CONSTRAINT `FK_m_group_level` FOREIGN KEY (`level_Id`) REFERENCES `m_group_level` (`id`),
+ CONSTRAINT `FK_m_group_m_staff` FOREIGN KEY (`staff_id`) REFERENCES `m_staff` (`id`),
CONSTRAINT `m_group_ibfk_1` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`),
- CONSTRAINT `FK_m_group_m_staff` FOREIGN KEY (`loan_officer_id`) REFERENCES `m_staff` (`id`)
+ CONSTRAINT `Parent_Id_reference` FOREIGN KEY (`parent_id`) REFERENCES `m_group` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -781,6 +788,35 @@ LOCK TABLES `m_group_client` WRITE;
/*!40000 ALTER TABLE `m_group_client` ENABLE KEYS */;
UNLOCK TABLES;
+--
+-- Table structure for table `m_group_level`
+--
+
+DROP TABLE IF EXISTS `m_group_level`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `m_group_level` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `parent_id` int(11) DEFAULT NULL,
+ `level_name` varchar(100) NOT NULL,
+ `recursable` tinyint(1) NOT NULL,
+ `can_have_clients` tinyint(1) NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `Parent_levelId_reference` (`parent_id`),
+ CONSTRAINT `Parent_levelId_reference` FOREIGN KEY (`parent_id`) REFERENCES `m_group_level` (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `m_group_level`
+--
+
+LOCK TABLES `m_group_level` WRITE;
+/*!40000 ALTER TABLE `m_group_level` DISABLE KEYS */;
+INSERT INTO `m_group_level` VALUES (1,NULL,'Center',1,0),(2,NULL,'Group',0,1);
+/*!40000 ALTER TABLE `m_group_level` ENABLE KEYS */;
+UNLOCK TABLES;
+
--
-- Table structure for table `m_guarantor`
--
@@ -1933,4 +1969,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2013-02-19 0:44:13
+-- Dump completed on 2013-02-20 9:57:08
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/domain/ChargeRepositoryWrapper.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/domain/ChargeRepositoryWrapper.java
new file mode 100644
index 000000000..12fd1dcde
--- /dev/null
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/domain/ChargeRepositoryWrapper.java
@@ -0,0 +1,43 @@
+/**
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.mifosplatform.portfolio.charge.domain;
+
+import org.mifosplatform.portfolio.charge.exception.ChargeIsNotActiveException;
+import org.mifosplatform.portfolio.charge.exception.ChargeNotFoundException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ *
+ * Wrapper for {@link ChargeRepository} that is responsible for checking if
+ * {@link Charge} is returned when using findOne repository method
+ * and throwing an appropriate not found exception.
+ *
+ *
+ *
+ * This is to avoid need for checking and throwing in multiple areas of code
+ * base where {@link ChargeRepository} is required.
+ *
+ */
+@Service
+public class ChargeRepositoryWrapper {
+
+ private final ChargeRepository repository;
+
+ @Autowired
+ public ChargeRepositoryWrapper(final ChargeRepository repository) {
+ this.repository = repository;
+ }
+
+ public Charge findOneWithNotFoundDetection(final Long id) {
+
+ final Charge chargeDefinition = this.repository.findOne(id);
+ if (chargeDefinition == null || chargeDefinition.isDeleted()) { throw new ChargeNotFoundException(id); }
+ if (!chargeDefinition.isActive()) { throw new ChargeIsNotActiveException(id, chargeDefinition.getName()); }
+
+ return chargeDefinition;
+ }
+}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/command/LoanChargeCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/command/LoanChargeCommand.java
index 9622c1e07..19a02235a 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/command/LoanChargeCommand.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/command/LoanChargeCommand.java
@@ -6,16 +6,12 @@
package org.mifosplatform.portfolio.loanaccount.command;
import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.List;
import org.joda.time.LocalDate;
-import org.mifosplatform.infrastructure.core.data.ApiParameterError;
-import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
-import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
+import org.mifosplatform.portfolio.loanaccount.domain.LoanCharge;
/**
- * Immutable command for creating and updating loan charges.
+ * Java object representation of {@link LoanCharge} API JSON.
*/
public class LoanChargeCommand implements Comparable {
@@ -23,10 +19,12 @@ public class LoanChargeCommand implements Comparable {
private final Long id;
private final Long chargeId;
private final BigDecimal amount;
+ @SuppressWarnings("unused")
private final Integer chargeTimeType;
+ @SuppressWarnings("unused")
private final Integer chargeCalculationType;
@SuppressWarnings("unused")
- private final LocalDate specifiedDueDate;
+ private final LocalDate dueDate;
public LoanChargeCommand(final Long id, final Long chargeId, final BigDecimal amount, final Integer chargeTimeType,
final Integer chargeCalculationType, final LocalDate specifiedDueDate) {
@@ -35,7 +33,7 @@ public class LoanChargeCommand implements Comparable {
this.amount = amount;
this.chargeTimeType = chargeTimeType;
this.chargeCalculationType = chargeCalculationType;
- this.specifiedDueDate = specifiedDueDate;
+ this.dueDate = specifiedDueDate;
}
@Override
@@ -46,18 +44,4 @@ public class LoanChargeCommand implements Comparable {
}
return comparison;
}
-
- @Deprecated
- public void validateForUpdate() {
- List dataValidationErrors = new ArrayList();
-
- DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("charge");
-
- baseDataValidator.reset().parameter("amount").value(this.amount).ignoreIfNull().positiveAmount();
- baseDataValidator.reset().parameter("chargeTimeType").value(this.chargeTimeType).ignoreIfNull().inMinMaxRange(1, 2);
- baseDataValidator.reset().parameter("chargeCalculationType").value(this.chargeCalculationType).ignoreIfNull().inMinMaxRange(1, 4);
-
- if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
- "Validation errors exist.", dataValidationErrors); }
- }
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanChargeData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanChargeData.java
index 0e4657a6f..c50ba2b73 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanChargeData.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/data/LoanChargeData.java
@@ -31,7 +31,7 @@ public class LoanChargeData {
private final EnumOptionData chargeTimeType;
@SuppressWarnings("unused")
- private final LocalDate dueAsOfDate;
+ private final LocalDate dueDate;
@SuppressWarnings("unused")
private final EnumOptionData chargeCalculationType;
@@ -81,7 +81,7 @@ public class LoanChargeData {
public LoanChargeData(final Long id, final Long chargeId, final String name, final CurrencyData currency, final BigDecimal amount,
final BigDecimal amountPaid, final BigDecimal amountWaived, final BigDecimal amountWrittenOff,
- final BigDecimal amountOutstanding, final EnumOptionData chargeTimeType, final LocalDate dueAsOfDate,
+ final BigDecimal amountOutstanding, final EnumOptionData chargeTimeType, final LocalDate dueDate,
final EnumOptionData chargeCalculationType, final BigDecimal percentage, final BigDecimal amountPercentageAppliedTo,
final boolean penalty) {
this.id = id;
@@ -94,7 +94,7 @@ public class LoanChargeData {
this.amountWrittenOff = amountWrittenOff;
this.amountOutstanding = amountOutstanding;
this.chargeTimeType = chargeTimeType;
- this.dueAsOfDate = dueAsOfDate;
+ this.dueDate = dueDate;
this.chargeCalculationType = chargeCalculationType;
this.percentage = percentage;
this.amountPercentageAppliedTo = amountPercentageAppliedTo;
@@ -122,7 +122,7 @@ public class LoanChargeData {
this.amountWrittenOff = BigDecimal.ZERO;
this.amountOutstanding = amount;
this.chargeTimeType = chargeTimeType;
- this.dueAsOfDate = null;
+ this.dueDate = null;
this.chargeCalculationType = chargeCalculationType;
this.percentage = null;
this.amountPercentageAppliedTo = null;
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/AbstractLoanRepaymentScheduleTransactionProcessor.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/AbstractLoanRepaymentScheduleTransactionProcessor.java
index ef9d4a496..d12e26df2 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/AbstractLoanRepaymentScheduleTransactionProcessor.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/AbstractLoanRepaymentScheduleTransactionProcessor.java
@@ -150,7 +150,7 @@ public abstract class AbstractLoanRepaymentScheduleTransactionProcessor implemen
for (LoanCharge loanCharge : charges) {
if (loanCharge.isNotFullyPaid() && !loanCharge.isDueAtDisbursement()) {
if (earliestUnpaidCharge == null
- || loanCharge.getDueForCollectionAsOfLocalDate().isBefore(earliestUnpaidCharge.getDueForCollectionAsOfLocalDate())) {
+ || loanCharge.getDueLocalDate().isBefore(earliestUnpaidCharge.getDueLocalDate())) {
earliestUnpaidCharge = loanCharge;
}
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java
index a0d002847..ebad29111 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java
@@ -322,7 +322,7 @@ public class Loan extends AbstractAuditableCustom {
Money chargesDue = Money.of(getCurrency(), BigDecimal.ZERO);
- for (LoanCharge charge : getNullPointerSafeLoanCharges()) {
+ for (LoanCharge charge : setOfLoanCharges()) {
if (charge.isDueAtDisbursement()) {
chargesDue = chargesDue.plus(charge.amount());
}
@@ -362,7 +362,8 @@ public class Loan extends AbstractAuditableCustom {
validateLoanIsNotClosed(loanCharge);
if (isDisbursed() && loanCharge.isDueAtDisbursement()) {
- // Note: added this constraint to restrict adding charges to a loan
+ // Note: added this constraint to restrict adding disbursement
+ // charges to a loan
// after it is disbursed
// if the loan charge payment type is 'Disbursement'.
// To undo this constraint would mean resolving how charges due are
@@ -380,7 +381,7 @@ public class Loan extends AbstractAuditableCustom {
validateChargeHasValidSpecifiedDateIfApplicable(loanCharge, getDisbursementDate(), getLastRepaymentPeriodDueDate());
loanCharge.update(this);
- getNullPointerSafeLoanCharges().add(loanCharge);
+ setOfLoanCharges().add(loanCharge);
updateTotalChargesDueAtDisbursement();
@@ -390,11 +391,11 @@ public class Loan extends AbstractAuditableCustom {
if (!loanCharge.isDueAtDisbursement()) {
final List allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(), allNonContraTransactionsPostDisbursement,
- getCurrency(), this.repaymentScheduleInstallments, getNullPointerSafeLoanCharges());
+ getCurrency(), this.repaymentScheduleInstallments, setOfLoanCharges());
} else {
// just reprocess the loan schedule only for now.
LoanScheduleWrapper wrapper = new LoanScheduleWrapper();
- wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, getNullPointerSafeLoanCharges());
+ wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, setOfLoanCharges());
}
}
@@ -435,7 +436,7 @@ public class Loan extends AbstractAuditableCustom {
// if you want ability to remove loan charges that are waived.
validateLoanChargeIsNotWaived(loanCharge);
- boolean removed = getNullPointerSafeLoanCharges().remove(loanCharge);
+ boolean removed = setOfLoanCharges().remove(loanCharge);
if (removed) {
updateTotalChargesDueAtDisbursement();
}
@@ -447,7 +448,7 @@ public class Loan extends AbstractAuditableCustom {
if (!loanCharge.isDueAtDisbursement() && loanCharge.isPaidOrPartiallyPaid(loanCurrency())) {
final List allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(), allNonContraTransactionsPostDisbursement,
- getCurrency(), this.repaymentScheduleInstallments, getNullPointerSafeLoanCharges());
+ getCurrency(), this.repaymentScheduleInstallments, setOfLoanCharges());
}
}
@@ -484,7 +485,7 @@ public class Loan extends AbstractAuditableCustom {
validateLoanIsNotClosed(loanCharge);
- if (getNullPointerSafeLoanCharges().contains(loanCharge)) {
+ if (setOfLoanCharges().contains(loanCharge)) {
final Map loanChargeChanges = loanCharge.update(command, getPrincpal().getAmount());
actualChanges.putAll(loanChargeChanges);
updateTotalChargesDueAtDisbursement();
@@ -495,11 +496,11 @@ public class Loan extends AbstractAuditableCustom {
if (!loanCharge.isDueAtDisbursement()) {
final List allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(), allNonContraTransactionsPostDisbursement,
- getCurrency(), this.repaymentScheduleInstallments, getNullPointerSafeLoanCharges());
+ getCurrency(), this.repaymentScheduleInstallments, setOfLoanCharges());
} else {
// reprocess loan schedule based on charge been waived.
LoanScheduleWrapper wrapper = new LoanScheduleWrapper();
- wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, getNullPointerSafeLoanCharges());
+ wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, setOfLoanCharges());
}
return actualChanges;
@@ -523,7 +524,7 @@ public class Loan extends AbstractAuditableCustom {
LocalDate transactionDate = getDisbursementDate();
if (loanCharge.isSpecifiedDueDate()) {
- transactionDate = loanCharge.getDueForCollectionAsOfLocalDate();
+ transactionDate = loanCharge.getDueLocalDate();
}
updateTotalChargesDueAtDisbursement();
@@ -538,11 +539,11 @@ public class Loan extends AbstractAuditableCustom {
if (!loanCharge.isDueAtDisbursement() && loanCharge.isPaidOrPartiallyPaid(loanCurrency())) {
final List allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(), allNonContraTransactionsPostDisbursement,
- getCurrency(), this.repaymentScheduleInstallments, getNullPointerSafeLoanCharges());
+ getCurrency(), this.repaymentScheduleInstallments, setOfLoanCharges());
} else {
// reprocess loan schedule based on charge been waived.
LoanScheduleWrapper wrapper = new LoanScheduleWrapper();
- wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, getNullPointerSafeLoanCharges());
+ wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, setOfLoanCharges());
}
doPostLoanTransactionChecks(waiveLoanChargeTransaction.getTransactionDate(), loanLifecycleStateMachine);
@@ -595,8 +596,8 @@ public class Loan extends AbstractAuditableCustom {
}
public void updateLoanCharges(final Set loanCharges) {
- getNullPointerSafeLoanCharges().clear();
- getNullPointerSafeLoanCharges().addAll(associateChargesWithThisLoan(loanCharges));
+ setOfLoanCharges().clear();
+ setOfLoanCharges().addAll(associateChargesWithThisLoan(loanCharges));
this.totalChargesDueAtDisbursement = deriveSumTotalOfChargesDueAtDisbursement();
}
@@ -630,7 +631,7 @@ public class Loan extends AbstractAuditableCustom {
final LoanRepaymentScheduleTransactionProcessor loanRepaymentScheduleTransactionProcessor = this.transactionProcessor
.determineProcessor(this.transactionProcessingStrategy);
loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(), repaymentsOrWaivers, getCurrency(),
- this.repaymentScheduleInstallments, getNullPointerSafeLoanCharges());
+ this.repaymentScheduleInstallments, setOfLoanCharges());
}
public void updateLoanScheduleDependentDerivedFields() {
@@ -785,7 +786,7 @@ public class Loan extends AbstractAuditableCustom {
final String chargesParamName = "charges";
if (command.parameterExists(chargesParamName)) {
- final Set existingLoanCharges = getNullPointerSafeLoanCharges();
+ final Set existingLoanCharges = setOfLoanCharges();
if (!possiblyModifedLoanCharges.equals(existingLoanCharges)) {
actualChanges.put(chargesParamName, getLoanCharges(possiblyModifedLoanCharges));
@@ -797,20 +798,6 @@ public class Loan extends AbstractAuditableCustom {
validateChargeHasValidSpecifiedDateIfApplicable(loanCharge, getDisbursementDate(), getLastRepaymentPeriodDueDate());
}
}
-
- // final ImmutableSet difference =
- // Sets.symmetricDifference(existingLoanCharges,
- // possiblyModifedLoanCharges)
- // .immutableCopy();
- // if (!difference.isEmpty()) {
- // actualChanges.put(chargesParamName, getLoanCharges(difference));
- // actualChanges.put("recalculateLoanSchedule", true);
- //
- // for (LoanCharge loanCharge : possiblyModifedLoanCharges) {
- // validateChargeHasValidSpecifiedDateIfApplicable(loanCharge,
- // getDisbursementDate(), getLastRepaymentPeriodDueDate());
- // }
- // }
}
final String collateralParamName = "collateral";
@@ -819,22 +806,12 @@ public class Loan extends AbstractAuditableCustom {
if (!possiblyModifedLoanCollateralItems.equals(this.collateral)) {
actualChanges.put(collateralParamName, listOfLoanCollateralData(possiblyModifedLoanCollateralItems));
}
-
- //
- // final ImmutableSet difference =
- // Sets.symmetricDifference(this.collateral,
- // possiblyModifedLoanCollateralItems)
- // .immutableCopy();
- // if (!difference.isEmpty()) {
- // actualChanges.put(collateralParamName,
- // listOfLoanCollateralData(difference));
- // }
}
return actualChanges;
}
- private Set getNullPointerSafeLoanCharges() {
+ private Set setOfLoanCharges() {
Set loanCharges = this.charges;
if (this.charges == null) {
loanCharges = new HashSet();
@@ -933,7 +910,7 @@ public class Loan extends AbstractAuditableCustom {
}
// charges are optional
- for (LoanCharge loanCharge : getNullPointerSafeLoanCharges()) {
+ for (LoanCharge loanCharge : setOfLoanCharges()) {
validateChargeHasValidSpecifiedDateIfApplicable(loanCharge, getDisbursementDate(), getLastRepaymentPeriodDueDate());
}
}
@@ -1190,7 +1167,7 @@ public class Loan extends AbstractAuditableCustom {
final LoanSchedule loanSchedule = new LoanSchedule(loanScheduleGenerator, applicationCurrency, principal, interestRatePerPeriod,
interestRatePeriodFrequencyType, defaultAnnualNominalInterestRate, interestMethod, interestCalculationPeriodMethod,
repaymentEvery, repaymentPeriodFrequencyType, numberOfRepayments, amortizationMethod, loanTermFrequency,
- loanTermPeriodFrequencyType, getNullPointerSafeLoanCharges(), this.getDisbursementDate(),
+ loanTermPeriodFrequencyType, setOfLoanCharges(), this.getDisbursementDate(),
this.getExpectedFirstRepaymentOnDate(), this.getInterestChargedFromDate(), inArrearsTolerance);
final LoanScheduleData generatedData = loanSchedule.generate();
@@ -1215,7 +1192,7 @@ public class Loan extends AbstractAuditableCustom {
chargesPayment.updateLoan(this);
this.loanTransactions.add(chargesPayment);
- for (LoanCharge charge : getNullPointerSafeLoanCharges()) {
+ for (LoanCharge charge : setOfLoanCharges()) {
if (charge.isDueAtDisbursement()) {
charge.markAsFullyPaid();
}
@@ -1281,7 +1258,7 @@ public class Loan extends AbstractAuditableCustom {
private void updateLoanToPreDisbursalState() {
this.actualDisbursementDate = null;
- for (LoanCharge charge : getNullPointerSafeLoanCharges()) {
+ for (LoanCharge charge : setOfLoanCharges()) {
charge.resetToOriginal(loanCurrency());
}
@@ -1290,7 +1267,7 @@ public class Loan extends AbstractAuditableCustom {
}
LoanScheduleWrapper wrapper = new LoanScheduleWrapper();
- wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, getNullPointerSafeLoanCharges());
+ wrapper.reprocess(getCurrency(), getDisbursementDate(), this.repaymentScheduleInstallments, setOfLoanCharges());
}
public LoanTransaction waiveInterest(final JsonCommand command, final LoanLifecycleStateMachine loanLifecycleStateMachine) {
@@ -1370,11 +1347,11 @@ public class Loan extends AbstractAuditableCustom {
.determineProcessor(this.transactionProcessingStrategy);
if (isTransactionChronologicallyLatest && adjustedTransaction == null) {
loanRepaymentScheduleTransactionProcessor.handleTransaction(loanTransaction, getCurrency(), this.repaymentScheduleInstallments,
- getNullPointerSafeLoanCharges());
+ setOfLoanCharges());
} else {
final List allNonContraTransactionsPostDisbursement = retreiveListOfTransactionsPostDisbursement();
loanRepaymentScheduleTransactionProcessor.handleTransaction(getDisbursementDate(), allNonContraTransactionsPostDisbursement,
- getCurrency(), this.repaymentScheduleInstallments, getNullPointerSafeLoanCharges());
+ getCurrency(), this.repaymentScheduleInstallments, setOfLoanCharges());
}
doPostLoanTransactionChecks(loanTransaction.getTransactionDate(), loanLifecycleStateMachine);
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanCharge.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanCharge.java
index 13ad1d177..cb2c4ccdb 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanCharge.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/LoanCharge.java
@@ -50,7 +50,7 @@ public class LoanCharge extends AbstractPersistable {
@Temporal(TemporalType.DATE)
@Column(name = "due_for_collection_as_of_date")
- private Date dueForCollectionAsOfDate;
+ private Date dueDate;
@Column(name = "charge_calculation_enum")
private Integer chargeCalculation;
@@ -85,29 +85,32 @@ public class LoanCharge extends AbstractPersistable {
public static LoanCharge createNewFromJson(final Loan loan, final Charge chargeDefinition, final JsonCommand command) {
final BigDecimal amount = command.bigDecimalValueOfParameterNamed("amount");
- final Integer chargeTimeType = command.integerValueOfParameterNamed("chargeTimeType");
- final Integer chargeCalculationType = command.integerValueOfParameterNamed("chargeCalculationType");
- final LocalDate specifiedDueDate = command.localDateValueOfParameterNamed("specifiedDueDate");
+ // final Integer chargeTimeType =
+ // command.integerValueOfParameterNamed("chargeTimeType");
+ // final Integer chargeCalculationType =
+ // command.integerValueOfParameterNamed("chargeCalculationType");
+ final LocalDate dueDate = command.localDateValueOfParameterNamed("dueDate");
ChargeTimeType chargeTime = null;
- if (chargeTimeType != null) {
- chargeTime = ChargeTimeType.fromInt(chargeTimeType);
- }
+ // if (chargeTimeType != null) {
+ // chargeTime = ChargeTimeType.fromInt(chargeTimeType);
+ // }
ChargeCalculationType chargeCalculation = null;
- if (chargeCalculationType != null) {
- chargeCalculation = ChargeCalculationType.fromInt(chargeCalculationType);
- }
+ // if (chargeCalculationType != null) {
+ // chargeCalculation =
+ // ChargeCalculationType.fromInt(chargeCalculationType);
+ // }
return new LoanCharge(loan, chargeDefinition, loan.getPrincpal().getAmount(), amount, chargeTime, chargeCalculation,
- specifiedDueDate);
+ dueDate);
}
/*
* loanPrincipal is required for charges that are percentage based
*/
public static LoanCharge createNewWithoutLoan(final Charge chargeDefinition, final BigDecimal loanPrincipal, final BigDecimal amount,
- final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculation, final LocalDate specifiedDueDate) {
- return new LoanCharge(null, chargeDefinition, loanPrincipal, amount, chargeTime, chargeCalculation, specifiedDueDate);
+ final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculation, final LocalDate dueDate) {
+ return new LoanCharge(null, chargeDefinition, loanPrincipal, amount, chargeTime, chargeCalculation, dueDate);
}
protected LoanCharge() {
@@ -115,7 +118,7 @@ public class LoanCharge extends AbstractPersistable {
}
public LoanCharge(final Loan loan, final Charge chargeDefinition, final BigDecimal loanPrincipal, final BigDecimal amount,
- final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculation, final LocalDate specifiedDueDate) {
+ final ChargeTimeType chargeTime, final ChargeCalculationType chargeCalculation, final LocalDate dueDate) {
this.loan = loan;
this.charge = chargeDefinition;
this.penaltyCharge = chargeDefinition.isPenalty();
@@ -127,15 +130,15 @@ public class LoanCharge extends AbstractPersistable {
if (ChargeTimeType.fromInt(this.chargeTime).equals(ChargeTimeType.SPECIFIED_DUE_DATE)) {
- if (specifiedDueDate == null) {
- final String defaultUserMessage = "Loan charge is missing specified due date";
- throw new LoanChargeWithoutMandatoryFieldException("loancharge", "specifiedDueDate", defaultUserMessage,
+ if (dueDate == null) {
+ final String defaultUserMessage = "Loan charge is missing due date.";
+ throw new LoanChargeWithoutMandatoryFieldException("loanCharge", "dueDate", defaultUserMessage,
chargeDefinition.getId(), chargeDefinition.getName());
}
- this.dueForCollectionAsOfDate = specifiedDueDate.toDate();
+ this.dueDate = dueDate.toDate();
} else {
- this.dueForCollectionAsOfDate = null;
+ this.dueDate = null;
}
this.chargeCalculation = chargeDefinition.getChargeCalculation();
@@ -240,7 +243,7 @@ public class LoanCharge extends AbstractPersistable {
public void update(final BigDecimal amount, final LocalDate specifiedDueDate, final BigDecimal loanPrincipal) {
if (specifiedDueDate != null) {
- this.dueForCollectionAsOfDate = specifiedDueDate.toDate();
+ this.dueDate = specifiedDueDate.toDate();
}
if (amount != null) {
@@ -279,31 +282,37 @@ public class LoanCharge extends AbstractPersistable {
final String dateFormatAsInput = command.dateFormat();
final String localeAsInput = command.locale();
- final String chargeTimeParamName = "chargeTime";
- if (command.isChangeInIntegerParameterNamed(chargeTimeParamName, this.chargeTime)) {
- final Integer newValue = command.integerValueOfParameterNamed(chargeTimeParamName);
- actualChanges.put(chargeTimeParamName, newValue);
- actualChanges.put("locale", localeAsInput);
- this.chargeTime = ChargeTimeType.fromInt(newValue).getValue();
- }
+ // final String chargeTimeParamName = "chargeTime";
+ // if (command.isChangeInIntegerParameterNamed(chargeTimeParamName,
+ // this.chargeTime)) {
+ // final Integer newValue =
+ // command.integerValueOfParameterNamed(chargeTimeParamName);
+ // actualChanges.put(chargeTimeParamName, newValue);
+ // actualChanges.put("locale", localeAsInput);
+ // this.chargeTime = ChargeTimeType.fromInt(newValue).getValue();
+ // }
+ //
+ // final String chargeCalculationParamName = "chargeCalculation";
+ // if
+ // (command.isChangeInIntegerParameterNamed(chargeCalculationParamName,
+ // this.chargeCalculation)) {
+ // final Integer newValue =
+ // command.integerValueOfParameterNamed(chargeCalculationParamName);
+ // actualChanges.put(chargeCalculationParamName, newValue);
+ // actualChanges.put("locale", localeAsInput);
+ // this.chargeCalculation =
+ // ChargeCalculationType.fromInt(newValue).getValue();
+ // }
- final String chargeCalculationParamName = "chargeCalculation";
- if (command.isChangeInIntegerParameterNamed(chargeCalculationParamName, this.chargeCalculation)) {
- final Integer newValue = command.integerValueOfParameterNamed(chargeCalculationParamName);
- actualChanges.put(chargeCalculationParamName, newValue);
- actualChanges.put("locale", localeAsInput);
- this.chargeCalculation = ChargeCalculationType.fromInt(newValue).getValue();
- }
-
- final String specifiedDueDateParamName = "specifiedDueDate";
- if (command.isChangeInLocalDateParameterNamed(specifiedDueDateParamName, getDueForCollectionAsOfLocalDate())) {
+ final String specifiedDueDateParamName = "dueDate";
+ if (command.isChangeInLocalDateParameterNamed(specifiedDueDateParamName, getDueLocalDate())) {
final String valueAsInput = command.stringValueOfParameterNamed(specifiedDueDateParamName);
actualChanges.put(specifiedDueDateParamName, valueAsInput);
actualChanges.put("dateFormat", dateFormatAsInput);
actualChanges.put("locale", localeAsInput);
final LocalDate newValue = command.localDateValueOfParameterNamed(specifiedDueDateParamName);
- this.dueForCollectionAsOfDate = newValue.toDate();
+ this.dueDate = newValue.toDate();
}
final String amountParamName = "amount";
@@ -355,13 +364,13 @@ public class LoanCharge extends AbstractPersistable {
public LoanChargeCommand toCommand() {
return new LoanChargeCommand(this.getId(), this.charge.getId(), this.amount, this.chargeTime, this.chargeCalculation,
- getDueForCollectionAsOfLocalDate());
+ getDueLocalDate());
}
- public LocalDate getDueForCollectionAsOfLocalDate() {
+ public LocalDate getDueLocalDate() {
LocalDate specifiedDueDate = null;
- if (this.dueForCollectionAsOfDate != null) {
- specifiedDueDate = new LocalDate(this.dueForCollectionAsOfDate);
+ if (this.dueDate != null) {
+ specifiedDueDate = new LocalDate(this.dueDate);
}
return specifiedDueDate;
}
@@ -418,7 +427,7 @@ public class LoanCharge extends AbstractPersistable {
}
public boolean isDueForCollectionFromAndUpToAndIncluding(final LocalDate fromNotInclusive, final LocalDate upToAndInclusive) {
- final LocalDate specifiedDueDate = getDueForCollectionAsOfLocalDate();
+ final LocalDate specifiedDueDate = getDueLocalDate();
return occursOnDayFromAndUpToAndIncluding(fromNotInclusive, upToAndInclusive, specifiedDueDate);
}
@@ -508,7 +517,7 @@ public class LoanCharge extends AbstractPersistable {
.append(this.getId(), rhs.getId()) //
.append(this.charge.getId(), rhs.charge.getId()) //
.append(this.amount, rhs.amount) //
- .append(this.getDueForCollectionAsOfLocalDate(), rhs.getDueForCollectionAsOfLocalDate()) //
+ .append(this.getDueLocalDate(), rhs.getDueLocalDate()) //
.isEquals();
}
@@ -517,7 +526,7 @@ public class LoanCharge extends AbstractPersistable {
return new HashCodeBuilder(3, 5) //
.append(this.getId()) //
.append(this.charge.getId()) //
- .append(this.amount).append(this.getDueForCollectionAsOfLocalDate()) //
+ .append(this.amount).append(this.getDueLocalDate()) //
.toHashCode();
}
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanChargeCommandFromApiJsonDeserializer.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanChargeCommandFromApiJsonDeserializer.java
deleted file mode 100644
index d15a2c697..000000000
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanChargeCommandFromApiJsonDeserializer.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-package org.mifosplatform.portfolio.loanaccount.serialization;
-
-import java.lang.reflect.Type;
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.lang.StringUtils;
-import org.joda.time.LocalDate;
-import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
-import org.mifosplatform.infrastructure.core.serialization.AbstractFromApiJsonDeserializer;
-import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
-import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
-import org.mifosplatform.portfolio.loanaccount.command.LoanChargeCommand;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import com.google.gson.JsonElement;
-import com.google.gson.reflect.TypeToken;
-
-/**
- * Implementation of {@link FromApiJsonDeserializer} for
- * {@link LoanChargeCommand}'s.
- */
-@Component
-public final class LoanChargeCommandFromApiJsonDeserializer extends AbstractFromApiJsonDeserializer {
-
- /**
- * The parameters supported for this command.
- */
- final Set supportedParameters = new HashSet(Arrays.asList("id", "chargeId", "amount", "chargeTimeType",
- "chargeCalculationType", "specifiedDueDate", "locale", "dateFormat"));
-
- private final FromJsonHelper fromApiJsonHelper;
-
- @Autowired
- public LoanChargeCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
- this.fromApiJsonHelper = fromApiJsonHelper;
- }
-
- @Override
- public LoanChargeCommand commandFromApiJson(final String json) {
-
- if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
-
- final Type typeOfMap = new TypeToken