use of org.mifos.dto.domain.MeetingDto in project head by mifos.
the class XlsClientsImporter method parse.
public ParsedClientsDto parse(final InputStream input) {
final List<ValueListElement> buisnessActivitiesList = customerDao.retrieveBusinessActivities();
final List<ValueListElement> gendersList = customerDao.retrieveGenders();
final List<ValueListElement> citizenshipsList = customerDao.retrieveCitizenship();
final List<ValueListElement> ethinicitiesList = customerDao.retrieveEthnicity();
final List<ValueListElement> educationLevelsList = customerDao.retrieveEducationLevels();
final List<ValueListElement> handicappedList = customerDao.retrieveHandicapped();
final List<ValueListElement> povertyStatusList = customerDao.retrievePoverty();
final List<ValueListElement> maritalStatusList = customerDao.retrieveMaritalStatuses();
final List<ValueListElement> salutationsList = customerDao.retrieveSalutations();
final List<OfficeDto> allOfficess = officeDao.findAllOffices();
final FieldConfig fieldConfig = FieldConfig.getInstance();
final List<String> globalCustNums = new ArrayList<String>();
final List<String> errorsList = new ArrayList<String>();
final List<ImportedClientDetail> parsedClientDetails = new ArrayList<ImportedClientDetail>();
try {
final HSSFWorkbook workbook = new HSSFWorkbook(input);
final HSSFSheet sheet = workbook.getSheetAt(0);
/* test first data row */
HSSFRow row = sheet.getRow(XlsImportConstants.FIRST_CLIENT_ROW.value());
if (row == null) {
errorsList.add(getMessage(XlsMessageConstants.NOT_ENOUGH_INPUT_ROW));
}
@SuppressWarnings("rawtypes") Iterator rowIterator = sheet.rowIterator();
/* Skip first rows */
if (errorsList.isEmpty()) {
for (int i = 0; i < XlsImportConstants.SKIPPED_ROWS.value(); i++) {
if (rowIterator.hasNext()) {
rowIterator.next();
} else {
errorsList.add(getMessage(XlsMessageConstants.NOT_ENOUGH_INPUT_ROW));
break;
}
}
}
XlsImportConstants currentCell = XlsImportConstants.CLIENT_NUM_CELL;
int friendlyRowNumber = 0;
/* Parse client data */
if (errorsList.isEmpty()) {
while (rowIterator.hasNext()) {
try {
row = (HSSFRow) rowIterator.next();
friendlyRowNumber = row.getRowNum() + 1;
/* Get data from sheet */
currentCell = XlsImportConstants.CLIENT_NUM_CELL;
String clientGlobalNum = getCellStringValue(row, currentCell);
if (StringUtils.isBlank(clientGlobalNum)) {
// generate number
clientGlobalNum = null;
} else {
// check for duplicates
validateGlobalCustNum(clientGlobalNum, globalCustNums);
globalCustNums.add(clientGlobalNum);
}
currentCell = XlsImportConstants.BRANCH_SHORT_NAME_CELL;
final String branchShortName = getCellStringValue(row, currentCell);
final Short branchOfficeId = getBranchId(branchShortName, allOfficess);
currentCell = XlsImportConstants.GROUP_GLOBAL_NUM_CELL;
final String groupGlobalNum = getCellStringValue(row, currentCell);
validateGroup(groupGlobalNum);
if (StringUtils.isBlank(groupGlobalNum) && branchOfficeId == null) {
String error = getRowError(friendlyRowNumber) + getMessage(XlsMessageConstants.OFFICE_AND_BRANCH);
errorsList.add(error);
continue;
}
currentCell = XlsImportConstants.SALUTATION_CELL;
final String salutation = getCellStringValue(row, currentCell);
final Integer salutationId = getValueElementId(salutation, salutationsList);
validateMandatoryField(salutationId);
currentCell = XlsImportConstants.FIRST_NAME_CELL;
final String clientFirstName = getCellStringValue(row, currentCell);
validateMandatoryField(clientFirstName);
currentCell = XlsImportConstants.MIDDLE_NAME_CELL;
final String clientMiddleName = getCellStringValue(row, currentCell);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.MIDDLE_NAME)) {
validateMandatoryField(clientMiddleName);
}
currentCell = XlsImportConstants.LAST_NAME_CELL;
final String clientLastName = getCellStringValue(row, currentCell);
validateMandatoryField(clientLastName);
currentCell = XlsImportConstants.SECOND_LAST_NAME_CELL;
final String clientSecondLastName = getCellStringValue(row, currentCell);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.SECOND_LAST_NAME)) {
validateMandatoryField(clientSecondLastName);
}
currentCell = XlsImportConstants.GOVERNMENT_ID_CELL;
String governmentId = getCellStringValue(row, currentCell);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.GOVERNMENT_ID)) {
validateMandatoryField(governmentId);
}
currentCell = XlsImportConstants.DATE_OF_BIRTH_CELL;
final Date dateOfBirth = getCellDateValue(row, currentCell);
validateMandatoryField(dateOfBirth);
validateAge(dateOfBirth);
currentCell = XlsImportConstants.GENDER_CELL;
final String gender = getCellStringValue(row, currentCell);
final Short genderId = intToShort(getValueElementId(gender, gendersList));
validateMandatoryField(genderId);
currentCell = XlsImportConstants.MARITAL_STATUS_CELL;
final String maritalStatus = getCellStringValue(row, currentCell);
final Integer maritalStatusId = getValueElementId(maritalStatus, maritalStatusList);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.MARITAL_STATUS)) {
validateMandatoryField(maritalStatusId);
}
currentCell = XlsImportConstants.NUMBER_OF_CHILDREN_CELL;
final Short numberOfChildren = intToShort(getCellIntegerValue(row, currentCell));
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.NUMBER_OF_CHILDREN)) {
validateMandatoryField(numberOfChildren);
}
currentCell = XlsImportConstants.CITIZENSHIP_CELL;
final String citizenship = getCellStringValue(row, currentCell);
final Integer citizenshipId = getValueElementId(citizenship, citizenshipsList);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.CITIZENSHIP)) {
validateMandatoryField(citizenshipId);
}
currentCell = XlsImportConstants.ETHINICITY_CELL;
final String ethinicity = getCellStringValue(row, currentCell);
final Integer ethinicityId = getValueElementId(ethinicity, ethinicitiesList);
if (fieldConfig.isFieldHidden(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.ETHNICITY)) {
validateMandatoryField(ethinicityId);
}
currentCell = XlsImportConstants.EDUCATION_LEVEL_CELL;
final String educationLevel = getCellStringValue(row, currentCell);
final Integer educationLevelId = getValueElementId(educationLevel, educationLevelsList);
if (fieldConfig.isFieldHidden(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.EDUCATION_LEVEL)) {
validateMandatoryField(educationLevelId);
}
currentCell = XlsImportConstants.ACTIVITIES_CELL;
final String activites = getCellStringValue(row, currentCell);
final Integer activityId = getValueElementId(activites, buisnessActivitiesList);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.BUSINESS_ACTIVITIES)) {
validateMandatoryField(activityId);
}
currentCell = XlsImportConstants.POVERTY_STATUS_CELL;
final String povertyStatus = getCellStringValue(row, currentCell);
final Short povertyStatusId = intToShort(getValueElementId(povertyStatus, povertyStatusList));
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.POVERTY_STATUS)) {
validateMandatoryField(povertyStatusId);
}
currentCell = XlsImportConstants.HANDICAPPED_CELL;
final String handicapped = getCellStringValue(row, currentCell);
final Integer handicappedId = getValueElementId(handicapped, handicappedList);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.HANDICAPPED)) {
validateMandatoryField(handicappedId);
}
currentCell = XlsImportConstants.SPOUSE_FATHER_RELATIONSHIP_CELL;
final String spouseOrFather = getCellStringValue(row, currentCell);
final Short spouseFatherNameType = getSpouseNameType(spouseOrFather);
final boolean familyMandatory = fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.FAMILY_DETAILS);
if (familyMandatory) {
validateMandatoryField(spouseFatherNameType);
}
currentCell = XlsImportConstants.SPOUSE_FIRST_NAME_CELL;
final String spouseFirstName = getCellStringValue(row, currentCell);
if (familyMandatory) {
validateMandatoryField(spouseFirstName);
}
currentCell = XlsImportConstants.SPOUSE_MIDDLE_NAME_CELL;
final String spouseMiddleName = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.SPOUSE_SECOND_LAST_NAME_CELL;
final String spouseSecondLastName = getCellStringValue(row, currentCell);
if (familyMandatory && fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.SPOUSE_FATHER_SECOND_LAST_NAME)) {
validateMandatoryField(spouseSecondLastName);
}
currentCell = XlsImportConstants.SPOUSE_LAST_NAME_CELL;
final String spouseLastName = getCellStringValue(row, currentCell);
if (familyMandatory) {
validateMandatoryField(spouseLastName);
}
currentCell = XlsImportConstants.ADDRESS_CELL;
final String address = getCellStringValue(row, currentCell);
if (fieldConfig.isFieldManadatory(CLIENT_ENTITY + HiddenMandatoryFieldNamesConstants.ADDRESS1)) {
validateMandatoryField(address);
}
currentCell = XlsImportConstants.CITY_DISTRICT_CELL;
final String cityDistrict = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.STATE_CELL;
final String state = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.COUNTRY_CELL;
final String country = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.POSTAL_CODE_CELL;
final String postalCode = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.TELEPHONE_CELL;
final String telephone = getCellStringValue(row, currentCell);
currentCell = XlsImportConstants.RECRUITED_BY_CELL;
final String recruitedBy = getCellStringValue(row, currentCell);
validateMandatoryField(recruitedBy);
final Short formedBy = getOfficerId(recruitedBy);
currentCell = XlsImportConstants.STATUS_CELL;
final String status = getCellStringValue(row, currentCell);
final Short statusId = statusToShort(status);
currentCell = XlsImportConstants.LOAN_OFFICER_CELL;
final String loanOfficer = getCellStringValue(row, currentCell);
if (!StringUtils.isBlank(groupGlobalNum) && !StringUtils.isBlank(loanOfficer)) {
throw new CellException(getMessage(XlsMessageConstants.LOAN_OFFICER_FOR_GROUP_CLIENT));
}
currentCell = XlsImportConstants.ACTIVATION_DATE_CELL;
final LocalDate activationDate = DateUtils.getLocalDateFromDate(getCellDateValue(row, currentCell));
if (activationDate != null && !status.equals(getMessage(XlsMessageConstants.ACTIVE))) {
throw new CellException(getMessage(XlsMessageConstants.ACTIVE_STATUS_FOR_ACTIVATION_DATE));
}
/* Meeting data */
currentCell = XlsImportConstants.MEETING_FREQUENCY_CELL;
final Integer recurrenceType = getRecurrenceType(getCellStringValue(row, currentCell));
currentCell = XlsImportConstants.MEETING_RECUR_EVERY_WEEK_CELL;
final Integer recurEveryWeek = getCellIntegerValue(row, currentCell);
currentCell = XlsImportConstants.MEETING_ON_WEEK_CELL;
final Integer weeklyMeetingDay = getDayValue(getCellStringValue(row, currentCell));
currentCell = XlsImportConstants.MEETING_OPT1_DAY_CELL;
final Integer opt1Day = getCellIntegerValue(row, currentCell);
validateMonthDay(opt1Day);
currentCell = XlsImportConstants.MEETING_OPT1_EVERY_CELL;
final Integer opt1Every = getCellIntegerValue(row, currentCell);
validatePositive(opt1Every);
currentCell = XlsImportConstants.MEETING_OPT2_THE_CELL;
final Integer opt2The = getDayRankValue(getCellStringValue(row, currentCell));
currentCell = XlsImportConstants.MEETING_OPT2_DAY_CELL;
final Integer opt2Day = getDayValue(getCellStringValue(row, currentCell));
currentCell = XlsImportConstants.MEETING_OPT2_EVERY_CELL;
final Integer opt2Every = getCellIntegerValue(row, currentCell);
validatePositive(opt2Every);
currentCell = XlsImportConstants.MEETING_LOCATION_CELL;
final String meetingLocation = getCellStringValue(row, currentCell);
Integer recurrenceDayNumber = 0;
Integer recurrenceWeekOfMonth = 0;
Integer recurrenceDayOfWeek = 0;
Integer recurEvery = 0;
/*
* Validate meeting data
*/
if (!StringUtils.isBlank(groupGlobalNum) && recurrenceType != null) {
// no meeting allowed for a group
throw new RowException(getMessage(XlsMessageConstants.MEETING_FOR_GROUP));
} else if (recurrenceType == null) {
// make sure everything is empty
if (recurEveryWeek != null || weeklyMeetingDay != null || opt1Day != null || opt1Every != null || opt2Day != null || opt2Every != null || opt2The != null || !StringUtils.isBlank(meetingLocation)) {
throw new RowException(getMessage(XlsMessageConstants.INCOMPLETE_MEETING_DATA));
}
} else if (recurrenceType == RecurrenceType.WEEKLY.getValue().intValue()) {
// make sure weekly data is set
if (recurEveryWeek == null || weeklyMeetingDay == null) {
throw new RowException(getMessage(XlsMessageConstants.INCOMPLETE_MEETING_DATA));
}
// make sure monthly details are empty
if (opt1Day != null || opt1Every != null || opt2Day != null || opt2Every != null || opt2The != null) {
throw new RowException(getMessage(XlsMessageConstants.MONTHLY_MEETING_DETAILS_NOT_EMPTY));
}
// set data
recurrenceDayOfWeek = weeklyMeetingDay;
recurEvery = recurEveryWeek;
// validate location
validateMandatoryField(meetingLocation);
} else {
// make sure weekly details are empty
if (recurEveryWeek != null || weeklyMeetingDay != null) {
throw new RowException(getMessage(XlsMessageConstants.WEEKLY_MEETING_DETAILS_NOT_EMPTY));
}
if (opt1Day == null) {
// make sure option 2 is set
if (opt2Day == null || opt2Every == null || opt2The == null) {
throw new RowException(getMessage(XlsMessageConstants.INCOMPLETE_MEETING_DATA));
}
// make sure option 1 is empty
if (opt1Every != null) {
throw new RowException(getMessage(XlsMessageConstants.OPTIONS_EXCLUSIVE));
}
// set data
recurrenceWeekOfMonth = opt2The;
recurrenceDayOfWeek = opt2Day;
recurEvery = opt2Every;
} else {
// make sure option 1 is set
if (opt1Every == null) {
throw new RowException(getMessage(XlsMessageConstants.INCOMPLETE_MEETING_DATA));
}
// make sure option 2 is empty
if (opt2Day != null || opt2Every != null || opt2The != null) {
throw new RowException(getMessage(XlsMessageConstants.OPTIONS_EXCLUSIVE));
}
// set data
recurrenceDayNumber = opt1Day;
recurEvery = opt1Every;
}
// validate location
validateMandatoryField(meetingLocation);
}
/*
* Create meeting data
*/
MeetingDto meetingDto = null;
if (recurrenceType != null) {
final LocalDate meetingStartDate = new LocalDate();
final MeetingRecurrenceDto meetingRecurrenceDto = new MeetingRecurrenceDto(recurrenceDayNumber, recurrenceWeekOfMonth, recurrenceDayOfWeek);
final MeetingDetailsDto meetingDetailsDto = new MeetingDetailsDto(recurrenceType, null, recurEvery, meetingRecurrenceDto);
final MeetingTypeDto meetingTypeDto = new MeetingTypeDto(MeetingType.CUSTOMER_MEETING.getValue().intValue(), null, null);
meetingDto = new MeetingDto(meetingStartDate, meetingLocation, meetingTypeDto, meetingDetailsDto);
} else {
}
String clientName = buildName(clientFirstName, clientMiddleName, clientLastName, clientSecondLastName);
customerDao.validateClientForDuplicateNameOrGovtId(clientName, dateOfBirth, governmentId);
/* Create dto's */
/* address */
final Address addressObject = new Address(address, null, null, cityDistrict, state, country, postalCode, telephone);
final AddressDto addressDto = Address.toDto(addressObject);
/* Personal details */
final ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(CLIENT_NAME_TYPE, salutationId, clientFirstName, clientMiddleName, clientLastName, clientSecondLastName);
final ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(ethinicityId, citizenshipId, handicappedId, activityId, maritalStatusId, educationLevelId, numberOfChildren, genderId, povertyStatusId);
/* Spouse details */
ClientNameDetailDto spouseNameDetailDto = null;
if (spouseFatherNameType == null) {
spouseNameDetailDto = new ClientNameDetailDto();
spouseNameDetailDto.setFirstName("");
spouseNameDetailDto.setLastName("");
} else {
spouseNameDetailDto = new ClientNameDetailDto(spouseFatherNameType, null, spouseFirstName, spouseMiddleName, spouseLastName, spouseSecondLastName);
}
/* branch office */
Short officeId = 0;
Short loanOfficerId = null;
Short groupFlagValue = 1;
if (StringUtils.isBlank(groupGlobalNum)) {
if (statusId == CustomerStatus.CLIENT_ACTIVE.getValue() && meetingDto == null) {
String error = getRowError(friendlyRowNumber) + getMessage(XlsMessageConstants.NO_MEETING_ERROR);
errorsList.add(error);
continue;
}
groupFlagValue = 0;
officeId = branchOfficeId;
List<PersonnelBO> officers = legacyPersonnelDao.getActiveLoanOfficersUnderOffice(officeId);
if (officers.isEmpty()) {
String error = getCellError(friendlyRowNumber, XlsImportConstants.BRANCH_SHORT_NAME_CELL) + getMessage(XlsMessageConstants.NO_OFFICERS_ERROR, branchShortName);
errorsList.add(error);
continue;
}
loanOfficerId = null;
for (PersonnelBO officer : officers) {
if (officer.getDisplayName().equals(loanOfficer)) {
loanOfficerId = officer.getPersonnelId();
break;
}
}
} else {
validateGroupStatus(groupGlobalNum, statusId);
}
/* Not imported values */
final boolean trained = false;
final Date trainedDate = null;
final java.sql.Date mfiJoiningDate = null;
final String externalId = "";
final InputStream picture = null;
final List<ApplicableAccountFeeDto> feesToApply = null;
final List<ClientNameDetailDto> familyNames = null;
final List<ClientFamilyDetailDto> familyDetails = null;
final List<Short> selectedSavingsProducts = null;
/* Final dto */
final ClientCreationDetail clientCreationDetail = new ClientCreationDetail(selectedSavingsProducts, clientName, statusId, mfiJoiningDate, externalId, addressDto, formedBy, dateOfBirth, governmentId, trained, trainedDate, groupFlagValue, clientNameDetailDto, clientPersonalDetailDto, spouseNameDetailDto, picture, feesToApply, groupGlobalNum, familyNames, familyDetails, loanOfficerId, officeId, activationDate);
validateDuplicateCustomers(clientCreationDetail, parsedClientDetails);
final ImportedClientDetail importedClientDetail = new ImportedClientDetail(clientCreationDetail, clientGlobalNum, meetingDto);
parsedClientDetails.add(importedClientDetail);
} catch (RowException ex) {
final String error = getRowError(friendlyRowNumber) + ex.getMessage();
errorsList.add(error);
} catch (CustomerException ex) {
final String error = getRowError(friendlyRowNumber) + getMessage(XlsMessageConstants.DUPLICATE_CLIENT_ERROR);
errorsList.add(error);
} catch (Exception ex) {
final String error = getCellError(friendlyRowNumber, currentCell) + ex.getMessage();
errorsList.add(error);
}
}
}
} catch (Exception ex) {
errorsList.add(getMessage(XlsMessageConstants.ERROR_READING_DOCUMENT, ex.getMessage()));
}
return new ParsedClientsDto(errorsList, parsedClientDetails);
}
use of org.mifos.dto.domain.MeetingDto in project head by mifos.
the class CenterServiceFacadeWebTierIntegrationTest method shouldCreateCenterWithExpectedSearchId.
@Test
public void shouldCreateCenterWithExpectedSearchId() {
MeetingBO meeting = new MeetingBuilder().withStartDate(new DateTime().minusWeeks(2)).build();
MeetingDto meetingDto = meeting.toDto();
String displayName = "testCenter";
String externalId = null;
AddressDto addressDto = new AddressDto("here", "", "", "", "", "", "", "");
PersonnelBO user = IntegrationTestObjectMother.findPersonnelById(Short.valueOf("1"));
Short loanOfficerId = user.getPersonnelId();
List<CreateAccountFeeDto> feesToApply = new ArrayList<CreateAccountFeeDto>();
CustomerStatus.GROUP_ACTIVE.getValue();
OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
// setup
createOfficeHierarchyUnderHeadOffice(headOffice);
Short officeId = branch1.getOfficeId();
DateTime mfiJoiningDate = new DateTime().minusWeeks(2);
new DateTime().minusWeeks(1);
CenterCreationDetail centerCreationDetail = new CenterCreationDetail(mfiJoiningDate.toLocalDate(), displayName, externalId, addressDto, loanOfficerId, officeId, feesToApply);
// exercise test
CustomerDetailsDto newlyCreatedCenterDetails = centerServiceFacade.createNewCenter(centerCreationDetail, meetingDto);
// verification
CenterBO center = customerDao.findCenterBySystemId(newlyCreatedCenterDetails.getGlobalCustNum());
Assert.assertThat(center.getSearchId(), is("1." + center.getCustomerId()));
}
use of org.mifos.dto.domain.MeetingDto in project head by mifos.
the class MeetingBO method toDto.
public MeetingDto toDto() {
MeetingTypeDto meetingType = this.meetingType.toDto();
MeetingDetailsDto meetingDetailsDto = this.meetingDetails.toDto();
return new MeetingDto(new LocalDate(this.meetingStartDate), this.meetingPlace, meetingType, meetingDetailsDto);
}
use of org.mifos.dto.domain.MeetingDto in project head by mifos.
the class GroupLoanAccountServiceFacadeWebTier method createGroupLoanAccount.
private LoanCreationResultDto createGroupLoanAccount(CreateGroupLoanAccount loanAccountInfo, Map<Integer, List<LoanPaymentDto>> backdatedLoanPayments, List<QuestionGroupDetail> questionGroups, LoanAccountCashFlow loanAccountCashFlow, List<DateTime> loanScheduleInstallmentDates, List<Number> totalInstallmentAmounts, List<CreateLoanAccount> memberDetails, boolean isBackdatedLoan) {
DateTime creationDate = new DateTime();
// 0. verify member details for GLIM group accounts
for (CreateLoanAccount groupMemberAccount : memberDetails) {
ClientBO member = this.customerDao.findClientById(groupMemberAccount.getCustomerId());
if (creationDate.isBefore(new DateTime(member.getCreatedDate()))) {
throw new BusinessRuleException("errors.cannotCreateLoan.because.clientsAreCreatedInFuture");
}
}
// 1. assemble loan details
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
OfficeBO userOffice = this.officeDao.findOfficeById(user.getBranchId());
PersonnelBO createdBy = this.personnelDao.findPersonnelById(userContext.getId());
CustomerBO customer = this.customerDao.findCustomerById(loanAccountInfo.getGroupLoanAccountDetails().getCustomerId());
if (customer.isGroup()) {
customer = this.customerDao.findGroupBySystemId(customer.getGlobalCustNum());
}
// assemble
LoanAccountDetail loanAccountDetail = assembleLoanAccountDetail(loanAccountInfo);
List<AccountFeesEntity> accountFeeEntities = assembleAccountFees(loanAccountInfo.getGroupLoanAccountDetails().getAccountFees());
List<AccountPenaltiesEntity> accountPenaltyEntities = assembleAccountPenalties(loanAccountInfo.getGroupLoanAccountDetails().getAccountPenalties());
LoanProductOverridenDetail overridenDetail = new LoanProductOverridenDetail(loanAccountDetail.getLoanAmount(), loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), loanAccountInfo.getGroupLoanAccountDetails().getInterestRate(), loanAccountInfo.getGroupLoanAccountDetails().getNumberOfInstallments(), loanAccountInfo.getGroupLoanAccountDetails().getGraceDuration(), accountFeeEntities, accountPenaltyEntities);
Integer interestDays = Integer.valueOf(AccountingRules.getNumberOfInterestDays().intValue());
boolean loanScheduleIndependentOfCustomerMeetingEnabled = loanAccountInfo.getGroupLoanAccountDetails().isRepaymentScheduleIndependentOfCustomerMeeting();
LoanScheduleConfiguration configuration = new LoanScheduleConfiguration(loanScheduleIndependentOfCustomerMeetingEnabled, interestDays);
MeetingBO repaymentDayMeeting = null;
if (loanScheduleIndependentOfCustomerMeetingEnabled) {
repaymentDayMeeting = this.createNewMeetingForRepaymentDay(loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), loanAccountInfo.getGroupLoanAccountDetails(), loanAccountDetail.getCustomer());
} else {
MeetingDto customerMeetingDto = customer.getCustomerMeetingValue().toDto();
repaymentDayMeeting = new MeetingFactory().create(customerMeetingDto);
Short recurAfter = loanAccountDetail.getLoanProduct().getLoanOfferingMeeting().getMeeting().getRecurAfter();
repaymentDayMeeting.getMeetingDetails().setRecurAfter(recurAfter);
}
List<DateTime> loanScheduleDates = new ArrayList<DateTime>(loanScheduleInstallmentDates);
LoanSchedule loanSchedule = assembleLoanSchedule(loanAccountDetail.getCustomer(), loanAccountDetail.getLoanProduct(), overridenDetail, configuration, repaymentDayMeeting, userOffice, loanScheduleDates, loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), totalInstallmentAmounts);
// 2. create loan
InstallmentRange installmentRange = new MaxMinNoOfInstall(loanAccountInfo.getGroupLoanAccountDetails().getMinAllowedNumberOfInstallments().shortValue(), loanAccountInfo.getGroupLoanAccountDetails().getMaxAllowedNumberOfInstallments().shortValue(), null);
AmountRange amountRange = new MaxMinLoanAmount(loanAccountInfo.getGroupLoanAccountDetails().getMaxAllowedLoanAmount().doubleValue(), loanAccountInfo.getGroupLoanAccountDetails().getMinAllowedLoanAmount().doubleValue(), null);
if (isBackdatedLoan) {
creationDate = loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate().toDateMidnight().toDateTime();
}
CreationDetail creationDetail = new CreationDetail(creationDate, Integer.valueOf(user.getUserId()));
LoanBO loan = LoanBO.openGroupLoanAccount(loanAccountDetail.getLoanProduct(), loanAccountDetail.getCustomer(), repaymentDayMeeting, loanSchedule, loanAccountDetail.getAccountState(), loanAccountDetail.getFund(), overridenDetail, configuration, installmentRange, amountRange, creationDetail, createdBy);
loan.setBusinessActivityId(loanAccountInfo.getGroupLoanAccountDetails().getLoanPurposeId());
loan.setExternalId(loanAccountInfo.getGroupLoanAccountDetails().getExternalId());
loan.setCollateralNote(loanAccountInfo.getGroupLoanAccountDetails().getCollateralNotes());
loan.setCollateralTypeId(loanAccountInfo.getGroupLoanAccountDetails().getCollateralTypeId());
if (isBackdatedLoan) {
loan.markAsCreatedWithBackdatedPayments();
}
//set up predefined loan account for importing loans
if (loanAccountInfo.getGroupLoanAccountDetails().getPredefinedAccountNumber() != null) {
loan.setGlobalAccountNum(loanAccountInfo.getGroupLoanAccountDetails().getPredefinedAccountNumber());
}
try {
personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
try {
transactionHelper.startTransaction();
this.loanDao.save(loan);
transactionHelper.flushSession();
//no predefined account number, generate one instead
if (loanAccountInfo.getGroupLoanAccountDetails().getPredefinedAccountNumber() == null) {
try {
loan.setGlobalAccountNum(loan.generateId(userOffice.getGlobalOfficeNum()));
} catch (AccountException e) {
throw new BusinessRuleException(e.getMessage());
}
this.loanDao.save(loan);
transactionHelper.flushSession();
}
//set up status flag
AccountStateFlagEntity flagEntity = null;
if (loanAccountInfo.getGroupLoanAccountDetails().getFlagId() != null) {
try {
flagEntity = legacyMasterDao.getPersistentObject(AccountStateFlagEntity.class, loanAccountInfo.getGroupLoanAccountDetails().getFlagId());
loan.setUserContext(userContext);
loan.setFlag(flagEntity);
loan.setClosedDate(new DateTimeService().getCurrentJavaDateTime());
loan.setUserContext(userContext);
} catch (PersistenceException e) {
throw new BusinessRuleException(e.getMessage());
}
this.loanDao.save(loan);
transactionHelper.flushSession();
}
// for GLIM loans only
List<CreateLoanAccount> individualMembersOfGroupLoan = new ArrayList<CreateLoanAccount>();
List<BigDecimal> radio = new ArrayList<BigDecimal>(loan.getNoOfInstallments());
List<LoanProductOverridenDetail> memberOverridenDetails = new ArrayList<LoanProductOverridenDetail>();
List<LoanSchedule> memberLoanSchedules = new ArrayList<LoanSchedule>();
List<ClientBO> clients = new ArrayList<ClientBO>();
for (CreateLoanAccount groupMemberAccount : memberDetails) {
ClientBO member = this.customerDao.findClientById(groupMemberAccount.getCustomerId());
Money loanAmount = new Money(loanAccountDetail.getLoanProduct().getCurrency(), groupMemberAccount.getLoanAmount());
List<CreateAccountPenaltyDto> defaultAccountPenalties = new ArrayList<CreateAccountPenaltyDto>();
radio.add(loanAmount.divide(loan.getLoanAmount()));
int memberCount = memberDetails.size();
for (CreateAccountPenaltyDto createAccountPenaltyDto : loanAccountInfo.getGroupLoanAccountDetails().getAccountPenalties()) {
Integer penaltyId = createAccountPenaltyDto.getPenaltyId();
String amount = createAccountPenaltyDto.getAmount();
PenaltyBO penaltyBO = this.penaltyDao.findPenaltyById(penaltyId.shortValue());
if (penaltyBO instanceof AmountPenaltyBO) {
amount = String.valueOf(Double.valueOf(createAccountPenaltyDto.getAmount()) / memberCount);
}
defaultAccountPenalties.add(new CreateAccountPenaltyDto(penaltyId, amount));
}
List<AccountFeesEntity> feeEntities = assembleAccountFees(groupMemberAccount.getAccountFees());
List<AccountPenaltiesEntity> penaltyEntities = assembleAccountPenalties(defaultAccountPenalties);
LoanProductOverridenDetail memberOverridenDetail = new LoanProductOverridenDetail(loanAmount, feeEntities, overridenDetail, penaltyEntities);
LoanSchedule memberSchedule = assembleLoanSchedule(member, loanAccountDetail.getLoanProduct(), memberOverridenDetail, configuration, repaymentDayMeeting, userOffice, new ArrayList<DateTime>(), loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), new ArrayList<Number>());
memberOverridenDetails.add(memberOverridenDetail);
memberLoanSchedules.add(memberSchedule);
clients.add(member);
individualMembersOfGroupLoan.add(groupMemberAccount);
}
//for original schedule persisting
List<LoanBO> memberLoans = new ArrayList<LoanBO>();
int index = 0;
for (CreateLoanAccount groupMemberAccount : individualMembersOfGroupLoan) {
LoanBO memberLoan = LoanBO.openGroupLoanForAccount(loan, loanAccountDetail.getLoanProduct(), clients.get(index), repaymentDayMeeting, memberLoanSchedules.get(index), memberOverridenDetails.get(index), configuration, installmentRange, amountRange, creationDetail, createdBy, Boolean.TRUE);
if (groupMemberAccount.getLoanPurposeId() > 0) {
memberLoan.setBusinessActivityId(groupMemberAccount.getLoanPurposeId());
}
if (!backdatedLoanPayments.isEmpty()) {
memberLoan.markAsCreatedWithBackdatedPayments();
}
this.loanDao.save(memberLoan);
transactionHelper.flushSession();
try {
memberLoan.setGlobalAccountNum(memberLoan.generateId(userOffice.getGlobalOfficeNum()));
} catch (AccountException e) {
throw new BusinessRuleException(e.getMessage());
}
this.loanDao.save(memberLoan);
transactionHelper.flushSession();
memberLoans.add(memberLoan);
index++;
}
// update loan schedule for Group Loan Account
loanSchedule = this.loanScheduleService.generateGroupLoanSchedule(loanAccountDetail.getLoanProduct(), repaymentDayMeeting, loanSchedule, memberLoanSchedules, loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), overridenDetail, configuration, userOffice.getOfficeId(), loanAccountDetail.getCustomer(), accountFeeEntities);
fixMemberAndParentInstallmentDetails(loan, memberLoans);
for (LoanBO memberLoan : memberLoans) {
memberLoan.updateLoanSummary();
loanDao.save(memberLoan);
}
this.loanDao.save(loan);
transactionHelper.flushSession();
// save question groups
if (!questionGroups.isEmpty()) {
Integer eventSourceId = questionnaireServiceFacade.getEventSourceId("Create", "Loan");
QuestionGroupDetails questionGroupDetails = new QuestionGroupDetails(Integer.valueOf(user.getUserId()).shortValue(), loan.getAccountId(), eventSourceId, questionGroups);
questionnaireServiceFacade.saveResponses(questionGroupDetails);
transactionHelper.flushSession();
}
if (loanAccountCashFlow != null && !loanAccountCashFlow.getMonthlyCashFlow().isEmpty()) {
List<MonthlyCashFlowDetail> monthlyCashFlowDetails = new ArrayList<MonthlyCashFlowDetail>();
for (MonthlyCashFlowDto monthlyCashFlow : loanAccountCashFlow.getMonthlyCashFlow()) {
MonthlyCashFlowDetail monthlyCashFlowDetail = new MonthlyCashFlowDetail(monthlyCashFlow.getMonthDate(), monthlyCashFlow.getRevenue(), monthlyCashFlow.getExpenses(), monthlyCashFlow.getNotes());
monthlyCashFlowDetails.add(monthlyCashFlowDetail);
}
org.mifos.platform.cashflow.service.CashFlowDetail cashFlowDetail = new org.mifos.platform.cashflow.service.CashFlowDetail(monthlyCashFlowDetails);
cashFlowDetail.setTotalCapital(loanAccountCashFlow.getTotalCapital());
cashFlowDetail.setTotalLiability(loanAccountCashFlow.getTotalLiability());
cashFlowService.save(cashFlowDetail);
transactionHelper.flushSession();
}
if (isBackdatedLoan) {
// 3. auto approve loan
String comment = "Automatic Status Update (Redo Loan)";
LocalDate approvalDate = loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate();
loan.approve(createdBy, comment, approvalDate);
for (LoanBO memberLoan : memberLoans) {
memberLoan.approve(createdBy, comment, approvalDate);
}
// 4. disburse loan
String receiptNumber = null;
Date receiptDate = null;
PaymentTypeEntity paymentType = new PaymentTypeEntity(PaymentTypes.CASH.getValue());
if (loanAccountInfo.getGroupLoanAccountDetails().getDisbursalPaymentTypeId() != null) {
paymentType = new PaymentTypeEntity(loanAccountInfo.getGroupLoanAccountDetails().getDisbursalPaymentTypeId());
}
Date paymentDate = loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate().toDateMidnight().toDate();
AccountPaymentEntity disbursalPayment = new AccountPaymentEntity(loan, loan.getLoanAmount(), receiptNumber, receiptDate, paymentType, paymentDate);
disbursalPayment.setCreatedByUser(createdBy);
this.loanBusinessService.persistOriginalSchedule(loan);
for (LoanBO memberLoan : memberLoans) {
this.loanBusinessService.persistOriginalSchedule(memberLoan);
}
// refactoring of loan disbursal
if (customer.isDisbursalPreventedDueToAnyExistingActiveLoansForTheSameProduct(loan.getLoanOffering())) {
throw new BusinessRuleException("errors.cannotDisburseLoan.because.otherLoansAreActive");
}
try {
loan.updateCustomer(customer);
new ProductMixValidator().checkIfProductsOfferingCanCoexist(loan);
} catch (ServiceException e1) {
throw new AccountException(e1.getMessage());
}
loan.disburse(createdBy, disbursalPayment);
for (LoanBO memberLoan : memberLoans) {
memberLoan.disburse(createdBy, disbursalPayment);
}
customer.updatePerformanceHistoryOnDisbursement(loan, loan.getLoanAmount());
// end of refactoring of loan disbural
this.loanDao.save(loan);
transactionHelper.flushSession();
// 5. apply each payment
for (LoanBO memberLoan : memberLoans) {
Integer id = memberLoan.getCustomer().getCustomerId();
List<LoanPaymentDto> payments = backdatedLoanPayments.get(id);
for (LoanPaymentDto loanPayment : payments) {
Money amountPaidToDate = new Money(loan.getCurrency(), loanPayment.getAmount());
PaymentData paymentData = new PaymentData(amountPaidToDate, createdBy, loanPayment.getPaymentTypeId(), loanPayment.getPaymentDate().toDateMidnight().toDate());
memberLoan.applyPayment(paymentData);
loan.applyPayment(paymentData);
this.loanDao.save(memberLoan);
this.loanDao.save(loan);
}
}
}
transactionHelper.commitTransaction();
return new LoanCreationResultDto(false, loan.getAccountId(), loan.getGlobalAccountNum());
} catch (BusinessRuleException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getMessageKey(), e);
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.transactionHelper.closeSession();
}
}
use of org.mifos.dto.domain.MeetingDto in project head by mifos.
the class GroupLoanAccountServiceFacadeWebTier method getGroupLoanScheduleDto.
@Override
public GroupLoanScheduleDto getGroupLoanScheduleDto(CreateGroupLoanAccount loanAccountInfo, List<CreateLoanAccount> memberDetails) {
DateTime creationDate = new DateTime();
// 0. verify member details for GLIM group accounts
for (CreateLoanAccount groupMemberAccount : memberDetails) {
ClientBO member = this.customerDao.findClientById(groupMemberAccount.getCustomerId());
if (creationDate.isBefore(new DateTime(member.getCreatedDate()))) {
throw new BusinessRuleException("errors.cannotCreateLoan.because.clientsAreCreatedInFuture");
}
}
// 1. assemble loan details
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
OfficeBO userOffice = this.officeDao.findOfficeById(user.getBranchId());
PersonnelBO createdBy = this.personnelDao.findPersonnelById(userContext.getId());
CustomerBO customer = this.customerDao.findCustomerById(loanAccountInfo.getGroupLoanAccountDetails().getCustomerId());
if (customer.isGroup()) {
customer = this.customerDao.findGroupBySystemId(customer.getGlobalCustNum());
}
// assemble
LoanAccountDetail loanAccountDetail = assembleLoanAccountDetail(loanAccountInfo);
List<AccountFeesEntity> accountFeeEntities = assembleAccountFees(loanAccountInfo.getGroupLoanAccountDetails().getAccountFees());
List<AccountPenaltiesEntity> accountPenaltyEntities = assembleAccountPenalties(loanAccountInfo.getGroupLoanAccountDetails().getAccountPenalties());
LoanProductOverridenDetail overridenDetail = new LoanProductOverridenDetail(loanAccountDetail.getLoanAmount(), loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), loanAccountInfo.getGroupLoanAccountDetails().getInterestRate(), loanAccountInfo.getGroupLoanAccountDetails().getNumberOfInstallments(), loanAccountInfo.getGroupLoanAccountDetails().getGraceDuration(), accountFeeEntities, accountPenaltyEntities);
Integer interestDays = Integer.valueOf(AccountingRules.getNumberOfInterestDays().intValue());
boolean loanScheduleIndependentOfCustomerMeetingEnabled = loanAccountInfo.getGroupLoanAccountDetails().isRepaymentScheduleIndependentOfCustomerMeeting();
LoanScheduleConfiguration configuration = new LoanScheduleConfiguration(loanScheduleIndependentOfCustomerMeetingEnabled, interestDays);
MeetingBO repaymentDayMeeting = null;
if (loanScheduleIndependentOfCustomerMeetingEnabled) {
repaymentDayMeeting = this.createNewMeetingForRepaymentDay(loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), loanAccountInfo.getGroupLoanAccountDetails(), loanAccountDetail.getCustomer());
} else {
MeetingDto customerMeetingDto = customer.getCustomerMeetingValue().toDto();
repaymentDayMeeting = new MeetingFactory().create(customerMeetingDto);
Short recurAfter = loanAccountDetail.getLoanProduct().getLoanOfferingMeeting().getMeeting().getRecurAfter();
repaymentDayMeeting.getMeetingDetails().setRecurAfter(recurAfter);
}
List<DateTime> loanScheduleDates = new ArrayList<DateTime>();
LoanSchedule loanSchedule = assembleLoanSchedule(loanAccountDetail.getCustomer(), loanAccountDetail.getLoanProduct(), overridenDetail, configuration, repaymentDayMeeting, userOffice, loanScheduleDates, loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), new ArrayList<Number>());
// 2. create loan
InstallmentRange installmentRange = new MaxMinNoOfInstall(loanAccountInfo.getGroupLoanAccountDetails().getMinAllowedNumberOfInstallments().shortValue(), loanAccountInfo.getGroupLoanAccountDetails().getMaxAllowedNumberOfInstallments().shortValue(), null);
AmountRange amountRange = new MaxMinLoanAmount(loanAccountInfo.getGroupLoanAccountDetails().getMaxAllowedLoanAmount().doubleValue(), loanAccountInfo.getGroupLoanAccountDetails().getMinAllowedLoanAmount().doubleValue(), null);
creationDate = loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate().toDateMidnight().toDateTime();
CreationDetail creationDetail = new CreationDetail(creationDate, Integer.valueOf(user.getUserId()));
LoanBO loan = LoanBO.openGroupLoanAccount(loanAccountDetail.getLoanProduct(), loanAccountDetail.getCustomer(), repaymentDayMeeting, loanSchedule, loanAccountDetail.getAccountState(), loanAccountDetail.getFund(), overridenDetail, configuration, installmentRange, amountRange, creationDetail, createdBy);
loan.setBusinessActivityId(loanAccountInfo.getGroupLoanAccountDetails().getLoanPurposeId());
loan.setExternalId(loanAccountInfo.getGroupLoanAccountDetails().getExternalId());
loan.setCollateralNote(loanAccountInfo.getGroupLoanAccountDetails().getCollateralNotes());
loan.setCollateralTypeId(loanAccountInfo.getGroupLoanAccountDetails().getCollateralTypeId());
loan.markAsCreatedWithBackdatedPayments();
//set up predefined loan account for importing loans
if (loanAccountInfo.getGroupLoanAccountDetails().getPredefinedAccountNumber() != null) {
loan.setGlobalAccountNum(loanAccountInfo.getGroupLoanAccountDetails().getPredefinedAccountNumber());
}
// for GLIM loans only
List<CreateLoanAccount> individualMembersOfGroupLoan = new ArrayList<CreateLoanAccount>();
List<BigDecimal> radio = new ArrayList<BigDecimal>(loan.getNoOfInstallments());
List<LoanProductOverridenDetail> memberOverridenDetails = new ArrayList<LoanProductOverridenDetail>();
List<LoanSchedule> memberLoanSchedules = new ArrayList<LoanSchedule>();
List<ClientBO> clients = new ArrayList<ClientBO>();
for (CreateLoanAccount groupMemberAccount : memberDetails) {
ClientBO member = this.customerDao.findClientById(groupMemberAccount.getCustomerId());
Money loanAmount = new Money(loanAccountDetail.getLoanProduct().getCurrency(), groupMemberAccount.getLoanAmount());
List<CreateAccountPenaltyDto> defaultAccountPenalties = new ArrayList<CreateAccountPenaltyDto>();
radio.add(loanAmount.divide(loan.getLoanAmount()));
int memberCount = memberDetails.size();
for (CreateAccountPenaltyDto createAccountPenaltyDto : loanAccountInfo.getGroupLoanAccountDetails().getAccountPenalties()) {
Integer penaltyId = createAccountPenaltyDto.getPenaltyId();
String amount = createAccountPenaltyDto.getAmount();
PenaltyBO penaltyBO = this.penaltyDao.findPenaltyById(penaltyId.shortValue());
if (penaltyBO instanceof AmountPenaltyBO) {
amount = String.valueOf(Double.valueOf(createAccountPenaltyDto.getAmount()) / memberCount);
}
defaultAccountPenalties.add(new CreateAccountPenaltyDto(penaltyId, amount));
}
List<AccountFeesEntity> feeEntities = assembleAccountFees(groupMemberAccount.getAccountFees());
List<AccountPenaltiesEntity> penaltyEntities = assembleAccountPenalties(defaultAccountPenalties);
LoanProductOverridenDetail memberOverridenDetail = new LoanProductOverridenDetail(loanAmount, feeEntities, overridenDetail, penaltyEntities);
LoanSchedule memberSchedule = assembleLoanSchedule(member, loanAccountDetail.getLoanProduct(), memberOverridenDetail, configuration, repaymentDayMeeting, userOffice, new ArrayList<DateTime>(), loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), new ArrayList<Number>());
memberOverridenDetails.add(memberOverridenDetail);
memberLoanSchedules.add(memberSchedule);
clients.add(member);
individualMembersOfGroupLoan.add(groupMemberAccount);
}
//for original schedule persisting
List<LoanBO> memberLoans = new ArrayList<LoanBO>();
int index = 0;
for (CreateLoanAccount groupMemberAccount : individualMembersOfGroupLoan) {
LoanBO memberLoan = LoanBO.openGroupLoanForAccount(loan, loanAccountDetail.getLoanProduct(), clients.get(index), repaymentDayMeeting, memberLoanSchedules.get(index), memberOverridenDetails.get(index), configuration, installmentRange, amountRange, creationDetail, createdBy, Boolean.TRUE);
if (groupMemberAccount.getLoanPurposeId() > 0) {
memberLoan.setBusinessActivityId(groupMemberAccount.getLoanPurposeId());
}
memberLoan.markAsCreatedWithBackdatedPayments();
memberLoans.add(memberLoan);
index++;
}
// update loan schedule for Group Loan Account
loanSchedule = this.loanScheduleService.generateGroupLoanSchedule(loanAccountDetail.getLoanProduct(), repaymentDayMeeting, loanSchedule, memberLoanSchedules, loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), overridenDetail, configuration, userOffice.getOfficeId(), loanAccountDetail.getCustomer(), accountFeeEntities);
fixMemberAndParentInstallmentDetails(loan, memberLoans);
// translate schedules to dto form
Map<Integer, LoanScheduleEntity> parentScheduleEntities = loan.getLoanScheduleEntityMap();
List<LoanCreationInstallmentDto> parentInstallments = new ArrayList<LoanCreationInstallmentDto>();
Map<Integer, List<LoanCreationInstallmentDto>> memberInstallments = new HashMap<Integer, List<LoanCreationInstallmentDto>>();
for (CreateLoanAccount member : memberDetails) {
memberInstallments.put(member.getCustomerId(), new ArrayList<LoanCreationInstallmentDto>());
}
Short digitsAfterDecimal = AccountingRules.getDigitsAfterDecimal();
for (Integer installmentId : parentScheduleEntities.keySet()) {
LoanScheduleEntity loanScheduleEntity = parentScheduleEntities.get(installmentId);
parentInstallments.add(loanScheduleEntity.toLoanCreationInstallmentDto(digitsAfterDecimal));
for (LoanBO memberLoan : memberLoans) {
LoanScheduleEntity memberLoanScheduleEntity = memberLoan.getLoanScheduleEntityMap().get(installmentId);
memberInstallments.get(memberLoan.getCustomer().getCustomerId()).add(memberLoanScheduleEntity.toLoanCreationInstallmentDto(digitsAfterDecimal));
}
}
GroupLoanScheduleDto groupScheduleDto = new GroupLoanScheduleDto(customer.getDisplayName(), Double.valueOf(loan.getLoanAmount().getAmountDoubleValue()), loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), loan.getGraceType().getValue().intValue(), parentInstallments);
groupScheduleDto.setMemberSchedules(new HashMap<Integer, LoanScheduleDto>());
for (LoanBO memberLoan : memberLoans) {
Integer id = memberLoan.getCustomer().getCustomerId();
LoanScheduleDto memberScheduleDto = new LoanScheduleDto(memberLoan.getCustomer().getDisplayName(), Double.valueOf(memberLoan.getLoanAmount().getAmountDoubleValue()), loanAccountInfo.getGroupLoanAccountDetails().getDisbursementDate(), loan.getGraceType().getValue().intValue(), memberInstallments.get(id));
groupScheduleDto.getMemberSchedules().put(id, memberScheduleDto);
}
return groupScheduleDto;
}
Aggregations