You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2019/01/02 06:10:20 UTC

[GitHub] ShruthiRajaram closed pull request #506: FINERACT-669 client transfer details

ShruthiRajaram closed pull request #506: FINERACT-669 client transfer details
URL: https://github.com/apache/fineract/pull/506
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResource.java
index 383a9ef45..e7616d24d 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResource.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResource.java
@@ -389,6 +389,7 @@ 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 })
@@ -396,9 +397,6 @@ public String retrieveTransferTemplate(@PathParam("clientId") final Long clientI
 
 		this.context.authenticatedUser().validateHasReadPermission(ClientApiConstants.CLIENT_RESOURCE_NAME);
 		final Date transferDate = this.clientReadPlatformService.retrieveClientTransferProposalDate(clientId);
-		if (transferDate != null) {
-			return this.toApiJsonSerializer.serialize(new LocalDate(transferDate));
-		}
-		return this.toApiJsonSerializer.serialize(transferDate);
+		return this.toApiJsonSerializer.serialize((transferDate != null ? new LocalDate(transferDate) : null));
 	}
 }
\ No newline at end of file
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java
index ed4e0565b..f6afd7d3d 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/Client.java
@@ -231,6 +231,10 @@
     @ManyToOne(optional = true, fetch = FetchType.LAZY)
     @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,
@@ -1057,5 +1061,16 @@ public void loadLazyCollections() {
 
     public String getMiddlename(){return this.middlename;}
 
-    public String getLastname(){return this.lastname;}
+	public String getLastname() {
+		return this.lastname;
+	}
+
+	public Date getProposedTransferDate() {
+		return proposedTransferDate;
+	}
+
+	public void updateProposedTransferDate(Date proposedTransferDate) {
+		this.proposedTransferDate = proposedTransferDate;
+	}
+
 }
\ No newline at end of file
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientTransferDetails.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientTransferDetails.java
new file mode 100644
index 000000000..18c56f71a
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientTransferDetails.java
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.portfolio.client.domain;
+
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
+
+@SuppressWarnings("serial")
+@Entity
+@Table(name = "m_client_transfer_details")
+public class ClientTransferDetails extends AbstractPersistableCustom<Long> {
+
+	@Column(name = "client_id", length = 20, unique = true, nullable = false)
+	private Long clientId;
+
+	@Column(name = "from_office_id", nullable = false)
+	private Long fromOfficeId;
+
+	@Column(name = "to_office_id", nullable = false)
+	private Long toOfficeId;
+
+	@Column(name = "proposed_transfer_date", nullable = true)
+	@Temporal(TemporalType.DATE)
+	private Date proposedTransferDate;
+
+	@Column(name = "transfer_type", nullable = false)
+	private Integer transferEventType;
+
+	@Column(name = "submitted_on", nullable = false)
+	@Temporal(TemporalType.DATE)
+	private Date submittedOn;
+
+	@Column(name = "submitted_by", nullable = false)
+	private Long submittedBy;
+
+	protected ClientTransferDetails() {
+	}
+
+	private ClientTransferDetails(final Long clientId, final Long fromOfficeId, final Long toOfficeId,
+			final Date proposedTransferDate, final Integer transferEventType, final Date submittedOn,
+			final Long submittedBy) {
+		this.clientId = clientId;
+		this.fromOfficeId = fromOfficeId;
+		this.toOfficeId = toOfficeId;
+		this.proposedTransferDate = proposedTransferDate;
+		this.transferEventType = transferEventType;
+		this.submittedOn = submittedOn;
+		this.submittedBy = submittedBy;
+	}
+
+	public static ClientTransferDetails instance(final Long clientId, final Long fromOfficeId, final Long toOfficeId,
+			final Date proposedTransferDate, final Integer transferEventType, final Date submittedOn,
+			final Long submittedBy) {
+		return new ClientTransferDetails(clientId, fromOfficeId, toOfficeId, proposedTransferDate, transferEventType,
+				submittedOn, submittedBy);
+
+	}
+
+}
\ No newline at end of file
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientTransferDetailsRepository.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientTransferDetailsRepository.java
new file mode 100644
index 000000000..753fab980
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientTransferDetailsRepository.java
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.portfolio.client.domain;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface ClientTransferDetailsRepository
+		extends JpaRepository<ClientTransferDetails, Long>, JpaSpecificationExecutor<ClientTransferDetails> {
+
+}
\ No newline at end of file
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientTransferDetailsRepositoryWrapper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientTransferDetailsRepositoryWrapper.java
new file mode 100644
index 000000000..c2cdac364
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientTransferDetailsRepositoryWrapper.java
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.portfolio.client.domain;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ClientTransferDetailsRepositoryWrapper {
+
+	private final ClientTransferDetailsRepository repository;
+
+	@Autowired
+	public ClientTransferDetailsRepositoryWrapper(final ClientTransferDetailsRepository repository) {
+		this.repository = repository;
+	}
+
+	public void save(final ClientTransferDetails clientTransferDetails) {
+		this.repository.save(clientTransferDetails);
+	}
+
+}
\ No newline at end of file
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformService.java
index b9461deaa..c2cdb35bc 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformService.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformService.java
@@ -49,9 +49,5 @@
     
 	Date retrieveClientTransferProposalDate(Long clientId);
 
-	Date retrieveClientTransferProposalDateByLoan(Long clientId);
-
-	Date retrieveClientTransferProposalDateBySavings(Long clientId);
-
 	void validateClient(Long clientId);
 }
\ No newline at end of file
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java
index 43968d8d3..987b47fc8 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientReadPlatformServiceImpl.java
@@ -824,38 +824,14 @@ public ClientData retrieveAllNarrations(final String clientNarrations) {
     }
     
 	@Override
-	public Date retrieveClientTransferProposalDateByLoan(Long clientId) {
-		try {
-			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;
-
-		}
-	}
-
-	@Override
-	public Date retrieveClientTransferProposalDateBySavings(Long clientId) {
+	public Date retrieveClientTransferProposalDate(Long clientId) {
+		validateClient(clientId);
+		final String sql = "SELECT cl.proposed_transfer_date FROM m_client cl WHERE cl.id =? ";
 		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());
+			return this.jdbcTemplate.queryForObject(sql, Date.class, clientId);
 		} 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
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java
index b464dba9b..f5e677e36 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/transfer/service/TransferWritePlatformServiceJpaRepositoryImpl.java
@@ -27,6 +27,7 @@
 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;
@@ -40,6 +41,8 @@
 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;
@@ -81,6 +84,8 @@
     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,
@@ -89,7 +94,9 @@ public TransferWritePlatformServiceJpaRepositoryImpl(final ClientRepositoryWrapp
             final LoanRepositoryWrapper loanRepositoryWrapper, final TransfersDataValidator transfersDataValidator,
             final NoteWritePlatformService noteWritePlatformService, final StaffRepositoryWrapper staffRepositoryWrapper,
             final SavingsAccountRepositoryWrapper savingsAccountRepositoryWrapper,
-            final SavingsAccountWritePlatformService savingsAccountWritePlatformService) {
+			final SavingsAccountWritePlatformService savingsAccountWritePlatformService,
+			final ClientTransferDetailsRepositoryWrapper clientTransferDetailsRepositoryWrapper,
+			final PlatformSecurityContext context) {
         this.clientRepositoryWrapper = clientRepositoryWrapper;
         this.officeRepository = officeRepository;
         this.calendarInstanceRepository = calendarInstanceRepository;
@@ -101,6 +108,9 @@ public TransferWritePlatformServiceJpaRepositoryImpl(final ClientRepositoryWrapp
         this.staffRepositoryWrapper = staffRepositoryWrapper;
         this.savingsAccountRepositoryWrapper = savingsAccountRepositoryWrapper;
         this.savingsAccountWritePlatformService = savingsAccountWritePlatformService;
+        this.clientTransferDetailsRepositoryWrapper = clientTransferDetailsRepositoryWrapper;
+    	this.context = context;
+        
     }
 
     @Override
@@ -438,7 +448,8 @@ private void handleClientTransferLifecycleEvent(final Client client, final Offic
                 client.setStatus(ClientStatus.ACTIVE.getValue());
                 client.updateTransferToOffice(null);
                 client.updateOffice(destinationOffice);
-                client.updateOfficeJoiningDate(todaysDate);
+                client.updateOfficeJoiningDate(client.getProposedTransferDate());
+                client.updateProposedTransferDate(null);
                 if (client.getGroups().size() == 1) {
                     if (destinationGroup == null) {
                         throw new TransferNotSupportedException(TRANSFER_NOT_SUPPORTED_REASON.CLIENT_DESTINATION_GROUP_NOT_SPECIFIED,
@@ -458,18 +469,26 @@ 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);
-    }
+		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()));
+	}
 
     private List<Client> assembleListOfClients(final JsonCommand command) {
 
diff --git a/fineract-provider/src/main/resources/sql/migrations/core_db/V349__client_transfer_details.sql b/fineract-provider/src/main/resources/sql/migrations/core_db/V349__client_transfer_details.sql
new file mode 100644
index 000000000..a725d9338
--- /dev/null
+++ b/fineract-provider/src/main/resources/sql/migrations/core_db/V349__client_transfer_details.sql
@@ -0,0 +1,41 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you under the Apache License, Version 2.0 (the
+-- "License"); you may not use this file except in compliance
+-- with the License. You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing,
+-- software distributed under the License is distributed on an
+-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+-- KIND, either express or implied. See the License for the
+-- specific language governing permissions and limitations
+-- under the License.
+--
+
+ALTER TABLE `m_client`
+	ADD COLUMN `proposed_transfer_date` DATE NULL DEFAULT NULL AFTER `email_address`;
+
+	CREATE TABLE `m_client_transfer_details` (
+	`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
+	`client_id` BIGINT(20) NOT NULL,
+	`from_office_id` BIGINT(20) NOT NULL,
+	`to_office_id` BIGINT(20) NOT NULL,
+	`proposed_transfer_date` DATE NULL DEFAULT NULL,
+	`transfer_type` TINYINT(2) NOT NULL,
+	`submitted_on` DATE NOT NULL,
+	`submitted_by` BIGINT(20) NOT NULL,
+	PRIMARY KEY (`id`),
+	INDEX `FK_m_client_transfer_details_m_client` (`client_id`),
+	INDEX `FK_m_client_transfer_details_m_office` (`from_office_id`),
+	INDEX `FK_m_client_transfer_details_m_office_2` (`to_office_id`),
+	INDEX `FK_m_client_transfer_details_m_appuser` (`submitted_by`),
+	CONSTRAINT `FK_m_client_transfer_details_m_appuser` FOREIGN KEY (`submitted_by`) REFERENCES `m_appuser` (`id`),
+	CONSTRAINT `FK_m_client_transfer_details_m_client` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`),
+	CONSTRAINT `FK_m_client_transfer_details_m_office` FOREIGN KEY (`from_office_id`) REFERENCES `m_office` (`id`),
+	CONSTRAINT `FK_m_client_transfer_details_m_office_2` FOREIGN KEY (`to_office_id`) REFERENCES `m_office` (`id`)
+);
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services