Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
            }
        }