Example #1
0
        public int GetSaldoBefore(long emplid, DateTime beforeDate)
        {
            List <EmployeeWeekTimeRecording> list = GetEntitiesByEmployeeId(emplid);

            if (list != null)
            {
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    if (list[i].WeekBegin < beforeDate)
                    {
                        return(list[i].Saldo);
                    }
                }
            }
            EmployeeWeekTimeRecording entity = LoadLastEntity(emplid, beforeDate);

            if (entity != null)
            {
                if (list != null)
                {
                    list.Insert(0, entity);
                }
                else
                {
                    list = new List <EmployeeWeekTimeRecording>();
                    list.Add(entity);
                    _index.Add(emplid, list);
                }

                return(entity.Saldo);
            }
            return(0);
        }
Example #2
0
        // warning!!!!  recursive function
        public void UpdatePlanningSaldo(EmployeeWeekTimePlanning prevEntity)
        {
            if (prevEntity == null)
            {
                throw new ArgumentNullException();
            }

            EmployeeWeekTimeRecording entity = GetRecordingWeek(prevEntity.EmployeeID, prevEntity.WeekBegin);

            DateTime mondayDate = DateTimeHelper.GetNextMonday(prevEntity.WeekBegin);
            DateTime sundayDate = DateTimeHelper.GetNextSunday(prevEntity.WeekBegin);

            if (entity != null)
            {
                EmployeeWeekTimePlanning nextEntity = GetEmployeeWeekState(prevEntity.EmployeeID, mondayDate, sundayDate);

                if (nextEntity != null)
                {
                    nextEntity.Saldo = entity.Saldo + nextEntity.PlusMinusHours;
                    SaveOrUpdate(nextEntity);

                    UpdatePlanningSaldo(nextEntity);
                }
            }
            else
            {
                UpdateSaldo(prevEntity);
            }
        }
Example #3
0
        public void InitList(long[] emplids, DateTime fromDate)
        {
            Debug.Assert(fromDate.DayOfWeek == DayOfWeek.Monday);

            ClearList();

            List <EmployeeWeekTimeRecording> lst = LoadEntities(emplids, fromDate);

            if (lst != null)
            {
                _entities = lst;
                BuildIndex();
            }

            // if employee had long time absence need load last recording week
            if (emplids != null)
            {
                for (int i = 0; i < emplids.Length; i++)
                {
                    if (!_index.ContainsKey(emplids[i]))
                    {
                        EmployeeWeekTimeRecording entity = LoadLastEntity(emplids[i], fromDate);

                        if (entity != null)
                        {
                            lst = new List <EmployeeWeekTimeRecording>();
                            lst.Add(entity);
                            _index[emplids[i]] = lst;
                            _entities.Add(entity);
                        }
                    }
                }
            }
        }
Example #4
0
 protected virtual void DeleteEntity(EmployeeWeekTimeRecording entity)
 {
     if (entity.IsNew)
     {
         return;
     }
     Service.Delete(entity);
 }
Example #5
0
        public virtual void UpdateSaldo(long emplid, DateTime date, int lastSaldo, bool allin)
        {
            EmployeeWeekTimeRecording entity = GetByDate(emplid, date);

            if (entity != null)
            {
                _UpdateSaldo(entity, lastSaldo, allin);
            }
        }
Example #6
0
        public EmployeeWeekTimeRecording GetLastEntity(long emplid)
        {
            List <EmployeeWeekTimeRecording> list   = GetEntitiesByEmployeeId(emplid);
            EmployeeWeekTimeRecording        entity = null;

            if (list != null && list.Count > 0)
            {
                entity = list[list.Count - 1];
            }

            return(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);
                }
            }
        }
Example #8
0
        protected virtual void UpdateEntity(EmployeeWeekTimeRecording entity)
        {
            if (entity.IsNew)
            {
                Service.Save(entity);
            }
            else
            {
                Service.Update(entity);
            }

            //Service.SaveOrUpdate(entity);
        }
        public static int CompareEntities(EmployeeWeekTimeRecording x, EmployeeWeekTimeRecording y)
        {
            Debug.Assert(x != null && y != null);

            int i = x.EmployeeID.CompareTo(y.EmployeeID);

            if (i == 0)
            {
                i = x.WeekBegin.CompareTo(y.WeekBegin);
            }

            return i;
        }
Example #10
0
        public static int CompareEntities(EmployeeWeekTimeRecording x, EmployeeWeekTimeRecording y)
        {
            Debug.Assert(x != null && y != null);

            int i = x.EmployeeID.CompareTo(y.EmployeeID);

            if (i == 0)
            {
                i = x.WeekBegin.CompareTo(y.WeekBegin);
            }

            return(i);
        }
Example #11
0
        protected override void _UpdateSaldo(EmployeeWeekTimeRecording 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);
                }
            }
        }
Example #12
0
        //public static int BuildCountSundayForNextWeek(EmployeeWeek week)
        //{
        //    DateTime bDate = week.BeginDate;
        //    DateTime eDate = week.EndDate;

        //    int result = week.CountSunday;

        //    if (bDate.Month == eDate.Month)
        //    {
        //        // if sunday = last month day=> result = 0
        //        if (DateTimeHelper.IsLastDayOfMonth(eDate))
        //            result = 0;
        //        else
        //            if (week.IsSundayWorking)
        //                result++;
        //    }
        //    else
        //        if (week.IsSundayWorking)
        //            result = 1;

        //    return result;
        //}
        //public static int BuildCountSaturdayForNextWeek(EmployeeWeek week)
        //{
        //    DateTime bDate = week.BeginDate;
        //    DateTime eDate = week.EndDate;
        //    DateTime sDate = eDate.AddDays(-1);

        //    int result = week.CountSaturday;

        //    if (bDate.Month == sDate.Month)
        //    {
        //        if (week.IsSaturdayWorking)
        //            result++;

        //        if (bDate.Month != eDate.Month || DateTimeHelper.IsLastDayOfMonth (eDate))
        //                result = 0;
        //    }
        //    else
        //        if (week.IsSaturdayWorking)
        //            result = 1;

        //    return result;
        //}
        //public static int BuildMonthSumForNextWeek(EmployeeWeek week)
        //{
        //    DateTime bDate = week.BeginDate;
        //    DateTime eDate = week.EndDate;
        //    int result = week.WorkingTimeByMonth;

        //    if (bDate.Month == eDate.Month)
        //    {
        //        result += week.CountWeeklyPlanningWorkingHours;

        //        if (DateTimeHelper.IsLastDayOfMonth(eDate))
        //            result = 0;
        //    }
        //    else
        //    {
        //        int sum = 0;

        //        foreach (EmployeeDay day in week.DaysList)
        //            if (day.Date.Month == eDate.Month)
        //                sum += day.CountDailyPlannedWorkingHours;
        //        result = sum;
        //    }


        //    return result;
        //}


        public static bool IsModified(EmployeeWeekTimeRecording 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);
        }
Example #13
0
        public EmployeeWeekTimeRecording UpdateLastSaldoAsCustom(long emplid, int saldo)
        {
            List <EmployeeWeekTimeRecording> list = GetEntitiesByEmployeeId(emplid);

            EmployeeWeekTimeRecording entity = GetLastEntity(emplid);

            if (entity != null)
            {
                entity.Saldo      = saldo;
                entity.CustomEdit = true;

                UpdateEntity(entity);
            }

            return(entity);
        }
Example #14
0
        public virtual EmployeeWeekTimeRecording GetByDate(long emplid, DateTime date)
        {
            Debug.Assert(date.DayOfWeek == DayOfWeek.Monday);
            EmployeeWeekTimeRecording        returnEntity = null;
            List <EmployeeWeekTimeRecording> list         = GetEntitiesByEmployeeId(emplid);

            if (list != null)
            {
                foreach (EmployeeWeekTimeRecording entity in list)
                {
                    if (entity.EmployeeID == emplid && entity.WeekBegin == date)
                    {
                        returnEntity = entity;
                    }
                }
            }

            return(returnEntity);
        }
Example #15
0
        protected virtual void _UpdateSaldo(EmployeeWeekTimeRecording entity, int lastSaldo, bool allin)
        {
            Debug.Assert(entity != null);
            if (entity != null)
            {
                entity.AllIn = allin;

                entity.CalculateSaldo(lastSaldo);
                //if (!entity.CustomEdit)
                //{
                //    entity.Saldo = lastSaldo - entity.ContractHours;

                //    if (!allin)
                //    {
                //        entity.Saldo += entity.AdditionalCharge;
                //    }

                //    entity.Saldo += entity.PlannedHours;
                //}
            }
        }
Example #16
0
        public void ValidateWeekWithContractEnd(long emplid, DateTime date)
        {
            List <EmployeeWeekTimeRecording> list = null;

            _index.TryGetValue(emplid, out list);

            if (list == null)
            {
                return;
            }

            for (int i = list.Count - 1; i >= 0; i--)
            {
                EmployeeWeekTimeRecording entity = list[i];
                if (date <= entity.WeekBegin)
                {
                    DeleteEntity(entity);
                    list.RemoveAt(i);
                }
            }
        }
Example #17
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);
            }
        }
Example #18
0
        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;
                    }
                }
            }
        }
        protected override void _UpdateSaldo(EmployeeWeekTimeRecording 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);
                }
            }
        }
        protected virtual void UpdateEntity(EmployeeWeekTimeRecording entity)
        {
            if (entity.IsNew)
                Service.Save(entity);
            else
                Service.Update(entity);

            //Service.SaveOrUpdate(entity);
        }
 protected virtual void DeleteEntity(EmployeeWeekTimeRecording entity)
 {
     if (entity.IsNew) return;
     Service.Delete(entity);
 }
        public virtual void UpdateEntityAfterRecording(EmployeeWeek week)
        {
            EmployeeWeekTimeRecording entity = GetByDate(week.EmployeeId, week.BeginDate);
            List<EmployeeWeekTimeRecording> list = GetEntitiesByEmployeeId(week.EmployeeId);

            if (entity == null)
            {
                entity = new EmployeeWeekTimeRecording();
                EmployeeWeekProcessor.AssignTo(entity, week);
                UpdateEntity(entity);

                if (list == null)
                {
                    list = new List<EmployeeWeekTimeRecording>();

                    _index[week.EmployeeId] = list;
                }

                _entities.Add(entity);
                list.Add(entity);

                list.Sort();

            }
            else
            {
                if (EmployeeWeekProcessor.IsModified(entity, week))
                {
                    EmployeeWeekProcessor.AssignTo(entity, week);
                    UpdateEntity(entity);
                }
            }

            if (list != null)
            {
                int previous_saldo = entity.Saldo;
                foreach (EmployeeWeekTimeRecording next_entity in list)
                {
                    if (next_entity.WeekBegin <= week.BeginDate) continue;

                    if (next_entity.CalculateSaldo(previous_saldo))
                    {
                        UpdateEntity(next_entity);
                        previous_saldo = next_entity.Saldo;
                    }
                    else break;
                }
            }

            SrvEmployeeWeekPlanningList planList = new SrvEmployeeWeekPlanningList(week.EmployeeId, week.EndDate.AddDays(1));
            //planList.UpdateSaldoFrom2(week.EmployeeId, week.EndDate.AddDays(1), week.Saldo);
            planList.UpdateSaldoAfterRecording(week.EmployeeId, list, week.EndDate.AddDays(1));
        }
Example #23
0
        public virtual void UpdateEntityAfterRecording(EmployeeWeek week)
        {
            EmployeeWeekTimeRecording        entity = GetByDate(week.EmployeeId, week.BeginDate);
            List <EmployeeWeekTimeRecording> list   = GetEntitiesByEmployeeId(week.EmployeeId);

            if (entity == null)
            {
                entity = new EmployeeWeekTimeRecording();
                EmployeeWeekProcessor.AssignTo(entity, week);
                UpdateEntity(entity);

                if (list == null)
                {
                    list = new List <EmployeeWeekTimeRecording>();

                    _index[week.EmployeeId] = list;
                }

                _entities.Add(entity);
                list.Add(entity);

                list.Sort();
            }
            else
            {
                if (EmployeeWeekProcessor.IsModified(entity, week))
                {
                    EmployeeWeekProcessor.AssignTo(entity, week);
                    UpdateEntity(entity);
                }
            }



            if (list != null)
            {
                int previous_saldo = entity.Saldo;
                foreach (EmployeeWeekTimeRecording next_entity in list)
                {
                    if (next_entity.WeekBegin <= week.BeginDate)
                    {
                        continue;
                    }

                    if (next_entity.CalculateSaldo(previous_saldo))
                    {
                        UpdateEntity(next_entity);
                        previous_saldo = next_entity.Saldo;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            SrvEmployeeWeekPlanningList planList = new SrvEmployeeWeekPlanningList(week.EmployeeId, week.EndDate.AddDays(1));

            //planList.UpdateSaldoFrom2(week.EmployeeId, week.EndDate.AddDays(1), week.Saldo);
            planList.UpdateSaldoAfterRecording(week.EmployeeId, list, week.EndDate.AddDays(1));
        }
        protected virtual void _UpdateSaldo(EmployeeWeekTimeRecording entity, int lastSaldo, bool allin)
        {
            Debug.Assert(entity != null);
            if (entity != null)
            {
                entity.AllIn = allin;

                entity.CalculateSaldo(lastSaldo);
                //if (!entity.CustomEdit)
                //{
                //    entity.Saldo = lastSaldo - entity.ContractHours;

                //    if (!allin)
                //    {
                //        entity.Saldo += entity.AdditionalCharge;
                //    }

                //    entity.Saldo += entity.PlannedHours;
                //}
            }
        }
Example #25
0
 public WeekPair(DateTime date, EmployeeWeekTimeRecording week)
     : this(date)
 {
     RecordingWeek = week;
 }
Example #26
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);
            }
        }
Example #27
0
 //public static int BuildCountSundayForNextWeek(EmployeeWeek week)
 //{
 //    DateTime bDate = week.BeginDate;
 //    DateTime eDate = week.EndDate;
 //    int result = week.CountSunday;
 //    if (bDate.Month == eDate.Month)
 //    {
 //        // if sunday = last month day=> result = 0
 //        if (DateTimeHelper.IsLastDayOfMonth(eDate))
 //            result = 0;
 //        else
 //            if (week.IsSundayWorking)
 //                result++;
 //    }
 //    else
 //        if (week.IsSundayWorking)
 //            result = 1;
 //    return result;
 //}
 //public static int BuildCountSaturdayForNextWeek(EmployeeWeek week)
 //{
 //    DateTime bDate = week.BeginDate;
 //    DateTime eDate = week.EndDate;
 //    DateTime sDate = eDate.AddDays(-1);
 //    int result = week.CountSaturday;
 //    if (bDate.Month == sDate.Month)
 //    {
 //        if (week.IsSaturdayWorking)
 //            result++;
 //        if (bDate.Month != eDate.Month || DateTimeHelper.IsLastDayOfMonth (eDate))
 //                result = 0;
 //    }
 //    else
 //        if (week.IsSaturdayWorking)
 //            result = 1;
 //    return result;
 //}
 //public static int BuildMonthSumForNextWeek(EmployeeWeek week)
 //{
 //    DateTime bDate = week.BeginDate;
 //    DateTime eDate = week.EndDate;
 //    int result = week.WorkingTimeByMonth;
 //    if (bDate.Month == eDate.Month)
 //    {
 //        result += week.CountWeeklyPlanningWorkingHours;
 //        if (DateTimeHelper.IsLastDayOfMonth(eDate))
 //            result = 0;
 //    }
 //    else
 //    {
 //        int sum = 0;
 //        foreach (EmployeeDay day in week.DaysList)
 //            if (day.Date.Month == eDate.Month)
 //                sum += day.CountDailyPlannedWorkingHours;
 //        result = sum;
 //    }
 //    return result;
 //}
 public static bool IsModified(EmployeeWeekTimeRecording 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 );
 }