public virtual bool IsEqualByData(EmployeeHolidaysInfo entity) { if (entity == null) { return(false); } return(this.PlannedHolidays == entity.PlannedHolidays && this.TakenHolidays == entity.TakenHolidays && this.SpareHolidaysExc == entity.SpareHolidaysExc && this.SpareHolidaysInc == entity.SpareHolidaysInc && this.EmployeeID == entity.EmployeeID && this.OldHolidays == entity.OldHolidays && this.NewHolidays == entity.NewHolidays && this.Year == entity.Year && this.UsedHolidays == entity.UsedHolidays); }
public static List<EmployeeHolidaysInfo> BuildOldHolidaysFromPreviousYear(long storeid, int year) { ILog log = LogManager.GetLogger("ExEmployeeHolidays"); if (year - 1 < DateTimeSql.SmallDatetimeMin.Year) return null; DateTime begin_year_date = DateTimeHelper.GetBeginYearDate(year); DateTime end_year_date = DateTimeHelper.GetEndYearDate(year); if (log.IsDebugEnabled) log.Debug(string.Format("Begin move spare(exc) holidays from {0} to {1} years for store {2}", year-1, year, storeid)); EmployeeService service = ServerEnvironment.EmployeeService as EmployeeService; List<Employee> employeesList = service.EmployeeDao.GetStoreEmployeesHaveContracts(storeid, begin_year_date, end_year_date); if (log.IsDebugEnabled) { int iCount = (employeesList != null)? employeesList.Count: 0; log.Debug(string.Format("Loaded {0} employees for year {1}", iCount, year)); } if (employeesList == null || employeesList.Count == 0) return null; List<EmployeeHolidaysInfo> listOldHolidaysInfo = GetAllByStore(storeid, year - 1); if (listOldHolidaysInfo == null || listOldHolidaysInfo.Count == 0) return null; List<EmployeeHolidaysInfo> listCurrentHolidaysInfo = GetAllByStore(storeid, year); Dictionary<long, EmployeeHolidaysInfo> diction_old_holidays = ConvertToDictionary(listOldHolidaysInfo); Dictionary<long, EmployeeHolidaysInfo> diction_current_holidays = ConvertToDictionary(listCurrentHolidaysInfo); if (log.IsDebugEnabled) { int iCount = (listCurrentHolidaysInfo != null) ? listCurrentHolidaysInfo.Count : 0; int iCount2 = (listOldHolidaysInfo != null) ? listOldHolidaysInfo.Count : 0; log.Debug(string.Format("Loaded previous entities {0} and current entities {1} ", iCount2, iCount)); } EmployeeHolidaysInfo old_holiday_info = null; EmployeeHolidaysInfo current_holiday_info = null; foreach (Employee employee in employeesList) { old_holiday_info = current_holiday_info = null; diction_old_holidays.TryGetValue(employee.ID, out old_holiday_info); diction_current_holidays.TryGetValue(employee.ID, out current_holiday_info); if (old_holiday_info != null) { if (current_holiday_info != null) { bool modified = current_holiday_info.OldHolidays != old_holiday_info.SpareHolidaysExc; current_holiday_info.OldHolidays = old_holiday_info.SpareHolidaysExc; modified |= current_holiday_info.CalculateSpareHolidays(); if (modified) { Srv.SaveOrUpdate(current_holiday_info); } } else { current_holiday_info = new EmployeeHolidaysInfo(employee.ID, (short)year); current_holiday_info.OldHolidays = old_holiday_info.SpareHolidaysExc; EmlpoyeeHolidaysSumDays sums_by_year = GetHolidaysSumDays(employee.ID, begin_year_date, end_year_date); if (sums_by_year != null) { current_holiday_info.TakenHolidays = sums_by_year.TimeRecording; current_holiday_info.PlannedHolidays = sums_by_year.TimePlanning; } current_holiday_info.CalculateSpareHolidays(); Srv.SaveOrUpdate(current_holiday_info); if (log.IsDebugEnabled) { log.Debug(string.Format("Create entity from employee ID={0} and Name = {1}; Year={2} ", employee.ID, employee.FullName, year)); } } } } listCurrentHolidaysInfo = GetAllByStore(storeid, year); return listCurrentHolidaysInfo; }
public EmployeeHolidaysInfo UpdateFromEmployee(Employee employee) { if (employee == null) return null; if (employee.IsNew) return null; if (EmployeeId != employee.ID) return null; EmployeeHolidaysInfo entity = GetEntity(EmployeeId, Year); if (entity == null) { entity = new EmployeeHolidaysInfo(); } entity.EmployeeID = employee.ID; entity.NewHolidays = employee.NewHolidays; entity.OldHolidays = employee.OldHolidays; entity.UsedHolidays = employee.UsedHolidays; entity.Year = (short)Year; entity.CalculateSpareHolidays(); Srv.SaveOrUpdate(entity); return entity; }
public EmployeeHolidaysInfo CalculateAndUpdate() { EmployeeHolidaysInfo entity = GetEntity(EmployeeId, Year); if (entity == null) { entity = new EmployeeHolidaysInfo(); entity.Year = (short)Year; entity.EmployeeID = EmployeeId; entity.NewHolidays = entity.OldHolidays = 0; entity.PlannedHolidays = entity.TakenHolidays = 0; entity.SpareHolidaysExc = entity.SpareHolidaysInc = 0; entity.UsedHolidays = 0; } ExEmployeeHolidays.CalculateAndUpdate(entity); Debug.Assert(!entity.IsNew); return entity; //int TodayYear = DateTimeHelper.GetYearByDate(DateTime.Today); //DateTime begin_year_date = DateTimeHelper.GetBeginYearDate(Year); //DateTime end_year_date = DateTimeHelper.GetEndYearDate(Year); //StoreService storeservice = ServerEnvironment.StoreService as StoreService; //EmlpoyeeHolidaysSumDays sums_by_year = // storeservice.EmlpoyeeHolidaysSumInfoByEmployeeIDGet(EmployeeId, begin_year_date, end_year_date, DateTime.Today); //EmployeeHolidaysInfo entity = Service.GetEntity(EmployeeId, Year); //if (entity == null) //{ // entity = new EmployeeHolidaysInfo(); // entity.Year = (short)Year; // entity.EmployeeID = EmployeeId; // entity.NewHolidays = entity.OldHolidays = 0; // entity.PlannedHolidays = entity.TakenHolidays = 0; // entity.SpareHolidaysExc = entity.SpareHolidaysInc = 0; //} //if (sums_by_year != null) //{ // entity.TakenHolidays = Math.Round(sums_by_year.TimeRecording / 1440, 2); // entity.PlannedHolidays = Math.Round(sums_by_year.TimePlanning / 1440, 2); //} //Service.SaveOrUpdate(entity); //return entity; }
// After dayly import austrian employees - recalculate holidays // Attention: list_employees - must contain only employees which have valid contract(per year) public static void UpdateSpareHolidaysExc_Austria(List<Employee> list_employees, long[] ids, int year) { ILog log = LogManager.GetLogger(typeof(ExEmployeeHolidays)); if (ids == null || ids.Length == 0) return; if (list_employees == null || list_employees.Count == 0) return; List<EmployeeHolidaysInfo> list_entities = GetAllByEmployees(ids, year); Dictionary<long, EmployeeHolidaysInfo> diction_entities = ConvertToDictionary(list_entities); EmployeeHolidaysInfo entity = null; foreach (Employee employee in list_employees) { if (log.IsDebugEnabled) log.Debug(employee.ID.ToString () + " " + employee.FullName + " AvailableHolidays=" + employee.AvailableHolidays.ToString ()); entity = null; if (!diction_entities.TryGetValue(employee.ID, out entity)) { if (log.IsDebugEnabled) log.Debug(String.Format ("Create new holidays entity: EmployeeID={0}, Name={1}, Year={2}", employee.ID,employee.FullName, year)); entity = new EmployeeHolidaysInfo((short)year, 0m, 0m, 0m, employee.ID); } bool bModified = entity.IsNew || (entity.SpareHolidaysExc != employee.AvailableHolidays); entity.SpareHolidaysExc = employee.AvailableHolidays; Srv.SaveOrUpdate(entity); CalculateAndUpdate(entity, true); if (log.IsDebugEnabled) log.Debug(String.Format("holidays entity: EmployeeID={0}, Name={1}, Year={2}, TakenHoliday={3}, PlannedHolidays={4}, SpareExc={5}", new object[] { employee.ID, employee.FullName, year,entity.TakenHolidays,entity.PlannedHolidays,entity.SpareHolidaysExc})); } }
public static EmployeeHolidaysInfo UpdateSpareHolidaysExc_Austria(EmployeeHolidaysInfo entity, double spare_holidays) { if (entity == null) throw new ArgumentNullException(); decimal new_spare_exc = Convert.ToDecimal(spare_holidays); decimal old_spare_exc = entity.SpareHolidaysExc; bool bModified = entity.IsNew || (old_spare_exc != new_spare_exc); entity.SpareHolidaysExc = new_spare_exc; bModified |= entity.CalculateSpareHolidays_Austria(); if (bModified) Srv.SaveOrUpdate(entity); return entity; }
public static EmployeeHolidaysInfo UpdateSpareHolidaysExc_Austria(long emplid, int year, double spare_holidays) { EmployeeHolidaysInfo entity = GetEntity(emplid, year); if (entity == null) { entity = new EmployeeHolidaysInfo((short)year, 0m, 0m, 0m, emplid); } return UpdateSpareHolidaysExc_Austria(entity, spare_holidays); }
public static EmployeeHolidaysInfo UpdateNewOldHolidays(EmployeeHolidaysInfo entity, double old_holidays, double new_holidays) { if (entity == null) throw new ArgumentNullException(); bool bModified = entity.IsNew ||entity.OldHolidays != Convert.ToDecimal(old_holidays) || entity.NewHolidays != Convert.ToDecimal(new_holidays); entity.OldHolidays = Convert.ToDecimal(old_holidays); entity.NewHolidays = Convert.ToDecimal(new_holidays); if (entity.CalculateSpareHolidays()) Srv.SaveOrUpdate(entity); return entity; }
public static EmployeeHolidaysInfo UpdateNewOldHolidays(long emplid, int year, double old_holidays, double new_holidays) { EmployeeHolidaysInfo entity = GetEntity(emplid, year); if (entity == null) { entity = new EmployeeHolidaysInfo((short)year, 0m,0m,0m,emplid); } return UpdateNewOldHolidays(entity, old_holidays, new_holidays); }
public static long[] ExtractEmployeesId(EmployeeHolidaysInfo[] list) { if (list == null) return null; return ExtractEmployeesId(new List<EmployeeHolidaysInfo>(list)); }
public static EmployeeHolidaysInfo CalculateAndUpdate(EmployeeHolidaysInfo entity, bool bAustria) { Debug.Assert(entity != null); if (entity == null) return null; Debug.WriteLine("Begin calculate: " + entity.ToString()); int TodayYear = DateTimeHelper.GetYearByDate(DateTime.Today); DateTime begin_year_date = DateTimeHelper.GetBeginYearDate(entity.Year); DateTime end_year_date = DateTimeHelper.GetEndYearDate(entity.Year); StoreService storeservice = ServerEnvironment.StoreService as StoreService; EmlpoyeeHolidaysSumDays sums_by_year = storeservice.EmlpoyeeHolidaysSumInfoByEmployeeIDGet(entity.EmployeeID, begin_year_date, end_year_date, DateTime.Today); bool bModified = entity.IsNew; if (sums_by_year != null) { //decimal taken = Math.Round(sums_by_year.TimeRecording / 1440, 2); //decimal used = Math.Round(sums_by_year.TimePlanning / 1440, 2); decimal taken = Math.Round(sums_by_year.TimeRecording, 2); decimal used = Math.Round(sums_by_year.TimePlanning, 2); bModified |= (taken != entity.TakenHolidays) || (used != entity.PlannedHolidays); entity.TakenHolidays = taken; entity.PlannedHolidays = used; } if (bAustria ) bModified |= entity.CalculateSpareHolidays_Austria(); else bModified |= entity.CalculateSpareHolidays(); //Debug.Assert(entity.IsNew == bModified); if (bModified) { Debug.WriteLine("Entity was changed : " + entity.ToString()); Srv.SaveOrUpdate(entity); } Debug.WriteLine("End calculate: " + entity.ToString()); return entity; }
public static EmployeeHolidaysInfo CalculateAndUpdate(EmployeeHolidaysInfo entity) { return CalculateAndUpdate(entity, false); }
public AbsencePlanningQuery GetAllAbsencePlanning(long storeID, long countryID, int year, DateTime today) { int TodayYear = DateTimeHelper.GetYearByDate(DateTime.Today); bool isAustria = countryID == _countryService.AustriaCountryID; DateTime begin, end; begin = DateTimeHelper.GetBeginYearDate(year); end = DateTimeHelper.GetEndYearDate(year); DateTime dateToday = DateTime.Today; AbsencePlanningQuery result = new AbsencePlanningQuery(); List<long> employee_ids = new List<long>(); result.Year = year; result.StoreID = storeID; // need remove - once per country need load result.Absences = _absenceService.GetCountryAbsences(countryID); result.AvgDaysPerWeek = _countryService.AvgWorkingDaysInWeekService .GetAvgWorkingDaysInWeek(countryID, year); result.StoreDays = _storeService.GetStoreDays(storeID, begin, end); result.LongabsencesEntities = _employeeService.LongTimeAbsenceService.FindAllByCountry(countryID); EmployeeService service = _employeeService as EmployeeService; List<Employee> employees = service.EmployeeDao.GetStoreEmployeesHaveContracts(storeID, begin, end); long[] ids_employee = null; if (employees != null && employees.Count > 0) { foreach (Employee empl in employees) employee_ids.Add(empl.ID); ids_employee = employee_ids.ToArray(); EmployeeContractService contract_service = ServerEnvironment.EmployeeContractService as EmployeeContractService; result.Contracts = contract_service.GetEmployeeContractsByStore(storeID, begin, end); EmployeeRelationService relation_service = _employeeService.EmployeeRelationService as EmployeeRelationService; result.Relations = relation_service.GetEmployeeRelationByMainStore(storeID, begin, end); result.Longabsences = _employeeLongTimeAbsenceService.GetEmployeesHasLongTimeAbsence(storeID, begin, end); //Debug.Assert(result.Contracts != null && result.Contracts.Count >= employees.Count); //Debug.Assert(result.Relations != null && result.Relations.Count >= employees.Count); if (dateToday < begin) { result.Plannings = _absenceTimePlanningService .GetAbsenceTimePlanningsByEmployeeIds(ids_employee, begin, end); } else if (dateToday > end) { result.Recordings = _absenceTimeRecordingService .GetAbsenceTimeRecordingsByEmployeeIds(ids_employee, begin, end); } else { result.Plannings = _absenceTimePlanningService .GetAbsenceTimePlanningsByEmployeeIds(ids_employee, dateToday, end); result.Recordings = _absenceTimeRecordingService .GetAbsenceTimeRecordingsByEmployeeIds(ids_employee, begin, dateToday.AddDays(-1)); } List<EmployeeHolidaysInfo> holidays = ExEmployeeHolidays.GetAllByStore(storeID, year); Dictionary<long, EmployeeHolidaysInfo> hash = new Dictionary<long, EmployeeHolidaysInfo>(); hash = EmployeeHolidaysInfo.BuildDiction(holidays); BzEmployeeHoliday bz_entity = null; EmployeeHolidaysInfo entity = null; foreach (Employee empl in employees) { if (result._holidays == null) result._holidays = new List<BzEmployeeHoliday>(); if (!hash.TryGetValue(empl.ID, out entity)) { entity = new EmployeeHolidaysInfo((short)year, 0, 0, 0, empl.ID); } bz_entity = new BzEmployeeHoliday(entity, empl.FullName, empl.MainStoreID, empl.OrderHwgrID); bz_entity.IsAustria = isAustria; if (isAustria && year == TodayYear) bz_entity.AvailableHolidays = Convert.ToDouble(empl.AvailableHolidays); result._holidays.Add(bz_entity); } } return result; }
public virtual bool IsEqualByData(EmployeeHolidaysInfo entity) { if (entity == null) return false; return this.PlannedHolidays == entity.PlannedHolidays && this.TakenHolidays == entity.TakenHolidays && this.SpareHolidaysExc == entity.SpareHolidaysExc && this.SpareHolidaysInc == entity.SpareHolidaysInc && this.EmployeeID == entity.EmployeeID && this.OldHolidays == entity.OldHolidays && this.NewHolidays == entity.NewHolidays && this.Year == entity.Year && this.UsedHolidays == entity.UsedHolidays; }