use of org.mifos.accounts.savings.util.helpers.SavingsAccountDto in project head by mifos.
the class SaveCollectionSheetFromLegacyAssembler method assembleCustomerSavings.
private List<SaveCollectionSheetCustomerSavingDto> assembleCustomerSavings(List<SavingsAccountDto> savingsAccountDetails, Short currencyId, Boolean attemptingToPopulateClientIndividualSavingsList, Short customerLevelId) {
if ((null != savingsAccountDetails) && (savingsAccountDetails.size() > 0)) {
List<SaveCollectionSheetCustomerSavingDto> saveCollectionSheetCustomerSavings = new ArrayList<SaveCollectionSheetCustomerSavingDto>();
for (SavingsAccountDto savingsAccountDto : savingsAccountDetails) {
Boolean match = false;
if (attemptingToPopulateClientIndividualSavingsList) {
if (isClient(customerLevelId) && isIndividualSavingsAccount(savingsAccountDto.getRecommendedAmntUnitId())) {
match = true;
}
}
if (!attemptingToPopulateClientIndividualSavingsList) {
if (isClient(customerLevelId)) {
if (!isIndividualSavingsAccount(savingsAccountDto.getRecommendedAmntUnitId())) {
match = true;
}
} else {
match = true;
}
}
if (match) {
BigDecimal depositEntered = setBigDecimalAmount(savingsAccountDto.getDepositAmountEntered());
BigDecimal withdrawalEntered = setBigDecimalAmount(savingsAccountDto.getWithDrawalAmountEntered());
SaveCollectionSheetCustomerSavingDto saveCollectionSheetCustomerSaving = null;
try {
saveCollectionSheetCustomerSaving = new SaveCollectionSheetCustomerSavingDto(savingsAccountDto.getAccountId(), currencyId, depositEntered, withdrawalEntered);
} catch (SaveCollectionSheetException e) {
throw new MifosRuntimeException(e.printInvalidSaveCollectionSheetReasons());
}
saveCollectionSheetCustomerSavings.add(saveCollectionSheetCustomerSaving);
}
}
if (saveCollectionSheetCustomerSavings.size() > 0) {
return saveCollectionSheetCustomerSavings;
}
}
return null;
}
use of org.mifos.accounts.savings.util.helpers.SavingsAccountDto in project head by mifos.
the class CollectionSheetEntryDtoPostPreviewValidator method validatePopulatedData.
private ActionErrors validatePopulatedData(final CollectionSheetEntryDto parent, final ActionErrors errors, final Locale locale) {
List<CollectionSheetEntryDto> children = parent.getCollectionSheetEntryChildren();
String acCollections = MessageLookup.getLocalizedMessage(CollectionSheetEntryConstants.AC_COLLECTION);
if (null != children) {
for (CollectionSheetEntryDto collectionSheetEntryDto : children) {
validatePopulatedData(collectionSheetEntryDto, errors, locale);
}
}
for (LoanAccountsProductDto accountView : parent.getLoanAccountDetails()) {
if (accountView.isDisburseLoanAccountPresent() || accountView.getLoanAccountViews().size() > 1) {
Money enteredAmount = new Money(Money.getDefaultCurrency(), 0.0);
if (null != accountView.getEnteredAmount() && accountView.isValidAmountEntered()) {
enteredAmount = new Money(Money.getDefaultCurrency(), getDoubleValue(accountView.getEnteredAmount()));
}
Money enteredDisbursalAmount = new Money(Money.getDefaultCurrency(), 0.0);
if (null != accountView.getDisBursementAmountEntered() && accountView.isValidDisbursementAmount()) {
enteredDisbursalAmount = new Money(Money.getDefaultCurrency(), getDoubleValue(accountView.getDisBursementAmountEntered()));
}
Money totalDueAmount = new Money(Money.getDefaultCurrency(), accountView.getTotalAmountDue());
Money totalDisburtialAmount = new Money(Money.getDefaultCurrency(), accountView.getTotalDisburseAmount());
if (totalDisburtialAmount.isGreaterThanZero()) {
if ((!accountView.isValidDisbursementAmount() || accountView.getDisBursementAmountEntered() == null || !enteredDisbursalAmount.toString().equals(totalDisburtialAmount.toString())) && !enteredDisbursalAmount.isZero()) {
errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
}
}
if (totalDueAmount.isGreaterThanZero()) {
if ((!accountView.isValidAmountEntered() || accountView.getEnteredAmount() == null || !enteredAmount.toString().equals(totalDueAmount.toString())) && !enteredAmount.isZero()) {
errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
}
}
boolean moreThanTwoLoanAccountsToPrepaid = isThereMoreThanTwoLoanAccountsToPrepaid(accountView.getLoanAccountViews());
if (totalDisburtialAmount.isLessThanOrEqualZero() && totalDueAmount.isLessThanOrEqualZero()) {
if (!accountView.isValidAmountEntered() || !accountView.isValidDisbursementAmount() || !enteredDisbursalAmount.isZero() || (!moreThanTwoLoanAccountsToPrepaid && !enteredAmount.isZero())) {
errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
} else if (moreThanTwoLoanAccountsToPrepaid && !enteredAmount.isZero()) {
errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDPREPAYAMOUNT, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDPREPAYAMOUNT, accountView.getPrdOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
}
}
}
}
for (SavingsAccountDto savingsAccountDto : parent.getSavingsAccountDetails()) {
if (!savingsAccountDto.isValidDepositAmountEntered() || !savingsAccountDto.isValidWithDrawalAmountEntered()) {
errors.add(CollectionSheetEntryConstants.ERRORINVALIDAMOUNT, new ActionMessage(CollectionSheetEntryConstants.ERRORINVALIDAMOUNT, savingsAccountDto.getSavingsOfferingShortName(), parent.getCustomerDetail().getDisplayName()));
}
}
CustomerAccountDto customerAccountDto = parent.getCustomerAccountDetails();
Double customerAccountAmountEntered = 0.0;
if (null != customerAccountDto.getCustomerAccountAmountEntered() && customerAccountDto.isValidCustomerAccountAmountEntered()) {
customerAccountAmountEntered = getDoubleValue(customerAccountDto.getCustomerAccountAmountEntered());
}
if (!customerAccountDto.isValidCustomerAccountAmountEntered() || customerAccountAmountEntered < 0.0) {
errors.add(CollectionSheetEntryConstants.BULKENTRYINVALIDACCOLLECTIONS, new ActionMessage(CollectionSheetEntryConstants.BULKENTRYINVALIDACCOLLECTIONS, acCollections, parent.getCustomerDetail().getDisplayName()));
}
return errors;
}
use of org.mifos.accounts.savings.util.helpers.SavingsAccountDto in project head by mifos.
the class BulkEntryDisplayHelper method getWithdrawalSavingsRow.
private void getWithdrawalSavingsRow(final StringBuilder builder, final List<SavingsAccountDto> bulkEntryAccountList, final List<ProductDto> savingsProducts, final int rows, final Money[] groupTotals, final int size, final int initialAccNo, final int loanProductsSize, final String method, final int levelId, final MifosCurrency currency) {
for (ProductDto prdOffering : savingsProducts) {
boolean isIdMatched = false;
builder.append("<td class=\"drawtablerow\">");
for (SavingsAccountDto accountView : bulkEntryAccountList) {
isIdMatched = prdOffering.getId().equals(accountView.getSavingsOfferingId());
if (isIdMatched) {
generateSavingsValues(builder, rows, columnIndex, accountView, groupTotals, size, initialAccNo, method, false, columnIndex, loanProductsSize, savingsProducts.size(), levelId, currency);
break;
}
}
if (!isIdMatched) {
builder.append(" ");
}
builder.append("</td>");
columnIndex++;
}
}
use of org.mifos.accounts.savings.util.helpers.SavingsAccountDto in project head by mifos.
the class BulkEntryDisplayHelperIntegrationTest method createBulkEntry.
private CollectionSheetEntryGridDto createBulkEntry() throws Exception {
MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
Date startDate = new Date(System.currentTimeMillis());
center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group", CustomerStatus.GROUP_ACTIVE, center);
client = TestObjectFactory.createClient(this.getClass().getSimpleName() + " Client", CustomerStatus.CLIENT_ACTIVE, group);
LoanOfferingBO loanOffering1 = TestObjectFactory.createLoanOffering(startDate, meeting);
LoanOfferingBO loanOffering2 = TestObjectFactory.createLoanOffering("Loan2345", "313f", startDate, meeting);
groupAccount = TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, startDate, loanOffering1);
clientAccount = getLoanAccount(AccountState.LOAN_APPROVED, startDate, loanOffering2);
java.util.Date currentDate = new java.util.Date(System.currentTimeMillis());
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), TestUtils.RUPEE);
SavingsAccountDto centerSavingsAccountView = getSavingsAccountView(centerSavingsAccount);
centerSavingsAccountView.setDepositAmountEntered("100");
centerSavingsAccountView.setWithDrawalAmountEntered("10");
bulkEntryParent.addSavingsAccountDetail(centerSavingsAccountView);
bulkEntryParent.setCustomerAccountDetails(getCustomerAccountView(center));
CollectionSheetEntryDto bulkEntryChild = new CollectionSheetEntryDto(getCusomerView(group), TestUtils.RUPEE);
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), TestUtils.RUPEE);
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);
bulkEntryChild.getLoanAccountDetails().get(0).setPrdOfferingId(groupLoanAccountView.getPrdOfferingId());
bulkEntryChild.getLoanAccountDetails().get(0).setEnteredAmount("100.0");
bulkEntrySubChild.getLoanAccountDetails().get(0).setDisBursementAmountEntered(clientAccount.getLoanAmount().toString());
bulkEntrySubChild.getLoanAccountDetails().get(0).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 savingOfferingDto = new ProductDto(savingsOffering1.getPrdOfferingId(), savingsOffering1.getPrdOfferingShortName());
ProductDto savingOfferingDto2 = new ProductDto(savingsOffering2.getPrdOfferingId(), savingsOffering2.getPrdOfferingShortName());
ProductDto savingOfferingDto3 = new ProductDto(savingsOffering3.getPrdOfferingId(), savingsOffering3.getPrdOfferingShortName());
List<ProductDto> savingsProducts = Arrays.asList(savingOfferingDto, savingOfferingDto2, savingOfferingDto3);
final PersonnelDto loanOfficer = getPersonnelView(center.getPersonnel());
final OfficeDetailsDto officeDetailsDto = null;
final List<CustomValueListElementDto> attendanceTypesList = new ArrayList<CustomValueListElementDto>();
CollectionSheetEntryGridDto bulkEntry = new CollectionSheetEntryGridDto(bulkEntryParent, loanOfficer, officeDetailsDto, getPaymentTypeView(), new java.util.Date(), "324343242", new java.util.Date(), loanProducts, savingsProducts, attendanceTypesList);
return bulkEntry;
}
use of org.mifos.accounts.savings.util.helpers.SavingsAccountDto in project head by mifos.
the class CollectionSheetDtoTranslatorImplTest method shouldTranslateLoanSavingsAndCustomerDetailsOnToCollectionSheetEntryGridDto.
@Test
public void shouldTranslateLoanSavingsAndCustomerDetailsOnToCollectionSheetEntryGridDto() throws Exception {
// setup
final Integer customerId = Integer.valueOf(7);
final Integer customerAccountId = Integer.valueOf("55");
final Integer savingsAccountId = Integer.valueOf("77");
final String savingsProductShortName = "sav1";
final Double savingsDepositDue = Double.valueOf("125.00");
final Integer loanAccountId = Integer.valueOf("101");
final String loanProductShortName = "lon1";
final Double totalRepaymentDue = Double.valueOf("67.00");
final Double totalCustomerAccountCollectionFee = Double.valueOf("29.87");
final CollectionSheetCustomerAccountDto customerAccountDto = new CollectionSheetCustomerAccountDto(customerAccountId, defaultCurrencyId, totalCustomerAccountCollectionFee);
final List<CollectionSheetCustomerDto> collectionSheetCustomer = Arrays.asList(centerCustomer);
final List<CollectionSheetCustomerSavingDto> collectionSheetCustomerSavings = Arrays.asList(collectionSheetSaving);
final List<CollectionSheetCustomerLoanDto> collectionSheetCustomerLoans = Arrays.asList(collectionSheetLoan);
// stubbing
when(collectionSheetData.getCollectionSheetCustomer()).thenReturn(collectionSheetCustomer);
when(centerCustomer.getCustomerId()).thenReturn(customerId);
when(centerCustomer.getCollectionSheetCustomerAccount()).thenReturn(customerAccountDto);
when(centerCustomer.getCollectionSheetCustomerSaving()).thenReturn(collectionSheetCustomerSavings);
when(centerCustomer.getCollectionSheetCustomerLoan()).thenReturn(collectionSheetCustomerLoans);
// stub savings
when(collectionSheetSaving.getCustomerId()).thenReturn(customerId);
when(collectionSheetSaving.getAccountId()).thenReturn(savingsAccountId);
when(collectionSheetSaving.getProductShortName()).thenReturn(savingsProductShortName);
when(collectionSheetSaving.getTotalDepositAmount()).thenReturn(savingsDepositDue);
// stub loans
when(collectionSheetLoan.getCustomerId()).thenReturn(customerId);
when(collectionSheetLoan.getAccountId()).thenReturn(loanAccountId);
when(collectionSheetLoan.getProductShortName()).thenReturn(loanProductShortName);
when(collectionSheetLoan.getPayInterestAtDisbursement()).thenReturn(Constants.NO);
when(collectionSheetLoan.getTotalRepaymentDue()).thenReturn(totalRepaymentDue);
when(collectionSheetLoan.getAccountStateId()).thenReturn(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING.getValue());
// exercise test
final CollectionSheetEntryGridDto formDto = collectionSheetDtoTranslator.toLegacyDto(collectionSheetData, formEnteredDataDto, null, defaultCurrency);
// verification
assertThat(formDto.getTotalCustomers(), is(collectionSheetCustomer.size()));
// assert that the parent entry view exists with correctly populated
final CollectionSheetEntryDto collectionSheetEntryParent = formDto.getBulkEntryParent();
assertThat(collectionSheetEntryParent, is(notNullValue()));
assertThat(collectionSheetEntryParent.getAttendence(), is(Short.valueOf("0")));
assertThat(collectionSheetEntryParent.getCountOfCustomers(), is(1));
assertThat(collectionSheetEntryParent.getCustomerDetail().getCustomerId(), is(customerId));
// customer account details
assertThat(collectionSheetEntryParent.getCustomerAccountDetails().getAccountId(), is(customerAccountId));
assertThat(collectionSheetEntryParent.getCustomerAccountDetails().getTotalAmountDue().getAmountDoubleValue(), is(totalCustomerAccountCollectionFee));
// savings account
List<SavingsAccountDto> savingAccounts = collectionSheetEntryParent.getSavingsAccountDetails();
assertThat(savingAccounts.size(), is(1));
assertThat(savingAccounts.get(0).getAccountId(), is(savingsAccountId));
assertThat(savingAccounts.get(0).getCustomerId(), is(customerId));
assertThat(savingAccounts.get(0).getTotalDepositDue(), is(savingsDepositDue));
// loan accounts
List<LoanAccountsProductDto> loanAccountProductViews = collectionSheetEntryParent.getLoanAccountDetails();
assertThat(loanAccountProductViews.size(), is(1));
assertThat(loanAccountProductViews.get(0).getPrdOfferingShortName(), is(loanProductShortName));
assertThat(loanAccountProductViews.get(0).getTotalAmountDue(), is(totalRepaymentDue));
assertThat(loanAccountProductViews.get(0).getLoanAccountViews().size(), is(1));
assertThat(loanAccountProductViews.get(0).getLoanAccountViews().get(0).getTotalAmountDue(), is(totalRepaymentDue));
}
Aggregations