mifosx 344

This commit is contained in:
wuyanna
2013-05-10 22:00:55 +08:00
parent 4712a1e3a9
commit bf841ebb16
6 changed files with 98 additions and 1 deletions
@@ -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);
@@ -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) {
@@ -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());
}
}
@@ -10,4 +10,6 @@ public interface ScheduledJobRunnerService {
void updateLoanSummaryDetails();
void updateLoanArrearsAgeingDetails();
void checkAnnualFeeDueDate();
}
@@ -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<Long> savingsIds = jdbcTemplate.queryForList(sql, Long.class);
for (Long savingsId : savingsIds) {
this.savingsAccountWritePlatformService.addAnnualFee(savingsId);
}
logger.info("Results affected by update: " + savingsIds.size());
}
}
@@ -16,6 +16,9 @@
<bean id="cronQuartzJobB" class="org.mifosplatform.scheduledjobs.UpdateLoanArrearsAgeingScheduledJob">
<constructor-arg ref="scheduledJobRunnerService" />
</bean>
<bean id="cronQuartzJobC" class="org.mifosplatform.scheduledjobs.CheckAnnualFeeDueDateScheduledJob">
<constructor-arg ref="scheduledJobRunnerService" />
</bean>
<bean id="jobADetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="group" value="mifosJobs" />
@@ -30,6 +33,13 @@
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
<bean id="jobCDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="group" value="mifosJobs" />
<property name="targetObject" ref="cronQuartzJobC" />
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
<bean id="cronTriggerA" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobADetail" />
@@ -40,12 +50,18 @@
<property name="jobDetail" ref="jobBDetail" />
<property name="cronExpression" value="0 10 22 1/1 * ? *" />
</bean>
<bean id="cronTriggerC" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobCDetail" />
<property name="cronExpression" value="0 20 22 1/1 * ? *" />
</bean>
<bean name="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTriggerA" />
<ref bean="cronTriggerB" />
<ref bean="cronTriggerC" />
</list>
</property>
</bean>