Example #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;
                }
            }
        }
Example #2
0
        private void CheckAndInit()
        {
            if (AllInManagers == null)
            {
                AllInManagers = new CacheEmployeesAllIn();

                AllInManagers.LoadByEmployee(Employee.ID);
            }

            if (RecordingWeeks == null)
            {
                RecordingWeeks = new SrvEmployeeWeekRecordingList();

                RecordingWeeks.InitList(Employee.ID, DateOfInit);

                RecordingWeeks.CacheAllIn = AllInManagers;
            }
        }
Example #3
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);
        }
Example #4
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();
            }
        }
Example #5
0
        public List <EmployeeWeek> BuildEmployeeWeeks(long storeid, long worldid, DateTime aBegin, DateTime aEnd, bool bPlanning)
        {
            Store store = ServerEnvironment.StoreService.FindById(storeid);

            if (store == null)
            {
                return(null);
            }
            long countryid = store.CountryID;
            bool IsAustria = store.CountryID == ServerEnvironment.CountryService.AustriaCountryID;


            // list of all employee for storeid and world
            IList employees = EmployeeService.EmployeeDao.GetPlanningEmployeesByWorld(storeid, worldid, aBegin, aEnd);

            if (employees == null && employees.Count == 0)
            {
                return(null);
            }

            long[] ids = new long[employees.Count];
            for (int i = 0; i < employees.Count; i++)
            {
                ids[i] = (employees[i] as Employee).ID;
            }

            EmployeeRelationService relationService = EmployeeService.EmployeeRelationService as EmployeeRelationService;

            List <EmployeeRelation> emplRelations = relationService.GetEmployeeRelationsByEmployeeIds(ids, aBegin, aEnd);

            //CountryStoreWorldManager swmanager = new CountryStoreWorldManager(EmployeeService.StoreWorldService);
            //swmanager.StoreId = storeid;
            if (swCountryManager == null)
            {
                //long countryid = EmployeeService.StoreService.GetCountryByStoreId(storeid);
                swCountryManager           = new CountryStoreWorldManager(EmployeeService.StoreWorldService);
                swCountryManager.CountryId = countryid;
            }

            List <EmployeeLongTimeAbsence> emplLongTimeAbsences =
                EmployeeService.EmployeeLongTimeAbsenceService.GetEmployeesHasLongTimeAbsence(ids, aBegin, aEnd);

            EmployeeLongTimeAbsenceIndexer absenceIndexer = new EmployeeLongTimeAbsenceIndexer(emplLongTimeAbsences);

            DictionListEmployeeRelations relationIndexer = new DictionListEmployeeRelations(emplRelations);

            List <EmployeeContract> contracts = EmployeeService.EmployeeContractService.GetEmployeeContracts(ids, aBegin, aEnd);

            ContractIndexer = new DictionListEmployeesContract(contracts);


            // applly relations
            EmployeeRelation relationWorld     = null;
            bool             bExistsRelation   = false;
            bool             bExistsContract   = false;
            bool             bNotExistsAbsence = true;

            _listweeks = new List <EmployeeWeek>();
            EmployeeWeek emplWeek = null;


            foreach (Employee empl in employees)
            {
                emplWeek           = new EmployeeWeek(empl.ID, empl.FullName, aBegin, aEnd, empl.OrderHwgrID.HasValue ? empl.OrderHwgrID.Value : 0);
                emplWeek.LastSaldo = (int)Math.Round(empl.BalanceHours);
                bExistsRelation    = false;

                foreach (EmployeeDay d in emplWeek.DaysList)
                {
                    relationWorld = relationIndexer.GetRelationEntity(empl.ID, d.Date);
                    if (relationWorld != null)
                    {
                        d.StoreWorldId = swCountryManager.GetStoreWorldIdByStoreAndWorldId(relationWorld.StoreID, relationWorld.WorldID.Value);
                        d.StoreId      = relationWorld.StoreID;
                    }

                    bExistsRelation |= d.HasRelation;
                }
                if (bExistsRelation)
                {
                    bExistsContract = ContractIndexer.FillEmployeeWeek(emplWeek);
                    if (bExistsContract)
                    {
                        bNotExistsAbsence = absenceIndexer.FillEmployeeWeek(emplWeek);

                        if (bNotExistsAbsence)
                        {
                            _listweeks.Add(emplWeek);
                        }
                    }
                }
            }

            FillEmployeeDayByStoreDay(storeid, aBegin, aEnd);

            _dictionWeek = EmployeeWeekProcessor.GetDictionary(_listweeks);
            _employeeids = EmployeeWeekProcessor.GetEmployeeIds(_listweeks);


            if (bPlanning)
            {
                FillPlanningEmployeeWeeks(storeid, worldid, aBegin, aEnd);
            }
            else
            {
                FillActualEmployeeWeeks(storeid, worldid, aBegin, aEnd);
            }

            //LastSaldoBuilder saldoBuilder = new LastSaldoBuilder();
            LastSaldoBuilder saldoBuilder = (IsAustria) ? new LastSaldoBuilderAustria() : new LastSaldoBuilder();



            saldoBuilder.FillLastSaldo(_dictionWeek, _employeeids, aBegin, bPlanning);

            EmployeeMonthWorkingTime monthData = new EmployeeMonthWorkingTime(EmployeeService.EmployeeTimeService as EmployeeTimeService);

            monthData.IsPlanning    = bPlanning;
            monthData.CurrentMonday = aBegin;
            CacheEmployeesAllIn managerAllIn = new CacheEmployeesAllIn();

            managerAllIn.LoadByStoreRelation(storeid);

            foreach (EmployeeWeek ew in _listweeks)
            {
                ew.WorkingTimeByMonth = monthData.GetMonthWorkingTime(ew.EmployeeId);
                ew.CountSaturday      = (byte)monthData.CountSaturday;
                ew.CountSunday        = (byte)monthData.CountSunday;

                ew.WorkingDaysBefore = (byte)monthData.WorkingDaysBefore;
                ew.WorkingDaysAfter  = (byte)monthData.WorkingDaysAfter;
                ew.AllIn             = managerAllIn.GetAllIn(ew.EmployeeId, aBegin, aEnd);
            }

            return(_listweeks);
        }