001    /**
002     * Copyright 2004-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.hr.time.detail.web;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.joda.time.DateTime;
020    import org.joda.time.format.DateTimeFormat;
021    import org.joda.time.format.DateTimeFormatter;
022    import org.kuali.hr.lm.balancetransfer.BalanceTransfer;
023    import org.kuali.hr.time.calendar.TkCalendar;
024    import org.kuali.hr.time.service.base.TkServiceLocator;
025    import org.kuali.hr.time.timeblock.TimeBlock;
026    import org.kuali.hr.time.timesummary.TimeSummary;
027    import org.kuali.hr.time.util.TKUtils;
028    import org.kuali.hr.time.util.TkConstants;
029    
030    import java.text.SimpleDateFormat;
031    import java.util.*;
032    
033    public class TimeDetailActionForm extends TimeDetailActionFormBase {
034    
035        private static DateTimeFormatter SDF_NO_TZ = DateTimeFormat.forPattern("EEE MMM d HH:mm:ss yyyy");
036    
037        /**
038         *
039         */
040        private static final long serialVersionUID = 5277197287612035236L;
041    
042    
043            private TimeBlock timeBlock;
044            private String clockAction;
045            private String serverTimezone;
046            private String userTimezone;
047            private TimeSummary timeSummary;
048            private Map<String, String> assignStyleClassMap = new HashMap<String, String>();
049        private String timeBlockString;
050        private String leaveBlockString;
051        private TkCalendar calendar;
052        private String docEditable;
053        private String workingOnItsOwn;     // true if the user is working on its own timesheet
054        private List<String> overtimeEarnCodes = new ArrayList<String>();
055        private String tkTimeHourDetailId;
056        private String isLunchDeleted;
057        private boolean canAddTimeblock;
058    
059        public TkCalendar getTkCalendar() {
060            return calendar;
061        }
062    
063        public void setTkCalendar(TkCalendar calendar) {
064            this.calendar = calendar;
065        }
066    
067            public List<TimeBlock> getTimeBlockList() {
068                    return this.getTimesheetDocument().getTimeBlocks();
069            }
070            
071            // for Actual Time Inquiry display only
072            public List<TimeBlock> getClockLogTimeBlockList() {
073                    List<TimeBlock> clockList = new ArrayList<TimeBlock>();
074                    for(TimeBlock tb : this.getTimeBlockList()){
075                            if(tb.getClockLogCreated()) {
076                                    clockList.add(tb);
077                            }
078                    }
079                    return clockList;
080            }
081    
082            public TimeBlock getTimeBlock() {
083                    return timeBlock;
084            }
085    
086            public void setTimeBlock(TimeBlock timeBlock) {
087                    this.timeBlock = timeBlock;
088            }
089    
090            public String getClockAction() {
091                    return clockAction;
092            }
093    
094            public void setClockAction(String clockAction) {
095                    this.clockAction = clockAction;
096            }
097    
098            public String getIsVirtualWorkDay() {
099                    Calendar cal = Calendar.getInstance();
100                    cal.setTime(getBeginPeriodDateTime());
101                    return Boolean.toString(TKUtils.isVirtualWorkDay(cal));
102            }
103    
104            public TimeSummary getTimeSummary() {
105                    return timeSummary;
106            }
107    
108            public void setTimeSummary(TimeSummary timeSummary) {
109                    this.timeSummary = timeSummary;
110            }
111    
112            public String getServerTimezone() {
113                    return TKUtils.getSystemTimeZone();
114            }
115    
116            public String getUserTimezone() {
117                    return TkServiceLocator.getTimezoneService().getUserTimezone();
118            }
119    
120            public Map<String, String> getAssignStyleClassMap() {
121                    return assignStyleClassMap;
122            }
123    
124            public void setAssignStyleClassMap(Map<String, String> assignStyleClassMap) {
125                    this.assignStyleClassMap = assignStyleClassMap;
126            }
127    
128        public String getTimeBlockString() {
129            return timeBlockString;
130        }
131    
132        public void setTimeBlockString(String timeBlockString) {
133            this.timeBlockString = timeBlockString;
134        }
135    
136        public String getBeginPeriodDTNoTZ() {
137            return SDF_NO_TZ.print(new DateTime(this.getBeginPeriodDateTime()));
138        }
139    
140        public String getEndPeriodDTNoTZ() {
141            return SDF_NO_TZ.print(new DateTime(this.getEndPeriodDateTime()));
142        }
143        
144    
145        public boolean isCurrentTimesheet() {
146            return (TKUtils.getCurrentDate().compareTo(this.getBeginPeriodDateTime()) >= 0 && TKUtils.getCurrentDate().compareTo(this.getEndPeriodDateTime()) < 0 );
147        }
148    
149            public String getDocEditable() {
150                    if(StringUtils.isEmpty(docEditable)) {
151                            docEditable="false";
152                    }
153                    return docEditable;
154            }
155    
156            public void setDocEditable(String docEditable) {
157                    this.docEditable = docEditable;
158            }
159    
160            public List<String> getOvertimeEarnCodes() {
161                    return overtimeEarnCodes;
162            }
163    
164            public void setOvertimeEarnCodes(List<String> overtimeEarnCodes) {
165                    this.overtimeEarnCodes = overtimeEarnCodes;
166            }
167    
168        public String getTkTimeHourDetailId() {
169            return tkTimeHourDetailId;
170        }
171    
172        public void setTkTimeHourDetailId(String tkTimeHourDetailId) {
173            this.tkTimeHourDetailId = tkTimeHourDetailId;
174        }
175    
176        public String getLunchDeleted() {
177            return isLunchDeleted;
178        }
179    
180        public void setLunchDeleted(String lunchDeleted) {
181            isLunchDeleted = lunchDeleted;
182        }
183    
184        public boolean isCanAddTimeblock() {
185            return TkServiceLocator.getPermissionsService().canAddTimeBlock();
186        }
187    
188            public String getWorkingOnItsOwn() {
189                    if(StringUtils.isEmpty(workingOnItsOwn)) {
190                            workingOnItsOwn="false";
191                    }
192                    return workingOnItsOwn;
193            }
194    
195            public void setWorkingOnItsOwn(String workingOnItsOwn) {
196                    this.workingOnItsOwn = workingOnItsOwn;
197            }
198    
199            public String getLeaveBlockString() {
200                    return leaveBlockString;
201            }
202    
203            public void setLeaveBlockString(String leaveBlockString) {
204                    this.leaveBlockString = leaveBlockString;
205            }
206    
207    }