Search in sources :

Example 6 with LoanAccountDto

use of org.mifos.accounts.loan.util.helpers.LoanAccountDto in project head by mifos.

the class ProductDtoComparator method createEntryViewHierarchyFromCollectionSheetData.

private CollectionSheetEntryDto createEntryViewHierarchyFromCollectionSheetData(final List<CollectionSheetCustomerDto> collectionSheetCustomerHierarchy, final MifosCurrency currency) {
    final int countOfCustomers = collectionSheetCustomerHierarchy.size();
    CollectionSheetEntryDto parentView = null;
    for (CollectionSheetCustomerDto customer : collectionSheetCustomerHierarchy) {
        final CustomerDto parentCustomerDetail = new CustomerDto(customer.getCustomerId(), customer.getName(), customer.getParentCustomerId(), customer.getLevelId());
        CollectionSheetEntryDto childView = new CollectionSheetEntryDto(parentCustomerDetail, currency);
        childView.setAttendence(customer.getAttendanceId());
        childView.setCountOfCustomers(countOfCustomers);
        final Integer accountId = customer.getCollectionSheetCustomerAccount().getAccountId();
        final Integer customerId = customer.getCustomerId();
        final Short installmentId = null;
        final Integer actionDateId = null;
        final Date actionDate = null;
        final Money miscFee = new Money(currency, customer.getCollectionSheetCustomerAccount().getTotalCustomerAccountCollectionFee().toString());
        final Money miscFeePaid = new Money(currency, "0.0");
        final Money miscPenalty = new Money(currency, "0.0");
        final Money miscPenaltyPaid = new Money(currency, "0.0");
        final CustomerAccountDto customerAccountDetails = new CustomerAccountDto(customer.getCollectionSheetCustomerAccount().getAccountId(), customer.getCustomerId(), currency);
        customerAccountDetails.setAccountId(customer.getCollectionSheetCustomerAccount().getAccountId());
        // we only create one installment fee and set the total amount due
        // in the miscFee column for now
        final CollectionSheetEntryInstallmentDto installmentView = new CollectionSheetEntryCustomerAccountInstallmentDto(accountId, customerId, installmentId, actionDateId, actionDate, miscFee, miscFeePaid, miscPenalty, miscPenaltyPaid, currency);
        final List<CollectionSheetEntryInstallmentDto> installmentViewList = java.util.Arrays.asList(installmentView);
        customerAccountDetails.setAccountActionDates(installmentViewList);
        childView.setCustomerAccountDetails(customerAccountDetails);
        // saving accounts
        for (CollectionSheetCustomerSavingDto customerSavingDto : customer.getCollectionSheetCustomerSaving()) {
            final Integer savCustomerId = customerSavingDto.getCustomerId();
            final Integer savAccountId = customerSavingDto.getAccountId();
            final String savingProductShortName = customerSavingDto.getProductShortName();
            final Short savOfferingId = customerSavingDto.getProductId();
            final Short savingsTypeId = Short.valueOf("1");
            final Short recommendedAmntUnitId = customerSavingDto.getRecommendedAmountUnitId();
            final SavingsAccountDto savingsAccount = new SavingsAccountDto(savAccountId, savCustomerId, savingProductShortName, savOfferingId, savingsTypeId, recommendedAmntUnitId);
            final Short savInstallmentId = null;
            final Integer savActionDateId = null;
            final Date savActionDate = null;
            final Money savDeposit = new Money(currency, customerSavingDto.getTotalDepositAmount().toString());
            final Money savDepositPaid = new Money(currency, "0.0");
            final CollectionSheetEntryInstallmentDto accountTrxnDetail = new CollectionSheetEntrySavingsInstallmentDto(savAccountId, savCustomerId, savInstallmentId, savActionDateId, savActionDate, savDeposit, savDepositPaid);
            savingsAccount.addAccountTrxnDetail(accountTrxnDetail);
            childView.addSavingsAccountDetail(savingsAccount);
        }
        // special savings accounts to be paid individually by clients
        for (CollectionSheetCustomerSavingDto clientIndividualSavingsAccount : customer.getIndividualSavingAccounts()) {
            final Integer savCustomerId = clientIndividualSavingsAccount.getCustomerId();
            final Integer savAccountId = clientIndividualSavingsAccount.getAccountId();
            final String savingProductShortName = clientIndividualSavingsAccount.getProductShortName();
            final Short savOfferingId = clientIndividualSavingsAccount.getProductId();
            final Short savingsTypeId = Short.valueOf("1");
            final Short recommendedAmntUnitId = Short.valueOf("1");
            final SavingsAccountDto savingsAccount = new SavingsAccountDto(savAccountId, savCustomerId, savingProductShortName, savOfferingId, savingsTypeId, recommendedAmntUnitId);
            final Short savInstallmentId = null;
            final Integer savActionDateId = null;
            final Date savActionDate = null;
            final Money savDeposit = new Money(currency, clientIndividualSavingsAccount.getDepositDue().toString());
            final Money savDepositPaid = new Money(currency, clientIndividualSavingsAccount.getDepositPaid().toString());
            final CollectionSheetEntryInstallmentDto accountTrxnDetail = new CollectionSheetEntrySavingsInstallmentDto(savAccountId, savCustomerId, savInstallmentId, savActionDateId, savActionDate, savDeposit, savDepositPaid);
            savingsAccount.addAccountTrxnDetail(accountTrxnDetail);
            childView.addSavingsAccountDetail(savingsAccount);
        }
        // loan accounts
        for (CollectionSheetCustomerLoanDto customerLoanDto : customer.getCollectionSheetCustomerLoan()) {
            final Integer loanAccountId = customerLoanDto.getAccountId();
            final Integer loanCustomerId = customerLoanDto.getCustomerId();
            final String loanOfferingShortName = customerLoanDto.getProductShortName();
            final Short loanOfferingId = customerLoanDto.getProductId();
            final Short loanInstallmentId = null;
            final Integer loanActionDateId = null;
            final Date loanActionDate = null;
            final Short loanAccountState = customerLoanDto.getAccountStateId();
            final Short interestDeductedAtDisbursement = customerLoanDto.getPayInterestAtDisbursement();
            final Money loanAmount = new Money(currency, customerLoanDto.getTotalDisbursement().toString());
            final Money principal = new Money(currency, customerLoanDto.getTotalRepaymentDue().toString());
            final LoanAccountDto loanAccount = new LoanAccountDto(loanAccountId, loanCustomerId, loanOfferingShortName, loanOfferingId, loanAccountState, interestDeductedAtDisbursement, loanAmount);
            loanAccount.setAmountPaidAtDisbursement(customerLoanDto.getAmountDueAtDisbursement());
            final CollectionSheetEntryInstallmentDto accountTrxnDetail = new CollectionSheetEntryLoanInstallmentDto(loanAccountId, loanCustomerId, loanInstallmentId, loanActionDateId, loanActionDate, principal, new Money(currency), new Money(currency), new Money(currency), new Money(currency), new Money(currency), new Money(currency), new Money(currency), new Money(currency), new Money(currency), currency);
            loanAccount.addTrxnDetails(Arrays.asList(accountTrxnDetail));
            childView.addLoanAccountDetails(loanAccount);
        }
        // center-group-client hierarchy
        if (parentView == null) {
            parentView = childView;
        } else {
            addChildToAppropriateParent(parentView, childView);
        }
    }
    return parentView;
}
Also used : CollectionSheetEntryLoanInstallmentDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryLoanInstallmentDto) CustomerAccountDto(org.mifos.customers.util.helpers.CustomerAccountDto) CustomerDto(org.mifos.dto.domain.CustomerDto) LoanAccountDto(org.mifos.accounts.loan.util.helpers.LoanAccountDto) Date(java.util.Date) SavingsAccountDto(org.mifos.accounts.savings.util.helpers.SavingsAccountDto) Money(org.mifos.framework.util.helpers.Money) CollectionSheetEntrySavingsInstallmentDto(org.mifos.application.collectionsheet.business.CollectionSheetEntrySavingsInstallmentDto) CollectionSheetEntryDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryDto) CollectionSheetEntryCustomerAccountInstallmentDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryCustomerAccountInstallmentDto) CollectionSheetEntryInstallmentDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryInstallmentDto)

Example 7 with LoanAccountDto

use of org.mifos.accounts.loan.util.helpers.LoanAccountDto in project head by mifos.

the class BulkEntryActionStrutsTest method getSuccessfulBulkEntry.

private CollectionSheetEntryGridDto getSuccessfulBulkEntry() throws Exception {
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    Date startDate = new Date(System.currentTimeMillis());
    center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
    client = TestObjectFactory.createClient("Client", CustomerStatus.CLIENT_ACTIVE, group);
    LoanOfferingBO loanOffering1 = TestObjectFactory.createLoanOffering(startDate, meeting);
    LoanOfferingBO loanOffering2 = TestObjectFactory.createLoanOffering("Loan2345", "313f", ApplicableTo.CLIENTS, startDate, PrdStatus.LOAN_ACTIVE, 300.0, 1.2, 3, InterestType.FLAT, meeting);
    groupAccount = TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, startDate, loanOffering1);
    clientAccount = getLoanAccount(AccountState.LOAN_APPROVED, startDate, 1, loanOffering2);
    Date currentDate = new Date(System.currentTimeMillis());
    // 2010-01-18: JohnW - This use of TestObjectFactory.createSavingsProduct used to break a number of
    // business rules.
    // E.g all the savings products were set up as applicable for Groups and "per individual" which is wrong for
    // centers and clients. In the case of the client being wrongly set up as "Per Individual" it now triggers save
    // collection sheet validation (which checks that the account associated with the client marked "per individual"
    // matches its parent group or center)
    // Also, when creating the center savings accounts (which is effectively "per individual") and the group savings
    // account which is "per individual" the saving_schedule entries for the client are not written (they are in the
    // production code).
    //
    // Considered using/updating the savingsProductBuilder functionality but that doesn't deal with the
    // "per individual" aspect either (update: it does, but still problem with builder creating installments).
    // Decided not to try and fix it up (good deal of effort involved) but rather change the
    // TestObjectFactory.createSavingsProduct to accept a RecommendedAmountUnit parameter.
    // Unfortunately it wouldn't allow a null parameter (which is valid for centers and clients) through so, where
    // necessary, I picked a value that worked for the test but was wrong in a business rule sense (just as its
    // always been).
    // So the savings product test data doesn't adhere to business rules but all tests pass here and in others
    // tests.
    SavingsOfferingBO savingsOffering1 = TestObjectFactory.createSavingsProduct("SavingPrd1", "ased", currentDate, RecommendedAmountUnit.COMPLETE_GROUP);
    SavingsOfferingBO savingsOffering2 = TestObjectFactory.createSavingsProduct("SavingPrd2", "cvdf", currentDate, RecommendedAmountUnit.COMPLETE_GROUP);
    SavingsOfferingBO savingsOffering3 = TestObjectFactory.createSavingsProduct("SavingPrd3", "zxsd", currentDate, RecommendedAmountUnit.COMPLETE_GROUP);
    centerSavingsAccount = TestObjectFactory.createSavingsAccount("43244334", center, Short.valueOf("16"), startDate, savingsOffering1);
    groupSavingsAccount = TestObjectFactory.createSavingsAccount("43234434", group, Short.valueOf("16"), startDate, savingsOffering2);
    clientSavingsAccount = TestObjectFactory.createSavingsAccount("43245434", client, Short.valueOf("16"), startDate, savingsOffering3);
    CollectionSheetEntryDto bulkEntryParent = new CollectionSheetEntryDto(getCusomerView(center), null);
    SavingsAccountDto centerSavingsAccountView = getSavingsAccountView(centerSavingsAccount);
    centerSavingsAccountView.setDepositAmountEntered("100");
    centerSavingsAccountView.setWithDrawalAmountEntered("10");
    bulkEntryParent.addSavingsAccountDetail(centerSavingsAccountView);
    bulkEntryParent.setCustomerAccountDetails(getCustomerAccountView(center));
    CollectionSheetEntryDto bulkEntryChild = new CollectionSheetEntryDto(getCusomerView(group), null);
    LoanAccountDto groupLoanAccountView = getLoanAccountView(groupAccount);
    SavingsAccountDto groupSavingsAccountView = getSavingsAccountView(groupSavingsAccount);
    groupSavingsAccountView.setDepositAmountEntered("100");
    groupSavingsAccountView.setWithDrawalAmountEntered("10");
    bulkEntryChild.addLoanAccountDetails(groupLoanAccountView);
    bulkEntryChild.addSavingsAccountDetail(groupSavingsAccountView);
    bulkEntryChild.setCustomerAccountDetails(getCustomerAccountView(group));
    CollectionSheetEntryDto bulkEntrySubChild = new CollectionSheetEntryDto(getCusomerView(client), null);
    LoanAccountDto clientLoanAccountView = getLoanAccountView(clientAccount);
    clientLoanAccountView.setAmountPaidAtDisbursement(0.0);
    SavingsAccountDto clientSavingsAccountView = getSavingsAccountView(clientSavingsAccount);
    clientSavingsAccountView.setDepositAmountEntered("100");
    clientSavingsAccountView.setWithDrawalAmountEntered("10");
    bulkEntrySubChild.addLoanAccountDetails(clientLoanAccountView);
    bulkEntrySubChild.setAttendence(new Short("2"));
    bulkEntrySubChild.addSavingsAccountDetail(clientSavingsAccountView);
    bulkEntrySubChild.setCustomerAccountDetails(getCustomerAccountView(client));
    bulkEntryChild.addChildNode(bulkEntrySubChild);
    bulkEntryParent.addChildNode(bulkEntryChild);
    LoanAccountsProductDto childView = bulkEntryChild.getLoanAccountDetails().get(0);
    childView.setPrdOfferingId(groupLoanAccountView.getPrdOfferingId());
    childView.setEnteredAmount("100.0");
    LoanAccountsProductDto subchildView = bulkEntrySubChild.getLoanAccountDetails().get(0);
    subchildView.setDisBursementAmountEntered(clientAccount.getLoanAmount().toString());
    subchildView.setPrdOfferingId(clientLoanAccountView.getPrdOfferingId());
    ProductDto loanOfferingDto = new ProductDto(loanOffering1.getPrdOfferingId(), loanOffering1.getPrdOfferingShortName());
    ProductDto loanOfferingDto2 = new ProductDto(loanOffering2.getPrdOfferingId(), loanOffering2.getPrdOfferingShortName());
    List<ProductDto> loanProducts = Arrays.asList(loanOfferingDto, loanOfferingDto2);
    ProductDto savingsOfferingDto = new ProductDto(savingsOffering1.getPrdOfferingId(), savingsOffering1.getPrdOfferingShortName());
    ProductDto savingsOfferingDto2 = new ProductDto(savingsOffering2.getPrdOfferingId(), savingsOffering2.getPrdOfferingShortName());
    ProductDto savingsOfferingDto3 = new ProductDto(savingsOffering3.getPrdOfferingId(), savingsOffering3.getPrdOfferingShortName());
    List<ProductDto> savingsProducts = Arrays.asList(savingsOfferingDto, savingsOfferingDto2, savingsOfferingDto3);
    final PersonnelDto loanOfficer = getPersonnelView(center.getPersonnel());
    final OfficeDetailsDto officeDetailsDto = null;
    final List<CustomValueListElementDto> attendanceTypesList = new ArrayList<CustomValueListElementDto>();
    bulkEntryParent.setCountOfCustomers(3);
    final CollectionSheetEntryGridDto bulkEntry = new CollectionSheetEntryGridDto(bulkEntryParent, loanOfficer, officeDetailsDto, getPaymentTypeView(), startDate, "324343242", startDate, loanProducts, savingsProducts, attendanceTypesList);
    return bulkEntry;
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) CustomValueListElementDto(org.mifos.application.master.business.CustomValueListElementDto) ArrayList(java.util.ArrayList) LoanAccountDto(org.mifos.accounts.loan.util.helpers.LoanAccountDto) PersonnelDto(org.mifos.dto.domain.PersonnelDto) OfficeDetailsDto(org.mifos.dto.domain.OfficeDetailsDto) Date(java.util.Date) LoanAccountsProductDto(org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto) SavingsAccountDto(org.mifos.accounts.savings.util.helpers.SavingsAccountDto) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) SavingsOfferingBO(org.mifos.accounts.productdefinition.business.SavingsOfferingBO) CollectionSheetEntryDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryDto) LoanAccountsProductDto(org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto) ProductDto(org.mifos.application.servicefacade.ProductDto) CollectionSheetEntryGridDto(org.mifos.application.collectionsheet.business.CollectionSheetEntryGridDto)

Example 8 with LoanAccountDto

use of org.mifos.accounts.loan.util.helpers.LoanAccountDto in project head by mifos.

the class SaveCollectionSheetFromLegacyAssembler method assembleCustomerLoans.

private List<SaveCollectionSheetCustomerLoanDto> assembleCustomerLoans(List<LoanAccountsProductDto> loanAccountDetails, Short currencyId) {
    if (null != loanAccountDetails && loanAccountDetails.size() > 0) {
        List<SaveCollectionSheetCustomerLoanDto> saveCollectionSheetCustomerLoans = new ArrayList<SaveCollectionSheetCustomerLoanDto>();
        for (LoanAccountsProductDto loanAccountDetail : loanAccountDetails) {
            List<LoanAccountDto> loanAccountDtos = loanAccountDetail.getLoanAccountViews();
            if ((null != loanAccountDtos) && (loanAccountDtos.size() == 1)) {
                BigDecimal repaymentAmount = setBigDecimalAmount(loanAccountDetail.getEnteredAmount());
                BigDecimal disbursementAmount = setBigDecimalAmount(loanAccountDetail.getDisBursementAmountEntered());
                SaveCollectionSheetCustomerLoanDto saveCollectionSheetCustomerLoan = null;
                try {
                    saveCollectionSheetCustomerLoan = new SaveCollectionSheetCustomerLoanDto(loanAccountDtos.get(0).getAccountId(), currencyId, repaymentAmount, disbursementAmount);
                } catch (SaveCollectionSheetException e) {
                    throw new MifosRuntimeException(e.printInvalidSaveCollectionSheetReasons());
                }
                saveCollectionSheetCustomerLoans.add(saveCollectionSheetCustomerLoan);
            } else {
                if ((loanAccountDtos == null) || (loanAccountDtos.size() == 0)) {
                    throw new RuntimeException("Loan Product: " + loanAccountDetail.getPrdOfferingShortName() + " has no loans associated with it.");
                }
                for (LoanAccountDto loanAccountDto : loanAccountDtos) {
                    // more than one loan against a particular loan product
                    // offering
                    // The user has to either set to zero or pay all
                    // (enforced on web front end)
                    BigDecimal repaymentAmount = setBigDecimalAmount(loanAccountDetail.getEnteredAmount());
                    if (repaymentAmount.compareTo(BigDecimal.ZERO) > 0) {
                        repaymentAmount = new BigDecimal(loanAccountDto.getTotalAmountDue());
                    }
                    BigDecimal disbursementAmount = setBigDecimalAmount(loanAccountDetail.getDisBursementAmountEntered());
                    if (disbursementAmount.compareTo(BigDecimal.ZERO) > 0) {
                        disbursementAmount = new BigDecimal(loanAccountDto.getTotalDisburseAmount());
                    }
                    SaveCollectionSheetCustomerLoanDto saveCollectionSheetCustomerLoan = null;
                    try {
                        saveCollectionSheetCustomerLoan = new SaveCollectionSheetCustomerLoanDto(loanAccountDto.getAccountId(), currencyId, repaymentAmount, disbursementAmount);
                    } catch (SaveCollectionSheetException e) {
                        throw new MifosRuntimeException(e.printInvalidSaveCollectionSheetReasons());
                    }
                    saveCollectionSheetCustomerLoans.add(saveCollectionSheetCustomerLoan);
                }
            }
        }
        return saveCollectionSheetCustomerLoans;
    }
    return null;
}
Also used : MifosRuntimeException(org.mifos.core.MifosRuntimeException) ArrayList(java.util.ArrayList) LoanAccountDto(org.mifos.accounts.loan.util.helpers.LoanAccountDto) LoanAccountsProductDto(org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto) BigDecimal(java.math.BigDecimal) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

LoanAccountDto (org.mifos.accounts.loan.util.helpers.LoanAccountDto)8 ArrayList (java.util.ArrayList)7 CollectionSheetEntryDto (org.mifos.application.collectionsheet.business.CollectionSheetEntryDto)4 Date (java.util.Date)3 LoanAccountsProductDto (org.mifos.accounts.loan.util.helpers.LoanAccountsProductDto)3 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)3 SavingsOfferingBO (org.mifos.accounts.productdefinition.business.SavingsOfferingBO)3 SavingsAccountDto (org.mifos.accounts.savings.util.helpers.SavingsAccountDto)3 CollectionSheetEntryGridDto (org.mifos.application.collectionsheet.business.CollectionSheetEntryGridDto)3 CustomValueListElementDto (org.mifos.application.master.business.CustomValueListElementDto)3 MeetingBO (org.mifos.application.meeting.business.MeetingBO)3 ProductDto (org.mifos.application.servicefacade.ProductDto)3 OfficeDetailsDto (org.mifos.dto.domain.OfficeDetailsDto)3 PersonnelDto (org.mifos.dto.domain.PersonnelDto)3 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)2 BigDecimal (java.math.BigDecimal)1 Date (java.sql.Date)1 CollectionSheetEntryCustomerAccountInstallmentDto (org.mifos.application.collectionsheet.business.CollectionSheetEntryCustomerAccountInstallmentDto)1 CollectionSheetEntryInstallmentDto (org.mifos.application.collectionsheet.business.CollectionSheetEntryInstallmentDto)1 CollectionSheetEntryLoanInstallmentDto (org.mifos.application.collectionsheet.business.CollectionSheetEntryLoanInstallmentDto)1