예제 #1
0
        public static EmployeeHolidaysInfo UpdateNewOldHolidays(EmployeeHolidaysInfo entity, double old_holidays, double new_holidays)
        {
            if (entity == null)
                throw new ArgumentNullException();

            bool bModified = entity.IsNew ||entity.OldHolidays != Convert.ToDecimal(old_holidays) ||
                entity.NewHolidays != Convert.ToDecimal(new_holidays);

            entity.OldHolidays = Convert.ToDecimal(old_holidays);
            entity.NewHolidays = Convert.ToDecimal(new_holidays);

            if (entity.CalculateSpareHolidays())
                Srv.SaveOrUpdate(entity);

            return entity;
        }
예제 #2
0
        public static List<EmployeeHolidaysInfo> BuildOldHolidaysFromPreviousYear(long storeid, int year)
        {
            ILog log = LogManager.GetLogger("ExEmployeeHolidays");

            if (year - 1 < DateTimeSql.SmallDatetimeMin.Year) return null;
            DateTime begin_year_date = DateTimeHelper.GetBeginYearDate(year);
            DateTime end_year_date = DateTimeHelper.GetEndYearDate(year);

            if (log.IsDebugEnabled)
                log.Debug(string.Format("Begin move spare(exc) holidays from {0} to {1} years for store {2}", year-1, year, storeid));

            EmployeeService service = ServerEnvironment.EmployeeService as EmployeeService;
            List<Employee> employeesList = service.EmployeeDao.GetStoreEmployeesHaveContracts(storeid, begin_year_date, end_year_date);

            if (log.IsDebugEnabled)
            {
                int iCount = (employeesList != null)? employeesList.Count: 0;

                log.Debug(string.Format("Loaded {0} employees for year {1}", iCount, year));

            }

            if (employeesList == null || employeesList.Count == 0) return null;

            List<EmployeeHolidaysInfo> listOldHolidaysInfo = GetAllByStore(storeid, year - 1);
            if (listOldHolidaysInfo == null || listOldHolidaysInfo.Count == 0) return null;

            List<EmployeeHolidaysInfo> listCurrentHolidaysInfo = GetAllByStore(storeid, year);

            Dictionary<long, EmployeeHolidaysInfo> diction_old_holidays = ConvertToDictionary(listOldHolidaysInfo);
            Dictionary<long, EmployeeHolidaysInfo> diction_current_holidays = ConvertToDictionary(listCurrentHolidaysInfo);

            if (log.IsDebugEnabled)
            {
                int iCount = (listCurrentHolidaysInfo != null) ? listCurrentHolidaysInfo.Count : 0;
                int iCount2 = (listOldHolidaysInfo != null) ? listOldHolidaysInfo.Count : 0;

                log.Debug(string.Format("Loaded previous entities {0} and current entities {1} ", iCount2, iCount));

            }

            EmployeeHolidaysInfo old_holiday_info = null;
            EmployeeHolidaysInfo current_holiday_info = null;

            foreach (Employee employee in employeesList)
            {
                old_holiday_info = current_holiday_info = null;

                diction_old_holidays.TryGetValue(employee.ID, out old_holiday_info);
                diction_current_holidays.TryGetValue(employee.ID, out current_holiday_info);

                if (old_holiday_info != null)
                {
                    if (current_holiday_info != null)
                    {
                        bool modified = current_holiday_info.OldHolidays != old_holiday_info.SpareHolidaysExc;

                        current_holiday_info.OldHolidays = old_holiday_info.SpareHolidaysExc;
                        modified |= current_holiday_info.CalculateSpareHolidays();

                        if (modified)
                        {
                            Srv.SaveOrUpdate(current_holiday_info);
                        }
                    }
                    else
                    {
                        current_holiday_info = new EmployeeHolidaysInfo(employee.ID, (short)year);

                        current_holiday_info.OldHolidays = old_holiday_info.SpareHolidaysExc;

                        EmlpoyeeHolidaysSumDays sums_by_year = GetHolidaysSumDays(employee.ID, begin_year_date, end_year_date);

                        if (sums_by_year != null)
                        {
                            current_holiday_info.TakenHolidays = sums_by_year.TimeRecording;
                            current_holiday_info.PlannedHolidays = sums_by_year.TimePlanning;

                        }
                        current_holiday_info.CalculateSpareHolidays();
                        Srv.SaveOrUpdate(current_holiday_info);

                        if (log.IsDebugEnabled)
                        {
                            log.Debug(string.Format("Create entity from employee ID={0} and Name = {1}; Year={2} ", employee.ID, employee.FullName, year));
                        }

                    }
                }
            }

            listCurrentHolidaysInfo = GetAllByStore(storeid, year);

            return listCurrentHolidaysInfo;
        }
예제 #3
0
        public static EmployeeHolidaysInfo CalculateAndUpdate(EmployeeHolidaysInfo entity, bool bAustria)
        {
            Debug.Assert(entity != null);

            if (entity == null) return null;

            Debug.WriteLine("Begin calculate: " + entity.ToString());
            int TodayYear = DateTimeHelper.GetYearByDate(DateTime.Today);

            DateTime begin_year_date = DateTimeHelper.GetBeginYearDate(entity.Year);
            DateTime end_year_date = DateTimeHelper.GetEndYearDate(entity.Year);

            StoreService storeservice = ServerEnvironment.StoreService as StoreService;
            EmlpoyeeHolidaysSumDays sums_by_year =
                storeservice.EmlpoyeeHolidaysSumInfoByEmployeeIDGet(entity.EmployeeID, begin_year_date, end_year_date, DateTime.Today);

            bool bModified = entity.IsNew;

            if (sums_by_year != null)
            {
                //decimal taken = Math.Round(sums_by_year.TimeRecording / 1440, 2);
                //decimal used = Math.Round(sums_by_year.TimePlanning / 1440, 2);

                decimal taken = Math.Round(sums_by_year.TimeRecording, 2);
                decimal used = Math.Round(sums_by_year.TimePlanning, 2);

                bModified |= (taken != entity.TakenHolidays) ||
                    (used != entity.PlannedHolidays);

                entity.TakenHolidays = taken;
                entity.PlannedHolidays = used;
            }
            if (bAustria )
                bModified |= entity.CalculateSpareHolidays_Austria();
            else
                bModified |= entity.CalculateSpareHolidays();

            //Debug.Assert(entity.IsNew == bModified);

            if (bModified)
            {
                Debug.WriteLine("Entity was changed : " + entity.ToString());
                Srv.SaveOrUpdate(entity);
            }

            Debug.WriteLine("End calculate: " + entity.ToString());
            return entity;
        }