protected virtual void DoDeleteEntity(EmployeeWeekTimePlanning entity) { if (entity.IsNew) { return; } ServerEnvironment.EmployeeWeekTimePlanningService.Delete(entity); }
protected virtual void _UpdateSaldo(EmployeeWeekTimePlanning entity, int lastSaldo, bool allin) { Debug.Assert(entity != null); if (entity != null) { entity.AllIn = allin; entity.CalculateSaldo(lastSaldo); } }
public virtual void UpdateSaldo(long emplid, DateTime date, int lastSaldo, bool allin) { EmployeeWeekTimePlanning entity = GetByDate(emplid, date); if (entity != null) { _UpdateSaldo(entity, lastSaldo, allin); } }
protected virtual void DoUpdateEntity(EmployeeWeekTimePlanning entity) { if (entity.IsNew) { ServerEnvironment.EmployeeWeekTimePlanningService.Save(entity); } else { ServerEnvironment.EmployeeWeekTimePlanningService.Update(entity); } //ServerEnvironment.EmployeeWeekTimePlanningService.SaveOrUpdate(entity); }
public int?GetEmployeeLastVerifiedSaldo(long employeeid, DateTime currentMonday) { EmployeeWeekTimeRecording entity = (EmployeeWeekTimeRecording)HibernateTemplate.Execute( delegate(ISession session) { return(session.CreateCriteria(typeof(EmployeeWeekTimeRecording)) .Add(Expression.Eq("EmployeeID", employeeid)) .Add(Expression.Lt("WeekBegin", currentMonday)) .AddOrder(Order.Desc("WeekBegin")) .SetMaxResults(1) .UniqueResult <EmployeeWeekTimeRecording>()); } ); EmployeeWeekTimePlanning entity2 = (EmployeeWeekTimePlanning)HibernateTemplate.Execute( delegate(ISession session) { return(session.CreateCriteria(typeof(EmployeeWeekTimePlanning)) .Add(Expression.Eq("EmployeeID", employeeid)) .Add(Expression.Lt("WeekBegin", currentMonday)) .AddOrder(Order.Desc("WeekBegin")) .SetMaxResults(1) .UniqueResult <EmployeeWeekTimePlanning>()); } ); if (entity == null && entity2 == null) { return(null); } else { if (entity == null) { return(entity2.Saldo); } if (entity2 == null) { return(entity.Saldo); } if (entity.WeekBegin < entity2.WeekBegin) { return(entity2.Saldo); } else { return(entity.Saldo); } } }
public void AddEntity(EmployeeWeekTimePlanning entity) { _entities.Add(entity); List <EmployeeWeekTimePlanning> lst = GetEntitiesByEmployeeId(entity.EmployeeID); if (lst == null) { lst = new List <EmployeeWeekTimePlanning>(); _index[entity.EmployeeID] = lst; } lst.Add(entity); lst.Sort(new PlanningWeekComparer()); }
protected override void _UpdateSaldo(EmployeeWeekTimePlanning entity, int lastSaldo, bool allin) { Debug.Assert(entity != null); if (entity != null) { int oldSaldo = entity.Saldo; base._UpdateSaldo(entity, lastSaldo, allin); if (oldSaldo != entity.Saldo) { UpdateEntity(entity); } } }
public static bool IsModified(EmployeeWeekTimePlanning entity, EmployeeWeek week) { return(entity.EmployeeID != week.EmployeeId || entity.Saldo != week.Saldo || entity.WeekBegin != week.BeginDate || entity.WeekEnd != week.EndDate || entity.WeekNumber != DateTimeHelper.GetWeekNumber(week.BeginDate, week.EndDate) || entity.AdditionalCharge != week.CountWeeklyAdditionalCharges || entity.PlannedHours != week.CountWeeklyPlanningWorkingHours || entity.PlusMinusHours != week.CountWeeklyPlusMinusHours || entity.WorkingHours != week.CountWeeklyWorkingHours || entity.ContractHours != week.ContractHoursPerWeek || entity.CustomEdit != week.CustomEdit || entity.AllIn != week.AllIn); }
public EmployeeWeekTimePlanning Assign(EmployeeWeekTimePlanning weekinfo) { if (weekinfo == null) { throw new NullReferenceException(); } ID = weekinfo.ID; CountWeeklyWorkingHours = weekinfo.WorkingHours; ContractHoursPerWeek = weekinfo.ContractHours; CountWeeklyPlusMinusHours = weekinfo.PlusMinusHours; CountWeeklyPlanningWorkingHours = weekinfo.PlannedHours; CountWeeklyAdditionalCharges = weekinfo.AdditionalCharge; Saldo = weekinfo.Saldo; _CustomEdit = weekinfo.CustomEdit; AllIn = weekinfo.AllIn; return(weekinfo); }
public virtual EmployeeWeekTimePlanning GetByDate(long emplid, DateTime date) { Debug.Assert(date.DayOfWeek == DayOfWeek.Monday); EmployeeWeekTimePlanning returnEntity = null; List <EmployeeWeekTimePlanning> list = null; _index.TryGetValue(emplid, out list); if (list != null) { foreach (EmployeeWeekTimePlanning entity in list) { if (entity.EmployeeID == emplid && entity.WeekBegin == date) { returnEntity = entity; } } } return(returnEntity); }
public void ValidateWeekWithContractEnd(long emplid, DateTime date) { List <EmployeeWeekTimePlanning> list = null; _index.TryGetValue(emplid, out list); if (list == null) { return; } for (int i = list.Count - 1; i >= 0; i--) { EmployeeWeekTimePlanning entity = list[i]; if (date <= entity.WeekBegin) { DoDeleteEntity(entity); list.RemoveAt(i); } } }
public void UpdateSaldoAfterPlanning(EmployeeWeek week) { EmployeeWeekTimePlanning entity = GetByDate(week.EmployeeId, week.BeginDate); if (entity == null) { entity = new EmployeeWeekTimePlanning(); EmployeeWeekProcessor.AssignTo(entity, week); UpdateEntity(entity); } else { if (EmployeeWeekProcessor.IsModified(entity, week)) { EmployeeWeekProcessor.AssignTo(entity, week); UpdateEntity(entity); } } UpdateSaldoFrom(week.EmployeeId, DateTimeHelper.GetNextMonday(week.BeginDate), week.Saldo); }
public EmployeeWeekTimePlanning AssignTo(EmployeeWeekTimePlanning weekinfo) { if (weekinfo == null) { throw new ArgumentNullException(); } //weekinfo.ID = ID; weekinfo.WorkingHours = CountWeeklyWorkingHours; weekinfo.ContractHours = ContractHoursPerWeek; weekinfo.PlusMinusHours = CountWeeklyPlusMinusHours; weekinfo.PlannedHours = CountWeeklyPlanningWorkingHours; weekinfo.AdditionalCharge = CountWeeklyAdditionalCharges; weekinfo.EmployeeID = EmployeeId; weekinfo.Saldo = Saldo; weekinfo.WeekBegin = BeginDate; weekinfo.WeekEnd = EndDate; weekinfo.CustomEdit = _CustomEdit; weekinfo.AllIn = AllIn; return(weekinfo); }
public static void RecalculateAfterModifiedContractEndDate(long[] emplids) { ILog Log = LogManager.GetLogger("EmployeeBusinessObject"); if (emplids == null || emplids.Length == 0) { Log.Debug("RecalculateAfterModifiedContractEndDate - Count of employees = 0"); return; } CacheListEmployeeContracts contracts = new CacheListEmployeeContracts(); contracts.LoadByEmployees(emplids); if (Log.IsDebugEnabled) { Log.Debug("Load contracts by long[] ids of employees"); } CacheListEmployeeRelations relations = new CacheListEmployeeRelations(); relations.LoadByEmployees(emplids); if (Log.IsDebugEnabled) { Log.Debug("Load relations by long[] ids of employees"); } #region debug checking #if DEBUG { //for (int i = 0; i < emplids.Length; i++) //{ // ListEmployeeContracts contract_list1 = contracts[emplids[i]]; // ListEmployeeRelations relation_list1 = relations[emplids[i]]; // if (contract_list1 == null && relation_list1 == null) // { // Log.Debug("Employee (" + emplids[i].ToString() + ") don't have contract and relation"); // } // if (contract_list1 == null) // { // Log.Debug("Employee (" + emplids[i].ToString() + ") don't have contract"); // } // if (relation_list1 == null) // { // Log.Debug("Employee (" + emplids[i].ToString() + ") don't have relation"); // } // DateTime lastContractDate = contract_list1.GetLastContractDate(); // DateTime lastRelationDate = relation_list1.GetLastRelationDate(); // if (lastContractDate != lastRelationDate) // { // Log.Debug(String.Format("Employee({0}) has not equal contract and relation end date: {1} and {2}", emplids[i], lastContractDate.ToShortDateString(), lastRelationDate.ToShortDateString())); // } //} } #endif #endregion Dictionary <long, DateTime> setStoreWorlds = new Dictionary <long, DateTime>(); Dictionary <long, DateTime> setStores = new Dictionary <long, DateTime>(); ListEmployeeContracts contract_list = null; DateTime last_contract_date; SrvEmployeeWeekRecordingList recording_weeks = new SrvEmployeeWeekRecordingList(); recording_weeks.InitList(emplids, DateTimeSql.FirstMinMonday); SrvEmployeeWeekPlanningList planning_weeks = new SrvEmployeeWeekPlanningList(emplids, DateTimeSql.FirstMinMonday); foreach (long employeeid in emplids) { Employee employee = ServerEnvironment.EmployeeService.FindById(employeeid); if (employee == null) { Log.Warn(String.Format("Employee({0}) not found !!!", employeeid)); continue; } setStores[employee.MainStoreID] = DateTime.Today; if (Log.IsDebugEnabled) { String debugMessage = String.Format(" Process {0}({1}) ( {2} )", employee.FullName, employee.PersID, employee.PersNumber); Log.Debug(debugMessage); } contract_list = contracts[employeeid]; if (contract_list == null || contract_list.Count == 0) { continue; } last_contract_date = contract_list.GetLastContractDate(); last_contract_date = last_contract_date.AddDays(1); last_contract_date = last_contract_date.Date; EmployeePlanningDayListEx planning_days = new EmployeePlanningDayListEx(employeeid, last_contract_date); foreach (EmployeeDayStatePlanning day in planning_days) { if (last_contract_date <= day.Date) { if (setStoreWorlds.ContainsKey(day.StoreWorldId)) { DateTime date = setStoreWorlds[day.StoreWorldId]; if (last_contract_date < date) { setStoreWorlds[day.StoreWorldId] = last_contract_date; } } else { setStoreWorlds[day.StoreWorldId] = last_contract_date; } } } EmployeeRecordingDayListEx recording_days = new EmployeeRecordingDayListEx(employeeid, last_contract_date, DateTimeSql.SmallDatetimeMax); foreach (EmployeeDayStateRecording day in recording_days) { if (last_contract_date <= day.Date) { if (setStoreWorlds.ContainsKey(day.StoreWorldId)) { DateTime date = setStoreWorlds[day.StoreWorldId]; if (last_contract_date < date) { setStoreWorlds[day.StoreWorldId] = last_contract_date; } } else { setStoreWorlds[day.StoreWorldId] = last_contract_date; } } } recording_weeks.ValidateWeekWithContractEnd(employeeid, last_contract_date); planning_weeks.ValidateWeekWithContractEnd(employeeid, last_contract_date); if (recording_days.Count > 0) { recording_days.RemoveFromDatabase(last_contract_date, DateTimeSql.SmallDatetimeMax); } if (planning_days.Count > 0) { planning_days.RemoveFromDatabase(last_contract_date, DateTimeSql.SmallDatetimeMax); } ClearEmployeeTimes(employeeid, last_contract_date, DateTimeSql.SmallDatetimeMax); if (last_contract_date.DayOfWeek != DayOfWeek.Monday) { DateTime monday = DateTimeHelper.GetMonday(last_contract_date); DateTime sunday = DateTimeHelper.GetSunday(monday); planning_days = new EmployeePlanningDayListEx(employeeid, monday, sunday); EmployeeWeekTimePlanning week_planning = planning_weeks.GetByDate(employeeid, monday); if (week_planning != null) { week_planning.PlannedHours = 0; week_planning.WorkingHours = 0; week_planning.AdditionalCharge = 0; int prevSaldo = week_planning.GetPrevSaldo(); foreach (EmployeeDayStatePlanning e in planning_days) { week_planning.PlannedHours += e.AllreadyPlannedHours; week_planning.WorkingHours += e.WorkingHours; week_planning.AdditionalCharge += e.SumOfAddHours; } week_planning.CalculateSaldo(prevSaldo); ServerEnvironment.EmployeeWeekTimePlanningService.Update(week_planning); } recording_days = new EmployeeRecordingDayListEx(employeeid, monday, sunday); EmployeeWeekTimeRecording week_recording = recording_weeks.GetByDate(employeeid, monday); if (week_recording != null) { week_recording.PlannedHours = 0; week_recording.WorkingHours = 0; week_recording.AdditionalCharge = 0; int prevSaldo = week_recording.GetPrevSaldo(); foreach (EmployeeDayStateRecording e in recording_days) { week_recording.PlannedHours += e.AllreadyPlannedHours; week_recording.WorkingHours += e.WorkingHours; week_recording.AdditionalCharge += e.SumOfAddHours; } week_recording.CalculateSaldo(prevSaldo); ServerEnvironment.EmployeeWeekTimeRecordingService.Update(week_recording); } } } List <StoreToWorld> lst = ServerEnvironment.StoreToWorldService.FindAll(); Dictionary <long, StoreToWorld> dc = new Dictionary <long, StoreToWorld>(); if (lst != null) { foreach (StoreToWorld sw in lst) { dc[sw.ID] = sw; } } //setStores.Clear(); StoreToWorld sw1 = null; foreach (long swid in setStoreWorlds.Keys) { if (dc.TryGetValue(swid, out sw1)) { setStores[sw1.StoreID] = DateTime.Today; } } foreach (long storeid in setStores.Keys) { StoreBufferHoursAvailableManager.UpdateWholeYear(storeid, 2008); } }
public override void FillPlanningLastSaldo(Dictionary <long, EmployeePlanningWeek> dict, long[] ids, DateTime aBeginWeek) { DateTime todayMonday = DateTimeHelper.GetMonday(DateTime.Today); Debug.Assert(aBeginWeek.DayOfWeek == DayOfWeek.Monday); DateTime currentMonday = aBeginWeek; bool bPastWeek = todayMonday > currentMonday; bool bFutureWeek = todayMonday < currentMonday; bool bCurrentWeek = todayMonday == currentMonday; if (bCurrentWeek) { return; } if (bFutureWeek) { SrvEmployeeWeekPlanningList cache_weeks = new SrvEmployeeWeekPlanningList(ids, todayMonday); foreach (EmployeePlanningWeek week in dict.Values) { List <EmployeeWeekTimePlanning> list_weeks = cache_weeks.GetEntitiesByEmployeeId(week.EmployeeId); DateTime minDate = todayMonday; EmployeeWeekTimePlanning prevWeekEntity = null; if (list_weeks != null && list_weeks.Count > 0) { foreach (EmployeeWeekTimePlanning entity in list_weeks) { if (entity.WeekBegin < currentMonday && minDate <= entity.WeekBegin) { prevWeekEntity = entity; minDate = prevWeekEntity.WeekBegin; } } } if (prevWeekEntity != null) { Debug.Assert(prevWeekEntity.WeekBegin < currentMonday); week.LastSaldo = prevWeekEntity.Saldo; } } return; } if (bPastWeek) { foreach (EmployeePlanningWeek week in dict.Values) { if (week.IsNew) { week.LastSaldo = 0; } else { week.LastSaldo = PlanningWeekProcessor.GetLastSaldoFromSaldo(week); } } } }
public void UpdateEntity(EmployeeWeekTimePlanning entity) { DoUpdateEntity(entity); }
public WeekPair(DateTime date, EmployeeWeekTimePlanning week) : this(date) { PlanningWeek = week; }