Skip to content

Commit

Permalink
Revert "FINERACT-669 back dated client transfer changes"
Browse files Browse the repository at this point in the history
  • Loading branch information
ShruthiRajaram authored Dec 31, 2018
1 parent db389a0 commit 5702ce8
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.fineract.portfolio.client.api;

import io.swagger.annotations.*;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -71,14 +72,6 @@
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@Path("/clients")
@Component
@Scope("singleton")
Expand Down Expand Up @@ -396,15 +389,16 @@ public String retrieveObligeeDetails(@PathParam("clientId") final Long clientId,
return this.toApiJsonSerializer.serialize(ObligeeList);
}

@GET
@Path("{clientId}/transferproposaldate")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveTransferTemplate(@PathParam("clientId") final Long clientId, @Context final UriInfo uriInfo) {

this.context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);

this.context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
final Date transferDate = this.clientReadPlatformService.retrieveClientTransferProposalDate(clientId);
return this.toApiJsonSerializer.serialize((transferDate != null ? new LocalDate(transferDate) : null));
if (transferDate != null) {
return this.toApiJsonSerializer.serialize(new LocalDate(transferDate));
}
return this.toApiJsonSerializer.serialize(transferDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ public final class Client extends AbstractPersistableCustom<Long> {
@JoinColumn(name = "reopened_by_userid", nullable = true)
private AppUser reopenedBy;

@Column(name = "proposed_transfer_date", nullable = true)
@Temporal(TemporalType.DATE)
private Date proposedTransferDate;

public static Client createNew(final AppUser currentUser, final Office clientOffice, final Group clientParentGroup, final Staff staff,
final Long savingsProductId, final CodeValue gender, final CodeValue clientType, final CodeValue clientClassification,
final Integer legalForm, final JsonCommand command) {
Expand Down Expand Up @@ -1062,13 +1058,4 @@ public void loadLazyCollections() {
public String getMiddlename(){return this.middlename;}

public String getLastname(){return this.lastname;}

public Date getProposedTransferDate() {
return proposedTransferDate;
}

public void updateProposedTransferDate(Date proposedTransferDate) {
this.proposedTransferDate = proposedTransferDate;
}

}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,9 @@ public interface ClientReadPlatformService {

Date retrieveClientTransferProposalDate(Long clientId);

Date retrieveClientTransferProposalDateByLoan(Long clientId);

Date retrieveClientTransferProposalDateBySavings(Long clientId);

void validateClient(Long clientId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
import org.apache.fineract.portfolio.client.domain.LegalForm;
import org.apache.fineract.portfolio.client.exception.ClientNotFoundException;
import org.apache.fineract.portfolio.group.data.GroupGeneralData;
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
import org.apache.fineract.portfolio.savings.SavingsAccountTransactionType;
import org.apache.fineract.portfolio.savings.data.SavingsProductData;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountStatusType;
import org.apache.fineract.portfolio.savings.service.SavingsProductReadPlatformService;
import org.apache.fineract.useradministration.domain.AppUser;
import org.joda.time.LocalDate;
Expand Down Expand Up @@ -820,16 +824,40 @@ public ClientData retrieveAllNarrations(final String clientNarrations) {
}

@Override
public Date retrieveClientTransferProposalDate(Long clientId) {
validateClient(clientId);
final String sql = "SELECT cl.proposed_transfer_date FROM m_client cl WHERE cl.id =? ";
public Date retrieveClientTransferProposalDateByLoan(Long clientId) {
try {
return this.jdbcTemplate.queryForObject(sql, Date.class, clientId);
String sql = "SELECT t.transaction_date FROM m_client c LEFT JOIN m_loan loan ON c.id = loan.client_id AND c.id = ? AND loan.loan_status_id = ? LEFT JOIN m_loan_transaction t ON loan.id = t.loan_id AND t.transaction_type_enum = ? ORDER BY t.id DESC LIMIT 1";
return this.jdbcTemplate.queryForObject(sql, Date.class, clientId,
LoanStatus.TRANSFER_IN_PROGRESS.getValue(), LoanTransactionType.INITIATE_TRANSFER.getValue());
} catch (final EmptyResultDataAccessException e) {
return null;
return null;

}
}

@Override
public Date retrieveClientTransferProposalDateBySavings(Long clientId) {
try {
String sql = "SELECT t.transaction_date FROM m_client c LEFT JOIN m_savings_account savings ON c.id = savings.client_id AND c.id = ? AND savings.status_enum = ? LEFT JOIN m_savings_account_transaction t ON savings.id = t.savings_account_id AND t.transaction_type_enum = ? ORDER BY t.id DESC LIMIT 1";
return this.jdbcTemplate.queryForObject(sql, Date.class, clientId,
SavingsAccountStatusType.TRANSFER_IN_PROGRESS.getValue(),
SavingsAccountTransactionType.INITIATE_TRANSFER.getValue());
} catch (final EmptyResultDataAccessException e) {
return null;

}
}

@Override
public Date retrieveClientTransferProposalDate(Long clientId) {
validateClient(clientId);
Date transferDateForLoan = retrieveClientTransferProposalDateByLoan(clientId);
if (transferDateForLoan == null) {
transferDateForLoan = retrieveClientTransferProposalDateBySavings(clientId);
}
return transferDateForLoan;
}

@Override
public void validateClient(Long clientId) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.core.exception.GeneralPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.organisation.office.domain.Office;
import org.apache.fineract.organisation.office.domain.OfficeRepositoryWrapper;
import org.apache.fineract.organisation.staff.domain.Staff;
Expand All @@ -41,8 +40,6 @@
import org.apache.fineract.portfolio.client.domain.Client;
import org.apache.fineract.portfolio.client.domain.ClientRepositoryWrapper;
import org.apache.fineract.portfolio.client.domain.ClientStatus;
import org.apache.fineract.portfolio.client.domain.ClientTransferDetails;
import org.apache.fineract.portfolio.client.domain.ClientTransferDetailsRepositoryWrapper;
import org.apache.fineract.portfolio.client.exception.ClientHasBeenClosedException;
import org.apache.fineract.portfolio.group.domain.Group;
import org.apache.fineract.portfolio.group.domain.GroupRepositoryWrapper;
Expand Down Expand Up @@ -84,8 +81,6 @@ public class TransferWritePlatformServiceJpaRepositoryImpl implements TransferWr
private final TransfersDataValidator transfersDataValidator;
private final NoteWritePlatformService noteWritePlatformService;
private final StaffRepositoryWrapper staffRepositoryWrapper;
private final ClientTransferDetailsRepositoryWrapper clientTransferDetailsRepositoryWrapper;
private final PlatformSecurityContext context;

@Autowired
public TransferWritePlatformServiceJpaRepositoryImpl(final ClientRepositoryWrapper clientRepositoryWrapper,
Expand All @@ -94,10 +89,8 @@ public TransferWritePlatformServiceJpaRepositoryImpl(final ClientRepositoryWrapp
final LoanRepositoryWrapper loanRepositoryWrapper, final TransfersDataValidator transfersDataValidator,
final NoteWritePlatformService noteWritePlatformService, final StaffRepositoryWrapper staffRepositoryWrapper,
final SavingsAccountRepositoryWrapper savingsAccountRepositoryWrapper,
final SavingsAccountWritePlatformService savingsAccountWritePlatformService,
final ClientTransferDetailsRepositoryWrapper clientTransferDetailsRepositoryWrapper,
final PlatformSecurityContext context) {
this.clientRepositoryWrapper = clientRepositoryWrapper;
final SavingsAccountWritePlatformService savingsAccountWritePlatformService) {
this.clientRepositoryWrapper = clientRepositoryWrapper;
this.officeRepository = officeRepository;
this.calendarInstanceRepository = calendarInstanceRepository;
this.loanWritePlatformService = loanWritePlatformService;
Expand All @@ -108,9 +101,7 @@ public TransferWritePlatformServiceJpaRepositoryImpl(final ClientRepositoryWrapp
this.staffRepositoryWrapper = staffRepositoryWrapper;
this.savingsAccountRepositoryWrapper = savingsAccountRepositoryWrapper;
this.savingsAccountWritePlatformService = savingsAccountWritePlatformService;
this.clientTransferDetailsRepositoryWrapper = clientTransferDetailsRepositoryWrapper;
this.context = context;
}
}

@Override
@Transactional
Expand Down Expand Up @@ -447,8 +438,7 @@ private void handleClientTransferLifecycleEvent(final Client client, final Offic
client.setStatus(ClientStatus.ACTIVE.getValue());
client.updateTransferToOffice(null);
client.updateOffice(destinationOffice);
client.updateOfficeJoiningDate(client.getProposedTransferDate());
client.updateProposedTransferDate(null);
client.updateOfficeJoiningDate(todaysDate);
if (client.getGroups().size() == 1) {
if (destinationGroup == null) {
throw new TransferNotSupportedException(TRANSFER_NOT_SUPPORTED_REASON.CLIENT_DESTINATION_GROUP_NOT_SPECIFIED,
Expand All @@ -468,26 +458,18 @@ private void handleClientTransferLifecycleEvent(final Client client, final Offic
case PROPOSAL:
client.setStatus(ClientStatus.TRANSFER_IN_PROGRESS.getValue());
client.updateTransferToOffice(destinationOffice);
client.updateProposedTransferDate(transferDate.toDate());
break;
case REJECTION:
client.setStatus(ClientStatus.TRANSFER_ON_HOLD.getValue());
client.updateTransferToOffice(null);
client.updateProposedTransferDate(null);
break;
case WITHDRAWAL:
client.setStatus(ClientStatus.ACTIVE.getValue());
client.updateTransferToOffice(null);
client.updateProposedTransferDate(null);
}

this.noteWritePlatformService.createAndPersistClientNote(client, jsonCommand);
Date proposedTransferDate = transferDate != null ? transferDate.toDate() : null;
this.clientTransferDetailsRepositoryWrapper
.save(ClientTransferDetails.instance(client.getId(), client.getOffice().getId(),
destinationOffice.getId(), proposedTransferDate, transferEventType.getValue(),
DateUtils.getLocalDateTimeOfTenant().toDate(), this.context.authenticatedUser().getId()));
}
this.noteWritePlatformService.createAndPersistClientNote(client, jsonCommand);
}

private List<Client> assembleListOfClients(final JsonCommand command) {

Expand Down
Loading

0 comments on commit 5702ce8

Please sign in to comment.