Search in sources :

Example 21 with PaymentTypeEntity

use of org.mifos.application.master.business.PaymentTypeEntity in project head by mifos.

the class RepayLoanAction method loadRepayment.

@TransactionDemarcate(joinToken = true)
public ActionForward loadRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.info("Loading repay loan page");
    RepayLoanActionForm actionForm = (RepayLoanActionForm) form;
    actionForm.setReceiptNumber(null);
    actionForm.setReceiptDate(null);
    actionForm.setPaymentTypeId(null);
    actionForm.setWaiverInterest(true);
    actionForm.setDateOfPayment(DateUtils.makeDateAsSentFromBrowser());
    actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
    actionForm.setPrintReceipt(false);
    actionForm.setTruePrintReceipt(false);
    UserContext userContext = getUserContext(request);
    String globalAccountNum = request.getParameter("globalAccountNum");
    RepayLoanDto repayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(globalAccountNum);
    LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
    java.util.Date lastPaymentDate = new java.util.Date(0);
    AccountPaymentEntity lastPayment = loan.findMostRecentNonzeroPaymentByPaymentDate();
    if (lastPayment != null) {
        lastPaymentDate = lastPayment.getPaymentDate();
    }
    actionForm.setLastPaymentDate(lastPaymentDate);
    SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST, repayLoanDto.shouldWaiverInterest(), request);
    SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST_SELECTED, repayLoanDto.shouldWaiverInterest(), request);
    SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, new Money(loan.getCurrency(), repayLoanDto.getEarlyRepaymentMoney()), request);
    SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, new Money(loan.getCurrency(), repayLoanDto.getWaivedRepaymentMoney()), request);
    SessionUtils.setCollectionAttribute(Constants.ACCOUNTS_FOR_TRANSFER, repayLoanDto.getSavingsAccountsForTransfer(), request);
    List<PaymentTypeEntity> loanPaymentTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.loan_repayment.getValue());
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, loanPaymentTypes, request);
    return mapping.findForward(Constants.LOAD_SUCCESS);
}
Also used : UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) Date(java.sql.Date) LocalDate(org.joda.time.LocalDate) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 22 with PaymentTypeEntity

use of org.mifos.application.master.business.PaymentTypeEntity in project head by mifos.

the class LoanDisbursementAction method load.

@TransactionDemarcate(joinToken = true)
public ActionForward load(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanDisbursementActionForm loanDisbursementActionForm = (LoanDisbursementActionForm) form;
    loanDisbursementActionForm.clear();
    loanDisbursementActionForm.setAmountCannotBeZero(false);
    Integer loanAccountId = Integer.valueOf(loanDisbursementActionForm.getAccountId());
    LoanDisbursalDto loanDisbursalDto = loanAccountServiceFacade.retrieveLoanDisbursalDetails(loanAccountId);
    UserContext uc = getUserContext(request);
    SessionUtils.setAttribute(LoanConstants.PROPOSED_DISBURSAL_DATE, loanDisbursalDto.getProposedDate(), request);
    loanDisbursementActionForm.setTransactionDate(getUserLocaleDate(uc.getPreferredLocale(), loanDisbursalDto.getProposedDate()));
    loanDisbursementActionForm.setAmount(loanDisbursalDto.getAmountPaidAtDisbursement());
    loanDisbursementActionForm.setLoanAmount(loanDisbursalDto.getLoanAmount());
    if (loanDisbursalDto.isMultiCurrencyEnabled()) {
        loanDisbursementActionForm.setCurrencyId(loanDisbursalDto.getCurrencyId());
    }
    Short repaymentIndependentOfMeetingScheduleValue = loanDisbursalDto.isRepaymentIndependentOfMeetingSchedule() ? Short.valueOf("1") : Short.valueOf("0");
    SessionUtils.setAttribute(LoanConstants.REPAYMENT_SCHEDULES_INDEPENDENT_OF_MEETING_IS_ENABLED, repaymentIndependentOfMeetingScheduleValue, request);
    SessionUtils.setAttribute(AccountingRulesConstants.BACKDATED_TRANSACTIONS_ALLOWED, loanDisbursalDto.isBackDatedTransactionsAllowed(), request);
    List<PaymentTypeEntity> disbursementTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.loan_disbursement.getValue());
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, disbursementTypes, request);
    List<PaymentTypeEntity> feesTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(uc.getLocaleId(), TrxnTypes.loan_repayment.getValue());
    SessionUtils.setCollectionAttribute(MasterConstants.FEE_PAYMENT_TYPE, feesTypes, request);
    SessionUtils.setAttribute(LoanConstants.PAYMENT_TYPE_TRANSFER_FROM_SAVINGS_ID, legacyAcceptedPaymentTypeDao.getSavingsTransferId(), request);
    SessionUtils.setCollectionAttribute(Constants.ACCOUNTS_FOR_TRANSFER, accountServiceFacade.getActiveSavingsAccountsForClientByLoanId(loanAccountId), request);
    return mapping.findForward(Constants.LOAD_SUCCESS);
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) LoanDisbursementActionForm(org.mifos.accounts.loan.struts.actionforms.LoanDisbursementActionForm) UserContext(org.mifos.security.util.UserContext) LoanDisbursalDto(org.mifos.dto.screen.LoanDisbursalDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 23 with PaymentTypeEntity

use of org.mifos.application.master.business.PaymentTypeEntity in project head by mifos.

the class RepayLoanAction method loadGroupRepayment.

@TransactionDemarcate(joinToken = true)
public ActionForward loadGroupRepayment(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    logger.info("Loading repay group loan page");
    RepayLoanActionForm actionForm = (RepayLoanActionForm) form;
    actionForm.setReceiptNumber(null);
    actionForm.setReceiptDate(null);
    actionForm.setPaymentTypeId(null);
    actionForm.setWaiverInterest(true);
    actionForm.setDateOfPayment(DateUtils.makeDateAsSentFromBrowser());
    actionForm.setTransferPaymentTypeId(this.legacyAcceptedPaymentTypeDao.getSavingsTransferId());
    actionForm.setPrintReceipt(false);
    actionForm.setTruePrintReceipt(false);
    UserContext userContext = getUserContext(request);
    LoanBO parent = loanDao.findByGlobalAccountNum(request.getParameter("globalAccountNum"));
    RepayLoanDto parentRepayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(parent.getGlobalAccountNum());
    Map<String, Double> memberNumWithAmount = new HashMap<String, Double>();
    Money earlyRepaymentMoney;
    Money waivedRepaymentMoney;
    if (parent.isGroupLoanAccountMember()) {
        earlyRepaymentMoney = new Money(parent.getCurrency(), parentRepayLoanDto.getEarlyRepaymentMoney());
        waivedRepaymentMoney = new Money(parent.getCurrency(), parentRepayLoanDto.getWaivedRepaymentMoney());
    } else {
        earlyRepaymentMoney = new Money(parent.getCurrency());
        waivedRepaymentMoney = new Money(parent.getCurrency());
    }
    for (LoanBO member : parent.getMemberAccounts()) {
        RepayLoanDto memberRepayLoanDto = this.loanAccountServiceFacade.retrieveLoanRepaymentDetails(member.getGlobalAccountNum());
        earlyRepaymentMoney = earlyRepaymentMoney.add(new Money(parent.getCurrency(), memberRepayLoanDto.getEarlyRepaymentMoney()));
        waivedRepaymentMoney = waivedRepaymentMoney.add(new Money(parent.getCurrency(), memberRepayLoanDto.getWaivedRepaymentMoney()));
        memberNumWithAmount.put(member.getAccountId().toString(), Double.valueOf(memberRepayLoanDto.getEarlyRepaymentMoney()));
    }
    java.util.Date lastPaymentDate = new java.util.Date(0);
    AccountPaymentEntity lastPayment = parent.findMostRecentNonzeroPaymentByPaymentDate();
    if (lastPayment != null) {
        lastPaymentDate = lastPayment.getPaymentDate();
    }
    actionForm.setLastPaymentDate(lastPaymentDate);
    SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST, parentRepayLoanDto.shouldWaiverInterest(), request);
    SessionUtils.setAttribute(LoanConstants.WAIVER_INTEREST_SELECTED, parentRepayLoanDto.shouldWaiverInterest(), request);
    SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, earlyRepaymentMoney, request);
    SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, waivedRepaymentMoney, request);
    SessionUtils.setCollectionAttribute(Constants.ACCOUNTS_FOR_TRANSFER, parentRepayLoanDto.getSavingsAccountsForTransfer(), request);
    SessionUtils.setMapAttribute(LoanConstants.MEMBER_LOAN_REPAYMENT, new HashMap<String, Double>(memberNumWithAmount), request);
    List<PaymentTypeEntity> loanPaymentTypes = legacyAcceptedPaymentTypeDao.getAcceptedPaymentTypesForATransaction(userContext.getLocaleId(), TrxnTypes.loan_repayment.getValue());
    SessionUtils.setCollectionAttribute(MasterConstants.PAYMENT_TYPE, loanPaymentTypes, request);
    return mapping.findForward(Constants.LOAD_GROUP_SUCCESS);
}
Also used : HashMap(java.util.HashMap) UserContext(org.mifos.security.util.UserContext) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) Date(java.sql.Date) LocalDate(org.joda.time.LocalDate) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money) RepayLoanDto(org.mifos.dto.screen.RepayLoanDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 24 with PaymentTypeEntity

use of org.mifos.application.master.business.PaymentTypeEntity 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");
}
Also used : SavingsPersistence(org.mifos.accounts.savings.persistence.SavingsPersistence) UserContext(org.mifos.security.util.UserContext) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsClosureActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm) SavingsBO(org.mifos.accounts.savings.business.SavingsBO) LocalDate(org.joda.time.LocalDate) SavingsAccountClosureDto(org.mifos.dto.domain.SavingsAccountClosureDto) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) Money(org.mifos.framework.util.helpers.Money) LegacyAcceptedPaymentTypeDao(org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 25 with PaymentTypeEntity

use of org.mifos.application.master.business.PaymentTypeEntity in project head by mifos.

the class SavingsClosureAction method preview.

@TransactionDemarcate(joinToken = true)
public ActionForward preview(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    SavingsClosureActionForm actionForm = (SavingsClosureActionForm) form;
    AccountPaymentEntity payment = (AccountPaymentEntity) SessionUtils.getAttribute(SavingsConstants.ACCOUNT_PAYMENT, request);
    AccountPaymentEntity accountPaymentEntity = null;
    Date transactionDate = new DateTimeService().getCurrentJavaDateTime();
    if (actionForm.getReceiptDate() != null && actionForm.getReceiptDate() != "") {
        accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), new java.util.Date(DateUtils.getDateAsSentFromBrowser(actionForm.getReceiptDate()).getTime()), new PaymentTypeEntity(Short.valueOf(actionForm.getPaymentTypeId())), transactionDate);
    } else {
        if (actionForm.getPaymentTypeId() != null && !actionForm.getPaymentTypeId().equals("")) {
            if (!(actionForm.getPaymentTypeId().equals(""))) {
                accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(Short.valueOf(actionForm.getPaymentTypeId())), transactionDate);
            } else {
                accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(), transactionDate);
            }
        } else {
            accountPaymentEntity = new AccountPaymentEntity(payment.getAccount(), payment.getAmount(), actionForm.getReceiptId(), null, new PaymentTypeEntity(), transactionDate);
        }
    }
    SessionUtils.setAttribute(SavingsConstants.ACCOUNT_PAYMENT, accountPaymentEntity, request);
    return closeSavingsQuestionnaire.fetchAppliedQuestions(mapping, actionForm, request, ActionForwards.preview_success);
}
Also used : PaymentTypeEntity(org.mifos.application.master.business.PaymentTypeEntity) AccountPaymentEntity(org.mifos.accounts.business.AccountPaymentEntity) SavingsClosureActionForm(org.mifos.accounts.savings.struts.actionforms.SavingsClosureActionForm) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

PaymentTypeEntity (org.mifos.application.master.business.PaymentTypeEntity)40 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)24 LocalDate (org.joda.time.LocalDate)16 Money (org.mifos.framework.util.helpers.Money)16 Date (java.util.Date)15 ArrayList (java.util.ArrayList)13 UserContext (org.mifos.security.util.UserContext)12 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)10 Date (java.sql.Date)9 Test (org.junit.Test)9 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)8 MifosRuntimeException (org.mifos.core.MifosRuntimeException)8 PersistenceException (org.mifos.framework.exceptions.PersistenceException)8 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)8 CustomerBO (org.mifos.customers.business.CustomerBO)6 DateTime (org.joda.time.DateTime)4 AcceptedPaymentType (org.mifos.accounts.acceptedpaymenttype.business.AcceptedPaymentType)4 DateTimeService (org.mifos.framework.util.DateTimeService)4 BigDecimal (java.math.BigDecimal)3 LegacyAcceptedPaymentTypeDao (org.mifos.accounts.acceptedpaymenttype.persistence.LegacyAcceptedPaymentTypeDao)3