// user can change saldo from Employee manager // here recalculate saldo for planning week public void UpdateCustomSaldo(int saldo) { CheckAndInit(); if (!AustriaEmployee) { EmployeeWeekTimeRecording entity = RecordingWeeks.UpdateLastSaldoAsCustom(Employee.ID, saldo); int lastsaldo = saldo; DateTime date = DateTimeSql.FirstMinMonday; if (entity != null) { date = entity.WeekBegin.AddDays(7); } else { _employee.BalanceHours = Convert.ToDecimal(saldo); (ServerEnvironment.EmployeeService as EmployeeService).EmployeeDao.UpdateSaldo(Employee.ID, Employee.BalanceHours); } PlanningWeeks = new SrvEmployeeWeekPlanningList(); if (entity != null) { PlanningWeeks.InitList(Employee.ID, entity.WeekBegin); PlanningWeeks.SetCustomEditFlag(Employee.ID, entity.WeekBegin, saldo); } else { PlanningWeeks.InitList(Employee.ID, date); } PlanningWeeks.AllInManager = AllInManagers; PlanningWeeks.UpdateSaldoFrom(Employee.ID, date, lastsaldo); } }
public void RecalculateAfterImport(DateTime monday) { long id = BzEmployee.Employee.ID; if (!IsNeedRecalculationAfterImport(id, monday)) { return; } int lastSaldo = 0; if (BzEmployee.AustriaEmployee) { lastSaldo = Convert.ToInt32(BzEmployee.Employee.BalanceHours); } else { DateTime prevMonday = monday.AddDays(-7); IEmployeeWeek week = RecordingWeeks.GetByDate(id, prevMonday); if (week == null) { week = GetByDate(id, prevMonday); if (week == null) { lastSaldo = BzEmployee.GetLastSaldoForPlanning(monday); } else { lastSaldo = week.Saldo; } } else { lastSaldo = week.Saldo; } } List <EmployeeWeekTimePlanning> list = GetEntitiesByEmployeeId(id); if (list != null && list.Count > 0) { int contract = 0; bool allin = false; bool customedit = false; bool bModified = false; foreach (EmployeeWeekTimePlanning entity in list) { contract = 0; allin = false; customedit = false; bModified = false; if (entity.EmployeeID == id && entity.WeekBegin >= monday) { allin = AllInManager.GetAllIn(id, entity.WeekBegin, entity.WeekEnd); if (RecordingWeeks != null) { EmployeeWeekTimeRecording rec = RecordingWeeks.GetByDate(id, entity.WeekBegin); if (rec != null) { customedit = rec.CustomEdit; } } contract = Contracts.GetContractHours(entity.EmployeeID, entity.WeekBegin, entity.WeekEnd); bModified = (entity.CustomEdit != customedit) | (entity.AllIn != allin) | (entity.ContractHours != contract); if (bModified) { entity.CustomEdit = customedit; entity.AllIn = allin; entity.ContractHours = contract; } if (entity.CalculateSaldo(lastSaldo) | bModified) { UpdateEntity(entity); } lastSaldo = entity.Saldo; } } } }