From bf841ebb16979658cdc00f97cc6b80e43204d6bb Mon Sep 17 00:00:00 2001 From: wuyanna Date: Fri, 10 May 2013 22:00:55 +0800 Subject: [PATCH] mifosx 344 --- .../SavingsAccountWritePlatformService.java | 2 ++ ...WritePlatformServiceJpaRepositoryImpl.java | 23 ++++++++++++++ .../CheckAnnualFeeDueDateScheduledJob.java | 31 +++++++++++++++++++ .../service/ScheduledJobRunnerService.java | 2 ++ .../ScheduledJobRunnerServiceImpl.java | 25 ++++++++++++++- .../resources/META-INF/spring/scheduler.xml | 16 ++++++++++ 6 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/CheckAnnualFeeDueDateScheduledJob.java diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformService.java index 51a760d2f..8796bd81b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformService.java @@ -21,6 +21,8 @@ public interface SavingsAccountWritePlatformService { CommandProcessingResult deposit(Long savingsId, JsonCommand command); CommandProcessingResult withdrawal(Long savingsId, JsonCommand command); + + CommandProcessingResult addAnnualFee(Long savingsId); CommandProcessingResult calculateInterest(Long savingsId, JsonCommand command); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java index 00ecddd65..3b3dbc98c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savings/service/SavingsAccountWritePlatformServiceJpaRepositoryImpl.java @@ -313,6 +313,29 @@ public class SavingsAccountWritePlatformServiceJpaRepositoryImpl implements Savi .withSavingsId(savingsId) // .build(); } + + @Transactional + @Override + public CommandProcessingResult addAnnualFee(final Long savingsId) { + + final SavingsAccount account = this.savingAccountRepository.findOneWithNotFoundDetection(savingsId); + + final LocalDate transactionDate = LocalDate.now(); + + final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy"); + + final SavingsAccountTransaction annualFee = account.addAnnualFee(fmt, transactionDate); + final Long transactionId = saveTransactionToGenerateTransactionId(annualFee); + this.savingAccountRepository.save(account); + + return new CommandProcessingResultBuilder() // + .withEntityId(transactionId) // + .withOfficeId(account.officeId()) // + .withClientId(account.clientId()) // + .withGroupId(account.groupId()) // + .withSavingsId(savingsId) // + .build(); + } @Override public CommandProcessingResult calculateInterest(final Long savingsId, final JsonCommand command) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/CheckAnnualFeeDueDateScheduledJob.java b/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/CheckAnnualFeeDueDateScheduledJob.java new file mode 100644 index 000000000..561920ac8 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/CheckAnnualFeeDueDateScheduledJob.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.scheduledjobs; + +import java.util.Date; + +import org.mifosplatform.scheduledjobs.service.ScheduledJobRunnerService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CheckAnnualFeeDueDateScheduledJob { + + private final static Logger logger = LoggerFactory.getLogger(CheckAnnualFeeDueDateScheduledJob.class); + + private final ScheduledJobRunnerService scheduledJobRunnerService; + + public CheckAnnualFeeDueDateScheduledJob(final ScheduledJobRunnerService scheduledJobRunnerService) { + this.scheduledJobRunnerService = scheduledJobRunnerService; + } + + public void execute() { + logger.info("Running Job C " + new Date()); + + this.scheduledJobRunnerService.checkAnnualFeeDueDate(); + + logger.info("Finishing Job C " + new Date()); + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerService.java b/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerService.java index 327f48cd9..b1b1cf6a9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerService.java @@ -10,4 +10,6 @@ public interface ScheduledJobRunnerService { void updateLoanSummaryDetails(); void updateLoanArrearsAgeingDetails(); + + void checkAnnualFeeDueDate(); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java index 2a4fab657..b98772ecc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/scheduledjobs/service/ScheduledJobRunnerServiceImpl.java @@ -5,10 +5,13 @@ */ package org.mifosplatform.scheduledjobs.service; +import java.util.List; + import org.mifosplatform.infrastructure.core.domain.MifosPlatformTenant; import org.mifosplatform.infrastructure.core.service.DataSourcePerTenantService; import org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil; import org.mifosplatform.infrastructure.security.service.TenantDetailsService; +import org.mifosplatform.portfolio.savings.service.SavingsAccountWritePlatformService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -23,12 +26,14 @@ public class ScheduledJobRunnerServiceImpl implements ScheduledJobRunnerService private final TenantDetailsService tenantDetailsService; private final DataSourcePerTenantService dataSourcePerTenantService; + private final SavingsAccountWritePlatformService savingsAccountWritePlatformService; @Autowired public ScheduledJobRunnerServiceImpl(final DataSourcePerTenantService dataSourcePerTenantService, - final TenantDetailsService tenantDetailsService) { + final TenantDetailsService tenantDetailsService, final SavingsAccountWritePlatformService savingsAccountWritePlatformService) { this.dataSourcePerTenantService = dataSourcePerTenantService; this.tenantDetailsService = tenantDetailsService; + this.savingsAccountWritePlatformService = savingsAccountWritePlatformService; } @Transactional @@ -137,4 +142,22 @@ public class ScheduledJobRunnerServiceImpl implements ScheduledJobRunnerService logger.info("Results affected by update: " + result); } + + @Override + public void checkAnnualFeeDueDate() { + final MifosPlatformTenant tenant = this.tenantDetailsService.loadTenantById("default"); + + ThreadLocalContextUtil.setTenant(tenant); + + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSourcePerTenantService.retrieveTenantAwareDataSource()); + + String sql = "SELECT ms.id as savingsAccountId FROM m_savings_account ms WHERE ms.annual_fee_next_due_date <= NOW() "; + List savingsIds = jdbcTemplate.queryForList(sql, Long.class); + + for (Long savingsId : savingsIds) { + this.savingsAccountWritePlatformService.addAnnualFee(savingsId); + } + + logger.info("Results affected by update: " + savingsIds.size()); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/resources/META-INF/spring/scheduler.xml b/mifosng-provider/src/main/resources/META-INF/spring/scheduler.xml index b4debf546..bca9f2b1e 100644 --- a/mifosng-provider/src/main/resources/META-INF/spring/scheduler.xml +++ b/mifosng-provider/src/main/resources/META-INF/spring/scheduler.xml @@ -16,6 +16,9 @@ + + + @@ -30,6 +33,13 @@ + + + + + + + @@ -40,12 +50,18 @@ + + + + + +