use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class GroupServiceFacadeWebTier method updateCustomerHistoricalData.
@Override
public void updateCustomerHistoricalData(String globalCustNum, CustomerHistoricalDataUpdateRequest historicalData) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
CustomerBO customerBO = this.customerDao.findCustomerBySystemId(globalCustNum);
customerBO.updateDetails(userContext);
try {
CustomerHistoricalDataEntity customerHistoricalDataEntity = customerBO.getHistoricalData();
if (customerBO.getPersonnel() != null) {
checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), customerBO.getPersonnel().getPersonnelId());
} else {
checkPermissionForAddingHistoricalData(customerBO.getLevel(), userContext, customerBO.getOffice().getOfficeId(), userContext.getId());
}
// Integer oldLoanCycleNo = 0;
if (customerHistoricalDataEntity == null) {
customerHistoricalDataEntity = new CustomerHistoricalDataEntity(customerBO);
customerHistoricalDataEntity.setCreatedBy(customerBO.getUserContext().getId());
customerHistoricalDataEntity.setCreatedDate(new DateTimeService().getCurrentJavaDateTime());
} else {
// oldLoanCycleNo =
// customerHistoricalDataEntity.getLoanCycleNumber();
customerHistoricalDataEntity.setUpdatedDate(new DateTimeService().getCurrentJavaDateTime());
customerHistoricalDataEntity.setUpdatedBy(customerBO.getUserContext().getId());
}
customerHistoricalDataEntity.setInterestPaid(StringUtils.isBlank(historicalData.getInterestPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getInterestPaid()));
customerHistoricalDataEntity.setLoanAmount(StringUtils.isBlank(historicalData.getLoanAmount()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getLoanAmount()));
customerHistoricalDataEntity.setLoanCycleNumber(historicalData.getLoanCycleNumber());
customerHistoricalDataEntity.setMissedPaymentsCount(historicalData.getMissedPaymentsCount());
customerHistoricalDataEntity.setNotes(historicalData.getNotes());
customerHistoricalDataEntity.setProductName(historicalData.getProductName());
customerHistoricalDataEntity.setTotalAmountPaid(StringUtils.isBlank(historicalData.getTotalAmountPaid()) ? null : new Money(Money.getDefaultCurrency(), historicalData.getTotalAmountPaid()));
customerHistoricalDataEntity.setTotalPaymentsCount(historicalData.getTotalPaymentsCount());
customerHistoricalDataEntity.setMfiJoiningDate(historicalData.getMfiJoiningDate());
this.transactionHelper.startTransaction();
this.transactionHelper.beginAuditLoggingFor(customerBO);
customerBO.updateHistoricalData(customerHistoricalDataEntity);
this.customerDao.save(customerBO);
this.transactionHelper.commitTransaction();
} catch (ApplicationException e) {
this.transactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class CollectionSheetServiceFacadeWebTier method saveCollectionSheet.
@Override
public CollectionSheetErrorsDto saveCollectionSheet(final CollectionSheetEntryGridDto previousCollectionSheetEntryDto, final Short userId) {
final SaveCollectionSheetDto saveCollectionSheetDto = new SaveCollectionSheetFromLegacyAssembler().fromWebTierLegacyStructuretoSaveCollectionSheetDto(previousCollectionSheetEntryDto, userId);
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
int customerId = saveCollectionSheetDto.getSaveCollectionSheetCustomers().get(0).getCustomerId();
CustomerBO customerBO = this.customerDao.findCustomerById(customerId);
try {
personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
monthClosingServiceFacade.validateTransactionDate(saveCollectionSheetDto.getTransactionDate().toDateMidnight().toDate());
return saveCollectionSheet(saveCollectionSheetDto);
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class ClientServiceFacadeWebTier method retrieveClientFormCreationData.
@Override
public ClientFormCreationDto retrieveClientFormCreationData(Short groupFlag, Short officeId, String parentGroupId) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
List<PersonnelDto> personnelList = new ArrayList<PersonnelDto>();
MeetingBO parentCustomerMeeting = null;
Short formedByPersonnelId = null;
String formedByPersonnelName = "";
String centerDisplayName = "";
String groupDisplayName = "";
String officeName = "";
List<FeeBO> fees = new ArrayList<FeeBO>();
Short applicableOfficeId = officeId;
if (YesNoFlag.YES.getValue().equals(groupFlag)) {
Integer parentCustomerId = Integer.valueOf(parentGroupId);
CustomerBO parentCustomer = this.customerDao.findCustomerById(parentCustomerId);
groupDisplayName = parentCustomer.getDisplayName();
if (parentCustomer.getPersonnel() != null) {
formedByPersonnelId = parentCustomer.getPersonnel().getPersonnelId();
formedByPersonnelName = parentCustomer.getPersonnel().getDisplayName();
}
if (parentCustomer.getParentCustomer() != null) {
centerDisplayName = parentCustomer.getParentCustomer().getDisplayName();
}
applicableOfficeId = parentCustomer.getOffice().getOfficeId();
officeName = parentCustomer.getOffice().getOfficeName();
if (parentCustomer.getCustomerMeeting() != null) {
parentCustomerMeeting = parentCustomer.getCustomerMeetingValue();
fees = this.customerDao.retrieveFeesApplicableToClientsRefinedBy(parentCustomer.getCustomerMeetingValue());
} else {
fees = this.customerDao.retrieveFeesApplicableToClients();
}
} else if (YesNoFlag.NO.getValue().equals(groupFlag)) {
CenterCreation centerCreation = new CenterCreation(applicableOfficeId, userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
personnelList = this.personnelDao.findActiveLoanOfficersForOffice(centerCreation);
fees = this.customerDao.retrieveFeesApplicableToClients();
}
CustomerApplicableFeesDto applicableFees = CustomerApplicableFeesDto.toDto(fees, userContext);
List<ApplicableAccountFeeDto> defaultFees = new ArrayList<ApplicableAccountFeeDto>();
for (FeeDto fee : applicableFees.getDefaultFees()) {
defaultFees.add(new ApplicableAccountFeeDto(fee.getFeeIdValue().intValue(), fee.getFeeName(), fee.getAmount(), fee.isRemoved(), fee.isWeekly(), fee.isMonthly(), fee.isPeriodic(), fee.getFeeSchedule()));
}
List<ApplicableAccountFeeDto> additionalFees = new ArrayList<ApplicableAccountFeeDto>();
for (FeeDto fee : applicableFees.getAdditionalFees()) {
additionalFees.add(new ApplicableAccountFeeDto(fee.getFeeIdValue().intValue(), fee.getFeeName(), fee.getAmount(), fee.isRemoved(), fee.isWeekly(), fee.isMonthly(), fee.isPeriodic(), fee.getFeeSchedule()));
}
List<SavingsDetailDto> savingsOfferings = this.customerDao.retrieveSavingOfferingsApplicableToClient();
ClientRulesDto clientRules = retrieveClientRules();
ClientDropdownsDto clientDropdowns = retrieveClientDropdownData();
List<PersonnelDto> formedByPersonnel = this.customerDao.findLoanOfficerThatFormedOffice(applicableOfficeId);
MeetingDto parentMeeting = null;
if (parentCustomerMeeting != null) {
parentMeeting = parentCustomerMeeting.toDto();
}
return new ClientFormCreationDto(clientDropdowns, clientRules, applicableOfficeId, officeName, formedByPersonnelId, formedByPersonnelName, personnelList, formedByPersonnel, savingsOfferings, parentMeeting, centerDisplayName, groupDisplayName, additionalFees, defaultFees);
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class ClientServiceFacadeWebTier method createNewClient.
@Override
public CustomerDetailsDto createNewClient(ClientCreationDetail clientCreationDetail, MeetingDto meetingDto, List<SavingsDetailDto> allowedSavingProducts) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
try {
ClientBO client = null;
List<AccountFeesEntity> feesForCustomerAccount = convertFeeViewsToAccountFeeEntities(clientCreationDetail.getFeesToApply());
List<SavingsOfferingBO> selectedOfferings = new ArrayList<SavingsOfferingBO>();
for (Short productId : clientCreationDetail.getSelectedSavingProducts()) {
if (productId != null) {
for (SavingsDetailDto savingsOffering : allowedSavingProducts) {
if (productId.equals(savingsOffering.getPrdOfferingId())) {
SavingsOfferingBO savingsProduct = savingsProductDao.findById(productId.intValue());
selectedOfferings.add(savingsProduct);
}
}
}
}
List<ClientInitialSavingsOfferingEntity> offeringsAssociatedInCreate = new ArrayList<ClientInitialSavingsOfferingEntity>();
for (SavingsOfferingBO offering : selectedOfferings) {
offeringsAssociatedInCreate.add(new ClientInitialSavingsOfferingEntity(null, offering));
}
Short personnelId = null;
Short officeId = null;
ClientNameDetailDto spouseNameDetailView = null;
if (ClientRules.isFamilyDetailsRequired()) {
// actionForm.setFamilyDateOfBirth();
// actionForm.constructFamilyDetails();
} else {
spouseNameDetailView = clientCreationDetail.getSpouseFatherName();
}
String secondMiddleName = null;
ClientNameDetailEntity clientNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, clientCreationDetail.getClientNameDetailDto());
ClientNameDetailEntity spouseFatherNameDetailEntity = null;
if (spouseNameDetailView != null) {
spouseFatherNameDetailEntity = new ClientNameDetailEntity(null, secondMiddleName, spouseNameDetailView);
}
ClientDetailEntity clientDetailEntity = new ClientDetailEntity();
clientDetailEntity.updateClientDetails(clientCreationDetail.getClientPersonalDetailDto());
DateTime dob = new DateTime(clientCreationDetail.getDateOfBirth());
boolean trainedBool = clientCreationDetail.isTrained();
DateTime trainedDateTime = null;
if (clientCreationDetail.getTrainedDate() != null) {
trainedDateTime = new DateTime(clientCreationDetail.getTrainedDate());
}
String clientFirstName = clientCreationDetail.getClientNameDetailDto().getFirstName();
String clientLastName = clientCreationDetail.getClientNameDetailDto().getLastName();
String secondLastName = clientCreationDetail.getClientNameDetailDto().getSecondLastName();
CustomerStatus clientStatus = CustomerStatus.fromInt(clientCreationDetail.getClientStatus());
PersonnelBO formedBy = this.personnelDao.findPersonnelById(clientCreationDetail.getFormedBy());
Address address = null;
if (clientCreationDetail.getAddress() != null) {
AddressDto dto = clientCreationDetail.getAddress();
address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
}
if (YesNoFlag.YES.getValue().equals(clientCreationDetail.getGroupFlag())) {
Integer parentGroupId = Integer.parseInt(clientCreationDetail.getParentGroupId());
CustomerBO group = this.customerDao.findCustomerById(parentGroupId);
if (group.getPersonnel() != null) {
personnelId = group.getPersonnel().getPersonnelId();
}
officeId = group.getOffice().getOfficeId();
client = ClientBO.createNewInGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, new DateTime(clientCreationDetail.getMfiJoiningDate()), group, formedBy, clientNameDetailEntity, dob, clientCreationDetail.getGovernmentId(), trainedBool, trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, offeringsAssociatedInCreate, clientCreationDetail.getExternalId(), address, clientCreationDetail.getActivationDate());
if (ClientRules.isFamilyDetailsRequired()) {
client.setFamilyAndNameDetailSets(clientCreationDetail.getFamilyNames(), clientCreationDetail.getFamilyDetails());
}
this.customerService.createClient(client, client.getCustomerMeetingValue(), feesForCustomerAccount, selectedOfferings);
} else {
personnelId = clientCreationDetail.getLoanOfficerId();
officeId = clientCreationDetail.getOfficeId();
PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(personnelId);
OfficeBO office = this.officeDao.findOfficeById(officeId);
int lastSearchIdCustomerValue = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
MeetingBO clientMeeting = null;
if (meetingDto != null) {
clientMeeting = new MeetingFactory().create(meetingDto);
clientMeeting.setUserContext(userContext);
}
client = ClientBO.createNewOutOfGroupHierarchy(userContext, clientCreationDetail.getClientName(), clientStatus, new DateTime(clientCreationDetail.getMfiJoiningDate()), office, loanOfficer, clientMeeting, formedBy, clientNameDetailEntity, dob, clientCreationDetail.getGovernmentId(), trainedBool, trainedDateTime, clientCreationDetail.getGroupFlag(), clientFirstName, clientLastName, secondLastName, spouseFatherNameDetailEntity, clientDetailEntity, offeringsAssociatedInCreate, clientCreationDetail.getExternalId(), address, lastSearchIdCustomerValue);
if (ClientRules.isFamilyDetailsRequired()) {
client.setFamilyAndNameDetailSets(clientCreationDetail.getFamilyNames(), clientCreationDetail.getFamilyDetails());
}
try {
personnelDao.checkAccessPermission(userContext, client.getOfficeId(), client.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
this.customerService.createClient(client, clientMeeting, feesForCustomerAccount, selectedOfferings);
}
clientPhotoService.create(client.getCustomerId().longValue(), clientCreationDetail.getPicture());
return new CustomerDetailsDto(client.getCustomerId(), client.getGlobalCustNum());
} catch (CustomerException e) {
throw new BusinessRuleException(e.getKey(), e.getValues(), e);
}
}
use of org.mifos.customers.business.CustomerBO in project head by mifos.
the class LoanAccountServiceFacadeWebTier method validateLoanWithBackdatedPaymentsDisbursementDate.
@Override
public Errors validateLoanWithBackdatedPaymentsDisbursementDate(LocalDate loanDisbursementDate, Integer customerId, Integer productId) {
Errors errors = new Errors();
if (!loanDisbursementDate.isBefore(new LocalDate())) {
String[] args = { "" };
errors.addError("dibursementdate.before.todays.date", args);
}
CustomerBO customer = this.customerDao.findCustomerById(customerId);
LocalDate customerActivationDate = new LocalDate(customer.getCustomerActivationDate());
if (loanDisbursementDate.isBefore(customerActivationDate)) {
String[] args = { customerActivationDate.toString("dd-MMM-yyyy") };
errors.addError("dibursementdate.before.customer.activation.date", args);
}
LoanOfferingBO loanProduct = this.loanProductDao.findById(productId);
LocalDate productStartDate = new LocalDate(loanProduct.getStartDate());
if (loanDisbursementDate.isBefore(productStartDate)) {
String[] args = { productStartDate.toString("dd-MMM-yyyy") };
errors.addError("dibursementdate.before.product.startDate", args);
}
try {
this.holidayServiceFacade.validateDisbursementDateForNewLoan(customer.getOfficeId(), loanDisbursementDate.toDateMidnight().toDateTime());
} catch (BusinessRuleException e) {
String[] args = { "" };
errors.addError("dibursementdate.falls.on.holiday", args);
}
return errors;
}
Aggregations