use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class AccountAppAction method removeFees.
@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward removeFees(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
Integer accountId = getIntegerValue(request.getParameter("accountId"));
Short feeId = getShortValue(request.getParameter("feeId"));
this.centerServiceFacade.removeAccountFee(accountId, feeId);
AccountBO accountBO = getAccountBusinessService().getAccount(accountId);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
String fromPage = request.getParameter(CenterConstants.FROM_PAGE);
StringBuilder forward = new StringBuilder();
forward = forward.append(AccountConstants.REMOVE + "_" + fromPage + "_" + AccountConstants.CHARGES);
if (fromPage != null) {
return mapping.findForward(forward.toString());
}
return mapping.findForward(AccountConstants.REMOVE_SUCCESS);
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class AccountAppAction method removePenalties.
@CloseSession
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward removePenalties(ActionMapping mapping, @SuppressWarnings("unused") ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
Integer accountId = getIntegerValue(request.getParameter("accountId"));
Short penaltyId = getShortValue(request.getParameter("penaltyId"));
AccountBO accountBO = getAccountBusinessService().getAccount(accountId);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
if (accountBO instanceof LoanBO) {
this.loanAccountServiceFacade.removeLoanPenalty(accountId, penaltyId);
}
String fromPage = request.getParameter(CenterConstants.FROM_PAGE);
StringBuilder forward = new StringBuilder();
forward = forward.append(AccountConstants.REMOVE + "_" + fromPage + "_" + AccountConstants.CHARGES);
if (fromPage != null) {
return mapping.findForward(forward.toString());
}
return mapping.findForward(AccountConstants.REMOVE_SUCCESS);
}
use of org.mifos.accounts.business.AccountBO 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.business.AccountBO in project head by mifos.
the class AccountApplyPaymentActionForm method validateModeOfPaymentSecurity.
private void validateModeOfPaymentSecurity(HttpServletRequest request, ActionErrors errors) {
UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
AccountBO account = null;
Short personnelId = userContext.getId();
try {
if (accountId != null) {
account = new AccountBusinessService().getAccount(Integer.valueOf(accountId));
if (account.getPersonnel() != null) {
personnelId = account.getPersonnel().getPersonnelId();
}
}
} catch (NumberFormatException e) {
throw new MifosRuntimeException(e);
} catch (ServiceException e) {
throw new MifosRuntimeException(e);
}
if (getPaymentTypeId().equals("4") && !ActivityMapper.getInstance().isModeOfPaymentSecurity(userContext, personnelId)) {
errors.add(AccountConstants.LOAN_TRANSFER_PERMISSION, new ActionMessage(AccountConstants.LOAN_TRANSFER_PERMISSION, getLocalizedMessage("accounts.mode_of_payment_permission")));
}
}
use of org.mifos.accounts.business.AccountBO in project head by mifos.
the class GenerateMeetingsForCustomerAndSavingsHelper method execute.
@Override
public void execute(@SuppressWarnings("unused") final long timeInMillis) throws BatchJobException {
workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays();
officeCurrentAndFutureHolidays = new HashMap<Short, List<Holiday>>();
long taskStartTime = new DateTimeService().getCurrentDateTime().getMillis();
List<Integer> customerAndSavingsAccountIds = findActiveCustomerAndSavingsAccountIdsThatRequiredMeetingsToBeGenerated();
int accountCount = customerAndSavingsAccountIds.size();
if (accountCount == 0) {
return;
}
List<String> errorList = new ArrayList<String>();
int currentRecordNumber = 0;
int outputIntervalForBatchJobs = GeneralConfig.getOutputIntervalForBatchJobs();
int batchSize = GeneralConfig.getBatchSizeForBatchJobs();
// jpw - hardcoded recordCommittingSize to 500 because now only accounts that need more schedules are returned
int recordCommittingSize = 500;
infoLogBatchParameters(accountCount, outputIntervalForBatchJobs, batchSize, recordCommittingSize);
long startTime = new DateTimeService().getCurrentDateTime().getMillis();
Integer currentAccountId = null;
int updatedRecordCount = 0;
try {
StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
for (Integer accountId : customerAndSavingsAccountIds) {
currentRecordNumber++;
currentAccountId = accountId;
AccountBO accountBO = legacyAccountDao.getAccount(accountId);
List<Holiday> currentAndFutureHolidays = getOfficeCurrentAndFutureHolidays(accountBO.getOffice().getOfficeId());
ScheduledDateGeneration scheduleGenerationStrategy = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration(workingDays, currentAndFutureHolidays);
if (accountBO instanceof CustomerAccountBO) {
((CustomerAccountBO) accountBO).generateNextSetOfMeetingDates(scheduleGenerationStrategy);
updatedRecordCount++;
} else if (accountBO instanceof SavingsBO) {
((SavingsBO) accountBO).generateNextSetOfMeetingDates(workingDays, currentAndFutureHolidays);
updatedRecordCount++;
}
if (currentRecordNumber % batchSize == 0) {
StaticHibernateUtil.flushAndClearSession();
getLogger().debug("completed HibernateUtil.flushAndClearSession()");
}
if (updatedRecordCount > 0) {
if (updatedRecordCount % recordCommittingSize == 0) {
StaticHibernateUtil.commitTransaction();
StaticHibernateUtil.getSessionTL();
StaticHibernateUtil.startTransaction();
}
}
if (currentRecordNumber % outputIntervalForBatchJobs == 0) {
long time = System.currentTimeMillis();
String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
logMessage(message);
startTime = time;
}
}
StaticHibernateUtil.commitTransaction();
long time = System.currentTimeMillis();
String message = "" + currentRecordNumber + " processed, " + (accountCount - currentRecordNumber) + " remaining, " + updatedRecordCount + " updated, batch time: " + (time - startTime) + " ms";
logMessage(message);
} catch (Exception e) {
logMessage("account " + currentAccountId.intValue() + " exception " + e.getMessage());
StaticHibernateUtil.rollbackTransaction();
errorList.add(currentAccountId.toString());
getLogger().error("Unable to generate schedules for account with ID " + currentAccountId, e);
} finally {
StaticHibernateUtil.closeSession();
}
if (errorList.size() > 0) {
throw new BatchJobException(SchedulerConstants.FAILURE, errorList);
}
logMessage("GenerateMeetingsForCustomerAndSavings ran in " + (new DateTimeService().getCurrentDateTime().getMillis() - taskStartTime));
}
Aggregations