use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class GroupServiceFacadeWebTier method updateCustomerHistoricalData.
@Override
public void updateCustomerHistoricalData(String globalCustNum, CustomerHistoricalDataUpdateRequest historicalData) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
customerBO.updateDetails(userContext);
try {
CustomerHistoricalDataEntity customerHistoricalDataEntity = customerBO.getHistoricalData();
if (customerBO.getPersonnel() != null) {
checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), customerBO.getPersonnel().getPersonnelId());
} else {
checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), userContext.getId());
}
// Integer oldLoanCycleNo = 0;
if (customerHistoricalDataEntity == null) {
customerHistoricalDataEntity = new CustomerHistoricalDataEntity(customerBO);
customerHistoricalDataEntity.setCreatedBy(customerBO.getUserContext().getId());
customerHistoricalDataEntity.setCreatedDate(new DateTimeService().getCurrentJavaDateTime());
} else {
// oldLoanCycleNo =
// customerHistoricalDataEntity.getLoanCycleNumber();
customerHistoricalDataEntity.setUpdatedDate(new DateTimeService().getCurrentJavaDateTime());
customerHistoricalDataEntity.setUpdatedBy(customerBO.getUserContext().getId());
}
customerHistoricalDataEntity.setInterestPaid(StringUtils.isBlank(historicalData.getInterestPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getInterestPaid()));
customerHistoricalDataEntity.setLoanAmount(StringUtils.isBlank(historicalData.getLoanAmount()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getLoanAmount()));
customerHistoricalDataEntity.setLoanCycleNumber(historicalData.getLoanCycleNumber());
customerHistoricalDataEntity.setMissedPaymentsCount(historicalData.getMissedPaymentsCount());
customerHistoricalDataEntity.setNotes(historicalData.getNotes());
customerHistoricalDataEntity.setProductName(historicalData.getProductName());
customerHistoricalDataEntity.setTotalAmountPaid(StringUtils.isBlank(historicalData.getTotalAmountPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getTotalAmountPaid()));
customerHistoricalDataEntity.setTotalPaymentsCount(historicalData.getTotalPaymentsCount());
customerHistoricalDataEntity.setMfiJoiningDate(historicalData.getMfiJoiningDate());
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(customerBO);
customerBO.updateHistoricalData(customerHistoricalDataEntity);
this.customerDao.save(customerBO);
this.transactionHelper.commitTransaction();
} catch (ApplicationException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class CenterServiceFacadeWebTier method createCustomerNote.
@Override
public void createCustomerNote(CustomerNoteFormDto customerNoteForm) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
CustomerBO customer = this.customerDao.findCustomerBySystemId(customerNoteForm.getGlobalNum());
customer.updateDetails(userContext);
PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
CustomerNoteEntity customerNote = new CustomerNoteEntity(customerNoteForm.getComment(), new DateTimeService().getCurrentJavaSqlDate(), loggedInUser, customer);
customer.addCustomerNotes(customerNote);
try {
this.transactionHelper.startTransaction();
this.customerDao.save(customer);
this.transactionHelper.commitTransaction();
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(customer.getCustomerAccount().getAccountId().toString(), e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class MeetingAction method createMeeting.
private MeetingBO createMeeting(MeetingActionForm form) throws MeetingException {
MeetingBO meeting = null;
Date startDate = null;
if (form.getMeetingStartDate() == null || form.getMeetingStartDate().isEmpty()) {
startDate = new DateTimeService().getCurrentJavaDateTime();
} else {
startDate = DateUtils.getDate(form.getMeetingStartDate());
}
if (form.getRecurrenceType().equals(RecurrenceType.WEEKLY)) {
meeting = new MeetingBO(form.getWeekDayValue(), form.getRecurWeekValue(), startDate, MeetingType.CUSTOMER_MEETING, form.getMeetingPlace());
} else if (form.getRecurrenceType().equals(RecurrenceType.DAILY)) {
meeting = new MeetingBO(form.getRecurDayShort(), startDate, MeetingType.CUSTOMER_MEETING, form.getMeetingPlace());
} else if (form.isMonthlyOnDate()) {
meeting = new MeetingBO(form.getMonthDayValue(), form.getDayRecurMonthValue(), startDate, MeetingType.CUSTOMER_MEETING, form.getMeetingPlace());
} else {
meeting = new MeetingBO(form.getMonthWeekValue(), form.getMonthRankValue(), form.getRecurMonthValue(), startDate, MeetingType.CUSTOMER_MEETING, form.getMeetingPlace());
}
return meeting;
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class EditStatusAction method update.
@TransactionDemarcate(validateAndResetToken = true)
@CloseSession
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
UserContext userContext = getUserContext(request);
EditStatusActionForm editStatusActionForm = (EditStatusActionForm) form;
Integer accountId = Integer.valueOf(editStatusActionForm.getAccountId());
AccountBO accountBO = new AccountBusinessService().getAccount(accountId);
Short flagId = null;
Short newStatusId = null;
String updateComment = editStatusActionForm.getNotes();
if (StringUtils.isNotBlank(editStatusActionForm.getFlagId())) {
flagId = getShortValue(editStatusActionForm.getFlagId());
}
if (StringUtils.isNotBlank(editStatusActionForm.getNewStatusId())) {
newStatusId = getShortValue(editStatusActionForm.getNewStatusId());
}
Date trxnDate = editStatusActionForm.getTransactionDateValue(userContext.getPreferredLocale());
if (editStatusActionForm.getNewStatusId().equals(AccountState.LOAN_APPROVED) && !AccountingRules.isBackDatedApprovalAllowed()) {
trxnDate = new DateTimeService().getCurrentJavaDateTime();
}
checkPermission(accountBO, getUserContext(request), newStatusId, flagId);
if (accountBO.isLoanAccount() || accountBO.isGroupLoanAccount()) {
initializeLoanQuestionnaire(accountBO.getGlobalAccountNum(), newStatusId != null ? newStatusId.toString() : null);
loanQuestionnaire.saveResponses(request, editStatusActionForm, accountId);
//GLIM
List<LoanBO> individualLoans = this.loanDao.findIndividualLoans(accountId);
List<AccountUpdateStatus> updateStatus = new ArrayList<AccountUpdateStatus>(individualLoans.size() + 1);
updateStatus.add(new AccountUpdateStatus(accountId.longValue(), newStatusId, flagId, updateComment));
for (LoanBO individual : individualLoans) {
updateStatus.add(new AccountUpdateStatus(individual.getAccountId().longValue(), newStatusId, flagId, updateComment));
}
try {
if (individualLoans.size() == 0) {
this.loanAccountServiceFacade.updateSingleLoanAccountStatus(updateStatus.get(0), trxnDate);
} else {
this.loanAccountServiceFacade.updateSeveralLoanAccountStatuses(updateStatus, trxnDate);
}
} catch (AccessDeniedException e) {
throw new ServiceException(SecurityConstants.KEY_ACTIVITY_APPROVE_LOAN_NOT_ALLOWED);
}
return mapping.findForward(ActionForwards.loan_detail_page.toString());
}
if (accountBO.isSavingsAccount()) {
AccountUpdateStatus updateStatus = new AccountUpdateStatus(accountId.longValue(), newStatusId, flagId, updateComment);
this.savingsServiceFacade.updateSavingsAccountStatus(updateStatus);
return mapping.findForward(ActionForwards.savings_details_page.toString());
}
// nothing but loan of savings account should be detected. customer account status change goes through separate action.
return null;
}
use of org.mifos.framework.util.DateTimeService in project head by mifos.
the class LoanAdjustmentsIntegrationTest method testWhenACompletedLoanIsAdjustedThatAnAccountStatusChangeHistoryEntryisCreated.
@Test
public void testWhenACompletedLoanIsAdjustedThatAnAccountStatusChangeHistoryEntryisCreated() throws Exception {
// relates to mifos-3479
new DateTimeService().setCurrentDateTimeFixed(date(2010, 10, 13));
loan = createLoan();
loan.updateDetails(TestUtils.makeUserWithLocales());
// pay 3 installments
makePayment(loan, "333.0");
loan.updateDetails(TestUtils.makeUserWithLocales());
makeEarlyPayment(loan);
loan.updateDetails(TestUtils.makeUserWithLocales());
adjustLastLoanPayment(loan);
loan.updateDetails(TestUtils.makeUserWithLocales());
assertNotNull("Account Status Change History Should Not Be Null", loan.getAccountStatusChangeHistory());
Integer listSize = loan.getAccountStatusChangeHistory().size();
assertFalse(listSize == 0);
// check if the last entry has an oldstatus LOAN_CLOSED_OBLIGATIONS_MET and a new status of
// LOAN_ACTIVE_IN_GOOD_STANDING
AccountStateEntity oldStatus = loan.getAccountStatusChangeHistory().get(listSize - 1).getOldStatus();
AccountStateEntity newStatus = loan.getAccountStatusChangeHistory().get(listSize - 1).getNewStatus();
assertTrue("Old Status Should Have Been LOAN_CLOSED_OBLIGATIONS_MET", oldStatus.isInState(AccountState.LOAN_CLOSED_OBLIGATIONS_MET));
assertTrue("New Status Should Have Been LOAN_ACTIVE_IN_GOOD_STANDING", newStatus.isInState(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING));
}
Aggregations