use of org.mifos.accounts.savings.persistence.SavingsPersistence in project head by mifos.
the class CustomerServiceImpl method changeStatus.
private void changeStatus(CustomerBO customer, CustomerStatus oldStatus, CustomerStatus newStatus) throws CustomerException {
Short oldStatusId = oldStatus.getValue();
Short newStatusId = newStatus.getValue();
if (customer.isClient()) {
ClientBO client = (ClientBO) customer;
if (client.isActiveForFirstTime(oldStatusId, newStatusId)) {
if (client.getParentCustomer() != null) {
CustomerHierarchyEntity hierarchy = new CustomerHierarchyEntity(client, client.getParentCustomer());
client.addCustomerHierarchy(hierarchy);
}
CalendarEvent applicableCalendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
List<AccountFeesEntity> accountFees = new ArrayList<AccountFeesEntity>(customer.getCustomerAccount().getAccountFees());
client.getCustomerAccount().createSchedulesAndFeeSchedulesForFirstTimeActiveCustomer(customer, accountFees, customer.getCustomerMeetingValue(), applicableCalendarEvents, new DateMidnight().toDateTime());
client.setCustomerActivationDate(new DateTimeService().getCurrentJavaDateTime());
if (client.getOfferingsAssociatedInCreate() != null) {
for (ClientInitialSavingsOfferingEntity clientOffering : client.getOfferingsAssociatedInCreate()) {
try {
SavingsOfferingBO savingsOffering = savingsProductDao.findById(clientOffering.getSavingsOffering().getPrdOfferingId().intValue());
if (savingsOffering.isActive()) {
List<CustomFieldDto> customerFieldsForSavings = new ArrayList<CustomFieldDto>();
client.addAccount(new SavingsBO(client.getUserContext(), savingsOffering, client, AccountState.SAVINGS_ACTIVE, savingsOffering.getRecommendedAmount(), customerFieldsForSavings));
}
} catch (AccountException pe) {
throw new CustomerException(pe);
}
}
}
new SavingsPersistence().persistSavingAccounts(client);
try {
if (client.getParentCustomer() != null) {
List<SavingsBO> savingsList = new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getCustomerId());
if (client.getParentCustomer().getParentCustomer() != null) {
savingsList.addAll(new CustomerPersistence().retrieveSavingsAccountForCustomer(client.getParentCustomer().getParentCustomer().getCustomerId()));
}
for (SavingsBO savings : savingsList) {
savings.setUserContext(client.getUserContext());
if (client.getCustomerMeeting().getMeeting() != null) {
if (!(savings.getCustomer().getLevel() == CustomerLevel.GROUP && savings.getRecommendedAmntUnit().getId().equals(RecommendedAmountUnit.COMPLETE_GROUP.getValue()))) {
DateTime today = new DateTime().toDateMidnight().toDateTime();
savings.generateDepositAccountActions(client, client.getCustomerMeeting().getMeeting(), applicableCalendarEvents.getWorkingDays(), applicableCalendarEvents.getHolidays(), today);
savings.update();
}
}
}
}
} catch (PersistenceException pe) {
throw new CustomerException(pe);
} catch (AccountException ae) {
throw new CustomerException(ae);
}
}
}
}
use of org.mifos.accounts.savings.persistence.SavingsPersistence in project head by mifos.
the class LegacyClientDao method saveClient.
public void saveClient(final ClientBO clientBO) throws CustomerException {
CustomerPersistence customerPersistence = new CustomerPersistence();
customerPersistence.saveCustomer(clientBO);
try {
if (clientBO.getParentCustomer() != null) {
customerPersistence.createOrUpdate(clientBO.getParentCustomer());
}
// seems fishy... why do savings accounts need updating here?
new SavingsPersistence().persistSavingAccounts(clientBO);
} catch (PersistenceException pe) {
throw new CustomerException(CustomerConstants.CREATE_FAILED_EXCEPTION, pe);
}
}
use of org.mifos.accounts.savings.persistence.SavingsPersistence in project head by mifos.
the class SavingsApplyAdjustmentAction method adjustLastUserAction.
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward adjustLastUserAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
request.setAttribute("method", "adjustLastUserAction");
UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
Integer accountId = savings.getAccountId();
Integer versionNum = savings.getVersionNo();
savings = savingsDao.findById(accountId);
// NOTE: initialise so when error occurs when apply adjustment, savings object is correctly initialised for
// use within Tag library in jsp.
new SavingsPersistence().initialize(savings);
checkVersionMismatch(versionNum, savings.getVersionNo());
savings.setUserContext(uc);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
if (savings.getPersonnel() != null) {
getBizService().checkPermissionForAdjustment(AccountTypes.SAVINGS_ACCOUNT, null, uc, savings.getOffice().getOfficeId(), savings.getPersonnel().getPersonnelId());
} else {
getBizService().checkPermissionForAdjustment(AccountTypes.SAVINGS_ACCOUNT, null, uc, savings.getOffice().getOfficeId(), uc.getId());
}
SavingsApplyAdjustmentActionForm actionForm = (SavingsApplyAdjustmentActionForm) form;
if (actionForm.getLastPaymentAmount() == null) {
throw new MifosRuntimeException("Null payment amount is not allowed");
}
// date validation
Date meetingDate = new CustomerPersistence().getLastMeetingDateForCustomer(savings.getCustomer().getCustomerId());
boolean repaymentIndependentOfMeetingEnabled = new ConfigurationPersistence().isRepaymentIndepOfMeetingEnabled();
if (!savings.isTrxnDateValid(actionForm.getTrxnDateLocal().toDateMidnight().toDate(), meetingDate, repaymentIndependentOfMeetingEnabled)) {
throw new AccountException(AccountConstants.ERROR_INVALID_TRXN);
}
Long savingsId = Long.valueOf(accountId.toString());
Double adjustedAmount = Double.valueOf(actionForm.getLastPaymentAmount());
String note = actionForm.getNote();
AccountPaymentEntity adjustedPayment = savings.findPaymentById(actionForm.getPaymentId());
AccountPaymentEntity otherTransferPayment = adjustedPayment.getOtherTransferPayment();
try {
if (otherTransferPayment == null || otherTransferPayment.isSavingsDepositOrWithdrawal()) {
// regular savings payment adjustment or savings-savings transfer adjustment
SavingsAdjustmentDto savingsAdjustment = new SavingsAdjustmentDto(savingsId, adjustedAmount, note, actionForm.getPaymentId(), actionForm.getTrxnDateLocal());
this.savingsServiceFacade.adjustTransaction(savingsAdjustment);
} else {
// adjust repayment from savings account
AccountBO account = adjustedPayment.getOtherTransferPayment().getAccount();
AdjustedPaymentDto adjustedPaymentDto = new AdjustedPaymentDto(actionForm.getLastPaymentAmount(), actionForm.getTrxnDateLocal().toDateMidnight().toDate(), otherTransferPayment.getPaymentType().getId());
this.accountServiceFacade.applyHistoricalAdjustment(account.getGlobalAccountNum(), otherTransferPayment.getPaymentId(), note, uc.getId(), adjustedPaymentDto);
}
} catch (BusinessRuleException e) {
throw new AccountException(e.getMessageKey(), e);
} finally {
doCleanUp(request);
}
return mapping.findForward("account_detail_page");
}
use of org.mifos.accounts.savings.persistence.SavingsPersistence in project head by mifos.
the class SavingsClosureAction method load.
@TransactionDemarcate(joinToken = true)
public ActionForward load(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
actionForm.clearForm();
UserContext uc = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
SavingsBO savings = (SavingsBO) SessionUtils.getAttribute(Constants.BUSINESS_KEY, request);
Long savingsId = Long.valueOf(savings.getAccountId());
savings = this.savingsDao.findById(savingsId);
savings.setUserContext(uc);
// NOTE: initialise so when error occurs when apply adjustment, savings object is correctly initialised for
// use within Tag library in jsp.
new SavingsPersistence().initialize(savings);
LocalDate accountCloseDate = new LocalDate();
SavingsAccountClosureDto closureDetails = this.savingsServiceFacade.retrieveClosingDetails(savingsId, accountCloseDate);
LegacyAcceptedPaymentTypeDao persistence = legacyAcceptedPaymentTypeDao;
List<PaymentTypeEntity> acceptedPaymentTypes = persistence.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.savings_withdrawal.getValue());
Money interestAmountDue = new Money(savings.getCurrency(), closureDetails.getInterestAmountAtClosure());
Money endOfAccountBalance = new Money(savings.getCurrency(), closureDetails.getBalance());
Date transactionDate = closureDetails.getClosureDate().toDateMidnight().toDate();
Money withdrawalAmountAtClosure = endOfAccountBalance.add(interestAmountDue);
AccountPaymentEntity payment = new AccountPaymentEntity(savings, withdrawalAmountAtClosure, null, null, null, transactionDate);
actionForm.setAmount(withdrawalAmountAtClosure.toString());
actionForm.setTrxnDate(DateUtils.getCurrentDate(uc.getPreferredLocale()));
SessionUtils.setAttribute(Constants.BUSINESS_KEY, savings, request);
SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, acceptedPaymentTypes, request);
SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, payment, request);
return mapping.findForward("load_success");
}
use of org.mifos.accounts.savings.persistence.SavingsPersistence in project head by mifos.
the class SavingsAccountRESTController method applyAdjustment.
@RequestMapping(value = "account/savings/num-{globalAccountNum}/adjustment", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> applyAdjustment(@PathVariable String globalAccountNum, @RequestParam BigDecimal amount, @RequestParam String note, @RequestParam(required = false) Integer paymentId) throws Exception {
validateAmount(amount);
validateNote(note);
SavingsBO savingsBO = savingsDao.findBySystemId(globalAccountNum);
new SavingsPersistence().initialize(savingsBO);
Integer accountId = savingsBO.getAccountId();
Long savingsId = Long.valueOf(accountId.toString());
SavingsAdjustmentDto savingsAdjustment = new SavingsAdjustmentDto(savingsId, amount.doubleValue(), note, (paymentId == null) ? savingsBO.getLastPmnt().getPaymentId() : paymentId, new LocalDate(savingsBO.getLastPmnt().getPaymentDate()));
Money balanceBeforePayment = savingsBO.getSavingsBalance();
this.savingsServiceFacade.adjustTransaction(savingsAdjustment);
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
DateTime today = new DateTime();
CustomerBO client = savingsBO.getCustomer();
Map<String, String> map = new HashMap<String, String>();
map.put("status", "success");
map.put("clientName", client.getDisplayName());
map.put("clientNumber", client.getGlobalCustNum());
map.put("savingsDisplayName", savingsBO.getSavingsOffering().getPrdOfferingName());
map.put("adjustmentDate", today.toLocalDate().toString());
map.put("adjustmentTime", today.toLocalTime().toString());
map.put("adjustmentAmount", savingsBO.getLastPmnt().getAmount().toString());
map.put("adjustmentMadeBy", personnelDao.findPersonnelById((short) user.getUserId()).getDisplayName());
map.put("balanceBeforeAdjustment", balanceBeforePayment.toString());
map.put("balanceAfterAdjustment", savingsBO.getSavingsBalance().toString());
map.put("note", note);
return map;
}
Aggregations