Beispiel #1
0
        public void UpdateAllInFlag(DateTime date)
        {
            DateTime fromDate = DateTimeHelper.GetMonday(date);


            AllInManagers = new CacheEmployeesAllIn();
            AllInManagers.LoadByEmployee(Employee.ID);



            PlanningWeeks = new SrvEmployeeWeekPlanningList(Employee.ID, fromDate);
            PlanningDays  = new SrvEmployeesPlanningDayList(Employee.ID, fromDate);
            PlanningWeeks.AllInManager = AllInManagers;


            List <EmployeeWeekTimePlanning> list =
                PlanningWeeks.GetEntitiesByEmployeeId(Employee.ID);

            if (list != null && list.Count > 0)
            {
                int lastSaldo = GetLastSaldoForPlanning(fromDate);

                bool bAllIn = false;
                foreach (EmployeeWeekTimePlanning week_entity in list)
                {
                    if (week_entity.WeekBegin < fromDate)
                    {
                        continue;
                    }

                    bAllIn = AllInManagers.GetAllIn(week_entity.EmployeeID, week_entity.WeekBegin, week_entity.WeekEnd);

                    Debug.WriteLine(Employee.FullName + week_entity.Dump());


                    if (week_entity.AllIn != bAllIn)
                    {
                        week_entity.AllIn = bAllIn;

                        if (!week_entity.AllIn)
                        {
                            week_entity.AdditionalCharge = PlanningDays.GetAdditionalChargesForWeekRange(week_entity.EmployeeID,
                                                                                                         week_entity.WeekBegin, week_entity.WeekEnd);;

                            week_entity.CalculateSaldo(lastSaldo);
                        }
                        else
                        {
                            week_entity.AdditionalCharge = 0;
                        }
                        PlanningWeeks.UpdateEntity(week_entity);
                    }

                    Debug.WriteLine(Employee.FullName + week_entity.Dump());

                    lastSaldo = week_entity.Saldo;
                }
            }
        }
Beispiel #2
0
        public void RecalculateFrom(DateTime date)
        {
            DateTime monday     = DateTimeHelper.GetMonday(date);
            DateTime PrevMonday = monday.AddDays(-7);

            if (Relations == null)
            {
                Relations = new DictionListEmployeeRelations(ServerEnvironment.EmployeeRelationService.GetEmployeeRelations(Employee.ID));
            }
            if (Contracts == null)
            {
                Contracts = new DictionListEmployeesContract(ServerEnvironment.EmployeeContractService.GetEmployeeContracts(Employee.ID));
            }

            //LongAbsences = new EmployeeLongTimeAbsenceIndexer(ServerEnvironment.EmployeeLongTimeAbsenceService, Employee.ID);
            if (AllInManagers == null)
            {
                AllInManagers = new CacheEmployeesAllIn(Employee.ID);
            }
            if (RecordingWeeks == null)
            {
                RecordingWeeks = new SrvEmployeeWeekRecordingList();

                RecordingWeeks.InitList(Employee.ID, PrevMonday);
            }


            if (PlanningWeeks == null)
            {
                PlanningWeeks = new SrvEmployeeWeekPlanningList(Employee.ID, PrevMonday);
            }
            PlanningWeeks.BzEmployee     = this;
            PlanningWeeks.AllInManager   = AllInManagers;
            PlanningWeeks.Contracts      = Contracts;
            PlanningWeeks.RecordingWeeks = RecordingWeeks;

            PlanningWeeks.RecalculateAfterImport(monday);
        }
        public virtual void Save()
        {
            if (_employeeweeks != null && _employeeweeks.Count > 0)
            {
                long[] ids = EmployeeWeekProcessor.GetEmployeeIds(_employeeweeks);
                // load from BeginDate to 2079 year
                SrvEmployeeWeekPlanningList plan_list = new SrvEmployeeWeekPlanningList(ids, BeginDate);
                SrvEmployeesPlanningDayList day_list  = new SrvEmployeesPlanningDayList(ids, BeginDate);
                foreach (EmployeeWeek w in _employeeweeks)
                {
                    plan_list.UpdateSaldoAfterPlanning(w);
                    foreach (EmployeeDay ed in w.DaysList)
                    {
                        day_list.CompareAndSave(ed);
                    }
                }


                EmployeePlanningWorkingModelHelper wmhelper = new EmployeePlanningWorkingModelHelper(_timeservice.EmployeePlanningWorkingModelService);

                wmhelper.SaveEmployeeWorkingModel(_employeeweeks);
            }
        }
Beispiel #4
0
        // 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);
            }
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        public static void Recalculate(long[] ids)
        {
            EmployeeService empl_service = ServerEnvironment.EmployeeService as EmployeeService;

            List <Employee> lst = empl_service.EmployeeDao.GetEmployeeByIds(ids);

            IList list = empl_service.EmployeeDao.GetDifferenceContractsAndRelations();

            if (lst == null)
            {
                return;
            }
            int i = 0;

            DictionListEmployeeRelations rels = new DictionListEmployeeRelations(ServerEnvironment.EmployeeRelationService.LoadAllSorted());



            CacheListEmployeeContracts contracts = (new CacheListEmployeeContracts()).LoadAll();

            CacheEmployeesAllIn all = (new CacheEmployeesAllIn()).LoadAll();

            DateTime beginDate = DateTime.Today.AddDays(-7);

            beginDate = DateTimeHelper.GetMonday(beginDate);


            SrvEmployeeWeekPlanningList PlanningWeeks = new SrvEmployeeWeekPlanningList();

            PlanningWeeks.InitList(null, beginDate);

            SrvEmployeeWeekRecordingList RecordingWeeks = new SrvEmployeeWeekRecordingList();

            RecordingWeeks.InitList(null, beginDate);

            List <Store>             stores         = ServerEnvironment.StoreService.FindAll();
            Dictionary <long, Store> diction_stores = new Dictionary <long, Store>();

            foreach (Store s in stores)
            {
                diction_stores[s.ID] = s;
            }

            long austriaid = ServerEnvironment.CountryService.AustriaCountryID;
            //rels.LoadRelations(ServerEnvironment.EmployeeRelationService);
            EmployeeBusinessObject bz = null;

            foreach (Employee e in lst)
            {
                i++;

                if (bz == null)
                {
                    bz = new EmployeeBusinessObject(e, DateTime.Today);
                }
                else
                {
                    bz.Employee = e;
                }

                bz.AustriaEmployee = diction_stores[e.MainStoreID].CountryID == austriaid;

                bz.Relations     = rels;
                bz.Contracts     = contracts;
                bz.AllInManagers = all;

                bz.PlanningWeeks  = PlanningWeeks;
                bz.RecordingWeeks = RecordingWeeks;
                bz.RecalculateFrom();
            }
        }
Beispiel #7
0
        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);
                    }
                }
            }
        }