public AbsencePlanningResponse SaveAbsencePlanning(AbsencePlanningResponse response) { // diction id of empluyees which absences or holidays number changed Dictionary <long, object> d_ids = new Dictionary <long, object>(); if (response.DeletedIds != null) { List <long> ids = new List <long>(response.DeletedIds); List <AbsenceTimePlanning> listAbsences = AbsenceTimePlanningService.FindByIDList(ids); if (listAbsences != null) { foreach (AbsenceTimePlanning a in listAbsences) { d_ids[a.EmployeeID] = a; } } AbsenceTimePlanningService.DeleteList(listAbsences);// DeleteListByID(ids); } if (response.ModifiedEntity != null) { List <EmployeeHolidaysInfo> lst = new List <EmployeeHolidaysInfo>(response.ModifiedEntity); EmployeeHolidaysInfoService.SaveOrUpdateList(lst); foreach (EmployeeHolidaysInfo o in lst) { d_ids[o.EmployeeID] = o; } } if (response.NewAbsences != null) { foreach (AbsenceTimeRange a in response.NewAbsences) { Debug.Assert(a.EmployeeID > 0); Debug.Assert(a.AbsenceID > 0); Debug.Assert(a.ID <= 0); d_ids[a.EmployeeID] = a; ClearEmployeePlanningTime(a.EmployeeID, a.Date, a.Date); AbsenceTimePlanning entity = new AbsenceTimePlanning(a.Begin, a.End, a.Time, a.AbsenceID, a.EmployeeID); entity.ID = 0; entity.Date = a.Date; AbsenceTimePlanningService.SaveOrUpdate(entity); a.ID = entity.ID; } } if (d_ids.Count > 0) { long[] ids = new long[d_ids.Count]; d_ids.Keys.CopyTo(ids, 0); ExEmployeeHolidays.CalculateAndUpdate(ids, response.Year); } return(response); }
public void SavePlanning2(long storeid, DateTime aBegin, DateTime aEnd, List <EmployeePlanningWeek> lstWeeks) { #region validate date Debug.Assert(aBegin < aEnd); Debug.Assert(aBegin.DayOfWeek == DayOfWeek.Monday); Debug.Assert(aEnd.DayOfWeek == DayOfWeek.Sunday); if (aEnd < DateTime.Today) { if (Log.IsWarnEnabled) { User user = ServerEnvironment.AuthorizationService.GetCurrentUser(); string username = String.Empty; if (user != null) { username = user.LoginName; } Log.Warn(string.Format("User - '{0}', try save planning date in date({1}) with input data {2}-{3} storeid={4}", new object[] { username, DateTime.Today, aBegin, aEnd, storeid })); } return; } #endregion try { HolidayCalculator calculatorHolidays = new HolidayCalculator(); calculatorHolidays.Calculate(storeid, aBegin, lstWeeks); WorkingTimePlanningService.SetWeekTimePlanning(lstWeeks); AbsenceTimePlanningService.SetWeekTimePlanning(lstWeeks); StoreWeekCalculater calculator = new StoreWeekCalculater(storeid, aBegin, aEnd, this); calculator.Process(); if (lstWeeks != null) { long[] ids = PlanningWeekProcessor.ListToEmployeeIds(lstWeeks); ExEmployeeHolidays.CalculateAndUpdate(ids, DateTimeHelper.GetYearByDate(aBegin)); } _storeService.LastEmployeeWeekTimePlanningUpdate(storeid, aBegin); } catch (EntityException) { throw; } catch (Exception ex) { CheckForDBValidationException(null, ex); throw new SaveException(ex); } }
public List <EmployeeHolidaysInfo> MoveSpareHolidaysToYear(long storeid, int year) { if (Log.IsInfoEnabled) { try { Store store = ServerEnvironment.StoreService.FindById(storeid); Log.Info(String.Format("{0} take spare holidays for store({2}) from previous year(current year={1}).", new object[] { ServerEnvironment.LogUserPrefix, year, (store != null ? store.Name : "Unknown") })); } catch {} } return(ExEmployeeHolidays.BuildOldHolidaysFromPreviousYear(storeid, year)); }
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 void SaveActualEmployeeTimeRange(long storeid, DateTime aBegin, DateTime aEnd, long[] employeeids, List <EmployeeTimeRange> lst) { #region validate date Debug.Assert(aBegin < aEnd); Debug.Assert(aBegin.DayOfWeek == DayOfWeek.Monday); Debug.Assert(aEnd.DayOfWeek == DayOfWeek.Sunday); if (aBegin >= DateTime.Today) { if (Log.IsWarnEnabled) { User user = ServerEnvironment.AuthorizationService.GetCurrentUser(); string username = String.Empty; if (user != null) { username = user.LoginName; } Log.Warn(string.Format("User - '{0}', try save recording date in date({1}) with input data {2}-{3} storeid={4}", new object[] { username, DateTime.Today, aBegin, aEnd, storeid })); } return; } #endregion try { if (employeeids == null || employeeids.Length == 0) { return; } if (lst != null) { lst.Sort(); } List <EmployeeTimeRange> lstWorks = new List <EmployeeTimeRange>(); List <EmployeeTimeRange> lstAbsences = new List <EmployeeTimeRange>(); EmployeeTimeRangeHelper.GetWorkingAndAbsenceTimeRange(lst, lstWorks, lstAbsences); (WorkingTimeRecordingService as IServerEmployeeTimeRangeService).SaveEmployeeTimeRanges(employeeids, lstWorks, aBegin, aEnd); (AbsenceTimeRecordingService as IServerEmployeeTimeRangeService).SaveEmployeeTimeRanges(employeeids, lstAbsences, aBegin, aEnd); SrvRecordingStoreWeekCalculator calculator = new SrvRecordingStoreWeekCalculator(storeid, aBegin, aEnd, this); calculator.Process(); _storeService.LastEmployeeWeekTimeRecordingUpdate(storeid, aBegin); ExEmployeeHolidays.CalculateAndUpdate(employeeids, DateTimeHelper.GetYearByDate(aBegin)); } catch (EntityException) { throw; } catch (Exception ex) { CheckForDBValidationException(null, ex); throw new SaveException(ex); } }