Skip to content

Commit

Permalink
added leave edit and leave cancel options
Browse files Browse the repository at this point in the history
  • Loading branch information
sibow committed Dec 5, 2024
1 parent 652d199 commit 49e83e2
Show file tree
Hide file tree
Showing 12 changed files with 373 additions and 42 deletions.
58 changes: 53 additions & 5 deletions src/main/java/in/bloomington/timer/action/LeaveRequestAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class LeaveRequestAction extends TopAction{
static final long serialVersionUID = 3800L;
static Logger logger = LogManager.getLogger(LeaveRequestAction.class);
//
String pay_period_id = "", job_id = "";
String pay_period_id = "", job_id = "", cancel_reason="";
String leavesTitle = "Previous Leave Requests";
LeaveRequest leave = null;
List<LeaveRequest> requests = null;
Expand All @@ -44,7 +44,7 @@ public String execute(){
if(!back.isEmpty()){
return back;
}
if(action.startsWith("Submit")){
if(action.startsWith("Submit Request")){
leave.setInitiated_by(user.getId());
leave.setJob_id(job_id);
leave.setEarn_code_ids(earn_code_ids);
Expand All @@ -69,7 +69,48 @@ public String execute(){
addMessage("Submitted Successfully");
}
}
if(action.equals("Cancel")){
else if(action.equals("Edit")){
getLeave();
back = leave.doSelect();
if(!back.isEmpty()){
addError(back);
}
else{
job_id = leave.getJob_id();
earn_code_ids = leave.getEarn_code_ids();
}
}
else if(action.startsWith("Save")){
leave.setInitiated_by(user.getId());
leave.setJob_id(job_id);
leave.setEarn_code_ids(earn_code_ids);
back = leave.doUpdate();
if(!back.isEmpty()){
addError(back);
}
else{
// reset
id = "";
earn_code_ids = new String[1];
earn_code_ids[0] = "";
leave = new LeaveRequest();
leave.setJob_id(job_id);
leave.setInitiated_by(user.getId());
addMessage("Saved Successfully");
}
}
else if(action.startsWith("startCancel")){
getLeave();
back = leave.doSelect();
if(!back.isEmpty()){
addError(back);
}
else{
job_id = leave.getJob_id();
ret = "leave_cancel";
}
}
else if(action.startsWith("Submit Cancel")){
getLeave();
back = leave.doSelect();
if(!back.isEmpty()){
Expand All @@ -79,6 +120,7 @@ public String execute(){
review.setLeave_id(leave.getId());
review.setLeave(leave);
review.setReviewed_by(user.getId());
review.setCancelReason(cancel_reason);
back = review.doCancel();
if(!back.isEmpty()){
addError(back);
Expand Down Expand Up @@ -169,6 +211,10 @@ public void setAction2(String val){
if(val != null && !val.isEmpty())
action = val;
}
public void setCancel_reason(String val){
if(val != null && !val.isEmpty())
cancel_reason = val;
}
public void setPay_period_id(String val){
if(val != null && !val.isEmpty())
pay_period_id = val;
Expand All @@ -190,6 +236,9 @@ public String[] getEarn_code_ids(){
}
return earn_code_ids;
}
public String getCancel_reason(){
return cancel_reason;
}
void findCurrentPayPeriod(){
//
if(pay_period_id.isEmpty()){
Expand All @@ -210,7 +259,6 @@ public List<LeaveRequest> getRequests(){
LeaveRequestList tl = new LeaveRequestList();
tl.setJob_id(job_id);
tl.setPay_period_id(pay_period_id);
// tl.setIsReviewed();
String back = tl.find();
if(back.isEmpty()){
List<LeaveRequest> ones = tl.getRequests();
Expand Down Expand Up @@ -267,7 +315,7 @@ public List<LeaveRequest> getPendingLeaves(){
return pending_leaves;
}
*/
public boolean hasDecidedRequests(){
public boolean hasCurrentRequests(){
getRequests();
return requests != null && requests.size() > 0;
}
Expand Down
69 changes: 65 additions & 4 deletions src/main/java/in/bloomington/timer/action/LeaveReviewAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public class LeaveReviewAction extends TopAction{
String group_id="", pay_period_id="", leave_id="",
department_id="";
String selected_group_id = "";
// leave filter
String filter_emp_id="", date_from="", date_to="";
// review filter
String rev_filter_emp_id="", rev_date_from="", rev_date_to="";
String[] statusVals = {"Approved","Denied"};
PayPeriod payPeriod = null;
Group group = null;
Expand All @@ -41,6 +44,7 @@ public class LeaveReviewAction extends TopAction{
Employee reviewer = null;
List<LeaveReview> reviews = null;
List<Employee> employees = null;//for filter
List<Employee> rev_employees = null;//for history filter
int leaves_total_number = 0;
public String execute(){
String ret = SUCCESS;
Expand Down Expand Up @@ -125,11 +129,27 @@ public String getDate_from(){
public String getDate_to(){
return date_to;
}
public void setRev_date_to(String val){
if(val != null && !val.isEmpty()){
rev_date_to = val;
}
}
public void setRev_date_from(String val){
if(val != null && !val.isEmpty()){
rev_date_from = val;
}
}
public String getRev_date_from(){
return rev_date_from;
}
public String getRev_date_to(){
return rev_date_to;
}
public void setDate_to(String val){
if(val != null && !val.isEmpty()){
date_to = val;
}
}
}
public String getLeave_id(){
return leave_id = "";
}
Expand Down Expand Up @@ -285,11 +305,17 @@ public void setFilter_emp_id(String val){
filter_emp_id = val;
}
}
public String getFilter_emp_id(){
if(filter_emp_id.isEmpty())
public void setRev_filter_emp_id(String val){
if(val != null && !val.equals("-1")){
rev_filter_emp_id = val;
}
}
public String getRev_filter_emp_id(){
if(rev_filter_emp_id.isEmpty())
return "-1";
return filter_emp_id;
return rev_filter_emp_id;
}


public Department getDepartment(){
if(department == null){
Expand Down Expand Up @@ -407,15 +433,50 @@ public boolean hasReviews(){
return reviews != null && reviews.size() > 0;

}
//
// we need a filter if we have more than 3 reviews
//
public boolean isRevFilterNeeded(){
if(hasReviews()){
return reviews != null && reviews.size() > 3;
}
return false;
}
public boolean hasRevEmployees(){
return rev_employees != null && rev_employees.size() > 0;
}
public List<Employee> getRev_employees(){
return rev_employees;
}
void findReviews(){
LeaveReviewList lrl = new LeaveReviewList();
lrl.setReviewed_by(user.getId());
if(!rev_date_from.isEmpty()){
lrl.setDate_from_ff(rev_date_from);
}
if(!rev_date_to.isEmpty()){
lrl.setDate_to_ff(rev_date_to);
}
if(!rev_filter_emp_id.isEmpty()){
lrl.setEmployee_id(rev_filter_emp_id);
}
String back = lrl.find();
if(back.isEmpty()){
List<LeaveReview> ones = lrl.getReviews();
if(ones != null && ones.size() > 0){
reviews = ones;
}
if(reviews != null){
for(LeaveReview one:reviews){
Employee emp = one.getLeave().getEmployee();
if(emp != null){
if(rev_employees == null)
rev_employees = new ArrayList<>();
rev_employees.add(emp);
}
}

}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/in/bloomington/timer/bean/LeaveRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ public String getManagerName(){
}
return full_name;
}
public boolean canBeCancelled(){
if(!hasReviewer()){
if(payPeriod == null)
findCurrentPayPeriod();
return (start_date.compareTo(payPeriod.getStartDateYmd()) >= 0);
}
return false;
}
// for notification
public GroupManager getManager(){
findGroupManager();
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/in/bloomington/timer/bean/LeaveReview.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class LeaveReview implements java.io.Serializable{
static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
static Logger logger = LogManager.getLogger(LeaveReview.class);
String id="", status="", // Approved, Denied, Cancelled
leave_id="", reviewed_by="", date="", notes="";
leave_id="", reviewed_by="", date="", notes="", cancel_reason="";
boolean activeMail = false;
String mail_host = "";
Employee user = null;
Expand Down Expand Up @@ -109,6 +109,10 @@ public void setNotes(String val){
if(val != null)
notes=val;
}
public void setCancelReason(String val){
if(val != null)
cancel_reason=val;
}
public void setReviewStatus(String val){
if(val != null)
status=val;
Expand Down Expand Up @@ -489,7 +493,8 @@ public String doCancel(){
pstmt = con.prepareStatement(qq);
pstmt.setString(1, leave_id);
pstmt.setString(2, status);
pstmt.setNull(3, Types.VARCHAR);
cancel_reason = "Request cancelled by the employee for the following reason: "+cancel_reason;
pstmt.setString(3, cancel_reason);
pstmt.setString(4, reviewed_by);
pstmt.executeUpdate();
//
Expand Down Expand Up @@ -586,7 +591,7 @@ String informEmployee(String leave_one,

}
if(rev_status_one.equals("Approved")){
email_msg += "Please update your availability in any calendars or out of office notifications.\n\n";
email_msg += "Please update your availability in your personal calendar, department time off calendar, and any out of office notifications.\n\n";
}
//
MailHandle mailer = new
Expand Down
42 changes: 39 additions & 3 deletions src/main/java/in/bloomington/timer/list/LeaveReviewList.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class LeaveReviewList{
static SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
static final long serialVersionUID = 3800L;
String leave_id="", date_from="", date_to="", sortBy="id desc";
String date_from_ff="", date_to_ff="";
String employee_id="";
String reviewed_by="";
List<LeaveReview> reviews = null;

Expand All @@ -41,10 +43,22 @@ public void setDate_to(String val){
if(val != null)
date_to = val;
}
public void setDate_from_ff(String val){
if(val != null)
date_from_ff = val;
}
public void setDate_to_ff(String val){
if(val != null)
date_to_ff = val;
}
public void setReviewed_by(String val){
if(val != null)
reviewed_by=val;
}
}
public void setEmployee_id(String val){
if(val != null)
employee_id=val;
}
public void setSortBy(String val){
if(val != null)
sortBy = val;
Expand All @@ -55,8 +69,9 @@ public String find(){
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection con = UnoConnect.getConnection();
String qq = "select id,leave_id,date_format(review_date,'%m/%d/%Y'),review_status,review_notes,reviewed_by "+
"from leave_reviews ";
String qq = "select r.id,r.leave_id,date_format(r.review_date,'%m/%d/%Y'),r.review_status,r.review_notes,r.reviewed_by "+
"from leave_reviews r join leave_requests l on l.id=r.leave_id "+
"join jobs j on j.id=l.job_id ";
if(con == null){
back = "Could not connect to DB";
return back;
Expand All @@ -79,6 +94,18 @@ public String find(){
if(!qw.isEmpty()) qw += " and ";
qw += " reviewed_by = ? ";
}
if(!date_from_ff.isEmpty()){
if(!qw.isEmpty()) qw += " and ";
qw += " review_date >= ? ";
}
if(!date_to_ff.isEmpty()){
if(!qw.isEmpty()) qw += " and ";
qw += " review_date <= ? ";
}
if(!employee_id.isEmpty()){
if(!qw.isEmpty()) qw += " and ";
qw += " j.employee_id = ? ";
}
if(!qw.isEmpty()){
qq += " where "+qw;
}
Expand All @@ -100,6 +127,15 @@ public String find(){
if(!reviewed_by.isEmpty()){
pstmt.setString(jj++,reviewed_by);
}
if(!date_from_ff.isEmpty()){
pstmt.setString(jj++, date_from_ff);
}
if(!date_to_ff.isEmpty()){
pstmt.setString(jj++, date_to_ff);
}
if(!employee_id.isEmpty()){
pstmt.setString(jj++,employee_id);
}
rs = pstmt.executeQuery();
if(reviews == null)
reviews = new ArrayList<>();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<result name="error">/WEB-INF/jsp/leave_request.jsp</result>
<result name="success">/WEB-INF/jsp/leave_request.jsp</result>
<result name="view">/WEB-INF/jsp/leave_view.jsp</result>
<result name="leave_cancel">/WEB-INF/jsp/leave_cancel.jsp</result>
</action>
<action name="leave_review"
class="in.bloomington.timer.action.LeaveReviewAction"
Expand Down
Loading

0 comments on commit 49e83e2

Please sign in to comment.