diff --git a/mifosng-db/migrations/core_db/V171__added_mandatory_savings_and_rd_changes.sql b/mifosng-db/migrations/core_db/V171__added_mandatory_savings_and_rd_changes.sql new file mode 100644 index 000000000..e539eb3cd --- /dev/null +++ b/mifosng-db/migrations/core_db/V171__added_mandatory_savings_and_rd_changes.sql @@ -0,0 +1,71 @@ +INSERT INTO `c_configuration` (`name`, `value`, `enabled`) VALUES ('age_limit_for_senior_citizen', 65, 1); +INSERT INTO `c_configuration` (`name`, `value`, `enabled`) VALUES ('age_limit_for_children', 15, 1); + + +ALTER TABLE `m_interest_rate_slab` + ADD COLUMN `interest_rate_for_female` DECIMAL(19,6) NULL AFTER `annual_interest_rate`, + ADD COLUMN `interest_rate_for_children` DECIMAL(19,6) NULL AFTER `interest_rate_for_female`, + ADD COLUMN `interest_rate_for_senior_citizen` DECIMAL(19,6) NULL AFTER `interest_rate_for_children`; + +ALTER TABLE `m_savings_account_interest_rate_slab` + ADD COLUMN `interest_rate_for_female` DECIMAL(19,6) NULL AFTER `annual_interest_rate`, + ADD COLUMN `interest_rate_for_children` DECIMAL(19,6) NULL AFTER `interest_rate_for_female`, + ADD COLUMN `interest_rate_for_senior_citizen` DECIMAL(19,6) NULL AFTER `interest_rate_for_children`; + +ALTER TABLE `m_deposit_account_recurring_detail` + CHANGE COLUMN `recurring_deposit_amount` `mandatory_recommended_deposit_amount` DECIMAL(19,6) NULL DEFAULT NULL, + ADD COLUMN `is_mandatory` TINYINT NOT NULL DEFAULT '0', + ADD COLUMN `allow_withdrawal` TINYINT NOT NULL DEFAULT '0', + ADD COLUMN `adjust_advance_towards_future_payments` TINYINT NOT NULL DEFAULT '1', + ADD COLUMN `is_calendar_inherited` TINYINT NOT NULL DEFAULT '0', + ADD COLUMN `total_overdue_amount` DECIMAL(19,6) NULL DEFAULT NULL, + ADD COLUMN `no_of_overdue_installments` INT(11) NULL DEFAULT NULL, + DROP COLUMN `recurring_deposit_type_enum`, + DROP COLUMN `recurring_deposit_frequency`, + DROP COLUMN `recurring_deposit_frequency_type_enum`; + + +ALTER TABLE `m_deposit_product_term_and_preclosure` + DROP COLUMN `interest_free_period_applicable`, + DROP COLUMN `interest_free_from_period`, + DROP COLUMN `interest_free_to_period`, + DROP COLUMN `interest_free_period_frequency_enum`; + +ALTER TABLE `m_deposit_product_recurring_detail` + ADD COLUMN `is_mandatory` TINYINT(1) NOT NULL DEFAULT '1', + ADD COLUMN `allow_withdrawal` TINYINT(1) NOT NULL DEFAULT '0', + ADD COLUMN `adjust_advance_towards_future_payments` TINYINT(1) NOT NULL DEFAULT '1', + DROP COLUMN `recurring_deposit_type_enum`, + DROP COLUMN `recurring_deposit_frequency`, + DROP COLUMN `recurring_deposit_frequency_type_enum`; + +ALTER TABLE `m_deposit_account_term_and_preclosure` + DROP COLUMN `interest_free_period_applicable`, + DROP COLUMN `interest_free_from_period`, + DROP COLUMN `interest_free_to_period`, + DROP COLUMN `interest_free_period_frequency_enum`; + +CREATE TABLE `m_mandatory_savings_schedule` ( + `id` BIGINT(20) NOT NULL AUTO_INCREMENT, + `savings_account_id` BIGINT(20) NOT NULL, + `fromdate` DATE NULL DEFAULT NULL, + `duedate` DATE NOT NULL, + `installment` SMALLINT(5) NOT NULL, + `deposit_amount` DECIMAL(19,6) NULL DEFAULT NULL, + `deposit_amount_completed_derived` DECIMAL(19,6) NULL DEFAULT NULL, + `total_paid_in_advance_derived` DECIMAL(19,6) NULL DEFAULT NULL, + `total_paid_late_derived` DECIMAL(19,6) NULL DEFAULT NULL, + `completed_derived` BIT(1) NOT NULL, + `obligations_met_on_date` DATE NULL DEFAULT NULL, + `createdby_id` BIGINT(20) NULL DEFAULT NULL, + `created_date` DATETIME NULL DEFAULT NULL, + `lastmodified_date` DATETIME NULL DEFAULT NULL, + `lastmodifiedby_id` BIGINT(20) NULL DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `FKMSS0000000001` (`savings_account_id`), + CONSTRAINT `FKMSS0000000001` FOREIGN KEY (`savings_account_id`) REFERENCES `m_savings_account` (`id`) +); + + +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('organisation', 'READ_RECURRINGDEPOSITPRODUCT', 'RECURRINGDEPOSITPRODUCT', 'READ', 0); +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('organisation', 'READ_FIXEDDEPOSITPRODUCT', 'FIXEDDEPOSITPRODUCT', 'READ', 0); \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java index 71d145d92..c474f8673 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java @@ -5,7 +5,6 @@ */ package org.mifosplatform.commands.domain; -import org.mifosplatform.portfolio.savings.DepositAccountType; public class CommandWrapper { @@ -28,8 +27,6 @@ public class CommandWrapper { @SuppressWarnings("unused") private Long templateId; - private Long interestRatechartId; - private DepositAccountType depositAccountType; public static CommandWrapper wrap(final String actionName, final String entityName, final Long resourceId, final Long subresourceId) { return new CommandWrapper(null, actionName, entityName, resourceId, subresourceId, null, null); @@ -68,8 +65,7 @@ public class CommandWrapper { public CommandWrapper(final Long officeId, final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String actionName, final String entityName, final Long entityId, final Long subentityId, final String href, - final String json, final String transactionId, final Long productId, final Long templateId, Long interestRatechartId, - DepositAccountType depositAccountType) { + final String json, final String transactionId, final Long productId, final Long templateId) { this.commandId = null; this.officeId = officeId; @@ -87,8 +83,6 @@ public class CommandWrapper { this.transactionId = transactionId; this.productId = productId; this.templateId = templateId; - this.interestRatechartId = interestRatechartId; - this.depositAccountType = depositAccountType; } private CommandWrapper(final Long commandId, final String actionName, final String entityName, final Long resourceId, @@ -720,10 +714,6 @@ public class CommandWrapper { return this.entityName.equalsIgnoreCase("CACHE"); } - public Long interestRatechartId() { - return this.interestRatechartId; - } - // Begin - Deposit product public boolean isFixedDepositProductResource() { return this.entityName.equalsIgnoreCase("FIXEDDEPOSITPRODUCT"); @@ -737,53 +727,101 @@ public class CommandWrapper { // Begin - Deposit accounts public boolean isDepositAccountResource() { - return this.entityName.equalsIgnoreCase("FIXEDDEPOSITACCOUNT") || this.entityName.equalsIgnoreCase("RECURRINGDEPOSITACCOUNT"); + return isFixedDepositAccountResource() || isRecurringDepositAccountResource(); } - public boolean isRejectionOfDepositAccountApplication() { - return this.actionName.equalsIgnoreCase("REJECT") && isDepositAccountResource(); + public boolean isFixedDepositAccountResource() { + return this.entityName.equalsIgnoreCase("FIXEDDEPOSITACCOUNT"); } - public boolean isWithdrawFromDepositAccountApplicationByApplicant() { - return this.actionName.equalsIgnoreCase("WITHDRAW") && isDepositAccountResource(); + public boolean isRecurringDepositAccountResource() { + return this.entityName.equalsIgnoreCase("RECURRINGDEPOSITACCOUNT"); } - public boolean isApprovalOfDepositAccountApplication() { - return this.actionName.equalsIgnoreCase("APPROVE") && isDepositAccountResource(); + public boolean isFixedDepositAccountCreate() { + return isCreate() && isFixedDepositAccountResource(); + } + + public boolean isRecurringDepositAccountCreate() { + return isCreate() && isRecurringDepositAccountResource(); + } + + public boolean isFixedDepositAccountUpdate() { + return isUpdate() && isFixedDepositAccountResource(); + } + + public boolean isRecurringDepositAccountUpdate() { + return isUpdate() && isRecurringDepositAccountResource(); + } + + public boolean isFixedDepositAccountDelete() { + return isDelete() && isFixedDepositAccountResource(); + } + + public boolean isRecurringDepositAccountDelete() { + return isDelete() && isRecurringDepositAccountResource(); + } + + public boolean isRejectionOfFixedDepositAccountApplication() { + return this.actionName.equalsIgnoreCase("REJECT") && isFixedDepositAccountResource(); + } + + public boolean isRejectionOfRecurringDepositAccountApplication() { + return this.actionName.equalsIgnoreCase("REJECT") && isRecurringDepositAccountResource(); + } + + public boolean isWithdrawFixedDepositAccountApplicationByApplicant() { + return this.actionName.equalsIgnoreCase("WITHDRAW") && isFixedDepositAccountResource(); + } + + public boolean isWithdrawRecurringDepositAccountApplicationByApplicant() { + return this.actionName.equalsIgnoreCase("WITHDRAW") && isRecurringDepositAccountResource(); + } + + public boolean isApprovalOfFixedDepositAccountApplication() { + return this.actionName.equalsIgnoreCase("APPROVE") && isFixedDepositAccountResource(); + } + + public boolean isApprovalOfRecurringDepositAccountApplication() { + return this.actionName.equalsIgnoreCase("APPROVE") && isRecurringDepositAccountResource(); } - public boolean isUndoApprovalOfDepositAccountApplication() { - return this.actionName.equalsIgnoreCase("APPROVALUNDO") && isDepositAccountResource(); + public boolean isUndoApprovalOfFixedDepositAccountApplication() { + return this.actionName.equalsIgnoreCase("APPROVALUNDO") && isFixedDepositAccountResource(); + } + + public boolean isUndoApprovalOfRecurringDepositAccountApplication() { + return this.actionName.equalsIgnoreCase("APPROVALUNDO") && isRecurringDepositAccountResource(); } //Account transaction actions - public boolean isDepositAccountDeposit() { - return this.actionName.equalsIgnoreCase("DEPOSIT") && isDepositAccountResource(); + public boolean isDeposit() { + return this.actionName.equalsIgnoreCase("DEPOSIT"); } - - public boolean isDepositAccountWithdrawal() { - return this.actionName.equalsIgnoreCase("WITHDRAWAL") && isDepositAccountResource(); + + public boolean isWithdrawal() { + return this.actionName.equalsIgnoreCase("WITHDRAWAL"); } - public boolean isDepositAccountActivation() { - return this.actionName.equalsIgnoreCase("ACTIVATE") && isDepositAccountResource(); + public boolean isActivation() { + return this.actionName.equalsIgnoreCase("ACTIVATE"); } - public boolean isDepositAccountInterestCalculation() { - return this.actionName.equalsIgnoreCase("CALCULATEINTEREST") && isDepositAccountResource(); + public boolean isInterestCalculation() { + return this.actionName.equalsIgnoreCase("CALCULATEINTEREST"); } - public boolean isDepositAccountInterestPosting() { - return this.actionName.equalsIgnoreCase("POSTINTEREST") && isDepositAccountResource(); + public boolean isInterestPosting() { + return this.actionName.equalsIgnoreCase("POSTINTEREST"); } - - public boolean isDepositAccountUndoTransaction() { - return this.actionName.equalsIgnoreCase("UNDOTRANSACTION") && isDepositAccountResource(); + + public boolean isUndoTransaction() { + return this.actionName.equalsIgnoreCase("UNDOTRANSACTION"); } - public boolean isAdjustDeopsitAccountTransaction() { - return this.actionName.equalsIgnoreCase("ADJUSTTRANSACTION") && isDepositAccountResource(); + public boolean isAdjustTransaction() { + return this.actionName.equalsIgnoreCase("ADJUSTTRANSACTION"); } public boolean isDepositAccountClose() { @@ -795,8 +833,4 @@ public class CommandWrapper { } // End - Deposit accounts - - public DepositAccountType depositAccountType(){ - return this.depositAccountType; - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java index 66a314e8d..a829e809a 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java @@ -6,7 +6,6 @@ package org.mifosplatform.commands.service; import org.mifosplatform.commands.domain.CommandWrapper; -import org.mifosplatform.portfolio.savings.DepositAccountType; public class CommandWrapperBuilder { @@ -24,13 +23,11 @@ public class CommandWrapperBuilder { private String transactionId; private Long productId; private Long templateId; - private Long interestRatechartId; - private DepositAccountType depositAccountType; public CommandWrapper build() { return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId, this.actionName, this.entityName, this.entityId, this.subentityId, this.href, this.json, this.transactionId, this.productId, - this.templateId, this.interestRatechartId, this.depositAccountType); + this.templateId); } public CommandWrapperBuilder withLoanId(final Long withLoanId) { @@ -1185,7 +1182,7 @@ public class CommandWrapperBuilder { this.actionName = "CREATE"; this.entityName = "CHARTSLAB"; this.entityId = null; - this.interestRatechartId = chartId; + this.subentityId = chartId; //refer to chart id this.href = "/interestratechart/" + chartId + "/chartdetails/template"; return this; } @@ -1194,7 +1191,7 @@ public class CommandWrapperBuilder { this.actionName = "UPDATE"; this.entityName = "CHARTSLAB"; this.entityId = chartSlabId; - this.interestRatechartId = chartId; + this.subentityId = chartId;//refers parent chart this.href = "/interestratechart/" + chartId + "/chartdetails/" + chartSlabId; return this; } @@ -1203,7 +1200,7 @@ public class CommandWrapperBuilder { this.actionName = "DELETE"; this.entityName = "CHARTSLAB"; this.entityId = chartSlabId; - this.interestRatechartId = chartId; + this.subentityId = chartId;//refers parent chart this.href = "/interestratechart/" + chartId + "/chartdetails/" + chartSlabId; return this; } @@ -1698,7 +1695,6 @@ public class CommandWrapperBuilder { this.actionName = "CREATE"; this.entityName = "FIXEDDEPOSITACCOUNT"; this.entityId = null; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/template"; return this; } @@ -1707,7 +1703,6 @@ public class CommandWrapperBuilder { this.actionName = "UPDATE"; this.entityName = "FIXEDDEPOSITACCOUNT"; this.entityId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId; return this; } @@ -1716,7 +1711,6 @@ public class CommandWrapperBuilder { this.actionName = "DELETE"; this.entityName = "FIXEDDEPOSITACCOUNT"; this.entityId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId; return this; } @@ -1726,7 +1720,6 @@ public class CommandWrapperBuilder { this.entityName = "FIXEDDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId + "?command=reject"; return this; } @@ -1736,7 +1729,6 @@ public class CommandWrapperBuilder { this.entityName = "FIXEDDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId + "?command=withdrawnByApplicant"; return this; } @@ -1746,7 +1738,6 @@ public class CommandWrapperBuilder { this.entityName = "FIXEDDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId + "?command=approve"; return this; } @@ -1756,7 +1747,6 @@ public class CommandWrapperBuilder { this.entityName = "FIXEDDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId + "?command=undoapproval"; return this; } @@ -1766,7 +1756,6 @@ public class CommandWrapperBuilder { this.entityName = "FIXEDDEPOSITACCOUNT"; this.savingsId = accountId; this.entityId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId + "?command=activate"; return this; } @@ -1776,7 +1765,6 @@ public class CommandWrapperBuilder { this.entityName = "FIXEDDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId + "?command=close"; return this; } @@ -1786,7 +1774,6 @@ public class CommandWrapperBuilder { this.entityName = "FIXEDDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId + "?command=prematureClose"; return this; } @@ -1796,7 +1783,6 @@ public class CommandWrapperBuilder { this.entityName = "FIXEDDEPOSITACCOUNT"; this.savingsId = accountId; this.entityId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId + "?command=calculateInterest"; return this; } @@ -1806,7 +1792,6 @@ public class CommandWrapperBuilder { this.entityName = "FIXEDDEPOSITACCOUNT"; this.savingsId = accountId; this.entityId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.href = "/fixeddepositaccounts/" + accountId + "?command=postInterest"; return this; } @@ -1815,7 +1800,6 @@ public class CommandWrapperBuilder { this.actionName = "DEPOSIT"; this.entityName = "FIXEDDEPOSITACCOUNT"; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.entityId = accountId; this.href = "/fixeddepositaccounts/" + accountId + "/transactions?command=deposit"; return this; @@ -1825,7 +1809,6 @@ public class CommandWrapperBuilder { this.actionName = "WITHDRAWAL"; this.entityName = "FIXEDDEPOSITACCOUNT"; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.FIXED_DEPOSIT; this.entityId = accountId; this.href = "/fixeddepositaccounts/" + accountId + "/transactions?command=withdrawal"; return this; @@ -1835,7 +1818,6 @@ public class CommandWrapperBuilder { this.actionName = "CREATE"; this.entityName = "RECURRINGDEPOSITACCOUNT"; this.entityId = null; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/template"; return this; } @@ -1844,7 +1826,6 @@ public class CommandWrapperBuilder { this.actionName = "UPDATE"; this.entityName = "RECURRINGDEPOSITACCOUNT"; this.entityId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId; return this; } @@ -1853,7 +1834,6 @@ public class CommandWrapperBuilder { this.actionName = "DEPOSIT"; this.entityName = "RECURRINGDEPOSITACCOUNT"; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.entityId = accountId; this.href = "/recurringdepositaccounts/" + accountId + "/transactions?command=deposit"; return this; @@ -1863,7 +1843,6 @@ public class CommandWrapperBuilder { this.actionName = "WITHDRAWAL"; this.entityName = "RECURRINGDEPOSITACCOUNT"; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.entityId = accountId; this.href = "/recurringdepositaccounts/" + accountId + "/transactions?command=withdrawal"; return this; @@ -1874,7 +1853,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.savingsId = accountId; this.entityId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.subentityId = transactionId; this.transactionId = transactionId.toString(); this.href = "/recurringdepositaccounts/" + accountId + "/transactions/" + transactionId + "?command=modify"; @@ -1886,7 +1864,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.savingsId = accountId; this.entityId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.subentityId = transactionId; this.transactionId = transactionId.toString(); this.href = "/recurringdepositaccounts/" + accountId + "/transactions/" + transactionId + "?command=undo"; @@ -1897,7 +1874,6 @@ public class CommandWrapperBuilder { this.actionName = "DELETE"; this.entityName = "RECURRINGDEPOSITACCOUNT"; this.entityId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId; return this; } @@ -1907,7 +1883,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId + "?command=reject"; return this; } @@ -1917,7 +1892,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId + "?command=withdrawnByApplicant"; return this; } @@ -1927,7 +1901,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId + "?command=approve"; return this; } @@ -1937,7 +1910,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId + "?command=undoapproval"; return this; } @@ -1947,7 +1919,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.savingsId = accountId; this.entityId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId + "?command=activate"; return this; } @@ -1957,7 +1928,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId + "?command=close"; return this; } @@ -1967,7 +1937,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.entityId = accountId; this.savingsId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId + "?command=prematureClose"; return this; } @@ -1977,7 +1946,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.savingsId = accountId; this.entityId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId + "?command=calculateInterest"; return this; } @@ -1987,7 +1955,6 @@ public class CommandWrapperBuilder { this.entityName = "RECURRINGDEPOSITACCOUNT"; this.savingsId = accountId; this.entityId = accountId; - this.depositAccountType = DepositAccountType.RECURRING_DEPOSIT; this.href = "/recurringdepositaccounts/" + accountId + "?command=postInterest"; return this; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java index d77700c92..86f210042 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java @@ -68,8 +68,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json); final JsonCommand command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), wrapper.getEntityId(), wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), - wrapper.getSavingsId(), wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId(), - wrapper.interestRatechartId(), wrapper.depositAccountType()); + wrapper.getSavingsId(), wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId()); result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker); } catch (final RollbackTransactionAsCommandIsNotApprovedByCheckerException e) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java index f98c29e04..d84b499ca 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java @@ -503,43 +503,87 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer } else { throw new UnsupportedCommandException(wrapper.commandName()); } - } else if (wrapper.isDepositAccountResource()) { + } else if (wrapper.isFixedDepositAccountResource()) { if (wrapper.isCreate()) { - handler = this.applicationContext - .getBean("depositAccountApplicationSubmittalCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isUpdate()) { - handler = this.applicationContext.getBean("depositAccountApplicationModificationCommandHandler", + handler = this.applicationContext.getBean("fixedDepositAccountApplicationSubmittalCommandHandler", + NewCommandSourceHandler.class); + }else if (wrapper.isUpdate()) { + handler = this.applicationContext.getBean("fixedDepositAccountApplicationModificationCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = this.applicationContext.getBean("depositAccountApplicationDeletionCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isRejectionOfDepositAccountApplication()) { - handler = this.applicationContext.getBean("depositAccountApplicationRejectedCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isWithdrawFromDepositAccountApplicationByApplicant()) { - handler = this.applicationContext.getBean("depositAccountApplicationWithdrawnByApplicantCommandHandler", + handler = this.applicationContext.getBean("fixedDepositAccountApplicationDeletionCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isApprovalOfDepositAccountApplication()) { - handler = this.applicationContext.getBean("depositAccountApplicationApprovalCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isUndoApprovalOfDepositAccountApplication()) { - handler = this.applicationContext.getBean("depositAccountApplicationApprovalUndoCommandHandler", + } else if (wrapper.isRejectionOfFixedDepositAccountApplication()) { + handler = this.applicationContext.getBean("fixedDepositAccountApplicationRejectedCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isDepositAccountDeposit()) { - handler = this.applicationContext.getBean("depositAccountDepositCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isDepositAccountWithdrawal()) { - handler = this.applicationContext.getBean("withdrawDepositAccountCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isDepositAccountActivation()) { - handler = this.applicationContext.getBean("activateDepositAccountCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isDepositAccountInterestCalculation()) { - handler = this.applicationContext.getBean("calculateInterestDepositAccountCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isDepositAccountInterestPosting()) { - handler = this.applicationContext.getBean("postInterestDepositAccountCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isDepositAccountUndoTransaction()) { - handler = this.applicationContext.getBean("undoTransactionDepositAccountCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isAdjustDeopsitAccountTransaction()) { - handler = this.applicationContext.getBean("depositTransactionAdjustmentCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isWithdrawFixedDepositAccountApplicationByApplicant()) { + handler = this.applicationContext.getBean("fixedDepositAccountApplicationWithdrawnByApplicantCommandHandler", + NewCommandSourceHandler.class); + } else if (wrapper.isApprovalOfFixedDepositAccountApplication()) { + handler = this.applicationContext.getBean("fixedDepositAccountApplicationApprovalCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isUndoApprovalOfFixedDepositAccountApplication()) { + handler = this.applicationContext.getBean("fixedDepositAccountApplicationApprovalUndoCommandHandler", + NewCommandSourceHandler.class); + } else if (wrapper.isDeposit()) { + handler = this.applicationContext.getBean("fixedDepositAccountDepositCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isWithdrawal()) { + handler = this.applicationContext.getBean("withdrawalFixedDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isActivation()) { + handler = this.applicationContext.getBean("activateFixedDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isInterestCalculation()) { + handler = this.applicationContext.getBean("calculateInterestFixedDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isInterestPosting()) { + handler = this.applicationContext.getBean("postInterestFixedDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isUndoTransaction()) { + handler = this.applicationContext.getBean("undoTransactionFixedDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isAdjustTransaction()) { + handler = this.applicationContext.getBean("fixedDepositTransactionAdjustmentCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDepositAccountClose()) { - handler = this.applicationContext.getBean("closeDepositAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("closeFixedDepositAccountCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDepositAccountPrematureClose()) { - handler = this.applicationContext.getBean("prematureCloseDepositAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("prematureCloseFixedDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else { + throw new UnsupportedCommandException(wrapper.commandName()); + } + } else if (wrapper.isRecurringDepositAccountResource()) { + if (wrapper.isCreate()) { + handler = this.applicationContext.getBean("recurringDepositAccountApplicationSubmittalCommandHandler", + NewCommandSourceHandler.class); + }else if (wrapper.isUpdate()) { + handler = this.applicationContext.getBean("recurringDepositAccountApplicationModificationCommandHandler", + NewCommandSourceHandler.class); + } else if (wrapper.isDelete()) { + handler = this.applicationContext.getBean("recurringDepositAccountApplicationDeletionCommandHandler", + NewCommandSourceHandler.class); + } else if (wrapper.isRejectionOfRecurringDepositAccountApplication()) { + handler = this.applicationContext.getBean("recurringDepositAccountApplicationRejectedCommandHandler", + NewCommandSourceHandler.class); + } else if (wrapper.isWithdrawRecurringDepositAccountApplicationByApplicant()) { + handler = this.applicationContext.getBean("recurringDepositAccountApplicationWithdrawnByApplicantCommandHandler", + NewCommandSourceHandler.class); + } else if (wrapper.isApprovalOfRecurringDepositAccountApplication()) { + handler = this.applicationContext.getBean("recurringDepositAccountApplicationApprovalCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isUndoApprovalOfRecurringDepositAccountApplication()) { + handler = this.applicationContext.getBean("recurringDepositAccountApplicationApprovalUndoCommandHandler", + NewCommandSourceHandler.class); + } else if (wrapper.isDeposit()) { + handler = this.applicationContext.getBean("recurringDepositAccountDepositCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isWithdrawal()) { + handler = this.applicationContext.getBean("withdrawalRecurringDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isActivation()) { + handler = this.applicationContext.getBean("activateRecurringDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isInterestCalculation()) { + handler = this.applicationContext.getBean("calculateInterestRecurringDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isInterestPosting()) { + handler = this.applicationContext.getBean("postInterestRecurringDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isUndoTransaction()) { + handler = this.applicationContext.getBean("undoTransactionRecurringDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isAdjustTransaction()) { + handler = this.applicationContext.getBean("recurringDepositTransactionAdjustmentCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isDepositAccountClose()) { + handler = this.applicationContext.getBean("closeRecurringDepositAccountCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isDepositAccountPrematureClose()) { + handler = this.applicationContext.getBean("prematureCloseRecurringDepositAccountCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ConfigurationDomainService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ConfigurationDomainService.java index 4e1502dda..42f68170d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ConfigurationDomainService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ConfigurationDomainService.java @@ -34,4 +34,8 @@ public interface ConfigurationDomainService { Long retrievePasswordLiveTime(); Long retrieveGraceOnPenaltyPostingPeriod(); + + Long ageLimitForSeniorCitizen(); + + Long ageLimitForChildren(); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ConfigurationDomainServiceJpa.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ConfigurationDomainServiceJpa.java index fa6ee9bbe..938278623 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ConfigurationDomainServiceJpa.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/domain/ConfigurationDomainServiceJpa.java @@ -135,4 +135,19 @@ public class ConfigurationDomainServiceJpa implements ConfigurationDomainService final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); return property.getValue(); } + + @Override + public Long ageLimitForSeniorCitizen() { + final String propertyName = "age_limit_for_senior_citizen"; + final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); + return property.getValue(); + } + + @Override + public Long ageLimitForChildren() { + final String propertyName = "age_limit_for_children"; + final GlobalConfigurationProperty property = this.globalConfigurationRepository.findOneByNameWithNotFoundDetection(propertyName); + return property.getValue(); + } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java index 784645361..53cec0aa6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java @@ -21,7 +21,6 @@ import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; import org.mifosplatform.infrastructure.security.domain.BasicPasswordEncodablePlatformUser; import org.mifosplatform.infrastructure.security.domain.PlatformUser; import org.mifosplatform.infrastructure.security.service.PlatformPasswordEncoder; -import org.mifosplatform.portfolio.savings.DepositAccountType; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -49,35 +48,28 @@ public final class JsonCommand { private final String transactionId; private final String url; private final Long productId; - private final Long interestRateChartId; - private final DepositAccountType depositAccountType; public static JsonCommand from(final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId, final Long groupId, final Long clientId, - final Long loanId, final Long savingsId, final String transactionId, final String url, final Long productId, - final Long interestRateChartId, final DepositAccountType depositAccountType) { + final Long loanId, final Long savingsId, final String transactionId, final String url, final Long productId) { return new JsonCommand(null, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId, - clientId, loanId, savingsId, transactionId, url, productId, interestRateChartId, depositAccountType); + clientId, loanId, savingsId, transactionId, url, productId); } public static JsonCommand fromExistingCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId, final String url, final Long productId) { - final Long interestRateChartId = null; - final DepositAccountType depositAccountType = null; return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, null, null, - null, null, null, url, productId, interestRateChartId, depositAccountType); + null, null, null, url, productId); } public static JsonCommand fromExistingCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId, final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final String url, final Long productId) { - final Long interestRateChartId = null; - final DepositAccountType depositAccountType = null; return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subresourceId, groupId, - clientId, loanId, savingsId, transactionId, url, productId, interestRateChartId, depositAccountType); + clientId, loanId, savingsId, transactionId, url, productId); } @@ -85,13 +77,13 @@ public final class JsonCommand { final String jsonCommand = command.fromApiJsonHelper.toJson(parsedCommand); return new JsonCommand(command.commandId, jsonCommand, parsedCommand, command.fromApiJsonHelper, command.entityName, command.resourceId, command.subresourceId, command.groupId, command.clientId, command.loanId, command.savingsId, - command.transactionId, command.url, command.productId, command.interestRateChartId, command.depositAccountType); + command.transactionId, command.url, command.productId); } public JsonCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long subresourceId, final Long groupId, final Long clientId, final Long loanId, final Long savingsId, final String transactionId, final String url, - final Long productId, final Long interestRateChartId, final DepositAccountType depositAccountType) { + final Long productId) { this.commandId = commandId; this.jsonCommand = jsonCommand; @@ -107,8 +99,6 @@ public final class JsonCommand { this.transactionId = transactionId; this.url = url; this.productId = productId; - this.interestRateChartId = interestRateChartId; - this.depositAccountType = depositAccountType; } public String json() { @@ -503,12 +493,5 @@ public final class JsonCommand { public void checkForUnsupportedParameters(final Type typeOfMap, final String json, final Set requestDataParameters) { this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, requestDataParameters); } - - public Long interestRateChartId() { - return this.interestRateChartId; - } - - public DepositAccountType depositAccounttype() { - return this.depositAccountType; - } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/data/AccountTransferDTO.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/data/AccountTransferDTO.java index e938d122c..1bce5f8f6 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/data/AccountTransferDTO.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/data/AccountTransferDTO.java @@ -32,14 +32,15 @@ public class AccountTransferDTO { private final String noteText; private final String txnExternalId; private final Loan loan; - private final SavingsAccount savingsAccount; - + private final SavingsAccount toSavingsAccount; + private final SavingsAccount fromSavingsAccount; + public AccountTransferDTO(final LocalDate transactionDate, final BigDecimal transactionAmount, final PortfolioAccountType fromAccountType, final PortfolioAccountType toAccountType, final Long fromAccountId, final Long toAccountId, final String description, final Locale locale, final DateTimeFormatter fmt, final PaymentDetail paymentDetail, final Integer fromTransferType, final Integer toTransferType, final Long chargeId, Integer loanInstallmentNumber, Integer transferType, final AccountTransferDetails accountTransferDetails, - final String noteText, final String txnExternalId, final Loan loan, SavingsAccount savingsAccount) { + final String noteText, final String txnExternalId, final Loan loan, SavingsAccount toSavingsAccount, final SavingsAccount fromSavingsAccount) { this.transactionDate = transactionDate; this.transactionAmount = transactionAmount; this.fromAccountType = fromAccountType; @@ -59,7 +60,8 @@ public class AccountTransferDTO { this.noteText = noteText; this.txnExternalId = txnExternalId; this.loan = loan; - this.savingsAccount = savingsAccount; + this.toSavingsAccount = toSavingsAccount; + this.fromSavingsAccount = fromSavingsAccount; } public LocalDate getTransactionDate() { @@ -138,8 +140,12 @@ public class AccountTransferDTO { return this.loan; } - public SavingsAccount getSavingsAccount() { - return this.savingsAccount; + public SavingsAccount getToSavingsAccount() { + return this.toSavingsAccount; + } + + public SavingsAccount getFromSavingsAccount() { + return this.fromSavingsAccount; } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/domain/AccountAssociations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/domain/AccountAssociations.java index d17b05c65..76b72ccfa 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/domain/AccountAssociations.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/domain/AccountAssociations.java @@ -13,17 +13,14 @@ import org.springframework.data.jpa.domain.AbstractPersistable; @Table(name = "m_portfolio_account_associations") public class AccountAssociations extends AbstractPersistable { - @SuppressWarnings("unused") @ManyToOne @JoinColumn(name = "loan_account_id", nullable = true) private Loan loanAccount; - @SuppressWarnings("unused") @ManyToOne @JoinColumn(name = "savings_account_id", nullable = true) private SavingsAccount savingsAccount; - @SuppressWarnings("unused") @ManyToOne @JoinColumn(name = "linked_loan_account_id", nullable = true) private Loan linkedLoanAccount; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransferEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransferEnumerations.java index 149d001db..80a501d79 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransferEnumerations.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransferEnumerations.java @@ -86,6 +86,10 @@ public class AccountTransferEnumerations { optionData = new EnumOptionData(AccountTransferType.CHARGE_PAYMENT.getValue().longValue(), AccountTransferType.CHARGE_PAYMENT.getCode(), "Charge Payment"); break; + case INTEREST_TRANSFER: + optionData = new EnumOptionData(AccountTransferType.INTEREST_TRANSFER.getValue().longValue(), + AccountTransferType.INTEREST_TRANSFER.getCode(), "Interest Transfer"); + break; } } return optionData; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java index 983c3333e..9b9957b44 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/AccountTransfersWritePlatformServiceImpl.java @@ -274,11 +274,15 @@ public class AccountTransfersWritePlatformServiceImpl implements AccountTransfer SavingsAccount fromSavingsAccount = null; SavingsAccount toSavingsAccount = null; if (accountTransferDetails == null) { - fromSavingsAccount = this.savingsAccountAssembler.assembleFrom(accountTransferDTO.getFromAccountId()); - if (accountTransferDTO.getSavingsAccount() == null) { + if (accountTransferDTO.getFromSavingsAccount() == null) { + fromSavingsAccount = this.savingsAccountAssembler.assembleFrom(accountTransferDTO.getFromAccountId()); + }else{ + fromSavingsAccount = accountTransferDTO.getFromSavingsAccount(); + } + if (accountTransferDTO.getToSavingsAccount() == null) { toSavingsAccount = this.savingsAccountAssembler.assembleFrom(accountTransferDTO.getToAccountId()); } else { - toSavingsAccount = accountTransferDTO.getSavingsAccount(); + toSavingsAccount = accountTransferDTO.getToSavingsAccount(); } } else { fromSavingsAccount = accountTransferDetails.fromSavingsAccount(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java index b7522e60a..bb46a0324 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/account/service/StandingInstructionWritePlatformServiceImpl.java @@ -42,6 +42,7 @@ import org.mifosplatform.portfolio.account.exception.StandingInstructionNotFound import org.mifosplatform.portfolio.common.domain.PeriodFrequencyType; import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.DefaultScheduledDateGenerator; import org.mifosplatform.portfolio.loanaccount.loanschedule.domain.ScheduledDateGenerator; +import org.mifosplatform.portfolio.savings.domain.SavingsAccount; import org.mifosplatform.portfolio.savings.exception.InsufficientAccountBalanceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -213,11 +214,12 @@ public class StandingInstructionWritePlatformServiceImpl implements StandingInst if (isDueForTransfer && transactionAmount != null && transactionAmount.compareTo(BigDecimal.ZERO) > 0) { final AccountTransferDetails accountTransferDetails = this.accountTransferDetailRepository.findOne(data.accountDetailId()); + final SavingsAccount fromSavingsAccount = null; accountTransferDetails.accountTransferStandingInstruction().updateLatsRunDate(transactionDate.toDate()); AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, transactionAmount, data.fromAccountType(), data.toAccountType(), data.fromAccount().accountId(), data.toAccount().accountId(), data.name() + " Standing instruction trasfer ", null, null, null, null, data.toTransferType(), null, null, data - .transferType().getValue(), accountTransferDetails, null, null, null, null); + .transferType().getValue(), accountTransferDetails, null, null, null, null, fromSavingsAccount); transferAmount(sb, accountTransferDTO, data.getId()); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/api/CalendarsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/api/CalendarsApiResource.java index 8b994a7f5..5d4501901 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/api/CalendarsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/api/CalendarsApiResource.java @@ -236,6 +236,9 @@ public class CalendarsApiResource { case LOANS: resourceDetails.withLoanId(entityId); break; + case SAVINGS: + resourceDetails.withSavingsId(entityId); + break; case INVALID: break; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/data/CalendarData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/data/CalendarData.java index 299438926..5fc7fd785 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/data/CalendarData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/data/CalendarData.java @@ -326,4 +326,12 @@ public class CalendarData { compareDate); } return false; } + + public Integer interval(){ + return this.interval; + } + + public EnumOptionData frequencyType(){ + return this.frequency; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/Calendar.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/Calendar.java index 4722367ab..2041f8a91 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/Calendar.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/Calendar.java @@ -128,6 +128,23 @@ public class Calendar extends AbstractAuditableCustom { this.secondReminder = secondReminder; } + public static Calendar createRepeatingCalendar(final String title, final LocalDate startDate, final Integer typeId, + final CalendarFrequencyType frequencyType, final Integer interval, final Integer repeatsOnDay) { + + final String description = null; + final String location = null; + final LocalDate endDate = null; + final Integer duration = null; + final boolean repeating = true; + final Integer remindById = null; + final Integer firstReminder = null; + final Integer secondReminder = null; + final String recurrence = constructRecurrence(frequencyType, interval, repeatsOnDay); + + return new Calendar(title, description, location, startDate, endDate, duration, typeId, repeating, recurrence, remindById, + firstReminder, secondReminder); + } + public static Calendar fromJson(final JsonCommand command) { // final Long entityId = command.getSupportedEntityId(); @@ -301,6 +318,25 @@ public class Calendar extends AbstractAuditableCustom { return actualChanges; } + + @SuppressWarnings("null") + public Map updateRepeatingCalendar(final LocalDate calendarStartDate, final CalendarFrequencyType frequencyType, final Integer interval, final Integer repeatsOnDay){ + final Map actualChanges = new LinkedHashMap(9); + + if(calendarStartDate != null & this.startDate != null){ + if(!calendarStartDate.equals(this.getStartDateLocalDate())){ + actualChanges.put("startDate", calendarStartDate); + this.startDate = calendarStartDate.toDate(); + } + } + + final String newRecurrence = Calendar.constructRecurrence(frequencyType, interval, repeatsOnDay); + if (!StringUtils.isBlank(this.recurrence) && !newRecurrence.equalsIgnoreCase(this.recurrence)) { + actualChanges.put("recurrence", newRecurrence); + this.recurrence = newRecurrence; + } + return actualChanges; + } public String getTitle() { return this.title; @@ -419,29 +455,38 @@ public class Calendar extends AbstractAuditableCustom { } if (repeating) { - final StringBuilder recurrenceBuilder = new StringBuilder(200); final Integer frequency = command.integerValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.FREQUENCY.getValue()); final CalendarFrequencyType frequencyType = CalendarFrequencyType.fromInt(frequency); - recurrenceBuilder.append("FREQ="); - recurrenceBuilder.append(frequencyType.toString().toUpperCase()); final Integer interval = command.integerValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.INTERVAL.getValue()); - if (interval > 1) { - recurrenceBuilder.append(";INTERVAL="); - recurrenceBuilder.append(interval); - } + Integer repeatsOnDay = null; if (frequencyType.isWeekly()) { - final Integer repeatsOnDay = command.integerValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_ON_DAY.getValue()); - final CalendarWeekDaysType weekDays = CalendarWeekDaysType.fromInt(repeatsOnDay); - if (!weekDays.isInvalid()) { - recurrenceBuilder.append(";BYDAY="); - recurrenceBuilder.append(weekDays.toString().toUpperCase()); - } + repeatsOnDay = command.integerValueOfParameterNamed(CALENDAR_SUPPORTED_PARAMETERS.REPEATS_ON_DAY.getValue()); } - return recurrenceBuilder.toString(); + + return constructRecurrence(frequencyType, interval, repeatsOnDay); } return ""; } + private static String constructRecurrence(final CalendarFrequencyType frequencyType, final Integer interval, final Integer repeatsOnDay) { + final StringBuilder recurrenceBuilder = new StringBuilder(200); + + recurrenceBuilder.append("FREQ="); + recurrenceBuilder.append(frequencyType.toString().toUpperCase()); + if (interval > 1) { + recurrenceBuilder.append(";INTERVAL="); + recurrenceBuilder.append(interval); + } + if (frequencyType.isWeekly()) { + final CalendarWeekDaysType weekDays = CalendarWeekDaysType.fromInt(repeatsOnDay); + if (!weekDays.isInvalid()) { + recurrenceBuilder.append(";BYDAY="); + recurrenceBuilder.append(weekDays.toString().toUpperCase()); + } + } + return recurrenceBuilder.toString(); + } + public boolean isValidRecurringDate(final LocalDate compareDate) { if (isBetweenStartAndEndDate(compareDate)) { return CalendarUtils.isValidRedurringDate(getRecurrence(), getStartDateLocalDate(), diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarEntityType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarEntityType.java index d3458b74b..2641d020e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarEntityType.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarEntityType.java @@ -11,7 +11,7 @@ import java.util.Map; public enum CalendarEntityType { INVALID(0, "calendarEntityType.invalid"), CLIENTS(1, "calendarEntityType.clients"), GROUPS(2, "calendarEntityType.groups"), LOANS(3, - "calendarEntityType.loans"), CENTERS(4, "calendarEntityType.centers"); + "calendarEntityType.loans"), CENTERS(4, "calendarEntityType.centers"), SAVINGS(5, "calendarEntityType.savings"); private final Integer value; private final String code; @@ -126,5 +126,17 @@ public enum CalendarEntityType { public static CalendarEntityType getEntityType(String entityType) { return entityNameToEnumMap.get(entityType.toLowerCase()); } + + public static boolean isSavings(final Integer value) { + return CalendarEntityType.SAVINGS.value.equals(value) ? true : false; + } + + public static boolean isSavings(final String name) { + return CalendarEntityType.SAVINGS.name().equalsIgnoreCase(name) ? true : false; + } + + public boolean isSavings() { + return this.value.equals(CalendarEntityType.SAVINGS.getValue()); + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarFrequencyType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarFrequencyType.java index f4985d3d0..7a7be41f0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarFrequencyType.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarFrequencyType.java @@ -8,6 +8,7 @@ package org.mifosplatform.portfolio.calendar.domain; import java.util.HashMap; import java.util.Map; +import org.mifosplatform.portfolio.common.domain.PeriodFrequencyType; import org.springframework.util.StringUtils; public enum CalendarFrequencyType { @@ -84,4 +85,44 @@ public enum CalendarFrequencyType { public boolean isInvalid() { return this.value.equals(CalendarFrequencyType.INVALID.value); } + + /** To convert from period frequency type tp calendar frequency type. + * This method requires code refactoring. + * @param periodFrequencyType + * @return + */ + public static CalendarFrequencyType from(final PeriodFrequencyType periodFrequencyType) { + switch (periodFrequencyType) { + case DAYS: + return CalendarFrequencyType.DAILY; + case WEEKS: + return CalendarFrequencyType.WEEKLY; + case MONTHS: + return CalendarFrequencyType.MONTHLY; + case YEARS: + return CalendarFrequencyType.YEARLY; + default: + return CalendarFrequencyType.INVALID; + } + } + + /** To convert from period frequency type tp calendar frequency type. + * This method requires code refactoring. + * @param frequencyType + * @return + */ + public static PeriodFrequencyType from(final CalendarFrequencyType frequencyType) { + switch (frequencyType) { + case DAILY: + return PeriodFrequencyType.DAYS; + case WEEKLY: + return PeriodFrequencyType.WEEKS; + case MONTHLY: + return PeriodFrequencyType.MONTHS; + case YEARLY: + return PeriodFrequencyType.YEARS; + default: + return PeriodFrequencyType.INVALID; + } + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarInstance.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarInstance.java index fba630456..de794ad4a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarInstance.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarInstance.java @@ -5,6 +5,7 @@ */ package org.mifosplatform.portfolio.calendar.domain; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.JoinColumn; @@ -17,7 +18,7 @@ import org.springframework.data.jpa.domain.AbstractPersistable; @Table(name = "m_calendar_instance") public class CalendarInstance extends AbstractPersistable { - @ManyToOne + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "calendar_id", nullable = false) private Calendar calendar; @@ -37,7 +38,7 @@ public class CalendarInstance extends AbstractPersistable { } - public static CalendarInstance fromJson(final Calendar calendar, final Long entityId, final Integer entityTypeId) { + public static CalendarInstance from(final Calendar calendar, final Long entityId, final Integer entityTypeId) { return new CalendarInstance(calendar, entityId, entityTypeId); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarInstanceRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarInstanceRepository.java index 0718ff442..9ee79e294 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarInstanceRepository.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/domain/CalendarInstanceRepository.java @@ -8,17 +8,28 @@ package org.mifosplatform.portfolio.calendar.domain; import java.util.Collection; import java.util.List; +import org.mifosplatform.portfolio.group.domain.Group; +import org.mifosplatform.portfolio.loanaccount.domain.Loan; +import org.mifosplatform.portfolio.savings.domain.SavingsAccount; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import ch.qos.logback.core.net.server.Client; + public interface CalendarInstanceRepository extends JpaRepository, JpaSpecificationExecutor { CalendarInstance findByCalendarIdAndEntityIdAndEntityTypeId(Long calendarId, Long entityId, Integer entityTypeId); Collection findByEntityIdAndEntityTypeId(Long entityId, Integer entityTypeId); + /** + * @param entityId : Id of {@link Client}, {@link Group}, {@link Loan} or {@link SavingsAccount}. + * @param entityTypeId: {@link CalendarEntityType} + * @param calendarTypeId: {@link CalendarType} + * @return + */ CalendarInstance findByEntityIdAndEntityTypeIdAndCalendarTypeId(Long entityId, Integer entityTypeId, Integer calendarTypeId); @Query("from CalendarInstance ci where ci.entityId = :loanId and ci.entityTypeId = :entityTypeId") diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java index a86f50a66..0889895ab 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/calendar/service/CalendarWritePlatformServiceJpaRepositoryImpl.java @@ -138,7 +138,7 @@ public class CalendarWritePlatformServiceJpaRepositoryImpl implements CalendarWr this.calendarRepository.save(newCalendar); - final CalendarInstance newCalendarInstance = CalendarInstance.fromJson(newCalendar, entityId, entityTypeId); + final CalendarInstance newCalendarInstance = CalendarInstance.from(newCalendar, entityId, entityTypeId); this.calendarInstanceRepository.save(newCalendarInstance); return new CommandProcessingResultBuilder() // diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientData.java index bc04f00a9..125f7124a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/data/ClientData.java @@ -65,11 +65,9 @@ final public class ClientData implements Comparable { // template private final Collection officeOptions; private final Collection staffOptions; - @SuppressWarnings("unused") private final Collection closureReasons; private final Collection savingProductOptions; private final Collection savingAccountOptions; - @SuppressWarnings("unused") private final Collection genderOptions; public static ClientData template(final Long officeId, final LocalDate joinedDate, final Collection officeOptions, @@ -87,7 +85,7 @@ final public class ClientData implements Comparable { clientData.transferToOfficeId, clientData.transferToOfficeName, clientData.id, clientData.firstname, clientData.middlename, clientData.lastname, clientData.fullname, clientData.displayName, clientData.externalId, clientData.mobileNo, clientData.dateOfBirth, clientData.gender, clientData.activationDate, clientData.imageId, clientData.staffId, - clientData.staffName, templateData.officeOptions, clientData.groups, templateData.staffOptions, null, null, null, + clientData.staffName, templateData.officeOptions, clientData.groups, templateData.staffOptions, templateData.closureReasons, templateData.genderOptions, clientData.timeline, templateData.savingProductOptions, clientData.savingsProductId, clientData.savingsProductName, clientData.savingsAccountId, clientData.savingAccountOptions); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java index 845f78b6d..dfa5694cd 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java @@ -32,6 +32,7 @@ import org.apache.commons.lang.StringUtils; import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; import org.joda.time.LocalDate; +import org.joda.time.Years; import org.joda.time.format.DateTimeFormatter; import org.mifosplatform.infrastructure.codes.domain.CodeValue; import org.mifosplatform.infrastructure.core.api.JsonCommand; @@ -45,6 +46,7 @@ import org.mifosplatform.organisation.office.domain.Office; import org.mifosplatform.organisation.staff.domain.Staff; import org.mifosplatform.portfolio.client.api.ClientApiConstants; import org.mifosplatform.portfolio.group.domain.Group; +import org.mifosplatform.portfolio.interestratechart.data.ClientIncentiveAttributes; import org.mifosplatform.portfolio.savings.domain.SavingsAccount; import org.mifosplatform.portfolio.savings.domain.SavingsProduct; import org.mifosplatform.useradministration.domain.AppUser; @@ -157,6 +159,9 @@ public final class Client extends AbstractPersistable { @JoinColumn(name = "default_savings_account", nullable = true) private SavingsAccount savingsAccount; + @Transient + private ClientIncentiveAttributes incentiveAttributes; + public static Client createNew(final AppUser currentUser, final Office clientOffice, final Group clientParentGroup, final Staff staff, final SavingsProduct savingsProduct, final CodeValue gender, final JsonCommand command) { @@ -272,7 +277,7 @@ public final class Client extends AbstractPersistable { this.savingsProduct = savingsProduct; this.savingsAccount = savingsAccount; - if(gender != null){ + if (gender != null) { this.gender = gender; } if (dateOfBirth != null) { @@ -692,4 +697,41 @@ public final class Client extends AbstractPersistable { public void updateSavingsAccount(SavingsAccount savingsAccount) { this.savingsAccount = savingsAccount; } + + public ClientIncentiveAttributes incentiveAttributes() { + return this.incentiveAttributes; + } + + public void updateIncentiveAttributes(final Long ageLimitForChildren, final Long ageLimitForSeniorCitizen, final LocalDate compareOnDate) { + boolean isFemale = false; + boolean isChild = false; + boolean isSeniorCitizen = false; + + if (this.gender != null) { + // FIXME: this needs to be handled in better way + if (this.gender.label().equalsIgnoreCase("FEMALE")) { + isFemale = true; + } + } + + if (this.dateOfBirth != null) { + final LocalDate dobLacalDate = LocalDate.fromDateFields(this.dateOfBirth); + final int age = Years.yearsBetween(dobLacalDate, compareOnDate).getYears(); + + if (age >= ageLimitForSeniorCitizen.intValue()) { + isSeniorCitizen = true; + } + + if (age <= ageLimitForChildren.intValue()) { + isChild = true; + } + } + + this.incentiveAttributes = ClientIncentiveAttributes.instance(isFemale, isChild, isSeniorCitizen); + + } + + public CodeValue gender() { + return this.gender; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/CollectionSheetConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/CollectionSheetConstants.java index 63b8361f6..b6616eb85 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/CollectionSheetConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/CollectionSheetConstants.java @@ -20,6 +20,7 @@ public class CollectionSheetConstants { public static final String actualDisbursementDateParamName = "actualDisbursementDate"; public static final String bulkRepaymentTransactionsParamName = "bulkRepaymentTransactions"; public static final String bulkDisbursementTransactionsParamName = "bulkDisbursementTransactions"; + public static final String bulkSavingsDueTransactionsParamName = "bulkSavingsDueTransactions"; public static final String noteParamName = "note"; public static final String calendarIdParamName = "calendarId"; @@ -29,9 +30,10 @@ public class CollectionSheetConstants { public static final String attendanceTypeParamName = "attendanceType"; public static final String loanIdParamName = "loanId"; + public static final String savingsIdParamName = "savingsId"; public static final String transactionAmountParamName = "transactionAmount"; public static final Set COLLECTIONSHEET_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, dateFormatParamName, transactionDateParamName, actualDisbursementDateParamName, bulkRepaymentTransactionsParamName, - bulkDisbursementTransactionsParamName, noteParamName, calendarIdParamName, clientsAttendanceParamName)); + bulkDisbursementTransactionsParamName, noteParamName, calendarIdParamName, clientsAttendanceParamName, bulkSavingsDueTransactionsParamName)); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/CollectionSheetTransactionDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/CollectionSheetTransactionDataValidator.java index d9a7f0170..63bcc46fc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/CollectionSheetTransactionDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/CollectionSheetTransactionDataValidator.java @@ -10,10 +10,12 @@ import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstan import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.attendanceTypeParamName; import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.bulkDisbursementTransactionsParamName; import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.bulkRepaymentTransactionsParamName; +import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.bulkSavingsDueTransactionsParamName; import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.calendarIdParamName; import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.clientIdParamName; import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.clientsAttendanceParamName; import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.loanIdParamName; +import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.savingsIdParamName; import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.noteParamName; import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.transactionAmountParamName; import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.transactionDateParamName; @@ -80,6 +82,8 @@ public class CollectionSheetTransactionDataValidator { validateDisbursementTransactions(element, baseDataValidator); validateRepaymentTransactions(element, baseDataValidator); + + validateSavingsDueTransactions(element, baseDataValidator); throwExceptionIfValidationWarningsExist(dataValidationErrors); } @@ -147,8 +151,31 @@ public class CollectionSheetTransactionDataValidator { } } } + + private void validateSavingsDueTransactions(final JsonElement element, final DataValidatorBuilder baseDataValidator) { + final JsonObject topLevelJsonElement = element.getAsJsonObject(); + final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); + if (element.isJsonObject()) { + if (topLevelJsonElement.has(bulkSavingsDueTransactionsParamName) + && topLevelJsonElement.get(bulkSavingsDueTransactionsParamName).isJsonArray()) { + final JsonArray array = topLevelJsonElement.get(bulkSavingsDueTransactionsParamName).getAsJsonArray(); + + for (int i = 0; i < array.size(); i++) { + final JsonObject savingsTransactionElement = array.get(i).getAsJsonObject(); + final Long savingsId = this.fromApiJsonHelper.extractLongNamed(savingsIdParamName, savingsTransactionElement); + final BigDecimal dueAmount = this.fromApiJsonHelper.extractBigDecimalNamed(transactionAmountParamName, + savingsTransactionElement, locale); + + baseDataValidator.reset().parameter("bulktransaction" + "[" + i + "].savings.id").value(savingsId).notNull() + .integerGreaterThanZero(); + baseDataValidator.reset().parameter("bulktransaction" + "[" + i + "].due.amount").value(dueAmount) + .notNull().zeroOrPositiveAmount(); + } + } + } + } private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } -} \ No newline at end of file +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGClientData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGClientData.java index a0644e3c5..b64a7880e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGClientData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGClientData.java @@ -18,21 +18,50 @@ public class JLGClientData { private final Long clientId; private final String clientName; private Collection loans; + private Collection savings; @SuppressWarnings("unused") private final EnumOptionData attendanceType; - public JLGClientData(final Long clientId, final String clientName, final Collection loans, + public static JLGClientData instance(final Long clientId, final String clientName, final EnumOptionData attendanceType){ + final Collection loans = null; + final Collection savings = null; + return new JLGClientData(clientId, clientName, loans, savings, attendanceType); + } + + public static JLGClientData withSavings(final JLGClientData client, final Collection savings){ + final Collection loans = null; + final EnumOptionData attendanceType = null; + + return new JLGClientData(client.clientId, client.clientName, loans, savings, attendanceType); + } + + /*public JLGClientData(final Long clientId, final String clientName, final Collection loans, final EnumOptionData attendanceType) { this.clientId = clientId; this.clientName = clientName; this.loans = loans; this.attendanceType = attendanceType; - } + }*/ - public JLGClientData(final Long clientId, final String clientName, final EnumOptionData attendanceType) { + public static JLGClientData withAttendance(final Long clientId, final String clientName, final EnumOptionData attendanceType) { + final Collection loans = null; + final Collection savings = null; + return new JLGClientData(clientId, clientName, loans, savings, attendanceType); + } + + /** + * @param clientId + * @param clientName + * @param loans + * @param savings + * @param attendanceType + */ + private JLGClientData(Long clientId, String clientName, Collection loans, Collection savings, + EnumOptionData attendanceType) { this.clientId = clientId; this.clientName = clientName; - this.loans = null; + this.loans = loans; + this.savings = savings; this.attendanceType = attendanceType; } @@ -51,4 +80,24 @@ public class JLGClientData { public void setLoans(final Collection loans) { this.loans = loans; } + + public Collection getSavings() { + return this.savings; + } + + + public void setSavings(Collection savings) { + this.savings = savings; + } + + @Override + public boolean equals(final Object obj) { + final JLGClientData clientData = (JLGClientData) obj; + return clientData.clientId.compareTo(this.clientId) == 0; + } + + @Override + public int hashCode() { + return this.clientId.hashCode(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGCollectionSheetData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGCollectionSheetData.java index c61ffdf44..3ee5503bc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGCollectionSheetData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGCollectionSheetData.java @@ -11,6 +11,7 @@ import java.util.List; import org.joda.time.LocalDate; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.portfolio.loanproduct.data.LoanProductData; +import org.mifosplatform.portfolio.savings.data.SavingsProductData; /** * Immutable data object for join liability group's collection sheet. @@ -19,14 +20,27 @@ public class JLGCollectionSheetData { private final LocalDate dueDate; private final Collection loanProducts; - private final Collection groups; @SuppressWarnings("unused") + private final Collection savingsProducts; + private final Collection groups; private final List attendanceTypeOptions; - public JLGCollectionSheetData(final LocalDate date, final Collection loanProducts, + public static JLGCollectionSheetData instance(final LocalDate date, final Collection loanProducts, final Collection groups, final List attendanceTypeOptions) { - this.dueDate = date; + return new JLGCollectionSheetData(date, loanProducts, null, groups, attendanceTypeOptions); + } + + public static JLGCollectionSheetData withSavingsProducts(final JLGCollectionSheetData data, + final Collection savingsProducts) { + + return new JLGCollectionSheetData(data.dueDate, data.loanProducts, savingsProducts, data.groups, data.attendanceTypeOptions); + } + + private JLGCollectionSheetData(LocalDate dueDate, Collection loanProducts, + Collection savingsProducts, Collection groups, List attendanceTypeOptions) { + this.dueDate = dueDate; this.loanProducts = loanProducts; + this.savingsProducts = savingsProducts; this.groups = groups; this.attendanceTypeOptions = attendanceTypeOptions; } @@ -42,4 +56,5 @@ public class JLGCollectionSheetData { public Collection getLoanProducts() { return this.loanProducts; } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGCollectionSheetFlatData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGCollectionSheetFlatData.java index 5d82309ec..31afe46f4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGCollectionSheetFlatData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGCollectionSheetFlatData.java @@ -153,12 +153,12 @@ public class JLGCollectionSheetFlatData { } public JLGClientData getClientData() { - return new JLGClientData(this.clientId, this.clientName, this.attendanceType); + return JLGClientData.withAttendance(this.clientId, this.clientName, this.attendanceType); } public JLGGroupData getJLGGroupData() { - return new JLGGroupData(this.groupId, this.groupName, this.staffId, this.staffName, this.levelId, this.levelName); + return JLGGroupData.instance(this.groupId, this.groupName, this.staffId, this.staffName, this.levelId, this.levelName); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGGroupData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGGroupData.java index d825680da..84fa5a4dd 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGGroupData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/JLGGroupData.java @@ -21,14 +21,24 @@ public class JLGGroupData { private final String levelName; private Collection clients; - public JLGGroupData(final Long groupId, final String groupName, final Long staffId, final String staffName, final Long levelId, - final String levelName) { + public static JLGGroupData instance(final Long groupId, final String groupName, final Long staffId, final String staffName, final Long levelId, + final String levelName){ + return new JLGGroupData(groupId, groupName, staffId, staffName, levelId, levelName, null); + } + + public static JLGGroupData withClients(final JLGGroupData group, Collection clients){ + return new JLGGroupData(group.groupId, group.groupName, group.staffId, group.staffName, group.levelId, group.levelName, clients); + } + + private JLGGroupData(final Long groupId, final String groupName, final Long staffId, final String staffName, final Long levelId, + final String levelName, final Collection clients) { this.groupId = groupId; this.groupName = groupName; this.staffId = staffId; this.staffName = staffName; this.levelId = levelId; this.levelName = levelName; + this.clients = clients; } public Long getGroupId() { @@ -62,4 +72,15 @@ public class JLGGroupData { public void setClients(final Collection clients) { this.clients = clients; } + + @Override + public boolean equals(final Object obj) { + final JLGGroupData groupData = (JLGGroupData) obj; + return groupData.groupId.compareTo(this.groupId) == 0; + } + + @Override + public int hashCode() { + return this.groupId.hashCode(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/SavingsDueData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/SavingsDueData.java new file mode 100644 index 000000000..20d26ed9a --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/data/SavingsDueData.java @@ -0,0 +1,55 @@ +/** + * 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.collectionsheet.data; + +import java.math.BigDecimal; + +import org.mifosplatform.organisation.monetary.data.CurrencyData; + +/** + * Immutable data object for representing loan with dues (example: loan is due + * for disbursement, repayments). + */ +public class SavingsDueData { + + @SuppressWarnings("unused") + private final Long savingsId; + @SuppressWarnings("unused") + private final String accountId; + @SuppressWarnings("unused") + private final Integer accountStatusId; + private final String productName; + private final Long productId; + @SuppressWarnings("unused") + private final CurrencyData currency; + @SuppressWarnings("unused") + private BigDecimal dueAmount = BigDecimal.ZERO; + + public static SavingsDueData instance(final Long savingsId, final String accountId, final Integer accountStatusId, + final String productName, final Long productId, final CurrencyData currency, final BigDecimal dueAmount) { + return new SavingsDueData(savingsId, accountId, accountStatusId, productName, productId, currency, dueAmount); + } + + private SavingsDueData(final Long savingsId, final String accountId, final Integer accountStatusId, final String productName, + final Long productId, final CurrencyData currency, final BigDecimal dueAmount) { + this.savingsId = savingsId; + this.accountId = accountId; + this.accountStatusId = accountStatusId; + this.productName = productName; + this.productId = productId; + this.currency = currency; + this.dueAmount = dueAmount; + } + + public String productName() { + return this.productName; + } + + public Long productId() { + return this.productId; + } + +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java index 19582312a..ca2719d9b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java @@ -35,6 +35,7 @@ import org.mifosplatform.portfolio.collectionsheet.data.JLGCollectionSheetData; import org.mifosplatform.portfolio.collectionsheet.data.JLGCollectionSheetFlatData; import org.mifosplatform.portfolio.collectionsheet.data.JLGGroupData; import org.mifosplatform.portfolio.collectionsheet.data.LoanDueData; +import org.mifosplatform.portfolio.collectionsheet.data.SavingsDueData; import org.mifosplatform.portfolio.collectionsheet.serialization.CollectionSheetGenerateCommandFromApiJsonDeserializer; import org.mifosplatform.portfolio.group.data.CenterData; import org.mifosplatform.portfolio.group.data.GroupGeneralData; @@ -43,8 +44,11 @@ import org.mifosplatform.portfolio.group.service.GroupReadPlatformService; import org.mifosplatform.portfolio.loanproduct.data.LoanProductData; import org.mifosplatform.portfolio.meeting.attendance.service.AttendanceDropdownReadPlatformService; import org.mifosplatform.portfolio.meeting.attendance.service.AttendanceEnumerations; +import org.mifosplatform.portfolio.savings.data.SavingsProductData; import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; @@ -61,6 +65,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe private final CollectionSheetGenerateCommandFromApiJsonDeserializer collectionSheetGenerateCommandFromApiJsonDeserializer; private final CalendarRepositoryWrapper calendarRepositoryWrapper; private final AttendanceDropdownReadPlatformService attendanceDropdownReadPlatformService; + final MandatorySavingsCollectionsheetExtractor mandatorySavingsExtractor = new MandatorySavingsCollectionsheetExtractor(); @Autowired public CollectionSheetReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource, @@ -162,7 +167,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe jlgGroupsData.add(jlgGroupData); } - jlgCollectionSheetData = new JLGCollectionSheetData(dueDate, loanProducts, jlgGroupsData, + jlgCollectionSheetData = JLGCollectionSheetData.instance(dueDate, loanProducts, jlgGroupsData, this.attendanceDropdownReadPlatformService.retrieveAttendanceTypeOptions()); } @@ -296,8 +301,6 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe final JLGCollectionSheetFaltDataMapper mapper = new JLGCollectionSheetFaltDataMapper(); - final StringBuilder sql = new StringBuilder(mapper.collectionSheetSchema(false)); - // entityType should be center if it's within a center final CalendarEntityType entityType = (group.isChildGroup()) ? CalendarEntityType.CENTERS : CalendarEntityType.GROUPS; @@ -305,10 +308,81 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe .addValue("groupId", group.getId()).addValue("officeHierarchy", officeHierarchy) .addValue("entityTypeId", entityType.getValue()); - final Collection collectionSheetFlatDatas = this.namedParameterjdbcTemplate.query(sql.toString(), - namedParameters, mapper); + final Collection collectionSheetFlatDatas = this.namedParameterjdbcTemplate.query( + mapper.collectionSheetSchema(false), namedParameters, mapper); - return buildJLGCollectionSheet(transactionDate, collectionSheetFlatDatas); + // loan data for collection sheet + JLGCollectionSheetData collectionSheetData = buildJLGCollectionSheet(transactionDate, collectionSheetFlatDatas); + + // mandatory savings data for collection sheet + Collection groupsWithSavingsData = this.namedParameterjdbcTemplate.query( + mandatorySavingsExtractor.collectionSheetSchema(false), namedParameters, mandatorySavingsExtractor); + + // merge savings data into loan data + mergeSavingsGroupDataIntoCollectionsheetData(groupsWithSavingsData, collectionSheetData); + + collectionSheetData = JLGCollectionSheetData.withSavingsProducts(collectionSheetData, + retrieveSavingsProducts(groupsWithSavingsData)); + + return collectionSheetData; + } + + private void mergeSavingsGroupDataIntoCollectionsheetData(final Collection groupsWithSavingsData, + final JLGCollectionSheetData collectionSheetData) { + final List groupsWithLoanData = (List) collectionSheetData.getGroups(); + for (JLGGroupData groupSavingsData : groupsWithSavingsData) { + if (groupsWithLoanData.contains(groupSavingsData)) { + mergeGroup(groupSavingsData, groupsWithLoanData); + } else { + groupsWithLoanData.add(groupSavingsData); + } + } + + } + + private void mergeGroup(final JLGGroupData groupSavingsData, final List groupsWithLoanData) { + final int index = groupsWithLoanData.indexOf(groupSavingsData); + + if (index < 0) return; + + JLGGroupData groupLoanData = groupsWithLoanData.get(index); + List clientsLoanData = (List) groupLoanData.getClients(); + List clientsSavingsData = (List) groupSavingsData.getClients(); + + for (JLGClientData clientSavingsData : clientsSavingsData) { + if (clientsLoanData.contains(clientSavingsData)) { + mergeClient(clientSavingsData, clientsLoanData); + } else { + clientsLoanData.add(clientSavingsData); + } + } + } + + private void mergeClient(final JLGClientData clientSavingsData, List clientsLoanData) { + final int index = clientsLoanData.indexOf(clientSavingsData); + + if (index < 0) return; + + JLGClientData clientLoanData = clientsLoanData.get(index); + clientLoanData.setSavings(clientSavingsData.getSavings()); + } + + private Collection retrieveSavingsProducts(Collection groupsWithSavingsData) { + List savingsProducts = new ArrayList(); + for (JLGGroupData groupSavingsData : groupsWithSavingsData) { + Collection clientsSavingsData = groupSavingsData.getClients(); + for (JLGClientData clientSavingsData : clientsSavingsData) { + Collection savingsDatas = clientSavingsData.getSavings(); + for (SavingsDueData savingsDueData : savingsDatas) { + final SavingsProductData savingsProduct = SavingsProductData.lookup(savingsDueData.productId(), + savingsDueData.productName()); + if (!savingsProducts.contains(savingsProduct)) { + savingsProducts.add(savingsProduct); + } + } + } + } + return savingsProducts; } @Override @@ -337,6 +411,204 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe final Collection collectionSheetFlatDatas = this.namedParameterjdbcTemplate.query(sql.toString(), namedParameters, mapper); - return buildJLGCollectionSheet(transactionDate, collectionSheetFlatDatas); + // loan data for collection sheet + JLGCollectionSheetData collectionSheetData = buildJLGCollectionSheet(transactionDate, collectionSheetFlatDatas); + + // mandatory savings data for collection sheet + Collection groupsWithSavingsData = this.namedParameterjdbcTemplate.query( + mandatorySavingsExtractor.collectionSheetSchema(true), namedParameters, mandatorySavingsExtractor); + + // merge savings data into loan data + mergeSavingsGroupDataIntoCollectionsheetData(groupsWithSavingsData, collectionSheetData); + + collectionSheetData = JLGCollectionSheetData.withSavingsProducts(collectionSheetData, + retrieveSavingsProducts(groupsWithSavingsData)); + + return collectionSheetData; + } + + private static final class MandatorySavingsCollectionsheetExtractor implements ResultSetExtractor> { + + private GroupSavingsDataMapper groupSavingsDataMapper = new GroupSavingsDataMapper(); + + public String collectionSheetSchema(final boolean isCenterCollection) { + + final StringBuffer sql = new StringBuffer(400); + sql.append("SELECT gp.display_name As groupName, ") + .append("gp.id As groupId, ") + .append("cl.display_name As clientName, ") + .append("cl.id As clientId, ") + .append("sf.id As staffId, ") + .append("sf.display_name As staffName, ") + .append("gl.id As levelId, ") + .append("gl.level_name As levelName, ") + .append("sa.id As savingsId, ") + .append("sa.account_no As accountId, ") + .append("sa.status_enum As accountStatusId, ") + .append("sp.short_name As productShortName, ") + .append("sp.id As productId, ") + .append("sa.currency_code as currencyCode, ") + .append("sa.currency_digits as currencyDigits, ") + .append("sa.currency_multiplesof as inMultiplesOf, ") + .append("rc.`name` as currencyName, ") + .append("rc.display_symbol as currencyDisplaySymbol, ") + .append("rc.internationalized_name_code as currencyNameCode, ") + .append("sum(ifnull(mss.deposit_amount,0) - ifnull(mss.deposit_amount_completed_derived,0)) as dueAmount ") + + .append("FROM m_group gp ") + .append("LEFT JOIN m_office of ON of.id = gp.office_id AND of.hierarchy like :officeHierarchy ") + .append("JOIN m_group_level gl ON gl.id = gp.level_Id ") + .append("LEFT JOIN m_staff sf ON sf.id = gp.staff_id ") + .append("JOIN m_group_client gc ON gc.group_id = gp.id ") + .append("JOIN m_client cl ON cl.id = gc.client_id ") + .append("JOIN m_savings_account sa ON sa.client_id=cl.id and sa.status_enum=300 ") + .append("JOIN m_savings_product sp ON sa.product_id=sp.id ") + .append("JOIN m_deposit_account_recurring_detail dard ON sa.id = dard.savings_account_id AND dard.is_mandatory = true AND dard.is_calendar_inherited = true ") + .append("JOIN m_mandatory_savings_schedule mss ON mss.savings_account_id=sa.id AND mss.duedate <= :dueDate ") + .append("LEFT JOIN m_currency rc on rc.`code` = sa.currency_code "); + + if (isCenterCollection) { + sql.append("WHERE gp.parent_id = :centerId "); + } else { + sql.append("WHERE gp.id = :groupId "); + } + + sql.append("and (gp.status_enum = 300 or (gp.status_enum = 600 and gp.closedon_date >= :dueDate)) ") + .append("and (cl.status_enum = 300 or (cl.status_enum = 600 and cl.closedon_date >= :dueDate)) ") + .append("GROUP BY gp.id ,cl.id , sa.id ORDER BY gp.id , cl.id , sa.id "); + + return sql.toString(); + } + + @Override + public Collection extractData(ResultSet rs) throws SQLException, DataAccessException { + List groups = new ArrayList(); + + JLGGroupData group = null; + int groupIndex = 0; + boolean isEndOfRecords = false; + // move cursor to first row. + rs.next(); + + while (!isEndOfRecords) { + group = groupSavingsDataMapper.mapRowData(rs, groupIndex++); + groups.add(group); + isEndOfRecords = rs.isAfterLast(); + } + + return groups; + } + } + + private static final class GroupSavingsDataMapper implements RowMapper { + + private ClientSavingsDataMapper clientSavingsDataMapper = new ClientSavingsDataMapper(); + + private GroupSavingsDataMapper() {} + + public JLGGroupData mapRowData(ResultSet rs, int rowNum) throws SQLException { + final List clients = new ArrayList(); + final JLGGroupData group = this.mapRow(rs, rowNum); + final Long previousGroupId = group.getGroupId(); + + // first client row of new group + JLGClientData client = clientSavingsDataMapper.mapRowData(rs, rowNum); + clients.add(client); + + //if its not after last row loop + while (!rs.isAfterLast()) { + final Long groupId = JdbcSupport.getLong(rs, "groupId"); + if (previousGroupId != null && groupId.compareTo(previousGroupId) != 0) { + // return for next group details + return JLGGroupData.withClients(group, clients); + } + client = clientSavingsDataMapper.mapRowData(rs, rowNum); + clients.add(client); + } + + return JLGGroupData.withClients(group, clients); + } + + @Override + public JLGGroupData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { + + final String groupName = rs.getString("groupName"); + final Long groupId = JdbcSupport.getLong(rs, "groupId"); + final Long staffId = JdbcSupport.getLong(rs, "staffId"); + final String staffName = rs.getString("staffName"); + final Long levelId = JdbcSupport.getLong(rs, "levelId"); + final String levelName = rs.getString("levelName"); + return JLGGroupData.instance(groupId, groupName, staffId, staffName, levelId, levelName); + } + } + + private static final class ClientSavingsDataMapper implements RowMapper { + + private SavingsDueDataMapper savingsDueDataMapper = new SavingsDueDataMapper(); + + private ClientSavingsDataMapper() {} + + public JLGClientData mapRowData(ResultSet rs, int rowNum) throws SQLException { + + List savings = new ArrayList(); + + JLGClientData client = this.mapRow(rs, rowNum); + final Long previousClientId = client.getClientId(); + + // first savings row of new client record + SavingsDueData saving = savingsDueDataMapper.mapRow(rs, rowNum); + savings.add(saving); + + while (rs.next()) { + final Long clientId = JdbcSupport.getLong(rs, "clientId"); + if (previousClientId != null && clientId.compareTo(previousClientId) != 0) { + // client id changes then return for next client data + return JLGClientData.withSavings(client, savings); + } + saving = savingsDueDataMapper.mapRow(rs, rowNum); + savings.add(saving); + } + return JLGClientData.withSavings(client, savings); + } + + @Override + public JLGClientData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { + + final String clientName = rs.getString("clientName"); + final Long clientId = JdbcSupport.getLong(rs, "clientId"); + // final Integer attendanceTypeId = rs.getInt("attendanceTypeId"); + // final EnumOptionData attendanceType = + // AttendanceEnumerations.attendanceType(attendanceTypeId); + final EnumOptionData attendanceType = null; + + return JLGClientData.instance(clientId, clientName, attendanceType); + } + } + + private static final class SavingsDueDataMapper implements RowMapper { + + private SavingsDueDataMapper() {} + + @Override + public SavingsDueData mapRow(ResultSet rs, @SuppressWarnings("unused") int rowNum) throws SQLException { + final Long savingsId = rs.getLong("savingsId"); + final String accountId = rs.getString("accountId"); + final Integer accountStatusId = JdbcSupport.getInteger(rs, "accountStatusId"); + final String productName = rs.getString("productShortName"); + final Long productId = rs.getLong("productId"); + final BigDecimal dueAmount = rs.getBigDecimal("dueAmount"); + + final String currencyCode = rs.getString("currencyCode"); + final String currencyName = rs.getString("currencyName"); + final String currencyNameCode = rs.getString("currencyNameCode"); + final String currencyDisplaySymbol = rs.getString("currencyDisplaySymbol"); + final Integer currencyDigits = JdbcSupport.getInteger(rs, "currencyDigits"); + final Integer inMultiplesOf = JdbcSupport.getInteger(rs, "inMultiplesOf"); + // currency + final CurrencyData currency = new CurrencyData(currencyCode, currencyName, currencyDigits, inMultiplesOf, + currencyDisplaySymbol, currencyNameCode); + + return SavingsDueData.instance(savingsId, accountId, accountStatusId, productName, productId, currency, dueAmount); + } } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetWritePlatformServiceJpaRepositoryImpl.java index 53761d5e6..085b1d1c4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetWritePlatformServiceJpaRepositoryImpl.java @@ -5,6 +5,7 @@ */ package org.mifosplatform.portfolio.collectionsheet.service; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -19,6 +20,9 @@ import org.mifosplatform.portfolio.collectionsheet.serialization.CollectionSheet import org.mifosplatform.portfolio.collectionsheet.serialization.CollectionSheetBulkRepaymentCommandFromApiJsonDeserializer; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.mifosplatform.portfolio.meeting.service.MeetingWritePlatformService; +import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionDTO; +import org.mifosplatform.portfolio.savings.domain.DepositAccountAssembler; +import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -30,18 +34,23 @@ public class CollectionSheetWritePlatformServiceJpaRepositoryImpl implements Col private final CollectionSheetBulkDisbursalCommandFromApiJsonDeserializer bulkDisbursalCommandFromApiJsonDeserializer; private final CollectionSheetTransactionDataValidator transactionDataValidator; private final MeetingWritePlatformService meetingWritePlatformService; + private final DepositAccountAssembler accountAssembler; + private final DepositAccountWritePlatformService accountWritePlatformService; @Autowired public CollectionSheetWritePlatformServiceJpaRepositoryImpl(final LoanWritePlatformService loanWritePlatformService, final CollectionSheetBulkRepaymentCommandFromApiJsonDeserializer bulkRepaymentCommandFromApiJsonDeserializer, final CollectionSheetBulkDisbursalCommandFromApiJsonDeserializer bulkDisbursalCommandFromApiJsonDeserializer, final CollectionSheetTransactionDataValidator transactionDataValidator, - final MeetingWritePlatformService meetingWritePlatformService) { + final MeetingWritePlatformService meetingWritePlatformService, final DepositAccountAssembler accountAssembler, + final DepositAccountWritePlatformService accountWritePlatformService) { this.loanWritePlatformService = loanWritePlatformService; this.bulkRepaymentCommandFromApiJsonDeserializer = bulkRepaymentCommandFromApiJsonDeserializer; this.bulkDisbursalCommandFromApiJsonDeserializer = bulkDisbursalCommandFromApiJsonDeserializer; this.transactionDataValidator = transactionDataValidator; this.meetingWritePlatformService = meetingWritePlatformService; + this.accountAssembler = accountAssembler; + this.accountWritePlatformService = accountWritePlatformService; } @Override @@ -61,6 +70,8 @@ public class CollectionSheetWritePlatformServiceJpaRepositoryImpl implements Col changes.putAll(updateBulkReapayments(command)); changes.putAll(updateBulkDisbursals(command)); + + changes.putAll(updateBulkMandatorySavingsDuePayments(command)); this.meetingWritePlatformService.updateCollectionSheetAttendance(command); @@ -86,4 +97,21 @@ public class CollectionSheetWritePlatformServiceJpaRepositoryImpl implements Col changes.putAll(this.loanWritePlatformService.bulkLoanDisbursal(command, bulkDisbursalCommand, false)); return changes; } + + private Map updateBulkMandatorySavingsDuePayments(final JsonCommand command) { + final Map changes = new HashMap(); + final Collection savingsTransactions = this.accountAssembler.assembleBulkMandatorySavingsAccountTransactionDTOs(command); + + for (SavingsAccountTransactionDTO savingsAccountTransactionDTO : savingsTransactions) { + try { + this.accountWritePlatformService.mandatorySavingsAccountDeposit(savingsAccountTransactionDTO); + changes.put("savingsAccountId", savingsAccountTransactionDTO.getSavingsAccountId()); + changes.put("transationAmount", savingsAccountTransactionDTO.getTransactionAmount()); + } catch (Exception e) { + // TODO: handle exception + } + } + + return changes; + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/common/domain/PeriodFrequencyType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/common/domain/PeriodFrequencyType.java index b6aba7dca..16f90c397 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/common/domain/PeriodFrequencyType.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/common/domain/PeriodFrequencyType.java @@ -5,6 +5,9 @@ */ package org.mifosplatform.portfolio.common.domain; +import java.util.ArrayList; +import java.util.List; + public enum PeriodFrequencyType { DAYS(0, "periodFrequencyType.days"), // @@ -57,4 +60,19 @@ public enum PeriodFrequencyType { public boolean isYearly() { return this.value.equals(PeriodFrequencyType.MONTHS.getValue()); } + + public boolean isInvalid() { + return this.value.equals(PeriodFrequencyType.INVALID.getValue()); + } + + public static Object[] integerValues() { + final List values = new ArrayList(); + for (final PeriodFrequencyType enumType : values()) { + if (!enumType.isInvalid()) { + values.add(enumType.getValue()); + } + } + + return values.toArray(); + } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartApiConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartApiConstants.java index 81b65b197..23b705329 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartApiConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartApiConstants.java @@ -29,16 +29,19 @@ public class InterestRateChartApiConstants { public static final String descriptionParamName = "description"; public static final String fromDateParamName = "fromDate"; public static final String endDateParamName = "endDate"; - public static final String savingsProductIdParamName = "savingsProductId"; - public static final String savingsProductNameParamName = "savingsProductName"; + public static final String productIdParamName = "productId"; + public static final String productNameParamName = "productName"; // interest rate chart Slabs parameters - public static final String periodTypeParamName = "periodType"; - public static final String fromPeriodParamName = "fromPeriod"; - public static final String toPeriodParamName = "toPeriod"; - public static final String amountRangeFromParamName = "amountRangeFrom"; - public static final String amountRangeToParamName = "amountRangeTo"; - public static final String annualInterestRateParamName = "annualInterestRate"; +// public static final String periodTypeParamName = "periodType"; +// public static final String fromPeriodParamName = "fromPeriod"; +// public static final String toPeriodParamName = "toPeriod"; +// public static final String amountRangeFromParamName = "amountRangeFrom"; +// public static final String amountRangeToParamName = "amountRangeTo"; +// public static final String annualInterestRateParamName = "annualInterestRate"; +// public static final String interestRateForFemaleParamName = "interestRateForFemale"; +// public static final String interestRateForChildrenParamName = "interestRateForChildren"; +// public static final String interestRateForSeniorCitizenParamName = "interestRateForSeniorCitizen"; // associations public static final String chartSlabs = "chartSlabs"; @@ -47,7 +50,7 @@ public class InterestRateChartApiConstants { public static final String deleteParamName = "delete"; public static final Set INTERESTRATE_CHART_CREATE_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, - dateFormatParamName, nameParamName, descriptionParamName, fromDateParamName, endDateParamName, savingsProductIdParamName, + dateFormatParamName, nameParamName, descriptionParamName, fromDateParamName, endDateParamName, productIdParamName, chartSlabs)); public static final Set INTERESTRATE_CHART_UPDATE_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartPeriodType.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartPeriodType.java deleted file mode 100644 index 79386c4d7..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartPeriodType.java +++ /dev/null @@ -1,74 +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.interestratechart; - -import java.util.ArrayList; -import java.util.List; - - -/** - * An enumeration of supported calendar periods used in savings. - */ -public enum InterestRateChartPeriodType { - - DAYS(0, "interestChartPeriodType.days"), // - WEEKS(1, "interestChartPeriodType.weeks"), // - MONTHS(2, "interestChartPeriodType.months"), // - YEARS(3, "interestChartPeriodType.years"), // - INVALID(4, "interestChartPeriodType.invalid"); - - private final Integer value; - private final String code; - - private InterestRateChartPeriodType(final Integer value, final String code) { - this.value = value; - this.code = code; - } - - public Integer getValue() { - return this.value; - } - - public String getCode() { - return this.code; - } - - public static InterestRateChartPeriodType fromInt(final Integer type) { - InterestRateChartPeriodType periodType = InterestRateChartPeriodType.INVALID; - if (type != null) { - switch (type) { - case 0: - periodType = InterestRateChartPeriodType.DAYS; - break; - case 1: - periodType = InterestRateChartPeriodType.WEEKS; - break; - case 2: - periodType = InterestRateChartPeriodType.MONTHS; - break; - case 3: - periodType = InterestRateChartPeriodType.YEARS; - break; - } - } - return periodType; - } - - public static Object[] integerValues() { - final List values = new ArrayList(); - for (final InterestRateChartPeriodType enumType : values()) { - if (!enumType.isInvalid()) { - values.add(enumType.getValue()); - } - } - - return values.toArray(); - } - - public boolean isInvalid(){ - return this.value.equals(InterestRateChartPeriodType.INVALID.value); - } -} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartSlabApiConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartSlabApiConstants.java index 794b0b9ce..f3e16be6f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartSlabApiConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/InterestRateChartSlabApiConstants.java @@ -30,19 +30,25 @@ public class InterestRateChartSlabApiConstants { public static final String amountRangeFromParamName = "amountRangeFrom"; public static final String amountRangeToParamName = "amountRangeTo"; public static final String annualInterestRateParamName = "annualInterestRate"; - public static final String currencyCodeParamName = "currencyCode"; + public static final String interestRateForFemaleParamName = "interestRateForFemale"; + public static final String interestRateForChildrenParamName = "interestRateForChildren"; + public static final String interestRateForSeniorCitizenParamName = "interestRateForSeniorCitizen"; + public static final String currencyCodeParamName = "currencyCode"; // associations public static final Set INTERESTRATE_CHART_SLAB_CREATE_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList( localeParamName, idParamName, descriptionParamName, periodTypeParamName, fromPeriodParamName, toPeriodParamName, - amountRangeFromParamName, amountRangeToParamName, annualInterestRateParamName, currencyCodeParamName)); - + amountRangeFromParamName, amountRangeToParamName, annualInterestRateParamName, interestRateForFemaleParamName, + interestRateForChildrenParamName, interestRateForSeniorCitizenParamName, currencyCodeParamName)); + public static final Set INTERESTRATE_CHART_SLAB_UPDATE_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList( localeParamName, idParamName, descriptionParamName, periodTypeParamName, fromPeriodParamName, toPeriodParamName, - amountRangeFromParamName, amountRangeToParamName, annualInterestRateParamName, currencyCodeParamName)); + amountRangeFromParamName, amountRangeToParamName, annualInterestRateParamName, interestRateForFemaleParamName, + interestRateForChildrenParamName, interestRateForSeniorCitizenParamName, currencyCodeParamName)); public static final Set INTERESTRATE_CHART_SLAB_RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, idParamName, descriptionParamName, periodTypeParamName, fromPeriodParamName, toPeriodParamName, amountRangeFromParamName, - amountRangeToParamName, annualInterestRateParamName, currencyCodeParamName)); + amountRangeToParamName, annualInterestRateParamName, interestRateForFemaleParamName, interestRateForChildrenParamName, + interestRateForSeniorCitizenParamName, currencyCodeParamName)); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/api/InterestRateChartSlabsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/api/InterestRateChartSlabsApiResource.java index 352278774..f5b85e434 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/api/InterestRateChartSlabsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/api/InterestRateChartSlabsApiResource.java @@ -64,9 +64,10 @@ public class InterestRateChartSlabsApiResource { @Path("template") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String template() { - // TODO: implement - return null; + public String template(@Context final UriInfo uriInfo) { + InterestRateChartSlabData chartSlab = this.interestRateChartSlabReadPlatformService.retrieveTemplate(); + final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); + return this.toApiJsonSerializer.serialize(settings, chartSlab, INTERESTRATE_CHART_SLAB_RESPONSE_DATA_PARAMETERS); } @GET diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/api/InterestRateChartsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/api/InterestRateChartsApiResource.java index dfd078b15..c4f8e8dca 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/api/InterestRateChartsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/api/InterestRateChartsApiResource.java @@ -6,6 +6,7 @@ package org.mifosplatform.portfolio.interestratechart.api; import java.util.Collection; +import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -23,6 +24,7 @@ import javax.ws.rs.core.UriInfo; import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; +import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; @@ -94,8 +96,15 @@ public class InterestRateChartsApiResource { public String retrieveOne(@PathParam("chartId") final Long chartId, @Context final UriInfo uriInfo) { this.context.authenticatedUser().validateHasReadPermission(InterestRateChartApiConstants.INTERESTRATE_CHART_RESOURCE_NAME); - - InterestRateChartData chartData = this.chartReadPlatformService.retrieveOneWithSlabs(chartId); + + InterestRateChartData chartData = null; + final Set associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); + if (!associationParameters.isEmpty() && associationParameters.contains(InterestRateChartApiConstants.chartSlabs)) { + chartData = this.chartReadPlatformService.retrieveOneWithSlabs(chartId); + }else { + chartData = this.chartReadPlatformService.retrieveOne(chartId); + } + final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); if (settings.isTemplate()) { chartData = this.chartReadPlatformService.retrieveWithTemplate(chartData); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/ClientIncentiveAttributes.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/ClientIncentiveAttributes.java new file mode 100644 index 000000000..bc31d7cf8 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/ClientIncentiveAttributes.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.interestratechart.data; + + +/** + * Immutable data object representing a ClientIncentiveAttributes used + * for determining interest rate applicable from Interest rate chart. + */ +public class ClientIncentiveAttributes { + + private final boolean isFemale; + private final boolean isChild; + private final boolean isSeniorCitizen; + + + public static ClientIncentiveAttributes instance(final boolean isFemale, final boolean isChild, final boolean isSeniorCitizen) { + return new ClientIncentiveAttributes(isFemale, isChild, isSeniorCitizen); + } + + + + private ClientIncentiveAttributes(final boolean isFemale, final boolean isChild, final boolean isSeniorCitizen) { + this.isFemale = isFemale; + this.isChild = isChild; + this.isSeniorCitizen = isSeniorCitizen; + } + + public boolean isFemale(){ + return this.isFemale; + } + + public boolean isChild(){ + return this.isChild; + } + + public boolean isSeniorCitizen(){ + return this.isSeniorCitizen; + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartData.java index f65f39bb4..dc29bef6c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartData.java @@ -22,8 +22,8 @@ public class InterestRateChartData { private final String description; private final LocalDate fromDate; private final LocalDate endDate; - private final Long savingsProductId; - private final String savingsProductName; + private final Long productId; + private final String productName; // associations private Set chartSlabs; @@ -32,8 +32,9 @@ public class InterestRateChartData { private Collection periodTypes; public static InterestRateChartData instance(Long id, String name, String description, LocalDate fromDate, LocalDate endDate, - Long savingsProductId, String savingsProductName, Set chartSlabs) { + Long savingsProductId, String savingsProductName) { Collection periodTypes = null; + Set chartSlabs = null; return new InterestRateChartData(id, name, description, fromDate, endDate, savingsProductId, savingsProductName, chartSlabs, periodTypes); } @@ -41,14 +42,14 @@ public class InterestRateChartData { public static InterestRateChartData withSlabs(InterestRateChartData interestRateChartData, Set chartSlabs) { return new InterestRateChartData(interestRateChartData.id, interestRateChartData.name, interestRateChartData.description, - interestRateChartData.fromDate, interestRateChartData.endDate, interestRateChartData.savingsProductId, - interestRateChartData.savingsProductName, chartSlabs, interestRateChartData.periodTypes); + interestRateChartData.fromDate, interestRateChartData.endDate, interestRateChartData.productId, + interestRateChartData.productName, chartSlabs, interestRateChartData.periodTypes); } public static InterestRateChartData withTemplate(InterestRateChartData interestRateChartData, Collection periodTypes) { return new InterestRateChartData(interestRateChartData.id, interestRateChartData.name, interestRateChartData.description, - interestRateChartData.fromDate, interestRateChartData.endDate, interestRateChartData.savingsProductId, - interestRateChartData.savingsProductName, interestRateChartData.chartSlabs, periodTypes); + interestRateChartData.fromDate, interestRateChartData.endDate, interestRateChartData.productId, + interestRateChartData.productName, interestRateChartData.chartSlabs, periodTypes); } public static InterestRateChartData template(Collection periodTypes) { @@ -73,8 +74,8 @@ public class InterestRateChartData { this.fromDate = fromDate; this.endDate = endDate; this.chartSlabs = chartSlabs; - this.savingsProductId = savingsProductId; - this.savingsProductName = savingsProductName; + this.productId = savingsProductId; + this.productName = savingsProductName; this.periodTypes = periodTypes; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartDataValidator.java index 2cd04620a..d4eb3a83c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartDataValidator.java @@ -14,7 +14,7 @@ import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApi import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.fromDateParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.idParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.nameParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.savingsProductIdParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.productIdParamName; import java.lang.reflect.Type; import java.util.ArrayList; @@ -112,9 +112,9 @@ public class InterestRateChartDataValidator { final JsonElement element = this.fromApiJsonHelper.parse(json); - if (this.fromApiJsonHelper.parameterExists(savingsProductIdParamName, element)) { - final Long savingsProductId = this.fromApiJsonHelper.extractLongNamed(savingsProductIdParamName, element); - baseDataValidator.reset().parameter(savingsProductIdParamName).value(savingsProductId).notNull().integerGreaterThanZero(); + if (this.fromApiJsonHelper.parameterExists(productIdParamName, element)) { + final Long savingsProductId = this.fromApiJsonHelper.extractLongNamed(productIdParamName, element); + baseDataValidator.reset().parameter(productIdParamName).value(savingsProductId).notNull().integerGreaterThanZero(); } if (this.fromApiJsonHelper.parameterExists(nameParamName, element)) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabData.java index 2cea3a8ba..179a496b0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabData.java @@ -24,25 +24,52 @@ public class InterestRateChartSlabData { private final BigDecimal amountRangeFrom; private final BigDecimal amountRangeTo; private final BigDecimal annualInterestRate; + private final BigDecimal interestRateForFemale; + private final BigDecimal interestRateForChildren; + private final BigDecimal interestRateForSeniorCitizen; private final CurrencyData currency; // template - private Collection periodTypes; + private final Collection periodTypes; - public static InterestRateChartSlabData instance(Long id, String description, EnumOptionData periodType, Integer fromPeriod, - Integer toPeriod, BigDecimal amountRangeFrom, BigDecimal amountRangeTo, BigDecimal annualInterestRate, CurrencyData currency) { - Collection periodTypes = null; + public static InterestRateChartSlabData instance(final Long id, final String description, final EnumOptionData periodType, + final Integer fromPeriod, final Integer toPeriod, final BigDecimal amountRangeFrom, final BigDecimal amountRangeTo, + final BigDecimal annualInterestRate, final BigDecimal interestRateForFemale, final BigDecimal interestRateForChildren, + final BigDecimal interestRateForSeniorCitizen, final CurrencyData currency) { + final Collection periodTypes = null; return new InterestRateChartSlabData(id, description, periodType, fromPeriod, toPeriod, amountRangeFrom, amountRangeTo, - annualInterestRate, currency, periodTypes); - } - - public static InterestRateChartSlabData withTemplate(InterestRateChartSlabData chartSlab, Collection periodTypes) { - return new InterestRateChartSlabData(chartSlab.id, chartSlab.description, chartSlab.periodType, chartSlab.fromPeriod, chartSlab.toPeriod, chartSlab.amountRangeFrom, chartSlab.amountRangeTo, - chartSlab.annualInterestRate, chartSlab.currency, periodTypes); + annualInterestRate, interestRateForFemale, interestRateForChildren, interestRateForSeniorCitizen, currency, periodTypes); } - private InterestRateChartSlabData(Long id, String description, EnumOptionData periodType, Integer fromPeriod, Integer toPeriod, - BigDecimal amountRangeFrom, BigDecimal amountRangeTo, BigDecimal annualInterestRate, CurrencyData currency, Collection periodTypes) { + public static InterestRateChartSlabData withTemplate(final InterestRateChartSlabData chartSlab, + final Collection periodTypes) { + return new InterestRateChartSlabData(chartSlab.id, chartSlab.description, chartSlab.periodType, chartSlab.fromPeriod, + chartSlab.toPeriod, chartSlab.amountRangeFrom, chartSlab.amountRangeTo, chartSlab.annualInterestRate, + chartSlab.interestRateForFemale, chartSlab.interestRateForChildren, chartSlab.interestRateForSeniorCitizen, + chartSlab.currency, periodTypes); + } + + public static InterestRateChartSlabData template(final Collection periodTypes) { + final Long id = null; + final String description = null; + final EnumOptionData periodType = null; + final Integer fromPeriod = null; + final Integer toPeriod = null; + final BigDecimal amountRangeFrom = null; + final BigDecimal amountRangeTo = null; + final BigDecimal annualInterestRate = null; + final BigDecimal interestRateForFemale = null; + final BigDecimal interestRateForChildren = null; + final BigDecimal interestRateForSeniorCitizen = null; + final CurrencyData currency = null; + return new InterestRateChartSlabData(id, description, periodType, fromPeriod, toPeriod, amountRangeFrom, amountRangeTo, + annualInterestRate, interestRateForFemale, interestRateForChildren, interestRateForSeniorCitizen, currency, periodTypes); + } + + private InterestRateChartSlabData(final Long id, final String description, final EnumOptionData periodType, final Integer fromPeriod, + final Integer toPeriod, final BigDecimal amountRangeFrom, final BigDecimal amountRangeTo, final BigDecimal annualInterestRate, + final BigDecimal interestRateForFemale, final BigDecimal interestRateForChildren, + final BigDecimal interestRateForSeniorCitizen, final CurrencyData currency, final Collection periodTypes) { this.id = id; this.description = description; this.periodType = periodType; @@ -51,51 +78,59 @@ public class InterestRateChartSlabData { this.amountRangeFrom = amountRangeFrom; this.amountRangeTo = amountRangeTo; this.annualInterestRate = annualInterestRate; + this.interestRateForFemale = interestRateForFemale; + this.interestRateForChildren = interestRateForChildren; + this.interestRateForSeniorCitizen = interestRateForSeniorCitizen; this.currency = currency; this.periodTypes = periodTypes; } - + public String description() { return this.description; } - public EnumOptionData periodType() { return this.periodType; } - public Integer fromPeriod() { return this.fromPeriod; } - public Integer toPeriod() { return this.toPeriod; } - public BigDecimal amountRangeFrom() { return this.amountRangeFrom; } - public BigDecimal amountRangeTo() { return this.amountRangeTo; } - public BigDecimal annualInterestRate() { return this.annualInterestRate; } - + + public BigDecimal interestRateForFemale() { + return this.interestRateForFemale; + } + public BigDecimal interestRateForChildren() { + return this.interestRateForChildren; + } + + public BigDecimal interestRateForSeniorCitizen() { + return this.interestRateForSeniorCitizen; + } + public CurrencyData currency() { return this.currency; } - + public Collection periodTypes() { return this.periodTypes; } - + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java index 872a81384..0d161f776 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/data/InterestRateChartSlabDataValidator.java @@ -14,6 +14,9 @@ import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSla import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.currencyCodeParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.descriptionParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.fromPeriodParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForChildrenParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForFemaleParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForSeniorCitizenParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.periodTypeParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.toPeriodParamName; @@ -30,7 +33,7 @@ import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; -import org.mifosplatform.portfolio.interestratechart.InterestRateChartPeriodType; +import org.mifosplatform.portfolio.common.domain.PeriodFrequencyType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -61,17 +64,16 @@ public class InterestRateChartSlabDataValidator { final JsonElement element = this.fromApiJsonHelper.parse(json); final JsonObject objectElement = element.getAsJsonObject(); final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(objectElement); - + final String currencyCode = this.fromApiJsonHelper.extractStringNamed(currencyCodeParamName, element); baseDataValidator.reset().parameter(currencyCodeParamName).value(currencyCode).notBlank().notExceedingLengthOf(3); - + validateChartSlabsCreate(element, baseDataValidator, locale); throwExceptionIfValidationWarningsExist(dataValidationErrors); } public void validateChartSlabsCreate(final JsonElement element, final DataValidatorBuilder baseDataValidator, final Locale locale) { - if (this.fromApiJsonHelper.parameterExists(descriptionParamName, element)) { final String description = this.fromApiJsonHelper.extractStringNamed(descriptionParamName, element); @@ -80,7 +82,7 @@ public class InterestRateChartSlabDataValidator { final Integer periodType = this.fromApiJsonHelper.extractIntegerNamed(periodTypeParamName, element, locale); baseDataValidator.reset().parameter(periodTypeParamName).value(periodType).notNull() - .isOneOfTheseValues(InterestRateChartPeriodType.integerValues()); + .isOneOfTheseValues(PeriodFrequencyType.integerValues()); Integer toPeriod = null; @@ -117,6 +119,25 @@ public class InterestRateChartSlabDataValidator { final BigDecimal annualInterestRate = this.fromApiJsonHelper.extractBigDecimalNamed(annualInterestRateParamName, element, locale); baseDataValidator.reset().parameter(annualInterestRateParamName).value(annualInterestRate).notNull().zeroOrPositiveAmount(); + + if (this.fromApiJsonHelper.parameterExists(interestRateForFemaleParamName, element)) { + final BigDecimal interestRateForFemale = this.fromApiJsonHelper.extractBigDecimalNamed(interestRateForFemaleParamName, element, + locale); + baseDataValidator.reset().parameter(interestRateForFemaleParamName).value(interestRateForFemale).notNull().zeroOrPositiveAmount(); + } + + if (this.fromApiJsonHelper.parameterExists(interestRateForChildrenParamName, element)) { + final BigDecimal interestRateForChildren = this.fromApiJsonHelper.extractBigDecimalNamed(interestRateForChildrenParamName, element, + locale); + baseDataValidator.reset().parameter(interestRateForChildrenParamName).value(interestRateForChildren).notNull().zeroOrPositiveAmount(); + } + + if (this.fromApiJsonHelper.parameterExists(interestRateForSeniorCitizenParamName, element)) { + final BigDecimal interestRateForSeniorCitizen = this.fromApiJsonHelper.extractBigDecimalNamed(interestRateForSeniorCitizenParamName, element, + locale); + baseDataValidator.reset().parameter(interestRateForSeniorCitizenParamName).value(interestRateForSeniorCitizen).notNull().zeroOrPositiveAmount(); + } + } public void validateUpdate(final String json) { @@ -138,7 +159,6 @@ public class InterestRateChartSlabDataValidator { } public void validateChartSlabsUpdate(final JsonElement element, final DataValidatorBuilder baseDataValidator, final Locale locale) { - if (this.fromApiJsonHelper.parameterExists(descriptionParamName, element)) { final String description = this.fromApiJsonHelper.extractStringNamed(descriptionParamName, element); @@ -148,7 +168,7 @@ public class InterestRateChartSlabDataValidator { if (this.fromApiJsonHelper.parameterExists(periodTypeParamName, element)) { final Integer periodType = this.fromApiJsonHelper.extractIntegerNamed(periodTypeParamName, element, locale); baseDataValidator.reset().parameter(periodTypeParamName).value(periodType).notNull() - .isOneOfTheseValues(InterestRateChartPeriodType.integerValues()); + .isOneOfTheseValues(PeriodFrequencyType.integerValues()); } Integer fromPeriod = null; @@ -192,6 +212,24 @@ public class InterestRateChartSlabDataValidator { locale); baseDataValidator.reset().parameter(annualInterestRateParamName).value(annualInterestRate).notNull().zeroOrPositiveAmount(); } + + if (this.fromApiJsonHelper.parameterExists(interestRateForFemaleParamName, element)) { + final BigDecimal interestRateForFemale = this.fromApiJsonHelper.extractBigDecimalNamed(interestRateForFemaleParamName, element, + locale); + baseDataValidator.reset().parameter(interestRateForFemaleParamName).value(interestRateForFemale).notNull().zeroOrPositiveAmount(); + } + + if (this.fromApiJsonHelper.parameterExists(interestRateForChildrenParamName, element)) { + final BigDecimal interestRateForChildren = this.fromApiJsonHelper.extractBigDecimalNamed(interestRateForChildrenParamName, element, + locale); + baseDataValidator.reset().parameter(interestRateForChildrenParamName).value(interestRateForChildren).notNull().zeroOrPositiveAmount(); + } + + if (this.fromApiJsonHelper.parameterExists(interestRateForSeniorCitizenParamName, element)) { + final BigDecimal interestRateForSeniorCitizen = this.fromApiJsonHelper.extractBigDecimalNamed(interestRateForSeniorCitizenParamName, element, + locale); + baseDataValidator.reset().parameter(interestRateForSeniorCitizenParamName).value(interestRateForSeniorCitizen).notNull().zeroOrPositiveAmount(); + } if (this.fromApiJsonHelper.parameterExists(currencyCodeParamName, element)) { final String currencyCode = this.fromApiJsonHelper.extractStringNamed(currencyCodeParamName, element); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChart.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChart.java index 7005b1902..a5bdc5ca4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChart.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChart.java @@ -6,15 +6,18 @@ package org.mifosplatform.portfolio.interestratechart.domain; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.INTERESTRATE_CHART_RESOURCE_NAME; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.amountRangeFromParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.amountRangeToParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.annualInterestRateParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.amountRangeFromParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.amountRangeToParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.annualInterestRateParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.deleteParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.descriptionParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.fromPeriodParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.fromPeriodParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.idParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.periodTypeParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.toPeriodParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForChildrenParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForFemaleParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForSeniorCitizenParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.periodTypeParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.toPeriodParamName; import java.math.BigDecimal; import java.util.ArrayList; @@ -202,8 +205,12 @@ public class InterestRateChart extends AbstractPersistable { final BigDecimal amountRangeTo = chartSlabsCommand.bigDecimalValueOfParameterNamed(amountRangeToParamName); final BigDecimal annualInterestRate = chartSlabsCommand .bigDecimalValueOfParameterNamed(annualInterestRateParamName); + final BigDecimal interestRateForFemale = chartSlabsCommand.bigDecimalValueOfParameterNamed(interestRateForFemaleParamName); + final BigDecimal interestRateForChildren = chartSlabsCommand.bigDecimalValueOfParameterNamed(interestRateForChildrenParamName); + final BigDecimal interestRateForSeniorCitizen = chartSlabsCommand.bigDecimalValueOfParameterNamed(interestRateForSeniorCitizenParamName); + final InterestRateChartSlabFields slabFields = InterestRateChartSlabFields.createNew(description, periodFrequencyType, - fromPeriod, toPeriod, amountRangeFrom, amountRangeTo, annualInterestRate, currencyCode); + fromPeriod, toPeriod, amountRangeFrom, amountRangeTo, annualInterestRate, interestRateForFemale, interestRateForChildren, interestRateForSeniorCitizen, currencyCode); final InterestRateChartSlab chartSlab = InterestRateChartSlab.createNew(slabFields, this); chartSlab.slabFields().validateChartSlabPlatformRules(chartSlabsCommand, baseDataValidator); this.addChartSlab(chartSlab); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartFields.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartFields.java index 17f470d36..9accfe9c4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartFields.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartFields.java @@ -84,7 +84,7 @@ public class InterestRateChartFields { this.fromDate = newValue.toDate(); } - if (command.isChangeInLocalDateParameterNamed(endDateParamName, getFromDateAsLocalDate())) { + if (command.isChangeInLocalDateParameterNamed(endDateParamName, getEndDateAsLocalDate())) { final LocalDate newValue = command.localDateValueOfParameterNamed(endDateParamName); final String newValueAsString = command.stringValueOfParameterNamed(endDateParamName); actualChanges.put(endDateParamName, newValueAsString); @@ -135,7 +135,7 @@ public class InterestRateChartFields { final LocalDateInterval thisInterval = LocalDateInterval.create(thisFromDate, thisEndDate); final LocalDateInterval thatInterval = LocalDateInterval.create(thatFromDate, thatEndDate); - if(thisInterval.containsPortionOf(thatInterval) || thisInterval.contains(thatInterval)){ + if(thisInterval.containsPortionOf(thatInterval) || thatInterval.containsPortionOf(thisInterval)){ return true; } return false;// no overlapping diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartSlabFields.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartSlabFields.java index bd6c13df5..6986d388a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartSlabFields.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/domain/InterestRateChartSlabFields.java @@ -5,13 +5,16 @@ */ package org.mifosplatform.portfolio.interestratechart.domain; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.amountRangeFromParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.amountRangeToParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.annualInterestRateParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.descriptionParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.fromPeriodParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.periodTypeParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.toPeriodParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.amountRangeFromParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.amountRangeToParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.annualInterestRateParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForFemaleParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForChildrenParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForSeniorCitizenParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.descriptionParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.fromPeriodParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.periodTypeParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.toPeriodParamName; import java.math.BigDecimal; import java.util.Map; @@ -52,6 +55,15 @@ public class InterestRateChartSlabFields { @Column(name = "annual_interest_rate", scale = 6, precision = 19, nullable = false) private BigDecimal annualInterestRate; + @Column(name = "interest_rate_for_female", scale = 6, precision = 19, nullable = true) + private BigDecimal interestRateForFemale; + + @Column(name = "interest_rate_for_children", scale = 6, precision = 19, nullable = true) + private BigDecimal interestRateForChildren; + + @Column(name = "interest_rate_for_senior_citizen", scale = 6, precision = 19, nullable = true) + private BigDecimal interestRateForSeniorCitizen; + @Column(name = "currency_code", nullable = false) private String currencyCode; @@ -59,15 +71,18 @@ public class InterestRateChartSlabFields { // } - public static InterestRateChartSlabFields createNew(String description, final SavingsPeriodFrequencyType periodFrequencyType, - Integer fromPeriod, Integer toPeriod, BigDecimal amountRangeFrom, BigDecimal amountRangeTo, BigDecimal annualInterestRate, - String currencyCode) { + public static InterestRateChartSlabFields createNew(final String description, final SavingsPeriodFrequencyType periodFrequencyType, + final Integer fromPeriod, final Integer toPeriod, final BigDecimal amountRangeFrom, final BigDecimal amountRangeTo, + final BigDecimal annualInterestRate, final BigDecimal interestRateForFemale, final BigDecimal interestRateForChildren, + final BigDecimal interestRateForSeniorCitizen, final String currencyCode) { return new InterestRateChartSlabFields(description, periodFrequencyType, fromPeriod, toPeriod, amountRangeFrom, amountRangeTo, - annualInterestRate, currencyCode); + annualInterestRate, interestRateForFemale, interestRateForChildren, interestRateForSeniorCitizen, currencyCode); } - private InterestRateChartSlabFields(String description, final SavingsPeriodFrequencyType periodFrequencyType, Integer fromPeriod, - Integer toPeriod, BigDecimal amountRangeFrom, BigDecimal amountRangeTo, BigDecimal annualInterestRate, String currencyCode) { + private InterestRateChartSlabFields(final String description, final SavingsPeriodFrequencyType periodFrequencyType, + final Integer fromPeriod, final Integer toPeriod, final BigDecimal amountRangeFrom, final BigDecimal amountRangeTo, + final BigDecimal annualInterestRate, final BigDecimal interestRateForFemale, final BigDecimal interestRateForChildren, + final BigDecimal interestRateForSeniorCitizen, final String currencyCode) { this.description = description; this.periodType = (periodFrequencyType == null) ? null : periodFrequencyType.getValue(); this.fromPeriod = fromPeriod; @@ -75,10 +90,13 @@ public class InterestRateChartSlabFields { this.amountRangeFrom = amountRangeFrom; this.amountRangeTo = amountRangeTo; this.annualInterestRate = annualInterestRate; + this.interestRateForFemale = interestRateForFemale; + this.interestRateForChildren = interestRateForChildren; + this.interestRateForSeniorCitizen = interestRateForSeniorCitizen; this.currencyCode = currencyCode; } - public void update(JsonCommand command, final Map actualChanges, final DataValidatorBuilder baseDataValidator) { + public void update(final JsonCommand command, final Map actualChanges, final DataValidatorBuilder baseDataValidator) { if (command.isChangeInStringParameterNamed(descriptionParamName, this.description)) { final String newValue = command.stringValueOfParameterNamed(descriptionParamName); @@ -86,52 +104,70 @@ public class InterestRateChartSlabFields { this.description = newValue; } - if (command.isChangeInIntegerParameterNamed(periodTypeParamName, periodType)) { + if (command.isChangeInIntegerParameterNamed(periodTypeParamName, this.periodType)) { final Integer newValue = command.integerValueOfParameterNamed(periodTypeParamName); actualChanges.put(periodTypeParamName, newValue); this.periodType = newValue; } - if (command.isChangeInIntegerParameterNamed(fromPeriodParamName, fromPeriod)) { + if (command.isChangeInIntegerParameterNamed(fromPeriodParamName, this.fromPeriod)) { final Integer newValue = command.integerValueOfParameterNamed(fromPeriodParamName); actualChanges.put(fromPeriodParamName, newValue); this.fromPeriod = newValue; } - if (command.isChangeInIntegerParameterNamed(toPeriodParamName, toPeriod)) { + if (command.isChangeInIntegerParameterNamed(toPeriodParamName, this.toPeriod)) { final Integer newValue = command.integerValueOfParameterNamed(toPeriodParamName); actualChanges.put(toPeriodParamName, newValue); this.toPeriod = newValue; } - if (command.isChangeInBigDecimalParameterNamed(amountRangeFromParamName, amountRangeFrom)) { + if (command.isChangeInBigDecimalParameterNamed(amountRangeFromParamName, this.amountRangeFrom)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(amountRangeFromParamName); actualChanges.put(amountRangeFromParamName, newValue); this.amountRangeFrom = newValue; } - if (command.isChangeInBigDecimalParameterNamed(amountRangeToParamName, amountRangeTo)) { + if (command.isChangeInBigDecimalParameterNamed(amountRangeToParamName, this.amountRangeTo)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(amountRangeToParamName); actualChanges.put(amountRangeToParamName, newValue); this.amountRangeTo = newValue; } - if (command.isChangeInBigDecimalParameterNamed(annualInterestRateParamName, annualInterestRate)) { + if (command.isChangeInBigDecimalParameterNamed(annualInterestRateParamName, this.annualInterestRate)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(annualInterestRateParamName); actualChanges.put(annualInterestRateParamName, newValue); this.annualInterestRate = newValue; } - this.validateChartSlabPlatformRules(command, baseDataValidator); + if (command.isChangeInBigDecimalParameterNamed(interestRateForFemaleParamName, this.interestRateForFemale)) { + final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(interestRateForFemaleParamName); + actualChanges.put(interestRateForFemaleParamName, newValue); + this.interestRateForFemale = newValue; + } + + if (command.isChangeInBigDecimalParameterNamed(interestRateForChildrenParamName, this.interestRateForChildren)) { + final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(interestRateForChildrenParamName); + actualChanges.put(interestRateForChildrenParamName, newValue); + this.interestRateForChildren = newValue; + } + + if (command.isChangeInBigDecimalParameterNamed(interestRateForSeniorCitizenParamName, this.interestRateForSeniorCitizen)) { + final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(interestRateForSeniorCitizenParamName); + actualChanges.put(interestRateForSeniorCitizenParamName, newValue); + this.interestRateForSeniorCitizen = newValue; + } + + validateChartSlabPlatformRules(command, baseDataValidator); } - public void validateChartSlabPlatformRules(JsonCommand chartSlabsCommand, DataValidatorBuilder baseDataValidator) { - if (this.isFromPeriodGreaterThanToPeriod()) { + public void validateChartSlabPlatformRules(final JsonCommand chartSlabsCommand, final DataValidatorBuilder baseDataValidator) { + if (isFromPeriodGreaterThanToPeriod()) { final Integer fromPeriod = chartSlabsCommand.integerValueOfParameterNamed(fromPeriodParamName); baseDataValidator.parameter(fromPeriodParamName).value(fromPeriod).failWithCode("from.period.is.greater.than.to.period"); } - if (this.isAmountRangeFromGreaterThanTo()) { + if (isAmountRangeFromGreaterThanTo()) { final BigDecimal amountRangeFrom = chartSlabsCommand.bigDecimalValueOfParameterNamed(amountRangeFromParamName); baseDataValidator.parameter(amountRangeFromParamName).value(amountRangeFrom) .failWithCode("amount.range.from.is.greater.than.amount.range.to"); @@ -140,7 +176,7 @@ public class InterestRateChartSlabFields { public boolean isFromPeriodGreaterThanToPeriod() { boolean isGreater = false; - if (this.toPeriod != null && fromPeriod.compareTo(this.toPeriod) > 1) { + if (this.toPeriod != null && this.fromPeriod.compareTo(this.toPeriod) > 1) { isGreater = true; } return isGreater; @@ -166,7 +202,7 @@ public class InterestRateChartSlabFields { return this.toPeriod; } - public boolean isPeriodOverlapping(InterestRateChartSlabFields that) { + public boolean isPeriodOverlapping(final InterestRateChartSlabFields that) { if (that.toPeriod == null) { if (this.toPeriod == null) { return true; } return that.fromPeriod <= this.toPeriod; @@ -187,9 +223,21 @@ public class InterestRateChartSlabFields { return this.annualInterestRate; } + public BigDecimal interestRateForFemale() { + return this.interestRateForFemale; + } + + public BigDecimal interestRateForChildren() { + return this.interestRateForChildren; + } + + public BigDecimal interestRateForSeniorCitizen() { + return this.interestRateForSeniorCitizen; + } + public Integer depositPeriod(final LocalDate periodStartDate, final LocalDate periodEndDate) { Integer actualDepositPeriod = 0; - final SavingsPeriodFrequencyType periodFrequencyType = SavingsPeriodFrequencyType.fromInt(this.periodType()); + final SavingsPeriodFrequencyType periodFrequencyType = SavingsPeriodFrequencyType.fromInt(periodType()); switch (periodFrequencyType) { case DAYS: actualDepositPeriod = Days.daysBetween(periodStartDate, periodEndDate).getDays(); @@ -216,7 +264,9 @@ public class InterestRateChartSlabFields { returnValue = depositAmount.compareTo(amountRangeFrom) >= 0 && depositAmount.compareTo(amountRangeTo) <= 0; } else if (amountRangeFrom != null) { returnValue = depositAmount.compareTo(amountRangeFrom) >= 0; - } else if (amountRangeTo != null) { return depositAmount.compareTo(amountRangeTo) <= 0; } + } else if (amountRangeTo != null) { + returnValue = depositAmount.compareTo(amountRangeTo) <= 0; + } return returnValue; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/handler/DeleteInterestRateChartSlabCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/handler/DeleteInterestRateChartSlabCommandHandler.java index b39321d02..235ca6c76 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/handler/DeleteInterestRateChartSlabCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/handler/DeleteInterestRateChartSlabCommandHandler.java @@ -24,6 +24,7 @@ public class DeleteInterestRateChartSlabCommandHandler implements NewCommandSour @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.deleteChartSlab(command.entityId(), command.interestRateChartId()); + //command.subentityId(); //returns chart id + return this.writePlatformService.deleteChartSlab(command.entityId(), command.subentityId()); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/handler/UpdateInterestRateChartSlabCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/handler/UpdateInterestRateChartSlabCommandHandler.java index d998c9480..52377c6b3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/handler/UpdateInterestRateChartSlabCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/handler/UpdateInterestRateChartSlabCommandHandler.java @@ -24,6 +24,7 @@ public class UpdateInterestRateChartSlabCommandHandler implements NewCommandSour @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.update(command.entityId(), command.interestRateChartId(), command); + //command.subentityId();//returns chart id + return this.writePlatformService.update(command.entityId(), command.subentityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartDropdownReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartDropdownReadPlatformServiceImpl.java index 0b5565d7c..2d59f56a0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartDropdownReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartDropdownReadPlatformServiceImpl.java @@ -8,7 +8,7 @@ package org.mifosplatform.portfolio.interestratechart.service; import java.util.Collection; import org.mifosplatform.infrastructure.core.data.EnumOptionData; -import org.mifosplatform.portfolio.interestratechart.InterestRateChartPeriodType; +import org.mifosplatform.portfolio.common.domain.PeriodFrequencyType; import org.springframework.stereotype.Service; @Service @@ -16,7 +16,7 @@ public class InterestRateChartDropdownReadPlatformServiceImpl implements Interes @Override public Collection retrievePeriodTypeOptions() { - return InterestRateChartEnumerations.periodType(InterestRateChartPeriodType.values()); + return InterestRateChartEnumerations.periodType(PeriodFrequencyType.values()); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartEnumerations.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartEnumerations.java index dc43941b7..0733602fa 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartEnumerations.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartEnumerations.java @@ -9,45 +9,45 @@ import java.util.ArrayList; import java.util.List; import org.mifosplatform.infrastructure.core.data.EnumOptionData; -import org.mifosplatform.portfolio.interestratechart.InterestRateChartPeriodType; +import org.mifosplatform.portfolio.common.domain.PeriodFrequencyType; public class InterestRateChartEnumerations { public static EnumOptionData periodType(final Integer type) { - return periodType(InterestRateChartPeriodType.fromInt(type)); + return periodType(PeriodFrequencyType.fromInt(type)); } - public static EnumOptionData periodType(final InterestRateChartPeriodType type) { - EnumOptionData optionData = new EnumOptionData(InterestRateChartPeriodType.INVALID.getValue().longValue(), - InterestRateChartPeriodType.INVALID.getCode(), "Invalid"); + public static EnumOptionData periodType(final PeriodFrequencyType type) { + EnumOptionData optionData = new EnumOptionData(PeriodFrequencyType.INVALID.getValue().longValue(), + PeriodFrequencyType.INVALID.getCode(), "Invalid"); switch (type) { case INVALID: break; case DAYS: - optionData = new EnumOptionData(InterestRateChartPeriodType.DAYS.getValue().longValue(), - InterestRateChartPeriodType.DAYS.getCode(), "Days"); + optionData = new EnumOptionData(PeriodFrequencyType.DAYS.getValue().longValue(), + PeriodFrequencyType.DAYS.getCode(), "Days"); break; case WEEKS: - optionData = new EnumOptionData(InterestRateChartPeriodType.WEEKS.getValue().longValue(), - InterestRateChartPeriodType.WEEKS.getCode(), "Weeks"); + optionData = new EnumOptionData(PeriodFrequencyType.WEEKS.getValue().longValue(), + PeriodFrequencyType.WEEKS.getCode(), "Weeks"); break; case MONTHS: - optionData = new EnumOptionData(InterestRateChartPeriodType.MONTHS.getValue().longValue(), - InterestRateChartPeriodType.MONTHS.getCode(), "Months"); + optionData = new EnumOptionData(PeriodFrequencyType.MONTHS.getValue().longValue(), + PeriodFrequencyType.MONTHS.getCode(), "Months"); break; case YEARS: - optionData = new EnumOptionData(InterestRateChartPeriodType.YEARS.getValue().longValue(), - InterestRateChartPeriodType.YEARS.getCode(), "Years"); + optionData = new EnumOptionData(PeriodFrequencyType.YEARS.getValue().longValue(), + PeriodFrequencyType.YEARS.getCode(), "Years"); break; } return optionData; } - public static List periodType(final InterestRateChartPeriodType[] periodTypes) { + public static List periodType(final PeriodFrequencyType[] periodTypes) { final List optionDatas = new ArrayList(); - for (final InterestRateChartPeriodType periodType : periodTypes) { + for (final PeriodFrequencyType periodType : periodTypes) { if (!periodType.isInvalid()) { optionDatas.add(periodType(periodType)); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartReadPlatformServiceImpl.java index d93f94298..e75d3e2d9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartReadPlatformServiceImpl.java @@ -47,13 +47,6 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha this.chartDropdownReadPlatformService = chartDropdownReadPlatformService; } - /* - * @Override public Collection retrieveAll(Long - * productId) { - * - * // TODO return null; } - */ - @Override public InterestRateChartData retrieveOne(Long chartId) { try { @@ -65,14 +58,6 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha } } - /* - * @Override public Collection - * retrieveAllWithSlabs() { this.context.authenticatedUser(); final String - * sql = "select " + this.chartExtractor.schema() + - * " order by irc.id, ircd.id "; return this.jdbcTemplate.query(sql, - * this.chartExtractor); } - */ - @Override public Collection retrieveAllWithSlabs(Long productId) { this.context.authenticatedUser(); @@ -143,6 +128,8 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha .append("ircd.id as ircdId, ircd.description as ircdDescription, ircd.period_type_enum ircdPeriodTypeId, ") .append("ircd.from_period as ircdFromPeriod, ircd.to_period as ircdToPeriod, ircd.amount_range_from as ircdAmountRangeFrom, ") .append("ircd.amount_range_to as ircdAmountRangeTo, ircd.annual_interest_rate as ircdAnnualInterestRate, ") + .append("ircd.interest_rate_for_female as ircdInterestRateForFemale, ircd.interest_rate_for_children as ircdInterestRateForChildren, ") + .append("ircd.interest_rate_for_senior_citizen as ircdInterestRateForSeniorCitizen, ") .append("curr.code as currencyCode, curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ") .append("curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf, ") .append("sp.id as savingsProductId, sp.name as savingsProductName ") @@ -198,7 +185,7 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha final StringBuilder sqlBuilder = new StringBuilder(400); sqlBuilder.append("irc.id as ircId, irc.name as ircName, irc.description as ircDescription, ") - .append("irc.from_date as ircFromDate, irc.end_date as ircEndDate, irc.is_active_chart as isActiveChart, ") + .append("irc.from_date as ircFromDate, irc.end_date as ircEndDate, ") .append("sp.id as savingsProductId, sp.name as savingsProductName ").append("from ") .append("m_interest_rate_chart irc ") .append("left join m_deposit_product_interest_rate_chart dpirc on irc.id=dpirc.interest_rate_chart_id ") @@ -213,10 +200,10 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha final String description = rs.getString("ircDescription"); final LocalDate fromDate = JdbcSupport.getLocalDate(rs, "ircFromDate"); final LocalDate endDate = JdbcSupport.getLocalDate(rs, "ircEndDate"); - final Long savingsProductId = rs.getLong("savingsProductId"); + final Long savingsProductId = JdbcSupport.getLongDefaultToNullIfZero(rs, "savingsProductId"); final String savingsProductName = rs.getString("savingsProductName"); - return InterestRateChartData.instance(id, name, description, fromDate, endDate, savingsProductId, savingsProductName, null); + return InterestRateChartData.instance(id, name, description, fromDate, endDate, savingsProductId, savingsProductName); } } @@ -237,6 +224,8 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha .append("ircd.id as ircdId, ircd.description as ircdDescription, ircd.period_type_enum ircdPeriodTypeId, ") .append("ircd.from_period as ircdFromPeriod, ircd.to_period as ircdToPeriod, ircd.amount_range_from as ircdAmountRangeFrom, ") .append("ircd.amount_range_to as ircdAmountRangeTo, ircd.annual_interest_rate as ircdAnnualInterestRate, ") + .append("ircd.interest_rate_for_female as ircdInterestRateForFemale, ircd.interest_rate_for_children as ircdInterestRateForChildren, ") + .append("ircd.interest_rate_for_senior_citizen as ircdInterestRateForSeniorCitizen, ") .append("curr.code as currencyCode, curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ") .append("curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf ") .append("from ").append("m_interest_rate_slab ircd ") @@ -259,6 +248,9 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha final BigDecimal amountRangeFrom = rs.getBigDecimal("ircdAmountRangeFrom"); final BigDecimal amountRangeTo = rs.getBigDecimal("ircdAmountRangeTo"); final BigDecimal annualInterestRate = rs.getBigDecimal("ircdAnnualInterestRate"); + final BigDecimal interestRateForFemale = rs.getBigDecimal("ircdInterestRateForFemale"); + final BigDecimal interestRateForChildren = rs.getBigDecimal("ircdInterestRateForChildren"); + final BigDecimal interestRateForSeniorCitizen = rs.getBigDecimal("ircdInterestRateForSeniorCitizen"); // currency Slabs final String currencyCode = rs.getString("currencyCode"); @@ -272,7 +264,7 @@ public class InterestRateChartReadPlatformServiceImpl implements InterestRateCha currencyDisplaySymbol, currencyNameCode); return InterestRateChartSlabData.instance(id, description, periodType, fromPeriod, toPeriod, amountRangeFrom, amountRangeTo, - annualInterestRate, currency); + annualInterestRate, interestRateForFemale, interestRateForChildren, interestRateForSeniorCitizen, currency); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabAssembler.java index 1b0cfb428..d5072dc32 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabAssembler.java @@ -5,14 +5,17 @@ */ package org.mifosplatform.portfolio.interestratechart.service; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.amountRangeFromParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.amountRangeToParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.annualInterestRateParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.amountRangeFromParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.amountRangeToParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.annualInterestRateParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForFemaleParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForChildrenParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.interestRateForSeniorCitizenParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.chartSlabs; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.descriptionParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.fromPeriodParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.periodTypeParamName; -import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.toPeriodParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.fromPeriodParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.periodTypeParamName; +import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.toPeriodParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.INTERESTRATE_CHART_SLAB_RESOURCE_NAME; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartSlabApiConstants.currencyCodeParamName; @@ -32,6 +35,7 @@ import org.mifosplatform.portfolio.interestratechart.data.InterestRateChartRepos import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChart; import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChartSlab; import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChartSlabFields; +import org.mifosplatform.portfolio.interestratechart.exception.InterestRateChartSlabNotFoundException; import org.mifosplatform.portfolio.savings.SavingsPeriodFrequencyType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -64,7 +68,7 @@ public class InterestRateChartSlabAssembler { final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(elementObject); final String currencyCode = command.stringValueOfParameterNamed(currencyCodeParamName); - final Long chartId = command.interestRateChartId(); + final Long chartId = command.subentityId();// returns chart id final InterestRateChart chart = this.interestRateChartRepositoryWrapper.findOneWithNotFoundDetection(chartId); @@ -91,8 +95,12 @@ public class InterestRateChartSlabAssembler { final BigDecimal amountRangeFrom = this.fromApiJsonHelper.extractBigDecimalNamed(amountRangeFromParamName, element, locale); final BigDecimal amountRangeTo = this.fromApiJsonHelper.extractBigDecimalNamed(amountRangeToParamName, element, locale); final BigDecimal annualInterestRate = this.fromApiJsonHelper.extractBigDecimalNamed(annualInterestRateParamName, element, locale); + final BigDecimal interestRateForFemale = this.fromApiJsonHelper.extractBigDecimalNamed(interestRateForFemaleParamName, element, locale); + final BigDecimal interestRateForChildren = this.fromApiJsonHelper.extractBigDecimalNamed(interestRateForChildrenParamName, element, locale); + final BigDecimal interestRateForSeniorCitizen = this.fromApiJsonHelper.extractBigDecimalNamed(interestRateForSeniorCitizenParamName, element, locale); + final InterestRateChartSlabFields slabFields = InterestRateChartSlabFields.createNew(description, periodType, fromPeriod, toPeriod, - amountRangeFrom, amountRangeTo, annualInterestRate, currencyCode); + amountRangeFrom, amountRangeTo, annualInterestRate, interestRateForFemale, interestRateForChildren, interestRateForSeniorCitizen, currencyCode); return InterestRateChartSlab.createNew(slabFields, interestRateChart); } @@ -100,6 +108,9 @@ public class InterestRateChartSlabAssembler { public InterestRateChartSlab assembleFrom(final Long chartSlabId, final Long chartId) { final InterestRateChart chart = this.interestRateChartRepositoryWrapper.findOneWithNotFoundDetection(chartId); final InterestRateChartSlab interestRateChartSlab = chart.findChartSlab(chartSlabId); + + if (interestRateChartSlab == null) throw new InterestRateChartSlabNotFoundException(chartSlabId, chartId); + return interestRateChartSlab; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabReadPlatformService.java index b27e8d5fa..649def7d1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabReadPlatformService.java @@ -16,4 +16,6 @@ public interface InterestRateChartSlabReadPlatformService { InterestRateChartSlabData retrieveOne(Long chartId, Long chartSlabId); InterestRateChartSlabData retrieveWithTemplate(InterestRateChartSlabData chartSlab); + + InterestRateChartSlabData retrieveTemplate(); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabReadPlatformServiceImpl.java index a345ed8a8..8f25e7ce7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabReadPlatformServiceImpl.java @@ -62,6 +62,11 @@ public class InterestRateChartSlabReadPlatformServiceImpl implements InterestRat return InterestRateChartSlabData.withTemplate(chartSlab, this.chartDropdownReadPlatformService.retrievePeriodTypeOptions()); } + @Override + public InterestRateChartSlabData retrieveTemplate() { + return InterestRateChartSlabData.template(this.chartDropdownReadPlatformService.retrievePeriodTypeOptions()); + } + private static final class InterestRateChartSlabsMapper implements RowMapper { private final String schemaSql; @@ -77,6 +82,8 @@ public class InterestRateChartSlabReadPlatformServiceImpl implements InterestRat .append("ircd.id as ircdId, ircd.description as ircdDescription, ircd.period_type_enum ircdPeriodTypeId, ") .append("ircd.from_period as ircdFromPeriod, ircd.to_period as ircdToPeriod, ircd.amount_range_from as ircdAmountRangeFrom, ") .append("ircd.amount_range_to as ircdAmountRangeTo, ircd.annual_interest_rate as ircdAnnualInterestRate, ") + .append("ircd.interest_rate_for_female as ircdInterestRateForFemale, ircd.interest_rate_for_children as ircdInterestRateForChildren, ") + .append("ircd.interest_rate_for_senior_citizen as ircdInterestRateForSeniorCitizen, ") .append("curr.code as currencyCode, curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ") .append("curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf ") .append("from ").append("m_interest_rate_slab ircd ") @@ -99,6 +106,9 @@ public class InterestRateChartSlabReadPlatformServiceImpl implements InterestRat final BigDecimal amountRangeFrom = rs.getBigDecimal("ircdAmountRangeFrom"); final BigDecimal amountRangeTo = rs.getBigDecimal("ircdAmountRangeTo"); final BigDecimal annualInterestRate = rs.getBigDecimal("ircdAnnualInterestRate"); + final BigDecimal interestRateForFemale = rs.getBigDecimal("ircdInterestRateForFemale"); + final BigDecimal interestRateForChildren = rs.getBigDecimal("ircdInterestRateForChildren"); + final BigDecimal interestRateForSeniorCitizen = rs.getBigDecimal("ircdInterestRateForSeniorCitizen"); // currency Slabs final String currencyCode = rs.getString("currencyCode"); @@ -112,7 +122,7 @@ public class InterestRateChartSlabReadPlatformServiceImpl implements InterestRat currencyDisplaySymbol, currencyNameCode); return InterestRateChartSlabData.instance(id, description, periodType, fromPeriod, toPeriod, amountRangeFrom, amountRangeTo, - annualInterestRate, currency); + annualInterestRate, interestRateForFemale, interestRateForChildren, interestRateForSeniorCitizen, currency); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabWritePlatformServiceJpaRepositoryImpl.java index 9048a14fe..42a1cc002 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/interestratechart/service/InterestRateChartSlabWritePlatformServiceJpaRepositoryImpl.java @@ -63,7 +63,7 @@ public class InterestRateChartSlabWritePlatformServiceJpaRepositoryImpl implemen final InterestRateChartSlab interestRateChartSlab = this.interestRateChartSlabAssembler.assembleFrom(command); - this.chartSlabRepository.saveAndFlush(interestRateChartSlab); + this.chartSlabRepository.save(interestRateChartSlab); final Long interestRateChartId = interestRateChartSlab.getId(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index 994294b9b..fddd92a7f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -121,6 +121,7 @@ import org.mifosplatform.portfolio.note.domain.Note; import org.mifosplatform.portfolio.note.domain.NoteRepository; import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail; import org.mifosplatform.portfolio.paymentdetail.service.PaymentDetailWritePlatformService; +import org.mifosplatform.portfolio.savings.domain.SavingsAccount; import org.mifosplatform.portfolio.savings.exception.InsufficientAccountBalanceException; import org.mifosplatform.useradministration.domain.AppUser; import org.slf4j.Logger; @@ -319,10 +320,11 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); for (final Map.Entry entrySet : disBuLoanCharges.entrySet()) { final PortfolioAccountData savingAccountData = this.accountAssociationsReadPlatformService.retriveLoanAssociation(loanId); + final SavingsAccount fromSavingsAccount = null; final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(actualDisbursementDate, entrySet.getValue(), PortfolioAccountType.SAVINGS, PortfolioAccountType.LOAN, savingAccountData.accountId(), loanId, "Loan Charge Payment", locale, fmt, null, null, LoanTransactionType.REPAYMENT_AT_DISBURSEMENT.getValue(), entrySet.getKey(), null, - AccountTransferType.CHARGE_PAYMENT.getValue(), null, null, null, null, null); + AccountTransferType.CHARGE_PAYMENT.getValue(), null, null, null, null, null, fromSavingsAccount); this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); } @@ -491,10 +493,12 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf for (final Map.Entry entrySet : disBuLoanCharges.entrySet()) { final PortfolioAccountData savingAccountData = this.accountAssociationsReadPlatformService.retriveLoanAssociation(loan .getId()); + final SavingsAccount fromSavingsAccount = null; final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(actualDisbursementDate, entrySet.getValue(), PortfolioAccountType.SAVINGS, PortfolioAccountType.LOAN, savingAccountData.accountId(), loan.getId(), "Loan Charge Payment", locale, fmt, null, null, LoanTransactionType.REPAYMENT_AT_DISBURSEMENT.getValue(), - entrySet.getKey(), null, AccountTransferType.CHARGE_PAYMENT.getValue(), null, null, null, null, null); + entrySet.getKey(), null, AccountTransferType.CHARGE_PAYMENT.getValue(), null, null, null, null, null, + fromSavingsAccount); this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); } } @@ -1252,10 +1256,11 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final String errorMessage = "Charge with id:" + loanChargeId + " requires linked savings account for payment"; throw new LinkedAccountRequiredException("loanCharge.pay", errorMessage, loanChargeId); } + final SavingsAccount fromSavingsAccount = null; final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, amount, PortfolioAccountType.SAVINGS, PortfolioAccountType.LOAN, portfolioAccountData.accountId(), loanId, "Loan Charge Payment", locale, fmt, null, null, LoanTransactionType.CHARGE_PAYMENT.getValue(), loanChargeId, loanInstallmentNumber, - AccountTransferType.CHARGE_PAYMENT.getValue(), null, null, null, null, null); + AccountTransferType.CHARGE_PAYMENT.getValue(), null, null, null, null, null, fromSavingsAccount); this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); return new CommandProcessingResultBuilder() // @@ -1280,11 +1285,11 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final String errorMessage = "Disburse Loan with id:" + loan.getId() + " requires linked savings account for payment"; throw new LinkedAccountRequiredException("loan.disburse.to.savings", errorMessage, loan.getId()); } - + final SavingsAccount fromSavingsAccount = null; final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, amount.getAmount(), PortfolioAccountType.LOAN, PortfolioAccountType.SAVINGS, loan.getId(), portfolioAccountData.accountId(), "Loan Disbursement", locale, fmt, paymentDetail, LoanTransactionType.DISBURSEMENT.getValue(), null, null, null, - AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, txnExternalId, loan, null); + AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, txnExternalId, loan, null, fromSavingsAccount); this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); } @@ -1307,23 +1312,25 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf portfolioAccountData = this.accountAssociationsReadPlatformService.retriveLoanAssociation(chargeData .getLoanId()); } + final SavingsAccount fromSavingsAccount = null; final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(new LocalDate(), installmentChargeData.getAmountOutstanding(), PortfolioAccountType.SAVINGS, PortfolioAccountType.LOAN, portfolioAccountData.accountId(), chargeData.getLoanId(), "Loan Charge Payment", null, null, null, null, LoanTransactionType.CHARGE_PAYMENT.getValue(), chargeData.getId(), installmentChargeData.getInstallmentNumber(), AccountTransferType.CHARGE_PAYMENT.getValue(), null, - null, null, null, null); + null, null, null, null, fromSavingsAccount); transferFeeCharge(sb, accountTransferDTO); } } } else if (chargeData.getDueDate() != null && !chargeData.getDueDate().isAfter(new LocalDate())) { final PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService .retriveLoanAssociation(chargeData.getLoanId()); + final SavingsAccount fromSavingsAccount = null; final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(new LocalDate(), chargeData.getAmountOutstanding(), PortfolioAccountType.SAVINGS, PortfolioAccountType.LOAN, portfolioAccountData.accountId(), chargeData.getLoanId(), "Loan Charge Payment", null, null, null, null, LoanTransactionType.CHARGE_PAYMENT.getValue(), chargeData.getId(), null, - AccountTransferType.CHARGE_PAYMENT.getValue(), null, null, null, null, null); + AccountTransferType.CHARGE_PAYMENT.getValue(), null, null, null, null, null, fromSavingsAccount); transferFeeCharge(sb, accountTransferDTO); } } @@ -1812,7 +1819,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final JsonElement parsedCommand = this.fromApiJsonHelper.parse(overdueInstallment.toString()); final JsonCommand command = JsonCommand.from(overdueInstallment.toString(), parsedCommand, this.fromApiJsonHelper, - null, null, null, null, null, overdueInstallment.getLoanId(), null, null, null, null, null, null); + null, null, null, null, null, overdueInstallment.getLoanId(), null, null, null, null); applyChargeToOverdueLoanInstallment(overdueInstallment.getLoanId(), overdueInstallment.getChargeId(), overdueInstallment.getPeriodNumber(), command); @@ -2032,10 +2039,11 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final String errorMessage = "Charge with id:" + loanChargeId + " requires linked savings account for payment"; throw new LinkedAccountRequiredException("loanCharge.pay", errorMessage, loanChargeId); } + final SavingsAccount fromSavingsAccount = null; final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, amount, PortfolioAccountType.SAVINGS, PortfolioAccountType.LOAN, portfolioAccountData.accountId(), loanId, "Loan Charge Payment", locale, fmt, null, null, LoanTransactionType.CHARGE_PAYMENT.getValue(), loanChargeId, loanInstallmentNumber, - AccountTransferType.CHARGE_PAYMENT.getValue(), null, null, null, null, null); + AccountTransferType.CHARGE_PAYMENT.getValue(), null, null, null, null, null, fromSavingsAccount); this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); return transaction; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/meeting/api/MeetingsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/meeting/api/MeetingsApiResource.java index a69de16a8..e38675944 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/meeting/api/MeetingsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/meeting/api/MeetingsApiResource.java @@ -247,6 +247,9 @@ public class MeetingsApiResource { case LOANS: resourceDetails.withLoanId(entityId); break; + case SAVINGS: + resourceDetails.withSavingsId(entityId); + break; case INVALID: break; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/DepositsApiConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/DepositsApiConstants.java index 074e15f71..b2b3d4b82 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/DepositsApiConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/DepositsApiConstants.java @@ -97,10 +97,6 @@ public class DepositsApiConstants { public static final String bankNumberParamName = "bankNumber"; // Preclosure parameters - public static final String interestFreePeriodApplicableParamName = "interestFreePeriodApplicable"; - public static final String interestFreeFromPeriodParamName = "interestFreeFromPeriod"; - public static final String interestFreeToPeriodParamName = "interestFreeToPeriod"; - public static final String interestFreePeriodFrequencyTypeIdParamName = "interestFreePeriodFrequencyTypeId"; public static final String preClosurePenalApplicableParamName = "preClosurePenalApplicable"; public static final String preClosurePenalInterestParamName = "preClosurePenalInterest"; public static final String preClosurePenalInterestOnTypeIdParamName = "preClosurePenalInterestOnTypeId"; @@ -125,12 +121,14 @@ public class DepositsApiConstants { public static final String depositPeriodFrequencyIdParamName = "depositPeriodFrequencyId"; // recurring parameters - public static final String recurringDepositAmountParamName = "recurringDepositAmount"; - public static final String recurringDepositType = "recurringDepositType"; - public static final String recurringDepositFrequencyType = "recurringDepositFrequencyType"; - public static final String recurringDepositFrequencyParamName = "recurringDepositFrequency"; - public static final String recurringDepositTypeIdParamName = "recurringDepositTypeId"; - public static final String recurringDepositFrequencyTypeIdParamName = "recurringDepositFrequencyTypeId"; + public static final String mandatoryRecommendedDepositAmountParamName = "mandatoryRecommendedDepositAmount"; + public static final String isMandatoryDepositParamName = "isMandatoryDeposit"; + public static final String allowWithdrawalParamName = "allowWithdrawal"; + public static final String adjustAdvanceTowardsFuturePaymentsParamName = "adjustAdvanceTowardsFuturePayments"; + + public static final String recurringFrequencyTypeParamName = "recurringFrequencyType"; + public static final String recurringFrequencyParamName = "recurringFrequency"; + public static final String isCalendarInheritedParamName = "isCalendarInherited"; // transaction parameters public static final String transactionDateParamName = "transactionDate"; @@ -206,14 +204,10 @@ public class DepositsApiConstants { SAVINGS_PRODUCT_ACCOUNTING_PARAMS.PENALTY_INCOME_ACCOUNT_MAPPING.getValue(), chartsParamName)); private static final Set PRECLOSURE_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList( - interestFreePeriodApplicableParamName, interestFreeFromPeriodParamName, interestFreeToPeriodParamName, - interestFreePeriodFrequencyTypeIdParamName, preClosurePenalApplicableParamName, preClosurePenalInterestParamName, - preClosurePenalInterestOnTypeIdParamName)); + preClosurePenalApplicableParamName, preClosurePenalInterestParamName, preClosurePenalInterestOnTypeIdParamName)); private static final Set PRECLOSURE_RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList( - interestFreePeriodApplicableParamName, interestFreeFromPeriodParamName, interestFreeToPeriodParamName, - interestFreePeriodFrequencyType, preClosurePenalApplicableParamName, preClosurePenalInterestParamName, - preClosurePenalInterestOnType)); + preClosurePenalApplicableParamName, preClosurePenalInterestParamName, preClosurePenalInterestOnType)); private static final Set DEPOSIT_TERM_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(minDepositTermParamName, maxDepositTermParamName, minDepositTermTypeIdParamName, maxDepositTermTypeIdParamName, inMultiplesOfDepositTermParamName, @@ -224,11 +218,14 @@ public class DepositsApiConstants { inMultiplesOfDepositTermType, depositAmountParamName, depositMinAmountParamName, depositMaxAmountParamName)); private static final Set RECURRING_DETAILS_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList( - recurringDepositAmountParamName, recurringDepositTypeIdParamName, recurringDepositFrequencyTypeIdParamName, - recurringDepositFrequencyParamName)); + mandatoryRecommendedDepositAmountParamName, isMandatoryDepositParamName, allowWithdrawalParamName, + adjustAdvanceTowardsFuturePaymentsParamName, recurringFrequencyTypeParamName, recurringFrequencyParamName, + isCalendarInheritedParamName)); private static final Set RECURRING_DETAILS_RESPONSE_DATA_PARAMETERS = new HashSet(Arrays.asList( - recurringDepositAmountParamName, recurringDepositType, recurringDepositFrequencyParamName, recurringDepositFrequencyType)); + mandatoryRecommendedDepositAmountParamName, isMandatoryDepositParamName, allowWithdrawalParamName, + adjustAdvanceTowardsFuturePaymentsParamName, recurringFrequencyTypeParamName, recurringFrequencyParamName, + isCalendarInheritedParamName)); public static final Set DEPOSIT_PRECLOSURE_CALCULATION_REQUEST_DATA_PARAMETERS = new HashSet( Arrays.asList(preMatureCloseOnDateParamName)); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/FixedDepositProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/FixedDepositProductsApiResource.java index ed2d7ffc8..92d404757 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/FixedDepositProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/FixedDepositProductsApiResource.java @@ -44,6 +44,7 @@ import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService; import org.mifosplatform.portfolio.charge.data.ChargeData; import org.mifosplatform.portfolio.charge.service.ChargeReadPlatformService; +import org.mifosplatform.portfolio.common.service.DropdownReadPlatformService; import org.mifosplatform.portfolio.interestratechart.data.InterestRateChartData; import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartReadPlatformService; import org.mifosplatform.portfolio.paymentdetail.PaymentDetailConstants; @@ -69,7 +70,7 @@ import org.springframework.util.CollectionUtils; public class FixedDepositProductsApiResource { private final DepositProductReadPlatformService depositProductReadPlatformService; - private final SavingsDropdownReadPlatformService dropdownReadPlatformService; + private final SavingsDropdownReadPlatformService savingsDropdownReadPlatformService; private final CurrencyReadPlatformService currencyReadPlatformService; private final PlatformSecurityContext context; private final DefaultToApiJsonSerializer toApiJsonSerializer; @@ -82,10 +83,11 @@ public class FixedDepositProductsApiResource { private final InterestRateChartReadPlatformService chartReadPlatformService; private final InterestRateChartReadPlatformService interestRateChartReadPlatformService; private final DepositsDropdownReadPlatformService depositsDropdownReadPlatformService; + private final DropdownReadPlatformService dropdownReadPlatformService; @Autowired public FixedDepositProductsApiResource(final DepositProductReadPlatformService depositProductReadPlatformService, - final SavingsDropdownReadPlatformService dropdownReadPlatformService, + final SavingsDropdownReadPlatformService savingsDropdownReadPlatformService, final CurrencyReadPlatformService currencyReadPlatformService, final PlatformSecurityContext context, final DefaultToApiJsonSerializer toApiJsonSerializer, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, @@ -94,9 +96,10 @@ public class FixedDepositProductsApiResource { final ProductToGLAccountMappingReadPlatformService accountMappingReadPlatformService, final ChargeReadPlatformService chargeReadPlatformService, final InterestRateChartReadPlatformService chartReadPlatformService, final InterestRateChartReadPlatformService interestRateChartReadPlatformService, - final DepositsDropdownReadPlatformService depositsDropdownReadPlatformService) { + final DepositsDropdownReadPlatformService depositsDropdownReadPlatformService, + final DropdownReadPlatformService dropdownReadPlatformService) { this.depositProductReadPlatformService = depositProductReadPlatformService; - this.dropdownReadPlatformService = dropdownReadPlatformService; + this.savingsDropdownReadPlatformService = savingsDropdownReadPlatformService; this.currencyReadPlatformService = currencyReadPlatformService; this.context = context; this.toApiJsonSerializer = toApiJsonSerializer; @@ -109,6 +112,7 @@ public class FixedDepositProductsApiResource { this.chartReadPlatformService = chartReadPlatformService; this.interestRateChartReadPlatformService = interestRateChartReadPlatformService; this.depositsDropdownReadPlatformService = depositsDropdownReadPlatformService; + this.dropdownReadPlatformService = dropdownReadPlatformService; } @POST @@ -231,22 +235,23 @@ public class FixedDepositProductsApiResource { currency = new ArrayList(currencyOptions).get(0); } - final Collection interestCompoundingPeriodTypeOptions = this.dropdownReadPlatformService + final Collection interestCompoundingPeriodTypeOptions = this.savingsDropdownReadPlatformService .retrieveCompoundingInterestPeriodTypeOptions(); - final Collection interestPostingPeriodTypeOptions = this.dropdownReadPlatformService + final Collection interestPostingPeriodTypeOptions = this.savingsDropdownReadPlatformService .retrieveInterestPostingPeriodTypeOptions(); - final Collection interestCalculationTypeOptions = this.dropdownReadPlatformService + final Collection interestCalculationTypeOptions = this.savingsDropdownReadPlatformService .retrieveInterestCalculationTypeOptions(); - final Collection interestCalculationDaysInYearTypeOptions = this.dropdownReadPlatformService + final Collection interestCalculationDaysInYearTypeOptions = this.savingsDropdownReadPlatformService .retrieveInterestCalculationDaysInYearTypeOptions(); - final Collection lockinPeriodFrequencyTypeOptions = this.dropdownReadPlatformService + final Collection lockinPeriodFrequencyTypeOptions = this.savingsDropdownReadPlatformService .retrieveLockinPeriodFrequencyTypeOptions(); - final Collection withdrawalFeeTypeOptions = this.dropdownReadPlatformService.retrievewithdrawalFeeTypeOptions(); + final Collection withdrawalFeeTypeOptions = this.savingsDropdownReadPlatformService + .retrievewithdrawalFeeTypeOptions(); final Collection paymentTypeOptions = this.codeValueReadPlatformService .retrieveCodeValuesByCode(PaymentDetailConstants.paymentTypeCodeName); @@ -260,13 +265,7 @@ public class FixedDepositProductsApiResource { final Collection preClosurePenalInterestOnTypeOptions = this.depositsDropdownReadPlatformService .retrievePreClosurePenalInterestOnTypeOptions(); - final Collection interestFreePeriodTypeOptions = this.depositsDropdownReadPlatformService - .retrieveInterestFreePeriodFrequencyTypeOptions(); - - final Collection depositTermTypeOptions = this.depositsDropdownReadPlatformService.retrieveDepositTermTypeOptions(); - - final Collection inMultiplesOfDepositTermTypeOptions = this.depositsDropdownReadPlatformService - .retrieveInMultiplesOfDepositTermTypeOptions(); + final Collection periodFrequencyTypeOptions = this.dropdownReadPlatformService.retrievePeriodFrequencyTypeOptions(); // charges final boolean feeChargesOnly = true; @@ -285,16 +284,14 @@ public class FixedDepositProductsApiResource { interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, chargeOptions, penaltyOptions, chartTemplate, - interestFreePeriodTypeOptions, preClosurePenalInterestOnTypeOptions, depositTermTypeOptions, - inMultiplesOfDepositTermTypeOptions); + preClosurePenalInterestOnTypeOptions, periodFrequencyTypeOptions); } else { fixedDepositProductToReturn = FixedDepositProductData.template(currency, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, accountingRule, currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, chargeOptions, penaltyOptions, chartTemplate, - interestFreePeriodTypeOptions, preClosurePenalInterestOnTypeOptions, depositTermTypeOptions, - inMultiplesOfDepositTermTypeOptions); + preClosurePenalInterestOnTypeOptions, periodFrequencyTypeOptions); } return fixedDepositProductToReturn; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositAccountTransactionsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositAccountTransactionsApiResource.java index def6c996a..9aee80458 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositAccountTransactionsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositAccountTransactionsApiResource.java @@ -90,7 +90,7 @@ public class RecurringDepositAccountTransactionsApiResource { savingsAccount = this.depositAccountReadPlatformService .retrieveRecurringAccountDepositTransactionTemplate(recurringDepositAccountId); } else if (is(commandParam, "withdrawal")) { - + // } else { throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "deposit", "withdrawal" }); } @@ -168,7 +168,7 @@ public class RecurringDepositAccountTransactionsApiResource { CommandProcessingResult result = null; if (is(commandParam, DepositsApiConstants.COMMAND_UNDO_TRANSACTION)) { - final CommandWrapper commandRequest = builder.undoSavingsAccountTransaction(recurringDepositAccountId, transactionId).build(); + final CommandWrapper commandRequest = builder.undoRecurringAccountTransaction(recurringDepositAccountId, transactionId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, DepositsApiConstants.COMMAND_ADJUST_TRANSACTION)) { final CommandWrapper commandRequest = builder.adjustRecurringAccountTransaction(recurringDepositAccountId, transactionId).build(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositProductsApiResource.java index 5b13d0264..97e2500e9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/api/RecurringDepositProductsApiResource.java @@ -44,6 +44,7 @@ import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService; import org.mifosplatform.portfolio.charge.data.ChargeData; import org.mifosplatform.portfolio.charge.service.ChargeReadPlatformService; +import org.mifosplatform.portfolio.common.service.DropdownReadPlatformService; import org.mifosplatform.portfolio.interestratechart.data.InterestRateChartData; import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartReadPlatformService; import org.mifosplatform.portfolio.paymentdetail.PaymentDetailConstants; @@ -69,7 +70,7 @@ import org.springframework.util.CollectionUtils; public class RecurringDepositProductsApiResource { private final DepositProductReadPlatformService depositProductReadPlatformService; - private final SavingsDropdownReadPlatformService dropdownReadPlatformService; + private final SavingsDropdownReadPlatformService savingsDropdownReadPlatformService; private final CurrencyReadPlatformService currencyReadPlatformService; private final PlatformSecurityContext context; private final DefaultToApiJsonSerializer toApiJsonSerializer; @@ -82,10 +83,11 @@ public class RecurringDepositProductsApiResource { private final InterestRateChartReadPlatformService chartReadPlatformService; private final InterestRateChartReadPlatformService interestRateChartReadPlatformService; private final DepositsDropdownReadPlatformService depositsDropdownReadPlatformService; + private final DropdownReadPlatformService dropdownReadPlatformService; @Autowired public RecurringDepositProductsApiResource(final DepositProductReadPlatformService depositProductReadPlatformService, - final SavingsDropdownReadPlatformService dropdownReadPlatformService, + final SavingsDropdownReadPlatformService savingsDropdownReadPlatformService, final CurrencyReadPlatformService currencyReadPlatformService, final PlatformSecurityContext context, final DefaultToApiJsonSerializer toApiJsonSerializer, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, @@ -94,9 +96,10 @@ public class RecurringDepositProductsApiResource { final ProductToGLAccountMappingReadPlatformService accountMappingReadPlatformService, final ChargeReadPlatformService chargeReadPlatformService, final InterestRateChartReadPlatformService chartReadPlatformService, final InterestRateChartReadPlatformService interestRateChartReadPlatformService, - final DepositsDropdownReadPlatformService depositsDropdownReadPlatformService) { + final DepositsDropdownReadPlatformService depositsDropdownReadPlatformService, + final DropdownReadPlatformService dropdownReadPlatformService) { this.depositProductReadPlatformService = depositProductReadPlatformService; - this.dropdownReadPlatformService = dropdownReadPlatformService; + this.savingsDropdownReadPlatformService = savingsDropdownReadPlatformService; this.currencyReadPlatformService = currencyReadPlatformService; this.context = context; this.toApiJsonSerializer = toApiJsonSerializer; @@ -109,6 +112,7 @@ public class RecurringDepositProductsApiResource { this.chartReadPlatformService = chartReadPlatformService; this.interestRateChartReadPlatformService = interestRateChartReadPlatformService; this.depositsDropdownReadPlatformService = depositsDropdownReadPlatformService; + this.dropdownReadPlatformService = dropdownReadPlatformService; } @POST @@ -232,22 +236,23 @@ public class RecurringDepositProductsApiResource { currency = new ArrayList(currencyOptions).get(0); } - final Collection interestCompoundingPeriodTypeOptions = this.dropdownReadPlatformService + final Collection interestCompoundingPeriodTypeOptions = this.savingsDropdownReadPlatformService .retrieveCompoundingInterestPeriodTypeOptions(); - final Collection interestPostingPeriodTypeOptions = this.dropdownReadPlatformService + final Collection interestPostingPeriodTypeOptions = this.savingsDropdownReadPlatformService .retrieveInterestPostingPeriodTypeOptions(); - final Collection interestCalculationTypeOptions = this.dropdownReadPlatformService + final Collection interestCalculationTypeOptions = this.savingsDropdownReadPlatformService .retrieveInterestCalculationTypeOptions(); - final Collection interestCalculationDaysInYearTypeOptions = this.dropdownReadPlatformService + final Collection interestCalculationDaysInYearTypeOptions = this.savingsDropdownReadPlatformService .retrieveInterestCalculationDaysInYearTypeOptions(); - final Collection lockinPeriodFrequencyTypeOptions = this.dropdownReadPlatformService + final Collection lockinPeriodFrequencyTypeOptions = this.savingsDropdownReadPlatformService .retrieveLockinPeriodFrequencyTypeOptions(); - final Collection withdrawalFeeTypeOptions = this.dropdownReadPlatformService.retrievewithdrawalFeeTypeOptions(); + final Collection withdrawalFeeTypeOptions = this.savingsDropdownReadPlatformService + .retrievewithdrawalFeeTypeOptions(); final Collection paymentTypeOptions = this.codeValueReadPlatformService .retrieveCodeValuesByCode(PaymentDetailConstants.paymentTypeCodeName); @@ -257,8 +262,6 @@ public class RecurringDepositProductsApiResource { .retrieveAccountMappingOptionsForSavingsProducts(); final Collection preClosurePenalInterestOnTypeOptions = this.depositsDropdownReadPlatformService .retrievePreClosurePenalInterestOnTypeOptions(); - final Collection interestFreePeriodTypeOptions = this.depositsDropdownReadPlatformService - .retrieveInterestFreePeriodFrequencyTypeOptions(); // charges final boolean feeChargesOnly = true; @@ -268,15 +271,7 @@ public class RecurringDepositProductsApiResource { Collection penaltyOptions = this.chargeReadPlatformService.retrieveSavingsAccountApplicablePenalties(); penaltyOptions = CollectionUtils.isEmpty(penaltyOptions) ? null : penaltyOptions; - Collection recurringDepositTypeOptions = this.depositsDropdownReadPlatformService - .retrieveRecurringDepositTypeOptions(); - Collection recurringDepositFrequencyTypeOptions = this.depositsDropdownReadPlatformService - .retrieveRecurringDepositFrequencyTypeOptions(); - - final Collection depositTermTypeOptions = this.depositsDropdownReadPlatformService.retrieveDepositTermTypeOptions(); - - final Collection inMultiplesOfDepositTermTypeOptions = this.depositsDropdownReadPlatformService - .retrieveInMultiplesOfDepositTermTypeOptions(); + final Collection periodFrequencyTypeOptions = this.dropdownReadPlatformService.retrievePeriodFrequencyTypeOptions(); // interest rate chart template final InterestRateChartData chartTemplate = this.interestRateChartReadPlatformService.template(); @@ -287,16 +282,14 @@ public class RecurringDepositProductsApiResource { interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, chargeOptions, penaltyOptions, chartTemplate, - interestFreePeriodTypeOptions, preClosurePenalInterestOnTypeOptions, recurringDepositTypeOptions, - recurringDepositFrequencyTypeOptions, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions); + preClosurePenalInterestOnTypeOptions, periodFrequencyTypeOptions); } else { recurringDepositProductToReturn = RecurringDepositProductData.template(currency, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, accountingRule, currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, chargeOptions, penaltyOptions, chartTemplate, - interestFreePeriodTypeOptions, preClosurePenalInterestOnTypeOptions, recurringDepositTypeOptions, - recurringDepositFrequencyTypeOptions, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions); + preClosurePenalInterestOnTypeOptions, periodFrequencyTypeOptions); } return recurringDepositProductToReturn; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountData.java index c64a7091c..0301717bb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountData.java @@ -29,8 +29,8 @@ public class DepositAccountData { protected final String groupName; protected final Long clientId; protected final String clientName; - protected final Long savingsProductId; - protected final String savingsProductName; + protected final Long depositProductId; + protected final String depositProductName; protected final Long fieldOfficerId; protected final String fieldOfficerName; protected final SavingsAccountStatusEnumData status; @@ -177,8 +177,8 @@ public class DepositAccountData { this.groupName = groupName; this.clientId = clientId; this.clientName = clientName; - this.savingsProductId = productId; - this.savingsProductName = productName; + this.depositProductId = productId; + this.depositProductName = productName; this.fieldOfficerId = fieldofficerId; this.fieldOfficerName = fieldofficerName; this.status = status; @@ -244,7 +244,7 @@ public class DepositAccountData { } public Long productId() { - return this.savingsProductId; + return this.depositProductId; } public CurrencyData currency() { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountDataValidator.java index 97a13a947..7c3746cce 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountDataValidator.java @@ -5,16 +5,17 @@ */ package org.mifosplatform.portfolio.savings.data; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.adjustAdvanceTowardsFuturePaymentsParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.allowWithdrawalParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositAmountParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositPeriodFrequencyIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositPeriodParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.inMultiplesOfDepositTermParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.inMultiplesOfDepositTermTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreeFromPeriodParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreePeriodApplicableParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreePeriodFrequencyTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreeToPeriodParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.isCalendarInheritedParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.isMandatoryDepositParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.linkedAccountParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.mandatoryRecommendedDepositAmountParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.maxDepositTermParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.maxDepositTermTypeIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.minDepositTermParamName; @@ -22,9 +23,8 @@ import static org.mifosplatform.portfolio.savings.DepositsApiConstants.minDeposi import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalApplicableParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalInterestOnTypeIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalInterestParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositFrequencyParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositFrequencyTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositTypeIdParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringFrequencyParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringFrequencyTypeParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.accountNoParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.amountParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.chargeIdParamName; @@ -62,11 +62,10 @@ import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; -import org.mifosplatform.portfolio.interestratechart.InterestRateChartPeriodType; +import org.mifosplatform.portfolio.calendar.domain.CalendarFrequencyType; import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.DepositsApiConstants; import org.mifosplatform.portfolio.savings.PreClosurePenalInterestOnType; -import org.mifosplatform.portfolio.savings.RecurringDepositType; import org.mifosplatform.portfolio.savings.SavingsCompoundingInterestPeriodType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationDaysInYearType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationType; @@ -93,7 +92,7 @@ public class DepositAccountDataValidator { this.productDataValidator = productDataValidator; } - private void validateFixedDepositForSubmit(final String json) { + public void validateFixedDepositForSubmit(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); @@ -113,7 +112,7 @@ public class DepositAccountDataValidator { throwExceptionIfValidationWarningsExist(dataValidationErrors); } - private void validateFixedDepositForUpdate(final String json) { + public void validateFixedDepositForUpdate(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); @@ -133,7 +132,7 @@ public class DepositAccountDataValidator { throwExceptionIfValidationWarningsExist(dataValidationErrors); } - private void validateRecurringDepositForSubmit(final String json) { + public void validateRecurringDepositForSubmit(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); @@ -154,7 +153,7 @@ public class DepositAccountDataValidator { throwExceptionIfValidationWarningsExist(dataValidationErrors); } - private void validateRecurringDepositForUpdate(final String json) { + public void validateRecurringDepositForUpdate(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } final Type typeOfMap = new TypeToken>() {}.getType(); @@ -253,13 +252,16 @@ public class DepositAccountDataValidator { baseDataValidator.reset().parameter(minRequiredOpeningBalanceParamName).value(minOpeningBalance).zeroOrPositiveAmount(); } + boolean isLockinPeriodFrequencyValidated = false; + boolean isLockinPeriodFrequencyTypeValidated = false; if (this.fromApiJsonHelper.parameterExists(lockinPeriodFrequencyParamName, element)) { - + isLockinPeriodFrequencyValidated = true; final Integer lockinPeriodFrequency = this.fromApiJsonHelper.extractIntegerWithLocaleNamed(lockinPeriodFrequencyParamName, element); baseDataValidator.reset().parameter(lockinPeriodFrequencyParamName).value(lockinPeriodFrequency).integerZeroOrGreater(); if (lockinPeriodFrequency != null) { + isLockinPeriodFrequencyTypeValidated = true; final Integer lockinPeriodFrequencyType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( lockinPeriodFrequencyTypeParamName, element); baseDataValidator.reset().parameter(lockinPeriodFrequencyTypeParamName).value(lockinPeriodFrequencyType).notNull() @@ -267,12 +269,12 @@ public class DepositAccountDataValidator { } } - if (this.fromApiJsonHelper.parameterExists(lockinPeriodFrequencyTypeParamName, element)) { + if (!isLockinPeriodFrequencyTypeValidated && this.fromApiJsonHelper.parameterExists(lockinPeriodFrequencyTypeParamName, element)) { final Integer lockinPeriodFrequencyType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( lockinPeriodFrequencyTypeParamName, element); baseDataValidator.reset().parameter(lockinPeriodFrequencyTypeParamName).value(lockinPeriodFrequencyType).inMinMaxRange(0, 3); - if (lockinPeriodFrequencyType != null) { + if (lockinPeriodFrequencyType != null && !isLockinPeriodFrequencyValidated) { final Integer lockinPeriodFrequency = this.fromApiJsonHelper.extractIntegerWithLocaleNamed(lockinPeriodFrequencyParamName, element); baseDataValidator.reset().parameter(lockinPeriodFrequencyParamName).value(lockinPeriodFrequency).notNull() @@ -425,31 +427,6 @@ public class DepositAccountDataValidator { } private void validatePreClosureDetailForSubmit(final JsonElement element, final DataValidatorBuilder baseDataValidator) { - if (fromApiJsonHelper.parameterExists(interestFreePeriodApplicableParamName, element)) { - - final boolean interestFreePeriodApplicable = fromApiJsonHelper.extractBooleanNamed(interestFreePeriodApplicableParamName, - element); - - if (interestFreePeriodApplicable) { - final Integer interestFreeFromPeriod = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestFreeFromPeriodParamName, - element); - baseDataValidator.reset().parameter(interestFreeFromPeriodParamName).value(interestFreeFromPeriod) - .cantBeBlankWhenParameterProvidedIs(interestFreePeriodApplicableParamName, interestFreePeriodApplicable) - .integerZeroOrGreater(); - - final Integer interestFreeToPeriod = fromApiJsonHelper - .extractIntegerSansLocaleNamed(interestFreeToPeriodParamName, element); - baseDataValidator.reset().parameter(interestFreeToPeriodParamName).value(interestFreeToPeriod) - .cantBeBlankWhenParameterProvidedIs(interestFreePeriodApplicableParamName, interestFreePeriodApplicable) - .integerZeroOrGreater().integerGreaterThanNumber(interestFreeFromPeriod); - - final Integer periodFrequencyType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( - interestFreePeriodFrequencyTypeIdParamName, element); - baseDataValidator.reset().parameter(interestFreePeriodFrequencyTypeIdParamName).value(periodFrequencyType) - .cantBeBlankWhenParameterProvidedIs(interestFreePeriodApplicableParamName, interestFreePeriodApplicable) - .isOneOfTheseValues(InterestRateChartPeriodType.integerValues()); - } - } if (fromApiJsonHelper.parameterExists(preClosurePenalApplicableParamName, element)) { final boolean preClosurePenalApplicable = fromApiJsonHelper.extractBooleanNamed(preClosurePenalApplicableParamName, element); @@ -549,38 +526,106 @@ public class DepositAccountDataValidator { } private void validateRecurringDetailForSubmit(final JsonElement element, final DataValidatorBuilder baseDataValidator) { - if (fromApiJsonHelper.parameterExists(recurringDepositTypeIdParamName, element)) { - final Integer rdTypeId = fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringDepositTypeIdParamName, element); - baseDataValidator.reset().parameter(recurringDepositTypeIdParamName).value(rdTypeId).notNull() - .isOneOfTheseValues(RecurringDepositType.integerValues()); + + final BigDecimal mandatoryRecommendedDepositAmount = fromApiJsonHelper.extractBigDecimalWithLocaleNamed(mandatoryRecommendedDepositAmountParamName, element); + baseDataValidator.reset().parameter(mandatoryRecommendedDepositAmountParamName).value(mandatoryRecommendedDepositAmount).notNull().positiveAmount(); + + if (this.fromApiJsonHelper.parameterExists(isMandatoryDepositParamName, element)) { + final Boolean isMandatoryDeposit = this.fromApiJsonHelper.extractBooleanNamed(isMandatoryDepositParamName, element); + baseDataValidator.reset().parameter(isMandatoryDepositParamName).value(isMandatoryDeposit).ignoreIfNull() + .validateForBooleanValue(); } - if (fromApiJsonHelper.parameterExists(recurringDepositFrequencyParamName, element)) { - final Integer rdFrequency = fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringDepositFrequencyParamName, element); - baseDataValidator.reset().parameter(recurringDepositFrequencyParamName).value(rdFrequency).notNull().integerGreaterThanZero(); + if (this.fromApiJsonHelper.parameterExists(allowWithdrawalParamName, element)) { + final Boolean allowWithdrawal = this.fromApiJsonHelper.extractBooleanNamed(allowWithdrawalParamName, element); + baseDataValidator.reset().parameter(allowWithdrawalParamName).value(allowWithdrawal).ignoreIfNull().validateForBooleanValue(); } - if (fromApiJsonHelper.parameterExists(recurringDepositFrequencyTypeIdParamName, element)) { - final Integer rdFrequencyTypeId = fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringDepositFrequencyTypeIdParamName, - element); - baseDataValidator.reset().parameter(recurringDepositFrequencyTypeIdParamName).value(rdFrequencyTypeId).notNull() - .isOneOfTheseValues(SavingsPeriodFrequencyType.integerValues()); + if (this.fromApiJsonHelper.parameterExists(adjustAdvanceTowardsFuturePaymentsParamName, element)) { + final Boolean adjustAdvanceTowardsFuturePayments = this.fromApiJsonHelper.extractBooleanNamed( + adjustAdvanceTowardsFuturePaymentsParamName, element); + baseDataValidator.reset().parameter(adjustAdvanceTowardsFuturePaymentsParamName).value(adjustAdvanceTowardsFuturePayments) + .ignoreIfNull().validateForBooleanValue(); + } + + // First validate if string is empty + final String isCalendarInheritedString = this.fromApiJsonHelper.extractStringNamed(isCalendarInheritedParamName, element); + if (StringUtils.isBlank(isCalendarInheritedString)) { + baseDataValidator.reset().parameter(isCalendarInheritedParamName).value(isCalendarInheritedString).notBlank(); + } else { + // validate the boolean value + final Boolean isCalendarInherited = this.fromApiJsonHelper.extractBooleanNamed(isCalendarInheritedParamName, element); + baseDataValidator.reset().parameter(isCalendarInheritedParamName).value(isCalendarInherited).notNull() + .validateForBooleanValue(); + if (!isCalendarInherited) { + final Integer frequencyType = this.fromApiJsonHelper + .extractIntegerSansLocaleNamed(recurringFrequencyTypeParamName, element); + baseDataValidator.reset().parameter(recurringFrequencyTypeParamName).value(frequencyType).notBlank() + .inMinMaxRange(CalendarFrequencyType.getMinValue(), CalendarFrequencyType.getMaxValue()); + + final Integer frequency = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringFrequencyParamName, element); + baseDataValidator.reset().parameter(recurringFrequencyParamName).value(frequency).notNull().integerGreaterThanZero(); + + /* + * if (CalendarFrequencyType.fromInt(frequency).isWeekly()) { + * final Integer repeatsOnDay = + * this.fromApiJsonHelper.extractIntegerSansLocaleNamed + * (repeatsOnDayParamName, element); + * baseDataValidator.reset().parameter + * (repeatsOnDayParamName).value(repeatsOnDay).notBlank() + * .inMinMaxRange(CalendarWeekDaysType.getMinValue(), + * CalendarWeekDaysType.getMaxValue()); } + */ + } } } private void validateRecurringDetailForUpdate(final JsonElement element, final DataValidatorBuilder baseDataValidator) { - this.productDataValidator.validateRecurringDepositUpdate(element, baseDataValidator); - } + if (this.fromApiJsonHelper.parameterExists(isMandatoryDepositParamName, element)) { + final Boolean isMandatoryDeposit = this.fromApiJsonHelper.extractBooleanNamed(isMandatoryDepositParamName, element); + baseDataValidator.reset().parameter(isMandatoryDepositParamName).value(isMandatoryDeposit).ignoreIfNull() + .validateForBooleanValue(); + } - public void validateForSubmit(final String json, final DepositAccountType depositAccountType) { + if (this.fromApiJsonHelper.parameterExists(allowWithdrawalParamName, element)) { + final Boolean allowWithdrawal = this.fromApiJsonHelper.extractBooleanNamed(allowWithdrawalParamName, element); + baseDataValidator.reset().parameter(allowWithdrawalParamName).value(allowWithdrawal).ignoreIfNull().validateForBooleanValue(); + } - if (depositAccountType.isFixedDeposit()) { - this.validateFixedDepositForSubmit(json); - } else if (depositAccountType.isRecurringDeposit()) { - this.validateRecurringDepositForSubmit(json); - } else { - // FIXME: AA handle unsupported deposit account type - // throw unsupported account type exception + if (this.fromApiJsonHelper.parameterExists(adjustAdvanceTowardsFuturePaymentsParamName, element)) { + final Boolean adjustAdvanceTowardsFuturePayments = this.fromApiJsonHelper.extractBooleanNamed( + adjustAdvanceTowardsFuturePaymentsParamName, element); + baseDataValidator.reset().parameter(adjustAdvanceTowardsFuturePaymentsParamName).value(adjustAdvanceTowardsFuturePayments) + .ignoreIfNull().validateForBooleanValue(); + } + + if (this.fromApiJsonHelper.parameterExists(isCalendarInheritedParamName, element)) { + final Boolean isCalendarInherited = this.fromApiJsonHelper.extractBooleanNamed(isCalendarInheritedParamName, element); + baseDataValidator.reset().parameter(isCalendarInheritedParamName).value(isCalendarInherited).notNull() + .validateForBooleanValue(); + } + + if (this.fromApiJsonHelper.parameterExists(recurringFrequencyTypeParamName, element)) { + final Integer frequencyType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringFrequencyTypeParamName, element); + baseDataValidator.reset().parameter(recurringFrequencyTypeParamName).value(frequencyType).notBlank() + .inMinMaxRange(CalendarFrequencyType.getMinValue(), CalendarFrequencyType.getMaxValue()); + } + + if (this.fromApiJsonHelper.parameterExists(recurringFrequencyParamName, element)) { + final Integer frequency = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringFrequencyParamName, element); + baseDataValidator.reset().parameter(recurringFrequencyParamName).value(frequency).notNull().integerGreaterThanZero(); + /* + * if (this.fromApiJsonHelper.parameterExists(repeatsOnDayParamName, + * element)) { if + * (CalendarFrequencyType.fromInt(frequency).isWeekly()) { final + * Integer repeatsOnDay = + * this.fromApiJsonHelper.extractIntegerSansLocaleNamed + * (repeatsOnDayParamName, element); + * baseDataValidator.reset().parameter + * (repeatsOnDayParamName).value(repeatsOnDay).notBlank() + * .inMinMaxRange(CalendarWeekDaysType.getMinValue(), + * CalendarWeekDaysType.getMaxValue()); } } + */ } } @@ -649,19 +694,6 @@ public class DepositAccountDataValidator { } } - public void validateForUpdate(final String json, final DepositAccountType depositAccountType) { - - if (depositAccountType.isFixedDeposit()) { - this.validateFixedDepositForUpdate(json); - } else if (depositAccountType.isRecurringDeposit()) { - this.validateRecurringDepositForUpdate(json); - } else { - // FIXME: AA handle unsupported deposit account type - // throw unsupported account type exception - } - - } - private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountInterestRateChartSlabData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountInterestRateChartSlabData.java index f199e88f0..869311907 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountInterestRateChartSlabData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountInterestRateChartSlabData.java @@ -25,34 +25,47 @@ public class DepositAccountInterestRateChartSlabData { private final BigDecimal amountRangeFrom; private final BigDecimal amountRangeTo; private final BigDecimal annualInterestRate; + private final BigDecimal interestRateForFemale; + private final BigDecimal interestRateForChildren; + private final BigDecimal interestRateForSeniorCitizen; private final CurrencyData currency; // associations // template @SuppressWarnings("unused") - private Collection periodTypes; + private final Collection periodTypes; - public static DepositAccountInterestRateChartSlabData instance(Long id, String description, EnumOptionData periodType, Integer fromPeriod, - Integer toPeriod, BigDecimal amountRangeFrom, BigDecimal amountRangeTo, BigDecimal annualInterestRate, CurrencyData currency) { - Collection periodTypes = null; - return new DepositAccountInterestRateChartSlabData(id, description, periodType, fromPeriod, toPeriod, amountRangeFrom, amountRangeTo, - annualInterestRate, currency, periodTypes); - } - - public static DepositAccountInterestRateChartSlabData from(InterestRateChartSlabData chartSlabData) { - final Long id = null; - return new DepositAccountInterestRateChartSlabData(id, chartSlabData.description(), chartSlabData.periodType(), chartSlabData.fromPeriod(), chartSlabData.toPeriod(), chartSlabData.amountRangeFrom(), chartSlabData.amountRangeTo(), - chartSlabData.annualInterestRate(), chartSlabData.currency(), chartSlabData.periodTypes()); - } - - public static DepositAccountInterestRateChartSlabData withTemplate(DepositAccountInterestRateChartSlabData chartSlab, Collection periodTypes) { - return new DepositAccountInterestRateChartSlabData(chartSlab.id, chartSlab.description, chartSlab.periodType, chartSlab.fromPeriod, chartSlab.toPeriod, chartSlab.amountRangeFrom, chartSlab.amountRangeTo, - chartSlab.annualInterestRate, chartSlab.currency, periodTypes); + public static DepositAccountInterestRateChartSlabData instance(final Long id, final String description, + final EnumOptionData periodType, final Integer fromPeriod, final Integer toPeriod, final BigDecimal amountRangeFrom, + final BigDecimal amountRangeTo, final BigDecimal annualInterestRate, final BigDecimal interestRateForFemale, + final BigDecimal interestRateForChildren, final BigDecimal interestRateForSeniorCitizen, final CurrencyData currency) { + final Collection periodTypes = null; + return new DepositAccountInterestRateChartSlabData(id, description, periodType, fromPeriod, toPeriod, amountRangeFrom, + amountRangeTo, annualInterestRate, interestRateForFemale, interestRateForChildren, interestRateForSeniorCitizen, currency, + periodTypes); } - private DepositAccountInterestRateChartSlabData(Long id, String description, EnumOptionData periodType, Integer fromPeriod, Integer toPeriod, - BigDecimal amountRangeFrom, BigDecimal amountRangeTo, BigDecimal annualInterestRate, CurrencyData currency, Collection periodTypes) { + public static DepositAccountInterestRateChartSlabData from(final InterestRateChartSlabData chartSlabData) { + final Long id = null; + return new DepositAccountInterestRateChartSlabData(id, chartSlabData.description(), chartSlabData.periodType(), + chartSlabData.fromPeriod(), chartSlabData.toPeriod(), chartSlabData.amountRangeFrom(), chartSlabData.amountRangeTo(), + chartSlabData.annualInterestRate(), chartSlabData.interestRateForFemale(), chartSlabData.interestRateForChildren(), + chartSlabData.interestRateForSeniorCitizen(), chartSlabData.currency(), chartSlabData.periodTypes()); + } + + public static DepositAccountInterestRateChartSlabData withTemplate(final DepositAccountInterestRateChartSlabData chartSlab, + final Collection periodTypes) { + return new DepositAccountInterestRateChartSlabData(chartSlab.id, chartSlab.description, chartSlab.periodType, chartSlab.fromPeriod, + chartSlab.toPeriod, chartSlab.amountRangeFrom, chartSlab.amountRangeTo, chartSlab.annualInterestRate, + chartSlab.interestRateForFemale, chartSlab.interestRateForChildren, chartSlab.interestRateForSeniorCitizen, + chartSlab.currency, periodTypes); + } + + private DepositAccountInterestRateChartSlabData(final Long id, final String description, final EnumOptionData periodType, + final Integer fromPeriod, final Integer toPeriod, final BigDecimal amountRangeFrom, final BigDecimal amountRangeTo, + final BigDecimal annualInterestRate, final BigDecimal interestRateForFemale, final BigDecimal interestRateForChildren, + final BigDecimal interestRateForSeniorCitizen, final CurrencyData currency, final Collection periodTypes) { this.id = id; this.description = description; this.periodType = periodType; @@ -61,6 +74,9 @@ public class DepositAccountInterestRateChartSlabData { this.amountRangeFrom = amountRangeFrom; this.amountRangeTo = amountRangeTo; this.annualInterestRate = annualInterestRate; + this.interestRateForFemale = interestRateForFemale; + this.interestRateForChildren = interestRateForChildren; + this.interestRateForSeniorCitizen = interestRateForSeniorCitizen; this.currency = currency; this.periodTypes = periodTypes; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountTransactionDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountTransactionDataValidator.java index 9ea827154..ca0c17d1d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountTransactionDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositAccountTransactionDataValidator.java @@ -159,7 +159,7 @@ public class DepositAccountTransactionDataValidator { if (accountOnClosureType.isTransferToSavings()) { final Long toSavingsAccountId = this.fromApiJsonHelper.extractLongNamed(toSavingsAccountIdParamName, element); baseDataValidator.reset().parameter(toSavingsAccountIdParamName).value(toSavingsAccountId) - .cantBeBlankWhenParameterProvidedIs(onAccountClosureIdParamName, onAccountClosureId); + .cantBeBlankWhenParameterProvidedIs(onAccountClosureIdParamName, DepositAccountOnClosureType.fromInt(onAccountClosureId).getCode()); } else if (accountOnClosureType.isReinvest() && isPreMatureClose) { baseDataValidator.reset().parameter(onAccountClosureIdParamName).value(onAccountClosureId) .failWithCode("reinvest.not.allowed", "Re-Invest is not supported for account pre mature close"); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositProductDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositProductDataValidator.java index f40162c4a..7bb5319c2 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositProductDataValidator.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/DepositProductDataValidator.java @@ -10,16 +10,15 @@ import static org.mifosplatform.portfolio.savings.DepositsApiConstants.FIXED_DEP import static org.mifosplatform.portfolio.savings.DepositsApiConstants.FIXED_DEPOSIT_PRODUCT_RESOURCE_NAME; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.RECURRING_DEPOSIT_PRODUCT_REQUEST_DATA_PARAMETERS; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.RECURRING_DEPOSIT_PRODUCT_RESOURCE_NAME; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.adjustAdvanceTowardsFuturePaymentsParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.allowWithdrawalParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.chartsParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositAmountParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositMaxAmountParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositMinAmountParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.inMultiplesOfDepositTermParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.inMultiplesOfDepositTermTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreeFromPeriodParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreePeriodApplicableParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreePeriodFrequencyTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreeToPeriodParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.isMandatoryDepositParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.maxDepositTermParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.maxDepositTermTypeIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.minDepositTermParamName; @@ -27,9 +26,6 @@ import static org.mifosplatform.portfolio.savings.DepositsApiConstants.minDeposi import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalApplicableParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalInterestOnTypeIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalInterestParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositFrequencyParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositFrequencyTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositTypeIdParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.currencyCodeParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.descriptionParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.digitsAfterDecimalParamName; @@ -64,10 +60,8 @@ import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; -import org.mifosplatform.portfolio.interestratechart.InterestRateChartPeriodType; import org.mifosplatform.portfolio.interestratechart.data.InterestRateChartDataValidator; import org.mifosplatform.portfolio.savings.PreClosurePenalInterestOnType; -import org.mifosplatform.portfolio.savings.RecurringDepositType; import org.mifosplatform.portfolio.savings.SavingsCompoundingInterestPeriodType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationDaysInYearType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationType; @@ -321,32 +315,6 @@ public class DepositProductDataValidator { } public void validatePreClosureDetailForCreate(JsonElement element, DataValidatorBuilder baseDataValidator) { - if (fromApiJsonHelper.parameterExists(interestFreePeriodApplicableParamName, element)) { - - final boolean interestFreePeriodApplicable = fromApiJsonHelper.extractBooleanNamed(interestFreePeriodApplicableParamName, - element); - - if (interestFreePeriodApplicable) { - final Integer interestFreeFromPeriod = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestFreeFromPeriodParamName, - element); - baseDataValidator.reset().parameter(interestFreeFromPeriodParamName).value(interestFreeFromPeriod) - .cantBeBlankWhenParameterProvidedIs(interestFreePeriodApplicableParamName, interestFreePeriodApplicable) - .integerZeroOrGreater(); - - final Integer interestFreeToPeriod = fromApiJsonHelper - .extractIntegerSansLocaleNamed(interestFreeToPeriodParamName, element); - baseDataValidator.reset().parameter(interestFreeToPeriodParamName).value(interestFreeToPeriod) - .cantBeBlankWhenParameterProvidedIs(interestFreePeriodApplicableParamName, interestFreePeriodApplicable) - .integerZeroOrGreater().integerGreaterThanNumber(interestFreeFromPeriod); - - final Integer periodFrequencyType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( - interestFreePeriodFrequencyTypeIdParamName, element); - baseDataValidator.reset().parameter(interestFreePeriodFrequencyTypeIdParamName).value(periodFrequencyType) - .cantBeBlankWhenParameterProvidedIs(interestFreePeriodApplicableParamName, interestFreePeriodApplicable) - .isOneOfTheseValues(InterestRateChartPeriodType.integerValues()); - } - } - if (fromApiJsonHelper.parameterExists(preClosurePenalApplicableParamName, element)) { final boolean preClosurePenalApplicable = fromApiJsonHelper.extractBooleanNamed(preClosurePenalApplicableParamName, element); @@ -369,7 +337,7 @@ public class DepositProductDataValidator { public void validateDepositTermDeatilForCreate(JsonElement element, DataValidatorBuilder baseDataValidator) { final Integer minTerm = fromApiJsonHelper.extractIntegerSansLocaleNamed(minDepositTermParamName, element); - baseDataValidator.reset().parameter(minDepositTermParamName).value(minTerm).integerGreaterThanZero(); + baseDataValidator.reset().parameter(minDepositTermParamName).value(minTerm).notNull().integerGreaterThanZero(); if (fromApiJsonHelper.parameterExists(maxDepositTermParamName, element)) { final Integer maxTerm = fromApiJsonHelper.extractIntegerSansLocaleNamed(maxDepositTermParamName, element); @@ -546,33 +514,6 @@ public class DepositProductDataValidator { } public void validatePreClosureDetailForUpdate(JsonElement element, DataValidatorBuilder baseDataValidator) { - - if (fromApiJsonHelper.parameterExists(interestFreePeriodApplicableParamName, element)) { - final Boolean interestFreePeriodApplicable = fromApiJsonHelper.extractBooleanNamed(interestFreePeriodApplicableParamName, - element); - baseDataValidator.reset().parameter(interestFreePeriodApplicableParamName).value(interestFreePeriodApplicable).notNull(); - } - - if (fromApiJsonHelper.parameterExists(interestFreeFromPeriodParamName, element)) { - - final Integer interestFreeFromPeriod = fromApiJsonHelper - .extractIntegerSansLocaleNamed(interestFreeFromPeriodParamName, element); - baseDataValidator.reset().parameter(interestFreeFromPeriodParamName).value(interestFreeFromPeriod).notNull() - .integerZeroOrGreater(); - } - - if (fromApiJsonHelper.parameterExists(interestFreeToPeriodParamName, element)) { - final Integer interestFreeToPeriod = fromApiJsonHelper.extractIntegerSansLocaleNamed(interestFreeToPeriodParamName, element); - baseDataValidator.reset().parameter(interestFreeToPeriodParamName).value(interestFreeToPeriod).notNull().integerZeroOrGreater(); - } - - if (fromApiJsonHelper.parameterExists(interestFreePeriodFrequencyTypeIdParamName, element)) { - final Integer periodFrequencyType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( - interestFreePeriodFrequencyTypeIdParamName, element); - baseDataValidator.reset().parameter(interestFreePeriodFrequencyTypeIdParamName).value(periodFrequencyType).notNull() - .isOneOfTheseValues(InterestRateChartPeriodType.integerValues()); - } - if (fromApiJsonHelper.parameterExists(preClosurePenalApplicableParamName, element)) { final Boolean preClosurePenalApplicable = fromApiJsonHelper.extractBooleanNamed(preClosurePenalApplicableParamName, element); baseDataValidator.reset().parameter(preClosurePenalApplicableParamName).value(preClosurePenalApplicable).notNull(); @@ -711,37 +652,34 @@ public class DepositProductDataValidator { public void validateRecurringDetailForCreate(JsonElement element, DataValidatorBuilder baseDataValidator) { - final Integer rdTypeId = fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringDepositTypeIdParamName, element); - baseDataValidator.reset().parameter(recurringDepositTypeIdParamName).value(rdTypeId).notNull() - .isOneOfTheseValues(RecurringDepositType.integerValues()); - - final Integer rdFrequency = fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringDepositFrequencyParamName, element); - baseDataValidator.reset().parameter(recurringDepositFrequencyParamName).value(rdFrequency).notNull().integerGreaterThanZero(); - - final Integer rdFrequencyTypeId = fromApiJsonHelper - .extractIntegerSansLocaleNamed(recurringDepositFrequencyTypeIdParamName, element); - baseDataValidator.reset().parameter(recurringDepositFrequencyTypeIdParamName).value(rdFrequencyTypeId).notNull() - .isOneOfTheseValues(SavingsPeriodFrequencyType.integerValues()); + final Boolean isMandatoryDeposit = this.fromApiJsonHelper.extractBooleanNamed(isMandatoryDepositParamName, element); + baseDataValidator.reset().parameter(isMandatoryDepositParamName).value(isMandatoryDeposit).ignoreIfNull().validateForBooleanValue(); + final Boolean allowWithdrawal = this.fromApiJsonHelper.extractBooleanNamed(allowWithdrawalParamName, element); + baseDataValidator.reset().parameter(allowWithdrawalParamName).value(allowWithdrawal).ignoreIfNull().validateForBooleanValue(); + final Boolean adjustAdvanceTowardsFuturePayments = this.fromApiJsonHelper.extractBooleanNamed( + adjustAdvanceTowardsFuturePaymentsParamName, element); + baseDataValidator.reset().parameter(adjustAdvanceTowardsFuturePaymentsParamName).value(adjustAdvanceTowardsFuturePayments) + .ignoreIfNull().validateForBooleanValue(); } public void validateRecurringDepositUpdate(JsonElement element, DataValidatorBuilder baseDataValidator) { - if (fromApiJsonHelper.parameterExists(recurringDepositTypeIdParamName, element)) { - final Integer rdTypeId = fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringDepositTypeIdParamName, element); - baseDataValidator.reset().parameter(recurringDepositTypeIdParamName).value(rdTypeId).notNull() - .isOneOfTheseValues(RecurringDepositType.integerValues()); + if (this.fromApiJsonHelper.parameterExists(isMandatoryDepositParamName, element)) { + final Boolean isMandatoryDeposit = this.fromApiJsonHelper.extractBooleanNamed(isMandatoryDepositParamName, element); + baseDataValidator.reset().parameter(isMandatoryDepositParamName).value(isMandatoryDeposit).ignoreIfNull() + .validateForBooleanValue(); } - if (fromApiJsonHelper.parameterExists(recurringDepositFrequencyParamName, element)) { - final Integer rdFrequency = fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringDepositFrequencyParamName, element); - baseDataValidator.reset().parameter(recurringDepositFrequencyParamName).value(rdFrequency).notNull().integerGreaterThanZero(); + if (this.fromApiJsonHelper.parameterExists(allowWithdrawalParamName, element)) { + final Boolean allowWithdrawal = this.fromApiJsonHelper.extractBooleanNamed(allowWithdrawalParamName, element); + baseDataValidator.reset().parameter(allowWithdrawalParamName).value(allowWithdrawal).ignoreIfNull().validateForBooleanValue(); } - if (fromApiJsonHelper.parameterExists(recurringDepositFrequencyTypeIdParamName, element)) { - final Integer rdFrequencyTypeId = fromApiJsonHelper.extractIntegerSansLocaleNamed(recurringDepositFrequencyTypeIdParamName, - element); - baseDataValidator.reset().parameter(recurringDepositFrequencyTypeIdParamName).value(rdFrequencyTypeId).notNull() - .isOneOfTheseValues(SavingsPeriodFrequencyType.integerValues()); + if (this.fromApiJsonHelper.parameterExists(adjustAdvanceTowardsFuturePaymentsParamName, element)) { + final Boolean adjustAdvanceTowardsFuturePayments = this.fromApiJsonHelper.extractBooleanNamed( + adjustAdvanceTowardsFuturePaymentsParamName, element); + baseDataValidator.reset().parameter(adjustAdvanceTowardsFuturePaymentsParamName).value(adjustAdvanceTowardsFuturePayments) + .ignoreIfNull().validateForBooleanValue(); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/FixedDepositAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/FixedDepositAccountData.java index bc3fec635..8c2e7a98d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/FixedDepositAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/FixedDepositAccountData.java @@ -25,11 +25,6 @@ import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; */ public class FixedDepositAccountData extends DepositAccountData { - // additional fields - private boolean interestFreePeriodApplicable; - private Integer interestFreeFromPeriod; - private Integer interestFreeToPeriod; - private EnumOptionData interestFreePeriodFrequencyType; private boolean preClosurePenalApplicable; private BigDecimal preClosurePenalInterest; private EnumOptionData preClosurePenalInterestOnType; @@ -51,32 +46,25 @@ public class FixedDepositAccountData extends DepositAccountData { private final PortfolioAccountData linkedAccount; private final Boolean transferInterestToSavings; - private Collection interestFreePeriodTypeOptions; private Collection preClosurePenalInterestOnTypeOptions; - private Collection depositTermTypeOptions; - private Collection inMultiplesOfDepositTermTypeOptions; - private Collection depositPeriodFrequencyOptions; + private Collection periodFrequencyTypeOptions; private Collection savingsAccounts; // for account close private Collection onAccountClosureOptions; private Collection paymentTypeOptions; - public static FixedDepositAccountData instance(final DepositAccountData depositAccountData, final boolean interestFreePeriodApplicable, - final Integer interestFreeFromPeriod, final Integer interestFreeToPeriod, final EnumOptionData interestFreePeriodFrequencyType, - final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, - final EnumOptionData preClosurePenalInterestOnType, final Integer minDepositTerm, final Integer maxDepositTerm, - final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, final Integer inMultiplesOfDepositTerm, - final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal depositAmount, final BigDecimal maturityAmount, - final LocalDate maturityDate, final Integer depositPeriod, final EnumOptionData depositPeriodFrequency, - final EnumOptionData onAccountClosure, final Boolean transferInterestToSavings) { + public static FixedDepositAccountData instance(final DepositAccountData depositAccountData, final boolean preClosurePenalApplicable, + final BigDecimal preClosurePenalInterest, final EnumOptionData preClosurePenalInterestOnType, final Integer minDepositTerm, + final Integer maxDepositTerm, final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, + final Integer inMultiplesOfDepositTerm, final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal depositAmount, + final BigDecimal maturityAmount, final LocalDate maturityDate, final Integer depositPeriod, + final EnumOptionData depositPeriodFrequency, final EnumOptionData onAccountClosure, final Boolean transferInterestToSavings) { final PortfolioAccountData linkedAccount = null; - final Collection interestFreePeriodTypeOptions = null; final Collection preClosurePenalInterestOnTypeOptions = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; - final Collection depositPeriodFrequencyOptions = null; + final Collection periodFrequencyTypeOptions = null; + final EnumOptionData depositType = SavingsEnumerations.depositType(DepositAccountType.FIXED_DEPOSIT.getValue()); final Collection onAccountClosureOptions = null; final Collection paymentTypeOptions = null; @@ -84,7 +72,7 @@ public class FixedDepositAccountData extends DepositAccountData { return new FixedDepositAccountData(depositAccountData.id, depositAccountData.accountNo, depositAccountData.externalId, depositAccountData.groupId, depositAccountData.groupName, depositAccountData.clientId, depositAccountData.clientName, - depositAccountData.savingsProductId, depositAccountData.savingsProductName, depositAccountData.fieldOfficerId, + depositAccountData.depositProductId, depositAccountData.depositProductName, depositAccountData.fieldOfficerId, depositAccountData.fieldOfficerName, depositAccountData.status, depositAccountData.timeline, depositAccountData.currency, depositAccountData.nominalAnnualInterestRate, depositAccountData.interestCompoundingPeriodType, depositAccountData.interestPostingPeriodType, depositAccountData.interestCalculationType, @@ -96,19 +84,17 @@ public class FixedDepositAccountData extends DepositAccountData { depositAccountData.interestCalculationTypeOptions, depositAccountData.interestCalculationDaysInYearTypeOptions, depositAccountData.lockinPeriodFrequencyTypeOptions, depositAccountData.withdrawalFeeTypeOptions, depositAccountData.charges, depositAccountData.chargeOptions, depositAccountData.accountChart, - depositAccountData.chartTemplate, interestFreePeriodApplicable, interestFreeFromPeriod, interestFreeToPeriod, - interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestOnType, - interestFreePeriodTypeOptions, preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, - maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, - depositPeriod, depositPeriodFrequency, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - depositPeriodFrequencyOptions, depositType, onAccountClosure, onAccountClosureOptions, paymentTypeOptions, - savingsAccountDatas, linkedAccount, transferInterestToSavings); + depositAccountData.chartTemplate, preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestOnType, + preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, + inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, depositPeriod, + depositPeriodFrequency, periodFrequencyTypeOptions, depositType, onAccountClosure, onAccountClosureOptions, + paymentTypeOptions, savingsAccountDatas, linkedAccount, transferInterestToSavings); } public static FixedDepositAccountData withInterestChart(final FixedDepositAccountData account, final DepositAccountInterestRateChartData accountChart) { return new FixedDepositAccountData(account.id, account.accountNo, account.externalId, account.groupId, account.groupName, - account.clientId, account.clientName, account.savingsProductId, account.savingsProductName, account.fieldOfficerId, + account.clientId, account.clientName, account.depositProductId, account.depositProductName, account.fieldOfficerId, account.fieldOfficerName, account.status, account.timeline, account.currency, account.nominalAnnualInterestRate, account.interestCompoundingPeriodType, account.interestPostingPeriodType, account.interestCalculationType, account.interestCalculationDaysInYearType, account.minRequiredOpeningBalance, account.lockinPeriodFrequency, @@ -117,15 +103,12 @@ public class FixedDepositAccountData extends DepositAccountData { account.interestPostingPeriodTypeOptions, account.interestCalculationTypeOptions, account.interestCalculationDaysInYearTypeOptions, account.lockinPeriodFrequencyTypeOptions, account.withdrawalFeeTypeOptions, account.charges, account.chargeOptions, accountChart, account.chartTemplate, - account.interestFreePeriodApplicable, account.interestFreeFromPeriod, account.interestFreeToPeriod, - account.interestFreePeriodFrequencyType, account.preClosurePenalApplicable, account.preClosurePenalInterest, - account.preClosurePenalInterestOnType, account.interestFreePeriodTypeOptions, account.preClosurePenalInterestOnTypeOptions, - account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, account.maxDepositTermType, - account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, account.maturityAmount, - account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, account.depositTermTypeOptions, - account.inMultiplesOfDepositTermTypeOptions, account.depositTermTypeOptions, account.depositType, account.onAccountClosure, - account.onAccountClosureOptions, account.paymentTypeOptions, account.savingsAccounts, account.linkedAccount, - account.transferInterestToSavings); + account.preClosurePenalApplicable, account.preClosurePenalInterest, account.preClosurePenalInterestOnType, + account.preClosurePenalInterestOnTypeOptions, account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, + account.maxDepositTermType, account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, + account.maturityAmount, account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, + account.periodFrequencyTypeOptions, account.depositType, account.onAccountClosure, account.onAccountClosureOptions, + account.paymentTypeOptions, account.savingsAccounts, account.linkedAccount, account.transferInterestToSavings); } public static FixedDepositAccountData associationsAndTemplate(final FixedDepositAccountData account, FixedDepositAccountData template, @@ -137,7 +120,7 @@ public class FixedDepositAccountData extends DepositAccountData { } return new FixedDepositAccountData(account.id, account.accountNo, account.externalId, account.groupId, account.groupName, - account.clientId, account.clientName, account.savingsProductId, account.savingsProductName, account.fieldOfficerId, + account.clientId, account.clientName, account.depositProductId, account.depositProductName, account.fieldOfficerId, account.fieldOfficerName, account.status, account.timeline, account.currency, account.nominalAnnualInterestRate, account.interestCompoundingPeriodType, account.interestPostingPeriodType, account.interestCalculationType, account.interestCalculationDaysInYearType, account.minRequiredOpeningBalance, account.lockinPeriodFrequency, @@ -146,15 +129,12 @@ public class FixedDepositAccountData extends DepositAccountData { template.interestPostingPeriodTypeOptions, template.interestCalculationTypeOptions, template.interestCalculationDaysInYearTypeOptions, template.lockinPeriodFrequencyTypeOptions, template.withdrawalFeeTypeOptions, charges, template.chargeOptions, account.accountChart, account.chartTemplate, - account.interestFreePeriodApplicable, account.interestFreeFromPeriod, account.interestFreeToPeriod, - account.interestFreePeriodFrequencyType, account.preClosurePenalApplicable, account.preClosurePenalInterest, - account.preClosurePenalInterestOnType, template.interestFreePeriodTypeOptions, + account.preClosurePenalApplicable, account.preClosurePenalInterest, account.preClosurePenalInterestOnType, template.preClosurePenalInterestOnTypeOptions, account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, account.maxDepositTermType, account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, account.maturityAmount, account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, - template.depositTermTypeOptions, template.inMultiplesOfDepositTermTypeOptions, template.depositPeriodFrequencyOptions, - account.depositType, account.onAccountClosure, account.onAccountClosureOptions, account.paymentTypeOptions, - template.savingsAccounts, linkedAccount, account.transferInterestToSavings); + template.periodFrequencyTypeOptions, account.depositType, account.onAccountClosure, account.onAccountClosureOptions, + account.paymentTypeOptions, template.savingsAccounts, linkedAccount, account.transferInterestToSavings); } public static FixedDepositAccountData withTemplateOptions(final FixedDepositAccountData account, @@ -165,13 +145,12 @@ public class FixedDepositAccountData extends DepositAccountData { final Collection interestCalculationDaysInYearTypeOptions, final Collection lockinPeriodFrequencyTypeOptions, final Collection withdrawalFeeTypeOptions, final Collection transactions, final Collection charges, - final Collection chargeOptions, final Collection interestFreePeriodTypeOptions, - final Collection preClosurePenalInterestOnTypeOptions, final Collection depositTermTypeOptions, - final Collection inMultiplesOfDepositTermTypeOptions, - final Collection depositPeriodFrequencyOptions, final Collection savingsAccounts) { + final Collection chargeOptions, final Collection preClosurePenalInterestOnTypeOptions, + final Collection periodFrequencyTypeOptions, final Collection savingsAccounts) { + return new FixedDepositAccountData(account.id, account.accountNo, account.externalId, account.groupId, account.groupName, - account.clientId, account.clientName, account.savingsProductId, account.savingsProductName, account.fieldOfficerId, + account.clientId, account.clientName, account.depositProductId, account.depositProductName, account.fieldOfficerId, account.fieldOfficerName, account.status, account.timeline, account.currency, account.nominalAnnualInterestRate, account.interestCompoundingPeriodType, account.interestPostingPeriodType, account.interestCalculationType, account.interestCalculationDaysInYearType, account.minRequiredOpeningBalance, account.lockinPeriodFrequency, @@ -179,15 +158,12 @@ public class FixedDepositAccountData extends DepositAccountData { fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, charges, chargeOptions, account.accountChart, account.chartTemplate, - account.interestFreePeriodApplicable, account.interestFreeFromPeriod, account.interestFreeToPeriod, - account.interestFreePeriodFrequencyType, account.preClosurePenalApplicable, account.preClosurePenalInterest, - account.preClosurePenalInterestOnType, interestFreePeriodTypeOptions, preClosurePenalInterestOnTypeOptions, - account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, account.maxDepositTermType, - account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, account.maturityAmount, - account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, depositTermTypeOptions, - inMultiplesOfDepositTermTypeOptions, depositPeriodFrequencyOptions, account.depositType, account.onAccountClosure, - account.onAccountClosureOptions, account.paymentTypeOptions, savingsAccounts, account.linkedAccount, - account.transferInterestToSavings); + account.preClosurePenalApplicable, account.preClosurePenalInterest, account.preClosurePenalInterestOnType, + preClosurePenalInterestOnTypeOptions, account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, + account.maxDepositTermType, account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, + account.maturityAmount, account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, + periodFrequencyTypeOptions, account.depositType, account.onAccountClosure, account.onAccountClosureOptions, + account.paymentTypeOptions, savingsAccounts, account.linkedAccount, account.transferInterestToSavings); } public static FixedDepositAccountData withClientTemplate(final Long clientId, final String clientName, final Long groupId, @@ -229,10 +205,6 @@ public class FixedDepositAccountData extends DepositAccountData { final DepositAccountInterestRateChartData accountChart = null; final DepositAccountInterestRateChartData chartTemplate = null; - final boolean interestFreePeriodApplicable = false; - final Integer interestFreeFromPeriod = null; - final Integer interestFreeToPeriod = null; - final EnumOptionData interestFreePeriodFrequencyType = null; final boolean preClosurePenalApplicable = false; final BigDecimal preClosurePenalInterest = null; final EnumOptionData preClosurePenalInterestOnType = null; @@ -250,12 +222,9 @@ public class FixedDepositAccountData extends DepositAccountData { final EnumOptionData onAccountClosure = null; final PortfolioAccountData linkedAccount = null; final Boolean transferInterestToSavings = null; - - final Collection interestFreePeriodTypeOptions = null; final Collection preClosurePenalInterestOnTypeOptions = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; - final Collection depositPeriodFrequencyOptions = null; + final Collection periodFrequencyTypeOptions = null; + final EnumOptionData depositType = SavingsEnumerations.depositType(DepositAccountType.FIXED_DEPOSIT.getValue()); final Collection onAccountClosureOptions = null; final Collection paymentTypeOptions = null; @@ -267,14 +236,11 @@ public class FixedDepositAccountData extends DepositAccountData { lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeForTransfers, summary, transactions, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, - withdrawalFeeTypeOptions, charges, chargeOptions, accountChart, chartTemplate, interestFreePeriodApplicable, - interestFreeFromPeriod, interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, - preClosurePenalInterest, preClosurePenalInterestOnType, interestFreePeriodTypeOptions, - preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, - inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, depositPeriod, - depositPeriodFrequency, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, depositPeriodFrequencyOptions, - depositType, onAccountClosure, onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas, linkedAccount, - transferInterestToSavings); + withdrawalFeeTypeOptions, charges, chargeOptions, accountChart, chartTemplate, preClosurePenalApplicable, + preClosurePenalInterest, preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, minDepositTerm, + maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, + depositAmount, maturityAmount, maturityDate, depositPeriod, depositPeriodFrequency, periodFrequencyTypeOptions, + depositType, onAccountClosure, onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas, linkedAccount, transferInterestToSavings); } public static FixedDepositAccountData preClosureDetails(final Long accountId, BigDecimal maturityAmount, @@ -305,7 +271,6 @@ public class FixedDepositAccountData extends DepositAccountData { final boolean withdrawalFeeForTransfers = false; final SavingsAccountSummaryData summary = null; final Collection transactions = null; - final Collection productOptions = null; final Collection fieldOfficerOptions = null; final Collection interestCompoundingPeriodTypeOptions = null; @@ -320,10 +285,6 @@ public class FixedDepositAccountData extends DepositAccountData { final DepositAccountInterestRateChartData accountChart = null; final DepositAccountInterestRateChartData chartTemplate = null; - final boolean interestFreePeriodApplicable = false; - final Integer interestFreeFromPeriod = null; - final Integer interestFreeToPeriod = null; - final EnumOptionData interestFreePeriodFrequencyType = null; final boolean preClosurePenalApplicable = false; final BigDecimal preClosurePenalInterest = null; final EnumOptionData preClosurePenalInterestOnType = null; @@ -340,11 +301,9 @@ public class FixedDepositAccountData extends DepositAccountData { final EnumOptionData onAccountClosure = null; final Boolean transferInterestToSavings = null; - final Collection interestFreePeriodTypeOptions = null; final Collection preClosurePenalInterestOnTypeOptions = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; - final Collection depositPeriodFrequencyOptions = null; + final Collection periodFrequencyTypeOptions = null; + final EnumOptionData depositType = SavingsEnumerations.depositType(DepositAccountType.FIXED_DEPOSIT.getValue()); final PortfolioAccountData linkedAccount = null; @@ -354,14 +313,11 @@ public class FixedDepositAccountData extends DepositAccountData { lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeForTransfers, summary, transactions, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, - withdrawalFeeTypeOptions, charges, chargeOptions, accountChart, chartTemplate, interestFreePeriodApplicable, - interestFreeFromPeriod, interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, - preClosurePenalInterest, preClosurePenalInterestOnType, interestFreePeriodTypeOptions, - preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, - inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, depositPeriod, - depositPeriodFrequency, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, depositPeriodFrequencyOptions, - depositType, onAccountClosure, onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas, linkedAccount, - transferInterestToSavings); + withdrawalFeeTypeOptions, charges, chargeOptions, accountChart, chartTemplate, preClosurePenalApplicable, + preClosurePenalInterest, preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, minDepositTerm, + maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, + depositAmount, maturityAmount, maturityDate, depositPeriod, depositPeriodFrequency, periodFrequencyTypeOptions, + depositType, onAccountClosure, onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas, linkedAccount, transferInterestToSavings); } public static FixedDepositAccountData withClosureTemplateDetails(final FixedDepositAccountData account, @@ -369,7 +325,7 @@ public class FixedDepositAccountData extends DepositAccountData { final Collection savingsAccountDatas) { return new FixedDepositAccountData(account.id, account.accountNo, account.externalId, account.groupId, account.groupName, - account.clientId, account.clientName, account.savingsProductId, account.savingsProductName, account.fieldOfficerId, + account.clientId, account.clientName, account.depositProductId, account.depositProductName, account.fieldOfficerId, account.fieldOfficerName, account.status, account.timeline, account.currency, account.nominalAnnualInterestRate, account.interestCompoundingPeriodType, account.interestPostingPeriodType, account.interestCalculationType, account.interestCalculationDaysInYearType, account.minRequiredOpeningBalance, account.lockinPeriodFrequency, @@ -378,15 +334,13 @@ public class FixedDepositAccountData extends DepositAccountData { account.interestPostingPeriodTypeOptions, account.interestCalculationTypeOptions, account.interestCalculationDaysInYearTypeOptions, account.lockinPeriodFrequencyTypeOptions, account.withdrawalFeeTypeOptions, account.charges, account.chargeOptions, account.accountChart, account.chartTemplate, - account.interestFreePeriodApplicable, account.interestFreeFromPeriod, account.interestFreeToPeriod, - account.interestFreePeriodFrequencyType, account.preClosurePenalApplicable, account.preClosurePenalInterest, - account.preClosurePenalInterestOnType, account.interestFreePeriodTypeOptions, account.preClosurePenalInterestOnTypeOptions, - account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, account.maxDepositTermType, - account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, account.maturityAmount, - account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, account.depositTermTypeOptions, - account.inMultiplesOfDepositTermTypeOptions, account.depositPeriodFrequencyOptions, account.depositType, - account.onAccountClosure, onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas, account.linkedAccount, - account.transferInterestToSavings); + account.preClosurePenalApplicable, account.preClosurePenalInterest, account.preClosurePenalInterestOnType, + account.preClosurePenalInterestOnTypeOptions, account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, + account.maxDepositTermType, account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, + account.maturityAmount, account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, + account.periodFrequencyTypeOptions, account.depositType, account.onAccountClosure, onAccountClosureOptions, + paymentTypeOptions, savingsAccountDatas, account.linkedAccount, account.transferInterestToSavings); + } private FixedDepositAccountData(final Long id, final String accountNo, final String externalId, final Long groupId, @@ -406,17 +360,13 @@ public class FixedDepositAccountData extends DepositAccountData { final Collection lockinPeriodFrequencyTypeOptions, final Collection withdrawalFeeTypeOptions, final Collection charges, final Collection chargeOptions, final DepositAccountInterestRateChartData accountChart, final DepositAccountInterestRateChartData chartTemplate, - final boolean interestFreePeriodApplicable, final Integer interestFreeFromPeriod, final Integer interestFreeToPeriod, - final EnumOptionData interestFreePeriodFrequencyType, final boolean preClosurePenalApplicable, - final BigDecimal preClosurePenalInterest, final EnumOptionData preClosurePenalInterestOnType, - final Collection interestFreePeriodTypeOptions, - final Collection preClosurePenalInterestOnTypeOptions, final Integer minDepositTerm, - final Integer maxDepositTerm, final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, - final Integer inMultiplesOfDepositTerm, final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal depositAmount, - final BigDecimal maturityAmount, final LocalDate maturityDate, final Integer depositPeriod, - final EnumOptionData depositPeriodFrequency, final Collection depositTermTypeOptions, - final Collection inMultiplesOfDepositTermTypeOptions, - final Collection depositPeriodFrequencyOptions, final EnumOptionData depositType, + final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, + final EnumOptionData preClosurePenalInterestOnType, final Collection preClosurePenalInterestOnTypeOptions, + final Integer minDepositTerm, final Integer maxDepositTerm, final EnumOptionData minDepositTermType, + final EnumOptionData maxDepositTermType, final Integer inMultiplesOfDepositTerm, + final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal depositAmount, final BigDecimal maturityAmount, + final LocalDate maturityDate, final Integer depositPeriod, final EnumOptionData depositPeriodFrequency, + final Collection periodFrequencyTypeOptions, final EnumOptionData depositType, final EnumOptionData onAccountClosure, final Collection onAccountClosureOptions, final Collection paymentTypeOptions, final Collection savingsAccountDatas, final PortfolioAccountData linkedAccount, final Boolean transferInterestToSavings) { @@ -429,11 +379,6 @@ public class FixedDepositAccountData extends DepositAccountData { interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, charges, chargeOptions, accountChart, chartTemplate, depositType); - // fixed deposit additional fields - this.interestFreePeriodApplicable = interestFreePeriodApplicable; - this.interestFreeFromPeriod = interestFreeFromPeriod; - this.interestFreeToPeriod = interestFreeToPeriod; - this.interestFreePeriodFrequencyType = interestFreePeriodFrequencyType; this.preClosurePenalApplicable = preClosurePenalApplicable; this.preClosurePenalInterest = preClosurePenalInterest; this.preClosurePenalInterestOnType = preClosurePenalInterestOnType; @@ -453,11 +398,8 @@ public class FixedDepositAccountData extends DepositAccountData { this.transferInterestToSavings = transferInterestToSavings; // template - this.interestFreePeriodTypeOptions = interestFreePeriodTypeOptions; this.preClosurePenalInterestOnTypeOptions = preClosurePenalInterestOnTypeOptions; - this.depositTermTypeOptions = depositTermTypeOptions; - this.inMultiplesOfDepositTermTypeOptions = inMultiplesOfDepositTermTypeOptions; - this.depositPeriodFrequencyOptions = depositPeriodFrequencyOptions; + this.periodFrequencyTypeOptions = periodFrequencyTypeOptions; // account close template options this.onAccountClosureOptions = onAccountClosureOptions; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/FixedDepositProductData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/FixedDepositProductData.java index 0390ea620..6dfe81446 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/FixedDepositProductData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/FixedDepositProductData.java @@ -25,10 +25,6 @@ import org.mifosplatform.portfolio.interestratechart.data.InterestRateChartData; public class FixedDepositProductData extends DepositProductData { // additional fields - private boolean interestFreePeriodApplicable; - private Integer interestFreeFromPeriod; - private Integer interestFreeToPeriod; - protected EnumOptionData interestFreePeriodFrequencyType; private boolean preClosurePenalApplicable; protected BigDecimal preClosurePenalInterest; protected EnumOptionData preClosurePenalInterestOnType; @@ -42,10 +38,8 @@ public class FixedDepositProductData extends DepositProductData { protected BigDecimal depositAmount; protected BigDecimal maxDepositAmount; - private Collection interestFreePeriodTypeOptions; private Collection preClosurePenalInterestOnTypeOptions; - private Collection depositTermTypeOptions; - private Collection inMultiplesOfDepositTermTypeOptions; + private Collection periodFrequencyTypeOptions; public static FixedDepositProductData template(final CurrencyData currency, final EnumOptionData interestCompoundingPeriodType, final EnumOptionData interestPostingPeriodType, final EnumOptionData interestCalculationType, @@ -58,9 +52,8 @@ public class FixedDepositProductData extends DepositProductData { final Collection paymentTypeOptions, final Collection accountingRuleOptions, final Map> accountingMappingOptions, final Collection chargeOptions, final Collection penaltyOptions, final InterestRateChartData chartTemplate, - final Collection interestFreePeriodTypes, - final Collection preClosurePenalInterestOnTypeOptions, final Collection depositTermTypeOptions, - final Collection inMultiplesOfDepositTermTypeOptions) { + final Collection preClosurePenalInterestOnTypeOptions, + final Collection periodFrequencyTypeOptions) { final Long id = null; final String name = null; @@ -75,10 +68,7 @@ public class FixedDepositProductData extends DepositProductData { final Collection feeToIncomeAccountMappings = null; final Collection penaltyToIncomeAccountMappings = null; final Collection interestRateCharts = null; - final boolean interestFreePeriodApplicable = false; - final Integer interestFreeFromPeriod = null; - final Integer interestFreeToPeriod = null; - final EnumOptionData interestFreePeriodFrequencyType = null; + final boolean preClosurePenalApplicable = false; final BigDecimal preClosurePenalInterest = null; final EnumOptionData preClosurePenalInterestOnType = null; @@ -98,11 +88,10 @@ public class FixedDepositProductData extends DepositProductData { currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, charges, chargeOptions, penaltyOptions, feeToIncomeAccountMappings, - penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, - preClosurePenalInterestOnType, interestFreePeriodTypes, preClosurePenalInterestOnTypeOptions, minDepositTerm, - maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, - minDepositAmount, depositAmount, maxDepositAmount, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions); + penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, preClosurePenalApplicable, preClosurePenalInterest, + preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, + maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, minDepositAmount, depositAmount, + maxDepositAmount, periodFrequencyTypeOptions); } public static FixedDepositProductData withCharges(final FixedDepositProductData existingProduct, final Collection charges) { @@ -118,14 +107,12 @@ public class FixedDepositProductData extends DepositProductData { existingProduct.paymentTypeOptions, existingProduct.accountingRuleOptions, existingProduct.accountingMappingOptions, charges, existingProduct.chargeOptions, existingProduct.penaltyOptions, existingProduct.feeToIncomeAccountMappings, existingProduct.penaltyToIncomeAccountMappings, existingProduct.interestRateCharts, existingProduct.chartTemplate, - existingProduct.interestFreePeriodApplicable, existingProduct.interestFreeFromPeriod, existingProduct.interestFreeToPeriod, - existingProduct.interestFreePeriodFrequencyType, existingProduct.preClosurePenalApplicable, - existingProduct.preClosurePenalInterest, existingProduct.preClosurePenalInterestOnType, - existingProduct.interestFreePeriodTypeOptions, existingProduct.preClosurePenalInterestOnTypeOptions, + existingProduct.preClosurePenalApplicable, existingProduct.preClosurePenalInterest, + existingProduct.preClosurePenalInterestOnType, existingProduct.preClosurePenalInterestOnTypeOptions, existingProduct.minDepositTerm, existingProduct.maxDepositTerm, existingProduct.minDepositTermType, existingProduct.maxDepositTermType, existingProduct.inMultiplesOfDepositTerm, existingProduct.inMultiplesOfDepositTermType, existingProduct.minDepositAmount, existingProduct.depositAmount, existingProduct.maxDepositAmount, - existingProduct.depositTermTypeOptions, existingProduct.inMultiplesOfDepositTermTypeOptions); + existingProduct.periodFrequencyTypeOptions); } /** @@ -142,9 +129,8 @@ public class FixedDepositProductData extends DepositProductData { final Collection paymentTypeOptions, final Collection accountingRuleOptions, final Map> accountingMappingOptions, final Collection chargeOptions, final Collection penaltyOptions, final InterestRateChartData chartTemplate, - final Collection interestFreePeriodTypes, - final Collection preClosurePenalInterestOnTypeOptions, final Collection depositTermTypeOptions, - final Collection inMultiplesOfDepositTermTypeOptions) { + final Collection preClosurePenalInterestOnTypeOptions, + final Collection periodFrequencyTypeOptions) { return new FixedDepositProductData(existingProduct.id, existingProduct.name, existingProduct.shortName, existingProduct.description, existingProduct.currency, existingProduct.nominalAnnualInterestRate, @@ -156,14 +142,12 @@ public class FixedDepositProductData extends DepositProductData { interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, existingProduct.charges, chargeOptions, penaltyOptions, existingProduct.feeToIncomeAccountMappings, existingProduct.penaltyToIncomeAccountMappings, - existingProduct.interestRateCharts, chartTemplate, existingProduct.interestFreePeriodApplicable, - existingProduct.interestFreeFromPeriod, existingProduct.interestFreeToPeriod, - existingProduct.interestFreePeriodFrequencyType, existingProduct.preClosurePenalApplicable, - existingProduct.preClosurePenalInterest, existingProduct.preClosurePenalInterestOnType, interestFreePeriodTypes, + existingProduct.interestRateCharts, chartTemplate, existingProduct.preClosurePenalApplicable, + existingProduct.preClosurePenalInterest, existingProduct.preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, existingProduct.minDepositTerm, existingProduct.maxDepositTerm, existingProduct.minDepositTermType, existingProduct.maxDepositTermType, existingProduct.inMultiplesOfDepositTerm, existingProduct.inMultiplesOfDepositTermType, existingProduct.minDepositAmount, existingProduct.depositAmount, - existingProduct.maxDepositAmount, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions); + existingProduct.maxDepositAmount, periodFrequencyTypeOptions); } public static FixedDepositProductData withAccountingDetails(final FixedDepositProductData existingProduct, @@ -195,23 +179,19 @@ public class FixedDepositProductData extends DepositProductData { lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, existingProduct.charges, chargeOptions, penaltyOptions, feeToIncomeAccountMappings, penaltyToIncomeAccountMappings, existingProduct.interestRateCharts, existingProduct.chartTemplate, - existingProduct.interestFreePeriodApplicable, existingProduct.interestFreeFromPeriod, existingProduct.interestFreeToPeriod, - existingProduct.interestFreePeriodFrequencyType, existingProduct.preClosurePenalApplicable, - existingProduct.preClosurePenalInterest, existingProduct.preClosurePenalInterestOnType, - existingProduct.interestFreePeriodTypeOptions, existingProduct.preClosurePenalInterestOnTypeOptions, + existingProduct.preClosurePenalApplicable, existingProduct.preClosurePenalInterest, + existingProduct.preClosurePenalInterestOnType, existingProduct.preClosurePenalInterestOnTypeOptions, existingProduct.minDepositTerm, existingProduct.maxDepositTerm, existingProduct.minDepositTermType, existingProduct.maxDepositTermType, existingProduct.inMultiplesOfDepositTerm, existingProduct.inMultiplesOfDepositTermType, existingProduct.minDepositAmount, existingProduct.depositAmount, existingProduct.maxDepositAmount, - existingProduct.depositTermTypeOptions, existingProduct.inMultiplesOfDepositTermTypeOptions); + existingProduct.periodFrequencyTypeOptions); } - public static FixedDepositProductData instance(final DepositProductData depositProductData, final boolean interestFreePeriodApplicable, - final Integer interestFreeFromPeriod, final Integer interestFreeToPeriod, final EnumOptionData interestFreePeriodFrequencyType, - final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, - final EnumOptionData preClosurePenalInterestOnType, final Integer minDepositTerm, final Integer maxDepositTerm, - final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, final Integer inMultiplesOfDepositTerm, - final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal minDepositAmount, final BigDecimal depositAmount, - final BigDecimal maxDepositAmount) { + public static FixedDepositProductData instance(final DepositProductData depositProductData, final boolean preClosurePenalApplicable, + final BigDecimal preClosurePenalInterest, final EnumOptionData preClosurePenalInterestOnType, final Integer minDepositTerm, + final Integer maxDepositTerm, final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, + final Integer inMultiplesOfDepositTerm, final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal minDepositAmount, + final BigDecimal depositAmount, final BigDecimal maxDepositAmount) { final Map accountingMappings = null; final Collection paymentChannelToFundSourceMappings = null; @@ -233,10 +213,8 @@ public class FixedDepositProductData extends DepositProductData { final Collection penaltyToIncomeAccountMappings = null; final Collection interestRateCharts = null; final InterestRateChartData chartTemplate = null; - final Collection interestFreePeriodTypes = null; final Collection preClosurePenalInterestOnTypeOptions = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; + final Collection periodFrequencyTypeOptions = null; return new FixedDepositProductData(depositProductData.id, depositProductData.name, depositProductData.shortName, depositProductData.description, depositProductData.currency, depositProductData.nominalAnnualInterestRate, @@ -247,11 +225,10 @@ public class FixedDepositProductData extends DepositProductData { interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, charges, chargeOptions, penaltyOptions, feeToIncomeAccountMappings, - penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, - preClosurePenalInterestOnType, interestFreePeriodTypes, preClosurePenalInterestOnTypeOptions, minDepositTerm, - maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, - minDepositAmount, depositAmount, maxDepositAmount, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions); + penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, preClosurePenalApplicable, preClosurePenalInterest, + preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, + maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, minDepositAmount, depositAmount, + maxDepositAmount, periodFrequencyTypeOptions); } public static FixedDepositProductData lookup(final Long id, final String name) { @@ -287,14 +264,9 @@ public class FixedDepositProductData extends DepositProductData { final Collection penaltyToIncomeAccountMappings = null; final Collection interestRateCharts = null; final InterestRateChartData chartTemplate = null; - final boolean interestFreePeriodApplicable = false; - final Integer interestFreeFromPeriod = null; - final Integer interestFreeToPeriod = null; - final EnumOptionData interestFreePeriodFrequencyType = null; final boolean preClosurePenalApplicable = false; final BigDecimal preClosurePenalInterest = null; final EnumOptionData preClosurePenalInterestOnType = null; - final Collection interestFreePeriodTypes = null; final Collection preClosurePenalInterestOnTypeOptions = null; final Integer minDepositTerm = null; final Integer maxDepositTerm = null; @@ -305,8 +277,7 @@ public class FixedDepositProductData extends DepositProductData { final BigDecimal minDepositAmount = null; final BigDecimal depositAmount = null; final BigDecimal maxDepositAmount = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; + final Collection periodFrequencyTypeOptions = null; return new FixedDepositProductData(id, name, shortName, description, currency, nominalAnnualInterestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, @@ -314,11 +285,10 @@ public class FixedDepositProductData extends DepositProductData { currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, charges, chargeOptions, penaltyOptions, feeToIncomeAccountMappings, - penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, - preClosurePenalInterestOnType, interestFreePeriodTypes, preClosurePenalInterestOnTypeOptions, minDepositTerm, - maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, - minDepositAmount, depositAmount, maxDepositAmount, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions); + penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, preClosurePenalApplicable, preClosurePenalInterest, + preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, + maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, minDepositAmount, depositAmount, + maxDepositAmount, periodFrequencyTypeOptions); } public static FixedDepositProductData withInterestChart(final FixedDepositProductData existingProduct, @@ -335,15 +305,13 @@ public class FixedDepositProductData extends DepositProductData { existingProduct.paymentTypeOptions, existingProduct.accountingRuleOptions, existingProduct.accountingMappingOptions, existingProduct.charges, existingProduct.chargeOptions, existingProduct.penaltyOptions, existingProduct.feeToIncomeAccountMappings, existingProduct.penaltyToIncomeAccountMappings, interestRateCharts, - existingProduct.chartTemplate, existingProduct.interestFreePeriodApplicable, existingProduct.interestFreeFromPeriod, - existingProduct.interestFreeToPeriod, existingProduct.interestFreePeriodFrequencyType, - existingProduct.preClosurePenalApplicable, existingProduct.preClosurePenalInterest, - existingProduct.preClosurePenalInterestOnType, existingProduct.interestFreePeriodTypeOptions, - existingProduct.preClosurePenalInterestOnTypeOptions, existingProduct.minDepositTerm, existingProduct.maxDepositTerm, - existingProduct.minDepositTermType, existingProduct.maxDepositTermType, existingProduct.inMultiplesOfDepositTerm, - existingProduct.inMultiplesOfDepositTermType, existingProduct.minDepositAmount, existingProduct.depositAmount, - existingProduct.maxDepositAmount, existingProduct.depositTermTypeOptions, - existingProduct.inMultiplesOfDepositTermTypeOptions); + existingProduct.chartTemplate, existingProduct.preClosurePenalApplicable, existingProduct.preClosurePenalInterest, + existingProduct.preClosurePenalInterestOnType, existingProduct.preClosurePenalInterestOnTypeOptions, + existingProduct.minDepositTerm, existingProduct.maxDepositTerm, existingProduct.minDepositTermType, + existingProduct.maxDepositTermType, existingProduct.inMultiplesOfDepositTerm, existingProduct.inMultiplesOfDepositTermType, + existingProduct.minDepositAmount, existingProduct.depositAmount, existingProduct.maxDepositAmount, + existingProduct.periodFrequencyTypeOptions); + } private FixedDepositProductData(final Long id, final String name, final String shortName, final String description, @@ -364,15 +332,12 @@ public class FixedDepositProductData extends DepositProductData { final Collection feeToIncomeAccountMappings, final Collection penaltyToIncomeAccountMappings, final Collection interestRateCharts, final InterestRateChartData chartTemplate, - final boolean interestFreePeriodApplicable, final Integer interestFreeFromPeriod, final Integer interestFreeToPeriod, - final EnumOptionData interestFreePeriodFrequencyType, final boolean preClosurePenalApplicable, - final BigDecimal preClosurePenalInterest, final EnumOptionData preClosurePenalInterestOnType, - final Collection interestFreePeriodTypeOptions, - final Collection preClosurePenalInterestOnTypeOptions, final Integer minDepositTerm, - final Integer maxDepositTerm, final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, - final Integer inMultiplesOfDepositTerm, final EnumOptionData inMultiplesOfDepositTermType, - final BigDecimal minDepositAmount, final BigDecimal depositAmount, final BigDecimal maxDepositAmount, - final Collection depositTermTypeOptions, Collection inMultiplesOfDepositTermTypeOptions) { + final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, + final EnumOptionData preClosurePenalInterestOnType, final Collection preClosurePenalInterestOnTypeOptions, + final Integer minDepositTerm, final Integer maxDepositTerm, final EnumOptionData minDepositTermType, + final EnumOptionData maxDepositTermType, final Integer inMultiplesOfDepositTerm, + final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal minDepositAmount, final BigDecimal depositAmount, + final BigDecimal maxDepositAmount, final Collection periodFrequencyTypeOptions) { super(id, name, shortName, description, currency, nominalAnnualInterestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, lockinPeriodFrequency, @@ -383,10 +348,6 @@ public class FixedDepositProductData extends DepositProductData { penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate); // fixed deposit additional fields - this.interestFreePeriodApplicable = interestFreePeriodApplicable; - this.interestFreeFromPeriod = interestFreeFromPeriod; - this.interestFreeToPeriod = interestFreeToPeriod; - this.interestFreePeriodFrequencyType = interestFreePeriodFrequencyType; this.preClosurePenalApplicable = preClosurePenalApplicable; this.preClosurePenalInterest = preClosurePenalInterest; this.preClosurePenalInterestOnType = preClosurePenalInterestOnType; @@ -401,10 +362,8 @@ public class FixedDepositProductData extends DepositProductData { this.maxDepositAmount = maxDepositAmount; // template - this.interestFreePeriodTypeOptions = interestFreePeriodTypeOptions; this.preClosurePenalInterestOnTypeOptions = preClosurePenalInterestOnTypeOptions; - this.depositTermTypeOptions = depositTermTypeOptions; - this.inMultiplesOfDepositTermTypeOptions = inMultiplesOfDepositTermTypeOptions; + this.periodFrequencyTypeOptions = periodFrequencyTypeOptions; } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/RecurringDepositAccountData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/RecurringDepositAccountData.java index 5dcbeb73a..771341746 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/RecurringDepositAccountData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/RecurringDepositAccountData.java @@ -25,73 +25,65 @@ import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; public class RecurringDepositAccountData extends DepositAccountData { // additional fields - private boolean interestFreePeriodApplicable; - private Integer interestFreeFromPeriod; - private Integer interestFreeToPeriod; - private EnumOptionData interestFreePeriodFrequencyType; - private boolean preClosurePenalApplicable; - private BigDecimal preClosurePenalInterest; - private EnumOptionData preClosurePenalInterestOnType; - private Integer minDepositTerm; - private Integer maxDepositTerm; - private EnumOptionData minDepositTermType; - private EnumOptionData maxDepositTermType; - private Integer inMultiplesOfDepositTerm; - private EnumOptionData inMultiplesOfDepositTermType; - private BigDecimal depositAmount; - private BigDecimal maturityAmount; - private LocalDate maturityDate; - private Integer depositPeriod; - private EnumOptionData depositPeriodFrequency; - private BigDecimal recurringDepositAmount; - private EnumOptionData recurringDepositType; - private Integer recurringDepositFrequency; - private EnumOptionData recurringDepositFrequencyType; - private LocalDate expectedFirstDepositOnDate; + private final boolean preClosurePenalApplicable; + private final BigDecimal preClosurePenalInterest; + private final EnumOptionData preClosurePenalInterestOnType; + private final Integer minDepositTerm; + private final Integer maxDepositTerm; + private final EnumOptionData minDepositTermType; + private final EnumOptionData maxDepositTermType; + private final Integer inMultiplesOfDepositTerm; + private final EnumOptionData inMultiplesOfDepositTermType; + private final BigDecimal depositAmount; + private final BigDecimal maturityAmount; + private final LocalDate maturityDate; + private final Integer depositPeriod; + private final EnumOptionData depositPeriodFrequency; + private final BigDecimal mandatoryRecommendedDepositAmount; + private final BigDecimal totalOverdueAmount; + private final Integer noOfOverdueInstallments; + private final boolean isMandatoryDeposit; + private final boolean allowWithdrawal; + private final boolean adjustAdvanceTowardsFuturePayments; + private final LocalDate expectedFirstDepositOnDate; + private final boolean isCalendarInherited; + private final Integer recurringFrequency; + private final EnumOptionData recurringFrequencyType; // used for account close - private EnumOptionData onAccountClosure; + private final EnumOptionData onAccountClosure; - private Collection interestFreePeriodTypeOptions; - private Collection preClosurePenalInterestOnTypeOptions; - private Collection recurringDepositTypeOptions; - private Collection recurringDepositFrequencyTypeOptions; - private Collection depositTermTypeOptions; - private Collection inMultiplesOfDepositTermTypeOptions; - private Collection depositPeriodFrequencyOptions; - private Collection savingsAccounts; + private final Collection preClosurePenalInterestOnTypeOptions; + private final Collection periodFrequencyTypeOptions; + private final Collection savingsAccounts; // for account close - private Collection onAccountClosureOptions; - private Collection paymentTypeOptions; + private final Collection onAccountClosureOptions; + private final Collection paymentTypeOptions; public static RecurringDepositAccountData instance(final DepositAccountData depositAccountData, - final boolean interestFreePeriodApplicable, final Integer interestFreeFromPeriod, final Integer interestFreeToPeriod, - final EnumOptionData interestFreePeriodFrequencyType, final boolean preClosurePenalApplicable, - final BigDecimal preClosurePenalInterest, final EnumOptionData preClosurePenalInterestOnType, final Integer minDepositTerm, - final Integer maxDepositTerm, final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, - final Integer inMultiplesOfDepositTerm, final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal depositAmount, - final BigDecimal maturityAmount, final LocalDate maturityDate, final Integer depositPeriod, - final EnumOptionData depositPeriodFrequency, final BigDecimal recurringDepositAmount, - final EnumOptionData recurringDepositType, final Integer recurringDepositFrequency, - final EnumOptionData recurringDepositFrequencyType, final EnumOptionData onAccountClosure, - final LocalDate expectedFirstDepositOnDate) { + final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, + final EnumOptionData preClosurePenalInterestOnType, final Integer minDepositTerm, final Integer maxDepositTerm, + final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, final Integer inMultiplesOfDepositTerm, + final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal depositAmount, final BigDecimal maturityAmount, + final LocalDate maturityDate, final Integer depositPeriod, final EnumOptionData depositPeriodFrequency, + final BigDecimal mandatoryRecommendedDepositAmount, final EnumOptionData onAccountClosure, + final LocalDate expectedFirstDepositOnDate, final BigDecimal totalOverdueAmount, final Integer noOfOverdueInstallments, + final boolean isMandatoryDeposit, final boolean allowWithdrawal, final boolean adjustAdvanceTowardsFuturePayments, final boolean isCalendarInherited) { - final Collection interestFreePeriodTypeOptions = null; final Collection preClosurePenalInterestOnTypeOptions = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; - final Collection recurringDepositTypeOptions = null; - final Collection recurringDepositFrequencyTypeOptions = null; - final Collection depositPeriodFrequencyOptions = null; + final Collection periodFrequencyTypeOptions = null; + final EnumOptionData depositType = SavingsEnumerations.depositType(DepositAccountType.FIXED_DEPOSIT.getValue()); final Collection onAccountClosureOptions = null; final Collection paymentTypeOptions = null; final Collection savingsAccountDatas = null; + final Integer recurringFrequency = null; + final EnumOptionData recurringFrequencyType = null; return new RecurringDepositAccountData(depositAccountData.id, depositAccountData.accountNo, depositAccountData.externalId, depositAccountData.groupId, depositAccountData.groupName, depositAccountData.clientId, depositAccountData.clientName, - depositAccountData.savingsProductId, depositAccountData.savingsProductName, depositAccountData.fieldOfficerId, + depositAccountData.depositProductId, depositAccountData.depositProductName, depositAccountData.fieldOfficerId, depositAccountData.fieldOfficerName, depositAccountData.status, depositAccountData.timeline, depositAccountData.currency, depositAccountData.nominalAnnualInterestRate, depositAccountData.interestCompoundingPeriodType, depositAccountData.interestPostingPeriodType, depositAccountData.interestCalculationType, @@ -103,20 +95,18 @@ public class RecurringDepositAccountData extends DepositAccountData { depositAccountData.interestCalculationTypeOptions, depositAccountData.interestCalculationDaysInYearTypeOptions, depositAccountData.lockinPeriodFrequencyTypeOptions, depositAccountData.withdrawalFeeTypeOptions, depositAccountData.charges, depositAccountData.chargeOptions, depositAccountData.accountChart, - depositAccountData.chartTemplate, interestFreePeriodApplicable, interestFreeFromPeriod, interestFreeToPeriod, - interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestOnType, - interestFreePeriodTypeOptions, preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, - maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, - depositPeriod, depositPeriodFrequency, recurringDepositAmount, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - recurringDepositType, recurringDepositFrequency, recurringDepositFrequencyType, recurringDepositTypeOptions, - recurringDepositFrequencyTypeOptions, depositPeriodFrequencyOptions, depositType, onAccountClosure, - onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas, expectedFirstDepositOnDate); + depositAccountData.chartTemplate, preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestOnType, + preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, + inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, depositPeriod, + depositPeriodFrequency, mandatoryRecommendedDepositAmount, periodFrequencyTypeOptions, depositType, onAccountClosure, + onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas, expectedFirstDepositOnDate, totalOverdueAmount, + noOfOverdueInstallments, isMandatoryDeposit, allowWithdrawal, adjustAdvanceTowardsFuturePayments, isCalendarInherited, recurringFrequency, recurringFrequencyType); } - public static RecurringDepositAccountData withInterestChart(final RecurringDepositAccountData account, - final DepositAccountInterestRateChartData accountChart) { + public static RecurringDepositAccountData withInterestChartAndRecurringDetails(final RecurringDepositAccountData account, + final DepositAccountInterestRateChartData accountChart, final Integer recurringFrequency, final EnumOptionData recurringFrequencyType) { return new RecurringDepositAccountData(account.id, account.accountNo, account.externalId, account.groupId, account.groupName, - account.clientId, account.clientName, account.savingsProductId, account.savingsProductName, account.fieldOfficerId, + account.clientId, account.clientName, account.depositProductId, account.depositProductName, account.fieldOfficerId, account.fieldOfficerName, account.status, account.timeline, account.currency, account.nominalAnnualInterestRate, account.interestCompoundingPeriodType, account.interestPostingPeriodType, account.interestCalculationType, account.interestCalculationDaysInYearType, account.minRequiredOpeningBalance, account.lockinPeriodFrequency, @@ -125,17 +115,15 @@ public class RecurringDepositAccountData extends DepositAccountData { account.interestPostingPeriodTypeOptions, account.interestCalculationTypeOptions, account.interestCalculationDaysInYearTypeOptions, account.lockinPeriodFrequencyTypeOptions, account.withdrawalFeeTypeOptions, account.charges, account.chargeOptions, accountChart, account.chartTemplate, - account.interestFreePeriodApplicable, account.interestFreeFromPeriod, account.interestFreeToPeriod, - account.interestFreePeriodFrequencyType, account.preClosurePenalApplicable, account.preClosurePenalInterest, - account.preClosurePenalInterestOnType, account.interestFreePeriodTypeOptions, account.preClosurePenalInterestOnTypeOptions, - account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, account.maxDepositTermType, - account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, account.maturityAmount, - account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, account.recurringDepositAmount, - account.depositTermTypeOptions, account.inMultiplesOfDepositTermTypeOptions, account.recurringDepositType, - account.recurringDepositFrequency, account.recurringDepositFrequencyType, account.recurringDepositTypeOptions, - account.recurringDepositFrequencyTypeOptions, account.depositPeriodFrequencyOptions, account.depositType, + account.preClosurePenalApplicable, account.preClosurePenalInterest, account.preClosurePenalInterestOnType, + account.preClosurePenalInterestOnTypeOptions, account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, + account.maxDepositTermType, account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, + account.maturityAmount, account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, + account.mandatoryRecommendedDepositAmount, account.periodFrequencyTypeOptions, account.depositType, account.onAccountClosure, account.onAccountClosureOptions, account.paymentTypeOptions, account.savingsAccounts, - account.expectedFirstDepositOnDate); + account.expectedFirstDepositOnDate, account.totalOverdueAmount, account.noOfOverdueInstallments, + account.isMandatoryDeposit, account.allowWithdrawal, account.adjustAdvanceTowardsFuturePayments, + account.isCalendarInherited, recurringFrequency, recurringFrequencyType); } public static RecurringDepositAccountData withTemplateOptions(final RecurringDepositAccountData account, @@ -153,24 +141,17 @@ public class RecurringDepositAccountData extends DepositAccountData { final Collection withdrawalFeeTypeOptions = null; final Collection chargeOptions = null; - final Collection interestFreePeriodTypeOptions = null; final Collection preClosurePenalInterestOnTypeOptions = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; - final Collection recurringDepositTypeOptions = null; - final Collection recurringDepositFrequencyTypeOptions = null; - final Collection depositPeriodFrequencyOptions = null; + final Collection periodFrequencyTypeOptions = null; return withTemplateOptions(account, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, transactions, charges, chargeOptions, - interestFreePeriodTypeOptions, preClosurePenalInterestOnTypeOptions, depositTermTypeOptions, - inMultiplesOfDepositTermTypeOptions, recurringDepositTypeOptions, recurringDepositFrequencyTypeOptions, - depositPeriodFrequencyOptions); + preClosurePenalInterestOnTypeOptions, periodFrequencyTypeOptions); } return new RecurringDepositAccountData(account.id, account.accountNo, account.externalId, account.groupId, account.groupName, - account.clientId, account.clientName, account.savingsProductId, account.savingsProductName, account.fieldOfficerId, + account.clientId, account.clientName, account.depositProductId, account.depositProductName, account.fieldOfficerId, account.fieldOfficerName, account.status, account.timeline, account.currency, account.nominalAnnualInterestRate, account.interestCompoundingPeriodType, account.interestPostingPeriodType, account.interestCalculationType, account.interestCalculationDaysInYearType, account.minRequiredOpeningBalance, account.lockinPeriodFrequency, @@ -179,17 +160,15 @@ public class RecurringDepositAccountData extends DepositAccountData { template.interestPostingPeriodTypeOptions, template.interestCalculationTypeOptions, template.interestCalculationDaysInYearTypeOptions, template.lockinPeriodFrequencyTypeOptions, template.withdrawalFeeTypeOptions, charges, template.chargeOptions, account.accountChart, account.chartTemplate, - account.interestFreePeriodApplicable, account.interestFreeFromPeriod, account.interestFreeToPeriod, - account.interestFreePeriodFrequencyType, account.preClosurePenalApplicable, account.preClosurePenalInterest, - account.preClosurePenalInterestOnType, template.interestFreePeriodTypeOptions, + account.preClosurePenalApplicable, account.preClosurePenalInterest, account.preClosurePenalInterestOnType, template.preClosurePenalInterestOnTypeOptions, account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, account.maxDepositTermType, account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, account.maturityAmount, account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, - account.recurringDepositAmount, template.depositTermTypeOptions, template.inMultiplesOfDepositTermTypeOptions, - account.recurringDepositType, account.recurringDepositFrequency, account.recurringDepositFrequencyType, - template.recurringDepositTypeOptions, template.recurringDepositFrequencyTypeOptions, - template.depositPeriodFrequencyOptions, account.depositType, account.onAccountClosure, account.onAccountClosureOptions, - account.paymentTypeOptions, account.savingsAccounts, account.expectedFirstDepositOnDate); + account.mandatoryRecommendedDepositAmount, template.periodFrequencyTypeOptions, account.depositType, + account.onAccountClosure, account.onAccountClosureOptions, account.paymentTypeOptions, account.savingsAccounts, + account.expectedFirstDepositOnDate, account.totalOverdueAmount, account.noOfOverdueInstallments, + account.isMandatoryDeposit, account.allowWithdrawal, account.adjustAdvanceTowardsFuturePayments, + account.isCalendarInherited, account.recurringFrequency, account.recurringFrequencyType); } @@ -201,15 +180,11 @@ public class RecurringDepositAccountData extends DepositAccountData { final Collection interestCalculationDaysInYearTypeOptions, final Collection lockinPeriodFrequencyTypeOptions, final Collection withdrawalFeeTypeOptions, final Collection transactions, final Collection charges, - final Collection chargeOptions, final Collection interestFreePeriodTypeOptions, - final Collection preClosurePenalInterestOnTypeOptions, final Collection depositTermTypeOptions, - final Collection inMultiplesOfDepositTermTypeOptions, - final Collection recurringDepositTypeOptions, - final Collection recurringDepositFrequencyTypeOptions, - final Collection depositPeriodFrequencyOptions) { + final Collection chargeOptions, final Collection preClosurePenalInterestOnTypeOptions, + final Collection periodFrequencyTypeOptions) { return new RecurringDepositAccountData(account.id, account.accountNo, account.externalId, account.groupId, account.groupName, - account.clientId, account.clientName, account.savingsProductId, account.savingsProductName, account.fieldOfficerId, + account.clientId, account.clientName, account.depositProductId, account.depositProductName, account.fieldOfficerId, account.fieldOfficerName, account.status, account.timeline, account.currency, account.nominalAnnualInterestRate, account.interestCompoundingPeriodType, account.interestPostingPeriodType, account.interestCalculationType, account.interestCalculationDaysInYearType, account.minRequiredOpeningBalance, account.lockinPeriodFrequency, @@ -217,16 +192,15 @@ public class RecurringDepositAccountData extends DepositAccountData { fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, charges, chargeOptions, account.accountChart, account.chartTemplate, - account.interestFreePeriodApplicable, account.interestFreeFromPeriod, account.interestFreeToPeriod, - account.interestFreePeriodFrequencyType, account.preClosurePenalApplicable, account.preClosurePenalInterest, - account.preClosurePenalInterestOnType, interestFreePeriodTypeOptions, preClosurePenalInterestOnTypeOptions, - account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, account.maxDepositTermType, - account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, account.maturityAmount, - account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, account.recurringDepositAmount, - depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, account.recurringDepositType, - account.recurringDepositFrequency, account.recurringDepositFrequencyType, recurringDepositTypeOptions, - recurringDepositFrequencyTypeOptions, depositPeriodFrequencyOptions, account.depositType, account.onAccountClosure, - account.onAccountClosureOptions, account.paymentTypeOptions, account.savingsAccounts, account.expectedFirstDepositOnDate); + account.preClosurePenalApplicable, account.preClosurePenalInterest, account.preClosurePenalInterestOnType, + preClosurePenalInterestOnTypeOptions, account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, + account.maxDepositTermType, account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, + account.maturityAmount, account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, + account.mandatoryRecommendedDepositAmount, periodFrequencyTypeOptions, account.depositType, account.onAccountClosure, + account.onAccountClosureOptions, account.paymentTypeOptions, account.savingsAccounts, account.expectedFirstDepositOnDate, + account.totalOverdueAmount, account.noOfOverdueInstallments, account.isMandatoryDeposit, account.allowWithdrawal, + account.adjustAdvanceTowardsFuturePayments, account.isCalendarInherited, account.recurringFrequency, + account.recurringFrequencyType); } public static RecurringDepositAccountData withClientTemplate(final Long clientId, final String clientName, final Long groupId, @@ -268,10 +242,6 @@ public class RecurringDepositAccountData extends DepositAccountData { final DepositAccountInterestRateChartData accountChart = null; final DepositAccountInterestRateChartData chartTemplate = null; - final boolean interestFreePeriodApplicable = false; - final Integer interestFreeFromPeriod = null; - final Integer interestFreeToPeriod = null; - final EnumOptionData interestFreePeriodFrequencyType = null; final boolean preClosurePenalApplicable = false; final BigDecimal preClosurePenalInterest = null; final EnumOptionData preClosurePenalInterestOnType = null; @@ -286,45 +256,46 @@ public class RecurringDepositAccountData extends DepositAccountData { final LocalDate maturityDate = null; final Integer depositPeriod = null; final EnumOptionData depositPeriodFrequency = null; - final BigDecimal recurringDepositAmount = null; + final BigDecimal mandatoryRecommendedDepositAmount = null; final EnumOptionData onAccountClosure = null; - final Collection interestFreePeriodTypeOptions = null; final Collection preClosurePenalInterestOnTypeOptions = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; + final Collection periodFrequencyTypeOptions = null; - final EnumOptionData recurringDepositType = null; - final Integer recurringDepositFrequency = null; - final EnumOptionData recurringDepositFrequencyType = null; - final Collection recurringDepositTypeOptions = null; - final Collection recurringDepositFrequencyTypeOptions = null; - final Collection depositPeriodFrequencyOptions = null; final EnumOptionData depositType = SavingsEnumerations.depositType(DepositAccountType.RECURRING_DEPOSIT.getValue()); final Collection onAccountClosureOptions = null; final Collection paymentTypeOptions = null; final Collection savingsAccountDatas = null; final LocalDate expectedFirstDepositOnDate = null; + final BigDecimal totalOverdueAmount = null; + final Integer noOfOverdueInstallments = null; + final boolean isMandatoryDeposit = false; + final boolean allowWithdrawal = false; + final boolean adjustAdvanceTowardsFuturePayments = false; + + final boolean isCalendarInherited = false; + final Integer recurringFrequency = null; + final EnumOptionData recurringFrequencyType = null; + return new RecurringDepositAccountData(id, accountNo, externalId, groupId, groupName, clientId, clientName, productId, productName, fieldOfficerId, fieldOfficerName, status, timeline, currency, nominalAnnualInterestRate, interestPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeForTransfers, summary, transactions, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, - withdrawalFeeTypeOptions, charges, chargeOptions, accountChart, chartTemplate, interestFreePeriodApplicable, - interestFreeFromPeriod, interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, - preClosurePenalInterest, preClosurePenalInterestOnType, interestFreePeriodTypeOptions, - preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, - inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, depositPeriod, - depositPeriodFrequency, recurringDepositAmount, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - recurringDepositType, recurringDepositFrequency, recurringDepositFrequencyType, recurringDepositTypeOptions, - recurringDepositFrequencyTypeOptions, depositPeriodFrequencyOptions, depositType, onAccountClosure, - onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas, expectedFirstDepositOnDate); + withdrawalFeeTypeOptions, charges, chargeOptions, accountChart, chartTemplate, preClosurePenalApplicable, + preClosurePenalInterest, preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, minDepositTerm, + maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, + depositAmount, maturityAmount, maturityDate, depositPeriod, depositPeriodFrequency, mandatoryRecommendedDepositAmount, + periodFrequencyTypeOptions, depositType, onAccountClosure, onAccountClosureOptions, paymentTypeOptions, + savingsAccountDatas, expectedFirstDepositOnDate, totalOverdueAmount, noOfOverdueInstallments, isMandatoryDeposit, + allowWithdrawal, adjustAdvanceTowardsFuturePayments, isCalendarInherited, recurringFrequency, recurringFrequencyType); } - public static RecurringDepositAccountData preClosureDetails(final Long accountId, BigDecimal maturityAmount, - final Collection onAccountClosureOptions, final Collection paymentTypeOptions, final Collection savingsAccountDatas) { + public static RecurringDepositAccountData preClosureDetails(final Long accountId, final BigDecimal maturityAmount, + final Collection onAccountClosureOptions, final Collection paymentTypeOptions, + final Collection savingsAccountDatas) { final String accountNo = null; final String externalId = null; @@ -361,10 +332,6 @@ public class RecurringDepositAccountData extends DepositAccountData { final DepositAccountInterestRateChartData accountChart = null; final DepositAccountInterestRateChartData chartTemplate = null; - final boolean interestFreePeriodApplicable = false; - final Integer interestFreeFromPeriod = null; - final Integer interestFreeToPeriod = null; - final EnumOptionData interestFreePeriodFrequencyType = null; final boolean preClosurePenalApplicable = false; final BigDecimal preClosurePenalInterest = null; final EnumOptionData preClosurePenalInterestOnType = null; @@ -378,20 +345,10 @@ public class RecurringDepositAccountData extends DepositAccountData { final LocalDate maturityDate = null; final Integer depositPeriod = null; final EnumOptionData depositPeriodFrequency = null; - final BigDecimal recurringDepositAmount = null; + final BigDecimal mandatoryRecommendedDepositAmount = null; final EnumOptionData onAccountClosure = null; - - final Collection interestFreePeriodTypeOptions = null; final Collection preClosurePenalInterestOnTypeOptions = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; - - final EnumOptionData recurringDepositType = null; - final Integer recurringDepositFrequency = null; - final EnumOptionData recurringDepositFrequencyType = null; - final Collection recurringDepositTypeOptions = null; - final Collection recurringDepositFrequencyTypeOptions = null; - final Collection depositPeriodFrequencyOptions = null; + final Collection periodFrequencyTypeOptions = null; final EnumOptionData depositType = SavingsEnumerations.depositType(DepositAccountType.RECURRING_DEPOSIT.getValue()); final Long groupId = null; @@ -400,28 +357,36 @@ public class RecurringDepositAccountData extends DepositAccountData { final String clientName = null; final LocalDate expectedFirstDepositOnDate = null; + final BigDecimal totalOverdueAmount = null; + final Integer noOfOverdueInstallments = null; + final boolean isMandatoryDeposit = false; + final boolean allowWithdrawal = false; + final boolean adjustAdvanceTowardsFuturePayments = false; + final boolean isCalendarInherited = false; + final Integer recurringFrequency = null; + final EnumOptionData recurringFrequencyType = null; + return new RecurringDepositAccountData(accountId, accountNo, externalId, groupId, groupName, clientId, clientName, productId, productName, fieldOfficerId, fieldOfficerName, status, timeline, currency, nominalAnnualInterestRate, interestPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeForTransfers, summary, transactions, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, - withdrawalFeeTypeOptions, charges, chargeOptions, accountChart, chartTemplate, interestFreePeriodApplicable, - interestFreeFromPeriod, interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, - preClosurePenalInterest, preClosurePenalInterestOnType, interestFreePeriodTypeOptions, - preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, - inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, depositPeriod, - depositPeriodFrequency, recurringDepositAmount, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - recurringDepositType, recurringDepositFrequency, recurringDepositFrequencyType, recurringDepositTypeOptions, - recurringDepositFrequencyTypeOptions, depositPeriodFrequencyOptions, depositType, onAccountClosure, - onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas, expectedFirstDepositOnDate); + withdrawalFeeTypeOptions, charges, chargeOptions, accountChart, chartTemplate, preClosurePenalApplicable, + preClosurePenalInterest, preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, minDepositTerm, + maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, + depositAmount, maturityAmount, maturityDate, depositPeriod, depositPeriodFrequency, mandatoryRecommendedDepositAmount, + periodFrequencyTypeOptions, depositType, onAccountClosure, onAccountClosureOptions, paymentTypeOptions, + savingsAccountDatas, expectedFirstDepositOnDate, totalOverdueAmount, noOfOverdueInstallments, isMandatoryDeposit, + allowWithdrawal, adjustAdvanceTowardsFuturePayments, isCalendarInherited, recurringFrequency, recurringFrequencyType); } public static RecurringDepositAccountData withClosureTemplateDetails(final RecurringDepositAccountData account, - final Collection onAccountClosureOptions, final Collection paymentTypeOptions, final Collection savingsAccountDatas) { + final Collection onAccountClosureOptions, final Collection paymentTypeOptions, + final Collection savingsAccountDatas) { return new RecurringDepositAccountData(account.id, account.accountNo, account.externalId, account.groupId, account.groupName, - account.clientId, account.clientName, account.savingsProductId, account.savingsProductName, account.fieldOfficerId, + account.clientId, account.clientName, account.depositProductId, account.depositProductName, account.fieldOfficerId, account.fieldOfficerName, account.status, account.timeline, account.currency, account.nominalAnnualInterestRate, account.interestCompoundingPeriodType, account.interestPostingPeriodType, account.interestCalculationType, account.interestCalculationDaysInYearType, account.minRequiredOpeningBalance, account.lockinPeriodFrequency, @@ -430,17 +395,15 @@ public class RecurringDepositAccountData extends DepositAccountData { account.interestPostingPeriodTypeOptions, account.interestCalculationTypeOptions, account.interestCalculationDaysInYearTypeOptions, account.lockinPeriodFrequencyTypeOptions, account.withdrawalFeeTypeOptions, account.charges, account.chargeOptions, account.accountChart, account.chartTemplate, - account.interestFreePeriodApplicable, account.interestFreeFromPeriod, account.interestFreeToPeriod, - account.interestFreePeriodFrequencyType, account.preClosurePenalApplicable, account.preClosurePenalInterest, - account.preClosurePenalInterestOnType, account.interestFreePeriodTypeOptions, account.preClosurePenalInterestOnTypeOptions, - account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, account.maxDepositTermType, - account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, account.maturityAmount, - account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, account.recurringDepositAmount, - account.depositTermTypeOptions, account.inMultiplesOfDepositTermTypeOptions, account.recurringDepositType, - account.recurringDepositFrequency, account.recurringDepositFrequencyType, account.recurringDepositTypeOptions, - account.recurringDepositFrequencyTypeOptions, account.depositPeriodFrequencyOptions, account.depositType, + account.preClosurePenalApplicable, account.preClosurePenalInterest, account.preClosurePenalInterestOnType, + account.preClosurePenalInterestOnTypeOptions, account.minDepositTerm, account.maxDepositTerm, account.minDepositTermType, + account.maxDepositTermType, account.inMultiplesOfDepositTerm, account.inMultiplesOfDepositTermType, account.depositAmount, + account.maturityAmount, account.maturityDate, account.depositPeriod, account.depositPeriodFrequency, + account.mandatoryRecommendedDepositAmount, account.periodFrequencyTypeOptions, account.depositType, account.onAccountClosure, onAccountClosureOptions, paymentTypeOptions, savingsAccountDatas, - account.expectedFirstDepositOnDate); + account.expectedFirstDepositOnDate, account.totalOverdueAmount, account.noOfOverdueInstallments, + account.isMandatoryDeposit, account.allowWithdrawal, account.adjustAdvanceTowardsFuturePayments, + account.isCalendarInherited, account.recurringFrequency, account.recurringFrequencyType); } private RecurringDepositAccountData(final Long id, final String accountNo, final String externalId, final Long groupId, @@ -460,23 +423,19 @@ public class RecurringDepositAccountData extends DepositAccountData { final Collection lockinPeriodFrequencyTypeOptions, final Collection withdrawalFeeTypeOptions, final Collection charges, final Collection chargeOptions, final DepositAccountInterestRateChartData accountChart, final DepositAccountInterestRateChartData chartTemplate, - final boolean interestFreePeriodApplicable, final Integer interestFreeFromPeriod, final Integer interestFreeToPeriod, - final EnumOptionData interestFreePeriodFrequencyType, final boolean preClosurePenalApplicable, - final BigDecimal preClosurePenalInterest, final EnumOptionData preClosurePenalInterestOnType, - final Collection interestFreePeriodTypeOptions, - final Collection preClosurePenalInterestOnTypeOptions, final Integer minDepositTerm, - final Integer maxDepositTerm, final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, - final Integer inMultiplesOfDepositTerm, final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal depositAmount, - final BigDecimal maturityAmount, final LocalDate maturityDate, final Integer depositPeriod, - final EnumOptionData depositPeriodFrequency, final BigDecimal recurringDepositAmount, - final Collection depositTermTypeOptions, Collection inMultiplesOfDepositTermTypeOptions, - final EnumOptionData recurringDepositType, final Integer recurringDepositFrequency, - final EnumOptionData recurringDepositFrequencyType, final Collection recurringDepositTypeOptions, - final Collection recurringDepositFrequencyTypeOptions, - final Collection depositPeriodFrequencyOptions, final EnumOptionData depositType, - final EnumOptionData onAccountClosure, final Collection onAccountClosureOptions, - final Collection paymentTypeOptions, final Collection savingsAccountDatas, - final LocalDate expectedFirstDepositOnDate) { + final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, + final EnumOptionData preClosurePenalInterestOnType, final Collection preClosurePenalInterestOnTypeOptions, + final Integer minDepositTerm, final Integer maxDepositTerm, final EnumOptionData minDepositTermType, + final EnumOptionData maxDepositTermType, final Integer inMultiplesOfDepositTerm, + final EnumOptionData inMultiplesOfDepositTermType, final BigDecimal depositAmount, final BigDecimal maturityAmount, + final LocalDate maturityDate, final Integer depositPeriod, final EnumOptionData depositPeriodFrequency, + final BigDecimal mandatoryRecommendedDepositAmount, final Collection periodFrequencyTypeOptions, + final EnumOptionData depositType, final EnumOptionData onAccountClosure, + final Collection onAccountClosureOptions, final Collection paymentTypeOptions, + final Collection savingsAccountDatas, final LocalDate expectedFirstDepositOnDate, + final BigDecimal totalOverdueAmount, final Integer noOfOverdueInstallments, final boolean isMandatoryDeposit, + final boolean allowWithdrawal, final boolean adjustAdvanceTowardsFuturePayments, final boolean isCalendarInherited, + final Integer recurringFrequency, final EnumOptionData recurringFrequencyType) { super(id, accountNo, externalId, groupId, groupName, clientId, clientName, productId, productName, fieldofficerId, fieldofficerName, status, timeline, currency, nominalAnnualInterestRate, interestPeriodType, interestPostingPeriodType, @@ -486,10 +445,6 @@ public class RecurringDepositAccountData extends DepositAccountData { interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, charges, chargeOptions, accountChart, chartTemplate, depositType); - this.interestFreePeriodApplicable = interestFreePeriodApplicable; - this.interestFreeFromPeriod = interestFreeFromPeriod; - this.interestFreeToPeriod = interestFreeToPeriod; - this.interestFreePeriodFrequencyType = interestFreePeriodFrequencyType; this.preClosurePenalApplicable = preClosurePenalApplicable; this.preClosurePenalInterest = preClosurePenalInterest; this.preClosurePenalInterestOnType = preClosurePenalInterestOnType; @@ -504,20 +459,20 @@ public class RecurringDepositAccountData extends DepositAccountData { this.maturityDate = maturityDate; this.depositPeriod = depositPeriod; this.depositPeriodFrequency = depositPeriodFrequency; - this.recurringDepositAmount = recurringDepositAmount; - this.recurringDepositFrequencyType = recurringDepositFrequencyType; - this.recurringDepositFrequency = recurringDepositFrequency; - this.recurringDepositType = recurringDepositType; this.expectedFirstDepositOnDate = expectedFirstDepositOnDate; + this.mandatoryRecommendedDepositAmount = mandatoryRecommendedDepositAmount; + this.totalOverdueAmount = totalOverdueAmount; + this.noOfOverdueInstallments = noOfOverdueInstallments; + this.isMandatoryDeposit = isMandatoryDeposit; + this.allowWithdrawal = allowWithdrawal; + this.adjustAdvanceTowardsFuturePayments = adjustAdvanceTowardsFuturePayments; + + this.isCalendarInherited = isCalendarInherited; + this.recurringFrequency = recurringFrequency; + this.recurringFrequencyType = recurringFrequencyType; - // template data - this.interestFreePeriodTypeOptions = interestFreePeriodTypeOptions; this.preClosurePenalInterestOnTypeOptions = preClosurePenalInterestOnTypeOptions; - this.recurringDepositTypeOptions = recurringDepositTypeOptions; - this.recurringDepositFrequencyTypeOptions = recurringDepositFrequencyTypeOptions; - this.depositTermTypeOptions = depositTermTypeOptions; - this.inMultiplesOfDepositTermTypeOptions = inMultiplesOfDepositTermTypeOptions; - this.depositPeriodFrequencyOptions = depositPeriodFrequencyOptions; + this.periodFrequencyTypeOptions = periodFrequencyTypeOptions; this.onAccountClosure = onAccountClosure; this.savingsAccounts = savingsAccountDatas; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/RecurringDepositProductData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/RecurringDepositProductData.java index 9a95747e3..4faebc17f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/RecurringDepositProductData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/RecurringDepositProductData.java @@ -24,10 +24,6 @@ import org.mifosplatform.portfolio.interestratechart.data.InterestRateChartData; */ public class RecurringDepositProductData extends DepositProductData { - private boolean interestFreePeriodApplicable; - private Integer interestFreeFromPeriod; - private Integer interestFreeToPeriod; - protected EnumOptionData interestFreePeriodFrequencyType; private boolean preClosurePenalApplicable; private BigDecimal preClosurePenalInterest; private EnumOptionData preClosurePenalInterestOnType; @@ -37,19 +33,15 @@ public class RecurringDepositProductData extends DepositProductData { private EnumOptionData maxDepositTermType; private Integer inMultiplesOfDepositTerm; private EnumOptionData inMultiplesOfDepositTermType; - private EnumOptionData recurringDepositType; - private Integer recurringDepositFrequency; - private EnumOptionData recurringDepositFrequencyType; private BigDecimal minDepositAmount; private BigDecimal depositAmount; private BigDecimal maxDepositAmount; + private boolean isMandatoryDeposit; + private boolean allowWithdrawal; + private boolean adjustAdvanceTowardsFuturePayments; - private Collection interestFreePeriodTypeOptions; private Collection preClosurePenalInterestOnTypeOptions; - private Collection recurringDepositTypeOptions; - private Collection recurringDepositFrequencyTypeOptions; - private Collection depositTermTypeOptions; - private Collection inMultiplesOfDepositTermTypeOptions; + private Collection periodFrequencyTypeOptions; public static RecurringDepositProductData template(final CurrencyData currency, final EnumOptionData interestCompoundingPeriodType, final EnumOptionData interestPostingPeriodType, final EnumOptionData interestCalculationType, @@ -62,11 +54,8 @@ public class RecurringDepositProductData extends DepositProductData { final Collection paymentTypeOptions, final Collection accountingRuleOptions, final Map> accountingMappingOptions, final Collection chargeOptions, final Collection penaltyOptions, final InterestRateChartData chartTemplate, - final Collection interestFreePeriodTypes, final Collection preClosurePenalInterestOnTypeOptions, - final Collection recurringDepositTypeOptions, - final Collection recurringDepositFrequencyTypeOptions, final Collection depositTermTypeOptions, - final Collection inMultiplesOfDepositTermTypeOptions) { + final Collection periodFrequencyTypeOptions) { final Long id = null; final String name = null; @@ -83,16 +72,12 @@ public class RecurringDepositProductData extends DepositProductData { final Collection feeToIncomeAccountMappings = null; final Collection penaltyToIncomeAccountMappings = null; final Collection interestRateCharts = null; - final boolean interestFreePeriodApplicable = false; - final Integer interestFreeFromPeriod = null; - final Integer interestFreeToPeriod = null; - final EnumOptionData interestFreePeriodFrequencyType = null; final boolean preClosurePenalApplicable = false; final BigDecimal preClosurePenalInterest = null; final EnumOptionData preClosurePenalInterestOnType = null; - final EnumOptionData recurringDepositType = null; - final Integer recurringDepositFrequency = null; - final EnumOptionData recurringDepositFrequencyType = null; + final boolean isMandatoryDeposit = false; + final boolean allowWithdrawal = false; + final boolean adjustAdvanceTowardsFuturePayments = false; final Integer minDepositTerm = null; final Integer maxDepositTerm = null; final EnumOptionData minDepositTermType = null; @@ -102,20 +87,17 @@ public class RecurringDepositProductData extends DepositProductData { final BigDecimal minDepositAmount = null; final BigDecimal depositAmount = null; final BigDecimal maxDepositAmount = null; - + return new RecurringDepositProductData(id, name, shortName, description, currency, nominalAnnualInterestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, lockinPeriodFrequency, lockinPeriodFrequencyType, accountingRule, accountingMappings, paymentChannelToFundSourceMappings, currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, charges, chargeOptions, penaltyOptions, feeToIncomeAccountMappings, - penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, - preClosurePenalInterestOnType, interestFreePeriodTypes, preClosurePenalInterestOnTypeOptions, minDepositTerm, - maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, recurringDepositType, - recurringDepositFrequency, recurringDepositFrequencyType, recurringDepositTypeOptions, - recurringDepositFrequencyTypeOptions, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - minDepositAmount, depositAmount, maxDepositAmount); + penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, preClosurePenalApplicable, preClosurePenalInterest, + preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, + maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, isMandatoryDeposit, allowWithdrawal, + adjustAdvanceTowardsFuturePayments, periodFrequencyTypeOptions, minDepositAmount, depositAmount, maxDepositAmount); } public static RecurringDepositProductData withCharges(final RecurringDepositProductData existingProduct, @@ -132,17 +114,13 @@ public class RecurringDepositProductData extends DepositProductData { existingProduct.paymentTypeOptions, existingProduct.accountingRuleOptions, existingProduct.accountingMappingOptions, charges, existingProduct.chargeOptions, existingProduct.penaltyOptions, existingProduct.feeToIncomeAccountMappings, existingProduct.penaltyToIncomeAccountMappings, existingProduct.interestRateCharts, existingProduct.chartTemplate, - existingProduct.interestFreePeriodApplicable, existingProduct.interestFreeFromPeriod, existingProduct.interestFreeToPeriod, - existingProduct.interestFreePeriodFrequencyType, existingProduct.preClosurePenalApplicable, - existingProduct.preClosurePenalInterest, existingProduct.preClosurePenalInterestOnType, - existingProduct.interestFreePeriodTypeOptions, existingProduct.preClosurePenalInterestOnTypeOptions, + existingProduct.preClosurePenalApplicable, existingProduct.preClosurePenalInterest, + existingProduct.preClosurePenalInterestOnType, existingProduct.preClosurePenalInterestOnTypeOptions, existingProduct.minDepositTerm, existingProduct.maxDepositTerm, existingProduct.minDepositTermType, existingProduct.maxDepositTermType, existingProduct.inMultiplesOfDepositTerm, existingProduct.inMultiplesOfDepositTermType, - existingProduct.recurringDepositType, existingProduct.recurringDepositFrequency, - existingProduct.recurringDepositFrequencyType, existingProduct.recurringDepositTypeOptions, - existingProduct.recurringDepositFrequencyTypeOptions, existingProduct.depositTermTypeOptions, - existingProduct.inMultiplesOfDepositTermTypeOptions, existingProduct.minDepositAmount, - existingProduct.depositAmount, existingProduct.maxDepositAmount); + existingProduct.isMandatoryDeposit, existingProduct.allowWithdrawal, existingProduct.adjustAdvanceTowardsFuturePayments, + existingProduct.periodFrequencyTypeOptions, existingProduct.minDepositAmount, existingProduct.depositAmount, + existingProduct.maxDepositAmount); } /** @@ -159,11 +137,8 @@ public class RecurringDepositProductData extends DepositProductData { final Collection paymentTypeOptions, final Collection accountingRuleOptions, final Map> accountingMappingOptions, final Collection chargeOptions, final Collection penaltyOptions, final InterestRateChartData chartTemplate, - final Collection interestFreePeriodTypes, final Collection preClosurePenalInterestOnTypeOptions, - final Collection recurringDepositTypeOptions, - final Collection recurringDepositFrequencyTypeOptions, final Collection depositTermTypeOptions, - final Collection inMultiplesOfDepositTermTypeOptions) { + final Collection periodFrequencyTypeOptions) { return new RecurringDepositProductData(existingProduct.id, existingProduct.name, existingProduct.shortName, existingProduct.description, existingProduct.currency, existingProduct.nominalAnnualInterestRate, @@ -175,16 +150,14 @@ public class RecurringDepositProductData extends DepositProductData { interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, existingProduct.charges, chargeOptions, penaltyOptions, existingProduct.feeToIncomeAccountMappings, existingProduct.penaltyToIncomeAccountMappings, - existingProduct.interestRateCharts, chartTemplate, existingProduct.interestFreePeriodApplicable, - existingProduct.interestFreeFromPeriod, existingProduct.interestFreeToPeriod, - existingProduct.interestFreePeriodFrequencyType, existingProduct.preClosurePenalApplicable, - existingProduct.preClosurePenalInterest, existingProduct.preClosurePenalInterestOnType, interestFreePeriodTypes, + existingProduct.interestRateCharts, chartTemplate, existingProduct.preClosurePenalApplicable, + existingProduct.preClosurePenalInterest, existingProduct.preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, existingProduct.minDepositTerm, existingProduct.maxDepositTerm, existingProduct.minDepositTermType, existingProduct.maxDepositTermType, existingProduct.inMultiplesOfDepositTerm, - existingProduct.inMultiplesOfDepositTermType, existingProduct.recurringDepositType, - existingProduct.recurringDepositFrequency, existingProduct.recurringDepositFrequencyType, recurringDepositTypeOptions, - recurringDepositFrequencyTypeOptions, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, existingProduct.minDepositAmount, + existingProduct.inMultiplesOfDepositTermType, existingProduct.isMandatoryDeposit, existingProduct.allowWithdrawal, + existingProduct.adjustAdvanceTowardsFuturePayments, periodFrequencyTypeOptions, existingProduct.minDepositAmount, existingProduct.depositAmount, existingProduct.maxDepositAmount); + } public static RecurringDepositProductData withAccountingDetails(final RecurringDepositProductData existingProduct, @@ -216,28 +189,21 @@ public class RecurringDepositProductData extends DepositProductData { lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, existingProduct.charges, chargeOptions, penaltyOptions, feeToIncomeAccountMappings, penaltyToIncomeAccountMappings, existingProduct.interestRateCharts, existingProduct.chartTemplate, - existingProduct.interestFreePeriodApplicable, existingProduct.interestFreeFromPeriod, existingProduct.interestFreeToPeriod, - existingProduct.interestFreePeriodFrequencyType, existingProduct.preClosurePenalApplicable, - existingProduct.preClosurePenalInterest, existingProduct.preClosurePenalInterestOnType, - existingProduct.interestFreePeriodTypeOptions, existingProduct.preClosurePenalInterestOnTypeOptions, + existingProduct.preClosurePenalApplicable, existingProduct.preClosurePenalInterest, + existingProduct.preClosurePenalInterestOnType, existingProduct.preClosurePenalInterestOnTypeOptions, existingProduct.minDepositTerm, existingProduct.maxDepositTerm, existingProduct.minDepositTermType, existingProduct.maxDepositTermType, existingProduct.inMultiplesOfDepositTerm, existingProduct.inMultiplesOfDepositTermType, - existingProduct.recurringDepositType, existingProduct.recurringDepositFrequency, - existingProduct.recurringDepositFrequencyType, existingProduct.recurringDepositTypeOptions, - existingProduct.recurringDepositFrequencyTypeOptions, existingProduct.depositTermTypeOptions, - existingProduct.inMultiplesOfDepositTermTypeOptions, existingProduct.minDepositAmount, - existingProduct.depositAmount, existingProduct.maxDepositAmount); + existingProduct.isMandatoryDeposit, existingProduct.allowWithdrawal, existingProduct.adjustAdvanceTowardsFuturePayments, + existingProduct.periodFrequencyTypeOptions, existingProduct.minDepositAmount, existingProduct.depositAmount, + existingProduct.maxDepositAmount); } public static RecurringDepositProductData instance(final DepositProductData depositProductData, - final boolean interestFreePeriodApplicable, final Integer interestFreeFromPeriod, final Integer interestFreeToPeriod, - final EnumOptionData interestFreePeriodFrequencyType, final boolean preClosurePenalApplicable, - final BigDecimal preClosurePenalInterest, final EnumOptionData preClosurePenalInterestOnType, final Integer minDepositTerm, - final Integer maxDepositTerm, final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, - final Integer inMultiplesOfDepositTerm, final EnumOptionData inMultiplesOfDepositTermType, - final EnumOptionData recurringDepositType, final Integer recurringDepositFrequency, - final EnumOptionData recurringDepositFrequencyType, - final BigDecimal minDepositAmount,final BigDecimal depositAmount, + final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, + final EnumOptionData preClosurePenalInterestOnType, final Integer minDepositTerm, final Integer maxDepositTerm, + final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, final Integer inMultiplesOfDepositTerm, + final EnumOptionData inMultiplesOfDepositTermType, final boolean isMandatoryDeposit, boolean allowWithdrawal, + boolean adjustAdvanceTowardsFuturePayments, final BigDecimal minDepositAmount, final BigDecimal depositAmount, final BigDecimal maxDepositAmount) { final Map accountingMappings = null; @@ -260,12 +226,8 @@ public class RecurringDepositProductData extends DepositProductData { final Collection penaltyToIncomeAccountMappings = null; final Collection interestRateCharts = null; final InterestRateChartData chartTemplate = null; - final Collection interestFreePeriodTypes = null; final Collection preClosurePenalInterestOnTypeOptions = null; - final Collection recurringDepositTypeOptions = null; - final Collection recurringDepositFrequencyTypeOptions = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; + final Collection periodFrequencyTypeOptions = null; return new RecurringDepositProductData(depositProductData.id, depositProductData.name, depositProductData.shortName, depositProductData.description, depositProductData.currency, depositProductData.nominalAnnualInterestRate, @@ -276,13 +238,10 @@ public class RecurringDepositProductData extends DepositProductData { interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, charges, chargeOptions, penaltyOptions, feeToIncomeAccountMappings, - penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, - preClosurePenalInterestOnType, interestFreePeriodTypes, preClosurePenalInterestOnTypeOptions, minDepositTerm, - maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, - recurringDepositType, recurringDepositFrequency, recurringDepositFrequencyType, recurringDepositTypeOptions, - recurringDepositFrequencyTypeOptions, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - minDepositAmount, depositAmount, maxDepositAmount); + penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, preClosurePenalApplicable, preClosurePenalInterest, + preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, + maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, isMandatoryDeposit, allowWithdrawal, + adjustAdvanceTowardsFuturePayments, periodFrequencyTypeOptions, minDepositAmount, depositAmount, maxDepositAmount); } public static RecurringDepositProductData lookup(final Long id, final String name) { @@ -320,28 +279,20 @@ public class RecurringDepositProductData extends DepositProductData { final Collection penaltyToIncomeAccountMappings = null; final Collection interestRateCharts = null; final InterestRateChartData chartTemplate = null; - final boolean interestFreePeriodApplicable = false; - final Integer interestFreeFromPeriod = null; - final Integer interestFreeToPeriod = null; - final EnumOptionData interestFreePeriodFrequencyType = null; final boolean preClosurePenalApplicable = false; final BigDecimal preClosurePenalInterest = null; final EnumOptionData preClosurePenalInterestOnType = null; - final Collection interestFreePeriodTypes = null; final Collection preClosurePenalInterestOnTypeOptions = null; - final EnumOptionData recurringDepositType = null; - final Integer recurringDepositFrequency = null; - final EnumOptionData recurringDepositFrequencyType = null; - final Collection recurringDepositTypeOptions = null; - final Collection recurringDepositFrequencyTypeOptions = null; + final boolean isMandatoryDeposit = false; + final boolean allowWithdrawal = false; + final boolean adjustAdvanceTowardsFuturePayments = false; final Integer minDepositTerm = null; final Integer maxDepositTerm = null; final EnumOptionData minDepositTermType = null; final EnumOptionData maxDepositTermType = null; final Integer inMultiplesOfDepositTerm = null; final EnumOptionData inMultiplesOfDepositTermType = null; - final Collection depositTermTypeOptions = null; - final Collection inMultiplesOfDepositTermTypeOptions = null; + final Collection periodFrequencyTypeOptions = null; final BigDecimal minDepositAmount = null; final BigDecimal depositAmount = null; final BigDecimal maxDepositAmount = null; @@ -352,13 +303,10 @@ public class RecurringDepositProductData extends DepositProductData { currencyOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, withdrawalFeeTypeOptions, paymentTypeOptions, accountingRuleOptions, accountingMappingOptions, charges, chargeOptions, penaltyOptions, feeToIncomeAccountMappings, - penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, - preClosurePenalInterestOnType, interestFreePeriodTypes, preClosurePenalInterestOnTypeOptions, minDepositTerm, - maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, - recurringDepositType, recurringDepositFrequency, recurringDepositFrequencyType, recurringDepositTypeOptions, - recurringDepositFrequencyTypeOptions, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - minDepositAmount, depositAmount, maxDepositAmount); + penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate, preClosurePenalApplicable, preClosurePenalInterest, + preClosurePenalInterestOnType, preClosurePenalInterestOnTypeOptions, minDepositTerm, maxDepositTerm, minDepositTermType, + maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, isMandatoryDeposit, allowWithdrawal, + adjustAdvanceTowardsFuturePayments, periodFrequencyTypeOptions, minDepositAmount, depositAmount, maxDepositAmount); } public static RecurringDepositProductData withInterestChart(final RecurringDepositProductData product, @@ -373,14 +321,12 @@ public class RecurringDepositProductData extends DepositProductData { product.withdrawalFeeTypeOptions, product.paymentTypeOptions, product.accountingRuleOptions, product.accountingMappingOptions, product.charges, product.chargeOptions, product.penaltyOptions, product.feeToIncomeAccountMappings, product.penaltyToIncomeAccountMappings, interestRateCharts, product.chartTemplate, - product.interestFreePeriodApplicable, product.interestFreeFromPeriod, product.interestFreeToPeriod, - product.interestFreePeriodFrequencyType, product.preClosurePenalApplicable, product.preClosurePenalInterest, - product.preClosurePenalInterestOnType, product.interestFreePeriodTypeOptions, product.preClosurePenalInterestOnTypeOptions, - product.minDepositTerm, product.maxDepositTerm, product.minDepositTermType, product.maxDepositTermType, - product.inMultiplesOfDepositTerm, product.inMultiplesOfDepositTermType, product.recurringDepositType, - product.recurringDepositFrequency, product.recurringDepositFrequencyType, product.recurringDepositTypeOptions, - product.recurringDepositFrequencyTypeOptions, product.depositTermTypeOptions, product.inMultiplesOfDepositTermTypeOptions, product.minDepositAmount, - product.depositAmount, product.maxDepositAmount); + product.preClosurePenalApplicable, product.preClosurePenalInterest, product.preClosurePenalInterestOnType, + product.preClosurePenalInterestOnTypeOptions, product.minDepositTerm, product.maxDepositTerm, product.minDepositTermType, + product.maxDepositTermType, product.inMultiplesOfDepositTerm, product.inMultiplesOfDepositTermType, + product.isMandatoryDeposit, product.allowWithdrawal, product.adjustAdvanceTowardsFuturePayments, + product.periodFrequencyTypeOptions, product.minDepositAmount, product.depositAmount, product.maxDepositAmount); + } private RecurringDepositProductData(final Long id, final String name, final String shortName, final String description, @@ -401,18 +347,13 @@ public class RecurringDepositProductData extends DepositProductData { final Collection feeToIncomeAccountMappings, final Collection penaltyToIncomeAccountMappings, final Collection interestRateCharts, final InterestRateChartData chartTemplate, - final boolean interestFreePeriodApplicable, final Integer interestFreeFromPeriod, final Integer interestFreeToPeriod, - final EnumOptionData interestFreePeriodFrequencyType, final boolean preClosurePenalApplicable, - final BigDecimal preClosurePenalInterest, final EnumOptionData preClosurePenalInterestOnType, - final Collection interestFreePeriodTypeOptions, - final Collection preClosurePenalInterestOnTypeOptions, final Integer minDepositTerm, - final Integer maxDepositTerm, final EnumOptionData minDepositTermType, final EnumOptionData maxDepositTermType, - final Integer inMultiplesOfDepositTerm, final EnumOptionData inMultiplesOfDepositTermType, - final EnumOptionData recurringDepositType, final Integer recurringDepositFrequency, - final EnumOptionData recurringDepositFrequencyType, final Collection recurringDepositTypeOptions, - final Collection recurringDepositFrequencyTypeOptions, final Collection depositTermTypeOptions, - final Collection inMultiplesOfDepositTermTypeOptions,final BigDecimal minDepositAmount, - final BigDecimal depositAmount, final BigDecimal maxDepositAmount) { + final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, + final EnumOptionData preClosurePenalInterestOnType, final Collection preClosurePenalInterestOnTypeOptions, + final Integer minDepositTerm, final Integer maxDepositTerm, final EnumOptionData minDepositTermType, + final EnumOptionData maxDepositTermType, final Integer inMultiplesOfDepositTerm, + final EnumOptionData inMultiplesOfDepositTermType, final boolean isMandatoryDeposit, boolean allowWithdrawal, + boolean adjustAdvanceTowardsFuturePayments, final Collection periodFrequencyTypeOptions, + final BigDecimal minDepositAmount, final BigDecimal depositAmount, final BigDecimal maxDepositAmount) { super(id, name, shortName, description, currency, nominalAnnualInterestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, lockinPeriodFrequency, @@ -422,10 +363,6 @@ public class RecurringDepositProductData extends DepositProductData { accountingRuleOptions, accountingMappingOptions, charges, chargeOptions, penaltyOptions, feeToIncomeAccountMappings, penaltyToIncomeAccountMappings, interestRateCharts, chartTemplate); - this.interestFreePeriodApplicable = interestFreePeriodApplicable; - this.interestFreeFromPeriod = interestFreeFromPeriod; - this.interestFreeToPeriod = interestFreeToPeriod; - this.interestFreePeriodFrequencyType = interestFreePeriodFrequencyType; this.preClosurePenalApplicable = preClosurePenalApplicable; this.preClosurePenalInterest = preClosurePenalInterest; this.preClosurePenalInterestOnType = preClosurePenalInterestOnType; @@ -435,21 +372,16 @@ public class RecurringDepositProductData extends DepositProductData { this.maxDepositTermType = maxDepositTermType; this.inMultiplesOfDepositTerm = inMultiplesOfDepositTerm; this.inMultiplesOfDepositTermType = inMultiplesOfDepositTermType; - this.recurringDepositFrequencyType = recurringDepositFrequencyType; - this.recurringDepositFrequency = recurringDepositFrequency; - this.recurringDepositType = recurringDepositType; this.minDepositAmount = minDepositAmount; this.depositAmount = depositAmount; this.maxDepositAmount = maxDepositAmount; + this.isMandatoryDeposit = isMandatoryDeposit; + this.allowWithdrawal = allowWithdrawal; + this.adjustAdvanceTowardsFuturePayments = adjustAdvanceTowardsFuturePayments; // template data - this.interestFreePeriodTypeOptions = interestFreePeriodTypeOptions; this.preClosurePenalInterestOnTypeOptions = preClosurePenalInterestOnTypeOptions; - this.recurringDepositTypeOptions = recurringDepositTypeOptions; - this.recurringDepositFrequencyTypeOptions = recurringDepositFrequencyTypeOptions; - this.depositTermTypeOptions = depositTermTypeOptions; - this.inMultiplesOfDepositTermTypeOptions = inMultiplesOfDepositTermTypeOptions; - + this.periodFrequencyTypeOptions = periodFrequencyTypeOptions; } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionDTO.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionDTO.java index f608c7dfa..66127a4fe 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionDTO.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsAccountTransactionDTO.java @@ -14,6 +14,7 @@ public class SavingsAccountTransactionDTO { private final BigDecimal transactionAmount; private final PaymentDetail paymentDetail; private final Date createdDate; + private final Long savingsAccountId; public SavingsAccountTransactionDTO(final DateTimeFormatter formatter, final LocalDate transactionDate, final BigDecimal transactionAmount, final PaymentDetail paymentDetail, final Date createdDate) { @@ -22,7 +23,28 @@ public class SavingsAccountTransactionDTO { this.transactionAmount = transactionAmount; this.paymentDetail = paymentDetail; this.createdDate = createdDate; + this.savingsAccountId = null; } + + /** This constructor is used for bulk deposit transactions + * @param formatter + * @param transactionDate + * @param transactionAmount + * @param paymentDetail + * @param createdDate + * @param savingsAccountId + */ + public SavingsAccountTransactionDTO(DateTimeFormatter formatter, LocalDate transactionDate, BigDecimal transactionAmount, + PaymentDetail paymentDetail, Date createdDate, Long savingsAccountId) { + this.formatter = formatter; + this.transactionDate = transactionDate; + this.transactionAmount = transactionAmount; + this.paymentDetail = paymentDetail; + this.createdDate = createdDate; + this.savingsAccountId = savingsAccountId; + } + + public DateTimeFormatter getFormatter() { return this.formatter; @@ -43,4 +65,9 @@ public class SavingsAccountTransactionDTO { public Date getCreatedDate() { return this.createdDate; } + + public Long getSavingsAccountId() { + return this.savingsAccountId; + } + } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductData.java index eee26ade8..f7e91ec4d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/data/SavingsProductData.java @@ -330,4 +330,15 @@ public class SavingsProductData { public int accountingRuleTypeId() { return this.accountingRule.getId().intValue(); } + + @Override + public boolean equals(final Object obj) { + final SavingsProductData productData = (SavingsProductData) obj; + return productData.id.compareTo(this.id) == 0; + } + + @Override + public int hashCode() { + return this.id.hashCode(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountAssembler.java index 67a4d27cb..0d3fe5bbb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountAssembler.java @@ -5,15 +5,20 @@ */ package org.mifosplatform.portfolio.savings.domain; +import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.bulkSavingsDueTransactionsParamName; +import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.savingsIdParamName; +import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.transactionAmountParamName; +import static org.mifosplatform.portfolio.collectionsheet.CollectionSheetConstants.transactionDateParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.adjustAdvanceTowardsFuturePaymentsParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.allowWithdrawalParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.chartIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositAmountParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositPeriodFrequencyIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositPeriodParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.expectedFirstDepositOnDateParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositAmountParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositFrequencyParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositFrequencyTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositTypeIdParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.isCalendarInheritedParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.isMandatoryDepositParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.mandatoryRecommendedDepositAmountParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.transferInterestToSavingsParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.accountNoParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.clientIdParamName; @@ -33,10 +38,19 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.submittedO import static org.mifosplatform.portfolio.savings.SavingsApiConstants.withdrawalFeeForTransfersParamName; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Locale; import java.util.Set; +import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; +import org.mifosplatform.infrastructure.configuration.domain.ConfigurationDomainService; import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; import org.mifosplatform.infrastructure.core.service.DateUtils; import org.mifosplatform.organisation.staff.domain.Staff; @@ -52,14 +66,15 @@ import org.mifosplatform.portfolio.group.exception.CenterNotActiveException; import org.mifosplatform.portfolio.group.exception.ClientNotInGroupException; import org.mifosplatform.portfolio.group.exception.GroupNotActiveException; import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChart; +import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail; import org.mifosplatform.portfolio.savings.DepositAccountOnClosureType; import org.mifosplatform.portfolio.savings.DepositAccountType; -import org.mifosplatform.portfolio.savings.RecurringDepositType; import org.mifosplatform.portfolio.savings.SavingsCompoundingInterestPeriodType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationDaysInYearType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationType; import org.mifosplatform.portfolio.savings.SavingsPeriodFrequencyType; import org.mifosplatform.portfolio.savings.SavingsPostingInterestPeriodType; +import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionDTO; import org.mifosplatform.portfolio.savings.exception.FixedDepositProductNotFoundException; import org.mifosplatform.portfolio.savings.exception.RecurringDepositProductNotFoundException; import org.mifosplatform.portfolio.savings.exception.SavingsProductNotFoundException; @@ -67,7 +82,9 @@ import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; +import com.google.gson.JsonObject; @Service public class DepositAccountAssembler { @@ -83,6 +100,7 @@ public class DepositAccountAssembler { private final SavingsAccountChargeAssembler savingsAccountChargeAssembler; private final FromJsonHelper fromApiJsonHelper; private final DepositProductAssembler depositProductAssembler; + private final ConfigurationDomainService configurationDomainService; @Autowired public DepositAccountAssembler(final SavingsAccountTransactionSummaryWrapper savingsAccountTransactionSummaryWrapper, @@ -92,7 +110,9 @@ public class DepositAccountAssembler { final SavingsAccountChargeAssembler savingsAccountChargeAssembler, final FromJsonHelper fromApiJsonHelper, final DepositProductAssembler depositProductAssembler, final RecurringDepositProductRepository recurringDepositProductRepository, - final AccountTransfersReadPlatformService accountTransfersReadPlatformService) { + final AccountTransfersReadPlatformService accountTransfersReadPlatformService, + final ConfigurationDomainService configurationDomainService) { + this.savingsAccountTransactionSummaryWrapper = savingsAccountTransactionSummaryWrapper; this.clientRepository = clientRepository; this.groupRepository = groupRepository; @@ -104,6 +124,7 @@ public class DepositAccountAssembler { this.depositProductAssembler = depositProductAssembler; this.recurringDepositProductRepository = recurringDepositProductRepository; this.savingsHelper = new SavingsHelper(accountTransfersReadPlatformService); + this.configurationDomainService = configurationDomainService; } /** @@ -246,7 +267,9 @@ public class DepositAccountAssembler { productChart = product.applicableChart(submittedOnDate); } - accountChart = DepositAccountInterestRateChart.from(productChart); + if (productChart != null) { + accountChart = DepositAccountInterestRateChart.from(productChart); + } SavingsAccount account = null; if (depositAccountType.isFixedDeposit()) { @@ -287,6 +310,7 @@ public class DepositAccountAssembler { if (account != null) { account.setHelpers(this.savingsAccountTransactionSummaryWrapper, this.savingsHelper); account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(), depositAccountType.resourceName()); + updateIncentiveAttributes(account.getClient(), account.accountSubmittedOrActivationDate()); } return account; @@ -295,10 +319,17 @@ public class DepositAccountAssembler { public SavingsAccount assembleFrom(final Long savingsId, DepositAccountType depositAccountType) { final SavingsAccount account = this.savingsAccountRepository.findOneWithNotFoundDetection(savingsId, depositAccountType); account.setHelpers(this.savingsAccountTransactionSummaryWrapper, this.savingsHelper); - + updateIncentiveAttributes(account.getClient(), account.accountSubmittedOrActivationDate()); return account; } + private void updateIncentiveAttributes(final Client client, final LocalDate compareOnDate) { + if (client == null) return; + final Long ageLimitForSeniorCitizen = this.configurationDomainService.ageLimitForSeniorCitizen(); + final Long ageLimitForChildren = this.configurationDomainService.ageLimitForChildren(); + client.updateIncentiveAttributes(ageLimitForChildren, ageLimitForSeniorCitizen, compareOnDate); + } + public void assignSavingAccountHelpers(final SavingsAccount savingsAccount) { savingsAccount.setHelpers(this.savingsAccountTransactionSummaryWrapper, this.savingsHelper); } @@ -334,44 +365,71 @@ public class DepositAccountAssembler { public DepositAccountRecurringDetail assembleAccountRecurringDetail(final JsonCommand command, final DepositRecurringDetail prodRecurringDetail) { - RecurringDepositType recurringDepositType = null; - Integer recurringDepositTypeValue = null; + final BigDecimal recurringDepositAmount = command.bigDecimalValueOfParameterNamed(mandatoryRecommendedDepositAmountParamName); + boolean isMandatoryDeposit; + boolean allowWithdrawal; + boolean adjustAdvanceTowardsFuturePayments; + boolean isCalendarInherited; - final BigDecimal recurringDepositAmount = command.bigDecimalValueOfParameterNamed(recurringDepositAmountParamName); - - if (command.parameterExists(recurringDepositTypeIdParamName)) { - recurringDepositTypeValue = command.integerValueOfParameterNamed(recurringDepositTypeIdParamName); + if (command.parameterExists(isMandatoryDepositParamName)) { + isMandatoryDeposit = command.booleanObjectValueOfParameterNamed(isMandatoryDepositParamName); } else { - recurringDepositTypeValue = prodRecurringDetail.recurringDepositType(); + isMandatoryDeposit = prodRecurringDetail.isMandatoryDeposit(); } - if (recurringDepositTypeValue != null) { - recurringDepositType = RecurringDepositType.fromInt(recurringDepositTypeValue); - } - - SavingsPeriodFrequencyType recurringDepositFrequencyType = null; - Integer recurringDepositFrequencyTypeValue = null; - if (command.parameterExists(recurringDepositFrequencyTypeIdParamName)) { - recurringDepositFrequencyTypeValue = command.integerValueOfParameterNamed(recurringDepositFrequencyTypeIdParamName); + if (command.parameterExists(allowWithdrawalParamName)) { + allowWithdrawal = command.booleanObjectValueOfParameterNamed(allowWithdrawalParamName); } else { - recurringDepositFrequencyTypeValue = prodRecurringDetail.recurringDepositFrequencyTypeId(); + allowWithdrawal = prodRecurringDetail.allowWithdrawal(); } - if (recurringDepositFrequencyTypeValue != null) { - recurringDepositFrequencyType = SavingsPeriodFrequencyType.fromInt(recurringDepositFrequencyTypeValue); - } - - Integer recurringDepositFrequency = null; - if (command.parameterExists(recurringDepositFrequencyTypeIdParamName)) { - recurringDepositFrequency = command.integerValueOfParameterNamed(recurringDepositFrequencyParamName); + if (command.parameterExists(adjustAdvanceTowardsFuturePaymentsParamName)) { + adjustAdvanceTowardsFuturePayments = command.booleanObjectValueOfParameterNamed(adjustAdvanceTowardsFuturePaymentsParamName); } else { - recurringDepositFrequency = prodRecurringDetail.recurringDepositFrequency(); + adjustAdvanceTowardsFuturePayments = prodRecurringDetail.adjustAdvanceTowardsFuturePayments(); } - final DepositRecurringDetail depositRecurringDetail = DepositRecurringDetail.createFrom(recurringDepositType, - recurringDepositFrequency, recurringDepositFrequencyType); + if (command.parameterExists(isCalendarInheritedParamName)) { + isCalendarInherited = command.booleanObjectValueOfParameterNamed(isCalendarInheritedParamName); + } else { + isCalendarInherited = false; + } + + final DepositRecurringDetail depositRecurringDetail = DepositRecurringDetail.createFrom(isMandatoryDeposit, allowWithdrawal, + adjustAdvanceTowardsFuturePayments); final DepositAccountRecurringDetail depositAccountRecurringDetail = DepositAccountRecurringDetail.createNew(recurringDepositAmount, - depositRecurringDetail, null); + depositRecurringDetail, null, isCalendarInherited); return depositAccountRecurringDetail; } + + public Collection assembleBulkMandatorySavingsAccountTransactionDTOs(final JsonCommand command){ + final String json = command.json(); + if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); } + final JsonElement element = this.fromApiJsonHelper.parse(json); + final Collection savingsAccountTransactions = new ArrayList(); + final PaymentDetail paymentDetail = null; + final LocalDate transactionDate = this.fromApiJsonHelper.extractLocalDateNamed(transactionDateParamName, element); + final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(element.getAsJsonObject()); + final JsonObject topLevelJsonElement = element.getAsJsonObject(); + final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement); + final DateTimeFormatter formatter = DateTimeFormat.forPattern(dateFormat).withLocale(locale); + + if (element.isJsonObject()) { + if (topLevelJsonElement.has(bulkSavingsDueTransactionsParamName) + && topLevelJsonElement.get(bulkSavingsDueTransactionsParamName).isJsonArray()) { + final JsonArray array = topLevelJsonElement.get(bulkSavingsDueTransactionsParamName).getAsJsonArray(); + + for (int i = 0; i < array.size(); i++) { + final JsonObject savingsTransactionElement = array.get(i).getAsJsonObject(); + final Long savingsId = this.fromApiJsonHelper.extractLongNamed(savingsIdParamName, savingsTransactionElement); + final BigDecimal dueAmount = this.fromApiJsonHelper.extractBigDecimalNamed(transactionAmountParamName, + savingsTransactionElement, locale); + final SavingsAccountTransactionDTO savingsAccountTransactionDTO = new SavingsAccountTransactionDTO(formatter, transactionDate, dueAmount, paymentDetail, new Date(), savingsId); + savingsAccountTransactions.add(savingsAccountTransactionDTO); + } + } + } + + return savingsAccountTransactions; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainService.java index 10d09f734..7cd168e42 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainService.java @@ -19,12 +19,21 @@ public interface DepositAccountDomainService { SavingsAccountTransaction handleWithdrawal(SavingsAccount account, DateTimeFormatter fmt, LocalDate transactionDate, BigDecimal transactionAmount, PaymentDetail paymentDetail, boolean applyWithdrawFee); - SavingsAccountTransaction handleDeposit(SavingsAccount account, DateTimeFormatter fmt, LocalDate transactionDate, + SavingsAccountTransaction handleFDDeposit(FixedDepositAccount account, DateTimeFormatter fmt, LocalDate transactionDate, + BigDecimal transactionAmount, PaymentDetail paymentDetail); + + SavingsAccountTransaction handleRDDeposit(RecurringDepositAccount account, DateTimeFormatter fmt, LocalDate transactionDate, BigDecimal transactionAmount, PaymentDetail paymentDetail); - SavingsAccountTransaction handleAccountClosure(SavingsAccount account, PaymentDetail paymentDetail, AppUser user, JsonCommand command, + Long handleFDAccountClosure(FixedDepositAccount account, PaymentDetail paymentDetail, AppUser user, JsonCommand command, LocalDate tenantsTodayDate, Map changes); - SavingsAccountTransaction handleAccountPreMatureClosure(SavingsAccount account, PaymentDetail paymentDetail, AppUser user, JsonCommand command, + Long handleRDAccountClosure(RecurringDepositAccount account, PaymentDetail paymentDetail, AppUser user, JsonCommand command, + LocalDate tenantsTodayDate, Map changes); + + Long handleFDAccountPreMatureClosure(FixedDepositAccount account, PaymentDetail paymentDetail, AppUser user, JsonCommand command, + LocalDate tenantsTodayDate, Map changes); + + Long handleRDAccountPreMatureClosure(RecurringDepositAccount account, PaymentDetail paymentDetail, AppUser user, JsonCommand command, LocalDate tenantsTodayDate, Map changes); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainServiceJpa.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainServiceJpa.java index d829da2f1..cd84ad79e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainServiceJpa.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountDomainServiceJpa.java @@ -26,14 +26,15 @@ import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency; import org.mifosplatform.organisation.monetary.domain.ApplicationCurrencyRepositoryWrapper; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; import org.mifosplatform.organisation.monetary.domain.Money; -import org.mifosplatform.portfolio.account.domain.AccountTransferDetailRepository; -import org.mifosplatform.portfolio.account.domain.AccountTransferDetails; -import org.mifosplatform.portfolio.account.domain.AccountTransferTransaction; +import org.mifosplatform.portfolio.account.PortfolioAccountType; +import org.mifosplatform.portfolio.account.data.AccountTransferDTO; import org.mifosplatform.portfolio.account.domain.AccountTransferType; +import org.mifosplatform.portfolio.account.service.AccountTransfersWritePlatformService; import org.mifosplatform.portfolio.client.domain.AccountNumberGenerator; import org.mifosplatform.portfolio.client.domain.AccountNumberGeneratorFactory; import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail; import org.mifosplatform.portfolio.savings.DepositAccountType; +import org.mifosplatform.portfolio.savings.SavingsApiConstants; import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionDTO; import org.mifosplatform.useradministration.domain.AppUser; import org.springframework.beans.factory.annotation.Autowired; @@ -48,26 +49,26 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi private final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepositoryWrapper; private final JournalEntryWritePlatformService journalEntryWritePlatformService; private final AccountNumberGeneratorFactory accountIdentifierGeneratorFactory; - private final AccountTransferDetailRepository accountTransferDetailRepository; private final DepositAccountAssembler depositAccountAssembler; private final SavingsAccountDomainService savingsAccountDomainService; + private final AccountTransfersWritePlatformService accountTransfersWritePlatformService; @Autowired public DepositAccountDomainServiceJpa(final SavingsAccountRepositoryWrapper savingsAccountRepository, final SavingsAccountTransactionRepository savingsAccountTransactionRepository, final ApplicationCurrencyRepositoryWrapper applicationCurrencyRepositoryWrapper, final JournalEntryWritePlatformService journalEntryWritePlatformService, - final AccountNumberGeneratorFactory accountIdentifierGeneratorFactory, - final AccountTransferDetailRepository accountTransferDetailRepository, final DepositAccountAssembler depositAccountAssembler, - final SavingsAccountDomainService savingsAccountDomainService) { + final AccountNumberGeneratorFactory accountIdentifierGeneratorFactory, final DepositAccountAssembler depositAccountAssembler, + final SavingsAccountDomainService savingsAccountDomainService, + final AccountTransfersWritePlatformService accountTransfersWritePlatformService) { this.savingsAccountRepository = savingsAccountRepository; this.savingsAccountTransactionRepository = savingsAccountTransactionRepository; this.applicationCurrencyRepositoryWrapper = applicationCurrencyRepositoryWrapper; this.journalEntryWritePlatformService = journalEntryWritePlatformService; this.accountIdentifierGeneratorFactory = accountIdentifierGeneratorFactory; - this.accountTransferDetailRepository = accountTransferDetailRepository; this.depositAccountAssembler = depositAccountAssembler; this.savingsAccountDomainService = savingsAccountDomainService; + this.accountTransfersWritePlatformService = accountTransfersWritePlatformService; } @Transactional @@ -102,12 +103,36 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi @Transactional @Override - public SavingsAccountTransaction handleDeposit(final SavingsAccount account, final DateTimeFormatter fmt, + public SavingsAccountTransaction handleFDDeposit(final FixedDepositAccount account, final DateTimeFormatter fmt, final LocalDate transactionDate, final BigDecimal transactionAmount, final PaymentDetail paymentDetail) { + return this.savingsAccountDomainService.handleDeposit(account, fmt, transactionDate, transactionAmount, paymentDetail); + } + + @Transactional + @Override + public SavingsAccountTransaction handleRDDeposit(final RecurringDepositAccount account, final DateTimeFormatter fmt, + final LocalDate transactionDate, final BigDecimal transactionAmount, final PaymentDetail paymentDetail) { + + final MathContext mc = MathContext.DECIMAL64; + final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(account, fmt, transactionDate, + transactionAmount, paymentDetail); + + account.handleScheduleInstallments(deposit); + account.updateMaturityDateAndAmount(mc); + account.updateOverduePayments(DateUtils.getLocalDateOfTenant()); + return deposit; + } + + @Transactional + @Override + public Long handleFDAccountClosure(final FixedDepositAccount account, final PaymentDetail paymentDetail, final AppUser user, + final JsonCommand command, final LocalDate tenantsTodayDate, final Map changes) { + final Set existingTransactionIds = new HashSet(); final Set existingReversedTransactionIds = new HashSet(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); +/*<<<<<<< HEAD final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, transactionDate, transactionAmount, paymentDetail, new Date()); final SavingsAccountTransaction deposit = account.deposit(transactionDTO); @@ -119,108 +144,107 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi } else { final LocalDate today = DateUtils.getLocalDateOfTenant(); account.calculateInterestUsing(mc, today, isInterestTransfer); +======= +*/ + final MathContext mc = MathContext.DECIMAL64; + final Locale locale = command.extractLocale(); + final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); + final LocalDate closedDate = command.localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName); + Long savingsTransactionId = null; + account.postMaturityInterest(); + if (account.isReinvestOnClosure()) { + FixedDepositAccount reinvestedDeposit = account.reInvest(account.getAccountBalance()); + this.depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit); + reinvestedDeposit.updateMaturityDateAndAmountBeforeAccountActivation(mc); + this.savingsAccountRepository.save(reinvestedDeposit); + autoGenerateAccountNumber(reinvestedDeposit); + final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, account.getAccountBalance(), + paymentDetail, false); + savingsTransactionId = withdrawal.getId(); + } else if (account.isTransferToSavingsOnClosure()) { + final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName); + final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName); + final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId, + DepositAccountType.SAVINGS_DEPOSIT); + + final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(closedDate, account.getAccountBalance(), + PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, null, null, transferDescription, locale, fmt, null, null, + null, null, null, AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, toSavingsAccount, account); + this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); + } else { + final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, account.getAccountBalance(), + paymentDetail, false); + savingsTransactionId = withdrawal.getId(); } - - saveTransactionToGenerateTransactionId(deposit); - + + account.close(user, command, tenantsTodayDate, changes); this.savingsAccountRepository.save(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); - return deposit; + return savingsTransactionId; } @Transactional @Override - public SavingsAccountTransaction handleAccountClosure(final SavingsAccount account, final PaymentDetail paymentDetail, - final AppUser user, final JsonCommand command, final LocalDate tenantsTodayDate, final Map changes) { + public Long handleRDAccountClosure(final RecurringDepositAccount account, final PaymentDetail paymentDetail, final AppUser user, + final JsonCommand command, final LocalDate tenantsTodayDate, final Map changes) { final Set existingTransactionIds = new HashSet(); final Set existingReversedTransactionIds = new HashSet(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); - final DepositAccountType depositAccountType = account.depositAccountType(); - SavingsAccountTransaction withdrawal = null; final MathContext mc = MathContext.DECIMAL64; - if (depositAccountType.isFixedDeposit()) { - final FixedDepositAccount fdAccount = (FixedDepositAccount) account; - withdrawal = fdAccount.close(user, command, tenantsTodayDate, paymentDetail, changes); - final Money transactionAmount = withdrawal.getAmount(fdAccount.getCurrency()); - final LocalDate transactionDate = withdrawal.transactionLocalDate(); - if (fdAccount.isReinvestOnClosure()) { - FixedDepositAccount reinvestedDeposit = fdAccount.reInvest(transactionAmount); - fdAccount.updateMaturityDateAndAmountBeforeAccountActivation(mc); - this.savingsAccountRepository.save(reinvestedDeposit); - autoGenerateAccountNumber(reinvestedDeposit); - } else if (fdAccount.isTransferToSavingsOnClosure()) { - final Locale locale = command.extractLocale(); - final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); - final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName); - final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName); - final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId, - DepositAccountType.SAVINGS_DEPOSIT); - final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, - withdrawal.transactionLocalDate(), transactionAmount.getAmount(), null); + final Locale locale = command.extractLocale(); + final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); + final LocalDate closedDate = command.localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName); + Long savingsTransactionId = null; + account.postMaturityInterest(); + final BigDecimal transactionAmount = account.getAccountBalance(); + if (account.isReinvestOnClosure()) { + RecurringDepositAccount reinvestedDeposit = account.reInvest(transactionAmount); + depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit); + reinvestedDeposit.updateMaturityDateAndAmount(mc); + reinvestedDeposit.processAccountUponActivation(fmt); + reinvestedDeposit.updateMaturityDateAndAmount(mc); + this.savingsAccountRepository.save(reinvestedDeposit); - final AccountTransferDetails accountTransferDetails = AccountTransferDetails.savingsToSavingsTransfer(fdAccount.office(), - fdAccount.getClient(), fdAccount, toSavingsAccount.office(), toSavingsAccount.getClient(), toSavingsAccount, - AccountTransferType.ACCOUNT_TRANSFER.getValue()); - AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.savingsToSavingsTransfer( - accountTransferDetails, withdrawal, deposit, transactionDate, transactionAmount, transferDescription); - - accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction); - - this.accountTransferDetailRepository.save(accountTransferDetails); + Money amountForDeposit = reinvestedDeposit.activateWithBalance(); + if (amountForDeposit.isGreaterThanZero()) { + handleRDDeposit(reinvestedDeposit, fmt, reinvestedDeposit.getActivationLocalDate(), amountForDeposit.getAmount(), + paymentDetail); } - } else if (depositAccountType.isRecurringDeposit()) { - final RecurringDepositAccount rdAccount = (RecurringDepositAccount) account; - withdrawal = rdAccount.close(user, command, tenantsTodayDate, paymentDetail, changes); - final Money transactionAmount = withdrawal.getAmount(rdAccount.getCurrency()); - final LocalDate transactionDate = withdrawal.transactionLocalDate(); - if (rdAccount.isReinvestOnClosure()) { - RecurringDepositAccount reinvestedDeposit = rdAccount.reInvest(transactionAmount); - depositAccountAssembler.assignSavingAccountHelpers(reinvestedDeposit); - final Locale locale = command.extractLocale(); - final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); - final LocalDate transactionStartDate = reinvestedDeposit.getActivationLocalDate(); - final LocalDate nextTransactionStartDate = reinvestedDeposit.nextDepositDate(transactionStartDate); - reinvestedDeposit.updateMaturityDateAndAmount(mc, nextTransactionStartDate); - this.savingsAccountRepository.save(reinvestedDeposit); - Money amountForDeposit = reinvestedDeposit.activateWithBalance(); - if (amountForDeposit.isGreaterThanZero()) { - handleDeposit(reinvestedDeposit, fmt, reinvestedDeposit.getActivationLocalDate(), amountForDeposit.getAmount(), null); - } - reinvestedDeposit.updateMaturityDateAndAmount(mc, nextTransactionStartDate); + reinvestedDeposit.updateMaturityDateAndAmount(mc); + this.savingsAccountRepository.save(reinvestedDeposit); + autoGenerateAccountNumber(reinvestedDeposit); - this.savingsAccountRepository.save(reinvestedDeposit); - autoGenerateAccountNumber(reinvestedDeposit); - } else if (rdAccount.isTransferToSavingsOnClosure()) { - final Locale locale = command.extractLocale(); - final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); - final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName); - final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName); - final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId, - DepositAccountType.SAVINGS_DEPOSIT); - final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, - withdrawal.transactionLocalDate(), transactionAmount.getAmount(), null); + final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, account.getAccountBalance(), + paymentDetail, false); + savingsTransactionId = withdrawal.getId(); - final AccountTransferDetails accountTransferDetails = AccountTransferDetails.savingsToSavingsTransfer(rdAccount.office(), - rdAccount.getClient(), rdAccount, toSavingsAccount.office(), toSavingsAccount.getClient(), toSavingsAccount, - AccountTransferType.ACCOUNT_TRANSFER.getValue()); - AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.savingsToSavingsTransfer( - accountTransferDetails, withdrawal, deposit, transactionDate, transactionAmount, transferDescription); + } else if (account.isTransferToSavingsOnClosure()) { + final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName); + final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName); + final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId, + DepositAccountType.SAVINGS_DEPOSIT); - accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction); - - this.accountTransferDetailRepository.save(accountTransferDetails); - } + final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(closedDate, transactionAmount, + PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, null, null, transferDescription, locale, fmt, null, null, + null, null, null, AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, toSavingsAccount, account); + this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); + } else { + final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, account.getAccountBalance(), + paymentDetail, false); + savingsTransactionId = withdrawal.getId(); } + account.close(user, command, tenantsTodayDate, changes); + this.savingsAccountRepository.save(account); postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); - return withdrawal; + return savingsTransactionId; } private void autoGenerateAccountNumber(final SavingsAccount account) { @@ -234,75 +258,79 @@ public class DepositAccountDomainServiceJpa implements DepositAccountDomainServi @Transactional @Override - public SavingsAccountTransaction handleAccountPreMatureClosure(final SavingsAccount account, final PaymentDetail paymentDetail, + public Long handleFDAccountPreMatureClosure(final FixedDepositAccount account, final PaymentDetail paymentDetail, final AppUser user, + final JsonCommand command, final LocalDate tenantsTodayDate, final Map changes) { + + final Set existingTransactionIds = new HashSet(); + final Set existingReversedTransactionIds = new HashSet(); + updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); + + final LocalDate closedDate = command.localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName); + final Locale locale = command.extractLocale(); + final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); + Long savingsTransactionId = null; + // post interest + account.postPreMaturityInterest(closedDate); + + if (account.isTransferToSavingsOnClosure()) { + + final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName); + final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName); + final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId, + DepositAccountType.SAVINGS_DEPOSIT); + final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(closedDate, account.getAccountBalance(), + PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, null, null, transferDescription, locale, fmt, null, null, + null, null, null, AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, toSavingsAccount, account); + this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); + } else { + final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, account.getAccountBalance(), + paymentDetail, false); + savingsTransactionId = withdrawal.getId(); + } + + account.prematureClosure(user, command, tenantsTodayDate, changes); + + this.savingsAccountRepository.save(account); + + postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); + return savingsTransactionId; + } + + @Transactional + @Override + public Long handleRDAccountPreMatureClosure(final RecurringDepositAccount account, final PaymentDetail paymentDetail, final AppUser user, final JsonCommand command, final LocalDate tenantsTodayDate, final Map changes) { final Set existingTransactionIds = new HashSet(); final Set existingReversedTransactionIds = new HashSet(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); - final DepositAccountType depositAccountType = account.depositAccountType(); - SavingsAccountTransaction withdrawal = null; - if (depositAccountType.isFixedDeposit()) { - final FixedDepositAccount fdAccount = (FixedDepositAccount) account; - withdrawal = fdAccount.prematureClosure(user, command, tenantsTodayDate, paymentDetail, changes); - final Money transactionAmount = withdrawal.getAmount(fdAccount.getCurrency()); - final LocalDate transactionDate = withdrawal.transactionLocalDate(); - if (fdAccount.isTransferToSavingsOnClosure()) { - final Locale locale = command.extractLocale(); - final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); - final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName); - final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName); - final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId, - DepositAccountType.SAVINGS_DEPOSIT); - final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, - withdrawal.transactionLocalDate(), transactionAmount.getAmount(), null); + final LocalDate closedDate = command.localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName); + final Locale locale = command.extractLocale(); + final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); + Long savingsTransactionId = null; + // post interest + account.postPreMaturityInterest(closedDate); - final AccountTransferDetails accountTransferDetails = AccountTransferDetails.savingsToSavingsTransfer(fdAccount.office(), - fdAccount.getClient(), fdAccount, toSavingsAccount.office(), toSavingsAccount.getClient(), toSavingsAccount, - AccountTransferType.ACCOUNT_TRANSFER.getValue()); - AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.savingsToSavingsTransfer( - accountTransferDetails, withdrawal, deposit, transactionDate, transactionAmount, transferDescription); - - accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction); - - this.accountTransferDetailRepository.save(accountTransferDetails); - } - } else if (depositAccountType.isRecurringDeposit()) { - final RecurringDepositAccount rdAccount = (RecurringDepositAccount) account; - withdrawal = rdAccount.prematureClosure(user, command, tenantsTodayDate, paymentDetail, changes); - final Money transactionAmount = withdrawal.getAmount(rdAccount.getCurrency()); - final LocalDate transactionDate = withdrawal.transactionLocalDate(); - if (rdAccount.isTransferToSavingsOnClosure()) { - final Locale locale = command.extractLocale(); - final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); - final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName); - final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName); - final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId, - DepositAccountType.SAVINGS_DEPOSIT); - final SavingsAccountTransaction deposit = this.savingsAccountDomainService.handleDeposit(toSavingsAccount, fmt, - transactionDate, transactionAmount.getAmount(), null); - - final AccountTransferDetails accountTransferDetails = AccountTransferDetails.savingsToSavingsTransfer(rdAccount.office(), - rdAccount.getClient(), rdAccount, toSavingsAccount.office(), toSavingsAccount.getClient(), toSavingsAccount, - AccountTransferType.ACCOUNT_TRANSFER.getValue()); - AccountTransferTransaction accountTransferTransaction = AccountTransferTransaction.savingsToSavingsTransfer( - accountTransferDetails, withdrawal, deposit, transactionDate, transactionAmount, transferDescription); - - accountTransferDetails.addAccountTransferTransaction(accountTransferTransaction); - - this.accountTransferDetailRepository.save(accountTransferDetails); - } - } - if (withdrawal != null) { - saveTransactionToGenerateTransactionId(withdrawal); + if (account.isTransferToSavingsOnClosure()) { + final Long toSavingsId = command.longValueOfParameterNamed(toSavingsAccountIdParamName); + final String transferDescription = command.stringValueOfParameterNamed(transferDescriptionParamName); + final SavingsAccount toSavingsAccount = this.depositAccountAssembler.assembleFrom(toSavingsId, + DepositAccountType.SAVINGS_DEPOSIT); + final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(closedDate, account.getAccountBalance(), + PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, null, null, transferDescription, locale, fmt, null, null, + null, null, null, AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, toSavingsAccount, account); + this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); + } else { + final SavingsAccountTransaction withdrawal = this.handleWithdrawal(account, fmt, closedDate, account.getAccountBalance(), + paymentDetail, false); + savingsTransactionId = withdrawal.getId(); } + account.prematureClosure(user, command, tenantsTodayDate, changes); this.savingsAccountRepository.save(account); - postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); - - return withdrawal; + return savingsTransactionId; } private Long saveTransactionToGenerateTransactionId(final SavingsAccountTransaction transaction) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountInterestRateChart.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountInterestRateChart.java index 42634af43..c6ad48b89 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountInterestRateChart.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountInterestRateChart.java @@ -20,6 +20,7 @@ import javax.persistence.Table; import org.hibernate.annotations.LazyCollection; import org.hibernate.annotations.LazyCollectionOption; import org.joda.time.LocalDate; +import org.mifosplatform.portfolio.interestratechart.data.ClientIncentiveAttributes; import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChart; import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChartFields; import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChartSlab; @@ -50,8 +51,9 @@ public class DepositAccountInterestRateChart extends AbstractPersistable { for (InterestRateChartSlab interestRateChartSlab : chartSlabs) { depostiChartSlabs.add(DepositAccountInterestRateChartSlabs.from(interestRateChartSlab.slabFields(), null)); } - final DepositAccountInterestRateChart depositChart = new DepositAccountInterestRateChart(productChart.chartFields(), null, depostiChartSlabs); - //update deposit account interest rate chart ference to chart Slabs + final DepositAccountInterestRateChart depositChart = new DepositAccountInterestRateChart(productChart.chartFields(), null, + depostiChartSlabs); + // update deposit account interest rate chart ference to chart Slabs depositChart.updateChartSlabsReference(); return depositChart; } @@ -63,13 +65,13 @@ public class DepositAccountInterestRateChart extends AbstractPersistable { this.chartSlabs = chartSlabs; } - private void updateChartSlabsReference(){ + private void updateChartSlabsReference() { final Set chartSlabs = setOfChartSlabs(); for (DepositAccountInterestRateChartSlabs chartSlab : chartSlabs) { chartSlab.updateChartReference(this); } } - + public Set setOfChartSlabs() { if (this.chartSlabs == null) { this.chartSlabs = new HashSet(); @@ -86,11 +88,6 @@ public class DepositAccountInterestRateChart extends AbstractPersistable { return null; } - /*private boolean removeChartSlab(DepositAccountInterestRateChartSlabs chartSlab) { - final Set chartSlabs = setOfChartSlabs(); - return chartSlabs.remove(chartSlab); - }*/ - public LocalDate getFromDateAsLocalDate() { return this.chartFields.getFromDateAsLocalDate(); } @@ -107,26 +104,43 @@ public class DepositAccountInterestRateChart extends AbstractPersistable { return this.account; } - /*private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } - }*/ - public InterestRateChartFields chartFields() { return this.chartFields; } - - public void updateDepositAccountReference(final SavingsAccount account){ + + public void updateDepositAccountReference(final SavingsAccount account) { this.account = account; } - - public BigDecimal getApplicableInterestRate(final BigDecimal depositAmount, final LocalDate periodStartDate, final LocalDate periodEndDate){ + + public BigDecimal getApplicableInterestRate(final BigDecimal depositAmount, + final LocalDate periodStartDate, final LocalDate periodEndDate, final ClientIncentiveAttributes incentiveAttributes) { BigDecimal effectiveInterestRate = BigDecimal.ZERO; for (DepositAccountInterestRateChartSlabs slab : setOfChartSlabs()) { - if(slab.slabFields().isBetweenPeriod(periodStartDate, periodEndDate) && slab.slabFields().isAmountBetween(depositAmount)){ - effectiveInterestRate = slab.slabFields().annualInterestRate(); + if (slab.slabFields().isBetweenPeriod(periodStartDate, periodEndDate) && slab.slabFields().isAmountBetween(depositAmount)) { + + if (incentiveAttributes == null) { + effectiveInterestRate = slab.slabFields().annualInterestRate(); + } else { + if (incentiveAttributes.isSeniorCitizen()) { + effectiveInterestRate = slab.slabFields().interestRateForSeniorCitizen(); + } + if (incentiveAttributes.isFemale()) { + + effectiveInterestRate = slab.slabFields().interestRateForFemale(); + } + if (incentiveAttributes.isChild()) { + effectiveInterestRate = slab.slabFields().interestRateForChildren(); + } + } + + // effectiveInterestRate is zero or null then reset to default + // interest rate. + if (effectiveInterestRate == null || effectiveInterestRate.compareTo(BigDecimal.ZERO) == 0) { + effectiveInterestRate = slab.slabFields().annualInterestRate(); + } } } - + return effectiveInterestRate; } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountRecurringDetail.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountRecurringDetail.java index ff02c61fc..bc3782217 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountRecurringDetail.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountRecurringDetail.java @@ -5,7 +5,7 @@ */ package org.mifosplatform.portfolio.savings.domain; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositAmountParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.mandatoryRecommendedDepositAmountParamName; import java.math.BigDecimal; import java.util.LinkedHashMap; @@ -19,48 +19,76 @@ import javax.persistence.OneToOne; import javax.persistence.Table; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.portfolio.savings.SavingsPeriodFrequencyType; +import org.mifosplatform.organisation.monetary.domain.Money; import org.springframework.data.jpa.domain.AbstractPersistable; @Entity @Table(name = "m_deposit_account_recurring_detail") public class DepositAccountRecurringDetail extends AbstractPersistable { - @Column(name = "recurring_deposit_amount", scale = 6, precision = 19, nullable = true) - private BigDecimal recurringDepositAmount; + @Column(name = "mandatory_recommended_deposit_amount", scale = 6, precision = 19, nullable = true) + private BigDecimal mandatoryRecommendedDepositAmount; + + @Column(name = "total_overdue_amount", scale = 6, precision = 19, nullable = true) + private BigDecimal totalOverdueAmount; + + @Column(name = "is_calendar_inherited", nullable = false) + private boolean isCalendarInherited; + @Column(name = "no_of_overdue_installments", nullable = false) + private Integer noOfOverdueInstallments; + @Embedded private DepositRecurringDetail recurringDetail; @OneToOne @JoinColumn(name = "savings_account_id", nullable = false) private SavingsAccount account; - - protected DepositAccountRecurringDetail() { - super(); + + /** + * + */ + public DepositAccountRecurringDetail() { + this.noOfOverdueInstallments = 0; + this.isCalendarInherited = false; } - public static DepositAccountRecurringDetail createNew(final BigDecimal recurringDepositAmount, DepositRecurringDetail recurringDetail, SavingsAccount account) { + - return new DepositAccountRecurringDetail(recurringDepositAmount, recurringDetail, account); + public static DepositAccountRecurringDetail createNew(final BigDecimal mandatoryRecommendedDepositAmount, + final DepositRecurringDetail recurringDetail, final SavingsAccount account, final boolean isCalendarInherited) { + final BigDecimal totalOverdueAmount = null; + final Integer noOfOverdueInstallments = null; + return new DepositAccountRecurringDetail(mandatoryRecommendedDepositAmount, totalOverdueAmount, noOfOverdueInstallments, + recurringDetail, account, isCalendarInherited); } - private DepositAccountRecurringDetail(final BigDecimal recurringDepositAmount, DepositRecurringDetail recurringDetail, SavingsAccount account) { - this.recurringDepositAmount = recurringDepositAmount; + /** + * @param mandatoryRecommendedDepositAmount + * @param totalOverdueAmount + * @param noOfOverdueInstallments + * @param recurringDetail + * @param account + */ + protected DepositAccountRecurringDetail(final BigDecimal mandatoryRecommendedDepositAmount, final BigDecimal totalOverdueAmount, + final Integer noOfOverdueInstallments, final DepositRecurringDetail recurringDetail, final SavingsAccount account, final boolean isCalendarInherited) { + this.mandatoryRecommendedDepositAmount = mandatoryRecommendedDepositAmount; + this.totalOverdueAmount = totalOverdueAmount; + this.noOfOverdueInstallments = noOfOverdueInstallments; this.recurringDetail = recurringDetail; this.account = account; + this.isCalendarInherited = isCalendarInherited; } - public Map update(final JsonCommand command, final DataValidatorBuilder baseDataValidator) { + public Map update(final JsonCommand command) { final Map actualChanges = new LinkedHashMap(10); - if (command.isChangeInBigDecimalParameterNamed(recurringDepositAmountParamName, this.recurringDepositAmount)) { - final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(recurringDepositAmountParamName); - actualChanges.put(recurringDepositAmountParamName, newValue); - this.recurringDepositAmount = newValue; + if (command.isChangeInBigDecimalParameterNamed(mandatoryRecommendedDepositAmountParamName, this.mandatoryRecommendedDepositAmount)) { + final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(mandatoryRecommendedDepositAmountParamName); + actualChanges.put(mandatoryRecommendedDepositAmountParamName, newValue); + this.mandatoryRecommendedDepositAmount = newValue; } if (this.recurringDetail != null) { - actualChanges.putAll(this.recurringDetail.update(command, baseDataValidator)); + actualChanges.putAll(this.recurringDetail.update(command)); } return actualChanges; } @@ -72,30 +100,36 @@ public class DepositAccountRecurringDetail extends AbstractPersistable { public void updateAccountReference(final SavingsAccount account) { this.account = account; } - - public Integer recurringDepositType() { - return this.recurringDetail().recurringDepositType(); + + public boolean isMandatoryDeposit() { + return this.recurringDetail.isMandatoryDeposit(); } - public Integer recurringDepositFrequency() { - return this.recurringDetail().recurringDepositFrequency(); + public boolean allowWithdrawal() { + return this.recurringDetail.allowWithdrawal(); } - public Integer recurringDepositFrequencyTypeId() { - return this.recurringDetail().recurringDepositFrequencyTypeId(); + public boolean adjustAdvanceTowardsFuturePayments() { + return this.recurringDetail.adjustAdvanceTowardsFuturePayments(); + } + + public BigDecimal mandatoryRecommendedDepositAmount() { + return this.mandatoryRecommendedDepositAmount; + } + + public boolean isCalendarInherited(){ + return this.isCalendarInherited; } - public SavingsPeriodFrequencyType recurringDepositFrequencyType() { - return SavingsPeriodFrequencyType.fromInt(this.recurringDepositFrequencyTypeId()); - } - - public BigDecimal recurringDepositAmount(){ - return this.recurringDepositAmount; - } - - public DepositAccountRecurringDetail copy(){ - final BigDecimal recurringDepositAmount = this.recurringDepositAmount; + public DepositAccountRecurringDetail copy() { + final BigDecimal mandatoryRecommendedDepositAmount = this.mandatoryRecommendedDepositAmount; final DepositRecurringDetail recurringDetail = this.recurringDetail.copy(); - return DepositAccountRecurringDetail.createNew(recurringDepositAmount, recurringDetail, account); + final boolean isCalendarInherited = this.isCalendarInherited; + return DepositAccountRecurringDetail.createNew(mandatoryRecommendedDepositAmount, recurringDetail, null, isCalendarInherited); + } + + public void updateOverdueDetails(final int noOfOverdueInstallments, final Money totalOverdueAmount){ + this.noOfOverdueInstallments = noOfOverdueInstallments; + this.totalOverdueAmount = totalOverdueAmount.getAmount(); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountTermAndPreClosure.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountTermAndPreClosure.java index eee1b0488..37455978f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountTermAndPreClosure.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositAccountTermAndPreClosure.java @@ -5,11 +5,13 @@ */ package org.mifosplatform.portfolio.savings.domain; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.dateFormatParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositAmountParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositPeriodFrequencyIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositPeriodParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.expectedFirstDepositOnDateParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.transferInterestToSavingsParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.localeParamName; import java.math.BigDecimal; import java.util.Date; @@ -32,9 +34,7 @@ import org.joda.time.Weeks; import org.joda.time.Years; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.organisation.monetary.domain.Money; import org.mifosplatform.portfolio.savings.DepositAccountOnClosureType; -import org.mifosplatform.portfolio.savings.SavingsApiConstants; import org.mifosplatform.portfolio.savings.SavingsPeriodFrequencyType; import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; import org.springframework.data.jpa.domain.AbstractPersistable; @@ -132,13 +132,12 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable { final String localeAsInput = command.locale(); final String dateFormat = command.dateFormat(); - - if (command.isChangeInLocalDateParameterNamed(expectedFirstDepositOnDateParamName, getExpectedFirstDepositOnDate())) { + if (command.isChangeInLocalDateParameterNamed(expectedFirstDepositOnDateParamName, this.getExpectedFirstDepositOnDate())) { final LocalDate newValue = command.localDateValueOfParameterNamed(expectedFirstDepositOnDateParamName); final String newValueAsString = command.stringValueOfParameterNamed(expectedFirstDepositOnDateParamName); actualChanges.put(expectedFirstDepositOnDateParamName, newValueAsString); - actualChanges.put(SavingsApiConstants.localeParamName, localeAsInput); - actualChanges.put(SavingsApiConstants.dateFormatParamName, dateFormat); + actualChanges.put(localeParamName, localeAsInput); + actualChanges.put(dateFormatParamName, dateFormat); this.expectedFirstDepositOnDate = newValue.toDate(); } @@ -263,10 +262,10 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable { return DepositAccountOnClosureType.fromInt(this.onAccountClosureType).isTransferToSavings(); } - public DepositAccountTermAndPreClosure deepCopy(Money depositAmount) { + public DepositAccountTermAndPreClosure copy(BigDecimal depositAmount) { final SavingsAccount account = null; final BigDecimal maturityAmount = null; - final BigDecimal actualDepositAmount = null; + final BigDecimal actualDepositAmount = depositAmount; final LocalDate maturityDate = null; final Integer depositPeriod = this.depositPeriod; final SavingsPeriodFrequencyType depositPeriodFrequency = SavingsPeriodFrequencyType.fromInt(this.depositPeriodFrequency); @@ -285,8 +284,15 @@ public class DepositAccountTermAndPreClosure extends AbstractPersistable { this.expectedFirstDepositOnDate = expectedFirstDepositOnDate.toDate(); } - public boolean isTransferInterestToLinkedAccount() { return this.transferInterestToLinkedAccount; } + + public boolean isAfterExpectedFirstDepositDate(final LocalDate compareDate) { + boolean isAfterExpectedFirstDepositDate = false; + if (this.expectedFirstDepositOnDate != null) { + isAfterExpectedFirstDepositDate = compareDate.isAfter(getExpectedFirstDepositOnDate()); + } + return isAfterExpectedFirstDepositDate; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositPreClosureDetail.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositPreClosureDetail.java index 6a077a05f..458b819df 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositPreClosureDetail.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositPreClosureDetail.java @@ -5,10 +5,6 @@ */ package org.mifosplatform.portfolio.savings.domain; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreeFromPeriodParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreePeriodApplicableParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreePeriodFrequencyTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreeToPeriodParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalApplicableParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalInterestOnTypeIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalInterestParamName; @@ -23,8 +19,6 @@ import javax.persistence.Embeddable; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.portfolio.interestratechart.InterestRateChartPeriodType; -import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartEnumerations; import org.mifosplatform.portfolio.savings.PreClosurePenalInterestOnType; import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; @@ -36,46 +30,27 @@ import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; @Embeddable public class DepositPreClosureDetail { - @Column(name = "interest_free_period_applicable") - private boolean interestFreePeriodApplicable; - @Column(name = "pre_closure_penal_applicable") private boolean preClosurePenalApplicable; - @Column(name = "interest_free_from_period", nullable = true) - private Integer interestFreeFromPeriod; - - @Column(name = "interest_free_to_period", nullable = true) - private Integer interestFreeToPeriod; - - @Column(name = "interest_free_period_frequency_enum", nullable = true) - private Integer interestFreePeriodFrequencyType; - @Column(name = "pre_closure_penal_interest", scale = 6, precision = 19, nullable = true) private BigDecimal preClosurePenalInterest; @Column(name = "pre_closure_penal_interest_on_enum", nullable = true) private Integer preClosurePenalInterestOnType; - public static DepositPreClosureDetail createFrom(final boolean interestFreePeriodApplicable, final Integer interestFreeFromPeriod, - final Integer interestFreeToPeriod, final InterestRateChartPeriodType periodType, final boolean preClosurePenalApplicable, - final BigDecimal preClosurePenalInterest, final PreClosurePenalInterestOnType preClosurePenalInterestType) { + public static DepositPreClosureDetail createFrom(final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, + final PreClosurePenalInterestOnType preClosurePenalInterestType) { - return new DepositPreClosureDetail(interestFreePeriodApplicable, interestFreeFromPeriod, interestFreeToPeriod, periodType, - preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestType); + return new DepositPreClosureDetail(preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestType); } protected DepositPreClosureDetail() { // } - private DepositPreClosureDetail(final boolean interestFreePeriodApplicable, final Integer interestFreeFromPeriod, - final Integer interestFreeToPeriod, final InterestRateChartPeriodType periodType, final boolean preClosurePenalApplicable, - final BigDecimal preClosurePenalInterest, final PreClosurePenalInterestOnType preClosurePenalInterestType) { - this.interestFreePeriodApplicable = interestFreePeriodApplicable; - this.interestFreeFromPeriod = interestFreeFromPeriod; - this.interestFreeToPeriod = interestFreeToPeriod; - this.interestFreePeriodFrequencyType = (periodType == null) ? null : periodType.getValue(); + private DepositPreClosureDetail(final boolean preClosurePenalApplicable, final BigDecimal preClosurePenalInterest, + final PreClosurePenalInterestOnType preClosurePenalInterestType) { this.preClosurePenalApplicable = preClosurePenalApplicable; this.preClosurePenalInterest = preClosurePenalInterest; this.preClosurePenalInterestOnType = (preClosurePenalInterestType == null) ? null : preClosurePenalInterestType.getValue(); @@ -86,52 +61,6 @@ public class DepositPreClosureDetail { final String localeAsInput = command.locale(); - if (command.isChangeInBooleanParameterNamed(interestFreePeriodApplicableParamName, this.interestFreePeriodApplicable)) { - final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(interestFreePeriodApplicableParamName); - actualChanges.put(interestFreePeriodApplicableParamName, newValue); - this.interestFreePeriodApplicable = newValue; - } - - if (this.interestFreePeriodApplicable) { - - if (command.isChangeInIntegerParameterNamed(interestFreeFromPeriodParamName, this.interestFreeFromPeriod)) { - final Integer newValue = command.integerValueOfParameterNamed(interestFreeFromPeriodParamName); - actualChanges.put(interestFreeFromPeriodParamName, newValue); - this.interestFreeFromPeriod = newValue; - } - - if (command.isChangeInIntegerParameterNamed(interestFreeToPeriodParamName, this.interestFreeToPeriod)) { - final Integer newValue = command.integerValueOfParameterNamed(interestFreeToPeriodParamName); - actualChanges.put(interestFreeToPeriodParamName, newValue); - this.interestFreeToPeriod = newValue; - } - - if (command.isChangeInIntegerParameterNamed(interestFreePeriodFrequencyTypeIdParamName, this.interestFreePeriodFrequencyType)) { - final Integer newValue = command.integerValueOfParameterNamed(interestFreePeriodFrequencyTypeIdParamName); - actualChanges.put(interestFreePeriodFrequencyTypeIdParamName, InterestRateChartEnumerations.periodType(newValue)); - this.interestFreePeriodFrequencyType = newValue; - } - - if (this.interestFreeFromPeriod == null) { - baseDataValidator.parameter(interestFreeFromPeriodParamName).value(this.interestFreeFromPeriod) - .cantBeBlankWhenParameterProvidedIs(interestFreePeriodApplicableParamName, this.interestFreePeriodApplicable); - } - - if (this.interestFreeToPeriod == null) { - baseDataValidator.parameter(interestFreeToPeriodParamName).value(this.interestFreeToPeriod) - .cantBeBlankWhenParameterProvidedIs(interestFreePeriodApplicableParamName, this.interestFreePeriodApplicable); - } - - if (this.interestFreePeriodFrequencyType == null) { - baseDataValidator.parameter(interestFreePeriodFrequencyTypeIdParamName).value(this.interestFreePeriodFrequencyType) - .cantBeBlankWhenParameterProvidedIs(interestFreePeriodApplicableParamName, this.interestFreePeriodApplicable); - } - } else { // reset if interest free period is not applicable - this.interestFreeFromPeriod = null; - this.interestFreeToPeriod = null; - this.interestFreePeriodFrequencyType = null; - } - if (command.isChangeInBooleanParameterNamed(preClosurePenalApplicableParamName, this.preClosurePenalApplicable)) { final boolean newValue = command.booleanPrimitiveValueOfParameterNamed(preClosurePenalApplicableParamName); actualChanges.put(preClosurePenalApplicableParamName, newValue); @@ -167,44 +96,13 @@ public class DepositPreClosureDetail { this.preClosurePenalInterestOnType = null; } - if (isFromPeriodAfterToPeriod()) { - baseDataValidator - .parameter(interestFreeFromPeriodParamName) - .value(this.interestFreeFromPeriod) - .failWithCode("interest.free.from.period.is.greater.than.to.period", this.interestFreeFromPeriod, - this.interestFreeToPeriod); - } - return actualChanges; } - private boolean isFromPeriodAfterToPeriod() { - if (this.interestFreePeriodApplicable && this.interestFreeFromPeriod != null && this.interestFreeToPeriod != null) { - if (this.interestFreeFromPeriod.compareTo(interestFreeToPeriod) > 0) { return true; } - } - return false; - } - - public boolean interestFreePeriodApplicable() { - return this.interestFreePeriodApplicable; - } - public boolean preClosurePenalApplicable() { return this.preClosurePenalApplicable; } - public Integer interestFreeFromPeriod() { - return this.interestFreeFromPeriod; - } - - public Integer interestFreeToPeriod() { - return this.interestFreeToPeriod; - } - - public Integer interestFreePeriodFrequencyType() { - return this.interestFreePeriodFrequencyType; - } - public BigDecimal preClosurePenalInterest() { return this.preClosurePenalInterest; } @@ -213,19 +111,16 @@ public class DepositPreClosureDetail { return this.preClosurePenalInterestOnType; } - public PreClosurePenalInterestOnType preClosurePenalInterestOnType(){ + public PreClosurePenalInterestOnType preClosurePenalInterestOnType() { return PreClosurePenalInterestOnType.fromInt(preClosurePenalInterestOnType); } - - public DepositPreClosureDetail copy(){ - final boolean interestFreePeriodApplicable = this.interestFreePeriodApplicable; - final Integer interestFreeFromPeriod = this.interestFreeFromPeriod; - final Integer interestFreeToPeriod = this.interestFreeToPeriod; + + public DepositPreClosureDetail copy() { final boolean preClosurePenalApplicable = this.preClosurePenalApplicable; final BigDecimal preClosurePenalInterest = this.preClosurePenalInterest; - final InterestRateChartPeriodType periodType = InterestRateChartPeriodType.fromInt(this.interestFreePeriodFrequencyType); - final PreClosurePenalInterestOnType preClosurePenalInterestType = PreClosurePenalInterestOnType.fromInt(this.preClosurePenalInterestOnType); - - return DepositPreClosureDetail.createFrom(interestFreePeriodApplicable, interestFreeFromPeriod, interestFreeToPeriod, periodType, preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestType); + final PreClosurePenalInterestOnType preClosurePenalInterestType = PreClosurePenalInterestOnType + .fromInt(this.preClosurePenalInterestOnType); + + return DepositPreClosureDetail.createFrom(preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestType); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductAmountDetails.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductAmountDetails.java index c66c41e74..b9794465a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductAmountDetails.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductAmountDetails.java @@ -13,7 +13,6 @@ import javax.persistence.Column; import javax.persistence.Embeddable; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; /** * RecurringDepositProductAmountDetails encapsulates all recurring Deposit @@ -47,7 +46,7 @@ public class DepositProductAmountDetails { this.maxDepositAmount = maxDepositAmount; } - public Map update(final JsonCommand command, final DataValidatorBuilder baseDataValidator) { + public Map update(final JsonCommand command) { final Map actualChanges = new LinkedHashMap(20); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductAssembler.java index 85dd33088..73d5c3d3a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductAssembler.java @@ -5,15 +5,15 @@ */ package org.mifosplatform.portfolio.savings.domain; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.FIXED_DEPOSIT_PRODUCT_RESOURCE_NAME; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.RECURRING_DEPOSIT_PRODUCT_RESOURCE_NAME; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.adjustAdvanceTowardsFuturePaymentsParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.allowWithdrawalParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.chartsParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositAmountParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositMaxAmountParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositMinAmountParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.inMultiplesOfDepositTermParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.inMultiplesOfDepositTermTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreeFromPeriodParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreePeriodApplicableParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreePeriodFrequencyTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.interestFreeToPeriodParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.isMandatoryDepositParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.maxDepositTermParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.maxDepositTermTypeIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.minDepositTermParamName; @@ -21,12 +21,6 @@ import static org.mifosplatform.portfolio.savings.DepositsApiConstants.minDeposi import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalApplicableParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalInterestOnTypeIdParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.preClosurePenalInterestParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositFrequencyParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositFrequencyTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositAmountParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositMinAmountParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.depositMaxAmountParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.chargesParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.currencyCodeParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.descriptionParamName; @@ -44,38 +38,31 @@ import static org.mifosplatform.portfolio.savings.SavingsApiConstants.nominalAnn import static org.mifosplatform.portfolio.savings.SavingsApiConstants.shortNameParamName; import java.math.BigDecimal; -import java.util.ArrayList; import java.util.HashSet; -import java.util.List; import java.util.Set; import org.mifosplatform.accounting.common.AccountingRuleType; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; import org.mifosplatform.portfolio.charge.domain.Charge; import org.mifosplatform.portfolio.charge.domain.ChargeRepositoryWrapper; import org.mifosplatform.portfolio.charge.exception.ChargeCannotBeAppliedToException; -import org.mifosplatform.portfolio.interestratechart.InterestRateChartPeriodType; import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChart; import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartAssembler; import org.mifosplatform.portfolio.loanproduct.exception.InvalidCurrencyException; import org.mifosplatform.portfolio.savings.PreClosurePenalInterestOnType; -import org.mifosplatform.portfolio.savings.RecurringDepositType; import org.mifosplatform.portfolio.savings.SavingsCompoundingInterestPeriodType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationDaysInYearType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationType; import org.mifosplatform.portfolio.savings.SavingsPeriodFrequencyType; import org.mifosplatform.portfolio.savings.SavingsPostingInterestPeriodType; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -@Component +@Service public class DepositProductAssembler { private final ChargeRepositoryWrapper chargeRepository; @@ -131,7 +118,7 @@ public class DepositProductAssembler { if (lockinPeriodFrequencyTypeValue != null) { lockinPeriodFrequencyType = SavingsPeriodFrequencyType.fromInt(lockinPeriodFrequencyTypeValue); } - + final AccountingRuleType accountingRuleType = AccountingRuleType.fromInt(command.integerValueOfParameterNamed("accountingRule")); final DepositPreClosureDetail preClosureDetail = this.assemblePreClosureDetail(command); @@ -154,27 +141,11 @@ public class DepositProductAssembler { // update product reference productTermAndPreClosure.updateProductReference(fixedDepositProduct); - validateFixedDepositProductDomainRules(fixedDepositProduct); + fixedDepositProduct.validateDomainRules(); return fixedDepositProduct; } - private void validateFixedDepositProductDomainRules(FixedDepositProduct fixedDepositProduct) { - final List dataValidationErrors = new ArrayList(); - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) - .resource(FIXED_DEPOSIT_PRODUCT_RESOURCE_NAME); - final DepositTermDetail termDetails = fixedDepositProduct.depositProductTermAndPreClosure().depositTermDetail(); - final boolean isMinTermGreaterThanMax = termDetails.isMinDepositTermGreaterThanMaxDepositTerm(); - if (isMinTermGreaterThanMax) { - final Integer maxTerm = termDetails.maxDepositTerm(); - baseDataValidator.reset().parameter(maxDepositTermParamName).value(maxTerm) - .failWithCodeNoParameterAddedToErrorCode("max.term.lessthan.min.term"); - } - fixedDepositProduct.validateCharts(baseDataValidator); - fixedDepositProduct.validateInterestPostingAndCompoundingPeriodTypes(baseDataValidator); - throwExceptionIfValidationWarningsExist(dataValidationErrors); - } - public RecurringDepositProduct assembleRecurringDepositProduct(final JsonCommand command) { final String name = command.stringValueOfParameterNamed(nameParamName); @@ -212,14 +183,14 @@ public class DepositProductAssembler { if (interestCalculationDaysInYearTypeValue != null) { interestCalculationDaysInYearType = SavingsInterestCalculationDaysInYearType.fromInt(interestCalculationDaysInYearTypeValue); } - + final Integer lockinPeriodFrequency = command.integerValueOfParameterNamedDefaultToNullIfZero(lockinPeriodFrequencyParamName); SavingsPeriodFrequencyType lockinPeriodFrequencyType = null; final Integer lockinPeriodFrequencyTypeValue = command.integerValueOfParameterNamed(lockinPeriodFrequencyTypeParamName); if (lockinPeriodFrequencyTypeValue != null) { lockinPeriodFrequencyType = SavingsPeriodFrequencyType.fromInt(lockinPeriodFrequencyTypeValue); } - + final AccountingRuleType accountingRuleType = AccountingRuleType.fromInt(command.integerValueOfParameterNamed("accountingRule")); final DepositPreClosureDetail preClosureDetail = this.assemblePreClosureDetail(command); @@ -248,46 +219,13 @@ public class DepositProductAssembler { productTermAndPreClosure.updateProductReference(recurringDepositProduct); productRecurringDetail.updateProductReference(recurringDepositProduct); - validateRecurringDepositProductDomainRules(recurringDepositProduct); - + recurringDepositProduct.validateDomainRules(); + return recurringDepositProduct; } - private void validateRecurringDepositProductDomainRules(RecurringDepositProduct recurringDepositProduct) { - final List dataValidationErrors = new ArrayList(); - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) - .resource(RECURRING_DEPOSIT_PRODUCT_RESOURCE_NAME); - final DepositTermDetail termDetails = recurringDepositProduct.depositProductTermAndPreClosure().depositTermDetail(); - final boolean isMinTermGreaterThanMax = termDetails.isMinDepositTermGreaterThanMaxDepositTerm(); - if (isMinTermGreaterThanMax) { - final Integer maxTerm = termDetails.maxDepositTerm(); - baseDataValidator.reset().parameter(maxDepositTermParamName).value(maxTerm) - .failWithCodeNoParameterAddedToErrorCode("max.term.lessthan.min.term"); - } - recurringDepositProduct.validateCharts(baseDataValidator); - recurringDepositProduct.validateInterestPostingAndCompoundingPeriodTypes(baseDataValidator); - - throwExceptionIfValidationWarningsExist(dataValidationErrors); - } - public DepositPreClosureDetail assemblePreClosureDetail(final JsonCommand command) { - boolean interestFreePeriodApplicable = false; - Integer interestFreeFromPeriod = null; - Integer interestFreeToPeriod = null; - InterestRateChartPeriodType interestFreePeriodFrequencyType = null; - - if (command.parameterExists(interestFreePeriodApplicableParamName)) { - interestFreePeriodApplicable = command.booleanObjectValueOfParameterNamed(interestFreePeriodApplicableParamName); - if (interestFreePeriodApplicable) { - interestFreeFromPeriod = command.integerValueOfParameterNamed(interestFreeFromPeriodParamName); - interestFreeToPeriod = command.integerValueOfParameterNamed(interestFreeToPeriodParamName); - final Integer interestFreePreriodTypeId = command.integerValueOfParameterNamed(interestFreePeriodFrequencyTypeIdParamName); - interestFreePeriodFrequencyType = (interestFreePreriodTypeId == null) ? null : InterestRateChartPeriodType - .fromInt(interestFreePreriodTypeId); - } - } - boolean preClosurePenalApplicable = false; BigDecimal preClosurePenalInterest = null; PreClosurePenalInterestOnType preClosurePenalInterestType = null; @@ -303,53 +241,13 @@ public class DepositProductAssembler { } } - DepositPreClosureDetail preClosureDetail = DepositPreClosureDetail.createFrom(interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, + DepositPreClosureDetail preClosureDetail = DepositPreClosureDetail.createFrom(preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestType); return preClosureDetail; } public DepositPreClosureDetail assemblePreClosureDetail(final JsonCommand command, DepositPreClosureDetail produPreClosureDetail) { - - boolean interestFreePeriodApplicable = false; - Integer interestFreeFromPeriod = null; - Integer interestFreeToPeriod = null; - InterestRateChartPeriodType interestFreePeriodFrequencyType = null; - Integer interestFreePreriodTypeId = null; - - if (command.parameterExists(interestFreePeriodApplicableParamName)) { - interestFreePeriodApplicable = command.booleanObjectValueOfParameterNamed(interestFreePeriodApplicableParamName); - if (interestFreePeriodApplicable) { - if (command.parameterExists(interestFreeFromPeriodParamName)) { - interestFreeFromPeriod = command.integerValueOfParameterNamed(interestFreeFromPeriodParamName); - } else { - interestFreeFromPeriod = produPreClosureDetail.interestFreeFromPeriod(); - } - - if (command.parameterExists(interestFreeToPeriodParamName)) { - interestFreeToPeriod = command.integerValueOfParameterNamed(interestFreeToPeriodParamName); - } else { - interestFreeToPeriod = produPreClosureDetail.interestFreeToPeriod(); - } - - if (command.parameterExists(interestFreePeriodFrequencyTypeIdParamName)) { - interestFreePreriodTypeId = command.integerValueOfParameterNamed(interestFreePeriodFrequencyTypeIdParamName); - } else { - interestFreePreriodTypeId = produPreClosureDetail.interestFreePeriodFrequencyType(); - } - interestFreePeriodFrequencyType = (interestFreePreriodTypeId == null) ? null : InterestRateChartPeriodType - .fromInt(interestFreePreriodTypeId); - } - } else { - interestFreePeriodApplicable = produPreClosureDetail.interestFreePeriodApplicable(); - interestFreeFromPeriod = produPreClosureDetail.interestFreeFromPeriod(); - interestFreeToPeriod = produPreClosureDetail.interestFreeToPeriod(); - interestFreePreriodTypeId = produPreClosureDetail.interestFreePeriodFrequencyType(); - interestFreePeriodFrequencyType = (interestFreePreriodTypeId == null) ? null : InterestRateChartPeriodType - .fromInt(interestFreePreriodTypeId); - } - boolean preClosurePenalApplicable = false; BigDecimal preClosurePenalInterest = null; PreClosurePenalInterestOnType preClosurePenalInterestType = null; @@ -378,9 +276,8 @@ public class DepositProductAssembler { preClosurePenalInterestType = preClosurePenalInterestOnTypeId == null ? null : PreClosurePenalInterestOnType .fromInt(preClosurePenalInterestOnTypeId); - DepositPreClosureDetail preClosureDetail1 = DepositPreClosureDetail.createFrom(interestFreePeriodApplicable, - interestFreeFromPeriod, interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, - preClosurePenalInterest, preClosurePenalInterestType); + DepositPreClosureDetail preClosureDetail1 = DepositPreClosureDetail.createFrom(preClosurePenalApplicable, preClosurePenalInterest, + preClosurePenalInterestType); return preClosureDetail1; } @@ -468,22 +365,17 @@ public class DepositProductAssembler { public DepositRecurringDetail assembleRecurringDetail(final JsonCommand command) { - RecurringDepositType recurringDepositType = null; - final Integer recurringDepositTypeValue = command.integerValueOfParameterNamed(recurringDepositTypeIdParamName); - if (recurringDepositTypeValue != null) { - recurringDepositType = RecurringDepositType.fromInt(recurringDepositTypeValue); - } + Boolean isMandatoryDeposit = command.booleanObjectValueOfParameterNamed(isMandatoryDepositParamName); + Boolean allowWithdrawal = command.booleanObjectValueOfParameterNamed(allowWithdrawalParamName); + Boolean adjustAdvanceTowardsFuturePayments = command + .booleanObjectValueOfParameterNamed(adjustAdvanceTowardsFuturePaymentsParamName); - SavingsPeriodFrequencyType recurringDepositFrequencyType = null; - final Integer recurringDepositFrequencyTypeValue = command.integerValueOfParameterNamed(recurringDepositFrequencyTypeIdParamName); - if (recurringDepositFrequencyTypeValue != null) { - recurringDepositFrequencyType = SavingsPeriodFrequencyType.fromInt(recurringDepositFrequencyTypeValue); - } + if (isMandatoryDeposit == null) isMandatoryDeposit = false; + if (allowWithdrawal == null) allowWithdrawal = false; + if (adjustAdvanceTowardsFuturePayments == null) adjustAdvanceTowardsFuturePayments = false; - final Integer recurringDepositFrequency = command.integerValueOfParameterNamed(recurringDepositFrequencyParamName); - - final DepositRecurringDetail depositRecurringDetail = DepositRecurringDetail.createFrom(recurringDepositType, - recurringDepositFrequency, recurringDepositFrequencyType); + final DepositRecurringDetail depositRecurringDetail = DepositRecurringDetail.createFrom(isMandatoryDeposit, allowWithdrawal, + adjustAdvanceTowardsFuturePayments); return depositRecurringDetail; } @@ -538,29 +430,25 @@ public class DepositProductAssembler { return charts; } - private void throwExceptionIfValidationWarningsExist(final List dataValidationErrors) { - if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } - } - public DepositProductAmountDetails assembleDepositAmountDetails(final JsonCommand command) { - + BigDecimal minDepositAmount = null; - if(command.parameterExists(depositMinAmountParamName)) { - minDepositAmount = command.bigDecimalValueOfParameterNamed(depositMinAmountParamName); + if (command.parameterExists(depositMinAmountParamName)) { + minDepositAmount = command.bigDecimalValueOfParameterNamed(depositMinAmountParamName); } - + BigDecimal maxDepositAmount = null; - if(command.parameterExists(depositMaxAmountParamName)) { - maxDepositAmount = command.bigDecimalValueOfParameterNamed(depositMaxAmountParamName); + if (command.parameterExists(depositMaxAmountParamName)) { + maxDepositAmount = command.bigDecimalValueOfParameterNamed(depositMaxAmountParamName); } - + BigDecimal depositAmount = null; - if(command.parameterExists(depositAmountParamName)) { - depositAmount = command.bigDecimalValueOfParameterNamed(depositAmountParamName); + if (command.parameterExists(depositAmountParamName)) { + depositAmount = command.bigDecimalValueOfParameterNamed(depositAmountParamName); } - - final DepositProductAmountDetails depositRecurringDetail = new DepositProductAmountDetails(minDepositAmount, - depositAmount, maxDepositAmount); + + final DepositProductAmountDetails depositRecurringDetail = new DepositProductAmountDetails(minDepositAmount, depositAmount, + maxDepositAmount); return depositRecurringDetail; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductRecurringDetail.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductRecurringDetail.java index 064214607..aeb926db3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductRecurringDetail.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductRecurringDetail.java @@ -15,7 +15,6 @@ import javax.persistence.OneToOne; import javax.persistence.Table; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; import org.springframework.data.jpa.domain.AbstractPersistable; @Entity @@ -43,10 +42,10 @@ public class DepositProductRecurringDetail extends AbstractPersistable { this.product = (RecurringDepositProduct) product; } - public Map update(final JsonCommand command, final DataValidatorBuilder baseDataValidator) { + public Map update(final JsonCommand command) { final Map actualChanges = new LinkedHashMap(10); if (this.recurringDetail != null) { - actualChanges.putAll(this.recurringDetail.update(command, baseDataValidator)); + actualChanges.putAll(this.recurringDetail.update(command)); } return actualChanges; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductTermAndPreClosure.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductTermAndPreClosure.java index 5618b367f..10c9e0a4f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductTermAndPreClosure.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositProductTermAndPreClosure.java @@ -65,7 +65,7 @@ public class DepositProductTermAndPreClosure extends AbstractPersistable { } if(this.depositProductAmountDetails != null) { - actualChanges.putAll(this.depositProductAmountDetails.update(command, baseDataValidator)); + actualChanges.putAll(this.depositProductAmountDetails.update(command)); } return actualChanges; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositRecurringDetail.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositRecurringDetail.java index f0f92db53..bf304f055 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositRecurringDetail.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositRecurringDetail.java @@ -5,9 +5,9 @@ */ package org.mifosplatform.portfolio.savings.domain; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositFrequencyParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositFrequencyTypeIdParamName; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringDepositTypeIdParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.adjustAdvanceTowardsFuturePaymentsParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.allowWithdrawalParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.isMandatoryDepositParamName; import java.util.LinkedHashMap; import java.util.Map; @@ -16,10 +16,6 @@ import javax.persistence.Column; import javax.persistence.Embeddable; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; -import org.mifosplatform.portfolio.savings.RecurringDepositType; -import org.mifosplatform.portfolio.savings.SavingsPeriodFrequencyType; -import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; /** * DepositRecurringDetail encapsulates all the details of a @@ -29,77 +25,68 @@ import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; @Embeddable public class DepositRecurringDetail { - @Column(name = "recurring_deposit_type_enum", nullable = true) - private Integer recurringDepositType; + @Column(name = "is_mandatory", nullable = true) + private boolean isMandatoryDeposit; - @Column(name = "recurring_deposit_frequency", nullable = true) - private Integer recurringDepositFrequency; + @Column(name = "allow_withdrawal", nullable = true) + private boolean allowWithdrawal; - @Column(name = "recurring_deposit_frequency_type_enum", nullable = true) - private Integer recurringDepositFrequencyType; - - public static DepositRecurringDetail createFrom(final RecurringDepositType recurringDepositType, - final Integer recurringDepositFrequency, final SavingsPeriodFrequencyType recurringDepositFrequencyType) { - - return new DepositRecurringDetail(recurringDepositType, recurringDepositFrequency, recurringDepositFrequencyType); - } + @Column(name = "adjust_advance_towards_future_payments", nullable = true) + private boolean adjustAdvanceTowardsFuturePayments; protected DepositRecurringDetail() { // } - private DepositRecurringDetail(final RecurringDepositType recurringDepositType, final Integer recurringDepositFrequency, - final SavingsPeriodFrequencyType recurringDepositFrequencyType) { - this.recurringDepositFrequency = recurringDepositFrequency; - this.recurringDepositFrequencyType = recurringDepositFrequencyType.getValue(); - this.recurringDepositType = recurringDepositType.getValue(); + public static DepositRecurringDetail createFrom(final boolean isMandatoryDeposit, boolean allowWithdrawal, + boolean adjustAdvanceTowardsFuturePayments) { + + return new DepositRecurringDetail(isMandatoryDeposit, allowWithdrawal, adjustAdvanceTowardsFuturePayments); } - public Map update(final JsonCommand command, @SuppressWarnings("unused") final DataValidatorBuilder baseDataValidator) { + private DepositRecurringDetail(final boolean isMandatoryDeposit, boolean allowWithdrawal, boolean adjustAdvanceTowardsFuturePayments) { + this.isMandatoryDeposit = isMandatoryDeposit; + this.allowWithdrawal = allowWithdrawal; + this.adjustAdvanceTowardsFuturePayments = adjustAdvanceTowardsFuturePayments; + } + + public Map update(final JsonCommand command) { final Map actualChanges = new LinkedHashMap(10); - if (command.isChangeInIntegerParameterNamed(recurringDepositFrequencyParamName, this.recurringDepositFrequency)) { - final Integer newValue = command.integerValueOfParameterNamed(recurringDepositFrequencyParamName); - actualChanges.put(recurringDepositFrequencyParamName, newValue); - this.recurringDepositFrequency = newValue; + if (command.isChangeInBooleanParameterNamed(isMandatoryDepositParamName, this.isMandatoryDeposit)) { + final boolean newValue = command.booleanObjectValueOfParameterNamed(isMandatoryDepositParamName); + actualChanges.put(isMandatoryDepositParamName, newValue); + this.isMandatoryDeposit = newValue; } - if (command.isChangeInIntegerParameterNamed(recurringDepositFrequencyTypeIdParamName, this.recurringDepositFrequencyType)) { - final Integer newValue = command.integerValueOfParameterNamed(recurringDepositFrequencyTypeIdParamName); - actualChanges.put(recurringDepositFrequencyTypeIdParamName, SavingsEnumerations.recurringDepositFrequencyType(newValue)); - this.recurringDepositFrequencyType = newValue; + if (command.isChangeInBooleanParameterNamed(allowWithdrawalParamName, this.allowWithdrawal)) { + final boolean newValue = command.booleanObjectValueOfParameterNamed(allowWithdrawalParamName); + actualChanges.put(allowWithdrawalParamName, newValue); + this.allowWithdrawal = newValue; } - - if (command.isChangeInIntegerParameterNamed(recurringDepositTypeIdParamName, this.recurringDepositType)) { - final Integer newValue = command.integerValueOfParameterNamed(recurringDepositTypeIdParamName); - actualChanges.put(recurringDepositTypeIdParamName, SavingsEnumerations.recurringDepositType(newValue)); - this.recurringDepositType = newValue; + + if (command.isChangeInBooleanParameterNamed(adjustAdvanceTowardsFuturePaymentsParamName, this.adjustAdvanceTowardsFuturePayments)) { + final boolean newValue = command.booleanObjectValueOfParameterNamed(adjustAdvanceTowardsFuturePaymentsParamName); + actualChanges.put(adjustAdvanceTowardsFuturePaymentsParamName, newValue); + this.adjustAdvanceTowardsFuturePayments = newValue; } return actualChanges; } - - public Integer recurringDepositType() { - return this.recurringDepositType; + + public boolean isMandatoryDeposit() { + return this.isMandatoryDeposit; } - - public Integer recurringDepositFrequency() { - return this.recurringDepositFrequency; + + public boolean allowWithdrawal() { + return this.allowWithdrawal; } - - public Integer recurringDepositFrequencyTypeId() { - return this.recurringDepositFrequencyType; - } - - public SavingsPeriodFrequencyType recurringDepositFrequencyType() { - return SavingsPeriodFrequencyType.fromInt(this.recurringDepositFrequencyType); + + public boolean adjustAdvanceTowardsFuturePayments() { + return this.adjustAdvanceTowardsFuturePayments; } public DepositRecurringDetail copy() { - final RecurringDepositType recurringDepositType = RecurringDepositType.fromInt(this.recurringDepositType); - final Integer recurringDepositFrequency = this.recurringDepositFrequency; - final SavingsPeriodFrequencyType recurringDepositFrequencyType = SavingsPeriodFrequencyType - .fromInt(this.recurringDepositFrequencyType); - return DepositRecurringDetail.createFrom(recurringDepositType, recurringDepositFrequency, recurringDepositFrequencyType); + return DepositRecurringDetail.createFrom(this.isMandatoryDeposit, this.allowWithdrawal, this.adjustAdvanceTowardsFuturePayments); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositTermDetail.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositTermDetail.java index 06d09468f..3d8359d5a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositTermDetail.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/DepositTermDetail.java @@ -164,21 +164,27 @@ public class DepositTermDetail { public boolean isValidInMultiplesOfPeriod(final Integer depositPeriod, final SavingsPeriodFrequencyType depositPeriodFrequencyType) { + boolean isValidInMultiplesOfPeriod = true; final Integer depositPeriodInDays = this.convertToSafeDays(depositPeriod, depositPeriodFrequencyType); - final Integer inMultiplesOfInDays = this.convertToSafeDays(this.inMultiplesOfDepositTerm(), - SavingsPeriodFrequencyType.fromInt(this.inMultiplesOfDepositTermType())); - final Integer minDepositInDays = this.convertToSafeDays(minDepositTerm, SavingsPeriodFrequencyType.fromInt(minDepositTermType)); + if (this.inMultiplesOfDepositTerm() != null) { + final Integer inMultiplesOfInDays = this.convertToSafeDays(this.inMultiplesOfDepositTerm(), + SavingsPeriodFrequencyType.fromInt(this.inMultiplesOfDepositTermType())); + final Integer minDepositInDays = this.convertToSafeDays(minDepositTerm, SavingsPeriodFrequencyType.fromInt(minDepositTermType)); + isValidInMultiplesOfPeriod = ((depositPeriodInDays - minDepositInDays) % inMultiplesOfInDays == 0); + } - return ((depositPeriodInDays - minDepositInDays) % inMultiplesOfInDays == 0); + return isValidInMultiplesOfPeriod; } private boolean isEqualOrGreaterThanMin(LocalDate depositStartDate, LocalDate depositEndDate) { + if (minDepositTerm() == null) return true; final SavingsPeriodFrequencyType periodFrequencyType = SavingsPeriodFrequencyType.fromInt(this.minDepositTermType()); final Integer depositPeriod = depositPeriod(depositStartDate, depositEndDate, periodFrequencyType); return minDepositTerm() == null || depositPeriod.compareTo(minDepositTerm()) >= 0; } private boolean isEqualOrLessThanMax(LocalDate depositStartDate, LocalDate depositEndDate) { + if (maxDepositTerm() == null) return true; final SavingsPeriodFrequencyType periodFrequencyType = SavingsPeriodFrequencyType.fromInt(this.maxDepositTermType()); final Integer depositPeriod = depositPeriod(depositStartDate, depositEndDate, periodFrequencyType); return maxDepositTerm() == null || depositPeriod.compareTo(maxDepositTerm()) <= 0; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositAccount.java index ef4093f75..10deac8e7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositAccount.java @@ -41,9 +41,9 @@ import org.mifosplatform.organisation.staff.domain.Staff; import org.mifosplatform.portfolio.accountdetails.domain.AccountType; import org.mifosplatform.portfolio.client.domain.Client; import org.mifosplatform.portfolio.group.domain.Group; +import org.mifosplatform.portfolio.interestratechart.data.ClientIncentiveAttributes; import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChart; import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartAssembler; -import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail; import org.mifosplatform.portfolio.savings.DepositAccountOnClosureType; import org.mifosplatform.portfolio.savings.DepositsApiConstants; import org.mifosplatform.portfolio.savings.PreClosurePenalInterestOnType; @@ -125,8 +125,8 @@ public class FixedDepositAccount extends SavingsAccount { final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(FIXED_DEPOSIT_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.modifyApplicationAction); super.modifyApplication(command, actualChanges, baseDataValidator); - - accountTermAndPreClosure.update(command, baseDataValidator); + final Map termAndPreClosureChanges = accountTermAndPreClosure.update(command, baseDataValidator); + actualChanges.putAll(termAndPreClosureChanges); validateDomainRules(baseDataValidator); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } @@ -134,33 +134,38 @@ public class FixedDepositAccount extends SavingsAccount { @Override protected BigDecimal getEffectiveInterestRateAsFraction(final MathContext mc, final LocalDate interestPostingUpToDate) { - final boolean isPreMatureClosure = SavingsAccountStatusType.fromInt(this.status).isPreMatureClosure(); - boolean applyPreMaturePenalty = false; - BigDecimal penalInterest = BigDecimal.ZERO; - LocalDate depositCloseDate = calculateMaturityDate(); - if (isPreMatureClosure) { - if (this.accountTermAndPreClosure.isPreClosurePenalApplicable()) { - applyPreMaturePenalty = true; - penalInterest = this.accountTermAndPreClosure.depositPreClosureDetail().preClosurePenalInterest(); - final PreClosurePenalInterestOnType preClosurePenalInterestOnType = this.accountTermAndPreClosure.depositPreClosureDetail() - .preClosurePenalInterestOnType(); - if (preClosurePenalInterestOnType.isWholeTerm()) { - depositCloseDate = interestCalculatedUpto(); - } else if (preClosurePenalInterestOnType.isTillPrematureWithdrawal()) { - depositCloseDate = interestPostingUpToDate; + // default it to nominalAnnualInterst rate. interest chart overrrides + // this value. + BigDecimal applicableInterestRate = this.nominalAnnualInterestRate; + if (this.chart != null) { + final boolean isPreMatureClosure = SavingsAccountStatusType.fromInt(this.status).isPreMatureClosure(); + boolean applyPreMaturePenalty = false; + BigDecimal penalInterest = BigDecimal.ZERO; + LocalDate depositCloseDate = calculateMaturityDate(); + if (isPreMatureClosure) { + if (this.accountTermAndPreClosure.isPreClosurePenalApplicable()) { + applyPreMaturePenalty = true; + penalInterest = this.accountTermAndPreClosure.depositPreClosureDetail().preClosurePenalInterest(); + final PreClosurePenalInterestOnType preClosurePenalInterestOnType = this.accountTermAndPreClosure + .depositPreClosureDetail().preClosurePenalInterestOnType(); + if (preClosurePenalInterestOnType.isWholeTerm()) { + depositCloseDate = interestCalculatedUpto(); + } else if (preClosurePenalInterestOnType.isTillPrematureWithdrawal()) { + depositCloseDate = interestPostingUpToDate; + } } } + + final BigDecimal depositAmount = accountTermAndPreClosure.depositAmount(); + final ClientIncentiveAttributes incentiveAttributes = (this.client == null) ? null : this.client.incentiveAttributes(); + applicableInterestRate = this.chart.getApplicableInterestRate(depositAmount, depositStartDate(), depositCloseDate, + incentiveAttributes); + + if (applyPreMaturePenalty) { + applicableInterestRate = applicableInterestRate.subtract(penalInterest); + applicableInterestRate = applicableInterestRate.compareTo(BigDecimal.ZERO) == -1 ? BigDecimal.ZERO : applicableInterestRate; + } } - - final BigDecimal depositAmount = accountTermAndPreClosure.depositAmount(); - - BigDecimal applicableInterestRate = this.chart.getApplicableInterestRate(depositAmount, depositStartDate(), depositCloseDate); - - if (applyPreMaturePenalty) { - applicableInterestRate = applicableInterestRate.subtract(penalInterest); - applicableInterestRate = applicableInterestRate.compareTo(BigDecimal.ZERO) == -1 ? BigDecimal.ZERO : applicableInterestRate; - } - this.nominalAnnualInterestRate = applicableInterestRate; return applicableInterestRate.divide(BigDecimal.valueOf(100l), mc); @@ -177,10 +182,23 @@ public class FixedDepositAccount extends SavingsAccount { updateMaturityDateAndAmount(mc, allTransactions); } + public void updateMaturityDateAndAmount(final MathContext mc) { + updateMaturityDateAndAmount(mc, retreiveOrderedNonInterestPostingTransactions()); + } + public void updateMaturityDateAndAmount(final MathContext mc, final List transactions) { final LocalDate maturityDate = calculateMaturityDate(); final LocalDate interestCalculationUpto = maturityDate.minusDays(1); + + // set end of day balance to maturity date for maturity interest + // calculation + this.resetAccountTransactionsEndOfDayBalances(transactions, maturityDate); + final List postingPeriods = calculateInterestPayable(mc, interestCalculationUpto, transactions); + + // reset end of day balance back to today's date + this.resetAccountTransactionsEndOfDayBalances(transactions, DateUtils.getLocalDateOfTenant()); + Money totalInterestPayable = Money.zero(getCurrency()); for (PostingPeriod postingPeriod : postingPeriods) { totalInterestPayable = totalInterestPayable.plus(postingPeriod.getInterestEarned()); @@ -206,7 +224,7 @@ public class FixedDepositAccount extends SavingsAccount { if (!this.maturityDate().isAfter(todayDate)) { // update account status this.status = SavingsAccountStatusType.MATURED.getValue(); - postMaturityInterest(maturityDate()); + postMaturityInterest(); } } @@ -238,11 +256,6 @@ public class FixedDepositAccount extends SavingsAccount { private List calculateInterestPayable(final MathContext mc, final LocalDate maturityDate, final List transactions) { - // 1. default to calculate interest based on entire history OR - // 2. determine latest 'posting period' and find interest credited to - // that period - - // A generate list of EndOfDayBalances (not including interest postings) final SavingsPostingInterestPeriodType postingPeriodType = SavingsPostingInterestPeriodType.fromInt(this.interestPostingPeriodType); final SavingsCompoundingInterestPeriodType compoundingPeriodType = SavingsCompoundingInterestPeriodType @@ -279,8 +292,8 @@ public class FixedDepositAccount extends SavingsAccount { return allPostingPeriods; } - public SavingsAccountTransaction prematureClosure(final AppUser currentUser, final JsonCommand command, - final LocalDate tenantsTodayDate, final PaymentDetail paymentDetail, final Map actualChanges) { + public void prematureClosure(final AppUser currentUser, final JsonCommand command, + final LocalDate tenantsTodayDate, final Map actualChanges) { final List dataValidationErrors = new ArrayList(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) @@ -302,6 +315,12 @@ public class FixedDepositAccount extends SavingsAccount { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } + if (isAccountLocked(closedDate)) { + baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate) + .failWithCode("must.be.after.lockin.period"); + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } + } + if (closedDate.isAfter(maturityDate())) { baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate) .failWithCode("must.be.before.maturity.date"); @@ -329,15 +348,14 @@ public class FixedDepositAccount extends SavingsAccount { final Integer onAccountClosureId = command.integerValueOfParameterNamed(onAccountClosureIdParamName); final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId); this.accountTermAndPreClosure.updateOnAccountClosureStatus(onClosureType); + - postPreMaturityInterest(closedDate); - - // withdraw deposit amount before closing the account +/* // withdraw deposit amount before closing the account final Money transactionAmountMoney = Money.of(this.currency, this.getAccountBalance()); final SavingsAccountTransaction withdraw = SavingsAccountTransaction.withdrawal(this, office(), paymentDetail, closedDate, transactionAmountMoney, new Date()); this.transactions.add(withdraw); - +*/ actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status)); actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat()); @@ -349,8 +367,7 @@ public class FixedDepositAccount extends SavingsAccount { this.withdrawnBy = null; this.closedOnDate = closedDate.toDate(); this.closedBy = currentUser; - - return withdraw; + this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); } @Override @@ -358,8 +375,8 @@ public class FixedDepositAccount extends SavingsAccount { return Money.of(this.currency, this.accountTermAndPreClosure.depositAmount()); } - public SavingsAccountTransaction close(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate, - final PaymentDetail paymentDetail, final Map actualChanges) { + public void close(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate, + final Map actualChanges) { final List dataValidationErrors = new ArrayList(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) @@ -390,6 +407,7 @@ public class FixedDepositAccount extends SavingsAccount { .failWithCode("cannot.be.a.future.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } + final List savingsAccountTransactions = retreiveListOfTransactions(); if (savingsAccountTransactions.size() > 0) { final SavingsAccountTransaction accountTransaction = savingsAccountTransactions.get(savingsAccountTransactions.size() - 1); @@ -407,13 +425,14 @@ public class FixedDepositAccount extends SavingsAccount { final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId); this.accountTermAndPreClosure.updateOnAccountClosureStatus(onClosureType); - postMaturityInterest(maturityDate()); - - // withdraw deposit amount before closing the account - final Money transactionAmountMoney = Money.of(this.currency, this.getAccountBalance()); - final SavingsAccountTransaction withdraw = SavingsAccountTransaction.withdrawal(this, office(), paymentDetail, closedDate, - transactionAmountMoney, new Date()); - this.transactions.add(withdraw); + // // withdraw deposit amount before closing the account + // final Money transactionAmountMoney = Money.of(this.currency, + // this.getAccountBalance()); + // final SavingsAccountTransaction withdraw = + // SavingsAccountTransaction.withdrawal(this, office(), paymentDetail, + // closedDate, + // transactionAmountMoney, new Date()); + // this.transactions.add(withdraw); actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status)); actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); @@ -426,12 +445,12 @@ public class FixedDepositAccount extends SavingsAccount { this.withdrawnBy = null; this.closedOnDate = closedDate.toDate(); this.closedBy = currentUser; - - return withdraw; + // this.summary.updateSummary(this.currency, + // this.savingsAccountTransactionSummaryWrapper, this.transactions); } - public void postMaturityInterest(final LocalDate interestPostingUpToDate) { - + public void postMaturityInterest() { + final LocalDate interestPostingUpToDate = maturityDate(); final MathContext mc = MathContext.DECIMAL64; final boolean isInterestTransfer = false; final List postingPeriods = calculateInterestUsing(mc, interestPostingUpToDate, isInterestTransfer); @@ -569,10 +588,22 @@ public class FixedDepositAccount extends SavingsAccount { return interestPostedToDate; } - public void updateMaturityDateAndAmountAfterAccountActivation(final MathContext mc) { - List allTransactions = new ArrayList(); - allTransactions.addAll(retreiveOrderedNonInterestPostingTransactions()); - updateMaturityDateAndAmount(mc, allTransactions); + @Override + public Map activate(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate) { + final Map actualChanges = super.activate(currentUser, command, tenantsTodayDate); + + // if (isAccountLocked(calculateMaturityDate())) { + // final List dataValidationErrors = new + // ArrayList(); + // final DataValidatorBuilder baseDataValidator = new + // DataValidatorBuilder(dataValidationErrors) + // .resource(FIXED_DEPOSIT_ACCOUNT_RESOURCE_NAME); + // baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("deposit.period.must.be.greater.than.lock.in.period", + // "Deposit period must be greater than account lock-in period."); + // if (!dataValidationErrors.isEmpty()) { throw new + // PlatformApiDataValidationException(dataValidationErrors); } + // } + return actualChanges; } private LocalDate depositStartDate() { @@ -629,9 +660,7 @@ public class FixedDepositAccount extends SavingsAccount { } } - if (this.chart == null) { - baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.valid.interest.rate.slab.available"); - } else { + if (this.chart != null) { final LocalDate chartFromDate = this.chart.getFromDateAsLocalDate(); LocalDate chartEndDate = this.chart.getEndDateAsLocalDate(); chartEndDate = chartEndDate == null ? DateUtils.getLocalDateOfTenant() : chartEndDate; @@ -640,7 +669,22 @@ public class FixedDepositAccount extends SavingsAccount { if (!chartInterval.contains(accountSubmittedOrActivationDate())) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.valid.interest.rate.slab.available"); } + + final BigDecimal depositAmount = accountTermAndPreClosure.depositAmount(); + final ClientIncentiveAttributes incentiveAttributes = (this.client == null) ? null : this.client.incentiveAttributes(); + BigDecimal applicableInterestRate = this.chart.getApplicableInterestRate(depositAmount, depositStartDate(), + calculateMaturityDate(), incentiveAttributes); + + if (applicableInterestRate.equals(BigDecimal.ZERO)) { + baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( + "no.applicable.interest.rate.is.found.based.on.amount.and.deposit.period"); + } + + } else if (this.nominalAnnualInterestRate == null || this.nominalAnnualInterestRate.compareTo(BigDecimal.ZERO) == 0) { + baseDataValidator.reset().parameter(DepositsApiConstants.nominalAnnualInterestRateParamName).value(nominalAnnualInterestRate) + .failWithCodeNoParameterAddedToErrorCode("valid.interest.chart.or.nominal.interest.rate.required"); } + } public boolean isReinvestOnClosure() { @@ -651,9 +695,9 @@ public class FixedDepositAccount extends SavingsAccount { return this.accountTermAndPreClosure.isTransferToSavingsOnClosure(); } - public FixedDepositAccount reInvest(Money depositAmount) { + public FixedDepositAccount reInvest(BigDecimal depositAmount) { - final DepositAccountTermAndPreClosure newAccountTermAndPreClosure = this.accountTermAndPreClosure.deepCopy(depositAmount); + final DepositAccountTermAndPreClosure newAccountTermAndPreClosure = this.accountTermAndPreClosure.copy(depositAmount); final SavingsProduct product = this.product; final InterestRateChart productChart = product.applicableChart(getClosedOnDate()); final DepositAccountInterestRateChart newChart = DepositAccountInterestRateChart.from(productChart); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositProduct.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositProduct.java index ad8a63dd1..9036bafcb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositProduct.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/FixedDepositProduct.java @@ -8,6 +8,7 @@ package org.mifosplatform.portfolio.savings.domain; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.deleteParamName; import static org.mifosplatform.portfolio.interestratechart.InterestRateChartApiConstants.idParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.FIXED_DEPOSIT_PRODUCT_RESOURCE_NAME; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.maxDepositTermParamName; import java.math.BigDecimal; import java.util.ArrayList; @@ -72,16 +73,15 @@ public class FixedDepositProduct extends SavingsProduct { final MonetaryCurrency currency, final BigDecimal interestRate, final SavingsCompoundingInterestPeriodType interestCompoundingPeriodType, final SavingsPostingInterestPeriodType interestPostingPeriodType, final SavingsInterestCalculationType interestCalculationType, - final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, - final Integer lockinPeriodFrequency, final SavingsPeriodFrequencyType lockinPeriodFrequencyType, - final AccountingRuleType accountingRuleType, final Set charges, - final DepositProductTermAndPreClosure productTermAndPreClosure, final Set charts) { + final SavingsInterestCalculationDaysInYearType interestCalculationDaysInYearType, final Integer lockinPeriodFrequency, + final SavingsPeriodFrequencyType lockinPeriodFrequencyType, final AccountingRuleType accountingRuleType, + final Set charges, final DepositProductTermAndPreClosure productTermAndPreClosure, final Set charts) { final BigDecimal minRequiredOpeningBalance = null; final boolean withdrawalFeeApplicableForTransfer = false; final boolean allowOverdraft = false; final BigDecimal overdraftLimit = null; - + return new FixedDepositProduct(name, shortName, description, currency, interestRate, interestCompoundingPeriodType, interestPostingPeriodType, interestCalculationType, interestCalculationDaysInYearType, minRequiredOpeningBalance, lockinPeriodFrequency, lockinPeriodFrequencyType, withdrawalFeeApplicableForTransfer, accountingRuleType, charges, @@ -135,6 +135,8 @@ public class FixedDepositProduct extends SavingsProduct { actualChanges.putAll(this.update(command, baseDataValidator)); + validateDomainRules(baseDataValidator); + throwExceptionIfValidationWarningsExist(dataValidationErrors); return actualChanges; @@ -188,7 +190,7 @@ public class FixedDepositProduct extends SavingsProduct { } } - this.validateCharts(baseDataValidator); + // this.validateCharts(baseDataValidator); // add chart changes to actual changes list. if (!chartsChanges.isEmpty()) { @@ -249,7 +251,7 @@ public class FixedDepositProduct extends SavingsProduct { InterestRateChart applicableChart = null; if (this.charts != null) { for (InterestRateChart chart : this.charts) { - if(chart.isApplicableChartFor(target)){ + if (chart.isApplicableChartFor(target)) { applicableChart = chart; break; } @@ -261,37 +263,70 @@ public class FixedDepositProduct extends SavingsProduct { public DepositProductTermAndPreClosure depositProductTermAndPreClosure() { return this.productTermAndPreClosure; } - - @SuppressWarnings("unchecked") - public void validateInterestPostingAndCompoundingPeriodTypes(final DataValidatorBuilder baseDataValidator) { - Map> postingtoCompoundMap = - new HashMap>(); - postingtoCompoundMap.put(SavingsPostingInterestPeriodType.MONTHLY, - Arrays.asList(new SavingsCompoundingInterestPeriodType[]{SavingsCompoundingInterestPeriodType.DAILY,SavingsCompoundingInterestPeriodType.MONTHLY})); - - postingtoCompoundMap.put(SavingsPostingInterestPeriodType.QUATERLY, - Arrays.asList(new SavingsCompoundingInterestPeriodType[]{SavingsCompoundingInterestPeriodType.DAILY - ,SavingsCompoundingInterestPeriodType.MONTHLY,SavingsCompoundingInterestPeriodType.QUATERLY})); - - postingtoCompoundMap.put(SavingsPostingInterestPeriodType.BIANNUAL, - Arrays.asList(new SavingsCompoundingInterestPeriodType[]{SavingsCompoundingInterestPeriodType.DAILY, - SavingsCompoundingInterestPeriodType.MONTHLY,SavingsCompoundingInterestPeriodType.QUATERLY,SavingsCompoundingInterestPeriodType.BI_ANNUAL})); - - postingtoCompoundMap.put(SavingsPostingInterestPeriodType.ANNUAL, - Arrays.asList(new SavingsCompoundingInterestPeriodType[]{SavingsCompoundingInterestPeriodType.DAILY, - SavingsCompoundingInterestPeriodType.MONTHLY,SavingsCompoundingInterestPeriodType.QUATERLY - ,SavingsCompoundingInterestPeriodType.BI_ANNUAL,SavingsCompoundingInterestPeriodType.ANNUAL})); - - SavingsPostingInterestPeriodType savingsPostingInterestPeriodType = SavingsPostingInterestPeriodType.fromInt(interestPostingPeriodType); - SavingsCompoundingInterestPeriodType savingsCompoundingInterestPeriodType = SavingsCompoundingInterestPeriodType.fromInt(interestCompoundingPeriodType); - - if(postingtoCompoundMap.get(savingsPostingInterestPeriodType) == null || - !postingtoCompoundMap.get(savingsPostingInterestPeriodType).contains(savingsCompoundingInterestPeriodType)) { - baseDataValidator.failWithCodeNoParameterAddedToErrorCode("posting.period.type.is.less.than.compound.period.type", - savingsPostingInterestPeriodType.name(),savingsCompoundingInterestPeriodType.name()); - + + public void validateInterestPostingAndCompoundingPeriodTypes(final DataValidatorBuilder baseDataValidator) { + Map> postingtoCompoundMap = new HashMap>(); + postingtoCompoundMap.put( + SavingsPostingInterestPeriodType.MONTHLY, + Arrays.asList(new SavingsCompoundingInterestPeriodType[] { SavingsCompoundingInterestPeriodType.DAILY, + SavingsCompoundingInterestPeriodType.MONTHLY })); + + postingtoCompoundMap.put( + SavingsPostingInterestPeriodType.QUATERLY, + Arrays.asList(new SavingsCompoundingInterestPeriodType[] { SavingsCompoundingInterestPeriodType.DAILY, + SavingsCompoundingInterestPeriodType.MONTHLY, SavingsCompoundingInterestPeriodType.QUATERLY })); + + postingtoCompoundMap.put( + SavingsPostingInterestPeriodType.BIANNUAL, + Arrays.asList(new SavingsCompoundingInterestPeriodType[] { SavingsCompoundingInterestPeriodType.DAILY, + SavingsCompoundingInterestPeriodType.MONTHLY, SavingsCompoundingInterestPeriodType.QUATERLY, + SavingsCompoundingInterestPeriodType.BI_ANNUAL })); + + postingtoCompoundMap.put( + SavingsPostingInterestPeriodType.ANNUAL, + Arrays.asList(new SavingsCompoundingInterestPeriodType[] { SavingsCompoundingInterestPeriodType.DAILY, + SavingsCompoundingInterestPeriodType.MONTHLY, SavingsCompoundingInterestPeriodType.QUATERLY, + SavingsCompoundingInterestPeriodType.BI_ANNUAL, SavingsCompoundingInterestPeriodType.ANNUAL })); + + SavingsPostingInterestPeriodType savingsPostingInterestPeriodType = SavingsPostingInterestPeriodType + .fromInt(interestPostingPeriodType); + SavingsCompoundingInterestPeriodType savingsCompoundingInterestPeriodType = SavingsCompoundingInterestPeriodType + .fromInt(interestCompoundingPeriodType); + + if (postingtoCompoundMap.get(savingsPostingInterestPeriodType) == null + || !postingtoCompoundMap.get(savingsPostingInterestPeriodType).contains(savingsCompoundingInterestPeriodType)) { + baseDataValidator.failWithCodeNoParameterAddedToErrorCode("posting.period.type.is.less.than.compound.period.type", + savingsPostingInterestPeriodType.name(), savingsCompoundingInterestPeriodType.name()); + } } - + + public void validateDomainRules() { + final List dataValidationErrors = new ArrayList(); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource(FIXED_DEPOSIT_PRODUCT_RESOURCE_NAME); + validateDomainRules(baseDataValidator); + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + private void validateDomainRules(final DataValidatorBuilder baseDataValidator) { + + final DepositTermDetail termDetails = this.depositProductTermAndPreClosure().depositTermDetail(); + final boolean isMinTermGreaterThanMax = termDetails.isMinDepositTermGreaterThanMaxDepositTerm(); + if (isMinTermGreaterThanMax) { + final Integer maxTerm = termDetails.maxDepositTerm(); + baseDataValidator.reset().parameter(maxDepositTermParamName).value(maxTerm) + .failWithCodeNoParameterAddedToErrorCode("max.term.lessthan.min.term"); + } + + if (this.charts != null) { + validateCharts(baseDataValidator); + } else if (this.nominalAnnualInterestRate == null || this.nominalAnnualInterestRate.compareTo(BigDecimal.ZERO) == 0) { + baseDataValidator.reset().parameter(DepositsApiConstants.nominalAnnualInterestRateParamName).value(nominalAnnualInterestRate) + .failWithCodeNoParameterAddedToErrorCode("interest.chart.or.nominal.interest.rate.required"); + } + + this.validateInterestPostingAndCompoundingPeriodTypes(baseDataValidator); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositAccount.java index 36c72f761..f1c0bd244 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositAccount.java @@ -25,9 +25,12 @@ import javax.persistence.CascadeType; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Transient; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; @@ -41,10 +44,11 @@ import org.mifosplatform.organisation.monetary.domain.Money; import org.mifosplatform.organisation.staff.domain.Staff; import org.mifosplatform.portfolio.accountdetails.domain.AccountType; import org.mifosplatform.portfolio.client.domain.Client; +import org.mifosplatform.portfolio.common.domain.PeriodFrequencyType; import org.mifosplatform.portfolio.group.domain.Group; +import org.mifosplatform.portfolio.interestratechart.data.ClientIncentiveAttributes; import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChart; import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartAssembler; -import org.mifosplatform.portfolio.paymentdetail.domain.PaymentDetail; import org.mifosplatform.portfolio.savings.DepositAccountOnClosureType; import org.mifosplatform.portfolio.savings.DepositsApiConstants; import org.mifosplatform.portfolio.savings.PreClosurePenalInterestOnType; @@ -70,10 +74,14 @@ public class RecurringDepositAccount extends SavingsAccount { private DepositAccountRecurringDetail recurringDetail; @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "account") - protected DepositAccountInterestRateChart chart; + private DepositAccountInterestRateChart chart; + + @LazyCollection(LazyCollectionOption.FALSE) + @OneToMany(cascade = CascadeType.ALL, mappedBy = "account", orphanRemoval = true) + private List depositScheduleInstallments = new ArrayList(); @Transient - protected InterestRateChartAssembler chartAssembler; + private InterestRateChartAssembler chartAssembler; protected RecurringDepositAccount() { // @@ -153,9 +161,9 @@ public class RecurringDepositAccount extends SavingsAccount { final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.modifyApplicationAction); super.modifyApplication(command, actualChanges, baseDataValidator); - - accountTermAndPreClosure.update(command, baseDataValidator); - recurringDetail.update(command, baseDataValidator); + final Map termAndPreClosureChanges = accountTermAndPreClosure.update(command, baseDataValidator); + actualChanges.putAll(termAndPreClosureChanges); + recurringDetail.update(command); validateDomainRules(baseDataValidator); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } @@ -182,9 +190,10 @@ public class RecurringDepositAccount extends SavingsAccount { } } - final BigDecimal depositAmount = recurringDetail.recurringDepositAmount(); - - BigDecimal applicableInterestRate = this.chart.getApplicableInterestRate(depositAmount, depositStartDate(), depositCloseDate); + final BigDecimal depositAmount = accountTermAndPreClosure.depositAmount(); + final ClientIncentiveAttributes incentiveAttributes = (this.client == null) ? null : this.client.incentiveAttributes(); + BigDecimal applicableInterestRate = this.chart.getApplicableInterestRate(depositAmount, depositStartDate(), depositCloseDate, + incentiveAttributes); if (applyPreMaturePenalty) { applicableInterestRate = applicableInterestRate.subtract(penalInterest); @@ -196,11 +205,10 @@ public class RecurringDepositAccount extends SavingsAccount { return applicableInterestRate.divide(BigDecimal.valueOf(100l), mc); } - public void updateMaturityDateAndAmount(final MathContext mc, final LocalDate transactionStartDate) { + public void updateMaturityDateAndAmount(final MathContext mc) { final LocalDate maturityDate = calculateMaturityDate(); final LocalDate interestCalculationUpto = maturityDate.minusDays(1); - final List allTransactions = generateIncludingFutureTransactions(transactionStartDate, - interestCalculationUpto); + final List allTransactions = generateIncludingFutureTransactions(interestCalculationUpto); final List postingPeriods = calculateInterestPayable(mc, interestCalculationUpto, allTransactions); Money totalInterestPayable = Money.zero(getCurrency()); @@ -228,7 +236,7 @@ public class RecurringDepositAccount extends SavingsAccount { if (!this.maturityDate().isAfter(todayDate)) { // update account status this.status = SavingsAccountStatusType.MATURED.getValue(); - postMaturityInterest(maturityDate()); + postMaturityInterest(); } } @@ -301,19 +309,16 @@ public class RecurringDepositAccount extends SavingsAccount { return allPostingPeriods; } - private List generateIncludingFutureTransactions(final LocalDate transactionStartDate, - final LocalDate depositEndDate) { - LocalDate transactionDate = transactionStartDate; - final BigDecimal recurringDepositAmount = this.recurringDetail.recurringDepositAmount(); + private List generateIncludingFutureTransactions(final LocalDate depositEndDate) { List allTransactions = new ArrayList(); // add existing transactions allTransactions.addAll(retreiveOrderedNonInterestPostingTransactions()); - while (!transactionDate.isAfter(depositEndDate) && !transactionDate.isEqual(depositEndDate)) { - final Money transactionAmountMoney = Money.of(this.currency, recurringDepositAmount); - final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(null, office(), null, transactionDate, - transactionAmountMoney, new Date()); - allTransactions.add(transaction); - transactionDate = nextDepositDate(transactionDate); + for (RecurringDepositScheduleInstallment installment : depositScheduleInstallments()) { + if (installment.isPrincipalNotCompleted(getCurrency())) { + final SavingsAccountTransaction transaction = SavingsAccountTransaction.deposit(null, office(), null, + installment.dueDate(), installment.getDepositAmountOutstanding(getCurrency()), installment.dueDate().toDate()); + allTransactions.add(transaction); + } } allTransactions = sortTransactions(allTransactions); @@ -338,7 +343,7 @@ public class RecurringDepositAccount extends SavingsAccount { LocalDate endOfBalanceDate = depositEndDate; for (int i = allTransactions.size() - 1; i >= 0; i--) { final SavingsAccountTransaction transaction = allTransactions.get(i); - if (transaction.isNotReversed()) { + if (transaction.isNotReversed() && !transaction.isInterestPostingAndNotReversed()) { transaction.updateCumulativeBalanceAndDates(this.currency, endOfBalanceDate); endOfBalanceDate = transaction.transactionLocalDate().minusDays(1); } @@ -346,49 +351,37 @@ public class RecurringDepositAccount extends SavingsAccount { return allTransactions; } - public LocalDate nextDepositDate(LocalDate depositDate) { - final LocalDate depositStartDate = depositStartDate(); - LocalDate nextDepositDate = depositStartDate; - while (!depositDate.isBefore(nextDepositDate)) { - nextDepositDate = calculateNextDepositDate(nextDepositDate); - } - return nextDepositDate; - } + private LocalDate calculateNextDepositDate(final LocalDate lastDepositDate, final PeriodFrequencyType frequency, + final int recurringEvery) { + LocalDate nextDepositDate = lastDepositDate; - private LocalDate calculateNextDepositDate(final LocalDate depositDate) { - final Integer depositFrequency = this.recurringDetail.recurringDepositFrequency(); - LocalDate nextDepositDate = depositDate; - final SavingsPeriodFrequencyType depositFrequencyType = this.recurringDetail.recurringDepositFrequencyType(); - switch (depositFrequencyType) { + switch (frequency) { case DAYS: - nextDepositDate = depositDate.plusDays(depositFrequency); + nextDepositDate = lastDepositDate.plusDays(recurringEvery); break; case WEEKS: - nextDepositDate = depositDate.plusWeeks(depositFrequency); + nextDepositDate = lastDepositDate.plusWeeks(recurringEvery); break; case MONTHS: - nextDepositDate = depositDate.plusMonths(depositFrequency); + nextDepositDate = lastDepositDate.plusMonths(recurringEvery); break; case YEARS: - nextDepositDate = depositDate.plusYears(depositFrequency); + nextDepositDate = lastDepositDate.plusYears(recurringEvery); break; case INVALID: - nextDepositDate = null; break; } return nextDepositDate; } public LocalDate depositStartDate() { - // TODO: Support to add deposit start date which can be a date after - // account activation date. final LocalDate depositStartDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate(); if (depositStartDate == null) return accountSubmittedOrActivationDate(); return depositStartDate; } - public SavingsAccountTransaction prematureClosure(final AppUser currentUser, final JsonCommand command, - final LocalDate tenantsTodayDate, final PaymentDetail paymentDetail, final Map actualChanges) { + public void prematureClosure(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate, + final Map actualChanges) { final List dataValidationErrors = new ArrayList(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) @@ -410,6 +403,12 @@ public class RecurringDepositAccount extends SavingsAccount { if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } + if (isAccountLocked(closedDate)) { + baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate) + .failWithCode("must.be.after.lockin.period"); + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } + } + if (closedDate.isAfter(maturityDate())) { baseDataValidator.reset().parameter(SavingsApiConstants.closedOnDateParamName).value(closedDate) .failWithCode("must.be.before.maturity.date"); @@ -421,6 +420,13 @@ public class RecurringDepositAccount extends SavingsAccount { .failWithCode("cannot.be.a.future.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } + + if (isAccountLocked(calculateMaturityDate())) { + baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("deposit.period.must.be.greater.than.lock.in.period", + "Deposit period must be greater than account lock-in period."); + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } + } + final List savingsAccountTransactions = retreiveListOfTransactions(); if (savingsAccountTransactions.size() > 0) { final SavingsAccountTransaction accountTransaction = savingsAccountTransactions.get(savingsAccountTransactions.size() - 1); @@ -438,14 +444,14 @@ public class RecurringDepositAccount extends SavingsAccount { final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId); this.accountTermAndPreClosure.updateOnAccountClosureStatus(onClosureType); - postPreMaturityInterest(closedDate); - - // withdraw deposit amount before closing the account - final Money transactionAmountMoney = Money.of(this.currency, this.getAccountBalance()); - final SavingsAccountTransaction withdraw = SavingsAccountTransaction.withdrawal(this, office(), paymentDetail, closedDate, - transactionAmountMoney, new Date()); - this.transactions.add(withdraw); - + /* + * // withdraw deposit amount before closing the account final Money + * transactionAmountMoney = Money.of(this.currency, + * this.getAccountBalance()); final SavingsAccountTransaction withdraw = + * SavingsAccountTransaction.withdrawal(this, office(), paymentDetail, + * closedDate, transactionAmountMoney, new Date()); + * this.transactions.add(withdraw); + */ actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status)); actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat()); @@ -457,8 +463,8 @@ public class RecurringDepositAccount extends SavingsAccount { this.withdrawnBy = null; this.closedOnDate = closedDate.toDate(); this.closedBy = currentUser; + this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); - return withdraw; } @Override @@ -466,8 +472,21 @@ public class RecurringDepositAccount extends SavingsAccount { return Money.of(this.currency, this.minRequiredOpeningBalance); } - public SavingsAccountTransaction close(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate, - final PaymentDetail paymentDetail, final Map actualChanges) { + protected void processAccountUponActivation(final DateTimeFormatter fmt) { + final Money minRequiredOpeningBalance = Money.of(this.currency, this.minRequiredOpeningBalance); + if (minRequiredOpeningBalance.isGreaterThanZero()) { + final SavingsAccountTransactionDTO transactionDTO = new SavingsAccountTransactionDTO(fmt, getActivationLocalDate(), + minRequiredOpeningBalance.getAmount(), null, new Date()); + deposit(transactionDTO); + + // update existing transactions so derived balance fields are + // correct. + recalculateDailyBalances(Money.zero(this.currency), DateUtils.getLocalDateOfTenant()); + } + } + + public void close(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate, + final Map actualChanges) { final List dataValidationErrors = new ArrayList(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) @@ -515,13 +534,14 @@ public class RecurringDepositAccount extends SavingsAccount { final DepositAccountOnClosureType onClosureType = DepositAccountOnClosureType.fromInt(onAccountClosureId); this.accountTermAndPreClosure.updateOnAccountClosureStatus(onClosureType); - postMaturityInterest(maturityDate()); - - // withdraw deposit amount before closing the account - final Money transactionAmountMoney = Money.of(this.currency, this.getAccountBalance()); - final SavingsAccountTransaction withdraw = SavingsAccountTransaction.withdrawal(this, office(), paymentDetail, closedDate, - transactionAmountMoney, new Date()); - this.transactions.add(withdraw); + /* + * // withdraw deposit amount before closing the account final Money + * transactionAmountMoney = Money.of(this.currency, + * this.getAccountBalance()); final SavingsAccountTransaction withdraw = + * SavingsAccountTransaction.withdrawal(this, office(), paymentDetail, + * closedDate, transactionAmountMoney, new Date()); + * this.transactions.add(withdraw); + */ actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status)); actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); @@ -534,15 +554,14 @@ public class RecurringDepositAccount extends SavingsAccount { this.withdrawnBy = null; this.closedOnDate = closedDate.toDate(); this.closedBy = currentUser; - - return withdraw; + this.summary.updateSummary(this.currency, this.savingsAccountTransactionSummaryWrapper, this.transactions); } - public void postMaturityInterest(final LocalDate interestPostingUpToDate) { - + public void postMaturityInterest() { + final LocalDate interestPostingUpToDate = maturityDate(); final MathContext mc = MathContext.DECIMAL64; boolean isInterestTransfer = false; - final List postingPeriods = calculateInterestUsing(mc, interestPostingUpToDate,isInterestTransfer); + final List postingPeriods = calculateInterestUsing(mc, interestPostingUpToDate, isInterestTransfer); Money interestPostedToDate = Money.zero(this.currency); @@ -632,12 +651,12 @@ public class RecurringDepositAccount extends SavingsAccount { final Money interestEarnedForPeriod = interestPostingPeriod.getInterestEarned(); interestOnMaturity = interestOnMaturity.plus(interestEarnedForPeriod); } - + this.summary.updateFromInterestPeriodSummaries(this.currency, postingPeriods); return interestOnMaturity; } @Override - public void postInterest(final MathContext mc, final LocalDate postingDate,final boolean isInterestTransfer) { + public void postInterest(final MathContext mc, final LocalDate postingDate, final boolean isInterestTransfer) { final LocalDate interestPostingUpToDate = interestPostingUpToDate(postingDate); super.postInterest(mc, interestPostingUpToDate, isInterestTransfer); } @@ -657,10 +676,14 @@ public class RecurringDepositAccount extends SavingsAccount { return interestPostingUpToDate; } - private LocalDate maturityDate() { + public LocalDate maturityDate() { return this.accountTermAndPreClosure.getMaturityLocalDate(); } + public BigDecimal maturityAmount() { + return this.accountTermAndPreClosure.maturityAmount(); + } + private LocalDate interestCalculatedUpto() { LocalDate uptoMaturityDate = calculateMaturityDate(); if (uptoMaturityDate != null) { @@ -683,15 +706,20 @@ public class RecurringDepositAccount extends SavingsAccount { @Override public Map activate(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate) { + final Map actualChanges = super.activate(currentUser, command, tenantsTodayDate); - final MathContext mc = MathContext.DECIMAL64; - final LocalDate transactionStartDate = getActivationLocalDate(); - // TODO: If first deposit and activation date are not same then - // recalculate the nextTransaction date + if (accountTermAndPreClosure.isAfterExpectedFirstDepositDate(getActivationLocalDate())) { + final List dataValidationErrors = new ArrayList(); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource(RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME); + final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat()).withLocale(command.extractLocale()); + final String dateAsString = formatter.print(this.accountTermAndPreClosure.getExpectedFirstDepositOnDate()); + baseDataValidator.reset().parameter(DepositsApiConstants.activatedOnDateParamName).value(dateAsString) + .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.expected.first.deposit.date"); + if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } + } - final LocalDate nextTransactionStartDate = nextDepositDate(transactionStartDate); - updateMaturityDateAndAmount(mc, nextTransactionStartDate); return actualChanges; } @@ -722,7 +750,7 @@ public class RecurringDepositAccount extends SavingsAccount { if (!isBeforeMaturityDate(transactionDTO.getTransactionDate())) { final String defaultUserMessage = "Transaction is not allowed. Transaction date is on or after account maturity date."; final ApiParameterError error = ApiParameterError.parameterError( - "error.msg.recurring.deposit.account.transaction.date.is.on.or.after.account.maturity.date", defaultUserMessage, + "error.msg.recurring.deposit.account.transaction.date.is.after.account.maturity.date", defaultUserMessage, "transactionDate", transactionDTO.getTransactionDate().toString(transactionDTO.getFormatter())); final List dataValidationErrors = new ArrayList(); @@ -730,15 +758,96 @@ public class RecurringDepositAccount extends SavingsAccount { throw new PlatformApiDataValidationException(dataValidationErrors); } - final SavingsAccountTransaction transaction = super.deposit(transactionDTO); - final LocalDate nextTransactionDate = nextDepositDate(transactionDTO.getTransactionDate()); - final MathContext mc = MathContext.DECIMAL64; - updateMaturityDateAndAmount(mc, nextTransactionDate); + if (isBeforeDepositStartDate(transactionDTO.getTransactionDate())) { + final String defaultUserMessage = "Transaction is not allowed. Transaction date is on or after account activation and deposit start date."; + final ApiParameterError error = ApiParameterError.parameterError( + "error.msg.recurring.deposit.account.transaction.date.is.before.account.activation.or.deposit.date", + defaultUserMessage, "transactionDate", transactionDTO.getTransactionDate().toString(transactionDTO.getFormatter())); + + final List dataValidationErrors = new ArrayList(); + dataValidationErrors.add(error); + + throw new PlatformApiDataValidationException(dataValidationErrors); + } + + final SavingsAccountTransaction transaction = super.deposit(transactionDTO); return transaction; } + public void handleScheduleInstallments(final SavingsAccountTransaction transaction) { + + final LocalDate transactionDate = transaction.transactionLocalDate(); + Money transactionAmountUnprocessed = transaction.getAmount(getCurrency()); + + for (RecurringDepositScheduleInstallment currentInstallment : depositScheduleInstallments()) { + if (currentInstallment.isNotFullyPaidOff() && transactionAmountUnprocessed.isGreaterThanZero()) { + if (!this.adjustAdvanceTowardsFuturePayments() && currentInstallment.dueDate().isAfter(transactionDate)) { + transactionAmountUnprocessed = Money.zero(getCurrency()); + } + transactionAmountUnprocessed = handleInstallmentTransaction(currentInstallment, transactionAmountUnprocessed, + transactionDate); + } + } + + } + + public void updateScheduleInstallments() { + + // reset all installments to process from the beginning + for (RecurringDepositScheduleInstallment currentInstallment : depositScheduleInstallments()) { + currentInstallment.resetDerivedFields(); + } + + final List orderedDepositTransactions = retreiveOrderedDepositTransactions(); + for (SavingsAccountTransaction transaction : orderedDepositTransactions) { + handleScheduleInstallments(transaction); + } + } + + private List retreiveOrderedDepositTransactions() { + final List listOfTransactionsSorted = retreiveListOfTransactions(); + + final List orderedDepositTransactions = new ArrayList(); + + for (final SavingsAccountTransaction transaction : listOfTransactionsSorted) { + if (transaction.isDepositAndNotReversed()) { + orderedDepositTransactions.add(transaction); + } + } + + return orderedDepositTransactions; + } + + /** + * This method is responsible for checking if the current transaction is 'an + * advance/early payment' based on the details passed through. + * + * Default implementation is check transaction date is before installment + * due date. + */ + protected boolean isTransactionInAdvanceOfInstallment(final int currentInstallmentIndex, + final List installments, final LocalDate transactionDate) { + + final RecurringDepositScheduleInstallment currentInstallment = installments.get(currentInstallmentIndex); + + return transactionDate.isBefore(currentInstallment.dueDate()); + } + + private Money handleInstallmentTransaction(final RecurringDepositScheduleInstallment currentInstallment, + final Money transactionAmountUnprocessed, final LocalDate transactionDate) { + + Money transactionAmountRemaining = transactionAmountUnprocessed; + Money depositAmountPortion = Money.zero(transactionAmountRemaining.getCurrency()); + + depositAmountPortion = currentInstallment.payInstallment(transactionDate, transactionAmountRemaining); + transactionAmountRemaining = transactionAmountRemaining.minus(depositAmountPortion); + + return transactionAmountRemaining; + + } + private boolean isAccountMatured() { return SavingsAccountStatusType.fromInt(status).isMatured(); } @@ -748,6 +857,10 @@ public class RecurringDepositAccount extends SavingsAccount { return compareDate.isBefore(maturityDate); } + private boolean isBeforeDepositStartDate(LocalDate compareDate) { + return compareDate.isBefore(depositStartDate()); + } + public void validateDomainRules() { final List dataValidationErrors = new ArrayList(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) @@ -760,17 +873,17 @@ public class RecurringDepositAccount extends SavingsAccount { final boolean isMinTermGreaterThanMax = this.accountTermAndPreClosure.depositTermDetail() .isMinDepositTermGreaterThanMaxDepositTerm(); - final boolean isValidDepositPeriod = this.accountTermAndPreClosure.depositTermDetail().isDepositBetweenMinAndMax( - depositStartDate(), calculateMaturityDate()); // deposit period should be within min and max deposit term if (isMinTermGreaterThanMax) { final Integer maxTerm = this.accountTermAndPreClosure.depositTermDetail().maxDepositTerm(); baseDataValidator.reset().parameter(maxDepositTermParamName).value(maxTerm) .failWithCodeNoParameterAddedToErrorCode("max.term.lessthan.min.term"); } + final Integer depositPeriod = this.accountTermAndPreClosure.depositPeriod(); final SavingsPeriodFrequencyType depositPeriodFrequencyType = this.accountTermAndPreClosure.depositPeriodFrequencyType(); - + final boolean isValidDepositPeriod = this.accountTermAndPreClosure.depositTermDetail().isDepositBetweenMinAndMax( + depositStartDate(), calculateMaturityDate()); if (!isValidDepositPeriod) { baseDataValidator.reset().parameter(depositPeriodParamName).value(depositPeriod) .failWithCodeNoParameterAddedToErrorCode("deposit.period.not.between.min.and.max.deposit.term"); @@ -785,30 +898,59 @@ public class RecurringDepositAccount extends SavingsAccount { } } } - - final LocalDate chartFromDate = this.chart.getFromDateAsLocalDate(); - LocalDate chartEndDate = this.chart.getEndDateAsLocalDate(); - chartEndDate = chartEndDate == null ? DateUtils.getLocalDateOfTenant() : chartEndDate; - - final LocalDateInterval chartInterval = LocalDateInterval.create(chartFromDate, chartEndDate); - if (!chartInterval.contains(accountSubmittedOrActivationDate())) { - baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.valid.interest.rate.slab.available.for.date.range"); + if (isAccountLocked(calculateMaturityDate())) { + baseDataValidator + .reset() + .parameter(depositPeriodParamName) + .value(depositPeriod) + .failWithCode("deposit.period.must.be.greater.than.lock.in.period", + "Deposit period must be greater than account lock-in period."); } - final boolean firstDepositDateBeforeMaturityAndOnOrAfterActivationDate = firstDepositDateBeforeMaturityAndOnOrAfterActivationDate(); - - if (!firstDepositDateBeforeMaturityAndOnOrAfterActivationDate) { + if (firstDepositDateBeforeAccountSubmittedOrActivationDate()) { baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( - "expected.first.deposit.date.is.not.between.maturity.date.and.activation.or.submitted.date"); + "expected.first.deposit.date.must.be.after.account.submitted.or.activation.date"); } - final BigDecimal recurringDepositAmount = recurringDetail.recurringDepositAmount(); - BigDecimal applicableInterestRate = this.chart.getApplicableInterestRate(recurringDepositAmount, depositStartDate(), - calculateMaturityDate()); + // FIXME: Handle this scenario + /* + * //final boolean recurringFrequencyBeforeDepositPeriod = + * recurringFrequencyBeforeDepositPeriod(); + * + * if (!recurringFrequencyBeforeDepositPeriod) { + * baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( + * "recurring.frequency.not.before.deposit.period"); } + */ + } - if (applicableInterestRate.equals(BigDecimal.ZERO)) { - baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( - "no.applicable.interest.rate.is.found.based.on.amount.and.deposit.period"); + public void validateApplicableInterestRate() { + final List dataValidationErrors = new ArrayList(); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource(RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME); + + if (this.chart != null) { + final LocalDate chartFromDate = this.chart.getFromDateAsLocalDate(); + LocalDate chartEndDate = this.chart.getEndDateAsLocalDate(); + chartEndDate = chartEndDate == null ? DateUtils.getLocalDateOfTenant() : chartEndDate; + + final LocalDateInterval chartInterval = LocalDateInterval.create(chartFromDate, chartEndDate); + if (!chartInterval.contains(accountSubmittedOrActivationDate())) { + baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode("no.valid.interest.rate.slab.available.for.date.range"); + } + + final BigDecimal maturityAmount = this.accountTermAndPreClosure.maturityAmount(); + final ClientIncentiveAttributes incentiveAttributes = (this.client == null) ? null : this.client.incentiveAttributes(); + BigDecimal applicableInterestRate = this.chart.getApplicableInterestRate(maturityAmount, depositStartDate(), + calculateMaturityDate(), incentiveAttributes); + + if (applicableInterestRate.equals(BigDecimal.ZERO)) { + baseDataValidator.reset().failWithCodeNoParameterAddedToErrorCode( + "no.applicable.interest.rate.is.found.based.on.amount.and.deposit.period"); + } + + } else if (this.nominalAnnualInterestRate == null || this.nominalAnnualInterestRate.compareTo(BigDecimal.ZERO) == 0) { + baseDataValidator.reset().parameter(DepositsApiConstants.nominalAnnualInterestRateParamName).value(nominalAnnualInterestRate) + .failWithCodeNoParameterAddedToErrorCode("interest.chart.or.nominal.interest.rate.required"); } /** @@ -829,9 +971,9 @@ public class RecurringDepositAccount extends SavingsAccount { return this.accountTermAndPreClosure.isTransferToSavingsOnClosure(); } - public RecurringDepositAccount reInvest(Money depositAmount) { + public RecurringDepositAccount reInvest(BigDecimal depositAmount) { - final DepositAccountTermAndPreClosure newAccountTermAndPreClosure = this.accountTermAndPreClosure.deepCopy(depositAmount); + final DepositAccountTermAndPreClosure newAccountTermAndPreClosure = this.accountTermAndPreClosure.copy(depositAmount); final DepositAccountRecurringDetail recurringDetail = this.recurringDetail.copy(); final SavingsProduct product = this.product; final InterestRateChart productChart = product.applicableChart(getClosedOnDate()); @@ -845,14 +987,14 @@ public class RecurringDepositAccount extends SavingsAccount { final SavingsInterestCalculationType interestCalculationType = SavingsInterestCalculationType.fromInt(this.interestCalculationType); final SavingsInterestCalculationDaysInYearType daysInYearType = SavingsInterestCalculationDaysInYearType .fromInt(this.interestCalculationDaysInYearType); - final BigDecimal minRequiredOpeningBalance = depositAmount.getAmount(); + final BigDecimal minRequiredOpeningBalance = depositAmount; final BigDecimal interestRate = BigDecimal.ZERO; final Set savingsAccountCharges = null; final SavingsPeriodFrequencyType lockinPeriodFrequencyType = SavingsPeriodFrequencyType.fromInt(this.lockinPeriodFrequencyType); final Integer lockinPeriodFrequency = this.lockinPeriodFrequency; final boolean withdrawalFeeApplicableForTransfer = false; - LocalDate now = LocalDate.now(); + LocalDate now = DateUtils.getLocalDateOfTenant(); newAccountTermAndPreClosure.updateExpectedFirstDepositDate(now); @@ -870,14 +1012,10 @@ public class RecurringDepositAccount extends SavingsAccount { } - private boolean firstDepositDateBeforeMaturityAndOnOrAfterActivationDate() { - LocalDate expectedFirstDepositLocalDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate(); - LocalDate maturityLocalDate = calculateMaturityDate(); - LocalDate activateOnSubmittedLocalDate = accountSubmittedOrActivationDate(); - if (expectedFirstDepositLocalDate != null) { return expectedFirstDepositLocalDate.isBefore(maturityLocalDate) - && (activateOnSubmittedLocalDate.isEqual(expectedFirstDepositLocalDate) || activateOnSubmittedLocalDate - .isBefore(expectedFirstDepositLocalDate)); } - return true; + private boolean firstDepositDateBeforeAccountSubmittedOrActivationDate() { + final LocalDate expectedFirstDepositLocalDate = accountTermAndPreClosure.getExpectedFirstDepositOnDate(); + if (expectedFirstDepositLocalDate == null) return false; + return expectedFirstDepositLocalDate.isBefore(accountSubmittedOrActivationDate()); } public void setDatesFrom(final LocalDate now) { @@ -898,4 +1036,57 @@ public class RecurringDepositAccount extends SavingsAccount { protected boolean isTransferInterestToOtherAccount() { return this.accountTermAndPreClosure.isTransferInterestToLinkedAccount(); } + + public void generateSchedule(final PeriodFrequencyType frequency, final Integer recurringEvery) { + final List depositScheduleInstallments = depositScheduleInstallments(); + depositScheduleInstallments.clear(); + LocalDate installmentDate = depositStartDate(); + final LocalDate maturityDate = calculateMaturityDate(); + int installmentNumber = 1; + final BigDecimal depositAmount = this.recurringDetail.mandatoryRecommendedDepositAmount(); + while (maturityDate.isAfter(installmentDate)) { + final RecurringDepositScheduleInstallment installment = RecurringDepositScheduleInstallment.installment(this, + installmentNumber, installmentDate.toDate(), depositAmount); + depositScheduleInstallments.add(installment); + installmentDate = calculateNextDepositDate(installmentDate, frequency, recurringEvery); + installmentNumber += 1; + } + } + + private List depositScheduleInstallments() { + if (this.depositScheduleInstallments == null) { + this.depositScheduleInstallments = new ArrayList(); + } + return this.depositScheduleInstallments; + } + + public boolean isCalendarInherited() { + return this.recurringDetail.isCalendarInherited(); + } + + public void updateOverduePayments(final LocalDate todayDate) { + LocalDate overdueUptoDate = this.maturityDate(); + if (overdueUptoDate.isAfter(todayDate)) { + overdueUptoDate = todayDate; + } + + final List installments = depositScheduleInstallments(); + int noOfOverdueInstallments = 0; + Money totalOverdueAmount = Money.zero(getCurrency()); + for (RecurringDepositScheduleInstallment installment : installments) { + if (installment.isNotFullyPaidOff() && overdueUptoDate.isAfter(installment.dueDate())) { + noOfOverdueInstallments++; + totalOverdueAmount = totalOverdueAmount.plus(installment.getDepositAmountOutstanding(getCurrency())); + } + } + this.recurringDetail.updateOverdueDetails(noOfOverdueInstallments, totalOverdueAmount); + } + + public boolean allowWithdrawal() { + return this.recurringDetail.allowWithdrawal(); + } + + public boolean adjustAdvanceTowardsFuturePayments() { + return this.recurringDetail.adjustAdvanceTowardsFuturePayments(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositProduct.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositProduct.java index 80defd3d1..2a5f09d24 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositProduct.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositProduct.java @@ -6,6 +6,7 @@ package org.mifosplatform.portfolio.savings.domain; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.RECURRING_DEPOSIT_PRODUCT_RESOURCE_NAME; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.maxDepositTermParamName; import java.math.BigDecimal; import java.util.ArrayList; @@ -27,6 +28,7 @@ import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidation import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; import org.mifosplatform.portfolio.charge.domain.Charge; import org.mifosplatform.portfolio.interestratechart.domain.InterestRateChart; +import org.mifosplatform.portfolio.savings.DepositsApiConstants; import org.mifosplatform.portfolio.savings.SavingsCompoundingInterestPeriodType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationDaysInYearType; import org.mifosplatform.portfolio.savings.SavingsInterestCalculationType; @@ -91,6 +93,8 @@ public class RecurringDepositProduct extends FixedDepositProduct { actualChanges.putAll(this.update(command, baseDataValidator)); + validateDomainRules(baseDataValidator); + throwExceptionIfValidationWarningsExist(dataValidationErrors); return actualChanges; @@ -103,7 +107,7 @@ public class RecurringDepositProduct extends FixedDepositProduct { actualChanges.putAll(super.update(command, baseDataValidator)); if (this.recurringDetail != null) { - actualChanges.putAll(this.recurringDetail.update(command, baseDataValidator)); + actualChanges.putAll(this.recurringDetail.update(command)); } return actualChanges; @@ -117,4 +121,33 @@ public class RecurringDepositProduct extends FixedDepositProduct { return this.recurringDetail; } + @Override + public void validateDomainRules() { + final List dataValidationErrors = new ArrayList(); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource(RECURRING_DEPOSIT_PRODUCT_RESOURCE_NAME); + + validateDomainRules(baseDataValidator); + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + private void validateDomainRules(final DataValidatorBuilder baseDataValidator) { + final DepositTermDetail termDetails = this.depositProductTermAndPreClosure().depositTermDetail(); + final boolean isMinTermGreaterThanMax = termDetails.isMinDepositTermGreaterThanMaxDepositTerm(); + if (isMinTermGreaterThanMax) { + final Integer maxTerm = termDetails.maxDepositTerm(); + baseDataValidator.reset().parameter(maxDepositTermParamName).value(maxTerm) + .failWithCodeNoParameterAddedToErrorCode("max.term.lessthan.min.term"); + } + + if (this.charts != null) { + validateCharts(baseDataValidator); + } else if (this.nominalAnnualInterestRate == null || this.nominalAnnualInterestRate.compareTo(BigDecimal.ZERO) == 0) { + baseDataValidator.reset().parameter(DepositsApiConstants.nominalAnnualInterestRateParamName).value(nominalAnnualInterestRate) + .failWithCodeNoParameterAddedToErrorCode("interest.chart.or.nominal.interest.rate.required"); + } + + this.validateInterestPostingAndCompoundingPeriodTypes(baseDataValidator); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositScheduleInstallment.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositScheduleInstallment.java new file mode 100644 index 000000000..82591474d --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/RecurringDepositScheduleInstallment.java @@ -0,0 +1,226 @@ +/** + * 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.savings.domain; + +import java.math.BigDecimal; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.joda.time.LocalDate; +import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom; +import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; +import org.mifosplatform.organisation.monetary.domain.Money; +import org.mifosplatform.useradministration.domain.AppUser; + +@Entity +@Table(name = "m_mandatory_savings_schedule") +public class RecurringDepositScheduleInstallment extends AbstractAuditableCustom { + + @ManyToOne(optional = false) + @JoinColumn(name = "savings_account_id") + private RecurringDepositAccount account; + + @Column(name = "installment", nullable = false) + private Integer installmentNumber; + + @Temporal(TemporalType.DATE) + @Column(name = "fromdate", nullable = true) + private Date fromDate; + + @Temporal(TemporalType.DATE) + @Column(name = "duedate", nullable = false) + private Date dueDate; + + @Column(name = "deposit_amount", scale = 6, precision = 19, nullable = true) + private BigDecimal depositAmount; + + @Column(name = "deposit_amount_completed_derived", scale = 6, precision = 19, nullable = true) + private BigDecimal depositAmountCompleted; + + @Column(name = "total_paid_in_advance_derived", scale = 6, precision = 19, nullable = true) + private BigDecimal totalPaidInAdvance; + + @Column(name = "total_paid_late_derived", scale = 6, precision = 19, nullable = true) + private BigDecimal totalPaidLate; + + @Column(name = "completed_derived", nullable = false) + private boolean obligationsMet; + + @Temporal(TemporalType.DATE) + @Column(name = "obligations_met_on_date") + private Date obligationsMetOnDate; + + /** + * + */ + protected RecurringDepositScheduleInstallment() { + this.installmentNumber = null; + this.fromDate = null; + this.dueDate = null; + this.obligationsMet = false; + } + + /** + * @param account + * @param installmentNumber + * @param fromDate + * @param dueDate + * @param depositAmount + * @param depositAmountCompleted + * @param totalPaidInAdvance + * @param totalPaidLate + * @param obligationsMet + * @param obligationsMetOnDate + */ + private RecurringDepositScheduleInstallment(final RecurringDepositAccount account, final Integer installmentNumber, + final Date fromDate, final Date dueDate, final BigDecimal depositAmount, final BigDecimal depositAmountCompleted, + final BigDecimal totalPaidInAdvance, final BigDecimal totalPaidLate, final boolean obligationsMet, + final Date obligationsMetOnDate) { + this.account = account; + this.installmentNumber = installmentNumber; + this.fromDate = fromDate; + this.dueDate = dueDate; + this.depositAmount = defaultToNullIfZero(depositAmount); + this.depositAmountCompleted = depositAmountCompleted; + this.totalPaidInAdvance = totalPaidInAdvance; + this.totalPaidLate = totalPaidLate; + this.obligationsMet = obligationsMet; + this.obligationsMetOnDate = obligationsMetOnDate; + } + + public static RecurringDepositScheduleInstallment from(final RecurringDepositAccount account, final Integer installmentNumber, + final Date fromDate, final Date dueDate, final BigDecimal depositAmount, final BigDecimal depositAmountCompleted, + final BigDecimal totalPaidInAdvance, final BigDecimal totalPaidLate, final boolean obligationsMet, + final Date obligationsMetOnDate) { + return new RecurringDepositScheduleInstallment(account, installmentNumber, fromDate, dueDate, depositAmount, + depositAmountCompleted, totalPaidInAdvance, totalPaidLate, obligationsMet, obligationsMetOnDate); + } + + public static RecurringDepositScheduleInstallment installment(final RecurringDepositAccount account, final Integer installmentNumber, + final Date dueDate, final BigDecimal depositAmount) { + + final Date fromDate = null; + final BigDecimal depositAmountCompleted = null; + final BigDecimal totalPaidInAdvance = null; + final BigDecimal totalPaidLate = null; + final boolean obligationsMet = false; + final Date obligationsMetOnDate = null; + + return new RecurringDepositScheduleInstallment(account, installmentNumber, fromDate, dueDate, depositAmount, + depositAmountCompleted, totalPaidInAdvance, totalPaidLate, obligationsMet, obligationsMetOnDate); + } + + private BigDecimal defaultToNullIfZero(final BigDecimal value) { + BigDecimal result = value; + if (BigDecimal.ZERO.compareTo(value) == 0) { + result = null; + } + return result; + } + + public boolean isObligationsMet() { + return this.obligationsMet; + } + + public boolean isNotFullyPaidOff() { + return !this.obligationsMet; + } + + public boolean isPrincipalNotCompleted(final MonetaryCurrency currency) { + return !isPrincipalCompleted(currency); + } + + public boolean isPrincipalCompleted(final MonetaryCurrency currency) { + return getDepositAmountOutstanding(currency).isZero(); + } + + public Money getDepositAmountOutstanding(final MonetaryCurrency currency) { + final Money depositAmountAccountedFor = getDepositAmountCompleted(currency); + return getDepositAmount(currency).minus(depositAmountAccountedFor); + } + + public Money getDepositAmountCompleted(final MonetaryCurrency currency) { + return Money.of(currency, this.depositAmountCompleted); + } + + public Money getDepositAmount(final MonetaryCurrency currency) { + return Money.of(currency, this.depositAmount); + } + + public LocalDate dueDate() { + return (this.dueDate == null) ? null : new LocalDate(this.dueDate); + } + + public Money payInstallment(final LocalDate transactionDate, final Money transactionAmountRemaining) { + + final MonetaryCurrency currency = transactionAmountRemaining.getCurrency(); + Money depositAmountPortionOfTransaction = Money.zero(currency); + + final Money depositAmount = getDepositAmountOutstanding(currency); + if (transactionAmountRemaining.isGreaterThanOrEqualTo(depositAmount)) { + this.depositAmountCompleted = getDepositAmountCompleted(currency).plus(depositAmount).getAmount(); + depositAmountPortionOfTransaction = depositAmountPortionOfTransaction.plus(depositAmount); + } else { + this.depositAmountCompleted = getDepositAmountCompleted(currency).plus(transactionAmountRemaining).getAmount(); + depositAmountPortionOfTransaction = depositAmountPortionOfTransaction.plus(transactionAmountRemaining); + } + + this.depositAmountCompleted = defaultToNullIfZero(this.depositAmountCompleted); + + checkIfInstallmentObligationsAreMet(transactionDate, currency); + + trackAdvanceAndLateTotalsForInstallment(transactionDate, currency, depositAmountPortionOfTransaction); + + return depositAmountPortionOfTransaction; + } + + private void checkIfInstallmentObligationsAreMet(final LocalDate transactionDate, final MonetaryCurrency currency) { + this.obligationsMet = getTotalOutstanding(currency).isZero(); + if (this.obligationsMet) { + this.obligationsMetOnDate = transactionDate.toDate(); + } + } + + public Money getTotalOutstanding(final MonetaryCurrency currency) { + return getDepositAmountOutstanding(currency); + } + + private void trackAdvanceAndLateTotalsForInstallment(final LocalDate transactionDate, final MonetaryCurrency currency, + final Money amountPaidInInstallment) { + if (isInAdvance(transactionDate)) { + this.totalPaidInAdvance = asMoney(this.totalPaidInAdvance, currency).plus(amountPaidInInstallment).getAmount(); + } else if (isLatePayment(transactionDate)) { + this.totalPaidLate = asMoney(this.totalPaidLate, currency).plus(amountPaidInInstallment).getAmount(); + } + } + + private boolean isInAdvance(final LocalDate transactionDate) { + return transactionDate.isBefore(dueDate()); + } + + private boolean isLatePayment(final LocalDate transactionDate) { + return transactionDate.isAfter(dueDate()); + } + + private Money asMoney(final BigDecimal decimal, final MonetaryCurrency currency) { + return Money.of(currency, decimal); + } + + public void resetDerivedFields(){ + this.depositAmountCompleted = null; + this.totalPaidInAdvance = null; + this.totalPaidLate = null; + this.obligationsMet = false; + this.obligationsMetOnDate = null; + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java index 906de0c8a..4fce7eed8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccount.java @@ -82,6 +82,7 @@ import org.mifosplatform.portfolio.savings.SavingsPostingInterestPeriodType; import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionDTO; import org.mifosplatform.portfolio.savings.domain.interest.PostingPeriod; import org.mifosplatform.portfolio.savings.exception.InsufficientAccountBalanceException; +import org.mifosplatform.portfolio.savings.exception.SavingsAccountTransactionNotFoundException; import org.mifosplatform.portfolio.savings.exception.SavingsActivityPriorToClientTransferException; import org.mifosplatform.portfolio.savings.exception.SavingsTransferTransactionsCannotBeUndoneException; import org.mifosplatform.portfolio.savings.service.SavingsEnumerations; @@ -583,13 +584,16 @@ public class SavingsAccount extends AbstractPersistable { if (isTransactionsModified) { accountTransactionsSorted = retreiveListOfTransactions(); } - // loop over transactions in reverse + resetAccountTransactionsEndOfDayBalances(accountTransactionsSorted, interestPostingUpToDate); + } + + protected void resetAccountTransactionsEndOfDayBalances(final List accountTransactionsSorted, final LocalDate interestPostingUpToDate) { + // loop over transactions in reverse LocalDate endOfBalanceDate = interestPostingUpToDate; for (int i = accountTransactionsSorted.size() - 1; i >= 0; i--) { final SavingsAccountTransaction transaction = accountTransactionsSorted.get(i); if (transaction.isNotReversed() && !transaction.isInterestPostingAndNotReversed()) { transaction.updateCumulativeBalanceAndDates(this.currency, endOfBalanceDate); - // this transactions transaction date is end of balance date for // previous transaction. endOfBalanceDate = transaction.transactionLocalDate().minusDays(1); @@ -598,11 +602,12 @@ public class SavingsAccount extends AbstractPersistable { } public SavingsAccountTransaction deposit(final SavingsAccountTransactionDTO transactionDTO) { - + final String resourceTypeName = depositAccountType().resourceName(); if (isNotActive()) { final String defaultUserMessage = "Transaction is not allowed. Account is not active."; - final ApiParameterError error = ApiParameterError.parameterError("error.msg.savingsaccount.transaction.account.is.not.active", - defaultUserMessage, "transactionDate", transactionDTO.getTransactionDate().toString(transactionDTO.getFormatter())); + final ApiParameterError error = ApiParameterError.parameterError("error.msg." + resourceTypeName + + ".transaction.account.is.not.active", defaultUserMessage, "transactionDate", transactionDTO.getTransactionDate() + .toString(transactionDTO.getFormatter())); final List dataValidationErrors = new ArrayList(); dataValidationErrors.add(error); @@ -612,7 +617,7 @@ public class SavingsAccount extends AbstractPersistable { if (isDateInTheFuture(transactionDTO.getTransactionDate())) { final String defaultUserMessage = "Transaction date cannot be in the future."; - final ApiParameterError error = ApiParameterError.parameterError("error.msg.savingsaccount.transaction.in.the.future", + final ApiParameterError error = ApiParameterError.parameterError("error.msg." + resourceTypeName + ".transaction.in.the.future", defaultUserMessage, "transactionDate", transactionDTO.getTransactionDate().toString(transactionDTO.getFormatter())); final List dataValidationErrors = new ArrayList(); @@ -625,8 +630,8 @@ public class SavingsAccount extends AbstractPersistable { final Object[] defaultUserArgs = Arrays.asList(transactionDTO.getTransactionDate().toString(transactionDTO.getFormatter()), getActivationLocalDate().toString(transactionDTO.getFormatter())).toArray(); final String defaultUserMessage = "Transaction date cannot be before accounts activation date."; - final ApiParameterError error = ApiParameterError.parameterError("error.msg.savingsaccount.transaction.before.activation.date", - defaultUserMessage, "transactionDate", defaultUserArgs); + final ApiParameterError error = ApiParameterError.parameterError("error.msg." + resourceTypeName + + ".transaction.before.activation.date", defaultUserMessage, "transactionDate", defaultUserArgs); final List dataValidationErrors = new ArrayList(); dataValidationErrors.add(error); @@ -785,7 +790,7 @@ public class SavingsAccount extends AbstractPersistable { // final List dataValidationErrors = new ArrayList(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) - .resource(SAVINGS_ACCOUNT_RESOURCE_NAME + transactionAction); + .resource(depositAccountType().resourceName() + transactionAction); if (this.allowOverdraft) { Money limit = runningBalance.zero(); @@ -803,7 +808,7 @@ public class SavingsAccount extends AbstractPersistable { } } - private boolean isAccountLocked(final LocalDate transactionDate) { + protected boolean isAccountLocked(final LocalDate transactionDate) { boolean isLocked = false; final boolean accountHasLockedInSetting = this.lockedInUntilDate != null; if (accountHasLockedInSetting) { @@ -1308,24 +1313,20 @@ public class SavingsAccount extends AbstractPersistable { } } - if (transactionToUndo == null) { - // throw non found exception - - } else { - validateAttemptToUndoTransferRelatedTransactions(transactionToUndo); - validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_UNDO_TRANSACTION, - transactionToUndo.transactionLocalDate()); - transactionToUndo.reverse(); - if (transactionToUndo.isChargeTransaction() || transactionToUndo.isWaiveCharge()) { - // undo charge - final Set chargesPaidBy = transactionToUndo.getSavingsAccountChargesPaid(); - for (final SavingsAccountChargePaidBy savingsAccountChargePaidBy : chargesPaidBy) { - final SavingsAccountCharge chargeToUndo = savingsAccountChargePaidBy.getSavingsAccountCharge(); - if (transactionToUndo.isChargeTransaction()) { - chargeToUndo.undoPayment(this.getCurrency(), transactionToUndo.getAmount(this.getCurrency())); - } else if (transactionToUndo.isWaiveCharge()) { - chargeToUndo.undoWaiver(this.getCurrency(), transactionToUndo.getAmount(this.getCurrency())); - } + if (transactionToUndo == null) { throw new SavingsAccountTransactionNotFoundException(this.getId(), transactionId); } + + validateAttemptToUndoTransferRelatedTransactions(transactionToUndo); + validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_UNDO_TRANSACTION, transactionToUndo.transactionLocalDate()); + transactionToUndo.reverse(); + if (transactionToUndo.isChargeTransaction() || transactionToUndo.isWaiveCharge()) { + // undo charge + final Set chargesPaidBy = transactionToUndo.getSavingsAccountChargesPaid(); + for (final SavingsAccountChargePaidBy savingsAccountChargePaidBy : chargesPaidBy) { + final SavingsAccountCharge chargeToUndo = savingsAccountChargePaidBy.getSavingsAccountCharge(); + if (transactionToUndo.isChargeTransaction()) { + chargeToUndo.undoPayment(this.getCurrency(), transactionToUndo.getAmount(this.getCurrency())); + } else if (transactionToUndo.isWaiveCharge()) { + chargeToUndo.undoWaiver(this.getCurrency(), transactionToUndo.getAmount(this.getCurrency())); } } } @@ -1478,7 +1479,7 @@ public class SavingsAccount extends AbstractPersistable { final List dataValidationErrors = new ArrayList(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) - .resource(SAVINGS_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.activateAction); + .resource(depositAccountType().resourceName() + SavingsApiConstants.activateAction); final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status); if (!SavingsAccountStatusType.APPROVED.hasStateOf(currentStatus)) { @@ -2043,4 +2044,10 @@ public class SavingsAccount extends AbstractPersistable { protected boolean isTransferInterestToOtherAccount() { return false; } + + public boolean accountSubmittedAndActivationOnSameDate() { + if (getSubmittedOnLocalDate() == null || getActivationLocalDate() == null) { return false; } + return getActivationLocalDate().isEqual(getSubmittedOnLocalDate()); + + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java index a437cca99..868dd25fb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsAccountAssembler.java @@ -5,8 +5,8 @@ */ package org.mifosplatform.portfolio.savings.domain; -import static org.mifosplatform.portfolio.savings.SavingsApiConstants.accountNoParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME; +import static org.mifosplatform.portfolio.savings.SavingsApiConstants.accountNoParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.allowOverdraftParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.clientIdParamName; import static org.mifosplatform.portfolio.savings.SavingsApiConstants.externalIdParamName; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProduct.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProduct.java index 70ff25412..62ea84add 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProduct.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/SavingsProduct.java @@ -215,7 +215,7 @@ public class SavingsProduct extends AbstractPersistable { } public BigDecimal nominalAnnualInterestRate() { - return Money.of(this.currency, this.nominalAnnualInterestRate).getAmount(); + return this.nominalAnnualInterestRate; } public SavingsCompoundingInterestPeriodType interestCompoundingPeriodType() { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/interest/EndOfDayBalance.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/interest/EndOfDayBalance.java index 17496966e..cd2e53b54 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/interest/EndOfDayBalance.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/interest/EndOfDayBalance.java @@ -6,7 +6,6 @@ import java.math.RoundingMode; import org.joda.time.LocalDate; import org.mifosplatform.infrastructure.core.domain.LocalDateInterval; -import org.mifosplatform.infrastructure.core.service.DateUtils; import org.mifosplatform.organisation.monetary.domain.Money; public class EndOfDayBalance { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/interest/MonthlyCompoundingPeriod.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/interest/MonthlyCompoundingPeriod.java index ee97e203a..ce13ac38d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/interest/MonthlyCompoundingPeriod.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/domain/interest/MonthlyCompoundingPeriod.java @@ -118,6 +118,8 @@ public class MonthlyCompoundingPeriod implements CompoundingPeriod { // break; case INVALID: break; + default: + break; } interestEarned = interestEarned.add(interestOnBalanceUnrounded); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CloseDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/ActivateFixedDepositAccountCommandHandler.java similarity index 76% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CloseDepositAccountCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/ActivateFixedDepositAccountCommandHandler.java index d17fce265..e3bac5932 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CloseDepositAccountCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/ActivateFixedDepositAccountCommandHandler.java @@ -14,18 +14,18 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class CloseDepositAccountCommandHandler implements NewCommandSourceHandler { +public class ActivateFixedDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; @Autowired - public CloseDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + public ActivateFixedDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.close(command.entityId(), command, command.depositAccounttype()); + return this.depositAccountWritePlatformService.activateFDAccount(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CalculateInterestDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/ActivateRecurringDepositAccountCommandHandler.java similarity index 82% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CalculateInterestDepositAccountCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/ActivateRecurringDepositAccountCommandHandler.java index 150d8d0fc..45943223b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CalculateInterestDepositAccountCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/ActivateRecurringDepositAccountCommandHandler.java @@ -14,18 +14,18 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class CalculateInterestDepositAccountCommandHandler implements NewCommandSourceHandler { +public class ActivateRecurringDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; @Autowired - public CalculateInterestDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + public ActivateRecurringDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.calculateInterest(command.entityId(), command.depositAccounttype()); + return this.depositAccountWritePlatformService.activateRDAccount(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CalculateInterestFixedDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CalculateInterestFixedDepositAccountCommandHandler.java new file mode 100644 index 000000000..1e1f79296 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CalculateInterestFixedDepositAccountCommandHandler.java @@ -0,0 +1,32 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; +import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class CalculateInterestFixedDepositAccountCommandHandler implements NewCommandSourceHandler { + + private final DepositAccountWritePlatformService depositAccountWritePlatformService; + + @Autowired + public CalculateInterestFixedDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.calculateInterest(command.entityId(), DepositAccountType.FIXED_DEPOSIT); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CalculateInterestRecurringDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CalculateInterestRecurringDepositAccountCommandHandler.java new file mode 100644 index 000000000..4d46f30f1 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CalculateInterestRecurringDepositAccountCommandHandler.java @@ -0,0 +1,32 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; +import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class CalculateInterestRecurringDepositAccountCommandHandler implements NewCommandSourceHandler { + + private final DepositAccountWritePlatformService depositAccountWritePlatformService; + + @Autowired + public CalculateInterestRecurringDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.calculateInterest(command.entityId(), DepositAccountType.RECURRING_DEPOSIT); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountDepositCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CloseFixedDepositAccountCommandHandler.java similarity index 75% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountDepositCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CloseFixedDepositAccountCommandHandler.java index 74da4561c..05da4dda2 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountDepositCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CloseFixedDepositAccountCommandHandler.java @@ -14,18 +14,18 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DepositAccountDepositCommandHandler implements NewCommandSourceHandler { +public class CloseFixedDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; @Autowired - public DepositAccountDepositCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + public CloseFixedDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.deposit(command.entityId(), command, command.depositAccounttype()); + return this.depositAccountWritePlatformService.closeFDAccount(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PrematureCloseDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CloseRecurringDepositAccountCommandHandler.java similarity index 81% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PrematureCloseDepositAccountCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CloseRecurringDepositAccountCommandHandler.java index f2e794faf..f4ed5ac6d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PrematureCloseDepositAccountCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/CloseRecurringDepositAccountCommandHandler.java @@ -14,18 +14,18 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class PrematureCloseDepositAccountCommandHandler implements NewCommandSourceHandler { +public class CloseRecurringDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; @Autowired - public PrematureCloseDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + public CloseRecurringDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.prematureClose(command.entityId(), command, command.depositAccounttype()); + return this.depositAccountWritePlatformService.closeRDAccount(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationApprovalCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationApprovalCommandHandler.java similarity index 80% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationApprovalCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationApprovalCommandHandler.java index 2ed8a133d..a8c17b9d4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationApprovalCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationApprovalCommandHandler.java @@ -8,18 +8,19 @@ package org.mifosplatform.portfolio.savings.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DepositAccountApplicationApprovalCommandHandler implements NewCommandSourceHandler { +public class FixedDepositAccountApplicationApprovalCommandHandler implements NewCommandSourceHandler { private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; @Autowired - public DepositAccountApplicationApprovalCommandHandler( + public FixedDepositAccountApplicationApprovalCommandHandler( final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @@ -27,6 +28,6 @@ public class DepositAccountApplicationApprovalCommandHandler implements NewComma @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.approveApplication(command.entityId(), command, command.depositAccounttype()); + return this.depositAccountWritePlatformService.approveApplication(command.entityId(), command, DepositAccountType.FIXED_DEPOSIT); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationApprovalUndoCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationApprovalUndoCommandHandler.java similarity index 79% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationApprovalUndoCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationApprovalUndoCommandHandler.java index 7766a24ad..e191e01b1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationApprovalUndoCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationApprovalUndoCommandHandler.java @@ -8,18 +8,19 @@ package org.mifosplatform.portfolio.savings.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DepositAccountApplicationApprovalUndoCommandHandler implements NewCommandSourceHandler { +public class FixedDepositAccountApplicationApprovalUndoCommandHandler implements NewCommandSourceHandler { private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; @Autowired - public DepositAccountApplicationApprovalUndoCommandHandler( + public FixedDepositAccountApplicationApprovalUndoCommandHandler( final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @@ -27,6 +28,6 @@ public class DepositAccountApplicationApprovalUndoCommandHandler implements NewC @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.undoApplicationApproval(command.entityId(), command, command.depositAccounttype()); + return this.depositAccountWritePlatformService.undoApplicationApproval(command.entityId(), command, DepositAccountType.FIXED_DEPOSIT); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationDeletionCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationDeletionCommandHandler.java similarity index 80% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationDeletionCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationDeletionCommandHandler.java index 6fb850777..9d3709891 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationDeletionCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationDeletionCommandHandler.java @@ -8,18 +8,19 @@ package org.mifosplatform.portfolio.savings.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DepositAccountApplicationDeletionCommandHandler implements NewCommandSourceHandler { +public class FixedDepositAccountApplicationDeletionCommandHandler implements NewCommandSourceHandler { private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; @Autowired - public DepositAccountApplicationDeletionCommandHandler( + public FixedDepositAccountApplicationDeletionCommandHandler( final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @@ -27,6 +28,6 @@ public class DepositAccountApplicationDeletionCommandHandler implements NewComma @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.deleteApplication(command.entityId(), command.depositAccounttype()); + return this.depositAccountWritePlatformService.deleteApplication(command.entityId(), DepositAccountType.FIXED_DEPOSIT); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationModificationCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationModificationCommandHandler.java new file mode 100644 index 000000000..11da4baa8 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationModificationCommandHandler.java @@ -0,0 +1,32 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class FixedDepositAccountApplicationModificationCommandHandler implements NewCommandSourceHandler { + + private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; + + @Autowired + public FixedDepositAccountApplicationModificationCommandHandler( + final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.modifyFDApplication(command.entityId(), command); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationRejectedCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationRejectedCommandHandler.java similarity index 80% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationRejectedCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationRejectedCommandHandler.java index 7776e2da3..95b7af027 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationRejectedCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationRejectedCommandHandler.java @@ -8,18 +8,19 @@ package org.mifosplatform.portfolio.savings.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DepositAccountApplicationRejectedCommandHandler implements NewCommandSourceHandler { +public class FixedDepositAccountApplicationRejectedCommandHandler implements NewCommandSourceHandler { private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; @Autowired - public DepositAccountApplicationRejectedCommandHandler( + public FixedDepositAccountApplicationRejectedCommandHandler( final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @@ -27,6 +28,6 @@ public class DepositAccountApplicationRejectedCommandHandler implements NewComma @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.rejectApplication(command.entityId(), command, command.depositAccounttype()); + return this.depositAccountWritePlatformService.rejectApplication(command.entityId(), command, DepositAccountType.FIXED_DEPOSIT); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationSubmittalCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationSubmittalCommandHandler.java similarity index 81% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationSubmittalCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationSubmittalCommandHandler.java index 4d440bf76..315acbc12 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationSubmittalCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationSubmittalCommandHandler.java @@ -14,12 +14,12 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DepositAccountApplicationSubmittalCommandHandler implements NewCommandSourceHandler { +public class FixedDepositAccountApplicationSubmittalCommandHandler implements NewCommandSourceHandler { private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; @Autowired - public DepositAccountApplicationSubmittalCommandHandler( + public FixedDepositAccountApplicationSubmittalCommandHandler( final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @@ -27,6 +27,6 @@ public class DepositAccountApplicationSubmittalCommandHandler implements NewComm @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.submitApplication(command, command.depositAccounttype()); + return this.depositAccountWritePlatformService.submitFDApplication(command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationWithdrawnByApplicantCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationWithdrawnByApplicantCommandHandler.java similarity index 80% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationWithdrawnByApplicantCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationWithdrawnByApplicantCommandHandler.java index 490af5aee..ad4dca739 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationWithdrawnByApplicantCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountApplicationWithdrawnByApplicantCommandHandler.java @@ -8,18 +8,19 @@ package org.mifosplatform.portfolio.savings.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DepositAccountApplicationWithdrawnByApplicantCommandHandler implements NewCommandSourceHandler { +public class FixedDepositAccountApplicationWithdrawnByApplicantCommandHandler implements NewCommandSourceHandler { private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; @Autowired - public DepositAccountApplicationWithdrawnByApplicantCommandHandler( + public FixedDepositAccountApplicationWithdrawnByApplicantCommandHandler( final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @@ -28,6 +29,6 @@ public class DepositAccountApplicationWithdrawnByApplicantCommandHandler impleme @Override public CommandProcessingResult processCommand(final JsonCommand command) { return this.depositAccountWritePlatformService.applicantWithdrawsFromApplication(command.entityId(), command, - command.depositAccounttype()); + DepositAccountType.FIXED_DEPOSIT); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PostInterestDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountDepositCommandHandler.java similarity index 82% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PostInterestDepositAccountCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountDepositCommandHandler.java index ddf850ad2..d52e6f09e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PostInterestDepositAccountCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositAccountDepositCommandHandler.java @@ -14,18 +14,18 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class PostInterestDepositAccountCommandHandler implements NewCommandSourceHandler { +public class FixedDepositAccountDepositCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; @Autowired - public PostInterestDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + public FixedDepositAccountDepositCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.postInterest(command.entityId(), command.depositAccounttype()); + return this.depositAccountWritePlatformService.depositToFDAccount(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositTransactionAdjustmentCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositTransactionAdjustmentCommandHandler.java similarity index 74% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositTransactionAdjustmentCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositTransactionAdjustmentCommandHandler.java index 5e879301f..7cfb3e77a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositTransactionAdjustmentCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/FixedDepositTransactionAdjustmentCommandHandler.java @@ -14,12 +14,12 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DepositTransactionAdjustmentCommandHandler implements NewCommandSourceHandler { +public class FixedDepositTransactionAdjustmentCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; @Autowired - public DepositTransactionAdjustmentCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + public FixedDepositTransactionAdjustmentCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @@ -27,7 +27,6 @@ public class DepositTransactionAdjustmentCommandHandler implements NewCommandSou @Override public CommandProcessingResult processCommand(final JsonCommand command) { final Long transactionId = Long.valueOf(command.getTransactionId()); - return this.depositAccountWritePlatformService.adjustDepositTransaction(command.entityId(), transactionId, command, - command.depositAccounttype()); + return this.depositAccountWritePlatformService.adjustFDTransaction(command.entityId(), transactionId, command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PostInterestFixedDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PostInterestFixedDepositAccountCommandHandler.java new file mode 100644 index 000000000..7df5b4304 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PostInterestFixedDepositAccountCommandHandler.java @@ -0,0 +1,32 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; +import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class PostInterestFixedDepositAccountCommandHandler implements NewCommandSourceHandler { + + private final DepositAccountWritePlatformService depositAccountWritePlatformService; + + @Autowired + public PostInterestFixedDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.postInterest(command.entityId(), DepositAccountType.FIXED_DEPOSIT); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PostInterestRecurringDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PostInterestRecurringDepositAccountCommandHandler.java new file mode 100644 index 000000000..cf76ea9eb --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PostInterestRecurringDepositAccountCommandHandler.java @@ -0,0 +1,32 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; +import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class PostInterestRecurringDepositAccountCommandHandler implements NewCommandSourceHandler { + + private final DepositAccountWritePlatformService depositAccountWritePlatformService; + + @Autowired + public PostInterestRecurringDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.postInterest(command.entityId(), DepositAccountType.RECURRING_DEPOSIT); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PrematureCloseFixedDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PrematureCloseFixedDepositAccountCommandHandler.java new file mode 100644 index 000000000..a3ba3e1af --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PrematureCloseFixedDepositAccountCommandHandler.java @@ -0,0 +1,31 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class PrematureCloseFixedDepositAccountCommandHandler implements NewCommandSourceHandler { + + private final DepositAccountWritePlatformService depositAccountWritePlatformService; + + @Autowired + public PrematureCloseFixedDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.prematureCloseFDAccount(command.entityId(), command); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PrematureCloseRecurringDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PrematureCloseRecurringDepositAccountCommandHandler.java new file mode 100644 index 000000000..e3e1c6556 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/PrematureCloseRecurringDepositAccountCommandHandler.java @@ -0,0 +1,31 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class PrematureCloseRecurringDepositAccountCommandHandler implements NewCommandSourceHandler { + + private final DepositAccountWritePlatformService depositAccountWritePlatformService; + + @Autowired + public PrematureCloseRecurringDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.prematureCloseRDAccount(command.entityId(), command); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationApprovalCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationApprovalCommandHandler.java new file mode 100644 index 000000000..03a94c5c3 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationApprovalCommandHandler.java @@ -0,0 +1,33 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; +import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class RecurringDepositAccountApplicationApprovalCommandHandler implements NewCommandSourceHandler { + + private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; + + @Autowired + public RecurringDepositAccountApplicationApprovalCommandHandler( + final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.approveApplication(command.entityId(), command, DepositAccountType.RECURRING_DEPOSIT); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationApprovalUndoCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationApprovalUndoCommandHandler.java new file mode 100644 index 000000000..c94b56446 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationApprovalUndoCommandHandler.java @@ -0,0 +1,33 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; +import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class RecurringDepositAccountApplicationApprovalUndoCommandHandler implements NewCommandSourceHandler { + + private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; + + @Autowired + public RecurringDepositAccountApplicationApprovalUndoCommandHandler( + final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.undoApplicationApproval(command.entityId(), command, DepositAccountType.RECURRING_DEPOSIT); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationModificationCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationDeletionCommandHandler.java similarity index 76% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationModificationCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationDeletionCommandHandler.java index e2fcde8bb..a486c2ce7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/DepositAccountApplicationModificationCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationDeletionCommandHandler.java @@ -8,18 +8,19 @@ package org.mifosplatform.portfolio.savings.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DepositAccountApplicationModificationCommandHandler implements NewCommandSourceHandler { +public class RecurringDepositAccountApplicationDeletionCommandHandler implements NewCommandSourceHandler { private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; @Autowired - public DepositAccountApplicationModificationCommandHandler( + public RecurringDepositAccountApplicationDeletionCommandHandler( final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @@ -27,6 +28,6 @@ public class DepositAccountApplicationModificationCommandHandler implements NewC @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.modifyApplication(command.entityId(), command, command.depositAccounttype()); + return this.depositAccountWritePlatformService.deleteApplication(command.entityId(), DepositAccountType.RECURRING_DEPOSIT); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationModificationCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationModificationCommandHandler.java new file mode 100644 index 000000000..101402ff8 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationModificationCommandHandler.java @@ -0,0 +1,32 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class RecurringDepositAccountApplicationModificationCommandHandler implements NewCommandSourceHandler { + + private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; + + @Autowired + public RecurringDepositAccountApplicationModificationCommandHandler( + final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.modifyRDApplication(command.entityId(), command); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationRejectedCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationRejectedCommandHandler.java new file mode 100644 index 000000000..885074425 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationRejectedCommandHandler.java @@ -0,0 +1,33 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; +import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class RecurringDepositAccountApplicationRejectedCommandHandler implements NewCommandSourceHandler { + + private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; + + @Autowired + public RecurringDepositAccountApplicationRejectedCommandHandler( + final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.rejectApplication(command.entityId(), command, DepositAccountType.RECURRING_DEPOSIT); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationSubmittalCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationSubmittalCommandHandler.java new file mode 100644 index 000000000..71c8eb33f --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationSubmittalCommandHandler.java @@ -0,0 +1,32 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class RecurringDepositAccountApplicationSubmittalCommandHandler implements NewCommandSourceHandler { + + private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; + + @Autowired + public RecurringDepositAccountApplicationSubmittalCommandHandler( + final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.submitRDApplication(command); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationWithdrawnByApplicantCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationWithdrawnByApplicantCommandHandler.java new file mode 100644 index 000000000..a33d4a797 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountApplicationWithdrawnByApplicantCommandHandler.java @@ -0,0 +1,34 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; +import org.mifosplatform.portfolio.savings.service.DepositApplicationProcessWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class RecurringDepositAccountApplicationWithdrawnByApplicantCommandHandler implements NewCommandSourceHandler { + + private final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService; + + @Autowired + public RecurringDepositAccountApplicationWithdrawnByApplicantCommandHandler( + final DepositApplicationProcessWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + return this.depositAccountWritePlatformService.applicantWithdrawsFromApplication(command.entityId(), command, + DepositAccountType.RECURRING_DEPOSIT); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/ActivateDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountDepositCommandHandler.java similarity index 75% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/ActivateDepositAccountCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountDepositCommandHandler.java index 2d6311210..b24118934 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/ActivateDepositAccountCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositAccountDepositCommandHandler.java @@ -14,18 +14,18 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class ActivateDepositAccountCommandHandler implements NewCommandSourceHandler { +public class RecurringDepositAccountDepositCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; @Autowired - public ActivateDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + public RecurringDepositAccountDepositCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.activate(command.entityId(), command, command.depositAccounttype()); + return this.depositAccountWritePlatformService.depositToRDAccount(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositTransactionAdjustmentCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositTransactionAdjustmentCommandHandler.java new file mode 100644 index 000000000..68c0a3804 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/RecurringDepositTransactionAdjustmentCommandHandler.java @@ -0,0 +1,32 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class RecurringDepositTransactionAdjustmentCommandHandler implements NewCommandSourceHandler { + + private final DepositAccountWritePlatformService depositAccountWritePlatformService; + + @Autowired + public RecurringDepositTransactionAdjustmentCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + final Long transactionId = Long.valueOf(command.getTransactionId()); + return this.depositAccountWritePlatformService.adjustRDTransaction(command.entityId(), transactionId, command); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/UndoTransactionFixedDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/UndoTransactionFixedDepositAccountCommandHandler.java new file mode 100644 index 000000000..72e4e4b61 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/UndoTransactionFixedDepositAccountCommandHandler.java @@ -0,0 +1,32 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class UndoTransactionFixedDepositAccountCommandHandler implements NewCommandSourceHandler { + + private final DepositAccountWritePlatformService depositAccountWritePlatformService; + + @Autowired + public UndoTransactionFixedDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + final Long transactionId = Long.valueOf(command.getTransactionId()); + return this.depositAccountWritePlatformService.undoFDTransaction(command.entityId(), transactionId, false); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/UndoTransactionRecurringDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/UndoTransactionRecurringDepositAccountCommandHandler.java new file mode 100644 index 000000000..10d1e50f6 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/UndoTransactionRecurringDepositAccountCommandHandler.java @@ -0,0 +1,32 @@ +/** + * 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.savings.handler; + +import org.mifosplatform.commands.handler.NewCommandSourceHandler; +import org.mifosplatform.infrastructure.core.api.JsonCommand; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class UndoTransactionRecurringDepositAccountCommandHandler implements NewCommandSourceHandler { + + private final DepositAccountWritePlatformService depositAccountWritePlatformService; + + @Autowired + public UndoTransactionRecurringDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + this.depositAccountWritePlatformService = depositAccountWritePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + final Long transactionId = Long.valueOf(command.getTransactionId()); + return this.depositAccountWritePlatformService.undoRDTransaction(command.entityId(), transactionId, false); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/UndoTransactionDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/WithdrawalFixedDepositAccountCommandHandler.java similarity index 76% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/UndoTransactionDepositAccountCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/WithdrawalFixedDepositAccountCommandHandler.java index 10f3b7234..e133f64f5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/UndoTransactionDepositAccountCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/WithdrawalFixedDepositAccountCommandHandler.java @@ -8,26 +8,25 @@ package org.mifosplatform.portfolio.savings.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class UndoTransactionDepositAccountCommandHandler implements NewCommandSourceHandler { +public class WithdrawalFixedDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; @Autowired - public UndoTransactionDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + public WithdrawalFixedDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - final Long transactionId = Long.valueOf(command.getTransactionId()); - return this.depositAccountWritePlatformService.undoTransaction(command.entityId(), transactionId, false, - command.depositAccounttype()); + return this.depositAccountWritePlatformService.withdrawal(command.entityId(), command, DepositAccountType.FIXED_DEPOSIT); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/WithdrawDepositAccountCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/WithdrawalRecurringDepositAccountCommandHandler.java similarity index 75% rename from mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/WithdrawDepositAccountCommandHandler.java rename to mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/WithdrawalRecurringDepositAccountCommandHandler.java index 658a392a1..129edfc79 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/WithdrawDepositAccountCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/handler/WithdrawalRecurringDepositAccountCommandHandler.java @@ -8,24 +8,25 @@ package org.mifosplatform.portfolio.savings.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.service.DepositAccountWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class WithdrawDepositAccountCommandHandler implements NewCommandSourceHandler { +public class WithdrawalRecurringDepositAccountCommandHandler implements NewCommandSourceHandler { private final DepositAccountWritePlatformService depositAccountWritePlatformService; @Autowired - public WithdrawDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { + public WithdrawalRecurringDepositAccountCommandHandler(final DepositAccountWritePlatformService depositAccountWritePlatformService) { this.depositAccountWritePlatformService = depositAccountWritePlatformService; } @Transactional @Override public CommandProcessingResult processCommand(final JsonCommand command) { - return this.depositAccountWritePlatformService.withdrawal(command.entityId(), command, command.depositAccounttype()); + return this.depositAccountWritePlatformService.withdrawal(command.entityId(), command, DepositAccountType.RECURRING_DEPOSIT); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountInterestRateChartReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountInterestRateChartReadPlatformServiceImpl.java index 3294a6216..19dffb713 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountInterestRateChartReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountInterestRateChartReadPlatformServiceImpl.java @@ -18,7 +18,7 @@ import org.mifosplatform.infrastructure.core.domain.JdbcSupport; import org.mifosplatform.infrastructure.core.service.RoutingDataSource; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.data.CurrencyData; -import org.mifosplatform.portfolio.interestratechart.InterestRateChartPeriodType; +import org.mifosplatform.portfolio.common.domain.PeriodFrequencyType; import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartDropdownReadPlatformService; import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartEnumerations; import org.mifosplatform.portfolio.savings.data.DepositAccountInterestRateChartData; @@ -114,6 +114,8 @@ public class DepositAccountInterestRateChartReadPlatformServiceImpl implements D .append("ircd.id as ircdId, ircd.description as ircdDescription, ircd.period_type_enum ircdPeriodTypeId, ") .append("ircd.from_period as ircdFromPeriod, ircd.to_period as ircdToPeriod, ircd.amount_range_from as ircdAmountRangeFrom, ") .append("ircd.amount_range_to as ircdAmountRangeTo, ircd.annual_interest_rate as ircdAnnualInterestRate, ") + .append("ircd.interest_rate_for_female as ircdInterestRateForFemale, ircd.interest_rate_for_children as ircdInterestRateForChildren, ") + .append("ircd.interest_rate_for_senior_citizen as ircdInterestRateForSeniorCitizen, ") .append("curr.code as currencyCode, curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, ") .append("curr.display_symbol as currencyDisplaySymbol, curr.decimal_places as currencyDigits, curr.currency_multiplesof as inMultiplesOf, ") .append("sa.id as accountId, sa.account_no as accountNumber ") @@ -183,9 +185,9 @@ public class DepositAccountInterestRateChartReadPlatformServiceImpl implements D final LocalDate endDate = JdbcSupport.getLocalDate(rs, "ircEndDate"); final Long accountId = rs.getLong("accountId"); final String accountNumber = rs.getString("accountNumber"); - final Collection periodTypes = InterestRateChartEnumerations.periodType(InterestRateChartPeriodType.values()); - return DepositAccountInterestRateChartData.instance(id, name, description, fromDate, endDate, accountId, accountNumber, - null, periodTypes); + final Collection periodTypes = InterestRateChartEnumerations.periodType(PeriodFrequencyType.values()); + return DepositAccountInterestRateChartData.instance(id, name, description, fromDate, endDate, accountId, accountNumber, null, + periodTypes); } } @@ -231,6 +233,9 @@ public class DepositAccountInterestRateChartReadPlatformServiceImpl implements D final BigDecimal amountRangeFrom = rs.getBigDecimal("ircdAmountRangeFrom"); final BigDecimal amountRangeTo = rs.getBigDecimal("ircdAmountRangeTo"); final BigDecimal annualInterestRate = rs.getBigDecimal("ircdAnnualInterestRate"); + final BigDecimal interestRateForFemale = rs.getBigDecimal("ircdInterestRateForFemale"); + final BigDecimal interestRateForChildren = rs.getBigDecimal("ircdInterestRateForChildren"); + final BigDecimal interestRateForSeniorCitizen = rs.getBigDecimal("ircdInterestRateForSeniorCitizen"); // currency Slabs final String currencyCode = rs.getString("currencyCode"); @@ -244,7 +249,8 @@ public class DepositAccountInterestRateChartReadPlatformServiceImpl implements D currencyDisplaySymbol, currencyNameCode); return DepositAccountInterestRateChartSlabData.instance(id, description, periodType, fromPeriod, toPeriod, amountRangeFrom, - amountRangeTo, annualInterestRate, currency); + amountRangeTo, annualInterestRate, interestRateForFemale, interestRateForChildren, interestRateForSeniorCitizen, + currency); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountReadPlatformServiceImpl.java index 088be592e..b91a18d61 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountReadPlatformServiceImpl.java @@ -18,7 +18,6 @@ import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.data.PaginationParameters; import org.mifosplatform.infrastructure.core.data.PaginationParametersDataValidator; import org.mifosplatform.infrastructure.core.domain.JdbcSupport; -import org.mifosplatform.infrastructure.core.service.DateUtils; import org.mifosplatform.infrastructure.core.service.Page; import org.mifosplatform.infrastructure.core.service.PaginationHelper; import org.mifosplatform.infrastructure.core.service.RoutingDataSource; @@ -30,14 +29,20 @@ import org.mifosplatform.portfolio.account.PortfolioAccountType; import org.mifosplatform.portfolio.account.data.AccountTransferDTO; import org.mifosplatform.portfolio.account.data.AccountTransferData; import org.mifosplatform.portfolio.account.domain.AccountTransferType; +import org.mifosplatform.portfolio.calendar.data.CalendarData; +import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType; +import org.mifosplatform.portfolio.calendar.domain.CalendarFrequencyType; +import org.mifosplatform.portfolio.calendar.service.CalendarReadPlatformService; import org.mifosplatform.portfolio.charge.data.ChargeData; import org.mifosplatform.portfolio.charge.service.ChargeReadPlatformService; import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; +import org.mifosplatform.portfolio.common.domain.PeriodFrequencyType; +import org.mifosplatform.portfolio.common.service.CommonEnumerations; +import org.mifosplatform.portfolio.common.service.DropdownReadPlatformService; import org.mifosplatform.portfolio.group.data.GroupGeneralData; import org.mifosplatform.portfolio.group.service.GroupReadPlatformService; import org.mifosplatform.portfolio.interestratechart.data.InterestRateChartData; -import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartEnumerations; import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartReadPlatformService; import org.mifosplatform.portfolio.paymentdetail.PaymentDetailConstants; import org.mifosplatform.portfolio.paymentdetail.data.PaymentDetailData; @@ -96,6 +101,8 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead private final CodeValueReadPlatformService codeValueReadPlatformService; private final SavingsAccountReadPlatformService savingsAccountReadPlatformService; private final RecurringAccountDepositTransactionTemplateMapper rdTransactionTemplateMapper; + private final DropdownReadPlatformService dropdownReadPlatformService; + private final CalendarReadPlatformService calendarReadPlatformService; @Autowired public DepositAccountReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource, @@ -108,7 +115,8 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final DepositsDropdownReadPlatformService depositsDropdownReadPlatformService, final InterestRateChartReadPlatformService productChartReadPlatformService, final CodeValueReadPlatformService codeValueReadPlatformService, - final SavingsAccountReadPlatformService savingsAccountReadPlatformService) { + final SavingsAccountReadPlatformService savingsAccountReadPlatformService, + final DropdownReadPlatformService dropdownReadPlatformService, final CalendarReadPlatformService calendarReadPlatformService) { this.context = context; this.jdbcTemplate = new JdbcTemplate(dataSource); this.accountChartReadPlatformService = chartReadPlatformService; @@ -125,6 +133,8 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead this.codeValueReadPlatformService = codeValueReadPlatformService; this.savingsAccountReadPlatformService = savingsAccountReadPlatformService; this.rdTransactionTemplateMapper = new RecurringAccountDepositTransactionTemplateMapper(); + this.dropdownReadPlatformService = dropdownReadPlatformService; + this.calendarReadPlatformService = calendarReadPlatformService; } @Override @@ -257,7 +267,14 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead if (depositAccountType.isFixedDeposit()) { depositAccount = FixedDepositAccountData.withInterestChart((FixedDepositAccountData) depositAccount, chart); } else if (depositAccountType.isRecurringDeposit()) { - depositAccount = RecurringDepositAccountData.withInterestChart((RecurringDepositAccountData) depositAccount, chart); + CalendarData calendar = this.calendarReadPlatformService.retrieveCollctionCalendarByEntity(accountId, + CalendarEntityType.SAVINGS.getValue()); + final Integer frequency = calendar.interval() == -1 ? 1 : calendar.interval(); + final CalendarFrequencyType calendarFrequencyType = CalendarFrequencyType.fromInt(calendar.frequencyType().getId().intValue()); + final PeriodFrequencyType periodFrequencyType = CalendarFrequencyType.from(calendarFrequencyType); + final EnumOptionData frequencyType = CommonEnumerations.termFrequencyType(periodFrequencyType, "recurring.deposit.frequency."); + depositAccount = RecurringDepositAccountData.withInterestChartAndRecurringDetails((RecurringDepositAccountData) depositAccount, + chart, frequency, frequencyType); } return depositAccount; @@ -298,21 +315,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final Collection preClosurePenalInterestOnTypeOptions = this.depositsDropdownReadPlatformService .retrievePreClosurePenalInterestOnTypeOptions(); - final Collection interestFreePeriodTypeOptions = this.depositsDropdownReadPlatformService - .retrieveInterestFreePeriodFrequencyTypeOptions(); - - final Collection depositTermTypeOptions = this.depositsDropdownReadPlatformService.retrieveDepositTermTypeOptions(); - - final Collection depositPeriodFrequencyOptions = this.depositsDropdownReadPlatformService - .retrieveDepositTermTypeOptions(); - - final Collection inMultiplesOfDepositTermTypeOptions = this.depositsDropdownReadPlatformService - .retrieveInMultiplesOfDepositTermTypeOptions(); - final Collection recurringDepositTypeOptions = this.depositsDropdownReadPlatformService - .retrieveRecurringDepositTypeOptions(); - final Collection recurringDepositFrequencyTypeOptions = this.depositsDropdownReadPlatformService - .retrieveRecurringDepositFrequencyTypeOptions(); - + final Collection periodFrequencyTypeOptions = this.dropdownReadPlatformService.retrievePeriodFrequencyTypeOptions(); final Collection productOptions = this.depositProductReadPlatformService .retrieveAllForLookup(depositAccountType); DepositAccountData template = null; @@ -385,19 +388,18 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead template = FixedDepositAccountData.withTemplateOptions((FixedDepositAccountData) template, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, - withdrawalFeeTypeOptions, transactions, charges, chargeOptions, interestFreePeriodTypeOptions, - preClosurePenalInterestOnTypeOptions, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - depositPeriodFrequencyOptions, savingsAccountDatas); + withdrawalFeeTypeOptions, transactions, charges, chargeOptions, preClosurePenalInterestOnTypeOptions, + periodFrequencyTypeOptions, savingsAccountDatas); + template = FixedDepositAccountData.withInterestChart((FixedDepositAccountData) template, accountChart); } else if (depositAccountType.isRecurringDeposit()) { - template = RecurringDepositAccountData.withTemplateOptions((RecurringDepositAccountData) template, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, - withdrawalFeeTypeOptions, transactions, charges, chargeOptions, interestFreePeriodTypeOptions, - preClosurePenalInterestOnTypeOptions, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - recurringDepositTypeOptions, recurringDepositFrequencyTypeOptions, depositPeriodFrequencyOptions); - template = RecurringDepositAccountData.withInterestChart((RecurringDepositAccountData) template, accountChart); + withdrawalFeeTypeOptions, transactions, charges, chargeOptions, preClosurePenalInterestOnTypeOptions, + periodFrequencyTypeOptions); + template = RecurringDepositAccountData.withInterestChartAndRecurringDetails((RecurringDepositAccountData) template, + accountChart, null, null); } @@ -435,9 +437,8 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead template = FixedDepositAccountData.withTemplateOptions((FixedDepositAccountData) template, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, - withdrawalFeeTypeOptions, transactions, charges, chargeOptions, interestFreePeriodTypeOptions, - preClosurePenalInterestOnTypeOptions, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - depositPeriodFrequencyOptions, savingsAccountDatas); + withdrawalFeeTypeOptions, transactions, charges, chargeOptions, preClosurePenalInterestOnTypeOptions, + periodFrequencyTypeOptions, savingsAccountDatas); } else if (depositAccountType.isRecurringDeposit()) { template = RecurringDepositAccountData.withClientTemplate(clientId, clientName, groupId, groupName); @@ -445,9 +446,8 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead template = RecurringDepositAccountData.withTemplateOptions((RecurringDepositAccountData) template, productOptions, fieldOfficerOptions, interestCompoundingPeriodTypeOptions, interestPostingPeriodTypeOptions, interestCalculationTypeOptions, interestCalculationDaysInYearTypeOptions, lockinPeriodFrequencyTypeOptions, - withdrawalFeeTypeOptions, transactions, charges, chargeOptions, interestFreePeriodTypeOptions, - preClosurePenalInterestOnTypeOptions, depositTermTypeOptions, inMultiplesOfDepositTermTypeOptions, - recurringDepositTypeOptions, recurringDepositFrequencyTypeOptions, depositPeriodFrequencyOptions); + withdrawalFeeTypeOptions, transactions, charges, chargeOptions, preClosurePenalInterestOnTypeOptions, + periodFrequencyTypeOptions); } } @@ -458,7 +458,8 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead public SavingsAccountTransactionData retrieveRecurringAccountDepositTransactionTemplate(final Long accountId) { try { - final String sql = "select " + this.rdTransactionTemplateMapper.schema() + " where sa.id = ? and sa.deposit_type_enum = ?"; + final String sql = "select " + this.rdTransactionTemplateMapper.schema() + + " where sa.id = ? and sa.deposit_type_enum = ? order by mss.installment limit 1"; return this.jdbcTemplate.queryForObject(sql, this.rdTransactionTemplateMapper, new Object[] { accountId, DepositAccountType.RECURRING_DEPOSIT.getValue() }); @@ -698,11 +699,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final StringBuilder sqlBuilder = new StringBuilder(400); sqlBuilder.append(super.selectFieldsSql()); - sqlBuilder.append(", datp.interest_free_period_applicable as interestFreePeriodApplicable, "); - sqlBuilder.append("datp.interest_free_from_period as interestFreeFromPeriod, "); - sqlBuilder.append("datp.interest_free_to_period as interestFreeToPeriod, "); - sqlBuilder.append("datp.interest_free_period_frequency_enum as interestFreePeriodFrequencyId, "); - sqlBuilder.append("datp.pre_closure_penal_applicable as preClosurePenalApplicable, "); + sqlBuilder.append(", datp.pre_closure_penal_applicable as preClosurePenalApplicable, "); sqlBuilder.append("datp.pre_closure_penal_interest as preClosurePenalInterest, "); sqlBuilder.append("datp.pre_closure_penal_interest_on_enum as preClosurePenalInterestOnId, "); sqlBuilder.append("datp.min_deposit_term as minDepositTerm, "); @@ -733,13 +730,6 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead public FixedDepositAccountData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { final DepositAccountData depositAccountData = super.mapRow(rs); - - final boolean interestFreePeriodApplicable = rs.getBoolean("interestFreePeriodApplicable"); - final Integer interestFreeFromPeriod = JdbcSupport.getInteger(rs, "interestFreeFromPeriod"); - final Integer interestFreeToPeriod = JdbcSupport.getInteger(rs, "interestFreeToPeriod"); - final Integer periodFrequencyTypeId = JdbcSupport.getInteger(rs, "interestFreePeriodFrequencyId"); - final EnumOptionData interestFreePeriodFrequencyType = (periodFrequencyTypeId == null) ? null : InterestRateChartEnumerations - .periodType(periodFrequencyTypeId); final boolean preClosurePenalApplicable = rs.getBoolean("preClosurePenalApplicable"); final BigDecimal preClosurePenalInterest = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "preClosurePenalInterest"); final Integer preClosurePenalInterestOnTypeId = JdbcSupport.getInteger(rs, "preClosurePenalInterestOnId"); @@ -772,8 +762,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead .depositAccountOnClosureType(onAccountClosureId); final Boolean transferInterestToSavings = rs.getBoolean("transferInterestToSavings"); - return FixedDepositAccountData.instance(depositAccountData, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, + return FixedDepositAccountData.instance(depositAccountData, preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestOnType, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, depositPeriod, depositPeriodFrequencyType, onAccountClosureType, transferInterestToSavings); @@ -788,17 +777,16 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final StringBuilder sqlBuilder = new StringBuilder(400); sqlBuilder.append(this.selectFieldsSql()); - sqlBuilder.append(", datp.interest_free_period_applicable as interestFreePeriodApplicable, "); - sqlBuilder.append("datp.interest_free_from_period as interestFreeFromPeriod, "); - sqlBuilder.append("datp.interest_free_to_period as interestFreeToPeriod, "); - sqlBuilder.append("datp.interest_free_period_frequency_enum as interestFreePeriodFrequencyId, "); - sqlBuilder.append("datp.pre_closure_penal_applicable as preClosurePenalApplicable, "); + sqlBuilder.append(", datp.pre_closure_penal_applicable as preClosurePenalApplicable, "); sqlBuilder.append("datp.pre_closure_penal_interest as preClosurePenalInterest, "); sqlBuilder.append("datp.pre_closure_penal_interest_on_enum as preClosurePenalInterestOnId, "); - sqlBuilder.append("dard.recurring_deposit_amount as recurringDepositAmount, "); - sqlBuilder.append("dard.recurring_deposit_type_enum as recurringDepositTypeId, "); - sqlBuilder.append("dard.recurring_deposit_frequency as recurringDepositFrequency, "); - sqlBuilder.append("dard.recurring_deposit_frequency_type_enum as recurringDepositFrequencyTypeId, "); + sqlBuilder.append("dard.mandatory_recommended_deposit_amount as mandatoryRecommendedDepositAmount, "); + sqlBuilder.append("dard.total_overdue_amount as totalOverdueAmount, "); + sqlBuilder.append("dard.no_of_overdue_installments as noOfOverdueInstallments, "); + sqlBuilder.append("dard.is_mandatory as isMandatoryDeposit, "); + sqlBuilder.append("dard.allow_withdrawal as allowWithdrawal, "); + sqlBuilder.append("dard.adjust_advance_towards_future_payments as adjustAdvanceTowardsFuturePayments, "); + sqlBuilder.append("dard.is_calendar_inherited as isCalendarInherited, "); sqlBuilder.append("datp.min_deposit_term as minDepositTerm, "); sqlBuilder.append("datp.max_deposit_term as maxDepositTerm, "); sqlBuilder.append("datp.min_deposit_term_type_enum as minDepositTermTypeId, "); @@ -829,25 +817,11 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final DepositAccountData depositAccountData = super.mapRow(rs); - final boolean interestFreePeriodApplicable = rs.getBoolean("interestFreePeriodApplicable"); - final Integer interestFreeFromPeriod = JdbcSupport.getInteger(rs, "interestFreeFromPeriod"); - final Integer interestFreeToPeriod = JdbcSupport.getInteger(rs, "interestFreeToPeriod"); - final Integer periodFrequencyTypeId = JdbcSupport.getInteger(rs, "interestFreePeriodFrequencyId"); - final EnumOptionData interestFreePeriodFrequencyType = (periodFrequencyTypeId == null) ? null : InterestRateChartEnumerations - .periodType(periodFrequencyTypeId); final boolean preClosurePenalApplicable = rs.getBoolean("preClosurePenalApplicable"); final BigDecimal preClosurePenalInterest = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "preClosurePenalInterest"); final Integer preClosurePenalInterestOnTypeId = JdbcSupport.getInteger(rs, "preClosurePenalInterestOnId"); final EnumOptionData preClosurePenalInterestOnType = (preClosurePenalInterestOnTypeId == null) ? null : SavingsEnumerations .preClosurePenaltyInterestOnType(preClosurePenalInterestOnTypeId); - final Integer recurringDepositTypeId = JdbcSupport.getInteger(rs, "recurringDepositTypeId"); - final EnumOptionData recurringDepositType = (recurringDepositTypeId == null) ? null : SavingsEnumerations - .recurringDepositType(recurringDepositTypeId); - final Integer recurringDepositFrequency = JdbcSupport.getInteger(rs, "recurringDepositFrequency"); - final Integer recurringDepositFrequencyTypeId = JdbcSupport.getInteger(rs, "recurringDepositFrequencyTypeId"); - final EnumOptionData recurringDepositFrequencyType = (recurringDepositFrequencyTypeId == null) ? null : SavingsEnumerations - .recurringDepositFrequencyType(recurringDepositFrequencyTypeId); - final Integer minDepositTerm = JdbcSupport.getInteger(rs, "minDepositTerm"); final Integer maxDepositTerm = JdbcSupport.getInteger(rs, "maxDepositTerm"); final Integer minDepositTermTypeId = JdbcSupport.getInteger(rs, "minDepositTermTypeId"); @@ -868,17 +842,27 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final Integer depositPeriodFrequencyTypeId = JdbcSupport.getInteger(rs, "depositPeriodFrequencyTypeId"); final EnumOptionData depositPeriodFrequencyType = (depositPeriodFrequencyTypeId == null) ? null : SavingsEnumerations .depositPeriodFrequency(depositPeriodFrequencyTypeId); - final BigDecimal recurringDepositAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "recurringDepositAmount"); + final BigDecimal mandatoryRecommendedDepositAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, + "mandatoryRecommendedDepositAmount"); + final BigDecimal totalOverdueAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "totalOverdueAmount"); + final Integer noOfOverdueInstallments = JdbcSupport.getInteger(rs, "noOfOverdueInstallments"); + final boolean isMandatoryDeposit = rs.getBoolean("isMandatoryDeposit"); + final boolean allowWithdrawal = rs.getBoolean("allowWithdrawal"); + final boolean adjustAdvanceTowardsFuturePayments = rs.getBoolean("adjustAdvanceTowardsFuturePayments"); + final boolean isCalendarInherited = rs.getBoolean("isCalendarInherited"); + final Integer onAccountClosureId = JdbcSupport.getInteger(rs, "onAccountClosureId"); final EnumOptionData onAccountClosureType = (onAccountClosureId == null) ? null : SavingsEnumerations .depositAccountOnClosureType(onAccountClosureId); final LocalDate expectedFirstDepositOnDate = JdbcSupport.getLocalDate(rs, "expectedFirstDepositOnDate"); - return RecurringDepositAccountData.instance(depositAccountData, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, + + return RecurringDepositAccountData.instance(depositAccountData, preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestOnType, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, depositPeriod, - depositPeriodFrequencyType, recurringDepositAmount, recurringDepositType, recurringDepositFrequency, - recurringDepositFrequencyType, onAccountClosureType, expectedFirstDepositOnDate); + depositPeriodFrequencyType, mandatoryRecommendedDepositAmount, onAccountClosureType, expectedFirstDepositOnDate, + totalOverdueAmount, noOfOverdueInstallments, isMandatoryDeposit, allowWithdrawal, adjustAdvanceTowardsFuturePayments, + isCalendarInherited); + } } @@ -1143,11 +1127,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final StringBuilder sqlBuilder = new StringBuilder(400); sqlBuilder.append(super.selectFieldsSql()); - sqlBuilder.append(", dptp.interest_free_period_applicable as interestFreePeriodApplicable, "); - sqlBuilder.append("dptp.interest_free_from_period as interestFreeFromPeriod, "); - sqlBuilder.append("dptp.interest_free_to_period as interestFreeToPeriod, "); - sqlBuilder.append("dptp.interest_free_period_frequency_enum as interestFreePeriodFrequencyId, "); - sqlBuilder.append("dptp.pre_closure_penal_applicable as preClosurePenalApplicable, "); + sqlBuilder.append(", dptp.pre_closure_penal_applicable as preClosurePenalApplicable, "); sqlBuilder.append("dptp.pre_closure_penal_interest as preClosurePenalInterest, "); sqlBuilder.append("dptp.pre_closure_penal_interest_on_enum as preClosurePenalInterestOnId, "); sqlBuilder.append("dptp.min_deposit_term as minDepositTerm, "); @@ -1172,12 +1152,6 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final DepositAccountData depositAccountData = super.mapRow(rs); - final boolean interestFreePeriodApplicable = rs.getBoolean("interestFreePeriodApplicable"); - final Integer interestFreeFromPeriod = JdbcSupport.getInteger(rs, "interestFreeFromPeriod"); - final Integer interestFreeToPeriod = JdbcSupport.getInteger(rs, "interestFreeToPeriod"); - final Integer periodFrequencyTypeId = JdbcSupport.getInteger(rs, "interestFreePeriodFrequencyId"); - final EnumOptionData interestFreePeriodFrequencyType = (periodFrequencyTypeId == null) ? null : InterestRateChartEnumerations - .periodType(periodFrequencyTypeId); final boolean preClosurePenalApplicable = rs.getBoolean("preClosurePenalApplicable"); final BigDecimal preClosurePenalInterest = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "preClosurePenalInterest"); final Integer preClosurePenalInterestOnTypeId = JdbcSupport.getInteger(rs, "preClosurePenalInterestOnId"); @@ -1205,8 +1179,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final EnumOptionData onAccountClosureType = null; final Boolean transferInterestToSavings = false; - return FixedDepositAccountData.instance(depositAccountData, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, + return FixedDepositAccountData.instance(depositAccountData, preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestOnType, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, depositPeriod, depositPeriodFrequencyType, onAccountClosureType, transferInterestToSavings); @@ -1222,16 +1195,12 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final StringBuilder sqlBuilder = new StringBuilder(400); sqlBuilder.append(this.selectFieldsSql()); - sqlBuilder.append(", dptp.interest_free_period_applicable as interestFreePeriodApplicable, "); - sqlBuilder.append("dptp.interest_free_from_period as interestFreeFromPeriod, "); - sqlBuilder.append("dptp.interest_free_to_period as interestFreeToPeriod, "); - sqlBuilder.append("dptp.interest_free_period_frequency_enum as interestFreePeriodFrequencyId, "); - sqlBuilder.append("dptp.pre_closure_penal_applicable as preClosurePenalApplicable, "); + sqlBuilder.append(", dptp.pre_closure_penal_applicable as preClosurePenalApplicable, "); sqlBuilder.append("dptp.pre_closure_penal_interest as preClosurePenalInterest, "); sqlBuilder.append("dptp.pre_closure_penal_interest_on_enum as preClosurePenalInterestOnId, "); - sqlBuilder.append("dprd.recurring_deposit_type_enum as recurringDepositTypeId, "); - sqlBuilder.append("dprd.recurring_deposit_frequency as recurringDepositFrequency, "); - sqlBuilder.append("dprd.recurring_deposit_frequency_type_enum as recurringDepositFrequencyTypeId, "); + sqlBuilder.append("dprd.is_mandatory as isMandatoryDeposit, "); + sqlBuilder.append("dprd.allow_withdrawal as allowWithdrawal, "); + sqlBuilder.append("dprd.adjust_advance_towards_future_payments as adjustAdvanceTowardsFuturePayments, "); sqlBuilder.append("dptp.min_deposit_term as minDepositTerm, "); sqlBuilder.append("dptp.max_deposit_term as maxDepositTerm, "); sqlBuilder.append("dptp.min_deposit_term_type_enum as minDepositTermTypeId, "); @@ -1255,24 +1224,11 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final DepositAccountData depositAccountData = super.mapRow(rs); - final boolean interestFreePeriodApplicable = rs.getBoolean("interestFreePeriodApplicable"); - final Integer interestFreeFromPeriod = JdbcSupport.getInteger(rs, "interestFreeFromPeriod"); - final Integer interestFreeToPeriod = JdbcSupport.getInteger(rs, "interestFreeToPeriod"); - final Integer periodFrequencyTypeId = JdbcSupport.getInteger(rs, "interestFreePeriodFrequencyId"); - final EnumOptionData interestFreePeriodFrequencyType = (periodFrequencyTypeId == null) ? null : InterestRateChartEnumerations - .periodType(periodFrequencyTypeId); final boolean preClosurePenalApplicable = rs.getBoolean("preClosurePenalApplicable"); final BigDecimal preClosurePenalInterest = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "preClosurePenalInterest"); final Integer preClosurePenalInterestOnTypeId = JdbcSupport.getInteger(rs, "preClosurePenalInterestOnId"); final EnumOptionData preClosurePenalInterestOnType = (preClosurePenalInterestOnTypeId == null) ? null : SavingsEnumerations .preClosurePenaltyInterestOnType(preClosurePenalInterestOnTypeId); - final Integer recurringDepositTypeId = JdbcSupport.getInteger(rs, "recurringDepositTypeId"); - final EnumOptionData recurringDepositType = (recurringDepositTypeId == null) ? null : SavingsEnumerations - .recurringDepositType(recurringDepositTypeId); - final Integer recurringDepositFrequency = JdbcSupport.getInteger(rs, "recurringDepositFrequency"); - final Integer recurringDepositFrequencyTypeId = JdbcSupport.getInteger(rs, "recurringDepositFrequencyTypeId"); - final EnumOptionData recurringDepositFrequencyType = (recurringDepositFrequencyTypeId == null) ? null : SavingsEnumerations - .recurringDepositFrequencyType(recurringDepositFrequencyTypeId); final Integer minDepositTerm = JdbcSupport.getInteger(rs, "minDepositTerm"); final Integer maxDepositTerm = JdbcSupport.getInteger(rs, "maxDepositTerm"); @@ -1286,21 +1242,28 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final Integer inMultiplesOfDepositTermTypeId = JdbcSupport.getInteger(rs, "inMultiplesOfDepositTermTypeId"); final EnumOptionData inMultiplesOfDepositTermType = (inMultiplesOfDepositTermTypeId == null) ? null : SavingsEnumerations .depositTermFrequencyType(inMultiplesOfDepositTermTypeId); + final boolean isMandatoryDeposit = rs.getBoolean("isMandatoryDeposit"); + final boolean allowWithdrawal = rs.getBoolean("allowWithdrawal"); + final boolean adjustAdvanceTowardsFuturePayments = rs.getBoolean("adjustAdvanceTowardsFuturePayments"); + final boolean isCalendarInherited = false; final BigDecimal depositAmount = null; final BigDecimal maturityAmount = null; final LocalDate maturityDate = null; final Integer depositPeriod = null; final EnumOptionData depositPeriodFrequencyType = null; - final BigDecimal recurringDepositAmount = null; final LocalDate expectedFirstDepositOnDate = null; + final BigDecimal mandatoryRecommendedDepositAmount = null; final EnumOptionData onAccountClosureType = null; - return RecurringDepositAccountData.instance(depositAccountData, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, + final BigDecimal totalOverdueAmount = null; + final Integer noOfOverdueInstallments = null; + + return RecurringDepositAccountData.instance(depositAccountData, preClosurePenalApplicable, preClosurePenalInterest, preClosurePenalInterestOnType, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, depositAmount, maturityAmount, maturityDate, depositPeriod, - depositPeriodFrequencyType, recurringDepositAmount, recurringDepositType, recurringDepositFrequency, - recurringDepositFrequencyType, onAccountClosureType, expectedFirstDepositOnDate); + depositPeriodFrequencyType, mandatoryRecommendedDepositAmount, onAccountClosureType, expectedFirstDepositOnDate, + totalOverdueAmount, noOfOverdueInstallments, isMandatoryDeposit, allowWithdrawal, adjustAdvanceTowardsFuturePayments, + isCalendarInherited); } } @@ -1362,9 +1325,10 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead .append("sa.currency_code as currencyCode, sa.currency_digits as currencyDigits, sa.currency_multiplesof as inMultiplesOf, "); sqlBuilder.append("curr.name as currencyName, curr.internationalized_name_code as currencyNameCode, "); sqlBuilder.append("curr.display_symbol as currencyDisplaySymbol, "); - sqlBuilder.append("dard.recurring_deposit_amount as recurringDepositAmount "); + sqlBuilder + .append("mss.duedate as duedate, (mss.deposit_amount - ifnull(mss.deposit_amount_completed_derived,0)) as dueamount "); sqlBuilder.append("from m_savings_account sa "); - sqlBuilder.append("join m_deposit_account_recurring_detail dard on dard.savings_account_id = sa.id "); + sqlBuilder.append("join m_mandatory_savings_schedule mss on mss.savings_account_id=sa.id and mss.completed_derived = false "); sqlBuilder.append("join m_currency curr on curr.code = sa.currency_code "); this.schemaSql = sqlBuilder.toString(); @@ -1379,7 +1343,8 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final Long savingsId = rs.getLong("id"); final String accountNo = rs.getString("accountNo"); - final BigDecimal recurringDepositAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "recurringDepositAmount"); + final BigDecimal dueamount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "dueamount"); + final LocalDate duedate = JdbcSupport.getLocalDate(rs, "duedate"); final String currencyCode = rs.getString("currencyCode"); final String currencyName = rs.getString("currencyName"); final String currencyNameCode = rs.getString("currencyNameCode"); @@ -1393,8 +1358,8 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final PaymentDetailData paymentDetailData = null; final AccountTransferData transfer = null; final BigDecimal runningBalance = null; - return SavingsAccountTransactionData.create(savingsId, transactionType, paymentDetailData, savingsId, accountNo, - DateUtils.getLocalDateOfTenant(), currency, recurringDepositAmount, runningBalance, false, transfer); + return SavingsAccountTransactionData.create(savingsId, transactionType, paymentDetailData, savingsId, accountNo, duedate, + currency, dueamount, runningBalance, false, transfer); } } @@ -1425,7 +1390,7 @@ public class DepositAccountReadPlatformServiceImpl implements DepositAccountRead final LocalDate transactionDate = JdbcSupport.getLocalDate(rs, "transactionDate"); return new AccountTransferDTO(transactionDate, transactionAmount, PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, fromAccountId, toAccountId, "trasfer interest to savings", null, null, null, null, null, null, null, - AccountTransferType.INTEREST_TRANSFER.getValue(), null, null, null, null, null); + AccountTransferType.INTEREST_TRANSFER.getValue(), null, null, null, null, null, null); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformService.java index 88e2aecaa..530626333 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformService.java @@ -12,13 +12,18 @@ import org.mifosplatform.infrastructure.jobs.exception.JobExecutionException; import org.mifosplatform.organisation.office.domain.Office; import org.mifosplatform.organisation.staff.domain.Staff; import org.mifosplatform.portfolio.savings.DepositAccountType; +import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionDTO; import org.mifosplatform.portfolio.savings.domain.SavingsAccountTransaction; public interface DepositAccountWritePlatformService { - CommandProcessingResult activate(Long savingsId, JsonCommand command, final DepositAccountType depositAccountType); + CommandProcessingResult activateFDAccount(Long savingsId, JsonCommand command); + + CommandProcessingResult activateRDAccount(Long savingsId, JsonCommand command); - CommandProcessingResult deposit(Long savingsId, JsonCommand command, final DepositAccountType depositAccountType); + CommandProcessingResult depositToFDAccount(Long savingsId, JsonCommand command); + + CommandProcessingResult depositToRDAccount(Long savingsId, JsonCommand command); CommandProcessingResult withdrawal(Long savingsId, JsonCommand command, final DepositAccountType depositAccountType); @@ -26,13 +31,21 @@ public interface DepositAccountWritePlatformService { CommandProcessingResult postInterest(Long savingsId, final DepositAccountType depositAccountType); - CommandProcessingResult undoTransaction(Long savingsId, Long transactionId, boolean allowAccountTransferModification, final DepositAccountType depositAccountType); - - CommandProcessingResult adjustDepositTransaction(Long savingsId, Long transactionId, JsonCommand command, final DepositAccountType depositAccountType); - - CommandProcessingResult close(Long savingsId, JsonCommand command, final DepositAccountType depositAccountType); + CommandProcessingResult undoFDTransaction(Long savingsId, Long transactionId, boolean allowAccountTransferModification); - CommandProcessingResult prematureClose(Long savingsId, JsonCommand command, final DepositAccountType depositAccountType); + CommandProcessingResult undoRDTransaction(Long savingsId, Long transactionId, boolean allowAccountTransferModification); + + CommandProcessingResult adjustFDTransaction(Long savingsId, Long transactionId, JsonCommand command); + + CommandProcessingResult adjustRDTransaction(Long savingsId, Long transactionId, JsonCommand command); + + CommandProcessingResult closeFDAccount(Long savingsId, JsonCommand command); + + CommandProcessingResult closeRDAccount(Long savingsId, JsonCommand command); + + CommandProcessingResult prematureCloseFDAccount(Long savingsId, JsonCommand command); + + CommandProcessingResult prematureCloseRDAccount(Long savingsId, JsonCommand command); SavingsAccountTransaction initiateSavingsTransfer(Long accountId, LocalDate transferDate, final DepositAccountType depositAccountType); @@ -57,4 +70,6 @@ public interface DepositAccountWritePlatformService { void updateMaturityDetails(final Long depositAccountId, final DepositAccountType depositAccountType); void transferInterestToSavings() throws JobExecutionException; + + SavingsAccountTransaction mandatorySavingsAccountDeposit(final SavingsAccountTransactionDTO accountTransactionDTO); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java index b239775ca..fa71b84d5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java @@ -54,10 +54,18 @@ import org.mifosplatform.portfolio.account.domain.AccountTransferType; import org.mifosplatform.portfolio.account.service.AccountAssociationsReadPlatformService; import org.mifosplatform.portfolio.account.service.AccountTransfersReadPlatformService; import org.mifosplatform.portfolio.account.service.AccountTransfersWritePlatformService; +import org.mifosplatform.portfolio.calendar.domain.Calendar; +import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType; +import org.mifosplatform.portfolio.calendar.domain.CalendarFrequencyType; +import org.mifosplatform.portfolio.calendar.domain.CalendarInstance; +import org.mifosplatform.portfolio.calendar.domain.CalendarInstanceRepository; +import org.mifosplatform.portfolio.calendar.domain.CalendarType; +import org.mifosplatform.portfolio.calendar.service.CalendarUtils; import org.mifosplatform.portfolio.charge.domain.Charge; import org.mifosplatform.portfolio.charge.domain.ChargeRepositoryWrapper; import org.mifosplatform.portfolio.client.domain.Client; import org.mifosplatform.portfolio.client.exception.ClientNotActiveException; +import org.mifosplatform.portfolio.common.domain.PeriodFrequencyType; import org.mifosplatform.portfolio.group.domain.Group; import org.mifosplatform.portfolio.group.exception.GroupNotActiveException; import org.mifosplatform.portfolio.note.domain.Note; @@ -112,6 +120,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo private final AccountAssociationsReadPlatformService accountAssociationsReadPlatformService; private final AccountTransfersWritePlatformService accountTransfersWritePlatformService; private final DepositAccountReadPlatformService depositAccountReadPlatformService; + private final CalendarInstanceRepository calendarInstanceRepository; @Autowired public DepositAccountWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, @@ -130,7 +139,9 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo final WorkingDaysWritePlatformService workingDaysWritePlatformService, final AccountAssociationsReadPlatformService accountAssociationsReadPlatformService, final AccountTransfersWritePlatformService accountTransfersWritePlatformService, - final DepositAccountReadPlatformService depositAccountReadPlatformService) { + final DepositAccountReadPlatformService depositAccountReadPlatformService, + final CalendarInstanceRepository calendarInstanceRepository) { + this.context = context; this.savingAccountRepository = savingAccountRepository; this.savingsAccountTransactionRepository = savingsAccountTransactionRepository; @@ -150,17 +161,19 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo this.accountAssociationsReadPlatformService = accountAssociationsReadPlatformService; this.accountTransfersWritePlatformService = accountTransfersWritePlatformService; this.depositAccountReadPlatformService = depositAccountReadPlatformService; + this.calendarInstanceRepository = calendarInstanceRepository; } @Transactional @Override - public CommandProcessingResult activate(final Long savingsId, final JsonCommand command, final DepositAccountType depositAccountType) { + public CommandProcessingResult activateFDAccount(final Long savingsId, final JsonCommand command) { final AppUser user = this.context.authenticatedUser(); this.depositAccountTransactionDataValidator.validateActivation(command); - - final SavingsAccount account = this.depositAccountAssembler.assembleFrom(savingsId, depositAccountType); + final MathContext mc = MathContext.DECIMAL64; + final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, + DepositAccountType.FIXED_DEPOSIT); checkClientOrGroupActive(account); final Set existingTransactionIds = new HashSet(); @@ -168,6 +181,75 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); final Map changes = account.activate(user, command, DateUtils.getLocalDateOfTenant()); + + if (!changes.isEmpty()) { + final Locale locale = command.extractLocale(); + final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); + Money amountForDeposit = account.activateWithBalance(); + if (amountForDeposit.isGreaterThanZero()) { + + final PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService + .retriveSavingsAssociation(savingsId); + + if (portfolioAccountData == null) { + final PaymentDetail paymentDetail = null; + this.depositAccountDomainService.handleFDDeposit(account, fmt, account.getActivationLocalDate(), + amountForDeposit.getAmount(), paymentDetail); + } else { + final SavingsAccount fromSavingsAccount = null; + final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(account.getActivationLocalDate(), + amountForDeposit.getAmount(), PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, + portfolioAccountData.accountId(), account.getId(), "Account Transfer", locale, fmt, null, null, null, null, + null, AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, account, fromSavingsAccount); + this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); + } + final boolean isInterestTransfer = false; + if (account.isBeforeLastPostingPeriod(account.getActivationLocalDate())) { + final LocalDate today = DateUtils.getLocalDateOfTenant(); + account.postInterest(mc, today, isInterestTransfer); + } else { + final LocalDate today = DateUtils.getLocalDateOfTenant(); + account.calculateInterestUsing(mc, today, isInterestTransfer); + } + + updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); + } + + account.updateMaturityDateAndAmount(mc); + account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name()); + this.savingAccountRepository.save(account); + } + + postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); + + return new CommandProcessingResultBuilder() // + .withEntityId(savingsId) // + .withOfficeId(account.officeId()) // + .withClientId(account.clientId()) // + .withGroupId(account.groupId()) // + .withSavingsId(savingsId) // + .with(changes) // + .build(); + } + + @Transactional + @Override + public CommandProcessingResult activateRDAccount(final Long savingsId, final JsonCommand command) { + + final AppUser user = this.context.authenticatedUser(); + + this.depositAccountTransactionDataValidator.validateActivation(command); + + final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, + DepositAccountType.RECURRING_DEPOSIT); + checkClientOrGroupActive(account); + + final Set existingTransactionIds = new HashSet(); + final Set existingReversedTransactionIds = new HashSet(); + updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); + + final Map changes = account.activate(user, command, DateUtils.getLocalDateOfTenant()); + if (!changes.isEmpty()) { final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); @@ -176,18 +258,46 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo final PortfolioAccountData portfolioAccountData = this.accountAssociationsReadPlatformService .retriveSavingsAssociation(savingsId); if (portfolioAccountData == null) { - this.depositAccountDomainService.handleDeposit(account, fmt, account.getActivationLocalDate(), + this.depositAccountDomainService.handleRDDeposit(account, fmt, account.getActivationLocalDate(), amountForDeposit.getAmount(), null); } else { + final SavingsAccount fromSavingsAccount = null; final AccountTransferDTO accountTransferDTO = new AccountTransferDTO(account.getActivationLocalDate(), amountForDeposit.getAmount(), PortfolioAccountType.SAVINGS, PortfolioAccountType.SAVINGS, portfolioAccountData.accountId(), account.getId(), "Account Transfer", locale, fmt, null, null, null, null, - null, AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, account); + null, AccountTransferType.ACCOUNT_TRANSFER.getValue(), null, null, null, null, account, fromSavingsAccount); this.accountTransfersWritePlatformService.transferFunds(accountTransferDTO); } updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); } - // account.processAccountUponActivation(fmt); + + final MathContext mc = MathContext.DECIMAL64; + + // submitted and activation date are different then recalculate + // maturity date and schedule + if (!account.accountSubmittedAndActivationOnSameDate()) { + final CalendarInstance calendarInstance = this.calendarInstanceRepository.findByEntityIdAndEntityTypeIdAndCalendarTypeId( + savingsId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue()); + + final Calendar calendar = calendarInstance.getCalendar(); + final PeriodFrequencyType frequencyType = CalendarFrequencyType.from(CalendarUtils.getFrequency(calendar.getRecurrence())); + Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence()); + frequency = frequency == -1 ? 1 : frequency; + account.generateSchedule(frequencyType, frequency); + account.updateMaturityDateAndAmount(mc); + } + + final LocalDate overdueUptoDate = account.maturityDate().isAfter(DateUtils.getLocalDateOfTenant()) ? DateUtils + .getLocalDateOfTenant() : account.maturityDate(); + account.updateOverduePayments(overdueUptoDate); + final boolean isInterestTransfer = false; + if (account.isBeforeLastPostingPeriod(account.getActivationLocalDate())) { + final LocalDate today = DateUtils.getLocalDateOfTenant(); + account.postInterest(mc, today, isInterestTransfer); + } else { + final LocalDate today = DateUtils.getLocalDateOfTenant(); + account.calculateInterestUsing(mc, today, isInterestTransfer); + } account.validateAccountBalanceDoesNotBecomeNegative(SavingsAccountTransactionType.PAY_CHARGE.name()); @@ -208,16 +318,22 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo @Transactional @Override - public CommandProcessingResult deposit(final Long savingsId, final JsonCommand command, final DepositAccountType depositAccountType) { + public CommandProcessingResult depositToFDAccount(final Long savingsId, @SuppressWarnings("unused") final JsonCommand command) { + // this.context.authenticatedUser(); + throw new DepositAccountTransactionNotAllowedException(savingsId, "deposit", DepositAccountType.FIXED_DEPOSIT); + + } + + @Transactional + @Override + public CommandProcessingResult depositToRDAccount(final Long savingsId, final JsonCommand command) { this.context.authenticatedUser(); - if (depositAccountType.isFixedDeposit()) { throw new DepositAccountTransactionNotAllowedException(savingsId, "deposit", - depositAccountType); } + this.depositAccountTransactionDataValidator.validate(command, DepositAccountType.RECURRING_DEPOSIT); - this.depositAccountTransactionDataValidator.validate(command, depositAccountType); - - final SavingsAccount account = this.depositAccountAssembler.assembleFrom(savingsId, depositAccountType); + final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, + DepositAccountType.RECURRING_DEPOSIT); checkClientOrGroupActive(account); final Locale locale = command.extractLocale(); @@ -228,8 +344,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo final Map changes = new LinkedHashMap(); final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService.createAndPersistPaymentDetail(command, changes); - - final SavingsAccountTransaction deposit = this.depositAccountDomainService.handleDeposit(account, fmt, transactionDate, + final SavingsAccountTransaction deposit = this.depositAccountDomainService.handleRDDeposit(account, fmt, transactionDate, transactionAmount, paymentDetail); return new CommandProcessingResultBuilder() // @@ -253,7 +368,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo this.depositAccountTransactionDataValidator.validate(command, depositAccountType); - if (depositAccountType.isFixedDeposit()) { throw new DepositAccountTransactionNotAllowedException(savingsId, "withdraw", + if (depositAccountType.isFixedDeposit()) { throw new DepositAccountTransactionNotAllowedException(savingsId, "withdrawal", depositAccountType); } final LocalDate transactionDate = command.localDateValueOfParameterNamed("transactionDate"); @@ -265,7 +380,11 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo final Map changes = new LinkedHashMap(); final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService.createAndPersistPaymentDetail(command, changes); - final SavingsAccount account = this.depositAccountAssembler.assembleFrom(savingsId, depositAccountType); + final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, + depositAccountType); + + if (!account.allowWithdrawal()) { throw new DepositAccountTransactionNotAllowedException(savingsId, "withdrawal", + depositAccountType); } checkClientOrGroupActive(account); final SavingsAccountTransaction withdrawal = this.depositAccountDomainService.handleWithdrawal(account, fmt, transactionDate, @@ -356,13 +475,18 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo } @Override - public CommandProcessingResult undoTransaction(final Long savingsId, final Long transactionId, - final boolean allowAccountTransferModification, final DepositAccountType depositAccountType) { + public CommandProcessingResult undoFDTransaction(final Long savingsId, @SuppressWarnings("unused") final Long transactionId, + @SuppressWarnings("unused") final boolean allowAccountTransferModification) { - if (depositAccountType.isFixedDeposit()) { throw new DepositAccountTransactionNotAllowedException(savingsId, "undo", - depositAccountType); } + throw new DepositAccountTransactionNotAllowedException(savingsId, "undo", DepositAccountType.FIXED_DEPOSIT); + } - final SavingsAccount account = this.depositAccountAssembler.assembleFrom(savingsId, depositAccountType); + @Override + public CommandProcessingResult undoRDTransaction(final Long savingsId, final Long transactionId, + final boolean allowAccountTransferModification) { + + final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, + DepositAccountType.RECURRING_DEPOSIT); final Set existingTransactionIds = new HashSet(); final Set existingReversedTransactionIds = new HashSet(); updateExistingTransactionsDetails(account, existingTransactionIds, existingReversedTransactionIds); @@ -373,11 +497,11 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo if (!allowAccountTransferModification && this.accountTransfersReadPlatformService.isAccountTransfer(transactionId, PortfolioAccountType.SAVINGS)) { throw new PlatformServiceUnavailableException( - "error.msg.saving.account.transfer.transaction.update.not.allowed", "Savings account transaction:" + transactionId - + " update not allowed as it involves in account transfer", transactionId); } + "error.msg.recurring.deposit.account.transfer.transaction.update.not.allowed", "Recurring deposit account transaction:" + + transactionId + " update not allowed as it involves in account transfer", transactionId); } final LocalDate today = DateUtils.getLocalDateOfTenant(); - final MathContext mc = new MathContext(15, RoundingMode.HALF_EVEN); + final MathContext mc = MathContext.DECIMAL64; if (account.isNotActive()) { throwValidationForActiveStatus(SavingsApiConstants.undoTransactionAction); @@ -392,7 +516,18 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo account.calculateInterestUsing(mc, today, isInterestTransfer); } account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.undoTransactionAction); - account.activateAccountBasedOnBalance(); + // account.activateAccountBasedOnBalance(); + account.updateMaturityDateAndAmount(mc); + + final LocalDate overdueUptoDate = account.maturityDate().isAfter(DateUtils.getLocalDateOfTenant()) ? DateUtils + .getLocalDateOfTenant() : account.maturityDate(); + + if (savingsAccountTransaction.isDeposit()) { + account.updateScheduleInstallments(); + } + + account.updateOverduePayments(overdueUptoDate); + postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); return new CommandProcessingResultBuilder() // @@ -405,12 +540,16 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo } @Override - public CommandProcessingResult adjustDepositTransaction(final Long savingsId, final Long transactionId, final JsonCommand command, - final DepositAccountType depositAccountType) { + public CommandProcessingResult adjustFDTransaction(final Long savingsId, @SuppressWarnings("unused") final Long transactionId, + @SuppressWarnings("unused") final JsonCommand command) { - if (depositAccountType.isFixedDeposit()) { throw new DepositAccountTransactionNotAllowedException(savingsId, "modify", - depositAccountType); } - this.depositAccountTransactionDataValidator.validate(command, depositAccountType); + throw new DepositAccountTransactionNotAllowedException(savingsId, "modify", DepositAccountType.FIXED_DEPOSIT); + } + + @Override + public CommandProcessingResult adjustRDTransaction(final Long savingsId, final Long transactionId, final JsonCommand command) { + + this.depositAccountTransactionDataValidator.validate(command, DepositAccountType.RECURRING_DEPOSIT); final SavingsAccountTransaction savingsAccountTransaction = this.savingsAccountTransactionRepository .findOneByIdAndSavingsAccountId(transactionId, savingsId); @@ -425,7 +564,8 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo final LocalDate today = DateUtils.getLocalDateOfTenant(); - final SavingsAccount account = this.depositAccountAssembler.assembleFrom(savingsId, depositAccountType); + final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, + DepositAccountType.RECURRING_DEPOSIT); if (account.isNotActive()) { throwValidationForActiveStatus(SavingsApiConstants.adjustTransactionAction); } @@ -461,8 +601,17 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo } else { account.calculateInterestUsing(mc, today, isInterestTransfer); } + account.validateAccountBalanceDoesNotBecomeNegative(SavingsApiConstants.adjustTransactionAction); account.activateAccountBasedOnBalance(); + + if (savingsAccountTransaction.isDeposit()) { + account.handleScheduleInstallments(savingsAccountTransaction); + } + final LocalDate overdueUptoDate = account.maturityDate().isAfter(DateUtils.getLocalDateOfTenant()) ? DateUtils + .getLocalDateOfTenant() : account.maturityDate(); + account.updateOverduePayments(overdueUptoDate); + postJournalEntries(account, existingTransactionIds, existingReversedTransactionIds); return new CommandProcessingResultBuilder() // .withEntityId(newtransactionId) // @@ -497,19 +646,20 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo } @Override - public CommandProcessingResult close(final Long savingsId, final JsonCommand command, final DepositAccountType depositAccountType) { + public CommandProcessingResult closeFDAccount(final Long savingsId, final JsonCommand command) { final AppUser user = this.context.authenticatedUser(); - - this.depositAccountTransactionDataValidator.validateClosing(command, depositAccountType, false); + final boolean isPreMatureClose = false; + this.depositAccountTransactionDataValidator.validateClosing(command, DepositAccountType.FIXED_DEPOSIT, isPreMatureClose); final Map changes = new LinkedHashMap(); final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService.createAndPersistPaymentDetail(command, changes); - final SavingsAccount account = this.depositAccountAssembler.assembleFrom(savingsId, depositAccountType); + final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, + DepositAccountType.FIXED_DEPOSIT); checkClientOrGroupActive(account); - final SavingsAccountTransaction withdrawal = this.depositAccountDomainService.handleAccountClosure(account, paymentDetail, user, - command, DateUtils.getLocalDateOfTenant(), changes); + this.depositAccountDomainService.handleFDAccountClosure(account, paymentDetail, user, command, DateUtils.getLocalDateOfTenant(), + changes); final String noteText = command.stringValueOfParameterNamed("note"); if (StringUtils.isNotBlank(noteText)) { @@ -519,7 +669,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo } return new CommandProcessingResultBuilder() // - .withEntityId(withdrawal.getId()) // + .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // @@ -530,20 +680,20 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo } @Override - public CommandProcessingResult prematureClose(final Long savingsId, final JsonCommand command, - final DepositAccountType depositAccountType) { + public CommandProcessingResult closeRDAccount(final Long savingsId, final JsonCommand command) { final AppUser user = this.context.authenticatedUser(); - this.depositAccountTransactionDataValidator.validateClosing(command, depositAccountType, true); + this.depositAccountTransactionDataValidator.validateClosing(command, DepositAccountType.RECURRING_DEPOSIT, false); final Map changes = new LinkedHashMap(); final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService.createAndPersistPaymentDetail(command, changes); - final SavingsAccount account = this.depositAccountAssembler.assembleFrom(savingsId, depositAccountType); + final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, + DepositAccountType.RECURRING_DEPOSIT); checkClientOrGroupActive(account); - final SavingsAccountTransaction withdrawal = this.depositAccountDomainService.handleAccountPreMatureClosure(account, paymentDetail, - user, command, DateUtils.getLocalDateOfTenant(), changes); + this.depositAccountDomainService.handleRDAccountClosure(account, paymentDetail, user, command, DateUtils.getLocalDateOfTenant(), + changes); final String noteText = command.stringValueOfParameterNamed("note"); if (StringUtils.isNotBlank(noteText)) { @@ -553,7 +703,75 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo } return new CommandProcessingResultBuilder() // - .withEntityId(withdrawal.getId()) // + .withEntityId(savingsId) // + .withOfficeId(account.officeId()) // + .withClientId(account.clientId()) // + .withGroupId(account.groupId()) // + .withSavingsId(savingsId) // + .with(changes)// + .build(); + + } + + @Override + public CommandProcessingResult prematureCloseFDAccount(final Long savingsId, final JsonCommand command) { + final AppUser user = this.context.authenticatedUser(); + + this.depositAccountTransactionDataValidator.validateClosing(command, DepositAccountType.FIXED_DEPOSIT, true); + + final Map changes = new LinkedHashMap(); + final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService.createAndPersistPaymentDetail(command, changes); + + final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, + DepositAccountType.FIXED_DEPOSIT); + checkClientOrGroupActive(account); + + this.depositAccountDomainService.handleFDAccountPreMatureClosure(account, paymentDetail, user, command, + DateUtils.getLocalDateOfTenant(), changes); + + final String noteText = command.stringValueOfParameterNamed("note"); + if (StringUtils.isNotBlank(noteText)) { + final Note note = Note.savingNote(account, noteText); + changes.put("note", noteText); + this.noteRepository.save(note); + } + + return new CommandProcessingResultBuilder() // + .withEntityId(savingsId) // + .withOfficeId(account.officeId()) // + .withClientId(account.clientId()) // + .withGroupId(account.groupId()) // + .withSavingsId(savingsId) // + .with(changes)// + .build(); + + } + + @Override + public CommandProcessingResult prematureCloseRDAccount(final Long savingsId, final JsonCommand command) { + final AppUser user = this.context.authenticatedUser(); + + this.depositAccountTransactionDataValidator.validateClosing(command, DepositAccountType.RECURRING_DEPOSIT, true); + + final Map changes = new LinkedHashMap(); + final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService.createAndPersistPaymentDetail(command, changes); + + final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler.assembleFrom(savingsId, + DepositAccountType.RECURRING_DEPOSIT); + checkClientOrGroupActive(account); + + this.depositAccountDomainService.handleRDAccountPreMatureClosure(account, paymentDetail, user, command, + DateUtils.getLocalDateOfTenant(), changes); + + final String noteText = command.stringValueOfParameterNamed("note"); + if (StringUtils.isNotBlank(noteText)) { + final Note note = Note.savingNote(account, noteText); + changes.put("note", noteText); + this.noteRepository.save(note); + } + + return new CommandProcessingResultBuilder() // + .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // @@ -944,4 +1162,15 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo existingTransactionIds, existingReversedTransactionIds); this.journalEntryWritePlatformService.createJournalEntriesForSavings(accountingBridgeData); } + + @Transactional + @Override + public SavingsAccountTransaction mandatorySavingsAccountDeposit(final SavingsAccountTransactionDTO accountTransactionDTO) { + final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler.assembleFrom( + accountTransactionDTO.getSavingsAccountId(), DepositAccountType.RECURRING_DEPOSIT); + return this.depositAccountDomainService.handleRDDeposit(account, accountTransactionDTO.getFormatter(), + accountTransactionDTO.getTransactionDate(), accountTransactionDTO.getTransactionAmount(), + accountTransactionDTO.getPaymentDetail()); + } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformService.java index 52704935e..9d0df0e74 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformService.java @@ -11,9 +11,13 @@ import org.mifosplatform.portfolio.savings.DepositAccountType; public interface DepositApplicationProcessWritePlatformService { - CommandProcessingResult submitApplication(JsonCommand command, DepositAccountType depositAccountType); + CommandProcessingResult submitFDApplication(JsonCommand command); + + CommandProcessingResult submitRDApplication(JsonCommand command); - CommandProcessingResult modifyApplication(Long accountId, JsonCommand command, DepositAccountType depositAccountType); + CommandProcessingResult modifyFDApplication(Long accountId, JsonCommand command); + + CommandProcessingResult modifyRDApplication(Long accountId, JsonCommand command); CommandProcessingResult deleteApplication(Long accountId, DepositAccountType depositAccountType); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java index ba51f3528..9040ea04d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java @@ -5,7 +5,9 @@ */ package org.mifosplatform.portfolio.savings.service; -import static org.mifosplatform.portfolio.savings.DepositsApiConstants.linkedAccountParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.isCalendarInheritedParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringFrequencyParamName; +import static org.mifosplatform.portfolio.savings.DepositsApiConstants.recurringFrequencyTypeParamName; import static org.mifosplatform.portfolio.savings.DepositsApiConstants.transferInterestToSavingsParamName; import java.math.MathContext; @@ -22,6 +24,7 @@ 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.GeneralPlatformDomainRuleException; import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException; import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; @@ -31,11 +34,19 @@ import org.mifosplatform.organisation.staff.domain.Staff; import org.mifosplatform.organisation.staff.domain.StaffRepositoryWrapper; import org.mifosplatform.portfolio.account.domain.AccountAssociations; import org.mifosplatform.portfolio.account.domain.AccountAssociationsRepository; +import org.mifosplatform.portfolio.calendar.domain.Calendar; +import org.mifosplatform.portfolio.calendar.domain.CalendarEntityType; +import org.mifosplatform.portfolio.calendar.domain.CalendarFrequencyType; +import org.mifosplatform.portfolio.calendar.domain.CalendarInstance; +import org.mifosplatform.portfolio.calendar.domain.CalendarInstanceRepository; +import org.mifosplatform.portfolio.calendar.domain.CalendarType; +import org.mifosplatform.portfolio.calendar.service.CalendarUtils; import org.mifosplatform.portfolio.client.domain.AccountNumberGenerator; import org.mifosplatform.portfolio.client.domain.AccountNumberGeneratorFactory; import org.mifosplatform.portfolio.client.domain.Client; import org.mifosplatform.portfolio.client.domain.ClientRepositoryWrapper; import org.mifosplatform.portfolio.client.exception.ClientNotActiveException; +import org.mifosplatform.portfolio.common.domain.PeriodFrequencyType; import org.mifosplatform.portfolio.group.domain.Group; import org.mifosplatform.portfolio.group.domain.GroupRepository; import org.mifosplatform.portfolio.group.exception.CenterNotActiveException; @@ -88,6 +99,7 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl private final SavingsAccountChargeAssembler savingsAccountChargeAssembler; private final AccountAssociationsRepository accountAssociationsRepository; private final FromJsonHelper fromJsonHelper; + private final CalendarInstanceRepository calendarInstanceRepository; @Autowired public DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, @@ -100,7 +112,8 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl final SavingsAccountChargeAssembler savingsAccountChargeAssembler, final FixedDepositAccountRepository fixedDepositAccountRepository, final RecurringDepositAccountRepository recurringDepositAccountRepository, - final AccountAssociationsRepository accountAssociationsRepository, final FromJsonHelper fromJsonHelper) { + final AccountAssociationsRepository accountAssociationsRepository, final FromJsonHelper fromJsonHelper, + final CalendarInstanceRepository calendarInstanceRepository) { this.context = context; this.savingAccountRepository = savingAccountRepository; this.depositAccountAssembler = depositAccountAssembler; @@ -117,6 +130,7 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl this.recurringDepositAccountRepository = recurringDepositAccountRepository; this.accountAssociationsRepository = accountAssociationsRepository; this.fromJsonHelper = fromJsonHelper; + this.calendarInstanceRepository = calendarInstanceRepository; } /* @@ -149,23 +163,18 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl @Transactional @Override - public CommandProcessingResult submitApplication(final JsonCommand command, final DepositAccountType depositAccountType) { + public CommandProcessingResult submitFDApplication(final JsonCommand command) { try { - this.depositAccountDataValidator.validateForSubmit(command.json(), depositAccountType); + this.depositAccountDataValidator.validateFixedDepositForSubmit(command.json()); final AppUser submittedBy = this.context.authenticatedUser(); - final SavingsAccount account = this.depositAccountAssembler.assembleFrom(command, submittedBy, depositAccountType); + final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler.assembleFrom(command, submittedBy, + DepositAccountType.FIXED_DEPOSIT); final MathContext mc = MathContext.DECIMAL64; - if (depositAccountType.isFixedDeposit()) { - ((FixedDepositAccount) account).updateMaturityDateAndAmountBeforeAccountActivation(mc); - this.fixedDepositAccountRepository.saveAndFlush((FixedDepositAccount) account); - } else if (depositAccountType.isRecurringDeposit()) { - final LocalDate transactionStartDate = ((RecurringDepositAccount) account).depositStartDate(); - ((RecurringDepositAccount) account).updateMaturityDateAndAmount(mc, transactionStartDate); - this.recurringDepositAccountRepository.save((RecurringDepositAccount) account); - } + account.updateMaturityDateAndAmountBeforeAccountActivation(mc); + this.fixedDepositAccountRepository.save(account); if (account.isAccountNumberRequiresAutoGeneration()) { final AccountNumberGenerator accountNoGenerator = this.accountIdentifierGeneratorFactory @@ -186,6 +195,7 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl } final Long savingsId = account.getId(); + return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withEntityId(savingsId) // @@ -202,84 +212,185 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl @Transactional @Override - public CommandProcessingResult modifyApplication(final Long accountId, final JsonCommand command, - final DepositAccountType depositAccountType) { + public CommandProcessingResult submitRDApplication(final JsonCommand command) { try { - this.depositAccountDataValidator.validateForUpdate(command.json(), depositAccountType); + this.depositAccountDataValidator.validateRecurringDepositForSubmit(command.json()); + final AppUser submittedBy = this.context.authenticatedUser(); + + final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler.assembleFrom(command, + submittedBy, DepositAccountType.RECURRING_DEPOSIT); + + this.recurringDepositAccountRepository.save(account); + + if (account.isAccountNumberRequiresAutoGeneration()) { + final AccountNumberGenerator accountNoGenerator = this.accountIdentifierGeneratorFactory + .determineSavingsAccountNoGenerator(account.getId()); + account.updateAccountNo(accountNoGenerator.generate()); + } + + final Long savingsId = account.getId(); + final CalendarInstance calendarInstance = getCalendarInstance(command, account); + this.calendarInstanceRepository.save(calendarInstance); + + // FIXME: Avoid save separately (Calendar instance requires account + // details) + final MathContext mc = MathContext.DECIMAL64; + final Calendar calendar = calendarInstance.getCalendar(); + final PeriodFrequencyType frequencyType = CalendarFrequencyType.from(CalendarUtils.getFrequency(calendar.getRecurrence())); + Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence()); + frequency = frequency == -1 ? 1 : frequency; + account.generateSchedule(frequencyType, frequency); + account.updateMaturityDateAndAmount(mc); + account.validateApplicableInterestRate(); + this.savingAccountRepository.save(account); + + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(savingsId) // + .withOfficeId(account.officeId()) // + .withClientId(account.clientId()) // + .withGroupId(account.groupId()) // + .withSavingsId(savingsId) // + .build(); + } catch (final DataAccessException dve) { + handleDataIntegrityIssues(command, dve); + return CommandProcessingResult.empty(); + } + } + + private CalendarInstance getCalendarInstance(final JsonCommand command, RecurringDepositAccount account) { + CalendarInstance calendarInstance = null; + final boolean isCalendarInherited = command.booleanPrimitiveValueOfParameterNamed(isCalendarInheritedParamName); + + if (isCalendarInherited) { + Set groups = account.getClient().getGroups(); + Long groupId = null; + if (groups.isEmpty()) { + final String defaultUserMessage = "Client does not belong to group/center. Cannot follow group/center meeting frequency."; + throw new GeneralPlatformDomainRuleException( + "error.msg.recurring.deposit.account.cannot.create.not.belongs.to.any.groups.to.follow.meeting.frequency", + defaultUserMessage, account.clientId()); + } else if (groups.size() > 1) { + final String defaultUserMessage = "Client belongs to more than one group. Cannot support recurring deposit."; + throw new GeneralPlatformDomainRuleException( + "error.msg.recurring.deposit.account.cannot.create.belongs.to.multiple.groups", defaultUserMessage, + account.clientId()); + } else { + Group group = groups.iterator().next(); + Group parent = group.getParent(); + Integer entityType = CalendarEntityType.GROUPS.getValue(); + if (parent != null) { + groupId = parent.getId(); + entityType = CalendarEntityType.CENTERS.getValue(); + } else { + groupId = group.getId(); + } + CalendarInstance parentCalendarInstance = this.calendarInstanceRepository.findByEntityIdAndEntityTypeIdAndCalendarTypeId( + groupId, entityType, CalendarType.COLLECTION.getValue()); + calendarInstance = CalendarInstance.from(parentCalendarInstance.getCalendar(), account.getId(), + CalendarEntityType.SAVINGS.getValue()); + } + } else { + LocalDate calendarStartDate = account.depositStartDate(); + final Integer frequencyType = command.integerValueSansLocaleOfParameterNamed(recurringFrequencyTypeParamName); + final PeriodFrequencyType periodFrequencyType = PeriodFrequencyType.fromInt(frequencyType); + final Integer frequency = command.integerValueSansLocaleOfParameterNamed(recurringFrequencyParamName); + + final Integer repeatsOnDay = calendarStartDate.getDayOfWeek(); + final String title = "recurring_savings_" + account.getId(); + final Calendar calendar = Calendar.createRepeatingCalendar(title, calendarStartDate, CalendarType.COLLECTION.getValue(), + CalendarFrequencyType.from(periodFrequencyType), frequency, repeatsOnDay); + calendarInstance = CalendarInstance.from(calendar, account.getId(), CalendarEntityType.SAVINGS.getValue()); + } + if (calendarInstance == null) { + final String defaultUserMessage = "No valid recurring details available for recurring depost account creation."; + throw new GeneralPlatformDomainRuleException( + "error.msg.recurring.deposit.account.cannot.create.no.valid.recurring.details.available", defaultUserMessage, + account.clientId()); + } + return calendarInstance; + } + + @Transactional + @Override + public CommandProcessingResult modifyFDApplication(final Long accountId, final JsonCommand command) { + try { + this.depositAccountDataValidator.validateFixedDepositForUpdate(command.json()); final Map changes = new LinkedHashMap(20); - final SavingsAccount account = this.depositAccountAssembler.assembleFrom(accountId, depositAccountType); + final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler.assembleFrom(accountId, + DepositAccountType.FIXED_DEPOSIT); checkClientOrGroupActive(account); account.modifyApplication(command, changes); - account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(), depositAccountType.resourceName()); + account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(), DepositAccountType.FIXED_DEPOSIT.resourceName()); if (!changes.isEmpty()) { - - if (changes.containsKey(SavingsApiConstants.clientIdParamName)) { - final Long clientId = command.longValueOfParameterNamed(SavingsApiConstants.clientIdParamName); - if (clientId != null) { - final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId); - if (client.isNotActive()) { throw new ClientNotActiveException(clientId); } - account.update(client); - } else { - final Client client = null; - account.update(client); - } - } - - if (changes.containsKey(SavingsApiConstants.groupIdParamName)) { - final Long groupId = command.longValueOfParameterNamed(SavingsApiConstants.groupIdParamName); - if (groupId != null) { - final Group group = this.groupRepository.findOne(groupId); - if (group == null) { throw new GroupNotFoundException(groupId); } - if (group.isNotActive()) { - if (group.isCenter()) { throw new CenterNotActiveException(groupId); } - throw new GroupNotActiveException(groupId); - } - account.update(group); - } else { - final Group group = null; - account.update(group); - } - } - - if (changes.containsKey(SavingsApiConstants.productIdParamName)) { - final Long productId = command.longValueOfParameterNamed(SavingsApiConstants.productIdParamName); - final SavingsProduct product = this.savingsProductRepository.findOne(productId); - if (product == null) { throw new SavingsProductNotFoundException(productId); } - - account.update(product); - } - - if (changes.containsKey(SavingsApiConstants.fieldOfficerIdParamName)) { - final Long fieldOfficerId = command.longValueOfParameterNamed(SavingsApiConstants.fieldOfficerIdParamName); - Staff fieldOfficer = null; - if (fieldOfficerId != null) { - fieldOfficer = this.staffRepository.findOneWithNotFoundDetection(fieldOfficerId); - } else { - changes.put(SavingsApiConstants.fieldOfficerIdParamName, ""); - } - account.update(fieldOfficer); - } - - if (changes.containsKey("charges")) { - final Set charges = this.savingsAccountChargeAssembler.fromParsedJson(command.parsedJson(), - account.getCurrency().getCode()); - final boolean updated = account.update(charges); - if (!updated) { - changes.remove("charges"); - } - } + updateFDAndRDCommonChanges(changes, command, account); final MathContext mc = MathContext.DECIMAL64; - if (depositAccountType.isFixedDeposit()) { - ((FixedDepositAccount) account).updateMaturityDateAndAmountBeforeAccountActivation(mc); - } else if (depositAccountType.isRecurringDeposit()) { - final LocalDate transactionStartDate = ((RecurringDepositAccount) account).depositStartDate(); - ((RecurringDepositAccount) account).updateMaturityDateAndAmount(mc, transactionStartDate); - } + account.updateMaturityDateAndAmountBeforeAccountActivation(mc); + this.savingAccountRepository.save(account); + } - this.savingAccountRepository.saveAndFlush(account); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(accountId) // + .withOfficeId(account.officeId()) // + .withClientId(account.clientId()) // + .withGroupId(account.groupId()) // + .withSavingsId(accountId) // + .with(changes) // + .build(); + } catch (final DataAccessException dve) { + handleDataIntegrityIssues(command, dve); + return new CommandProcessingResult(Long.valueOf(-1)); + } + } + + @Transactional + @Override + public CommandProcessingResult modifyRDApplication(final Long accountId, final JsonCommand command) { + try { + this.depositAccountDataValidator.validateRecurringDepositForUpdate(command.json()); + + final Map changes = new LinkedHashMap(20); + + final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler.assembleFrom(accountId, + DepositAccountType.RECURRING_DEPOSIT); + checkClientOrGroupActive(account); + account.modifyApplication(command, changes); + account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(), DepositAccountType.RECURRING_DEPOSIT.resourceName()); + + if (!changes.isEmpty()) { + updateFDAndRDCommonChanges(changes, command, account); + final MathContext mc = MathContext.DECIMAL64; + final CalendarInstance calendarInstance = this.calendarInstanceRepository.findByEntityIdAndEntityTypeIdAndCalendarTypeId( + accountId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue()); + final Calendar calendar = calendarInstance.getCalendar(); + final PeriodFrequencyType frequencyType = CalendarFrequencyType.from(CalendarUtils.getFrequency(calendar.getRecurrence())); + Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence()); + frequency = frequency == -1 ? 1 : frequency; + account.generateSchedule(frequencyType, frequency); + account.updateMaturityDateAndAmount(mc); + account.validateApplicableInterestRate(); + this.savingAccountRepository.save(account); + + } + + // update calendar details + if (!account.isCalendarInherited()) { + final LocalDate calendarStartDate = account.depositStartDate(); + final Integer frequencyType = command.integerValueSansLocaleOfParameterNamed(recurringFrequencyTypeParamName); + final PeriodFrequencyType periodFrequencyType = PeriodFrequencyType.fromInt(frequencyType); + final Integer frequency = command.integerValueSansLocaleOfParameterNamed(recurringFrequencyParamName); + final Integer repeatsOnDay = calendarStartDate.getDayOfWeek(); + + CalendarInstance calendarInstance = this.calendarInstanceRepository.findByEntityIdAndEntityTypeIdAndCalendarTypeId( + accountId, CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue()); + Calendar calendar = calendarInstance.getCalendar(); + calendar.updateRepeatingCalendar(calendarStartDate, CalendarFrequencyType.from(periodFrequencyType), frequency, + repeatsOnDay); + this.calendarInstanceRepository.save(calendarInstance); } boolean isLinkedAccRequired = command.booleanPrimitiveValueOfParameterNamed(transferInterestToSavingsParamName); @@ -338,6 +449,66 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl } } + private void updateFDAndRDCommonChanges(final Map changes, final JsonCommand command, final SavingsAccount account) { + + if (changes.containsKey(SavingsApiConstants.clientIdParamName)) { + final Long clientId = command.longValueOfParameterNamed(SavingsApiConstants.clientIdParamName); + if (clientId != null) { + final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId); + if (client.isNotActive()) { throw new ClientNotActiveException(clientId); } + account.update(client); + } else { + final Client client = null; + account.update(client); + } + } + + if (changes.containsKey(SavingsApiConstants.groupIdParamName)) { + final Long groupId = command.longValueOfParameterNamed(SavingsApiConstants.groupIdParamName); + if (groupId != null) { + final Group group = this.groupRepository.findOne(groupId); + if (group == null) { throw new GroupNotFoundException(groupId); } + if (group.isNotActive()) { + if (group.isCenter()) { throw new CenterNotActiveException(groupId); } + throw new GroupNotActiveException(groupId); + } + account.update(group); + } else { + final Group group = null; + account.update(group); + } + } + + if (changes.containsKey(SavingsApiConstants.productIdParamName)) { + final Long productId = command.longValueOfParameterNamed(SavingsApiConstants.productIdParamName); + final SavingsProduct product = this.savingsProductRepository.findOne(productId); + if (product == null) { throw new SavingsProductNotFoundException(productId); } + + account.update(product); + } + + if (changes.containsKey(SavingsApiConstants.fieldOfficerIdParamName)) { + final Long fieldOfficerId = command.longValueOfParameterNamed(SavingsApiConstants.fieldOfficerIdParamName); + Staff fieldOfficer = null; + if (fieldOfficerId != null) { + fieldOfficer = this.staffRepository.findOneWithNotFoundDetection(fieldOfficerId); + } else { + changes.put(SavingsApiConstants.fieldOfficerIdParamName, ""); + } + account.update(fieldOfficer); + } + + if (changes.containsKey("charges")) { + final Set charges = this.savingsAccountChargeAssembler.fromParsedJson(command.parsedJson(), account + .getCurrency().getCode()); + final boolean updated = account.update(charges); + if (!updated) { + changes.remove("charges"); + } + } + + } + @Transactional @Override public CommandProcessingResult deleteApplication(final Long savingsId, final DepositAccountType depositAccountType) { @@ -347,8 +518,8 @@ public class DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl impl if (account.isNotSubmittedAndPendingApproval()) { final List dataValidationErrors = new ArrayList(); - final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) - .resource(DepositsApiConstants.FIXED_DEPOSIT_ACCOUNT_RESOURCE_NAME + DepositsApiConstants.deleteApplicationAction); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource(depositAccountType + .resourceName() + DepositsApiConstants.deleteApplicationAction); baseDataValidator.reset().parameter(DepositsApiConstants.activatedOnDateParamName) .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state"); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositProductReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositProductReadPlatformServiceImpl.java index b0951b8a3..202bee84d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositProductReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositProductReadPlatformServiceImpl.java @@ -17,7 +17,6 @@ import org.mifosplatform.infrastructure.core.service.RoutingDataSource; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.portfolio.interestratechart.data.InterestRateChartData; -import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartEnumerations; import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartReadPlatformService; import org.mifosplatform.portfolio.savings.DepositAccountType; import org.mifosplatform.portfolio.savings.data.DepositProductData; @@ -196,11 +195,7 @@ public class DepositProductReadPlatformServiceImpl implements DepositProductRead public FixedDepositProductMapper() { final StringBuilder sqlBuilder = new StringBuilder(400); sqlBuilder.append(super.schema()); - sqlBuilder.append(", dptp.interest_free_period_applicable as interestFreePeriodApplicable, "); - sqlBuilder.append("dptp.interest_free_from_period as interestFreeFromPeriod, "); - sqlBuilder.append("dptp.interest_free_to_period as interestFreeToPeriod, "); - sqlBuilder.append("dptp.interest_free_period_frequency_enum as interestFreePeriodFrequencyId, "); - sqlBuilder.append("dptp.pre_closure_penal_applicable as preClosurePenalApplicable, "); + sqlBuilder.append(", dptp.pre_closure_penal_applicable as preClosurePenalApplicable, "); sqlBuilder.append("dptp.pre_closure_penal_interest as preClosurePenalInterest, "); sqlBuilder.append("dptp.pre_closure_penal_interest_on_enum as preClosurePenalInterestOnId, "); sqlBuilder.append("dptp.min_deposit_term as minDepositTerm, "); @@ -228,12 +223,6 @@ public class DepositProductReadPlatformServiceImpl implements DepositProductRead final DepositProductData depositProductData = super.mapRow(rs); - final boolean interestFreePeriodApplicable = rs.getBoolean("interestFreePeriodApplicable"); - final Integer interestFreeFromPeriod = JdbcSupport.getInteger(rs, "interestFreeFromPeriod"); - final Integer interestFreeToPeriod = JdbcSupport.getInteger(rs, "interestFreeToPeriod"); - final Integer periodFrequencyTypeId = JdbcSupport.getInteger(rs, "interestFreePeriodFrequencyId"); - final EnumOptionData interestFreePeriodFrequencyType = (periodFrequencyTypeId == null) ? null : InterestRateChartEnumerations - .periodType(periodFrequencyTypeId); final boolean preClosurePenalApplicable = rs.getBoolean("preClosurePenalApplicable"); final BigDecimal preClosurePenalInterest = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "preClosurePenalInterest"); final Integer preClosurePenalInterestOnTypeId = JdbcSupport.getInteger(rs, "preClosurePenalInterestOnId"); @@ -256,10 +245,9 @@ public class DepositProductReadPlatformServiceImpl implements DepositProductRead final BigDecimal depositAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "depositAmount"); final BigDecimal maxDepositAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "maxDepositAmount"); - return FixedDepositProductData.instance(depositProductData, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, - preClosurePenalInterestOnType, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, - inMultiplesOfDepositTermType, minDepositAmount, depositAmount, maxDepositAmount); + return FixedDepositProductData.instance(depositProductData, preClosurePenalApplicable, preClosurePenalInterest, + preClosurePenalInterestOnType, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, + inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, minDepositAmount, depositAmount, maxDepositAmount); } } @@ -270,19 +258,15 @@ public class DepositProductReadPlatformServiceImpl implements DepositProductRead public RecurringDepositProductMapper() { final StringBuilder sqlBuilder = new StringBuilder(400); sqlBuilder.append(super.schema()); - sqlBuilder.append(", dptp.interest_free_period_applicable as interestFreePeriodApplicable, "); - sqlBuilder.append("dptp.interest_free_from_period as interestFreeFromPeriod, "); - sqlBuilder.append("dptp.interest_free_to_period as interestFreeToPeriod, "); - sqlBuilder.append("dptp.interest_free_period_frequency_enum as interestFreePeriodFrequencyId, "); - sqlBuilder.append("dptp.pre_closure_penal_applicable as preClosurePenalApplicable, "); + sqlBuilder.append(", dptp.pre_closure_penal_applicable as preClosurePenalApplicable, "); sqlBuilder.append("dptp.pre_closure_penal_interest as preClosurePenalInterest, "); sqlBuilder.append("dptp.pre_closure_penal_interest_on_enum as preClosurePenalInterestOnId, "); - sqlBuilder.append("dprd.recurring_deposit_type_enum as recurringDepositTypeId, "); - sqlBuilder.append("dprd.recurring_deposit_frequency as recurringDepositFrequency, "); - sqlBuilder.append("dprd.recurring_deposit_frequency_type_enum as recurringDepositFrequencyTypeId, "); sqlBuilder.append("dptp.min_deposit_amount as minDepositAmount, "); sqlBuilder.append("dptp.deposit_amount as depositAmount, "); sqlBuilder.append("dptp.max_deposit_amount as maxDepositAmount, "); + sqlBuilder.append("dprd.is_mandatory as isMandatoryDeposit, "); + sqlBuilder.append("dprd.allow_withdrawal as allowWithdrawal, "); + sqlBuilder.append("dprd.adjust_advance_towards_future_payments as adjustAdvanceTowardsFuturePayments, "); sqlBuilder.append("dptp.min_deposit_term as minDepositTerm, "); sqlBuilder.append("dptp.max_deposit_term as maxDepositTerm, "); sqlBuilder.append("dptp.min_deposit_term_type_enum as minDepositTermTypeId, "); @@ -307,28 +291,17 @@ public class DepositProductReadPlatformServiceImpl implements DepositProductRead final DepositProductData depositProductData = super.mapRow(rs); - final boolean interestFreePeriodApplicable = rs.getBoolean("interestFreePeriodApplicable"); - final Integer interestFreeFromPeriod = JdbcSupport.getInteger(rs, "interestFreeFromPeriod"); - final Integer interestFreeToPeriod = JdbcSupport.getInteger(rs, "interestFreeToPeriod"); - final Integer periodFrequencyTypeId = JdbcSupport.getInteger(rs, "interestFreePeriodFrequencyId"); - final EnumOptionData interestFreePeriodFrequencyType = (periodFrequencyTypeId == null) ? null : InterestRateChartEnumerations - .periodType(periodFrequencyTypeId); + final boolean isMandatoryDeposit = rs.getBoolean("isMandatoryDeposit"); + final boolean allowWithdrawal = rs.getBoolean("allowWithdrawal"); + final boolean adjustAdvanceTowardsFuturePayments = rs.getBoolean("adjustAdvanceTowardsFuturePayments"); final boolean preClosurePenalApplicable = rs.getBoolean("preClosurePenalApplicable"); final BigDecimal preClosurePenalInterest = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "preClosurePenalInterest"); final Integer preClosurePenalInterestOnTypeId = JdbcSupport.getInteger(rs, "preClosurePenalInterestOnId"); final EnumOptionData preClosurePenalInterestOnType = (preClosurePenalInterestOnTypeId == null) ? null : SavingsEnumerations .preClosurePenaltyInterestOnType(preClosurePenalInterestOnTypeId); - final Integer recurringDepositTypeId = JdbcSupport.getInteger(rs, "recurringDepositTypeId"); - final EnumOptionData recurringDepositType = (recurringDepositTypeId == null) ? null : SavingsEnumerations - .recurringDepositType(recurringDepositTypeId); - final Integer recurringDepositFrequency = JdbcSupport.getInteger(rs, "recurringDepositFrequency"); - final Integer recurringDepositFrequencyTypeId = JdbcSupport.getInteger(rs, "recurringDepositFrequencyTypeId"); final BigDecimal minDepositAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "minDepositAmount"); final BigDecimal depositAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "depositAmount"); final BigDecimal maxDepositAmount = JdbcSupport.getBigDecimalDefaultToNullIfZero(rs, "maxDepositAmount"); - final EnumOptionData recurringDepositFrequencyType = (recurringDepositFrequencyTypeId == null) ? null : SavingsEnumerations - .recurringDepositFrequencyType(recurringDepositFrequencyTypeId); - final Integer minDepositTerm = JdbcSupport.getInteger(rs, "minDepositTerm"); final Integer maxDepositTerm = JdbcSupport.getInteger(rs, "maxDepositTerm"); final Integer minDepositTermTypeId = JdbcSupport.getInteger(rs, "minDepositTermTypeId"); @@ -342,11 +315,10 @@ public class DepositProductReadPlatformServiceImpl implements DepositProductRead final EnumOptionData inMultiplesOfDepositTermType = (inMultiplesOfDepositTermTypeId == null) ? null : SavingsEnumerations .depositTermFrequencyType(inMultiplesOfDepositTermTypeId); - return RecurringDepositProductData.instance(depositProductData, interestFreePeriodApplicable, interestFreeFromPeriod, - interestFreeToPeriod, interestFreePeriodFrequencyType, preClosurePenalApplicable, preClosurePenalInterest, - preClosurePenalInterestOnType, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, inMultiplesOfDepositTerm, - inMultiplesOfDepositTermType, recurringDepositType, recurringDepositFrequency, recurringDepositFrequencyType, - minDepositAmount, depositAmount, maxDepositAmount); + return RecurringDepositProductData.instance(depositProductData, preClosurePenalApplicable, preClosurePenalInterest, + preClosurePenalInterestOnType, minDepositTerm, maxDepositTerm, minDepositTermType, maxDepositTermType, + inMultiplesOfDepositTerm, inMultiplesOfDepositTermType, isMandatoryDeposit, allowWithdrawal, + adjustAdvanceTowardsFuturePayments, minDepositAmount, depositAmount, maxDepositAmount); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositsDropdownReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositsDropdownReadPlatformService.java index e10a7acf6..04c839bd8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositsDropdownReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositsDropdownReadPlatformService.java @@ -13,19 +13,12 @@ public interface DepositsDropdownReadPlatformService { // fixed deposit product dropdowns - Collection retrieveInterestFreePeriodFrequencyTypeOptions(); - Collection retrievePreClosurePenalInterestOnTypeOptions(); - // RECURRING deposit product dropdowns - Collection retrieveRecurringDepositTypeOptions(); - - Collection retrieveRecurringDepositFrequencyTypeOptions(); - - Collection retrieveDepositTermTypeOptions(); + /*Collection retrieveDepositTermTypeOptions(); Collection retrieveInMultiplesOfDepositTermTypeOptions(); - Collection retrieveDepositPeriodFrequencyOptions(); + Collection retrieveDepositPeriodFrequencyOptions();*/ } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositsDropdownReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositsDropdownReadPlatformServiceImpl.java index ce19eb09c..e7502a856 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositsDropdownReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/DepositsDropdownReadPlatformServiceImpl.java @@ -8,37 +8,18 @@ package org.mifosplatform.portfolio.savings.service; import java.util.Collection; import org.mifosplatform.infrastructure.core.data.EnumOptionData; -import org.mifosplatform.portfolio.interestratechart.InterestRateChartPeriodType; -import org.mifosplatform.portfolio.interestratechart.service.InterestRateChartEnumerations; import org.mifosplatform.portfolio.savings.PreClosurePenalInterestOnType; -import org.mifosplatform.portfolio.savings.RecurringDepositType; -import org.mifosplatform.portfolio.savings.SavingsPeriodFrequencyType; import org.springframework.stereotype.Service; @Service public class DepositsDropdownReadPlatformServiceImpl implements DepositsDropdownReadPlatformService { - - @Override - public Collection retrieveInterestFreePeriodFrequencyTypeOptions() { - return InterestRateChartEnumerations.periodType(InterestRateChartPeriodType.values()); - } - + @Override public Collection retrievePreClosurePenalInterestOnTypeOptions() { return SavingsEnumerations.preClosurePenaltyInterestOnType(PreClosurePenalInterestOnType.values()); } - @Override - public Collection retrieveRecurringDepositTypeOptions() { - return SavingsEnumerations.recurringDepositType(RecurringDepositType.values()); - } - - @Override - public Collection retrieveRecurringDepositFrequencyTypeOptions() { - return SavingsEnumerations.recurringDepositFrequencyType(SavingsPeriodFrequencyType.values()); - } - - @Override + /*@Override public Collection retrieveDepositTermTypeOptions() { return SavingsEnumerations.recurringDepositFrequencyType(SavingsPeriodFrequencyType.values()); } @@ -51,6 +32,6 @@ public class DepositsDropdownReadPlatformServiceImpl implements DepositsDropdown @Override public Collection retrieveInMultiplesOfDepositTermTypeOptions() { return SavingsEnumerations.recurringDepositFrequencyType(SavingsPeriodFrequencyType.values()); - } + }*/ } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/FixedDepositProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/FixedDepositProductWritePlatformServiceJpaRepositoryImpl.java index 04ed826dd..a4b26c7f0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/FixedDepositProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/FixedDepositProductWritePlatformServiceJpaRepositoryImpl.java @@ -112,7 +112,7 @@ public class FixedDepositProductWritePlatformServiceJpaRepositoryImpl implements changes.putAll(accountingMappingChanges); if (!changes.isEmpty()) { - this.fixedDepositProductRepository.saveAndFlush(product); + this.fixedDepositProductRepository.save(product); } return new CommandProcessingResultBuilder() // diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/RecurringDepositProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/RecurringDepositProductWritePlatformServiceJpaRepositoryImpl.java index 380b57cef..1d3c8e140 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/RecurringDepositProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/RecurringDepositProductWritePlatformServiceJpaRepositoryImpl.java @@ -112,7 +112,7 @@ public class RecurringDepositProductWritePlatformServiceJpaRepositoryImpl implem changes.putAll(accountingMappingChanges); if (!changes.isEmpty()) { - this.recurringDepositProductRepository.saveAndFlush(product); + this.recurringDepositProductRepository.save(product); } return new CommandProcessingResultBuilder() //