All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.spin.tar.model.MHRShiftIncidence Maven / Gradle / Ivy

There is a newer version: shw-air-terminal-vertical-1.0.57
Show newest version
/**************************************************************************************
 * Product: Adempiere ERP & CRM Smart Business Solution                               *
 * This program is free software; you can redistribute it and/or modify it    		  *
 * under the terms version 2 or later of the GNU General Public License as published  *
 * by the Free Software Foundation. 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 General Public License for more details.                               *
 * You should have received a copy of the GNU General Public License along            *
 * with this program; if not, printLine to the Free Software Foundation, Inc.,        *
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                             *
 * For the text or an alternative of this public license, you may reach us            *
 * Copyright (C) 2012-2018 E.R.P. Consultores y Asociados, S.A. All Rights Reserved.  *
 * Contributor: Yamel Senih [email protected]                                          *
 * See: www.erpya.com                                                                 *
 *************************************************************************************/
package org.spin.tar.model;

import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Properties;

import org.adempiere.core.domains.models.I_HR_ShiftIncidence;
import org.adempiere.core.domains.models.X_HR_ShiftIncidence;
import org.compiere.model.Query;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.compiere.util.TimeUtil;
import org.compiere.util.Util;

/**
 * 	Class added for handle shift incidence
 * 	@author Yamel Senih, [email protected], ERPCyA http://www.erpcya.com
 *		 shiftIncidenceList = shiftIncidenceListCache.get(key);
		if(requery
				|| shiftIncidenceList == null) {
			shiftIncidenceList = new Query(ctx, I_HR_ShiftIncidence.Table_Name, "HR_WorkShift_ID = ?", null)
					.setParameters(workShiftId)
					.list();
			if(shiftIncidenceList != null) {
				shiftIncidenceListCache.put(key, shiftIncidenceList);
			}
		}
		//	Default return
		return shiftIncidenceList;
	}
	
	/**
	 * Get Shift Incidence List
	 * @param eventType
	 * @param attendanceTime
	 * @return
	 */
	public static List getShiftIncidenceList(Properties ctx, int workShiftId, String eventType, Timestamp attendanceTime) {
		String keyPrefix = workShiftId + "|";
		//	Validate
		if(attendanceTime == null
				|| Util.isEmpty(eventType)) {
			return new ArrayList();
		}
		//	Get
		List shiftIncidenceList = shiftIncidenceForDaysCache.get(keyPrefix + eventType + TimeUtil.getDayOfWeek(attendanceTime));
		if(shiftIncidenceList != null) {
			return shiftIncidenceList;
		}
		//	Get reload false
		shiftIncidenceList = getShiftIncidenceList(ctx, workShiftId, false);
		String entrance = X_HR_ShiftIncidence.EVENTTYPE_Entrance;
		String egress = X_HR_ShiftIncidence.EVENTTYPE_Egress;
		String attendance = X_HR_ShiftIncidence.EVENTTYPE_Attendance;
		String leave = X_HR_ShiftIncidence.EVENTTYPE_Leave;
		//	Load Hash
		if(shiftIncidenceList != null) {
			//	Sunday
			shiftIncidenceForDaysCache.put(keyPrefix + entrance + Calendar.SUNDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + egress + Calendar.SUNDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + attendance + Calendar.SUNDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + leave + Calendar.SUNDAY, new ArrayList());
			//	Monday
			shiftIncidenceForDaysCache.put(keyPrefix + entrance + Calendar.MONDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + egress + Calendar.MONDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + attendance + Calendar.MONDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + leave + Calendar.MONDAY, new ArrayList());
			//	Tuesday
			shiftIncidenceForDaysCache.put(keyPrefix + entrance + Calendar.TUESDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + egress + Calendar.TUESDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + attendance + Calendar.TUESDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + leave + Calendar.TUESDAY, new ArrayList());
			//	Wednesday
			shiftIncidenceForDaysCache.put(keyPrefix + entrance + Calendar.WEDNESDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + egress + Calendar.WEDNESDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + attendance + Calendar.WEDNESDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + leave + Calendar.WEDNESDAY, new ArrayList());
			//	Thursday
			shiftIncidenceForDaysCache.put(keyPrefix + entrance + Calendar.THURSDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + egress + Calendar.THURSDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + attendance + Calendar.THURSDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + leave + Calendar.THURSDAY, new ArrayList());
			//	Friday
			shiftIncidenceForDaysCache.put(keyPrefix + entrance + Calendar.FRIDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + egress + Calendar.FRIDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + attendance + Calendar.FRIDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + leave + Calendar.FRIDAY, new ArrayList());
			//	Saturday
			shiftIncidenceForDaysCache.put(keyPrefix + entrance + Calendar.SATURDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + egress + Calendar.SATURDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + attendance + Calendar.SATURDAY, new ArrayList());
			shiftIncidenceForDaysCache.put(keyPrefix + leave + Calendar.SATURDAY, new ArrayList());
			//	Add
			for(MHRShiftIncidence shiftIncidence : shiftIncidenceList) {
				if(!shiftIncidence.isOnSunday()
						&& !shiftIncidence.isOnMonday()
						&& !shiftIncidence.isOnTuesday()
						&& !shiftIncidence.isOnWednesday()
						&& !shiftIncidence.isOnThursday()
						&& !shiftIncidence.isOnFriday()
						&& !shiftIncidence.isOnSaturday()) {
					//	Sunday
					shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.SUNDAY).add(shiftIncidence);
					//	Monday
					shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.MONDAY).add(shiftIncidence);
					//	Tuesday
					shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.TUESDAY).add(shiftIncidence);
					//	Wednesday
					shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.WEDNESDAY).add(shiftIncidence);
					//	Thursday
					shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.THURSDAY).add(shiftIncidence);
					//	Friday
					shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.FRIDAY).add(shiftIncidence);
					//	Saturday
					shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.SATURDAY).add(shiftIncidence);
				} else {
					//	Sunday
					if(shiftIncidence.isOnSunday()) {
						shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.SUNDAY).add(shiftIncidence);
					}
					//	Monday
					if(shiftIncidence.isOnMonday()) {
						shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.MONDAY).add(shiftIncidence);
					}
					//	Tuesday
					if(shiftIncidence.isOnTuesday()) {
						shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.TUESDAY).add(shiftIncidence);
					}
					//	Wednesday
					if(shiftIncidence.isOnWednesday()) {
						shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.WEDNESDAY).add(shiftIncidence);
					}
					//	Thursday
					if(shiftIncidence.isOnThursday()) {
						shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.THURSDAY).add(shiftIncidence);
					}
					//	Friday
					if(shiftIncidence.isOnFriday()) {
						shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.FRIDAY).add(shiftIncidence);
					}
					//	Saturday
					if(shiftIncidence.isOnSaturday()) {
						shiftIncidenceForDaysCache.get(keyPrefix + shiftIncidence.getEventType() + Calendar.SATURDAY).add(shiftIncidence);
					}
				}
			}	
		}
		//	Get
		shiftIncidenceList = shiftIncidenceForDaysCache.get(keyPrefix + eventType + TimeUtil.getDayOfWeek(attendanceTime));
		if(shiftIncidenceList == null) {
			return new ArrayList();
		}
		//	Return
		return shiftIncidenceList;
	}
	
	@Override
	public String toString() {
		return "MHRShiftIncidence [getBeginningTime()=" + getBeginningTime() + ", getDescription()=" + getDescription()
				+ ", getEventType()=" + getEventType() + ", getHR_Concept_ID()=" + getHR_Concept_ID()
				+ ", isOnFriday()=" + isOnFriday() + ", isOnMonday()=" + isOnMonday() + ", isOnSaturday()="
				+ isOnSaturday() + ", isOnSunday()=" + isOnSunday() + ", isOnThursday()=" + isOnThursday()
				+ ", isOnTuesday()=" + isOnTuesday() + ", isOnWednesday()=" + isOnWednesday() + ", getTimeFrom()="
				+ getTimeFrom() + ", getTimeTo()=" + getTimeTo() + ", getTimeUnit()=" + getTimeUnit() + "]";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy