MIFOSX-1737: Center Staff Assignment History
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
@@ -118,6 +119,9 @@ public final class Group extends AbstractPersistable<Long> {
|
||||
@JoinColumn(name = "submittedon_userid", nullable = true)
|
||||
private AppUser submittedBy;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "center", orphanRemoval = true)
|
||||
private Set<StaffAssignmentHistory> staffHistory;
|
||||
|
||||
// JPA default constructor for entity
|
||||
protected Group() {
|
||||
this.name = null;
|
||||
@@ -174,6 +178,7 @@ public final class Group extends AbstractPersistable<Long> {
|
||||
|
||||
this.submittedOnDate = submittedOnDate.toDate();
|
||||
this.submittedBy = currentUser;
|
||||
this.staffHistory = null;
|
||||
|
||||
associateClients(clientMembers);
|
||||
|
||||
@@ -372,10 +377,18 @@ public final class Group extends AbstractPersistable<Long> {
|
||||
}
|
||||
|
||||
public void updateStaff(final Staff staff) {
|
||||
if (this.isCenter() && this.isActive()) {
|
||||
LocalDate updatedDate = DateUtils.getLocalDateOfTenant();
|
||||
reassignStaff(staff, updatedDate);
|
||||
}
|
||||
this.staff = staff;
|
||||
}
|
||||
|
||||
public void unassignStaff() {
|
||||
if (this.isCenter() && this.isActive()) {
|
||||
LocalDate dateOfStaffUnassigned = DateUtils.getLocalDateOfTenant();
|
||||
removeStaff(dateOfStaffUnassigned);
|
||||
}
|
||||
this.staff = null;
|
||||
}
|
||||
|
||||
@@ -620,4 +633,43 @@ public final class Group extends AbstractPersistable<Long> {
|
||||
public Set<Client> getClientMembers() {
|
||||
return this.clientMembers;
|
||||
}
|
||||
|
||||
// StaffAssignmentHistory[during center creation]
|
||||
public void caputreStaffHistoryDuringCenterCreation(final Staff newStaff, final LocalDate assignmentDate) {
|
||||
if (this.isCenter() && this.isActive() && staff != null) {
|
||||
this.staff = newStaff;
|
||||
final StaffAssignmentHistory staffAssignmentHistory = StaffAssignmentHistory.createNew(this, this.staff, assignmentDate);
|
||||
if (staffAssignmentHistory != null) {
|
||||
staffHistory = new HashSet<>();
|
||||
this.staffHistory.add(staffAssignmentHistory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// StaffAssignmentHistory[assign staff]
|
||||
public void reassignStaff(final Staff newStaff, final LocalDate assignmentDate) {
|
||||
this.staff = newStaff;
|
||||
final StaffAssignmentHistory staffAssignmentHistory = StaffAssignmentHistory.createNew(this, this.staff, assignmentDate);
|
||||
this.staffHistory.add(staffAssignmentHistory);
|
||||
}
|
||||
|
||||
// StaffAssignmentHistory[unassign staff]
|
||||
public void removeStaff(final LocalDate unassignDate) {
|
||||
final StaffAssignmentHistory latestHistoryRecord = findLatestIncompleteHistoryRecord();
|
||||
if (latestHistoryRecord != null) {
|
||||
latestHistoryRecord.updateEndDate(unassignDate);
|
||||
}
|
||||
}
|
||||
|
||||
private StaffAssignmentHistory findLatestIncompleteHistoryRecord() {
|
||||
|
||||
StaffAssignmentHistory latestRecordWithNoEndDate = null;
|
||||
for (final StaffAssignmentHistory historyRecord : this.staffHistory) {
|
||||
if (historyRecord.isCurrentRecord()) {
|
||||
latestRecordWithNoEndDate = historyRecord;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return latestRecordWithNoEndDate;
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package org.mifosplatform.portfolio.group.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.domain.AbstractAuditableCustom;
|
||||
import org.mifosplatform.organisation.staff.domain.Staff;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
|
||||
@Entity
|
||||
@Table(name = "m_staff_assignment_history")
|
||||
public class StaffAssignmentHistory extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "centre_id", nullable = true)
|
||||
private Group center;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "staff_id", nullable = true)
|
||||
private Staff staff;
|
||||
|
||||
@Temporal(TemporalType.DATE)
|
||||
@Column(name = "start_date")
|
||||
private Date startDate;
|
||||
|
||||
@Temporal(TemporalType.DATE)
|
||||
@Column(name = "end_date")
|
||||
private Date endDate;
|
||||
|
||||
public static StaffAssignmentHistory createNew(final Group center, final Staff staff, final LocalDate startDate) {
|
||||
return new StaffAssignmentHistory(center, staff, startDate.toDate(), null);
|
||||
}
|
||||
|
||||
protected StaffAssignmentHistory() {
|
||||
//
|
||||
}
|
||||
|
||||
private StaffAssignmentHistory(final Group center, final Staff staff, final Date startDate, final Date endDate) {
|
||||
this.center = center;
|
||||
this.staff = staff;
|
||||
this.startDate = startDate;
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public void updateStaff(final Staff staff) {
|
||||
this.staff = staff;
|
||||
}
|
||||
|
||||
public void updateStartDate(final LocalDate startDate) {
|
||||
this.startDate = startDate.toDate();
|
||||
}
|
||||
|
||||
public void updateEndDate(final LocalDate endDate) {
|
||||
this.endDate = endDate.toDate();
|
||||
}
|
||||
|
||||
public boolean matchesStartDateOf(final LocalDate matchingDate) {
|
||||
return getStartDate().isEqual(matchingDate);
|
||||
}
|
||||
|
||||
public LocalDate getStartDate() {
|
||||
return new LocalDate(this.startDate);
|
||||
}
|
||||
|
||||
public boolean isCurrentRecord() {
|
||||
return this.endDate == null;
|
||||
}
|
||||
}
|
||||
+1
-5
@@ -189,7 +189,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
newGroup.generateHierarchy();
|
||||
|
||||
this.groupRepository.saveAndFlush(newGroup);
|
||||
|
||||
newGroup.caputreStaffHistoryDuringCenterCreation(staff, activationDate);
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(command.commandId()) //
|
||||
.withOfficeId(groupOffice.getId()) //
|
||||
@@ -404,9 +404,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
final Map<String, Object> actualChanges = new LinkedHashMap<>(9);
|
||||
|
||||
this.fromApiJsonDeserializer.validateForUnassignStaff(command.json());
|
||||
|
||||
final Group groupForUpdate = this.groupRepository.findOneWithNotFoundDetection(grouptId);
|
||||
|
||||
final Staff presentStaff = groupForUpdate.getStaff();
|
||||
Long presentStaffId = null;
|
||||
if (presentStaff == null) { throw new GroupHasNoStaffException(grouptId); }
|
||||
@@ -442,7 +440,6 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
|
||||
Staff staff = null;
|
||||
final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
|
||||
|
||||
final boolean inheritStaffForClientAccounts = command
|
||||
.booleanPrimitiveValueOfParameterNamed(GroupingTypesApiConstants.inheritStaffForClientAccounts);
|
||||
staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, groupForUpdate.getOffice().getHierarchy());
|
||||
@@ -476,7 +473,6 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.groupRepository.saveAndFlush(groupForUpdate);
|
||||
|
||||
actualChanges.put(GroupingTypesApiConstants.staffIdParamName, staffId);
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
||||
label.detail.center_name=Centers
|
||||
label.detail.staff_id=Staff Id
|
||||
label.detail.staff_name=Staff Name
|
||||
label.detail.from_date=From
|
||||
label.detail.assigned_on=Assigned On
|
||||
label.detail.assigned_by=Assigned By
|
||||
label.detail.unassigned_on=Unassigned On
|
||||
label.detail.unassigned_by=Unassigned By
|
||||
label.detail.to=To
|
||||
label.detail.
|
||||
label.detail.
|
||||
label.detail.
|
||||
label.detail.
|
||||
label.detail.
|
||||
label.detail.
|
||||
label.detail.
|
||||
head=Staff Assignmet History
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
CREATE TABLE IF NOT EXISTS `m_staff_assignment_history` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`centre_id` bigint(20) DEFAULT NULL,
|
||||
`staff_id` bigint(20) NOT NULL,
|
||||
`start_date` date NOT NULL,
|
||||
`end_date` date DEFAULT NULL,
|
||||
`createdby_id` bigint(20) DEFAULT NULL,
|
||||
`created_date` datetime DEFAULT NULL,
|
||||
`lastmodified_date` datetime DEFAULT NULL,
|
||||
`lastmodifiedby_id` bigint(20) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FK_m_staff_assignment_history_centre_id_m_group` (`centre_id`),
|
||||
KEY `FK_m_staff_assignment_history_m_staff` (`staff_id`),
|
||||
CONSTRAINT `FK_m_staff_assignment_history_centre_id_m_group` FOREIGN KEY (`centre_id`) REFERENCES `m_group` (`id`),
|
||||
CONSTRAINT `FK_m_staff_assignment_history_m_staff` FOREIGN KEY (`staff_id`) REFERENCES `m_staff` (`id`)
|
||||
)
|
||||
INSERT INTO stretchy_parameter ( parameter_name, parameter_variable, parameter_label, parameter_displayType, parameter_FormatType, parameter_default, special, selectOne, selectAll, parameter_sql, parent_id) VALUES ('selectCenterId', 'centerId', 'Enter Center Id', 'text', 'string', 'n/a', NULL, NULL, NULL, NULL, NULL);
|
||||
INSERT INTO stretchy_report ( report_name, report_type, report_subtype, report_category, report_sql, description, core_report, use_report) VALUES ( 'Staff Assignment History', 'Pentaho', NULL, NULL, NULL, NULL, 0, 1);
|
||||
INSERT INTO stretchy_report_parameter ( report_id, parameter_id, report_parameter_name)
|
||||
VALUES ((select sr.id from stretchy_report sr where sr.report_name='Staff Assignment History'),
|
||||
(select sp.id from stretchy_parameter sp where sp.parameter_name='selectCenterId'),
|
||||
'centerId');
|
||||
Reference in New Issue
Block a user