gt: 							if(overtime && time) {
context: /*******************************************************************************
   * This file is part of Termitaria, a project management tool 
   *    Copyright (C) 2008-2013 CodeSphere S.R.L., www.codesphere.ro
   *     
   *    Termitaria is free software; you can redistribute it and/or 
   *    modify it under the terms of the GNU Affero General Public License 
   *    as published by the Free Software Foundation; either version 3 of 
   *    the License, or (at your option) any later version.
   *    
   *    This program is distributed in the hope that it will be useful, 
   *    but WITHOUT ANY WARRANTY; without even the implied warranty of 
   *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
   *    GNU Affero General Public License for more details.
   *    
   *    You should have received a copy of the GNU Affero General Public License 
   *    along with Termitaria. If not, see  <http://www.gnu.org/licenses/> .
   ******************************************************************************/
  package ro.cs.ts.web.controller.form;
  
  import java.net.URLEncoder;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.GregorianCalendar;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  import java.util.Set;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import net.sf.json.JSONArray;
  import net.sf.json.JSONObject;
  
  import org.springframework.beans.propertyeditors.CustomDateEditor;
  import org.springframework.security.core.context.SecurityContextHolder;
  import org.springframework.validation.BindException;
  import org.springframework.validation.Errors;
  import org.springframework.web.bind.ServletRequestDataBinder;
  import org.springframework.web.bind.ServletRequestUtils;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.support.RequestContextUtils;
  
  import ro.cs.ts.business.BLActivity;
  import ro.cs.ts.business.BLAudit;
  import ro.cs.ts.business.BLCalendar;
  import ro.cs.ts.business.BLPersonDetail;
  import ro.cs.ts.business.BLProject;
  import ro.cs.ts.business.BLRecord;
  import ro.cs.ts.business.BLTeamMember;
  import ro.cs.ts.business.BLTeamMemberDetail;
  import ro.cs.ts.business.BLUser;
  import ro.cs.ts.cm.Project;
  import ro.cs.ts.cm.TeamMember;
  import ro.cs.ts.common.IConstant;
  import ro.cs.ts.common.PermissionConstant;
  import ro.cs.ts.context.TSContext;
  import ro.cs.ts.entity.Activity;
  import ro.cs.ts.entity.PersonDetail;
  import ro.cs.ts.entity.Record;
  import ro.cs.ts.entity.TeamMemberDetail;
  import ro.cs.ts.exception.BusinessException;
  import ro.cs.ts.nom.IntObj;
  import ro.cs.ts.om.Calendar;
  import ro.cs.ts.thread.NotificationThread;
  import ro.cs.ts.web.controller.root.ControllerUtils;
  import ro.cs.ts.web.controller.root.RootSimpleFormController;
  import ro.cs.ts.web.security.UserAuth;
  import ro.cs.ts.ws.client.om.OMWebServiceClient;
  import ro.cs.ts.ws.client.om.entity.UserSimple;
  
  public class RecordFormController extends RootSimpleFormController {
  	
  	public static final String FORM_VIEW								= "RecordForm";
  	public static final String SUCCESS_VIEW								= "RecordForm";
  	
  	//------------------------ATTRIBUTES---------------------------------------------------------------
  	private static final String ID 										= "recordId";
  	
  	//------------------------MESSAGES-----------------------------------------------------------------
  	private static final String GET_ERROR 								= "record.get.error";
  	private static final String UPDATE_MESSAGE 							= "record.update.message";
  	private static final String UPDATE_ERROR 							= "record.update.error";
  	private static final String ADD_MESSAGE								= "record.add.message";
  	private static final String ADD_ERROR								= "record.add.error";
  	private static final String GENERAL_ERROR							= "record.general.form.error";
  	private static final String GET_USER_PROJECTS_ERROR 				= "record.get.user.projects.error";
  	private static final String GET_PROJECT_ERROR						= "project.get.error";
  	private static final String GET_CALENDAR_ERROR						= "calendar.get.error";
  	private static final String PRICE_NOT_DEFINED						= "record.price.not.defined";
  	private static final String EXISTS_IDENTICAL_RECORD_TIME			= "record.exists.identical.time";
  	private static final String EXISTS_IDENTICAL_RECORD_TIME_OVERTIME	= "record.exists.identical.time.overtime";
  	private static final String EXISTS_IDENTICAL_RECORD_TTO				= "record.exists.identical.time.time.overtime";
  	private static final String EXISTS_IDENTICAL_RECORD_OVERTIME		= "record.exists.identical.overtime";
  	private static final String EXISTS_IDENTICAL_RECORD_OVERTIME_TIME	= "record.exists.identical.overtime.time";
  	private static final String EXISTS_IDENTICAL_RECORD_OOT				= "record.exists.identical.overtime.overtime.time";
  	private static final String EXISTS_IDENTICAL_HOURS					= "record.exists.identical.hours";		
  	
  	//--------------------BACK PARAMETERS-------------------------------------------------------------
  	private static final String BACK_URL 								= "BACK_URL";
  	private static final String NEXT_BACK_URL							= "NEXT_BACK_URL";
  	private static final String ENCODE_BACK_URL	 						= "ENCODE_BACK_URL";
  	
  	//--------------------MODEL-----------------------------------------------------------------------
  	private static final String USER_PROJECTS							= "USER_PROJECTS";
  	private static final String USER_PROJECTS_IS_PM_AND_MEMBERS			= "USER_PROJECTS_IS_PM_AND_MEMBERS";
  	private static final String IS_PM_FOR_AT_LEAST_ONE_PROJECT			= "IS_PM_FOR_AT_LEAST_ONE_PROJECT";
  	private static final String PERSON_ID								= "PERSON_ID";
  	private static final String IS_USER_ALL								= "IS_USER_ALL";
  	private static final String SHOW_BILLABLE							= "SHOW_BILLABLE";
  	private static final String TODAY_DATE								= "TODAY_DATE";
  	private static final String USER_NAME					 			= "USER_NAME";
  	private static final String IS_MANAGER								= "IS_MANAGER";
  	private static final String ACTIVITY_BILLABLE						= "ACTIVITY_BILLABLE";
  	
  	private static final String COST_PRICE_ACTIVITY						= "COST_PRICE_ACTIVITY";
  	private static final String BILLING_PRICE_ACTIVITY					= "BILLING_PRICE_ACTIVITY";
  	private static final String COST_PRICE_TEAM_MEMBER					= "COST_PRICE_TEAM_MEMBER";
  	private static final String BILLING_PRICE_TEAM_MEMBER				= "BILLING_PRICE_TEAM_MEMBER";
  	private static final String OVERTIME_COST_PRICE_TEAM_MEMBER			= "OVERTIME_COST_PRICE_TEAM_MEMBER";
  	private static final String OVERTIME_BILLING_PRICE_TEAM_MEMBER		= "OVERTIME_BILLING_PRICE_TEAM_MEMBER";
  	private static final String COST_PRICE_PERSON						= "COST_PRICE_PERSON";
  	private static final String OVERTIME_COST_PRICE_PERSON				= "OVERTIME_COST_PRICE_PERSON";
  	private static final String ACTIVITY								= "ACTIVITY";
  	private static final String SAME_ACTIVITY							= "SAME_ACTIVITY";
  		
  	public RecordFormController(){
  		setCommandName("recordBean");
  		setCommandClass(Record.class);
  		setFormView(FORM_VIEW);
  		setSuccessView(SUCCESS_VIEW);
  	}
  	
  	
  	/**
  	 * Registering Custom Editors to this controller for 
  	 * better binding request parameters.
  	 * (More details on each registering)
  	 * 
  	 * @author coni
  	 */
  	@Override
  	protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
  		logger.debug("initBinder - START");
  		
  		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
  		binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(
  				sdf, true));
  
  		logger.debug("initBinder - END");
  	}
  	
  	@Override
  	protected Object formBackingObject(HttpServletRequest request) throws Exception {
  		logger.debug("formBackingObject - START");
  			
  		
  		// used as a container for info/error messages
  		ArrayList<String> errorMessages = new ArrayList<String>();		
  		Record record = null;
  		
  		try {
  			//check if i have to edit the record
  			if (ServletRequestUtils.getIntParameter(request, ID) != null && 
  					ServletRequestUtils.getStringParameter(request, IConstant.REQ_ACTION) != null &&
  					IConstant.CMD_GET.equals(ServletRequestUtils.getStringParameter(request, IConstant.REQ_ACTION))){
  				logger.debug("formBackingObject: GET");				
  				//get the record with the specified recordId
  				record = handleGet(ServletRequestUtils.getIntParameter(request, ID).intValue(), errorMessages, request);
  				if (record == null){
  					record = new Record();
  				}
  			} else if (ServletRequestUtils.getStringParameter(request, IConstant.REQ_ACTION) != null &&
  					IConstant.CMD_ADD.equals(ServletRequestUtils.getStringParameter(request, IConstant.REQ_ACTION))){
  				logger.debug("formBackingObject: ADD");
  				record = handleGetNew(request, errorMessages);
  			} else {
  				record = new Record();
  			}
  		} catch (Exception e){
  			logger.error("formBackingObject", e);
  			errorMessages.add(messageSource.getMessage(GET_ERROR, new Object[] {null, ControllerUtils.getInstance().getFormattedCurrentTime()}, RequestContextUtils.getLocale(request)));
  		}
  		
  		if (IConstant.CMD_ADD.equals(ServletRequestUtils.getStringParameter(request, IConstant.REQ_ACTION)) &&
  				request.getParameter("projectId") != null &&
  				request.getParameter("activityId") != null) {
  			record.setActivityId(ServletRequestUtils.getIntParameter(request, "activityId").intValue());
  			record.setProjectId(ServletRequestUtils.getIntParameter(request, "projectId").intValue());
  		}
  		
  		logger.debug("formBackingObject - END");
  		return record;
  	}
  	
  	@Override
  	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)	throws Exception {
  		logger.debug("onSubmit - START");
  		ModelAndView mav = new ModelAndView(IConstant.FORM_VIEW_MESSAGES);
  		Record record = (Record) command;
  		Locale locale = RequestContextUtils.getLocale(request);
  		ArrayList<String> errorMessages = new ArrayList<String>();
  		ArrayList<String> infoMessages = new ArrayList<String>();
  		ArrayList<String> warningMessages = new ArrayList<String>();
  		
  		//set the start date and end date for work hours and over time to null if not checked
  		if (!record.isWorkHoursRecord()) {
  			record.setStartTime(null);
  			record.setEndTime(null);
  			record.setBillable(new Character(' '));
  			
  		}
  		
  		if (!record.isOvertimeRecord()) {
  			record.setOverTimeStartTime(null);
  			record.setOverTimeEndTime(null);
  			record.setOverTimeBillable(null);
  		}
  		
  		// check if the record has a recordId
  		if (record.getRecordId() != -1){
  			// if I have recordId, it means that I have "update" action
  			logger.debug("onSubmit - handleUpdate");
  			mav =  handleUpdate(record, request, locale, errorMessages, infoMessages, warningMessages);
  		} else {
  			// if I don't have record, it means that I have "add" action
  			logger.debug("onSubmit - handleAdd");
  			mav =  handleAdd(record, request, locale, errorMessages, infoMessages, warningMessages);
  		}
  		
  		setErrors(request, errorMessages);
  		setMessages(request, infoMessages);
  		setWarnings(request, warningMessages);
  		
  		mav.addAllObjects(referenceData(request, record, errors));
  		logger.debug("onSubmit - END");
  		return mav;
  	}
  	
  	/**
  	 * Gets the new record, for the add action
  	 * 
  	 * @author Adelina
  	 * 
  	 * @param request
  	 * @param errorMessages
  	 * @return
  	 */
  	public Record handleGetNew(HttpServletRequest request, ArrayList<String> errorMessages) {
  		logger.debug("handleGetNew - START");
  		
  		Record record = new Record();
  		String billable = (String) request.getParameter("billable");
  		//if the billable param doesn't have a value, the default 'Y' value must be replaced with ' ' 
  		if (billable == null) {
  			record.setBillable(new Character(' '));
  		}
  		try{			
  			//setting the organizationId for the new record
  			Integer organizationId = (Integer) ControllerUtils.getInstance().getOrganisationIdFromSession(request);
  			if (organizationId != null){				
  				record.setOrganizationId(organizationId);
  				
  				// get the work program form organization
  				Calendar calendar = BLCalendar.getInstance().getCalendarByOrganization(organizationId);				
  				
  				String delimiter = ":";
  				Date start = new Date();
  				Date end = new Date();
  											
  				// start work hour and minutes
  				String startWork = calendar.getStartWork();				
  		    	String[] startTime = startWork.split(delimiter);
  				
  		    	String startWorkHour = ControllerUtils.getInstance().removeSpaces(startTime[0]);
  				String startWorkMinutes = startTime[1];
  
  				// end work hour and minutes					
  				String todayDate = ControllerUtils.getInstance().getTodayHoursAndMinutes(new GregorianCalendar());							
  				String[] endTime = todayDate.split(delimiter);
  				
  		    	String endWorkHour = endTime[0];
  				String endWorkMinutes = endTime[1];
  				
  				Date date = new Date();
  				
  				// get the years, months, days, hours, minutes and seconds by dates
  				SimpleDateFormat simpleYearformat=new SimpleDateFormat("yyyy");		
  				Integer year = Integer.valueOf(simpleYearformat.format(date));    		    	        	  
  		    	
  		      	SimpleDateFormat simpleMonthformat=new SimpleDateFormat("MM");
  		    	Integer month = Integer.valueOf(simpleMonthformat.format(date));		    	    	  
  		       	          	
  		    	SimpleDateFormat simpleDayformat=new SimpleDateFormat("dd");
  		    	Integer day = Integer.valueOf(simpleDayformat.format(date)); 
  		    	
  		    	String startDate = year.toString().concat("/").concat(month.toString()).concat("/").concat(day.toString()).concat(" ").concat(startWorkHour).concat(":").concat(startWorkMinutes);
  		    	String endDate = year.toString().concat("/").concat(month.toString()).concat("/").concat(day.toString()).concat(" ").concat(endWorkHour).concat(":").concat(endWorkMinutes);
  		    	
  		    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
  		    			   		    		
  	    		try{
  	        		start = sdf.parse(startDate);
  	        		end = sdf.parse(endDate);
  	        	} catch (ParseException e) {}
  	        		        	
  	        	if(Integer.parseInt(startWorkHour) < Integer.parseInt(endWorkHour) || ((Integer.parseInt(startWorkHour) == Integer.parseInt(endWorkHour)) && (Integer.parseInt(startWorkMinutes) <= Integer.parseInt(endWorkMinutes)))) {
  	        		//set the start time and end time
  		        	record.setStartTime(start);		        	
  	        	} 		        			        	       
  	        	record.setEndTime(end);
  			}
  			
  		} catch (BusinessException be) {
  			logger.error("", be);
  			errorMessages.add(messageSource.getMessage(GET_CALENDAR_ERROR, new Object[] {be.getCode(), ControllerUtils.getInstance().getFormattedCurrentTime()}, RequestContextUtils
  					.getLocale(request)));
  		} catch (Exception e){
  			logger.error("", e);
  			errorMessages.add(messageSource.getMessage(GENERAL_ERROR, new Object[] {null, ControllerUtils.getInstance().getFormattedCurrentTime()}, RequestContextUtils
  					.getLocale(request)));
  		}
  		logger.debug("handleGetNew - END");
  		return record;
  	}	
  	
  	/**
  	 * Gets a Record with all its components
  	 * 
  	 * @author Coni
  	 * @param recordId
  	 * @param errorMessages
  	 * @param request
  	 * @return
  	 */
  	public Record handleGet(int recordId, ArrayList<String> errorMessages, HttpServletRequest request) {
  		logger.debug("handleGet - START");
  		Record record = null;
  		try {
  			record = BLRecord.getInstance().getAll(recordId);					
  			UserAuth userAuth = (UserAuth) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  			if (record != null) {
  				if (record.getProjectDetails() != null) {
  					record.setProjectId(record.getProjectDetails().getProjectId());
  				}
  				if (record.getTeamMemberDetail() != null) {
  					record.setUserId(record.getTeamMemberDetail().getTeamMemberId());
  					record.setTeamMemberDetailId(record.getTeamMemberDetail().getTeamMemberDetailId());
  					TeamMember member = BLTeamMember.getInstance().getTeamMember(record.getTeamMemberDetail().getTeamMemberId(), false);
  					record.setRecordOwnerName(member.getFirstName().concat(" ").concat(member.getLastName()));
  				} else if (record.getPersonDetail() != null) {
  					record.setUserId(record.getPersonDetail().getPersonId());
  					record.setPersonDetailId(record.getPersonDetail().getPersonDetailId());
  					if (record.getPersonDetail().getPersonId() == userAuth.getPersonId()) {
  						record.setRecordOwnerName(userAuth.getFirstName().concat(" ").concat(userAuth.getLastName()));
  					} else {
  						String[] personIds = new String[1];
  						personIds[0] = String.valueOf(record.getPersonDetail().getPersonId());
  						List<UserSimple> users = BLUser.getInstance().getUsersByPersonId(personIds);
  						record.setRecordOwnerName(users.get(0).getFirstName().concat(" ").concat(users.get(0).getLastName()));
  					}
  					
  				}
  				
  				if (record.getTime() != null && record.getTime() != "") {
  					record.setWorkHoursRecord(true);
  				} else {
  					record.setWorkHoursRecord(false);
  				}
  				if (record.getOverTimeTime() != null && record.getOverTimeTime() != "") {
  					record.setOvertimeRecord(true);
  				} else {
  					record.setOvertimeRecord(false);
  				}
  				
  				if (record.getActivity() != null) {
  					record.setActivityId(record.getActivity().getActivityId());					
  					request.setAttribute(ACTIVITY_BILLABLE, record.getActivity().getBillable());					
  				}
  			}			
  		} catch (BusinessException be) {
  			logger.error("handleGet", be);
  			errorMessages.add(messageSource.getMessage(GET_ERROR, new Object[] {be.getCode(), ControllerUtils.getInstance().getFormattedCurrentTime()}, RequestContextUtils.getLocale(request)));
  		}
  		logger.debug("handleGet - START");
  		return record;
  	}
  	
  	/**
  	 * Updates the record with the specified id
  	 * 
  	 * @author Coni
  	 * @param record
  	 * @param request
  	 * @param locale
  	 * @param errorMessages
  	 * @param infoMessages
  	 * @return
  	 */
  	private ModelAndView handleUpdate(Record record, HttpServletRequest request, Locale locale, ArrayList<String> errorMessages, ArrayList<String> infoMessages, ArrayList<String> warningMessages){
  		logger.debug("handleUpdate - START");
  		ModelAndView mav = new ModelAndView(getFormView());
  		try {
  			
  			// the organization id from the session
  			Integer organizationId = (Integer) ControllerUtils.getInstance().getOrganisationIdFromSession(request);
  			
  			// the user that logs in
  			UserAuth userAuth = (UserAuth) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  			
  			//add the command object
  			mav.addObject(getCommandName(), record);
  			
  			// if the record is added for an activity that belongs directly to the organization
  			// the record is not billable
  			if(record.getProjectId() == -1) {
  				record.setBillable(IConstant.NOM_BILLABLE_NO);
  			}			
  			logger.debug("record = " + record);	
  									
  			// handles all the dependencies for the record
  			BLRecord.getInstance().handleAddDepedencies(record);			
  			
  			Record recordIdentical = null;
  			
  			// get the team member detail
  			Integer teamMemberDetailId = null;
  			Integer personDetailId = null;
  			if (record.getProjectId().equals(IConstant.NOM_RECORD_FORM_PROJECT_SELECT_ORG_OPTION)) {
  				logger.debug("record.getUserId = " + record.getUserId());
  				PersonDetail personDetail = BLPersonDetail.getInstance().getByPersonId(record.getUserId());
  				logger.debug("personDetail = " + personDetail);
  				personDetailId = personDetail.getPersonDetailId();
  			} else {
  				TeamMemberDetail teamMemberDetail = BLTeamMemberDetail.getInstance().getByTeamMemberId(record.getUserId());	
  				teamMemberDetailId = teamMemberDetail.getTeamMemberDetailId();				
  			}
  			
  			if((record.getStartTime() != null && record.getEndTime() != null) || (record.getOverTimeStartTime()!= null && record.getOverTimeEndTime() != null)) {
  				recordIdentical = BLRecord.getInstance().hasIdenticalRecordForPerson(record.getRecordId(), teamMemberDetailId, record.getActivityId(), record.getStartTime(), record.getEndTime(), record.getTime(), record.getOverTimeStartTime(), record.getOverTimeEndTime(), record.getOverTimeTime(), personDetailId);
  				logger.debug("record identical = " + recordIdentical);			
  			}
  			
  			String ownerName = null;
  			if(record.getRecordOwnerName() == "") {
  				ownerName = userAuth.getFirstName().concat(" ").concat(userAuth.getLastName());
  			} else {
  				ownerName = record.getRecordOwnerName();
  			}
  			
  			// if exists a record that has the same interval or an interleaved interval, give the user a message
  			// to select another activity for the same record
  			if(recordIdentical != null) {		
  				if(recordIdentical.getRecordId() > 0) {			
  					logger.debug("record identical = " + recordIdentical.getRecordId());	
  										
  					boolean time = false;			
  					boolean overtime = false;
  					
  					// if we have work hours
  					if(recordIdentical.getStartTime() != null && recordIdentical.getEndTime() != null) {
  						if(record.getStartTime() != null && record.getEndTime() != null) {
  							if(((record.getStartTime().after(recordIdentical.getStartTime()) || record.getStartTime().equals(recordIdentical.getStartTime())) && (record.getEndTime().before(recordIdentical.getEndTime()) || record.getEndTime().equals(recordIdentical.getEndTime()))) || 
  				    				(record.getStartTime().before(recordIdentical.getStartTime()) && record.getEndTime().after(recordIdentical.getStartTime())) ||
  				    				(record.getStartTime().before(recordIdentical.getEndTime()) && record.getEndTime().after(recordIdentical.getEndTime())) || 
  				    				((record.getStartTime().before(recordIdentical.getStartTime()) || record.getStartTime().equals(recordIdentical.getStartTime())) && (record.getEndTime().after(recordIdentical.getEndTime()) || record.getEndTime().equals(recordIdentical.getEndTime())))) {
  								if(ControllerUtils.getInstance().hasOverlap(record.getStartTime(), record.getEndTime(), record.getTime(), recordIdentical.getStartTime(), recordIdentical.getEndTime(), recordIdentical.getTime())) {
  									time = true;									
  								}
  							}
  						}
  						if(record.getOverTimeStartTime() != null && record.getOverTimeEndTime() != null) {
  							if(((record.getOverTimeStartTime().after(recordIdentical.getStartTime()) || record.getOverTimeStartTime().equals(recordIdentical.getStartTime())) && (record.getOverTimeEndTime().before(recordIdentical.getEndTime()) || record.getOverTimeEndTime().equals(recordIdentical.getEndTime()))) || 
  				    				(record.getOverTimeStartTime().before(recordIdentical.getStartTime()) && record.getOverTimeEndTime().after(recordIdentical.getStartTime())) ||
  				    				(record.getOverTimeStartTime().before(recordIdentical.getEndTime()) && record.getOverTimeEndTime().after(recordIdentical.getEndTime())) || 
  				    				((record.getOverTimeStartTime().before(recordIdentical.getStartTime()) || record.getOverTimeStartTime().equals(recordIdentical.getStartTime())) && (record.getOverTimeEndTime().after(recordIdentical.getEndTime()) || record.getOverTimeEndTime().equals(recordIdentical.getEndTime())))) {								
  								if(ControllerUtils.getInstance().hasOverlap(record.getOverTimeStartTime(), record.getOverTimeEndTime(), record.getOverTimeTime(), recordIdentical.getStartTime(), recordIdentical.getEndTime(), recordIdentical.getTime())) {
  									overtime = true;									
  								}
  							}
  						}
  						logger.debug("time = " + time + ", overtime = " + overtime);
  						if(overtime && time) {
  							warningMessages.add(messageSource.getMessage(EXISTS_IDENTICAL_RECORD_TTO, new Object[] {ownerName, BLActivity.getInstance().get(record.getActivityId()).getName(), recordIdentical.getStartTime(), recordIdentical.getEndTime(), recordIdentical.getRecordId()}, RequestContextUtils.getLocale(request)));
  						} else if(overtime) {
  							warningMessages.add(messageSource.getMessage(EXISTS_IDENTICAL_RECORD_TIME_OVERTIME, new Object[] {ownerName, BLActivity.getInstance().get(record.getActivityId()).getName(), recordIdentical.getStartTime(), recordIdentical.getEndTime(), recordIdentical.getRecordId()}, RequestContextUtils.getLocale(request)));
  						} else if(time){
  							warningMessages.add(messageSource.getMessage(EXISTS_IDENTICAL_RECORD_TIME, new Object[] {ownerName, BLActivity.getInstance().get(record.getActivityId()).getName(), recordIdentical.getStartTime(), recordIdentical.getEndTime(), recordIdentical.getRecordId()}, RequestContextUtils.getLocale(request)));
  						}
  					} else {  				
  						
  						// if we have overtime hours
  						if(recordIdentical.getOverTimeStartTime() != null && recordIdentical.getOverTimeEndTime() != null) {						
  							if(record.getOverTimeStartTime() != null && record.getOverTimeEndTime() != null) {
  								if(((record.getOverTimeStartTime().after(recordIdentical.getOverTimeStartTime()) || record.getOverTimeStartTime().equals(recordIdentical.getOverTimeStartTime())) && (record.getOverTimeEndTime().before(recordIdentical.getOverTimeEndTime()) || record.getOverTimeEndTime().equals(recordIdentical.getOverTimeEndTime()))) || 
  					    				(record.getOverTimeStartTime().before(recordIdentical.getOverTimeStartTime()) && record.getOverTimeEndTime().after(recordIdentical.getOverTimeStartTime())) ||
  					    				(record.getOverTimeStartTime().before(recordIdentical.getOverTimeEndTime()) && record.getOverTimeEndTime().after(recordIdentical.getOverTimeEndTime())) || 
  					    				((record.getOverTimeStartTime().before(recordIdentical.getOverTimeStartTime()) || record.getOverTimeStartTime().equals(recordIdentical.getOverTimeStartTime())) && (record.getOverTimeEndTime().after(recordIdentical.getOverTimeEndTime()) || record.getOverTimeEndTime().equals(recordIdentical.getOverTimeEndTime())))) {								
  									if(ControllerUtils.getInstance().hasOverlap(record.getOverTimeStartTime(), record.getOverTimeEndTime(), record.getOverTimeTime(), recordIdentical.getOverTimeStartTime(), recordIdentical.getOverTimeEndTime(), recordIdentical.getOverTimeTime())) {
  										overtime = true;									
  									}
  								}
  							} 
  							if(record.getStartTime() != null && record.getEndTime() != null) {
  								if(((record.getStartTime().after(recordIdentical.getOverTimeStartTime()) || record.getStartTime().equals(recordIdentical.getOverTimeStartTime())) && (record.getEndTime().before(recordIdentical.getOverTimeEndTime()) || record.getEndTime().equals(recordIdentical.getOverTimeEndTime()))) || 
  						    				(record.getStartTime().before(recordIdentical.getOverTimeStartTime()) && record.getEndTime().after(recordIdentical.getOverTimeStartTime())) ||
  						    				(record.getStartTime().before(recordIdentical.getOverTimeEndTime()) && record.getEndTime().after(recordIdentical.getOverTimeEndTime())) || 
  						    				((record.getStartTime().before(recordIdentical.getOverTimeStartTime()) || record.getStartTime().equals(recordIdentical.getOverTimeStartTime())) && (record.getEndTime().after(recordIdentical.getOverTimeEndTime()) || record.getEndTime().equals(recordIdentical.getOverTimeEndTime())))) {									
  									if(ControllerUtils.getInstance().hasOverlap(record.getStartTime(), record.getEndTime(), record.getTime(), recordIdentical.getOverTimeStartTime(), recordIdentical.getOverTimeEndTime(), recordIdentical.getOverTimeTime())) {	
  										time = true;									
  									}
  								}
  							}
  							logger.debug("time = " + time + ", overtime = " + overtime);
  							
  